diff --git a/vp9/common/vp9_entropymv.c b/vp9/common/vp9_entropymv.c index ed6af665e43ab8896fa59b50f4f87c5c765b3206..c1b87e2812f6c4bc54f3d86b4b55564ce6cb0428 100644 --- a/vp9/common/vp9_entropymv.c +++ b/vp9/common/vp9_entropymv.c @@ -12,17 +12,12 @@ #include "vp9/common/vp9_onyxc_int.h" #include "vp9/common/vp9_entropymv.h" -//#define MV_COUNT_TESTING - #define MV_COUNT_SAT 20 #define MV_MAX_UPDATE_FACTOR 128 /* Integer pel reference mv threshold for use of high-precision 1/8 mv */ #define COMPANDED_MVREF_THRESH 8 -/* Smooth or bias the mv-counts before prob computation */ -/* #define SMOOTH_MV_COUNTS */ - const vp9_tree_index vp9_mv_joint_tree[2 * MV_JOINTS - 2] = { -MV_JOINT_ZERO, 2, -MV_JOINT_HNZVZ, 4, @@ -160,24 +155,6 @@ static void inc_mv_component(int v, nmv_component_counts *comp_counts, } } -#ifdef SMOOTH_MV_COUNTS -static void smooth_counts(nmv_component_counts *mvcomp) { - static const int flen = 3; // (filter_length + 1) / 2 - static const int fval[] = {8, 3, 1}; - static const int fvalbits = 4; - int i; - unsigned int smvcount[MV_VALS]; - vpx_memcpy(smvcount, mvcomp->mvcount, sizeof(smvcount)); - smvcount[MV_MAX] = (smvcount[MV_MAX - 1] + smvcount[MV_MAX + 1]) >> 1; - for (i = flen - 1; i <= MV_VALS - flen; ++i) { - int j, s = smvcount[i] * fval[0]; - for (j = 1; j < flen; ++j) - s += (smvcount[i - j] + smvcount[i + j]) * fval[j]; - mvcomp->mvcount[i] = (s + (1 << (fvalbits - 1))) >> fvalbits; - } -} -#endif - static void counts_to_context(nmv_component_counts *mvcomp, int usehp) { int v; vpx_memset(mvcomp->sign, 0, sizeof(nmv_component_counts) - sizeof(mvcomp->mvcount)); @@ -246,108 +223,41 @@ static unsigned int adapt_probs(unsigned int i, void vp9_adapt_mv_probs(VP9_COMMON *cm, int usehp) { int i, j; -#ifdef MV_COUNT_TESTING - printf("joints count: "); - for (j = 0; j < MV_JOINTS; ++j) printf("%d ", cm->fc.NMVcount.joints[j]); - printf("\n"); fflush(stdout); - printf("signs count:\n"); - for (i = 0; i < 2; ++i) - printf("%d/%d ", cm->fc.NMVcount.comps[i].sign[0], cm->fc.NMVcount.comps[i].sign[1]); - printf("\n"); fflush(stdout); - printf("classes count:\n"); - for (i = 0; i < 2; ++i) { - for (j = 0; j < MV_CLASSES; ++j) - printf("%d ", cm->fc.NMVcount.comps[i].classes[j]); - printf("\n"); fflush(stdout); - } - printf("class0 count:\n"); - for (i = 0; i < 2; ++i) { - for (j = 0; j < CLASS0_SIZE; ++j) - printf("%d ", cm->fc.NMVcount.comps[i].class0[j]); - printf("\n"); fflush(stdout); - } - printf("bits count:\n"); - for (i = 0; i < 2; ++i) { - for (j = 0; j < MV_OFFSET_BITS; ++j) - printf("%d/%d ", cm->fc.NMVcount.comps[i].bits[j][0], - cm->fc.NMVcount.comps[i].bits[j][1]); - printf("\n"); fflush(stdout); - } - printf("class0_fp count:\n"); - for (i = 0; i < 2; ++i) { - for (j = 0; j < CLASS0_SIZE; ++j) { - printf("{"); - for (k = 0; k < 4; ++k) - printf("%d ", cm->fc.NMVcount.comps[i].class0_fp[j][k]); - printf("}, "); - } - printf("\n"); fflush(stdout); - } - printf("fp count:\n"); - for (i = 0; i < 2; ++i) { - for (j = 0; j < 4; ++j) - printf("%d ", cm->fc.NMVcount.comps[i].fp[j]); - printf("\n"); fflush(stdout); - } - if (usehp) { - printf("class0_hp count:\n"); - for (i = 0; i < 2; ++i) - printf("%d/%d ", cm->fc.NMVcount.comps[i].class0_hp[0], - cm->fc.NMVcount.comps[i].class0_hp[1]); - printf("\n"); fflush(stdout); - printf("hp count:\n"); - for (i = 0; i < 2; ++i) - printf("%d/%d ", cm->fc.NMVcount.comps[i].hp[0], - cm->fc.NMVcount.comps[i].hp[1]); - printf("\n"); fflush(stdout); - } -#endif -#ifdef SMOOTH_MV_COUNTS - smooth_counts(&cm->fc.NMVcount.comps[0]); - smooth_counts(&cm->fc.NMVcount.comps[1]); -#endif - vp9_counts_process(&cm->fc.NMVcount, usehp); - adapt_probs(0, vp9_mv_joint_tree, - cm->fc.nmvc.joints, cm->fc.pre_nmvc.joints, - cm->fc.NMVcount.joints); + nmv_context *ctx = &cm->fc.nmvc; + nmv_context *pre_ctx = &cm->fc.pre_nmvc; + nmv_context_counts *cts = &cm->fc.NMVcount; + + vp9_counts_process(cts, usehp); + + adapt_probs(0, vp9_mv_joint_tree, ctx->joints, pre_ctx->joints, cts->joints); for (i = 0; i < 2; ++i) { - adapt_prob(&cm->fc.nmvc.comps[i].sign, - cm->fc.pre_nmvc.comps[i].sign, - cm->fc.NMVcount.comps[i].sign); - adapt_probs(0, vp9_mv_class_tree, - cm->fc.nmvc.comps[i].classes, cm->fc.pre_nmvc.comps[i].classes, - cm->fc.NMVcount.comps[i].classes); - adapt_probs(0, vp9_mv_class0_tree, - cm->fc.nmvc.comps[i].class0, cm->fc.pre_nmvc.comps[i].class0, - cm->fc.NMVcount.comps[i].class0); - for (j = 0; j < MV_OFFSET_BITS; ++j) { - adapt_prob(&cm->fc.nmvc.comps[i].bits[j], - cm->fc.pre_nmvc.comps[i].bits[j], - cm->fc.NMVcount.comps[i].bits[j]); - } + adapt_prob(&ctx->comps[i].sign, 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); + + for (j = 0; j < MV_OFFSET_BITS; ++j) + adapt_prob(&ctx->comps[i].bits[j], pre_ctx->comps[i].bits[j], + cts->comps[i].bits[j]); } + for (i = 0; i < 2; ++i) { - for (j = 0; j < CLASS0_SIZE; ++j) { - adapt_probs(0, vp9_mv_fp_tree, - cm->fc.nmvc.comps[i].class0_fp[j], - cm->fc.pre_nmvc.comps[i].class0_fp[j], - cm->fc.NMVcount.comps[i].class0_fp[j]); - } - adapt_probs(0, vp9_mv_fp_tree, - cm->fc.nmvc.comps[i].fp, - cm->fc.pre_nmvc.comps[i].fp, - cm->fc.NMVcount.comps[i].fp); + 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(0, vp9_mv_fp_tree, ctx->comps[i].fp, pre_ctx->comps[i].fp, + cts->comps[i].fp); } + if (usehp) { for (i = 0; i < 2; ++i) { - adapt_prob(&cm->fc.nmvc.comps[i].class0_hp, - cm->fc.pre_nmvc.comps[i].class0_hp, - cm->fc.NMVcount.comps[i].class0_hp); - adapt_prob(&cm->fc.nmvc.comps[i].hp, - cm->fc.pre_nmvc.comps[i].hp, - cm->fc.NMVcount.comps[i].hp); + adapt_prob(&ctx->comps[i].class0_hp, pre_ctx->comps[i].class0_hp, + cts->comps[i].class0_hp); + adapt_prob(&ctx->comps[i].hp, pre_ctx->comps[i].hp, cts->comps[i].hp); } } }