Commit 362888b9 authored by Alex Converse's avatar Alex Converse

Use rANS to code constrained token set.

For now this is in its own experiment for benchmarking purposes, but it
will eventually be folded into the main ANS experiment.

Change-Id: Icdb54b6ca3c0191ba717d6d10aaaffb11e2bebea
parent baa6815e
......@@ -125,7 +125,10 @@ static INLINE int aom_read_tree(aom_reader *r, const aom_tree_index *tree,
static INLINE int aom_read_tree_cdf(aom_reader *r, const uint16_t *cdf,
int nsymbs) {
#if CONFIG_DAALA_EC
#if CONFIG_RANS
(void)nsymbs;
return rans_read(r, cdf);
#elif CONFIG_DAALA_EC
return daala_read_tree_cdf(r, cdf, nsymbs);
#else
(void)r;
......
......@@ -100,7 +100,14 @@ static INLINE void aom_write_tree(aom_writer *w, const aom_tree_index *tree,
static INLINE void aom_write_tree_cdf(aom_writer *w, int symb,
const uint16_t *cdf, int nsymbs) {
#if CONFIG_DAALA_EC
#if CONFIG_RANS
(void)nsymbs;
struct rans_sym s;
assert(cdf);
s.cum_prob = cdf[symb];
s.prob = cdf[symb + 1] - s.cum_prob;
buf_rans_write(w, &s);
#elif CONFIG_DAALA_EC
daala_write_tree_cdf(w, symb, cdf, nsymbs);
#else
(void)w;
......
......@@ -9,10 +9,14 @@
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include "./aom_config.h"
#include "av1/common/entropy.h"
#include "av1/common/blockd.h"
#include "av1/common/onyxc_int.h"
#include "av1/common/entropymode.h"
#if CONFIG_RANS
#include "aom_dsp/ans.h"
#endif // CONFIG_RANS
#include "aom_mem/aom_mem.h"
#include "aom/aom_integer.h"
......@@ -384,6 +388,278 @@ const aom_prob av1_pareto8_full[COEFF_PROB_MODELS][MODEL_NODES] = {
{ 255, 243, 245, 255, 237, 255, 252, 254 },
{ 255, 246, 247, 255, 239, 255, 253, 255 },
};
#if CONFIG_RANS
// Model obtained from a 2-sided zero-centered distribution derived
// from a Pareto distribution. The cdf of the distribution is:
// cdf(x) = 0.5 + 0.5 * sgn(x) * [1 - {alpha/(alpha + |x|)} ^ beta]
//
// For a given beta and a given probability of the 1-node, the alpha
// is first solved, and then the {alpha, beta} pair is used to generate
// the probabilities for the rest of the nodes.
//
// The full source code of the generating program is available in:
// tools/gen_constrained_tokenset.py
//
// Values for tokens ONE_TOKEN through CATEGORY6_TOKEN included here.
// ZERO_TOKEN and EOB_TOKEN are coded as flags outside this coder.
const AnsP10 av1_pareto8_token_probs[COEFF_PROB_MODELS][ENTROPY_TOKENS - 2] = {
{ 4, 4, 4, 4, 8, 15, 30, 57, 103, 795 },
{ 8, 8, 8, 8, 15, 30, 57, 103, 168, 619 },
{ 12, 12, 12, 12, 23, 43, 80, 138, 205, 487 },
{ 16, 16, 15, 15, 30, 56, 101, 165, 225, 385 },
{ 20, 20, 19, 19, 36, 68, 119, 186, 231, 306 },
{ 24, 23, 23, 22, 43, 79, 135, 201, 230, 244 },
{ 28, 27, 26, 26, 49, 89, 149, 211, 223, 196 },
{ 32, 31, 30, 29, 55, 98, 160, 218, 212, 159 },
{ 36, 35, 33, 32, 60, 107, 171, 221, 200, 129 },
{ 40, 38, 37, 35, 66, 115, 179, 222, 187, 105 },
{ 44, 42, 40, 38, 71, 122, 186, 221, 174, 86 },
{ 48, 45, 43, 41, 76, 129, 192, 219, 160, 71 },
{ 52, 49, 46, 44, 80, 136, 196, 215, 148, 58 },
{ 56, 53, 49, 46, 85, 142, 200, 210, 135, 48 },
{ 60, 56, 52, 49, 89, 147, 203, 204, 124, 40 },
{ 64, 60, 55, 52, 93, 151, 205, 198, 113, 33 },
{ 68, 63, 58, 54, 97, 156, 205, 192, 103, 28 },
{ 72, 66, 61, 57, 100, 160, 206, 185, 94, 23 },
{ 76, 70, 64, 59, 104, 163, 205, 178, 85, 20 },
{ 80, 73, 67, 61, 107, 166, 205, 171, 77, 17 },
{ 84, 76, 69, 63, 110, 169, 204, 164, 71, 14 },
{ 88, 80, 72, 65, 113, 171, 202, 157, 64, 12 },
{ 92, 83, 75, 67, 116, 173, 200, 150, 58, 10 },
{ 96, 86, 77, 69, 118, 175, 198, 143, 53, 9 },
{ 100, 89, 80, 71, 121, 176, 195, 137, 48, 7 },
{ 104, 92, 82, 73, 123, 178, 192, 130, 44, 6 },
{ 108, 96, 84, 75, 125, 178, 189, 124, 40, 5 },
{ 112, 98, 87, 76, 127, 179, 186, 118, 36, 5 },
{ 116, 101, 89, 78, 129, 179, 183, 112, 33, 4 },
{ 120, 104, 91, 80, 131, 180, 179, 106, 30, 3 },
{ 124, 107, 93, 81, 132, 180, 176, 101, 27, 3 },
{ 128, 110, 95, 82, 134, 179, 172, 96, 25, 3 },
{ 132, 113, 97, 84, 135, 179, 168, 91, 23, 2 },
{ 136, 116, 99, 85, 136, 179, 164, 86, 21, 2 },
{ 140, 119, 101, 86, 137, 178, 160, 82, 19, 2 },
{ 144, 122, 103, 88, 138, 177, 157, 77, 17, 1 },
{ 148, 124, 105, 89, 139, 176, 153, 73, 16, 1 },
{ 152, 127, 107, 90, 140, 175, 149, 69, 14, 1 },
{ 156, 130, 108, 91, 141, 173, 145, 66, 13, 1 },
{ 160, 133, 110, 92, 141, 172, 141, 62, 12, 1 },
{ 164, 135, 111, 93, 142, 171, 137, 59, 11, 1 },
{ 168, 138, 113, 94, 142, 169, 133, 56, 10, 1 },
{ 172, 140, 115, 94, 142, 168, 130, 53, 9, 1 },
{ 176, 143, 116, 95, 143, 166, 126, 50, 8, 1 },
{ 180, 145, 118, 96, 143, 164, 122, 47, 8, 1 },
{ 184, 147, 119, 96, 143, 163, 119, 45, 7, 1 },
{ 188, 150, 120, 97, 143, 161, 116, 42, 6, 1 },
{ 192, 152, 121, 98, 143, 159, 112, 40, 6, 1 },
{ 196, 155, 123, 98, 142, 157, 109, 38, 5, 1 },
{ 200, 157, 124, 99, 142, 155, 105, 36, 5, 1 },
{ 204, 159, 125, 99, 142, 153, 102, 34, 5, 1 },
{ 208, 161, 126, 100, 142, 151, 99, 32, 4, 1 },
{ 212, 164, 127, 100, 141, 149, 96, 30, 4, 1 },
{ 216, 166, 129, 100, 141, 147, 93, 28, 3, 1 },
{ 220, 168, 130, 101, 140, 144, 90, 27, 3, 1 },
{ 224, 170, 131, 101, 140, 142, 87, 25, 3, 1 },
{ 228, 172, 132, 101, 139, 140, 84, 24, 3, 1 },
{ 232, 174, 132, 101, 139, 138, 81, 23, 3, 1 },
{ 236, 176, 133, 101, 138, 136, 79, 22, 2, 1 },
{ 240, 178, 134, 102, 137, 134, 76, 20, 2, 1 },
{ 244, 180, 135, 102, 136, 131, 74, 19, 2, 1 },
{ 248, 182, 135, 102, 136, 129, 71, 18, 2, 1 },
{ 252, 184, 136, 101, 135, 127, 69, 17, 2, 1 },
{ 256, 186, 137, 102, 134, 124, 66, 16, 2, 1 },
{ 260, 188, 138, 102, 133, 122, 64, 15, 1, 1 },
{ 264, 190, 138, 101, 132, 120, 62, 15, 1, 1 },
{ 268, 191, 139, 101, 131, 118, 60, 14, 1, 1 },
{ 272, 193, 139, 101, 130, 116, 58, 13, 1, 1 },
{ 276, 195, 139, 101, 129, 114, 56, 12, 1, 1 },
{ 280, 196, 140, 101, 128, 111, 54, 12, 1, 1 },
{ 284, 198, 140, 101, 127, 109, 52, 11, 1, 1 },
{ 288, 200, 141, 100, 126, 107, 50, 10, 1, 1 },
{ 292, 201, 141, 100, 125, 105, 48, 10, 1, 1 },
{ 296, 203, 141, 100, 123, 103, 47, 9, 1, 1 },
{ 300, 204, 142, 99, 122, 101, 45, 9, 1, 1 },
{ 304, 206, 142, 99, 121, 99, 43, 8, 1, 1 },
{ 308, 207, 142, 99, 119, 97, 42, 8, 1, 1 },
{ 312, 209, 142, 99, 118, 95, 40, 7, 1, 1 },
{ 316, 210, 142, 98, 117, 93, 39, 7, 1, 1 },
{ 320, 211, 142, 98, 116, 91, 37, 7, 1, 1 },
{ 324, 213, 142, 97, 115, 89, 36, 6, 1, 1 },
{ 328, 214, 142, 97, 113, 87, 35, 6, 1, 1 },
{ 332, 215, 143, 96, 112, 85, 33, 6, 1, 1 },
{ 336, 216, 143, 96, 111, 83, 32, 5, 1, 1 },
{ 340, 218, 143, 95, 109, 81, 31, 5, 1, 1 },
{ 344, 219, 142, 95, 108, 79, 30, 5, 1, 1 },
{ 348, 220, 142, 94, 107, 78, 29, 4, 1, 1 },
{ 352, 221, 142, 94, 105, 76, 28, 4, 1, 1 },
{ 356, 222, 142, 93, 104, 74, 27, 4, 1, 1 },
{ 360, 223, 142, 92, 103, 72, 26, 4, 1, 1 },
{ 364, 224, 142, 92, 101, 70, 25, 4, 1, 1 },
{ 368, 225, 142, 91, 100, 69, 24, 3, 1, 1 },
{ 372, 226, 141, 91, 99, 67, 23, 3, 1, 1 },
{ 376, 227, 141, 90, 97, 66, 22, 3, 1, 1 },
{ 380, 228, 141, 89, 96, 64, 21, 3, 1, 1 },
{ 384, 229, 140, 89, 95, 62, 20, 3, 1, 1 },
{ 388, 229, 140, 88, 93, 61, 20, 3, 1, 1 },
{ 392, 230, 140, 87, 92, 60, 19, 2, 1, 1 },
{ 396, 231, 140, 86, 91, 58, 18, 2, 1, 1 },
{ 400, 232, 139, 86, 89, 57, 17, 2, 1, 1 },
{ 404, 232, 139, 85, 88, 55, 17, 2, 1, 1 },
{ 408, 233, 138, 84, 87, 54, 16, 2, 1, 1 },
{ 412, 234, 138, 84, 85, 52, 15, 2, 1, 1 },
{ 416, 234, 137, 83, 84, 51, 15, 2, 1, 1 },
{ 420, 235, 137, 82, 82, 50, 14, 2, 1, 1 },
{ 424, 236, 136, 81, 81, 48, 14, 2, 1, 1 },
{ 428, 236, 136, 81, 80, 47, 13, 1, 1, 1 },
{ 432, 236, 135, 80, 79, 46, 13, 1, 1, 1 },
{ 436, 237, 135, 79, 77, 45, 12, 1, 1, 1 },
{ 440, 238, 134, 78, 76, 43, 12, 1, 1, 1 },
{ 444, 238, 134, 77, 75, 42, 11, 1, 1, 1 },
{ 448, 238, 133, 77, 73, 41, 11, 1, 1, 1 },
{ 452, 239, 132, 76, 72, 40, 10, 1, 1, 1 },
{ 456, 239, 131, 75, 71, 39, 10, 1, 1, 1 },
{ 460, 239, 131, 74, 70, 38, 9, 1, 1, 1 },
{ 464, 240, 130, 73, 68, 37, 9, 1, 1, 1 },
{ 468, 240, 129, 72, 67, 36, 9, 1, 1, 1 },
{ 472, 240, 128, 72, 66, 35, 8, 1, 1, 1 },
{ 476, 240, 127, 71, 65, 34, 8, 1, 1, 1 },
{ 480, 240, 127, 70, 63, 33, 8, 1, 1, 1 },
{ 484, 241, 126, 69, 62, 32, 7, 1, 1, 1 },
{ 488, 241, 125, 68, 61, 31, 7, 1, 1, 1 },
{ 492, 241, 124, 67, 60, 30, 7, 1, 1, 1 },
{ 496, 241, 124, 66, 59, 29, 6, 1, 1, 1 },
{ 500, 240, 123, 66, 58, 28, 6, 1, 1, 1 },
{ 504, 240, 122, 65, 57, 27, 6, 1, 1, 1 },
{ 508, 240, 121, 64, 55, 27, 6, 1, 1, 1 },
{ 512, 241, 120, 63, 54, 26, 5, 1, 1, 1 },
{ 516, 241, 119, 62, 53, 25, 5, 1, 1, 1 },
{ 520, 240, 118, 62, 52, 24, 5, 1, 1, 1 },
{ 524, 240, 117, 60, 51, 24, 5, 1, 1, 1 },
{ 528, 239, 116, 60, 50, 23, 5, 1, 1, 1 },
{ 532, 239, 116, 59, 49, 22, 4, 1, 1, 1 },
{ 536, 239, 115, 58, 48, 21, 4, 1, 1, 1 },
{ 540, 239, 113, 57, 47, 21, 4, 1, 1, 1 },
{ 544, 238, 113, 56, 46, 20, 4, 1, 1, 1 },
{ 548, 238, 112, 55, 45, 19, 4, 1, 1, 1 },
{ 552, 238, 110, 55, 44, 19, 3, 1, 1, 1 },
{ 556, 237, 110, 54, 43, 18, 3, 1, 1, 1 },
{ 560, 237, 108, 53, 42, 18, 3, 1, 1, 1 },
{ 564, 236, 108, 52, 41, 17, 3, 1, 1, 1 },
{ 568, 236, 106, 51, 40, 17, 3, 1, 1, 1 },
{ 572, 235, 105, 51, 39, 16, 3, 1, 1, 1 },
{ 576, 235, 104, 50, 38, 15, 3, 1, 1, 1 },
{ 580, 234, 103, 49, 37, 15, 3, 1, 1, 1 },
{ 584, 234, 102, 48, 37, 14, 2, 1, 1, 1 },
{ 588, 233, 101, 47, 36, 14, 2, 1, 1, 1 },
{ 592, 233, 100, 46, 35, 13, 2, 1, 1, 1 },
{ 596, 231, 99, 46, 34, 13, 2, 1, 1, 1 },
{ 600, 230, 98, 45, 33, 13, 2, 1, 1, 1 },
{ 604, 230, 97, 44, 32, 12, 2, 1, 1, 1 },
{ 608, 229, 96, 43, 31, 12, 2, 1, 1, 1 },
{ 612, 228, 95, 42, 31, 11, 2, 1, 1, 1 },
{ 616, 227, 93, 42, 30, 11, 2, 1, 1, 1 },
{ 620, 227, 92, 41, 29, 10, 2, 1, 1, 1 },
{ 624, 226, 92, 40, 28, 10, 1, 1, 1, 1 },
{ 628, 225, 90, 39, 28, 10, 1, 1, 1, 1 },
{ 632, 224, 89, 39, 27, 9, 1, 1, 1, 1 },
{ 636, 223, 88, 38, 26, 9, 1, 1, 1, 1 },
{ 640, 222, 87, 37, 25, 9, 1, 1, 1, 1 },
{ 644, 221, 86, 36, 25, 8, 1, 1, 1, 1 },
{ 648, 220, 84, 36, 24, 8, 1, 1, 1, 1 },
{ 652, 219, 83, 35, 23, 8, 1, 1, 1, 1 },
{ 656, 218, 82, 34, 23, 7, 1, 1, 1, 1 },
{ 660, 217, 81, 33, 22, 7, 1, 1, 1, 1 },
{ 664, 215, 80, 33, 21, 7, 1, 1, 1, 1 },
{ 668, 214, 78, 32, 21, 7, 1, 1, 1, 1 },
{ 672, 213, 78, 31, 20, 6, 1, 1, 1, 1 },
{ 676, 211, 76, 31, 20, 6, 1, 1, 1, 1 },
{ 680, 210, 75, 30, 19, 6, 1, 1, 1, 1 },
{ 684, 209, 74, 29, 18, 6, 1, 1, 1, 1 },
{ 688, 208, 73, 28, 18, 5, 1, 1, 1, 1 },
{ 692, 206, 72, 28, 17, 5, 1, 1, 1, 1 },
{ 696, 205, 70, 27, 17, 5, 1, 1, 1, 1 },
{ 700, 203, 69, 27, 16, 5, 1, 1, 1, 1 },
{ 704, 201, 68, 26, 16, 5, 1, 1, 1, 1 },
{ 708, 201, 67, 25, 15, 4, 1, 1, 1, 1 },
{ 712, 198, 66, 25, 15, 4, 1, 1, 1, 1 },
{ 716, 197, 65, 24, 14, 4, 1, 1, 1, 1 },
{ 720, 196, 63, 23, 14, 4, 1, 1, 1, 1 },
{ 724, 194, 62, 23, 13, 4, 1, 1, 1, 1 },
{ 728, 193, 61, 22, 13, 3, 1, 1, 1, 1 },
{ 732, 191, 60, 22, 12, 3, 1, 1, 1, 1 },
{ 736, 189, 59, 21, 12, 3, 1, 1, 1, 1 },
{ 740, 188, 58, 20, 11, 3, 1, 1, 1, 1 },
{ 744, 186, 56, 20, 11, 3, 1, 1, 1, 1 },
{ 748, 184, 55, 19, 11, 3, 1, 1, 1, 1 },
{ 752, 182, 54, 19, 10, 3, 1, 1, 1, 1 },
{ 756, 181, 53, 18, 10, 2, 1, 1, 1, 1 },
{ 760, 179, 52, 18, 9, 2, 1, 1, 1, 1 },
{ 764, 177, 51, 17, 9, 2, 1, 1, 1, 1 },
{ 768, 174, 50, 17, 9, 2, 1, 1, 1, 1 },
{ 772, 173, 49, 16, 8, 2, 1, 1, 1, 1 },
{ 776, 171, 47, 16, 8, 2, 1, 1, 1, 1 },
{ 780, 169, 46, 15, 8, 2, 1, 1, 1, 1 },
{ 784, 167, 45, 15, 7, 2, 1, 1, 1, 1 },
{ 788, 165, 44, 14, 7, 2, 1, 1, 1, 1 },
{ 792, 162, 43, 14, 7, 2, 1, 1, 1, 1 },
{ 796, 161, 42, 13, 7, 1, 1, 1, 1, 1 },
{ 800, 159, 41, 13, 6, 1, 1, 1, 1, 1 },
{ 804, 157, 40, 12, 6, 1, 1, 1, 1, 1 },
{ 808, 154, 39, 12, 6, 1, 1, 1, 1, 1 },
{ 812, 153, 38, 11, 5, 1, 1, 1, 1, 1 },
{ 816, 150, 37, 11, 5, 1, 1, 1, 1, 1 },
{ 820, 148, 36, 10, 5, 1, 1, 1, 1, 1 },
{ 824, 145, 35, 10, 5, 1, 1, 1, 1, 1 },
{ 828, 143, 34, 10, 4, 1, 1, 1, 1, 1 },
{ 832, 141, 33, 9, 4, 1, 1, 1, 1, 1 },
{ 836, 138, 32, 9, 4, 1, 1, 1, 1, 1 },
{ 840, 136, 30, 9, 4, 1, 1, 1, 1, 1 },
{ 844, 133, 30, 8, 4, 1, 1, 1, 1, 1 },
{ 848, 131, 29, 8, 3, 1, 1, 1, 1, 1 },
{ 852, 129, 28, 7, 3, 1, 1, 1, 1, 1 },
{ 856, 126, 27, 7, 3, 1, 1, 1, 1, 1 },
{ 860, 123, 26, 7, 3, 1, 1, 1, 1, 1 },
{ 864, 121, 25, 6, 3, 1, 1, 1, 1, 1 },
{ 868, 118, 24, 6, 3, 1, 1, 1, 1, 1 },
{ 872, 116, 23, 6, 2, 1, 1, 1, 1, 1 },
{ 876, 113, 22, 6, 2, 1, 1, 1, 1, 1 },
{ 880, 111, 21, 5, 2, 1, 1, 1, 1, 1 },
{ 884, 108, 20, 5, 2, 1, 1, 1, 1, 1 },
{ 888, 105, 19, 5, 2, 1, 1, 1, 1, 1 },
{ 892, 102, 19, 4, 2, 1, 1, 1, 1, 1 },
{ 896, 99, 18, 4, 2, 1, 1, 1, 1, 1 },
{ 900, 97, 17, 4, 1, 1, 1, 1, 1, 1 },
{ 904, 94, 16, 4, 1, 1, 1, 1, 1, 1 },
{ 908, 92, 15, 3, 1, 1, 1, 1, 1, 1 },
{ 912, 89, 14, 3, 1, 1, 1, 1, 1, 1 },
{ 916, 85, 14, 3, 1, 1, 1, 1, 1, 1 },
{ 920, 82, 13, 3, 1, 1, 1, 1, 1, 1 },
{ 924, 79, 12, 3, 1, 1, 1, 1, 1, 1 },
{ 928, 77, 11, 2, 1, 1, 1, 1, 1, 1 },
{ 932, 73, 11, 2, 1, 1, 1, 1, 1, 1 },
{ 936, 70, 10, 2, 1, 1, 1, 1, 1, 1 },
{ 940, 67, 9, 2, 1, 1, 1, 1, 1, 1 },
{ 944, 64, 8, 2, 1, 1, 1, 1, 1, 1 },
{ 948, 60, 8, 2, 1, 1, 1, 1, 1, 1 },
{ 952, 58, 7, 1, 1, 1, 1, 1, 1, 1 },
{ 956, 54, 7, 1, 1, 1, 1, 1, 1, 1 },
{ 960, 51, 6, 1, 1, 1, 1, 1, 1, 1 },
{ 964, 48, 5, 1, 1, 1, 1, 1, 1, 1 },
{ 968, 44, 5, 1, 1, 1, 1, 1, 1, 1 },
{ 972, 41, 4, 1, 1, 1, 1, 1, 1, 1 },
{ 976, 37, 4, 1, 1, 1, 1, 1, 1, 1 },
{ 980, 34, 3, 1, 1, 1, 1, 1, 1, 1 },
{ 984, 30, 3, 1, 1, 1, 1, 1, 1, 1 },
{ 988, 27, 2, 1, 1, 1, 1, 1, 1, 1 },
{ 992, 23, 2, 1, 1, 1, 1, 1, 1, 1 },
{ 996, 19, 2, 1, 1, 1, 1, 1, 1, 1 },
{ 1000, 16, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1004, 12, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1008, 8, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1012, 4, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1015, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1015, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
};
#endif // CONFIG_RANS
static const av1_coeff_probs_model default_coef_probs_4x4[PLANE_TYPES] = {
{ // Y plane
......@@ -1058,11 +1334,37 @@ void av1_model_to_full_probs(const aom_prob *model, aom_prob *full) {
extend_to_full_distribution(&full[UNCONSTRAINED_NODES], model[PIVOT_NODE]);
}
#if CONFIG_RANS
static void build_token_cdfs(const aom_prob *pdf_model, rans_lut cdf) {
int i;
assert(pdf_model[2] != 0);
cdf[0] = 0;
for (i = 0; i < ENTROPY_TOKENS - 2; ++i) {
cdf[i + 1] = cdf[i] + av1_pareto8_token_probs[pdf_model[2] - 1][i];
}
}
void av1_coef_pareto_cdfs(FRAME_CONTEXT *fc) {
TX_SIZE t;
int i, j, k, l;
for (t = TX_4X4; t <= TX_32X32; ++t)
for (i = 0; i < PLANE_TYPES; ++i)
for (j = 0; j < REF_TYPES; ++j)
for (k = 0; k < COEF_BANDS; ++k)
for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l)
build_token_cdfs(fc->coef_probs[t][i][j][k][l],
fc->coef_cdfs[t][i][j][k][l]);
}
#endif // CONFIG_RANS
void av1_default_coef_probs(AV1_COMMON *cm) {
av1_copy(cm->fc->coef_probs[TX_4X4], default_coef_probs_4x4);
av1_copy(cm->fc->coef_probs[TX_8X8], default_coef_probs_8x8);
av1_copy(cm->fc->coef_probs[TX_16X16], default_coef_probs_16x16);
av1_copy(cm->fc->coef_probs[TX_32X32], default_coef_probs_32x32);
#if CONFIG_RANS
av1_coef_pareto_cdfs(cm->fc);
#endif // CONFIG_RANS
}
#define COEF_COUNT_SAT 24
......@@ -1117,4 +1419,7 @@ void av1_adapt_coef_probs(AV1_COMMON *cm) {
}
for (t = TX_4X4; t <= TX_32X32; t++)
adapt_coef_probs(cm, t, count_sat, update_factor);
#if CONFIG_RANS
av1_coef_pareto_cdfs(cm->fc);
#endif // CONFIG_RANS
}
......@@ -12,7 +12,11 @@
#ifndef AV1_COMMON_ENTROPY_H_
#define AV1_COMMON_ENTROPY_H_
#include "./aom_config.h"
#include "aom/aom_integer.h"
#if CONFIG_RANS
#include "aom_dsp/ans.h"
#endif // CONFIG_RANS
#include "aom_dsp/prob.h"
#include "av1/common/common.h"
......@@ -173,6 +177,14 @@ typedef unsigned int av1_coeff_count_model
void av1_model_to_full_probs(const aom_prob *model, aom_prob *full);
#if CONFIG_RANS
typedef rans_lut coeff_cdf_model[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS];
extern const AnsP10
av1_pareto8_token_probs[COEFF_PROB_MODELS][ENTROPY_TOKENS - 2];
struct frame_contexts;
void av1_coef_pareto_cdfs(struct frame_contexts *fc);
#endif // CONFIG_RANS
typedef char ENTROPY_CONTEXT;
static INLINE int combine_entropy_contexts(ENTROPY_CONTEXT a,
......
......@@ -54,6 +54,9 @@ typedef struct frame_contexts {
aom_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
aom_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
av1_coeff_probs_model coef_probs[TX_SIZES][PLANE_TYPES];
#if CONFIG_RANS
coeff_cdf_model coef_cdfs[TX_SIZES][PLANE_TYPES];
#endif // CONFIG_RANS
aom_prob
switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS -
1];
......
......@@ -708,6 +708,9 @@ static void read_coef_probs(FRAME_CONTEXT *fc, TX_MODE tx_mode, aom_reader *r) {
TX_SIZE tx_size;
for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size)
read_coef_probs_common(fc->coef_probs[tx_size], r);
#if CONFIG_RANS
av1_coef_pareto_cdfs(fc);
#endif // CONFIG_RANS
}
static void setup_segmentation(AV1_COMMON *const cm,
......
......@@ -67,6 +67,11 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
const aom_prob(*coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] =
fc->coef_probs[tx_size][type][ref];
const aom_prob *prob;
#if CONFIG_RANS
const rans_lut(*coef_cdfs)[COEFF_CONTEXTS] =
fc->coef_cdfs[tx_size][type][ref];
const rans_lut *cdf;
#endif // CONFIG_RANS
unsigned int(*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1];
unsigned int(*eob_branch_count)[COEFF_CONTEXTS];
uint8_t token_cache[32 * 32];
......@@ -141,6 +146,58 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
prob = coef_probs[band][ctx];
}
#if CONFIG_RANS
cdf = &coef_cdfs[band][ctx];
token =
ONE_TOKEN + aom_read_tree_cdf(r, *cdf, CATEGORY6_TOKEN - ONE_TOKEN + 1);
INCREMENT_COUNT(ONE_TOKEN + (token > ONE_TOKEN));
switch (token) {
case ONE_TOKEN:
case TWO_TOKEN:
case THREE_TOKEN:
case FOUR_TOKEN: val = token; break;
case CATEGORY1_TOKEN:
val = CAT1_MIN_VAL + read_coeff(cat1_prob, 1, r);
break;
case CATEGORY2_TOKEN:
val = CAT2_MIN_VAL + read_coeff(cat2_prob, 2, r);
break;
case CATEGORY3_TOKEN:
val = CAT3_MIN_VAL + read_coeff(cat3_prob, 3, r);
break;
case CATEGORY4_TOKEN:
val = CAT4_MIN_VAL + read_coeff(cat4_prob, 4, r);
break;
case CATEGORY5_TOKEN:
val = CAT5_MIN_VAL + read_coeff(cat5_prob, 5, r);
break;
case CATEGORY6_TOKEN: {
#if CONFIG_MISC_FIXES
const int skip_bits = TX_SIZES - 1 - tx_size;
#else
const int skip_bits = 0;
#endif
const uint8_t *cat6p = cat6_prob + skip_bits;
#if CONFIG_AOM_HIGHBITDEPTH
switch (xd->bd) {
case AOM_BITS_8:
val = CAT6_MIN_VAL + read_coeff(cat6p, 14 - skip_bits, r);
break;
case AOM_BITS_10:
val = CAT6_MIN_VAL + read_coeff(cat6p, 16 - skip_bits, r);
break;
case AOM_BITS_12:
val = CAT6_MIN_VAL + read_coeff(cat6p, 18 - skip_bits, r);
break;
default: assert(0); return -1;
}
#else
val = CAT6_MIN_VAL + read_coeff(cat6p, 14 - skip_bits, r);
#endif
break;
}
}
#else // CONFIG_RANS
if (!aom_read(r, prob[ONE_CONTEXT_NODE])) {
INCREMENT_COUNT(ONE_TOKEN);
token = ONE_TOKEN;
......@@ -195,6 +252,7 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
}
}
}
#endif // CONFIG_RANS
#if CONFIG_AOM_QM
dqv = ((iqmatrix[scan[c]] * (int)dqv) + (1 << (AOM_QM_BITS - 1))) >>
AOM_QM_BITS;
......
......@@ -303,10 +303,12 @@ static void pack_mb_tokens(aom_writer *w, TOKENEXTRA **tp,
while (p < stop && p->token != EOSB_TOKEN) {
const int t = p->token;
#if !CONFIG_RANS
const struct av1_token *const a = &av1_coef_encodings[t];
int i = 0;
int v = a->value;
int n = a->len;
#endif // !CONFIG_RANS
#if CONFIG_AOM_HIGHBITDEPTH
const av1_extra_bit *b;
if (bit_depth == AOM_BITS_12)
......@@ -320,6 +322,17 @@ static void pack_mb_tokens(aom_writer *w, TOKENEXTRA **tp,
(void)bit_depth;
#endif // CONFIG_AOM_HIGHBITDEPTH
#if CONFIG_RANS
if (!p->skip_eob_node) aom_write(w, t != EOB_TOKEN, p->context_tree[0]);
if (t != EOB_TOKEN) {
aom_write(w, t != ZERO_TOKEN, p->context_tree[1]);
if (t != ZERO_TOKEN) {
aom_write_tree_cdf(w, t - ONE_TOKEN, *p->token_cdf,
CATEGORY6_TOKEN - ONE_TOKEN + 1);
}
}
#else
/* skip one or two nodes */
if (p->skip_eob_node) {
n -= p->skip_eob_node;
......@@ -345,6 +358,7 @@ static void pack_mb_tokens(aom_writer *w, TOKENEXTRA **tp,
} else {
aom_write_tree_bits(w, av1_coef_tree, p->context_tree, v, n, i);
}
#endif // CONFIG_RANS
if (b->base_val) {
const int e = p->extra, l = b->len;
......@@ -941,7 +955,7 @@ static void update_coef_probs_common(aom_writer *const bc, AV1_COMP *cpi,
/* Is coef updated at all */
if (update[1] == 0 || savings < 0) {
aom_write_bit(bc, 0);
return;
break;
}
aom_write_bit(bc, 1);
for (i = 0; i < PLANE_TYPES; ++i) {
......@@ -974,7 +988,7 @@ static void update_coef_probs_common(aom_writer *const bc, AV1_COMP *cpi,
}
}
}
return;
break;
}
case ONE_LOOP_REDUCED: {
......@@ -1027,10 +1041,13 @@ static void update_coef_probs_common(aom_writer *const bc, AV1_COMP *cpi,