Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

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