Merge "Update VP9_PROB_COST_SHIFT to VP10_PROB_COST_SHIFT" into nextgenv2
diff --git a/vp10/encoder/encoder.c b/vp10/encoder/encoder.c
index caac3ee..3f28008 100644
--- a/vp10/encoder/encoder.c
+++ b/vp10/encoder/encoder.c
@@ -283,8 +283,16 @@
   if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
     vp10_setup_past_independence(cm);
   } else {
+#if CONFIG_EXT_REFS
+    const GF_GROUP *gf_group = &cpi->twopass.gf_group;
+    if (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)
+      cm->frame_context_idx = EXT_ARF_FRAME;
+    else if (cpi->refresh_alt_ref_frame)
+      cm->frame_context_idx = ARF_FRAME;
+#else
     if (cpi->refresh_alt_ref_frame)
       cm->frame_context_idx = ARF_FRAME;
+#endif
     else if (cpi->rc.is_src_frame_alt_ref)
       cm->frame_context_idx = OVERLAY_FRAME;
     else if (cpi->refresh_golden_frame)
diff --git a/vp10/encoder/encoder.h b/vp10/encoder/encoder.h
index fca8b6f..b1b5855 100644
--- a/vp10/encoder/encoder.h
+++ b/vp10/encoder/encoder.h
@@ -81,6 +81,8 @@
 #if CONFIG_EXT_REFS
   // backward reference frame
   BRF_FRAME = 4,
+  // extra alternate reference frame
+  EXT_ARF_FRAME = 5
 #endif
 } FRAME_CONTEXT_INDEX;
 
diff --git a/vp10/encoder/rdopt.c b/vp10/encoder/rdopt.c
index 4249a67..624b10c 100644
--- a/vp10/encoder/rdopt.c
+++ b/vp10/encoder/rdopt.c
@@ -4978,6 +4978,10 @@
           MV mvp_full;
           int max_mv;
           int cost_list[5];
+          int tmp_col_min = x->mv_col_min;
+          int tmp_col_max = x->mv_col_max;
+          int tmp_row_min = x->mv_row_min;
+          int tmp_row_max = x->mv_row_max;
 
           /* Is the best so far sufficiently good that we cant justify doing
            * and new motion search. */
@@ -5041,6 +5045,11 @@
               cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL,
               &bsi->ref_mv[0]->as_mv, INT_MAX, 1);
 
+          x->mv_col_min = tmp_col_min;
+          x->mv_col_max = tmp_col_max;
+          x->mv_row_min = tmp_row_min;
+          x->mv_row_max = tmp_row_max;
+
           if (bestsme < INT_MAX) {
             int distortion;
             if (cpi->sf.use_upsampled_references) {
@@ -5722,8 +5731,6 @@
     vp10_setup_pre_planes(xd, ref_idx, scaled_ref_frame, mi_row, mi_col, NULL);
   }
 
-  vp10_set_mv_search_range(x, &ref_mv);
-
   // Work out the size of the first step in the mv step search.
   // 0 here is maximum length first step. 1 is VPXMAX >> 1 etc.
   if (cpi->sf.mv.auto_mv_step_size && cm->show_frame) {
@@ -5771,6 +5778,8 @@
     }
   }
 
+  vp10_set_mv_search_range(x, &ref_mv);
+
   mvp_full = pred_mv[x->mv_best_ref_index[ref]];
 
   mvp_full.col >>= 3;
@@ -5918,8 +5927,6 @@
     vp10_setup_pre_planes(xd, ref_idx, scaled_ref_frame, mi_row, mi_col, NULL);
   }
 
-  vp10_set_mv_search_range(x, &ref_mv);
-
   // Work out the size of the first step in the mv step search.
   // 0 here is maximum length first step. 1 is VPXMAX >> 1 etc.
   if (cpi->sf.mv.auto_mv_step_size && cm->show_frame) {
@@ -5967,6 +5974,8 @@
     }
   }
 
+  vp10_set_mv_search_range(x, &ref_mv);
+
   mvp_full = pred_mv.as_mv;
   mvp_full.col >>= 3;
   mvp_full.row >>= 3;