Commit a5562587 authored by Jingning Han's avatar Jingning Han Committed by Gerrit Code Review
Browse files

Merge "Refactor inter mode rate-distortion search"

parents 134dfea8 11abab35
......@@ -360,7 +360,6 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
const int mi_height = num_8x8_blocks_high_lookup[bsize];
assert(mi->mbmi.mode < MB_MODE_COUNT);
assert(mb_mode_index < MAX_MODES);
assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES);
assert(mi->mbmi.ref_frame[1] < MAX_REF_FRAMES);
assert(mi->mbmi.sb_type == bsize);
......@@ -422,7 +421,6 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
THR_D207_PRED /*D207_PRED*/,
THR_D63_PRED /*D63_PRED*/,
THR_TM /*TM_PRED*/,
THR_B_PRED /*I4X4_PRED*/,
};
cpi->mode_chosen_counts[kf_mode_index[mi->mbmi.mode]]++;
#endif
......@@ -597,12 +595,17 @@ static void pick_sb_modes(VP9_COMP *cpi, int mi_row, int mi_col,
// Find best coding mode & reconstruct the MB so it is available
// as a predictor for MBs that follow in the SB
if (cm->frame_type == KEY_FRAME)
if (cm->frame_type == KEY_FRAME) {
vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx,
best_rd);
else
vp9_rd_pick_inter_mode_sb(cpi, x, mi_row, mi_col, totalrate, totaldist,
bsize, ctx, best_rd);
} else {
if (bsize >= BLOCK_8X8)
vp9_rd_pick_inter_mode_sb(cpi, x, mi_row, mi_col, totalrate, totaldist,
bsize, ctx, best_rd);
else
vp9_rd_pick_inter_mode_sub8x8(cpi, x, mi_row, mi_col, totalrate,
totaldist, bsize, ctx, best_rd);
}
}
static void update_stats(VP9_COMP *cpi) {
......
......@@ -16,32 +16,17 @@
#include "vp9/encoder/vp9_onyx_int.h"
#include "vp9/common/vp9_onyxc_int.h"
typedef enum {
RD_DC_PRED = DC_PRED,
RD_V_PRED = V_PRED,
RD_H_PRED = H_PRED,
RD_D45_PRED = D45_PRED,
RD_D135_PRED = D135_PRED,
RD_D117_PRED = D117_PRED,
RD_D153_PRED = D153_PRED,
RD_D207_PRED = D207_PRED,
RD_D63_PRED = D63_PRED,
RD_TM_PRED = TM_PRED,
RD_NEARESTMV = NEARESTMV,
RD_NEARMV = NEARMV,
RD_ZEROMV = ZEROMV,
RD_NEWMV = NEWMV,
RD_I4X4_PRED,
RD_SPLITMV,
RD_MODE_COUNT
} RD_PREDICTION_MODE;
typedef struct {
RD_PREDICTION_MODE mode;
MB_PREDICTION_MODE mode;
MV_REFERENCE_FRAME ref_frame;
MV_REFERENCE_FRAME second_ref_frame;
} MODE_DEFINITION;
typedef struct {
MV_REFERENCE_FRAME ref_frame;
MV_REFERENCE_FRAME second_ref_frame;
} REF_DEFINITION;
struct optimize_ctx {
ENTROPY_CONTEXT ta[MAX_MB_PLANE][16];
ENTROPY_CONTEXT tl[MAX_MB_PLANE][16];
......
......@@ -616,19 +616,12 @@ static void set_rd_speed_thresholds(VP9_COMP *cpi, int mode) {
sf->thresh_mult[THR_COMP_NEARGA] += 1500;
sf->thresh_mult[THR_COMP_NEWGA] += 2000;
sf->thresh_mult[THR_SPLITMV] += 2500;
sf->thresh_mult[THR_SPLITG] += 2500;
sf->thresh_mult[THR_SPLITA] += 2500;
sf->thresh_mult[THR_COMP_SPLITLA] += 4500;
sf->thresh_mult[THR_COMP_SPLITGA] += 4500;
sf->thresh_mult[THR_ZEROMV] += 2000;
sf->thresh_mult[THR_ZEROG] += 2000;
sf->thresh_mult[THR_ZEROA] += 2000;
sf->thresh_mult[THR_COMP_ZEROLA] += 2500;
sf->thresh_mult[THR_COMP_ZEROGA] += 2500;
sf->thresh_mult[THR_B_PRED] += 2500;
sf->thresh_mult[THR_H_PRED] += 2000;
sf->thresh_mult[THR_V_PRED] += 2000;
sf->thresh_mult[THR_D45_PRED ] += 2500;
......@@ -644,21 +637,18 @@ static void set_rd_speed_thresholds(VP9_COMP *cpi, int mode) {
sf->thresh_mult[THR_NEARESTMV] = INT_MAX;
sf->thresh_mult[THR_ZEROMV ] = INT_MAX;
sf->thresh_mult[THR_NEARMV ] = INT_MAX;
sf->thresh_mult[THR_SPLITMV ] = INT_MAX;
}
if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) {
sf->thresh_mult[THR_NEARESTG ] = INT_MAX;
sf->thresh_mult[THR_ZEROG ] = INT_MAX;
sf->thresh_mult[THR_NEARG ] = INT_MAX;
sf->thresh_mult[THR_NEWG ] = INT_MAX;
sf->thresh_mult[THR_SPLITG ] = INT_MAX;
}
if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) {
sf->thresh_mult[THR_NEARESTA ] = INT_MAX;
sf->thresh_mult[THR_ZEROA ] = INT_MAX;
sf->thresh_mult[THR_NEARA ] = INT_MAX;
sf->thresh_mult[THR_NEWA ] = INT_MAX;
sf->thresh_mult[THR_SPLITA ] = INT_MAX;
}
if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) !=
......@@ -667,7 +657,6 @@ static void set_rd_speed_thresholds(VP9_COMP *cpi, int mode) {
sf->thresh_mult[THR_COMP_NEARESTLA] = INT_MAX;
sf->thresh_mult[THR_COMP_NEARLA ] = INT_MAX;
sf->thresh_mult[THR_COMP_NEWLA ] = INT_MAX;
sf->thresh_mult[THR_COMP_SPLITLA ] = INT_MAX;
}
if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) !=
(VP9_GOLD_FLAG | VP9_ALT_FLAG)) {
......@@ -675,16 +664,43 @@ static void set_rd_speed_thresholds(VP9_COMP *cpi, int mode) {
sf->thresh_mult[THR_COMP_NEARESTGA] = INT_MAX;
sf->thresh_mult[THR_COMP_NEARGA ] = INT_MAX;
sf->thresh_mult[THR_COMP_NEWGA ] = INT_MAX;
sf->thresh_mult[THR_COMP_SPLITGA ] = INT_MAX;
}
}
if (sf->disable_splitmv == 1) {
sf->thresh_mult[THR_SPLITMV ] = INT_MAX;
sf->thresh_mult[THR_SPLITG ] = INT_MAX;
sf->thresh_mult[THR_SPLITA ] = INT_MAX;
static void set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi, int mode) {
SPEED_FEATURES *sf = &cpi->sf;
int i;
sf->thresh_mult[THR_COMP_SPLITLA ] = INT_MAX;
sf->thresh_mult[THR_COMP_SPLITGA ] = INT_MAX;
for (i = 0; i < MAX_REFS; ++i)
sf->thresh_mult_sub8x8[i] = mode == 0 ? -500 : 0;
sf->thresh_mult_sub8x8[THR_LAST] += 2500;
sf->thresh_mult_sub8x8[THR_GOLD] += 2500;
sf->thresh_mult_sub8x8[THR_ALTR] += 2500;
sf->thresh_mult_sub8x8[THR_INTRA] += 2500;
sf->thresh_mult_sub8x8[THR_COMP_LA] += 4500;
sf->thresh_mult_sub8x8[THR_COMP_GA] += 4500;
// disable mode test if frame flag is not set
if (!(cpi->ref_frame_flags & VP9_LAST_FLAG))
sf->thresh_mult_sub8x8[THR_LAST] = INT_MAX;
if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG))
sf->thresh_mult_sub8x8[THR_GOLD] = INT_MAX;
if (!(cpi->ref_frame_flags & VP9_ALT_FLAG))
sf->thresh_mult_sub8x8[THR_ALTR] = INT_MAX;
if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) !=
(VP9_LAST_FLAG | VP9_ALT_FLAG))
sf->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))
sf->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX;
if (sf->disable_splitmv == 1) {
sf->thresh_mult_sub8x8[THR_LAST] = INT_MAX;
sf->thresh_mult_sub8x8[THR_GOLD] = INT_MAX;
sf->thresh_mult_sub8x8[THR_ALTR] = INT_MAX;
sf->thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX;
sf->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX;
}
}
......@@ -915,6 +931,7 @@ void vp9_set_speed_features(VP9_COMP *cpi) {
// Set rd thresholds based on mode and speed setting
set_rd_speed_thresholds(cpi, mode);
set_rd_speed_thresholds_sub8x8(cpi, mode);
// Slow quant, dct and trellis not worthwhile for first pass
// so make sure they are always turned off.
......@@ -1611,9 +1628,12 @@ VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
vp9_set_speed_features(cpi);
// Default rd threshold factors for mode selection
for (i = 0; i < BLOCK_SIZES; ++i)
for (i = 0; i < BLOCK_SIZES; ++i) {
for (j = 0; j < MAX_MODES; ++j)
cpi->rd_thresh_freq_fact[i][j] = 32;
for (j = 0; j < MAX_REFS; ++j)
cpi->rd_thresh_freq_sub8x8[i][j] = 32;
}
#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SVFHH, SVFHV, SVFHHV, \
SDX3F, SDX8F, SDX4DF)\
......@@ -3369,8 +3389,10 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
cm->frame_type, cpi->refresh_golden_frame,
cpi->refresh_alt_ref_frame);
for (i = 0; i < MAX_MODES; i++)
for (i = 0; i < MAX_MODES; ++i)
fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]);
for (i = 0; i < MAX_REFS; ++i)
fprintf(fmodes, "%5d ", cpi->sub8x8_mode_chosen_counts[i]);
fprintf(fmodes, "\n");
......
......@@ -49,7 +49,8 @@
#define KEY_FRAME_CONTEXT 5
#define MAX_MODES 36
#define MAX_MODES 30
#define MAX_REFS 6
#define MIN_THRESHMULT 32
#define MAX_THRESHMULT 512
......@@ -152,19 +153,12 @@ typedef enum {
THR_COMP_NEARGA,
THR_COMP_NEWGA,
THR_SPLITMV,
THR_SPLITG,
THR_SPLITA,
THR_COMP_SPLITLA,
THR_COMP_SPLITGA,
THR_ZEROMV,
THR_ZEROG,
THR_ZEROA,
THR_COMP_ZEROLA,
THR_COMP_ZEROGA,
THR_B_PRED,
THR_H_PRED,
THR_V_PRED,
THR_D135_PRED,
......@@ -175,6 +169,15 @@ typedef enum {
THR_D45_PRED,
} THR_MODES;
typedef enum {
THR_LAST,
THR_GOLD,
THR_ALTR,
THR_COMP_LA,
THR_COMP_GA,
THR_INTRA,
} THR_MODES_SUB8X8;
typedef enum {
DIAMOND = 0,
NSTEP = 1,
......@@ -243,6 +246,7 @@ typedef struct {
SUBPEL_SEARCH_METHODS subpel_search_method;
int subpel_iters_per_step;
int thresh_mult[MAX_MODES];
int thresh_mult_sub8x8[MAX_REFS];
int max_step_search_steps;
int reduce_first_step_size;
int auto_mv_step_size;
......@@ -368,12 +372,15 @@ typedef struct VP9_COMP {
int ambient_err;
unsigned int mode_chosen_counts[MAX_MODES];
unsigned int sub8x8_mode_chosen_counts[MAX_REFS];
int64_t mode_skip_mask;
int ref_frame_mask;
int set_ref_frame_mask;
int rd_threshes[BLOCK_SIZES][MAX_MODES];
int rd_thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
int rd_thresh_sub8x8[BLOCK_SIZES][MAX_REFS];
int rd_thresh_freq_sub8x8[BLOCK_SIZES][MAX_REFS];
int64_t rd_comp_pred_diff[NB_PREDICTION_TYPES];
int64_t rd_prediction_type_threshes[4][NB_PREDICTION_TYPES];
......
This diff is collapsed.
......@@ -29,6 +29,11 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
int *r, int64_t *d, BLOCK_SIZE bsize,
PICK_MODE_CONTEXT *ctx, int64_t best_rd);
int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
int mi_row, int mi_col,
int *r, int64_t *d, BLOCK_SIZE bsize,
PICK_MODE_CONTEXT *ctx, int64_t best_rd);
void vp9_init_me_luts();
void vp9_set_mbmode_and_mvs(MACROBLOCK *x,
......
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