From 83885235a7398045302a62f9afccd0c4b27324ab Mon Sep 17 00:00:00 2001 From: Deb Mukherjee Date: Tue, 4 Jun 2013 15:25:16 -0700 Subject: [PATCH] Clean-ups on switchable interpolation and mv_ref Adds backward adaptation and differential forward updates of switchable interpolation filter probabilities. Also adds some cosmetic cleanups and minor fixes on mv_ref probabilities. derfraw300: +0.353% (with most coming from switchable interp changes) Change-Id: Ie2718be73528c945fd0d80cfd63ca2d9cb3032de --- vp9/common/vp9_coefupdateprobs.h | 2 + vp9/common/vp9_entropymode.c | 50 ++++++++----- vp9/common/vp9_findnearmv.c | 6 +- vp9/common/vp9_modecont.c | 3 +- vp9/common/vp9_modecont.h | 3 +- vp9/common/vp9_onyxc_int.h | 11 ++- vp9/decoder/vp9_decodemv.c | 34 +++++++-- vp9/decoder/vp9_decodframe.c | 18 ++--- vp9/decoder/vp9_decodframe.h | 1 + vp9/encoder/vp9_bitstream.c | 153 +++++++++++++++++---------------------- vp9/encoder/vp9_encodeframe.c | 6 +- vp9/encoder/vp9_onyx_if.c | 9 ++- vp9/encoder/vp9_onyx_int.h | 4 +- vp9/encoder/vp9_ratectrl.c | 4 +- 14 files changed, 164 insertions(+), 140 deletions(-) diff --git a/vp9/common/vp9_coefupdateprobs.h b/vp9/common/vp9_coefupdateprobs.h index e862008..ce35634 100644 --- a/vp9/common/vp9_coefupdateprobs.h +++ b/vp9/common/vp9_coefupdateprobs.h @@ -14,6 +14,8 @@ /* Update probabilities for the nodes in the token entropy tree. Generated file included by vp9_entropy.c */ +#define VP9_DEF_UPDATE_PROB 252 + static const vp9_prob vp9_coef_update_prob[UNCONSTRAINED_NODES] = { 252, 252, 252, }; diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c index 0274b4d..516e82a 100644 --- a/vp9/common/vp9_entropymode.c +++ b/vp9/common/vp9_entropymode.c @@ -169,29 +169,30 @@ void vp9_entropy_mode_init() { } void vp9_init_mode_contexts(VP9_COMMON *pc) { - vpx_memset(pc->fc.mv_ref_ct, 0, sizeof(pc->fc.mv_ref_ct)); - vpx_memcpy(pc->fc.vp9_mode_contexts, - vp9_default_mode_contexts, - sizeof(vp9_default_mode_contexts)); + vpx_memset(pc->fc.inter_mode_counts, 0, sizeof(pc->fc.inter_mode_counts)); + vpx_memcpy(pc->fc.inter_mode_probs, + vp9_default_inter_mode_probs, + sizeof(vp9_default_inter_mode_probs)); } void vp9_accum_mv_refs(VP9_COMMON *pc, MB_PREDICTION_MODE m, const int context) { - unsigned int (*mv_ref_ct)[VP9_MVREFS - 1][2] = pc->fc.mv_ref_ct; + unsigned int (*inter_mode_counts)[VP9_MVREFS - 1][2] = + pc->fc.inter_mode_counts; if (m == ZEROMV) { - ++mv_ref_ct[context][0][0]; + ++inter_mode_counts[context][0][0]; } else { - ++mv_ref_ct[context][0][1]; + ++inter_mode_counts[context][0][1]; if (m == NEARESTMV) { - ++mv_ref_ct[context][1][0]; + ++inter_mode_counts[context][1][0]; } else { - ++mv_ref_ct[context][1][1]; + ++inter_mode_counts[context][1][1]; if (m == NEARMV) { - ++mv_ref_ct[context][2][0]; + ++inter_mode_counts[context][2][0]; } else { - ++mv_ref_ct[context][2][1]; + ++inter_mode_counts[context][2][1]; } } } @@ -201,19 +202,21 @@ void vp9_accum_mv_refs(VP9_COMMON *pc, #define MVREF_MAX_UPDATE_FACTOR 128 void vp9_adapt_mode_context(VP9_COMMON *pc) { int i, j; - unsigned int (*mv_ref_ct)[VP9_MVREFS - 1][2] = pc->fc.mv_ref_ct; - int (*mode_context)[VP9_MVREFS - 1] = pc->fc.vp9_mode_contexts; + unsigned int (*inter_mode_counts)[VP9_MVREFS - 1][2] = + pc->fc.inter_mode_counts; + vp9_prob (*mode_context)[VP9_MVREFS - 1] = pc->fc.inter_mode_probs; for (j = 0; j < INTER_MODE_CONTEXTS; j++) { for (i = 0; i < VP9_MVREFS - 1; i++) { - int count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1], factor; - + int count = inter_mode_counts[j][i][0] + inter_mode_counts[j][i][1]; + int factor; count = count > MVREF_COUNT_SAT ? MVREF_COUNT_SAT : count; factor = (MVREF_MAX_UPDATE_FACTOR * count / MVREF_COUNT_SAT); - mode_context[j][i] = weighted_prob(pc->fc.vp9_mode_contexts[j][i], - get_binary_prob(mv_ref_ct[j][i][0], - mv_ref_ct[j][i][1]), - factor); + mode_context[j][i] = weighted_prob( + pc->fc.pre_inter_mode_probs[j][i], + get_binary_prob(inter_mode_counts[j][i][0], + inter_mode_counts[j][i][1]), + factor); } } } @@ -290,6 +293,15 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) { update_mode_probs(PARTITION_TYPES, vp9_partition_tree, fc->partition_counts[i], fc->pre_partition_prob[i], fc->partition_prob[i], 0); + + if (cm->mcomp_filter_type == SWITCHABLE) { + for (i = 0; i <= VP9_SWITCHABLE_FILTERS; i++) { + update_mode_probs(VP9_SWITCHABLE_FILTERS, vp9_switchable_interp_tree, + fc->switchable_interp_count[i], + fc->pre_switchable_interp_prob[i], + fc->switchable_interp_prob[i], 0); + } + } } static void set_default_lf_deltas(MACROBLOCKD *xd) { diff --git a/vp9/common/vp9_findnearmv.c b/vp9/common/vp9_findnearmv.c index 9df6ce1..e3a46f2 100644 --- a/vp9/common/vp9_findnearmv.c +++ b/vp9/common/vp9_findnearmv.c @@ -25,9 +25,9 @@ static void lower_mv_precision(int_mv *mv, int usehp) { } vp9_prob *vp9_mv_ref_probs(VP9_COMMON *pc, vp9_prob *p, int context) { - p[0] = pc->fc.vp9_mode_contexts[context][0]; - p[1] = pc->fc.vp9_mode_contexts[context][1]; - p[2] = pc->fc.vp9_mode_contexts[context][2]; + p[0] = pc->fc.inter_mode_probs[context][0]; + p[1] = pc->fc.inter_mode_probs[context][1]; + p[2] = pc->fc.inter_mode_probs[context][2]; return p; } diff --git a/vp9/common/vp9_modecont.c b/vp9/common/vp9_modecont.c index 973bb06..2aaeaff 100644 --- a/vp9/common/vp9_modecont.c +++ b/vp9/common/vp9_modecont.c @@ -11,7 +11,8 @@ #include "vp9/common/vp9_entropy.h" -const int vp9_default_mode_contexts[INTER_MODE_CONTEXTS][VP9_MVREFS - 1] = { +const vp9_prob vp9_default_inter_mode_probs[INTER_MODE_CONTEXTS] + [VP9_MVREFS - 1] = { {2, 173, 34}, // 0 = both zero mv {7, 145, 85}, // 1 = one zero mv + one a predicted mv {7, 166, 63}, // 2 = two predicted mvs diff --git a/vp9/common/vp9_modecont.h b/vp9/common/vp9_modecont.h index a6c4893..7a6b359 100644 --- a/vp9/common/vp9_modecont.h +++ b/vp9/common/vp9_modecont.h @@ -13,6 +13,7 @@ #include "vp9/common/vp9_entropy.h" -extern const int vp9_default_mode_contexts[INTER_MODE_CONTEXTS][VP9_MVREFS - 1]; +extern const int vp9_default_inter_mode_probs[INTER_MODE_CONTEXTS] + [VP9_MVREFS - 1]; #endif // VP9_COMMON_VP9_MODECONT_H_ diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h index cbe010a..91b6bf0 100644 --- a/vp9/common/vp9_onyxc_int.h +++ b/vp9/common/vp9_onyxc_int.h @@ -71,9 +71,14 @@ typedef struct frame_contexts { nmv_context_counts NMVcount; vp9_prob switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1] [VP9_SWITCHABLE_FILTERS - 1]; - - int vp9_mode_contexts[INTER_MODE_CONTEXTS][VP9_MVREFS - 1]; - unsigned int mv_ref_ct[INTER_MODE_CONTEXTS][VP9_MVREFS - 1][2]; + vp9_prob pre_switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1] + [VP9_SWITCHABLE_FILTERS - 1]; + unsigned int switchable_interp_count[VP9_SWITCHABLE_FILTERS + 1] + [VP9_SWITCHABLE_FILTERS]; + + vp9_prob inter_mode_probs[INTER_MODE_CONTEXTS][VP9_MVREFS - 1]; + vp9_prob pre_inter_mode_probs[INTER_MODE_CONTEXTS][VP9_MVREFS - 1]; + unsigned int inter_mode_counts[INTER_MODE_CONTEXTS][VP9_MVREFS - 1][2]; } FRAME_CONTEXT; typedef enum { diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index efd852b..d91a319 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -20,6 +20,7 @@ #include "vp9/common/vp9_pred_common.h" #include "vp9/common/vp9_entropy.h" #include "vp9/decoder/vp9_decodemv.h" +#include "vp9/decoder/vp9_decodframe.h" #include "vp9/common/vp9_mvref_common.h" #if CONFIG_DEBUG #include @@ -344,12 +345,28 @@ unsigned int vp9_mv_cont_count[5][4] = { }; #endif -static void read_switchable_interp_probs(VP9D_COMP* const pbi, vp9_reader *r) { - VP9_COMMON *const cm = &pbi->common; +static void read_switchable_interp_probs(VP9_COMMON* const cm, vp9_reader *r) { int i, j; - for (j = 0; j < VP9_SWITCHABLE_FILTERS + 1; ++j) - for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) - cm->fc.switchable_interp_prob[j][i] = vp9_read_prob(r); + for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j) + for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) { + if (vp9_read(r, VP9_DEF_UPDATE_PROB)) { + cm->fc.switchable_interp_prob[j][i] = + // vp9_read_prob(r); + vp9_read_prob_diff_update(r, cm->fc.switchable_interp_prob[j][i]); + } + } +} + +static void read_inter_mode_probs(VP9_COMMON *const cm, vp9_reader *r) { + int i, j; + for (i = 0; i < INTER_MODE_CONTEXTS; ++i) + for (j = 0; j < VP9_MVREFS - 1; ++j) { + if (vp9_read(r, VP9_DEF_UPDATE_PROB)) { + // cm->fc.inter_mode_probs[i][j] = vp9_read_prob(r); + cm->fc.inter_mode_probs[i][j] = + vp9_read_prob_diff_update(r, cm->fc.inter_mode_probs[i][j]); + } + } } static INLINE COMPPREDMODE_TYPE read_comp_pred_mode(vp9_reader *r) { @@ -367,8 +384,10 @@ static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *r) { MACROBLOCKD *const xd = &pbi->mb; int i, j; + read_inter_mode_probs(cm, r); + if (cm->mcomp_filter_type == SWITCHABLE) - read_switchable_interp_probs(pbi, r); + read_switchable_interp_probs(cm, r); // Baseline probabilities for decoding reference frame cm->prob_intra_coded = vp9_read_prob(r); @@ -474,6 +493,9 @@ static INLINE INTERPOLATIONFILTERTYPE read_switchable_filter_type( const int index = treed_read(r, vp9_switchable_interp_tree, vp9_get_pred_probs(&pbi->common, &pbi->mb, PRED_SWITCHABLE_INTERP)); + ++pbi->common.fc.switchable_interp_count + [vp9_get_pred_context( + &pbi->common, &pbi->mb, PRED_SWITCHABLE_INTERP)][index]; return vp9_switchable_interp[index]; } diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c index 5c03061..45b0c63 100644 --- a/vp9/decoder/vp9_decodframe.c +++ b/vp9/decoder/vp9_decodframe.c @@ -153,7 +153,7 @@ static int inv_remap_prob(int v, int m) { } } -static vp9_prob read_prob_diff_update(vp9_reader *r, int oldp) { +vp9_prob vp9_read_prob_diff_update(vp9_reader *r, int oldp) { int delp = decode_term_subexp(r, SUBEXP_PARAM, 255); return (vp9_prob)inv_remap_prob(delp, oldp); } @@ -569,7 +569,7 @@ static void read_coef_probs_common(FRAME_CONTEXT *fc, TX_SIZE tx_size, vp9_prob *const p = coef_probs[i][j][k][l] + m; if (vp9_read(r, vp9_coef_update_prob[m])) { - *p = read_prob_diff_update(r, *p); + *p = vp9_read_prob_diff_update(r, *p); } } } @@ -784,14 +784,19 @@ static void update_frame_context(FRAME_CONTEXT *fc) { vp9_copy(fc->pre_uv_mode_prob, fc->uv_mode_prob); vp9_copy(fc->pre_partition_prob, fc->partition_prob); fc->pre_nmvc = fc->nmvc; + vp9_copy(fc->pre_switchable_interp_prob, + fc->switchable_interp_prob); + vp9_copy(fc->pre_inter_mode_probs, + fc->inter_mode_probs); vp9_zero(fc->coef_counts); vp9_zero(fc->eob_branch_counts); vp9_zero(fc->y_mode_counts); vp9_zero(fc->uv_mode_counts); vp9_zero(fc->NMVcount); - vp9_zero(fc->mv_ref_ct); + vp9_zero(fc->inter_mode_counts); vp9_zero(fc->partition_counts); + vp9_zero(fc->switchable_interp_count); } static void decode_tile(VP9D_COMP *pbi, vp9_reader *r) { @@ -1043,13 +1048,6 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) { setup_txfm_mode(pc, xd->lossless, &header_bc); // Read inter mode probability context updates - if (!keyframe) { - int i, j; - for (i = 0; i < INTER_MODE_CONTEXTS; ++i) - for (j = 0; j < VP9_MVREFS - 1; ++j) - if (vp9_read(&header_bc, 252)) - pc->fc.vp9_mode_contexts[i][j] = vp9_read_prob(&header_bc); - } update_frame_context(&pc->fc); diff --git a/vp9/decoder/vp9_decodframe.h b/vp9/decoder/vp9_decodframe.h index 00b6d67..66e951d 100644 --- a/vp9/decoder/vp9_decodframe.h +++ b/vp9/decoder/vp9_decodframe.h @@ -17,5 +17,6 @@ struct VP9Decompressor; void vp9_init_dequantizer(struct VP9Common *pc); int vp9_decode_frame(struct VP9Decompressor *cpi, const uint8_t **p_data_end); +vp9_prob vp9_read_prob_diff_update(vp9_reader *r, int oldp); #endif // VP9_DECODER_VP9_DECODFRAME_H_ diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 043ac6a..2f6d4ad 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -259,24 +259,6 @@ void vp9_update_skip_probs(VP9_COMP *cpi) { cpi->skip_true_count[k]); } -static void update_switchable_interp_probs(VP9_COMP *cpi, - vp9_writer* const bc) { - VP9_COMMON *const pc = &cpi->common; - unsigned int branch_ct[32][2]; - int i, j; - for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j) { - vp9_tree_probs_from_distribution( - vp9_switchable_interp_tree, - pc->fc.switchable_interp_prob[j], branch_ct, - cpi->switchable_interp_count[j], 0); - for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) { - if (pc->fc.switchable_interp_prob[j][i] < 1) - pc->fc.switchable_interp_prob[j][i] = 1; - vp9_write_prob(bc, pc->fc.switchable_interp_prob[j][i]); - } - } -} - // This function updates the reference frame prediction stats static void update_refpred_stats(VP9_COMP *cpi) { VP9_COMMON *const cm = &cpi->common; @@ -311,39 +293,6 @@ static void update_refpred_stats(VP9_COMP *cpi) { } } -// This function is called to update the mode probability context used to encode -// inter modes. It assumes the branch counts table has already been populated -// prior to the actual packing of the bitstream (in rd stage or dummy pack) -// -// The branch counts table is re-populated during the actual pack stage and in -// the decoder to facilitate backwards update of the context. -static void update_inter_mode_probs(VP9_COMMON *cm, - int mode_context[INTER_MODE_CONTEXTS][VP9_MVREFS - 1]) { - int i, j; - unsigned int (*mv_ref_ct)[VP9_MVREFS - 1][2] = cm->fc.mv_ref_ct; - - vpx_memcpy(mode_context, cm->fc.vp9_mode_contexts, - sizeof(cm->fc.vp9_mode_contexts)); - - for (i = 0; i < INTER_MODE_CONTEXTS; i++) { - for (j = 0; j < VP9_MVREFS - 1; j++) { - int new_prob, old_cost, new_cost; - - // Work out cost of coding branches with the old and optimal probability - old_cost = cost_branch256(mv_ref_ct[i][j], mode_context[i][j]); - new_prob = get_binary_prob(mv_ref_ct[i][j][0], mv_ref_ct[i][j][1]); - new_cost = cost_branch256(mv_ref_ct[i][j], new_prob); - - // If cost saving is >= 14 bits then update the mode probability. - // This is the approximate net cost of updating one probability given - // that the no update case ismuch more common than the update case. - if (new_cost <= (old_cost - (14 << 8))) { - mode_context[i][j] = new_prob; - } - } - } -} - static void write_intra_mode(vp9_writer *bc, int m, const vp9_prob *p) { write_token(bc, vp9_intra_mode_tree, p, vp9_intra_mode_encodings + m); } @@ -424,6 +373,7 @@ static void vp9_cond_prob_update(vp9_writer *bc, vp9_prob *oldp, vp9_prob upd, vp9_prob newp; int savings; newp = get_binary_prob(ct[0], ct[1]); + assert(newp >= 1); savings = prob_update_savings(ct, *oldp, newp, upd); if (savings > 0) { vp9_write(bc, 1, upd); @@ -434,6 +384,60 @@ static void vp9_cond_prob_update(vp9_writer *bc, vp9_prob *oldp, vp9_prob upd, } } +static void vp9_cond_prob_diff_update(vp9_writer *bc, vp9_prob *oldp, + vp9_prob upd, + unsigned int *ct) { + vp9_prob newp; + int savings; + newp = get_binary_prob(ct[0], ct[1]); + assert(newp >= 1); + savings = prob_diff_update_savings_search(ct, *oldp, &newp, upd); + if (savings > 0) { + vp9_write(bc, 1, upd); + write_prob_diff_update(bc, newp, *oldp); + *oldp = newp; + } else { + vp9_write(bc, 0, upd); + } +} + +static void update_switchable_interp_probs(VP9_COMMON *const pc, + vp9_writer* const bc) { + unsigned int branch_ct[VP9_SWITCHABLE_FILTERS + 1] + [VP9_SWITCHABLE_FILTERS - 1][2]; + vp9_prob new_prob[VP9_SWITCHABLE_FILTERS + 1][VP9_SWITCHABLE_FILTERS - 1]; + int i, j; + for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j) { + vp9_tree_probs_from_distribution( + vp9_switchable_interp_tree, + new_prob[j], branch_ct[j], + pc->fc.switchable_interp_count[j], 0); + } + for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j) { + for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) { + // vp9_cond_prob_update(bc, &pc->fc.switchable_interp_prob[j][i], + // VP9_DEF_UPDATE_PROB, branch_ct[j][i]); + vp9_cond_prob_diff_update(bc, &pc->fc.switchable_interp_prob[j][i], + VP9_DEF_UPDATE_PROB, branch_ct[j][i]); + } + } +} + +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_MVREFS - 1; j++) { + vp9_cond_prob_diff_update(bc, &pc->fc.inter_mode_probs[i][j], + VP9_DEF_UPDATE_PROB, + pc->fc.inter_mode_counts[i][j]); + // vp9_cond_prob_update( + // bc, &pc->fc.inter_mode_probs[i][j], + // VP9_DEF_UPDATE_PROB, pc->fc.inter_mode_counts[i][j]); + } + } +} + static void pack_mb_tokens(vp9_writer* const bc, TOKENEXTRA **tp, const TOKENEXTRA *const stop) { @@ -1516,7 +1520,7 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) { for (i = 0; i < VP9_SWITCHABLE_FILTERS; ++i) { count[i] = 0; for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j) - count[i] += cpi->switchable_interp_count[j][i]; + count[i] += cpi->common.fc.switchable_interp_count[j][i]; c += (count[i] > 0); } if (c == 1) { @@ -1563,36 +1567,6 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) { else encode_txfm(cpi, &header_bc); - // If appropriate update the inter mode probability context and code the - // changes in the bitstream. - if (pc->frame_type != KEY_FRAME) { - int i, j; - int new_context[INTER_MODE_CONTEXTS][VP9_MVREFS - 1]; - if (!cpi->dummy_packing) { - update_inter_mode_probs(pc, new_context); - } else { - // In dummy pack assume context unchanged. - vpx_memcpy(new_context, pc->fc.vp9_mode_contexts, - sizeof(pc->fc.vp9_mode_contexts)); - } - - for (i = 0; i < INTER_MODE_CONTEXTS; i++) { - for (j = 0; j < VP9_MVREFS - 1; j++) { - if (new_context[i][j] != pc->fc.vp9_mode_contexts[i][j]) { - vp9_write(&header_bc, 1, 252); - vp9_write_prob(&header_bc, new_context[i][j]); - - // Only update the persistent copy if this is the "real pack" - if (!cpi->dummy_packing) { - pc->fc.vp9_mode_contexts[i][j] = new_context[i][j]; - } - } else { - vp9_write(&header_bc, 0, 252); - } - } - } - } - vp9_clear_system_state(); // __asm emms; vp9_copy(cpi->common.fc.pre_coef_probs, cpi->common.fc.coef_probs); @@ -1600,7 +1574,10 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) { vp9_copy(cpi->common.fc.pre_uv_mode_prob, cpi->common.fc.uv_mode_prob); vp9_copy(cpi->common.fc.pre_partition_prob, cpi->common.fc.partition_prob); cpi->common.fc.pre_nmvc = cpi->common.fc.nmvc; - vp9_zero(cpi->common.fc.mv_ref_ct); + vp9_copy(cpi->common.fc.pre_switchable_interp_prob, + cpi->common.fc.switchable_interp_prob); + vp9_copy(cpi->common.fc.pre_inter_mode_probs, + cpi->common.fc.inter_mode_probs); update_coef_probs(cpi, &header_bc); @@ -1614,15 +1591,19 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) { } if (pc->frame_type != KEY_FRAME) { - // Update the probabilities used to encode reference frame data - update_ref_probs(cpi); #ifdef ENTROPY_STATS active_section = 1; #endif + update_inter_mode_probs(pc, &header_bc); + vp9_zero(cpi->common.fc.inter_mode_counts); + if (pc->mcomp_filter_type == SWITCHABLE) - update_switchable_interp_probs(cpi, &header_bc); + update_switchable_interp_probs(pc, &header_bc); + + // Update the probabilities used to encode reference frame data + update_ref_probs(cpi); vp9_write_prob(&header_bc, pc->prob_intra_coded); vp9_write_prob(&header_bc, pc->prob_last_coded); diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index d1666df..3ced30d 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -472,7 +472,7 @@ static void update_state(VP9_COMP *cpi, if (cpi->common.mcomp_filter_type == SWITCHABLE && is_inter_mode(mbmi->mode)) { - ++cpi->switchable_interp_count + ++cpi->common.fc.switchable_interp_count [vp9_get_pred_context(&cpi->common, xd, PRED_SWITCHABLE_INTERP)] [vp9_switchable_interp_map[mbmi->interp_filter]]; } @@ -1460,7 +1460,7 @@ static void init_encode_frame_mb_context(VP9_COMP *cpi) { vp9_zero(cpi->count_mb_ref_frame_usage) vp9_zero(cpi->y_mode_count) vp9_zero(cpi->y_uv_mode_count) - vp9_zero(cpi->common.fc.mv_ref_ct) + vp9_zero(cpi->common.fc.inter_mode_counts) vp9_zero(cpi->partition_count); // Note: this memset assumes above_context[0], [1] and [2] @@ -1524,7 +1524,7 @@ static void encode_frame_internal(VP9_COMP *cpi) { cpi->skip_true_count[0] = cpi->skip_true_count[1] = cpi->skip_true_count[2] = 0; cpi->skip_false_count[0] = cpi->skip_false_count[1] = cpi->skip_false_count[2] = 0; - vp9_zero(cpi->switchable_interp_count); + vp9_zero(cm->fc.switchable_interp_count); vp9_zero(cpi->best_switchable_interp_count); xd->mode_info_context = cm->mi; diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index a5659d6..1932e2d 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -466,7 +466,8 @@ static void configure_static_seg_features(VP9_COMP *cpi) { void vp9_update_mode_context_stats(VP9_COMP *cpi) { VP9_COMMON *cm = &cpi->common; int i, j; - unsigned int (*mv_ref_ct)[VP9_MVREFS - 1][2] = cm->fc.mv_ref_ct; + unsigned int (*inter_mode_counts)[VP9_MVREFS - 1][2] = + cm->fc.inter_mode_counts; int64_t (*mv_ref_stats)[VP9_MVREFS - 1][2] = cpi->mv_ref_stats; FILE *f; @@ -482,8 +483,8 @@ void vp9_update_mode_context_stats(VP9_COMP *cpi) { // Add in the values for this frame for (i = 0; i < INTER_MODE_CONTEXTS; i++) { for (j = 0; j < VP9_MVREFS - 1; j++) { - mv_ref_stats[i][j][0] += (int64_t)mv_ref_ct[i][j][0]; - mv_ref_stats[i][j][1] += (int64_t)mv_ref_ct[i][j][1]; + mv_ref_stats[i][j][0] += (int64_t)inter_mode_counts[i][j][0]; + mv_ref_stats[i][j][1] += (int64_t)inter_mode_counts[i][j][1]; } } @@ -499,7 +500,7 @@ void print_mode_context(VP9_COMP *cpi) { fprintf(f, "#include \"vp9_entropy.h\"\n"); fprintf(f, - "const int vp9_mode_contexts[INTER_MODE_CONTEXTS][VP9_MVREFS - 1] ="); + "const int inter_mode_probs[INTER_MODE_CONTEXTS][VP9_MVREFS - 1] ="); fprintf(f, "{\n"); for (j = 0; j < INTER_MODE_CONTEXTS; j++) { fprintf(f, " {/* %d */ ", j); diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index dece457..d1f52c2 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -85,8 +85,8 @@ typedef struct { vp9_prob switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1] [VP9_SWITCHABLE_FILTERS - 1]; - int mv_ref_ct[INTER_MODE_CONTEXTS][VP9_MVREFS - 1][2]; - int vp9_mode_contexts[INTER_MODE_CONTEXTS][VP9_MVREFS - 1]; + int inter_mode_counts[INTER_MODE_CONTEXTS][VP9_MVREFS - 1][2]; + vp9_prob inter_mode_probs[INTER_MODE_CONTEXTS][VP9_MVREFS - 1]; } CODING_CONTEXT; diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index 748c3a8..82f0306 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -122,7 +122,7 @@ void vp9_save_coding_context(VP9_COMP *cpi) { vp9_copy(cc->nmvcosts, cpi->mb.nmvcosts); vp9_copy(cc->nmvcosts_hp, cpi->mb.nmvcosts_hp); - vp9_copy(cc->vp9_mode_contexts, cm->fc.vp9_mode_contexts); + vp9_copy(cc->inter_mode_probs, cm->fc.inter_mode_probs); vp9_copy(cc->y_mode_prob, cm->fc.y_mode_prob); vp9_copy(cc->uv_mode_prob, cm->fc.uv_mode_prob); @@ -156,7 +156,7 @@ void vp9_restore_coding_context(VP9_COMP *cpi) { vp9_copy(cpi->mb.nmvcosts, cc->nmvcosts); vp9_copy(cpi->mb.nmvcosts_hp, cc->nmvcosts_hp); - vp9_copy(cm->fc.vp9_mode_contexts, cc->vp9_mode_contexts); + vp9_copy(cm->fc.inter_mode_probs, cc->inter_mode_probs); vp9_copy(cm->fc.y_mode_prob, cc->y_mode_prob); vp9_copy(cm->fc.uv_mode_prob, cc->uv_mode_prob); -- 2.7.4