shithub: libvpx

Download patch

ref: de80da39dc9b7b56c180bf27ee6e47779280fa4d
parent: aa76bf3d285c00ab170f89afaa3ee0c79ba82b0e
author: Paul Wilkins <paulwilkins@google.com>
date: Fri Apr 19 11:40:36 EDT 2013

Mv ref candidates cut to 2.

Further simplification of mvref search to return
only the top two candidates. Distance weights removed
as the test order reflects distance anyway.

Change-Id: I0518cab7280258fec2058670add4f853fab7b855

--- a/vp9/common/vp9_blockd.h
+++ b/vp9/common/vp9_blockd.h
@@ -41,7 +41,7 @@
 #define SEGMENT_DELTADATA   0
 #define SEGMENT_ABSDATA     1
 #define MAX_MV_REFS 9
-#define MAX_MV_REF_CANDIDATES 4
+#define MAX_MV_REF_CANDIDATES 2
 
 typedef enum {
   PLANE_TYPE_Y_WITH_DC,
--- a/vp9/common/vp9_findnearmv.c
+++ b/vp9/common/vp9_findnearmv.c
@@ -39,8 +39,6 @@
 }
 
 void vp9_find_best_ref_mvs(MACROBLOCKD *xd,
-                           uint8_t *ref_y_buffer,
-                           int ref_y_stride,
                            int_mv *mvlist,
                            int_mv *nearest,
                            int_mv *near) {
--- a/vp9/common/vp9_findnearmv.h
+++ b/vp9/common/vp9_findnearmv.h
@@ -24,8 +24,6 @@
 // above and a number cols of pixels in the left to select the one with best
 // score to use as ref motion vector
 void vp9_find_best_ref_mvs(MACROBLOCKD *xd,
-                           uint8_t *ref_y_buffer,
-                           int ref_y_stride,
                            int_mv *mvlist,
                            int_mv *nearest,
                            int_mv *near);
--- a/vp9/common/vp9_mvref_common.c
+++ b/vp9/common/vp9_mvref_common.c
@@ -17,29 +17,17 @@
     {-2, 0}, {-1, -2}, {-2, -1}, {-2, -2}
 };
 
-static int mb_ref_distance_weight[MVREF_NEIGHBOURS] =
-  { 3, 3, 2, 1, 1, 1, 1, 1 };
-
 static int sb_mv_ref_search[MVREF_NEIGHBOURS][2] = {
     {0, -1}, {-1, 0}, {1, -1}, {-1, 1},
     {-1, -1}, {0, -2}, {-2, 0}, {-1, -2}
 };
 
-static int sb_ref_distance_weight[MVREF_NEIGHBOURS] =
-  { 3, 3, 2, 2, 2, 1, 1, 1 };
-
-
-
 static int sb64_mv_ref_search[MVREF_NEIGHBOURS][2] = {
     {0, -1}, {-1, 0}, {1, -1}, {-1, 1},
     {2, -1}, {-1, 2}, {3, -1}, {-1,-1}
 };
 
-static int sb64_ref_distance_weight[MVREF_NEIGHBOURS] =
-  { 1, 1, 1, 1, 1, 1, 1, 1 };
 
-
-
 // clamp_mv_ref
 #define MV_BORDER (16 << 3) // Allow 16 pels in 1/8th pel units
 
@@ -164,7 +152,6 @@
   int i;
   MODE_INFO *candidate_mi;
   MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi;
-  int_mv candidate_mvs[MAX_MV_REF_CANDIDATES];
   int_mv c_refmv;
   int_mv c2_refmv;
   MV_REFERENCE_FRAME c_ref_frame;
@@ -173,23 +160,17 @@
   int refmv_count = 0;
   int split_count = 0;
   int (*mv_ref_search)[2];
-  int *ref_distance_weight;
   const int mb_col = (-xd->mb_to_left_edge) >> 7;
-
   // Blank the reference vector lists and other local structures.
   vpx_memset(mv_ref_list, 0, sizeof(int_mv) * MAX_MV_REF_CANDIDATES);
-  vpx_memset(candidate_mvs, 0, sizeof(int_mv) * MAX_MV_REF_CANDIDATES);
   vpx_memset(candidate_scores, 0, sizeof(candidate_scores));
 
   if (mbmi->sb_type == BLOCK_SIZE_SB64X64) {
     mv_ref_search = sb64_mv_ref_search;
-    ref_distance_weight = sb64_ref_distance_weight;
   } else if (mbmi->sb_type >= BLOCK_SIZE_SB32X32) {
     mv_ref_search = sb_mv_ref_search;
-    ref_distance_weight = sb_ref_distance_weight;
   } else {
     mv_ref_search = mb_mv_ref_search;
-    ref_distance_weight = mb_ref_distance_weight;
   }
 
   // We first scan for candidate vectors that match the current reference frame
@@ -205,8 +186,8 @@
                      (mv_ref_search[i][1] * xd->mode_info_stride);
 
       if (get_matching_candidate(candidate_mi, ref_frame, &c_refmv)) {
-        add_candidate_mv(candidate_mvs, candidate_scores,
-                         &refmv_count, c_refmv, ref_distance_weight[i] + 16);
+        add_candidate_mv(mv_ref_list, candidate_scores,
+                         &refmv_count, c_refmv, 16);
       }
       split_count += (candidate_mi->mbmi.mode == SPLITMV);
     }
@@ -224,8 +205,8 @@
                      (mv_ref_search[i][1] * xd->mode_info_stride);
 
       if (get_matching_candidate(candidate_mi, ref_frame, &c_refmv)) {
-        add_candidate_mv(candidate_mvs, candidate_scores,
-                         &refmv_count, c_refmv, ref_distance_weight[i] + 16);
+        add_candidate_mv(mv_ref_list, candidate_scores,
+                         &refmv_count, c_refmv, 16);
       }
     }
   }
@@ -234,8 +215,8 @@
   if (lf_here && (refmv_count < MAX_MV_REF_CANDIDATES)) {
     candidate_mi = lf_here;
     if (get_matching_candidate(candidate_mi, ref_frame, &c_refmv)) {
-      add_candidate_mv(candidate_mvs, candidate_scores,
-                       &refmv_count, c_refmv, 17);
+      add_candidate_mv(mv_ref_list, candidate_scores,
+                       &refmv_count, c_refmv, 16);
     }
   }
 
@@ -259,14 +240,14 @@
 
       if (c_ref_frame != INTRA_FRAME) {
         scale_mv(xd, ref_frame, c_ref_frame, &c_refmv, ref_sign_bias);
-        add_candidate_mv(candidate_mvs, candidate_scores,
-                         &refmv_count, c_refmv, ref_distance_weight[i]);
+        add_candidate_mv(mv_ref_list, candidate_scores,
+                         &refmv_count, c_refmv, 1);
       }
 
       if (c2_ref_frame != INTRA_FRAME) {
         scale_mv(xd, ref_frame, c2_ref_frame, &c2_refmv, ref_sign_bias);
-        add_candidate_mv(candidate_mvs, candidate_scores,
-                         &refmv_count, c2_refmv, ref_distance_weight[i]);
+        add_candidate_mv(mv_ref_list, candidate_scores,
+                         &refmv_count, c2_refmv, 1);
       }
     }
   }
@@ -280,13 +261,13 @@
 
     if (c_ref_frame != INTRA_FRAME) {
       scale_mv(xd, ref_frame, c_ref_frame, &c_refmv, ref_sign_bias);
-      add_candidate_mv(candidate_mvs, candidate_scores,
+      add_candidate_mv(mv_ref_list, candidate_scores,
                        &refmv_count, c_refmv, 1);
     }
 
     if (c2_ref_frame != INTRA_FRAME) {
       scale_mv(xd, ref_frame, c2_ref_frame, &c2_refmv, ref_sign_bias);
-      add_candidate_mv(candidate_mvs, candidate_scores,
+      add_candidate_mv(mv_ref_list, candidate_scores,
                        &refmv_count, c2_refmv, 1);
     }
   }
@@ -293,7 +274,7 @@
 
   // Define inter mode coding context.
   // 0,0 was best
-  if (candidate_mvs[0].as_int == 0) {
+  if (mv_ref_list[0].as_int == 0) {
     // 0,0 is only candidate
     if (refmv_count <= 1) {
       mbmi->mb_mode_context[ref_frame] = 0;
@@ -311,11 +292,8 @@
     mbmi->mb_mode_context[ref_frame] = candidate_scores[0] >= 16 ? 5 : 6;
   }
 
-  // Scan for 0,0 case and clamp non zero choices
+  // Clamp vectors
   for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) {
-    clamp_mv_ref(xd, &candidate_mvs[i]);
+    clamp_mv_ref(xd, &mv_ref_list[i]);
   }
-
-  // Copy over the candidate list.
-  vpx_memcpy(mv_ref_list, candidate_mvs, sizeof(candidate_mvs));
 }
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -684,11 +684,6 @@
     *sf0 = cm->active_ref_scale[mbmi->ref_frame - 1];
 
     {
-      const int use_prev_in_find_best_ref = sf0->x_num == sf0->x_den &&
-                                            sf0->y_num == sf0->y_den &&
-                                            !cm->error_resilient_mode &&
-                                            !cm->frame_parallel_decoding_mode;
-
       // Select the appropriate reference frame for this MB
       const int ref_fb_idx = cm->active_ref_idx[ref_frame - 1];
 
@@ -717,9 +712,6 @@
 
       if (mbmi->mode != ZEROMV) {
         vp9_find_best_ref_mvs(xd,
-                              use_prev_in_find_best_ref ? xd->pre.y_buffer
-                                                        : NULL,
-                              xd->pre.y_stride,
                               mbmi->ref_mvs[ref_frame],
                               &nearest, &nearby);
 
@@ -757,10 +749,6 @@
         const MV_REFERENCE_FRAME second_ref_frame = mbmi->second_ref_frame;
         struct scale_factors *sf1 = &xd->scale_factor[1];
         struct scale_factors *sf_uv1 = &xd->scale_factor_uv[1];
-        const int use_prev_in_find_best_ref = sf1->x_num == sf1->x_den &&
-                                              sf1->y_num == sf1->y_den &&
-                                              !cm->error_resilient_mode &&
-                                              !cm->frame_parallel_decoding_mode;
         const int second_ref_fb_idx = cm->active_ref_idx[second_ref_frame - 1];
         *sf1 = cm->active_ref_scale[second_ref_frame - 1];
 
@@ -774,9 +762,6 @@
 
         if (mbmi->mode != ZEROMV) {
           vp9_find_best_ref_mvs(xd,
-                                use_prev_in_find_best_ref ?
-                                    xd->second_pre.y_buffer : NULL,
-                                xd->second_pre.y_stride,
                                 mbmi->ref_mvs[second_ref_frame],
                                 &nearest_second,
                                 &nearby_second);
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -2692,7 +2692,7 @@
   YV12_BUFFER_CONFIG *yv12 = &cm->yv12_fb[cpi->common.ref_frame_map[idx]];
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
-  int use_prev_in_find_mv_refs, use_prev_in_find_best_ref;
+  int use_prev_in_find_mv_refs;
 
   // set up scaling factors
   scale[frame_type] = cpi->common.active_ref_scale[frame_type - 1];
@@ -2717,15 +2717,7 @@
                    cpi->common.ref_frame_sign_bias);
 
   // Candidate refinement carried out at encoder and decoder
-  use_prev_in_find_best_ref =
-      scale[frame_type].x_num == scale[frame_type].x_den &&
-      scale[frame_type].y_num == scale[frame_type].y_den &&
-      !cm->error_resilient_mode &&
-      !cm->frame_parallel_decoding_mode;
   vp9_find_best_ref_mvs(xd,
-                        use_prev_in_find_best_ref ?
-                            yv12_mb[frame_type].y_buffer : NULL,
-                        yv12->y_stride,
                         mbmi->ref_mvs[frame_type],
                         &frame_nearest_mv[frame_type],
                         &frame_near_mv[frame_type]);
--