]> granicus.if.org Git - libvpx/commitdiff
Added clipping of the buffer level to maximum_buffer_size
authorAdrian Grange <agrange@google.com>
Wed, 16 Nov 2011 00:39:53 +0000 (16:39 -0800)
committerAdrian Grange <agrange@google.com>
Wed, 16 Nov 2011 00:39:53 +0000 (16:39 -0800)
The buffer level was not being capped at the maximum decode
buffer size specified by the user.

In CBR mode this resulted in large files being generated
immediately after a dramatic reduction in the data rate
target. This fix should prevent this from happening.

Change-Id: Iaf01c9fb037cf51515217a5834d6ee4fbb0cb853

vp8/encoder/onyx_if.c
vp8/encoder/ratectrl.c

index faa36d66a8cf2c513db0d1c83bfb91f749fc332f..bf155e250554f7f06c7c3d3ddadfefd51448be58 100644 (file)
@@ -3490,6 +3490,9 @@ static void encode_frame_to_data_rate
         {
             cpi->decimation_count --;
             cpi->bits_off_target += cpi->av_per_frame_bandwidth;
+            if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
+                cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
+
             cm->current_video_frame++;
             cpi->frames_since_key++;
 
@@ -4321,6 +4324,10 @@ static void encode_frame_to_data_rate
     else
         cpi->bits_off_target += cpi->av_per_frame_bandwidth - cpi->projected_frame_size;
 
+    // Clip the buffer level to the maximum specified buffer size
+    if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
+        cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
+
     // Rolling monitors of whether we are over or underspending used to help regulate min and Max Q in two pass.
     cpi->rolling_target_bits = ((cpi->rolling_target_bits * 3) + cpi->this_frame_target + 2) / 4;
     cpi->rolling_actual_bits = ((cpi->rolling_actual_bits * 3) + cpi->projected_frame_size + 2) / 4;
index f3dccfd055ad3fe2b7389f54aacc73141a7a2dad..a0a3db1c43dca43100205d16e813e9aeeddb5247 100644 (file)
@@ -1029,6 +1029,8 @@ static void calc_pframe_target_size(VP8_COMP *cpi)
         {
             // Update the buffer level variable.
             cpi->bits_off_target += cpi->av_per_frame_bandwidth;
+            if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
+                cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
             cpi->buffer_level = cpi->bits_off_target;
         }
         else