Extend the eob context model Account for 1-D/2-D transform kernels for the eob modeling. To maintain a smaller context cardinality, set the two 1-D transform kernels in the same category. The difference in directions should be largely covered by the scan order. This and the previous CLs on nz_map context modeling together improve the compression performance of level-map coefficient coding system by 0.4% for lowres. Change-Id: I8c4f03ca01ce3d248950d04bd1266f445b4227a0
diff --git a/av1/common/entropy.h b/av1/common/entropy.h index e40e4a9..763da28 100644 --- a/av1/common/entropy.h +++ b/av1/common/entropy.h
@@ -67,7 +67,7 @@ #define EOB_COEF_CONTEXTS \ (EOB_COEF_CONTEXTS_2D + EOB_COEF_CONTEXTS_1D + EOB_COEF_CONTEXTS_1D) #else // CONFIG_CTX1D -#define EOB_COEF_CONTEXTS 25 +#define EOB_COEF_CONTEXTS 22 #endif // CONFIG_CTX1D #if CONFIG_EXT_TX
diff --git a/av1/common/entropymode.c b/av1/common/entropymode.c index b411421..9d672fc 100644 --- a/av1/common/entropymode.c +++ b/av1/common/entropymode.c
@@ -257,57 +257,57 @@ #else // CONFIG_CTX1D static const aom_prob default_eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS] = { - { { 221, 233, 232, 221, 231, 233, 216, 196, 233, 226, 200, 133, 227, - 206, 157, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, - { 167, 197, 190, 182, 201, 199, 170, 145, 200, 183, 147, 84, 198, - 166, 106, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } }, - { { 236, 244, 246, 243, 232, 244, 247, 243, 241, 231, 212, 250, 248, - 236, 206, 244, 236, 215, 158, 128, 128, 128, 128, 128, 128 }, - { 146, 204, 212, 194, 176, 206, 220, 208, 201, 174, 139, 227, 221, - 185, 149, 210, 190, 152, 93, 128, 128, 128, 128, 128, 128 } }, - { { 231, 242, 243, 248, 248, 249, 251, 251, 249, 246, 250, 247, 242, - 226, 252, 252, 248, 233, 249, 246, 240, 213, 128, 128, 128 }, - { 95, 187, 199, 228, 231, 230, 245, 243, 231, 241, 238, 235, 220, - 192, 244, 240, 230, 210, 217, 208, 170, 134, 128, 128, 128 } }, - { { 181, 218, 219, 232, 234, 235, 243, 245, 247, 251, 251, 248, 253, - 250, 252, 252, 250, 252, 253, 250, 233, 249, 247, 232, 202 }, - { 92, 181, 200, 233, 232, 235, 249, 253, 253, 255, 254, 238, 228, - 255, 251, 240, 128, 242, 233, 211, 171, 214, 179, 46, 128 } } + { { 225, 240, 225, 200, 128, 128, 128, 128, 128, 128, 128, + 245, 246, 238, 203, 128, 128, 128, 128, 128, 128, 128 }, + { 181, 219, 192, 144, 128, 128, 128, 128, 128, 128, 128, + 218, 231, 199, 152, 128, 128, 128, 128, 128, 128, 128 } }, + { { 233, 247, 240, 234, 211, 194, 128, 128, 128, 128, 128, + 252, 252, 249, 242, 221, 208, 128, 128, 128, 128, 128 }, + { 154, 222, 204, 180, 132, 128, 128, 128, 128, 128, 128, + 216, 235, 206, 181, 121, 112, 128, 128, 128, 128, 128 } }, + { { 233, 246, 241, 238, 231, 216, 186, 171, 128, 128, 128, + 251, 252, 251, 244, 233, 218, 192, 191, 128, 128, 128 }, + { 117, 221, 214, 223, 215, 202, 176, 116, 128, 128, 128, + 205, 234, 219, 183, 195, 126, 76, 128, 128, 128, 128 } }, + { { 194, 231, 213, 215, 207, 200, 183, 169, 135, 168, 128, + 240, 246, 243, 238, 210, 201, 172, 133, 107, 128, 128 }, + { 122, 232, 230, 244, 250, 247, 252, 253, 254, 52, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } } }; static const aom_prob default_eob_extra[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS] = { { { - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, }, { - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, } }, { { - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, }, { - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, } }, { { - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, }, { - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, } }, { { - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, }, { - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, } } }; #endif // CONFIG_CTX1D
diff --git a/av1/common/txb_common.c b/av1/common/txb_common.c index 42ebd55..921e659 100644 --- a/av1/common/txb_common.c +++ b/av1/common/txb_common.c
@@ -235,10 +235,16 @@ 17, 33, 65, 129, 257, 513 }; const int16_t k_eob_offset_bits[12] = { 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; -int get_eob_pos_ctx(int eob_token) { return eob_token - 1; } +int av1_get_eob_pos_ctx(TX_TYPE tx_type, int eob_token) { + int offset = 0; + int tx_class = get_tx_class(tx_type); + if (tx_class != TX_CLASS_2D) offset = 11; + return eob_token - 1 + offset; +} int16_t get_eob_pos_token(int eob, int16_t *extra) { int16_t t; + if (eob < 3) { t = eob; } else {
diff --git a/av1/common/txb_common.h b/av1/common/txb_common.h index c2e82e2..76ab7b5 100644 --- a/av1/common/txb_common.h +++ b/av1/common/txb_common.h
@@ -18,7 +18,7 @@ extern const int16_t k_eob_group_start[12]; extern const int16_t k_eob_offset_bits[12]; int16_t get_eob_pos_token(int eob, int16_t *extra); -int get_eob_pos_ctx(int eob_token); +int av1_get_eob_pos_ctx(TX_TYPE tx_type, int eob_token); extern const int16_t av1_coeff_band_4x4[16];
diff --git a/av1/decoder/decodetxb.c b/av1/decoder/decodetxb.c index 5006b19..d7732e5 100644 --- a/av1/decoder/decodetxb.c +++ b/av1/decoder/decodetxb.c
@@ -324,7 +324,7 @@ int is_equal = 0; for (int i = 1; i < max_eob_pt; i++) { - int eob_pos_ctx = get_eob_pos_ctx(i); + int eob_pos_ctx = av1_get_eob_pos_ctx(tx_type, i); is_equal = av1_read_record_bin( counts, r, ec_ctx->eob_flag_cdf[txs_ctx][plane_type][eob_pos_ctx], 2, ACCT_STR);
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c index 71eb693..9d14964 100644 --- a/av1/encoder/encodetxb.c +++ b/av1/encoder/encodetxb.c
@@ -130,18 +130,19 @@ return error; } -void av1_update_eob_context(int eob, int seg_eob, TX_SIZE txsize, - PLANE_TYPE plane, FRAME_CONTEXT *ec_ctx, - FRAME_COUNTS *counts) { +void av1_update_eob_context(int eob, int seg_eob, TX_SIZE tx_size, + TX_TYPE tx_type, PLANE_TYPE plane, + FRAME_CONTEXT *ec_ctx, FRAME_COUNTS *counts) { int16_t eob_extra; 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); for (int i = 1; i < max_eob_pt; i++) { - int eob_pos_ctx = get_eob_pos_ctx(i); - counts->eob_flag[txsize][plane][eob_pos_ctx][eob_pt == i]++; - update_cdf(ec_ctx->eob_flag_cdf[txsize][plane][eob_pos_ctx], eob_pt == i, + int eob_pos_ctx = av1_get_eob_pos_ctx(tx_type, i); + counts->eob_flag[txs_ctx][plane][eob_pos_ctx][eob_pt == i]++; + update_cdf(ec_ctx->eob_flag_cdf[txs_ctx][plane][eob_pos_ctx], eob_pt == i, 2); if (eob_pt == i) { break; @@ -151,13 +152,13 @@ if (k_eob_offset_bits[eob_pt] > 0) { int eob_shift = k_eob_offset_bits[eob_pt] - 1; int bit = (eob_extra & (1 << eob_shift)) ? 1 : 0; - counts->eob_extra[txsize][plane][eob_pt][bit]++; - update_cdf(ec_ctx->eob_extra_cdf[txsize][plane][eob_pt], bit, 2); + counts->eob_extra[txs_ctx][plane][eob_pt][bit]++; + update_cdf(ec_ctx->eob_extra_cdf[txs_ctx][plane][eob_pt], bit, 2); } } static int get_eob_cost(int eob, int seg_eob, - const LV_MAP_COEFF_COST *txb_costs) { + const LV_MAP_COEFF_COST *txb_costs, TX_TYPE tx_type) { int16_t eob_extra; int16_t eob_pt = get_eob_pos_token(eob, &eob_extra); int16_t dummy; @@ -166,7 +167,7 @@ // printf("Enc: [%d, %d], (%d, %d) ", seg_eob, eob, eob_pt, eob_extra); for (int i = 1; i < max_eob_pt; i++) { - int eob_pos_ctx = get_eob_pos_ctx(i); + int eob_pos_ctx = av1_get_eob_pos_ctx(tx_type, i); eob_cost += txb_costs->eob_cost[eob_pos_ctx][eob_pt == i]; if (eob_pt == i) { break; @@ -408,7 +409,7 @@ // printf("Enc: [%d, %d], (%d, %d) ", seg_eob, eob, eob_pt, eob_extra); for (int i = 1; i < max_eob_pt; i++) { - int eob_pos_ctx = get_eob_pos_ctx(i); + int eob_pos_ctx = av1_get_eob_pos_ctx(tx_type, i); aom_write_bin(w, eob_pt == i, ec_ctx->eob_flag_cdf[txs_ctx][plane_type][eob_pos_ctx], 2); @@ -774,7 +775,7 @@ #endif const int seg_eob = tx_size_2d[tx_size]; - int eob_cost = get_eob_cost(eob, seg_eob, coeff_costs); + int eob_cost = get_eob_cost(eob, seg_eob, coeff_costs, tx_type); cost += eob_cost; for (c = eob - 1; c >= 0; --c) { @@ -1794,7 +1795,7 @@ // forward optimize the nz_map` const int init_eob = txb_info->eob; const int seg_eob = txb_info->seg_eob; - int eob_cost = get_eob_cost(init_eob, seg_eob, txb_costs); + int eob_cost = get_eob_cost(init_eob, seg_eob, txb_costs, txb_info->tx_type); // backward optimize the level-k map int64_t accu_rate = eob_cost; @@ -1813,7 +1814,8 @@ accu_rate += stats.rate; } else { // check if it is better to make this the last significant coefficient - int cur_eob_rate = get_eob_cost(si + 1, seg_eob, txb_costs); + int cur_eob_rate = + get_eob_cost(si + 1, seg_eob, txb_costs, txb_info->tx_type); cur_eob_rd_cost = RDCOST(txb_info->rdmult, cur_eob_rate, 0); prev_eob_rd_cost = RDCOST(txb_info->rdmult, accu_rate + stats.nz_rate, accu_dist); @@ -2295,7 +2297,7 @@ unsigned int(*nz_map_count)[SIG_COEF_CONTEXTS][2] = &(td->counts->nz_map[txsize_ctx][plane_type]); - av1_update_eob_context(eob, seg_eob, txsize_ctx, plane_type, ec_ctx, + av1_update_eob_context(eob, seg_eob, tx_size, tx_type, plane_type, ec_ctx, td->counts); for (c = eob - 1; c >= 0; --c) { tran_low_t v = qcoeff[scan[c]];