summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kovalev <dkovalev@google.com>2014-04-11 14:08:16 -0700
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2014-04-11 14:08:16 -0700
commit6653bf71782963236632132fe96961a492fba0eb (patch)
treed6e495c6a2abfebf0c392825ff89b49eced8377f
parentbec3e3e3807ac0ddbfb843410ca04bf06cc666c6 (diff)
parent1ff4aa33de9c66882a5fdb422bd1c7f77597c7c7 (diff)
downloadlibvpx-6653bf71782963236632132fe96961a492fba0eb.tar
libvpx-6653bf71782963236632132fe96961a492fba0eb.tar.gz
libvpx-6653bf71782963236632132fe96961a492fba0eb.tar.bz2
libvpx-6653bf71782963236632132fe96961a492fba0eb.zip
Merge "Adding RD_OPT struct."
-rw-r--r--vp9/encoder/vp9_encodeframe.c52
-rw-r--r--vp9/encoder/vp9_onyx_if.c152
-rw-r--r--vp9/encoder/vp9_onyx_int.h56
-rw-r--r--vp9/encoder/vp9_pickmode.c4
-rw-r--r--vp9/encoder/vp9_rdopt.c92
5 files changed, 185 insertions, 171 deletions
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c
index 34ea88ccb..83c6a33c7 100644
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -243,8 +243,8 @@ static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile,
vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col);
// R/D setup.
- x->rddiv = cpi->RDDIV;
- x->rdmult = cpi->RDMULT;
+ x->rddiv = cpi->rd.RDDIV;
+ x->rdmult = cpi->rd.RDMULT;
// Setup segment ID.
if (seg->enabled) {
@@ -819,6 +819,7 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
int output_enabled) {
int i, x_idx, y;
VP9_COMMON *const cm = &cpi->common;
+ RD_OPT *const rd_opt = &cpi->rd;
MACROBLOCK *const x = &cpi->mb;
MACROBLOCKD *const xd = &x->e_mbd;
struct macroblock_plane *const p = x->plane;
@@ -904,7 +905,7 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
for (i = 0; i < TX_MODES; i++)
- cpi->rd_tx_select_diff[i] += ctx->tx_rd_diff[i];
+ rd_opt->tx_select_diff[i] += ctx->tx_rd_diff[i];
}
#if CONFIG_INTERNAL_STATS
@@ -937,12 +938,12 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
}
}
- cpi->rd_comp_pred_diff[SINGLE_REFERENCE] += ctx->single_pred_diff;
- cpi->rd_comp_pred_diff[COMPOUND_REFERENCE] += ctx->comp_pred_diff;
- cpi->rd_comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff;
+ rd_opt->comp_pred_diff[SINGLE_REFERENCE] += ctx->single_pred_diff;
+ rd_opt->comp_pred_diff[COMPOUND_REFERENCE] += ctx->comp_pred_diff;
+ rd_opt->comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff;
for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
- cpi->rd_filter_diff[i] += ctx->best_filter_diff[i];
+ rd_opt->filter_diff[i] += ctx->best_filter_diff[i];
}
}
@@ -2658,9 +2659,10 @@ static TX_MODE select_tx_mode(const VP9_COMP *cpi) {
if (cpi->sf.tx_size_search_method == USE_LARGESTALL) {
return ALLOW_32X32;
} else if (cpi->sf.tx_size_search_method == USE_FULL_RD) {
+ const RD_OPT *const rd_opt = &cpi->rd;
const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi);
- return cpi->rd_tx_select_threshes[frame_type][ALLOW_32X32] >
- cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ?
+ return rd_opt->tx_select_threshes[frame_type][ALLOW_32X32] >
+ rd_opt->tx_select_threshes[frame_type][TX_MODE_SELECT] ?
ALLOW_32X32 : TX_MODE_SELECT;
} else {
unsigned int total = 0;
@@ -3224,6 +3226,7 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, const TileInfo *const tile,
static void encode_frame_internal(VP9_COMP *cpi) {
SPEED_FEATURES *const sf = &cpi->sf;
+ RD_OPT *const rd_opt = &cpi->rd;
MACROBLOCK *const x = &cpi->mb;
VP9_COMMON *const cm = &cpi->common;
MACROBLOCKD *const xd = &x->e_mbd;
@@ -3234,10 +3237,10 @@ static void encode_frame_internal(VP9_COMP *cpi) {
vp9_zero(cm->counts);
vp9_zero(cpi->coef_counts);
vp9_zero(cpi->tx_stepdown_count);
- vp9_zero(cpi->rd_comp_pred_diff);
- vp9_zero(cpi->rd_filter_diff);
- vp9_zero(cpi->rd_tx_select_diff);
- vp9_zero(cpi->rd_tx_select_threshes);
+ vp9_zero(rd_opt->comp_pred_diff);
+ vp9_zero(rd_opt->filter_diff);
+ vp9_zero(rd_opt->tx_select_diff);
+ vp9_zero(rd_opt->tx_select_threshes);
cm->tx_mode = select_tx_mode(cpi);
@@ -3356,6 +3359,7 @@ static void encode_frame_internal(VP9_COMP *cpi) {
void vp9_encode_frame(VP9_COMP *cpi) {
VP9_COMMON *const cm = &cpi->common;
+ RD_OPT *const rd_opt = &cpi->rd;
// In the longer term the encoder should be generalized to match the
// decoder such that we allow compound where one of the 3 buffers has a
@@ -3388,8 +3392,8 @@ void vp9_encode_frame(VP9_COMP *cpi) {
// that for subsequent frames.
// It does the same analysis for transform size selection also.
const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi);
- const int64_t *mode_thresh = cpi->rd_prediction_type_threshes[frame_type];
- const int64_t *filter_thresh = cpi->rd_filter_threshes[frame_type];
+ const int64_t *mode_thresh = rd_opt->prediction_type_threshes[frame_type];
+ const int64_t *filter_thresh = rd_opt->filter_threshes[frame_type];
/* prediction (compound, single or hybrid) mode selection */
if (frame_type == ALTREF_FRAME || !cm->allow_comp_inter_inter)
@@ -3422,25 +3426,25 @@ void vp9_encode_frame(VP9_COMP *cpi) {
encode_frame_internal(cpi);
for (i = 0; i < REFERENCE_MODES; ++i) {
- const int diff = (int) (cpi->rd_comp_pred_diff[i] / cm->MBs);
- cpi->rd_prediction_type_threshes[frame_type][i] += diff;
- cpi->rd_prediction_type_threshes[frame_type][i] >>= 1;
+ const int diff = (int) (rd_opt->comp_pred_diff[i] / cm->MBs);
+ rd_opt->prediction_type_threshes[frame_type][i] += diff;
+ rd_opt->prediction_type_threshes[frame_type][i] >>= 1;
}
for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
- const int64_t diff = cpi->rd_filter_diff[i] / cm->MBs;
- cpi->rd_filter_threshes[frame_type][i] =
- (cpi->rd_filter_threshes[frame_type][i] + diff) / 2;
+ const int64_t diff = rd_opt->filter_diff[i] / cm->MBs;
+ rd_opt->filter_threshes[frame_type][i] =
+ (rd_opt->filter_threshes[frame_type][i] + diff) / 2;
}
for (i = 0; i < TX_MODES; ++i) {
- int64_t pd = cpi->rd_tx_select_diff[i];
+ int64_t pd = rd_opt->tx_select_diff[i];
int diff;
if (i == TX_MODE_SELECT)
pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, 2048 * (TX_SIZES - 1), 0);
diff = (int) (pd / cm->MBs);
- cpi->rd_tx_select_threshes[frame_type][i] += diff;
- cpi->rd_tx_select_threshes[frame_type][i] /= 2;
+ rd_opt->tx_select_threshes[frame_type][i] += diff;
+ rd_opt->tx_select_threshes[frame_type][i] /= 2;
}
if (cm->reference_mode == REFERENCE_MODE_SELECT) {
diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c
index 871d057c1..721ce48bb 100644
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -386,117 +386,119 @@ static int is_slowest_mode(int mode) {
static void set_rd_speed_thresholds(VP9_COMP *cpi) {
int i;
+ RD_OPT *const rd = &cpi->rd;
// Set baseline threshold values
for (i = 0; i < MAX_MODES; ++i)
- cpi->rd_thresh_mult[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0;
-
- cpi->rd_thresh_mult[THR_NEARESTMV] = 0;
- cpi->rd_thresh_mult[THR_NEARESTG] = 0;
- cpi->rd_thresh_mult[THR_NEARESTA] = 0;
-
- cpi->rd_thresh_mult[THR_DC] += 1000;
-
- cpi->rd_thresh_mult[THR_NEWMV] += 1000;
- cpi->rd_thresh_mult[THR_NEWA] += 1000;
- cpi->rd_thresh_mult[THR_NEWG] += 1000;
-
- cpi->rd_thresh_mult[THR_NEARMV] += 1000;
- cpi->rd_thresh_mult[THR_NEARA] += 1000;
- cpi->rd_thresh_mult[THR_COMP_NEARESTLA] += 1000;
- cpi->rd_thresh_mult[THR_COMP_NEARESTGA] += 1000;
-
- cpi->rd_thresh_mult[THR_TM] += 1000;
-
- cpi->rd_thresh_mult[THR_COMP_NEARLA] += 1500;
- cpi->rd_thresh_mult[THR_COMP_NEWLA] += 2000;
- cpi->rd_thresh_mult[THR_NEARG] += 1000;
- cpi->rd_thresh_mult[THR_COMP_NEARGA] += 1500;
- cpi->rd_thresh_mult[THR_COMP_NEWGA] += 2000;
-
- cpi->rd_thresh_mult[THR_ZEROMV] += 2000;
- cpi->rd_thresh_mult[THR_ZEROG] += 2000;
- cpi->rd_thresh_mult[THR_ZEROA] += 2000;
- cpi->rd_thresh_mult[THR_COMP_ZEROLA] += 2500;
- cpi->rd_thresh_mult[THR_COMP_ZEROGA] += 2500;
-
- cpi->rd_thresh_mult[THR_H_PRED] += 2000;
- cpi->rd_thresh_mult[THR_V_PRED] += 2000;
- cpi->rd_thresh_mult[THR_D45_PRED ] += 2500;
- cpi->rd_thresh_mult[THR_D135_PRED] += 2500;
- cpi->rd_thresh_mult[THR_D117_PRED] += 2500;
- cpi->rd_thresh_mult[THR_D153_PRED] += 2500;
- cpi->rd_thresh_mult[THR_D207_PRED] += 2500;
- cpi->rd_thresh_mult[THR_D63_PRED] += 2500;
+ rd->thresh_mult[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0;
+
+ rd->thresh_mult[THR_NEARESTMV] = 0;
+ rd->thresh_mult[THR_NEARESTG] = 0;
+ rd->thresh_mult[THR_NEARESTA] = 0;
+
+ rd->thresh_mult[THR_DC] += 1000;
+
+ rd->thresh_mult[THR_NEWMV] += 1000;
+ rd->thresh_mult[THR_NEWA] += 1000;
+ rd->thresh_mult[THR_NEWG] += 1000;
+
+ rd->thresh_mult[THR_NEARMV] += 1000;
+ rd->thresh_mult[THR_NEARA] += 1000;
+ rd->thresh_mult[THR_COMP_NEARESTLA] += 1000;
+ rd->thresh_mult[THR_COMP_NEARESTGA] += 1000;
+
+ rd->thresh_mult[THR_TM] += 1000;
+
+ rd->thresh_mult[THR_COMP_NEARLA] += 1500;
+ rd->thresh_mult[THR_COMP_NEWLA] += 2000;
+ rd->thresh_mult[THR_NEARG] += 1000;
+ rd->thresh_mult[THR_COMP_NEARGA] += 1500;
+ rd->thresh_mult[THR_COMP_NEWGA] += 2000;
+
+ rd->thresh_mult[THR_ZEROMV] += 2000;
+ rd->thresh_mult[THR_ZEROG] += 2000;
+ rd->thresh_mult[THR_ZEROA] += 2000;
+ rd->thresh_mult[THR_COMP_ZEROLA] += 2500;
+ rd->thresh_mult[THR_COMP_ZEROGA] += 2500;
+
+ rd->thresh_mult[THR_H_PRED] += 2000;
+ rd->thresh_mult[THR_V_PRED] += 2000;
+ rd->thresh_mult[THR_D45_PRED ] += 2500;
+ rd->thresh_mult[THR_D135_PRED] += 2500;
+ rd->thresh_mult[THR_D117_PRED] += 2500;
+ rd->thresh_mult[THR_D153_PRED] += 2500;
+ rd->thresh_mult[THR_D207_PRED] += 2500;
+ rd->thresh_mult[THR_D63_PRED] += 2500;
/* disable frame modes if flags not set */
if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) {
- cpi->rd_thresh_mult[THR_NEWMV ] = INT_MAX;
- cpi->rd_thresh_mult[THR_NEARESTMV] = INT_MAX;
- cpi->rd_thresh_mult[THR_ZEROMV ] = INT_MAX;
- cpi->rd_thresh_mult[THR_NEARMV ] = INT_MAX;
+ rd->thresh_mult[THR_NEWMV ] = INT_MAX;
+ rd->thresh_mult[THR_NEARESTMV] = INT_MAX;
+ rd->thresh_mult[THR_ZEROMV ] = INT_MAX;
+ rd->thresh_mult[THR_NEARMV ] = INT_MAX;
}
if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) {
- cpi->rd_thresh_mult[THR_NEARESTG ] = INT_MAX;
- cpi->rd_thresh_mult[THR_ZEROG ] = INT_MAX;
- cpi->rd_thresh_mult[THR_NEARG ] = INT_MAX;
- cpi->rd_thresh_mult[THR_NEWG ] = INT_MAX;
+ rd->thresh_mult[THR_NEARESTG ] = INT_MAX;
+ rd->thresh_mult[THR_ZEROG ] = INT_MAX;
+ rd->thresh_mult[THR_NEARG ] = INT_MAX;
+ rd->thresh_mult[THR_NEWG ] = INT_MAX;
}
if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) {
- cpi->rd_thresh_mult[THR_NEARESTA ] = INT_MAX;
- cpi->rd_thresh_mult[THR_ZEROA ] = INT_MAX;
- cpi->rd_thresh_mult[THR_NEARA ] = INT_MAX;
- cpi->rd_thresh_mult[THR_NEWA ] = INT_MAX;
+ rd->thresh_mult[THR_NEARESTA ] = INT_MAX;
+ rd->thresh_mult[THR_ZEROA ] = INT_MAX;
+ rd->thresh_mult[THR_NEARA ] = INT_MAX;
+ rd->thresh_mult[THR_NEWA ] = INT_MAX;
}
if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) !=
(VP9_LAST_FLAG | VP9_ALT_FLAG)) {
- cpi->rd_thresh_mult[THR_COMP_ZEROLA ] = INT_MAX;
- cpi->rd_thresh_mult[THR_COMP_NEARESTLA] = INT_MAX;
- cpi->rd_thresh_mult[THR_COMP_NEARLA ] = INT_MAX;
- cpi->rd_thresh_mult[THR_COMP_NEWLA ] = INT_MAX;
+ rd->thresh_mult[THR_COMP_ZEROLA ] = INT_MAX;
+ rd->thresh_mult[THR_COMP_NEARESTLA] = INT_MAX;
+ rd->thresh_mult[THR_COMP_NEARLA ] = INT_MAX;
+ rd->thresh_mult[THR_COMP_NEWLA ] = INT_MAX;
}
if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) !=
(VP9_GOLD_FLAG | VP9_ALT_FLAG)) {
- cpi->rd_thresh_mult[THR_COMP_ZEROGA ] = INT_MAX;
- cpi->rd_thresh_mult[THR_COMP_NEARESTGA] = INT_MAX;
- cpi->rd_thresh_mult[THR_COMP_NEARGA ] = INT_MAX;
- cpi->rd_thresh_mult[THR_COMP_NEWGA ] = INT_MAX;
+ rd->thresh_mult[THR_COMP_ZEROGA ] = INT_MAX;
+ rd->thresh_mult[THR_COMP_NEARESTGA] = INT_MAX;
+ rd->thresh_mult[THR_COMP_NEARGA ] = INT_MAX;
+ rd->thresh_mult[THR_COMP_NEWGA ] = INT_MAX;
}
}
static void set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) {
const SPEED_FEATURES *const sf = &cpi->sf;
+ RD_OPT *const rd = &cpi->rd;
int i;
for (i = 0; i < MAX_REFS; ++i)
- cpi->rd_thresh_mult_sub8x8[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0;
+ rd->thresh_mult_sub8x8[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0;
- cpi->rd_thresh_mult_sub8x8[THR_LAST] += 2500;
- cpi->rd_thresh_mult_sub8x8[THR_GOLD] += 2500;
- cpi->rd_thresh_mult_sub8x8[THR_ALTR] += 2500;
- cpi->rd_thresh_mult_sub8x8[THR_INTRA] += 2500;
- cpi->rd_thresh_mult_sub8x8[THR_COMP_LA] += 4500;
- cpi->rd_thresh_mult_sub8x8[THR_COMP_GA] += 4500;
+ rd->thresh_mult_sub8x8[THR_LAST] += 2500;
+ rd->thresh_mult_sub8x8[THR_GOLD] += 2500;
+ rd->thresh_mult_sub8x8[THR_ALTR] += 2500;
+ rd->thresh_mult_sub8x8[THR_INTRA] += 2500;
+ rd->thresh_mult_sub8x8[THR_COMP_LA] += 4500;
+ rd->thresh_mult_sub8x8[THR_COMP_GA] += 4500;
// Check for masked out split cases.
for (i = 0; i < MAX_REFS; i++)
if (sf->disable_split_mask & (1 << i))
- cpi->rd_thresh_mult_sub8x8[i] = INT_MAX;
+ rd->thresh_mult_sub8x8[i] = INT_MAX;
// disable mode test if frame flag is not set
if (!(cpi->ref_frame_flags & VP9_LAST_FLAG))
- cpi->rd_thresh_mult_sub8x8[THR_LAST] = INT_MAX;
+ rd->thresh_mult_sub8x8[THR_LAST] = INT_MAX;
if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG))
- cpi->rd_thresh_mult_sub8x8[THR_GOLD] = INT_MAX;
+ rd->thresh_mult_sub8x8[THR_GOLD] = INT_MAX;
if (!(cpi->ref_frame_flags & VP9_ALT_FLAG))
- cpi->rd_thresh_mult_sub8x8[THR_ALTR] = INT_MAX;
+ rd->thresh_mult_sub8x8[THR_ALTR] = INT_MAX;
if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) !=
(VP9_LAST_FLAG | VP9_ALT_FLAG))
- cpi->rd_thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX;
+ rd->thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX;
if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) !=
(VP9_GOLD_FLAG | VP9_ALT_FLAG))
- cpi->rd_thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX;
+ rd->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX;
}
static void set_speed_features(VP9_COMP *cpi) {
@@ -1276,9 +1278,9 @@ VP9_COMP *vp9_create_compressor(VP9_CONFIG *oxcf) {
// Default rd threshold factors for mode selection
for (i = 0; i < BLOCK_SIZES; ++i) {
for (j = 0; j < MAX_MODES; ++j)
- cpi->rd_thresh_freq_fact[i][j] = 32;
+ cpi->rd.thresh_freq_fact[i][j] = 32;
for (j = 0; j < MAX_REFS; ++j)
- cpi->rd_thresh_freq_sub8x8[i][j] = 32;
+ cpi->rd.thresh_freq_sub8x8[i][j] = 32;
}
#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SVFHH, SVFHV, SVFHHV, \
@@ -2537,7 +2539,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
vp9_clear_system_state();
- vp9_zero(cpi->rd_tx_select_threshes);
+ vp9_zero(cpi->rd.tx_select_threshes);
#if CONFIG_VP9_POSTPROC
if (cpi->oxcf.noise_sensitivity > 0) {
diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h
index 126711e02..9ad6ae49e 100644
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -185,6 +185,7 @@ typedef enum {
AQ_MODE_COUNT // This should always be the last member of the enum
} AQ_MODE;
+
typedef struct VP9_CONFIG {
BITSTREAM_PROFILE profile;
BIT_DEPTH bit_depth;
@@ -281,6 +282,35 @@ typedef struct VP9_CONFIG {
vp8e_tuning tuning;
} VP9_CONFIG;
+
+typedef struct RD_OPT {
+ // Thresh_mult is used to set a threshold for the rd score. A higher value
+ // means that we will accept the best mode so far more often. This number
+ // is used in combination with the current block size, and thresh_freq_fact
+ // to pick a threshold.
+ int thresh_mult[MAX_MODES];
+ int thresh_mult_sub8x8[MAX_REFS];
+
+ int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
+ int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
+ int thresh_sub8x8[MAX_SEGMENTS][BLOCK_SIZES][MAX_REFS];
+ int thresh_freq_sub8x8[BLOCK_SIZES][MAX_REFS];
+
+ int64_t comp_pred_diff[REFERENCE_MODES];
+ int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES];
+ int64_t tx_select_diff[TX_MODES];
+ // FIXME(rbultje) can this overflow?
+ int tx_select_threshes[MAX_REF_FRAMES][TX_MODES];
+
+ int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS];
+ int64_t filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS];
+ int64_t filter_cache[SWITCHABLE_FILTER_CONTEXTS];
+ int64_t mask_filter;
+
+ int RDMULT;
+ int RDDIV;
+} RD_OPT;
+
typedef struct VP9_COMP {
QUANTS quants;
MACROBLOCK mb;
@@ -343,31 +373,7 @@ typedef struct VP9_COMP {
// Ambient reconstruction err target for force key frames
int ambient_err;
- // Thresh_mult is used to set a threshold for the rd score. A higher value
- // means that we will accept the best mode so far more often. This number
- // is used in combination with the current block size, and thresh_freq_fact
- // to pick a threshold.
- int rd_thresh_mult[MAX_MODES];
- int rd_thresh_mult_sub8x8[MAX_REFS];
-
- int rd_threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
- int rd_thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
- int rd_thresh_sub8x8[MAX_SEGMENTS][BLOCK_SIZES][MAX_REFS];
- int rd_thresh_freq_sub8x8[BLOCK_SIZES][MAX_REFS];
-
- int64_t rd_comp_pred_diff[REFERENCE_MODES];
- int64_t rd_prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES];
- int64_t rd_tx_select_diff[TX_MODES];
- // FIXME(rbultje) can this overflow?
- int rd_tx_select_threshes[MAX_REF_FRAMES][TX_MODES];
-
- int64_t rd_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
- int64_t rd_filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS];
- int64_t rd_filter_cache[SWITCHABLE_FILTER_CONTEXTS];
- int64_t mask_filter_rd;
-
- int RDMULT;
- int RDDIV;
+ RD_OPT rd;
CODING_CONTEXT coding_context;
diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c
index f3fe99cdb..3d398edc9 100644
--- a/vp9/encoder/vp9_pickmode.c
+++ b/vp9/encoder/vp9_pickmode.c
@@ -233,8 +233,8 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
const int64_t intra_mode_cost = 50;
unsigned char segment_id = mbmi->segment_id;
- const int *const rd_threshes = cpi->rd_threshes[segment_id][bsize];
- const int *const rd_thresh_freq_fact = cpi->rd_thresh_freq_fact[bsize];
+ const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize];
+ const int *const rd_thresh_freq_fact = cpi->rd.thresh_freq_fact[bsize];
// Mode index conversion form THR_MODES to MB_PREDICTION_MODE for a ref frame.
int mode_idx[MB_MODE_COUNT] = {0};
INTERP_FILTER filter_ref = SWITCHABLE;
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index c81d9f922..d498f4c7f 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -245,6 +245,7 @@ void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) {
static void set_block_thresholds(VP9_COMP *cpi) {
const VP9_COMMON *const cm = &cpi->common;
+ RD_OPT *const rd = &cpi->rd;
int i, bsize, segment_id;
for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) {
@@ -260,14 +261,14 @@ static void set_block_thresholds(VP9_COMP *cpi) {
const int thresh_max = INT_MAX / t;
for (i = 0; i < MAX_MODES; ++i)
- cpi->rd_threshes[segment_id][bsize][i] =
- cpi->rd_thresh_mult[i] < thresh_max ? cpi->rd_thresh_mult[i] * t / 4
+ rd->threshes[segment_id][bsize][i] =
+ rd->thresh_mult[i] < thresh_max ? rd->thresh_mult[i] * t / 4
: INT_MAX;
for (i = 0; i < MAX_REFS; ++i) {
- cpi->rd_thresh_sub8x8[segment_id][bsize][i] =
- cpi->rd_thresh_mult_sub8x8[i] < thresh_max
- ? cpi->rd_thresh_mult_sub8x8[i] * t / 4
+ rd->thresh_sub8x8[segment_id][bsize][i] =
+ rd->thresh_mult_sub8x8[i] < thresh_max
+ ? rd->thresh_mult_sub8x8[i] * t / 4
: INT_MAX;
}
}
@@ -281,10 +282,10 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi) {
vp9_clear_system_state();
- cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128)
- cpi->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q);
+ cpi->rd.RDDIV = RDDIV_BITS; // in bits (to multiply D by 128)
+ cpi->rd.RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q);
- x->errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO;
+ x->errorperbit = cpi->rd.RDMULT / RD_MULT_EPB_RATIO;
x->errorperbit += (x->errorperbit == 0);
x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL &&
@@ -2697,6 +2698,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
int64_t *psse,
const int64_t ref_best_rd) {
VP9_COMMON *cm = &cpi->common;
+ RD_OPT *rd_opt = &cpi->rd;
MACROBLOCKD *xd = &x->e_mbd;
MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
const int is_comp_pred = has_second_ref(mbmi);
@@ -2794,14 +2796,13 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
// Search for best switchable filter by checking the variance of
// pred error irrespective of whether the filter will be used
- cpi->mask_filter_rd = 0;
+ rd_opt->mask_filter = 0;
for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
- cpi->rd_filter_cache[i] = INT64_MAX;
+ rd_opt->filter_cache[i] = INT64_MAX;
if (cm->interp_filter != BILINEAR) {
*best_filter = EIGHTTAP;
- if (x->source_variance <
- cpi->sf.disable_filter_search_var_thresh) {
+ if (x->source_variance < cpi->sf.disable_filter_search_var_thresh) {
*best_filter = EIGHTTAP;
} else {
int newbest;
@@ -2817,12 +2818,12 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
if (i > 0 && intpel_mv) {
rd = RDCOST(x->rdmult, x->rddiv, tmp_rate_sum, tmp_dist_sum);
- cpi->rd_filter_cache[i] = rd;
- cpi->rd_filter_cache[SWITCHABLE_FILTERS] =
- MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], rd + rs_rd);
+ rd_opt->filter_cache[i] = rd;
+ rd_opt->filter_cache[SWITCHABLE_FILTERS] =
+ MIN(rd_opt->filter_cache[SWITCHABLE_FILTERS], rd + rs_rd);
if (cm->interp_filter == SWITCHABLE)
rd += rs_rd;
- cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, rd);
+ rd_opt->mask_filter = MAX(rd_opt->mask_filter, rd);
} else {
int rate_sum = 0;
int64_t dist_sum = 0;
@@ -2842,12 +2843,12 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
model_rd_for_sb(cpi, bsize, x, xd, &rate_sum, &dist_sum);
rd = RDCOST(x->rdmult, x->rddiv, rate_sum, dist_sum);
- cpi->rd_filter_cache[i] = rd;
- cpi->rd_filter_cache[SWITCHABLE_FILTERS] =
- MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], rd + rs_rd);
+ rd_opt->filter_cache[i] = rd;
+ rd_opt->filter_cache[SWITCHABLE_FILTERS] =
+ MIN(rd_opt->filter_cache[SWITCHABLE_FILTERS], rd + rs_rd);
if (cm->interp_filter == SWITCHABLE)
rd += rs_rd;
- cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, rd);
+ rd_opt->mask_filter = MAX(rd_opt->mask_filter, rd);
if (i == 0 && intpel_mv) {
tmp_rate_sum = rate_sum;
@@ -3124,6 +3125,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
PICK_MODE_CONTEXT *ctx,
int64_t best_rd_so_far) {
VP9_COMMON *const cm = &cpi->common;
+ RD_OPT *const rd_opt = &cpi->rd;
MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const struct segmentation *const seg = &cm->seg;
@@ -3163,8 +3165,8 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
int best_skip2 = 0;
int mode_skip_mask = 0;
int mode_skip_start = cpi->sf.mode_skip_start + 1;
- const int *const rd_threshes = cpi->rd_threshes[segment_id][bsize];
- const int *const rd_thresh_freq_fact = cpi->rd_thresh_freq_fact[bsize];
+ const int *const rd_threshes = rd_opt->threshes[segment_id][bsize];
+ const int *const rd_thresh_freq_fact = rd_opt->thresh_freq_fact[bsize];
const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags;
const int intra_y_mode_mask =
cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]];
@@ -3609,21 +3611,21 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
/* keep record of best filter type */
if (!mode_excluded && cm->interp_filter != BILINEAR) {
- int64_t ref = cpi->rd_filter_cache[cm->interp_filter == SWITCHABLE ?
+ int64_t ref = rd_opt->filter_cache[cm->interp_filter == SWITCHABLE ?
SWITCHABLE_FILTERS : cm->interp_filter];
for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
int64_t adj_rd;
if (ref == INT64_MAX)
adj_rd = 0;
- else if (cpi->rd_filter_cache[i] == INT64_MAX)
+ else if (rd_opt->filter_cache[i] == INT64_MAX)
// when early termination is triggered, the encoder does not have
// access to the rate-distortion cost. it only knows that the cost
// should be above the maximum valid value. hence it takes the known
// maximum plus an arbitrary constant as the rate-distortion cost.
- adj_rd = cpi->mask_filter_rd - ref + 10;
+ adj_rd = rd_opt->mask_filter - ref + 10;
else
- adj_rd = cpi->rd_filter_cache[i] - ref;
+ adj_rd = rd_opt->filter_cache[i] - ref;
adj_rd += this_rd;
best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd);
@@ -3685,7 +3687,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
// combination that wins out.
if (cpi->sf.adaptive_rd_thresh) {
for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) {
- int *const fact = &cpi->rd_thresh_freq_fact[bsize][mode_index];
+ int *const fact = &rd_opt->thresh_freq_fact[bsize][mode_index];
if (mode_index == best_mode_index) {
*fact -= (*fact >> 3);
@@ -3757,6 +3759,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
PICK_MODE_CONTEXT *ctx,
int64_t best_rd_so_far) {
VP9_COMMON *const cm = &cpi->common;
+ RD_OPT *const rd_opt = &cpi->rd;
MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const struct segmentation *const seg = &cm->seg;
@@ -3878,9 +3881,9 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
// Test best rd so far against threshold for trying this mode.
if ((best_rd <
- ((int64_t)cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] *
- cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 5)) ||
- cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] == INT_MAX)
+ ((int64_t)rd_opt->thresh_sub8x8[segment_id][bsize][mode_index] *
+ rd_opt->thresh_freq_sub8x8[bsize][mode_index] >> 5)) ||
+ rd_opt->thresh_sub8x8[segment_id][bsize][mode_index] == INT_MAX)
continue;
if (ref_frame > INTRA_FRAME &&
@@ -4009,14 +4012,13 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
int uv_skippable;
this_rd_thresh = (ref_frame == LAST_FRAME) ?
- cpi->rd_thresh_sub8x8[segment_id][bsize][THR_LAST] :
- cpi->rd_thresh_sub8x8[segment_id][bsize][THR_ALTR];
+ rd_opt->thresh_sub8x8[segment_id][bsize][THR_LAST] :
+ rd_opt->thresh_sub8x8[segment_id][bsize][THR_ALTR];
this_rd_thresh = (ref_frame == GOLDEN_FRAME) ?
- cpi->rd_thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh;
-
- cpi->mask_filter_rd = 0;
+ rd_opt->thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh;
+ rd_opt->mask_filter = 0;
for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
- cpi->rd_filter_cache[i] = INT64_MAX;
+ rd_opt->filter_cache[i] = INT64_MAX;
if (cm->interp_filter != BILINEAR) {
tmp_best_filter = EIGHTTAP;
@@ -4049,14 +4051,14 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
continue;
rs = vp9_get_switchable_rate(x);
rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0);
- cpi->rd_filter_cache[switchable_filter_index] = tmp_rd;
- cpi->rd_filter_cache[SWITCHABLE_FILTERS] =
- MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS],
+ rd_opt->filter_cache[switchable_filter_index] = tmp_rd;
+ rd_opt->filter_cache[SWITCHABLE_FILTERS] =
+ MIN(rd_opt->filter_cache[SWITCHABLE_FILTERS],
tmp_rd + rs_rd);
if (cm->interp_filter == SWITCHABLE)
tmp_rd += rs_rd;
- cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, tmp_rd);
+ rd_opt->mask_filter = MAX(rd_opt->mask_filter, tmp_rd);
newbest = (tmp_rd < tmp_best_rd);
if (newbest) {
@@ -4290,20 +4292,20 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
/* keep record of best filter type */
if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME &&
cm->interp_filter != BILINEAR) {
- int64_t ref = cpi->rd_filter_cache[cm->interp_filter == SWITCHABLE ?
+ int64_t ref = rd_opt->filter_cache[cm->interp_filter == SWITCHABLE ?
SWITCHABLE_FILTERS : cm->interp_filter];
int64_t adj_rd;
for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
if (ref == INT64_MAX)
adj_rd = 0;
- else if (cpi->rd_filter_cache[i] == INT64_MAX)
+ else if (rd_opt->filter_cache[i] == INT64_MAX)
// when early termination is triggered, the encoder does not have
// access to the rate-distortion cost. it only knows that the cost
// should be above the maximum valid value. hence it takes the known
// maximum plus an arbitrary constant as the rate-distortion cost.
- adj_rd = cpi->mask_filter_rd - ref + 10;
+ adj_rd = rd_opt->mask_filter - ref + 10;
else
- adj_rd = cpi->rd_filter_cache[i] - ref;
+ adj_rd = rd_opt->filter_cache[i] - ref;
adj_rd += this_rd;
best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd);
@@ -4350,7 +4352,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
// combination that wins out.
if (cpi->sf.adaptive_rd_thresh) {
for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) {
- int *const fact = &cpi->rd_thresh_freq_sub8x8[bsize][mode_index];
+ int *const fact = &rd_opt->thresh_freq_sub8x8[bsize][mode_index];
if (mode_index == best_mode_index) {
*fact -= (*fact >> 3);