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