]> git.sesse.net Git - x264/commitdiff
Get rid of redundant speedcontrol variable fps, and clarify the units of some variables.
authorSteinar H. Gunderson <sesse@google.com>
Tue, 19 Apr 2016 22:37:55 +0000 (00:37 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 23 Apr 2016 18:32:32 +0000 (20:32 +0200)
Also fix a bug where the i_buffer_size parameter to x264_speedcontrol_sync()
would get ignored, and not update the dependent parameters properly.

AUTHORS
encoder/speed.c

diff --git a/AUTHORS b/AUTHORS
index d14deb881dfd102b6e4441572c711977075a1f5f..d5d8a142775877d3369f5e70d8bac2c3143d8733 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -97,3 +97,6 @@ N: Radek Czyz
 E: radoslaw AT syskin DOT cjb DOT net
 D: Cached motion compensation
 
+N: Google Inc
+E: opensource AT google DOT com
+D: speedcontrol bug fixes
index faade8e686dd2b1107d390aaf7607d08bf38a728..df8e2d8a607bbc10cc464a648f17b01cef30421f 100644 (file)
@@ -9,10 +9,10 @@ struct x264_speedcontrol_t
     // all times are in usec
     int64_t timestamp;   // when was speedcontrol last invoked
     int64_t cpu_time;    // time spent encoding the previous frame
-    int64_t buffer_size; // assumed application-side buffer of frames to be streamed,
+    int64_t buffer_size; // assumed application-side buffer of frames to be streamed (measured in microseconds),
     int64_t buffer_fill; //   where full = we don't have to hurry
     int64_t compensation_period; // how quickly we try to return to the target buffer fullness
-    float fps, spf;
+    float uspf;          // microseconds per frame
     int preset;          // which setting was used in the previous frame
     int prev_frame;
     float cplx_num;      // rolling average of estimated spf for preset #0
@@ -39,12 +39,12 @@ void x264_speedcontrol_new( x264_t *h )
 
     if( h->param.sc.f_speed <= 0 )
         h->param.sc.f_speed = 1;
-    sc->fps = h->param.i_fps_num / h->param.i_fps_den;
-    sc->spf = 1e6 / sc->fps;
+    float fps = h->param.i_fps_num / h->param.i_fps_den;
+    sc->uspf = 1e6 / fps;
     h->param.sc.i_buffer_size = X264_MAX( 3, h->param.sc.i_buffer_size );
-    sc->buffer_size = h->param.sc.i_buffer_size * 1e6 / sc->fps;
+    sc->buffer_size = h->param.sc.i_buffer_size * sc->uspf;
     sc->buffer_fill = sc->buffer_size * h->param.sc.f_buffer_init;
-    sc->buffer_fill = x264_clip3( sc->buffer_fill, sc->spf, sc->buffer_size );
+    sc->buffer_fill = x264_clip3( sc->buffer_fill, sc->uspf, sc->buffer_size );
     sc->compensation_period = sc->buffer_size/4;
     sc->timestamp = x264_mdate();
     sc->preset = -1;
@@ -170,7 +170,7 @@ void x264_speedcontrol_frame( x264_t *h )
 
     delta_f = h->i_frame - sc->prev_frame;
     delta_t = t - sc->timestamp;
-    delta_buffer = delta_f * sc->spf / h->param.sc.f_speed - delta_t;
+    delta_buffer = delta_f * sc->uspf / h->param.sc.f_speed - delta_t;
     if( !sc->buffer_complete )
         sc->buffer_fill += delta_buffer;
     sc->prev_frame = h->i_frame;
@@ -216,7 +216,7 @@ void x264_speedcontrol_frame( x264_t *h )
     {
         // pick the preset that should return the buffer to 3/4-full within a time
         // specified by compensation_period
-        float target = sc->spf / h->param.sc.f_speed
+        float target = sc->uspf / h->param.sc.f_speed
                      * (sc->buffer_fill + sc->compensation_period)
                      / (sc->buffer_size*3/4 + sc->compensation_period);
         float cplx = sc->cplx_num / sc->cplx_den;
@@ -262,8 +262,10 @@ void x264_speedcontrol_sync( x264_t *h, float f_buffer_fill, int i_buffer_size,
     if( !h->param.sc.i_buffer_size )
         return;
     if( i_buffer_size )
-        h->param.sc.i_buffer_size = X264_MAX( 3, h->param.sc.i_buffer_size );
-    sc->buffer_size = h->param.sc.i_buffer_size * 1e6 / sc->fps;
+        h->param.sc.i_buffer_size = X264_MAX( 3, i_buffer_size );
+    sc->buffer_size = h->param.sc.i_buffer_size * sc->uspf;
+    sc->cplx_decay = 1 - 1./h->param.sc.i_buffer_size;
+    sc->compensation_period = sc->buffer_size/4;
     sc->buffer_fill = sc->buffer_size * f_buffer_fill;
     sc->buffer_complete = !!buffer_complete;
 }