vp9: Copy partition using avg_source_sad.
authorJerome Jiang <jianj@google.com>
Mon, 23 Jan 2017 20:10:01 +0000 (12:10 -0800)
committerJerome Jiang <jianj@google.com>
Tue, 24 Jan 2017 18:31:22 +0000 (10:31 -0800)
Affecting only speed 8.
Speed tests on Nexus 6 show 4% faster for QVGA and 2.4% faster for VGA.
Little/negligible quality regression observed on both rtc and rtc_derf sets.

Change-Id: I337f301a2db49a568d18ba7623160f7678399ae1

vp9/encoder/vp9_encodeframe.c

index 4b6c9b0..913ef90 100644 (file)
@@ -925,12 +925,7 @@ static int choose_partitioning(VP9_COMP *cpi, const TileInfo *const tile,
   int variance4x4downsample[16];
   int segment_id;
   int sb_offset = (cm->mi_stride >> 3) * (mi_row >> 3) + (mi_col >> 3);
-  if (cpi->sf.use_source_sad && !is_key_frame) {
-    // The sb_offset2 is to make it consistent with the index in the function
-    // vp9_avg_source_sad() in vp9_ratectrl.c.
-    int sb_offset2 = ((cm->mi_cols + 7) >> 3) * (mi_row >> 3) + (mi_col >> 3);
-    x->skip_low_source_sad = cpi->avg_source_sad_sb[sb_offset2] == 1 ? 1 : 0;
-  }
+
   set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64);
   segment_id = xd->mi[0]->segment_id;
   if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) {
@@ -940,6 +935,28 @@ static int choose_partitioning(VP9_COMP *cpi, const TileInfo *const tile,
     }
   }
 
+  if (cpi->sf.use_source_sad && !is_key_frame) {
+    // The sb_offset2 is to make it consistent with the index in the function
+    // vp9_avg_source_sad() in vp9_ratectrl.c.
+    int sb_offset2 = ((cm->mi_cols + 7) >> 3) * (mi_row >> 3) + (mi_col >> 3);
+    x->skip_low_source_sad = cpi->avg_source_sad_sb[sb_offset2] == 1 ? 1 : 0;
+    // If avg_source_sad is lower than the threshold, copy the partition without
+    // computing the y_sad.
+    if (cpi->avg_source_sad_sb[sb_offset2] && cpi->sf.copy_partition_flag &&
+        cpi->rc.frames_since_key > 1 && segment_id == CR_SEGMENT_ID_BASE &&
+        cpi->prev_segment_id[sb_offset] == CR_SEGMENT_ID_BASE &&
+        cpi->copied_frame_cnt[sb_offset] < cpi->max_copied_frame) {
+      if (cpi->prev_partition != NULL) {
+        copy_prev_partition(cpi, BLOCK_64X64, mi_row, mi_col);
+        chroma_check(cpi, x, bsize, y_sad, is_key_frame);
+        cpi->copied_frame_cnt[sb_offset] += 1;
+        memcpy(x->variance_low, &(cpi->prev_variance_low[sb_offset * 25]),
+               sizeof(x->variance_low));
+        return 0;
+      }
+    }
+  }
+
   // For non keyframes, disable 4x4 average for low resolution when speed = 8
   threshold_4x4avg = (cpi->oxcf.speed < 8) ? thresholds[1] << 1 : INT64_MAX;