Commit 2cc5eb37 authored by Angie Chiang's avatar Angie Chiang
Browse files

Refactor av1_update_and_record_txb_context

Let the cdf update order match the actual coding order

Change-Id: Iaac0830b2530228ce1a4ea95d842c573dd3d0684
parent 41220ab6
...@@ -2271,7 +2271,7 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row, ...@@ -2271,7 +2271,7 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
struct macroblock_plane *p = &x->plane[plane]; struct macroblock_plane *p = &x->plane[plane];
struct macroblockd_plane *pd = &xd->plane[plane]; struct macroblockd_plane *pd = &xd->plane[plane];
MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
int eob = p->eobs[block], update_eob = -1; int eob = p->eobs[block];
const PLANE_TYPE plane_type = pd->plane_type; const PLANE_TYPE plane_type = pd->plane_type;
const tran_low_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block); const tran_low_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block);
tran_low_t *tcoeff = BLOCK_OFFSET(x->mbmi_ext->tcoeff[plane], block); tran_low_t *tcoeff = BLOCK_OFFSET(x->mbmi_ext->tcoeff[plane], block);
...@@ -2326,11 +2326,11 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row, ...@@ -2326,11 +2326,11 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
av1_get_nz_map_contexts(levels, scan, eob, tx_size, tx_type, coeff_contexts); av1_get_nz_map_contexts(levels, scan, eob, tx_size, tx_type, coeff_contexts);
update_eob = eob - 1;
for (c = eob - 1; c >= 0; --c) { for (c = eob - 1; c >= 0; --c) {
const int pos = scan[c]; const int pos = scan[c];
const int coeff_ctx = coeff_contexts[pos]; const int coeff_ctx = coeff_contexts[pos];
const tran_low_t v = qcoeff[pos]; const tran_low_t v = qcoeff[pos];
const tran_low_t level = abs(v);
const int is_nz = (v != 0); const int is_nz = (v != 0);
(void)is_nz; (void)is_nz;
...@@ -2339,62 +2339,39 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row, ...@@ -2339,62 +2339,39 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
assert(coeff_ctx < 4); assert(coeff_ctx < 4);
update_cdf( update_cdf(
ec_ctx->coeff_base_eob_cdf[txsize_ctx][plane_type][coeff_ctx], ec_ctx->coeff_base_eob_cdf[txsize_ctx][plane_type][coeff_ctx],
AOMMIN(abs(v), 3) - 1, 3); AOMMIN(level, 3) - 1, 3);
} else { } else {
update_cdf(ec_ctx->coeff_base_cdf[txsize_ctx][plane_type][coeff_ctx], update_cdf(ec_ctx->coeff_base_cdf[txsize_ctx][plane_type][coeff_ctx],
AOMMIN(abs(v), 3), 4); AOMMIN(level, 3), 4);
} }
} }
{ {
if (c == eob - 1) { if (c == eob - 1) {
assert(coeff_ctx < 4); assert(coeff_ctx < 4);
++td->counts->coeff_base_eob_multi[txsize_ctx][plane_type][coeff_ctx] ++td->counts->coeff_base_eob_multi[txsize_ctx][plane_type][coeff_ctx]
[AOMMIN(abs(v), 3) - 1]; [AOMMIN(level, 3) - 1];
} else { } else {
++td->counts->coeff_base_multi[txsize_ctx][plane_type][coeff_ctx] ++td->counts->coeff_base_multi[txsize_ctx][plane_type][coeff_ctx]
[AOMMIN(abs(v), 3)]; [AOMMIN(level, 3)];
}
} }
} }
if (level > NUM_BASE_LEVELS) {
// Update the context needed to code the DC sign (if applicable)
const int sign = (tcoeff[0] < 0) ? 1 : 0;
if (tcoeff[0] != 0) {
int dc_sign_ctx = txb_ctx.dc_sign_ctx;
#if CONFIG_ENTROPY_STATS
++td->counts->dc_sign[plane_type][dc_sign_ctx][sign];
#endif // CONFIG_ENTROPY_STATS
if (allow_update_cdf)
update_cdf(ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx], sign, 2);
x->mbmi_ext->dc_sign_ctx[plane][block] = dc_sign_ctx;
}
if (update_eob >= 0) {
for (c = update_eob; c >= 0; --c) {
const int pos = scan[c];
const tran_low_t level = abs(tcoeff[pos]);
int idx;
int ctx;
if (level <= NUM_BASE_LEVELS) continue;
// level is above 1.
const int base_range = level - 1 - NUM_BASE_LEVELS; const int base_range = level - 1 - NUM_BASE_LEVELS;
#if USE_CAUSAL_BR_CTX #if USE_CAUSAL_BR_CTX
ctx = get_br_ctx(levels, pos, bwl, level_counts[pos], tx_type); const int br_ctx =
get_br_ctx(levels, pos, bwl, level_counts[pos], tx_type);
#else #else
ctx = get_br_ctx(levels, pos, bwl, level_counts[pos]); const int br_ctx = get_br_ctx(levels, pos, bwl, level_counts[pos]);
#endif #endif
for (idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) {
const int k = AOMMIN(base_range - idx, BR_CDF_SIZE - 1); const int k = AOMMIN(base_range - idx, BR_CDF_SIZE - 1);
if (allow_update_cdf) { if (allow_update_cdf) {
update_cdf( update_cdf(
#if 0 #if 0
ec_ctx->coeff_br_cdf[AOMMIN(txsize_ctx, TX_16X16)][plane_type][ctx], ec_ctx->coeff_br_cdf[AOMMIN(txsize_ctx, TX_16X16)][plane_type][br_ctx],
#else #else
ec_ctx ec_ctx->coeff_br_cdf[AOMMIN(txsize_ctx, TX_32X32)][plane_type]
->coeff_br_cdf[AOMMIN(txsize_ctx, TX_32X32)][plane_type][ctx], [br_ctx],
#endif #endif
k, BR_CDF_SIZE); k, BR_CDF_SIZE);
} }
...@@ -2405,20 +2382,30 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row, ...@@ -2405,20 +2382,30 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
[ctx][lps == k]; [ctx][lps == k];
#else #else
++td->counts->coeff_lps[AOMMIN(txsize_ctx, TX_32X32)][plane_type][lps] ++td->counts->coeff_lps[AOMMIN(txsize_ctx, TX_32X32)][plane_type][lps]
[ctx][lps == k]; [br_ctx][lps == k];
#endif #endif
#endif // CONFIG_ENTROPY_STATS #endif // CONFIG_ENTROPY_STATS
if (lps == k) break; if (lps == k) break;
} }
++td->counts->coeff_lps_multi[AOMMIN(txsize_ctx, TX_32X32)][plane_type] ++td->counts->coeff_lps_multi[AOMMIN(txsize_ctx, TX_32X32)][plane_type]
[ctx][k]; [br_ctx][k];
if (k < BR_CDF_SIZE - 1) break; if (k < BR_CDF_SIZE - 1) break;
} }
// use 0-th order Golomb code to handle the residual level.
} }
} }
// Update the context needed to code the DC sign (if applicable)
const int sign = (tcoeff[0] < 0) ? 1 : 0;
if (tcoeff[0] != 0) {
int dc_sign_ctx = txb_ctx.dc_sign_ctx;
#if CONFIG_ENTROPY_STATS
++td->counts->dc_sign[plane_type][dc_sign_ctx][sign];
#endif // CONFIG_ENTROPY_STATS
if (allow_update_cdf)
update_cdf(ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx], sign, 2);
x->mbmi_ext->dc_sign_ctx[plane][block] = dc_sign_ctx;
}
int cul_level = av1_get_txb_entropy_context(tcoeff, scan_order, eob); int cul_level = av1_get_txb_entropy_context(tcoeff, scan_order, eob);
av1_set_contexts(xd, pd, plane, tx_size, cul_level, blk_col, blk_row); av1_set_contexts(xd, pd, plane, tx_size, cul_level, blk_col, blk_row);
} }
......
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