Commit f3dff402 authored by Deb Mukherjee's avatar Deb Mukherjee Committed by Yaowu Xu

Continued adaptive entropy coding

Incorporates mv_ref, mbsplit and second_mv into the adaptive
entropy framework. The mv_ref framework has been modified from
before.

Adds some clean-ups and fixes.

Results with the adaptive entropy experiment are currently up by
+1.93% on derf; +2.33% std-hd and +1.87% yt-hd.

Fixed a nasty intermittent bug.

Change-Id: I4b1ac9f9483b48432597595195bfec05f31d1e39
parent 9c9d6743
......@@ -16,6 +16,11 @@
#include "blockd.h"
#include "common.h"
#include "coefupdateprobs.h"
#define SUBMVREF_COUNT 5
#define VP8_NUMMBSPLITS 4
/* Coefficient token alphabet */
#define ZERO_TOKEN 0 /* 0 Extra Bits 0+0 */
......
......@@ -142,7 +142,7 @@ int vp8_mv_cont(const int_mv *l, const int_mv *a)
return SUBMVREF_NORMAL;
}
static const vp8_prob sub_mv_ref_prob [VP8_SUBMVREFS-1] = { 180, 162, 25};
const vp8_prob vp8_sub_mv_ref_prob [VP8_SUBMVREFS-1] = { 180, 162, 25};
const vp8_prob vp8_sub_mv_ref_prob2 [SUBMVREF_COUNT][VP8_SUBMVREFS-1] =
{
......@@ -372,7 +372,8 @@ void vp8_init_mbmode_probs(VP8_COMMON *x)
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));
vpx_memcpy(x->fc.sub_mv_ref_prob, vp8_sub_mv_ref_prob2, sizeof(vp8_sub_mv_ref_prob2));
vpx_memcpy(x->fc.mbsplit_prob, vp8_mbsplit_probs, sizeof(vp8_mbsplit_probs));
}
......@@ -435,15 +436,15 @@ void vp8_entropy_mode_init()
void vp8_init_mode_contexts(VP8_COMMON *pc)
{
vpx_memset(pc->mv_ref_ct, 0, sizeof(pc->mv_ref_ct));
vpx_memset(pc->mv_ref_ct_a, 0, sizeof(pc->mv_ref_ct_a));
vpx_memset(pc->fc.mv_ref_ct, 0, sizeof(pc->fc.mv_ref_ct));
vpx_memset(pc->fc.mv_ref_ct_a, 0, sizeof(pc->fc.mv_ref_ct_a));
vpx_memcpy( pc->mode_context,
vpx_memcpy( pc->fc.mode_context,
default_vp8_mode_contexts,
sizeof (pc->mode_context));
vpx_memcpy( pc->mode_context_a,
sizeof (pc->fc.mode_context));
vpx_memcpy( pc->fc.mode_context_a,
default_vp8_mode_contexts,
sizeof (pc->mode_context_a));
sizeof (pc->fc.mode_context_a));
}
......@@ -454,9 +455,9 @@ void vp8_accum_mv_refs(VP8_COMMON *pc,
int (*mv_ref_ct)[4][2];
if(pc->refresh_alt_ref_frame)
mv_ref_ct = pc->mv_ref_ct_a;
mv_ref_ct = pc->fc.mv_ref_ct_a;
else
mv_ref_ct = pc->mv_ref_ct;
mv_ref_ct = pc->fc.mv_ref_ct;
if (m == ZEROMV)
{
......@@ -492,6 +493,8 @@ void vp8_accum_mv_refs(VP8_COMMON *pc,
}
}
#define MVREF_COUNT_SAT 20
#define MVREF_MAX_UPDATE_FACTOR 128
void vp8_update_mode_context(VP8_COMMON *pc)
{
int i, j;
......@@ -500,13 +503,13 @@ void vp8_update_mode_context(VP8_COMMON *pc)
if(pc->refresh_alt_ref_frame)
{
mv_ref_ct = pc->mv_ref_ct_a;
mode_context = pc->mode_context_a;
mv_ref_ct = pc->fc.mv_ref_ct_a;
mode_context = pc->fc.mode_context_a;
}
else
{
mv_ref_ct = pc->mv_ref_ct;
mode_context = pc->mode_context;
mv_ref_ct = pc->fc.mv_ref_ct;
mode_context = pc->fc.mode_context;
}
for (j = 0; j < 6; j++)
......@@ -515,6 +518,18 @@ void vp8_update_mode_context(VP8_COMMON *pc)
{
int this_prob;
int count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1];
#if CONFIG_ADAPTIVE_ENTROPY
int factor;
{
this_prob = count > 0 ? 256 * mv_ref_ct[j][i][0] / count : 128;
count = count > MVREF_COUNT_SAT ? MVREF_COUNT_SAT : count;
factor = (MVREF_MAX_UPDATE_FACTOR * count / MVREF_COUNT_SAT);
this_prob = (pc->fc.vp8_mode_contexts[j][i] * (256 - factor) +
this_prob * factor + 128) >> 8;
this_prob = this_prob? (this_prob<255?this_prob:255):1;
mode_context[j][i] = this_prob;
}
#else
/* preventing rare occurances from skewing the probs */
if (count>=4)
{
......@@ -522,9 +537,11 @@ void vp8_update_mode_context(VP8_COMMON *pc)
this_prob = this_prob? (this_prob<255?this_prob:255):1;
mode_context[j][i] = this_prob;
}
#endif
}
}
}
#include "vp8/common/modecont.h"
void print_mode_contexts(VP8_COMMON *pc)
{
......@@ -534,7 +551,7 @@ void print_mode_contexts(VP8_COMMON *pc)
{
for (i = 0; i < 4; i++)
{
printf( "%4d ", pc->mode_context[j][i]);
printf( "%4d ", pc->fc.mode_context[j][i]);
}
printf("\n");
}
......@@ -543,7 +560,7 @@ void print_mode_contexts(VP8_COMMON *pc)
{
for (i = 0; i < 4; i++)
{
printf( "%4d ", pc->mode_context_a[j][i]);
printf( "%4d ", pc->fc.mode_context_a[j][i]);
}
printf("\n");
}
......@@ -557,8 +574,8 @@ void print_mv_ref_cts(VP8_COMMON *pc)
for (i = 0; i < 4; i++)
{
printf("(%4d:%4d) ",
pc->mv_ref_ct[j][i][0],
pc->mv_ref_ct[j][i][1]);
pc->fc.mv_ref_ct[j][i][0],
pc->fc.mv_ref_ct[j][i][1]);
}
printf("\n");
}
......@@ -567,17 +584,17 @@ void print_mv_ref_cts(VP8_COMMON *pc)
#if CONFIG_ADAPTIVE_ENTROPY
//#define MODE_COUNT_TESTING
#define MODE_COUNT_SAT 16
#define MODE_MAX_UPDATE_FACTOR 96
#define MODE_MAX_UPDATE_FACTOR 128
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];
vp8_prob sub_mv_ref_probs[VP8_SUBMVREFS-1];
vp8_prob mbsplit_probs[VP8_NUMMBSPLITS-1];
#ifdef MODE_COUNT_TESTING
printf("static const unsigned int\nymode_counts"
"[VP8_YMODES] = {\n");
......@@ -600,6 +617,19 @@ void vp8_adapt_mode_probs(VP8_COMMON *cm)
"[VP8_I8X8_MODES] = {\n");
for (t = 0; t<VP8_I8X8_MODES; ++t) printf("%d, ", cm->fc.i8x8_mode_counts[t]);
printf("};\n");
printf("static const unsigned int\nsub_mv_ref_counts"
"[SUBMVREF_COUNT] [VP8_SUBMVREFS] = {\n");
for (i = 0; i < SUBMVREF_COUNT; ++i)
{
printf(" {");
for (t = 0; t < VP8_SUBMVREFS; ++t) printf("%d, ", cm->fc.sub_mv_ref_counts[i][t]);
printf("},\n");
}
printf("};\n");
printf("static const unsigned int\nmbsplit_counts"
"[VP8_NUMMBSPLITS] = {\n");
for (t = 0; t<VP8_NUMMBSPLITS; ++t) printf("%d, ", cm->fc.mbsplit_counts[t]);
printf("};\n");
#endif
vp8_tree_probs_from_distribution(
VP8_YMODES, vp8_ymode_encodings, vp8_ymode_tree,
......@@ -609,8 +639,8 @@ void vp8_adapt_mode_probs(VP8_COMMON *cm)
{
int prob;
count = branch_ct[t][0] + branch_ct[t][1];
count = count > count_sat ? count_sat : count;
factor = (update_factor * count / count_sat);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_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;
......@@ -627,8 +657,8 @@ void vp8_adapt_mode_probs(VP8_COMMON *cm)
{
int prob;
count = branch_ct[t][0] + branch_ct[t][1];
count = count > count_sat ? count_sat : count;
factor = (update_factor * count / count_sat);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_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;
......@@ -644,8 +674,8 @@ void vp8_adapt_mode_probs(VP8_COMMON *cm)
{
int prob;
count = branch_ct[t][0] + branch_ct[t][1];
count = count > count_sat ? count_sat : count;
factor = (update_factor * count / count_sat);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_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;
......@@ -660,13 +690,48 @@ void vp8_adapt_mode_probs(VP8_COMMON *cm)
{
int prob;
count = branch_ct[t][0] + branch_ct[t][1];
count = count > count_sat ? count_sat : count;
factor = (update_factor * count / count_sat);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_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;
}
for (i = 0; i < SUBMVREF_COUNT; ++i)
{
vp8_tree_probs_from_distribution(
VP8_SUBMVREFS, vp8_sub_mv_ref_encoding_array, vp8_sub_mv_ref_tree,
sub_mv_ref_probs, branch_ct, cm->fc.sub_mv_ref_counts[i],
256, 1);
for (t = 0; t < VP8_SUBMVREFS-1; ++t)
{
int prob;
count = branch_ct[t][0] + branch_ct[t][1];
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
prob = ((int)cm->fc.pre_sub_mv_ref_prob[i][t] * (256-factor) +
(int)sub_mv_ref_probs[t] * factor + 128) >> 8;
if (prob <= 0) cm->fc.sub_mv_ref_prob[i][t] = 1;
else if (prob > 255) cm->fc.sub_mv_ref_prob[i][t] = 255;
else cm->fc.sub_mv_ref_prob[i][t] = prob;
}
}
vp8_tree_probs_from_distribution(
VP8_NUMMBSPLITS, vp8_mbsplit_encodings, vp8_mbsplit_tree,
mbsplit_probs, branch_ct, cm->fc.mbsplit_counts,
256, 1);
for (t = 0; t < VP8_NUMMBSPLITS-1; ++t)
{
int prob;
count = branch_ct[t][0] + branch_ct[t][1];
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
prob = ((int)cm->fc.pre_mbsplit_prob[t] * (256 - factor) +
(int)mbsplit_probs[t] * factor + 128) >> 8;
if (prob <= 0) cm->fc.mbsplit_prob[t] = 1;
else if (prob > 255) cm->fc.mbsplit_prob[t] = 255;
else cm->fc.mbsplit_prob[t] = prob;
}
}
#endif
......@@ -17,8 +17,6 @@
typedef const int vp8_mbsplit[16];
#define VP8_NUMMBSPLITS 4
extern vp8_mbsplit vp8_mbsplits [VP8_NUMMBSPLITS];
extern const int vp8_mbsplit_count [VP8_NUMMBSPLITS]; /* # of subsets */
......@@ -26,7 +24,8 @@ extern const int vp8_mbsplit_count [VP8_NUMMBSPLITS]; /* # of subsets */
extern const vp8_prob vp8_mbsplit_probs [VP8_NUMMBSPLITS-1];
extern int vp8_mv_cont(const int_mv *l, const int_mv *a);
#define SUBMVREF_COUNT 5
extern const vp8_prob vp8_sub_mv_ref_prob [VP8_SUBMVREFS-1];
extern const vp8_prob vp8_sub_mv_ref_prob2 [SUBMVREF_COUNT][VP8_SUBMVREFS-1];
......
......@@ -177,9 +177,9 @@ vp8_prob *vp8_mv_ref_probs(VP8_COMMON *pc,
vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
)
{
p[0] = pc->vp8_mode_contexts [near_mv_ref_ct[0]] [0];
p[1] = pc->vp8_mode_contexts [near_mv_ref_ct[1]] [1];
p[2] = pc->vp8_mode_contexts [near_mv_ref_ct[2]] [2];
p[3] = pc->vp8_mode_contexts [near_mv_ref_ct[3]] [3];
p[0] = pc->fc.vp8_mode_contexts [near_mv_ref_ct[0]] [0];
p[1] = pc->fc.vp8_mode_contexts [near_mv_ref_ct[1]] [1];
p[2] = pc->fc.vp8_mode_contexts [near_mv_ref_ct[2]] [2];
p[3] = pc->fc.vp8_mode_contexts [near_mv_ref_ct[3]] [3];
return p;
}
......@@ -48,7 +48,8 @@ typedef struct frame_contexts
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 sub_mv_ref_prob [SUBMVREF_COUNT][VP8_SUBMVREFS-1];
vp8_prob mbsplit_prob [VP8_NUMMBSPLITS-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];
MV_CONTEXT mvc[2];
......@@ -64,10 +65,14 @@ typedef struct frame_contexts
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];
vp8_prob pre_sub_mv_ref_prob [SUBMVREF_COUNT][VP8_SUBMVREFS-1];
vp8_prob pre_mbsplit_prob [VP8_NUMMBSPLITS-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 */
unsigned int sub_mv_ref_counts [SUBMVREF_COUNT][VP8_SUBMVREFS];
unsigned int mbsplit_counts [VP8_NUMMBSPLITS];
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];
......@@ -80,6 +85,11 @@ typedef struct frame_contexts
unsigned int MVcount_hp [2] [MVvals_hp];
#endif
#endif /* CONFIG_ADAPTIVE_ENTROPY */
int mode_context[6][4];
int mode_context_a[6][4];
int vp8_mode_contexts[6][4];
int mv_ref_ct[6][4][2];
int mv_ref_ct_a[6][4][2];
} FRAME_CONTEXT;
typedef enum
......@@ -254,11 +264,11 @@ typedef struct VP8Common
FRAME_CONTEXT lfc; /* last frame entropy */
FRAME_CONTEXT fc; /* this frame entropy */
int mv_ref_ct[6][4][2];
int mode_context[6][4];
int mv_ref_ct_a[6][4][2];
int mode_context_a[6][4];
int vp8_mode_contexts[6][4];
//int mv_ref_ct[6][4][2];
//int mv_ref_ct_a[6][4][2];
//int mode_context[6][4];
//int mode_context_a[6][4];
//int vp8_mode_contexts[6][4];
unsigned int current_video_frame;
int near_boffset[3];
......
......@@ -759,9 +759,12 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
case SPLITMV:
{
const int s = mbmi->partitioning =
vp8_treed_read(bc, vp8_mbsplit_tree, vp8_mbsplit_probs);
vp8_treed_read(bc, vp8_mbsplit_tree, cm->fc.mbsplit_prob);
const int num_p = vp8_mbsplit_count [s];
int j = 0;
#if CONFIG_ADAPTIVE_ENTROPY
cm->fc.mbsplit_counts[s]++;
#endif
mbmi->need_to_clamp_mvs = 0;
do /* for each subset j */
......@@ -782,7 +785,10 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
second_abovemv.as_int = above_block_second_mv(mi, k, mis);
}
mv_contz = vp8_mv_cont(&leftmv, &abovemv);
blockmode = sub_mv_ref(bc, vp8_sub_mv_ref_prob2 [mv_contz]);
blockmode = sub_mv_ref(bc, cm->fc.sub_mv_ref_prob [mv_contz]);
#if CONFIG_ADAPTIVE_ENTROPY
cm->fc.sub_mv_ref_counts[mv_contz][blockmode-LEFT4X4]++;
#endif
switch (blockmode)
{
......@@ -812,10 +818,22 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
{
#if CONFIG_HIGH_PRECISION_MV
if (xd->allow_high_precision_mv)
{
read_mv_hp(bc, &secondmv.as_mv, (const MV_CONTEXT_HP *) mvc_hp);
#if CONFIG_ADAPTIVE_ENTROPY
cm->fc.MVcount_hp[0][mv_max_hp+(secondmv.as_mv.row)]++;
cm->fc.MVcount_hp[1][mv_max_hp+(secondmv.as_mv.col)]++;
#endif
}
else
#endif
{
read_mv(bc, &secondmv.as_mv, (const MV_CONTEXT *) mvc);
#if CONFIG_ADAPTIVE_ENTROPY
cm->fc.MVcount[0][mv_max+(secondmv.as_mv.row>>1)]++;
cm->fc.MVcount[1][mv_max+(secondmv.as_mv.col>>1)]++;
#endif
}
secondmv.as_mv.row += best_mv_second.as_mv.row;
secondmv.as_mv.col += best_mv_second.as_mv.col;
}
......@@ -843,9 +861,9 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
blockmv.as_int = 0;
if (mbmi->second_ref_frame)
secondmv.as_int = 0;
#ifdef VPX_MODE_COUNT
#ifdef VPX_MODE_COUNT
vp8_mv_cont_count[mv_contz][2]++;
#endif
#endif
break;
default:
break;
......@@ -959,11 +977,23 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
{
#if CONFIG_HIGH_PRECISION_MV
if (xd->allow_high_precision_mv)
{
read_mv_hp(bc, &mbmi->second_mv.as_mv,
(const MV_CONTEXT_HP *) mvc_hp);
#if CONFIG_ADAPTIVE_ENTROPY
cm->fc.MVcount_hp[0][mv_max_hp+(mbmi->second_mv.as_mv.row)]++;
cm->fc.MVcount_hp[1][mv_max_hp+(mbmi->second_mv.as_mv.col)]++;
#endif
}
else
#endif
read_mv(bc, &mbmi->second_mv.as_mv, (const MV_CONTEXT *) mvc);
{
read_mv(bc, &mbmi->second_mv.as_mv, (const MV_CONTEXT *) mvc);
#if CONFIG_ADAPTIVE_ENTROPY
cm->fc.MVcount[0][mv_max+(mbmi->second_mv.as_mv.row>>1)]++;
cm->fc.MVcount[1][mv_max+(mbmi->second_mv.as_mv.col>>1)]++;
#endif
}
mbmi->second_mv.as_mv.row += best_mv_second.as_mv.row;
mbmi->second_mv.as_mv.col += best_mv_second.as_mv.col;
mbmi->need_to_clamp_secondmv |= vp8_check_mv_bounds(&mbmi->second_mv,
......
......@@ -729,13 +729,13 @@ static void init_frame(VP8D_COMP *pbi)
pc->ref_frame_sign_bias[GOLDEN_FRAME] = 0;
pc->ref_frame_sign_bias[ALTREF_FRAME] = 0;
vp8_init_mode_contexts(&pbi->common);
vpx_memcpy(&pc->lfc, &pc->fc, sizeof(pc->fc));
vpx_memcpy(&pc->lfc_a, &pc->fc, sizeof(pc->fc));
vp8_init_mode_contexts(&pbi->common);
vpx_memcpy( pbi->common.vp8_mode_contexts,
pbi->common.mode_context,
sizeof(pbi->common.mode_context));
vpx_memcpy( pbi->common.fc.vp8_mode_contexts,
pbi->common.fc.mode_context,
sizeof(pbi->common.fc.mode_context));
}
else
{
......@@ -1331,16 +1331,16 @@ int vp8_decode_frame(VP8D_COMP *pbi)
if(pc->refresh_alt_ref_frame)
{
vpx_memcpy(&pc->fc, &pc->lfc_a, sizeof(pc->fc));
vpx_memcpy( pc->vp8_mode_contexts,
pc->mode_context_a,
sizeof(pc->vp8_mode_contexts));
vpx_memcpy( pc->fc.vp8_mode_contexts,
pc->fc.mode_context_a,
sizeof(pc->fc.vp8_mode_contexts));
}
else
{
vpx_memcpy(&pc->fc, &pc->lfc, sizeof(pc->fc));
vpx_memcpy( pc->vp8_mode_contexts,
pc->mode_context,
sizeof(pc->vp8_mode_contexts));
vpx_memcpy( pc->fc.vp8_mode_contexts,
pc->fc.mode_context,
sizeof(pc->fc.vp8_mode_contexts));
}
/* Buffer to buffer copy flags. */
......@@ -1436,6 +1436,8 @@ int vp8_decode_frame(VP8D_COMP *pbi)
vp8_copy(pbi->common.fc.pre_uv_mode_prob, pbi->common.fc.uv_mode_prob);
vp8_copy(pbi->common.fc.pre_bmode_prob, pbi->common.fc.bmode_prob);
vp8_copy(pbi->common.fc.pre_i8x8_mode_prob, pbi->common.fc.i8x8_mode_prob);
vp8_copy(pbi->common.fc.pre_sub_mv_ref_prob, pbi->common.fc.sub_mv_ref_prob);
vp8_copy(pbi->common.fc.pre_mbsplit_prob, pbi->common.fc.mbsplit_prob);
vp8_copy(pbi->common.fc.pre_mvc, pbi->common.fc.mvc);
#if CONFIG_HIGH_PRECISION_MV
vp8_copy(pbi->common.fc.pre_mvc_hp, pbi->common.fc.mvc_hp);
......@@ -1446,14 +1448,18 @@ int vp8_decode_frame(VP8D_COMP *pbi)
vp8_zero(pbi->common.fc.uv_mode_counts);
vp8_zero(pbi->common.fc.bmode_counts);
vp8_zero(pbi->common.fc.i8x8_mode_counts);
vp8_zero(pbi->common.fc.sub_mv_ref_counts);
vp8_zero(pbi->common.fc.mbsplit_counts);
vp8_zero(pbi->common.fc.MVcount);
#if CONFIG_HIGH_PRECISION_MV
vp8_zero(pbi->common.fc.MVcount_hp);
#endif
#endif
#if COEFUPDATETYPE == 2
vp8_zero(pbi->common.fc.mv_ref_ct);
vp8_zero(pbi->common.fc.mv_ref_ct_a);
#endif /* CONFIG_ADAPTIVE_ENTROPY */
#if CONFIG_NEWUPDATE && COEFUPDATETYPE == 2
read_coef_probs2(pbi);
#elif COEFUPDATETYPE == 3
#elif CONFIG_NEWUPDATE && COEFUPDATETYPE == 3
read_coef_probs3(pbi);
#else
read_coef_probs(pbi);
......@@ -1481,10 +1487,12 @@ int vp8_decode_frame(VP8D_COMP *pbi)
pc->mb_no_coeff_skip = (int)vp8_read_bit(bc);
vp8_decode_mode_mvs(pbi);
if(pbi->common.frame_type != KEY_FRAME)
#if CONFIG_ADAPTIVE_ENTROPY == 0
if (pc->frame_type != KEY_FRAME)
{
vp8_update_mode_context(&pbi->common);
}
#endif
vpx_memset(pc->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * pc->mb_cols);
......@@ -1521,6 +1529,7 @@ int vp8_decode_frame(VP8D_COMP *pbi)
{
vp8_adapt_mode_probs(pc);
vp8_adapt_mv_probs(pc);
vp8_update_mode_context(&pbi->common);
}
#endif
......
......@@ -300,10 +300,10 @@ static void write_bmode(vp8_writer *bc, int m, const vp8_prob *p)
vp8_write_token(bc, vp8_bmode_tree, p, vp8_bmode_encodings + m);
}
static void write_split(vp8_writer *bc, int x)
static void write_split(vp8_writer *bc, int x, const vp8_prob *p)
{
vp8_write_token(
bc, vp8_mbsplit_tree, vp8_mbsplit_probs, vp8_mbsplit_encodings + x
bc, vp8_mbsplit_tree, p, vp8_mbsplit_encodings + x
);
}
......@@ -856,7 +856,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
vp8_write_mvprobs_hp(cpi);
else
#endif
vp8_write_mvprobs(cpi);
vp8_write_mvprobs(cpi);
mb_row = 0;
for (row=0; row < pc->mb_rows; row += 2)
......@@ -1061,21 +1061,29 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
#if CONFIG_HIGH_PRECISION_MV
if (xd->allow_high_precision_mv)
{
write_mv_hp(w, &mi->mv.as_mv, &best_mv, mvc_hp);
}
else
#endif
write_mv(w, &mi->mv.as_mv, &best_mv, mvc);
{
write_mv(w, &mi->mv.as_mv, &best_mv, mvc);
}
if (mi->second_ref_frame)
{
#if CONFIG_HIGH_PRECISION_MV
if (xd->allow_high_precision_mv)
{
write_mv_hp(w, &mi->second_mv.as_mv,
&best_second_mv, mvc_hp);
}
else
#endif
write_mv(w, &mi->second_mv.as_mv,
{
write_mv(w, &mi->second_mv.as_mv,
&best_second_mv, mvc);
}
}
break;
case SPLITMV:
......@@ -1086,7 +1094,10 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
++count_mb_seg [mi->partitioning];
#endif
write_split(w, mi->partitioning);
write_split(w, mi->partitioning, cpi->common.fc.mbsplit_prob);
#if CONFIG_ADAPTIVE_ENTROPY
cpi->mbsplit_count[mi->partitioning]++;
#endif
do
{
......@@ -1112,8 +1123,10 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
mv_contz = vp8_mv_cont(&leftmv, &abovemv);
write_sub_mv_ref(w, blockmode,
vp8_sub_mv_ref_prob2 [mv_contz]);
cpi->common.fc.sub_mv_ref_prob [mv_contz]);
#if CONFIG_ADAPTIVE_ENTROPY
cpi->sub_mv_ref_count[mv_contz][blockmode-LEFT4X4]++;
#endif
if (blockmode == NEW4X4)
{
#ifdef ENTROPY_STATS
......@@ -1121,23 +1134,31 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
#endif
#if CONFIG_HIGH_PRECISION_MV
if (xd->allow_high_precision_mv)
{
write_mv_hp(w, &blockmv.as_mv, &best_mv,
(const MV_CONTEXT_HP *) mvc_hp);
}
else
#endif
write_mv(w, &blockmv.as_mv, &best_mv,
{
write_mv(w, &blockmv.as_mv, &best_mv,