Commit eb15fe85 authored by Adrian Grange's avatar Adrian Grange
Browse files

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
parent 6dddcbc5
...@@ -3771,6 +3771,11 @@ static void encode_frame_to_data_rate ...@@ -3771,6 +3771,11 @@ static void encode_frame_to_data_rate
{ {
cpi->decimation_count --; cpi->decimation_count --;
cpi->bits_off_target += cpi->av_per_frame_bandwidth; 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++; cm->current_video_frame++;
cpi->frames_since_key++; cpi->frames_since_key++;
...@@ -4614,6 +4619,10 @@ static void encode_frame_to_data_rate ...@@ -4614,6 +4619,10 @@ static void encode_frame_to_data_rate
else else
cpi->bits_off_target += cpi->av_per_frame_bandwidth - cpi->projected_frame_size; 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. // 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_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; cpi->rolling_actual_bits = ((cpi->rolling_actual_bits * 3) + cpi->projected_frame_size + 2) / 4;
......
...@@ -1028,6 +1028,11 @@ static void calc_pframe_target_size(VP8_COMP *cpi) ...@@ -1028,6 +1028,11 @@ static void calc_pframe_target_size(VP8_COMP *cpi)
{ {
// Update the buffer level variable. // Update the buffer level variable.
cpi->bits_off_target += cpi->av_per_frame_bandwidth; 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; cpi->buffer_level = cpi->bits_off_target;
} }
else else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment