Commit b3eda2f4 authored by Debargha Mukherjee's avatar Debargha Mukherjee

Refactor/Change the entropy context for transforms

The change makes the entropy context for transforms use
the same mechanism as with and without lv_map.
For the non-lv-map case the context is now based on the
the larger transform dim for 2:1 rect transforms. The context
is now the average for 4:1 rect transforms for both lv-map and
non-lv-map cases.
There is one small fix for level map for getting the correct
rate when skip is set.

BDRATE: lowres, 30 frames, speed 1: -0.15% gain for the
non-lv-map case on the baseline.

Change-Id: I06a583d33bef68202d72a88e077f8d31cc5e7fe4
parent f0049ba5
......@@ -376,6 +376,11 @@ static INLINE aom_prob av1_mode_mv_merge_probs(aom_prob pre_prob,
return mode_mv_merge_probs(pre_prob, ct);
}
static INLINE TX_SIZE get_txsize_entropy_ctx(TX_SIZE txsize) {
return (TX_SIZE)((txsize_sqr_map[txsize] + txsize_sqr_up_map[txsize] + 1) >>
1);
}
void av1_average_tile_coef_cdfs(struct frame_contexts *fc,
struct frame_contexts *ec_ctxs[],
aom_cdf_prob *cdf_ptrs[], int num_tiles);
......
......@@ -30,10 +30,6 @@ typedef struct txb_ctx {
int dc_sign_ctx;
} TXB_CTX;
static INLINE TX_SIZE get_txsize_context(TX_SIZE tx_size) {
return txsize_sqr_up_map[tx_size];
}
static const int base_level_count_to_index[13] = {
0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
};
......
......@@ -66,7 +66,7 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
#else
FRAME_COUNTS *const counts = xd->counts;
#endif
const TX_SIZE txs_ctx = get_txsize_context(tx_size);
const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
const PLANE_TYPE plane_type = get_plane_type(plane);
MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const int seg_eob = av1_get_max_eob(tx_size);
......
......@@ -117,7 +117,7 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff,
#endif // CONFIG_AOM_QM
(void)tx_type;
int band, c = 0;
const TX_SIZE tx_size_ctx = txsize_sqr_map[tx_size];
const TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size);
aom_cdf_prob(*coef_head_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] =
ec_ctx->coef_head_cdfs[tx_size_ctx][type][ref];
aom_cdf_prob(*coef_tail_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] =
......
......@@ -171,9 +171,9 @@ static int optimize_b_greedy(const AV1_COMMON *cm, MACROBLOCK *mb, int plane,
int i, final_eob = 0;
const int cat6_bits = av1_get_cat6_extrabits_size(tx_size, xd->bd);
int(*head_token_costs)[COEFF_CONTEXTS][TAIL_TOKENS] =
mb->token_head_costs[txsize_sqr_map[tx_size]][plane_type][ref];
mb->token_head_costs[get_txsize_entropy_ctx(tx_size)][plane_type][ref];
int(*tail_token_costs)[COEFF_CONTEXTS][TAIL_TOKENS] =
mb->token_tail_costs[txsize_sqr_map[tx_size]][plane_type][ref];
mb->token_tail_costs[get_txsize_entropy_ctx(tx_size)][plane_type][ref];
const int64_t rdmult = (mb->rdmult * plane_rd_mult[ref][plane_type]) >> 1;
int64_t rate0, rate1;
......
......@@ -147,7 +147,7 @@ void av1_update_eob_context(int eob, int seg_eob, TX_SIZE tx_size,
int16_t eob_pt = get_eob_pos_token(eob, &eob_extra);
int16_t dummy;
int16_t max_eob_pt = get_eob_pos_token(seg_eob, &dummy);
TX_SIZE txs_ctx = get_txsize_context(tx_size);
TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
for (int i = 1; i < max_eob_pt; i++) {
int eob_pos_ctx = av1_get_eob_pos_ctx(tx_type, i);
......@@ -322,7 +322,7 @@ void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
uint16_t eob, TXB_CTX *txb_ctx) {
MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
const PLANE_TYPE plane_type = get_plane_type(plane);
const TX_SIZE txs_ctx = get_txsize_context(tx_size);
const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
const TX_TYPE tx_type =
av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size);
const SCAN_ORDER *const scan_order = get_scan(cm, tx_size, tx_type, mbmi);
......@@ -646,7 +646,7 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
int blk_row, int blk_col, int block, TX_SIZE tx_size,
TXB_CTX *txb_ctx) {
MACROBLOCKD *const xd = &x->e_mbd;
TX_SIZE txs_ctx = get_txsize_context(tx_size);
TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
const PLANE_TYPE plane_type = get_plane_type(plane);
const TX_TYPE tx_type =
av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size);
......@@ -2084,7 +2084,7 @@ int av1_optimize_txb(const AV1_COMMON *cm, MACROBLOCK *x, int plane,
TXB_CTX *txb_ctx, int fast_mode) {
MACROBLOCKD *const xd = &x->e_mbd;
const PLANE_TYPE plane_type = get_plane_type(plane);
const TX_SIZE txs_ctx = get_txsize_context(tx_size);
const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
const TX_TYPE tx_type =
av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size);
const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
......@@ -2200,7 +2200,7 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
DECLARE_ALIGNED(16, uint8_t, level_counts[MAX_TX_SQUARE]);
const uint8_t allow_update_cdf = args->allow_update_cdf;
TX_SIZE txsize_ctx = get_txsize_context(tx_size);
TX_SIZE txsize_ctx = get_txsize_entropy_ctx(tx_size);
FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
memcpy(tcoeff, qcoeff, sizeof(*tcoeff) * seg_eob);
......
......@@ -1620,7 +1620,7 @@ static int cost_coeffs(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
const uint16_t *band_count = &band_count_table[tx_size][1];
const int eob = p->eobs[block];
const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
const TX_SIZE tx_size_ctx = txsize_sqr_map[tx_size];
const TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size);
uint8_t token_cache[MAX_TX_SQUARE];
int pt = combine_entropy_contexts(*a, *l);
int c, cost;
......@@ -3852,14 +3852,14 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
#if CONFIG_LV_MAP
TX_SIZE txs_ctx = get_txsize_context(tx_size);
TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
TXB_CTX txb_ctx;
get_txb_ctx(plane_bsize, tx_size, plane, pta, ptl, &txb_ctx);
zero_blk_rate = x->coeff_costs[txs_ctx][get_plane_type(plane)]
.txb_skip_cost[txb_ctx.txb_skip_ctx][1];
#else
TX_SIZE tx_size_ctx = txsize_sqr_map[tx_size];
TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size);
int coeff_ctx = get_entropy_context(tx_size, pta, ptl);
zero_blk_rate =
x->token_head_costs[tx_size_ctx][pd->plane_type][1][0][coeff_ctx][0];
......@@ -4291,7 +4291,7 @@ static void tx_block_yrd(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
ENTROPY_CONTEXT *ta = above_ctx + blk_col;
ENTROPY_CONTEXT *tl = left_ctx + blk_row;
#if CONFIG_LV_MAP
const TX_SIZE txs_ctx = get_txsize_context(tx_size);
const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
TXB_CTX txb_ctx;
get_txb_ctx(plane_bsize, tx_size, plane, ta, tl, &txb_ctx);
......@@ -4299,7 +4299,7 @@ static void tx_block_yrd(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
.txb_skip_cost[txb_ctx.txb_skip_ctx][1];
#else
const int coeff_ctx = get_entropy_context(tx_size, ta, tl);
const TX_SIZE tx_size_ctx = txsize_sqr_map[tx_size];
const TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size);
const int zero_blk_rate =
x->token_head_costs[tx_size_ctx][pd->plane_type][1][0][coeff_ctx][0];
#endif // CONFIG_LV_MAP
......@@ -4720,7 +4720,7 @@ static void set_skip_flag(const AV1_COMP *cpi, MACROBLOCK *x,
(void)cpi;
// Rate.
const int tx_size_ctx = txsize_sqr_map[tx_size];
const int tx_size_ctx = get_txsize_entropy_ctx(tx_size);
ENTROPY_CONTEXT ctxa[2 * MAX_MIB_SIZE];
ENTROPY_CONTEXT ctxl[2 * MAX_MIB_SIZE];
av1_get_entropy_contexts(bsize, 0, &xd->plane[0], ctxa, ctxl);
......
......@@ -430,10 +430,10 @@ static void tokenize_b(int plane, int block, int blk_row, int blk_col,
FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
aom_cdf_prob(
*const coef_head_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] =
ec_ctx->coef_head_cdfs[txsize_sqr_map[tx_size]][type][ref];
ec_ctx->coef_head_cdfs[get_txsize_entropy_ctx(tx_size)][type][ref];
aom_cdf_prob(
*const coef_tail_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] =
ec_ctx->coef_tail_cdfs[txsize_sqr_map[tx_size]][type][ref];
ec_ctx->coef_tail_cdfs[get_txsize_entropy_ctx(tx_size)][type][ref];
int8_t eob_val;
int8_t first_val = 1;
const int seg_eob = av1_get_tx_eob(&cpi->common.seg, segment_id, tx_size);
......
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