From 0d8e4f91a25b3feb12fae22b05c80c62d6927cac Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Fri, 11 Apr 2014 12:42:13 -0700 Subject: [PATCH] Unfork rd_thresh sub8x8. Remove duplicate rd_thresh code introduced when vp9_rd_pick_inter_mode_sub8x8() was forked from vp9_rd_pick_inter_mode_sb(). Change-Id: I3c9b7143d182e1f28b29c16518eaca81dc2ecfed --- vp9/encoder/vp9_onyx_if.c | 2 - vp9/encoder/vp9_onyx_int.h | 2 - vp9/encoder/vp9_rdopt.c | 106 ++++++++++++++++++++++----------------------- 3 files changed, 51 insertions(+), 59 deletions(-) diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index f51c90d..8a94cf3 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -1226,8 +1226,6 @@ VP9_COMP *vp9_create_compressor(VP9_CONFIG *oxcf) { 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, \ diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index f855161..08287cb 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -298,8 +298,6 @@ typedef struct RD_OPT { 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]; diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index caa8008..5d53aaa 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -260,16 +260,18 @@ static void set_block_thresholds(VP9_COMP *cpi) { const int t = q * rd_thresh_block_size_factor[bsize]; const int thresh_max = INT_MAX / t; - for (i = 0; i < MAX_MODES; ++i) - 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) { - rd->thresh_sub8x8[segment_id][bsize][i] = - rd->thresh_mult_sub8x8[i] < thresh_max - ? rd->thresh_mult_sub8x8[i] * t / 4 - : INT_MAX; + if (bsize >= BLOCK_8X8) { + for (i = 0; i < MAX_MODES; ++i) + rd->threshes[segment_id][bsize][i] = + rd->thresh_mult[i] < thresh_max + ? rd->thresh_mult[i] * t / 4 + : INT_MAX; + } else { + for (i = 0; i < MAX_REFS; ++i) + rd->threshes[segment_id][bsize][i] = + rd->thresh_mult_sub8x8[i] < thresh_max + ? rd->thresh_mult_sub8x8[i] * t / 4 + : INT_MAX; } } } @@ -3115,6 +3117,34 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, ctx->mic = *xd->mi[0]; } +static INLINE int rd_less_than_thresh(int64_t best_rd, int thresh, + int thresh_fact) { + return best_rd < ((int64_t)thresh * thresh_fact >> 5) || thresh == INT_MAX; +} + +// Updating rd_thresh_freq_fact[] here means that the different +// partition/block sizes are handled independently based on the best +// choice for the current partition. It may well be better to keep a scaled +// best rd so far value and update rd_thresh_freq_fact based on the mode/size +// combination that wins out. +static void update_rd_thresh_fact(VP9_COMP *cpi, int bsize, + int best_mode_index) { + if (cpi->sf.adaptive_rd_thresh) { + const int top_mode = bsize < BLOCK_8X8 ? MAX_REFS : MAX_MODES; + int mode_index; + for (mode_index = 0; mode_index < top_mode; ++mode_index) { + int *const fact = &cpi->rd.thresh_freq_fact[bsize][mode_index]; + + if (mode_index == best_mode_index) { + *fact -= (*fact >> 3); + } else { + *fact = MIN(*fact + RD_THRESH_INC, + cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT); + } + } + } +} + int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, const TileInfo *const tile, int mi_row, int mi_col, @@ -3324,10 +3354,9 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, continue; // Test best rd so far against threshold for trying this mode. - if (best_rd < ((int64_t)rd_threshes[mode_index] * - rd_thresh_freq_fact[mode_index] >> 5) || - rd_threshes[mode_index] == INT_MAX) - continue; + if (rd_less_than_thresh(best_rd, rd_threshes[mode_index], + rd_thresh_freq_fact[mode_index])) + continue; this_mode = vp9_mode_order[mode_index].mode; ref_frame = vp9_mode_order[mode_index].ref_frame[0]; @@ -3680,23 +3709,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, (cm->interp_filter == best_mbmode.interp_filter) || !is_inter_block(&best_mbmode)); - // Updating rd_thresh_freq_fact[] here means that the different - // partition/block sizes are handled independently based on the best - // choice for the current partition. It may well be better to keep a scaled - // best rd so far value and update rd_thresh_freq_fact based on the mode/size - // combination that wins out. - if (cpi->sf.adaptive_rd_thresh) { - for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { - int *const fact = &rd_opt->thresh_freq_fact[bsize][mode_index]; - - if (mode_index == best_mode_index) { - *fact -= (*fact >> 3); - } else { - *fact = MIN(*fact + RD_THRESH_INC, - cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT); - } - } - } + update_rd_thresh_fact(cpi, bsize, best_mode_index); // macroblock modes *mbmi = best_mbmode; @@ -3880,10 +3893,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)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) + if (rd_less_than_thresh(best_rd, + rd_opt->threshes[segment_id][bsize][mode_index], + rd_opt->thresh_freq_fact[bsize][mode_index])) continue; if (ref_frame > INTRA_FRAME && @@ -4013,10 +4025,10 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, int uv_skippable; this_rd_thresh = (ref_frame == LAST_FRAME) ? - rd_opt->thresh_sub8x8[segment_id][bsize][THR_LAST] : - rd_opt->thresh_sub8x8[segment_id][bsize][THR_ALTR]; + rd_opt->threshes[segment_id][bsize][THR_LAST] : + rd_opt->threshes[segment_id][bsize][THR_ALTR]; this_rd_thresh = (ref_frame == GOLDEN_FRAME) ? - rd_opt->thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh; + rd_opt->threshes[segment_id][bsize][THR_GOLD] : this_rd_thresh; rd_opt->mask_filter = 0; for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) rd_opt->filter_cache[i] = INT64_MAX; @@ -4346,23 +4358,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, (cm->interp_filter == best_mbmode.interp_filter) || !is_inter_block(&best_mbmode)); - // Updating rd_thresh_freq_fact[] here means that the different - // partition/block sizes are handled independently based on the best - // choice for the current partition. It may well be better to keep a scaled - // best rd so far value and update rd_thresh_freq_fact based on the mode/size - // combination that wins out. - if (cpi->sf.adaptive_rd_thresh) { - for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) { - int *const fact = &rd_opt->thresh_freq_sub8x8[bsize][mode_index]; - - if (mode_index == best_mode_index) { - *fact -= (*fact >> 3); - } else { - *fact = MIN(*fact + RD_THRESH_INC, - cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT); - } - } - } + update_rd_thresh_fact(cpi, bsize, best_mode_index); // macroblock modes *mbmi = best_mbmode; -- 2.7.4