[x264-devel] commit: Fix intra refresh to not exceed max recovery_frame_cnt ( Jason Garrett-Glaser )

git at videolan.org git at videolan.org
Sun Sep 19 03:19:54 CEST 2010


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Wed Sep 15 12:06:47 2010 -0700| [ae403c4684b68a112f2fa62d13dcfd0e8716c139] | committer: Jason Garrett-Glaser 

Fix intra refresh to not exceed max recovery_frame_cnt
The spec constrains recovery_frame_cnt to [0, MaxFrameNum-1].
So make MaxFrameNum bigger in the case of intra refresh.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=ae403c4684b68a112f2fa62d13dcfd0e8716c139
---

 encoder/encoder.c |    2 +-
 encoder/set.c     |   14 ++++++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 0439a3a..2fb1e0a 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -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 );
diff --git a/encoder/set.c b/encoder/set.c
index 3dee484..c0b0f8c 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -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;



More information about the x264-devel mailing list