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 */
......
This diff is collapsed.
......@@ -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,
(const MV_CONTEXT *) mvc);
}
if (mi->second_ref_frame)
{
#if CONFIG_HIGH_PRECISION_MV
if (xd->allow_high_precision_mv)
{
write_mv_hp(w, &cpi->mb.partition_info->bmi[j].second_mv.as_mv,
&best_second_mv, (const MV_CONTEXT_HP *) mvc_hp);
}
else
#endif
{
write_mv(w, &cpi->mb.partition_info->bmi[j].second_mv.as_mv,
&best_second_mv, (const MV_CONTEXT *) mvc);
}
}
}
}
......@@ -2229,8 +2250,6 @@ static void segment_reference_frames(VP8_COMP *cpi)
enable_segfeature(xd,i,SEG_LVL_REF_FRAME);
set_segdata( xd,i, SEG_LVL_REF_FRAME, ref[i]);
}
}
void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
......@@ -2628,15 +2647,21 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
vp8_copy(cpi->common.fc.pre_ymode_prob, cpi->common.fc.ymode_prob);
vp8_copy(cpi->common.fc.pre_uv_mode_prob, cpi->common.fc.uv_mode_prob);
vp8_copy(cpi->common.fc.pre_bmode_prob, cpi->common.fc.bmode_prob);
vp8_copy(cpi->common.fc.pre_sub_mv_ref_prob, cpi->common.fc.sub_mv_ref_prob);
vp8_copy(cpi->common.fc.pre_mbsplit_prob, cpi->common.fc.mbsplit_prob);
vp8_copy(cpi->common.fc.pre_i8x8_mode_prob, cpi->common.fc.i8x8_mode_prob);
vp8_copy(cpi->common.fc.pre_mvc, cpi->common.fc.mvc);
#if CONFIG_HIGH_PRECISION_MV
vp8_copy(cpi->common.fc.pre_mvc_hp, cpi->common.fc.mvc_hp);
#endif
vp8_zero(cpi->sub_mv_ref_count);
vp8_zero(cpi->mbsplit_count);
vp8_zero(cpi->common.fc.mv_ref_ct)
vp8_zero(cpi->common.fc.mv_ref_ct_a)
#endif
#if COEFUPDATETYPE == 2
#if CONFIG_NEWUPDATE && COEFUPDATETYPE == 2
update_coef_probs2(cpi);
#elif COEFUPDATETYPE == 3
#elif CONFIG_NEWUPDATE && COEFUPDATETYPE == 3
update_coef_probs3(cpi);
#else
update_coef_probs(cpi);
......@@ -2661,8 +2686,9 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
else
{
pack_inter_mode_mvs(cpi);
#if CONFIG_ADAPTIVE_ENTROPY == 0
vp8_update_mode_context(&cpi->common);
#endif
#ifdef ENTROPY_STATS
active_section = 1;
......
......@@ -72,6 +72,7 @@ typedef struct
MODE_INFO mic;
PARTITION_INFO partition_info;
int_mv best_ref_mv;
int_mv second_best_ref_mv;
int rate;
int distortion;
int intra_error;
......
......@@ -458,7 +458,7 @@ static void update_state (VP8_COMP *cpi, MACROBLOCK *x, PICK_MODE_CONTEXT *ctx)
// Note how often each mode chosen as best
cpi->mode_chosen_counts[mb_mode_index]++;
rd_update_mvcount(cpi, x, &ctx->best_ref_mv);
rd_update_mvcount(cpi, x, &ctx->best_ref_mv, &ctx->second_best_ref_mv);
cpi->prediction_error += ctx->distortion;
cpi->intra_error += ctx->intra_error;
......@@ -1068,6 +1068,12 @@ void init_encode_frame_mb_context(VP8_COMP *cpi)
vp8_zero(cpi->ymode_count)
vp8_zero(cpi->i8x8_mode_count)
vp8_zero(cpi->y_uv_mode_count)
vp8_zero(cpi->sub_mv_ref_count)
vp8_zero(cpi->mbsplit_count)
#if CONFIG_ADAPTIVE_ENTROPY
vp8_zero(cpi->common.fc.mv_ref_ct)
vp8_zero(cpi->common.fc.mv_ref_ct_a)
#endif
//vp8_zero(cpi->uv_mode_count)
x->mvc = cm->fc.mvc;
......
......@@ -37,8 +37,14 @@ void vp8_init_mode_costs(VP8_COMP *c)
vp8_cost_tokens((int *)c->mb.inter_bmode_costs, x->fc.bmode_prob, T);
}
#if CONFIG_ADAPTIVE_ENTROPY
vp8_cost_tokens((int *)c->mb.inter_bmode_costs,
x->fc.sub_mv_ref_prob, vp8_sub_mv_ref_tree);
vp8_sub_mv_ref_prob, vp8_sub_mv_ref_tree);
//x->fc.sub_mv_ref_prob[1], vp8_sub_mv_ref_tree);
#else
vp8_cost_tokens((int *)c->mb.inter_bmode_costs,
vp8_sub_mv_ref_prob, vp8_sub_mv_ref_tree);
#endif
vp8_cost_tokens(c->mb.mbmode_cost[1], x->fc.ymode_prob, vp8_ymode_tree);
vp8_cost_tokens(c->mb.mbmode_cost[0],
......@@ -48,6 +54,7 @@ void vp8_init_mode_costs(VP8_COMP *c)
x->fc.uv_mode_prob[VP8_YMODES-1], vp8_uv_mode_tree);
vp8_cost_tokens(c->mb.intra_uv_mode_cost[0],
x->kf_uv_mode_prob[VP8_YMODES-1], vp8_uv_mode_tree);
vp8_cost_tokens((int *)c->mb.i8x8_mode_costs,
vp8_cost_tokens(c->mb.i8x8_mode_costs,
x->fc.i8x8_mode_prob,vp8_i8x8_mode_tree);
}
......@@ -3702,6 +3702,8 @@ static void encode_frame_to_data_rate
vp8_copy(cpi->common.fc.uv_mode_counts, cpi->y_uv_mode_count);
vp8_copy(cpi->common.fc.bmode_counts, cpi->bmode_count);
vp8_copy(cpi->common.fc.i8x8_mode_counts, cpi->i8x8_mode_count);
vp8_copy(cpi->common.fc.sub_mv_ref_counts, cpi->sub_mv_ref_count);
vp8_copy(cpi->common.fc.mbsplit_counts, cpi->mbsplit_count);
vp8_adapt_mode_probs(&cpi->common);
vp8_copy(cpi->common.fc.MVcount, cpi->MVcount);
......@@ -3709,6 +3711,7 @@ static void encode_frame_to_data_rate
vp8_copy(cpi->common.fc.MVcount_hp, cpi->MVcount_hp);
#endif
vp8_adapt_mv_probs(&cpi->common);
vp8_update_mode_context(&cpi->common);
}
#endif /* CONFIG_ADAPTIVE_ENTROPY */
......@@ -3809,7 +3812,7 @@ static void encode_frame_to_data_rate
// in this frame.
update_base_skip_probs( cpi );
#if 1 && CONFIG_INTERNAL_STATS
#if 0//1 && CONFIG_INTERNAL_STATS
{
FILE *f = fopen("tmp.stt", "a");
int recon_err;
......
......@@ -23,6 +23,7 @@
#include "encodemb.h"
#include "quantize.h"
#include "vp8/common/entropy.h"
#include "vp8/common/entropymode.h"
#include "vpx_ports/mem.h"
#include "vpx/internal/vpx_codec_internal.h"
#include "mcomp.h"
......@@ -99,6 +100,8 @@ typedef struct
vp8_prob uv_mode_prob [VP8_YMODES][VP8_UV_MODES-1];
vp8_prob bmode_prob [VP8_BINTRAMODES-1];
vp8_prob i8x8_mode_prob [VP8_I8X8_MODES-1];
vp8_prob sub_mv_ref_prob [SUBMVREF_COUNT][VP8_SUBMVREFS-1];
vp8_prob mbsplit_prob [VP8_NUMMBSPLITS-1];
int mv_ref_ct[6][4][2];
int mode_context[6][4];
......@@ -458,7 +461,10 @@ typedef struct VP8_COMP
int ymode_count [VP8_YMODES]; /* intra MB type cts this frame */
int bmode_count [VP8_BINTRAMODES];
int i8x8_mode_count [VP8_I8X8_MODES];
int sub_mv_ref_count [SUBMVREF_COUNT][VP8_SUBMVREFS];
int mbsplit_count [VP8_NUMMBSPLITS];
//int uv_mode_count[VP8_UV_MODES]; /* intra MB type cts this frame */
int y_uv_mode_count[VP8_YMODES][VP8_UV_MODES];
unsigned int MVcount [2] [MVvals]; /* (row,col) MV cts this frame */
#if CONFIG_HIGH_PRECISION_MV
......@@ -542,7 +548,6 @@ typedef struct VP8_COMP
int t4x4_count;
int t8x8_count;
int y_uv_mode_count[VP8_YMODES][VP8_UV_MODES];
unsigned char *segmentation_map;
// segment threashold for encode breakout
......
......@@ -150,15 +150,17 @@ void vp8_save_coding_context(VP8_COMP *cpi)
vp8_copy(cc->mvcosts_hp, cpi->mb.mvcosts_hp);
#endif
vp8_copy( cc->mv_ref_ct, cm->mv_ref_ct );
vp8_copy( cc->mode_context, cm->mode_context );
vp8_copy( cc->mv_ref_ct_a, cm->mv_ref_ct_a );
vp8_copy( cc->mode_context_a, cm->mode_context_a );
vp8_copy( cc->mv_ref_ct, cm->fc.mv_ref_ct );
vp8_copy( cc->mode_context, cm->fc.mode_context );
vp8_copy( cc->mv_ref_ct_a, cm->fc.mv_ref_ct_a );
vp8_copy( cc->mode_context_a, cm->fc.mode_context_a );
vp8_copy( cc->ymode_prob, cm->fc.ymode_prob );
vp8_copy( cc->bmode_prob, cm->fc.bmode_prob );
vp8_copy( cc->uv_mode_prob, cm->fc.uv_mode_prob );
vp8_copy( cc->i8x8_mode_prob, cm->fc.i8x8_mode_prob );
vp8_copy( cc->sub_mv_ref_prob, cm->fc.sub_mv_ref_prob );
vp8_copy( cc->mbsplit_prob, cm->fc.mbsplit_prob );
// Stats
#ifdef MODE_STATS
......@@ -201,15 +203,17 @@ void vp8_restore_coding_context(VP8_COMP *cpi)
vp8_copy(cpi->mb.mvcosts_hp, cc->mvcosts_hp);
#endif
vp8_copy( cm->mv_ref_ct, cc->mv_ref_ct );
vp8_copy( cm->mode_context, cc->mode_context );
vp8_copy( cm->mv_ref_ct_a, cc->mv_ref_ct_a );
vp8_copy( cm->mode_context_a, cc->mode_context_a );
vp8_copy( cm->fc.mv_ref_ct, cc->mv_ref_ct );
vp8_copy( cm->fc.mode_context, cc->mode_context );
vp8_copy( cm->fc.mv_ref_ct_a, cc->mv_ref_ct_a );
vp8_copy( cm->fc.mode_context_a, cc->mode_context_a );
vp8_copy( cm->fc.ymode_prob, cc->ymode_prob);
vp8_copy( cm->fc.bmode_prob, cc->bmode_prob);
vp8_copy( cm->fc.i8x8_mode_prob, cc->i8x8_mode_prob);
vp8_copy( cm->fc.uv_mode_prob, cc->uv_mode_prob);
vp8_copy( cm->fc.sub_mv_ref_prob, cc->sub_mv_ref_prob);
vp8_copy( cm->fc.mbsplit_prob, cc->mbsplit_prob );
// Stats
#ifdef MODE_STATS
......@@ -271,14 +275,16 @@ void vp8_setup_key_frame(VP8_COMP *cpi)
cpi->common.refresh_golden_frame = TRUE;
cpi->common.refresh_alt_ref_frame = TRUE;
vp8_init_mode_contexts(&cpi->common);
vpx_memcpy(&cpi->common.lfc, &cpi->common.fc, sizeof(cpi->common.fc));
vpx_memcpy(&cpi->common.lfc_a, &cpi->common.fc, sizeof(cpi->common.fc));
vp8_init_mode_contexts(&cpi->common);
vpx_memcpy( cpi->common.vp8_mode_contexts,
cpi->common.mode_context,
sizeof(cpi->common.mode_context));
vpx_memcpy( cpi->common.vp8_mode_contexts,
/*
vpx_memcpy( cpi->common.fc.vp8_mode_contexts,
cpi->common.fc.mode_context,
sizeof(cpi->common.fc.mode_context));
*/
vpx_memcpy( cpi->common.fc.vp8_mode_contexts,
default_vp8_mode_contexts,
sizeof(default_vp8_mode_contexts));
......@@ -293,18 +299,18 @@ void vp8_setup_inter_frame(VP8_COMP *cpi)
vpx_memcpy( &cpi->common.fc,
&cpi->common.lfc_a,
sizeof(cpi->common.fc));
vpx_memcpy( cpi->common.vp8_mode_contexts,
cpi->common.mode_context_a,
sizeof(cpi->common.vp8_mode_contexts));
vpx_memcpy( cpi->common.fc.vp8_mode_contexts,
cpi->common.fc.mode_context_a,
sizeof(cpi->common.fc.vp8_mode_contexts));
}
else
{
vpx_memcpy( &cpi->common.fc,
&cpi->common.lfc,
sizeof(cpi->common.fc));
vpx_memcpy( cpi->common.vp8_mode_contexts,
cpi->common.mode_context,
sizeof(cpi->common.vp8_mode_contexts));
vpx_memcpy( cpi->common.fc.vp8_mode_contexts,
cpi->common.fc.mode_context,
sizeof(cpi->common.fc.vp8_mode_contexts));
}
}
......
......@@ -2502,7 +2502,8 @@ void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse
}
}
void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv)
void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x,
int_mv *best_ref_mv, int_mv *second_best_ref_mv)
{
if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV)
{
......@@ -2519,6 +2520,15 @@ void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv)
- best_ref_mv->as_mv.row)]++;
cpi->MVcount_hp[1][mv_max_hp+(x->partition_info->bmi[i].mv.as_mv.col
- best_ref_mv->as_mv.col)]++;
#if CONFIG_ADAPTIVE_ENTROPY
if (x->e_mbd.mode_info_context->mbmi.second_ref_frame)
{
cpi->MVcount_hp[0][mv_max_hp+(x->partition_info->bmi[i].second_mv.as_mv.row
- second_best_ref_mv->as_mv.row)]++;
cpi->MVcount_hp[1][mv_max_hp+(x->partition_info->bmi[i].second_mv.as_mv.col
- second_best_ref_mv->as_mv.col)]++;
}
#endif
}
else
#endif
......@@ -2527,6 +2537,15 @@ void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv)
- best_ref_mv->as_mv.row) >> 1)]++;
cpi->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col
- best_ref_mv->as_mv.col) >> 1)]++;
#if CONFIG_ADAPTIVE_ENTROPY
if (x->e_mbd.mode_info_context->mbmi.second_ref_frame)
{