shithub: libvpx

Download patch

ref: d30c8f41efb0ba8ede9ca46d270b4ad398f192bf
parent: b9c3dd481a429159742385e31cec48dd44c0ff79
parent: b72ecbb1b98be5cb24e6f68d8d2eeda6efc38cc0
author: Ronald S. Bultje <rbultje@google.com>
date: Fri Jul 26 13:20:51 EDT 2013

Merge "Add best_rd breakout in intra4x4 RD loop."

--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -1174,10 +1174,11 @@
                                      ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l,
                                      int *bestrate, int *bestratey,
                                      int64_t *bestdistortion,
-                                     BLOCK_SIZE_TYPE bsize) {
+                                     BLOCK_SIZE_TYPE bsize,
+                                     int64_t rd_thresh) {
   MB_PREDICTION_MODE mode;
   MACROBLOCKD *xd = &x->e_mbd;
-  int64_t best_rd = INT64_MAX;
+  int64_t best_rd = rd_thresh;
   int rate = 0;
   int64_t distortion;
   VP9_COMMON *const cm = &cpi->common;
@@ -1258,6 +1259,8 @@
         distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff,
                                                           block, 16),
                                       16, &ssz) >> 2;
+        if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd)
+          goto next;
 
         if (tx_type != DCT_DCT)
           vp9_short_iht4x4_add(BLOCK_OFFSET(pd->dqcoeff, block, 16),
@@ -1280,6 +1283,8 @@
       best_tx_type = tx_type;
       vpx_memcpy(a, tempa, sizeof(tempa));
       vpx_memcpy(l, templ, sizeof(templ));
+      // FIXME(rbultje) why are we storing best_dqcoeff instead of the
+      // dst buffer here?
       for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
         for (idx = 0; idx < num_4x4_blocks_wide; ++idx) {
           block = ib + idy * 2 + idx;
@@ -1289,9 +1294,11 @@
         }
       }
     }
+  next:
+    {}
   }
 
-  if (x->skip_encode)
+  if (best_rd >= rd_thresh || x->skip_encode)
     return best_rd;
 
   for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
@@ -1348,7 +1355,7 @@
       const int mis = xd->mode_info_stride;
       MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
       int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry);
-      int64_t UNINITIALIZED_IS_SAFE(d);
+      int64_t UNINITIALIZED_IS_SAFE(d), this_rd;
       i = idy * 2 + idx;
 
       if (cpi->common.frame_type == KEY_FRAME) {
@@ -1359,9 +1366,14 @@
         bmode_costs  = mb->y_mode_costs[A][L];
       }
 
-      total_rd += rd_pick_intra4x4block(cpi, mb, i, &best_mode, bmode_costs,
-                                        t_above + idx, t_left + idy,
-                                        &r, &ry, &d, bsize);
+      this_rd = rd_pick_intra4x4block(cpi, mb, i, &best_mode, bmode_costs,
+                                      t_above + idx, t_left + idy,
+                                      &r, &ry, &d, bsize,
+                                      best_rd - total_rd);
+      if (this_rd >= best_rd - total_rd)
+        return INT64_MAX;
+
+      total_rd += this_rd;
       cost += r;
       distortion += d;
       tot_rate_y += ry;
@@ -3529,8 +3541,9 @@
         */
 
       mbmi->txfm_size = TX_4X4;
-      rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y,
-                                &distortion_y, INT64_MAX);
+      if (rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y,
+                                    &distortion_y, best_rd) >= best_rd)
+        continue;
       rate2 += rate;
       rate2 += intra_cost_penalty;
       distortion2 += distortion_y;