Commit eb6ef241 authored by Deb Mukherjee's avatar Deb Mukherjee
Browse files

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=" ...@@ -245,6 +245,7 @@ EXPERIMENT_LIST="
comp_interintra_pred comp_interintra_pred
enable_6tap enable_6tap
abovesprefmv abovesprefmv
code_nonzerocount
" "
CONFIG_LIST=" CONFIG_LIST="
external_build external_build
......
...@@ -250,6 +250,9 @@ typedef struct { ...@@ -250,6 +250,9 @@ typedef struct {
INTERPOLATIONFILTERTYPE interp_filter; INTERPOLATIONFILTERTYPE interp_filter;
BLOCK_SIZE_TYPE sb_type; BLOCK_SIZE_TYPE sb_type;
#if CONFIG_CODE_NONZEROCOUNT
uint16_t nzcs[256+64*2];
#endif
} MB_MODE_INFO; } MB_MODE_INFO;
typedef struct { typedef struct {
...@@ -295,6 +298,9 @@ typedef struct macroblockd { ...@@ -295,6 +298,9 @@ typedef struct macroblockd {
DECLARE_ALIGNED(16, int16_t, qcoeff[64*64+32*32*2]); 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, int16_t, dqcoeff[64*64+32*32*2]);
DECLARE_ALIGNED(16, uint16_t, eobs[256+64*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. */ /* 16 Y blocks, 4 U, 4 V, each with 16 entries. */
BLOCKD block[24]; BLOCKD block[24];
...@@ -592,4 +598,25 @@ static void update_blockd_bmi(MACROBLOCKD *xd) { ...@@ -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_ #endif // VP9_COMMON_VP9_BLOCKD_H_
...@@ -17,4 +17,11 @@ ...@@ -17,4 +17,11 @@
#define COEF_UPDATE_PROB_8X8 252 #define COEF_UPDATE_PROB_8X8 252
#define COEF_UPDATE_PROB_16X16 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__ #endif // VP9_COMMON_VP9_COEFUPDATEPROBS_H__
...@@ -695,3 +695,130 @@ static const vp9_coeff_probs default_coef_probs_32x32[BLOCK_TYPES] = { ...@@ -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) { ...@@ -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); 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_ #endif // VP9_COMMON_VP9_ENTROPY_H_
...@@ -58,10 +58,21 @@ typedef struct frame_contexts { ...@@ -58,10 +58,21 @@ typedef struct frame_contexts {
vp9_prob i8x8_mode_prob[VP9_I8X8_MODES - 1]; vp9_prob i8x8_mode_prob[VP9_I8X8_MODES - 1];
vp9_prob sub_mv_ref_prob[SUBMVREF_COUNT][VP9_SUBMVREFS - 1]; vp9_prob sub_mv_ref_prob[SUBMVREF_COUNT][VP9_SUBMVREFS - 1];
vp9_prob mbsplit_prob[VP9_NUMMBSPLITS - 1]; vp9_prob mbsplit_prob[VP9_NUMMBSPLITS - 1];
vp9_coeff_probs coef_probs_4x4[BLOCK_TYPES]; vp9_coeff_probs coef_probs_4x4[BLOCK_TYPES];
vp9_coeff_probs coef_probs_8x8[BLOCK_TYPES]; vp9_coeff_probs coef_probs_8x8[BLOCK_TYPES];
vp9_coeff_probs coef_probs_16x16[BLOCK_TYPES]; vp9_coeff_probs coef_probs_16x16[BLOCK_TYPES];
vp9_coeff_probs coef_probs_32x32[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 nmvc;
nmv_context pre_nmvc; nmv_context pre_nmvc;
...@@ -84,11 +95,31 @@ typedef struct frame_contexts { ...@@ -84,11 +95,31 @@ typedef struct frame_contexts {
vp9_coeff_probs pre_coef_probs_8x8[BLOCK_TYPES]; vp9_coeff_probs pre_coef_probs_8x8[BLOCK_TYPES];
vp9_coeff_probs pre_coef_probs_16x16[BLOCK_TYPES]; vp9_coeff_probs pre_coef_probs_16x16[BLOCK_TYPES];
vp9_coeff_probs pre_coef_probs_32x32[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_4x4[BLOCK_TYPES];
vp9_coeff_count coef_counts_8x8[BLOCK_TYPES]; vp9_coeff_count coef_counts_8x8[BLOCK_TYPES];
vp9_coeff_count coef_counts_16x16[BLOCK_TYPES]; vp9_coeff_count coef_counts_16x16[BLOCK_TYPES];
vp9_coeff_count coef_counts_32x32[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; nmv_context_counts NMVcount;
vp9_prob switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1] 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) { ...@@ -300,4 +331,31 @@ static void ref_cnt_fb(int *buf, int *idx, int new_idx) {
buf[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_ #endif // VP9_COMMON_VP9_ONYXC_INT_H_
...@@ -173,7 +173,6 @@ static void kfread_modes(VP9D_COMP *pbi, ...@@ -173,7 +173,6 @@ static void kfread_modes(VP9D_COMP *pbi,
m->mbmi.mb_skip_coeff = 0; m->mbmi.mb_skip_coeff = 0;
} }
y_mode = m->mbmi.sb_type ? y_mode = m->mbmi.sb_type ?
read_kf_sb_ymode(bc, read_kf_sb_ymode(bc,
pbi->common.sb_kf_ymode_prob[pbi->common.kf_ymode_probs_index]): pbi->common.sb_kf_ymode_prob[pbi->common.kf_ymode_probs_index]):
...@@ -677,22 +676,23 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, ...@@ -677,22 +676,23 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
mbmi->need_to_clamp_secondmv = 0; mbmi->need_to_clamp_secondmv = 0;
mbmi->second_ref_frame = NONE; mbmi->second_ref_frame = NONE;
// Make sure the MACROBLOCKD mode info pointer is pointed at the
// correct entry for the current macroblock.
xd->mode_info_context = mi;
xd->prev_mode_info_context = prev_mi;
// Distance of Mb to the various image edges. // Distance of Mb to the various image edges.
// These specified to 8th pel as they are always compared to MV values // These specified to 8th pel as they are always compared to MV values
// that are in 1/8th pel units // that are in 1/8th pel units
xd->mb_to_left_edge = mb_to_left_edge set_mb_row(cm, xd, mb_row, mb_size);
= -((mb_col * 16) << 3); set_mb_col(cm, xd, mb_col, mb_size);
mb_to_left_edge = xd->mb_to_left_edge;
mb_to_left_edge -= LEFT_TOP_MARGIN; mb_to_left_edge -= LEFT_TOP_MARGIN;
xd->mb_to_right_edge = mb_to_right_edge mb_to_right_edge = xd->mb_to_right_edge;
= ((pbi->common.mb_cols - mb_size - mb_col) * 16) << 3;
mb_to_right_edge += RIGHT_BOTTOM_MARGIN; mb_to_right_edge += RIGHT_BOTTOM_MARGIN;
// Make sure the MACROBLOCKD mode info pointer is pointed at the
// correct entry for the current macroblock.
xd->mode_info_context = mi;
xd->prev_mode_info_context = prev_mi;
// Read the macroblock segment id. // Read the macroblock segment id.
read_mb_segment_id(pbi, mb_row, mb_col, bc); read_mb_segment_id(pbi, mb_row, mb_col, bc);
...@@ -750,17 +750,6 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, ...@@ -750,17 +750,6 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
vp9_mv_ref_probs(&pbi->common, mv_ref_p, vp9_mv_ref_probs(&pbi->common, mv_ref_p,
mbmi->mb_mode_context[ref_frame]); mbmi->mb_mode_context[ref_frame]);
/*
if (pbi->common.current_video_frame == 1) {
int k = mbmi->mb_mode_context[ref_frame];
printf("vp9_mode_contexts: [%d %d %d %d] %d %d %d %d\n",
mb_row, mb_col, ref_frame, k,
cm->fc.vp9_mode_contexts[k][0],
cm->fc.vp9_mode_contexts[k][1],
cm->fc.vp9_mode_contexts[k][2],
cm->fc.vp9_mode_contexts[k][3]);
}
*/
// If the segment level skip mode enabled // If the segment level skip mode enabled
if (vp9_segfeature_active(xd, mbmi->segment_id, SEG_LVL_SKIP)) { if (vp9_segfeature_active(xd, mbmi->segment_id, SEG_LVL_SKIP)) {
...@@ -1176,20 +1165,270 @@ void vp9_decode_mode_mvs_init(VP9D_COMP* const pbi, BOOL_DECODER* const bc) { ...@@ -1176,20 +1165,270 @@ void vp9_decode_mode_mvs_init(VP9D_COMP* const pbi, BOOL_DECODER* const bc) {
vpx_memset(cm->mbskip_pred_probs, 0, sizeof(cm->mbskip_pred_probs)); vpx_memset(cm->mbskip_pred_probs, 0, sizeof(cm->mbskip_pred_probs));
if (pbi->common.mb_no_coeff_skip) { if (pbi->common.mb_no_coeff_skip) {
int k; int k;
for (k = 0; k < MBSKIP_CONTEXTS; ++k) for (k = 0; k < MBSKIP_CONTEXTS; ++k) {
cm->mbskip_pred_probs[k] = (vp9_prob)vp9_read_literal(bc, 8); cm->mbskip_pred_probs[k] = (vp9_prob)vp9_read_literal(bc, 8);
}
} }
mb_mode_mv_init(pbi, bc); mb_mode_mv_init(pbi, bc);
} }
#if CONFIG_CODE_NONZEROCOUNT
static uint16_t read_nzc(VP9_COMMON *const cm,
int nzc_context,
TX_SIZE tx_size,
int ref,
int type,
BOOL_DECODER* const bc) {
int c, e;
uint16_t nzc;
if (tx_size == TX_32X32) {
c = treed_read(bc, vp9_nzc32x32_tree,
cm->fc.nzc_probs_32x32[nzc_context][ref][type]);
cm->fc.nzc_counts_32x32[nzc_context][ref][type][c]++;
} else if (tx_size == TX_16X16) {
c = treed_read(bc, vp9_nzc16x16_tree,
cm->fc.nzc_probs_16x16[nzc_context][ref][type]);
cm->fc.nzc_counts_16x16[nzc_context][ref][type][c]++;
} else if (tx_size == TX_8X8) {
c = treed_read(bc, vp9_nzc8x8_tree,
cm->fc.nzc_probs_8x8[nzc_context][ref][type]);
cm->fc.nzc_counts_8x8[nzc_context][ref][type][c]++;
} else if (tx_size == TX_4X4) {
c = treed_read(bc, vp9_nzc4x4_tree,
cm->fc.nzc_probs_4x4[nzc_context][ref][type]);
cm->fc.nzc_counts_4x4[nzc_context][ref][type][c]++;
} else {
assert(0);
}
nzc = basenzcvalue(c);
if ((e = extranzcbits(c))) {
int x = 0;
while (e--)
x |= (vp9_read(bc, Pcat_nzc[nzc_context][c - 3][e]) << e);
nzc += x;
}
if (tx_size == TX_32X32)
assert(nzc <= 1024);
else if (tx_size == TX_16X16)
assert(nzc <= 256);
else if (tx_size == TX_8X8)
assert(nzc <= 64);
else if (tx_size == TX_4X4)
assert(nzc <= 16);
return nzc;
}
static void read_nzcs_sb64(VP9_COMMON *const cm,
MACROBLOCKD* xd,
int mb_row,
int mb_col,
BOOL_DECODER* const bc) {
MODE_INFO *m = xd->mode_info_context;
MB_MODE_INFO *const mi = &m->mbmi;
int j, nzc_context;
const int ref = m->mbmi.ref_frame != INTRA_FRAME;
assert(mb_col == get_mb_col(xd));
assert(mb_row == get_mb_row(xd));
vpx_memset(m->mbmi.nzcs, 0, 384 * sizeof(m->mbmi.nzcs[0]));
if (mi->mb_skip_coeff)
return;
switch (mi->txfm_size) {
case TX_32X32:
for (j = 0; j < 256; j += 64) {
nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_32X32, ref, 0, bc);
}
for (j = 256; j < 384; j += 64) {
nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_32X32, ref, 1, bc);
}
break;
case TX_16X16:
for (j = 0; j < 256; j += 16) {
nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_16X16, ref, 0, bc);
}
for (j = 256; j < 384; j += 16) {
nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_16X16, ref, 1, bc);
}
<