@@ -301,20 +301,26 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
301301 }
302302 memcpy (sps -> data , gb -> buffer , sps -> data_size );
303303
304+ sps -> b_mars_flag = 1 ; // [PolyV] always active
305+
304306 // Re-add the removed stop bit (may be used by hwaccels).
305307 if (!(gb -> size_in_bits & 7 ) && sps -> data_size < sizeof (sps -> data ))
306308 sps -> data [sps -> data_size ++ ] = 0x80 ;
307309
308310 profile_idc = get_bits (gb , 8 );
311+
309312 constraint_set_flags |= get_bits1 (gb ) << 0 ; // constraint_set0_flag
310313 constraint_set_flags |= get_bits1 (gb ) << 1 ; // constraint_set1_flag
311314 constraint_set_flags |= get_bits1 (gb ) << 2 ; // constraint_set2_flag
312315 constraint_set_flags |= get_bits1 (gb ) << 3 ; // constraint_set3_flag
313- constraint_set_flags |= get_bits1 (gb ) << 4 ; // constraint_set4_flag
314- constraint_set_flags |= get_bits1 (gb ) << 5 ; // constraint_set5_flag
316+
317+ skip_bits (gb , 2 ); // [PolyV] ignore constraint_set4_flag and constraint_set5_flag
318+
319+ sps_id = get_ue_golomb_31 (gb ); // [PolyV] Moved
320+
315321 skip_bits (gb , 2 ); // reserved_zero_2bits
322+
316323 level_idc = get_bits (gb , 8 );
317- sps_id = get_ue_golomb_31 (gb );
318324
319325 if (sps_id >= MAX_SPS_COUNT ) {
320326 av_log (avctx , AV_LOG_ERROR , "sps_id %u out of range\n" , sps_id );
@@ -356,8 +362,8 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
356362 goto fail ;
357363 }
358364 }
359- sps -> bit_depth_luma = get_ue_golomb_31 (gb ) + 8 ;
360365 sps -> bit_depth_chroma = get_ue_golomb_31 (gb ) + 8 ;
366+ sps -> bit_depth_luma = get_ue_golomb_31 (gb ) + 8 ; // [PolyV] Moved
361367 if (sps -> bit_depth_chroma != sps -> bit_depth_luma ) {
362368 avpriv_request_sample (avctx ,
363369 "Different chroma and luma bit depth" );
@@ -369,7 +375,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
369375 sps -> bit_depth_luma , sps -> bit_depth_chroma );
370376 goto fail ;
371377 }
372- sps -> transform_bypass = get_bits1 (gb );
378+ sps -> transform_bypass = get_bits1 (gb ) != 1 ;
373379 ret = decode_scaling_matrices (gb , sps , NULL , 1 , get_bits1 (gb ),
374380 & sps -> scaling_matrix_present_mask ,
375381 sps -> scaling_matrix4 , sps -> scaling_matrix8 );
@@ -383,14 +389,13 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
383389 }
384390
385391 log2_max_frame_num_minus4 = get_ue_golomb_31 (gb );
386- if (log2_max_frame_num_minus4 < MIN_LOG2_MAX_FRAME_NUM - 4 ||
387- log2_max_frame_num_minus4 > MAX_LOG2_MAX_FRAME_NUM - 4 ) {
392+ if (log2_max_frame_num_minus4 - 4 > 12 ) {
388393 av_log (avctx , AV_LOG_ERROR ,
389394 "log2_max_frame_num_minus4 out of range (0-12): %d\n" ,
390395 log2_max_frame_num_minus4 );
391396 goto fail ;
392397 }
393- sps -> log2_max_frame_num = log2_max_frame_num_minus4 + 4 ;
398+ sps -> log2_max_frame_num = log2_max_frame_num_minus4 ; // [PolyV] Removed +4
394399
395400 sps -> poc_type = get_ue_golomb_31 (gb );
396401
@@ -436,19 +441,22 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
436441 goto fail ;
437442 }
438443
439- sps -> ref_frame_count = get_ue_golomb_31 (gb );
444+ sps -> ref_frame_count = get_ue_golomb_31 (gb ) + 4 ; // [PolyV] Added +4
440445 if (avctx -> codec_tag == MKTAG ('S' , 'M' , 'V' , '2' ))
441446 sps -> ref_frame_count = FFMAX (2 , sps -> ref_frame_count );
442447 if (sps -> ref_frame_count > H264_MAX_DPB_FRAMES ) {
443448 av_log (avctx , AV_LOG_ERROR ,
444449 "too many reference frames %d\n" , sps -> ref_frame_count );
445450 goto fail ;
446451 }
447- sps -> gaps_in_frame_num_allowed_flag = get_bits1 (gb );
448- sps -> mb_width = get_ue_golomb (gb ) + 1 ;
449- sps -> mb_height = get_ue_golomb (gb ) + 1 ;
450452
451- sps -> frame_mbs_only_flag = get_bits1 (gb );
453+ sps -> mb_height = get_ue_golomb (gb ) + 1 ; // [PolyV] Moved
454+ sps -> mb_width = get_ue_golomb (gb ); // [PolyV] Removed +1
455+
456+ sps -> direct_8x8_inference_flag = get_bits1 (gb ); // [PolyV] Moved
457+ sps -> gaps_in_frame_num_allowed_flag = get_bits1 (gb ) != 1 ; // [PolyV] Moved, inverted
458+
459+ sps -> frame_mbs_only_flag = get_bits1 (gb ) != 1 ; // [PolyV] Moved, inverted
452460
453461 if (sps -> mb_height >= INT_MAX / 2U ) {
454462 av_log (avctx , AV_LOG_ERROR , "height overflow\n" );
@@ -469,14 +477,12 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
469477 goto fail ;
470478 }
471479
472- sps -> direct_8x8_inference_flag = get_bits1 (gb );
473-
474480 sps -> crop = get_bits1 (gb );
475481 if (sps -> crop ) {
482+ unsigned int crop_top = get_ue_golomb (gb ); // [PolyV] Moved
483+ unsigned int crop_bottom = get_ue_golomb (gb ); // [PolyV] Moved
476484 unsigned int crop_left = get_ue_golomb (gb );
477485 unsigned int crop_right = get_ue_golomb (gb );
478- unsigned int crop_top = get_ue_golomb (gb );
479- unsigned int crop_bottom = get_ue_golomb (gb );
480486 int width = 16 * sps -> mb_width ;
481487 int height = 16 * sps -> mb_height ;
482488
@@ -750,8 +756,6 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct
750756 goto fail ;
751757 }
752758
753- pps -> cabac = get_bits1 (gb );
754- pps -> pic_order_present = get_bits1 (gb );
755759 pps -> slice_group_count = get_ue_golomb (gb ) + 1 ;
756760 if (pps -> slice_group_count > 1 ) {
757761 pps -> mb_slice_group_map_type = get_ue_golomb (gb );
@@ -767,10 +771,18 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct
767771 goto fail ;
768772 }
769773
774+ pps -> cabac = get_bits1 (gb ); // [PolyV] Moved
775+ pps -> pic_order_present = get_bits1 (gb ); // [PolyV] Moved
776+
770777 qp_bd_offset = 6 * (sps -> bit_depth_luma - 8 );
771778
772779 pps -> weighted_pred = get_bits1 (gb );
773780 pps -> weighted_bipred_idc = get_bits (gb , 2 );
781+
782+ pps -> deblocking_filter_parameters_present = get_bits1 (gb ); // [PolyV] Moved
783+ pps -> constrained_intra_pred = get_bits1 (gb ); // [PolyV] Moved
784+ pps -> redundant_pic_cnt_present = get_bits1 (gb ); // [PolyV] Moved
785+
774786 pps -> init_qp = get_se_golomb (gb ) + 26U + qp_bd_offset ;
775787 pps -> init_qs = get_se_golomb (gb ) + 26U + qp_bd_offset ;
776788 pps -> chroma_qp_index_offset [0 ] = get_se_golomb (gb );
@@ -779,9 +791,7 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct
779791 goto fail ;
780792 }
781793
782- pps -> deblocking_filter_parameters_present = get_bits1 (gb );
783- pps -> constrained_intra_pred = get_bits1 (gb );
784- pps -> redundant_pic_cnt_present = get_bits1 (gb );
794+ get_ue_golomb (gb ); // [PolyV] Random read
785795
786796 pps -> transform_8x8_mode = 0 ;
787797 memcpy (pps -> scaling_matrix4 , sps -> scaling_matrix4 ,
@@ -792,13 +802,21 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct
792802 bits_left = bit_length - get_bits_count (gb );
793803 if (bits_left > 0 && more_rbsp_data_in_pps (sps , avctx )) {
794804 pps -> transform_8x8_mode = get_bits1 (gb );
795- pps -> pic_scaling_matrix_present_flag = get_bits1 (gb );
805+ //pps->pic_scaling_matrix_present_flag = get_bits1(gb); // [PolyV] ignored
806+
807+ if (sps -> b_mars_flag == 1 ) // [PolyV] added
808+ get_bits (gb , 2 );
809+
796810 ret = decode_scaling_matrices (gb , sps , pps , 0 ,
797811 pps -> pic_scaling_matrix_present_flag ,
798812 & pps -> pic_scaling_matrix_present_mask ,
799813 pps -> scaling_matrix4 , pps -> scaling_matrix8 );
800814 if (ret < 0 )
801815 goto fail ;
816+
817+ if (sps -> b_mars_flag == 1 ) // [PolyV] added
818+ get_se_golomb (gb );
819+
802820 // second_chroma_qp_index_offset
803821 pps -> chroma_qp_index_offset [1 ] = get_se_golomb (gb );
804822 if (pps -> chroma_qp_index_offset [1 ] < -12 || pps -> chroma_qp_index_offset [1 ] > 12 ) {
0 commit comments