From a35a495d8889b1265a558c06920b7e83c9cd1117 Mon Sep 17 00:00:00 2001 From: Fiona Glaser Date: Wed, 15 Sep 2010 12:06:47 -0700 Subject: [PATCH] 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. --- 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 d642a1c7..b0006f2e 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 3dee484d..c0b0f8c8 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; -- 2.40.0