Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1671 tullio 1
/* global.h, global variables                                               */
2
 
3
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
4
 
5
/*
6
 * Disclaimer of Warranty
7
 *
8
 * These software programs are available to the user without any license fee or
9
 * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
10
 * any and all warranties, whether express, implied, or statuary, including any
11
 * implied warranties or merchantability or of fitness for a particular
12
 * purpose.  In no event shall the copyright-holder be liable for any
13
 * incidental, punitive, or consequential damages of any kind whatsoever
14
 * arising from the use of these programs.
15
 *
16
 * This disclaimer of warranty extends to the user of these programs and user's
17
 * customers, employees, agents, transferees, successors, and assigns.
18
 *
19
 * The MPEG Software Simulation Group does not represent or warrant that the
20
 * programs furnished hereunder are free of infringement of any third-party
21
 * patents.
22
 *
23
 * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
24
 * are subject to royalty fees to patent holders.  Many of these patents are
25
 * general enough such that they are unavoidable regardless of implementation
26
 * design.
27
 *
28
 */
29
 
30
#include "ll/sys/types.h"
31
#include "kernel/kern.h"
32
#include "mpeg2dec.h"
33
 
34
#include <hartport/hartport/hartport.h>
35
#include "ll/i386/x-dos.h"
36
/* choose between declaration (GLOBAL undefined)
37
 * and definition (GLOBAL defined)
38
 * GLOBAL is defined in exactly one file mpeg2dec.c)
39
 */
40
 
41
#ifndef GLOBAL
42
#define EXTERN extern
43
#else
44
#define EXTERN
45
#endif
46
 
47
/* prototypes of global functions */
48
/* readpic.c */
49
void Substitute_Frame_Buffer(int bitstream_framenum,
50
  int sequence_framenum);
51
 
52
/* Get_Bits.c */
53
void Initialize_Buffer(void);
54
void Fill_Buffer(void);
55
unsigned int Show_Bits(int n);
56
unsigned int Get_Bits1(void);
57
void Flush_Buffer(int n);
58
unsigned int Get_Bits(int n);
59
int Get_Byte(void);
60
int Get_Word(void);
61
 
62
/* systems.c */
63
void Next_Packet(void);
64
int Get_Long(void);
65
void Flush_Buffer32(void);
66
unsigned int Get_Bits32(void);
67
 
68
 
69
/* getblk.c */
70
void Decode_MPEG1_Intra_Block(int comp, int dc_dct_pred[]);
71
void Decode_MPEG1_Non_Intra_Block(int comp);
72
void Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]);
73
void Decode_MPEG2_Non_Intra_Block(int comp);
74
 
75
/* gethdr.c */
76
int Get_Hdr(void);
77
void next_start_code(void);
78
int slice_header(void);
79
void marker_bit(char *text);
80
 
81
/* getpic.c */
82
void Decode_Picture(int bitstream_framenum, int sequence_framenum);
83
void Output_Last_Frame_of_Sequence(int framenum);
84
 
85
/* getvlc.c */
86
int Get_macroblock_type(void);
87
int Get_motion_code(void);
88
int Get_dmvector(void);
89
int Get_coded_block_pattern(void);
90
int Get_macroblock_address_increment(void);
91
int Get_Luma_DC_dct_diff(void);
92
int Get_Chroma_DC_dct_diff(void);
93
 
94
/* idct.c */
95
void Fast_IDCT(short *block);
96
void Initialize_Fast_IDCT(void);
97
 
98
/* Reference_IDCT.c */
99
void Initialize_Reference_IDCT(void);
100
void Reference_IDCT(short *block);
101
 
102
/* motion.c */
103
void motion_vectors(int PMV[2][2][2], int dmvector[2],
104
  int motion_vertical_field_select[2][2], int s, int motion_vector_count,
105
  int mv_format, int h_r_size, int v_r_size, int dmv, int mvscale);
106
void motion_vector(int *PMV, int *dmvector,
107
  int h_r_size, int v_r_size, int dmv, int mvscale, int full_pel_vector);
108
void Dual_Prime_Arithmetic(int DMV[][2], int *dmvector, int mvx, int mvy);
109
 
110
/* mpeg2dec.c */
111
void Error(char *text);
112
void Warning(char *text);
113
void Print_Bits(int code, int bits, int len);
114
 
115
/* recon.c */
116
void form_predictions(int bx, int by, int macroblock_type,
117
  int motion_type, int PMV[2][2][2], int motion_vertical_field_select[2][2],
118
  int dmvector[2], int stwtype);
119
 
120
/* spatscal.c */
121
void Spatial_Prediction(void);
122
 
123
/* store.c */
124
void Write_Frame(unsigned char *src[], int frame);
125
 
126
#ifdef DISPLAY
127
/* display.c */
128
void Initialize_Display_Process(char *name);
129
void Terminate_Display_Process (void);
130
void Display_Second_Field(void);
131
void dither(unsigned char *src[]);
132
void Initialize_Dither_Matrix(void);
133
#endif
134
 
135
/* global variables */
136
 
137
EXTERN char Version[]
138
#ifdef GLOBAL
139
  ="mpeg2decode V1.2a, 96/07/19"
140
#endif
141
;
142
 
143
EXTERN char Author[]
144
#ifdef GLOBAL
145
  ="(C) 1996, MPEG Software Simulation Group"
146
#endif
147
;
148
 
149
 
150
/* zig-zag and alternate scan patterns */
151
EXTERN unsigned char scan[2][64]
152
#ifdef GLOBAL
153
=
154
{
155
  { /* Zig-Zag scan pattern  */
156
    0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,
157
    12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,
158
    35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,
159
    58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63
160
  },
161
  { /* Alternate scan pattern */
162
    0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
163
    41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
164
    51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
165
    53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
166
  }
167
}
168
#endif
169
;
170
 
171
/* default intra quantization matrix */
172
EXTERN unsigned char default_intra_quantizer_matrix[64]
173
#ifdef GLOBAL
174
=
175
{
176
  8, 16, 19, 22, 26, 27, 29, 34,
177
  16, 16, 22, 24, 27, 29, 34, 37,
178
  19, 22, 26, 27, 29, 34, 34, 38,
179
  22, 22, 26, 27, 29, 34, 37, 40,
180
  22, 26, 27, 29, 32, 35, 40, 48,
181
  26, 27, 29, 32, 35, 40, 48, 58,
182
  26, 27, 29, 34, 38, 46, 56, 69,
183
  27, 29, 35, 38, 46, 56, 69, 83
184
}
185
#endif
186
;
187
 
188
/* non-linear quantization coefficient table */
189
EXTERN unsigned char Non_Linear_quantizer_scale[32]
190
#ifdef GLOBAL
191
=
192
{
193
   0, 1, 2, 3, 4, 5, 6, 7,
194
   8,10,12,14,16,18,20,22,
195
  24,28,32,36,40,44,48,52,
196
  56,64,72,80,88,96,104,112
197
}
198
#endif
199
;
200
 
201
/* color space conversion coefficients
202
 * for YCbCr -> RGB mapping
203
 *
204
 * entries are {crv,cbu,cgu,cgv}
205
 *
206
 * crv=(255/224)*65536*(1-cr)/0.5
207
 * cbu=(255/224)*65536*(1-cb)/0.5
208
 * cgu=(255/224)*65536*(cb/cg)*(1-cb)/0.5
209
 * cgv=(255/224)*65536*(cr/cg)*(1-cr)/0.5
210
 *
211
 * where Y=cr*R+cg*G+cb*B (cr+cg+cb=1)
212
 */
213
 
214
/* ISO/IEC 13818-2 section 6.3.6 sequence_display_extension() */
215
 
216
EXTERN int Inverse_Table_6_9[8][4]
217
#ifdef GLOBAL
218
=
219
{
220
  {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
221
  {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
222
  {104597, 132201, 25675, 53279}, /* unspecified */
223
  {104597, 132201, 25675, 53279}, /* reserved */
224
  {104448, 132798, 24759, 53109}, /* FCC */
225
  {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
226
  {104597, 132201, 25675, 53279}, /* SMPTE 170M */
227
  {117579, 136230, 16907, 35559}  /* SMPTE 240M (1987) */
228
}
229
#endif
230
;
231
 
232
 
233
 
234
 
235
 
236
/* output types (Output_Type) */
237
#define T_YUV   0
238
#define T_SIF   1
239
#define T_TGA   2
240
#define T_PPM   3
241
#define T_X11   4
242
#define T_X11HIQ 5
243
 
244
/* decoder operation control variables */
245
EXTERN int Output_Type;
246
EXTERN int hiQdither;
247
 
248
/* decoder operation control flags */
249
EXTERN int Quiet_Flag;
250
EXTERN int Trace_Flag;
251
EXTERN int Fault_Flag;
252
EXTERN int Verbose_Flag;
253
EXTERN int Two_Streams;
254
EXTERN int Spatial_Flag;
255
EXTERN int Reference_IDCT_Flag;
256
EXTERN int Frame_Store_Flag;
257
EXTERN int System_Stream_Flag;
258
EXTERN int Display_Progressive_Flag;
259
EXTERN int Ersatz_Flag;
260
EXTERN int Big_Picture_Flag;
261
EXTERN int Verify_Flag;
262
EXTERN int Stats_Flag;
263
EXTERN int User_Data_Flag;
264
EXTERN int Main_Bitstream_Flag;
265
 
266
 
267
/* filenames */
268
EXTERN char *Output_Picture_Filename;
269
EXTERN char *Substitute_Picture_Filename;
270
EXTERN char *Main_Bitstream_Filename;
271
EXTERN char *Enhancement_Layer_Bitstream_Filename;
272
 
273
 
274
/* buffers for multiuse purposes */
275
EXTERN char Error_Text[256];
276
EXTERN unsigned char *Clip;
277
 
278
/* pointers to generic picture buffers */
279
EXTERN unsigned char *backward_reference_frame[3];
280
EXTERN unsigned char *forward_reference_frame[3];
281
 
282
EXTERN unsigned char *auxframe[3];
283
EXTERN unsigned char *current_frame[3];
284
EXTERN unsigned char *substitute_frame[3];
285
 
286
 
287
/* pointers to scalability picture buffers */
288
EXTERN unsigned char *llframe0[3];
289
EXTERN unsigned char *llframe1[3];
290
 
291
EXTERN short *lltmp;
292
EXTERN char *Lower_Layer_Picture_Filename;
293
 
294
 
295
 
296
 
297
/* non-normative variables derived from normative elements */
298
EXTERN int Coded_Picture_Width;
299
EXTERN int Coded_Picture_Height;
300
EXTERN int Chroma_Width;
301
EXTERN int Chroma_Height;
302
EXTERN int block_count;
303
EXTERN int Second_Field;
304
EXTERN int profile, level;
305
 
306
/* normative derived variables (as per ISO/IEC 13818-2) */
307
EXTERN int horizontal_size;
308
EXTERN int vertical_size;
309
EXTERN int mb_width;
310
EXTERN int mb_height;
311
EXTERN double bit_rate;
312
EXTERN double frame_rate;
313
 
314
 
315
 
316
/* headers */
317
 
318
/* ISO/IEC 13818-2 section 6.2.2.1:  sequence_header() */
319
EXTERN int aspect_ratio_information;
320
EXTERN int frame_rate_code;
321
EXTERN int bit_rate_value;
322
EXTERN int vbv_buffer_size;
323
EXTERN int constrained_parameters_flag;
324
 
325
/* ISO/IEC 13818-2 section 6.2.2.3:  sequence_extension() */
326
EXTERN int profile_and_level_indication;
327
EXTERN int progressive_sequence;
328
EXTERN int chroma_format;
329
EXTERN int low_delay;
330
EXTERN int frame_rate_extension_n;
331
EXTERN int frame_rate_extension_d;
332
 
333
/* ISO/IEC 13818-2 section 6.2.2.4:  sequence_display_extension() */
334
EXTERN int video_format;  
335
EXTERN int color_description;
336
EXTERN int color_primaries;
337
EXTERN int transfer_characteristics;
338
EXTERN int matrix_coefficients;
339
EXTERN int display_horizontal_size;
340
EXTERN int display_vertical_size;
341
 
342
/* ISO/IEC 13818-2 section 6.2.3: picture_header() */
343
EXTERN int temporal_reference;
344
EXTERN int picture_coding_type;
345
EXTERN int vbv_delay;
346
EXTERN int full_pel_forward_vector;
347
EXTERN int forward_f_code;
348
EXTERN int full_pel_backward_vector;
349
EXTERN int backward_f_code;
350
 
351
 
352
/* ISO/IEC 13818-2 section 6.2.3.1: picture_coding_extension() header */
353
EXTERN int f_code[2][2];
354
EXTERN int intra_dc_precision;
355
EXTERN int picture_structure;
356
EXTERN int top_field_first;
357
EXTERN int frame_pred_frame_dct;
358
EXTERN int concealment_motion_vectors;
359
 
360
EXTERN int intra_vlc_format;
361
 
362
EXTERN int repeat_first_field;
363
 
364
EXTERN int chroma_420_type;
365
EXTERN int progressive_frame;
366
EXTERN int composite_display_flag;
367
EXTERN int v_axis;
368
EXTERN int field_sequence;
369
EXTERN int sub_carrier;
370
EXTERN int burst_amplitude;
371
EXTERN int sub_carrier_phase;
372
 
373
 
374
 
375
/* ISO/IEC 13818-2 section 6.2.3.3: picture_display_extension() header */
376
EXTERN int frame_center_horizontal_offset[3];
377
EXTERN int frame_center_vertical_offset[3];
378
 
379
 
380
 
381
/* ISO/IEC 13818-2 section 6.2.2.5: sequence_scalable_extension() header */
382
EXTERN int layer_id;
383
EXTERN int lower_layer_prediction_horizontal_size;
384
EXTERN int lower_layer_prediction_vertical_size;
385
EXTERN int horizontal_subsampling_factor_m;
386
EXTERN int horizontal_subsampling_factor_n;
387
EXTERN int vertical_subsampling_factor_m;
388
EXTERN int vertical_subsampling_factor_n;
389
 
390
 
391
/* ISO/IEC 13818-2 section 6.2.3.5: picture_spatial_scalable_extension() header */
392
EXTERN int lower_layer_temporal_reference;
393
EXTERN int lower_layer_horizontal_offset;
394
EXTERN int lower_layer_vertical_offset;
395
EXTERN int spatial_temporal_weight_code_table_index;
396
EXTERN int lower_layer_progressive_frame;
397
EXTERN int lower_layer_deinterlaced_field_select;
398
 
399
 
400
 
401
 
402
 
403
 
404
/* ISO/IEC 13818-2 section 6.2.3.6: copyright_extension() header */
405
EXTERN int copyright_flag;
406
EXTERN int copyright_identifier;
407
EXTERN int original_or_copy;
408
EXTERN int copyright_number_1;
409
EXTERN int copyright_number_2;
410
EXTERN int copyright_number_3;
411
 
412
/* ISO/IEC 13818-2 section 6.2.2.6: group_of_pictures_header()  */
413
EXTERN int drop_flag;
414
EXTERN int hour;
415
EXTERN int minute;
416
EXTERN int sec;
417
EXTERN int frame;
418
EXTERN int closed_gop;
419
EXTERN int broken_link;
420
 
421
 
422
 
423
/* layer specific variables (needed for SNR and DP scalability) */
424
EXTERN struct layer_data {
425
  /* bit input */
426
  int Infile;
427
 
428
  void *start_file_ptr;
429
  void *actual_file_ptr;
430
  void *end_file_ptr;
431
 
432
  int px;
433
  int py;
434
 
435
  unsigned char Rdbfr[2048];
436
  unsigned char *Rdptr;
437
  unsigned char Inbfr[16];
438
  /* from mpeg2play */
439
  unsigned int Bfr;
440
  unsigned char *Rdmax;
441
  int Incnt;
442
  int Bitcnt;
443
  /* sequence header and quant_matrix_extension() */
444
  int intra_quantizer_matrix[64];
445
  int non_intra_quantizer_matrix[64];
446
  int chroma_intra_quantizer_matrix[64];
447
  int chroma_non_intra_quantizer_matrix[64];
448
 
449
  int load_intra_quantizer_matrix;
450
  int load_non_intra_quantizer_matrix;
451
  int load_chroma_intra_quantizer_matrix;
452
  int load_chroma_non_intra_quantizer_matrix;
453
 
454
  int MPEG2_Flag;
455
  /* sequence scalable extension */
456
  int scalable_mode;
457
  /* picture coding extension */
458
  int q_scale_type;
459
  int alternate_scan;
460
  /* picture spatial scalable extension */
461
  int pict_scal;
462
  /* slice/macroblock */
463
  int priority_breakpoint;
464
  int quantizer_scale;
465
  int intra_slice;
466
  short block[12][64];
467
} base, enhan, *ld;
468
 
469
#ifdef VERIFY
470
EXTERN int verify_sequence_header;
471
EXTERN int verify_group_of_pictures_header;
472
EXTERN int verify_picture_header;
473
EXTERN int verify_slice_header;
474
EXTERN int verify_sequence_extension;
475
EXTERN int verify_sequence_display_extension;
476
EXTERN int verify_quant_matrix_extension;
477
EXTERN int verify_sequence_scalable_extension;
478
EXTERN int verify_picture_display_extension;
479
EXTERN int verify_picture_coding_extension;
480
EXTERN int verify_picture_spatial_scalable_extension;
481
EXTERN int verify_picture_temporal_scalable_extension;
482
EXTERN int verify_copyright_extension;
483
#endif /* VERIFY */
484
 
485
 
486
EXTERN int Decode_Layer;
487
 
488
/* verify.c */
489
#ifdef VERIFY
490
void Check_Headers(int Bitstream_Framenum, int Sequence_Framenum);
491
void Clear_Verify_Headers(void);
492
#endif /* VERIFY */
493
 
494
 
495
EXTERN int global_MBA;
496
EXTERN int global_pic;
497
EXTERN int True_Framenum;
498
 
499
 
500
/***************************************************************************'
501
 *
502
 * Global things (structs, varable)
503
 *
504
 * Author: Robert Bäckgren
505
 ****************************************************************************/
506
 
507
#define NUMBER_OF_MESSAGE 3 
508
#define BUFFERSIZE 2048
509
 
510
// The message that goes between the read task and decoder task
511
struct readDecodeMessage
512
{
513
  int size;
514
  unsigned char buffer[BUFFERSIZE];
515
};
516
 
517
// The message that goes between the decoder and display
518
struct decodeDisplayMessage
519
{
520
  int frame;
521
  unsigned char *src[3];
522
};
523
 
524
// The struct tha contain the different ports that the decoder is using.
525
struct DecoderPorts
526
{
527
  PORT readTaskPort;
528
  PORT displayTaskPort;
529
};
530
 
531
// The different ports
532
struct DecoderPorts *decoderTaskPort;
533
PORT readTaskPort;
534
PORT displayTaskPort;
535
 
536
// This flag is used in the decoder init fase (must use or else we will read in the buffer wrong) Use it in function read in file getbits.c and in function Initialize_Decoder in file mpeg2dec.c. 
537
int initfaseFlag;
538
 
539
void displayTaskFunction(unsigned char *src[], int frame);