summaryrefslogtreecommitdiff
path: root/vp9/encoder/vp9_ratectrl.c
diff options
context:
space:
mode:
authorclang-format <noreply@google.com>2016-07-26 20:43:23 -0700
committerJames Zern <jzern@google.com>2016-08-02 16:47:11 -0700
commite0cc52db3fc9b09c99d7bbee35153cf82964a860 (patch)
tree4988f1d3a21056339e2ffbd7a3b3d52fab54cb6b /vp9/encoder/vp9_ratectrl.c
parent3a04c9c9c4c4935925f4c00dcc70610100c5e9dd (diff)
downloadlibvpx-e0cc52db3fc9b09c99d7bbee35153cf82964a860.tar
libvpx-e0cc52db3fc9b09c99d7bbee35153cf82964a860.tar.gz
libvpx-e0cc52db3fc9b09c99d7bbee35153cf82964a860.tar.bz2
libvpx-e0cc52db3fc9b09c99d7bbee35153cf82964a860.zip
vp9/encoder: apply clang-format
Change-Id: I45d9fb4013f50766b24363a86365e8063e8954c2
Diffstat (limited to 'vp9/encoder/vp9_ratectrl.c')
-rw-r--r--vp9/encoder/vp9_ratectrl.c722
1 files changed, 322 insertions, 400 deletions
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c
index 21038984b..c60f22c8e 100644
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -48,29 +48,24 @@
#define LIMIT_QP_ONEPASS_VBR_LAG 0
#if CONFIG_VP9_HIGHBITDEPTH
-#define ASSIGN_MINQ_TABLE(bit_depth, name) \
- do { \
- switch (bit_depth) { \
- case VPX_BITS_8: \
- name = name##_8; \
- break; \
- case VPX_BITS_10: \
- name = name##_10; \
- break; \
- case VPX_BITS_12: \
- name = name##_12; \
- break; \
- default: \
- assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10" \
- " or VPX_BITS_12"); \
- name = NULL; \
- } \
+#define ASSIGN_MINQ_TABLE(bit_depth, name) \
+ do { \
+ switch (bit_depth) { \
+ case VPX_BITS_8: name = name##_8; break; \
+ case VPX_BITS_10: name = name##_10; break; \
+ case VPX_BITS_12: name = name##_12; break; \
+ default: \
+ assert(0 && \
+ "bit_depth should be VPX_BITS_8, VPX_BITS_10" \
+ " or VPX_BITS_12"); \
+ name = NULL; \
+ } \
} while (0)
#else
#define ASSIGN_MINQ_TABLE(bit_depth, name) \
- do { \
- (void) bit_depth; \
- name = name##_8; \
+ do { \
+ (void) bit_depth; \
+ name = name##_8; \
} while (0)
#endif
@@ -109,25 +104,22 @@ static int kf_low = 400;
static int get_minq_index(double maxq, double x3, double x2, double x1,
vpx_bit_depth_t bit_depth) {
int i;
- const double minqtarget = VPXMIN(((x3 * maxq + x2) * maxq + x1) * maxq,
- maxq);
+ const double minqtarget = VPXMIN(((x3 * maxq + x2) * maxq + x1) * maxq, maxq);
// Special case handling to deal with the step from q2.0
// down to lossless mode represented by q 1.0.
- if (minqtarget <= 2.0)
- return 0;
+ if (minqtarget <= 2.0) return 0;
for (i = 0; i < QINDEX_RANGE; i++) {
- if (minqtarget <= vp9_convert_qindex_to_q(i, bit_depth))
- return i;
+ if (minqtarget <= vp9_convert_qindex_to_q(i, bit_depth)) return i;
}
return QINDEX_RANGE - 1;
}
-static void init_minq_luts(int *kf_low_m, int *kf_high_m,
- int *arfgf_low, int *arfgf_high,
- int *inter, int *rtc, vpx_bit_depth_t bit_depth) {
+static void init_minq_luts(int *kf_low_m, int *kf_high_m, int *arfgf_low,
+ int *arfgf_high, int *inter, int *rtc,
+ vpx_bit_depth_t bit_depth) {
int i;
for (i = 0; i < QINDEX_RANGE; i++) {
const double maxq = vp9_convert_qindex_to_q(i, bit_depth);
@@ -158,15 +150,12 @@ void vp9_rc_init_minq_luts(void) {
// quantizer tables easier. If necessary they can be replaced by lookup
// tables if and when things settle down in the experimental bitstream
double vp9_convert_qindex_to_q(int qindex, vpx_bit_depth_t bit_depth) {
- // Convert the index to a real Q value (scaled down to match old Q values)
+// Convert the index to a real Q value (scaled down to match old Q values)
#if CONFIG_VP9_HIGHBITDEPTH
switch (bit_depth) {
- case VPX_BITS_8:
- return vp9_ac_quant(qindex, 0, bit_depth) / 4.0;
- case VPX_BITS_10:
- return vp9_ac_quant(qindex, 0, bit_depth) / 16.0;
- case VPX_BITS_12:
- return vp9_ac_quant(qindex, 0, bit_depth) / 64.0;
+ case VPX_BITS_8: return vp9_ac_quant(qindex, 0, bit_depth) / 4.0;
+ case VPX_BITS_10: return vp9_ac_quant(qindex, 0, bit_depth) / 16.0;
+ case VPX_BITS_12: return vp9_ac_quant(qindex, 0, bit_depth) / 64.0;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
return -1.0;
@@ -177,8 +166,7 @@ double vp9_convert_qindex_to_q(int qindex, vpx_bit_depth_t bit_depth) {
}
int vp9_rc_bits_per_mb(FRAME_TYPE frame_type, int qindex,
- double correction_factor,
- vpx_bit_depth_t bit_depth) {
+ double correction_factor, vpx_bit_depth_t bit_depth) {
const double q = vp9_convert_qindex_to_q(qindex, bit_depth);
int enumerator = frame_type == KEY_FRAME ? 2700000 : 1800000;
@@ -193,8 +181,8 @@ int vp9_rc_bits_per_mb(FRAME_TYPE frame_type, int qindex,
int vp9_estimate_bits_at_q(FRAME_TYPE frame_type, int q, int mbs,
double correction_factor,
vpx_bit_depth_t bit_depth) {
- const int bpm = (int)(vp9_rc_bits_per_mb(frame_type, q, correction_factor,
- bit_depth));
+ const int bpm =
+ (int)(vp9_rc_bits_per_mb(frame_type, q, correction_factor, bit_depth));
return VPXMAX(FRAME_OVERHEAD_BITS,
(int)((uint64_t)bpm * mbs) >> BPER_MB_NORMBITS);
}
@@ -202,10 +190,9 @@ int vp9_estimate_bits_at_q(FRAME_TYPE frame_type, int q, int mbs,
int vp9_rc_clamp_pframe_target_size(const VP9_COMP *const cpi, int target) {
const RATE_CONTROL *rc = &cpi->rc;
const VP9EncoderConfig *oxcf = &cpi->oxcf;
- const int min_frame_target = VPXMAX(rc->min_frame_bandwidth,
- rc->avg_frame_bandwidth >> 5);
- if (target < min_frame_target)
- target = min_frame_target;
+ const int min_frame_target =
+ VPXMAX(rc->min_frame_bandwidth, rc->avg_frame_bandwidth >> 5);
+ if (target < min_frame_target) target = min_frame_target;
if (cpi->refresh_golden_frame && rc->is_src_frame_alt_ref) {
// If there is an active ARF at this location use the minimum
// bits on this frame even if it is a constructed arf.
@@ -214,11 +201,10 @@ int vp9_rc_clamp_pframe_target_size(const VP9_COMP *const cpi, int target) {
target = min_frame_target;
}
// Clip the frame target to the maximum allowed value.
- if (target > rc->max_frame_bandwidth)
- target = rc->max_frame_bandwidth;
+ if (target > rc->max_frame_bandwidth) target = rc->max_frame_bandwidth;
if (oxcf->rc_max_inter_bitrate_pct) {
- const int max_rate = rc->avg_frame_bandwidth *
- oxcf->rc_max_inter_bitrate_pct / 100;
+ const int max_rate =
+ rc->avg_frame_bandwidth * oxcf->rc_max_inter_bitrate_pct / 100;
target = VPXMIN(target, max_rate);
}
return target;
@@ -228,12 +214,11 @@ int vp9_rc_clamp_iframe_target_size(const VP9_COMP *const cpi, int target) {
const RATE_CONTROL *rc = &cpi->rc;
const VP9EncoderConfig *oxcf = &cpi->oxcf;
if (oxcf->rc_max_intra_bitrate_pct) {
- const int max_rate = rc->avg_frame_bandwidth *
- oxcf->rc_max_intra_bitrate_pct / 100;
+ const int max_rate =
+ rc->avg_frame_bandwidth * oxcf->rc_max_intra_bitrate_pct / 100;
target = VPXMIN(target, max_rate);
}
- if (target > rc->max_frame_bandwidth)
- target = rc->max_frame_bandwidth;
+ if (target > rc->max_frame_bandwidth) target = rc->max_frame_bandwidth;
return target;
}
@@ -242,14 +227,13 @@ int vp9_rc_clamp_iframe_target_size(const VP9_COMP *const cpi, int target) {
static void update_layer_buffer_level(SVC *svc, int encoded_frame_size) {
int i = 0;
int current_temporal_layer = svc->temporal_layer_id;
- for (i = current_temporal_layer + 1;
- i < svc->number_temporal_layers; ++i) {
- const int layer = LAYER_IDS_TO_IDX(svc->spatial_layer_id, i,
- svc->number_temporal_layers);
+ for (i = current_temporal_layer + 1; i < svc->number_temporal_layers; ++i) {
+ const int layer =
+ LAYER_IDS_TO_IDX(svc->spatial_layer_id, i, svc->number_temporal_layers);
LAYER_CONTEXT *lc = &svc->layer_context[layer];
RATE_CONTROL *lrc = &lc->rc;
- int bits_off_for_this_layer = (int)(lc->target_bandwidth / lc->framerate -
- encoded_frame_size);
+ int bits_off_for_this_layer =
+ (int)(lc->target_bandwidth / lc->framerate - encoded_frame_size);
lrc->bits_off_target += bits_off_for_this_layer;
// Clip buffer level to maximum buffer size for the layer.
@@ -287,8 +271,8 @@ static void update_buffer_level(VP9_COMP *cpi, int encoded_frame_size) {
}
}
-int vp9_rc_get_default_min_gf_interval(
- int width, int height, double framerate) {
+int vp9_rc_get_default_min_gf_interval(int width, int height,
+ double framerate) {
// Assume we do not need any constraint lower than 4K 20 fps
static const double factor_safe = 3840 * 2160 * 20.0;
const double factor = width * height * framerate;
@@ -319,20 +303,20 @@ void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
rc->avg_frame_qindex[KEY_FRAME] = oxcf->worst_allowed_q;
rc->avg_frame_qindex[INTER_FRAME] = oxcf->worst_allowed_q;
} else {
- rc->avg_frame_qindex[KEY_FRAME] = (oxcf->worst_allowed_q +
- oxcf->best_allowed_q) / 2;
- rc->avg_frame_qindex[INTER_FRAME] = (oxcf->worst_allowed_q +
- oxcf->best_allowed_q) / 2;
+ rc->avg_frame_qindex[KEY_FRAME] =
+ (oxcf->worst_allowed_q + oxcf->best_allowed_q) / 2;
+ rc->avg_frame_qindex[INTER_FRAME] =
+ (oxcf->worst_allowed_q + oxcf->best_allowed_q) / 2;
}
rc->last_q[KEY_FRAME] = oxcf->best_allowed_q;
rc->last_q[INTER_FRAME] = oxcf->worst_allowed_q;
- rc->buffer_level = rc->starting_buffer_level;
+ rc->buffer_level = rc->starting_buffer_level;
rc->bits_off_target = rc->starting_buffer_level;
- rc->rolling_target_bits = rc->avg_frame_bandwidth;
- rc->rolling_actual_bits = rc->avg_frame_bandwidth;
+ rc->rolling_target_bits = rc->avg_frame_bandwidth;
+ rc->rolling_actual_bits = rc->avg_frame_bandwidth;
rc->long_rolling_target_bits = rc->avg_frame_bandwidth;
rc->long_rolling_actual_bits = rc->avg_frame_bandwidth;
@@ -348,8 +332,7 @@ void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
rc->fac_active_worst_inter = 150;
rc->fac_active_worst_gf = 100;
rc->force_qpmin = 0;
- for (i = 0; i < MAX_LAG_BUFFERS; ++i)
- rc->avg_source_sad[i] = 0;
+ for (i = 0; i < MAX_LAG_BUFFERS; ++i) rc->avg_source_sad[i] = 0;
rc->frames_since_key = 8; // Sensible default for first frame.
rc->this_key_frame_forced = 0;
rc->next_key_frame_forced = 0;
@@ -393,13 +376,11 @@ int vp9_rc_drop_frame(VP9_COMP *cpi) {
} else {
// If buffer is below drop_mark, for now just drop every other frame
// (starting with the next frame) until it increases back over drop_mark.
- int drop_mark = (int)(oxcf->drop_frames_water_mark *
- rc->optimal_buffer_level / 100);
- if ((rc->buffer_level > drop_mark) &&
- (rc->decimation_factor > 0)) {
+ int drop_mark =
+ (int)(oxcf->drop_frames_water_mark * rc->optimal_buffer_level / 100);
+ if ((rc->buffer_level > drop_mark) && (rc->decimation_factor > 0)) {
--rc->decimation_factor;
- } else if (rc->buffer_level <= drop_mark &&
- rc->decimation_factor == 0) {
+ } else if (rc->buffer_level <= drop_mark && rc->decimation_factor == 0) {
rc->decimation_factor = 1;
}
if (rc->decimation_factor > 0) {
@@ -426,7 +407,7 @@ static double get_rate_correction_factor(const VP9_COMP *cpi) {
rcf = rc->rate_correction_factors[KF_STD];
} else if (cpi->oxcf.pass == 2) {
RATE_FACTOR_LEVEL rf_lvl =
- cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
+ cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
rcf = rc->rate_correction_factors[rf_lvl];
} else {
if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
@@ -452,7 +433,7 @@ static void set_rate_correction_factor(VP9_COMP *cpi, double factor) {
rc->rate_correction_factors[KF_STD] = factor;
} else if (cpi->oxcf.pass == 2) {
RATE_FACTOR_LEVEL rf_lvl =
- cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
+ cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
rc->rate_correction_factors[rf_lvl] = factor;
} else {
if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
@@ -473,8 +454,7 @@ void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi) {
int projected_size_based_on_q = 0;
// Do not update the rate factors for arf overlay frames.
- if (cpi->rc.is_src_frame_alt_ref)
- return;
+ if (cpi->rc.is_src_frame_alt_ref) return;
// Clear down mmx registers to allow floating point in what follows
vpx_clear_system_state();
@@ -486,21 +466,19 @@ void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi) {
projected_size_based_on_q =
vp9_cyclic_refresh_estimate_bits_at_q(cpi, rate_correction_factor);
} else {
- projected_size_based_on_q = vp9_estimate_bits_at_q(cpi->common.frame_type,
- cm->base_qindex,
- cm->MBs,
- rate_correction_factor,
- cm->bit_depth);
+ projected_size_based_on_q =
+ vp9_estimate_bits_at_q(cpi->common.frame_type, cm->base_qindex, cm->MBs,
+ rate_correction_factor, cm->bit_depth);
}
// Work out a size correction factor.
if (projected_size_based_on_q > FRAME_OVERHEAD_BITS)
correction_factor = (int)((100 * (int64_t)cpi->rc.projected_frame_size) /
- projected_size_based_on_q);
+ projected_size_based_on_q);
// More heavily damped adjustment used if we have been oscillating either side
// of target.
- adjustment_limit = 0.25 +
- 0.5 * VPXMIN(1, fabs(log10(0.01 * correction_factor)));
+ adjustment_limit =
+ 0.25 + 0.5 * VPXMIN(1, fabs(log10(0.01 * correction_factor)));
cpi->rc.q_2_frame = cpi->rc.q_1_frame;
cpi->rc.q_1_frame = cm->base_qindex;
@@ -520,16 +498,16 @@ void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi) {
if (correction_factor > 102) {
// We are not already at the worst allowable quality
- correction_factor = (int)(100 + ((correction_factor - 100) *
- adjustment_limit));
+ correction_factor =
+ (int)(100 + ((correction_factor - 100) * adjustment_limit));
rate_correction_factor = (rate_correction_factor * correction_factor) / 100;
// Keep rate_correction_factor within limits
if (rate_correction_factor > MAX_BPB_FACTOR)
rate_correction_factor = MAX_BPB_FACTOR;
} else if (correction_factor < 99) {
// We are not already at the best allowable quality
- correction_factor = (int)(100 - ((100 - correction_factor) *
- adjustment_limit));
+ correction_factor =
+ (int)(100 - ((100 - correction_factor) * adjustment_limit));
rate_correction_factor = (rate_correction_factor * correction_factor) / 100;
// Keep rate_correction_factor within limits
@@ -540,7 +518,6 @@ void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi) {
set_rate_correction_factor(cpi, rate_correction_factor);
}
-
int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame,
int active_best_quality, int active_worst_quality) {
const VP9_COMMON *const cm = &cpi->common;
@@ -557,15 +534,13 @@ int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame,
i = active_best_quality;
do {
- if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
- cm->seg.enabled &&
+ if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled &&
cpi->svc.temporal_layer_id == 0) {
bits_per_mb_at_this_q =
(int)vp9_cyclic_refresh_rc_bits_per_mb(cpi, i, correction_factor);
} else {
- bits_per_mb_at_this_q = (int)vp9_rc_bits_per_mb(cm->frame_type, i,
- correction_factor,
- cm->bit_depth);
+ bits_per_mb_at_this_q = (int)vp9_rc_bits_per_mb(
+ cm->frame_type, i, correction_factor, cm->bit_depth);
}
if (bits_per_mb_at_this_q <= target_bits_per_mb) {
@@ -632,16 +607,20 @@ static int calc_active_worst_quality_one_pass_vbr(const VP9_COMP *cpi) {
int active_worst_quality;
if (cpi->common.frame_type == KEY_FRAME) {
- active_worst_quality = curr_frame == 0 ? rc->worst_quality
- : rc->last_q[KEY_FRAME] << 1;
+ active_worst_quality =
+ curr_frame == 0 ? rc->worst_quality : rc->last_q[KEY_FRAME] << 1;
} else {
if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
- active_worst_quality = curr_frame == 1 ? rc->last_q[KEY_FRAME] * 5 >> 2 :
- rc->last_q[INTER_FRAME] * rc->fac_active_worst_gf / 100;
+ active_worst_quality =
+ curr_frame == 1
+ ? rc->last_q[KEY_FRAME] * 5 >> 2
+ : rc->last_q[INTER_FRAME] * rc->fac_active_worst_gf / 100;
} else {
- active_worst_quality = curr_frame == 1 ? rc->last_q[KEY_FRAME] << 1 :
- rc->avg_frame_qindex[INTER_FRAME] * rc->fac_active_worst_inter / 100;
+ active_worst_quality = curr_frame == 1
+ ? rc->last_q[KEY_FRAME] << 1
+ : rc->avg_frame_qindex[INTER_FRAME] *
+ rc->fac_active_worst_inter / 100;
}
}
return VPXMIN(active_worst_quality, rc->worst_quality);
@@ -663,28 +642,27 @@ static int calc_active_worst_quality_one_pass_cbr(const VP9_COMP *cpi) {
int active_worst_quality;
int ambient_qp;
unsigned int num_frames_weight_key = 5 * cpi->svc.number_temporal_layers;
- if (cm->frame_type == KEY_FRAME)
- return rc->worst_quality;
+ if (cm->frame_type == KEY_FRAME) return rc->worst_quality;
// For ambient_qp we use minimum of avg_frame_qindex[KEY_FRAME/INTER_FRAME]
// for the first few frames following key frame. These are both initialized
// to worst_quality and updated with (3/4, 1/4) average in postencode_update.
// So for first few frames following key, the qp of that key frame is weighted
// into the active_worst_quality setting.
- ambient_qp = (cm->current_video_frame < num_frames_weight_key) ?
- VPXMIN(rc->avg_frame_qindex[INTER_FRAME],
- rc->avg_frame_qindex[KEY_FRAME]) :
- rc->avg_frame_qindex[INTER_FRAME];
+ ambient_qp = (cm->current_video_frame < num_frames_weight_key)
+ ? VPXMIN(rc->avg_frame_qindex[INTER_FRAME],
+ rc->avg_frame_qindex[KEY_FRAME])
+ : rc->avg_frame_qindex[INTER_FRAME];
active_worst_quality = VPXMIN(rc->worst_quality, ambient_qp * 5 >> 2);
if (rc->buffer_level > rc->optimal_buffer_level) {
// Adjust down.
// Maximum limit for down adjustment, ~30%.
int max_adjustment_down = active_worst_quality / 3;
if (max_adjustment_down) {
- buff_lvl_step = ((rc->maximum_buffer_size -
- rc->optimal_buffer_level) / max_adjustment_down);
+ buff_lvl_step = ((rc->maximum_buffer_size - rc->optimal_buffer_level) /
+ max_adjustment_down);
if (buff_lvl_step)
adjustment = (int)((rc->buffer_level - rc->optimal_buffer_level) /
- buff_lvl_step);
+ buff_lvl_step);
active_worst_quality -= adjustment;
}
} else if (rc->buffer_level > critical_level) {
@@ -724,18 +702,16 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
if (rc->this_key_frame_forced) {
int qindex = rc->last_boosted_qindex;
double last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
- int delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
- (last_boosted_q * 0.75),
- cm->bit_depth);
+ int delta_qindex = vp9_compute_qdelta(
+ rc, last_boosted_q, (last_boosted_q * 0.75), cm->bit_depth);
active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
} else if (cm->current_video_frame > 0) {
// not first frame of one pass and kf_boost is set
double q_adj_factor = 1.0;
double q_val;
- active_best_quality =
- get_kf_active_quality(rc, rc->avg_frame_qindex[KEY_FRAME],
- cm->bit_depth);
+ active_best_quality = get_kf_active_quality(
+ rc, rc->avg_frame_qindex[KEY_FRAME], cm->bit_depth);
// Allow somewhat lower kf minq with small image formats.
if ((cm->width * cm->height) <= (352 * 288)) {
@@ -745,12 +721,10 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
// Convert the adjustment factor to a qindex delta
// on active_best_quality.
q_val = vp9_convert_qindex_to_q(active_best_quality, cm->bit_depth);
- active_best_quality += vp9_compute_qdelta(rc, q_val,
- q_val * q_adj_factor,
- cm->bit_depth);
+ active_best_quality +=
+ vp9_compute_qdelta(rc, q_val, q_val * q_adj_factor, cm->bit_depth);
}
- } else if (!rc->is_src_frame_alt_ref &&
- !cpi->use_svc &&
+ } else if (!rc->is_src_frame_alt_ref && !cpi->use_svc &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
// Use the lower of active_worst_quality and recent
// average Q as basis for GF/ARF best Q limit unless last frame was
@@ -778,24 +752,22 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
}
// Clip the active best and worst quality values to limits
- active_best_quality = clamp(active_best_quality,
- rc->best_quality, rc->worst_quality);
- active_worst_quality = clamp(active_worst_quality,
- active_best_quality, rc->worst_quality);
+ active_best_quality =
+ clamp(active_best_quality, rc->best_quality, rc->worst_quality);
+ active_worst_quality =
+ clamp(active_worst_quality, active_best_quality, rc->worst_quality);
*top_index = active_worst_quality;
*bottom_index = active_best_quality;
#if LIMIT_QRANGE_FOR_ALTREF_AND_KEY
// Limit Q range for the adaptive loop.
- if (cm->frame_type == KEY_FRAME &&
- !rc->this_key_frame_forced &&
+ if (cm->frame_type == KEY_FRAME && !rc->this_key_frame_forced &&
!(cm->current_video_frame == 0)) {
int qdelta = 0;
vpx_clear_system_state();
- qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
- active_worst_quality, 2.0,
- cm->bit_depth);
+ qdelta = vp9_compute_qdelta_by_rate(
+ &cpi->rc, cm->frame_type, active_worst_quality, 2.0, cm->bit_depth);
*top_index = active_worst_quality + qdelta;
*top_index = (*top_index > *bottom_index) ? *top_index : *bottom_index;
}
@@ -805,8 +777,8 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
if (cm->frame_type == KEY_FRAME && rc->this_key_frame_forced) {
q = rc->last_boosted_qindex;
} else {
- q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
- active_best_quality, active_worst_quality);
+ q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality,
+ active_worst_quality);
if (q > *top_index) {
// Special case when we are targeting the max allowed rate
if (rc->this_frame_target >= rc->max_frame_bandwidth)
@@ -815,20 +787,18 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
q = *top_index;
}
}
- assert(*top_index <= rc->worst_quality &&
- *top_index >= rc->best_quality);
+ assert(*top_index <= rc->worst_quality && *top_index >= rc->best_quality);
assert(*bottom_index <= rc->worst_quality &&
*bottom_index >= rc->best_quality);
assert(q <= rc->worst_quality && q >= rc->best_quality);
return q;
}
-static int get_active_cq_level_one_pass(
- const RATE_CONTROL *rc, const VP9EncoderConfig *const oxcf) {
+static int get_active_cq_level_one_pass(const RATE_CONTROL *rc,
+ const VP9EncoderConfig *const oxcf) {
static const double cq_adjust_threshold = 0.1;
int active_cq_level = oxcf->cq_level;
- if (oxcf->rc_mode == VPX_CQ &&
- rc->total_target_bits > 0) {
+ if (oxcf->rc_mode == VPX_CQ && rc->total_target_bits > 0) {
const double x = (double)rc->total_actual_bits / rc->total_target_bits;
if (x < cq_adjust_threshold) {
active_cq_level = (int)(active_cq_level * x / cq_adjust_threshold);
@@ -837,17 +807,17 @@ static int get_active_cq_level_one_pass(
return active_cq_level;
}
-#define SMOOTH_PCT_MIN 0.1
-#define SMOOTH_PCT_DIV 0.05
-static int get_active_cq_level_two_pass(
- const TWO_PASS *twopass, const RATE_CONTROL *rc,
- const VP9EncoderConfig *const oxcf) {
+#define SMOOTH_PCT_MIN 0.1
+#define SMOOTH_PCT_DIV 0.05
+static int get_active_cq_level_two_pass(const TWO_PASS *twopass,
+ const RATE_CONTROL *rc,
+ const VP9EncoderConfig *const oxcf) {
static const double cq_adjust_threshold = 0.1;
int active_cq_level = oxcf->cq_level;
if (oxcf->rc_mode == VPX_CQ) {
if (twopass->mb_smooth_pct > SMOOTH_PCT_MIN) {
- active_cq_level -= (int)((twopass->mb_smooth_pct - SMOOTH_PCT_MIN) /
- SMOOTH_PCT_DIV);
+ active_cq_level -=
+ (int)((twopass->mb_smooth_pct - SMOOTH_PCT_MIN) / SMOOTH_PCT_DIV);
active_cq_level = VPXMAX(active_cq_level, 0);
}
if (rc->total_target_bits > 0) {
@@ -877,8 +847,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
if (oxcf->rc_mode == VPX_Q) {
int qindex = cq_level;
double q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
- int delta_qindex = vp9_compute_qdelta(rc, q, q * 0.25,
- cm->bit_depth);
+ int delta_qindex = vp9_compute_qdelta(rc, q, q * 0.25, cm->bit_depth);
active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
} else if (rc->this_key_frame_forced) {
// Handle the special case for key frames forced when we have reached
@@ -886,18 +855,16 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
// based on the ambient Q to reduce the risk of popping.
int qindex = rc->last_boosted_qindex;
double last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
- int delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
- last_boosted_q * 0.75,
- cm->bit_depth);
+ int delta_qindex = vp9_compute_qdelta(
+ rc, last_boosted_q, last_boosted_q * 0.75, cm->bit_depth);
active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
} else {
// not first frame of one pass and kf_boost is set
double q_adj_factor = 1.0;
double q_val;
- active_best_quality =
- get_kf_active_quality(rc, rc->avg_frame_qindex[KEY_FRAME],
- cm->bit_depth);
+ active_best_quality = get_kf_active_quality(
+ rc, rc->avg_frame_qindex[KEY_FRAME], cm->bit_depth);
// Allow somewhat lower kf minq with small image formats.
if ((cm->width * cm->height) <= (352 * 288)) {
@@ -907,9 +874,8 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
// Convert the adjustment factor to a qindex delta
// on active_best_quality.
q_val = vp9_convert_qindex_to_q(active_best_quality, cm->bit_depth);
- active_best_quality += vp9_compute_qdelta(rc, q_val,
- q_val * q_adj_factor,
- cm->bit_depth);
+ active_best_quality +=
+ vp9_compute_qdelta(rc, q_val, q_val * q_adj_factor, cm->bit_depth);
}
} else if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
@@ -927,8 +893,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
}
// For constrained quality dont allow Q less than the cq level
if (oxcf->rc_mode == VPX_CQ) {
- if (q < cq_level)
- q = cq_level;
+ if (q < cq_level) q = cq_level;
active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth);
@@ -951,12 +916,11 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
if (oxcf->rc_mode == VPX_Q) {
int qindex = cq_level;
double q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
- double delta_rate[FIXED_GF_INTERVAL] =
- {0.50, 1.0, 0.85, 1.0, 0.70, 1.0, 0.85, 1.0};
- int delta_qindex =
- vp9_compute_qdelta(rc, q,
- q * delta_rate[cm->current_video_frame %
- FIXED_GF_INTERVAL], cm->bit_depth);
+ double delta_rate[FIXED_GF_INTERVAL] = { 0.50, 1.0, 0.85, 1.0,
+ 0.70, 1.0, 0.85, 1.0 };
+ int delta_qindex = vp9_compute_qdelta(
+ rc, q, q * delta_rate[cm->current_video_frame % FIXED_GF_INTERVAL],
+ cm->bit_depth);
active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
} else {
// Use the min of the average Q and active_worst_quality as basis for
@@ -969,24 +933,23 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
}
// For the constrained quality mode we don't want
// q to fall below the cq level.
- if ((oxcf->rc_mode == VPX_CQ) &&
- (active_best_quality < cq_level)) {
+ if ((oxcf->rc_mode == VPX_CQ) && (active_best_quality < cq_level)) {
active_best_quality = cq_level;
}
}
}
// Clip the active best and worst quality values to limits
- active_best_quality = clamp(active_best_quality,
- rc->best_quality, rc->worst_quality);
- active_worst_quality = clamp(active_worst_quality,
- active_best_quality, rc->worst_quality);
+ active_best_quality =
+ clamp(active_best_quality, rc->best_quality, rc->worst_quality);
+ active_worst_quality =
+ clamp(active_worst_quality, active_best_quality, rc->worst_quality);
#if LIMIT_QP_ONEPASS_VBR_LAG
if (oxcf->lag_in_frames > 0 && oxcf->rc_mode == VPX_VBR) {
if (rc->force_qpmin > 0 && active_best_quality < rc->force_qpmin)
- active_best_quality = clamp(active_best_quality,
- rc->force_qpmin, rc->worst_quality);
+ active_best_quality =
+ clamp(active_best_quality, rc->force_qpmin, rc->worst_quality);
}
#endif
@@ -999,17 +962,14 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
vpx_clear_system_state();
// Limit Q range for the adaptive loop.
- if (cm->frame_type == KEY_FRAME &&
- !rc->this_key_frame_forced &&
+ if (cm->frame_type == KEY_FRAME && !rc->this_key_frame_forced &&
!(cm->current_video_frame == 0)) {
- qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
- active_worst_quality, 2.0,
- cm->bit_depth);
+ qdelta = vp9_compute_qdelta_by_rate(
+ &cpi->rc, cm->frame_type, active_worst_quality, 2.0, cm->bit_depth);
} else if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
- qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
- active_worst_quality, 1.75,
- cm->bit_depth);
+ qdelta = vp9_compute_qdelta_by_rate(
+ &cpi->rc, cm->frame_type, active_worst_quality, 1.75, cm->bit_depth);
}
*top_index = active_worst_quality + qdelta;
*top_index = (*top_index > *bottom_index) ? *top_index : *bottom_index;
@@ -1018,12 +978,12 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
if (oxcf->rc_mode == VPX_Q) {
q = active_best_quality;
- // Special case code to try and match quality with forced key frames
+ // Special case code to try and match quality with forced key frames
} else if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced) {
q = rc->last_boosted_qindex;
} else {
- q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
- active_best_quality, active_worst_quality);
+ q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality,
+ active_worst_quality);
if (q > *top_index) {
// Special case when we are targeting the max allowed rate
if (rc->this_frame_target >= rc->max_frame_bandwidth)
@@ -1033,8 +993,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
}
}
- assert(*top_index <= rc->worst_quality &&
- *top_index >= rc->best_quality);
+ assert(*top_index <= rc->worst_quality && *top_index >= rc->best_quality);
assert(*bottom_index <= rc->worst_quality &&
*bottom_index >= rc->best_quality);
assert(q <= rc->worst_quality && q >= rc->best_quality);
@@ -1049,18 +1008,18 @@ int vp9_frame_type_qdelta(const VP9_COMP *cpi, int rf_level, int q) {
1.75, // GF_ARF_STD
2.00, // KF_STD
};
- static const FRAME_TYPE frame_type[RATE_FACTOR_LEVELS] =
- {INTER_FRAME, INTER_FRAME, INTER_FRAME, INTER_FRAME, KEY_FRAME};
+ static const FRAME_TYPE frame_type[RATE_FACTOR_LEVELS] = {
+ INTER_FRAME, INTER_FRAME, INTER_FRAME, INTER_FRAME, KEY_FRAME
+ };
const VP9_COMMON *const cm = &cpi->common;
- int qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, frame_type[rf_level],
- q, rate_factor_deltas[rf_level],
- cm->bit_depth);
+ int qdelta =
+ vp9_compute_qdelta_by_rate(&cpi->rc, frame_type[rf_level], q,
+ rate_factor_deltas[rf_level], cm->bit_depth);
return qdelta;
}
#define STATIC_MOTION_THRESH 95
-static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
- int *bottom_index,
+static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int *bottom_index,
int *top_index) {
const VP9_COMMON *const cm = &cpi->common;
const RATE_CONTROL *const rc = &cpi->rc;
@@ -1087,16 +1046,14 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
active_best_quality = qindex;
last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
- last_boosted_q * 1.25,
- cm->bit_depth);
+ last_boosted_q * 1.25, cm->bit_depth);
active_worst_quality =
VPXMIN(qindex + delta_qindex, active_worst_quality);
} else {
qindex = rc->last_boosted_qindex;
last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
- last_boosted_q * 0.75,
- cm->bit_depth);
+ last_boosted_q * 0.75, cm->bit_depth);
active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
}
} else {
@@ -1104,8 +1061,8 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
double q_adj_factor = 1.0;
double q_val;
// Baseline value derived from cpi->active_worst_quality and kf boost.
- active_best_quality = get_kf_active_quality(rc, active_worst_quality,
- cm->bit_depth);
+ active_best_quality =
+ get_kf_active_quality(rc, active_worst_quality, cm->bit_depth);
// Allow somewhat lower kf minq with small image formats.
if ((cm->width * cm->height) <= (352 * 288)) {
@@ -1118,9 +1075,8 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
// Convert the adjustment factor to a qindex delta
// on active_best_quality.
q_val = vp9_convert_qindex_to_q(active_best_quality, cm->bit_depth);
- active_best_quality += vp9_compute_qdelta(rc, q_val,
- q_val * q_adj_factor,
- cm->bit_depth);
+ active_best_quality +=
+ vp9_compute_qdelta(rc, q_val, q_val * q_adj_factor, cm->bit_depth);
}
} else if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
@@ -1135,8 +1091,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
}
// For constrained quality dont allow Q less than the cq level
if (oxcf->rc_mode == VPX_CQ) {
- if (q < cq_level)
- q = cq_level;
+ if (q < cq_level) q = cq_level;
active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth);
@@ -1165,8 +1120,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
// For the constrained quality mode we don't want
// q to fall below the cq level.
- if ((oxcf->rc_mode == VPX_CQ) &&
- (active_best_quality < cq_level)) {
+ if ((oxcf->rc_mode == VPX_CQ) && (active_best_quality < cq_level)) {
active_best_quality = cq_level;
}
}
@@ -1179,11 +1133,11 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
(!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) {
active_best_quality -=
- (cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast);
+ (cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast);
active_worst_quality += (cpi->twopass.extend_maxq / 2);
} else {
active_best_quality -=
- (cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast) / 2;
+ (cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast) / 2;
active_worst_quality += cpi->twopass.extend_maxq;
}
}
@@ -1196,28 +1150,27 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
(cpi->twopass.last_kfgroup_zeromotion_pct < STATIC_MOTION_THRESH)) {
int qdelta = vp9_frame_type_qdelta(cpi, gf_group->rf_level[gf_group->index],
active_worst_quality);
- active_worst_quality = VPXMAX(active_worst_quality + qdelta,
- active_best_quality);
+ active_worst_quality =
+ VPXMAX(active_worst_quality + qdelta, active_best_quality);
}
#endif
// Modify active_best_quality for downscaled normal frames.
if (rc->frame_size_selector != UNSCALED && !frame_is_kf_gf_arf(cpi)) {
- int qdelta = vp9_compute_qdelta_by_rate(rc, cm->frame_type,
- active_best_quality, 2.0,
- cm->bit_depth);
+ int qdelta = vp9_compute_qdelta_by_rate(
+ rc, cm->frame_type, active_best_quality, 2.0, cm->bit_depth);
active_best_quality =
VPXMAX(active_best_quality + qdelta, rc->best_quality);
}
- active_best_quality = clamp(active_best_quality,
- rc->best_quality, rc->worst_quality);
- active_worst_quality = clamp(active_worst_quality,
- active_best_quality, rc->worst_quality);
+ active_best_quality =
+ clamp(active_best_quality, rc->best_quality, rc->worst_quality);
+ active_worst_quality =
+ clamp(active_worst_quality, active_best_quality, rc->worst_quality);
if (oxcf->rc_mode == VPX_Q) {
q = active_best_quality;
- // Special case code to try and match quality with forced key frames.
+ // Special case code to try and match quality with forced key frames.
} else if ((frame_is_intra_only(cm) || vp9_is_upper_layer_key_frame(cpi)) &&
rc->this_key_frame_forced) {
// If static since last kf use better of last boosted and last kf q.
@@ -1227,8 +1180,8 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
q = rc->last_boosted_qindex;
}
} else {
- q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
- active_best_quality, active_worst_quality);
+ q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality,
+ active_worst_quality);
if (q > active_worst_quality) {
// Special case when we are targeting the max allowed rate.
if (rc->this_frame_target >= rc->max_frame_bandwidth)
@@ -1242,16 +1195,15 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
*top_index = active_worst_quality;
*bottom_index = active_best_quality;
- assert(*top_index <= rc->worst_quality &&
- *top_index >= rc->best_quality);
+ assert(*top_index <= rc->worst_quality && *top_index >= rc->best_quality);
assert(*bottom_index <= rc->worst_quality &&
*bottom_index >= rc->best_quality);
assert(q <= rc->worst_quality && q >= rc->best_quality);
return q;
}
-int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi,
- int *bottom_index, int *top_index) {
+int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi, int *bottom_index,
+ int *top_index) {
int q;
if (cpi->oxcf.pass == 0) {
if (cpi->oxcf.rc_mode == VPX_CBR)
@@ -1262,8 +1214,7 @@ int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi,
q = rc_pick_q_and_bounds_two_pass(cpi, bottom_index, top_index);
}
if (cpi->sf.use_nonrd_pick_mode) {
- if (cpi->sf.force_frame_boost == 1)
- q -= cpi->sf.max_delta_qindex;
+ if (cpi->sf.force_frame_boost == 1) q -= cpi->sf.max_delta_qindex;
if (q < *bottom_index)
*bottom_index = q;
@@ -1273,20 +1224,19 @@ int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi,
return q;
}
-void vp9_rc_compute_frame_size_bounds(const VP9_COMP *cpi,
- int frame_target,
+void vp9_rc_compute_frame_size_bounds(const VP9_COMP *cpi, int frame_target,
int *frame_under_shoot_limit,
int *frame_over_shoot_limit) {
if (cpi->oxcf.rc_mode == VPX_Q) {
*frame_under_shoot_limit = 0;
- *frame_over_shoot_limit = INT_MAX;
+ *frame_over_shoot_limit = INT_MAX;
} else {
// For very small rate targets where the fractional adjustment
// may be tiny make sure there is at least a minimum range.
const int tolerance = (cpi->sf.recode_tolerance * frame_target) / 100;
*frame_under_shoot_limit = VPXMAX(frame_target - tolerance - 200, 0);
- *frame_over_shoot_limit = VPXMIN(frame_target + tolerance + 200,
- cpi->rc.max_frame_bandwidth);
+ *frame_over_shoot_limit =
+ VPXMIN(frame_target + tolerance + 200, cpi->rc.max_frame_bandwidth);
}
}
@@ -1299,12 +1249,12 @@ void vp9_rc_set_frame_target(VP9_COMP *cpi, int target) {
// Modify frame size target when down-scaling.
if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC &&
rc->frame_size_selector != UNSCALED)
- rc->this_frame_target = (int)(rc->this_frame_target
- * rate_thresh_mult[rc->frame_size_selector]);
+ rc->this_frame_target = (int)(rc->this_frame_target *
+ rate_thresh_mult[rc->frame_size_selector]);
// Target rate per SB64 (including partial SB64s.
- rc->sb64_target_rate = ((int64_t)rc->this_frame_target * 64 * 64) /
- (cm->width * cm->height);
+ rc->sb64_target_rate =
+ ((int64_t)rc->this_frame_target * 64 * 64) / (cm->width * cm->height);
}
static void update_alt_ref_frame_stats(VP9_COMP *cpi) {
@@ -1338,13 +1288,11 @@ static void update_golden_frame_stats(VP9_COMP *cpi) {
}
// Decrement count down till next gf
- if (rc->frames_till_gf_update_due > 0)
- rc->frames_till_gf_update_due--;
+ if (rc->frames_till_gf_update_due > 0) rc->frames_till_gf_update_due--;
} else if (!cpi->refresh_alt_ref_frame) {
// Decrement count down till next gf
- if (rc->frames_till_gf_update_due > 0)
- rc->frames_till_gf_update_due--;
+ if (rc->frames_till_gf_update_due > 0) rc->frames_till_gf_update_due--;
rc->frames_since_golden++;
}
@@ -1359,8 +1307,7 @@ static void compute_frame_low_motion(VP9_COMP *const cpi) {
int cnt_zeromv = 0;
for (mi_row = 0; mi_row < rows; mi_row++) {
for (mi_col = 0; mi_col < cols; mi_col++) {
- if (abs(mi[0]->mv[0].as_mv.row) < 16 &&
- abs(mi[0]->mv[0].as_mv.col) < 16)
+ if (abs(mi[0]->mv[0].as_mv.row) < 16 && abs(mi[0]->mv[0].as_mv.col) < 16)
cnt_zeromv++;
mi++;
}
@@ -1409,7 +1356,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) {
!(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) {
rc->last_q[INTER_FRAME] = qindex;
rc->avg_frame_qindex[INTER_FRAME] =
- ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2);
+ ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2);
rc->ni_frames++;
rc->tot_q += vp9_convert_qindex_to_q(qindex, cm->bit_depth);
rc->avg_q = rc->tot_q / rc->ni_frames;
@@ -1425,15 +1372,13 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) {
// If all mbs in this group are skipped only update if the Q value is
// better than that already stored.
// This is used to help set quality in forced key frames to reduce popping
- if ((qindex < rc->last_boosted_qindex) ||
- (cm->frame_type == KEY_FRAME) ||
+ if ((qindex < rc->last_boosted_qindex) || (cm->frame_type == KEY_FRAME) ||
(!rc->constrained_gf_group &&
(cpi->refresh_alt_ref_frame ||
(cpi->refresh_golden_frame && !rc->is_src_frame_alt_ref)))) {
rc->last_boosted_qindex = qindex;
}
- if (cm->frame_type == KEY_FRAME)
- rc->last_kf_qindex = qindex;
+ if (cm->frame_type == KEY_FRAME) rc->last_kf_qindex = qindex;
update_buffer_level(cpi, rc->projected_frame_size);
@@ -1466,8 +1411,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) {
update_golden_frame_stats(cpi);
}
- if (cm->frame_type == KEY_FRAME)
- rc->frames_since_key = 0;
+ if (cm->frame_type == KEY_FRAME) rc->frames_since_key = 0;
if (cm->show_frame) {
rc->frames_since_key++;
rc->frames_to_key--;
@@ -1481,8 +1425,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) {
}
if (oxcf->pass == 0) {
- if (cm->frame_type != KEY_FRAME)
- compute_frame_low_motion(cpi);
+ if (cm->frame_type != KEY_FRAME) compute_frame_low_motion(cpi);
}
}
@@ -1496,19 +1439,20 @@ void vp9_rc_postencode_update_drop_frame(VP9_COMP *cpi) {
}
// Use this macro to turn on/off use of alt-refs in one-pass mode.
-#define USE_ALTREF_FOR_ONE_PASS 1
+#define USE_ALTREF_FOR_ONE_PASS 1
static int calc_pframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
const RATE_CONTROL *const rc = &cpi->rc;
int target;
const int af_ratio = rc->af_ratio_onepass_vbr;
#if USE_ALTREF_FOR_ONE_PASS
- target = (!rc->is_src_frame_alt_ref &&
- (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) ?
- (rc->avg_frame_bandwidth * rc->baseline_gf_interval * af_ratio) /
- (rc->baseline_gf_interval + af_ratio - 1) :
- (rc->avg_frame_bandwidth * rc->baseline_gf_interval) /
- (rc->baseline_gf_interval + af_ratio - 1);
+ target =
+ (!rc->is_src_frame_alt_ref &&
+ (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))
+ ? (rc->avg_frame_bandwidth * rc->baseline_gf_interval * af_ratio) /
+ (rc->baseline_gf_interval + af_ratio - 1)
+ : (rc->avg_frame_bandwidth * rc->baseline_gf_interval) /
+ (rc->baseline_gf_interval + af_ratio - 1);
#else
target = rc->avg_frame_bandwidth;
#endif
@@ -1547,13 +1491,11 @@ void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) {
int target;
// TODO(yaowu): replace the "auto_key && 0" below with proper decision logic.
if (!cpi->refresh_alt_ref_frame &&
- (cm->current_video_frame == 0 ||
- (cpi->frame_flags & FRAMEFLAGS_KEY) ||
- rc->frames_to_key == 0 ||
- (cpi->oxcf.auto_key && 0))) {
+ (cm->current_video_frame == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY) ||
+ rc->frames_to_key == 0 || (cpi->oxcf.auto_key && 0))) {
cm->frame_type = KEY_FRAME;
- rc->this_key_frame_forced = cm->current_video_frame != 0 &&
- rc->frames_to_key == 0;
+ rc->this_key_frame_forced =
+ cm->current_video_frame != 0 && rc->frames_to_key == 0;
rc->frames_to_key = cpi->oxcf.key_freq;
rc->kf_boost = DEFAULT_KF_BOOST;
rc->source_alt_ref_active = 0;
@@ -1584,8 +1526,9 @@ void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) {
}
// Adjust boost and af_ratio based on avg_frame_low_motion, which varies
// between 0 and 100 (stationary, 100% zero/small motion).
- rc->gfu_boost = VPXMAX(500, DEFAULT_GF_BOOST *
- (rc->avg_frame_low_motion << 1) / (rc->avg_frame_low_motion + 100));
+ rc->gfu_boost =
+ VPXMAX(500, DEFAULT_GF_BOOST * (rc->avg_frame_low_motion << 1) /
+ (rc->avg_frame_low_motion + 100));
rc->af_ratio_onepass_vbr = VPXMIN(15, VPXMAX(5, 3 * rc->gfu_boost / 400));
}
adjust_gfint_frame_constraint(cpi, rc->frames_to_key);
@@ -1614,11 +1557,12 @@ static int calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
if (oxcf->gf_cbr_boost_pct) {
const int af_ratio_pct = oxcf->gf_cbr_boost_pct + 100;
- target = cpi->refresh_golden_frame ?
- (rc->avg_frame_bandwidth * rc->baseline_gf_interval * af_ratio_pct) /
- (rc->baseline_gf_interval * 100 + af_ratio_pct - 100) :
- (rc->avg_frame_bandwidth * rc->baseline_gf_interval * 100) /
- (rc->baseline_gf_interval * 100 + af_ratio_pct - 100);
+ target = cpi->refresh_golden_frame
+ ? (rc->avg_frame_bandwidth * rc->baseline_gf_interval *
+ af_ratio_pct) /
+ (rc->baseline_gf_interval * 100 + af_ratio_pct - 100)
+ : (rc->avg_frame_bandwidth * rc->baseline_gf_interval * 100) /
+ (rc->baseline_gf_interval * 100 + af_ratio_pct - 100);
} else {
target = rc->avg_frame_bandwidth;
}
@@ -1626,9 +1570,8 @@ static int calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
// Note that for layers, avg_frame_bandwidth is the cumulative
// per-frame-bandwidth. For the target size of this frame, use the
// layer average frame size (i.e., non-cumulative per-frame-bw).
- int layer =
- LAYER_IDS_TO_IDX(svc->spatial_layer_id,
- svc->temporal_layer_id, svc->number_temporal_layers);
+ int layer = LAYER_IDS_TO_IDX(svc->spatial_layer_id, svc->temporal_layer_id,
+ svc->number_temporal_layers);
const LAYER_CONTEXT *lc = &svc->layer_context[layer];
target = lc->avg_frame_size;
min_frame_target = VPXMAX(lc->avg_frame_size >> 4, FRAME_OVERHEAD_BITS);
@@ -1644,8 +1587,8 @@ static int calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
target += (target * pct_high) / 200;
}
if (oxcf->rc_max_inter_bitrate_pct) {
- const int max_rate = rc->avg_frame_bandwidth *
- oxcf->rc_max_inter_bitrate_pct / 100;
+ const int max_rate =
+ rc->avg_frame_bandwidth * oxcf->rc_max_inter_bitrate_pct / 100;
target = VPXMIN(target, max_rate);
}
return VPXMAX(min_frame_target, target);
@@ -1658,22 +1601,22 @@ static int calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
int target;
if (cpi->common.current_video_frame == 0) {
target = ((rc->starting_buffer_level / 2) > INT_MAX)
- ? INT_MAX : (int)(rc->starting_buffer_level / 2);
+ ? INT_MAX
+ : (int)(rc->starting_buffer_level / 2);
} else {
int kf_boost = 32;
double framerate = cpi->framerate;
- if (svc->number_temporal_layers > 1 &&
- oxcf->rc_mode == VPX_CBR) {
+ if (svc->number_temporal_layers > 1 && oxcf->rc_mode == VPX_CBR) {
// Use the layer framerate for temporal layers CBR mode.
- const int layer = LAYER_IDS_TO_IDX(svc->spatial_layer_id,
- svc->temporal_layer_id, svc->number_temporal_layers);
+ const int layer =
+ LAYER_IDS_TO_IDX(svc->spatial_layer_id, svc->temporal_layer_id,
+ svc->number_temporal_layers);
const LAYER_CONTEXT *lc = &svc->layer_context[layer];
framerate = lc->framerate;
}
kf_boost = VPXMAX(kf_boost, (int)(2 * framerate - 16));
- if (rc->frames_since_key < framerate / 2) {
- kf_boost = (int)(kf_boost * rc->frames_since_key /
- (framerate / 2));
+ if (rc->frames_since_key < framerate / 2) {
+ kf_boost = (int)(kf_boost * rc->frames_since_key / (framerate / 2));
}
target = ((16 + kf_boost) * rc->avg_frame_bandwidth) >> 4;
}
@@ -1684,12 +1627,12 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) {
VP9_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
int target = rc->avg_frame_bandwidth;
- int layer = LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id,
- cpi->svc.temporal_layer_id, cpi->svc.number_temporal_layers);
+ int layer =
+ LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id, cpi->svc.temporal_layer_id,
+ cpi->svc.number_temporal_layers);
// Periodic key frames is based on the super-frame counter
// (svc.current_superframe), also only base spatial layer is key frame.
- if ((cm->current_video_frame == 0) ||
- (cpi->frame_flags & FRAMEFLAGS_KEY) ||
+ if ((cm->current_video_frame == 0) || (cpi->frame_flags & FRAMEFLAGS_KEY) ||
(cpi->oxcf.auto_key &&
(cpi->svc.current_superframe % cpi->oxcf.key_freq == 0) &&
cpi->svc.spatial_layer_id == 0)) {
@@ -1697,16 +1640,14 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) {
rc->source_alt_ref_active = 0;
if (is_two_pass_svc(cpi)) {
cpi->svc.layer_context[layer].is_key_frame = 1;
- cpi->ref_frame_flags &=
- (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
+ cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
} else if (is_one_pass_cbr_svc(cpi)) {
- if (cm->current_video_frame > 0)
- vp9_svc_reset_key_frame(cpi);
+ if (cm->current_video_frame > 0) vp9_svc_reset_key_frame(cpi);
layer = LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id,
- cpi->svc.temporal_layer_id, cpi->svc.number_temporal_layers);
+ cpi->svc.temporal_layer_id,
+ cpi->svc.number_temporal_layers);
cpi->svc.layer_context[layer].is_key_frame = 1;
- cpi->ref_frame_flags &=
- (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
+ cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
// Assumption here is that LAST_FRAME is being updated for a keyframe.
// Thus no change in update flags.
target = calc_iframe_target_size_one_pass_cbr(cpi);
@@ -1720,8 +1661,7 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) {
} else {
lc->is_key_frame =
cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame;
- if (lc->is_key_frame)
- cpi->ref_frame_flags &= (~VP9_LAST_FLAG);
+ if (lc->is_key_frame) cpi->ref_frame_flags &= (~VP9_LAST_FLAG);
}
cpi->ref_frame_flags &= (~VP9_ALT_FLAG);
} else if (is_one_pass_cbr_svc(cpi)) {
@@ -1751,13 +1691,11 @@ void vp9_rc_get_one_pass_cbr_params(VP9_COMP *cpi) {
RATE_CONTROL *const rc = &cpi->rc;
int target;
// TODO(yaowu): replace the "auto_key && 0" below with proper decision logic.
- if ((cm->current_video_frame == 0 ||
- (cpi->frame_flags & FRAMEFLAGS_KEY) ||
- rc->frames_to_key == 0 ||
- (cpi->oxcf.auto_key && 0))) {
+ if ((cm->current_video_frame == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY) ||
+ rc->frames_to_key == 0 || (cpi->oxcf.auto_key && 0))) {
cm->frame_type = KEY_FRAME;
- rc->this_key_frame_forced = cm->current_video_frame != 0 &&
- rc->frames_to_key == 0;
+ rc->this_key_frame_forced =
+ cm->current_video_frame != 0 && rc->frames_to_key == 0;
rc->frames_to_key = cpi->oxcf.key_freq;
rc->kf_boost = DEFAULT_KF_BOOST;
rc->source_alt_ref_active = 0;
@@ -1804,15 +1742,13 @@ int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget,
// Convert the average q value to an index.
for (i = rc->best_quality; i < rc->worst_quality; ++i) {
start_index = i;
- if (vp9_convert_qindex_to_q(i, bit_depth) >= qstart)
- break;
+ if (vp9_convert_qindex_to_q(i, bit_depth) >= qstart) break;
}
// Convert the q target to an index
for (i = rc->best_quality; i < rc->worst_quality; ++i) {
target_index = i;
- if (vp9_convert_qindex_to_q(i, bit_depth) >= qtarget)
- break;
+ if (vp9_convert_qindex_to_q(i, bit_depth) >= qtarget) break;
}
return target_index - start_index;
@@ -1825,8 +1761,8 @@ int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type,
int i;
// Look up the current projected bits per block for the base index
- const int base_bits_per_mb = vp9_rc_bits_per_mb(frame_type, qindex, 1.0,
- bit_depth);
+ const int base_bits_per_mb =
+ vp9_rc_bits_per_mb(frame_type, qindex, 1.0, bit_depth);
// 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);
@@ -1885,8 +1821,8 @@ void vp9_rc_update_framerate(VP9_COMP *cpi) {
int vbr_max_bits;
rc->avg_frame_bandwidth = (int)(oxcf->target_bandwidth / cpi->framerate);
- rc->min_frame_bandwidth = (int)(rc->avg_frame_bandwidth *
- oxcf->two_pass_vbrmin_section / 100);
+ rc->min_frame_bandwidth =
+ (int)(rc->avg_frame_bandwidth * oxcf->two_pass_vbrmin_section / 100);
rc->min_frame_bandwidth =
VPXMAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS);
@@ -1898,8 +1834,9 @@ void vp9_rc_update_framerate(VP9_COMP *cpi) {
// a very high rate is given on the command line or the the rate cannnot
// be acheived because of a user specificed max q (e.g. when the user
// specifies lossless encode.
- vbr_max_bits = (int)(((int64_t)rc->avg_frame_bandwidth *
- oxcf->two_pass_vbrmax_section) / 100);
+ vbr_max_bits =
+ (int)(((int64_t)rc->avg_frame_bandwidth * oxcf->two_pass_vbrmax_section) /
+ 100);
rc->max_frame_bandwidth =
VPXMAX(VPXMAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P), vbr_max_bits);
@@ -1912,27 +1849,27 @@ static void vbr_rate_correction(VP9_COMP *cpi, int *this_frame_target) {
RATE_CONTROL *const rc = &cpi->rc;
int64_t vbr_bits_off_target = rc->vbr_bits_off_target;
int max_delta;
- int frame_window = VPXMIN(16,
- ((int)cpi->twopass.total_stats.count - cpi->common.current_video_frame));
+ int frame_window = VPXMIN(16, ((int)cpi->twopass.total_stats.count -
+ cpi->common.current_video_frame));
// Calcluate the adjustment to rate for this frame.
if (frame_window > 0) {
max_delta = (vbr_bits_off_target > 0)
- ? (int)(vbr_bits_off_target / frame_window)
- : (int)(-vbr_bits_off_target / frame_window);
+ ? (int)(vbr_bits_off_target / frame_window)
+ : (int)(-vbr_bits_off_target / frame_window);
max_delta = VPXMIN(max_delta,
- ((*this_frame_target * VBR_PCT_ADJUSTMENT_LIMIT) / 100));
+ ((*this_frame_target * VBR_PCT_ADJUSTMENT_LIMIT) / 100));
// vbr_bits_off_target > 0 means we have extra bits to spend
if (vbr_bits_off_target > 0) {
- *this_frame_target +=
- (vbr_bits_off_target > max_delta) ? max_delta
- : (int)vbr_bits_off_target;
+ *this_frame_target += (vbr_bits_off_target > max_delta)
+ ? max_delta
+ : (int)vbr_bits_off_target;
} else {
- *this_frame_target -=
- (vbr_bits_off_target < -max_delta) ? max_delta
- : (int)-vbr_bits_off_target;
+ *this_frame_target -= (vbr_bits_off_target < -max_delta)
+ ? max_delta
+ : (int)-vbr_bits_off_target;
}
}
@@ -1992,8 +1929,7 @@ int vp9_resize_one_pass_cbr(VP9_COMP *cpi) {
down_size_on = 0;
} else {
if (cpi->resize_state == ORIG &&
- (cm->width * 3 / 4 < min_width ||
- cm->height * 3 / 4 < min_height))
+ (cm->width * 3 / 4 < min_width || cm->height * 3 / 4 < min_height))
return 0;
else if (cpi->resize_state == THREE_QUARTER &&
((cpi->oxcf.width >> 1) < min_width ||
@@ -2069,33 +2005,29 @@ int vp9_resize_one_pass_cbr(VP9_COMP *cpi) {
cpi->resize_scale_den = 1;
}
tot_scale_change = (cpi->resize_scale_den * cpi->resize_scale_den) /
- (cpi->resize_scale_num * cpi->resize_scale_num);
+ (cpi->resize_scale_num * cpi->resize_scale_num);
// Reset buffer level to optimal, update target size.
rc->buffer_level = rc->optimal_buffer_level;
rc->bits_off_target = rc->optimal_buffer_level;
rc->this_frame_target = calc_pframe_target_size_one_pass_cbr(cpi);
// Get the projected qindex, based on the scaled target frame size (scaled
// so target_bits_per_mb in vp9_rc_regulate_q will be correct target).
- target_bits_per_frame = (resize_action >= 0) ?
- rc->this_frame_target * tot_scale_change :
- rc->this_frame_target / tot_scale_change;
+ target_bits_per_frame = (resize_action >= 0)
+ ? rc->this_frame_target * tot_scale_change
+ : rc->this_frame_target / tot_scale_change;
active_worst_quality = calc_active_worst_quality_one_pass_cbr(cpi);
- qindex = vp9_rc_regulate_q(cpi,
- target_bits_per_frame,
- rc->best_quality,
+ qindex = vp9_rc_regulate_q(cpi, target_bits_per_frame, rc->best_quality,
active_worst_quality);
// If resize is down, check if projected q index is close to worst_quality,
// and if so, reduce the rate correction factor (since likely can afford
// lower q for resized frame).
- if (resize_action > 0 &&
- qindex > 90 * cpi->rc.worst_quality / 100) {
+ if (resize_action > 0 && qindex > 90 * cpi->rc.worst_quality / 100) {
rc->rate_correction_factors[INTER_NORMAL] *= 0.85;
}
// If resize is back up, check if projected q index is too much above the
// current base_qindex, and if so, reduce the rate correction factor
// (since prefer to keep q for resized frame at least close to previous q).
- if (resize_action < 0 &&
- qindex > 130 * cm->base_qindex / 100) {
+ if (resize_action < 0 && qindex > 130 * cm->base_qindex / 100) {
rc->rate_correction_factors[INTER_NORMAL] *= 0.9;
}
}
@@ -2103,7 +2035,7 @@ int vp9_resize_one_pass_cbr(VP9_COMP *cpi) {
}
void adjust_gf_boost_lag_one_pass_vbr(VP9_COMP *cpi, uint64_t avg_sad_current) {
- VP9_COMMON * const cm = &cpi->common;
+ VP9_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
int target;
int found = 0;
@@ -2130,10 +2062,11 @@ void adjust_gf_boost_lag_one_pass_vbr(VP9_COMP *cpi, uint64_t avg_sad_current) {
}
// Detect up-coming scene change.
if (!found &&
- (rc->avg_source_sad[lagframe_idx] > VPXMAX(sad_thresh1,
- (unsigned int)(reference_sad << 1)) ||
- rc->avg_source_sad[lagframe_idx] > VPXMAX(3 * sad_thresh1 >> 2,
- (unsigned int)(reference_sad << 2)))) {
+ (rc->avg_source_sad[lagframe_idx] >
+ VPXMAX(sad_thresh1, (unsigned int)(reference_sad << 1)) ||
+ rc->avg_source_sad[lagframe_idx] >
+ VPXMAX(3 * sad_thresh1 >> 2,
+ (unsigned int)(reference_sad << 2)))) {
high_source_sad_lagindex = lagframe_idx;
found = 1;
}
@@ -2142,20 +2075,19 @@ void adjust_gf_boost_lag_one_pass_vbr(VP9_COMP *cpi, uint64_t avg_sad_current) {
rc->avg_source_sad[lagframe_idx - 1] > (sad_thresh1 >> 2)) {
found2 = 1;
for (i = lagframe_idx; i < tot_frames; ++i) {
- if (!(rc->avg_source_sad[i] > 0 &&
- rc->avg_source_sad[i] < (sad_thresh1 >> 2) &&
- rc->avg_source_sad[i] < (rc->avg_source_sad[lagframe_idx - 1] >> 1))) {
- found2 = 0;
- i = tot_frames;
- }
+ if (!(rc->avg_source_sad[i] > 0 &&
+ rc->avg_source_sad[i] < (sad_thresh1 >> 2) &&
+ rc->avg_source_sad[i] <
+ (rc->avg_source_sad[lagframe_idx - 1] >> 1))) {
+ found2 = 0;
+ i = tot_frames;
+ }
}
- if (found2)
- steady_sad_lagindex = lagframe_idx;
+ if (found2) steady_sad_lagindex = lagframe_idx;
}
avg_source_sad_lag += rc->avg_source_sad[lagframe_idx];
}
- if (tot_frames > 0)
- avg_source_sad_lag = avg_source_sad_lag / tot_frames;
+ if (tot_frames > 0) avg_source_sad_lag = avg_source_sad_lag / tot_frames;
// Constrain distance between detected scene cuts.
if (high_source_sad_lagindex != -1 &&
high_source_sad_lagindex != rc->high_source_sad_lagindex - 1 &&
@@ -2165,20 +2097,18 @@ void adjust_gf_boost_lag_one_pass_vbr(VP9_COMP *cpi, uint64_t avg_sad_current) {
rc->high_source_sad_lagindex = high_source_sad_lagindex;
// Adjust some factors for the next GF group, ignore initial key frame,
// and only for lag_in_frames not too small.
- if (cpi->refresh_golden_frame == 1 &&
- cm->frame_type != KEY_FRAME &&
- cm->current_video_frame > 30 &&
- cpi->oxcf.lag_in_frames > 8) {
+ if (cpi->refresh_golden_frame == 1 && cm->frame_type != KEY_FRAME &&
+ cm->current_video_frame > 30 && cpi->oxcf.lag_in_frames > 8) {
int frame_constraint;
if (rc->rolling_target_bits > 0)
rate_err =
- (double)rc->rolling_actual_bits / (double)rc->rolling_target_bits;
+ (double)rc->rolling_actual_bits / (double)rc->rolling_target_bits;
high_content = high_source_sad_lagindex != -1 ||
- avg_source_sad_lag > (rc->prev_avg_source_sad_lag << 1) ||
- avg_source_sad_lag > sad_thresh2;
+ avg_source_sad_lag > (rc->prev_avg_source_sad_lag << 1) ||
+ avg_source_sad_lag > sad_thresh2;
low_content = high_source_sad_lagindex == -1 &&
- ((avg_source_sad_lag < (rc->prev_avg_source_sad_lag >> 1)) ||
- (avg_source_sad_lag < sad_thresh1));
+ ((avg_source_sad_lag < (rc->prev_avg_source_sad_lag >> 1)) ||
+ (avg_source_sad_lag < sad_thresh1));
if (low_content) {
rc->gfu_boost = DEFAULT_GF_BOOST;
rc->baseline_gf_interval =
@@ -2210,8 +2140,7 @@ void adjust_gf_boost_lag_one_pass_vbr(VP9_COMP *cpi, uint64_t avg_sad_current) {
}
if (low_content && rc->avg_frame_low_motion > 80) {
rc->af_ratio_onepass_vbr = 15;
- }
- else if (high_content || rc->avg_frame_low_motion < 30) {
+ } else if (high_content || rc->avg_frame_low_motion < 30) {
rc->af_ratio_onepass_vbr = 5;
rc->gfu_boost = DEFAULT_GF_BOOST >> 2;
}
@@ -2234,13 +2163,13 @@ void adjust_gf_boost_lag_one_pass_vbr(VP9_COMP *cpi, uint64_t avg_sad_current) {
// This function also handles special case of lag_in_frames, to measure content
// level in #future frames set by the lag_in_frames.
void vp9_avg_source_sad(VP9_COMP *cpi) {
- VP9_COMMON * const cm = &cpi->common;
+ VP9_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
rc->high_source_sad = 0;
if (cpi->Last_Source != NULL &&
cpi->Last_Source->y_width == cpi->Source->y_width &&
cpi->Last_Source->y_height == cpi->Source->y_height) {
- YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS] = {NULL};
+ YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS] = { NULL };
uint8_t *src_y = cpi->Source->y_buffer;
int src_ystride = cpi->Source->y_stride;
uint8_t *last_src_y = cpi->Last_Source->y_buffer;
@@ -2256,43 +2185,44 @@ void vp9_avg_source_sad(VP9_COMP *cpi) {
thresh = 2.1f;
}
if (cpi->oxcf.lag_in_frames > 0) {
- frames_to_buffer = (cm->current_video_frame == 1) ?
- (int)vp9_lookahead_depth(cpi->lookahead) - 1: 2;
+ frames_to_buffer = (cm->current_video_frame == 1)
+ ? (int)vp9_lookahead_depth(cpi->lookahead) - 1
+ : 2;
start_frame = (int)vp9_lookahead_depth(cpi->lookahead) - 1;
for (frame = 0; frame < frames_to_buffer; ++frame) {
const int lagframe_idx = start_frame - frame;
if (lagframe_idx >= 0) {
- struct lookahead_entry *buf = vp9_lookahead_peek(cpi->lookahead,
- lagframe_idx);
+ struct lookahead_entry *buf =
+ vp9_lookahead_peek(cpi->lookahead, lagframe_idx);
frames[frame] = &buf->img;
}
}
// The avg_sad for this current frame is the value of frame#1
// (first future frame) from previous frame.
avg_sad_current = rc->avg_source_sad[1];
- if (avg_sad_current > VPXMAX(min_thresh,
- (unsigned int)(rc->avg_source_sad[0] * thresh)) &&
+ if (avg_sad_current >
+ VPXMAX(min_thresh,
+ (unsigned int)(rc->avg_source_sad[0] * thresh)) &&
cm->current_video_frame > (unsigned int)cpi->oxcf.lag_in_frames)
rc->high_source_sad = 1;
else
rc->high_source_sad = 0;
// Update recursive average for current frame.
if (avg_sad_current > 0)
- rc->avg_source_sad[0] = (3 * rc->avg_source_sad[0] +
- avg_sad_current) >> 2;
+ rc->avg_source_sad[0] =
+ (3 * rc->avg_source_sad[0] + avg_sad_current) >> 2;
// Shift back data, starting at frame#1.
for (frame = 1; frame < cpi->oxcf.lag_in_frames - 1; ++frame)
rc->avg_source_sad[frame] = rc->avg_source_sad[frame + 1];
}
for (frame = 0; frame < frames_to_buffer; ++frame) {
if (cpi->oxcf.lag_in_frames == 0 ||
- (frames[frame] != NULL &&
- frames[frame + 1] != NULL &&
+ (frames[frame] != NULL && frames[frame + 1] != NULL &&
frames[frame]->y_width == frames[frame + 1]->y_width &&
frames[frame]->y_height == frames[frame + 1]->y_height)) {
int sbi_row, sbi_col;
- const int lagframe_idx = (cpi->oxcf.lag_in_frames == 0) ? 0 :
- start_frame - frame + 1;
+ const int lagframe_idx =
+ (cpi->oxcf.lag_in_frames == 0) ? 0 : start_frame - frame + 1;
const BLOCK_SIZE bsize = BLOCK_64X64;
// Loop over sub-sample of frame, compute average sad over 64x64 blocks.
uint64_t avg_sad = 0;
@@ -2311,11 +2241,9 @@ void vp9_avg_source_sad(VP9_COMP *cpi) {
if ((sbi_row > 0 && sbi_col > 0) &&
(sbi_row < sb_rows - 1 && sbi_col < sb_cols - 1) &&
((sbi_row % 2 == 0 && sbi_col % 2 == 0) ||
- (sbi_row % 2 != 0 && sbi_col % 2 != 0))) {
+ (sbi_row % 2 != 0 && sbi_col % 2 != 0))) {
num_samples++;
- avg_sad += cpi->fn_ptr[bsize].sdf(src_y,
- src_ystride,
- last_src_y,
+ avg_sad += cpi->fn_ptr[bsize].sdf(src_y, src_ystride, last_src_y,
last_src_ystride);
}
src_y += 64;
@@ -2324,16 +2252,16 @@ void vp9_avg_source_sad(VP9_COMP *cpi) {
src_y += (src_ystride << 6) - (sb_cols << 6);
last_src_y += (last_src_ystride << 6) - (sb_cols << 6);
}
- if (num_samples > 0)
- avg_sad = avg_sad / num_samples;
+ if (num_samples > 0) avg_sad = avg_sad / num_samples;
// Set high_source_sad flag if we detect very high increase in avg_sad
// between current and previous frame value(s). Use minimum threshold
// for cases where there is small change from content that is completely
// static.
if (lagframe_idx == 0) {
- if (avg_sad > VPXMAX(min_thresh,
- (unsigned int)(rc->avg_source_sad[0] * thresh)) &&
- rc->frames_since_key > 1)
+ if (avg_sad >
+ VPXMAX(min_thresh,
+ (unsigned int)(rc->avg_source_sad[0] * thresh)) &&
+ rc->frames_since_key > 1)
rc->high_source_sad = 1;
else
rc->high_source_sad = 0;
@@ -2345,17 +2273,15 @@ void vp9_avg_source_sad(VP9_COMP *cpi) {
}
}
// For VBR, under scene change/high content change, force golden refresh.
- if (cpi->oxcf.rc_mode == VPX_VBR &&
- cm->frame_type != KEY_FRAME &&
- rc->high_source_sad &&
- rc->frames_to_key > 3 &&
+ if (cpi->oxcf.rc_mode == VPX_VBR && cm->frame_type != KEY_FRAME &&
+ rc->high_source_sad && rc->frames_to_key > 3 &&
rc->count_last_scene_change > 4 &&
cpi->ext_refresh_frame_flags_pending == 0) {
int target;
cpi->refresh_golden_frame = 1;
rc->gfu_boost = DEFAULT_GF_BOOST >> 1;
- rc->baseline_gf_interval = VPXMIN(20,
- VPXMAX(10, rc->baseline_gf_interval));
+ rc->baseline_gf_interval =
+ VPXMIN(20, VPXMAX(10, rc->baseline_gf_interval));
adjust_gfint_frame_constraint(cpi, rc->frames_to_key);
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
target = calc_pframe_target_size_one_pass_vbr(cpi);
@@ -2372,15 +2298,12 @@ void vp9_avg_source_sad(VP9_COMP *cpi) {
// Test if encoded frame will significantly overshoot the target bitrate, and
// if so, set the QP, reset/adjust some rate control parameters, and return 1.
-int vp9_encodedframe_overshoot(VP9_COMP *cpi,
- int frame_size,
- int *q) {
- VP9_COMMON * const cm = &cpi->common;
+int vp9_encodedframe_overshoot(VP9_COMP *cpi, int frame_size, int *q) {
+ VP9_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
int thresh_qp = 3 * (rc->worst_quality >> 2);
int thresh_rate = rc->avg_frame_bandwidth * 10;
- if (cm->base_qindex < thresh_qp &&
- frame_size > thresh_rate) {
+ if (cm->base_qindex < thresh_qp && frame_size > thresh_rate) {
double rate_correction_factor =
cpi->rc.rate_correction_factors[INTER_NORMAL];
const int target_size = cpi->rc.avg_frame_bandwidth;
@@ -2430,8 +2353,7 @@ int vp9_encodedframe_overshoot(VP9_COMP *cpi,
lrc->bits_off_target = rc->optimal_buffer_level;
lrc->rc_1_frame = 0;
lrc->rc_2_frame = 0;
- lrc->rate_correction_factors[INTER_NORMAL] =
- rate_correction_factor;
+ lrc->rate_correction_factors[INTER_NORMAL] = rate_correction_factor;
}
}
return 1;