Rev 1085 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | |
2 | /* mpeg2dec.c, main(), initialization, option processing */ |
||
3 | |||
4 | /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */ |
||
5 | |||
6 | /* |
||
7 | * Disclaimer of Warranty |
||
8 | * |
||
9 | * These software programs are available to the user without any license fee or |
||
10 | * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims |
||
11 | * any and all warranties, whether express, implied, or statuary, including any |
||
12 | * implied warranties or merchantability or of fitness for a particular |
||
13 | * purpose. In no event shall the copyright-holder be liable for any |
||
14 | * incidental, punitive, or consequential damages of any kind whatsoever |
||
15 | * arising from the use of these programs. |
||
16 | * |
||
17 | * This disclaimer of warranty extends to the user of these programs and user's |
||
18 | * customers, employees, agents, transferees, successors, and assigns. |
||
19 | * |
||
20 | * The MPEG Software Simulation Group does not represent or warrant that the |
||
21 | * programs furnished hereunder are free of infringement of any third-party |
||
22 | * patents. |
||
23 | * |
||
24 | * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, |
||
25 | * are subject to royalty fees to patent holders. Many of these patents are |
||
26 | * general enough such that they are unavoidable regardless of implementation |
||
27 | * design. |
||
28 | * |
||
29 | */ |
||
30 | |||
31 | #include <stdio.h> |
||
32 | #include <stdlib.h> |
||
33 | #include <ctype.h> |
||
34 | #include <fcntl.h> |
||
35 | |||
36 | #define GLOBAL |
||
37 | #include "config.h" |
||
38 | #include "global.h" |
||
39 | |||
40 | /* private prototypes */ |
||
41 | static int video_sequence _ANSI_ARGS_((int *framenum)); |
||
42 | static int Decode_Bitstream _ANSI_ARGS_((void)); |
||
43 | static int Headers _ANSI_ARGS_((void)); |
||
44 | static void Initialize_Sequence _ANSI_ARGS_((void)); |
||
45 | static void Initialize_Decoder _ANSI_ARGS_((void)); |
||
46 | static void Deinitialize_Sequence _ANSI_ARGS_((void)); |
||
47 | static void Process_Options _ANSI_ARGS_((int argc, char *argv[])); |
||
48 | |||
49 | |||
50 | #if OLD |
||
51 | static int Get_Val _ANSI_ARGS_((char *argv[])); |
||
52 | #endif |
||
53 | |||
54 | /* #define DEBUG */ |
||
55 | |||
56 | static void Clear_Options(); |
||
57 | #ifdef DEBUG |
||
58 | static void Print_Options(); |
||
59 | #endif |
||
60 | |||
61 | int main(argc,argv) |
||
62 | int argc; |
||
63 | char *argv[]; |
||
64 | { |
||
65 | int ret, code; |
||
66 | |||
67 | Clear_Options(); |
||
68 | |||
69 | /* decode command line arguments */ |
||
70 | Process_Options(argc,argv); |
||
71 | |||
72 | #ifdef DEBUG |
||
73 | Print_Options(); |
||
74 | #endif |
||
75 | |||
76 | ld = &base; /* select base layer context */ |
||
77 | |||
78 | /* open MPEG base layer bitstream file(s) */ |
||
79 | /* NOTE: this is either a base layer stream or a spatial enhancement stream */ |
||
80 | if ((base.Infile=open(Main_Bitstream_Filename,O_RDONLY|O_BINARY))<0) |
||
81 | { |
||
82 | fprintf(stderr,"Base layer input file %s not found\n", Main_Bitstream_Filename); |
||
83 | exit(1); |
||
84 | } |
||
85 | |||
86 | |||
87 | if(base.Infile != 0) |
||
88 | { |
||
89 | Initialize_Buffer(); |
||
90 | |||
91 | if(Show_Bits(8)==0x47) |
||
92 | { |
||
93 | sprintf(Error_Text,"Decoder currently does not parse transport streams\n"); |
||
94 | Error(Error_Text); |
||
95 | } |
||
96 | |||
97 | next_start_code(); |
||
98 | code = Show_Bits(32); |
||
99 | |||
100 | switch(code) |
||
101 | { |
||
102 | case SEQUENCE_HEADER_CODE: |
||
103 | break; |
||
104 | case PACK_START_CODE: |
||
105 | System_Stream_Flag = 1; |
||
106 | case VIDEO_ELEMENTARY_STREAM: |
||
107 | System_Stream_Flag = 1; |
||
108 | break; |
||
109 | default: |
||
110 | sprintf(Error_Text,"Unable to recognize stream type\n"); |
||
111 | Error(Error_Text); |
||
112 | break; |
||
113 | } |
||
114 | |||
115 | lseek(base.Infile, 0l, 0); |
||
116 | Initialize_Buffer(); |
||
117 | } |
||
118 | |||
119 | if(base.Infile!=0) |
||
120 | { |
||
121 | lseek(base.Infile, 0l, 0); |
||
122 | } |
||
123 | |||
124 | Initialize_Buffer(); |
||
125 | |||
126 | if(Two_Streams) |
||
127 | { |
||
128 | ld = &enhan; /* select enhancement layer context */ |
||
129 | |||
130 | if ((enhan.Infile = open(Enhancement_Layer_Bitstream_Filename,O_RDONLY|O_BINARY))<0) |
||
131 | { |
||
132 | sprintf(Error_Text,"enhancment layer bitstream file %s not found\n", |
||
133 | Enhancement_Layer_Bitstream_Filename); |
||
134 | |||
135 | Error(Error_Text); |
||
136 | } |
||
137 | |||
138 | Initialize_Buffer(); |
||
139 | ld = &base; |
||
140 | } |
||
141 | |||
142 | Initialize_Decoder(); |
||
143 | |||
144 | ret = Decode_Bitstream(); |
||
145 | |||
146 | close(base.Infile); |
||
147 | |||
148 | if (Two_Streams) |
||
149 | close(enhan.Infile); |
||
150 | |||
151 | return 0; |
||
152 | } |
||
153 | |||
154 | /* IMPLEMENTAION specific rouintes */ |
||
155 | static void Initialize_Decoder() |
||
156 | { |
||
157 | int i; |
||
158 | |||
159 | /* Clip table */ |
||
160 | if (!(Clip=(unsigned char *)malloc(1024))) |
||
161 | Error("Clip[] malloc failed\n"); |
||
162 | |||
163 | Clip += 384; |
||
164 | |||
165 | for (i=-384; i<640; i++) |
||
166 | Clip[i] = (i<0) ? 0 : ((i>255) ? 255 : i); |
||
167 | |||
168 | /* IDCT */ |
||
169 | if (Reference_IDCT_Flag) |
||
170 | Initialize_Reference_IDCT(); |
||
171 | else |
||
172 | Initialize_Fast_IDCT(); |
||
173 | |||
174 | } |
||
175 | |||
176 | /* mostly IMPLEMENTAION specific rouintes */ |
||
177 | static void Initialize_Sequence() |
||
178 | { |
||
179 | int cc, size; |
||
180 | static int Table_6_20[3] = {6,8,12}; |
||
181 | |||
182 | /* check scalability mode of enhancement layer */ |
||
183 | if (Two_Streams && (enhan.scalable_mode!=SC_SNR) && (base.scalable_mode!=SC_DP)) |
||
184 | Error("unsupported scalability mode\n"); |
||
185 | |||
186 | /* force MPEG-1 parameters for proper decoder behavior */ |
||
187 | /* see ISO/IEC 13818-2 section D.9.14 */ |
||
188 | if (!base.MPEG2_Flag) |
||
189 | { |
||
190 | progressive_sequence = 1; |
||
191 | progressive_frame = 1; |
||
192 | picture_structure = FRAME_PICTURE; |
||
193 | frame_pred_frame_dct = 1; |
||
194 | chroma_format = CHROMA420; |
||
195 | matrix_coefficients = 5; |
||
196 | } |
||
197 | |||
198 | /* round to nearest multiple of coded macroblocks */ |
||
199 | /* ISO/IEC 13818-2 section 6.3.3 sequence_header() */ |
||
200 | mb_width = (horizontal_size+15)/16; |
||
201 | mb_height = (base.MPEG2_Flag && !progressive_sequence) ? 2*((vertical_size+31)/32) |
||
202 | : (vertical_size+15)/16; |
||
203 | |||
204 | Coded_Picture_Width = 16*mb_width; |
||
205 | Coded_Picture_Height = 16*mb_height; |
||
206 | |||
207 | /* ISO/IEC 13818-2 sections 6.1.1.8, 6.1.1.9, and 6.1.1.10 */ |
||
208 | Chroma_Width = (chroma_format==CHROMA444) ? Coded_Picture_Width |
||
209 | : Coded_Picture_Width>>1; |
||
210 | Chroma_Height = (chroma_format!=CHROMA420) ? Coded_Picture_Height |
||
211 | : Coded_Picture_Height>>1; |
||
212 | |||
213 | /* derived based on Table 6-20 in ISO/IEC 13818-2 section 6.3.17 */ |
||
214 | block_count = Table_6_20[chroma_format-1]; |
||
215 | |||
216 | for (cc=0; cc<3; cc++) |
||
217 | { |
||
218 | if (cc==0) |
||
219 | size = Coded_Picture_Width*Coded_Picture_Height; |
||
220 | else |
||
221 | size = Chroma_Width*Chroma_Height; |
||
222 | |||
223 | if (!(backward_reference_frame[cc] = (unsigned char *)malloc(size))) |
||
224 | Error("backward_reference_frame[] malloc failed\n"); |
||
225 | |||
226 | if (!(forward_reference_frame[cc] = (unsigned char *)malloc(size))) |
||
227 | Error("forward_reference_frame[] malloc failed\n"); |
||
228 | |||
229 | if (!(auxframe[cc] = (unsigned char *)malloc(size))) |
||
230 | Error("auxframe[] malloc failed\n"); |
||
231 | |||
232 | if(Ersatz_Flag) |
||
233 | if (!(substitute_frame[cc] = (unsigned char *)malloc(size))) |
||
234 | Error("substitute_frame[] malloc failed\n"); |
||
235 | |||
236 | |||
237 | if (base.scalable_mode==SC_SPAT) |
||
238 | { |
||
239 | /* this assumes lower layer is 4:2:0 */ |
||
240 | if (!(llframe0[cc] = (unsigned char *)malloc((lower_layer_prediction_horizontal_size*lower_layer_prediction_vertical_size)/(cc?4:1)))) |
||
241 | Error("llframe0 malloc failed\n"); |
||
242 | if (!(llframe1[cc] = (unsigned char *)malloc((lower_layer_prediction_horizontal_size*lower_layer_prediction_vertical_size)/(cc?4:1)))) |
||
243 | Error("llframe1 malloc failed\n"); |
||
244 | } |
||
245 | } |
||
246 | |||
247 | /* SCALABILITY: Spatial */ |
||
248 | if (base.scalable_mode==SC_SPAT) |
||
249 | { |
||
250 | if (!(lltmp = (short *)malloc(lower_layer_prediction_horizontal_size*((lower_layer_prediction_vertical_size*vertical_subsampling_factor_n)/vertical_subsampling_factor_m)*sizeof(short)))) |
||
251 | Error("lltmp malloc failed\n"); |
||
252 | } |
||
253 | |||
254 | // PJ |
||
255 | Initialize_framebuf( Coded_Picture_Width*Coded_Picture_Height*sizeof(WORD) ); |
||
256 | gvideo_init(); |
||
257 | init_jetcontrol(); |
||
258 | |||
259 | #ifdef DISPLAY |
||
260 | if (Output_Type==T_X11) |
||
261 | { |
||
262 | Initialize_Display_Process(""); |
||
263 | Initialize_Dither_Matrix(); |
||
264 | } |
||
265 | #endif /* DISPLAY */ |
||
266 | |||
267 | } |
||
268 | |||
269 | void Error(text) |
||
270 | char *text; |
||
271 | { |
||
272 | fprintf(stderr,text); |
||
273 | exit(1); |
||
274 | } |
||
275 | |||
276 | /* Trace_Flag output */ |
||
277 | void Print_Bits(code,bits,len) |
||
278 | int code,bits,len; |
||
279 | { |
||
280 | int i; |
||
281 | for (i=0; i<len; i++) |
||
282 | printf("%d",(code>>(bits-1-i))&1); |
||
283 | } |
||
284 | |||
285 | |||
286 | |||
287 | /* option processing */ |
||
288 | static void Process_Options(argc,argv) |
||
289 | int argc; /* argument count */ |
||
290 | char *argv[]; /* argument vector */ |
||
291 | { |
||
292 | int i, LastArg, NextArg; |
||
293 | |||
294 | /* at least one argument should be present */ |
||
295 | if (argc<2) |
||
296 | { |
||
297 | printf("\n%s, %s\n",Version,Author); |
||
298 | printf("Usage: mpeg2decode {options}\n\ |
||
299 | Options: -b file main bitstream (base or spatial enhancement layer)\n\ |
||
300 | -cn file conformance report (n: level)\n\ |
||
301 | -e file enhancement layer bitstream (SNR or Data Partitioning)\n\ |
||
302 | -f store/display interlaced video in frame format\n\ |
||
303 | -g concatenated file format for substitution method (-x)\n\ |
||
304 | -in file information & statistics report (n: level)\n\ |
||
305 | -l file file name pattern for lower layer sequence\n\ |
||
306 | (for spatial scalability)\n\ |
||
307 | -on file output format (0:YUV 1:SIF 2:TGA 3:PPM 4:X11 5:X11HiQ)\n\ |
||
308 | -q disable warnings to stderr\n\ |
||
309 | -r use double precision reference IDCT\n\ |
||
310 | -t enable low level tracing to stdout\n\ |
||
311 | -u file print user_data to stdio or file\n\ |
||
312 | -vn verbose output (n: level)\n\ |
||
313 | -x file filename pattern of picture substitution sequence\n\n\ |
||
314 | File patterns: for sequential filenames, \"printf\" style, e.g. rec%%d\n\ |
||
315 | or rec%%d%%c for fieldwise storage\n\ |
||
316 | Levels: 0:none 1:sequence 2:picture 3:slice 4:macroblock 5:block\n\n\ |
||
317 | Example: mpeg2decode -b bitstream.mpg -f -r -o0 rec%%d\n\ |
||
318 | \n"); |
||
319 | exit(0); |
||
320 | } |
||
321 | |||
322 | |||
323 | Output_Type = -1; |
||
324 | i = 1; |
||
325 | |||
326 | /* command-line options are proceeded by '-' */ |
||
327 | |||
328 | while(i < argc) |
||
329 | { |
||
330 | /* check if this is the last argument */ |
||
331 | LastArg = ((argc-i)==1); |
||
332 | |||
333 | /* parse ahead to see if another flag immediately follows current |
||
334 | argument (this is used to tell if a filename is missing) */ |
||
335 | if(!LastArg) |
||
336 | NextArg = (argv[i+1][0]=='-'); |
||
337 | else |
||
338 | NextArg = 0; |
||
339 | |||
340 | /* second character, [1], after '-' is the switch */ |
||
341 | if(argv[i][0]=='-') |
||
342 | { |
||
343 | switch(toupper(argv[i][1])) |
||
344 | { |
||
345 | /* third character. [2], is the value */ |
||
346 | case 'B': |
||
347 | Main_Bitstream_Flag = 1; |
||
348 | |||
349 | if(NextArg || LastArg) |
||
350 | { |
||
351 | printf("ERROR: -b must be followed the main bitstream filename\n"); |
||
352 | } |
||
353 | else |
||
354 | Main_Bitstream_Filename = argv[++i]; |
||
355 | |||
356 | break; |
||
357 | |||
358 | |||
359 | case 'C': |
||
360 | |||
361 | #ifdef VERIFY |
||
362 | Verify_Flag = atoi(&argv[i][2]); |
||
363 | |||
364 | if((Verify_Flag < NO_LAYER) || (Verify_Flag > ALL_LAYERS)) |
||
365 | { |
||
366 | printf("ERROR: -c level (%d) out of range [%d,%d]\n", |
||
367 | Verify_Flag, NO_LAYER, ALL_LAYERS); |
||
368 | exit(ERROR); |
||
369 | } |
||
370 | #else /* VERIFY */ |
||
371 | printf("This program not compiled for Verify_Flag option\n"); |
||
372 | #endif /* VERIFY */ |
||
373 | break; |
||
374 | |||
375 | case 'E': |
||
376 | Two_Streams = 1; /* either Data Partitioning (DP) or SNR Scalability enhancment */ |
||
377 | |||
378 | if(NextArg || LastArg) |
||
379 | { |
||
380 | printf("ERROR: -e must be followed by filename\n"); |
||
381 | exit(ERROR); |
||
382 | } |
||
383 | else |
||
384 | Enhancement_Layer_Bitstream_Filename = argv[++i]; |
||
385 | |||
386 | break; |
||
387 | |||
388 | |||
389 | case 'F': |
||
390 | Frame_Store_Flag = 1; |
||
391 | break; |
||
392 | |||
393 | case 'G': |
||
394 | Big_Picture_Flag = 1; |
||
395 | break; |
||
396 | |||
397 | |||
398 | case 'I': |
||
399 | #ifdef VERIFY |
||
400 | Stats_Flag = atoi(&argv[i][2]); |
||
401 | #else /* VERIFY */ |
||
402 | printf("WARNING: This program not compiled for -i option\n"); |
||
403 | #endif /* VERIFY */ |
||
404 | break; |
||
405 | |||
406 | case 'L': /* spatial scalability flag */ |
||
407 | Spatial_Flag = 1; |
||
408 | |||
409 | if(NextArg || LastArg) |
||
410 | { |
||
411 | printf("ERROR: -l must be followed by filename\n"); |
||
412 | exit(ERROR); |
||
413 | } |
||
414 | else |
||
415 | Lower_Layer_Picture_Filename = argv[++i]; |
||
416 | |||
417 | break; |
||
418 | |||
419 | case 'O': |
||
420 | |||
421 | Output_Type = atoi(&argv[i][2]); |
||
422 | |||
423 | if((Output_Type==4) || (Output_Type==5)) |
||
424 | Output_Picture_Filename = ""; /* no need of filename */ |
||
425 | else if(NextArg || LastArg) |
||
426 | { |
||
427 | printf("ERROR: -o must be followed by filename\n"); |
||
428 | exit(ERROR); |
||
429 | } |
||
430 | else |
||
431 | /* filename is separated by space, so it becomes the next argument */ |
||
432 | Output_Picture_Filename = argv[++i]; |
||
433 | |||
434 | #ifdef DISPLAY |
||
435 | if (Output_Type==T_X11HIQ) |
||
436 | { |
||
437 | hiQdither = 1; |
||
438 | Output_Type=T_X11; |
||
439 | } |
||
440 | #endif /* DISPLAY */ |
||
441 | break; |
||
442 | |||
443 | case 'Q': |
||
444 | Quiet_Flag = 1; |
||
445 | break; |
||
446 | |||
447 | case 'R': |
||
448 | Reference_IDCT_Flag = 1; |
||
449 | break; |
||
450 | |||
451 | case 'T': |
||
452 | #ifdef TRACE |
||
453 | Trace_Flag = 1; |
||
454 | #else /* TRACE */ |
||
455 | printf("WARNING: This program not compiled for -t option\n"); |
||
456 | #endif /* TRACE */ |
||
457 | break; |
||
458 | |||
459 | case 'U': |
||
460 | User_Data_Flag = 1; |
||
461 | |||
462 | case 'V': |
||
463 | #ifdef VERBOSE |
||
464 | Verbose_Flag = atoi(&argv[i][2]); |
||
465 | #else /* VERBOSE */ |
||
466 | printf("This program not compiled for -v option\n"); |
||
467 | #endif /* VERBOSE */ |
||
468 | break; |
||
469 | |||
470 | |||
471 | case 'X': |
||
472 | Ersatz_Flag = 1; |
||
473 | |||
474 | if(NextArg || LastArg) |
||
475 | { |
||
476 | printf("ERROR: -x must be followed by filename\n"); |
||
477 | exit(ERROR); |
||
478 | } |
||
479 | else |
||
480 | Substitute_Picture_Filename = argv[++i]; |
||
481 | |||
482 | break; |
||
483 | |||
484 | |||
485 | |||
486 | default: |
||
487 | fprintf(stderr,"undefined option -%c ignored. Exiting program\n", |
||
488 | argv[i][1]); |
||
489 | |||
490 | exit(ERROR); |
||
491 | |||
492 | } /* switch() */ |
||
493 | } /* if argv[i][0] == '-' */ |
||
494 | |||
495 | i++; |
||
496 | |||
497 | /* check for bitstream filename argument (there must always be one, at the very end |
||
498 | of the command line arguments */ |
||
499 | |||
500 | } /* while() */ |
||
501 | |||
502 | |||
503 | /* options sense checking */ |
||
504 | |||
505 | if(Main_Bitstream_Flag!=1) |
||
506 | { |
||
507 | printf("There must be a main bitstream specified (-b filename)\n"); |
||
508 | } |
||
509 | |||
510 | /* force display process to show frame pictures */ |
||
511 | if((Output_Type==4 || Output_Type==5) && Frame_Store_Flag) |
||
512 | Display_Progressive_Flag = 1; |
||
513 | else |
||
514 | Display_Progressive_Flag = 0; |
||
515 | |||
516 | #ifdef VERIFY |
||
517 | /* parse the bitstream, do not actually decode it completely */ |
||
518 | |||
519 | |||
520 | #if 0 |
||
521 | if(Output_Type==-1) |
||
522 | { |
||
523 | Decode_Layer = Verify_Flag; |
||
524 | printf("FYI: Decoding bitstream elements up to: %s\n", |
||
525 | Layer_Table[Decode_Layer]); |
||
526 | } |
||
527 | else |
||
528 | #endif |
||
529 | Decode_Layer = ALL_LAYERS; |
||
530 | |||
531 | #endif /* VERIFY */ |
||
532 | |||
533 | /* no output type specified */ |
||
534 | if(Output_Type==-1) |
||
535 | { |
||
536 | Output_Type = 9; |
||
537 | Output_Picture_Filename = ""; |
||
538 | } |
||
539 | |||
540 | |||
541 | #ifdef DISPLAY |
||
542 | if (Output_Type==T_X11) |
||
543 | { |
||
544 | if(Frame_Store_Flag) |
||
545 | Display_Progressive_Flag = 1; |
||
546 | else |
||
547 | Display_Progressive_Flag = 0; |
||
548 | |||
549 | Frame_Store_Flag = 1; /* to avoid calling dither() twice */ |
||
550 | } |
||
551 | #endif |
||
552 | |||
553 | |||
554 | } |
||
555 | |||
556 | |||
557 | #ifdef OLD |
||
558 | /* |
||
559 | this is an old routine used to convert command line arguments |
||
560 | into integers |
||
561 | */ |
||
562 | static int Get_Val(argv) |
||
563 | char *argv[]; |
||
564 | { |
||
565 | int val; |
||
566 | |||
567 | if (sscanf(argv[1]+2,"%d",&val)!=1) |
||
568 | return 0; |
||
569 | |||
570 | while (isdigit(argv[1][2])) |
||
571 | argv[1]++; |
||
572 | |||
573 | return val; |
||
574 | } |
||
575 | #endif |
||
576 | |||
577 | |||
578 | |||
579 | static int Headers() |
||
580 | { |
||
581 | int ret; |
||
582 | |||
583 | ld = &base; |
||
584 | |||
585 | |||
586 | /* return when end of sequence (0) or picture |
||
587 | header has been parsed (1) */ |
||
588 | |||
589 | ret = Get_Hdr(); |
||
590 | |||
591 | |||
592 | if (Two_Streams) |
||
593 | { |
||
594 | ld = &enhan; |
||
595 | if (Get_Hdr()!=ret && !Quiet_Flag) |
||
596 | fprintf(stderr,"streams out of sync\n"); |
||
597 | ld = &base; |
||
598 | } |
||
599 | |||
600 | return ret; |
||
601 | } |
||
602 | |||
603 | |||
604 | |||
605 | static int Decode_Bitstream() |
||
606 | { |
||
607 | int ret; |
||
608 | int Bitstream_Framenum; |
||
609 | |||
610 | Bitstream_Framenum = 0; |
||
611 | |||
612 | for(;;) |
||
613 | { |
||
614 | |||
615 | #ifdef VERIFY |
||
616 | Clear_Verify_Headers(); |
||
617 | #endif /* VERIFY */ |
||
618 | |||
619 | ret = Headers(); |
||
620 | |||
621 | if(ret==1) |
||
622 | { |
||
623 | ret = video_sequence(&Bitstream_Framenum); |
||
624 | } |
||
625 | else |
||
626 | return(ret); |
||
627 | } |
||
628 | |||
629 | } |
||
630 | |||
631 | |||
632 | static void Deinitialize_Sequence() |
||
633 | { |
||
634 | int i; |
||
635 | |||
636 | /* clear flags */ |
||
637 | base.MPEG2_Flag=0; |
||
638 | |||
639 | for(i=0;i<3;i++) |
||
640 | { |
||
641 | free(backward_reference_frame[i]); |
||
642 | free(forward_reference_frame[i]); |
||
643 | free(auxframe[i]); |
||
644 | |||
645 | if (base.scalable_mode==SC_SPAT) |
||
646 | { |
||
647 | free(llframe0[i]); |
||
648 | free(llframe1[i]); |
||
649 | } |
||
650 | } |
||
651 | |||
652 | if (base.scalable_mode==SC_SPAT) |
||
653 | free(lltmp); |
||
654 | |||
655 | #ifdef DISPLAY |
||
656 | if (Output_Type==T_X11) |
||
657 | Terminate_Display_Process(); |
||
658 | #endif |
||
659 | } |
||
660 | |||
661 | |||
662 | static int video_sequence(Bitstream_Framenumber) |
||
663 | int *Bitstream_Framenumber; |
||
664 | { |
||
665 | int Bitstream_Framenum; |
||
666 | int Sequence_Framenum; |
||
667 | int Return_Value; |
||
668 | |||
669 | Bitstream_Framenum = *Bitstream_Framenumber; |
||
670 | Sequence_Framenum=0; |
||
671 | |||
672 | Initialize_Sequence(); |
||
673 | |||
674 | /* decode picture whose header has already been parsed in |
||
675 | Decode_Bitstream() */ |
||
676 | |||
677 | |||
678 | Decode_Picture(Bitstream_Framenum, Sequence_Framenum); |
||
679 | |||
680 | /* update picture numbers */ |
||
681 | if (!Second_Field) |
||
682 | { |
||
683 | Bitstream_Framenum++; |
||
684 | Sequence_Framenum++; |
||
685 | } |
||
686 | |||
687 | /* loop through the rest of the pictures in the sequence */ |
||
688 | while ((Return_Value=Headers())) |
||
689 | { |
||
690 | Decode_Picture(Bitstream_Framenum, Sequence_Framenum); |
||
691 | |||
692 | if (!Second_Field) |
||
693 | { |
||
694 | Bitstream_Framenum++; |
||
695 | Sequence_Framenum++; |
||
696 | } |
||
697 | } |
||
698 | |||
699 | /* put last frame */ |
||
700 | if (Sequence_Framenum!=0) |
||
701 | { |
||
702 | Output_Last_Frame_of_Sequence(Bitstream_Framenum); |
||
703 | } |
||
704 | |||
705 | Deinitialize_Sequence(); |
||
706 | |||
707 | #ifdef VERIFY |
||
708 | Clear_Verify_Headers(); |
||
709 | #endif /* VERIFY */ |
||
710 | |||
711 | *Bitstream_Framenumber = Bitstream_Framenum; |
||
712 | return(Return_Value); |
||
713 | } |
||
714 | |||
715 | |||
716 | |||
717 | static void Clear_Options() |
||
718 | { |
||
719 | Verbose_Flag = 0; |
||
720 | Output_Type = 0; |
||
721 | Output_Picture_Filename = " "; |
||
722 | hiQdither = 0; |
||
723 | Output_Type = 0; |
||
724 | Frame_Store_Flag = 0; |
||
725 | Spatial_Flag = 0; |
||
726 | Lower_Layer_Picture_Filename = " "; |
||
727 | Reference_IDCT_Flag = 0; |
||
728 | Trace_Flag = 0; |
||
729 | Quiet_Flag = 0; |
||
730 | Ersatz_Flag = 0; |
||
731 | Substitute_Picture_Filename = " "; |
||
732 | Two_Streams = 0; |
||
733 | Enhancement_Layer_Bitstream_Filename = " "; |
||
734 | Big_Picture_Flag = 0; |
||
735 | Main_Bitstream_Flag = 0; |
||
736 | Main_Bitstream_Filename = " "; |
||
737 | Verify_Flag = 0; |
||
738 | Stats_Flag = 0; |
||
739 | User_Data_Flag = 0; |
||
740 | } |
||
741 | |||
742 | |||
743 | #ifdef DEBUG |
||
744 | static void Print_Options() |
||
745 | { |
||
746 | |||
747 | printf("Verbose_Flag = %d\n", Verbose_Flag); |
||
748 | printf("Output_Type = %d\n", Output_Type); |
||
749 | printf("Output_Picture_Filename = %s\n", Output_Picture_Filename); |
||
750 | printf("hiQdither = %d\n", hiQdither); |
||
751 | printf("Output_Type = %d\n", Output_Type); |
||
752 | printf("Frame_Store_Flag = %d\n", Frame_Store_Flag); |
||
753 | printf("Spatial_Flag = %d\n", Spatial_Flag); |
||
754 | printf("Lower_Layer_Picture_Filename = %s\n", Lower_Layer_Picture_Filename); |
||
755 | printf("Reference_IDCT_Flag = %d\n", Reference_IDCT_Flag); |
||
756 | printf("Trace_Flag = %d\n", Trace_Flag); |
||
757 | printf("Quiet_Flag = %d\n", Quiet_Flag); |
||
758 | printf("Ersatz_Flag = %d\n", Ersatz_Flag); |
||
759 | printf("Substitute_Picture_Filename = %s\n", Substitute_Picture_Filename); |
||
760 | printf("Two_Streams = %d\n", Two_Streams); |
||
761 | printf("Enhancement_Layer_Bitstream_Filename = %s\n", Enhancement_Layer_Bitstream_Filename); |
||
762 | printf("Big_Picture_Flag = %d\n", Big_Picture_Flag); |
||
763 | printf("Main_Bitstream_Flag = %d\n", Main_Bitstream_Flag); |
||
764 | printf("Main_Bitstream_Filename = %s\n", Main_Bitstream_Filename); |
||
765 | printf("Verify_Flag = %d\n", Verify_Flag); |
||
766 | printf("Stats_Flag = %d\n", Stats_Flag); |
||
767 | printf("User_Data_Flag = %d\n", User_Data_Flag); |
||
768 | |||
769 | } |
||
770 | #endif |