Commit 87ee0961 authored by Dmitry Kovalev's avatar Dmitry Kovalev

Adding set_rc_buffer_sizes().

Change-Id: I76aab1e4f56a790597104b5c9b0d3543d6982eae
parent 86533dc7
......@@ -541,6 +541,20 @@ static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) {
set_tile_limits(cpi);
}
static void set_rc_buffer_sizes(RATE_CONTROL *rc,
const VP9EncoderConfig *oxcf) {
const int64_t bandwidth = oxcf->target_bandwidth;
const int64_t starting = oxcf->starting_buffer_level_ms;
const int64_t optimal = oxcf->optimal_buffer_level_ms;
const int64_t maximum = oxcf->maximum_buffer_size_ms;
rc->starting_buffer_level = starting * bandwidth / 1000;
rc->optimal_buffer_level = (optimal == 0) ? bandwidth / 8
: optimal * bandwidth / 1000;
rc->maximum_buffer_size = (maximum == 0) ? bandwidth / 8
: maximum * bandwidth / 1000;
}
void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
VP9_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
......@@ -574,28 +588,8 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
}
cpi->encode_breakout = cpi->oxcf.encode_breakout;
// local file playback mode == really big buffer
if (cpi->oxcf.rc_mode == VPX_VBR) {
cpi->oxcf.starting_buffer_level_ms = 60000;
cpi->oxcf.optimal_buffer_level_ms = 60000;
cpi->oxcf.maximum_buffer_size_ms = 240000;
}
rc->starting_buffer_level = cpi->oxcf.starting_buffer_level_ms *
cpi->oxcf.target_bandwidth / 1000;
// Set or reset optimal and maximum buffer levels.
if (cpi->oxcf.optimal_buffer_level_ms == 0)
rc->optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
else
rc->optimal_buffer_level = cpi->oxcf.optimal_buffer_level_ms *
cpi->oxcf.target_bandwidth / 1000;
set_rc_buffer_sizes(rc, &cpi->oxcf);
if (cpi->oxcf.maximum_buffer_size_ms == 0)
rc->maximum_buffer_size = cpi->oxcf.target_bandwidth / 8;
else
rc->maximum_buffer_size = cpi->oxcf.maximum_buffer_size_ms *
cpi->oxcf.target_bandwidth / 1000;
// Under a configuration change, where maximum_buffer_size may change,
// keep buffer level clipped to the maximum allowed buffer size.
rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size);
......
......@@ -325,6 +325,7 @@ static vpx_codec_err_t set_encoder_config(
VP9EncoderConfig *oxcf,
const vpx_codec_enc_cfg_t *cfg,
const struct vp9_extracfg *extra_cfg) {
const int is_vbr = cfg->rc_end_usage == VPX_VBR;
oxcf->profile = cfg->g_profile;
oxcf->width = cfg->g_w;
oxcf->height = cfg->g_h;
......@@ -371,9 +372,9 @@ static vpx_codec_err_t set_encoder_config(
oxcf->scaled_frame_width = cfg->rc_scaled_width;
oxcf->scaled_frame_height = cfg->rc_scaled_height;
oxcf->maximum_buffer_size_ms = cfg->rc_buf_sz;
oxcf->starting_buffer_level_ms = cfg->rc_buf_initial_sz;
oxcf->optimal_buffer_level_ms = cfg->rc_buf_optimal_sz;
oxcf->maximum_buffer_size_ms = is_vbr ? 240000 : cfg->rc_buf_sz;
oxcf->starting_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_initial_sz;
oxcf->optimal_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_optimal_sz;
oxcf->drop_frames_water_mark = cfg->rc_dropframe_thresh;
......
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