}
#if CONFIG_FP_MB_STATS
-static void output_fpmb_stats(uint8_t *this_frame_mb_stats, VP9_COMMON *cm,
- struct vpx_codec_pkt_list *pktlist) {
+static void output_fpmb_stats(uint8_t *this_frame_mb_stats,
+ VP10_COMMON *cm,
+ struct vpx_codec_pkt_list *pktlist) {
struct vpx_codec_cx_pkt pkt;
pkt.kind = VPX_CODEC_FPMB_STATS_PKT;
pkt.data.firstpass_mb_stats.buf = this_frame_mb_stats;
// bars and partially discounts other 0 energy areas.
#define MIN_ACTIVE_AREA 0.5
#define MAX_ACTIVE_AREA 1.0
-static double calculate_active_area(const VP9_COMP *cpi,
+static double calculate_active_area(const VP10_COMP *cpi,
const FIRSTPASS_STATS *this_frame)
{
double active_pct;
// Calculate a modified Error used in distributing bits between easier and
// harder frames.
#define ACT_AREA_CORRECTION 0.5
-static double calculate_modified_err(const VP9_COMP *cpi,
+static double calculate_modified_err(const VP10_COMP *cpi,
const TWO_PASS *twopass,
- const VP9EncoderConfig *oxcf,
+ const VP10EncoderConfig *oxcf,
const FIRSTPASS_STATS *this_frame) {
const FIRSTPASS_STATS *const stats = &twopass->total_stats;
const double av_weight = stats->weight / stats->count;
// This function returns the maximum target rate per frame.
static int frame_max_bits(const RATE_CONTROL *rc,
- const VP9EncoderConfig *oxcf) {
+ const VP10EncoderConfig *oxcf) {
int64_t max_bits = ((int64_t)rc->avg_frame_bandwidth *
(int64_t)oxcf->two_pass_vbrmax_section) / 100;
if (max_bits < 0)
return (int)max_bits;
}
-void vp10_init_first_pass(VP9_COMP *cpi) {
+void vp10_init_first_pass(VP10_COMP *cpi) {
zero_stats(&cpi->twopass.total_stats);
}
-void vp10_end_first_pass(VP9_COMP *cpi) {
+void vp10_end_first_pass(VP10_COMP *cpi) {
if (is_two_pass_svc(cpi)) {
int i;
for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
// Refine the motion search range according to the frame dimension
// for first pass test.
-static int get_search_range(const VP9_COMP *cpi) {
+static int get_search_range(const VP10_COMP *cpi) {
int sr = 0;
- const int dim = MIN(cpi->initial_width, cpi->initial_height);
+ const int dim = VPXMIN(cpi->initial_width, cpi->initial_height);
while ((dim << sr) < MAX_FULL_PEL_VAL)
++sr;
return sr;
}
-static void first_pass_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
+static void first_pass_motion_search(VP10_COMP *cpi, MACROBLOCK *x,
const MV *ref_mv, MV *best_mv,
int *best_motion_err) {
MACROBLOCKD *const xd = &x->e_mbd;
}
}
-static BLOCK_SIZE get_bsize(const VP9_COMMON *cm, int mb_row, int mb_col) {
+static BLOCK_SIZE get_bsize(const VP10_COMMON *cm, int mb_row, int mb_col) {
if (2 * mb_col + 1 < cm->mi_cols) {
return 2 * mb_row + 1 < cm->mi_rows ? BLOCK_16X16
: BLOCK_16X8;
return i;
}
-static void set_first_pass_params(VP9_COMP *cpi) {
- VP9_COMMON *const cm = &cpi->common;
+static void set_first_pass_params(VP10_COMP *cpi) {
+ VP10_COMMON *const cm = &cpi->common;
if (!cpi->refresh_alt_ref_frame &&
(cm->current_video_frame == 0 ||
(cpi->frame_flags & FRAMEFLAGS_KEY))) {
#define UL_INTRA_THRESH 50
#define INVALID_ROW -1
-void vp10_first_pass(VP9_COMP *cpi, const struct lookahead_entry *source) {
+void vp10_first_pass(VP10_COMP *cpi, const struct lookahead_entry *source) {
int mb_row, mb_col;
MACROBLOCK *const x = &cpi->td.mb;
- VP9_COMMON *const cm = &cpi->common;
+ VP10_COMMON *const cm = &cpi->common;
MACROBLOCKD *const xd = &x->e_mbd;
TileInfo tile;
struct macroblock_plane *const p = x->plane;
// Exclude any image dead zone
if (image_data_start_row > 0) {
intra_skip_count =
- MAX(0, intra_skip_count - (image_data_start_row * cm->mb_cols * 2));
+ VPXMAX(0, intra_skip_count - (image_data_start_row * cm->mb_cols * 2));
}
{
++twopass->sr_update_lag;
}
- vp9_extend_frame_borders(new_yv12);
+ vpx_extend_frame_borders(new_yv12);
if (lc != NULL) {
vp10_update_reference_frames(cpi);
// Adjustment based on actual quantizer to power term.
const double power_term =
- MIN(vp10_convert_qindex_to_q(q, bit_depth) * 0.01 + pt_low, pt_high);
+ VPXMIN(vp10_convert_qindex_to_q(q, bit_depth) * 0.01 + pt_low, pt_high);
// Calculate correction factor.
if (power_term < 1.0)
// increased size and hence coding cost of motion vectors.
#define EDIV_SIZE_FACTOR 800
-static int get_twopass_worst_quality(const VP9_COMP *cpi,
+static int get_twopass_worst_quality(const VP10_COMP *cpi,
const double section_err,
double inactive_zone,
int section_target_bandwidth,
double group_weight_factor) {
const RATE_CONTROL *const rc = &cpi->rc;
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *const oxcf = &cpi->oxcf;
inactive_zone = fclamp(inactive_zone, 0.0, 1.0);
} else {
const int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE)
? cpi->initial_mbs : cpi->common.MBs;
- const int active_mbs = MAX(1, num_mbs - (int)(num_mbs * inactive_zone));
+ const int active_mbs = VPXMAX(1, num_mbs - (int)(num_mbs * inactive_zone));
const double av_err_per_mb = section_err / active_mbs;
const double speed_term = 1.0 + 0.04 * oxcf->speed;
const double ediv_size_correction = (double)num_mbs / EDIV_SIZE_FACTOR;
// Restriction on active max q for constrained quality mode.
if (cpi->oxcf.rc_mode == VPX_CQ)
- q = MAX(q, oxcf->cq_level);
+ q = VPXMAX(q, oxcf->cq_level);
return q;
}
}
-static void setup_rf_level_maxq(VP9_COMP *cpi) {
+static void setup_rf_level_maxq(VP10_COMP *cpi) {
int i;
RATE_CONTROL *const rc = &cpi->rc;
for (i = INTER_NORMAL; i < RATE_FACTOR_LEVELS; ++i) {
int qdelta = vp10_frame_type_qdelta(cpi, i, rc->worst_quality);
- rc->rf_level_maxq[i] = MAX(rc->worst_quality + qdelta, rc->best_quality);
+ rc->rf_level_maxq[i] = VPXMAX(rc->worst_quality + qdelta, rc->best_quality);
}
}
-void vp10_init_subsampling(VP9_COMP *cpi) {
- const VP9_COMMON *const cm = &cpi->common;
+void vp10_init_subsampling(VP10_COMP *cpi) {
+ const VP10_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
const int w = cm->width;
const int h = cm->height;
setup_rf_level_maxq(cpi);
}
-void vp10_calculate_coded_size(VP9_COMP *cpi,
+void vp10_calculate_coded_size(VP10_COMP *cpi,
int *scaled_frame_width,
int *scaled_frame_height) {
RATE_CONTROL *const rc = &cpi->rc;
*scaled_frame_height = rc->frame_height[rc->frame_size_selector];
}
-void vp10_init_second_pass(VP9_COMP *cpi) {
+void vp10_init_second_pass(VP10_COMP *cpi) {
SVC *const svc = &cpi->svc;
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *const oxcf = &cpi->oxcf;
const int is_two_pass_svc = (svc->number_spatial_layers > 1) ||
(svc->number_temporal_layers > 1);
TWO_PASS *const twopass = is_two_pass_svc ?
#define LOW_SR_DIFF_TRHESH 0.1
#define SR_DIFF_MAX 128.0
-static double get_sr_decay_rate(const VP9_COMP *cpi,
+static double get_sr_decay_rate(const VP10_COMP *cpi,
const FIRSTPASS_STATS *frame) {
const int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE)
? cpi->initial_mbs : cpi->common.MBs;
if ((sr_diff > LOW_SR_DIFF_TRHESH)) {
- sr_diff = MIN(sr_diff, SR_DIFF_MAX);
+ sr_diff = VPXMIN(sr_diff, SR_DIFF_MAX);
sr_decay = 1.0 - (SR_DIFF_PART * sr_diff) -
(MOTION_AMP_PART * motion_amplitude_factor) -
(INTRA_PART * modified_pcnt_intra);
}
- return MAX(sr_decay, MIN(DEFAULT_DECAY_LIMIT, modified_pct_inter));
+ return VPXMAX(sr_decay, VPXMIN(DEFAULT_DECAY_LIMIT, modified_pct_inter));
}
// This function gives an estimate of how badly we believe the prediction
// quality is decaying from frame to frame.
-static double get_zero_motion_factor(const VP9_COMP *cpi,
+static double get_zero_motion_factor(const VP10_COMP *cpi,
const FIRSTPASS_STATS *frame) {
const double zero_motion_pct = frame->pcnt_inter -
frame->pcnt_motion;
double sr_decay = get_sr_decay_rate(cpi, frame);
- return MIN(sr_decay, zero_motion_pct);
+ return VPXMIN(sr_decay, zero_motion_pct);
}
#define ZM_POWER_FACTOR 0.75
-static double get_prediction_decay_rate(const VP9_COMP *cpi,
+static double get_prediction_decay_rate(const VP10_COMP *cpi,
const FIRSTPASS_STATS *next_frame) {
const double sr_decay_rate = get_sr_decay_rate(cpi, next_frame);
const double zero_motion_factor =
(0.95 * pow((next_frame->pcnt_inter - next_frame->pcnt_motion),
ZM_POWER_FACTOR));
- return MAX(zero_motion_factor,
- (sr_decay_rate + ((1.0 - sr_decay_rate) * zero_motion_factor)));
+ return VPXMAX(zero_motion_factor,
+ (sr_decay_rate + ((1.0 - sr_decay_rate) * zero_motion_factor)));
}
// Function to test for a condition where a complex transition is followed
// by a static section. For example in slide shows where there is a fade
// between slides. This is to help with more optimal kf and gf positioning.
-static int detect_transition_to_still(VP9_COMP *cpi,
+static int detect_transition_to_still(VP10_COMP *cpi,
int frame_interval, int still_interval,
double loop_decay_rate,
double last_decay_rate) {
}
#define BASELINE_ERR_PER_MB 1000.0
-static double calc_frame_boost(VP9_COMP *cpi,
+static double calc_frame_boost(VP10_COMP *cpi,
const FIRSTPASS_STATS *this_frame,
double this_frame_mv_in_out,
double max_boost) {
const double lq =
vp10_convert_qindex_to_q(cpi->rc.avg_frame_qindex[INTER_FRAME],
cpi->common.bit_depth);
- const double boost_q_correction = MIN((0.5 + (lq * 0.015)), 1.5);
+ const double boost_q_correction = VPXMIN((0.5 + (lq * 0.015)), 1.5);
int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE)
? cpi->initial_mbs : cpi->common.MBs;
// Correct for any inactive region in the image
- num_mbs = (int)MAX(1, num_mbs * calculate_active_area(cpi, this_frame));
+ num_mbs = (int)VPXMAX(1, num_mbs * calculate_active_area(cpi, this_frame));
// Underlying boost factor is based on inter error ratio.
frame_boost = (BASELINE_ERR_PER_MB * num_mbs) /
else
frame_boost += frame_boost * (this_frame_mv_in_out / 2.0);
- return MIN(frame_boost, max_boost * boost_q_correction);
+ return VPXMIN(frame_boost, max_boost * boost_q_correction);
}
-static int calc_arf_boost(VP9_COMP *cpi, int offset,
+static int calc_arf_boost(VP10_COMP *cpi, int offset,
int f_frames, int b_frames,
int *f_boost, int *b_boost) {
TWO_PASS *const twopass = &cpi->twopass;
arf_boost = (*f_boost + *b_boost);
if (arf_boost < ((b_frames + f_frames) * 20))
arf_boost = ((b_frames + f_frames) * 20);
- arf_boost = MAX(arf_boost, MIN_ARF_GF_BOOST);
+ arf_boost = VPXMAX(arf_boost, MIN_ARF_GF_BOOST);
return arf_boost;
}
}
// Calculate the total bits to allocate in this GF/ARF group.
-static int64_t calculate_total_gf_group_bits(VP9_COMP *cpi,
+static int64_t calculate_total_gf_group_bits(VP10_COMP *cpi,
double gf_group_err) {
const RATE_CONTROL *const rc = &cpi->rc;
const TWO_PASS *const twopass = &cpi->twopass;
}
// Calculate the number of extra bits for use in the boosted frame or frames.
- return MAX((int)(((int64_t)boost * total_group_bits) / allocation_chunks), 0);
+ return VPXMAX((int)(((int64_t)boost * total_group_bits) / allocation_chunks),
+ 0);
}
// Current limit on maximum number of active arfs in a GF/ARF group.
arf_buffer_indices[1] = ARF_SLOT2;
}
-static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits,
+static void allocate_gf_group_bits(VP10_COMP *cpi, int64_t gf_group_bits,
double group_error, int gf_arf_bits) {
RATE_CONTROL *const rc = &cpi->rc;
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *const oxcf = &cpi->oxcf;
TWO_PASS *const twopass = &cpi->twopass;
GF_GROUP *const gf_group = &twopass->gf_group;
FIRSTPASS_STATS frame_stats;
gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[arf_idx];
target_frame_size = clamp(target_frame_size, 0,
- MIN(max_bits, (int)total_group_bits));
+ VPXMIN(max_bits, (int)total_group_bits));
gf_group->update_type[frame_index] = LF_UPDATE;
gf_group->rf_level[frame_index] = INTER_NORMAL;
}
// Analyse and define a gf/arf group.
-static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
- VP9_COMMON *const cm = &cpi->common;
+static void define_gf_group(VP10_COMP *cpi, FIRSTPASS_STATS *this_frame) {
+ VP10_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
- VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ VP10EncoderConfig *const oxcf = &cpi->oxcf;
TWO_PASS *const twopass = &cpi->twopass;
FIRSTPASS_STATS next_frame;
const FIRSTPASS_STATS *const start_pos = twopass->stats_in;
int int_lbq =
(int)(vp10_convert_qindex_to_q(rc->last_boosted_qindex,
cpi->common.bit_depth));
- active_min_gf_interval = rc->min_gf_interval + MIN(2, int_max_q / 200);
+ active_min_gf_interval = rc->min_gf_interval + VPXMIN(2, int_max_q / 200);
if (active_min_gf_interval > rc->max_gf_interval)
active_min_gf_interval = rc->max_gf_interval;
// bits to spare and are better with a smaller interval and smaller boost.
// At high Q when there are few bits to spare we are better with a longer
// interval to spread the cost of the GF.
- active_max_gf_interval = 12 + MIN(4, (int_lbq / 6));
+ active_max_gf_interval = 12 + VPXMIN(4, (int_lbq / 6));
if (active_max_gf_interval < active_min_gf_interval)
active_max_gf_interval = active_min_gf_interval;
decay_accumulator = decay_accumulator * loop_decay_rate;
// Monitor for static sections.
- zero_motion_accumulator =
- MIN(zero_motion_accumulator, get_zero_motion_factor(cpi, &next_frame));
+ zero_motion_accumulator = VPXMIN(
+ zero_motion_accumulator, get_zero_motion_factor(cpi, &next_frame));
// Break clause to detect very still sections after motion. For example,
// a static image after a fade or other transition.
(cpi->multi_arf_allowed && (rc->baseline_gf_interval >= 6) &&
(zero_motion_accumulator < 0.995)) ? 1 : 0;
} else {
- rc->gfu_boost = MAX((int)boost_score, MIN_ARF_GF_BOOST);
+ rc->gfu_boost = VPXMAX((int)boost_score, MIN_ARF_GF_BOOST);
rc->source_alt_ref_pending = 0;
}
// rc factor is a weight factor that corrects for local rate control drift.
double rc_factor = 1.0;
if (rc->rate_error_estimate > 0) {
- rc_factor = MAX(RC_FACTOR_MIN,
- (double)(100 - rc->rate_error_estimate) / 100.0);
+ rc_factor = VPXMAX(RC_FACTOR_MIN,
+ (double)(100 - rc->rate_error_estimate) / 100.0);
} else {
- rc_factor = MIN(RC_FACTOR_MAX,
- (double)(100 - rc->rate_error_estimate) / 100.0);
+ rc_factor = VPXMIN(RC_FACTOR_MAX,
+ (double)(100 - rc->rate_error_estimate) / 100.0);
}
tmp_q =
get_twopass_worst_quality(cpi, group_av_err,
vbr_group_bits_per_frame,
twopass->kfgroup_inter_fraction * rc_factor);
twopass->active_worst_quality =
- MAX(tmp_q, twopass->active_worst_quality >> 1);
+ VPXMAX(tmp_q, twopass->active_worst_quality >> 1);
}
#endif
return is_viable_kf;
}
-static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
+static void find_next_key_frame(VP10_COMP *cpi, FIRSTPASS_STATS *this_frame) {
int i, j;
RATE_CONTROL *const rc = &cpi->rc;
TWO_PASS *const twopass = &cpi->twopass;
GF_GROUP *const gf_group = &twopass->gf_group;
- const VP9EncoderConfig *const oxcf = &cpi->oxcf;
+ const VP10EncoderConfig *const oxcf = &cpi->oxcf;
const FIRSTPASS_STATS first_frame = *this_frame;
const FIRSTPASS_STATS *const start_position = twopass->stats_in;
FIRSTPASS_STATS next_frame;
} else {
twopass->kf_group_bits = 0;
}
- twopass->kf_group_bits = MAX(0, twopass->kf_group_bits);
+ twopass->kf_group_bits = VPXMAX(0, twopass->kf_group_bits);
// Reset the first pass file position.
reset_fpf_position(twopass, start_position);
break;
// Monitor for static sections.
- zero_motion_accumulator =
- MIN(zero_motion_accumulator,
- get_zero_motion_factor(cpi, &next_frame));
+ zero_motion_accumulator = VPXMIN(
+ zero_motion_accumulator, get_zero_motion_factor(cpi, &next_frame));
// Not all frames in the group are necessarily used in calculating boost.
if ((i <= rc->max_gf_interval) ||
const double loop_decay_rate =
get_prediction_decay_rate(cpi, &next_frame);
decay_accumulator *= loop_decay_rate;
- decay_accumulator = MAX(decay_accumulator, MIN_DECAY_FACTOR);
+ decay_accumulator = VPXMAX(decay_accumulator, MIN_DECAY_FACTOR);
av_decay_accumulator += decay_accumulator;
++loop_decay_counter;
}
// Apply various clamps for min and max boost
rc->kf_boost = (int)(av_decay_accumulator * boost_score);
- rc->kf_boost = MAX(rc->kf_boost, (rc->frames_to_key * 3));
- rc->kf_boost = MAX(rc->kf_boost, MIN_KF_BOOST);
+ rc->kf_boost = VPXMAX(rc->kf_boost, (rc->frames_to_key * 3));
+ rc->kf_boost = VPXMAX(rc->kf_boost, MIN_KF_BOOST);
// Work out how many bits to allocate for the key frame itself.
kf_bits = calculate_boost_bits((rc->frames_to_key - 1),
}
// Define the reference buffers that will be updated post encode.
-static void configure_buffer_updates(VP9_COMP *cpi) {
+static void configure_buffer_updates(VP10_COMP *cpi) {
TWO_PASS *const twopass = &cpi->twopass;
cpi->rc.is_src_frame_alt_ref = 0;
}
}
-static int is_skippable_frame(const VP9_COMP *cpi) {
+static int is_skippable_frame(const VP10_COMP *cpi) {
// If the current frame does not have non-zero motion vector detected in the
// first pass, and so do its previous and forward frames, then this frame
// can be skipped for partition check, and the partition size is assigned
twopass->stats_in->pcnt_inter - twopass->stats_in->pcnt_motion == 1);
}
-void vp10_rc_get_second_pass_params(VP9_COMP *cpi) {
- VP9_COMMON *const cm = &cpi->common;
+void vp10_rc_get_second_pass_params(VP10_COMP *cpi) {
+ VP10_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
TWO_PASS *const twopass = &cpi->twopass;
GF_GROUP *const gf_group = &twopass->gf_group;
#define MINQ_ADJ_LIMIT 48
#define MINQ_ADJ_LIMIT_CQ 20
#define HIGH_UNDERSHOOT_RATIO 2
-void vp10_twopass_postencode_update(VP9_COMP *cpi) {
+void vp10_twopass_postencode_update(VP10_COMP *cpi) {
TWO_PASS *const twopass = &cpi->twopass;
RATE_CONTROL *const rc = &cpi->rc;
const int bits_used = rc->base_frame_target;
// is designed to prevent extreme behaviour at the end of a clip
// or group of frames.
rc->vbr_bits_off_target += rc->base_frame_target - rc->projected_frame_size;
- twopass->bits_left = MAX(twopass->bits_left - bits_used, 0);
+ twopass->bits_left = VPXMAX(twopass->bits_left - bits_used, 0);
// Calculate the pct rc error.
if (rc->total_actual_bits) {
twopass->kf_group_bits -= bits_used;
twopass->last_kfgroup_zeromotion_pct = twopass->kf_zeromotion_pct;
}
- twopass->kf_group_bits = MAX(twopass->kf_group_bits, 0);
+ twopass->kf_group_bits = VPXMAX(twopass->kf_group_bits, 0);
// Increment the gf group index ready for the next frame.
++twopass->gf_group.index;
rc->vbr_bits_off_target_fast +=
fast_extra_thresh - rc->projected_frame_size;
rc->vbr_bits_off_target_fast =
- MIN(rc->vbr_bits_off_target_fast, (4 * rc->avg_frame_bandwidth));
+ VPXMIN(rc->vbr_bits_off_target_fast, (4 * rc->avg_frame_bandwidth));
// Fast adaptation of minQ if necessary to use up the extra bits.
if (rc->avg_frame_bandwidth) {
twopass->extend_minq_fast =
(int)(rc->vbr_bits_off_target_fast * 8 / rc->avg_frame_bandwidth);
}
- twopass->extend_minq_fast = MIN(twopass->extend_minq_fast,
- minq_adj_limit - twopass->extend_minq);
+ twopass->extend_minq_fast = VPXMIN(
+ twopass->extend_minq_fast, minq_adj_limit - twopass->extend_minq);
} else if (rc->vbr_bits_off_target_fast) {
- twopass->extend_minq_fast = MIN(twopass->extend_minq_fast,
- minq_adj_limit - twopass->extend_minq);
+ twopass->extend_minq_fast = VPXMIN(
+ twopass->extend_minq_fast, minq_adj_limit - twopass->extend_minq);
} else {
twopass->extend_minq_fast = 0;
}