From: Anton Mitrofanov Date: Sat, 23 Apr 2016 19:45:44 +0000 (+0300) Subject: Fix corruption when using encoder_reconfig() with some parameters X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=928bd9d5def4f0ca5071ea176a11b816a01e6495;p=libx264 Fix corruption when using encoder_reconfig() with some parameters Changing parameters that affects SPS, like --ref for example, wasn't behaving correctly previously. Probably a regression in r2373. --- diff --git a/encoder/encoder.c b/encoder/encoder.c index 66f83575..b614198a 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -1144,6 +1144,7 @@ static int x264_validate_parameters( x264_t *h, int b_open ) if( h->param.analyse.i_subpel_refine >= 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) ) h->param.analyse.i_subpel_refine = 9; + if( b_open ) { const x264_level_t *l = x264_levels; if( h->param.i_level_idc < 0 ) @@ -1813,7 +1814,7 @@ int x264_encoder_reconfig_apply( x264_t *h, x264_param_t *param ) mbcmp_init( h ); if( !ret ) - x264_sps_init( h->sps, h->param.i_sps_id, &h->param ); + x264_sps_init_reconfigurable( h->sps, &h->param ); /* Supported reconfiguration options (1-pass only): * vbv-maxrate diff --git a/encoder/set.c b/encoder/set.c index 63560db9..778add72 100644 --- a/encoder/set.c +++ b/encoder/set.c @@ -184,20 +184,7 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param ) sps->b_mb_adaptive_frame_field = param->b_interlaced; sps->b_direct8x8_inference = 1; - sps->crop.i_left = param->crop_rect.i_left; - sps->crop.i_top = param->crop_rect.i_top; - sps->crop.i_right = param->crop_rect.i_right + sps->i_mb_width*16 - param->i_width; - sps->crop.i_bottom = (param->crop_rect.i_bottom + sps->i_mb_height*16 - param->i_height) >> !sps->b_frame_mbs_only; - sps->b_crop = sps->crop.i_left || sps->crop.i_top || - sps->crop.i_right || sps->crop.i_bottom; - - sps->vui.b_aspect_ratio_info_present = 0; - if( param->vui.i_sar_width > 0 && param->vui.i_sar_height > 0 ) - { - sps->vui.b_aspect_ratio_info_present = 1; - sps->vui.i_sar_width = param->vui.i_sar_width; - sps->vui.i_sar_height= param->vui.i_sar_height; - } + x264_sps_init_reconfigurable( sps, param ); sps->vui.b_overscan_info_present = param->vui.i_overscan > 0 && param->vui.i_overscan <= 2; if( sps->vui.b_overscan_info_present ) @@ -262,6 +249,24 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param ) } } +void x264_sps_init_reconfigurable( x264_sps_t *sps, x264_param_t *param ) +{ + sps->crop.i_left = param->crop_rect.i_left; + sps->crop.i_top = param->crop_rect.i_top; + sps->crop.i_right = param->crop_rect.i_right + sps->i_mb_width*16 - param->i_width; + sps->crop.i_bottom = (param->crop_rect.i_bottom + sps->i_mb_height*16 - param->i_height) >> !sps->b_frame_mbs_only; + sps->b_crop = sps->crop.i_left || sps->crop.i_top || + sps->crop.i_right || sps->crop.i_bottom; + + sps->vui.b_aspect_ratio_info_present = 0; + if( param->vui.i_sar_width > 0 && param->vui.i_sar_height > 0 ) + { + sps->vui.b_aspect_ratio_info_present = 1; + sps->vui.i_sar_width = param->vui.i_sar_width; + sps->vui.i_sar_height= param->vui.i_sar_height; + } +} + void x264_sps_write( bs_t *s, x264_sps_t *sps ) { bs_realign( s ); diff --git a/encoder/set.h b/encoder/set.h index 2202721e..bb210866 100644 --- a/encoder/set.h +++ b/encoder/set.h @@ -28,6 +28,7 @@ #define X264_ENCODER_SET_H void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param ); +void x264_sps_init_reconfigurable( x264_sps_t *sps, x264_param_t *param ); void x264_sps_write( bs_t *s, x264_sps_t *sps ); void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *sps ); void x264_pps_write( bs_t *s, x264_sps_t *sps, x264_pps_t *pps );