diff --git a/vp9/common/vp9_entropy.c b/vp9/common/vp9_entropy.c index 31ea2b5ef..e21eaba83 100644 --- a/vp9/common/vp9_entropy.c +++ b/vp9/common/vp9_entropy.c @@ -318,6 +318,29 @@ vp9_extra_bit_struct vp9_extra_bits[12] = { #include "vp9/common/vp9_default_coef_probs.h" +// This function updates and then returns n AC coefficient context +// This is currently a placeholder function to allow experimentation +// using various context models based on the energy earlier tokens +// within the current block. +// +// For now it just returns the previously used context. +int vp9_get_coef_context(int * recent_energy, int token) { + // int token_energy; + // int av_energy; + + // Placeholder code for experiments with token energy + // as a coefficient context. + /*token_energy = ((token != DCT_EOB_TOKEN) ? token : 0); + if (token_energy) { + av_energy = (token_energy + *recent_energy + 1) >> 1; + } else { + av_energy = 0; + } + *recent_energy = token_energy;*/ + + return vp9_prev_token_class[token]; +}; + void vp9_default_coef_probs(VP9_COMMON *pc) { vpx_memcpy(pc->fc.coef_probs_4x4, default_coef_probs_4x4, sizeof(pc->fc.coef_probs_4x4)); diff --git a/vp9/common/vp9_entropy.h b/vp9/common/vp9_entropy.h index c6f51e0c6..1979638d4 100644 --- a/vp9/common/vp9_entropy.h +++ b/vp9/common/vp9_entropy.h @@ -106,9 +106,6 @@ typedef vp9_prob vp9_coeff_probs[COEF_BANDS][PREV_COEF_CONTEXTS] #define SUBEXP_PARAM 4 /* Subexponential code parameter */ #define MODULUS_PARAM 13 /* Modulus parameter */ -extern DECLARE_ALIGNED(16, const uint8_t, - vp9_prev_token_class[MAX_ENTROPY_TOKENS]); - struct VP9Common; void vp9_default_coef_probs(struct VP9Common *); extern DECLARE_ALIGNED(16, const int, vp9_default_zig_zag1d_4x4[16]); @@ -129,4 +126,5 @@ static void vp9_reset_mb_tokens_context(MACROBLOCKD* const xd) { vpx_memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)); } +extern int vp9_get_coef_context(int * recent_energy, int token); #endif // VP9_COMMON_VP9_ENTROPY_H_ diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c index 9e1df063c..bfdb486b8 100644 --- a/vp9/decoder/vp9_detokenize.c +++ b/vp9/decoder/vp9_detokenize.c @@ -65,8 +65,8 @@ static int get_signed(BOOL_DECODER *br, int value_to_sign) { #define INCREMENT_COUNT(token) \ do { \ - coef_counts[type][coef_bands[c]][pt][token]++; \ - pt = vp9_prev_token_class[token]; \ + coef_counts[type][coef_bands[c]][pt][token]++; \ + pt = vp9_get_coef_context(&recent_energy, token); \ } while (0) #define WRITE_COEF_CONTINUE(val, token) \ @@ -95,6 +95,7 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd, const int lidx = vp9_block2left[txfm_size][block_idx]; ENTROPY_CONTEXT above_ec = A0[aidx] != 0, left_ec = L0[lidx] != 0; FRAME_CONTEXT *const fc = &dx->common.fc; + int recent_energy = 0; int nodc = (type == PLANE_TYPE_Y_NO_DC); int pt, c = nodc; vp9_coeff_probs *coef_probs; diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c index e7fb7a8e3..12082a88d 100644 --- a/vp9/encoder/vp9_encodemb.c +++ b/vp9/encoder/vp9_encodemb.c @@ -361,6 +361,13 @@ static const int plane_rd_mult[4] = { }\ } +// This function is a place holder for now but may ultimately need +// to scan previous tokens to work out the correct context. +static int trellis_get_coeff_context(int token) { + int recent_energy = 0; + return vp9_get_coef_context(&recent_energy, token); +} + static void optimize_b(MACROBLOCK *mb, int i, PLANE_TYPE type, ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, int tx_size) { @@ -453,7 +460,7 @@ static void optimize_b(MACROBLOCK *mb, int i, PLANE_TYPE type, /* Consider both possible successor states. */ if (next < default_eob) { band = bands[i + 1]; - pt = vp9_prev_token_class[t0]; + pt = trellis_get_coeff_context(t0); rate0 += mb->token_costs[tx_size][type][band][pt][tokens[next][0].token]; rate1 += @@ -501,12 +508,12 @@ static void optimize_b(MACROBLOCK *mb, int i, PLANE_TYPE type, if (next < default_eob) { band = bands[i + 1]; if (t0 != DCT_EOB_TOKEN) { - pt = vp9_prev_token_class[t0]; + pt = trellis_get_coeff_context(t0); rate0 += mb->token_costs[tx_size][type][band][pt][ tokens[next][0].token]; } if (t1 != DCT_EOB_TOKEN) { - pt = vp9_prev_token_class[t1]; + pt = trellis_get_coeff_context(t1); rate1 += mb->token_costs[tx_size][type][band][pt][ tokens[next][1].token]; } diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 5a2f1ebbd..8385a1872 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -490,23 +490,25 @@ static INLINE int cost_coeffs(MACROBLOCK *mb, seg_eob = 0; if (tx_type != DCT_DCT) { + int recent_energy = 0; for (; c < eob; c++) { int v = qcoeff_ptr[scan[c]]; int t = vp9_dct_value_tokens_ptr[v].Token; cost += token_costs[band[c]][pt][t]; cost += vp9_dct_value_cost_ptr[v]; - pt = vp9_prev_token_class[t]; + pt = vp9_get_coef_context(&recent_energy, t); } if (c < seg_eob) cost += mb->hybrid_token_costs[tx_size][type][band[c]] [pt][DCT_EOB_TOKEN]; } else { + int recent_energy = 0; for (; c < eob; c++) { int v = qcoeff_ptr[scan[c]]; int t = vp9_dct_value_tokens_ptr[v].Token; cost += token_costs[band[c]][pt][t]; cost += vp9_dct_value_cost_ptr[v]; - pt = vp9_prev_token_class[t]; + pt = vp9_get_coef_context(&recent_energy, t); } if (c < seg_eob) cost += mb->token_costs[tx_size][type][band[c]] @@ -670,7 +672,8 @@ static void macro_block_yrd_16x16(MACROBLOCK *mb, int *Rate, int *Distortion, // TODO(jingning) is it possible to quickly determine whether to force // trailing coefficients to be zero, instead of running trellis // optimization in the rate-distortion optimization loop? - if (mb->optimize && mb->e_mbd.mode_info_context->mbmi.mode < I8X8_PRED) + if (mb->optimize && + xd->mode_info_context->mbmi.mode < I8X8_PRED) vp9_optimize_mby_16x16(mb); d = vp9_mbblock_error(mb, 0); diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c index 25b29d588..12fee9037 100644 --- a/vp9/encoder/vp9_tokenize.c +++ b/vp9/encoder/vp9_tokenize.c @@ -109,6 +109,7 @@ static void tokenize_b(VP9_COMP *cpi, int dry_run) { int pt; /* near block/prev token context index */ int c = (type == PLANE_TYPE_Y_NO_DC) ? 1 : 0; + int recent_energy = 0; const BLOCKD * const b = xd->block + ib; const int eob = b->eob; /* one beyond last nonzero coeff */ TOKENEXTRA *t = *tp; /* store tokens starting here */ @@ -245,7 +246,8 @@ static void tokenize_b(VP9_COMP *cpi, if (!dry_run) { ++counts[type][band][pt][token]; } - pt = vp9_prev_token_class[token]; + + pt = vp9_get_coef_context(&recent_energy, token); ++t; } while (c < eob && ++c < seg_eob);