From 6761872e49d59e62472015ee42bf02703a195c81 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Wed, 30 Oct 2013 14:40:34 -0700 Subject: [PATCH] Replacing (SWITCHABLE_FILTERS + 1) with SWITCHABLE_FILTER_CONTEXTS. Change-Id: I9781a62bc1a4cd9176554d1271d87dbcafda9cb0 --- vp9/common/vp9_entropymode.c | 6 +++--- vp9/common/vp9_entropymode.h | 1 + vp9/common/vp9_onyxc_int.h | 4 ++-- vp9/decoder/vp9_decodframe.c | 2 +- vp9/encoder/vp9_bitstream.c | 23 ++++++++++------------- vp9/encoder/vp9_block.h | 5 ++--- vp9/encoder/vp9_encodeframe.c | 4 ++-- vp9/encoder/vp9_modecosts.c | 2 +- vp9/encoder/vp9_onyx_int.h | 8 ++++---- vp9/encoder/vp9_rdopt.c | 28 ++++++++++++++-------------- 10 files changed, 40 insertions(+), 43 deletions(-) diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c index 3347b35de..21c91d6e3 100644 --- a/vp9/common/vp9_entropymode.c +++ b/vp9/common/vp9_entropymode.c @@ -309,8 +309,8 @@ static const vp9_prob default_mbskip_probs[MBSKIP_CONTEXTS] = { 192, 128, 64 }; -static const vp9_prob default_switchable_interp_prob[SWITCHABLE_FILTERS+1] - [SWITCHABLE_FILTERS-1] = { +static const vp9_prob default_switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS] + [SWITCHABLE_FILTERS - 1] = { { 235, 162, }, { 36, 255, }, { 34, 3, }, @@ -416,7 +416,7 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) { fc->partition_prob[INTER_FRAME][i], 0); if (cm->mcomp_filter_type == SWITCHABLE) { - for (i = 0; i <= SWITCHABLE_FILTERS; i++) + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) update_mode_probs(SWITCHABLE_FILTERS, vp9_switchable_interp_tree, counts->switchable_interp[i], pre_fc->switchable_interp_prob[i], diff --git a/vp9/common/vp9_entropymode.h b/vp9/common/vp9_entropymode.h index ab37b75c6..ea9655577 100644 --- a/vp9/common/vp9_entropymode.h +++ b/vp9/common/vp9_entropymode.h @@ -16,6 +16,7 @@ #define TX_SIZE_CONTEXTS 2 #define SWITCHABLE_FILTERS 3 // number of switchable filters +#define SWITCHABLE_FILTER_CONTEXTS (SWITCHABLE_FILTERS + 1) // #define MODE_STATS diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h index a823de8cf..ba2e9d87d 100644 --- a/vp9/common/vp9_onyxc_int.h +++ b/vp9/common/vp9_onyxc_int.h @@ -43,7 +43,7 @@ typedef struct frame_contexts { vp9_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1]; vp9_prob partition_prob[FRAME_TYPES][PARTITION_CONTEXTS][PARTITION_TYPES - 1]; vp9_coeff_probs_model coef_probs[TX_SIZES][BLOCK_TYPES]; - vp9_prob switchable_interp_prob[SWITCHABLE_FILTERS + 1] + vp9_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS] [SWITCHABLE_FILTERS - 1]; vp9_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1]; vp9_prob intra_inter_prob[INTRA_INTER_CONTEXTS]; @@ -62,7 +62,7 @@ typedef struct { vp9_coeff_count_model coef[TX_SIZES][BLOCK_TYPES]; unsigned int eob_branch[TX_SIZES][BLOCK_TYPES][REF_TYPES] [COEF_BANDS][PREV_COEF_CONTEXTS]; - unsigned int switchable_interp[SWITCHABLE_FILTERS + 1] + unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS] [SWITCHABLE_FILTERS]; unsigned int inter_mode[INTER_MODE_CONTEXTS][INTER_MODES]; unsigned int intra_inter[INTRA_INTER_CONTEXTS][2]; diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c index 5b45bb80f..34029bb87 100644 --- a/vp9/decoder/vp9_decodframe.c +++ b/vp9/decoder/vp9_decodframe.c @@ -109,7 +109,7 @@ static void read_tx_probs(struct tx_probs *tx_probs, vp9_reader *r) { static void read_switchable_interp_probs(FRAME_CONTEXT *fc, vp9_reader *r) { int i, j; - for (j = 0; j < SWITCHABLE_FILTERS + 1; ++j) + for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) for (i = 0; i < SWITCHABLE_FILTERS - 1; ++i) vp9_diff_update_prob(r, &fc->switchable_interp_prob[j][i]); } diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index c6779073a..a996e0e3b 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -53,8 +53,7 @@ extern unsigned int active_section; int64_t tx_count_32x32p_stats[TX_SIZE_CONTEXTS][TX_SIZES]; int64_t tx_count_16x16p_stats[TX_SIZE_CONTEXTS][TX_SIZES - 1]; int64_t tx_count_8x8p_stats[TX_SIZE_CONTEXTS][TX_SIZES - 2]; -int64_t switchable_interp_stats[SWITCHABLE_FILTERS+1] - [SWITCHABLE_FILTERS]; +int64_t switchable_interp_stats[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; void init_tx_count_stats() { vp9_zero(tx_count_32x32p_stats); @@ -87,10 +86,9 @@ static void update_tx_count_stats(VP9_COMMON *cm) { static void update_switchable_interp_stats(VP9_COMMON *cm) { int i, j; - for (i = 0; i < SWITCHABLE_FILTERS+1; ++i) - for (j = 0; j < SWITCHABLE_FILTERS; ++j) { + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) + for (j = 0; j < SWITCHABLE_FILTERS; ++j) switchable_interp_stats[i][j] += cm->fc.switchable_interp_count[i][j]; - } } void write_tx_count_stats() { @@ -140,9 +138,9 @@ void write_switchable_interp_stats() { fclose(fp); printf( - "vp9_default_switchable_filter_count[SWITCHABLE_FILTERS+1]" + "vp9_default_switchable_filter_count[SWITCHABLE_FILTER_CONTEXTS]" "[SWITCHABLE_FILTERS] = {\n"); - for (i = 0; i < SWITCHABLE_FILTERS+1; i++) { + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { printf(" { "); for (j = 0; j < SWITCHABLE_FILTERS; j++) { printf("%"PRId64", ", switchable_interp_stats[i][j]); @@ -236,17 +234,16 @@ static void write_intra_mode(vp9_writer *bc, int m, const vp9_prob *p) { static void update_switchable_interp_probs(VP9_COMP *const cpi, vp9_writer* const bc) { VP9_COMMON *const cm = &cpi->common; - unsigned int branch_ct[SWITCHABLE_FILTERS + 1] - [SWITCHABLE_FILTERS - 1][2]; - vp9_prob new_prob[SWITCHABLE_FILTERS + 1][SWITCHABLE_FILTERS - 1]; + unsigned int branch_ct[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS - 1][2]; + vp9_prob new_prob[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS - 1]; int i, j; - for (j = 0; j <= SWITCHABLE_FILTERS; ++j) { + for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) { vp9_tree_probs_from_distribution( vp9_switchable_interp_tree, new_prob[j], branch_ct[j], cm->counts.switchable_interp[j], 0); } - for (j = 0; j <= SWITCHABLE_FILTERS; ++j) { + for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) { for (i = 0; i < SWITCHABLE_FILTERS - 1; ++i) { vp9_cond_prob_diff_update(bc, &cm->fc.switchable_interp_prob[j][i], branch_ct[j][i]); @@ -1142,7 +1139,7 @@ static void fix_mcomp_filter_type(VP9_COMP *cpi) { int i, j, c = 0; for (i = 0; i < SWITCHABLE_FILTERS; ++i) { count[i] = 0; - for (j = 0; j <= SWITCHABLE_FILTERS; ++j) + for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) count[i] += cm->counts.switchable_interp[j][i]; c += (count[i] > 0); } diff --git a/vp9/encoder/vp9_block.h b/vp9/encoder/vp9_block.h index db2564b4a..583c6c8d0 100644 --- a/vp9/encoder/vp9_block.h +++ b/vp9/encoder/vp9_block.h @@ -42,7 +42,7 @@ typedef struct { int comp_pred_diff; int single_pred_diff; int64_t tx_rd_diff[TX_MODES]; - int64_t best_filter_diff[SWITCHABLE_FILTERS + 1]; + int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; // motion vector cache for adaptive motion search control in partition // search loop @@ -118,8 +118,7 @@ struct macroblock { unsigned inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES]; int intra_uv_mode_cost[2][MB_MODE_COUNT]; int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; - int switchable_interp_costs[SWITCHABLE_FILTERS + 1] - [SWITCHABLE_FILTERS]; + int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; // These define limits to motion vector components to prevent them // from extending outside the UMV borders diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 9408e5473..44ade18de 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -465,7 +465,7 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; - for (i = 0; i <= SWITCHABLE_FILTERS; i++) + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) cpi->rd_filter_diff[i] += ctx->best_filter_diff[i]; } } @@ -2279,7 +2279,7 @@ void vp9_encode_frame(VP9_COMP *cpi) { cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; } - for (i = 0; i <= SWITCHABLE_FILTERS; i++) { + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { const int64_t diff = cpi->rd_filter_diff[i] / cpi->common.MBs; cpi->rd_filter_threshes[frame_type][i] = (cpi->rd_filter_threshes[frame_type][i] + diff) / 2; diff --git a/vp9/encoder/vp9_modecosts.c b/vp9/encoder/vp9_modecosts.c index b867d8b71..7eb659232 100644 --- a/vp9/encoder/vp9_modecosts.c +++ b/vp9/encoder/vp9_modecosts.c @@ -36,7 +36,7 @@ void vp9_init_mode_costs(VP9_COMP *c) { vp9_kf_uv_mode_prob[INTRA_MODES - 1], vp9_intra_mode_tree); - for (i = 0; i <= SWITCHABLE_FILTERS; ++i) + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) vp9_cost_tokens((int *)c->mb.switchable_interp_costs[i], cm->fc.switchable_interp_prob[i], vp9_switchable_interp_tree); diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index 20831bedf..0498043fc 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -396,9 +396,9 @@ typedef struct VP9_COMP { // FIXME(rbultje) can this overflow? int rd_tx_select_threshes[4][TX_MODES]; - int64_t rd_filter_diff[SWITCHABLE_FILTERS + 1]; - int64_t rd_filter_threshes[4][SWITCHABLE_FILTERS + 1]; - int64_t rd_filter_cache[SWITCHABLE_FILTERS + 1]; + int64_t rd_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; + int64_t rd_filter_threshes[4][SWITCHABLE_FILTER_CONTEXTS]; + int64_t rd_filter_cache[SWITCHABLE_FILTER_CONTEXTS]; int RDMULT; int RDDIV; @@ -641,7 +641,7 @@ typedef struct VP9_COMP { int dummy_packing; /* flag to indicate if packing is dummy */ - unsigned int switchable_interp_count[SWITCHABLE_FILTERS + 1] + unsigned int switchable_interp_count[SWITCHABLE_FILTER_CONTEXTS] [SWITCHABLE_FILTERS]; unsigned int tx_stepdown_count[TX_SIZES]; diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index c1342088a..5d6b9818f 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -2207,7 +2207,7 @@ static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, int_mv *second_ref_mv, int64_t comp_pred_diff[NB_PREDICTION_TYPES], int64_t tx_size_diff[TX_MODES], - int64_t best_filter_diff[SWITCHABLE_FILTERS + 1]) { + int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]) { MACROBLOCKD *const xd = &x->e_mbd; // Take a snapshot of the coding context so it can be @@ -2225,7 +2225,7 @@ static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); vpx_memcpy(ctx->best_filter_diff, best_filter_diff, - sizeof(*best_filter_diff) * (SWITCHABLE_FILTERS + 1)); + sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS); } static void setup_pred_block(const MACROBLOCKD *xd, @@ -3119,8 +3119,8 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, int64_t best_tx_diff[TX_MODES]; int64_t best_pred_diff[NB_PREDICTION_TYPES]; int64_t best_pred_rd[NB_PREDICTION_TYPES]; - int64_t best_filter_rd[SWITCHABLE_FILTERS + 1]; - int64_t best_filter_diff[SWITCHABLE_FILTERS + 1]; + int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; + int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; MB_MODE_INFO best_mbmode = { 0 }; int j; int mode_index, best_mode_index = 0; @@ -3158,7 +3158,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, best_pred_rd[i] = INT64_MAX; for (i = 0; i < TX_MODES; i++) best_tx_rd[i] = INT64_MAX; - for (i = 0; i <= SWITCHABLE_FILTERS; i++) + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) best_filter_rd[i] = INT64_MAX; for (i = 0; i < TX_SIZES; i++) rate_uv_intra[i] = INT_MAX; @@ -3547,7 +3547,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, if (!disable_skip && ref_frame == INTRA_FRAME) { for (i = 0; i < NB_PREDICTION_TYPES; ++i) best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); - for (i = 0; i <= SWITCHABLE_FILTERS; i++) + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); } @@ -3630,7 +3630,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, cm->mcomp_filter_type != BILINEAR) { int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ? SWITCHABLE_FILTERS : cm->mcomp_filter_type]; - for (i = 0; i <= SWITCHABLE_FILTERS; i++) { + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { int64_t adj_rd; // In cases of poor prediction, filter_cache[] can contain really big // values, which actually are bigger than this_rd itself. This can @@ -3752,7 +3752,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, } if (!x->skip) { - for (i = 0; i <= SWITCHABLE_FILTERS; i++) { + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { if (best_filter_rd[i] == INT64_MAX) best_filter_diff[i] = 0; else @@ -3817,8 +3817,8 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, int64_t best_tx_diff[TX_MODES]; int64_t best_pred_diff[NB_PREDICTION_TYPES]; int64_t best_pred_rd[NB_PREDICTION_TYPES]; - int64_t best_filter_rd[SWITCHABLE_FILTERS + 1]; - int64_t best_filter_diff[SWITCHABLE_FILTERS + 1]; + int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; + int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; MB_MODE_INFO best_mbmode = { 0 }; int mode_index, best_mode_index = 0; unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; @@ -3855,7 +3855,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, best_pred_rd[i] = INT64_MAX; for (i = 0; i < TX_MODES; i++) best_tx_rd[i] = INT64_MAX; - for (i = 0; i <= SWITCHABLE_FILTERS; i++) + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) best_filter_rd[i] = INT64_MAX; for (i = 0; i < TX_SIZES; i++) rate_uv_intra[i] = INT_MAX; @@ -4297,7 +4297,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, if (!disable_skip && ref_frame == INTRA_FRAME) { for (i = 0; i < NB_PREDICTION_TYPES; ++i) best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); - for (i = 0; i <= SWITCHABLE_FILTERS; i++) + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); } @@ -4375,7 +4375,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, cm->mcomp_filter_type != BILINEAR) { int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ? SWITCHABLE_FILTERS : cm->mcomp_filter_type]; - for (i = 0; i <= SWITCHABLE_FILTERS; i++) { + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { int64_t adj_rd; // In cases of poor prediction, filter_cache[] can contain really big // values, which actually are bigger than this_rd itself. This can @@ -4491,7 +4491,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, } if (!x->skip) { - for (i = 0; i <= SWITCHABLE_FILTERS; i++) { + for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { if (best_filter_rd[i] == INT64_MAX) best_filter_diff[i] = 0; else -- 2.40.0