AV1 RT: limit increased VBP thresholds for high QP

On midres there are several outliers in speed9 quality comapring to
speed 8. Mostly content with high quality. Limiting larger block size to
higher QPs will allow to maintain good quality onthose clips
Overall BDRate difference in speed9 vs speed8 on RTC set is 8% compared
to previous 12%. Still maintaining 10-30% speed up.

Change-Id: I617220e44e4fcde33bf35c0d137edb14d4a6f22b
diff --git a/av1/encoder/var_based_part.c b/av1/encoder/var_based_part.c
index b446430..59ee3d3 100644
--- a/av1/encoder/var_based_part.c
+++ b/av1/encoder/var_based_part.c
@@ -349,6 +349,7 @@
   int64_t threshold_base =
       (int64_t)(threshold_multiplier *
                 cpi->enc_quant_dequant_params.dequants.y_dequant_QTX[q][1]);
+  const int current_qindex = cm->quant_params.base_qindex;
 
   if (is_key_frame) {
     thresholds[0] = threshold_base;
@@ -379,19 +380,18 @@
     if (cm->width >= 1280 && cm->height >= 720)
       thresholds[3] = thresholds[3] << 1;
     if (cm->width * cm->height <= 352 * 288) {
-      int last_qindex = cpi->rc.last_q[INTER_FRAME];
-      if (last_qindex >= QINDEX_HIGH_THR) {
+      if (current_qindex >= QINDEX_HIGH_THR) {
         threshold_base = (5 * threshold_base) >> 1;
         thresholds[1] = threshold_base >> 3;
         thresholds[2] = threshold_base << 2;
         thresholds[3] = threshold_base << 5;
-      } else if (last_qindex < QINDEX_LOW_THR) {
+      } else if (current_qindex < QINDEX_LOW_THR) {
         thresholds[1] = threshold_base >> 3;
         thresholds[2] = threshold_base >> 1;
         thresholds[3] = threshold_base << 3;
       } else {
-        int64_t qi_diff_low = last_qindex - QINDEX_LOW_THR;
-        int64_t qi_diff_high = QINDEX_HIGH_THR - last_qindex;
+        int64_t qi_diff_low = current_qindex - QINDEX_LOW_THR;
+        int64_t qi_diff_high = QINDEX_HIGH_THR - current_qindex;
         int64_t threshold_diff = QINDEX_HIGH_THR - QINDEX_LOW_THR;
         int64_t threshold_base_high = (5 * threshold_base) >> 1;
 
@@ -415,9 +415,12 @@
       thresholds[2] = (5 * threshold_base) >> 1;
     }
     if (cpi->sf.rt_sf.force_large_partition_blocks) {
-      thresholds[1] <<= 2;
-      thresholds[2] <<= 5;
-      thresholds[3] = INT32_MAX;
+      if (current_qindex > QINDEX_LARGE_BLOCK_THR ||
+          cm->width * cm->height <= 352 * 288) {
+        thresholds[1] <<= 2;
+        thresholds[2] <<= 5;
+        thresholds[3] = INT32_MAX;
+      }
     }
   }
 }
diff --git a/av1/encoder/var_based_part.h b/av1/encoder/var_based_part.h
index e6f8209..8067bf5 100644
--- a/av1/encoder/var_based_part.h
+++ b/av1/encoder/var_based_part.h
@@ -30,6 +30,9 @@
 #define QINDEX_HIGH_THR \
   220  // Use high qindex variance partition thresholds when qindex is above
        // this threshold
+#define QINDEX_LARGE_BLOCK_THR \
+  100  // Use increased thresholds for midres for speed 9 when qindex is above
+       // this threshold
 
 /*!\brief Set the thresholds for variance based partition.
  *