ref: eb15fe85e088ff7788a39cb0998ece58afd692c2
parent: 6dddcbc57d82c30a2833067f99325e6f051581ea
author: Adrian Grange <agrange@google.com>
date: Thu Nov 17 10:57:37 EST 2011
Clip buffer level to the maximum buffer size in CBR The buffer level was able to increase indefinitely rather than being clipped to the maximum buffer size specified by the user. This change checks the buffrer level and prevents it from going beyond the upper limit of the buffer. Change-Id: Ifff55f79d3c018e4d3d77e554b11ada543cc1654
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -3771,6 +3771,11 @@
{
cpi->decimation_count --;
cpi->bits_off_target += cpi->av_per_frame_bandwidth;
+
+ // Clip the buffer level at the maximum buffer size
+ 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++;
@@ -4613,6 +4618,10 @@
cpi->bits_off_target -= cpi->projected_frame_size;
else
cpi->bits_off_target += cpi->av_per_frame_bandwidth - cpi->projected_frame_size;
+
+ // Clip the buffer level at the maximum 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;
--- a/vp8/encoder/ratectrl.c
+++ b/vp8/encoder/ratectrl.c
@@ -1028,6 +1028,11 @@
{
// Update the buffer level variable.
cpi->bits_off_target += cpi->av_per_frame_bandwidth;
+
+ // Clip the buffer level at the maximum buffer size
+ 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