shithub: libvpx

Download patch

ref: 64bb996e03f741d513c8b6c9b006fd970ddc7984
parent: 5de08054aeae55560e0a2ad5f5dfbe295272a2e6
parent: 1374a06bd87e2e2c41e17738bf5215d53e5223a0
author: Yaowu Xu <yaowu@google.com>
date: Fri Jun 28 05:29:39 EDT 2013

Merge "Optimize partition search order"

--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -1351,71 +1351,7 @@
   if (!cpi->sf.use_partitions_less_than
       || (cpi->sf.use_partitions_less_than
           && bsize <= cpi->sf.less_than_block_size)) {
-    // PARTITION_HORZ
-    if (bsize >= BLOCK_SIZE_SB8X8 && mi_col + (ms >> 1) < cm->mi_cols) {
-      int r2, r = 0;
-      int64_t d2, d = 0;
-      subsize = get_subsize(bsize, PARTITION_HORZ);
-      *(get_sb_index(xd, subsize)) = 0;
-      pick_sb_modes(cpi, mi_row, mi_col, tp, &r2, &d2, subsize,
-                    get_block_context(x, subsize));
-
-      if (mi_row + (ms >> 1) < cm->mi_rows) {
-        update_state(cpi, get_block_context(x, subsize), subsize, 0);
-        encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize);
-
-        *(get_sb_index(xd, subsize)) = 1;
-        pick_sb_modes(cpi, mi_row + (ms >> 1), mi_col, tp, &r, &d, subsize,
-                      get_block_context(x, subsize));
-        r2 += r;
-        d2 += d;
-      }
-      set_partition_seg_context(cm, xd, mi_row, mi_col);
-      pl = partition_plane_context(xd, bsize);
-      if (r2 < INT_MAX)
-        r2 += x->partition_cost[pl][PARTITION_HORZ];
-      if (RDCOST(x->rdmult, x->rddiv, r2, d2)
-          < RDCOST(x->rdmult, x->rddiv, srate, sdist)) {
-        srate = r2;
-        sdist = d2;
-        *(get_sb_partitioning(x, bsize)) = subsize;
-      }
-      restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize);
-    }
-
-    // PARTITION_VERT
-    if (bsize >= BLOCK_SIZE_SB8X8 && mi_row + (ms >> 1) < cm->mi_rows) {
-      int r2;
-      int64_t d2;
-      subsize = get_subsize(bsize, PARTITION_VERT);
-      *(get_sb_index(xd, subsize)) = 0;
-      pick_sb_modes(cpi, mi_row, mi_col, tp, &r2, &d2, subsize,
-                    get_block_context(x, subsize));
-      if (mi_col + (ms >> 1) < cm->mi_cols) {
-        int r = 0;
-        int64_t d = 0;
-        update_state(cpi, get_block_context(x, subsize), subsize, 0);
-        encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize);
-
-        *(get_sb_index(xd, subsize)) = 1;
-        pick_sb_modes(cpi, mi_row, mi_col + (ms >> 1), tp, &r, &d, subsize,
-                      get_block_context(x, subsize));
-        r2 += r;
-        d2 += d;
-      }
-      set_partition_seg_context(cm, xd, mi_row, mi_col);
-      pl = partition_plane_context(xd, bsize);
-      if (r2 < INT_MAX)
-        r2 += x->partition_cost[pl][PARTITION_VERT];
-      if (RDCOST(x->rdmult, x->rddiv, r2, d2)
-          < RDCOST(x->rdmult, x->rddiv, srate, sdist)) {
-        srate = r2;
-        sdist = d2;
-        *(get_sb_partitioning(x, bsize)) = subsize;
-      }
-      restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize);
-    }
-
+    int larger_is_better = 0;
     // PARTITION_NONE
     if ((mi_row + (ms >> 1) < cm->mi_rows) &&
         (mi_col + (ms >> 1) < cm->mi_cols)) {
@@ -1433,8 +1369,75 @@
           < RDCOST(x->rdmult, x->rddiv, srate, sdist)) {
         srate = r;
         sdist = d;
+        larger_is_better = 1;
         if (bsize >= BLOCK_SIZE_SB8X8)
           *(get_sb_partitioning(x, bsize)) = bsize;
+      }
+    }
+    if (!cpi->sf.less_rectangular_check || !larger_is_better) {
+      // PARTITION_HORZ
+      if (bsize >= BLOCK_SIZE_SB8X8 && mi_col + (ms >> 1) < cm->mi_cols) {
+        int r2, r = 0;
+        int64_t d2, d = 0;
+        subsize = get_subsize(bsize, PARTITION_HORZ);
+        *(get_sb_index(xd, subsize)) = 0;
+        pick_sb_modes(cpi, mi_row, mi_col, tp, &r2, &d2, subsize,
+                      get_block_context(x, subsize));
+
+        if (mi_row + (ms >> 1) < cm->mi_rows) {
+          update_state(cpi, get_block_context(x, subsize), subsize, 0);
+          encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize);
+
+          *(get_sb_index(xd, subsize)) = 1;
+          pick_sb_modes(cpi, mi_row + (ms >> 1), mi_col, tp, &r, &d, subsize,
+                        get_block_context(x, subsize));
+          r2 += r;
+          d2 += d;
+        }
+        set_partition_seg_context(cm, xd, mi_row, mi_col);
+        pl = partition_plane_context(xd, bsize);
+        if (r2 < INT_MAX)
+          r2 += x->partition_cost[pl][PARTITION_HORZ];
+        if (RDCOST(x->rdmult, x->rddiv, r2, d2)
+            < RDCOST(x->rdmult, x->rddiv, srate, sdist)) {
+          srate = r2;
+          sdist = d2;
+          *(get_sb_partitioning(x, bsize)) = subsize;
+        }
+        restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize);
+      }
+
+      // PARTITION_VERT
+      if (bsize >= BLOCK_SIZE_SB8X8 && mi_row + (ms >> 1) < cm->mi_rows) {
+        int r2;
+        int64_t d2;
+        subsize = get_subsize(bsize, PARTITION_VERT);
+        *(get_sb_index(xd, subsize)) = 0;
+        pick_sb_modes(cpi, mi_row, mi_col, tp, &r2, &d2, subsize,
+                      get_block_context(x, subsize));
+        if (mi_col + (ms >> 1) < cm->mi_cols) {
+          int r = 0;
+          int64_t d = 0;
+          update_state(cpi, get_block_context(x, subsize), subsize, 0);
+          encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize);
+
+          *(get_sb_index(xd, subsize)) = 1;
+          pick_sb_modes(cpi, mi_row, mi_col + (ms >> 1), tp, &r, &d, subsize,
+                        get_block_context(x, subsize));
+          r2 += r;
+          d2 += d;
+        }
+        set_partition_seg_context(cm, xd, mi_row, mi_col);
+        pl = partition_plane_context(xd, bsize);
+        if (r2 < INT_MAX)
+          r2 += x->partition_cost[pl][PARTITION_VERT];
+        if (RDCOST(x->rdmult, x->rddiv, r2, d2)
+            < RDCOST(x->rdmult, x->rddiv, srate, sdist)) {
+          srate = r2;
+          sdist = d2;
+          *(get_sb_partitioning(x, bsize)) = subsize;
+        }
+        restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize);
       }
     }
   }
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -659,7 +659,6 @@
   int mode = cpi->compressor_speed;
   int speed = cpi->speed;
   int i;
-
   // Only modes 0 and 1 supported for now in experimental code basae
   if (mode > 1)
     mode = 1;
@@ -699,6 +698,7 @@
   sf->adjust_thresholds_by_speed = 0;
   sf->partition_by_variance = 0;
   sf->use_one_partition_size_always = 0;
+  sf->less_rectangular_check = 0;
   sf->use_partitions_less_than = 0;
   sf->less_than_block_size = BLOCK_SIZE_MB16X16;
   sf->use_partitions_greater_than = 0;
@@ -730,12 +730,17 @@
 
       if (speed == 1) {
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
-        sf->use_largest_txform = !(cpi->common.frame_type == KEY_FRAME ||
-                                   cpi->common.intra_only ||
-                                   cpi->common.show_frame == 0);
+        sf->less_rectangular_check  = 1;
+        sf->use_largest_txform        = !(cpi->common.frame_type == KEY_FRAME ||
+                                          cpi->common.intra_only ||
+                                          cpi->common.show_frame == 0);
       }
       if (speed == 2) {
+        sf->use_largest_txform        = !(cpi->common.frame_type == KEY_FRAME ||
+                                          cpi->common.intra_only ||
+                                          cpi->common.show_frame == 0);
         sf->adjust_thresholds_by_speed = 1;
+        sf->less_rectangular_check  = 1;
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
         sf->reduce_first_step_size = 1;
         sf->optimize_coefficients = 0;
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -226,6 +226,7 @@
   int adjust_thresholds_by_speed;
   int partition_by_variance;
   int use_one_partition_size_always;
+  int less_rectangular_check;
   BLOCK_SIZE_TYPE always_this_block_size;
   int use_partitions_greater_than;
   BLOCK_SIZE_TYPE greater_than_block_size;