guard against space/time distortion
authorJohann <johannkoenig@google.com>
Wed, 29 Jun 2011 18:34:25 +0000 (14:34 -0400)
committerJohann <johannkoenig@google.com>
Wed, 29 Jun 2011 18:34:25 +0000 (14:34 -0400)
and divide by 0 errors

Change-Id: I8af5ca3d0913cb6f278fff754f8772bcb62e674a

vpxenc.c

index 26afcd6..775a22b 100644 (file)
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -1342,6 +1342,8 @@ static void update_rate_histogram(struct rate_hist          *hist,
     if(now < cfg->rc_buf_initial_sz)
         return;
 
+    then = now;
+
     /* Sum the size over the past rc_buf_sz ms */
     for(i = hist->frames; i > 0; i--)
     {
@@ -1353,6 +1355,9 @@ static void update_rate_histogram(struct rate_hist          *hist,
         sum_sz += hist->sz[i_idx];
     }
 
+    if (now == then)
+        return;
+
     avg_bitrate = sum_sz * 8 * 1000 / (now - then);
     idx = avg_bitrate * (RATE_BINS/2) / (cfg->rc_target_bitrate * 1000);
     if(idx < 0)