shithub: libvpx

Download patch

ref: d432f7e3cbaca3ca547fef71ec3216fdccf9b0c9
parent: dce0896249b9d3eebb52522beeebba00eface3b8
author: Daniel Kang <ddkang@google.com>
date: Tue Aug 7 12:44:26 EDT 2012

Some refactoring of mcomp functions.

Change-Id: Ic7a7cb1199b085e98ede0e634619b3077c348d57

--- a/vp8/encoder/mcomp.c
+++ b/vp8/encoder/mcomp.c
@@ -1249,20 +1249,11 @@
 #undef CHECK_POINT
 #undef CHECK_BETTER
 
-int vp8_diamond_search_sad
-(
-  MACROBLOCK *x,
-  BLOCK *b,
-  BLOCKD *d,
-  int_mv *ref_mv,
-  int_mv *best_mv,
-  int search_param,
-  int sad_per_bit,
-  int *num00,
-  vp8_variance_fn_ptr_t *fn_ptr,
-  int *mvcost[2],
-  int_mv *center_mv
-) {
+int vp8_diamond_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
+                           int_mv *ref_mv, int_mv *best_mv,
+                           int search_param, int sad_per_bit, int *num00,
+                           vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2],
+                           int_mv *center_mv) {
   int i, j, step;
 
   unsigned char *what = (*(b->base_src) + b->src);
@@ -1278,10 +1269,8 @@
   int best_site = 0;
   int last_site = 0;
 
-  int ref_row;
-  int ref_col;
-  int this_row_offset;
-  int this_col_offset;
+  int ref_row, ref_col;
+  int this_row_offset, this_col_offset;
   search_site *ss;
 
   unsigned char *check_here;
@@ -1372,20 +1361,11 @@
                   xd->allow_high_precision_mv);
 }
 
-int vp8_diamond_search_sadx4
-(
-  MACROBLOCK *x,
-  BLOCK *b,
-  BLOCKD *d,
-  int_mv *ref_mv,
-  int_mv *best_mv,
-  int search_param,
-  int sad_per_bit,
-  int *num00,
-  vp8_variance_fn_ptr_t *fn_ptr,
-  int *mvcost[2],
-  int_mv *center_mv
-) {
+int vp8_diamond_search_sadx4(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
+                             int_mv *ref_mv, int_mv *best_mv, int search_param,
+                             int sad_per_bit, int *num00,
+                             vp8_variance_fn_ptr_t *fn_ptr,
+                             int *mvcost[2], int_mv *center_mv) {
   int i, j, step;
 
   unsigned char *what = (*(b->base_src) + b->src);
@@ -1526,6 +1506,49 @@
                  (unsigned int *)(&thissad)) +
       mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit,
                   xd->allow_high_precision_mv);
+}
+
+#define XMVCOST (x->e_mbd.allow_high_precision_mv?x->mvcost_hp:x->mvcost)
+int vp8_full_pixel_diamond(VP8_COMP *cpi, MACROBLOCK *x, BLOCK *b,
+                           BLOCKD *d, int_mv *mvp_full, int step_param,
+                           int sadpb, int further_steps,
+                           int *do_refine, vp8_variance_fn_ptr_t *fn_ptr,
+                           int_mv *ref_mv, int_mv *dst_mv) {
+  int_mv temp_mv;
+  int thissme, n, num00;
+  int bestsme = cpi->diamond_search_sad(x, b, d, mvp_full, &temp_mv,
+                                        step_param, sadpb, &num00,
+                                        fn_ptr, XMVCOST, ref_mv);
+  dst_mv->as_int = temp_mv.as_int;
+
+  n = num00;
+  num00 = 0;
+
+  /* If there won't be more n-step search, check to see if refining search is needed. */
+  if (n > further_steps)
+    *do_refine = 0;
+
+  while (n < further_steps) {
+    n++;
+
+    if (num00)
+      num00--;
+    else {
+      thissme = cpi->diamond_search_sad(x, b, d, mvp_full, &temp_mv,
+                                        step_param + n, sadpb, &num00,
+                                        fn_ptr, XMVCOST, ref_mv);
+
+      /* check to see if refining search is needed. */
+      if (num00 > (further_steps - n))
+        *do_refine = 0;
+
+      if (thissme < bestsme) {
+        bestsme = thissme;
+        dst_mv->as_int = temp_mv.as_int;
+      }
+    }
+  }
+  return bestsme;
 }
 
 int vp8_full_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
--- a/vp8/encoder/mcomp.h
+++ b/vp8/encoder/mcomp.h
@@ -30,7 +30,13 @@
                            int Weight, int ishp);
 extern void vp8_init_dsmotion_compensation(MACROBLOCK *x, int stride);
 extern void vp8_init3smotion_compensation(MACROBLOCK *x,  int stride);
-
+// Runs sequence of diamond searches in smaller steps for RD
+struct VP8_COMP;
+int vp8_full_pixel_diamond(struct VP8_COMP *cpi, MACROBLOCK *x, BLOCK *b,
+                           BLOCKD *d, int_mv *mvp_full, int step_param,
+                           int sadpb, int further_steps, int *do_refine,
+                           vp8_variance_fn_ptr_t *fn_ptr,
+                           int_mv *ref_mv, int_mv *dst_mv);
 
 extern int vp8_hex_search
 (
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -1818,11 +1818,10 @@
 
       // motion search for newmv (single predictor case only)
       if (!x->e_mbd.mode_info_context->mbmi.second_ref_frame && this_mode == NEW4X4) {
-        int sseshift, num00, n;
+        int sseshift, n;
         int step_param = 0;
         int further_steps;
         int thissme, bestsme = INT_MAX;
-        int_mv  temp_mv;
         BLOCK *c;
         BLOCKD *e;
 
@@ -1851,6 +1850,7 @@
         further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
 
         {
+          int dummy;
           int sadpb = x->sadperbit4;
           int_mv mvp_full;
 
@@ -1863,37 +1863,12 @@
           c = &x->block[n];
           e = &x->e_mbd.block[n];
 
-          {
-            bestsme = cpi->diamond_search_sad(x, c, e, &mvp_full,
-                                              &mode_mv[NEW4X4], step_param,
-                                              sadpb, &num00, v_fn_ptr,
-                                              XMVCOST,
-                                              bsi->ref_mv);
+          // dummy takes the place of do_refine -- which is used in other places
+          bestsme = vp8_full_pixel_diamond(cpi, x, c, e, &mvp_full,
+                                           step_param, sadpb, further_steps,
+                                           &dummy, v_fn_ptr, bsi->ref_mv,
+                                           &mode_mv[NEW4X4]);
 
-            n = num00;
-            num00 = 0;
-
-            while (n < further_steps) {
-              n++;
-
-              if (num00)
-                num00--;
-              else {
-                thissme = cpi->diamond_search_sad(x, c, e,
-                                                  &mvp_full, &temp_mv,
-                                                  step_param + n, sadpb,
-                                                  &num00, v_fn_ptr,
-                                                  XMVCOST,
-                                                  bsi->ref_mv);
-
-                if (thissme < bestsme) {
-                  bestsme = thissme;
-                  mode_mv[NEW4X4].as_int = temp_mv.as_int;
-                }
-              }
-            }
-          }
-
           sseshift = segmentation_to_sseshift[segmentation];
 
           // Should we do a full search (best quality only)
@@ -2664,8 +2639,7 @@
   int_mv best_ref_mv, second_best_ref_mv;
   int_mv mode_mv[MB_MODE_COUNT];
   MB_PREDICTION_MODE this_mode;
-  int num00, i;
-  int best_mode_index = 0;
+  int i, best_mode_index = 0;
   int mode8x8[2][4];
   unsigned char segment_id = xd->mode_info_context->mbmi.segment_id;
 
@@ -3117,7 +3091,6 @@
           int thissme, bestsme = INT_MAX;
           int step_param = cpi->sf.first_step;
           int further_steps;
-          int n;
           int do_refine = 1;   /* If last step (1-away) of n-step search doesn't pick the center point as the best match,
                                 we will do a final 1-away diamond refining search  */
 
@@ -3146,48 +3119,14 @@
           if (sr > step_param)
             step_param = sr;
 
-          // Initial step/diamond search
-          {
-            bestsme = cpi->diamond_search_sad(x, b, d, &mvp_full, &d->bmi.as_mv.first,
-                                              step_param, sadpb, &num00,
-                                              &cpi->fn_ptr[BLOCK_16X16],
-                                              XMVCOST, &best_ref_mv);
-            mode_mv[NEWMV].as_int = d->bmi.as_mv.first.as_int;
+          // Further step/diamond searches as necessary
+          further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
 
-            // Further step/diamond searches as necessary
-            further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
-
-            n = num00;
-            num00 = 0;
-
-            /* If there won't be more n-step search, check to see if refining search is needed. */
-            if (n > further_steps)
-              do_refine = 0;
-
-            while (n < further_steps) {
-              n++;
-
-              if (num00)
-                num00--;
-              else {
-                thissme = cpi->diamond_search_sad(x, b, d, &mvp_full,
-                                                  &d->bmi.as_mv.first, step_param + n, sadpb, &num00,
-                                                  &cpi->fn_ptr[BLOCK_16X16],
-                                                  XMVCOST, &best_ref_mv);
-
-                /* check to see if refining search is needed. */
-                if (num00 > (further_steps - n))
-                  do_refine = 0;
-
-                if (thissme < bestsme) {
-                  bestsme = thissme;
-                  mode_mv[NEWMV].as_int = d->bmi.as_mv.first.as_int;
-                } else {
-                  d->bmi.as_mv.first.as_int = mode_mv[NEWMV].as_int;
-                }
-              }
-            }
-          }
+          bestsme = vp8_full_pixel_diamond(cpi, x, b, d, &mvp_full, step_param, sadpb,
+                                 further_steps, &do_refine,
+                                 &cpi->fn_ptr[BLOCK_16X16], &best_ref_mv,
+                                 &mode_mv[NEWMV]);
+          d->bmi.as_mv.first.as_int = mode_mv[NEWMV].as_int;
 
           /* final 1-away diamond refining search */
           if (do_refine == 1) {