Commit 74e2307b authored by Angie Chiang's avatar Angie Chiang

Use txb_entropy_ctx to store entropy ctx of lv_map

1) Add txb_entropy_ctx into MACROBLOCK_PLANE and PICK_MODE_CONTEXT

2) Add av1_get_txb_entropy_context() to compute the entropy context

3) Compute and sore the entropy context before av1_xform_quant()
return

Change-Id: Ia2170523af3163b9456f7c6a305c1e77ad2b23be
parent 47e4b369
......@@ -45,6 +45,9 @@ typedef struct macroblock_plane {
tran_low_t *qcoeff;
tran_low_t *coeff;
uint16_t *eobs;
#if CONFIG_LV_MAP
uint8_t *txb_entropy_ctx;
#endif
struct buf_2d src;
// Quantizer setings
......
......@@ -52,6 +52,12 @@ static void alloc_mode_context(AV1_COMMON *cm, int num_4x4_blk,
aom_memalign(32, num_pix * sizeof(*ctx->dqcoeff[i])));
CHECK_MEM_ERROR(cm, ctx->eobs[i],
aom_memalign(32, num_blk * sizeof(*ctx->eobs[i])));
#if CONFIG_LV_MAP
CHECK_MEM_ERROR(
cm, ctx->txb_entropy_ctx[i],
aom_memalign(32, num_blk * sizeof(*ctx->txb_entropy_ctx[i])));
#endif
#if CONFIG_PVQ
CHECK_MEM_ERROR(cm, ctx->pvq_ref_coeff[i],
aom_memalign(32, num_pix * sizeof(*ctx->pvq_ref_coeff[i])));
......@@ -88,6 +94,10 @@ static void free_mode_context(PICK_MODE_CONTEXT *ctx) {
#endif
aom_free(ctx->eobs[i]);
ctx->eobs[i] = 0;
#if CONFIG_LV_MAP
aom_free(ctx->txb_entropy_ctx[i]);
ctx->txb_entropy_ctx[i] = 0;
#endif
}
#if CONFIG_PALETTE
......
......@@ -42,6 +42,9 @@ typedef struct {
tran_low_t *pvq_ref_coeff[MAX_MB_PLANE];
#endif
uint16_t *eobs[MAX_MB_PLANE];
#if CONFIG_LV_MAP
uint8_t *txb_entropy_ctx[MAX_MB_PLANE];
#endif
int num_4x4_blk;
int skip;
......
......@@ -1137,6 +1137,9 @@ static void update_state(const AV1_COMP *const cpi, ThreadData *td,
pd[i].pvq_ref_coeff = ctx->pvq_ref_coeff[i];
#endif
p[i].eobs = ctx->eobs[i];
#if CONFIG_LV_MAP
p[i].txb_entropy_ctx = ctx->txb_entropy_ctx[i];
#endif // CONFIG_LV_MAP
}
#if CONFIG_PALETTE
for (i = 0; i < 2; ++i) pd[i].color_index_map = ctx->color_index_map[i];
......@@ -1856,6 +1859,9 @@ static void rd_pick_sb_modes(const AV1_COMP *const cpi, TileDataEnc *tile_data,
pd[i].pvq_ref_coeff = ctx->pvq_ref_coeff[i];
#endif
p[i].eobs = ctx->eobs[i];
#if CONFIG_LV_MAP
p[i].txb_entropy_ctx = ctx->txb_entropy_ctx[i];
#endif
}
#if CONFIG_PALETTE
......
......@@ -25,6 +25,9 @@
#include "av1/encoder/av1_quantize.h"
#include "av1/encoder/encodemb.h"
#if CONFIG_LV_MAP
#include "av1/encoder/encodetxb.h"
#endif
#include "av1/encoder/hybrid_fwd_txfm.h"
#include "av1/encoder/rd.h"
#include "av1/encoder/tokenize.h"
......@@ -633,6 +636,10 @@ void av1_xform_quant(const AV1_COMMON *cm, MACROBLOCK *x, int plane, int block,
av1_quantize_skip(tx2d_size, qcoeff, dqcoeff, eob);
}
}
#if CONFIG_LV_MAP
p->txb_entropy_ctx[block] =
(uint8_t)av1_get_txb_entropy_context(qcoeff, scan_order, *eob);
#endif // CONFIG_LV_MAP
return;
}
#endif // CONFIG_AOM_HIGHBITDEPTH
......@@ -645,7 +652,11 @@ void av1_xform_quant(const AV1_COMMON *cm, MACROBLOCK *x, int plane, int block,
av1_quantize_skip(tx2d_size, qcoeff, dqcoeff, eob);
}
}
#else // #if !CONFIG_PVQ
#if CONFIG_LV_MAP
p->txb_entropy_ctx[block] =
(uint8_t)av1_get_txb_entropy_context(qcoeff, scan_order, *eob);
#endif // CONFIG_LV_MAP
#else // #if !CONFIG_PVQ
(void)xform_quant_idx;
#if CONFIG_AOM_HIGHBITDEPTH
fwd_txfm_param.bd = xd->bd;
......@@ -1015,7 +1026,11 @@ void av1_set_txb_context(MACROBLOCK *x, int plane, int block, TX_SIZE tx_size,
(void)tx_size;
struct macroblock_plane *p = &x->plane[plane];
#if !CONFIG_LV_MAP
*a = *l = p->eobs[block] > 0;
#else // !CONFIG_LV_MAP
*a = *l = p->txb_entropy_ctx[block];
#endif // !CONFIG_LV_MAP
#if CONFIG_VAR_TX || CONFIG_LV_MAP
int i;
......
......@@ -367,6 +367,21 @@ typedef struct TxbParams {
int rate;
} TxbParams;
int av1_get_txb_entropy_context(const tran_low_t *qcoeff,
const SCAN_ORDER *scan_order, int eob) {
const int16_t *scan = scan_order->scan;
int cul_level = 0;
int c;
for (c = 0; c < eob; ++c) {
cul_level += abs(qcoeff[scan[c]]);
}
cul_level = AOMMIN(COEFF_CONTEXT_MASK, cul_level);
set_dc_sign(&cul_level, qcoeff[0]);
return cul_level;
}
static void update_txb_context(int plane, int block, int blk_row, int blk_col,
BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
void *arg) {
......@@ -385,20 +400,9 @@ static void update_txb_context(int plane, int block, int blk_row, int blk_col,
const TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size);
const SCAN_ORDER *const scan_order =
get_scan(cm, tx_size, tx_type, is_inter_block(mbmi));
const int16_t *scan = scan_order->scan;
(void)plane_bsize;
int cul_level = 0;
int c;
for (c = 0; c < eob; ++c) {
cul_level += abs(qcoeff[scan[c]]);
}
cul_level = AOMMIN(COEFF_CONTEXT_MASK, cul_level);
// DC value
set_dc_sign(&cul_level, qcoeff[0]);
int cul_level = av1_get_txb_entropy_context(qcoeff, scan_order, eob);
av1_set_contexts(xd, pd, plane, tx_size, cul_level, blk_col, blk_row);
}
......
......@@ -32,6 +32,8 @@ void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
TXB_CTX *txb_ctx);
void av1_write_coeffs_mb(const AV1_COMMON *const cm, MACROBLOCK *x,
aom_writer *w, int plane);
int av1_get_txb_entropy_context(const tran_low_t *qcoeff,
const SCAN_ORDER *scan_order, int eob);
void av1_update_txb_context(const AV1_COMP *cpi, ThreadData *td,
RUN_TYPE dry_run, BLOCK_SIZE bsize, int *rate,
const int mi_row, const int mi_col);
......
......@@ -585,6 +585,9 @@ void av1_first_pass(AV1_COMP *cpi, const struct lookahead_entry *source) {
pd[i].pvq_ref_coeff = ctx->pvq_ref_coeff[i];
#endif
p[i].eobs = ctx->eobs[i];
#if CONFIG_LV_MAP
p[i].txb_entropy_ctx = ctx->txb_entropy_ctx[i];
#endif
}
av1_init_mv_probs(cm);
......
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