shithub: libvpx

Download patch

ref: 643238a3e02a1936fe9ddbfe2f1f7e046f25c8a0
parent: ee2051f6500cf2a576a50f966c5e43df42430f86
author: Yaowu Xu <yaowu@google.com>
date: Tue Nov 15 11:16:30 EST 2011

changed find_near_mvs search to include a mb from last frame

This is an experiment to include a mv contribution from last frame to
nearest and near mv definition. Initial test showed some small though
consistent gain.

latest patch slightly better result ~.13%-~.18%.

TODO: the entropy used to encode the mode choice, i.e. the mv counts
based conditional distribution of modes should be re-collected to
reflect this change, it is expected that there is some further gain
from that.

Change-Id: Ief1e284a36d8aa56b49ae5b360c91419ec494fa4

--- a/vp8/common/alloccommon.c
+++ b/vp8/common/alloccommon.c
@@ -116,7 +116,7 @@
     oci->mi = oci->mip + oci->mode_info_stride + 1;
 
     /* allocate memory for last frame MODE_INFO array */
-#if CONFIG_ERROR_CONCEALMENT
+#if CONFIG_ERROR_CONCEALMENT || CONFIG_NEWNEAR
     oci->prev_mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
 
     if (!oci->prev_mip)
--- a/vp8/common/blockd.h
+++ b/vp8/common/blockd.h
@@ -235,6 +235,9 @@
     YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */
     YV12_BUFFER_CONFIG dst;
 
+#if CONFIG_NEWNEAR
+    MODE_INFO *prev_mode_info_context;
+#endif
     MODE_INFO *mode_info_context;
     int mode_info_stride;
 
--- a/vp8/common/findnearmv.c
+++ b/vp8/common/findnearmv.c
@@ -21,10 +21,12 @@
 /* Predict motion vectors using those from already-decoded nearby blocks.
    Note that we only consider one 4x4 subblock from each candidate 16x16
    macroblock.   */
+#if CONFIG_NEWNEAR
 void vp8_find_near_mvs
 (
     MACROBLOCKD *xd,
     const MODE_INFO *here,
+    const MODE_INFO *lf_here,
     int_mv *nearest,
     int_mv *nearby,
     int_mv *best_mv,
@@ -36,6 +38,7 @@
     const MODE_INFO *above = here - xd->mode_info_stride;
     const MODE_INFO *left = here - 1;
     const MODE_INFO *aboveleft = above - 1;
+    const MODE_INFO *third = NULL;
     int_mv            near_mvs[4];
     int_mv           *mv = near_mvs;
     int             *cntx = cnt;
@@ -55,7 +58,138 @@
                 refframe, mv, ref_frame_sign_bias);
             ++cntx;
         }
+        *cntx += 2;
+    }
 
+    /* Process left */
+    if (left->mbmi.ref_frame != INTRA_FRAME)
+    {
+        if (left->mbmi.mv.as_int)
+        {
+            int_mv this_mv;
+            this_mv.as_int = left->mbmi.mv.as_int;
+            mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame],
+                refframe, &this_mv, ref_frame_sign_bias);
+
+            if (this_mv.as_int != mv->as_int)
+            {
+                (++mv)->as_int = this_mv.as_int;
+                ++cntx;
+            }
+            *cntx += 2;
+        }
+        else
+            cnt[CNT_INTRA] += 2;
+    }
+    /* Process above left or the one frome last frame */
+    if ( aboveleft->mbmi.ref_frame != INTRA_FRAME||
+         (lf_here->mbmi.ref_frame==LAST_FRAME && refframe == LAST_FRAME))
+    {
+        if (aboveleft->mbmi.mv.as_int)
+        {
+            third = aboveleft;
+        }
+        else if(lf_here->mbmi.mv.as_int)
+        {
+            third = lf_here;
+        }
+        if(third)
+        {
+            int_mv this_mv;
+            this_mv.as_int = third->mbmi.mv.as_int;
+            mv_bias(ref_frame_sign_bias[third->mbmi.ref_frame],
+                refframe, &this_mv, ref_frame_sign_bias);
+
+            if (this_mv.as_int != mv->as_int)
+            {
+                (++mv)->as_int = this_mv.as_int;
+                ++cntx;
+            }
+            *cntx += 1;
+        }
+        else
+            cnt[CNT_INTRA] += 1;
+    }
+
+    /* If we have three distinct MV's ... */
+    if (cnt[CNT_SPLITMV])
+    {
+        /* See if the third MV can be merged with NEAREST */
+        if (mv->as_int == near_mvs[CNT_NEAREST].as_int)
+            cnt[CNT_NEAREST] += 1;
+    }
+
+    cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
+                        + (left->mbmi.mode == SPLITMV)) * 2
+                        + (
+#if CONFIG_NEWNEAR
+                        lf_here->mbmi.mode == SPLITMV ||
+#endif
+                       aboveleft->mbmi.mode == SPLITMV);
+
+    /* Swap near and nearest if necessary */
+    if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
+    {
+        int tmp;
+        tmp = cnt[CNT_NEAREST];
+        cnt[CNT_NEAREST] = cnt[CNT_NEAR];
+        cnt[CNT_NEAR] = tmp;
+        tmp = near_mvs[CNT_NEAREST].as_int;
+        near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
+        near_mvs[CNT_NEAR].as_int = tmp;
+    }
+
+    /* Use near_mvs[0] to store the "best" MV */
+    if (cnt[CNT_NEAREST] >= cnt[CNT_INTRA])
+        near_mvs[CNT_INTRA] = near_mvs[CNT_NEAREST];
+
+    /* Set up return values */
+    best_mv->as_int = near_mvs[0].as_int;
+    nearest->as_int = near_mvs[CNT_NEAREST].as_int;
+    nearby->as_int = near_mvs[CNT_NEAR].as_int;
+
+    //TODO: move clamp outside findnearmv
+    vp8_clamp_mv2(nearest, xd);
+    vp8_clamp_mv2(nearby, xd);
+    vp8_clamp_mv2(best_mv, xd);
+}
+
+
+#else
+void vp8_find_near_mvs
+(
+    MACROBLOCKD *xd,
+    const MODE_INFO *here,
+    int_mv *nearest,
+    int_mv *nearby,
+    int_mv *best_mv,
+    int cnt[4],
+    int refframe,
+    int *ref_frame_sign_bias
+)
+{
+    const MODE_INFO *above = here - xd->mode_info_stride;
+    const MODE_INFO *left = here - 1;
+    const MODE_INFO *aboveleft = above - 1;
+    int_mv            near_mvs[4];
+    int_mv           *mv = near_mvs;
+    int             *cntx = cnt;
+    enum {CNT_INTRA, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV};
+
+    /* Zero accumulators */
+    mv[0].as_int = mv[1].as_int = mv[2].as_int = 0;
+    cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
+
+    /* Process above */
+    if (above->mbmi.ref_frame != INTRA_FRAME)
+    {
+        if (above->mbmi.mv.as_int)
+        {
+            (++mv)->as_int = above->mbmi.mv.as_int;
+            mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame],
+                refframe, mv, ref_frame_sign_bias);
+            ++cntx;
+        }
         *cntx += 2;
     }
 
@@ -81,7 +215,6 @@
         else
             cnt[CNT_INTRA] += 2;
     }
-
     /* Process above left */
     if (aboveleft->mbmi.ref_frame != INTRA_FRAME)
     {
@@ -143,6 +276,7 @@
     vp8_clamp_mv2(nearby, xd);
     vp8_clamp_mv2(best_mv, xd);
 }
+#endif
 
 vp8_prob *vp8_mv_ref_probs(
     vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
--- a/vp8/common/findnearmv.h
+++ b/vp8/common/findnearmv.h
@@ -75,6 +75,9 @@
 (
     MACROBLOCKD *xd,
     const MODE_INFO *here,
+#if CONFIG_NEWNEAR
+    const MODE_INFO *lfhere,
+#endif
     int_mv *nearest, int_mv *nearby, int_mv *best,
     int near_mv_ref_cts[4],
     int refframe,
--- a/vp8/decoder/decodemv.c
+++ b/vp8/decoder/decodemv.c
@@ -425,6 +425,9 @@
 
 
 static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
+#if CONFIG_NEWNEAR
+                             MODE_INFO *prev_mi,
+#endif
                             int mb_row, int mb_col)
 {
     vp8_reader *const bc = & pbi->bc;
@@ -529,7 +532,11 @@
         int_mv nearest, nearby, best_mv;
         vp8_prob mv_ref_p [VP8_MVREFS-1];
 
-        vp8_find_near_mvs(xd, mi, &nearest, &nearby, &best_mv, rct,
+        vp8_find_near_mvs(xd, mi,
+#if CONFIG_NEWNEAR
+            prev_mi,
+#endif
+            &nearest, &nearby, &best_mv, rct,
                           mbmi->ref_frame, pbi->common.ref_frame_sign_bias);
         vp8_mv_ref_probs(mv_ref_p, rct);
 
@@ -725,6 +732,11 @@
 void vp8_decode_mode_mvs(VP8D_COMP *pbi)
 {
     MODE_INFO *mi = pbi->common.mi;
+
+#if CONFIG_NEWNEAR
+    MODE_INFO *prev_mi = pbi->common.prev_mi;
+#endif
+
     int mb_row = -1;
 
 //#if CONFIG_SEGFEATURES
@@ -771,7 +783,11 @@
             if(pbi->common.frame_type == KEY_FRAME)
                 vp8_kfread_modes(pbi, mi, mb_row, mb_col);
             else
-                read_mb_modes_mv(pbi, mi, &mi->mbmi, mb_row, mb_col);
+                read_mb_modes_mv(pbi, mi, &mi->mbmi,
+#if CONFIG_NEWNEAR
+                prev_mi,
+#endif
+                mb_row, mb_col);
 
             //printf("%3d", mi->mbmi.mode);
 
@@ -807,11 +823,15 @@
             fprintf(statsfile, "%2d%2d%2d   ",
                 mi->mbmi.segment_id, mi->mbmi.ref_frame, mi->mbmi.mode );
 #endif
-
-
+#if CONFIG_NEWNEAR
+            prev_mi++;
+#endif
             mi++;       /* next macroblock */
         }
        // printf("\n");
+#if CONFIG_NEWNEAR
+        prev_mi++;
+#endif
         mi++;           /* skip left predictor each row */
     }
 
--- a/vp8/decoder/onyxd_if.c
+++ b/vp8/decoder/onyxd_if.c
@@ -81,6 +81,41 @@
 }
 #endif
 
+#if WRITE_RECON_BUFFER
+void write_dx_frame_to_file(YV12_BUFFER_CONFIG *frame, int this_frame)
+{
+
+    // write the frame
+    FILE *yframe;
+    int i;
+    char filename[255];
+
+    sprintf(filename, "dx\\y%04d.raw", this_frame);
+    yframe = fopen(filename, "wb");
+
+    for (i = 0; i < frame->y_height; i++)
+        fwrite(frame->y_buffer + i * frame->y_stride, frame->y_width, 1, yframe);
+
+    fclose(yframe);
+    sprintf(filename, "dx\\u%04d.raw", this_frame);
+    yframe = fopen(filename, "wb");
+
+    for (i = 0; i < frame->uv_height; i++)
+        fwrite(frame->u_buffer + i * frame->uv_stride, frame->uv_width, 1, yframe);
+
+    fclose(yframe);
+    sprintf(filename, "dx\\v%04d.raw", this_frame);
+    yframe = fopen(filename, "wb");
+
+    for (i = 0; i < frame->uv_height; i++)
+        fwrite(frame->v_buffer + i * frame->uv_stride, frame->uv_width, 1, yframe);
+
+    fclose(yframe);
+}
+#endif
+
+
+
 void vp8dx_initialize()
 {
     static int init_done = 0;
@@ -540,6 +575,11 @@
             return -1;
         }
 
+#if WRITE_RECON_BUFFER
+        if(cm->show_frame)
+            write_dx_frame_to_file(cm->frame_to_show, cm->current_video_frame);
+#endif
+
         if(cm->filter_level)
         {
             /* Apply the loop filter if appropriate. */
@@ -573,6 +613,19 @@
                         pbi->common.prev_mi[i].mbmi.segment_id;
             }
         }
+    }
+#endif
+
+#if CONFIG_NEWNEAR
+    if(cm->show_frame)
+    {
+        vpx_memcpy(cm->prev_mip, cm->mip,
+            (cm->mb_cols + 1) * (cm->mb_rows + 1)* sizeof(MODE_INFO));
+    }
+    else
+    {
+        vpx_memset(cm->prev_mip, 0,
+            (cm->mb_cols + 1) * (cm->mb_rows + 1)* sizeof(MODE_INFO));
     }
 #endif
 
--- a/vp8/encoder/bitstream.c
+++ b/vp8/encoder/bitstream.c
@@ -948,7 +948,11 @@
     const int rf_intra = rfct[INTRA_FRAME];
     const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME];
 
-    MODE_INFO *m = pc->mi, *ms;
+    MODE_INFO *m = pc->mi;
+#if CONFIG_NEWNEAR
+    MODE_INFO *prev_m = pc->prev_mi;
+#endif
+
     const int mis = pc->mode_info_stride;
     int mb_row = -1;
 
@@ -955,7 +959,6 @@
     int prob_last_coded;
     int prob_gf_coded;
     int prob_skip_false = 0;
-    ms = pc->mi - 1;
 
     cpi->mb.partition_info = cpi->mb.pi;
 
@@ -1033,6 +1036,9 @@
 
             // Make sure the MacroBlockD mode info pointer is set correctly
             xd->mode_info_context = m;
+#if CONFIG_NEWNEAR
+            xd->prev_mode_info_context = prev_m;
+#endif
 
 #ifdef ENTROPY_STATS
             active_section = 9;
@@ -1110,7 +1116,11 @@
                     int_mv n1, n2;
                     int ct[4];
 
-                    vp8_find_near_mvs(xd, m, &n1, &n2, &best_mv, ct, rf, cpi->common.ref_frame_sign_bias);
+                    vp8_find_near_mvs(xd, m,
+#if CONFIG_NEWNEAR
+                        prev_m,
+#endif
+                        &n1, &n2, &best_mv, ct, rf, cpi->common.ref_frame_sign_bias);
                     vp8_mv_ref_probs(mv_ref_p, ct);
 
 #ifdef ENTROPY_STATS
@@ -1193,10 +1203,19 @@
             }
 
             ++m;
+#if CONFIG_NEWNEAR
+            ++prev_m;
+            assert((prev_m-cpi->common.prev_mip)==(m-cpi->common.mip));
+            assert((prev_m-cpi->common.prev_mi)==(m-cpi->common.mi));
+#endif
+
             cpi->mb.partition_info++;
         }
 
         ++m;  /* skip L prediction border */
+#if CONFIG_NEWNEAR
+        ++prev_m;
+#endif
         cpi->mb.partition_info++;
     }
 }
--- a/vp8/encoder/encodeframe.c
+++ b/vp8/encoder/encodeframe.c
@@ -767,6 +767,12 @@
 
         // skip to next mb
         xd->mode_info_context++;
+
+#if CONFIG_NEWNEAR
+        xd->prev_mode_info_context++;
+        assert((xd->prev_mode_info_context - cpi->common.prev_mip)
+            ==(xd->mode_info_context - cpi->common.mip));
+#endif
         x->partition_info++;
 
         xd->above_context++;
@@ -786,6 +792,9 @@
         xd->dst.v_buffer + 8);
 
     // this is to account for the border
+#if CONFIG_NEWNEAR
+    xd->prev_mode_info_context++;
+#endif
     xd->mode_info_context++;
     x->partition_info++;
 
@@ -829,7 +838,11 @@
 
     xd->mode_info_context = cm->mi;
     xd->mode_info_stride = cm->mode_info_stride;
+#if CONFIG_NEWNEAR
+    xd->prev_mode_info_context = cm->prev_mi;
+#endif
 
+
     xd->frame_type = cm->frame_type;
 
     xd->frames_since_golden = cm->frames_since_golden;
@@ -970,6 +983,11 @@
 
     xd->mode_info_context = cm->mi;
 
+#if CONFIG_NEWNEAR
+    xd->prev_mode_info_context = cm->prev_mi;
+#endif
+
+
     vp8_zero(cpi->MVcount);
     vp8_zero(cpi->coef_counts);
 
@@ -1022,7 +1040,13 @@
                 x->src.u_buffer +=  8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
                 x->src.v_buffer +=  8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
 
-                xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count;
+                xd->mode_info_context += xd->mode_info_stride
+                                        * cpi->encoding_thread_count;
+#if CONFIG_NEWNEAR
+                xd->prev_mode_info_context += xd->mode_info_stride
+                                            * cpi->encoding_thread_count;
+#endif
+
                 x->partition_info  += xd->mode_info_stride * cpi->encoding_thread_count;
                 x->gf_active_ptr   += cm->mb_cols * cpi->encoding_thread_count;
 
--- a/vp8/encoder/ethreading.c
+++ b/vp8/encoder/ethreading.c
@@ -248,6 +248,9 @@
                     recon_uvoffset += 8;
 
                     // skip to next mb
+#if CONFIG_NEWNEAR
+                    xd->prev_mode_info_context++;
+#endif
                     xd->mode_info_context++;
                     x->partition_info++;
                     xd->above_context++;
@@ -263,6 +266,10 @@
                     xd->dst.v_buffer + 8);
 
                 // this is to account for the border
+#if CONFIG_NEWNEAR
+                xd->prev_mode_info_context++;
+#endif
+
                 xd->mode_info_context++;
                 x->partition_info++;
 
@@ -270,7 +277,13 @@
                 x->src.u_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
                 x->src.v_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
 
-                xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count;
+                xd->mode_info_context += xd->mode_info_stride
+                                        * cpi->encoding_thread_count;
+#if CONFIG_NEWNEAR
+                xd->prev_mode_info_context += xd->mode_info_stride
+                                            * cpi->encoding_thread_count;
+#endif
+
                 x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count;
                 x->gf_active_ptr   += cm->mb_cols * cpi->encoding_thread_count;
 
@@ -437,7 +450,12 @@
 
         mb->partition_info = x->pi + x->e_mbd.mode_info_stride * (i + 1);
 
-        mbd->mode_info_context = cm->mi   + x->e_mbd.mode_info_stride * (i + 1);
+        mbd->mode_info_context = cm->mi
+                                 + x->e_mbd.mode_info_stride * (i + 1);
+#if CONFIG_NEWNEAR
+        mbd->prev_mode_info_context = cm->prev_mi
+                                    + x->e_mbd.mode_info_stride * (i + 1);
+#endif
         mbd->mode_info_stride  = cm->mode_info_stride;
 
         mbd->frame_type = cm->frame_type;
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -2439,7 +2439,7 @@
         {
             extern int count_mb_seg[4];
             char modes_stats_file[250];
-            FILE *f; 
+            FILE *f;
             double dr = (double)cpi->oxcf.frame_rate * (double)cpi->bytes * (double)8 / (double)cpi->count / (double)1000 ;
             sprintf(modes_stats_file, "modes_q%03d.stt",cpi->common.base_qindex);
             f = fopen(modes_stats_file, "w");
@@ -3292,7 +3292,7 @@
 }
 #endif
 
-#if 0
+#if WRITE_RECON_BUFFER
 void write_cx_frame_to_file(YV12_BUFFER_CONFIG *frame, int this_frame)
 {
 
@@ -4437,6 +4437,11 @@
 
     cm->frame_to_show = &cm->yv12_fb[cm->new_fb_idx];
 
+#if WRITE_RECON_BUFFER
+    if(cm->show_frame)
+        write_cx_frame_to_file(cm->frame_to_show, cm->current_video_frame);
+#endif
+
 #if CONFIG_MULTITHREAD
     if (cpi->b_multi_threaded)
     {
@@ -4811,6 +4816,20 @@
 #if OUTPUT_YUV_REC
     vp8_write_yuv_rec_frame(cm);
 #endif
+
+#if CONFIG_NEWNEAR
+    if(cm->show_frame)
+    {
+        vpx_memcpy(cm->prev_mip, cm->mip,
+            (cm->mb_cols + 1) * (cm->mb_rows + 1)* sizeof(MODE_INFO));
+    }
+    else
+    {
+        vpx_memset(cm->prev_mip, 0,
+            (cm->mb_cols + 1) * (cm->mb_rows + 1)* sizeof(MODE_INFO));
+    }
+#endif
+
 
 }
 
--- a/vp8/encoder/pickinter.c
+++ b/vp8/encoder/pickinter.c
@@ -460,7 +460,11 @@
     {
         YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx];
 
-        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &nearest_mv[LAST_FRAME], &near_mv[LAST_FRAME],
+        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context,
+#if CONFIG_NEWNEAR
+                        x->e_mbd.prev_mode_info_context,
+#endif
+            &nearest_mv[LAST_FRAME], &near_mv[LAST_FRAME],
                           &frame_best_ref_mv[LAST_FRAME], MDCounts[LAST_FRAME], LAST_FRAME, cpi->common.ref_frame_sign_bias);
 
         y_buffer[LAST_FRAME] = lst_yv12->y_buffer + recon_yoffset;
@@ -474,9 +478,14 @@
     {
         YV12_BUFFER_CONFIG *gld_yv12 = &cpi->common.yv12_fb[cpi->common.gld_fb_idx];
 
-        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &nearest_mv[GOLDEN_FRAME], &near_mv[GOLDEN_FRAME],
-                          &frame_best_ref_mv[GOLDEN_FRAME], MDCounts[GOLDEN_FRAME], GOLDEN_FRAME, cpi->common.ref_frame_sign_bias);
+        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context,
+#if CONFIG_NEWNEAR
+            x->e_mbd.prev_mode_info_context,
+#endif
 
+            &nearest_mv[GOLDEN_FRAME], &near_mv[GOLDEN_FRAME],
+            &frame_best_ref_mv[GOLDEN_FRAME], MDCounts[GOLDEN_FRAME], GOLDEN_FRAME, cpi->common.ref_frame_sign_bias);
+
         y_buffer[GOLDEN_FRAME] = gld_yv12->y_buffer + recon_yoffset;
         u_buffer[GOLDEN_FRAME] = gld_yv12->u_buffer + recon_uvoffset;
         v_buffer[GOLDEN_FRAME] = gld_yv12->v_buffer + recon_uvoffset;
@@ -488,8 +497,12 @@
     {
         YV12_BUFFER_CONFIG *alt_yv12 = &cpi->common.yv12_fb[cpi->common.alt_fb_idx];
 
-        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &nearest_mv[ALTREF_FRAME], &near_mv[ALTREF_FRAME],
-                          &frame_best_ref_mv[ALTREF_FRAME], MDCounts[ALTREF_FRAME], ALTREF_FRAME, cpi->common.ref_frame_sign_bias);
+        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context,
+#if CONFIG_NEWNEAR
+                        x->e_mbd.prev_mode_info_context,
+#endif
+                        &nearest_mv[ALTREF_FRAME], &near_mv[ALTREF_FRAME],
+                        &frame_best_ref_mv[ALTREF_FRAME], MDCounts[ALTREF_FRAME], ALTREF_FRAME, cpi->common.ref_frame_sign_bias);
 
         y_buffer[ALTREF_FRAME] = alt_yv12->y_buffer + recon_yoffset;
         u_buffer[ALTREF_FRAME] = alt_yv12->u_buffer + recon_uvoffset;
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -2003,8 +2003,12 @@
     {
         YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx];
 
-        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &frame_nearest_mv[LAST_FRAME], &frame_near_mv[LAST_FRAME],
-                          &frame_best_ref_mv[LAST_FRAME], frame_mdcounts[LAST_FRAME], LAST_FRAME, cpi->common.ref_frame_sign_bias);
+        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context,
+#if CONFIG_NEWNEAR
+            x->e_mbd.prev_mode_info_context,
+#endif
+            &frame_nearest_mv[LAST_FRAME], &frame_near_mv[LAST_FRAME],
+            &frame_best_ref_mv[LAST_FRAME], frame_mdcounts[LAST_FRAME], LAST_FRAME, cpi->common.ref_frame_sign_bias);
 
         y_buffer[LAST_FRAME] = lst_yv12->y_buffer + recon_yoffset;
         u_buffer[LAST_FRAME] = lst_yv12->u_buffer + recon_uvoffset;
@@ -2015,8 +2019,12 @@
     {
         YV12_BUFFER_CONFIG *gld_yv12 = &cpi->common.yv12_fb[cpi->common.gld_fb_idx];
 
-        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &frame_nearest_mv[GOLDEN_FRAME], &frame_near_mv[GOLDEN_FRAME],
-                          &frame_best_ref_mv[GOLDEN_FRAME], frame_mdcounts[GOLDEN_FRAME], GOLDEN_FRAME, cpi->common.ref_frame_sign_bias);
+        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context,
+#if CONFIG_NEWNEAR
+            x->e_mbd.prev_mode_info_context,
+#endif
+            &frame_nearest_mv[GOLDEN_FRAME], &frame_near_mv[GOLDEN_FRAME],
+            &frame_best_ref_mv[GOLDEN_FRAME], frame_mdcounts[GOLDEN_FRAME], GOLDEN_FRAME, cpi->common.ref_frame_sign_bias);
 
         y_buffer[GOLDEN_FRAME] = gld_yv12->y_buffer + recon_yoffset;
         u_buffer[GOLDEN_FRAME] = gld_yv12->u_buffer + recon_uvoffset;
@@ -2027,7 +2035,11 @@
     {
         YV12_BUFFER_CONFIG *alt_yv12 = &cpi->common.yv12_fb[cpi->common.alt_fb_idx];
 
-        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &frame_nearest_mv[ALTREF_FRAME], &frame_near_mv[ALTREF_FRAME],
+        vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context,
+#if CONFIG_NEWNEAR
+                          x->e_mbd.prev_mode_info_context,
+#endif
+                          &frame_nearest_mv[ALTREF_FRAME], &frame_near_mv[ALTREF_FRAME],
                           &frame_best_ref_mv[ALTREF_FRAME], frame_mdcounts[ALTREF_FRAME], ALTREF_FRAME, cpi->common.ref_frame_sign_bias);
 
         y_buffer[ALTREF_FRAME] = alt_yv12->y_buffer + recon_yoffset;