Commit 8e7ebacb authored by John Koleszar's avatar John Koleszar

increase rate control buffer level precision

The external API exposes the RC initial/optimal/full buffer level in
milliseconds, but this value was truncated internally to seconds. This
patch allows the use of the full precision during the conversion from
time to bits.

Change-Id: If8dd2a87614c05747f81432cbe75dd9e6ed2f04e
parent b0660457
...@@ -1326,6 +1326,18 @@ void vp8_new_frame_rate(VP8_COMP *cpi, double framerate) ...@@ -1326,6 +1326,18 @@ void vp8_new_frame_rate(VP8_COMP *cpi, double framerate)
} }
} }
static int
rescale(int val, int num, int denom)
{
int64_t llnum = num;
int64_t llden = denom;
int64_t llval = val;
return llval * llnum / llden;
}
void vp8_init_config(VP8_PTR ptr, VP8_CONFIG *oxcf) void vp8_init_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
{ {
VP8_COMP *cpi = (VP8_COMP *)(ptr); VP8_COMP *cpi = (VP8_COMP *)(ptr);
...@@ -1353,9 +1365,9 @@ void vp8_init_config(VP8_PTR ptr, VP8_CONFIG *oxcf) ...@@ -1353,9 +1365,9 @@ void vp8_init_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
cpi->oxcf.worst_allowed_q = MAXQ; cpi->oxcf.worst_allowed_q = MAXQ;
cpi->oxcf.end_usage = USAGE_STREAM_FROM_SERVER; cpi->oxcf.end_usage = USAGE_STREAM_FROM_SERVER;
cpi->oxcf.starting_buffer_level = 4; cpi->oxcf.starting_buffer_level = 4000;
cpi->oxcf.optimal_buffer_level = 5; cpi->oxcf.optimal_buffer_level = 5000;
cpi->oxcf.maximum_buffer_size = 6; cpi->oxcf.maximum_buffer_size = 6000;
cpi->oxcf.under_shoot_pct = 90; cpi->oxcf.under_shoot_pct = 90;
cpi->oxcf.allow_df = 0; cpi->oxcf.allow_df = 0;
cpi->oxcf.drop_frames_water_mark = 20; cpi->oxcf.drop_frames_water_mark = 20;
...@@ -1504,26 +1516,32 @@ void vp8_init_config(VP8_PTR ptr, VP8_CONFIG *oxcf) ...@@ -1504,26 +1516,32 @@ void vp8_init_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
// local file playback mode == really big buffer // local file playback mode == really big buffer
if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK) if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK)
{ {
cpi->oxcf.starting_buffer_level = 60; cpi->oxcf.starting_buffer_level = 60000;
cpi->oxcf.optimal_buffer_level = 60; cpi->oxcf.optimal_buffer_level = 60000;
cpi->oxcf.maximum_buffer_size = 240; cpi->oxcf.maximum_buffer_size = 240000;
} }
// Convert target bandwidth from Kbit/s to Bit/s // Convert target bandwidth from Kbit/s to Bit/s
cpi->oxcf.target_bandwidth *= 1000; cpi->oxcf.target_bandwidth *= 1000;
cpi->oxcf.starting_buffer_level *= cpi->oxcf.target_bandwidth; cpi->oxcf.starting_buffer_level =
rescale(cpi->oxcf.starting_buffer_level,
cpi->oxcf.target_bandwidth, 1000);
if (cpi->oxcf.optimal_buffer_level == 0) if (cpi->oxcf.optimal_buffer_level == 0)
cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
else else
cpi->oxcf.optimal_buffer_level *= cpi->oxcf.target_bandwidth; cpi->oxcf.optimal_buffer_level =
rescale(cpi->oxcf.optimal_buffer_level,
cpi->oxcf.target_bandwidth, 1000);
if (cpi->oxcf.maximum_buffer_size == 0) if (cpi->oxcf.maximum_buffer_size == 0)
cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8;
else else
cpi->oxcf.maximum_buffer_size *= cpi->oxcf.target_bandwidth; cpi->oxcf.maximum_buffer_size =
rescale(cpi->oxcf.maximum_buffer_size,
cpi->oxcf.target_bandwidth, 1000);
cpi->buffer_level = cpi->oxcf.starting_buffer_level; cpi->buffer_level = cpi->oxcf.starting_buffer_level;
cpi->bits_off_target = cpi->oxcf.starting_buffer_level; cpi->bits_off_target = cpi->oxcf.starting_buffer_level;
...@@ -1783,26 +1801,32 @@ void vp8_change_config(VP8_PTR ptr, VP8_CONFIG *oxcf) ...@@ -1783,26 +1801,32 @@ void vp8_change_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
// local file playback mode == really big buffer // local file playback mode == really big buffer
if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK) if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK)
{ {
cpi->oxcf.starting_buffer_level = 60; cpi->oxcf.starting_buffer_level = 60000;
cpi->oxcf.optimal_buffer_level = 60; cpi->oxcf.optimal_buffer_level = 60000;
cpi->oxcf.maximum_buffer_size = 240; cpi->oxcf.maximum_buffer_size = 240000;
} }
// Convert target bandwidth from Kbit/s to Bit/s // Convert target bandwidth from Kbit/s to Bit/s
cpi->oxcf.target_bandwidth *= 1000; cpi->oxcf.target_bandwidth *= 1000;
cpi->oxcf.starting_buffer_level *= cpi->oxcf.target_bandwidth; cpi->oxcf.starting_buffer_level =
rescale(cpi->oxcf.starting_buffer_level,
cpi->oxcf.target_bandwidth, 1000);
if (cpi->oxcf.optimal_buffer_level == 0) if (cpi->oxcf.optimal_buffer_level == 0)
cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
else else
cpi->oxcf.optimal_buffer_level *= cpi->oxcf.target_bandwidth; cpi->oxcf.optimal_buffer_level =
rescale(cpi->oxcf.optimal_buffer_level,
cpi->oxcf.target_bandwidth, 1000);
if (cpi->oxcf.maximum_buffer_size == 0) if (cpi->oxcf.maximum_buffer_size == 0)
cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8;
else else
cpi->oxcf.maximum_buffer_size *= cpi->oxcf.target_bandwidth; cpi->oxcf.maximum_buffer_size =
rescale(cpi->oxcf.maximum_buffer_size,
cpi->oxcf.target_bandwidth, 1000);
cpi->buffer_level = cpi->oxcf.starting_buffer_level; cpi->buffer_level = cpi->oxcf.starting_buffer_level;
cpi->bits_off_target = cpi->oxcf.starting_buffer_level; cpi->bits_off_target = cpi->oxcf.starting_buffer_level;
......
...@@ -296,9 +296,9 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf, ...@@ -296,9 +296,9 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf,
oxcf->under_shoot_pct = cfg.rc_undershoot_pct; oxcf->under_shoot_pct = cfg.rc_undershoot_pct;
//oxcf->over_shoot_pct = cfg.rc_overshoot_pct; //oxcf->over_shoot_pct = cfg.rc_overshoot_pct;
oxcf->maximum_buffer_size = cfg.rc_buf_sz / 1000; oxcf->maximum_buffer_size = cfg.rc_buf_sz;
oxcf->starting_buffer_level = cfg.rc_buf_initial_sz / 1000; oxcf->starting_buffer_level = cfg.rc_buf_initial_sz;
oxcf->optimal_buffer_level = cfg.rc_buf_optimal_sz / 1000; oxcf->optimal_buffer_level = cfg.rc_buf_optimal_sz;
oxcf->two_pass_vbrbias = cfg.rc_2pass_vbr_bias_pct; oxcf->two_pass_vbrbias = cfg.rc_2pass_vbr_bias_pct;
oxcf->two_pass_vbrmin_section = cfg.rc_2pass_vbr_minsection_pct; oxcf->two_pass_vbrmin_section = cfg.rc_2pass_vbr_minsection_pct;
......
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