Upsample reference frames after size dependent speed features are calculated.

This prevents a crash if the upsample_refs speed feature is
changed as part of set_size_dependent_vars, when the recode
loop is enabled.

Change-Id: I645e389bfe961879dd2001439a34fde2993868d9
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 34ca12f..0b6410a 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3194,12 +3194,6 @@
 
   set_size_independent_vars(cpi);
 
-  // cpi->sf.use_upsampled_references can be different from frame to frame.
-  // Every time when cpi->sf.use_upsampled_references is changed from 0 to 1.
-  // The reference frames for this frame have to be up-sampled before encoding.
-  if (!use_upsampled_ref && cpi->sf.use_upsampled_references)
-    reset_use_upsampled_references(cpi);
-
   do {
     aom_clear_system_state();
 
@@ -3208,6 +3202,14 @@
     if (loop_count == 0 || cpi->resize_pending != 0) {
       set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
 
+      // cpi->sf.use_upsampled_references can be different from frame to frame.
+      // Every time when cpi->sf.use_upsampled_references is changed from 0 to
+      // 1.
+      // The reference frames for this frame have to be up-sampled before
+      // encoding.
+      if (!use_upsampled_ref && cpi->sf.use_upsampled_references)
+        reset_use_upsampled_references(cpi);
+
       // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed.
       set_mv_search_params(cpi);