Commit 4d447696 authored by Dake He's avatar Dake He
Browse files

[lv_map_multi] base level coding

1. Train and init cdfs directly.
2. Use laplace prob estimates in aom_entropy_optimizer to avoid zero
probabilities.

Change-Id: I878fc0a306cbffe3eb51c5b86d5872459b6705c5
parent 434baf87
......@@ -247,7 +247,15 @@ static INLINE void update_cdf(aom_cdf_prob *cdf, int val, int nsymbs) {
// Single loop (faster)
for (i = 0; i < nsymbs - 1; ++i, tmp -= tmp0) {
tmp -= (i == val ? diff : 0);
#if CONFIG_LV_MAP_MULTI
if (tmp < cdf[i]) {
cdf[i] -= ((cdf[i] - tmp) >> rate);
} else {
cdf[i] += ((tmp - cdf[i]) >> rate);
}
#else
cdf[i] += ((tmp - cdf[i]) >> rate);
#endif
}
#endif
......
......@@ -937,15 +937,12 @@ void av1_average_tile_coef_cdfs(FRAME_CONTEXT *fc, FRAME_CONTEXT *ec_ctxs[],
AVERAGE_TILE_CDFS(dc_sign_cdf)
AVERAGE_TILE_CDFS(coeff_base_cdf)
#if CONFIG_LV_MAP_MULTI
#if USE_BASE_EOB_ALPHABET
AVERAGE_TILE_CDFS(coeff_base_eob_cdf)
#endif
#endif
#if !CONFIG_LV_MAP_MULTI
#else // CONFIG_LV_MAP_MULTI
AVERAGE_TILE_CDFS(coeff_lps_cdf)
#endif
AVERAGE_TILE_CDFS(coeff_br_cdf)
#else
#else // CONFI_LV_MAP
AVERAGE_TILE_CDFS(coef_head_cdfs)
AVERAGE_TILE_CDFS(coef_tail_cdfs)
#endif
......
......@@ -65,18 +65,11 @@ extern "C" {
#define SIG_COEF_CONTEXTS_1D 16
#if CONFIG_LV_MAP_MULTI
#define USE_CAUSAL_BR_CTX 1
#define USE_BASE_EOB_ALPHABET 1
#define SIG_COEF_CONTEXTS_EOB 4
#define SIG_COEF_CONTEXTS \
(SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D + SIG_COEF_CONTEXTS_EOB)
#else
#define TRAIN_INIT_PROB 1
#if TRAIN_INIT_PROB
#define SIG_COEF_CONTEXTS (SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D + 4)
#define SIG_COEF_CONTEXTS (SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D)
#else
#define SIG_COEF_CONTEXTS (SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D)
#endif
#endif
#define COEFF_BASE_CONTEXTS (SIG_COEF_CONTEXTS)
#define DC_SIGN_CONTEXTS 3
......
This diff is collapsed.
......@@ -86,13 +86,14 @@ typedef struct frame_contexts {
#if CONFIG_LV_MAP
aom_prob txb_skip[TX_SIZES][TXB_SKIP_CONTEXTS];
aom_prob nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS];
aom_prob eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS];
aom_prob eob_extra[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS];
aom_prob dc_sign[PLANE_TYPES][DC_SIGN_CONTEXTS];
#if !CONFIG_LV_MAP_MULTI
aom_prob nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS];
aom_prob coeff_base[TX_SIZES][PLANE_TYPES][NUM_BASE_LEVELS]
[COEFF_BASE_CONTEXTS];
#if !CONFIG_LV_MAP_MULTI
aom_prob coeff_lps[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS];
aom_prob coeff_br[TX_SIZES][PLANE_TYPES][BASE_RANGE_SETS][LEVEL_CONTEXTS];
#else
......@@ -110,10 +111,8 @@ typedef struct frame_contexts {
[CDF_SIZE(2)];
aom_cdf_prob dc_sign_cdf[PLANE_TYPES][DC_SIGN_CONTEXTS][CDF_SIZE(2)];
#if CONFIG_LV_MAP_MULTI
#if USE_BASE_EOB_ALPHABET
aom_cdf_prob coeff_base_eob_cdf[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS_EOB]
[CDF_SIZE(3)];
#endif
aom_cdf_prob coeff_base_cdf[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS]
[CDF_SIZE(4)];
aom_cdf_prob coeff_br_cdf[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS]
......@@ -265,13 +264,14 @@ typedef struct FRAME_COUNTS {
#if CONFIG_LV_MAP
unsigned int txb_skip[TX_SIZES][TXB_SKIP_CONTEXTS][2];
unsigned int nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS][2];
unsigned int eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS][2];
unsigned int eob_extra[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS][2];
unsigned int dc_sign[PLANE_TYPES][DC_SIGN_CONTEXTS][2];
#if !CONFIG_LV_MAP_MULTI
unsigned int nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS][2];
unsigned int coeff_base[TX_SIZES][PLANE_TYPES][NUM_BASE_LEVELS]
[COEFF_BASE_CONTEXTS][2];
#if !CONFIG_LV_MAP_MULTI
unsigned int coeff_br[TX_SIZES][PLANE_TYPES][BASE_RANGE_SETS][LEVEL_CONTEXTS]
[2];
unsigned int coeff_lps[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS][2];
......@@ -280,6 +280,10 @@ typedef struct FRAME_COUNTS {
[2];
unsigned int coeff_lps_multi[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS]
[BR_CDF_SIZE];
unsigned int coeff_base_multi[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS]
[NUM_BASE_LEVELS + 2];
unsigned int coeff_base_eob_multi[TX_SIZES][PLANE_TYPES]
[SIG_COEF_CONTEXTS_EOB][NUM_BASE_LEVELS + 1];
#endif
#endif // CONFIG_LV_MAP
......
......@@ -247,7 +247,7 @@ void av1_init_txb_probs(FRAME_CONTEXT *fc) {
#if CONFIG_LV_MAP_MULTI
for (tx_size = 0; tx_size < TX_SIZES; ++tx_size) {
for (plane = 0; plane < PLANE_TYPES; ++plane) {
#if USE_BASE_EOB_ALPHABET
#if 0
for (ctx = 0; ctx < SIG_COEF_CONTEXTS_EOB; ++ctx) {
int p = fc->coeff_base[tx_size][plane][0][SIG_COEF_CONTEXTS -
SIG_COEF_CONTEXTS_EOB + ctx] *
......@@ -261,7 +261,6 @@ void av1_init_txb_probs(FRAME_CONTEXT *fc) {
fc->coeff_base_eob_cdf[tx_size][plane][ctx][2] = AOM_ICDF(32768);
fc->coeff_base_eob_cdf[tx_size][plane][ctx][3] = 0;
}
#endif
for (ctx = 0; ctx < COEFF_BASE_CONTEXTS; ++ctx) {
int p = fc->nz_map[tx_size][plane][ctx] * 128;
fc->coeff_base_cdf[tx_size][plane][ctx][0] = AOM_ICDF(p);
......@@ -272,6 +271,9 @@ void av1_init_txb_probs(FRAME_CONTEXT *fc) {
fc->coeff_base_cdf[tx_size][plane][ctx][3] = AOM_ICDF(32768);
fc->coeff_base_cdf[tx_size][plane][ctx][4] = 0;
}
#else
(void)plane;
#endif
}
}
#else
......
......@@ -531,10 +531,10 @@ static INLINE int get_nz_map_ctx(const uint8_t *const levels,
const TX_SIZE tx_size, const TX_TYPE tx_type) {
#if CONFIG_LV_MAP_MULTI
if (is_eob) {
if (scan_idx == 0) return SIG_COEF_CONTEXTS - 4;
if (scan_idx <= (height << bwl) / 8) return SIG_COEF_CONTEXTS - 3;
if (scan_idx <= (height << bwl) / 4) return SIG_COEF_CONTEXTS - 2;
return SIG_COEF_CONTEXTS - 1;
if (scan_idx == 0) return 0;
if (scan_idx <= (height << bwl) / 8) return 1;
if (scan_idx <= (height << bwl) / 4) return 2;
return 3;
}
#endif
const TX_CLASS tx_class = tx_type_to_class[tx_type];
......
......@@ -171,13 +171,10 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
#if CONFIG_LV_MAP_MULTI
const int coeff_ctx = get_nz_map_ctx(levels, pos, bwl, height, c,
c == *eob - 1, tx_size, tx_type);
#if USE_BASE_EOB_ALPHABET
aom_cdf_prob *cdf;
int nsymbs;
if (c == *eob - 1) {
cdf = ec_ctx->coeff_base_eob_cdf[txs_ctx][plane_type]
[coeff_ctx - SIG_COEF_CONTEXTS +
SIG_COEF_CONTEXTS_EOB];
cdf = ec_ctx->coeff_base_eob_cdf[txs_ctx][plane_type][coeff_ctx];
nsymbs = 3;
} else {
cdf = ec_ctx->coeff_base_cdf[txs_ctx][plane_type][coeff_ctx];
......@@ -186,22 +183,14 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
const int level = av1_read_record_symbol(counts, r, cdf, nsymbs, ACCT_STR) +
(c == *eob - 1);
if (counts) {
if (c < *eob - 1) {
++counts->nz_map[txs_ctx][plane_type][coeff_ctx][level != 0];
}
if (level != 0) {
for (int k = 0; k < NUM_BASE_LEVELS; ++k) {
++counts
->coeff_base[txs_ctx][plane_type][k][coeff_ctx][level > k + 1];
if (level == k + 1) break;
}
if (c == *eob - 1) {
++counts
->coeff_base_eob_multi[txs_ctx][plane_type][coeff_ctx][level - 1];
} else {
++counts->coeff_base_multi[txs_ctx][plane_type][coeff_ctx][level];
}
}
#else
const int level = av1_read_record_symbol(
counts, r, ec_ctx->coeff_base_cdf[txs_ctx][plane_type][coeff_ctx], 4,
ACCT_STR);
#endif
// printf("base_cdf: %d %d %2d\n", txs_ctx, plane_type, coeff_ctx);
// printf("base_cdf: %d %d %2d : %3d %3d %3d\n", txs_ctx, plane_type,
// coeff_ctx,
......
......@@ -64,9 +64,7 @@ typedef int av1_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][COEFF_CONTEXTS]
typedef struct {
int txb_skip_cost[TXB_SKIP_CONTEXTS][2];
#if CONFIG_LV_MAP_MULTI
#if USE_BASE_EOB_ALPHABET
int base_eob_cost[SIG_COEF_CONTEXTS_EOB][3];
#endif
int base_cost[SIG_COEF_CONTEXTS][4];
#else
int nz_map_cost[SIG_COEF_CONTEXTS][2];
......
......@@ -74,6 +74,8 @@ void av1_cost_tokens_from_cdf(int *costs, const aom_cdf_prob *cdf,
#if CONFIG_LV_MAP_MULTI
aom_cdf_prob p15 = AOM_ICDF(cdf[i]) - prev_cdf;
p15 = (p15 < EC_MIN_PROB) ? EC_MIN_PROB : p15;
// p15 = (p15 < CDF_PROB_TOP - EC_MIN_PROB) ? p15 : CDF_PROB_TOP - EC_MIN_PROB;
// prev_cdf += p15;
#else
aom_cdf_prob p15 = AOM_ICDF(cdf[i]) - prev_cdf;
#endif
......
......@@ -35,7 +35,11 @@ typedef struct LevelDownStats {
int64_t dist_low;
int64_t rd;
int64_t rd_low;
#if CONFIG_LV_MAP_MULTI
int64_t nz_rd;
#else
int nz_rate; // for eob
#endif
int64_t rd_diff;
int cost_diff;
int64_t dist_diff;
......@@ -264,39 +268,53 @@ static void get_dist_cost_stats(LevelDownStats *const stats, const int scan_idx,
stats->rd = RDCOST(txb_info->rdmult, stats->rate, stats->dist);
stats->low_qc = get_lower_coeff(qc);
stats->low_dqc = qcoeff_to_dqcoeff(stats->low_qc,
int low_qc_cost;
#if CONFIG_LV_MAP_MULTI
if (is_eob && stats->low_qc == 0) {
stats->low_qc = qc;
stats->low_dqc = dqc;
low_qc_cost = qc_cost;
stats->rd_low = stats->rd; // disable selection of low_qc in this case.
} else {
#else
{
#endif
stats->low_dqc = qcoeff_to_dqcoeff(stats->low_qc,
#if CONFIG_NEW_QUANT
nq_dequant_val,
nq_dequant_val,
#endif // CONFIG_NEW_QUANT
dqv, txb_info->shift);
const int64_t low_dqc_dist =
get_coeff_dist(tqc, stats->low_dqc, txb_info->shift);
const int low_qc_cost = get_coeff_cost(stats->low_qc, scan_idx,
dqv, txb_info->shift);
const int64_t low_dqc_dist =
get_coeff_dist(tqc, stats->low_dqc, txb_info->shift);
low_qc_cost = get_coeff_cost(stats->low_qc, scan_idx,
#if CONFIG_LV_MAP_MULTI
is_eob,
is_eob,
#endif
txb_info, txb_costs, coeff_ctx);
stats->dist_low = low_dqc_dist - stats->dist0;
stats->rate_low = low_qc_cost;
stats->rd_low = RDCOST(txb_info->rdmult, stats->rate_low, stats->dist_low);
txb_info, txb_costs, coeff_ctx);
stats->dist_low = low_dqc_dist - stats->dist0;
stats->rate_low = low_qc_cost;
stats->rd_low = RDCOST(txb_info->rdmult, stats->rate_low, stats->dist_low);
}
#if CONFIG_LV_MAP_MULTI
(void)levels;
if ((stats->rd_low < stats->rd) && (stats->low_qc == 0)) {
stats->nz_rate = low_qc_cost;
} else {
const int coeff_ctx_temp =
get_nz_map_ctx(levels, coeff_idx, txb_info->bwl,
const int coeff_ctx_temp =
get_nz_map_ctx(levels, coeff_idx, txb_info->bwl,
#if CONFIG_LV_MAP_MULTI
txb_info->height, scan_idx, 1,
#endif
txb_info->tx_size, txb_info->tx_type);
const int qc_eob_cost =
get_coeff_cost((stats->rd_low < stats->rd) ? stats->low_qc : qc,
scan_idx, 1, txb_info, txb_costs, coeff_ctx_temp);
stats->nz_rate =
((stats->rd_low < stats->rd) ? low_qc_cost : qc_cost) - qc_eob_cost;
}
txb_info->height, scan_idx, 1,
#endif
txb_info->tx_size, txb_info->tx_type);
const int qc_eob_cost =
get_coeff_cost(qc, scan_idx, 1, txb_info, txb_costs, coeff_ctx_temp);
int64_t rd_eob = RDCOST(txb_info->rdmult, qc_eob_cost, stats->dist);
if (stats->low_qc != 0) {
const int low_qc_eob_cost = get_coeff_cost(
stats->low_qc, scan_idx, 1, txb_info, txb_costs, coeff_ctx_temp);
int64_t rd_eob_low =
RDCOST(txb_info->rdmult, low_qc_eob_cost, stats->dist_low);
rd_eob = (rd_eob > rd_eob_low) ? rd_eob_low : rd_eob;
}
stats->nz_rd = AOMMIN(stats->rd_low, stats->rd) - rd_eob;
#else
const int is_nz = (stats->rd_low < stats->rd && stats->low_qc == 0) ? 0 : 1;
stats->nz_rate = txb_costs->nz_map_cost[coeff_ctx][is_nz];
......@@ -437,23 +455,16 @@ void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
const tran_low_t v = tcoeff[pos];
#if CONFIG_LV_MAP_MULTI
#if USE_BASE_EOB_ALPHABET
if (c == eob - 1) {
aom_write_symbol(
w, AOMMIN(abs(v), 3) - 1,
ec_ctx->coeff_base_eob_cdf[txs_ctx][plane_type]
[coeff_ctx - SIG_COEF_CONTEXTS +
SIG_COEF_CONTEXTS_EOB],
3);
ec_ctx->coeff_base_eob_cdf[txs_ctx][plane_type][coeff_ctx], 3);
} else {
aom_write_symbol(w, AOMMIN(abs(v), 3),
ec_ctx->coeff_base_cdf[txs_ctx][plane_type][coeff_ctx],
4);
}
#else
aom_write_symbol(w, AOMMIN(abs(v), 3),
ec_ctx->coeff_base_cdf[txs_ctx][plane_type][coeff_ctx], 4);
#endif
#else
const int is_nz = (v != 0);
......@@ -681,17 +692,11 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, const MACROBLOCK *x,
const int level = abs(v);
const int coeff_ctx = coeff_contexts[pos];
#if CONFIG_LV_MAP_MULTI
#if USE_BASE_EOB_ALPHABET
if (c == eob - 1) {
cost += coeff_costs
->base_eob_cost[coeff_ctx - SIG_COEF_CONTEXTS +
SIG_COEF_CONTEXTS_EOB][AOMMIN(level, 3) - 1];
cost += coeff_costs->base_eob_cost[coeff_ctx][AOMMIN(level, 3) - 1];
} else {
cost += coeff_costs->base_cost[coeff_ctx][AOMMIN(level, 3)];
}
#else
cost += coeff_costs->base_cost[coeff_ctx][AOMMIN(level, 3)];
#endif
#else // CONFIG_LV_MAP_MULTI
if (c < eob - 1) {
cost += coeff_costs->nz_map_cost[coeff_ctx][is_nz];
......@@ -1496,18 +1501,11 @@ static int get_coeff_cost(const tran_low_t qc, const int scan_idx,
const int pos = scan[scan_idx];
#if CONFIG_LV_MAP_MULTI
#if USE_BASE_EOB_ALPHABET
if (is_eob) {
cost +=
txb_costs->base_eob_cost[coeff_ctx - SIG_COEF_CONTEXTS +
SIG_COEF_CONTEXTS_EOB][AOMMIN(abs_qc, 3) - 1];
cost += txb_costs->base_eob_cost[coeff_ctx][AOMMIN(abs_qc, 3) - 1];
} else {
cost += txb_costs->base_cost[coeff_ctx][AOMMIN(abs_qc, 3)];
}
#else
cost += txb_costs->base_cost[coeff_ctx][AOMMIN(abs_qc, 3)];
#endif
#else
if (scan_idx < txb_info->eob - 1) {
cost += txb_costs->nz_map_cost[coeff_ctx][is_nz];
......@@ -1840,7 +1838,11 @@ static int optimize_txb(TxbInfo *txb_info, const LV_MAP_COEFF_COST *txb_costs,
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 =
#if CONFIG_LV_MAP_MULTI
RDCOST(txb_info->rdmult, accu_rate, accu_dist) + stats.nz_rd;
#else
RDCOST(txb_info->rdmult, accu_rate + stats.nz_rate, accu_dist);
#endif
if (cur_eob_rd_cost <= prev_eob_rd_cost) {
update = 1;
for (int j = si + 1; j < txb_info->eob; j++) {
......@@ -1857,15 +1859,22 @@ static int optimize_txb(TxbInfo *txb_info, const LV_MAP_COEFF_COST *txb_costs,
1,
#endif
txb_costs, txb_info);
accu_rate += stats.rate;
accu_dist += stats.dist;
if ((stats.rd_low < stats.rd) && (stats.low_qc != 0)) {
update = 1;
update_coeff(coeff_idx, stats.low_qc, txb_info);
accu_rate += stats.rate_low;
accu_dist += stats.dist_low;
} else {
accu_rate += stats.rate;
accu_dist += stats.dist;
}
continue;
}
}
int bUpdCoeff = 0;
if (stats.rd_low < stats.rd) {
if (si < txb_info->eob - 1) {
if ((si < txb_info->eob - 1)) {
bUpdCoeff = 1;
update = 1;
}
......@@ -2225,8 +2234,10 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
tx_size, td->counts, allow_update_cdf);
#endif
#if !CONFIG_LV_MAP_MULTI
unsigned int(*nz_map_count)[SIG_COEF_CONTEXTS][2] =
&(td->counts->nz_map[txsize_ctx][plane_type]);
#endif
av1_update_eob_context(eob, seg_eob, tx_size, tx_type, plane_type, ec_ctx,
td->counts, allow_update_cdf);
......@@ -2241,34 +2252,28 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
#if CONFIG_LV_MAP_MULTI
(void)is_nz;
(void)nz_map_count;
#if USE_BASE_EOB_ALPHABET
if (c == eob - 1) {
update_cdf(ec_ctx->coeff_base_eob_cdf[txsize_ctx][plane_type]
[coeff_ctx - SIG_COEF_CONTEXTS +
SIG_COEF_CONTEXTS_EOB],
AOMMIN(abs(v), 3) - 1, 3);
} else {
update_cdf(ec_ctx->coeff_base_cdf[txsize_ctx][plane_type][coeff_ctx],
AOMMIN(abs(v), 3), 4);
if (allow_update_cdf) {
if (c == eob - 1) {
assert(coeff_ctx < 4);
update_cdf(
ec_ctx->coeff_base_eob_cdf[txsize_ctx][plane_type][coeff_ctx],
AOMMIN(abs(v), 3) - 1, 3);
} else {
update_cdf(ec_ctx->coeff_base_cdf[txsize_ctx][plane_type][coeff_ctx],
AOMMIN(abs(v), 3), 4);
}
}
{
if (c < eob - 1) {
++(*nz_map_count)[coeff_ctx][is_nz];
}
if (is_nz) {
for (int k = 0; k < NUM_BASE_LEVELS; ++k) {
int is_k = (abs(v) > (k + 1));
++td->counts->coeff_base[txsize_ctx][plane_type][k][coeff_ctx][is_k];
if (is_k == 0) break;
}
if (c == eob - 1) {
assert(coeff_ctx < 4);
++td->counts->coeff_base_eob_multi[txsize_ctx][plane_type][coeff_ctx]
[AOMMIN(abs(v), 3) - 1];
} else {
++td->counts->coeff_base_multi[txsize_ctx][plane_type][coeff_ctx]
[AOMMIN(abs(v), 3)];
}
}
#else
update_cdf(ec_ctx->coeff_base_cdf[txsize_ctx][plane_type][coeff_ctx],
AOMMIN(abs(v), 3), 4);
#endif
#else
if (c < eob - 1) {
++(*nz_map_count)[coeff_ctx][is_nz];
......@@ -2332,13 +2337,16 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
#endif
for (idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) {
const int k = AOMMIN(base_range - idx, BR_CDF_SIZE - 1);
update_cdf(
if (allow_update_cdf) {
update_cdf(
#if 0
ec_ctx->coeff_br_cdf[AOMMIN(txsize_ctx, TX_16X16)][plane_type][ctx],
#else
ec_ctx->coeff_br_cdf[AOMMIN(txsize_ctx, TX_32X32)][plane_type][ctx],
ec_ctx
->coeff_br_cdf[AOMMIN(txsize_ctx, TX_32X32)][plane_type][ctx],
#endif
k, BR_CDF_SIZE);
k, BR_CDF_SIZE);
}
for (int lps = 0; lps < BR_CDF_SIZE - 1; lps++) {
#if 0
++td->counts->coeff_lps[AOMMIN(txsize_ctx, TX_16X16)][plane_type][lps]
......
......@@ -426,12 +426,10 @@ void av1_fill_coeff_costs(MACROBLOCK *x, FRAME_CONTEXT *fc) {
fc->txb_skip_cdf[tx_size][ctx], NULL);
#if CONFIG_LV_MAP_MULTI
#if USE_BASE_EOB_ALPHABET
for (int ctx = 0; ctx < SIG_COEF_CONTEXTS_EOB; ++ctx)
av1_cost_tokens_from_cdf(pcost->base_eob_cost[ctx],
fc->coeff_base_eob_cdf[tx_size][plane][ctx],
NULL);
#endif
for (int ctx = 0; ctx < SIG_COEF_CONTEXTS; ++ctx)
av1_cost_tokens_from_cdf(pcost->base_cost[ctx],
fc->coeff_base_cdf[tx_size][plane][ctx], NULL);
......
......@@ -438,7 +438,7 @@ void av1_get_nz_map_contexts_sse2(const uint8_t *const levels,
#if CONFIG_LV_MAP_MULTI
const int last_idx = eob - 1;
if (!last_idx) {
coeff_contexts[0] = SIG_COEF_CONTEXTS - 4;
coeff_contexts[0] = 0;
return;
}
#else
......@@ -503,10 +503,10 @@ void av1_get_nz_map_contexts_sse2(const uint8_t *const levels,
const int bwl = get_txb_bwl(tx_size);
const int pos = scan[last_idx];
if (last_idx <= (height << bwl) / 8)
coeff_contexts[pos] = SIG_COEF_CONTEXTS - 3;
coeff_contexts[pos] = 1;
else if (last_idx <= (height << bwl) / 4)
coeff_contexts[pos] = SIG_COEF_CONTEXTS - 2;
coeff_contexts[pos] = 2;
else
coeff_contexts[pos] = SIG_COEF_CONTEXTS - 1;
coeff_contexts[pos] = 3;
#endif
}
......@@ -201,18 +201,22 @@ static int counts_to_cdf(const aom_count_type *counts, aom_cdf_prob *cdf,
fprintf(stderr, "Allocating csum array failed!\n");
return 1;
}
csum[0] = counts[0];
for (int i = 1; i < modes; ++i) csum[i] = counts[i] + csum[i - 1];
csum[0] = counts[0] + 1;
for (int i = 1; i < modes; ++i) csum[i] = counts[i] + 1 + csum[i - 1];
int64_t sum = csum[modes - 1];
int64_t round_shift = sum >> 1;
for (int i = 0; i < modes; ++i) {
if (sum <= 0)
cdf[i] = CDF_PROB_TOP;
else
if (sum <= 0) {
cdf[i] = CDF_PROB_TOP - modes + i + 1;
} else {
cdf[i] = (csum[i] * CDF_PROB_TOP + round_shift) / sum;
cdf[i] = AOMMIN(cdf[i], CDF_PROB_TOP - (modes - 1 + i) * 4);
cdf[i] = (i == 0) ? AOMMAX(cdf[i], 4) : AOMMAX(cdf[i], cdf[i - 1] + 4);
}
}
if (sum <= 0) cdf[0] = CDF_PROB_TOP - 1;
// if (sum <= 0) cdf[0] = CDF_PROB_TOP - 1;
return 0;
}
......@@ -568,20 +572,6 @@ int main(int argc, const char **argv) {
#endif
#if CONFIG_LV_MAP
cts_each_dim[0] = TX_SIZES;
cts_each_dim[1] = PLANE_TYPES;
cts_each_dim[2] = NUM_BASE_LEVELS;
cts_each_dim[3] = COEFF_BASE_CONTEXTS;
cts_each_dim[4] = 2;
optimize_entropy_table(&fc.coeff_base[0][0][0][0][0], probsfile, 5,
cts_each_dim, NULL, 1,
"static const aom_prob "
"default_coeff_base[TX_SIZES][PLANE_TYPES][NUM_BASE_"
"LEVELS][COEFF_BASE_CONTEXTS]");
optimize_cdf_table(&fc.coeff_base[0][0][0][0][0], probsfile, 5, cts_each_dim,
"static const aom_cdf_prob "
"default_coeff_base_cdf[TX_SIZES][PLANE_TYPES][NUM_BASE_"
"LEVELS][COEFF_BASE_CONTEXTS][CDF_SIZE(2)]");
cts_each_dim[0] = TX_SIZES;
cts_each_dim[1] = TXB_SKIP_CONTEXTS;
......@@ -595,19 +585,6 @@ int main(int argc, const char **argv) {
"default_nz_map_cdf[TX_SIZES][PLANE_TYPES][SIG_COEF_"
"CONTEXTS][CDF_SIZE(2)]");
cts_each_dim[0] = TX_SIZES;
cts_each_dim[1] = PLANE_TYPES;
cts_each_dim[2] = SIG_COEF_CONTEXTS;
cts_each_dim[3] = 2;
optimize_entropy_table(
&fc.nz_map[0][0][0][0], probsfile, 4, cts_each_dim, NULL, 1,
"static const aom_prob "
"default_nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS]");
optimize_cdf_table(&fc.nz_map[0][0][0][0], probsfile, 4, cts_each_dim,
"static const aom_cdf_prob "
"default_nz_map_cdf[TX_SIZES][PLANE_TYPES][SIG_COEF_"
"CONTEXTS][CDF_SIZE(2)]");
cts_each_dim[0] = TX_SIZES;