summaryrefslogtreecommitdiff
path: root/vp8/common
diff options
context:
space:
mode:
Diffstat (limited to 'vp8/common')
-rw-r--r--vp8/common/alloccommon.c3
-rw-r--r--[-rwxr-xr-x]vp8/common/default_coef_probs.h0
-rw-r--r--vp8/common/entropy.c137
-rw-r--r--vp8/common/entropy.h10
-rw-r--r--vp8/common/entropymode.c149
-rw-r--r--vp8/common/entropymode.h12
-rw-r--r--vp8/common/entropymv.c359
-rw-r--r--vp8/common/entropymv.h10
-rw-r--r--vp8/common/onyxc_int.h28
-rw-r--r--[-rwxr-xr-x]vp8/common/tapify.py0
10 files changed, 655 insertions, 53 deletions
diff --git a/vp8/common/alloccommon.c b/vp8/common/alloccommon.c
index 8bab3452f..2830c3e15 100644
--- a/vp8/common/alloccommon.c
+++ b/vp8/common/alloccommon.c
@@ -15,6 +15,7 @@
#include "onyxc_int.h"
#include "findnearmv.h"
#include "entropymode.h"
+#include "entropymv.h"
#include "systemdependent.h"
@@ -239,6 +240,8 @@ void vp8_initialize_common()
vp8_entropy_mode_init();
+ vp8_entropy_mv_init();
+
vp8_init_scan_order_mask();
}
diff --git a/vp8/common/default_coef_probs.h b/vp8/common/default_coef_probs.h
index 380f2c0c0..380f2c0c0 100755..100644
--- a/vp8/common/default_coef_probs.h
+++ b/vp8/common/default_coef_probs.h
diff --git a/vp8/common/entropy.c b/vp8/common/entropy.c
index 9849fd4c2..0b0a2357f 100644
--- a/vp8/common/entropy.c
+++ b/vp8/common/entropy.c
@@ -15,6 +15,7 @@
#include "string.h"
#include "blockd.h"
#include "onyxc_int.h"
+#include "entropymode.h"
#include "vpx_mem/vpx_mem.h"
#define uchar unsigned char /* typedefs can clash */
@@ -192,3 +193,139 @@ void vp8_coef_tree_initialize()
init_bit_trees();
vp8_tokens_from_tree(vp8_coef_encodings, vp8_coef_tree);
}
+
+#if CONFIG_ADAPTIVE_ENTROPY
+
+//#define COEF_COUNT_TESTING
+
+#define COEF_COUNT_SAT 24
+#define COEF_MAX_UPDATE_FACTOR 112
+#define COEF_COUNT_SAT_KEY 24
+#define COEF_MAX_UPDATE_FACTOR_KEY 112
+#define COEF_COUNT_SAT_AFTER_KEY 24
+#define COEF_MAX_UPDATE_FACTOR_AFTER_KEY 128
+
+void vp8_adapt_coef_probs(VP8_COMMON *cm)
+{
+ int t, i, j, k, count;
+ unsigned int branch_ct[ENTROPY_NODES][2];
+ vp8_prob coef_probs[ENTROPY_NODES];
+ int update_factor; /* denominator 256 */
+ int factor;
+ int count_sat;
+
+ //printf("Frame type: %d\n", cm->frame_type);
+ if (cm->frame_type == KEY_FRAME)
+ {
+ update_factor = COEF_MAX_UPDATE_FACTOR_KEY;
+ count_sat = COEF_COUNT_SAT_KEY;
+ }
+ else if (cm->last_frame_type == KEY_FRAME)
+ {
+ update_factor = COEF_MAX_UPDATE_FACTOR_AFTER_KEY; /* adapt quickly */
+ count_sat = COEF_COUNT_SAT_AFTER_KEY;
+ }
+ else
+ {
+ update_factor = COEF_MAX_UPDATE_FACTOR;
+ count_sat = COEF_COUNT_SAT;
+ }
+
+#ifdef COEF_COUNT_TESTING
+ {
+ printf("static const unsigned int\ncoef_counts"
+ "[BLOCK_TYPES] [COEF_BANDS]"
+ "[PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {\n");
+ for (i = 0; i<BLOCK_TYPES; ++i)
+ {
+ printf(" {\n");
+ for (j = 0; j<COEF_BANDS; ++j)
+ {
+ printf(" {\n");
+ for (k = 0; k<PREV_COEF_CONTEXTS; ++k)
+ {
+ printf(" {");
+ for (t = 0; t<MAX_ENTROPY_TOKENS; ++t) printf("%d, ", cm->fc.coef_counts[i][j][k][t]);
+ printf("},\n");
+ }
+ printf(" },\n");
+ }
+ printf(" },\n");
+ }
+ printf("};\n");
+ printf("static const unsigned int\ncoef_counts_8x8"
+ "[BLOCK_TYPES_8X8] [COEF_BANDS]"
+ "[PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {\n");
+ for (i = 0; i<BLOCK_TYPES_8X8; ++i)
+ {
+ printf(" {\n");
+ for (j = 0; j<COEF_BANDS; ++j)
+ {
+ printf(" {\n");
+ for (k = 0; k<PREV_COEF_CONTEXTS; ++k)
+ {
+ printf(" {");
+ for (t = 0; t<MAX_ENTROPY_TOKENS; ++t) printf("%d, ", cm->fc.coef_counts_8x8[i][j][k][t]);
+ printf("},\n");
+ }
+ printf(" },\n");
+ }
+ printf(" },\n");
+ }
+ printf("};\n");
+ }
+#endif
+
+ for (i = 0; i<BLOCK_TYPES; ++i)
+ for (j = 0; j<COEF_BANDS; ++j)
+ for (k = 0; k<PREV_COEF_CONTEXTS; ++k)
+ {
+#if CONFIG_EXPANDED_COEF_CONTEXT
+ if (k >=3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
+ continue;
+#endif
+ vp8_tree_probs_from_distribution(
+ MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree,
+ coef_probs, branch_ct, cm->fc.coef_counts [i][j][k],
+ 256, 1);
+ for (t=0; t<ENTROPY_NODES; ++t)
+ {
+ int prob;
+ count = branch_ct[t][0] + branch_ct[t][1];
+ count = count > count_sat ? count_sat : count;
+ factor = (update_factor * count / count_sat);
+ prob = ((int)cm->fc.pre_coef_probs[i][j][k][t] * (256-factor) +
+ (int)coef_probs[t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.coef_probs[i][j][k][t] = 1;
+ else if (prob > 255) cm->fc.coef_probs[i][j][k][t] = 255;
+ else cm->fc.coef_probs[i][j][k][t] = prob;
+ }
+ }
+
+ for (i = 0; i<BLOCK_TYPES_8X8; ++i)
+ for (j = 0; j<COEF_BANDS; ++j)
+ for (k = 0; k<PREV_COEF_CONTEXTS; ++k)
+ {
+#if CONFIG_EXPANDED_COEF_CONTEXT
+ if (k >=3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
+ continue;
+#endif
+ vp8_tree_probs_from_distribution(
+ MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree,
+ coef_probs, branch_ct, cm->fc.coef_counts_8x8 [i][j][k],
+ 256, 1);
+ for (t=0; t<ENTROPY_NODES; ++t)
+ {
+ int prob;
+ count = branch_ct[t][0] + branch_ct[t][1];
+ count = count > count_sat ? count_sat : count;
+ factor = (update_factor * count / count_sat);
+ prob = ((int)cm->fc.pre_coef_probs_8x8[i][j][k][t] * (256-factor) +
+ (int)coef_probs[t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.coef_probs_8x8[i][j][k][t] = 1;
+ else if (prob > 255) cm->fc.coef_probs_8x8[i][j][k][t] = 255;
+ else cm->fc.coef_probs_8x8[i][j][k][t] = prob;
+ }
+ }
+}
+#endif
diff --git a/vp8/common/entropy.h b/vp8/common/entropy.h
index 692c2c418..78f8d5d03 100644
--- a/vp8/common/entropy.h
+++ b/vp8/common/entropy.h
@@ -92,9 +92,9 @@ extern DECLARE_ALIGNED(64, const unsigned char, vp8_coef_bands_8x8[64]);
#endif
#if CONFIG_NEWUPDATE
-#define SUBEXP_PARAM 2 /* Subexponential code parameter */
-#define MODULUS_PARAM 21 /* Modulus parameter */
-#define COEFUPDATETYPE 2 /* coef update type to use (1/2/3) */
+#define SUBEXP_PARAM 4 /* Subexponential code parameter */
+#define MODULUS_PARAM 13 /* Modulus parameter */
+#define COEFUPDATETYPE 1 /* coef update type to use (1/2/3) */
#endif
@@ -107,4 +107,8 @@ extern short vp8_default_zig_zag_mask[16];
extern DECLARE_ALIGNED(64, const int, vp8_default_zig_zag1d_8x8[64]);
extern short vp8_default_zig_zag_mask_8x8[64];//int64_t
void vp8_coef_tree_initialize(void);
+
+#if CONFIG_ADAPTIVE_ENTROPY
+void vp8_adapt_coef_probs(struct VP8Common *);
+#endif
#endif
diff --git a/vp8/common/entropymode.c b/vp8/common/entropymode.c
index 0ae6a9343..a1a3cfa88 100644
--- a/vp8/common/entropymode.c
+++ b/vp8/common/entropymode.c
@@ -11,6 +11,7 @@
#include "modecont.h"
#include "entropymode.h"
+#include "entropymv.h"
#include "entropy.h"
#include "vpx_mem/vpx_mem.h"
@@ -325,40 +326,6 @@ struct vp8_token_struct vp8_mbsplit_encodings [VP8_NUMMBSPLITS];
struct vp8_token_struct vp8_mv_ref_encoding_array [VP8_MVREFS];
struct vp8_token_struct vp8_sub_mv_ref_encoding_array [VP8_SUBMVREFS];
-#if CONFIG_HIGH_PRECISION_MV
-const vp8_tree_index vp8_small_mvtree_hp [30] =
-{
- 2, 16,
- 4, 10,
- 6, 8,
- -0, -1,
- -2, -3,
- 12, 14,
- -4, -5,
- -6, -7,
- 18, 24,
- 20, 22,
- -8, -9,
- -10, -11,
- 26, 28,
- -12, -13,
- -14, -15
-};
-struct vp8_token_struct vp8_small_mvencodings_hp [16];
-#endif /* CONFIG_HIGH_PRECISION_MV */
-
-const vp8_tree_index vp8_small_mvtree [14] =
-{
- 2, 8,
- 4, 6,
- -0, -1,
- -2, -3,
- 10, 12,
- -4, -5,
- -6, -7
-};
-struct vp8_token_struct vp8_small_mvencodings [8];
-
void vp8_init_mbmode_probs(VP8_COMMON *x)
@@ -396,7 +363,7 @@ void vp8_init_mbmode_probs(VP8_COMMON *x)
vp8_tree_probs_from_distribution(
VP8_I8X8_MODES, vp8_i8x8_mode_encodings, vp8_i8x8_mode_tree,
- x->i8x8_mode_prob, bct, i8x8_mode_cts,
+ x->fc.i8x8_mode_prob, bct, i8x8_mode_cts,
256, 1);
vpx_memcpy(x->fc.sub_mv_ref_prob, sub_mv_ref_prob, sizeof(sub_mv_ref_prob));
@@ -458,11 +425,6 @@ void vp8_entropy_mode_init()
vp8_mv_ref_tree, NEARESTMV);
vp8_tokens_from_tree_offset(vp8_sub_mv_ref_encoding_array,
vp8_sub_mv_ref_tree, LEFT4X4);
-
- vp8_tokens_from_tree(vp8_small_mvencodings, vp8_small_mvtree);
-#if CONFIG_HIGH_PRECISION_MV
- vp8_tokens_from_tree(vp8_small_mvencodings_hp, vp8_small_mvtree_hp);
-#endif
}
void vp8_init_mode_contexts(VP8_COMMON *pc)
@@ -595,3 +557,110 @@ void print_mv_ref_cts(VP8_COMMON *pc)
printf("\n");
}
}
+
+#if CONFIG_ADAPTIVE_ENTROPY
+//#define MODE_COUNT_TESTING
+#define MODE_COUNT_SAT 16
+#define MODE_MAX_UPDATE_FACTOR 96
+void vp8_adapt_mode_probs(VP8_COMMON *cm)
+{
+ int i, t, count, factor;
+ unsigned int branch_ct[32][2];
+ int update_factor = MODE_MAX_UPDATE_FACTOR; /* denominator 256 */
+ int count_sat = MODE_COUNT_SAT;
+ vp8_prob ymode_probs[VP8_YMODES-1];
+ vp8_prob uvmode_probs[VP8_UV_MODES-1];
+ vp8_prob bmode_probs[VP8_BINTRAMODES-1];
+ vp8_prob i8x8_mode_probs[VP8_I8X8_MODES-1];
+#ifdef MODE_COUNT_TESTING
+ printf("static const unsigned int\nymode_counts"
+ "[VP8_YMODES] = {\n");
+ for (t = 0; t<VP8_YMODES; ++t) printf("%d, ", cm->fc.ymode_counts[t]);
+ printf("};\n");
+ printf("static const unsigned int\nuv_mode_counts"
+ "[VP8_YMODES] [VP8_UV_MODES] = {\n");
+ for (i = 0; i < VP8_YMODES; ++i)
+ {
+ printf(" {");
+ for (t = 0; t < VP8_UV_MODES; ++t) printf("%d, ", cm->fc.uv_mode_counts[i][t]);
+ printf("},\n");
+ }
+ printf("};\n");
+ printf("static const unsigned int\nbmode_counts"
+ "[VP8_BINTRAMODES] = {\n");
+ for (t = 0; t<VP8_BINTRAMODES; ++t) printf("%d, ", cm->fc.bmode_counts[t]);
+ printf("};\n");
+ printf("static const unsigned int\ni8x8_mode_counts"
+ "[VP8_I8X8_MODES] = {\n");
+ for (t = 0; t<VP8_I8X8_MODES; ++t) printf("%d, ", cm->fc.i8x8_mode_counts[t]);
+ printf("};\n");
+#endif
+ vp8_tree_probs_from_distribution(
+ VP8_YMODES, vp8_ymode_encodings, vp8_ymode_tree,
+ ymode_probs, branch_ct, cm->fc.ymode_counts,
+ 256, 1);
+ for (t=0; t<VP8_YMODES-1; ++t)
+ {
+ int prob;
+ count = branch_ct[t][0] + branch_ct[t][1];
+ count = count > count_sat ? count_sat : count;
+ factor = (update_factor * count / count_sat);
+ prob = ((int)cm->fc.pre_ymode_prob[t] * (256-factor) +
+ (int)ymode_probs[t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.ymode_prob[t] = 1;
+ else if (prob > 255) cm->fc.ymode_prob[t] = 255;
+ else cm->fc.ymode_prob[t] = prob;
+ }
+ for (i = 0; i < VP8_YMODES; ++i)
+ {
+ vp8_tree_probs_from_distribution(
+ VP8_UV_MODES, vp8_uv_mode_encodings, vp8_uv_mode_tree,
+ uvmode_probs, branch_ct, cm->fc.uv_mode_counts[i],
+ 256, 1);
+ for (t = 0; t < VP8_UV_MODES-1; ++t)
+ {
+ int prob;
+ count = branch_ct[t][0] + branch_ct[t][1];
+ count = count > count_sat ? count_sat : count;
+ factor = (update_factor * count / count_sat);
+ prob = ((int)cm->fc.pre_uv_mode_prob[i][t] * (256-factor) +
+ (int)uvmode_probs[t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.uv_mode_prob[i][t] = 1;
+ else if (prob > 255) cm->fc.uv_mode_prob[i][t] = 255;
+ else cm->fc.uv_mode_prob[i][t] = prob;
+ }
+ }
+ vp8_tree_probs_from_distribution(
+ VP8_BINTRAMODES, vp8_bmode_encodings, vp8_bmode_tree,
+ bmode_probs, branch_ct, cm->fc.bmode_counts,
+ 256, 1);
+ for (t=0; t<VP8_BINTRAMODES-1; ++t)
+ {
+ int prob;
+ count = branch_ct[t][0] + branch_ct[t][1];
+ count = count > count_sat ? count_sat : count;
+ factor = (update_factor * count / count_sat);
+ prob = ((int)cm->fc.pre_bmode_prob[t] * (256-factor) +
+ (int)bmode_probs[t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.bmode_prob[t] = 1;
+ else if (prob > 255) cm->fc.bmode_prob[t] = 255;
+ else cm->fc.bmode_prob[t] = prob;
+ }
+ vp8_tree_probs_from_distribution(
+ VP8_I8X8_MODES, vp8_i8x8_mode_encodings, vp8_i8x8_mode_tree,
+ i8x8_mode_probs, branch_ct, cm->fc.i8x8_mode_counts,
+ 256, 1);
+ for (t=0; t<VP8_I8X8_MODES-1; ++t)
+ {
+ int prob;
+ count = branch_ct[t][0] + branch_ct[t][1];
+ count = count > count_sat ? count_sat : count;
+ factor = (update_factor * count / count_sat);
+ prob = ((int)cm->fc.pre_i8x8_mode_prob[t] * (256-factor) +
+ (int)i8x8_mode_probs[t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.i8x8_mode_prob[t] = 1;
+ else if (prob > 255) cm->fc.i8x8_mode_prob[t] = 255;
+ else cm->fc.i8x8_mode_prob[t] = prob;
+ }
+}
+#endif
diff --git a/vp8/common/entropymode.h b/vp8/common/entropymode.h
index 09d5c7704..cfd532736 100644
--- a/vp8/common/entropymode.h
+++ b/vp8/common/entropymode.h
@@ -55,13 +55,6 @@ extern struct vp8_token_struct vp8_mbsplit_encodings [VP8_NUMMBSPLITS];
extern struct vp8_token_struct vp8_mv_ref_encoding_array [VP8_MVREFS];
extern struct vp8_token_struct vp8_sub_mv_ref_encoding_array [VP8_SUBMVREFS];
-extern const vp8_tree_index vp8_small_mvtree[];
-extern struct vp8_token_struct vp8_small_mvencodings [8];
-#if CONFIG_HIGH_PRECISION_MV
-extern const vp8_tree_index vp8_small_mvtree_hp[];
-extern struct vp8_token_struct vp8_small_mvencodings_hp [16];
-#endif
-
void vp8_entropy_mode_init(void);
void vp8_init_mbmode_probs(VP8_COMMON *x);
@@ -71,7 +64,10 @@ extern void vp8_accum_mv_refs(VP8_COMMON *pc,
MB_PREDICTION_MODE m,
const int ct[4]);
-void vp8_default_bmode_probs(vp8_prob dest [VP8_BINTRAMODES-1]);
+void vp8_default_bmode_probs(vp8_prob dest [VP8_BINTRAMODES-1]);
void vp8_kf_default_bmode_probs(vp8_prob dest [VP8_BINTRAMODES] [VP8_BINTRAMODES] [VP8_BINTRAMODES-1]);
+#if CONFIG_ADAPTIVE_ENTROPY
+void vp8_adapt_mode_probs(struct VP8Common *);
+#endif
#endif
diff --git a/vp8/common/entropymv.c b/vp8/common/entropymv.c
index 90195f7bc..2c27b0913 100644
--- a/vp8/common/entropymv.c
+++ b/vp8/common/entropymv.c
@@ -9,6 +9,7 @@
*/
+#include "onyxc_int.h"
#include "entropymv.h"
#if CONFIG_HIGH_PRECISION_MV
@@ -78,3 +79,361 @@ const MV_CONTEXT vp8_default_mv_context[2] =
128, 130, 130, 74, 148, 180, 203, 236, 254, 254 /* long bits */
}}
};
+
+#if CONFIG_HIGH_PRECISION_MV
+const vp8_tree_index vp8_small_mvtree_hp [30] =
+{
+ 2, 16,
+ 4, 10,
+ 6, 8,
+ -0, -1,
+ -2, -3,
+ 12, 14,
+ -4, -5,
+ -6, -7,
+ 18, 24,
+ 20, 22,
+ -8, -9,
+ -10, -11,
+ 26, 28,
+ -12, -13,
+ -14, -15
+};
+struct vp8_token_struct vp8_small_mvencodings_hp [16];
+#endif /* CONFIG_HIGH_PRECISION_MV */
+
+const vp8_tree_index vp8_small_mvtree [14] =
+{
+ 2, 8,
+ 4, 6,
+ -0, -1,
+ -2, -3,
+ 10, 12,
+ -4, -5,
+ -6, -7
+};
+struct vp8_token_struct vp8_small_mvencodings [8];
+
+
+__inline static void calc_prob(vp8_prob *p, const unsigned int ct[2], int pbits)
+{
+ const unsigned int tot = ct[0] + ct[1];
+ if (tot)
+ {
+ const vp8_prob x = ((ct[0] * 255) / tot) & -(1<<(8-pbits));
+ *p = x ? x : 1;
+ }
+}
+
+static void compute_component_probs(
+ const unsigned int events [MVvals],
+ vp8_prob Pnew [MVPcount],
+ unsigned int is_short_ct[2],
+ unsigned int sign_ct[2],
+ unsigned int bit_ct [mvlong_width] [2],
+ unsigned int short_ct [mvnum_short],
+ unsigned int short_bct [mvnum_short-1] [2]
+)
+{
+ is_short_ct[0] = is_short_ct[1] = 0;
+ sign_ct[0] = sign_ct[1] = 0;
+ vpx_memset(bit_ct, 0, sizeof(unsigned int)*mvlong_width*2);
+ vpx_memset(short_ct, 0, sizeof(unsigned int)*mvnum_short);
+ vpx_memset(short_bct, 0, sizeof(unsigned int)*(mvnum_short-1)*2);
+
+ {
+ const int c = events [mv_max];
+ is_short_ct [0] += c; // Short vector
+ short_ct [0] += c; // Magnitude distribution
+ }
+ {
+ int j = 1;
+ do
+ {
+ const int c1 = events [mv_max + j]; //positive
+ const int c2 = events [mv_max - j]; //negative
+ const int c = c1 + c2;
+ int a = j;
+
+ sign_ct [0] += c1;
+ sign_ct [1] += c2;
+
+ if (a < mvnum_short)
+ {
+ is_short_ct [0] += c; // Short vector
+ short_ct [a] += c; // Magnitude distribution
+ }
+ else
+ {
+ int k = mvlong_width - 1;
+ is_short_ct [1] += c; // Long vector
+
+ do
+ bit_ct [k] [(a >> k) & 1] += c;
+
+ while (--k >= 0);
+ }
+ }
+ while (++j <= mv_max);
+ }
+ calc_prob(Pnew + mvpis_short, is_short_ct, 8);
+
+ calc_prob(Pnew + MVPsign, sign_ct, 8);
+
+ {
+ vp8_prob p [mvnum_short - 1]; /* actually only need branch ct */
+ int j = 0;
+
+ vp8_tree_probs_from_distribution(
+ mvnum_short, vp8_small_mvencodings, vp8_small_mvtree,
+ p, short_bct, short_ct,
+ 256, 1
+ );
+
+ do
+ calc_prob(Pnew + MVPshort + j, short_bct[j], 8);
+ while (++j < mvnum_short - 1);
+ }
+
+ {
+ int j = 0;
+ do
+ calc_prob(Pnew + MVPbits + j, bit_ct[j], 8);
+ while (++j < mvlong_width);
+ }
+}
+
+#if CONFIG_HIGH_PRECISION_MV
+static void compute_component_probs_hp(
+ const unsigned int events [MVvals_hp],
+ vp8_prob Pnew [MVPcount_hp],
+ unsigned int is_short_ct[2],
+ unsigned int sign_ct[2],
+ unsigned int bit_ct [mvlong_width_hp] [2],
+ unsigned int short_ct [mvnum_short_hp],
+ unsigned int short_bct [mvnum_short_hp-1] [2]
+)
+{
+ is_short_ct[0] = is_short_ct[1] = 0;
+ sign_ct[0] = sign_ct[1] = 0;
+ vpx_memset(bit_ct, 0, sizeof(unsigned int)*mvlong_width_hp*2);
+ vpx_memset(short_ct, 0, sizeof(unsigned int)*mvnum_short_hp);
+ vpx_memset(short_bct, 0, sizeof(unsigned int)*(mvnum_short_hp-1)*2);
+
+ {
+ const int c = events [mv_max_hp];
+ is_short_ct [0] += c; // Short vector
+ short_ct [0] += c; // Magnitude distribution
+ }
+ {
+ int j = 1;
+ do
+ {
+ const int c1 = events [mv_max_hp + j]; //positive
+ const int c2 = events [mv_max_hp - j]; //negative
+ const int c = c1 + c2;
+ int a = j;
+
+ sign_ct [0] += c1;
+ sign_ct [1] += c2;
+
+ if (a < mvnum_short_hp)
+ {
+ is_short_ct [0] += c; // Short vector
+ short_ct [a] += c; // Magnitude distribution
+ }
+ else
+ {
+ int k = mvlong_width_hp - 1;
+ is_short_ct [1] += c; // Long vector
+
+ do
+ bit_ct [k] [(a >> k) & 1] += c;
+
+ while (--k >= 0);
+ }
+ }
+ while (++j <= mv_max_hp);
+ }
+ calc_prob(Pnew + mvpis_short_hp, is_short_ct, 8);
+
+ calc_prob(Pnew + MVPsign_hp, sign_ct, 8);
+
+ {
+ vp8_prob p [mvnum_short_hp - 1]; /* actually only need branch ct */
+ int j = 0;
+
+ vp8_tree_probs_from_distribution(
+ mvnum_short_hp, vp8_small_mvencodings_hp, vp8_small_mvtree_hp,
+ p, short_bct, short_ct,
+ 256, 1
+ );
+
+ do
+ calc_prob(Pnew + MVPshort_hp + j, short_bct[j], 8);
+ while (++j < mvnum_short_hp - 1);
+ }
+
+ {
+ int j = 0;
+ do
+ calc_prob(Pnew + MVPbits_hp + j, bit_ct[j], 8);
+ while (++j < mvlong_width_hp);
+ }
+}
+#endif /* CONFIG_HIGH_PRECISION_MV */
+
+void vp8_entropy_mv_init()
+{
+ vp8_tokens_from_tree(vp8_small_mvencodings, vp8_small_mvtree);
+#if CONFIG_HIGH_PRECISION_MV
+ vp8_tokens_from_tree(vp8_small_mvencodings_hp, vp8_small_mvtree_hp);
+#endif
+}
+
+#if CONFIG_ADAPTIVE_ENTROPY
+//#define MV_COUNT_TESTING
+#define MV_COUNT_SAT 16
+#define MV_MAX_UPDATE_FACTOR 128
+void vp8_adapt_mv_probs(VP8_COMMON *cm)
+{
+ int i, t, count, factor;
+#ifdef MV_COUNT_TESTING
+ printf("static const unsigned int\nMVcount[2][MVvals]={\n");
+ for (i = 0; i < 2; ++i)
+ {
+ printf(" { ");
+ for (t = 0; t < MVvals; t++)
+ {
+ printf("%d, ", cm->fc.MVcount[i][t]);
+ if (t%16 == 15 && t!=MVvals-1) printf("\n ");
+ }
+ printf("},\n");
+ }
+ printf("};\n");
+#if CONFIG_HIGH_PRECISION_MV
+ printf("static const unsigned int\nMVcount_hp[2][MVvals_hp]={\n");
+ for (i = 0; i < 2; ++i)
+ {
+ printf(" { ");
+ for (t = 0; t < MVvals_hp; t++)
+ {
+ printf("%d, ", cm->fc.MVcount_hp[i][t]);
+ if (t%16 == 15 && t!=MVvals_hp-1) printf("\n ");
+ }
+ printf("},\n");
+ }
+ printf("};\n");
+#endif
+#endif /* MV_COUNT_TESTING */
+
+ for (i = 0; i < 2; ++i)
+ {
+ int prob;
+ unsigned int is_short_ct[2];
+ unsigned int sign_ct[2];
+ unsigned int bit_ct [mvlong_width] [2];
+ unsigned int short_ct [mvnum_short];
+ unsigned int short_bct [mvnum_short-1] [2];
+ vp8_prob Pnew [MVPcount];
+ compute_component_probs(cm->fc.MVcount[i], Pnew,
+ is_short_ct, sign_ct,
+ bit_ct, short_ct, short_bct);
+ count = is_short_ct[0] + is_short_ct[1];
+ count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
+ factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
+ prob = ((int)cm->fc.pre_mvc[i].prob[mvpis_short] * (256-factor) +
+ (int)Pnew[mvpis_short] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.mvc[i].prob[mvpis_short] = 1;
+ else if (prob > 255) cm->fc.mvc[i].prob[mvpis_short] = 255;
+ else cm->fc.mvc[i].prob[mvpis_short] = prob;
+
+ count = sign_ct[0] + sign_ct[1];
+ count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
+ factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
+ prob = ((int)cm->fc.pre_mvc[i].prob[MVPsign] * (256-factor) +
+ (int)Pnew[MVPsign] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.mvc[i].prob[MVPsign] = 1;
+ else if (prob > 255) cm->fc.mvc[i].prob[MVPsign] = 255;
+ else cm->fc.mvc[i].prob[MVPsign] = prob;
+
+ for (t = 0; t < mvnum_short - 1; ++t)
+ {
+ count = short_bct[t][0] + short_bct[t][1];
+ count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
+ factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
+ prob = ((int)cm->fc.pre_mvc[i].prob[MVPshort+t] * (256-factor) +
+ (int)Pnew[MVPshort+t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.mvc[i].prob[MVPshort+t] = 1;
+ else if (prob > 255) cm->fc.mvc[i].prob[MVPshort+t] = 255;
+ else cm->fc.mvc[i].prob[MVPshort+t] = prob;
+ }
+ for (t = 0; t < mvlong_width; ++t)
+ {
+ count = bit_ct[t][0] + bit_ct[t][1];
+ count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
+ factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
+ prob = ((int)cm->fc.pre_mvc[i].prob[MVPbits+t] * (256-factor) +
+ (int)Pnew[MVPbits+t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.mvc[i].prob[MVPbits+t] = 1;
+ else if (prob > 255) cm->fc.mvc[i].prob[MVPbits+t] = 255;
+ else cm->fc.mvc[i].prob[MVPbits+t] = prob;
+ }
+ }
+#if CONFIG_HIGH_PRECISION_MV
+ for (i = 0; i < 2; ++i)
+ {
+ int prob;
+ unsigned int is_short_ct[2];
+ unsigned int sign_ct[2];
+ unsigned int bit_ct [mvlong_width_hp] [2];
+ unsigned int short_ct [mvnum_short_hp];
+ unsigned int short_bct [mvnum_short_hp-1] [2];
+ vp8_prob Pnew [MVPcount_hp];
+ compute_component_probs_hp(cm->fc.MVcount_hp[i], Pnew,
+ is_short_ct, sign_ct,
+ bit_ct, short_ct, short_bct);
+ count = is_short_ct[0] + is_short_ct[1];
+ count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
+ factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
+ prob = ((int)cm->fc.pre_mvc_hp[i].prob[mvpis_short_hp] * (256-factor) +
+ (int)Pnew[mvpis_short_hp] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.mvc_hp[i].prob[mvpis_short_hp] = 1;
+ else if (prob > 255) cm->fc.mvc_hp[i].prob[mvpis_short_hp] = 255;
+ else cm->fc.mvc_hp[i].prob[mvpis_short_hp] = prob;
+
+ count = sign_ct[0] + sign_ct[1];
+ count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
+ factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
+ prob = ((int)cm->fc.pre_mvc_hp[i].prob[MVPsign_hp] * (256-factor) +
+ (int)Pnew[MVPsign_hp] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.mvc_hp[i].prob[MVPsign_hp] = 1;
+ else if (prob > 255) cm->fc.mvc_hp[i].prob[MVPsign_hp] = 255;
+ else cm->fc.mvc_hp[i].prob[MVPsign_hp] = prob;
+
+ for (t = 0; t < mvnum_short_hp - 1; ++t)
+ {
+ count = short_bct[t][0] + short_bct[t][1];
+ count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
+ factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
+ prob = ((int)cm->fc.pre_mvc_hp[i].prob[MVPshort_hp+t] * (256-factor) +
+ (int)Pnew[MVPshort_hp+t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.mvc_hp[i].prob[MVPshort_hp+t] = 1;
+ else if (prob > 255) cm->fc.mvc_hp[i].prob[MVPshort_hp+t] = 255;
+ else cm->fc.mvc_hp[i].prob[MVPshort_hp+t] = prob;
+ }
+ for (t = 0; t < mvlong_width_hp; ++t)
+ {
+ count = bit_ct[t][0] + bit_ct[t][1];
+ count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
+ factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
+ prob = ((int)cm->fc.pre_mvc_hp[i].prob[MVPbits_hp+t] * (256-factor) +
+ (int)Pnew[MVPbits_hp+t] * factor + 128) >> 8;
+ if (prob <= 0) cm->fc.mvc_hp[i].prob[MVPbits_hp+t] = 1;
+ else if (prob > 255) cm->fc.mvc_hp[i].prob[MVPbits_hp+t] = 255;
+ else cm->fc.mvc_hp[i].prob[MVPbits_hp+t] = prob;
+ }
+ }
+#endif
+}
+#endif /* CONFIG_ADAPTIVE_ENTROPY */
diff --git a/vp8/common/entropymv.h b/vp8/common/entropymv.h
index d97c12eab..09c2587d2 100644
--- a/vp8/common/entropymv.h
+++ b/vp8/common/entropymv.h
@@ -71,6 +71,16 @@ typedef struct mv_context_hp
} MV_CONTEXT_HP;
extern const MV_CONTEXT_HP vp8_mv_update_probs_hp[2], vp8_default_mv_context_hp[2];
+
#endif /* CONFIG_HIGH_PRECISION_MV */
+extern const vp8_tree_index vp8_small_mvtree[];
+extern struct vp8_token_struct vp8_small_mvencodings [8];
+#if CONFIG_HIGH_PRECISION_MV
+extern const vp8_tree_index vp8_small_mvtree_hp[];
+extern struct vp8_token_struct vp8_small_mvencodings_hp [16];
+#endif
+
+void vp8_entropy_mv_init();
+
#endif
diff --git a/vp8/common/onyxc_int.h b/vp8/common/onyxc_int.h
index f36915c51..a068b43ae 100644
--- a/vp8/common/onyxc_int.h
+++ b/vp8/common/onyxc_int.h
@@ -47,6 +47,7 @@ typedef struct frame_contexts
vp8_prob bmode_prob [VP8_BINTRAMODES-1];
vp8_prob ymode_prob [VP8_YMODES-1]; /* interframe intra mode probs */
vp8_prob uv_mode_prob [VP8_YMODES][VP8_UV_MODES-1];
+ vp8_prob i8x8_mode_prob [VP8_I8X8_MODES-1];
vp8_prob sub_mv_ref_prob [VP8_SUBMVREFS-1];
vp8_prob coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
vp8_prob coef_probs_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
@@ -54,6 +55,31 @@ typedef struct frame_contexts
#if CONFIG_HIGH_PRECISION_MV
MV_CONTEXT_HP mvc_hp[2];
#endif
+#if CONFIG_ADAPTIVE_ENTROPY
+ MV_CONTEXT pre_mvc[2];
+#if CONFIG_HIGH_PRECISION_MV
+ MV_CONTEXT_HP pre_mvc_hp[2];
+#endif
+ vp8_prob pre_bmode_prob [VP8_BINTRAMODES-1];
+ vp8_prob pre_ymode_prob [VP8_YMODES-1]; /* interframe intra mode probs */
+ vp8_prob pre_uv_mode_prob [VP8_YMODES][VP8_UV_MODES-1];
+ vp8_prob pre_i8x8_mode_prob [VP8_I8X8_MODES-1];
+ unsigned int bmode_counts [VP8_BINTRAMODES];
+ unsigned int ymode_counts [VP8_YMODES]; /* interframe intra mode probs */
+ unsigned int uv_mode_counts [VP8_YMODES][VP8_UV_MODES];
+ unsigned int i8x8_mode_counts [VP8_I8X8_MODES]; /* interframe intra mode probs */
+
+ vp8_prob pre_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
+ vp8_prob pre_coef_probs_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
+ unsigned int coef_counts [BLOCK_TYPES] [COEF_BANDS]
+ [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
+ unsigned int coef_counts_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS]
+ [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
+ unsigned int MVcount [2] [MVvals];
+#if CONFIG_HIGH_PRECISION_MV
+ unsigned int MVcount_hp [2] [MVvals_hp];
+#endif
+#endif /* CONFIG_ADAPTIVE_ENTROPY */
} FRAME_CONTEXT;
typedef enum
@@ -104,7 +130,6 @@ typedef struct VP8_COMMON_RTCD
} VP8_COMMON_RTCD;
typedef struct VP8Common
-
{
struct vpx_internal_error_info error;
@@ -205,7 +230,6 @@ typedef struct VP8Common
int kf_ymode_probs_index;
int kf_ymode_probs_update;
vp8_prob kf_uv_mode_prob[VP8_YMODES] [VP8_UV_MODES-1];
- vp8_prob i8x8_mode_prob [VP8_UV_MODES-1];
vp8_prob prob_intra_coded;
vp8_prob prob_last_coded;
diff --git a/vp8/common/tapify.py b/vp8/common/tapify.py
index 99529cff0..99529cff0 100755..100644
--- a/vp8/common/tapify.py
+++ b/vp8/common/tapify.py