From: Anton Mitrofanov Date: Wed, 4 May 2011 07:49:06 +0000 (+0400) Subject: Fix bugs with ratecontrol reconfiguration X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=9a40ee6a6d7354ed5f453908fc29d813d1886481;p=x264.git Fix bugs with ratecontrol reconfiguration Initialization of some parameters was missed or wasn't synchronized with other threads --- diff --git a/encoder/encoder.c b/encoder/encoder.c index 81ac7f68..29031bcf 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -1308,22 +1308,17 @@ int x264_encoder_reconfig( x264_t *h, x264_param_t *param ) if( h->param.rc.i_vbv_max_bitrate > 0 && h->param.rc.i_vbv_buffer_size > 0 && param->rc.i_vbv_max_bitrate > 0 && param->rc.i_vbv_buffer_size > 0 ) { + rc_reconfig |= h->param.rc.i_vbv_max_bitrate != param->rc.i_vbv_max_bitrate; + rc_reconfig |= h->param.rc.i_vbv_buffer_size != param->rc.i_vbv_buffer_size; + rc_reconfig |= h->param.rc.i_bitrate != param->rc.i_bitrate; COPY( rc.i_vbv_max_bitrate ); COPY( rc.i_vbv_buffer_size ); COPY( rc.i_bitrate ); - rc_reconfig = 1; } - if( h->param.rc.f_rf_constant != param->rc.f_rf_constant ) - { - COPY( rc.f_rf_constant ); - rc_reconfig = 1; - } - if( h->param.rc.f_rf_constant_max != param->rc.f_rf_constant_max ) - { - COPY( rc.f_rf_constant_max ); - rc_reconfig = 1; - } - + rc_reconfig |= h->param.rc.f_rf_constant != param->rc.f_rf_constant; + rc_reconfig |= h->param.rc.f_rf_constant_max != param->rc.f_rf_constant_max; + COPY( rc.f_rf_constant ); + COPY( rc.f_rf_constant_max ); #undef COPY mbcmp_init( h ); @@ -2264,6 +2259,7 @@ static void x264_thread_sync_context( x264_t *dst, x264_t *src ) memcpy( &dst->i_frame, &src->i_frame, offsetof(x264_t, mb.type) - offsetof(x264_t, i_frame) ); dst->param = src->param; dst->stat = src->stat; + dst->pixf = src->pixf; } static void x264_thread_sync_stat( x264_t *dst, x264_t *src ) diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index d28696f3..b8f73ea5 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -459,6 +459,11 @@ void x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init ) if( h->param.rc.i_vbv_max_bitrate > 0 && h->param.rc.i_vbv_buffer_size > 0 ) { + /* We don't support changing the ABR bitrate right now, + so if the stream starts as CBR, keep it CBR. */ + if( rc->b_vbv_min_rate ) + h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate; + if( h->param.rc.i_vbv_buffer_size < (int)(h->param.rc.i_vbv_max_bitrate / rc->fps) ) { h->param.rc.i_vbv_buffer_size = h->param.rc.i_vbv_max_bitrate / rc->fps; @@ -466,17 +471,10 @@ void x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init ) h->param.rc.i_vbv_buffer_size ); } - /* We don't support changing the ABR bitrate right now, - so if the stream starts as CBR, keep it CBR. */ - if( rc->b_vbv_min_rate ) - h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate; - int vbv_buffer_size = h->param.rc.i_vbv_buffer_size * 1000; int vbv_max_bitrate = h->param.rc.i_vbv_max_bitrate * 1000; /* Init HRD */ - h->sps->vui.hrd.i_bit_rate_unscaled = vbv_max_bitrate; - h->sps->vui.hrd.i_cpb_size_unscaled = vbv_buffer_size; if( h->param.i_nal_hrd && b_init ) { h->sps->vui.hrd.i_cpb_cnt = 1; @@ -521,7 +519,11 @@ void x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init ) x264_log( h, X264_LOG_WARNING, "VBV parameters cannot be changed when NAL HRD is in use\n" ); return; } + h->sps->vui.hrd.i_bit_rate_unscaled = vbv_max_bitrate; + h->sps->vui.hrd.i_cpb_size_unscaled = vbv_buffer_size; + if( rc->b_vbv_min_rate ) + rc->bitrate = h->param.rc.i_bitrate * 1000.; rc->buffer_rate = vbv_max_bitrate / rc->fps; rc->vbv_max_rate = vbv_max_bitrate; rc->buffer_size = vbv_buffer_size; @@ -2392,13 +2394,14 @@ void x264_thread_sync_ratecontrol( x264_t *cur, x264_t *prev, x264_t *next ) COPY(prev_zone); COPY(qpbuf_pos); /* these vars can be updated by x264_ratecontrol_init_reconfigurable */ - COPY(buffer_rate); + COPY(bitrate); COPY(buffer_size); + COPY(buffer_rate); + COPY(vbv_max_rate); COPY(single_frame_vbv); COPY(cbr_decay); - COPY(b_vbv_min_rate); COPY(rate_factor_constant); - COPY(bitrate); + COPY(rate_factor_max_increment); #undef COPY } if( cur != next )