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

Continued experiment with nonzero count

Adds probability updates for extra bits for the nzcs, code for
getting nzc stats, plus some minor cleanups and fixes.

Change-Id: If2814e7f04fb52f5025ad9f400f3e6c50a00b543
parent 0643c3f1
......@@ -22,6 +22,7 @@
#define NZC_UPDATE_PROB_8X8 252
#define NZC_UPDATE_PROB_16X16 252
#define NZC_UPDATE_PROB_32X32 252
#define NZC_UPDATE_PROB_PCAT 252
#endif
#endif // VP9_COMMON_VP9_COEFUPDATEPROBS_H__
......@@ -697,18 +697,22 @@ 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] = {
// TODO(debargha): Remove the macro and count tables after experimentation
#define NZC_DEFAULT_COUNTS /* Uncomment to use counts as defaults */
#ifdef NZC_DEFAULT_COUNTS
static const unsigned int default_nzc_counts_4x4[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC4X4_TOKENS] = {
{
{
{ 967652, 29023, 15039, 6952, 1568, 116 },
{ 789116, 22938, 4522, 1935, 520, 47 }
{ 289116, 22938, 4522, 1935, 520, 47 }
}, {
{ 967652, 29023, 15039, 6952, 1568, 116 },
{ 789116, 22938, 4522, 1935, 520, 47 }
{ 689116, 22938, 4522, 1935, 520, 47 }
},
}, {
{
......@@ -716,109 +720,274 @@ static const unsigned int default_nzc4x4_counts[MAX_NZC_CONTEXTS]
{ 10405, 12395, 3401, 3574, 2461, 771 }
}, {
{ 124684, 37167, 15270, 8483, 1777, 102 },
{ 10405, 12395, 3401, 3574, 2461, 771 }
{ 20405, 12395, 3401, 3574, 2461, 771 }
}
}, {
{
{ 41100, 22976, 15627, 16137, 7982, 793 },
{ 4100, 22976, 15627, 16137, 7982, 1793 },
{ 4249, 3084, 2131, 4081, 6439, 1653 }
}, {
{ 41100, 22976, 15627, 16137, 7982, 793 },
{ 4249, 3084, 2131, 4081, 6439, 1653 }
{ 21100, 22976, 15627, 16137, 7982, 1793 },
{ 4249, 3084, 2131, 4081, 2439, 1653 }
}
}
};
static const unsigned int default_nzc8x8_counts[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC8X8_TOKENS] = {
static const unsigned int default_nzc_counts_8x8[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 },
{ 192052, 30468, 6973, 3250, 1500, 750, 375, 5 },
}
}, {
{
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6 },
{ 23772, 23120, 13127, 8115, 4000, 2000, 200, 6 },
}, {
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6 },
{ 23772, 23120, 13127, 8115, 4000, 2000, 200, 6 },
}
}, {
{
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12 },
{ 11612, 13874, 13329, 13022, 6500, 3250, 300, 12 },
}, {
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12 },
{ 11612, 13874, 13329, 13022, 6500, 3250, 300, 12 },
}
}
};
static const unsigned int default_nzc16x16_counts[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC16X16_TOKENS] = {
static const unsigned int default_nzc_counts_16x16[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 },
{ 32988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2 },
{ 92052, 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 },
{ 21533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2 },
{ 47772, 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 },
{ 21533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2 },
{ 27772, 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 },
{ 9612, 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 },
{ 9612, 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] = {
static const unsigned int default_nzc_counts_32x32[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 },
{ 72988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2, 1, 0 },
{ 52052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1, 0, 0 },
}, {
{ 372988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2, 1, 0 },
{ 72052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1 },
{ 72988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2, 1, 0 },
{ 72052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1, 0, 0 },
}
}, {
{
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2, 1, 0 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2 },
{ 21533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2, 1, 0 },
{ 27772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2, 1, 0 },
}, {
{ 121533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2, 1, 0 },
{ 17772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2 },
{ 21533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2, 1, 0 },
{ 27772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2, 1, 0 },
}
}, {
{
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17, 10, 5, 2, 1 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3 },
{ 9612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3, 2, 1 },
}, {
{ 29408, 11758, 8023, 10123, 6705, 2468, 369, 17, 10, 5, 2, 1 },
{ 6612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3 },
{ 9612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3, 2, 1 },
}
}
};
#else
static const vp9_prob default_nzc_probs_4x4[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC4X4_TOKENS] = {
{
{
{ 219, 162, 179, 142, 242, },
{ 214, 253, 228, 246, 255, },
}, {
{ 225, 236, 190, 229, 253, },
{ 251, 253, 240, 248, 255, },
},
}, {
{
{ 106, 126, 158, 126, 244, },
{ 118, 241, 201, 240, 255, },
}, {
{ 165, 179, 143, 189, 242, },
{ 173, 239, 192, 255, 128, },
},
}, {
{
{ 42 , 78 , 153, 92 , 223, },
{ 128, 128, 128, 128, 128, },
}, {
{ 76 , 68 , 126, 110, 216, },
{ 128, 128, 128, 128, 128, },
},
},
};
static const vp9_prob default_nzc_probs_8x8[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC8X8_TOKENS] = {
{
{
{ 134, 139, 170, 178, 142, 197, 255, },
{ 167, 224, 199, 252, 205, 255, 128, },
}, {
{ 181, 210, 180, 241, 190, 235, 255, },
{ 234, 251, 235, 252, 219, 255, 128, },
},
}, {
{
{ 33 , 64 , 155, 143, 86 , 216, 255, },
{ 73 , 160, 167, 251, 153, 255, 128, },
}, {
{ 79 , 104, 153, 195, 119, 246, 255, },
{ 149, 183, 186, 249, 203, 255, 128, },
},
}, {
{
{ 10 , 25 , 156, 61 , 69 , 156, 254, },
{ 32 , 1 , 128, 146, 64 , 255, 128, },
}, {
{ 37 , 48 , 143, 113, 81 , 202, 255, },
{ 1 , 255, 128, 128, 128, 128, 128, },
},
},
};
static const vp9_prob default_nzc_probs_16x16[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC16X16_TOKENS] = {
{
{
{ 11 , 188, 210, 167, 141, 143, 152, 255, 128, },
{ 171, 201, 203, 244, 207, 255, 255, 128, 128, },
}, {
{ 23 , 217, 207, 251, 198, 255, 219, 128, 128, },
{ 235, 249, 229, 255, 199, 128, 128, 128, 128, },
},
}, {
{
{ 9 , 45 , 168, 85 , 66 , 221, 139, 246, 255, },
{ 51 , 110, 163, 238, 94 , 255, 255, 128, 128, },
}, {
{ 4 , 149, 175, 240, 149, 255, 205, 128, 128, },
{ 141, 217, 186, 255, 128, 128, 128, 128, 128, },
},
}, {
{
{ 1 , 12 , 173, 6 , 68 , 145, 41 , 204, 255, },
{ 39 , 47 , 128, 199, 110, 255, 128, 128, 128, },
}, {
{ 1 , 121, 171, 149, 115, 242, 159, 255, 128, },
{ 1 , 255, 255, 128, 128, 128, 128, 128, 128, },
},
},
};
static const vp9_prob default_nzc_probs_32x32[MAX_NZC_CONTEXTS]
[REF_TYPES]
[BLOCK_TYPES]
[NZC32X32_TOKENS] = {
{
{
{ 11 , 216, 195, 201, 160, 247, 217, 255, 255, 128, 128, },
{ 177, 240, 239, 255, 192, 128, 128, 128, 128, 128, 128, },
}, {
{ 48 , 235, 213, 235, 199, 255, 255, 128, 128, 128, 128, },
{ 205, 255, 248, 128, 128, 128, 128, 128, 128, 128, 128, },
},
}, {
{
{ 6 , 96 , 138, 99 , 125, 248, 188, 255, 128, 128, 128, },
{ 17 , 53 , 43 , 189, 1 , 255, 171, 128, 128, 128, 128, },
}, {
{ 5 , 187, 235, 232, 117, 255, 219, 128, 128, 128, 128, },
{ 146, 255, 255, 128, 128, 128, 128, 128, 128, 128, 128, },
},
}, {
{
{ 1 , 7 , 93 , 14 , 100, 30 , 85 , 65 , 81 , 210, 255, },
{ 1 , 1 , 128, 26 , 1 , 218, 78 , 255, 255, 128, 128, },
}, {
{ 4 , 148, 206, 137, 160, 255, 255, 128, 128, 128, 128, },
{ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, },
},
},
};
#endif
static const vp9_prob default_nzc_pcat_probs[MAX_NZC_CONTEXTS]
[NZC_TOKENS_EXTRA]
[NZC_BITS_EXTRA] = {
// Bit probabilities are in least to most significance order
{
{176, 128, 128, 128, 128, 128, 128, 128, 128}, // 3 - 4
{164, 192, 128, 128, 128, 128, 128, 128, 128}, // 5 - 8
{154, 184, 208, 128, 128, 128, 128, 128, 128}, // 9 - 16
{144, 176, 200, 216, 128, 128, 128, 128, 128}, // 17 - 32
{140, 172, 192, 208, 224, 128, 128, 128, 128}, // 33 - 64
{136, 168, 188, 200, 220, 232, 128, 128, 128}, // 65 - 128
{132, 164, 184, 196, 216, 228, 240, 128, 128}, // 129 - 256
{130, 162, 178, 194, 212, 226, 240, 248, 128}, // 257 - 512
{128, 160, 176, 192, 208, 224, 240, 248, 254}, // 513 - 1024
}, {
{168, 128, 128, 128, 128, 128, 128, 128, 128}, // 3 - 4
{152, 184, 128, 128, 128, 128, 128, 128, 128}, // 5 - 8
{152, 184, 208, 128, 128, 128, 128, 128, 128}, // 9 - 16
{144, 176, 200, 216, 128, 128, 128, 128, 128}, // 17 - 32
{140, 172, 192, 208, 224, 128, 128, 128, 128}, // 33 - 64
{136, 168, 188, 200, 220, 232, 128, 128, 128}, // 65 - 128
{132, 164, 184, 196, 216, 228, 240, 128, 128}, // 129 - 256
{130, 162, 178, 194, 212, 226, 240, 248, 128}, // 257 - 512
{128, 160, 176, 192, 208, 224, 240, 248, 254}, // 513 - 1024
}, {
{160, 128, 128, 128, 128, 128, 128, 128, 128}, // 3 - 4
{152, 176, 128, 128, 128, 128, 128, 128, 128}, // 5 - 8
{150, 184, 208, 128, 128, 128, 128, 128, 128}, // 9 - 16
{144, 176, 200, 216, 128, 128, 128, 128, 128}, // 17 - 32
{140, 172, 192, 208, 224, 128, 128, 128, 128}, // 33 - 64
{136, 168, 188, 200, 220, 232, 128, 128, 128}, // 65 - 128
{132, 164, 184, 196, 216, 228, 240, 128, 128}, // 129 - 256
{130, 162, 178, 194, 212, 226, 240, 248, 128}, // 257 - 512
{128, 160, 176, 192, 208, 224, 240, 248, 254}, // 513 - 1024
},
};
#endif // CONFIG_CODE_NONZEROCOUNT
......@@ -235,39 +235,12 @@ const vp9_tree_index vp9_nzc32x32_tree[2 * NZC32X32_NODES] = {
};
struct vp9_token_struct vp9_nzc32x32_encodings[NZC32X32_TOKENS];
const vp9_prob Pcat_nzc[MAX_NZC_CONTEXTS]
[NZC_TOKENS_EXTRA][NZC_BITS_EXTRA] = { {
// Bit probabilities are in least to most significance order
{176, 0, 0, 0, 0, 0, 0, 0, 0}, // 3 - 4
{164, 192, 0, 0, 0, 0, 0, 0, 0}, // 5 - 8
{154, 184, 208, 0, 0, 0, 0, 0, 0}, // 9 - 16
{144, 176, 200, 216, 0, 0, 0, 0, 0}, // 17 - 32
{140, 172, 192, 208, 224, 0, 0, 0, 0}, // 33 - 64
{136, 168, 188, 200, 220, 232, 0, 0, 0}, // 65 - 128
{132, 164, 184, 196, 216, 228, 240, 0, 0}, // 129 - 256
{130, 162, 178, 194, 212, 226, 240, 248, 0}, // 257 - 512
{128, 160, 176, 192, 208, 224, 240, 248, 254}, // 513 - 1024
}, {
{168, 0, 0, 0, 0, 0, 0, 0, 0}, // 3 - 4
{152, 184, 0, 0, 0, 0, 0, 0, 0}, // 5 - 8
{152, 184, 208, 0, 0, 0, 0, 0, 0}, // 9 - 16
{144, 176, 200, 216, 0, 0, 0, 0, 0}, // 17 - 32
{140, 172, 192, 208, 224, 0, 0, 0, 0}, // 33 - 64
{136, 168, 188, 200, 220, 232, 0, 0, 0}, // 65 - 128
{132, 164, 184, 196, 216, 228, 240, 0, 0}, // 129 - 256
{130, 162, 178, 194, 212, 226, 240, 248, 0}, // 257 - 512
{128, 160, 176, 192, 208, 224, 240, 248, 254}, // 513 - 1024
}, {
{160, 0, 0, 0, 0, 0, 0, 0, 0}, // 3 - 4
{152, 176, 0, 0, 0, 0, 0, 0, 0}, // 5 - 8
{150, 184, 208, 0, 0, 0, 0, 0, 0}, // 9 - 16
{144, 176, 200, 216, 0, 0, 0, 0, 0}, // 17 - 32
{140, 172, 192, 208, 224, 0, 0, 0, 0}, // 33 - 64
{136, 168, 188, 200, 220, 232, 0, 0, 0}, // 65 - 128
{132, 164, 184, 196, 216, 228, 240, 0, 0}, // 129 - 256
{130, 162, 178, 194, 212, 226, 240, 248, 0}, // 257 - 512
{128, 160, 176, 192, 208, 224, 240, 248, 254}, // 513 - 1024
},
const int vp9_extranzcbits[NZC32X32_TOKENS] = {
0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
};
const int vp9_basenzcvalue[NZC32X32_TOKENS] = {
0, 1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513
};
#endif // CONFIG_CODE_NONZEROCOUNT
......@@ -340,17 +313,8 @@ int vp9_get_coef_context(int * recent_energy, int token) {
void vp9_default_coef_probs(VP9_COMMON *pc) {
#if CONFIG_CODE_NONZEROCOUNT
#ifdef NZC_DEFAULT_COUNTS
int h, g;
#endif
vpx_memcpy(pc->fc.coef_probs_4x4, default_coef_probs_4x4,
sizeof(pc->fc.coef_probs_4x4));
vpx_memcpy(pc->fc.coef_probs_8x8, default_coef_probs_8x8,
sizeof(pc->fc.coef_probs_8x8));
vpx_memcpy(pc->fc.coef_probs_16x16, default_coef_probs_16x16,
sizeof(pc->fc.coef_probs_16x16));
vpx_memcpy(pc->fc.coef_probs_32x32, default_coef_probs_32x32,
sizeof(pc->fc.coef_probs_32x32));
#if CONFIG_CODE_NONZEROCOUNT
for (h = 0; h < MAX_NZC_CONTEXTS; ++h) {
for (g = 0; g < REF_TYPES; ++g) {
int i;
......@@ -362,29 +326,49 @@ void vp9_default_coef_probs(VP9_COMMON *pc) {
vp9_tree_probs_from_distribution(
NZC4X4_TOKENS, vp9_nzc4x4_encodings, vp9_nzc4x4_tree,
pc->fc.nzc_probs_4x4[h][g][i], branch_ct4x4,
default_nzc4x4_counts[h][g][i]);
default_nzc_counts_4x4[h][g][i]);
}
for (i = 0; i < BLOCK_TYPES; ++i) {
vp9_tree_probs_from_distribution(
NZC8X8_TOKENS, vp9_nzc8x8_encodings, vp9_nzc8x8_tree,
pc->fc.nzc_probs_8x8[h][g][i], branch_ct8x8,
default_nzc8x8_counts[h][g][i]);
default_nzc_counts_8x8[h][g][i]);
}
for (i = 0; i < BLOCK_TYPES; ++i) {
vp9_tree_probs_from_distribution(
NZC16X16_TOKENS, vp9_nzc16x16_encodings, vp9_nzc16x16_tree,
pc->fc.nzc_probs_16x16[h][g][i], branch_ct16x16,
default_nzc16x16_counts[h][g][i]);
default_nzc_counts_16x16[h][g][i]);
}
for (i = 0; i < BLOCK_TYPES; ++i) {
vp9_tree_probs_from_distribution(
NZC32X32_TOKENS, vp9_nzc32x32_encodings, vp9_nzc32x32_tree,
pc->fc.nzc_probs_32x32[h][g][i], branch_ct32x32,
default_nzc32x32_counts[h][g][i]);
default_nzc_counts_32x32[h][g][i]);
}
}
}
#else
vpx_memcpy(pc->fc.nzc_probs_4x4, default_nzc_probs_4x4,
sizeof(pc->fc.nzc_probs_4x4));
vpx_memcpy(pc->fc.nzc_probs_8x8, default_nzc_probs_8x8,
sizeof(pc->fc.nzc_probs_8x8));
vpx_memcpy(pc->fc.nzc_probs_16x16, default_nzc_probs_16x16,
sizeof(pc->fc.nzc_probs_16x16));
vpx_memcpy(pc->fc.nzc_probs_32x32, default_nzc_probs_32x32,
sizeof(pc->fc.nzc_probs_32x32));
#endif
vpx_memcpy(pc->fc.nzc_pcat_probs, default_nzc_pcat_probs,
sizeof(pc->fc.nzc_pcat_probs));
#endif // CONFIG_CODE_NONZEROCOUNTyy
vpx_memcpy(pc->fc.coef_probs_4x4, default_coef_probs_4x4,
sizeof(pc->fc.coef_probs_4x4));
vpx_memcpy(pc->fc.coef_probs_8x8, default_coef_probs_8x8,
sizeof(pc->fc.coef_probs_8x8));
vpx_memcpy(pc->fc.coef_probs_16x16, default_coef_probs_16x16,
sizeof(pc->fc.coef_probs_16x16));
vpx_memcpy(pc->fc.coef_probs_32x32, default_coef_probs_32x32,
sizeof(pc->fc.coef_probs_32x32));
}
void vp9_coef_tree_initialize() {
......@@ -406,16 +390,19 @@ void vp9_coef_tree_initialize() {
(mb_row) >= 0)
#define choose_nzc_context(nzc_exp, t2, t1) \
((nzc_exp) >= ((t2) << 6) ? 2 : (nzc_exp) >= ((t1) << 6) ? 1 : 0)
((nzc_exp) >= (t2) ? 2 : (nzc_exp) >= (t1) ? 1 : 0)
#define NZC_T2_32X32 32
#define NZC_T1_32X32 8
#define NZC_T2_16X16 16
#define NZC_T1_16X16 4
#define NZC_T2_8X8 8
#define NZC_T1_8X8 2
#define NZC_T2_4X4 4
#define NZC_T1_4X4 1
#define NZC_T2_32X32 (16 << 6)
#define NZC_T1_32X32 (4 << 6)
#define NZC_T2_16X16 (12 << 6)
#define NZC_T1_16X16 (3 << 6)
#define NZC_T2_8X8 (8 << 6)
#define NZC_T1_8X8 (2 << 6)
#define NZC_T2_4X4 (4 << 6)
#define NZC_T1_4X4 (1 << 6)
// Transforms a mb16 block index to a sb64 block index
static inline int mb16_to_sb64_index(int mb_row, int mb_col, int block) {
......@@ -1253,7 +1240,7 @@ static void update_nzc(VP9_COMMON *cm,
TX_SIZE tx_size,
int ref,
int type) {
int c;
int e, c;
c = codenzc(nzc);
if (tx_size == TX_32X32)
cm->fc.nzc_counts_32x32[nzc_context][ref][type][c]++;
......@@ -1265,7 +1252,14 @@ static void update_nzc(VP9_COMMON *cm,
cm->fc.nzc_counts_4x4[nzc_context][ref][type][c]++;
else
assert(0);
// TODO(debargha): Handle extra bits later if needed
if ((e = vp9_extranzcbits[c])) {
int x = nzc - vp9_basenzcvalue[c];
while (e--) {
int b = (x >> e) & 1;
cm->fc.nzc_pcat_counts[nzc_context][c - NZC_TOKENS_NOEXTRA][e][b]++;
}
}
}
static void update_nzcs_sb64(VP9_COMMON *cm,
......@@ -1608,6 +1602,27 @@ static void adapt_nzc_probs(VP9_COMMON *cm,
}
}
static void adapt_nzc_pcat(VP9_COMMON *cm, int count_sat, int update_factor) {
int c, t;
int count, factor;
for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
for (t = 0; t < NZC_TOKENS_EXTRA; ++t) {
int bits = vp9_extranzcbits[t + NZC_TOKENS_NOEXTRA];
int b;
for (b = 0; b < bits; ++b) {
vp9_prob prob = get_binary_prob(cm->fc.nzc_pcat_counts[c][t][b][0],
cm->fc.nzc_pcat_counts[c][t][b][1]);
count = cm->fc.nzc_pcat_counts[c][t][b][0] +
cm->fc.nzc_pcat_counts[c][t][b][1];
count = count > count_sat ? count_sat : count;
factor = (update_factor * count / count_sat);
cm->fc.nzc_pcat_probs[c][t][b] = weighted_prob(
cm->fc.pre_nzc_pcat_probs[c][t][b], prob, factor);
}
}
}
}
// #define NZC_COUNT_TESTING
void vp9_adapt_nzc_probs(VP9_COMMON *cm) {
int count_sat;
......@@ -1643,5 +1658,6 @@ void vp9_adapt_nzc_probs(VP9_COMMON *cm) {
adapt_nzc_probs(cm, 8, count_sat, update_factor);
adapt_nzc_probs(cm, 16, count_sat, update_factor);
adapt_nzc_probs(cm, 32, count_sat, update_factor);
adapt_nzc_pcat(cm, count_sat, update_factor);
}
#endif // CONFIG_CODE_NONZEROCOUNT
......@@ -175,8 +175,14 @@ extern int vp9_get_coef_context(int * recent_energy, int token);
/* Max number of extra bits */
#define NZC_BITS_EXTRA 9
/* Tokens without extra bits */
#define NZC_TOKENS_NOEXTRA (NZC32X32_TOKENS - NZC_TOKENS_EXTRA)
#define MAX_NZC_CONTEXTS 3
/* whether to update extra bit probabilities */
#define NZC_PCAT_UPDATE