Commit d17ac4fe authored by Deb Mukherjee's avatar Deb Mukherjee

Continued rate control clean-ups

Moves all post encode rate control updates to a separate function
plus other cleanups.

Change-Id: I70e8eccf666c88d8b649b969997fd84d27e4baaa
parent b60293e1
......@@ -76,6 +76,19 @@ static int select_cq_level(int qindex) {
return ret_val;
}
static int gfboost_qadjust(int qindex) {
const double q = vp9_convert_qindex_to_q(qindex);
return (int)((0.00000828 * q * q * q) +
(-0.0055 * q * q) +
(1.32 * q) + 79.3);
}
static int kfboost_qadjust(int qindex) {
const double q = vp9_convert_qindex_to_q(qindex);
return (int)((0.00000973 * q * q * q) +
(-0.00613 * q * q) +
(1.316 * q) + 121.2);
}
// Resets the first pass file to the given position using a relative seek from
// the current position.
......@@ -928,11 +941,11 @@ static int64_t estimate_modemvcost(VP9_COMP *cpi,
intra_cost = bitcost(av_intra);
// Estimate of extra bits per mv overhead for mbs
// << 9 is the normalization to the (bits * 512) used in vp9_bits_per_mb
// << 9 is the normalization to the (bits * 512) used in vp9_rc_bits_per_mb
mv_cost = ((int)(fpstats->new_mv_count / fpstats->count) * 8) << 9;
// Crude estimate of overhead cost from modes
// << 9 is the normalization to (bits * 512) used in vp9_bits_per_mb
// << 9 is the normalization to (bits * 512) used in vp9_rc_bits_per_mb
mode_cost =
(int)((((av_pct_inter - av_pct_motion) * zz_cost) +
(av_pct_motion * motion_cost) +
......@@ -1052,8 +1065,8 @@ static int estimate_max_q(VP9_COMP *cpi,
sr_correction * speed_correction *
cpi->twopass.est_max_qcorrection_factor;
bits_per_mb_at_this_q = vp9_bits_per_mb(INTER_FRAME, q,
err_correction_factor);
bits_per_mb_at_this_q = vp9_rc_bits_per_mb(INTER_FRAME, q,
err_correction_factor);
if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
break;
......@@ -1140,7 +1153,7 @@ static int estimate_cq(VP9_COMP *cpi,
sr_correction * speed_correction * clip_iifactor;
bits_per_mb_at_this_q =
vp9_bits_per_mb(INTER_FRAME, q, err_correction_factor);
vp9_rc_bits_per_mb(INTER_FRAME, q, err_correction_factor);
if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
break;
......@@ -1936,7 +1949,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
int q = cpi->rc.last_q[INTER_FRAME];
int gf_bits;
int boost = (cpi->rc.gfu_boost * vp9_gfboost_qadjust(q)) / 100;
int boost = (cpi->rc.gfu_boost * gfboost_qadjust(q)) / 100;
// Set max and minimum boost and hence minimum allocation
boost = clamp(boost, 125, (cpi->rc.baseline_gf_interval + 1) * 200);
......@@ -2728,3 +2741,21 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// sizes.
cpi->twopass.modified_error_left -= kf_group_err;
}
void vp9_twopass_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) {
#ifdef DISABLE_RC_LONG_TERM_MEM
cpi->twopass.bits_left -= cpi->rc.this_frame_target;
#else
cpi->twopass.bits_left -= 8 * bytes_used;
#endif
if (!cpi->refresh_alt_ref_frame) {
double lower_bounds_min_rate = FRAME_OVERHEAD_BITS * cpi->oxcf.framerate;
double two_pass_min_rate = (double)(cpi->oxcf.target_bandwidth *
cpi->oxcf.two_pass_vbrmin_section
/ 100);
if (two_pass_min_rate < lower_bounds_min_rate)
two_pass_min_rate = lower_bounds_min_rate;
cpi->twopass.bits_left += (int64_t)(two_pass_min_rate /
cpi->oxcf.framerate);
}
}
This diff is collapsed.
......@@ -30,7 +30,6 @@
#include "vp9/encoder/vp9_lookahead.h"
#define DISABLE_RC_LONG_TERM_MEM 0
// #define MODE_TEST_HIT_STATS
// #define SPEEDSTATS 1
......
This diff is collapsed.
......@@ -20,24 +20,41 @@ void vp9_save_coding_context(VP9_COMP *cpi);
void vp9_restore_coding_context(VP9_COMP *cpi);
void vp9_setup_key_frame(VP9_COMP *cpi);
void vp9_update_rate_correction_factors(VP9_COMP *cpi, int damp_var);
int vp9_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame);
void vp9_adjust_key_frame_context(VP9_COMP *cpi);
void vp9_compute_frame_size_bounds(VP9_COMP *cpi,
int *frame_under_shoot_limit,
int *frame_over_shoot_limit);
void vp9_setup_inter_frame(VP9_COMP *cpi);
void vp9_init_minq_luts(void);
double vp9_convert_qindex_to_q(int qindex);
// return of 0 means drop frame
int vp9_pick_frame_size(VP9_COMP *cpi);
// Updates rate correction factors
void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi, int damp_var);
double vp9_convert_qindex_to_q(int qindex);
int vp9_gfboost_qadjust(int qindex);
int vp9_bits_per_mb(FRAME_TYPE frame_type, int qindex,
double correction_factor);
void vp9_setup_inter_frame(VP9_COMP *cpi);
int vp9_pick_q_and_adjust_q_bounds(VP9_COMP *cpi,
int * bottom_index, int * top_index);
// initialize luts for minq
void vp9_rc_init_minq_luts(void);
// return of 0 means drop frame
// Changes rc.this_frame_target and rc.sb64_rate_target
int vp9_rc_pick_frame_size_and_bounds(VP9_COMP *cpi,
int *frame_under_shoot_limit,
int *frame_over_shoot_limit);
// Picks q and q bounds given the target for bits
int vp9_rc_pick_q_and_adjust_q_bounds(VP9_COMP *cpi,
int * bottom_index,
int * top_index);
// Estimates q to achieve a target bits per frame
int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame);
// Post encode update of the rate control parameters based
// on bytes used and q used for the frame
void vp9_rc_postencode_update(VP9_COMP *cpi,
uint64_t bytes_used,
int q_used);
// estimates bits per mb for a given qindex and correction factor
int vp9_rc_bits_per_mb(FRAME_TYPE frame_type, int qindex,
double correction_factor);
// Post encode update of the rate control parameters for 2-pass
void vp9_twopass_postencode_update(VP9_COMP *cpi,
uint64_t bytes_used);
#endif // VP9_ENCODER_VP9_RATECTRL_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment