resize-refacor: Remove changing of scale by rate control

This patch removes resize triggering by rate control and also removes
pending resizes causing recodes in encode_with_recode_loop. The removed
functionality will be replaced in the future, but it is simply being
removed for now to simplify the work to do.

Change-Id: Ia4a5840dcb463faab5aab1c08f640a7bcf5e6c5a
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 261d23b..90fc1c7 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3045,29 +3045,6 @@
     aom_extend_frame_borders(dst);
 }
 
-static int scale_down(AV1_COMP *cpi, int q) {
-  RATE_CONTROL *const rc = &cpi->rc;
-  GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-  int scale = 0;
-  assert(frame_is_kf_gf_arf(cpi));
-
-  if (cpi->resize_scale_num == cpi->resize_scale_den &&
-      q >= rc->rf_level_maxq[gf_group->rf_level[gf_group->index]]) {
-    const int old_num = cpi->resize_scale_num;
-    --cpi->resize_scale_num;
-    if (cpi->resize_scale_num <= 0) {
-      cpi->resize_scale_num = old_num;
-      return 0;
-    }
-    const int max_size_thresh =
-        (int)(av1_resize_rate_factor(cpi) *
-              AOMMAX(rc->this_frame_target, rc->avg_frame_bandwidth));
-    cpi->resize_scale_num = old_num;
-    scale = rc->projected_frame_size > max_size_thresh ? 1 : 0;
-  }
-  return scale;
-}
-
 #if CONFIG_GLOBAL_MOTION
 #define GM_RECODE_LOOP_NUM4X4_FACTOR 192
 static int recode_loop_test_global_motion(AV1_COMP *cpi) {
@@ -3104,13 +3081,6 @@
   if ((rc->projected_frame_size >= rc->max_frame_bandwidth) ||
       (cpi->sf.recode_loop == ALLOW_RECODE) ||
       (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) {
-    if (frame_is_kfgfarf && (oxcf->resize_mode == RESIZE_DYNAMIC) &&
-        scale_down(cpi, q)) {
-      // Code this group at a lower resolution.
-      cpi->resize_pending = 1;
-      return 1;
-    }
-
     // TODO(agrange) high_limit could be greater than the scale-down threshold.
     if ((rc->projected_frame_size > high_limit && q < maxq) ||
         (rc->projected_frame_size < low_limit && q > minq)) {
@@ -4310,27 +4280,9 @@
         int last_q = q;
 #if !CONFIG_XIPHRC
         int retries = 0;
-#endif
 
-        if (cpi->resize_pending == 1) {
-          // Change in frame size so go back around the recode loop.
-          // 11/16 is close to the old 2/3, then goes back to 16/16.
-          cpi->resize_scale_num -= 5;
-          if (cpi->resize_scale_num < 8 || cpi->resize_scale_num > 16)
-            cpi->resize_scale_num = 16;
-          cpi->resize_scale_den = 16;
-          cpi->resize_next_scale_num = cpi->resize_scale_num;
-          cpi->resize_next_scale_den = cpi->resize_scale_den;
+        // TODO(afergs): Replace removed recode when resize_pending is true
 
-#if CONFIG_INTERNAL_STATS
-          ++cpi->tot_recode_hits;
-#endif
-          ++loop_count;
-          loop = 1;
-          continue;
-        }
-
-#if !CONFIG_XIPHRC
         // Frame size out of permitted range:
         // Update correction factor & compute new Q to try...
         // Frame is too large
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index 8500b83..efca371 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -1509,10 +1509,7 @@
     target = calc_pframe_target_size_one_pass_cbr(cpi);
 
   av1_rc_set_frame_target(cpi, target);
-  if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC)
-    cpi->resize_pending = av1_resize_one_pass_cbr(cpi);
-  else
-    cpi->resize_pending = 0;
+  // TODO(afergs): Decide whether to scale up, down, or not at all
 }
 
 int av1_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget,
@@ -1678,90 +1675,3 @@
     vbr_rate_correction(cpi, &target_rate);
   av1_rc_set_frame_target(cpi, target_rate);
 }
-
-// Check if we should resize, based on average QP from past x frames.
-// Only allow for resize at most one scale down for now, scaling factor is 2.
-int av1_resize_one_pass_cbr(AV1_COMP *cpi) {
-  const AV1_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  int resize_now = 0;
-  cpi->resize_scale_num = 1;
-  cpi->resize_scale_den = 1;
-  // Don't resize on key frame; reset the counters on key frame.
-  if (cm->frame_type == KEY_FRAME) {
-    cpi->resize_avg_qp = 0;
-    cpi->resize_count = 0;
-    return 0;
-  }
-  // Resize based on average buffer underflow and QP over some window.
-  // Ignore samples close to key frame, since QP is usually high after key.
-  if (cpi->rc.frames_since_key > 2 * cpi->framerate) {
-    const int window = (int)(5 * cpi->framerate);
-    cpi->resize_avg_qp += cm->base_qindex;
-    if (cpi->rc.buffer_level < (int)(30 * rc->optimal_buffer_level / 100))
-      ++cpi->resize_buffer_underflow;
-    ++cpi->resize_count;
-    // Check for resize action every "window" frames.
-    if (cpi->resize_count >= window) {
-      int avg_qp = cpi->resize_avg_qp / cpi->resize_count;
-      // Resize down if buffer level has underflowed sufficent amount in past
-      // window, and we are at original resolution.
-      // Resize back up if average QP is low, and we are currently in a resized
-      // down state.
-      if (cpi->resize_state == 0 &&
-          cpi->resize_buffer_underflow > (cpi->resize_count >> 2)) {
-        resize_now = 1;
-        cpi->resize_state = 1;
-      } else if (cpi->resize_state == 1 &&
-                 avg_qp < 40 * cpi->rc.worst_quality / 100) {
-        resize_now = -1;
-        cpi->resize_state = 0;
-      }
-      // Reset for next window measurement.
-      cpi->resize_avg_qp = 0;
-      cpi->resize_count = 0;
-      cpi->resize_buffer_underflow = 0;
-    }
-  }
-  // If decision is to resize, reset some quantities, and check is we should
-  // reduce rate correction factor,
-  if (resize_now != 0) {
-    int target_bits_per_frame;
-    int active_worst_quality;
-    int qindex;
-    int tot_scale_change;
-    // For now, resize is by 1/2 x 1/2.
-    cpi->resize_scale_num = 1;
-    cpi->resize_scale_den = 2;
-    tot_scale_change = (cpi->resize_scale_den * cpi->resize_scale_den) /
-                       (cpi->resize_scale_num * cpi->resize_scale_num);
-    // Reset buffer level to optimal, update target size.
-    rc->buffer_level = rc->optimal_buffer_level;
-    rc->bits_off_target = rc->optimal_buffer_level;
-    rc->this_frame_target = calc_pframe_target_size_one_pass_cbr(cpi);
-    // Reset cyclic refresh parameters.
-    if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled)
-      av1_cyclic_refresh_reset_resize(cpi);
-    // Get the projected qindex, based on the scaled target frame size (scaled
-    // so target_bits_per_mb in av1_rc_regulate_q will be correct target).
-    target_bits_per_frame = (resize_now == 1)
-                                ? rc->this_frame_target * tot_scale_change
-                                : rc->this_frame_target / tot_scale_change;
-    active_worst_quality = calc_active_worst_quality_one_pass_cbr(cpi);
-    qindex = av1_rc_regulate_q(cpi, target_bits_per_frame, rc->best_quality,
-                               active_worst_quality);
-    // If resize is down, check if projected q index is close to worst_quality,
-    // and if so, reduce the rate correction factor (since likely can afford
-    // lower q for resized frame).
-    if (resize_now == 1 && qindex > 90 * cpi->rc.worst_quality / 100) {
-      rc->rate_correction_factors[INTER_NORMAL] *= 0.85;
-    }
-    // If resize is back up, check if projected q index is too much above the
-    // current base_qindex, and if so, reduce the rate correction factor
-    // (since prefer to keep q for resized frame at least close to previous q).
-    if (resize_now == -1 && qindex > 130 * cm->base_qindex / 100) {
-      rc->rate_correction_factors[INTER_NORMAL] *= 0.9;
-    }
-  }
-  return resize_now;
-}