rtc: Adjustments for temporal layers.

1) Keep the same block_sad_low as in single layer
case, in the variance partitioning.

2) Use the superblock source_sad (sb_sad) for setting
the refresh map, with modified thresholds for base TL0.

bdrate gain for speed 10, 2TL, with 70/30 allocation
on rtc_derf:
avg/ovr/ssim, IC% speedup:
-0.230/-0.219/-0.774, -0.119

Change-Id: I6a78e73141c60f5ce80070dcb7b3352570564aed
diff --git a/av1/encoder/aq_cyclicrefresh.c b/av1/encoder/aq_cyclicrefresh.c
index 86a440a..9d1d224 100644
--- a/av1/encoder/aq_cyclicrefresh.c
+++ b/av1/encoder/aq_cyclicrefresh.c
@@ -331,13 +331,22 @@
     if (cr->use_block_sad_scene_det && cpi->rc.frames_since_key > 30 &&
         cr->counter_encode_maxq_scene_change > 30 &&
         cpi->src_sad_blk_64x64 != NULL &&
-        cpi->svc.number_temporal_layers == 1 &&
         cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) {
       sb_sad = cpi->src_sad_blk_64x64[sb_col_index + sb_cols * sb_row_index];
       int scale = (cm->width * cm->height < 640 * 360) ? 6 : 8;
       int scale_low = 2;
       thresh_sad = (scale * 64 * 64);
       thresh_sad_low = (scale_low * 64 * 64);
+      // For temporal layers: the base temporal layer (temporal_layer_id = 0)
+      // has larger frame separation (2 or 4 frames apart), so use larger sad
+      // thresholds to compensate for larger frame sad. The larger thresholds
+      // also increase the amount of refresh, which is needed for the base
+      // temporal layer.
+      if (cpi->svc.number_temporal_layers > 1 &&
+          cpi->svc.temporal_layer_id == 0) {
+        thresh_sad <<= 4;
+        thresh_sad_low <<= 2;
+      }
     }
     // cr_map only needed at 8x8 blocks.
     for (y = 0; y < ymis; y += 2) {
diff --git a/av1/encoder/var_based_part.c b/av1/encoder/var_based_part.c
index 05e0383..6dd0782 100644
--- a/av1/encoder/var_based_part.c
+++ b/av1/encoder/var_based_part.c
@@ -475,7 +475,6 @@
         // Increase the sad thresholds for base TL0, as reference/LAST is
         // 2/4 frames behind (for 2/3 #TL).
         avg_source_sad_thresh = 40000;
-        block_sad_low = 35000;
         block_sad_high = 70000;
       }
       if (is_segment_id_boosted == false &&