Unified approach for backward probability update.
Replacing update_mode_probs() and adapt_probs() with tree_merge_probs(). Change-Id: I50b2c968d67c9265f5216c700cbeba25fb014654
This commit is contained in:
@@ -350,23 +350,15 @@ void vp9_entropy_mode_init() {
|
||||
#define COUNT_SAT 20
|
||||
#define MAX_UPDATE_FACTOR 128
|
||||
|
||||
static int update_ct(vp9_prob pre_prob, const unsigned int ct[2]) {
|
||||
static int adapt_prob(vp9_prob pre_prob, const unsigned int ct[2]) {
|
||||
return merge_probs(pre_prob, ct, COUNT_SAT, MAX_UPDATE_FACTOR);
|
||||
}
|
||||
|
||||
static void update_mode_probs(int n_modes,
|
||||
const vp9_tree_index *tree,
|
||||
const unsigned int *cnt,
|
||||
const vp9_prob *pre_probs, vp9_prob *dst_probs,
|
||||
unsigned int tok0_offset) {
|
||||
#define MAX_PROBS 32
|
||||
unsigned int branch_ct[MAX_PROBS][2];
|
||||
int t;
|
||||
|
||||
assert(n_modes - 1 < MAX_PROBS);
|
||||
vp9_tree_probs_from_distribution(tree, branch_ct, cnt, tok0_offset);
|
||||
for (t = 0; t < n_modes - 1; ++t)
|
||||
dst_probs[t] = update_ct(pre_probs[t], branch_ct[t]);
|
||||
static void adapt_probs(const vp9_tree_index *tree,
|
||||
const vp9_prob *pre_probs, const unsigned int *counts,
|
||||
unsigned int offset, vp9_prob *probs) {
|
||||
tree_merge_probs(tree, pre_probs, counts, offset,
|
||||
COUNT_SAT, MAX_UPDATE_FACTOR, probs);
|
||||
}
|
||||
|
||||
void vp9_adapt_mode_probs(VP9_COMMON *cm) {
|
||||
@@ -376,44 +368,40 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) {
|
||||
const FRAME_COUNTS *counts = &cm->counts;
|
||||
|
||||
for (i = 0; i < INTRA_INTER_CONTEXTS; i++)
|
||||
fc->intra_inter_prob[i] = update_ct(pre_fc->intra_inter_prob[i],
|
||||
counts->intra_inter[i]);
|
||||
fc->intra_inter_prob[i] = adapt_prob(pre_fc->intra_inter_prob[i],
|
||||
counts->intra_inter[i]);
|
||||
for (i = 0; i < COMP_INTER_CONTEXTS; i++)
|
||||
fc->comp_inter_prob[i] = update_ct(pre_fc->comp_inter_prob[i],
|
||||
counts->comp_inter[i]);
|
||||
fc->comp_inter_prob[i] = adapt_prob(pre_fc->comp_inter_prob[i],
|
||||
counts->comp_inter[i]);
|
||||
for (i = 0; i < REF_CONTEXTS; i++)
|
||||
fc->comp_ref_prob[i] = update_ct(pre_fc->comp_ref_prob[i],
|
||||
counts->comp_ref[i]);
|
||||
fc->comp_ref_prob[i] = adapt_prob(pre_fc->comp_ref_prob[i],
|
||||
counts->comp_ref[i]);
|
||||
for (i = 0; i < REF_CONTEXTS; i++)
|
||||
for (j = 0; j < 2; j++)
|
||||
fc->single_ref_prob[i][j] = update_ct(pre_fc->single_ref_prob[i][j],
|
||||
counts->single_ref[i][j]);
|
||||
fc->single_ref_prob[i][j] = adapt_prob(pre_fc->single_ref_prob[i][j],
|
||||
counts->single_ref[i][j]);
|
||||
|
||||
for (i = 0; i < INTER_MODE_CONTEXTS; i++)
|
||||
update_mode_probs(INTER_MODES, vp9_inter_mode_tree,
|
||||
counts->inter_mode[i], pre_fc->inter_mode_probs[i],
|
||||
fc->inter_mode_probs[i], NEARESTMV);
|
||||
adapt_probs(vp9_inter_mode_tree, pre_fc->inter_mode_probs[i],
|
||||
counts->inter_mode[i], NEARESTMV, fc->inter_mode_probs[i]);
|
||||
|
||||
for (i = 0; i < BLOCK_SIZE_GROUPS; i++)
|
||||
update_mode_probs(INTRA_MODES, vp9_intra_mode_tree,
|
||||
counts->y_mode[i], pre_fc->y_mode_prob[i],
|
||||
fc->y_mode_prob[i], 0);
|
||||
adapt_probs(vp9_intra_mode_tree, pre_fc->y_mode_prob[i],
|
||||
counts->y_mode[i], 0, fc->y_mode_prob[i]);
|
||||
|
||||
for (i = 0; i < INTRA_MODES; ++i)
|
||||
update_mode_probs(INTRA_MODES, vp9_intra_mode_tree,
|
||||
counts->uv_mode[i], pre_fc->uv_mode_prob[i],
|
||||
fc->uv_mode_prob[i], 0);
|
||||
adapt_probs(vp9_intra_mode_tree, pre_fc->uv_mode_prob[i],
|
||||
counts->uv_mode[i], 0, fc->uv_mode_prob[i]);
|
||||
|
||||
for (i = 0; i < PARTITION_CONTEXTS; i++)
|
||||
update_mode_probs(PARTITION_TYPES, vp9_partition_tree, counts->partition[i],
|
||||
pre_fc->partition_prob[i], fc->partition_prob[i], 0);
|
||||
adapt_probs(vp9_partition_tree, pre_fc->partition_prob[i],
|
||||
counts->partition[i], 0, fc->partition_prob[i]);
|
||||
|
||||
if (cm->mcomp_filter_type == SWITCHABLE) {
|
||||
for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
|
||||
update_mode_probs(SWITCHABLE_FILTERS, vp9_switchable_interp_tree,
|
||||
counts->switchable_interp[i],
|
||||
pre_fc->switchable_interp_prob[i],
|
||||
fc->switchable_interp_prob[i], 0);
|
||||
adapt_probs(vp9_switchable_interp_tree, pre_fc->switchable_interp_prob[i],
|
||||
counts->switchable_interp[i], 0,
|
||||
fc->switchable_interp_prob[i]);
|
||||
}
|
||||
|
||||
if (cm->tx_mode == TX_MODE_SELECT) {
|
||||
@@ -425,23 +413,24 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) {
|
||||
for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
|
||||
tx_counts_to_branch_counts_8x8(counts->tx.p8x8[i], branch_ct_8x8p);
|
||||
for (j = 0; j < TX_SIZES - 3; ++j)
|
||||
fc->tx_probs.p8x8[i][j] = update_ct(pre_fc->tx_probs.p8x8[i][j],
|
||||
branch_ct_8x8p[j]);
|
||||
fc->tx_probs.p8x8[i][j] = adapt_prob(pre_fc->tx_probs.p8x8[i][j],
|
||||
branch_ct_8x8p[j]);
|
||||
|
||||
tx_counts_to_branch_counts_16x16(counts->tx.p16x16[i], branch_ct_16x16p);
|
||||
for (j = 0; j < TX_SIZES - 2; ++j)
|
||||
fc->tx_probs.p16x16[i][j] = update_ct(pre_fc->tx_probs.p16x16[i][j],
|
||||
branch_ct_16x16p[j]);
|
||||
fc->tx_probs.p16x16[i][j] = adapt_prob(pre_fc->tx_probs.p16x16[i][j],
|
||||
branch_ct_16x16p[j]);
|
||||
|
||||
tx_counts_to_branch_counts_32x32(counts->tx.p32x32[i], branch_ct_32x32p);
|
||||
for (j = 0; j < TX_SIZES - 1; ++j)
|
||||
fc->tx_probs.p32x32[i][j] = update_ct(pre_fc->tx_probs.p32x32[i][j],
|
||||
branch_ct_32x32p[j]);
|
||||
fc->tx_probs.p32x32[i][j] = adapt_prob(pre_fc->tx_probs.p32x32[i][j],
|
||||
branch_ct_32x32p[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < MBSKIP_CONTEXTS; ++i)
|
||||
fc->mbskip_probs[i] = update_ct(pre_fc->mbskip_probs[i], counts->mbskip[i]);
|
||||
fc->mbskip_probs[i] = adapt_prob(pre_fc->mbskip_probs[i],
|
||||
counts->mbskip[i]);
|
||||
}
|
||||
|
||||
static void set_default_lf_deltas(struct loopfilter *lf) {
|
||||
|
||||
@@ -194,57 +194,44 @@ static vp9_prob adapt_prob(vp9_prob prep, const unsigned int ct[2]) {
|
||||
return merge_probs(prep, ct, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR);
|
||||
}
|
||||
|
||||
static unsigned int adapt_probs(unsigned int i,
|
||||
vp9_tree tree,
|
||||
vp9_prob this_probs[],
|
||||
const vp9_prob last_probs[],
|
||||
const unsigned int num_events[]) {
|
||||
const unsigned int left = tree[i] <= 0
|
||||
? num_events[-tree[i]]
|
||||
: adapt_probs(tree[i], tree, this_probs, last_probs, num_events);
|
||||
|
||||
const unsigned int right = tree[i + 1] <= 0
|
||||
? num_events[-tree[i + 1]]
|
||||
: adapt_probs(tree[i + 1], tree, this_probs, last_probs, num_events);
|
||||
const unsigned int ct[2] = { left, right };
|
||||
this_probs[i >> 1] = adapt_prob(last_probs[i >> 1], ct);
|
||||
return left + right;
|
||||
static void adapt_probs(const vp9_tree_index *tree, const vp9_prob *pre_probs,
|
||||
const unsigned int *counts, vp9_prob *probs) {
|
||||
tree_merge_probs(tree, pre_probs, counts, 0,
|
||||
MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR, probs);
|
||||
}
|
||||
|
||||
|
||||
void vp9_adapt_mv_probs(VP9_COMMON *cm, int allow_hp) {
|
||||
int i, j;
|
||||
|
||||
const FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx];
|
||||
nmv_context *fc = &cm->fc.nmvc;
|
||||
const nmv_context *pre_fc = &cm->frame_contexts[cm->frame_context_idx].nmvc;
|
||||
const nmv_context_counts *counts = &cm->counts.mv;
|
||||
|
||||
nmv_context *ctx = &cm->fc.nmvc;
|
||||
const nmv_context *pre_ctx = &pre_fc->nmvc;
|
||||
const nmv_context_counts *cts = &cm->counts.mv;
|
||||
|
||||
adapt_probs(0, vp9_mv_joint_tree, ctx->joints, pre_ctx->joints, cts->joints);
|
||||
adapt_probs(vp9_mv_joint_tree, pre_fc->joints, counts->joints,
|
||||
fc->joints);
|
||||
|
||||
for (i = 0; i < 2; ++i) {
|
||||
ctx->comps[i].sign = adapt_prob(pre_ctx->comps[i].sign, cts->comps[i].sign);
|
||||
adapt_probs(0, vp9_mv_class_tree, ctx->comps[i].classes,
|
||||
pre_ctx->comps[i].classes, cts->comps[i].classes);
|
||||
adapt_probs(0, vp9_mv_class0_tree, ctx->comps[i].class0,
|
||||
pre_ctx->comps[i].class0, cts->comps[i].class0);
|
||||
nmv_component *comp = &fc->comps[i];
|
||||
const nmv_component *pre_comp = &pre_fc->comps[i];
|
||||
const nmv_component_counts *c = &counts->comps[i];
|
||||
|
||||
comp->sign = adapt_prob(pre_comp->sign, c->sign);
|
||||
adapt_probs(vp9_mv_class_tree, pre_comp->classes, c->classes,
|
||||
comp->classes);
|
||||
adapt_probs(vp9_mv_class0_tree, pre_comp->class0, c->class0, comp->class0);
|
||||
|
||||
for (j = 0; j < MV_OFFSET_BITS; ++j)
|
||||
ctx->comps[i].bits[j] = adapt_prob(pre_ctx->comps[i].bits[j],
|
||||
cts->comps[i].bits[j]);
|
||||
comp->bits[j] = adapt_prob(pre_comp->bits[j], c->bits[j]);
|
||||
|
||||
for (j = 0; j < CLASS0_SIZE; ++j)
|
||||
adapt_probs(0, vp9_mv_fp_tree, ctx->comps[i].class0_fp[j],
|
||||
pre_ctx->comps[i].class0_fp[j], cts->comps[i].class0_fp[j]);
|
||||
adapt_probs(vp9_mv_fp_tree, pre_comp->class0_fp[j], c->class0_fp[j],
|
||||
comp->class0_fp[j]);
|
||||
|
||||
adapt_probs(0, vp9_mv_fp_tree, ctx->comps[i].fp, pre_ctx->comps[i].fp,
|
||||
cts->comps[i].fp);
|
||||
adapt_probs(vp9_mv_fp_tree, pre_comp->fp, c->fp, comp->fp);
|
||||
|
||||
if (allow_hp) {
|
||||
ctx->comps[i].class0_hp = adapt_prob(pre_ctx->comps[i].class0_hp,
|
||||
cts->comps[i].class0_hp);
|
||||
ctx->comps[i].hp = adapt_prob(pre_ctx->comps[i].hp, cts->comps[i].hp);
|
||||
comp->class0_hp = adapt_prob(pre_comp->class0_hp, c->class0_hp);
|
||||
comp->hp = adapt_prob(pre_comp->hp, c->hp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,5 +91,37 @@ static INLINE vp9_prob merge_probs(vp9_prob pre_prob,
|
||||
return weighted_prob(pre_prob, prob, factor);
|
||||
}
|
||||
|
||||
static unsigned int tree_merge_probs_impl(unsigned int i,
|
||||
const vp9_tree_index *tree,
|
||||
const vp9_prob *pre_probs,
|
||||
const unsigned int *counts,
|
||||
unsigned int count_sat,
|
||||
unsigned int max_update_factor,
|
||||
vp9_prob *probs) {
|
||||
const int l = tree[i];
|
||||
const unsigned int left_count = (l <= 0)
|
||||
? counts[-l]
|
||||
: tree_merge_probs_impl(l, tree, pre_probs, counts,
|
||||
count_sat, max_update_factor, probs);
|
||||
const int r = tree[i + 1];
|
||||
const unsigned int right_count = (r <= 0)
|
||||
? counts[-r]
|
||||
: tree_merge_probs_impl(r, tree, pre_probs, counts,
|
||||
count_sat, max_update_factor, probs);
|
||||
const unsigned int ct[2] = { left_count, right_count };
|
||||
probs[i >> 1] = merge_probs(pre_probs[i >> 1], ct,
|
||||
count_sat, max_update_factor);
|
||||
return left_count + right_count;
|
||||
}
|
||||
|
||||
static void tree_merge_probs(const vp9_tree_index *tree,
|
||||
const vp9_prob *pre_probs,
|
||||
const unsigned int *counts, int offset,
|
||||
unsigned int count_sat,
|
||||
unsigned int max_update_factor, vp9_prob *probs) {
|
||||
tree_merge_probs_impl(0, tree, pre_probs, &counts[-offset],
|
||||
count_sat, max_update_factor, probs);
|
||||
}
|
||||
|
||||
|
||||
#endif // VP9_COMMON_VP9_TREECODER_H_
|
||||
|
||||
Reference in New Issue
Block a user