shithub: libvpx

Download patch

ref: 8e8e2d11bfb2f6dd90051b2ca897190fe99a0fbd
parent: 91aa1fae2a88e0a125161dc1ec3f8f73c3508707
parent: ac1358cd56b6b0c76d773703af2584bb3a204c33
author: Jerome Jiang <jianj@google.com>
date: Tue Jan 24 15:58:09 EST 2017

Merge "vp9: Copy partition using avg_source_sad."

--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -925,12 +925,7 @@
   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) {
@@ -937,6 +932,28 @@
     if (cyclic_refresh_segment_id_boosted(segment_id)) {
       int q = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
       set_vbp_thresholds(cpi, thresholds, q);
+    }
+  }
+
+  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;
+      }
     }
   }