]> git.sesse.net Git - x264/commitdiff
Fix bugs with ratecontrol reconfiguration
authorAnton Mitrofanov <BugMaster@narod.ru>
Wed, 4 May 2011 07:49:06 +0000 (11:49 +0400)
committerFiona Glaser <fiona@x264.com>
Tue, 10 May 2011 09:40:52 +0000 (02:40 -0700)
Initialization of some parameters was missed or wasn't synchronized with other threads

encoder/encoder.c
encoder/ratecontrol.c

index fd1450400ca091192eb3071eaf9908cfabb65369..fc8add1a60d217dffcc4f321fd70dde25bf30257 100644 (file)
@@ -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 )
index 570fd49843a3d4cfa9a6329f3e16407abd34c840..7db995556dcc4cf00cd26d5fcfce0f815fca9153 100644 (file)
@@ -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 )