Commit eb6ef241 authored by Deb Mukherjee's avatar Deb Mukherjee

Coding con-zero count rather than EOB for coeffs

This patch revamps the entropy coding of coefficients to code first
a non-zero count per coded block and correspondingly remove the EOB
token from the token set.

STATUS:
Main encode/decode code achieving encode/decode sync - done.
Forward and backward probability updates to the nzcs - done.
Rd costing updates for nzcs - done.
Note: The dynamic progrmaming apporach used in trellis quantization
is not exactly compatible with nzcs. A suboptimal approach has been
used instead where branch costs are updated to account for changes
in the nzcs.

TODO:
Training the default probs/counts for nzcs

Change-Id: I951bc1e22f47885077a7453a09b0493daa77883d
parent a9961fa8
......@@ -245,6 +245,7 @@ EXPERIMENT_LIST="
comp_interintra_pred
enable_6tap
abovesprefmv
code_nonzerocount
"
CONFIG_LIST="
external_build
......
......@@ -250,6 +250,9 @@ typedef struct {
INTERPOLATIONFILTERTYPE interp_filter;
BLOCK_SIZE_TYPE sb_type;
#if CONFIG_CODE_NONZEROCOUNT
uint16_t nzcs[256+64*2];
#endif
} MB_MODE_INFO;
typedef struct {
......@@ -295,6 +298,9 @@ typedef struct macroblockd {
DECLARE_ALIGNED(16, int16_t, qcoeff[64*64+32*32*2]);
DECLARE_ALIGNED(16, int16_t, dqcoeff[64*64+32*32*2]);
DECLARE_ALIGNED(16, uint16_t, eobs[256+64*2]);
#if CONFIG_CODE_NONZEROCOUNT
DECLARE_ALIGNED(16, uint16_t, nzcs[256+64*2]);
#endif
/* 16 Y blocks, 4 U, 4 V, each with 16 entries. */
BLOCKD block[24];
......@@ -592,4 +598,25 @@ static void update_blockd_bmi(MACROBLOCKD *xd) {
}
}
static TX_SIZE get_uv_tx_size(const MACROBLOCKD *xd) {
TX_SIZE tx_size_uv;
if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB64X64) {
tx_size_uv = xd->mode_info_context->mbmi.txfm_size;
} else if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB32X32) {
if (xd->mode_info_context->mbmi.txfm_size == TX_32X32)
tx_size_uv = TX_16X16;
else
tx_size_uv = xd->mode_info_context->mbmi.txfm_size;
} else {
if (xd->mode_info_context->mbmi.txfm_size == TX_16X16)
tx_size_uv = TX_8X8;
else if (xd->mode_info_context->mbmi.txfm_size == TX_8X8 &&
(xd->mode_info_context->mbmi.mode == I8X8_PRED ||
xd->mode_info_context->mbmi.mode == SPLITMV))
tx_size_uv = TX_4X4;
else
tx_size_uv = xd->mode_info_context->mbmi.txfm_size;
}
return tx_size_uv;
}
#endif // VP9_COMMON_VP9_BLOCKD_H_
......@@ -17,4 +17,11 @@
#define COEF_UPDATE_PROB_8X8 252
#define COEF_UPDATE_PROB_16X16 252
#if CONFIG_CODE_NONZEROCOUNT
#define NZC_UPDATE_PROB_4X4 252
#define NZC_UPDATE_PROB_8X8 252
#define NZC_UPDATE_PROB_16X16 252
#define NZC_UPDATE_PROB_32X32 252
#endif
#endif // VP9_COMMON_VP9_COEFUPDATEPROBS_H__
......@@ -695,3 +695,130 @@ static const vp9_coeff_probs default_coef_probs_32x32[BLOCK_TYPES] = {
}
}
};
#if CONFIG_CODE_NONZEROCOUNT
// TODO(debargha): Replace with probabilities once the stats stabilize
static const unsigned int default_nzc4x4_counts[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC4X4_TOKENS] = {
{
{
{ 967652, 29023, 15039, 6952, 1568, 116 },
{ 789116, 22938, 4522, 1935, 520, 47 }
}, {
{ 967652, 29023, 15039, 6952, 1568, 116 },
{ 789116, 22938, 4522, 1935, 520, 47 }
},
}, {
{
{ 124684, 37167, 15270, 8483, 1777, 102 },
{ 10405, 12395, 3401, 3574, 2461, 771 }
}, {
{ 124684, 37167, 15270, 8483, 1777, 102 },
{ 10405, 12395, 3401, 3574, 2461, 771 }
}
}, {
{
{ 41100, 22976, 15627, 16137, 7982, 793 },
{ 4249, 3084, 2131, 4081, 6439, 1653 }
}, {
{ 41100, 22976, 15627, 16137, 7982, 793 },
{ 4249, 3084, 2131, 4081, 6439, 1653 }
}
}
};
static const unsigned int default_nzc8x8_counts[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC8X8_TOKENS] = {
{
{
{ 372988, 62777, 19440, 11812, 5145, 1917, 439, 10 },
{ 72052, 30468, 6973, 3250, 1500, 750, 375, 5 },
}, {
{ 372988, 62777, 19440, 11812, 5145, 1917, 439, 10 },
{ 72052, 30468, 6973, 3250, 1500, 750, 375, 5 },
}
}, {
{
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6 },
}, {
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6 },
}
}, {
{
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12 },
}, {
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12 },
}
}
};
static const unsigned int default_nzc16x16_counts[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC16X16_TOKENS] = {
{
{
{ 372988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2 },
{ 72052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1 },
}, {
{ 372988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2 },
{ 72052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1 },
}
}, {
{
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2 },
}, {
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2 },
}
}, {
{
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17, 10, 5 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3 },
}, {
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17, 10, 5 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3 },
}
}
};
static const unsigned int default_nzc32x32_counts[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC32X32_TOKENS] = {
{
{
{ 372988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2, 1, 0 },
{ 72052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1 },
}, {
{ 372988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2, 1, 0 },
{ 72052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1 },
}
}, {
{
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2, 1, 0 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2 },
}, {
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2, 1, 0 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2 },
}
}, {
{
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17, 10, 5, 2, 1 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3 },
}, {
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17, 10, 5, 2, 1 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3 },
}
}
};
#endif
This diff is collapsed.
......@@ -142,4 +142,80 @@ static int get_coef_band(TX_SIZE tx_size, int coef_index) {
}
extern int vp9_get_coef_context(int * recent_energy, int token);
#if CONFIG_CODE_NONZEROCOUNT
/* Alphabet for number of non-zero symbols in block */
#define NZC_0 0 /* Used for all blocks */
#define NZC_1 1 /* Used for all blocks */
#define NZC_2 2 /* Used for all blocks */
#define NZC_3TO4 3 /* Used for all blocks */
#define NZC_5TO8 4 /* Used for all blocks */
#define NZC_9TO16 5 /* Used for all blocks */
#define NZC_17TO32 6 /* Used for 8x8 and larger blocks */
#define NZC_33TO64 7 /* Used for 8x8 and larger blocks */
#define NZC_65TO128 8 /* Used for 16x16 and larger blocks */
#define NZC_129TO256 9 /* Used for 16x16 and larger blocks */
#define NZC_257TO512 10 /* Used for 32x32 and larger blocks */
#define NZC_513TO1024 11 /* Used for 32x32 and larger blocks */
/* Number of tokens for each block size */
#define NZC4X4_TOKENS 6
#define NZC8X8_TOKENS 8
#define NZC16X16_TOKENS 10
#define NZC32X32_TOKENS 12
/* Number of nodes for each block size */
#define NZC4X4_NODES 5
#define NZC8X8_NODES 7
#define NZC16X16_NODES 9
#define NZC32X32_NODES 11
/* Max number of tokens with extra bits */
#define NZC_TOKENS_EXTRA 9
/* Max number of extra bits */
#define NZC_BITS_EXTRA 9
#define MAX_NZC_CONTEXTS 3
/* nzc trees */
extern const vp9_tree_index vp9_nzc4x4_tree[];
extern const vp9_tree_index vp9_nzc8x8_tree[];
extern const vp9_tree_index vp9_nzc16x16_tree[];
extern const vp9_tree_index vp9_nzc32x32_tree[];
/* nzc encodings */
extern struct vp9_token_struct vp9_nzc4x4_encodings[NZC4X4_TOKENS];
extern struct vp9_token_struct vp9_nzc8x8_encodings[NZC8X8_TOKENS];
extern struct vp9_token_struct vp9_nzc16x16_encodings[NZC16X16_TOKENS];
extern struct vp9_token_struct vp9_nzc32x32_encodings[NZC32X32_TOKENS];
#define codenzc(x) (\
(x) <= 3 ? (x) : (x) <= 4 ? 3 : (x) <= 8 ? 4 : \
(x) <= 16 ? 5 : (x) <= 32 ? 6 : (x) <= 64 ? 7 :\
(x) <= 128 ? 8 : (x) <= 256 ? 9 : (x) <= 512 ? 10 : 11)
#define extranzcbits(c) ((c) <= 2 ? 0 : (c) - 2)
#define basenzcvalue(c) ((c) <= 2 ? (c) : (1 << ((c) - 2)) + 1)
int vp9_get_nzc_context_y_sb64(struct VP9Common *cm, MODE_INFO *cur,
int mb_row, int mb_col, int block);
int vp9_get_nzc_context_y_sb32(struct VP9Common *cm, MODE_INFO *cur,
int mb_row, int mb_col, int block);
int vp9_get_nzc_context_y_mb16(struct VP9Common *cm, MODE_INFO *cur,
int mb_row, int mb_col, int block);
int vp9_get_nzc_context_uv_sb64(struct VP9Common *cm, MODE_INFO *cur,
int mb_row, int mb_col, int block);
int vp9_get_nzc_context_uv_sb32(struct VP9Common *cm, MODE_INFO *cur,
int mb_row, int mb_col, int block);
int vp9_get_nzc_context_uv_mb16(struct VP9Common *cm, MODE_INFO *cur,
int mb_row, int mb_col, int block);
int vp9_get_nzc_context(struct VP9Common *cm, MACROBLOCKD *xd, int block);
void vp9_update_nzc_counts(struct VP9Common *cm, MACROBLOCKD *xd,
int mb_row, int mb_col);
void vp9_adapt_nzc_probs(struct VP9Common *cm);
/* Extra bit probabilities - block size agnostic */
extern const vp9_prob Pcat_nzc[MAX_NZC_CONTEXTS][NZC_TOKENS_EXTRA]
[NZC_BITS_EXTRA];
#endif // CONFIG_CODE_NONZEROCOUNT
#endif // VP9_COMMON_VP9_ENTROPY_H_
......@@ -58,10 +58,21 @@ typedef struct frame_contexts {
vp9_prob i8x8_mode_prob[VP9_I8X8_MODES - 1];
vp9_prob sub_mv_ref_prob[SUBMVREF_COUNT][VP9_SUBMVREFS - 1];
vp9_prob mbsplit_prob[VP9_NUMMBSPLITS - 1];
vp9_coeff_probs coef_probs_4x4[BLOCK_TYPES];
vp9_coeff_probs coef_probs_8x8[BLOCK_TYPES];
vp9_coeff_probs coef_probs_16x16[BLOCK_TYPES];
vp9_coeff_probs coef_probs_32x32[BLOCK_TYPES];
#if CONFIG_CODE_NONZEROCOUNT
vp9_prob nzc_probs_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC4X4_NODES];
vp9_prob nzc_probs_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC8X8_NODES];
vp9_prob nzc_probs_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC16X16_NODES];
vp9_prob nzc_probs_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC32X32_NODES];
#endif
nmv_context nmvc;
nmv_context pre_nmvc;
......@@ -84,11 +95,31 @@ typedef struct frame_contexts {
vp9_coeff_probs pre_coef_probs_8x8[BLOCK_TYPES];
vp9_coeff_probs pre_coef_probs_16x16[BLOCK_TYPES];
vp9_coeff_probs pre_coef_probs_32x32[BLOCK_TYPES];
#if CONFIG_CODE_NONZEROCOUNT
vp9_prob pre_nzc_probs_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC4X4_NODES];
vp9_prob pre_nzc_probs_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC8X8_NODES];
vp9_prob pre_nzc_probs_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC16X16_NODES];
vp9_prob pre_nzc_probs_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC32X32_NODES];
#endif
vp9_coeff_count coef_counts_4x4[BLOCK_TYPES];
vp9_coeff_count coef_counts_8x8[BLOCK_TYPES];
vp9_coeff_count coef_counts_16x16[BLOCK_TYPES];
vp9_coeff_count coef_counts_32x32[BLOCK_TYPES];
#if CONFIG_CODE_NONZEROCOUNT
unsigned int nzc_counts_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC4X4_TOKENS];
unsigned int nzc_counts_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC8X8_TOKENS];
unsigned int nzc_counts_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC16X16_TOKENS];
unsigned int nzc_counts_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
[NZC32X32_TOKENS];
#endif
nmv_context_counts NMVcount;
vp9_prob switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1]
......@@ -300,4 +331,31 @@ static void ref_cnt_fb(int *buf, int *idx, int new_idx) {
buf[new_idx]++;
}
// TODO(debargha): merge the two functions
static void set_mb_row(VP9_COMMON *cm, MACROBLOCKD *xd,
int mb_row, int block_size) {
xd->mb_to_top_edge = -((mb_row * 16) << 3);
xd->mb_to_bottom_edge = ((cm->mb_rows - block_size - mb_row) * 16) << 3;
// Are edges available for intra prediction?
xd->up_available = (mb_row != 0);
}
static void set_mb_col(VP9_COMMON *cm, MACROBLOCKD *xd,
int mb_col, int block_size) {
xd->mb_to_left_edge = -((mb_col * 16) << 3);
xd->mb_to_right_edge = ((cm->mb_cols - block_size - mb_col) * 16) << 3;
// Are edges available for intra prediction?
xd->left_available = (mb_col > cm->cur_tile_mb_col_start);
xd->right_available = (mb_col + block_size < cm->cur_tile_mb_col_end);
}
static int get_mb_row(const MACROBLOCKD *xd) {
return ((-xd->mb_to_top_edge) >> 7);
}
static int get_mb_col(const MACROBLOCKD *xd) {
return ((-xd->mb_to_left_edge) >> 7);
}
#endif // VP9_COMMON_VP9_ONYXC_INT_H_
This diff is collapsed.
......@@ -39,7 +39,7 @@
#define COEFCOUNT_TESTING
//#define DEC_DEBUG
// #define DEC_DEBUG
#ifdef DEC_DEBUG
int dec_debug = 0;
#endif
......@@ -246,7 +246,7 @@ static void decode_8x8(VP9D_COMP *pbi, MACROBLOCKD *xd,
int i;
printf("\n");
printf("qcoeff 8x8\n");
for (i = 0; i < 400; i++) {
for (i = 0; i < 384; i++) {
printf("%3d ", xd->qcoeff[i]);
if (i % 16 == 15) printf("\n");
}
......@@ -862,14 +862,9 @@ static void set_offsets(VP9D_COMP *pbi, int block_size,
* values that are in 1/8th pel units
*/
block_size >>= 4; // in mb units
xd->mb_to_top_edge = -((mb_row * 16)) << 3;
xd->mb_to_left_edge = -((mb_col * 16) << 3);
xd->mb_to_bottom_edge = ((cm->mb_rows - block_size - mb_row) * 16) << 3;
xd->mb_to_right_edge = ((cm->mb_cols - block_size - mb_col) * 16) << 3;
xd->up_available = (mb_row != 0);
xd->left_available = (mb_col > cm->cur_tile_mb_col_start);
xd->right_available = (mb_col + block_size < cm->cur_tile_mb_col_end);
set_mb_row(cm, xd, mb_row, block_size);
set_mb_col(cm, xd, mb_col, block_size);
xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
......@@ -910,20 +905,6 @@ static void set_refs(VP9D_COMP *pbi, int block_size,
xd->corrupted |= cm->yv12_fb[second_ref_fb_idx].corrupted;
}
}
if (mbmi->sb_type) {
const int n_mbs = 1 << mbmi->sb_type;
const int y_mbs = MIN(n_mbs, cm->mb_rows - mb_row);
const int x_mbs = MIN(n_mbs, cm->mb_cols - mb_col);
const int mis = cm->mode_info_stride;
int x, y;
for (y = 0; y < y_mbs; y++) {
for (x = !y; x < x_mbs; x++) {
mi[y * mis + x] = *mi;
}
}
}
}
/* Decode a row of Superblocks (2x2 region of MBs) */
......@@ -938,6 +919,11 @@ static void decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc,
for (mb_col = pc->cur_tile_mb_col_start;
mb_col < pc->cur_tile_mb_col_end; mb_col += 4) {
if (vp9_read(bc, pc->sb64_coded)) {
#ifdef DEC_DEBUG
dec_debug = (pc->current_video_frame == 1 && mb_row == 0 && mb_col == 0);
if (dec_debug)
printf("Debug\n");
#endif
set_offsets(pbi, 64, mb_row, mb_col);
vp9_decode_mb_mode_mv(pbi, xd, mb_row, mb_col, bc);
set_refs(pbi, 64, mb_row, mb_col);
......@@ -958,6 +944,10 @@ static void decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc,
xd->sb_index = j;
if (vp9_read(bc, pc->sb32_coded)) {
#ifdef DEC_DEBUG
dec_debug = (pc->current_video_frame == 1 &&
mb_row + y_idx_sb == 0 && mb_col + x_idx_sb == 0);
#endif
set_offsets(pbi, 32, mb_row + y_idx_sb, mb_col + x_idx_sb);
vp9_decode_mb_mode_mv(pbi,
xd, mb_row + y_idx_sb, mb_col + x_idx_sb, bc);
......@@ -978,11 +968,14 @@ static void decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc,
// MB lies outside frame, skip on to next
continue;
}
#ifdef DEC_DEBUG
dec_debug = (pc->current_video_frame == 1 &&
mb_row + y_idx == 0 && mb_col + x_idx == 0);
#endif
set_offsets(pbi, 16, mb_row + y_idx, mb_col + x_idx);
xd->mb_index = i;
vp9_decode_mb_mode_mv(pbi, xd, mb_row + y_idx, mb_col + x_idx, bc);
update_blockd_bmi(xd);
set_refs(pbi, 16, mb_row + y_idx, mb_col + x_idx);
decode_macroblock(pbi, xd, mb_row + y_idx, mb_col + x_idx, bc);
......@@ -1073,6 +1066,63 @@ static void init_frame(VP9D_COMP *pbi) {
xd->fullpixel_mask = 0xfffffff8;
}
#if CONFIG_CODE_NONZEROCOUNT
static void read_nzc_probs_common(VP9_COMMON *cm,
BOOL_DECODER* const bc,
int block_size) {
int c, r, b, t;
int tokens, nodes;
vp9_prob *nzc_probs;
vp9_prob upd;
if (!vp9_read_bit(bc)) return;
if (block_size == 32) {
tokens = NZC32X32_TOKENS;
nzc_probs = cm->fc.nzc_probs_32x32[0][0][0];
upd = NZC_UPDATE_PROB_32X32;
} else if (block_size == 16) {
tokens = NZC16X16_TOKENS;
nzc_probs = cm->fc.nzc_probs_16x16[0][0][0];
upd = NZC_UPDATE_PROB_16X16;
} else if (block_size == 8) {
tokens = NZC8X8_TOKENS;
nzc_probs = cm->fc.nzc_probs_8x8[0][0][0];
upd = NZC_UPDATE_PROB_8X8;
} else {
tokens = NZC4X4_TOKENS;
nzc_probs = cm->fc.nzc_probs_4x4[0][0][0];
upd = NZC_UPDATE_PROB_4X4;
}
nodes = tokens - 1;
for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
for (r = 0; r < REF_TYPES; ++r) {
for (b = 0; b < BLOCK_TYPES; ++b) {
int offset = c * REF_TYPES * BLOCK_TYPES + r * BLOCK_TYPES + b;
int offset_nodes = offset * nodes;
for (t = 0; t < nodes; ++t) {
vp9_prob *p = &nzc_probs[offset_nodes + t];
if (vp9_read(bc, upd)) {
*p = read_prob_diff_update(bc, *p);
}
}
}
}
}
}
static void read_nzc_probs(VP9_COMMON *cm,
BOOL_DECODER* const bc) {
read_nzc_probs_common(cm, bc, 4);
if (cm->txfm_mode != ONLY_4X4)
read_nzc_probs_common(cm, bc, 8);
if (cm->txfm_mode > ALLOW_8X8)
read_nzc_probs_common(cm, bc, 16);
if (cm->txfm_mode > ALLOW_16X16)
read_nzc_probs_common(cm, bc, 32);
}
#endif // CONFIG_CODE_NONZEROCOUNT
static void read_coef_probs_common(BOOL_DECODER* const bc,
vp9_coeff_probs *coef_probs,
int block_types) {
......@@ -1085,7 +1135,7 @@ static void read_coef_probs_common(BOOL_DECODER* const bc,
for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
if (l >= 3 && k == 0)
continue;
for (m = 0; m < ENTROPY_NODES; m++) {
for (m = CONFIG_CODE_NONZEROCOUNT; m < ENTROPY_NODES; m++) {
vp9_prob *const p = coef_probs[i][j][k][l] + m;
if (vp9_read(bc, COEF_UPDATE_PROB)) {
......@@ -1539,6 +1589,17 @@ int vp9_decode_frame(VP9D_COMP *pbi, const unsigned char **p_data_end) {
pbi->common.fc.pre_interintra_prob = pbi->common.fc.interintra_prob;
#endif
pbi->common.fc.pre_nmvc = pbi->common.fc.nmvc;
#if CONFIG_CODE_NONZEROCOUNT
vp9_copy(pbi->common.fc.pre_nzc_probs_4x4,
pbi->common.fc.nzc_probs_4x4);
vp9_copy(pbi->common.fc.pre_nzc_probs_8x8,
pbi->common.fc.nzc_probs_8x8);
vp9_copy(pbi->common.fc.pre_nzc_probs_16x16,
pbi->common.fc.nzc_probs_16x16);
vp9_copy(pbi->common.fc.pre_nzc_probs_32x32,
pbi->common.fc.nzc_probs_32x32);
#endif
vp9_zero(pbi->common.fc.coef_counts_4x4);
vp9_zero(pbi->common.fc.coef_counts_8x8);
vp9_zero(pbi->common.fc.coef_counts_16x16);
......@@ -1555,8 +1616,17 @@ int vp9_decode_frame(VP9D_COMP *pbi, const unsigned char **p_data_end) {
#if CONFIG_COMP_INTERINTRA_PRED
vp9_zero(pbi->common.fc.interintra_counts);
#endif
#if CONFIG_CODE_NONZEROCOUNT
vp9_zero(pbi->common.fc.nzc_counts_4x4);
vp9_zero(pbi->common.fc.nzc_counts_8x8);
vp9_zero(pbi->common.fc.nzc_counts_16x16);
vp9_zero(pbi->common.fc.nzc_counts_32x32);
#endif
read_coef_probs(pbi, &header_bc);
#if CONFIG_CODE_NONZEROCOUNT
read_nzc_probs(&pbi->common, &header_bc);
#endif
/* Initialize xd pointers. Any reference should do for xd->pre, so use 0. */
vpx_memcpy(&xd->pre, &pc->yv12_fb[pc->active_ref_idx[0]],
......@@ -1700,8 +1770,12 @@ int vp9_decode_frame(VP9D_COMP *pbi, const unsigned char **p_data_end) {
}
if (!pc->error_resilient_mode &&
!pc->frame_parallel_decoding_mode)
!pc->frame_parallel_decoding_mode) {
vp9_adapt_coef_probs(pc);
#if CONFIG_CODE_NONZEROCOUNT
vp9_adapt_nzc_probs(pc);
#endif
}
if (pc->frame_type != KEY_FRAME) {
if (!pc->error_resilient_mode &&
!pc->frame_parallel_decoding_mode) {
......
......@@ -69,13 +69,24 @@ static int get_signed(BOOL_DECODER *br, int value_to_sign) {
pt = vp9_get_coef_context(&recent_energy, token); \
} while (0)
#if CONFIG_CODE_NONZEROCOUNT
#define WRITE_COEF_CONTINUE(val, token) \
{ \
qcoeff_ptr[scan[c]] = (int16_t) get_signed(br, val); \
qcoeff_ptr[scan[c]] = (int16_t) get_signed(br, val); \
INCREMENT_COUNT(token); \
c++; \
nzc++; \
continue; \
}
#else
#define WRITE_COEF_CONTINUE(val, token) \
{ \
qcoeff_ptr[scan[c]] = (int16_t) get_signed(br, val); \
INCREMENT_COUNT(token); \
c++; \
continue; \
}
#endif // CONFIG_CODE_NONZEROCOUNT
#define ADJUST_COEF(prob, bits_count) \
do { \
......@@ -99,6 +110,10 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,
vp9_prob *prob;
vp9_coeff_count *coef_counts;
const int ref = xd->mode_info_context->mbmi.ref_frame != INTRA_FRAME;
#if CONFIG_CODE_NONZEROCOUNT
uint16_t nzc = 0;
uint16_t nzc_expected = xd->mode_info_context->mbmi.nzcs[block_idx];
#endif
if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB64X64) {
aidx = vp9_block2above_sb64[txfm_size][block_idx];
......@@ -170,12 +185,24 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,