Add speed feature for gm parameter selection threshold

This controls the threshold for accepting a global motion model.
Being more selective with the warping error threshold causes the
recode loop to be triggered fewer times. We observe the following
speedups:

Speed 0: 16% speedup, no loss in quality on cam_lowres
Speed 1: 20% speedup, 0.07% loss in quality on cam_lowres
Speed 2: 37% speedup, 0.113% loss in quality on cam_lowres

Change-Id: Ie82ecfa035122feaa76f05588b348ace2c01ff6b
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 14b61f7..fd841a8 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -4345,7 +4345,8 @@
           if (!is_enough_erroradvantage(
                   (double)best_warp_error / ref_frame_error,
                   gm_get_params_cost(&cm->global_motion[frame], ref_params,
-                                     cm->allow_high_precision_mv))) {
+                                     cm->allow_high_precision_mv),
+                  cpi->sf.gm_erroradv_type)) {
             cm->global_motion[frame] = default_warp_params;
           }
           if (cm->global_motion[frame].wmtype != IDENTITY) break;
diff --git a/av1/encoder/global_motion.c b/av1/encoder/global_motion.c
index 040e35d..f396479 100644
--- a/av1/encoder/global_motion.c
+++ b/av1/encoder/global_motion.c
@@ -32,11 +32,21 @@
 // Border over which to compute the global motion
 #define ERRORADV_BORDER 0
 
-#define ERRORADV_MAX_THRESH 0.995
+#define ERRORADV_MAX_THRESH_0 0.75
+#define ERRORADV_MAX_THRESH_1 0.70
+#define ERRORADV_MAX_THRESH_2 0.65
 #define ERRORADV_COST_PRODUCT_THRESH 26000
 
-int is_enough_erroradvantage(double best_erroradvantage, int params_cost) {
-  return best_erroradvantage < ERRORADV_MAX_THRESH &&
+int is_enough_erroradvantage(double best_erroradvantage, int params_cost,
+                             int erroradv_type) {
+  double erroradv_tr = 0;
+  switch (erroradv_type) {
+    case GM_ERRORADV_TR_0: erroradv_tr = ERRORADV_MAX_THRESH_0; break;
+    case GM_ERRORADV_TR_1: erroradv_tr = ERRORADV_MAX_THRESH_1; break;
+    case GM_ERRORADV_TR_2: erroradv_tr = ERRORADV_MAX_THRESH_2; break;
+    default: assert(0 && "Invalid ERRORADV Type"); return 0;
+  }
+  return best_erroradvantage < erroradv_tr &&
          best_erroradvantage * params_cost < ERRORADV_COST_PRODUCT_THRESH;
 }
 
diff --git a/av1/encoder/global_motion.h b/av1/encoder/global_motion.h
index 59419cd..2c15753 100644
--- a/av1/encoder/global_motion.h
+++ b/av1/encoder/global_motion.h
@@ -24,7 +24,8 @@
 
 void convert_model_to_params(const double *params, WarpedMotionParams *model);
 
-int is_enough_erroradvantage(double erroradv, int params_cost);
+int is_enough_erroradvantage(double best_erroradvantage, int params_cost,
+                             int erroradv_type);
 
 // Returns the av1_warp_error between "dst" and the result of applying the
 // motion params that result from fine-tuning "wm" to "ref". Note that "wm" is
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index b2f1391..072b8e7 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -142,6 +142,7 @@
   sf->reduce_inter_modes = 1;
 
   if (speed >= 1) {
+    sf->gm_erroradv_type = GM_ERRORADV_TR_1;
     sf->selective_ref_frame = 1;
     sf->tx_size_search_init_depth_rect = 1;
     sf->tx_size_search_init_depth_sqr = 1;
@@ -158,6 +159,7 @@
   }
 
   if (speed >= 2) {
+    sf->gm_erroradv_type = GM_ERRORADV_TR_2;
     sf->tx_size_search_method = USE_FAST_RD;
     sf->tx_type_search.fast_intra_tx_type_search = 1;
     sf->tx_type_search.fast_inter_tx_type_search = 1;
@@ -399,6 +401,7 @@
   else
     sf->optimize_coefficients = FULL_TRELLIS_OPT;
 #endif  // DISABLE_TRELLISQ_SEARCH
+  sf->gm_erroradv_type = GM_ERRORADV_TR_0;
   sf->mv.reduce_first_step_size = 0;
   sf->coeff_prob_appx_step = 1;
   sf->mv.auto_mv_step_size = 0;
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index 4867c37..6d82381 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -279,6 +279,12 @@
 } GM_SEARCH_TYPE;
 
 typedef enum {
+  GM_ERRORADV_TR_0,
+  GM_ERRORADV_TR_1,
+  GM_ERRORADV_TR_2,
+} GM_ERRORADV_TYPE;
+
+typedef enum {
   NO_TRELLIS_OPT,         // No trellis optimization
   FULL_TRELLIS_OPT,       // Trellis optimization in all stages
   FINAL_PASS_TRELLIS_OPT  // Trellis optimization in only the final encode pass
@@ -300,6 +306,9 @@
   // Trellis (dynamic programming) optimization of quantized values
   TRELLIS_OPT_TYPE optimize_coefficients;
 
+  // Global motion warp error threshold
+  GM_ERRORADV_TYPE gm_erroradv_type;
+
   // Always set to 0. If on it enables 0 cost background transmission
   // (except for the initial transmission of the segmentation). The feature is
   // disabled because the addition of very large block sizes make the