summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vp9/encoder/vp9_firstpass.c5
-rw-r--r--vp9/encoder/vp9_onyx_if.c64
-rw-r--r--vp9/encoder/vp9_ratectrl.c28
3 files changed, 48 insertions, 49 deletions
diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c
index 25f7dcb94..cf0f8054a 100644
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -911,6 +911,7 @@ int vp9_twopass_worst_quality(VP9_COMP *cpi, FIRSTPASS_STATS *fpstats,
const double section_err = fpstats->coded_error / fpstats->count;
const double err_per_mb = section_err / num_mbs;
+ const double speed_term = 1.0 + ((double)cpi->speed * 0.04);
if (section_target_bandwitdh <= 0)
return rc->worst_quality; // Highest value allowed
@@ -924,8 +925,8 @@ int vp9_twopass_worst_quality(VP9_COMP *cpi, FIRSTPASS_STATS *fpstats,
for (q = rc->best_quality; q < rc->worst_quality; ++q) {
const double err_correction_factor = calc_correction_factor(err_per_mb,
ERR_DIVISOR, 0.5, 0.90, q);
- const int bits_per_mb_at_this_q = vp9_rc_bits_per_mb(INTER_FRAME, q,
- err_correction_factor);
+ const int bits_per_mb_at_this_q =
+ vp9_rc_bits_per_mb(INTER_FRAME, q, (err_correction_factor * speed_term));
if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
break;
}
diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c
index 0af61cb23..1f83f6b76 100644
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -237,27 +237,27 @@ int vp9_compute_qdelta(const VP9_COMP *cpi, double qstart, double qtarget) {
// Computes a q delta (in "q index" terms) to get from a starting q value
// to a value that should equate to the given rate ratio.
-int vp9_compute_qdelta_by_rate(VP9_COMP *cpi, int base_q_index,
+int vp9_compute_qdelta_by_rate(VP9_COMP *cpi, int qindex,
double rate_target_ratio) {
+ const FRAME_TYPE frame_type = cpi->common.frame_type;
+ const RATE_CONTROL *const rc = &cpi->rc;
+ int target_index = rc->worst_quality;
int i;
- int target_index = cpi->rc.worst_quality;
// Look up the current projected bits per block for the base index
- const int base_bits_per_mb = vp9_rc_bits_per_mb(cpi->common.frame_type,
- base_q_index, 1.0);
+ const int base_bits_per_mb = vp9_rc_bits_per_mb(frame_type, qindex, 1.0);
// Find the target bits per mb based on the base value and given ratio.
const int target_bits_per_mb = (int)(rate_target_ratio * base_bits_per_mb);
// Convert the q target to an index
- for (i = cpi->rc.best_quality; i < cpi->rc.worst_quality; ++i) {
+ for (i = rc->best_quality; i < rc->worst_quality; ++i) {
target_index = i;
- if (vp9_rc_bits_per_mb(cpi->common.frame_type, i, 1.0) <=
- target_bits_per_mb )
+ if (vp9_rc_bits_per_mb(frame_type, i, 1.0) <= target_bits_per_mb )
break;
}
- return target_index - base_q_index;
+ return target_index - qindex;
}
static void configure_static_seg_features(VP9_COMP *cpi) {
@@ -829,6 +829,7 @@ static void init_config(struct VP9_COMP *cpi, VP9_CONFIG *oxcf) {
void vp9_change_config(struct VP9_COMP *cpi, const VP9_CONFIG *oxcf) {
VP9_COMMON *const cm = &cpi->common;
+ RATE_CONTROL *const rc = &cpi->rc;
if (cm->version != oxcf->version)
cm->version = oxcf->version;
@@ -881,7 +882,7 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9_CONFIG *oxcf) {
} else {
cpi->mb.e_mbd.itxm_add = vp9_idct4x4_add;
}
- cpi->rc.baseline_gf_interval = DEFAULT_GF_INTERVAL;
+ rc->baseline_gf_interval = DEFAULT_GF_INTERVAL;
cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
cpi->refresh_golden_frame = 0;
@@ -930,17 +931,15 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9_CONFIG *oxcf) {
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.
- cpi->rc.bits_off_target = MIN(cpi->rc.bits_off_target,
- cpi->oxcf.maximum_buffer_size);
- cpi->rc.buffer_level = MIN(cpi->rc.buffer_level,
- cpi->oxcf.maximum_buffer_size);
+ rc->bits_off_target = MIN(rc->bits_off_target, cpi->oxcf.maximum_buffer_size);
+ rc->buffer_level = MIN(rc->buffer_level, cpi->oxcf.maximum_buffer_size);
// Set up frame rate and related parameters rate control values.
vp9_new_framerate(cpi, cpi->oxcf.framerate);
// Set absolute upper and lower quality limits
- cpi->rc.worst_quality = cpi->oxcf.worst_allowed_q;
- cpi->rc.best_quality = cpi->oxcf.best_allowed_q;
+ rc->worst_quality = cpi->oxcf.worst_allowed_q;
+ rc->best_quality = cpi->oxcf.best_allowed_q;
// active values should only be modified if out of new range
@@ -983,7 +982,7 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9_CONFIG *oxcf) {
#else
cpi->alt_ref_source = NULL;
#endif
- cpi->rc.is_src_frame_alt_ref = 0;
+ rc->is_src_frame_alt_ref = 0;
#if 0
// Experimental RD Code
@@ -2989,8 +2988,9 @@ void adjust_frame_rate(VP9_COMP *cpi) {
int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
size_t *size, uint8_t *dest,
int64_t *time_stamp, int64_t *time_end, int flush) {
- VP9_COMMON *cm = &cpi->common;
- MACROBLOCKD *xd = &cpi->mb.e_mbd;
+ VP9_COMMON *const cm = &cpi->common;
+ MACROBLOCKD *const xd = &cpi->mb.e_mbd;
+ RATE_CONTROL *const rc = &cpi->rc;
struct vpx_usec_timer cmptimer;
YV12_BUFFER_CONFIG *force_src_buffer = NULL;
MV_REFERENCE_FRAME ref_frame;
@@ -3017,7 +3017,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
cpi->refresh_alt_ref_frame = 0;
// Should we code an alternate reference frame.
- if (cpi->oxcf.play_alternate && cpi->rc.source_alt_ref_pending) {
+ if (cpi->oxcf.play_alternate && rc->source_alt_ref_pending) {
int frames_to_arf;
#if CONFIG_MULTIPLE_ARF
@@ -3029,9 +3029,9 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
- cpi->next_frame_in_order;
else
#endif
- frames_to_arf = cpi->rc.frames_till_gf_update_due;
+ frames_to_arf = rc->frames_till_gf_update_due;
- assert(frames_to_arf <= cpi->rc.frames_to_key);
+ assert(frames_to_arf <= rc->frames_to_key);
if ((cpi->source = vp9_lookahead_peek(cpi->lookahead, frames_to_arf))) {
#if CONFIG_MULTIPLE_ARF
@@ -3043,7 +3043,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
if (cpi->oxcf.arnr_max_frames > 0) {
// Produce the filtered ARF frame.
// TODO(agrange) merge these two functions.
- vp9_configure_arnr_filter(cpi, frames_to_arf, cpi->rc.gfu_boost);
+ vp9_configure_arnr_filter(cpi, frames_to_arf, rc->gfu_boost);
vp9_temporal_filter_prepare(cpi, frames_to_arf);
vp9_extend_frame_borders(&cpi->alt_ref_buffer);
force_src_buffer = &cpi->alt_ref_buffer;
@@ -3053,14 +3053,14 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
cpi->refresh_alt_ref_frame = 1;
cpi->refresh_golden_frame = 0;
cpi->refresh_last_frame = 0;
- cpi->rc.is_src_frame_alt_ref = 0;
+ rc->is_src_frame_alt_ref = 0;
#if CONFIG_MULTIPLE_ARF
if (!cpi->multi_arf_enabled)
#endif
- cpi->rc.source_alt_ref_pending = 0;
+ rc->source_alt_ref_pending = 0;
} else {
- cpi->rc.source_alt_ref_pending = 0;
+ rc->source_alt_ref_pending = 0;
}
}
@@ -3081,19 +3081,19 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
#if CONFIG_MULTIPLE_ARF
// Is this frame the ARF overlay.
- cpi->rc.is_src_frame_alt_ref = 0;
+ rc->is_src_frame_alt_ref = 0;
for (i = 0; i < cpi->arf_buffered; ++i) {
if (cpi->source == cpi->alt_ref_source[i]) {
- cpi->rc.is_src_frame_alt_ref = 1;
+ rc->is_src_frame_alt_ref = 1;
cpi->refresh_golden_frame = 1;
break;
}
}
#else
- cpi->rc.is_src_frame_alt_ref = cpi->alt_ref_source
- && (cpi->source == cpi->alt_ref_source);
+ rc->is_src_frame_alt_ref = cpi->alt_ref_source &&
+ (cpi->source == cpi->alt_ref_source);
#endif
- if (cpi->rc.is_src_frame_alt_ref) {
+ if (rc->is_src_frame_alt_ref) {
// Current frame is an ARF overlay frame.
#if CONFIG_MULTIPLE_ARF
cpi->alt_ref_source[i] = NULL;
@@ -3125,8 +3125,8 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
*frame_flags = cpi->source->flags;
#if CONFIG_MULTIPLE_ARF
- if ((cm->frame_type != KEY_FRAME) && (cpi->pass == 2))
- cpi->rc.source_alt_ref_pending = is_next_frame_arf(cpi);
+ if (cm->frame_type != KEY_FRAME && cpi->pass == 2)
+ rc->source_alt_ref_pending = is_next_frame_arf(cpi);
#endif
} else {
*size = 0;
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c
index 3c8baad79..9ee58185c 100644
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -977,12 +977,9 @@ int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi,
q = rc_pick_q_and_bounds_two_pass(cpi, bottom_index, top_index);
}
- // JBB : This is realtime mode. In real time mode the first frame
- // should be larger. Q of 0 is disabled because we force tx size to be
+ // Q of 0 is disabled because we force tx size to be
// 16x16...
if (cpi->sf.use_nonrd_pick_mode) {
- if (cpi->common.current_video_frame == 0)
- q /= 3;
if (q == 0)
q++;
if (cpi->sf.partition_check == 1)
@@ -1013,7 +1010,7 @@ void vp9_rc_compute_frame_size_bounds(const VP9_COMP *cpi,
*frame_over_shoot_limit = this_frame_target * 9 / 8;
*frame_under_shoot_limit = this_frame_target * 7 / 8;
} else {
- // Stron overshoot limit for constrained quality
+ // Strong overshoot limit for constrained quality
if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) {
*frame_over_shoot_limit = this_frame_target * 11 / 8;
*frame_under_shoot_limit = this_frame_target * 2 / 8;
@@ -1191,15 +1188,15 @@ static int test_for_kf_one_pass(VP9_COMP *cpi) {
static int calc_pframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
static const int af_ratio = 10;
- const RATE_CONTROL *rc = &cpi->rc;
+ const RATE_CONTROL *const rc = &cpi->rc;
int target;
#if USE_ALTREF_FOR_ONE_PASS
target = (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) ?
- (rc->av_per_frame_bandwidth * cpi->rc.baseline_gf_interval * af_ratio) /
- (cpi->rc.baseline_gf_interval + af_ratio - 1) :
- (rc->av_per_frame_bandwidth * cpi->rc.baseline_gf_interval) /
- (cpi->rc.baseline_gf_interval + af_ratio - 1);
+ (rc->av_per_frame_bandwidth * rc->baseline_gf_interval * af_ratio) /
+ (rc->baseline_gf_interval + af_ratio - 1) :
+ (rc->av_per_frame_bandwidth * rc->baseline_gf_interval) /
+ (rc->baseline_gf_interval + af_ratio - 1);
#else
target = rc->av_per_frame_bandwidth;
#endif
@@ -1299,13 +1296,14 @@ static int calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
void vp9_rc_get_svc_params(VP9_COMP *cpi) {
VP9_COMMON *const cm = &cpi->common;
- int target = cpi->rc.av_per_frame_bandwidth;
+ RATE_CONTROL *const rc = &cpi->rc;
+ int target = rc->av_per_frame_bandwidth;
if ((cm->current_video_frame == 0) ||
(cm->frame_flags & FRAMEFLAGS_KEY) ||
- (cpi->oxcf.auto_key && (cpi->rc.frames_since_key %
+ (cpi->oxcf.auto_key && (rc->frames_since_key %
cpi->key_frame_frequency == 0))) {
cm->frame_type = KEY_FRAME;
- cpi->rc.source_alt_ref_active = 0;
+ rc->source_alt_ref_active = 0;
if (cpi->pass == 0 && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) {
target = calc_iframe_target_size_one_pass_cbr(cpi);
}
@@ -1316,8 +1314,8 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) {
}
}
vp9_rc_set_frame_target(cpi, target);
- cpi->rc.frames_till_gf_update_due = INT_MAX;
- cpi->rc.baseline_gf_interval = INT_MAX;
+ rc->frames_till_gf_update_due = INT_MAX;
+ rc->baseline_gf_interval = INT_MAX;
}
void vp9_rc_get_one_pass_cbr_params(VP9_COMP *cpi) {