shithub: libvpx

Download patch

ref: 9f3ab83486e5259293b8074600019d4e38f3eae2
parent: 689957e3ad60b46ec8e22665f0d95d03c50f100e
author: Paul Wilkins <paulwilkins@google.com>
date: Wed Jun 26 13:06:25 EDT 2013

Auto adapt step size feature.

Also tweaks to other features and experiments with
what is on and off at different speed settings.

Change-Id: I3e1d0be0d195216bf17c2ac5df67f34ce0b306b2

--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -754,11 +754,11 @@
 #ifdef ENTROPY_STATS
             active_section = 11;
 #endif
-            vp9_encode_mv(bc, &blockmv.as_mv, &mi->best_mv.as_mv,
+            vp9_encode_mv(cpi, bc, &blockmv.as_mv, &mi->best_mv.as_mv,
                           nmvc, xd->allow_high_precision_mv);
 
             if (mi->ref_frame[1] > INTRA_FRAME)
-              vp9_encode_mv(bc,
+              vp9_encode_mv(cpi, bc,
                             &cpi->mb.partition_info->bmi[j].second_mv.as_mv,
                             &mi->best_second_mv.as_mv,
                             nmvc, xd->allow_high_precision_mv);
@@ -769,12 +769,12 @@
 #ifdef ENTROPY_STATS
       active_section = 5;
 #endif
-      vp9_encode_mv(bc,
+      vp9_encode_mv(cpi, bc,
                     &mi->mv[0].as_mv, &mi->best_mv.as_mv,
                     nmvc, xd->allow_high_precision_mv);
 
       if (mi->ref_frame[1] > INTRA_FRAME)
-        vp9_encode_mv(bc,
+        vp9_encode_mv(cpi, bc,
                       &mi->mv[1].as_mv, &mi->best_second_mv.as_mv,
                       nmvc, xd->allow_high_precision_mv);
     }
--- a/vp9/encoder/vp9_encodemv.c
+++ b/vp9/encoder/vp9_encodemv.c
@@ -591,7 +591,8 @@
   }
 }
 
-void vp9_encode_mv(vp9_writer* w, const MV* mv, const MV* ref,
+void vp9_encode_mv(VP9_COMP* cpi, vp9_writer* w,
+                   const MV* mv, const MV* ref,
                    const nmv_context* mvctx, int usehp) {
   const MV diff = {mv->row - ref->row,
                    mv->col - ref->col};
@@ -604,6 +605,13 @@
 
   if (mv_joint_horizontal(j))
     encode_mv_component(w, diff.col, &mvctx->comps[1], usehp);
+
+  // If auto_mv_step_size is enabled and it is an arf/non shown frame
+  // then keep track of the largest motion vector component used.
+  if (cpi->sf.auto_mv_step_size && !cpi->common.show_frame) {
+    cpi->max_mv_magnitude = MAX((MAX(abs(mv->row), abs(mv->col)) >> 3),
+                                cpi->max_mv_magnitude);
+  }
 }
 
 void vp9_build_nmv_cost_table(int *mvjoint,
--- a/vp9/encoder/vp9_encodemv.h
+++ b/vp9/encoder/vp9_encodemv.h
@@ -16,7 +16,7 @@
 
 void vp9_write_nmv_probs(VP9_COMP* const, int usehp, vp9_writer* const);
 
-void vp9_encode_mv(vp9_writer* w, const MV* mv, const MV* ref,
+void vp9_encode_mv(VP9_COMP *cpi, vp9_writer* w, const MV* mv, const MV* ref,
                    const nmv_context* mvctx, int usehp);
 
 void vp9_build_nmv_cost_table(int *mvjoint,
--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -41,6 +41,9 @@
 int vp9_init_search_range(VP9_COMP *cpi, int size) {
   int sr = 0;
 
+  // Minimum search size no matter what the passed in value.
+  size = MAX(16, size);
+
   while ((size << sr) < MAX_FULL_PEL_VAL)
     sr++;
 
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -671,6 +671,12 @@
     cpi->mode_chosen_counts[i] = 0;
   }
 
+  // Initialize cpi->max_mv_magnitude if appropriate.
+  if ((cpi->common.frame_type == KEY_FRAME) || cpi->common.intra_only ||
+    (cpi->common.show_frame == 0)) {
+    cpi->max_mv_magnitude = 0;
+  }
+
   // best quality defaults
   sf->RD = 1;
   sf->search_method = NSTEP;
@@ -681,6 +687,7 @@
   sf->iterative_sub_pixel = 1;
   sf->optimize_coefficients = !cpi->oxcf.lossless;
   sf->reduce_first_step_size = 0;
+  sf->auto_mv_step_size = 0;
   sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
   sf->comp_inter_joint_search_thresh = BLOCK_SIZE_AB4X4;
   sf->adpative_rd_thresh = 0;
@@ -716,35 +723,36 @@
 #else
       sf->static_segmentation = 0;
 #endif
-      sf->comp_inter_joint_search_thresh = BLOCK_SIZE_SB8X8;
+      sf->comp_inter_joint_search_thresh = BLOCK_SIZE_MB16X16;
+      sf->auto_mv_step_size = 1;
+      sf->use_avoid_tested_higherror = 1;
       sf->adpative_rd_thresh = 1;
+
       if (speed == 1) {
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
-        sf->optimize_coefficients = 0;
-        sf->reduce_first_step_size = 1;
-        sf->use_avoid_tested_higherror = 1;
-        sf->adjust_thresholds_by_speed = 1;
         sf->use_largest_txform = !(cpi->common.frame_type == KEY_FRAME ||
                                    cpi->common.intra_only ||
                                    cpi->common.show_frame == 0);
       }
       if (speed == 2) {
-        sf->comp_inter_joint_search_thresh = BLOCK_SIZE_SB8X8;
+        sf->adjust_thresholds_by_speed = 1;
+        sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
+        sf->reduce_first_step_size = 1;
+        sf->optimize_coefficients = 0;
         sf->use_lastframe_partitioning = 1;
-        sf->reduce_first_step_size = 0;
       }
       if (speed == 3) {
-        sf->comp_inter_joint_search_thresh = BLOCK_SIZE_SB8X8;
+        sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
         sf->partition_by_variance = 1;
-        sf->reduce_first_step_size = 0;
+        sf->reduce_first_step_size = 1;
       }
       if (speed == 4) {
-        sf->reduce_first_step_size = 0;
-        sf->comp_inter_joint_search_thresh = BLOCK_SIZE_SB8X8;
+        sf->reduce_first_step_size = 1;
+        sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
         sf->use_one_partition_size_always = 1;
         sf->always_this_block_size = BLOCK_SIZE_MB16X16;
       }
-      if (speed == 2) {
+/*      if (speed == 2) {
         sf->reduce_first_step_size = 0;
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_SB8X8;
         sf->use_partitions_less_than = 1;
@@ -755,7 +763,7 @@
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_SB8X8;
         sf->use_partitions_greater_than = 1;
         sf->greater_than_block_size = BLOCK_SIZE_SB8X8;
-      }
+      }*/
 
      break;
 
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -211,6 +211,7 @@
   int thresh_mult[MAX_MODES];
   int max_step_search_steps;
   int reduce_first_step_size;
+  int auto_mv_step_size;
   int optimize_coefficients;
   int search_best_filter;
   int static_segmentation;
@@ -470,6 +471,8 @@
 
   SPEED_FEATURES sf;
   int error_bins[1024];
+
+  unsigned int max_mv_magnitude;
 
   // Data used for real time conferencing mode to help determine if it would be good to update the gf
   int inter_zz_count;
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -228,7 +228,10 @@
         }
         cpi->rd_baseline_thresh[bsize][i] = cpi->rd_threshes[bsize][i];
 
-        cpi->rd_thresh_freq_fact[bsize][i] = MAX_RD_THRESH_FREQ_FACT;
+        if (cpi->sf.adpative_rd_thresh)
+          cpi->rd_thresh_freq_fact[bsize][i] = MAX_RD_THRESH_FREQ_FACT;
+        else
+          cpi->rd_thresh_freq_fact[bsize][i] = BASE_RD_THRESH_FREQ_FACT;
       }
     }
   } else {
@@ -248,7 +251,11 @@
           cpi->rd_threshes[bsize][i] = INT_MAX;
         }
         cpi->rd_baseline_thresh[bsize][i] = cpi->rd_threshes[bsize][i];
-        cpi->rd_thresh_freq_fact[bsize][i] = MAX_RD_THRESH_FREQ_FACT;
+
+        if (cpi->sf.adpative_rd_thresh)
+          cpi->rd_thresh_freq_fact[bsize][i] = MAX_RD_THRESH_FREQ_FACT;
+        else
+          cpi->rd_thresh_freq_fact[bsize][i] = BASE_RD_THRESH_FREQ_FACT;
       }
     }
   }
@@ -2018,8 +2025,14 @@
 
   vp9_clamp_mv_min_max(x, &ref_mv);
 
-  step_param = vp9_init_search_range(
-                 cpi, MIN(cpi->common.width, cpi->common.height));
+  // Work out the size of the first step in the mv step search.
+  // 0 here is maximum length first step. 1 is MAX >> 1 etc.
+  if (cpi->sf.auto_mv_step_size && cpi->common.show_frame) {
+    step_param = vp9_init_search_range(cpi, cpi->max_mv_magnitude);
+  } else {
+    step_param = vp9_init_search_range(
+                   cpi, MIN(cpi->common.width, cpi->common.height));
+  }
 
   // mvp_full.as_int = ref_mv[0].as_int;
   mvp_full.as_int =