static int get_minq_index(double maxq, double x3, double x2, double x1,
vpx_bit_depth_t bit_depth) {
int i;
- const double minqtarget = MIN(((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.
vpx_bit_depth_t bit_depth) {
const int bpm = (int)(vp10_rc_bits_per_mb(frame_type, q, correction_factor,
bit_depth));
- return MAX(FRAME_OVERHEAD_BITS,
- (int)((uint64_t)bpm * mbs) >> BPER_MB_NORMBITS);
+ return VPXMAX(FRAME_OVERHEAD_BITS,
+ (int)((uint64_t)bpm * mbs) >> BPER_MB_NORMBITS);
}
-int vp10_rc_clamp_pframe_target_size(const VP9_COMP *const cpi, int target) {
+int vp10_rc_clamp_pframe_target_size(const VP10_COMP *const cpi, int target) {
const RATE_CONTROL *rc = &cpi->rc;
- const VP9EncoderConfig *oxcf = &cpi->oxcf;
- const int min_frame_target = MAX(rc->min_frame_bandwidth,
- rc->avg_frame_bandwidth >> 5);
+ const VP10EncoderConfig *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;
if (cpi->refresh_golden_frame && rc->is_src_frame_alt_ref) {
if (oxcf->rc_max_inter_bitrate_pct) {
const int max_rate = rc->avg_frame_bandwidth *
oxcf->rc_max_inter_bitrate_pct / 100;
- target = MIN(target, max_rate);
+ target = VPXMIN(target, max_rate);
}
return target;
}
-int vp10_rc_clamp_iframe_target_size(const VP9_COMP *const cpi, int target) {
+int vp10_rc_clamp_iframe_target_size(const VP10_COMP *const cpi, int target) {
const RATE_CONTROL *rc = &cpi->rc;
- const VP9EncoderConfig *oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *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;
- target = MIN(target, max_rate);
+ target = VPXMIN(target, max_rate);
}
if (target > rc->max_frame_bandwidth)
target = rc->max_frame_bandwidth;
return target;
}
-// Update the buffer level for higher temporal layers, given the encoded current
-// temporal layer.
-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);
- 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);
- lrc->bits_off_target += bits_off_for_this_layer;
-
- // Clip buffer level to maximum buffer size for the layer.
- lrc->bits_off_target = MIN(lrc->bits_off_target, lrc->maximum_buffer_size);
- lrc->buffer_level = lrc->bits_off_target;
- }
-}
-
// Update the buffer level: leaky bucket model.
-static void update_buffer_level(VP9_COMP *cpi, int encoded_frame_size) {
+static void update_buffer_level(VP10_COMP *cpi, int encoded_frame_size) {
const VP10_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
}
// Clip the buffer level to the maximum specified buffer size.
- rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size);
+ rc->bits_off_target = VPXMIN(rc->bits_off_target, rc->maximum_buffer_size);
rc->buffer_level = rc->bits_off_target;
-
- if (is_one_pass_cbr_svc(cpi)) {
- update_layer_buffer_level(&cpi->svc, encoded_frame_size);
- }
}
int vp10_rc_get_default_min_gf_interval(
if (factor <= factor_safe)
return default_interval;
else
- return MAX(default_interval,
- (int)(MIN_GF_INTERVAL * factor / factor_safe + 0.5));
+ return VPXMAX(default_interval,
+ (int)(MIN_GF_INTERVAL * factor / factor_safe + 0.5));
// Note this logic makes:
// 4K24: 5
// 4K30: 6
}
int vp10_rc_get_default_max_gf_interval(double framerate, int min_gf_interval) {
- int interval = MIN(MAX_GF_INTERVAL, (int)(framerate * 0.75));
+ int interval = VPXMIN(MAX_GF_INTERVAL, (int)(framerate * 0.75));
interval += (interval & 0x01); // Round to even value
- return MAX(interval, min_gf_interval);
+ return VPXMAX(interval, min_gf_interval);
}
-void vp10_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
+void vp10_rc_init(const VP10EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
int i;
if (pass == 0 && oxcf->rc_mode == VPX_CBR) {
rc->baseline_gf_interval = (rc->min_gf_interval + rc->max_gf_interval) / 2;
}
-int vp10_rc_drop_frame(VP9_COMP *cpi) {
- const VP9EncoderConfig *oxcf = &cpi->oxcf;
+int vp10_rc_drop_frame(VP10_COMP *cpi) {
+ const VP10EncoderConfig *oxcf = &cpi->oxcf;
RATE_CONTROL *const rc = &cpi->rc;
if (!oxcf->drop_frames_water_mark) {
}
}
-static double get_rate_correction_factor(const VP9_COMP *cpi) {
+static double get_rate_correction_factor(const VP10_COMP *cpi) {
const RATE_CONTROL *const rc = &cpi->rc;
double rcf;
rcf = rc->rate_correction_factors[rf_lvl];
} else {
if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
- !rc->is_src_frame_alt_ref && !cpi->use_svc &&
+ !rc->is_src_frame_alt_ref &&
(cpi->oxcf.rc_mode != VPX_CBR || cpi->oxcf.gf_cbr_boost_pct > 20))
rcf = rc->rate_correction_factors[GF_ARF_STD];
else
return fclamp(rcf, MIN_BPB_FACTOR, MAX_BPB_FACTOR);
}
-static void set_rate_correction_factor(VP9_COMP *cpi, double factor) {
+static void set_rate_correction_factor(VP10_COMP *cpi, double factor) {
RATE_CONTROL *const rc = &cpi->rc;
// Normalize RCF to account for the size-dependent scaling factor.
rc->rate_correction_factors[rf_lvl] = factor;
} else {
if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
- !rc->is_src_frame_alt_ref && !cpi->use_svc &&
+ !rc->is_src_frame_alt_ref &&
(cpi->oxcf.rc_mode != VPX_CBR || cpi->oxcf.gf_cbr_boost_pct > 20))
rc->rate_correction_factors[GF_ARF_STD] = factor;
else
}
}
-void vp10_rc_update_rate_correction_factors(VP9_COMP *cpi) {
+void vp10_rc_update_rate_correction_factors(VP10_COMP *cpi) {
const VP10_COMMON *const cm = &cpi->common;
int correction_factor = 100;
double rate_correction_factor = get_rate_correction_factor(cpi);
// More heavily damped adjustment used if we have been oscillating either side
// of target.
adjustment_limit = 0.25 +
- 0.5 * MIN(1, fabs(log10(0.01 * correction_factor)));
+ 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;
}
-int vp10_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame,
+int vp10_rc_regulate_q(const VP10_COMP *cpi, int target_bits_per_frame,
int active_best_quality, int active_worst_quality) {
const VP10_COMMON *const cm = &cpi->common;
int q = active_worst_quality;
i = active_best_quality;
do {
- if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
- cm->seg.enabled &&
- cpi->svc.temporal_layer_id == 0 &&
- cpi->svc.spatial_layer_id == 0) {
+ if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) {
bits_per_mb_at_this_q =
(int)vp10_cyclic_refresh_rc_bits_per_mb(cpi, i, correction_factor);
} else {
if (cpi->oxcf.rc_mode == VPX_CBR &&
(cpi->rc.rc_1_frame * cpi->rc.rc_2_frame == -1) &&
cpi->rc.q_1_frame != cpi->rc.q_2_frame) {
- q = clamp(q, MIN(cpi->rc.q_1_frame, cpi->rc.q_2_frame),
- MAX(cpi->rc.q_1_frame, cpi->rc.q_2_frame));
+ q = clamp(q, VPXMIN(cpi->rc.q_1_frame, cpi->rc.q_2_frame),
+ VPXMAX(cpi->rc.q_1_frame, cpi->rc.q_2_frame));
}
return q;
}
arfgf_low_motion_minq, arfgf_high_motion_minq);
}
-static int calc_active_worst_quality_one_pass_vbr(const VP9_COMP *cpi) {
+static int calc_active_worst_quality_one_pass_vbr(const VP10_COMP *cpi) {
const RATE_CONTROL *const rc = &cpi->rc;
const unsigned int curr_frame = cpi->common.current_video_frame;
int active_worst_quality;
: rc->last_q[INTER_FRAME] * 2;
}
}
- return MIN(active_worst_quality, rc->worst_quality);
+ return VPXMIN(active_worst_quality, rc->worst_quality);
}
// Adjust active_worst_quality level based on buffer level.
-static int calc_active_worst_quality_one_pass_cbr(const VP9_COMP *cpi) {
+static int calc_active_worst_quality_one_pass_cbr(const VP10_COMP *cpi) {
// Adjust active_worst_quality: If buffer is above the optimal/target level,
// bring active_worst_quality down depending on fullness of buffer.
// If buffer is below the optimal level, let the active_worst_quality go from
// 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 < 5) ?
- MIN(rc->avg_frame_qindex[INTER_FRAME], rc->avg_frame_qindex[KEY_FRAME]) :
- rc->avg_frame_qindex[INTER_FRAME];
- active_worst_quality = MIN(rc->worst_quality,
- ambient_qp * 5 / 4);
+ 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 / 4);
if (rc->buffer_level > rc->optimal_buffer_level) {
// Adjust down.
// Maximum limit for down adjustment, ~30%.
return active_worst_quality;
}
-static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
+static int rc_pick_q_and_bounds_one_pass_cbr(const VP10_COMP *cpi,
int *bottom_index,
int *top_index) {
const VP10_COMMON *const cm = &cpi->common;
int delta_qindex = vp10_compute_qdelta(rc, last_boosted_q,
(last_boosted_q * 0.75),
cm->bit_depth);
- active_best_quality = MAX(qindex + delta_qindex, rc->best_quality);
+ 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;
cm->bit_depth);
}
} 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
}
static int get_active_cq_level(const RATE_CONTROL *rc,
- const VP9EncoderConfig *const oxcf) {
+ const VP10EncoderConfig *const oxcf) {
static const double cq_adjust_threshold = 0.1;
int active_cq_level = oxcf->cq_level;
if (oxcf->rc_mode == VPX_CQ &&
return active_cq_level;
}
-static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
+static int rc_pick_q_and_bounds_one_pass_vbr(const VP10_COMP *cpi,
int *bottom_index,
int *top_index) {
const VP10_COMMON *const cm = &cpi->common;
const RATE_CONTROL *const rc = &cpi->rc;
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *const oxcf = &cpi->oxcf;
const int cq_level = get_active_cq_level(rc, oxcf);
int active_best_quality;
int active_worst_quality = calc_active_worst_quality_one_pass_vbr(cpi);
int delta_qindex = vp10_compute_qdelta(rc, last_boosted_q,
last_boosted_q * 0.75,
cm->bit_depth);
- active_best_quality = MAX(qindex + delta_qindex, rc->best_quality);
+ 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;
return q;
}
-int vp10_frame_type_qdelta(const VP9_COMP *cpi, int rf_level, int q) {
+int vp10_frame_type_qdelta(const VP10_COMP *cpi, int rf_level, int q) {
static const double rate_factor_deltas[RATE_FACTOR_LEVELS] = {
1.00, // INTER_NORMAL
1.00, // INTER_HIGH
}
#define STATIC_MOTION_THRESH 95
-static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
+static int rc_pick_q_and_bounds_two_pass(const VP10_COMP *cpi,
int *bottom_index,
int *top_index) {
const VP10_COMMON *const cm = &cpi->common;
const RATE_CONTROL *const rc = &cpi->rc;
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *const oxcf = &cpi->oxcf;
const GF_GROUP *gf_group = &cpi->twopass.gf_group;
const int cq_level = get_active_cq_level(rc, oxcf);
int active_best_quality;
int *inter_minq;
ASSIGN_MINQ_TABLE(cm->bit_depth, inter_minq);
- if (frame_is_intra_only(cm) || vp10_is_upper_layer_key_frame(cpi)) {
+ if (frame_is_intra_only(cm)) {
// Handle the special case for key frames forced when we have reached
// the maximum key frame interval. Here force the Q to a range
// based on the ambient Q to reduce the risk of popping.
int qindex;
if (cpi->twopass.last_kfgroup_zeromotion_pct >= STATIC_MOTION_THRESH) {
- qindex = MIN(rc->last_kf_qindex, rc->last_boosted_qindex);
+ qindex = VPXMIN(rc->last_kf_qindex, rc->last_boosted_qindex);
active_best_quality = qindex;
last_boosted_q = vp10_convert_qindex_to_q(qindex, cm->bit_depth);
delta_qindex = vp10_compute_qdelta(rc, last_boosted_q,
last_boosted_q * 1.25,
cm->bit_depth);
- active_worst_quality = MIN(qindex + delta_qindex, active_worst_quality);
-
+ active_worst_quality =
+ VPXMIN(qindex + delta_qindex, active_worst_quality);
} else {
qindex = rc->last_boosted_qindex;
last_boosted_q = vp10_convert_qindex_to_q(qindex, cm->bit_depth);
delta_qindex = vp10_compute_qdelta(rc, last_boosted_q,
last_boosted_q * 0.75,
cm->bit_depth);
- active_best_quality = MAX(qindex + delta_qindex, rc->best_quality);
+ active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
}
} else {
// Not forced keyframe.
#if LIMIT_QRANGE_FOR_ALTREF_AND_KEY
vpx_clear_system_state();
// Static forced key frames Q restrictions dealt with elsewhere.
- if (!((frame_is_intra_only(cm) || vp10_is_upper_layer_key_frame(cpi))) ||
+ if (!(frame_is_intra_only(cm)) ||
!rc->this_key_frame_forced ||
(cpi->twopass.last_kfgroup_zeromotion_pct < STATIC_MOTION_THRESH)) {
int qdelta = vp10_frame_type_qdelta(cpi, gf_group->rf_level[gf_group->index],
active_worst_quality);
- active_worst_quality = MAX(active_worst_quality + qdelta,
- active_best_quality);
+ active_worst_quality = VPXMAX(active_worst_quality + qdelta,
+ active_best_quality);
}
#endif
int qdelta = vp10_compute_qdelta_by_rate(rc, cm->frame_type,
active_best_quality, 2.0,
cm->bit_depth);
- active_best_quality = MAX(active_best_quality + qdelta, rc->best_quality);
+ active_best_quality =
+ VPXMAX(active_best_quality + qdelta, rc->best_quality);
}
active_best_quality = clamp(active_best_quality,
if (oxcf->rc_mode == VPX_Q) {
q = active_best_quality;
// Special case code to try and match quality with forced key frames.
- } else if ((frame_is_intra_only(cm) || vp10_is_upper_layer_key_frame(cpi)) &&
- rc->this_key_frame_forced) {
+ } else if (frame_is_intra_only(cm) && rc->this_key_frame_forced) {
// If static since last kf use better of last boosted and last kf q.
if (cpi->twopass.last_kfgroup_zeromotion_pct >= STATIC_MOTION_THRESH) {
- q = MIN(rc->last_kf_qindex, rc->last_boosted_qindex);
+ q = VPXMIN(rc->last_kf_qindex, rc->last_boosted_qindex);
} else {
q = rc->last_boosted_qindex;
}
return q;
}
-int vp10_rc_pick_q_and_bounds(const VP9_COMP *cpi,
+int vp10_rc_pick_q_and_bounds(const VP10_COMP *cpi,
int *bottom_index, int *top_index) {
int q;
if (cpi->oxcf.pass == 0) {
} else {
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 (q < *bottom_index)
- *bottom_index = q;
- else if (q > *top_index)
- *top_index = q;
- }
+
return q;
}
-void vp10_rc_compute_frame_size_bounds(const VP9_COMP *cpi,
+void vp10_rc_compute_frame_size_bounds(const VP10_COMP *cpi,
int frame_target,
int *frame_under_shoot_limit,
int *frame_over_shoot_limit) {
// 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 = MAX(frame_target - tolerance - 200, 0);
- *frame_over_shoot_limit = MIN(frame_target + tolerance + 200,
- cpi->rc.max_frame_bandwidth);
+ *frame_under_shoot_limit = VPXMAX(frame_target - tolerance - 200, 0);
+ *frame_over_shoot_limit = VPXMIN(frame_target + tolerance + 200,
+ cpi->rc.max_frame_bandwidth);
}
}
-void vp10_rc_set_frame_target(VP9_COMP *cpi, int target) {
+void vp10_rc_set_frame_target(VP10_COMP *cpi, int target) {
const VP10_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
(cm->width * cm->height);
}
-static void update_alt_ref_frame_stats(VP9_COMP *cpi) {
+static void update_alt_ref_frame_stats(VP10_COMP *cpi) {
// this frame refreshes means next frames don't unless specified by user
RATE_CONTROL *const rc = &cpi->rc;
rc->frames_since_golden = 0;
rc->source_alt_ref_active = 1;
}
-static void update_golden_frame_stats(VP9_COMP *cpi) {
+static void update_golden_frame_stats(VP10_COMP *cpi) {
RATE_CONTROL *const rc = &cpi->rc;
// Update the Golden frame usage counts.
}
}
-void vp10_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) {
+void vp10_rc_postencode_update(VP10_COMP *cpi, uint64_t bytes_used) {
const VP10_COMMON *const cm = &cpi->common;
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *const oxcf = &cpi->oxcf;
RATE_CONTROL *const rc = &cpi->rc;
const int qindex = cm->base_qindex;
ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2);
} else {
if (rc->is_src_frame_alt_ref ||
- !(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) ||
- (cpi->use_svc && oxcf->rc_mode == VPX_CBR)) {
+ !(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);
}
}
-void vp10_rc_postencode_update_drop_frame(VP9_COMP *cpi) {
+void vp10_rc_postencode_update_drop_frame(VP10_COMP *cpi) {
// Update buffer level with zero size, update frame counters, and return.
update_buffer_level(cpi, 0);
cpi->rc.frames_since_key++;
// Use this macro to turn on/off use of alt-refs in one-pass mode.
#define USE_ALTREF_FOR_ONE_PASS 1
-static int calc_pframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
+static int calc_pframe_target_size_one_pass_vbr(const VP10_COMP *const cpi) {
static const int af_ratio = 10;
const RATE_CONTROL *const rc = &cpi->rc;
int target;
return vp10_rc_clamp_pframe_target_size(cpi, target);
}
-static int calc_iframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
+static int calc_iframe_target_size_one_pass_vbr(const VP10_COMP *const cpi) {
static const int kf_ratio = 25;
const RATE_CONTROL *rc = &cpi->rc;
const int target = rc->avg_frame_bandwidth * kf_ratio;
return vp10_rc_clamp_iframe_target_size(cpi, target);
}
-void vp10_rc_get_one_pass_vbr_params(VP9_COMP *cpi) {
+void vp10_rc_get_one_pass_vbr_params(VP10_COMP *cpi) {
VP10_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
int target;
vp10_rc_set_frame_target(cpi, target);
}
-static int calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
- const VP9EncoderConfig *oxcf = &cpi->oxcf;
+static int calc_pframe_target_size_one_pass_cbr(const VP10_COMP *cpi) {
+ const VP10EncoderConfig *oxcf = &cpi->oxcf;
const RATE_CONTROL *rc = &cpi->rc;
- const SVC *const svc = &cpi->svc;
const int64_t diff = rc->optimal_buffer_level - rc->buffer_level;
const int64_t one_pct_bits = 1 + rc->optimal_buffer_level / 100;
- int min_frame_target = MAX(rc->avg_frame_bandwidth >> 4, FRAME_OVERHEAD_BITS);
+ int min_frame_target =
+ VPXMAX(rc->avg_frame_bandwidth >> 4, FRAME_OVERHEAD_BITS);
int target;
if (oxcf->gf_cbr_boost_pct) {
} else {
target = rc->avg_frame_bandwidth;
}
- if (is_one_pass_cbr_svc(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);
- const LAYER_CONTEXT *lc = &svc->layer_context[layer];
- target = lc->avg_frame_size;
- min_frame_target = MAX(lc->avg_frame_size >> 4, FRAME_OVERHEAD_BITS);
- }
+
if (diff > 0) {
// Lower the target bandwidth for this frame.
- const int pct_low = (int)MIN(diff / one_pct_bits, oxcf->under_shoot_pct);
+ const int pct_low = (int)VPXMIN(diff / one_pct_bits, oxcf->under_shoot_pct);
target -= (target * pct_low) / 200;
} else if (diff < 0) {
// Increase the target bandwidth for this frame.
- const int pct_high = (int)MIN(-diff / one_pct_bits, oxcf->over_shoot_pct);
+ const int pct_high =
+ (int)VPXMIN(-diff / one_pct_bits, oxcf->over_shoot_pct);
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;
- target = MIN(target, max_rate);
+ target = VPXMIN(target, max_rate);
}
- return MAX(min_frame_target, target);
+ return VPXMAX(min_frame_target, target);
}
-static int calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
+static int calc_iframe_target_size_one_pass_cbr(const VP10_COMP *cpi) {
const RATE_CONTROL *rc = &cpi->rc;
- const VP9EncoderConfig *oxcf = &cpi->oxcf;
- const SVC *const svc = &cpi->svc;
int target;
if (cpi->common.current_video_frame == 0) {
target = ((rc->starting_buffer_level / 2) > INT_MAX)
} else {
int kf_boost = 32;
double framerate = cpi->framerate;
- 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 LAYER_CONTEXT *lc = &svc->layer_context[layer];
- framerate = lc->framerate;
- }
- kf_boost = MAX(kf_boost, (int)(2 * framerate - 16));
+
+ 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));
return vp10_rc_clamp_iframe_target_size(cpi, target);
}
-// Reset information needed to set proper reference frames and buffer updates
-// for temporal layering. This is called when a key frame is encoded.
-static void reset_temporal_layer_to_zero(VP9_COMP *cpi) {
- int sl;
- LAYER_CONTEXT *lc = NULL;
- cpi->svc.temporal_layer_id = 0;
-
- for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) {
- lc = &cpi->svc.layer_context[sl * cpi->svc.number_temporal_layers];
- lc->current_video_frame_in_layer = 0;
- lc->frames_from_key_frame = 0;
- }
-}
-
-void vp10_rc_get_svc_params(VP9_COMP *cpi) {
- VP10_COMMON *const cm = &cpi->common;
- RATE_CONTROL *const rc = &cpi->rc;
- int target = rc->avg_frame_bandwidth;
- const int layer = LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id,
- cpi->svc.temporal_layer_id, cpi->svc.number_temporal_layers);
-
- if ((cm->current_video_frame == 0) ||
- (cpi->frame_flags & FRAMEFLAGS_KEY) ||
- (cpi->oxcf.auto_key && (rc->frames_since_key %
- cpi->oxcf.key_freq == 0))) {
- cm->frame_type = KEY_FRAME;
- 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);
- } else if (is_one_pass_cbr_svc(cpi)) {
- cpi->svc.layer_context[layer].is_key_frame = 1;
- reset_temporal_layer_to_zero(cpi);
- 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);
- }
- } else {
- cm->frame_type = INTER_FRAME;
- if (is_two_pass_svc(cpi)) {
- LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
- if (cpi->svc.spatial_layer_id == 0) {
- lc->is_key_frame = 0;
- } 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);
- }
- cpi->ref_frame_flags &= (~VP9_ALT_FLAG);
- } else if (is_one_pass_cbr_svc(cpi)) {
- LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
- if (cpi->svc.spatial_layer_id == 0) {
- lc->is_key_frame = 0;
- } else {
- lc->is_key_frame =
- cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame;
- }
- target = calc_pframe_target_size_one_pass_cbr(cpi);
- }
- }
-
- // Any update/change of global cyclic refresh parameters (amount/delta-qp)
- // should be done here, before the frame qp is selected.
- if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
- vp10_cyclic_refresh_update_parameters(cpi);
-
- vp10_rc_set_frame_target(cpi, target);
- rc->frames_till_gf_update_due = INT_MAX;
- rc->baseline_gf_interval = INT_MAX;
-}
-
-void vp10_rc_get_one_pass_cbr_params(VP9_COMP *cpi) {
+void vp10_rc_get_one_pass_cbr_params(VP10_COMP *cpi) {
VP10_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
int target;
return target_index - qindex;
}
-void vp10_rc_set_gf_interval_range(const VP9_COMP *const cpi,
+void vp10_rc_set_gf_interval_range(const VP10_COMP *const cpi,
RATE_CONTROL *const rc) {
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *const oxcf = &cpi->oxcf;
// Set Maximum gf/arf interval
rc->max_gf_interval = oxcf->max_gf_interval;
rc->max_gf_interval = rc->static_scene_max_gf_interval;
// Clamp min to max
- rc->min_gf_interval = MIN(rc->min_gf_interval, rc->max_gf_interval);
+ rc->min_gf_interval = VPXMIN(rc->min_gf_interval, rc->max_gf_interval);
}
-void vp10_rc_update_framerate(VP9_COMP *cpi) {
+void vp10_rc_update_framerate(VP10_COMP *cpi) {
const VP10_COMMON *const cm = &cpi->common;
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *const oxcf = &cpi->oxcf;
RATE_CONTROL *const rc = &cpi->rc;
int vbr_max_bits;
rc->min_frame_bandwidth = (int)(rc->avg_frame_bandwidth *
oxcf->two_pass_vbrmin_section / 100);
- rc->min_frame_bandwidth = MAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS);
+ rc->min_frame_bandwidth =
+ VPXMAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS);
// A maximum bitrate for a frame is defined.
// The baseline for this aligns with HW implementations that
// specifies lossless encode.
vbr_max_bits = (int)(((int64_t)rc->avg_frame_bandwidth *
oxcf->two_pass_vbrmax_section) / 100);
- rc->max_frame_bandwidth = MAX(MAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P),
- vbr_max_bits);
+ rc->max_frame_bandwidth =
+ VPXMAX(VPXMAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P), vbr_max_bits);
vp10_rc_set_gf_interval_range(cpi, rc);
}
#define VBR_PCT_ADJUSTMENT_LIMIT 50
// For VBR...adjustment to the frame target based on error from previous frames
-static void vbr_rate_correction(VP9_COMP *cpi, int *this_frame_target) {
+static void vbr_rate_correction(VP10_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;
// Dont do it for kf,arf,gf or overlay frames.
if (!frame_is_kf_gf_arf(cpi) && !rc->is_src_frame_alt_ref &&
rc->vbr_bits_off_target_fast) {
- int one_frame_bits = MAX(rc->avg_frame_bandwidth, *this_frame_target);
+ int one_frame_bits = VPXMAX(rc->avg_frame_bandwidth, *this_frame_target);
int fast_extra_bits;
- fast_extra_bits =
- (int)MIN(rc->vbr_bits_off_target_fast, one_frame_bits);
- fast_extra_bits = (int)MIN(fast_extra_bits,
- MAX(one_frame_bits / 8, rc->vbr_bits_off_target_fast / 8));
+ fast_extra_bits = (int)VPXMIN(rc->vbr_bits_off_target_fast, one_frame_bits);
+ fast_extra_bits = (int)VPXMIN(
+ fast_extra_bits,
+ VPXMAX(one_frame_bits / 8, rc->vbr_bits_off_target_fast / 8));
*this_frame_target += (int)fast_extra_bits;
rc->vbr_bits_off_target_fast -= fast_extra_bits;
}
}
-void vp10_set_target_rate(VP9_COMP *cpi) {
+void vp10_set_target_rate(VP10_COMP *cpi) {
RATE_CONTROL *const rc = &cpi->rc;
int target_rate = rc->base_frame_target;
// Check if we should resize, based on average QP from past x frames.
// Only allow for resize at most one scale down for now, scaling factor is 2.
-int vp10_resize_one_pass_cbr(VP9_COMP *cpi) {
+int vp10_resize_one_pass_cbr(VP10_COMP *cpi) {
const VP10_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
int resize_now = 0;