Commit 8e89e2f2 authored by Dmitry Kovalev's avatar Dmitry Kovalev

Cleaning up vp9_entropy.h file.

Renaming constants for consistency:
  DCT_VAL_CATEGORY1 => CATEGORY1_TOKEN
  DCT_VAL_CATEGORY2 => CATEGORY2_TOKEN
  DCT_VAL_CATEGORY3 => CATEGORY3_TOKEN
  DCT_VAL_CATEGORY4 => CATEGORY4_TOKEN
  DCT_VAL_CATEGORY5 => CATEGORY5_TOKEN
  DCT_VAL_CATEGORY6 => CATEGORY6_TOKEN
  DCT_EOB_TOKEN     => EOB_TOKEN
  DCT_EOB_MODEL_TOKEN => EOB_MODEL_TOKEN
  MAX_ENTROPY_TOKENS => ENTROPY_TOKENS

Moving constants:
  INTER_MODE_CONTEXTS from vp9_entropy.h to vp9_blockd.h.
  EOSB_TOKEN from vp9_entropy.h to vp9_tokenize.h

Change-Id: I5fcbf081318e1d365792b6d290a930c6cb0f3fc2
parent 4585b9db
......@@ -26,8 +26,9 @@
#include "vp9/common/vp9_seg_common.h"
#include "vp9/common/vp9_treecoder.h"
#define BLOCK_SIZE_GROUPS 4
#define BLOCK_SIZE_GROUPS 4
#define MBSKIP_CONTEXTS 3
#define INTER_MODE_CONTEXTS 7
/* Segment Feature Masks */
#define MAX_MV_REF_CANDIDATES 2
......
......@@ -109,13 +109,13 @@ DECLARE_ALIGNED(16, const uint8_t, vp9_coefband_trans_4x4[16]) = {
0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5,
};
DECLARE_ALIGNED(16, const uint8_t, vp9_pt_energy_class[MAX_ENTROPY_TOKENS]) = {
DECLARE_ALIGNED(16, const uint8_t, vp9_pt_energy_class[ENTROPY_TOKENS]) = {
0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 5
};
const vp9_tree_index vp9_coefmodel_tree[6] = {
-DCT_EOB_MODEL_TOKEN, 2, /* 0 = EOB */
-ZERO_TOKEN, 4, /* 1 = ZERO */
const vp9_tree_index vp9_coefmodel_tree[TREE_SIZE(UNCONSTRAINED_NODES + 1)] = {
-EOB_MODEL_TOKEN, 2,
-ZERO_TOKEN, 4,
-ONE_TOKEN, -TWO_TOKEN,
};
......
......@@ -21,30 +21,27 @@
#define DIFF_UPDATE_PROB 252
/* Coefficient token alphabet */
#define ZERO_TOKEN 0 /* 0 Extra Bits 0+0 */
#define ONE_TOKEN 1 /* 1 Extra Bits 0+1 */
#define TWO_TOKEN 2 /* 2 Extra Bits 0+1 */
#define THREE_TOKEN 3 /* 3 Extra Bits 0+1 */
#define FOUR_TOKEN 4 /* 4 Extra Bits 0+1 */
#define DCT_VAL_CATEGORY1 5 /* 5-6 Extra Bits 1+1 */
#define DCT_VAL_CATEGORY2 6 /* 7-10 Extra Bits 2+1 */
#define DCT_VAL_CATEGORY3 7 /* 11-18 Extra Bits 3+1 */
#define DCT_VAL_CATEGORY4 8 /* 19-34 Extra Bits 4+1 */
#define DCT_VAL_CATEGORY5 9 /* 35-66 Extra Bits 5+1 */
#define DCT_VAL_CATEGORY6 10 /* 67+ Extra Bits 14+1 */
#define DCT_EOB_TOKEN 11 /* EOB Extra Bits 0+0 */
#define MAX_ENTROPY_TOKENS 12
#define ENTROPY_NODES 11
#define EOSB_TOKEN 127 /* Not signalled, encoder only */
#define INTER_MODE_CONTEXTS 7
extern DECLARE_ALIGNED(16, const uint8_t,
vp9_pt_energy_class[MAX_ENTROPY_TOKENS]);
#define DCT_EOB_MODEL_TOKEN 3 /* EOB Extra Bits 0+0 */
// Coefficient token alphabet
#define ZERO_TOKEN 0 // 0 Extra Bits 0+0
#define ONE_TOKEN 1 // 1 Extra Bits 0+1
#define TWO_TOKEN 2 // 2 Extra Bits 0+1
#define THREE_TOKEN 3 // 3 Extra Bits 0+1
#define FOUR_TOKEN 4 // 4 Extra Bits 0+1
#define CATEGORY1_TOKEN 5 // 5-6 Extra Bits 1+1
#define CATEGORY2_TOKEN 6 // 7-10 Extra Bits 2+1
#define CATEGORY3_TOKEN 7 // 11-18 Extra Bits 3+1
#define CATEGORY4_TOKEN 8 // 19-34 Extra Bits 4+1
#define CATEGORY5_TOKEN 9 // 35-66 Extra Bits 5+1
#define CATEGORY6_TOKEN 10 // 67+ Extra Bits 14+1
#define EOB_TOKEN 11 // EOB Extra Bits 0+0
#define ENTROPY_TOKENS 12
#define ENTROPY_NODES 11
extern DECLARE_ALIGNED(16, const uint8_t, vp9_pt_energy_class[ENTROPY_TOKENS]);
#define EOB_MODEL_TOKEN 3
extern const vp9_tree_index vp9_coefmodel_tree[];
typedef struct {
......@@ -55,7 +52,7 @@ typedef struct {
} vp9_extra_bit;
// indexed by token value
extern const vp9_extra_bit vp9_extra_bits[MAX_ENTROPY_TOKENS];
extern const vp9_extra_bit vp9_extra_bits[ENTROPY_TOKENS];
#define MAX_PROB 255
#define DCT_MAX_VALUE 16384
......@@ -90,7 +87,7 @@ extern const vp9_extra_bit vp9_extra_bits[MAX_ENTROPY_TOKENS];
// #define ENTROPY_STATS
typedef unsigned int vp9_coeff_count[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[MAX_ENTROPY_TOKENS];
[ENTROPY_TOKENS];
typedef unsigned int vp9_coeff_stats[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[ENTROPY_NODES][2];
......
......@@ -116,7 +116,7 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd,
if (!cm->frame_parallel_decoding_mode)
++eob_branch_count[band][pt];
if (!vp9_read(r, prob[EOB_CONTEXT_NODE])) {
INCREMENT_COUNT(DCT_EOB_MODEL_TOKEN);
INCREMENT_COUNT(EOB_MODEL_TOKEN);
break;
}
......@@ -156,12 +156,12 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd,
if (!vp9_read(r, prob[CAT_ONE_CONTEXT_NODE])) {
val = CAT1_MIN_VAL;
ADJUST_COEF(CAT1_PROB0, 0);
WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY1);
WRITE_COEF_CONTINUE(val, CATEGORY1_TOKEN);
}
val = CAT2_MIN_VAL;
ADJUST_COEF(CAT2_PROB1, 1);
ADJUST_COEF(CAT2_PROB0, 0);
WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY2);
WRITE_COEF_CONTINUE(val, CATEGORY2_TOKEN);
}
if (!vp9_read(r, prob[CAT_THREEFOUR_CONTEXT_NODE])) {
......@@ -170,14 +170,14 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd,
ADJUST_COEF(CAT3_PROB2, 2);
ADJUST_COEF(CAT3_PROB1, 1);
ADJUST_COEF(CAT3_PROB0, 0);
WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY3);
WRITE_COEF_CONTINUE(val, CATEGORY3_TOKEN);
}
val = CAT4_MIN_VAL;
ADJUST_COEF(CAT4_PROB3, 3);
ADJUST_COEF(CAT4_PROB2, 2);
ADJUST_COEF(CAT4_PROB1, 1);
ADJUST_COEF(CAT4_PROB0, 0);
WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY4);
WRITE_COEF_CONTINUE(val, CATEGORY4_TOKEN);
}
if (!vp9_read(r, prob[CAT_FIVE_CONTEXT_NODE])) {
......@@ -187,7 +187,7 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd,
ADJUST_COEF(CAT5_PROB2, 2);
ADJUST_COEF(CAT5_PROB1, 1);
ADJUST_COEF(CAT5_PROB0, 0);
WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY5);
WRITE_COEF_CONTINUE(val, CATEGORY5_TOKEN);
}
val = 0;
cat6 = cat6_prob;
......@@ -195,7 +195,7 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd,
val = (val << 1) | vp9_read(r, *cat6++);
val += CAT6_MIN_VAL;
WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY6);
WRITE_COEF_CONTINUE(val, CATEGORY6_TOKEN);
}
return c;
......
......@@ -279,7 +279,7 @@ static void pack_mb_tokens(vp9_writer* const w,
// is split into two treed writes. The first treed write takes care of the
// unconstrained nodes. The second treed write takes care of the
// constrained nodes.
if (t >= TWO_TOKEN && t < DCT_EOB_TOKEN) {
if (t >= TWO_TOKEN && t < EOB_TOKEN) {
int len = UNCONSTRAINED_NODES - p->skip_eob_node;
int bits = v >> (n - len);
treed_write(w, vp9_coef_tree, p->context_tree, bits, len, i);
......@@ -679,10 +679,10 @@ static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE tx_size) {
#ifdef ENTROPY_STATS
if (!cpi->dummy_packing) {
int t;
for (t = 0; t < MAX_ENTROPY_TOKENS; ++t)
for (t = 0; t < ENTROPY_TOKENS; ++t)
context_counters[tx_size][i][j][k][l][t] +=
coef_counts[i][j][k][l][t];
context_counters[tx_size][i][j][k][l][MAX_ENTROPY_TOKENS] +=
context_counters[tx_size][i][j][k][l][ENTROPY_TOKENS] +=
eob_branch_ct[i][j][k][l];
}
#endif
......
......@@ -86,7 +86,7 @@ struct macroblock_plane {
/* The [2] dimension is for whether we skip the EOB node (i.e. if previous
* coefficient in this block was zero) or not. */
typedef unsigned int vp9_coeff_cost[BLOCK_TYPES][REF_TYPES][COEF_BANDS][2]
[PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS];
[PREV_COEF_CONTEXTS][ENTROPY_TOKENS];
typedef struct macroblock MACROBLOCK;
struct macroblock {
......
......@@ -176,7 +176,7 @@ static void optimize_b(MACROBLOCK *mb,
tokens[eob][0].rate = 0;
tokens[eob][0].error = 0;
tokens[eob][0].next = default_eob;
tokens[eob][0].token = DCT_EOB_TOKEN;
tokens[eob][0].token = EOB_TOKEN;
tokens[eob][0].qc = 0;
*(tokens[eob] + 1) = *(tokens[eob] + 0);
next = eob;
......@@ -243,21 +243,19 @@ static void optimize_b(MACROBLOCK *mb,
/* If we reduced this coefficient to zero, check to see if
* we need to move the EOB back here.
*/
t0 = tokens[next][0].token == DCT_EOB_TOKEN ?
DCT_EOB_TOKEN : ZERO_TOKEN;
t1 = tokens[next][1].token == DCT_EOB_TOKEN ?
DCT_EOB_TOKEN : ZERO_TOKEN;
t0 = tokens[next][0].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN;
t1 = tokens[next][1].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN;
} else {
t0 = t1 = (vp9_dct_value_tokens_ptr + x)->token;
}
if (next < default_eob) {
band = band_translate[i + 1];
if (t0 != DCT_EOB_TOKEN) {
if (t0 != EOB_TOKEN) {
pt = trellis_get_coeff_context(scan, nb, i, t0, token_cache);
rate0 += mb->token_costs[tx_size][type][ref][band][!x][pt]
[tokens[next][0].token];
}
if (t1 != DCT_EOB_TOKEN) {
if (t1 != EOB_TOKEN) {
pt = trellis_get_coeff_context(scan, nb, i, t1, token_cache);
rate1 += mb->token_costs[tx_size][type][ref][band][!x][pt]
[tokens[next][1].token];
......@@ -289,12 +287,12 @@ static void optimize_b(MACROBLOCK *mb,
t0 = tokens[next][0].token;
t1 = tokens[next][1].token;
/* Update the cost of each path if we're past the EOB token. */
if (t0 != DCT_EOB_TOKEN) {
if (t0 != EOB_TOKEN) {
tokens[next][0].rate +=
mb->token_costs[tx_size][type][ref][band][1][0][t0];
tokens[next][0].token = ZERO_TOKEN;
}
if (t1 != DCT_EOB_TOKEN) {
if (t1 != EOB_TOKEN) {
tokens[next][1].rate +=
mb->token_costs[tx_size][type][ref][band][1][0][t1];
tokens[next][1].token = ZERO_TOKEN;
......
......@@ -2609,9 +2609,9 @@ static void full_to_model_count(unsigned int *model_count,
model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN];
model_count[ONE_TOKEN] = full_count[ONE_TOKEN];
model_count[TWO_TOKEN] = full_count[TWO_TOKEN];
for (n = THREE_TOKEN; n < DCT_EOB_TOKEN; ++n)
for (n = THREE_TOKEN; n < EOB_TOKEN; ++n)
model_count[TWO_TOKEN] += full_count[n];
model_count[DCT_EOB_MODEL_TOKEN] = full_count[DCT_EOB_TOKEN];
model_count[EOB_MODEL_TOKEN] = full_count[EOB_TOKEN];
}
static void full_to_model_counts(
......
......@@ -165,8 +165,8 @@ static void fill_token_costs(vp9_coeff_cost *c,
vp9_coef_tree);
vp9_cost_tokens_skip((int *)c[t][i][j][k][1][l], probs,
vp9_coef_tree);
assert(c[t][i][j][k][0][l][DCT_EOB_TOKEN] ==
c[t][i][j][k][1][l][DCT_EOB_TOKEN]);
assert(c[t][i][j][k][0][l][EOB_TOKEN] ==
c[t][i][j][k][1][l][EOB_TOKEN]);
}
}
......@@ -528,7 +528,7 @@ static INLINE int cost_coeffs(MACROBLOCK *x,
const int eob = pd->eobs[block];
const int16_t *const qcoeff_ptr = BLOCK_OFFSET(p->qcoeff, block);
const int ref = mbmi->ref_frame[0] != INTRA_FRAME;
unsigned int (*token_costs)[2][PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS] =
unsigned int (*token_costs)[2][PREV_COEF_CONTEXTS][ENTROPY_TOKENS] =
x->token_costs[tx_size][type][ref];
const ENTROPY_CONTEXT above_ec = !!*A, left_ec = !!*L;
uint8_t *p_tok = x->token_cache;
......@@ -541,7 +541,7 @@ static INLINE int cost_coeffs(MACROBLOCK *x,
if (eob == 0) {
// single eob token
cost = token_costs[0][0][pt][DCT_EOB_TOKEN];
cost = token_costs[0][0][pt][EOB_TOKEN];
c = 0;
} else {
int band_left = *band_count++;
......@@ -573,7 +573,7 @@ static INLINE int cost_coeffs(MACROBLOCK *x,
// eob token
if (band_left) {
pt = get_coef_context(nb, p_tok, c);
cost += (*token_costs)[0][pt][DCT_EOB_TOKEN];
cost += (*token_costs)[0][pt][EOB_TOKEN];
}
}
......
......@@ -27,30 +27,30 @@ static int dct_value_cost[DCT_MAX_VALUE * 2];
const int *vp9_dct_value_cost_ptr;
// Array indices are identical to previously-existing CONTEXT_NODE indices
const vp9_tree_index vp9_coef_tree[TREE_SIZE(MAX_ENTROPY_TOKENS)] = {
-DCT_EOB_TOKEN, 2, /* 0 = EOB */
-ZERO_TOKEN, 4, /* 1 = ZERO */
-ONE_TOKEN, 6, /* 2 = ONE */
8, 12, /* 3 = LOW_VAL */
-TWO_TOKEN, 10, /* 4 = TWO */
-THREE_TOKEN, -FOUR_TOKEN, /* 5 = THREE */
14, 16, /* 6 = HIGH_LOW */
-DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2, /* 7 = CAT_ONE */
18, 20, /* 8 = CAT_THREEFOUR */
-DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4, /* 9 = CAT_THREE */
-DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6 /* 10 = CAT_FIVE */
const vp9_tree_index vp9_coef_tree[TREE_SIZE(ENTROPY_TOKENS)] = {
-EOB_TOKEN, 2, // 0 = EOB
-ZERO_TOKEN, 4, // 1 = ZERO
-ONE_TOKEN, 6, // 2 = ONE
8, 12, // 3 = LOW_VAL
-TWO_TOKEN, 10, // 4 = TWO
-THREE_TOKEN, -FOUR_TOKEN, // 5 = THREE
14, 16, // 6 = HIGH_LOW
-CATEGORY1_TOKEN, -CATEGORY2_TOKEN, // 7 = CAT_ONE
18, 20, // 8 = CAT_THREEFOUR
-CATEGORY3_TOKEN, -CATEGORY4_TOKEN, // 9 = CAT_THREE
-CATEGORY5_TOKEN, -CATEGORY6_TOKEN // 10 = CAT_FIVE
};
// Unconstrained Node Tree
const vp9_tree_index vp9_coef_con_tree[TREE_SIZE(MAX_ENTROPY_TOKENS)] = {
2, 6, /* 0 = LOW_VAL */
-TWO_TOKEN, 4, /* 1 = TWO */
-THREE_TOKEN, -FOUR_TOKEN, /* 2 = THREE */
8, 10, /* 3 = HIGH_LOW */
-DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2, /* 4 = CAT_ONE */
12, 14, /* 5 = CAT_THREEFOUR */
-DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4, /* 6 = CAT_THREE */
-DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6 /* 7 = CAT_FIVE */
const vp9_tree_index vp9_coef_con_tree[TREE_SIZE(ENTROPY_TOKENS)] = {
2, 6, // 0 = LOW_VAL
-TWO_TOKEN, 4, // 1 = TWO
-THREE_TOKEN, -FOUR_TOKEN, // 2 = THREE
8, 10, // 3 = HIGH_LOW
-CATEGORY1_TOKEN, -CATEGORY2_TOKEN, // 4 = CAT_ONE
12, 14, // 5 = CAT_THREEFOUR
-CATEGORY3_TOKEN, -CATEGORY4_TOKEN, // 6 = CAT_THREE
-CATEGORY5_TOKEN, -CATEGORY6_TOKEN // 7 = CAT_FIVE
};
static const vp9_prob Pcat1[] = { 159};
......@@ -84,22 +84,22 @@ static void init_bit_trees() {
init_bit_tree(cat6, 14);
}
const vp9_extra_bit vp9_extra_bits[MAX_ENTROPY_TOKENS] = {
const vp9_extra_bit vp9_extra_bits[ENTROPY_TOKENS] = {
{0, 0, 0, 0}, // ZERO_TOKEN
{0, 0, 0, 1}, // ONE_TOKEN
{0, 0, 0, 2}, // TWO_TOKEN
{0, 0, 0, 3}, // THREE_TOKEN
{0, 0, 0, 4}, // FOUR_TOKEN
{cat1, Pcat1, 1, 5}, // DCT_VAL_CATEGORY1
{cat2, Pcat2, 2, 7}, // DCT_VAL_CATEGORY2
{cat3, Pcat3, 3, 11}, // DCT_VAL_CATEGORY3
{cat4, Pcat4, 4, 19}, // DCT_VAL_CATEGORY4
{cat5, Pcat5, 5, 35}, // DCT_VAL_CATEGORY5
{cat6, Pcat6, 14, 67}, // DCT_VAL_CATEGORY6
{0, 0, 0, 0} // DCT_EOB_TOKEN
{cat1, Pcat1, 1, 5}, // CATEGORY1_TOKEN
{cat2, Pcat2, 2, 7}, // CATEGORY2_TOKEN
{cat3, Pcat3, 3, 11}, // CATEGORY3_TOKEN
{cat4, Pcat4, 4, 19}, // CATEGORY4_TOKEN
{cat5, Pcat5, 5, 35}, // CATEGORY5_TOKEN
{cat6, Pcat6, 14, 67}, // CATEGORY6_TOKEN
{0, 0, 0, 0} // EOB_TOKEN
};
struct vp9_token vp9_coef_encodings[MAX_ENTROPY_TOKENS];
struct vp9_token vp9_coef_encodings[ENTROPY_TOKENS];
void vp9_coef_tree_initialize() {
init_bit_trees();
......@@ -226,7 +226,7 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE plane_bsize,
t->extra = vp9_dct_value_tokens_ptr[v].extra;
token = vp9_dct_value_tokens_ptr[v].token;
} else {
token = DCT_EOB_TOKEN;
token = EOB_TOKEN;
}
t->token = token;
......
......@@ -16,6 +16,8 @@
void vp9_tokenize_initialize();
#define EOSB_TOKEN 127 // Not signalled, encoder only
typedef struct {
int16_t token;
int16_t extra;
......
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