1 /* gethdr.c, header decoding */
3 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
6 * Disclaimer of Warranty
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.
16 * This disclaimer of warranty extends to the user of these programs and user's
17 * customers, employees, agents, transferees, successors, and assigns.
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
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
36 /* private prototypes */
37 static void sequence_header _ANSI_ARGS_((void));
38 static void group_of_pictures_header _ANSI_ARGS_((void));
39 static void picture_header _ANSI_ARGS_((void));
40 static void extension_and_user_data _ANSI_ARGS_((void));
41 static void sequence_extension _ANSI_ARGS_((void));
42 static void sequence_display_extension _ANSI_ARGS_((void));
43 static void quant_matrix_extension _ANSI_ARGS_((void));
44 static void sequence_scalable_extension _ANSI_ARGS_((void));
45 static void picture_display_extension _ANSI_ARGS_((void));
46 static void picture_coding_extension _ANSI_ARGS_((void));
47 static void picture_spatial_scalable_extension _ANSI_ARGS_((void));
48 static void picture_temporal_scalable_extension _ANSI_ARGS_((void));
49 static int extra_bit_information _ANSI_ARGS_((void));
50 static void copyright_extension _ANSI_ARGS_((void));
51 static void user_data _ANSI_ARGS_((void));
52 static void user_data _ANSI_ARGS_((void));
57 /* introduced in September 1995 to assist spatial scalable decoding */
58 static void Update_Temporal_Reference_Tacking_Data _ANSI_ARGS_((void));
59 /* private variables */
60 static int Temporal_Reference_Base = 0;
61 static int True_Framenum_max = -1;
62 static int Temporal_Reference_GOP_Reset = 0;
65 static double frame_rate_Table[16] =
68 ((23.0*1000.0)/1001.0),
71 ((30.0*1000.0)/1001.0),
74 ((60.0*1000.0)/1001.0),
87 * decode headers from one input stream
88 * until an End of Sequence or picture start code
97 /* look for next_start_code */
103 case SEQUENCE_HEADER_CODE:
106 case GROUP_START_CODE:
107 group_of_pictures_header();
109 case PICTURE_START_CODE:
113 case SEQUENCE_END_CODE:
118 fprintf(stderr,"Unexpected next_start_code %08x (ignored)\n",code);
125 /* align to start of next next_start_code */
127 void next_start_code()
130 Flush_Buffer(ld->Incnt&7);
131 while (Show_Bits(24)!=0x01L)
136 /* decode sequence header */
138 static void sequence_header()
146 horizontal_size = Get_Bits(12);
147 vertical_size = Get_Bits(12);
148 aspect_ratio_information = Get_Bits(4);
149 frame_rate_code = Get_Bits(4);
150 bit_rate_value = Get_Bits(18);
151 marker_bit("sequence_header()");
152 vbv_buffer_size = Get_Bits(10);
153 constrained_parameters_flag = Get_Bits(1);
155 if((ld->load_intra_quantizer_matrix = Get_Bits(1)))
158 ld->intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
163 ld->intra_quantizer_matrix[i] = default_intra_quantizer_matrix[i];
166 if((ld->load_non_intra_quantizer_matrix = Get_Bits(1)))
169 ld->non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
174 ld->non_intra_quantizer_matrix[i] = 16;
177 /* copy luminance to chrominance matrices */
180 ld->chroma_intra_quantizer_matrix[i] =
181 ld->intra_quantizer_matrix[i];
183 ld->chroma_non_intra_quantizer_matrix[i] =
184 ld->non_intra_quantizer_matrix[i];
188 if (Verbose_Flag > NO_LAYER)
190 printf("sequence header (byte %d)\n",(pos>>3)-4);
191 if (Verbose_Flag > SEQUENCE_LAYER)
193 printf(" horizontal_size=%d\n",horizontal_size);
194 printf(" vertical_size=%d\n",vertical_size);
195 printf(" aspect_ratio_information=%d\n",aspect_ratio_information);
196 printf(" frame_rate_code=%d",frame_rate_code);
197 printf(" bit_rate_value=%d\n",bit_rate_value);
198 printf(" vbv_buffer_size=%d\n",vbv_buffer_size);
199 printf(" constrained_parameters_flag=%d\n",constrained_parameters_flag);
200 printf(" load_intra_quantizer_matrix=%d\n",ld->load_intra_quantizer_matrix);
201 printf(" load_non_intra_quantizer_matrix=%d\n",ld->load_non_intra_quantizer_matrix);
207 verify_sequence_header++;
210 extension_and_user_data();
215 /* decode group of pictures header */
216 /* ISO/IEC 13818-2 section 6.2.2.6 */
217 static void group_of_pictures_header()
225 Temporal_Reference_Base = True_Framenum_max + 1; /* *CH* */
226 Temporal_Reference_GOP_Reset = 1;
228 drop_flag = Get_Bits(1);
230 minute = Get_Bits(6);
231 marker_bit("group_of_pictures_header()");
234 closed_gop = Get_Bits(1);
235 broken_link = Get_Bits(1);
238 if (Verbose_Flag > NO_LAYER)
240 printf("group of pictures (byte %d)\n",(pos>>3)-4);
241 if (Verbose_Flag > SEQUENCE_LAYER)
243 printf(" drop_flag=%d\n",drop_flag);
244 printf(" timecode %d:%02d:%02d:%02d\n",hour,minute,sec,frame);
245 printf(" closed_gop=%d\n",closed_gop);
246 printf(" broken_link=%d\n",broken_link);
252 verify_group_of_pictures_header++;
255 extension_and_user_data();
260 /* decode picture header */
262 /* ISO/IEC 13818-2 section 6.2.3 */
263 static void picture_header()
265 int Extra_Information_Byte_Count;
271 /* unless later overwritten by picture_spatial_scalable_extension() */
274 temporal_reference = Get_Bits(10);
275 picture_coding_type = Get_Bits(3);
276 vbv_delay = Get_Bits(16);
278 if (picture_coding_type==P_TYPE || picture_coding_type==B_TYPE)
280 full_pel_forward_vector = Get_Bits(1);
281 forward_f_code = Get_Bits(3);
283 if (picture_coding_type==B_TYPE)
285 full_pel_backward_vector = Get_Bits(1);
286 backward_f_code = Get_Bits(3);
290 if (Verbose_Flag>NO_LAYER)
292 printf("picture header (byte %d)\n",(pos>>3)-4);
293 if (Verbose_Flag>SEQUENCE_LAYER)
295 printf(" temporal_reference=%d\n",temporal_reference);
296 printf(" picture_coding_type=%d\n",picture_coding_type);
297 printf(" vbv_delay=%d\n",vbv_delay);
298 if (picture_coding_type==P_TYPE || picture_coding_type==B_TYPE)
300 printf(" full_pel_forward_vector=%d\n",full_pel_forward_vector);
301 printf(" forward_f_code =%d\n",forward_f_code);
303 if (picture_coding_type==B_TYPE)
305 printf(" full_pel_backward_vector=%d\n",full_pel_backward_vector);
306 printf(" backward_f_code =%d\n",backward_f_code);
313 verify_picture_header++;
316 Extra_Information_Byte_Count =
317 extra_bit_information();
318 (void)Extra_Information_Byte_Count;
320 extension_and_user_data();
322 /* update tracking information used to assist spatial scalability */
323 Update_Temporal_Reference_Tacking_Data();
326 /* decode slice header */
328 /* ISO/IEC 13818-2 section 6.2.4 */
331 int slice_vertical_position_extension;
332 int quantizer_scale_code;
333 int slice_picture_id_enable;
334 int slice_picture_id;
335 int extra_information_slice;
342 slice_vertical_position_extension =
343 (ld->MPEG2_Flag && vertical_size>2800) ? Get_Bits(3) : 0;
345 if (ld->scalable_mode==SC_DP)
346 ld->priority_breakpoint = Get_Bits(7);
348 quantizer_scale_code = Get_Bits(5);
349 ld->quantizer_scale =
350 ld->MPEG2_Flag ? (ld->q_scale_type ? Non_Linear_quantizer_scale[quantizer_scale_code] : quantizer_scale_code<<1) : quantizer_scale_code;
352 /* slice_id introduced in March 1995 as part of the video corridendum
353 (after the IS was drafted in November 1994) */
356 ld->intra_slice = Get_Bits(1);
358 slice_picture_id_enable = Get_Bits(1);
359 slice_picture_id = Get_Bits(6);
360 (void)slice_picture_id_enable;
361 (void)slice_picture_id;
363 extra_information_slice = extra_bit_information();
364 (void)extra_information_slice;
370 if (Verbose_Flag>PICTURE_LAYER)
372 printf("slice header (byte %d)\n",(pos>>3)-4);
373 if (Verbose_Flag>SLICE_LAYER)
375 if (ld->MPEG2_Flag && vertical_size>2800)
376 printf(" slice_vertical_position_extension=%d\n",slice_vertical_position_extension);
378 if (ld->scalable_mode==SC_DP)
379 printf(" priority_breakpoint=%d\n",ld->priority_breakpoint);
381 printf(" quantizer_scale_code=%d\n",quantizer_scale_code);
383 printf(" slice_picture_id_enable = %d\n", slice_picture_id_enable);
385 if(slice_picture_id_enable)
386 printf(" slice_picture_id = %d\n", slice_picture_id);
393 verify_slice_header++;
397 return slice_vertical_position_extension;
401 /* decode extension and user data */
402 /* ISO/IEC 13818-2 section 6.2.2.2 */
403 static void extension_and_user_data()
409 while ((code = Show_Bits(32))==EXTENSION_START_CODE || code==USER_DATA_START_CODE)
411 if (code==EXTENSION_START_CODE)
414 ext_ID = Get_Bits(4);
417 case SEQUENCE_EXTENSION_ID:
418 sequence_extension();
420 case SEQUENCE_DISPLAY_EXTENSION_ID:
421 sequence_display_extension();
423 case QUANT_MATRIX_EXTENSION_ID:
424 quant_matrix_extension();
426 case SEQUENCE_SCALABLE_EXTENSION_ID:
427 sequence_scalable_extension();
429 case PICTURE_DISPLAY_EXTENSION_ID:
430 picture_display_extension();
432 case PICTURE_CODING_EXTENSION_ID:
433 picture_coding_extension();
435 case PICTURE_SPATIAL_SCALABLE_EXTENSION_ID:
436 picture_spatial_scalable_extension();
438 case PICTURE_TEMPORAL_SCALABLE_EXTENSION_ID:
439 picture_temporal_scalable_extension();
441 case COPYRIGHT_EXTENSION_ID:
442 copyright_extension();
445 fprintf(stderr,"reserved extension start code ID %d\n",ext_ID);
453 if (Verbose_Flag>NO_LAYER)
454 printf("user data\n");
463 /* decode sequence extension */
465 /* ISO/IEC 13818-2 section 6.2.2.3 */
466 static void sequence_extension()
468 int horizontal_size_extension;
469 int vertical_size_extension;
470 int bit_rate_extension;
471 int vbv_buffer_size_extension;
475 /* derive bit position for trace */
481 ld->scalable_mode = SC_NONE; /* unless overwritten by sequence_scalable_extension() */
482 layer_id = 0; /* unless overwritten by sequence_scalable_extension() */
484 profile_and_level_indication = Get_Bits(8);
485 progressive_sequence = Get_Bits(1);
486 chroma_format = Get_Bits(2);
487 horizontal_size_extension = Get_Bits(2);
488 vertical_size_extension = Get_Bits(2);
489 bit_rate_extension = Get_Bits(12);
490 marker_bit("sequence_extension");
491 vbv_buffer_size_extension = Get_Bits(8);
492 low_delay = Get_Bits(1);
493 frame_rate_extension_n = Get_Bits(2);
494 frame_rate_extension_d = Get_Bits(5);
496 frame_rate = frame_rate_Table[frame_rate_code] *
497 ((frame_rate_extension_n+1)/(frame_rate_extension_d+1));
499 /* special case for 422 profile & level must be made */
500 if((profile_and_level_indication>>7) & 1)
501 { /* escape bit of profile_and_level_indication set */
503 /* 4:2:2 Profile @ Main Level */
504 if((profile_and_level_indication&15)==5)
506 profile = PROFILE_422;
512 profile = profile_and_level_indication >> 4; /* Profile is upper nibble */
513 level = profile_and_level_indication & 0xF; /* Level is lower nibble */
517 horizontal_size = (horizontal_size_extension<<12) | (horizontal_size&0x0fff);
518 vertical_size = (vertical_size_extension<<12) | (vertical_size&0x0fff);
521 /* ISO/IEC 13818-2 does not define bit_rate_value to be composed of
522 * both the original bit_rate_value parsed in sequence_header() and
523 * the optional bit_rate_extension in sequence_extension_header().
524 * However, we use it for bitstream verification purposes.
527 bit_rate_value += (bit_rate_extension << 18);
528 bit_rate = ((double) bit_rate_value) * 400.0;
529 vbv_buffer_size += (vbv_buffer_size_extension << 10);
532 if (Verbose_Flag>NO_LAYER)
534 printf("sequence extension (byte %d)\n",(pos>>3)-4);
536 if (Verbose_Flag>SEQUENCE_LAYER)
538 printf(" profile_and_level_indication=%d\n",profile_and_level_indication);
540 if (profile_and_level_indication<128)
542 printf(" profile=%d, level=%d\n",profile,level);
545 printf(" progressive_sequence=%d\n",progressive_sequence);
546 printf(" chroma_format=%d\n",chroma_format);
547 printf(" horizontal_size_extension=%d\n",horizontal_size_extension);
548 printf(" vertical_size_extension=%d\n",vertical_size_extension);
549 printf(" bit_rate_extension=%d\n",bit_rate_extension);
550 printf(" vbv_buffer_size_extension=%d\n",vbv_buffer_size_extension);
551 printf(" low_delay=%d\n",low_delay);
552 printf(" frame_rate_extension_n=%d\n",frame_rate_extension_n);
553 printf(" frame_rate_extension_d=%d\n",frame_rate_extension_d);
559 verify_sequence_extension++;
566 /* decode sequence display extension */
568 static void sequence_display_extension()
575 video_format = Get_Bits(3);
576 color_description = Get_Bits(1);
578 if (color_description)
580 color_primaries = Get_Bits(8);
581 transfer_characteristics = Get_Bits(8);
582 matrix_coefficients = Get_Bits(8);
585 display_horizontal_size = Get_Bits(14);
586 marker_bit("sequence_display_extension");
587 display_vertical_size = Get_Bits(14);
590 if (Verbose_Flag>NO_LAYER)
592 printf("sequence display extension (byte %d)\n",(pos>>3)-4);
593 if (Verbose_Flag>SEQUENCE_LAYER)
596 printf(" video_format=%d\n",video_format);
597 printf(" color_description=%d\n",color_description);
599 if (color_description)
601 printf(" color_primaries=%d\n",color_primaries);
602 printf(" transfer_characteristics=%d\n",transfer_characteristics);
603 printf(" matrix_coefficients=%d\n",matrix_coefficients);
605 printf(" display_horizontal_size=%d\n",display_horizontal_size);
606 printf(" display_vertical_size=%d\n",display_vertical_size);
612 verify_sequence_display_extension++;
618 /* decode quant matrix entension */
619 /* ISO/IEC 13818-2 section 6.2.3.2 */
620 static void quant_matrix_extension()
629 if((ld->load_intra_quantizer_matrix = Get_Bits(1)))
633 ld->chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]]
634 = ld->intra_quantizer_matrix[scan[ZIG_ZAG][i]]
639 if((ld->load_non_intra_quantizer_matrix = Get_Bits(1)))
643 ld->chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]]
644 = ld->non_intra_quantizer_matrix[scan[ZIG_ZAG][i]]
649 if((ld->load_chroma_intra_quantizer_matrix = Get_Bits(1)))
652 ld->chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
655 if((ld->load_chroma_non_intra_quantizer_matrix = Get_Bits(1)))
658 ld->chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
662 if (Verbose_Flag>NO_LAYER)
664 printf("quant matrix extension (byte %d)\n",(pos>>3)-4);
665 printf(" load_intra_quantizer_matrix=%d\n",
666 ld->load_intra_quantizer_matrix);
667 printf(" load_non_intra_quantizer_matrix=%d\n",
668 ld->load_non_intra_quantizer_matrix);
669 printf(" load_chroma_intra_quantizer_matrix=%d\n",
670 ld->load_chroma_intra_quantizer_matrix);
671 printf(" load_chroma_non_intra_quantizer_matrix=%d\n",
672 ld->load_chroma_non_intra_quantizer_matrix);
677 verify_quant_matrix_extension++;
683 /* decode sequence scalable extension */
684 /* ISO/IEC 13818-2 section 6.2.2.5 */
685 static void sequence_scalable_extension()
693 /* values (without the +1 offset) of scalable_mode are defined in
694 Table 6-10 of ISO/IEC 13818-2 */
695 ld->scalable_mode = Get_Bits(2) + 1; /* add 1 to make SC_DP != SC_NONE */
697 layer_id = Get_Bits(4);
699 if (ld->scalable_mode==SC_SPAT)
701 lower_layer_prediction_horizontal_size = Get_Bits(14);
702 marker_bit("sequence_scalable_extension()");
703 lower_layer_prediction_vertical_size = Get_Bits(14);
704 horizontal_subsampling_factor_m = Get_Bits(5);
705 horizontal_subsampling_factor_n = Get_Bits(5);
706 vertical_subsampling_factor_m = Get_Bits(5);
707 vertical_subsampling_factor_n = Get_Bits(5);
710 if (ld->scalable_mode==SC_TEMP)
711 Error("temporal scalability not implemented\n");
714 if (Verbose_Flag>NO_LAYER)
716 printf("sequence scalable extension (byte %d)\n",(pos>>3)-4);
717 if (Verbose_Flag>SEQUENCE_LAYER)
719 printf(" scalable_mode=%d\n",ld->scalable_mode-1);
720 printf(" layer_id=%d\n",layer_id);
721 if (ld->scalable_mode==SC_SPAT)
723 printf(" lower_layer_prediction_horiontal_size=%d\n",
724 lower_layer_prediction_horizontal_size);
725 printf(" lower_layer_prediction_vertical_size=%d\n",
726 lower_layer_prediction_vertical_size);
727 printf(" horizontal_subsampling_factor_m=%d\n",
728 horizontal_subsampling_factor_m);
729 printf(" horizontal_subsampling_factor_n=%d\n",
730 horizontal_subsampling_factor_n);
731 printf(" vertical_subsampling_factor_m=%d\n",
732 vertical_subsampling_factor_m);
733 printf(" vertical_subsampling_factor_n=%d\n",
734 vertical_subsampling_factor_n);
741 verify_sequence_scalable_extension++;
747 /* decode picture display extension */
748 /* ISO/IEC 13818-2 section 6.2.3.3. */
749 static void picture_display_extension()
752 int number_of_frame_center_offsets;
758 /* based on ISO/IEC 13818-2 section 6.3.12
759 (November 1994) Picture display extensions */
761 /* derive number_of_frame_center_offsets */
762 if(progressive_sequence)
764 if(repeat_first_field)
767 number_of_frame_center_offsets = 3;
769 number_of_frame_center_offsets = 2;
773 number_of_frame_center_offsets = 1;
778 if(picture_structure!=FRAME_PICTURE)
780 number_of_frame_center_offsets = 1;
784 if(repeat_first_field)
785 number_of_frame_center_offsets = 3;
787 number_of_frame_center_offsets = 2;
793 for (i=0; i<number_of_frame_center_offsets; i++)
795 frame_center_horizontal_offset[i] = Get_Bits(16);
796 marker_bit("picture_display_extension, first marker bit");
798 frame_center_vertical_offset[i] = Get_Bits(16);
799 marker_bit("picture_display_extension, second marker bit");
803 if (Verbose_Flag>NO_LAYER)
805 printf("picture display extension (byte %d)\n",(pos>>3)-4);
806 if (Verbose_Flag>SEQUENCE_LAYER)
809 for (i=0; i<number_of_frame_center_offsets; i++)
811 printf(" frame_center_horizontal_offset[%d]=%d\n",i,
812 frame_center_horizontal_offset[i]);
813 printf(" frame_center_vertical_offset[%d]=%d\n",i,
814 frame_center_vertical_offset[i]);
821 verify_picture_display_extension++;
827 /* decode picture coding extension */
828 static void picture_coding_extension()
836 f_code[0][0] = Get_Bits(4);
837 f_code[0][1] = Get_Bits(4);
838 f_code[1][0] = Get_Bits(4);
839 f_code[1][1] = Get_Bits(4);
841 intra_dc_precision = Get_Bits(2);
842 picture_structure = Get_Bits(2);
843 top_field_first = Get_Bits(1);
844 frame_pred_frame_dct = Get_Bits(1);
845 concealment_motion_vectors = Get_Bits(1);
846 ld->q_scale_type = Get_Bits(1);
847 intra_vlc_format = Get_Bits(1);
848 ld->alternate_scan = Get_Bits(1);
849 repeat_first_field = Get_Bits(1);
850 chroma_420_type = Get_Bits(1);
851 progressive_frame = Get_Bits(1);
852 composite_display_flag = Get_Bits(1);
854 if (composite_display_flag)
856 v_axis = Get_Bits(1);
857 field_sequence = Get_Bits(3);
858 sub_carrier = Get_Bits(1);
859 burst_amplitude = Get_Bits(7);
860 sub_carrier_phase = Get_Bits(8);
864 if (Verbose_Flag>NO_LAYER)
866 printf("picture coding extension (byte %d)\n",(pos>>3)-4);
867 if (Verbose_Flag>SEQUENCE_LAYER)
869 printf(" forward horizontal f_code=%d\n", f_code[0][0]);
870 printf(" forward vertical f_code=%d\n", f_code[0][1]);
871 printf(" backward horizontal f_code=%d\n", f_code[1][0]);
872 printf(" backward_vertical f_code=%d\n", f_code[1][1]);
873 printf(" intra_dc_precision=%d\n",intra_dc_precision);
874 printf(" picture_structure=%d\n",picture_structure);
875 printf(" top_field_first=%d\n",top_field_first);
876 printf(" frame_pred_frame_dct=%d\n",frame_pred_frame_dct);
877 printf(" concealment_motion_vectors=%d\n",concealment_motion_vectors);
878 printf(" q_scale_type=%d\n",ld->q_scale_type);
879 printf(" intra_vlc_format=%d\n",intra_vlc_format);
880 printf(" alternate_scan=%d\n",ld->alternate_scan);
881 printf(" repeat_first_field=%d\n",repeat_first_field);
882 printf(" chroma_420_type=%d\n",chroma_420_type);
883 printf(" progressive_frame=%d\n",progressive_frame);
884 printf(" composite_display_flag=%d\n",composite_display_flag);
886 if (composite_display_flag)
888 printf(" v_axis=%d\n",v_axis);
889 printf(" field_sequence=%d\n",field_sequence);
890 printf(" sub_carrier=%d\n",sub_carrier);
891 printf(" burst_amplitude=%d\n",burst_amplitude);
892 printf(" sub_carrier_phase=%d\n",sub_carrier_phase);
899 verify_picture_coding_extension++;
904 /* decode picture spatial scalable extension */
905 /* ISO/IEC 13818-2 section 6.2.3.5. */
906 static void picture_spatial_scalable_extension()
914 ld->pict_scal = 1; /* use spatial scalability in this picture */
916 lower_layer_temporal_reference = Get_Bits(10);
917 marker_bit("picture_spatial_scalable_extension(), first marker bit");
918 lower_layer_horizontal_offset = Get_Bits(15);
919 if (lower_layer_horizontal_offset>=16384)
920 lower_layer_horizontal_offset-= 32768;
921 marker_bit("picture_spatial_scalable_extension(), second marker bit");
922 lower_layer_vertical_offset = Get_Bits(15);
923 if (lower_layer_vertical_offset>=16384)
924 lower_layer_vertical_offset-= 32768;
925 spatial_temporal_weight_code_table_index = Get_Bits(2);
926 lower_layer_progressive_frame = Get_Bits(1);
927 lower_layer_deinterlaced_field_select = Get_Bits(1);
930 if (Verbose_Flag>NO_LAYER)
932 printf("picture spatial scalable extension (byte %d)\n",(pos>>3)-4);
933 if (Verbose_Flag>SEQUENCE_LAYER)
935 printf(" lower_layer_temporal_reference=%d\n",lower_layer_temporal_reference);
936 printf(" lower_layer_horizontal_offset=%d\n",lower_layer_horizontal_offset);
937 printf(" lower_layer_vertical_offset=%d\n",lower_layer_vertical_offset);
938 printf(" spatial_temporal_weight_code_table_index=%d\n",
939 spatial_temporal_weight_code_table_index);
940 printf(" lower_layer_progressive_frame=%d\n",lower_layer_progressive_frame);
941 printf(" lower_layer_deinterlaced_field_select=%d\n",lower_layer_deinterlaced_field_select);
947 verify_picture_spatial_scalable_extension++;
953 /* decode picture temporal scalable extension
957 /* ISO/IEC 13818-2 section 6.2.3.4. */
958 static void picture_temporal_scalable_extension()
960 Error("temporal scalability not supported\n");
963 verify_picture_temporal_scalable_extension++;
968 /* decode extra bit information */
969 /* ISO/IEC 13818-2 section 6.2.3.4. */
970 static int extra_bit_information()
985 /* ISO/IEC 13818-2 section 5.3 */
986 /* Purpose: this function is mainly designed to aid in bitstream conformance
987 testing. A simple Flush_Buffer(1) would do */
988 void marker_bit(text)
994 marker = Get_Bits(1);
999 printf("ERROR: %s--marker_bit set to 0",text);
1004 /* ISO/IEC 13818-2 sections 6.3.4.1 and 6.2.2.2.2 */
1005 static void user_data()
1007 /* skip ahead to the next start code */
1013 /* Copyright extension */
1014 /* ISO/IEC 13818-2 section 6.2.3.6. */
1015 /* (header added in November, 1994 to the IS document) */
1018 static void copyright_extension()
1025 #endif /* VERBOSE */
1028 copyright_flag = Get_Bits(1);
1029 copyright_identifier = Get_Bits(8);
1030 original_or_copy = Get_Bits(1);
1033 reserved_data = Get_Bits(7);
1034 (void)reserved_data;
1036 marker_bit("copyright_extension(), first marker bit");
1037 copyright_number_1 = Get_Bits(20);
1038 marker_bit("copyright_extension(), second marker bit");
1039 copyright_number_2 = Get_Bits(22);
1040 marker_bit("copyright_extension(), third marker bit");
1041 copyright_number_3 = Get_Bits(22);
1044 if(Verbose_Flag>NO_LAYER)
1046 printf("copyright_extension (byte %d)\n",(pos>>3)-4);
1047 if (Verbose_Flag>SEQUENCE_LAYER)
1049 printf(" copyright_flag =%d\n",copyright_flag);
1051 printf(" copyright_identifier=%d\n",copyright_identifier);
1053 printf(" original_or_copy = %d (original=1, copy=0)\n",
1056 printf(" copyright_number_1=%d\n",copyright_number_1);
1057 printf(" copyright_number_2=%d\n",copyright_number_2);
1058 printf(" copyright_number_3=%d\n",copyright_number_3);
1061 #endif /* VERBOSE */
1064 verify_copyright_extension++;
1070 /* introduced in September 1995 to assist Spatial Scalability */
1071 static void Update_Temporal_Reference_Tacking_Data()
1073 static int temporal_reference_wrap = 0;
1074 static int temporal_reference_old = 0;
1076 if (ld == &base) /* *CH* */
1078 if (picture_coding_type!=B_TYPE && temporal_reference!=temporal_reference_old)
1079 /* check first field of */
1082 if (temporal_reference_wrap)
1083 {/* wrap occured at previous I- or P-frame */
1084 /* now all intervening B-frames which could
1085 still have high temporal_reference values are done */
1086 Temporal_Reference_Base += 1024;
1087 temporal_reference_wrap = 0;
1090 /* distinguish from a reset */
1091 if (temporal_reference<temporal_reference_old && !Temporal_Reference_GOP_Reset)
1092 temporal_reference_wrap = 1; /* we must have just passed a GOP-Header! */
1094 temporal_reference_old = temporal_reference;
1095 Temporal_Reference_GOP_Reset = 0;
1098 True_Framenum = Temporal_Reference_Base + temporal_reference;
1100 /* temporary wrap of TR at 1024 for M frames */
1101 if (temporal_reference_wrap && temporal_reference <= temporal_reference_old)
1102 True_Framenum += 1024;
1104 True_Framenum_max = (True_Framenum > True_Framenum_max) ?
1105 True_Framenum : True_Framenum_max;