Add a best_yrd shortcut in splitmv mode search.
authorRonald S. Bultje <rbultje@google.com>
Wed, 17 Jul 2013 21:21:44 +0000 (14:21 -0700)
committerRonald S. Bultje <rbultje@google.com>
Wed, 17 Jul 2013 21:21:57 +0000 (14:21 -0700)
Encoding of first 50 frames of bus (speed 0) @ 1500kbps goes from
1min6.2 to 1min5.9, i.e. 0.5% faster overall.

Change-Id: I59d8a3b2f0a75010fa041d5e2646c8caac5bd683

vp9/encoder/vp9_rdopt.c

index 4fe207b..7f5f0de 100644 (file)
@@ -1716,12 +1716,10 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi,
                      src, src_stride,
                      dst, xd->plane[0].dst.stride);
 
-  *labelyrate = 0;
-  *distortion = 0;
   k = i;
   for (idy = 0; idy < bh / 4; ++idy) {
     for (idx = 0; idx < bw / 4; ++idx) {
-      int64_t ssz;
+      int64_t ssz, rd, rd1, rd2;
 
       k += (idy * 2 + idx);
       src_diff = raster_block_offset_int16(xd, BLOCK_SIZE_SB8X8, 0, k,
@@ -1736,13 +1734,17 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi,
       thisrate += cost_coeffs(cm, x, 0, k, PLANE_TYPE_Y_WITH_DC,
                               ta + (k & 1),
                               tl + (k >> 1), TX_4X4, 16);
+      rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2);
+      rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2);
+      rd = MIN(rd1, rd2);
+      if (rd >= best_yrd)
+        return INT64_MAX;
     }
   }
-  *distortion += thisdistortion;
-  *labelyrate += thisrate;
+  *distortion = thisdistortion >> 2;
+  *labelyrate = thisrate;
   *sse = thissse >> 2;
 
-  *distortion >>= 2;
   return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion);
 }
 
@@ -2008,8 +2010,10 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x,
                                           bsi->segment_rd - this_segment_rd,
                                           i, &labelyrate, &distortion, &sse,
                                           t_above_s, t_left_s);
-        this_rd += RDCOST(x->rdmult, x->rddiv, rate, 0);
-        rate += labelyrate;
+        if (this_rd < INT64_MAX) {
+          this_rd += RDCOST(x->rdmult, x->rddiv, rate, 0);
+          rate += labelyrate;
+        }
 
         if (this_rd < best_label_rd) {
           sbr = rate;
@@ -2024,6 +2028,11 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x,
         }
       } /*for each 4x4 mode*/
 
+      if (best_label_rd == INT64_MAX) {
+        bsi->segment_rd = INT64_MAX;
+        return;
+      }
+
       vpx_memcpy(t_above, t_above_b, sizeof(t_above));
       vpx_memcpy(t_left, t_left_b, sizeof(t_left));