ref: 8701bc11df3dc0b043eb9c80ff5c8d16e1d6d13d
parent: 18cb8bdd206596b6a18c2d6a0258dd54b008a7f6
author: Dmitry Kovalev <[email protected]>
date: Tue Jul 30 14:06:34 EDT 2013
Consistent update for inter_mode probabilities. Using inter-mode counts instead of inter-mode-tree branch counts inside FRAME_COUNTS structure. Change-Id: I60dde13af37d06146d7d15543311c1b5044e9e04
--- a/vp9/common/vp9_entropymode.c
+++ b/vp9/common/vp9_entropymode.c
@@ -356,29 +356,6 @@
vp9_inter_mode_tree, NEARESTMV);
}
-void vp9_accum_mv_refs(VP9_COMMON *pc,
- MB_PREDICTION_MODE m,
- const int context) {
- unsigned int (*inter_mode_counts)[VP9_INTER_MODES - 1][2] =
- pc->counts.inter_mode;
-
- if (m == ZEROMV) {
- ++inter_mode_counts[context][0][0];
- } else {
- ++inter_mode_counts[context][0][1];
- if (m == NEARESTMV) {
- ++inter_mode_counts[context][1][0];
- } else {
- ++inter_mode_counts[context][1][1];
- if (m == NEARMV) {
- ++inter_mode_counts[context][2][0];
- } else {
- ++inter_mode_counts[context][2][1];
- }
- }
- }
-}
-
#define COUNT_SAT 20
#define MAX_UPDATE_FACTOR 128
@@ -425,10 +402,11 @@
fc->single_ref_prob[i][j] = update_ct2(pre_fc->single_ref_prob[i][j],
counts->single_ref[i][j]);
- for (j = 0; j < INTER_MODE_CONTEXTS; j++)
- for (i = 0; i < VP9_INTER_MODES - 1; i++)
- fc->inter_mode_probs[j][i] = update_ct2(pre_fc->inter_mode_probs[j][i],
- counts->inter_mode[j][i]);
+ for (i = 0; i < INTER_MODE_CONTEXTS; i++)
+ update_mode_probs(VP9_INTER_MODES, vp9_inter_mode_tree,
+ counts->inter_mode[i], pre_fc->inter_mode_probs[i],
+ fc->inter_mode_probs[i], NEARESTMV);
+
for (i = 0; i < BLOCK_SIZE_GROUPS; i++)
update_mode_probs(VP9_INTRA_MODES, vp9_intra_mode_tree,
counts->y_mode[i], pre_fc->y_mode_prob[i],
--- a/vp9/common/vp9_entropymode.h
+++ b/vp9/common/vp9_entropymode.h
@@ -67,10 +67,6 @@
void vp9_adapt_mode_probs(struct VP9Common *);
-void vp9_accum_mv_refs(struct VP9Common *pc,
- MB_PREDICTION_MODE m,
- const int context);
-
void tx_counts_to_branch_counts_32x32(unsigned int *tx_count_32x32p,
unsigned int (*ct_32x32p)[2]);
void tx_counts_to_branch_counts_16x16(unsigned int *tx_count_16x16p,
--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -64,7 +64,7 @@
[COEF_BANDS][PREV_COEF_CONTEXTS];
unsigned int switchable_interp[VP9_SWITCHABLE_FILTERS + 1]
[VP9_SWITCHABLE_FILTERS];
- unsigned int inter_mode[INTER_MODE_CONTEXTS][VP9_INTER_MODES - 1][2];
+ unsigned int inter_mode[INTER_MODE_CONTEXTS][VP9_INTER_MODES];
unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
unsigned int single_ref[REF_CONTEXTS][2][2];
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -30,8 +30,12 @@
return (MB_PREDICTION_MODE)treed_read(r, vp9_intra_mode_tree, p);
}
-static MB_PREDICTION_MODE read_inter_mode(vp9_reader *r, const vp9_prob *p) {
- return (MB_PREDICTION_MODE)treed_read(r, vp9_inter_mode_tree, p);
+static MB_PREDICTION_MODE read_inter_mode(VP9_COMMON *cm, vp9_reader *r,
+ uint8_t context) {
+ MB_PREDICTION_MODE mode = treed_read(r, vp9_inter_mode_tree,
+ cm->fc.inter_mode_probs[context]);
+ ++cm->counts.inter_mode[context][inter_mode_offset(mode)];
+ return mode;
}
static int read_segment_id(vp9_reader *r, const struct segmentation *seg) {
@@ -446,7 +450,7 @@
int_mv nearest, nearby, best_mv;
int_mv nearest_second, nearby_second, best_mv_second;
- vp9_prob *mv_ref_p;
+ uint8_t inter_mode_ctx;
MV_REFERENCE_FRAME ref0, ref1;
read_ref_frames(pbi, r, mbmi->segment_id, mbmi->ref_frame);
@@ -456,14 +460,13 @@
vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context,
ref0, mbmi->ref_mvs[ref0], cm->ref_frame_sign_bias);
- mv_ref_p = cm->fc.inter_mode_probs[mbmi->mb_mode_context[ref0]];
+ inter_mode_ctx = mbmi->mb_mode_context[ref0];
- if (vp9_segfeature_active(&xd->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
+ if (vp9_segfeature_active(&xd->seg, mbmi->segment_id, SEG_LVL_SKIP))
mbmi->mode = ZEROMV;
- } else if (bsize >= BLOCK_SIZE_SB8X8) {
- mbmi->mode = read_inter_mode(r, mv_ref_p);
- vp9_accum_mv_refs(cm, mbmi->mode, mbmi->mb_mode_context[ref0]);
- }
+ else if (bsize >= BLOCK_SIZE_SB8X8)
+ mbmi->mode = read_inter_mode(cm, r, inter_mode_ctx);
+
mbmi->uv_mode = DC_PRED;
// nearest, nearby
@@ -495,10 +498,9 @@
for (idx = 0; idx < 2; idx += num_4x4_w) {
int_mv blockmv, secondmv;
const int j = idy * 2 + idx;
- const int blockmode = read_inter_mode(r, mv_ref_p);
+ const int b_mode = read_inter_mode(cm, r, inter_mode_ctx);
- vp9_accum_mv_refs(cm, blockmode, mbmi->mb_mode_context[ref0]);
- if (blockmode == NEARESTMV || blockmode == NEARMV) {
+ if (b_mode == NEARESTMV || b_mode == NEARMV) {
vp9_append_sub8x8_mvs_for_idx(cm, xd, &nearest, &nearby, j, 0);
if (ref1 > 0)
vp9_append_sub8x8_mvs_for_idx(cm, xd, &nearest_second,
@@ -505,7 +507,7 @@
&nearby_second, j, 1);
}
- switch (blockmode) {
+ switch (b_mode) {
case NEWMV:
read_mv(r, &blockmv.as_mv, &best_mv.as_mv, nmvc,
&cm->counts.mv, xd->allow_high_precision_mv);
@@ -540,7 +542,7 @@
mi->bmi[j + 2] = mi->bmi[j];
if (num_4x4_w == 2)
mi->bmi[j + 1] = mi->bmi[j];
- mi->mbmi.mode = blockmode;
+ mi->mbmi.mode = b_mode;
}
}
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -265,12 +265,17 @@
static void update_inter_mode_probs(VP9_COMMON *pc, vp9_writer* const bc) {
int i, j;
- for (i = 0; i < INTER_MODE_CONTEXTS; i++) {
- for (j = 0; j < VP9_INTER_MODES - 1; j++) {
+ for (i = 0; i < INTER_MODE_CONTEXTS; ++i) {
+ unsigned int branch_ct[VP9_INTER_MODES - 1][2];
+ vp9_prob new_prob[VP9_INTER_MODES - 1];
+
+ vp9_tree_probs_from_distribution(vp9_inter_mode_tree,
+ new_prob, branch_ct,
+ pc->counts.inter_mode[i], NEARESTMV);
+
+ for (j = 0; j < VP9_INTER_MODES - 1; ++j)
vp9_cond_prob_diff_update(bc, &pc->fc.inter_mode_probs[i][j],
- VP9_MODE_UPDATE_PROB,
- pc->counts.inter_mode[i][j]);
- }
+ VP9_MODE_UPDATE_PROB, branch_ct[j]);
}
}
@@ -468,7 +473,8 @@
if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) {
if (bsize >= BLOCK_SIZE_SB8X8) {
write_sb_mv_ref(bc, mode, mv_ref_p);
- vp9_accum_mv_refs(&cpi->common, mode, mi->mb_mode_context[rf]);
+ ++pc->counts.inter_mode[mi->mb_mode_context[rf]]
+ [inter_mode_offset(mode)];
}
}
@@ -494,7 +500,9 @@
blockmode = x->partition_info->bmi[j].mode;
blockmv = m->bmi[j].as_mv[0];
write_sb_mv_ref(bc, blockmode, mv_ref_p);
- vp9_accum_mv_refs(&cpi->common, blockmode, mi->mb_mode_context[rf]);
+ ++pc->counts.inter_mode[mi->mb_mode_context[rf]]
+ [inter_mode_offset(blockmode)];
+
if (blockmode == NEWMV) {
#ifdef ENTROPY_STATS
active_section = 11;