]> git.videolan.org Git - x264.git/commitdiff
Fix intra refresh to not exceed max recovery_frame_cnt
authorJason Garrett-Glaser <darkshikari@gmail.com>
Wed, 15 Sep 2010 19:06:47 +0000 (12:06 -0700)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Thu, 16 Sep 2010 10:38:01 +0000 (03:38 -0700)
The spec constrains recovery_frame_cnt to [0, MaxFrameNum-1].
So make MaxFrameNum bigger in the case of intra refresh.

encoder/encoder.c
encoder/set.c

index 0439a3a2bca780104893b40797d2221df06c3cb4..2fb1e0ac57d5eddcaf3ce87fec5127b15d2a9e69 100644 (file)
@@ -2617,7 +2617,7 @@ int     x264_encoder_encode( x264_t *h,
 
         if( h->fenc->i_type != X264_TYPE_IDR )
         {
-            int time_to_recovery = h->param.i_open_gop ? 0 : X264_MIN( h->mb.i_mb_width - 1, h->param.i_keyint_max ) + h->param.i_bframe;
+            int time_to_recovery = h->param.i_open_gop ? 0 : X264_MIN( h->mb.i_mb_width - 1, h->param.i_keyint_max ) + h->param.i_bframe - 1;
             x264_nal_start( h, NAL_SEI, NAL_PRIORITY_DISPOSABLE );
             x264_sei_recovery_point_write( h, &h->out.bs, time_to_recovery );
             x264_nal_end( h );
index 3dee484dfca1db123b22de5af349e3c4fb799a33..c0b0f8c87b54852ee2c23dbbda7243fc1d1adf4b 100644 (file)
@@ -99,7 +99,8 @@ static void x264_sei_write( bs_t *s, uint8_t *p_start )
 void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
 {
     sps->i_id = i_id;
-    int max_frame_num;
+    sps->i_mb_width = ( param->i_width + 15 ) / 16;
+    sps->i_mb_height= ( param->i_height + 15 ) / 16;
 
     sps->b_qpprime_y_zero_transform_bypass = param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant == 0;
     if( sps->b_qpprime_y_zero_transform_bypass )
@@ -140,7 +141,14 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
     sps->i_num_ref_frames -= param->i_bframe_pyramid == X264_B_PYRAMID_STRICT;
 
     /* number of refs + current frame */
-    max_frame_num = sps->vui.i_max_dec_frame_buffering * (!!param->i_bframe_pyramid+1) + 1;
+    int max_frame_num = sps->vui.i_max_dec_frame_buffering * (!!param->i_bframe_pyramid+1) + 1;
+    /* Intra refresh cannot write a recovery time greater than max frame num-1 */
+    if( param->b_intra_refresh )
+    {
+        int time_to_recovery = X264_MIN( sps->i_mb_width - 1, param->i_keyint_max ) + param->i_bframe - 1;
+        max_frame_num = X264_MAX( max_frame_num, time_to_recovery+1 );
+    }
+
     sps->i_log2_max_frame_num = 4;
     while( (1 << sps->i_log2_max_frame_num) <= max_frame_num )
         sps->i_log2_max_frame_num++;
@@ -172,8 +180,6 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
     sps->b_vui = 1;
 
     sps->b_gaps_in_frame_num_value_allowed = 0;
-    sps->i_mb_width = ( param->i_width + 15 ) / 16;
-    sps->i_mb_height= ( param->i_height + 15 ) / 16;
     sps->b_frame_mbs_only = !(param->b_interlaced || param->b_fake_interlaced);
     if( !sps->b_frame_mbs_only )
         sps->i_mb_height = ( sps->i_mb_height + 1 ) & ~1;