shithub: libvpx

Download patch

ref: a99e1aa8ca1b6361add6e74e90d74b07697e1786
parent: 6c0c6b86c14a89120beed55fcf7e68c038476eb5
author: John Koleszar <jkoleszar@google.com>
date: Thu Apr 25 07:15:38 EDT 2013

Remove predictor pointers from BLOCKD

Access these members from MACROBLOCKD instead.

Change-Id: I2574622e577bb9feede47f6b7ccbb11f3e928ca8

--- a/vp9/common/vp9_blockd.h
+++ b/vp9/common/vp9_blockd.h
@@ -279,12 +279,6 @@
 } MODE_INFO;
 
 typedef struct blockd {
-  /* 16 Y blocks, 4 U blocks, 4 V blocks each with 16 entries */
-  uint8_t **base_pre;
-  uint8_t **base_second_pre;
-  int pre;
-  int pre_stride;
-
   uint8_t **base_dst;
   int dst;
   int dst_stride;
--- a/vp9/common/vp9_mbpitch.c
+++ b/vp9/common/vp9_mbpitch.c
@@ -22,11 +22,6 @@
     b->dst_stride = stride;
     b->dst = offset;
     b->base_dst = base;
-  } else {
-    b->pre_stride = stride;
-    b->pre = offset;
-    b->base_pre = base;
-    b->base_second_pre = base2;
   }
 }
 
@@ -43,14 +38,6 @@
     y2 = NULL;
     u2 = NULL;
     v2 = NULL;
-  } else {
-    y = &mb->plane[0].pre[0].buf;
-    u = &mb->plane[1].pre[0].buf;
-    v = &mb->plane[2].pre[0].buf;
-
-    y2 = &mb->plane[0].pre[1].buf;
-    u2 = &mb->plane[1].pre[1].buf;
-    v2 = &mb->plane[2].pre[1].buf;
   }
 
   // luma
@@ -82,5 +69,4 @@
 void vp9_build_block_doffsets(MACROBLOCKD *mb) {
   // handle the destination pitch features
   setup_macroblock(mb, DEST);
-  setup_macroblock(mb, PRED);
 }
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -130,7 +130,7 @@
     FILE *fpfile;
     fpfile = fopen("firstpass.stt", "a");
 
-    fprintf(fpfile, "%12.0f %12.0f %12.0f %12.0f %12.0f %12.4f %12.4f"
+    fprintf(stdout, "%12.0f %12.0f %12.0f %12.0f %12.0f %12.4f %12.4f"
             "%12.4f %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f"
             "%12.0f %12.0f %12.4f %12.0f %12.0f %12.4f\n",
             stats->frame,
@@ -349,19 +349,12 @@
 
 static void zz_motion_search(VP9_COMP *cpi, MACROBLOCK *x, YV12_BUFFER_CONFIG *recon_buffer, int *best_motion_err, int recon_yoffset) {
   MACROBLOCKD *const xd = &x->e_mbd;
-  BLOCKD *d = &x->e_mbd.block[0];
 
-  uint8_t *src_ptr = x->plane[0].src.buf;
-  int src_stride = x->plane[0].src.stride;
-  uint8_t *ref_ptr;
-  int ref_stride = d->pre_stride;
-
   // Set up pointers for this macro block recon buffer
   xd->plane[0].pre[0].buf = recon_buffer->y_buffer + recon_yoffset;
 
-  ref_ptr = (uint8_t *)(*(d->base_pre) + d->pre);
-
-  vp9_mse16x16(src_ptr, src_stride, ref_ptr, ref_stride,
+  vp9_mse16x16(x->plane[0].src.buf, x->plane[0].src.stride,
+               xd->plane[0].pre[0].buf, xd->plane[0].pre[0].stride,
                (unsigned int *)(best_motion_err));
 }
 
--- a/vp9/encoder/vp9_mbgraph.c
+++ b/vp9/encoder/vp9_mbgraph.c
@@ -99,15 +99,6 @@
   MACROBLOCKD *const xd = &x->e_mbd;
   unsigned int err, tmp_err;
   int_mv tmp_mv;
-  int n;
-
-  for (n = 0; n < 16; n++) {
-    BLOCKD *d = &xd->block[n];
-
-    d->base_pre   = &xd->plane[0].pre[0].buf;
-    d->pre_stride = xd->plane[0].pre[0].stride;
-    d->pre        = xd->plane[0].pre[0].stride * (n & 12) + (n & 3) * 4;
-  }
 
   // Try zero MV first
   // FIXME should really use something like near/nearest MV and/or MV prediction
--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -265,10 +265,12 @@
   int offset;
   int usehp = xd->allow_high_precision_mv;
 
-  uint8_t *y = *(d->base_pre) + d->pre +
-               (bestmv->as_mv.row) * d->pre_stride + bestmv->as_mv.col;
-  y_stride = d->pre_stride;
+  uint8_t *y = xd->plane[0].pre[0].buf +
+               (bestmv->as_mv.row) * xd->plane[0].pre[0].stride +
+               bestmv->as_mv.col;
 
+  y_stride = xd->plane[0].pre[0].stride;
+
   rr = ref_mv->as_mv.row;
   rc = ref_mv->as_mv.col;
   br = bestmv->as_mv.row << 3;
@@ -440,9 +442,10 @@
   MACROBLOCKD *xd = &x->e_mbd;
   int usehp = xd->allow_high_precision_mv;
 
-  uint8_t *y = *(d->base_pre) + d->pre +
-               (bestmv->as_mv.row) * d->pre_stride + bestmv->as_mv.col;
-  y_stride = d->pre_stride;
+  uint8_t *y = xd->plane[0].pre[0].buf +
+               (bestmv->as_mv.row) * xd->plane[0].pre[0].stride +
+               bestmv->as_mv.col;
+  y_stride = xd->plane[0].pre[0].stride;
 
   // central mv
   bestmv->as_mv.row <<= 3;
@@ -940,9 +943,9 @@
   int y_stride;
   MACROBLOCKD *xd = &x->e_mbd;
 
-  uint8_t *y = *(d->base_pre) + d->pre +
-      (bestmv->as_mv.row) * d->pre_stride + bestmv->as_mv.col;
-  y_stride = d->pre_stride;
+  uint8_t *y = xd->plane[0].pre[0].buf +
+      (bestmv->as_mv.row) * xd->plane[0].pre[0].stride + bestmv->as_mv.col;
+  y_stride = xd->plane[0].pre[0].stride;
 
   // central mv
   bestmv->as_mv.row <<= 3;
@@ -1103,6 +1106,7 @@
   int *mvjcost, int *mvcost[2],
   int_mv *center_mv
 ) {
+  const MACROBLOCKD* const xd = &x->e_mbd;
   MV hex[6] = { { -1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0} };
   MV neighbors[4] = {{0, -1}, { -1, 0}, {1, 0}, {0, 1}};
   int i, j;
@@ -1109,7 +1113,7 @@
 
   uint8_t *what = x->plane[0].src.buf;
   int what_stride = x->plane[0].src.stride;
-  int in_what_stride = d->pre_stride;
+  int in_what_stride = xd->plane[0].pre[0].stride;
   int br, bc;
   int_mv this_mv;
   unsigned int bestsad = 0x7fffffff;
@@ -1130,8 +1134,8 @@
   bc = ref_mv->as_mv.col;
 
   // Work out the start point for the search
-  base_offset = (uint8_t *)(*(d->base_pre) + d->pre);
-  this_offset = base_offset + (br * (d->pre_stride)) + bc;
+  base_offset = (uint8_t *)(xd->plane[0].pre[0].buf);
+  this_offset = base_offset + (br * (xd->plane[0].pre[0].stride)) + bc;
   this_mv.as_mv.row = br;
   this_mv.as_mv.col = bc;
   bestsad = vfp->sdf(what, what_stride, this_offset,
@@ -1253,10 +1257,11 @@
                              int *mvcost[2], int_mv *center_mv) {
   int i, j, step;
 
+  const MACROBLOCKD* const xd = &x->e_mbd;
   uint8_t *what = x->plane[0].src.buf;
   int what_stride = x->plane[0].src.stride;
   uint8_t *in_what;
-  int in_what_stride = d->pre_stride;
+  int in_what_stride = xd->plane[0].pre[0].stride;
   uint8_t *best_address;
 
   int tot_steps;
@@ -1272,7 +1277,6 @@
 
   uint8_t *check_here;
   int thissad;
-  MACROBLOCKD *xd = &x->e_mbd;
   int_mv fcenter_mv;
 
   int *mvjsadcost = x->nmvjointsadcost;
@@ -1289,8 +1293,8 @@
   best_mv->as_mv.col = ref_col;
 
   // Work out the start point for the search
-  in_what = (uint8_t *)(*(d->base_pre) + d->pre +
-                        (ref_row * (d->pre_stride)) + ref_col);
+  in_what = (uint8_t *)(xd->plane[0].pre[0].buf +
+                        (ref_row * (xd->plane[0].pre[0].stride)) + ref_col);
   best_address = in_what;
 
   // Check the starting position
@@ -1364,10 +1368,11 @@
                              int *mvjcost, int *mvcost[2], int_mv *center_mv) {
   int i, j, step;
 
+  const MACROBLOCKD* const xd = &x->e_mbd;
   uint8_t *what = x->plane[0].src.buf;
   int what_stride = x->plane[0].src.stride;
   uint8_t *in_what;
-  int in_what_stride = d->pre_stride;
+  int in_what_stride = xd->plane[0].pre[0].stride;
   uint8_t *best_address;
 
   int tot_steps;
@@ -1385,7 +1390,6 @@
 
   uint8_t *check_here;
   unsigned int thissad;
-  MACROBLOCKD *xd = &x->e_mbd;
   int_mv fcenter_mv;
 
   int *mvjsadcost = x->nmvjointsadcost;
@@ -1402,8 +1406,8 @@
   best_mv->as_mv.col = ref_col;
 
   // Work out the start point for the search
-  in_what = (uint8_t *)(*(d->base_pre) + d->pre +
-                        (ref_row * (d->pre_stride)) + ref_col);
+  in_what = (uint8_t *)(xd->plane[0].pre[0].buf +
+                        (ref_row * (xd->plane[0].pre[0].stride)) + ref_col);
   best_address = in_what;
 
   // Check the starting position
@@ -1571,11 +1575,12 @@
                           vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
                           int *mvcost[2],
                           int_mv *center_mv) {
+  const MACROBLOCKD* const xd = &x->e_mbd;
   uint8_t *what = x->plane[0].src.buf;
   int what_stride = x->plane[0].src.stride;
   uint8_t *in_what;
-  int in_what_stride = d->pre_stride;
-  int mv_stride = d->pre_stride;
+  int in_what_stride = xd->plane[0].pre[0].stride;
+  int mv_stride = xd->plane[0].pre[0].stride;
   uint8_t *bestaddress;
   int_mv *best_mv = &d->bmi.as_mv[0];
   int_mv this_mv;
@@ -1584,7 +1589,6 @@
 
   uint8_t *check_here;
   int thissad;
-  MACROBLOCKD *xd = &x->e_mbd;
 
   int ref_row = ref_mv->as_mv.row;
   int ref_col = ref_mv->as_mv.col;
@@ -1602,8 +1606,8 @@
   fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
 
   // Work out the mid point for the search
-  in_what = *(d->base_pre) + d->pre;
-  bestaddress = in_what + (ref_row * d->pre_stride) + ref_col;
+  in_what = xd->plane[0].pre[0].buf;
+  bestaddress = in_what + (ref_row * xd->plane[0].pre[0].stride) + ref_col;
 
   best_mv->as_mv.row = ref_row;
   best_mv->as_mv.col = ref_col;
@@ -1666,11 +1670,12 @@
                           int sad_per_bit, int distance,
                           vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
                           int *mvcost[2], int_mv *center_mv) {
+  const MACROBLOCKD* const xd = &x->e_mbd;
   uint8_t *what = x->plane[0].src.buf;
   int what_stride = x->plane[0].src.stride;
   uint8_t *in_what;
-  int in_what_stride = d->pre_stride;
-  int mv_stride = d->pre_stride;
+  int in_what_stride = xd->plane[0].pre[0].stride;
+  int mv_stride = xd->plane[0].pre[0].stride;
   uint8_t *bestaddress;
   int_mv *best_mv = &d->bmi.as_mv[0];
   int_mv this_mv;
@@ -1679,7 +1684,6 @@
 
   uint8_t *check_here;
   unsigned int thissad;
-  MACROBLOCKD *xd = &x->e_mbd;
 
   int ref_row = ref_mv->as_mv.row;
   int ref_col = ref_mv->as_mv.col;
@@ -1699,8 +1703,8 @@
   fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
 
   // Work out the mid point for the search
-  in_what = *(d->base_pre) + d->pre;
-  bestaddress = in_what + (ref_row * d->pre_stride) + ref_col;
+  in_what = xd->plane[0].pre[0].buf;
+  bestaddress = in_what + (ref_row * xd->plane[0].pre[0].stride) + ref_col;
 
   best_mv->as_mv.row = ref_row;
   best_mv->as_mv.col = ref_col;
@@ -1795,11 +1799,12 @@
                           vp9_variance_fn_ptr_t *fn_ptr,
                           int *mvjcost, int *mvcost[2],
                           int_mv *center_mv) {
+  const MACROBLOCKD* const xd = &x->e_mbd;
   uint8_t *what = x->plane[0].src.buf;
   int what_stride = x->plane[0].src.stride;
   uint8_t *in_what;
-  int in_what_stride = d->pre_stride;
-  int mv_stride = d->pre_stride;
+  int in_what_stride = xd->plane[0].pre[0].stride;
+  int mv_stride = xd->plane[0].pre[0].stride;
   uint8_t *bestaddress;
   int_mv *best_mv = &d->bmi.as_mv[0];
   int_mv this_mv;
@@ -1808,7 +1813,6 @@
 
   uint8_t *check_here;
   unsigned int thissad;
-  MACROBLOCKD *xd = &x->e_mbd;
 
   int ref_row = ref_mv->as_mv.row;
   int ref_col = ref_mv->as_mv.col;
@@ -1829,8 +1833,8 @@
   fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
 
   // Work out the mid point for the search
-  in_what = *(d->base_pre) + d->pre;
-  bestaddress = in_what + (ref_row * d->pre_stride) + ref_col;
+  in_what = xd->plane[0].pre[0].buf;
+  bestaddress = in_what + (ref_row * xd->plane[0].pre[0].stride) + ref_col;
 
   best_mv->as_mv.row = ref_row;
   best_mv->as_mv.col = ref_col;
@@ -1948,21 +1952,21 @@
                               int_mv *ref_mv, int error_per_bit,
                               int search_range, vp9_variance_fn_ptr_t *fn_ptr,
                               int *mvjcost, int *mvcost[2], int_mv *center_mv) {
+  const MACROBLOCKD* const xd = &x->e_mbd;
   MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}};
   int i, j;
   int this_row_offset, this_col_offset;
 
   int what_stride = x->plane[0].src.stride;
-  int in_what_stride = d->pre_stride;
+  int in_what_stride = xd->plane[0].pre[0].stride;
   uint8_t *what = x->plane[0].src.buf;
-  uint8_t *best_address = (uint8_t *)(*(d->base_pre) + d->pre +
-                                      (ref_mv->as_mv.row * (d->pre_stride)) +
-                                      ref_mv->as_mv.col);
+  uint8_t *best_address = xd->plane[0].pre[0].buf +
+                          (ref_mv->as_mv.row * xd->plane[0].pre[0].stride) +
+                          ref_mv->as_mv.col;
   uint8_t *check_here;
   unsigned int thissad;
   int_mv this_mv;
   unsigned int bestsad = INT_MAX;
-  MACROBLOCKD *xd = &x->e_mbd;
   int_mv fcenter_mv;
 
   int *mvjsadcost = x->nmvjointsadcost;
@@ -2026,21 +2030,21 @@
                               int_mv *ref_mv, int error_per_bit,
                               int search_range, vp9_variance_fn_ptr_t *fn_ptr,
                               int *mvjcost, int *mvcost[2], int_mv *center_mv) {
+  const MACROBLOCKD* const xd = &x->e_mbd;
   MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}};
   int i, j;
   int this_row_offset, this_col_offset;
 
   int what_stride = x->plane[0].src.stride;
-  int in_what_stride = d->pre_stride;
+  int in_what_stride = xd->plane[0].pre[0].stride;
   uint8_t *what = x->plane[0].src.buf;
-  uint8_t *best_address = (uint8_t *)(*(d->base_pre) + d->pre +
-                                      (ref_mv->as_mv.row * (d->pre_stride)) +
-                                      ref_mv->as_mv.col);
+  uint8_t *best_address = xd->plane[0].pre[0].buf +
+                          (ref_mv->as_mv.row * xd->plane[0].pre[0].stride) +
+                          ref_mv->as_mv.col;
   uint8_t *check_here;
   unsigned int thissad;
   int_mv this_mv;
   unsigned int bestsad = INT_MAX;
-  MACROBLOCKD *xd = &x->e_mbd;
   int_mv fcenter_mv;
 
   int *mvjsadcost = x->nmvjointsadcost;
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -1723,10 +1723,14 @@
           raster_block_offset_int16(xd, BLOCK_SIZE_MB16X16, 0, i,
                                     x->plane[0].src_diff);
       int16_t* const coeff = BLOCK_OFFSET(x->plane[0].coeff, 16, i);
+      uint8_t* const pre =
+          raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 0, i,
+                                    xd->plane[0].pre[0].buf,
+                                    xd->plane[0].pre[0].stride);
       int thisdistortion;
 
-      vp9_build_inter_predictor(*(bd->base_pre) + bd->pre,
-                                bd->pre_stride,
+      vp9_build_inter_predictor(pre,
+                                xd->plane[0].pre[0].stride,
                                 *(bd->base_dst) + bd->dst,
                                 bd->dst_stride,
                                 &bd->bmi.as_mv[0],
@@ -1737,8 +1741,12 @@
       // implicit-compoundinter-weight experiment when implicit
       // weighting for splitmv modes is turned on.
       if (xd->mode_info_context->mbmi.second_ref_frame > 0) {
+        uint8_t* const second_pre =
+          raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 0, i,
+                                    xd->plane[0].pre[1].buf,
+                                    xd->plane[0].pre[1].stride);
         vp9_build_inter_predictor(
-            *(bd->base_second_pre) + bd->pre, bd->pre_stride,
+            second_pre, xd->plane[0].pre[1].stride,
             *(bd->base_dst) + bd->dst, bd->dst_stride,
             &bd->bmi.as_mv[1], &xd->scale_factor[1], 4, 4, 1,
             &xd->subpix);
@@ -1806,13 +1814,16 @@
 
       assert(idx < 16);
       for (which_mv = 0; which_mv < 1 + use_second_ref; ++which_mv) {
-        uint8_t **base_pre = which_mv ? bd->base_second_pre : bd->base_pre;
+        uint8_t* const pre =
+            raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 0, ib,
+                                      xd->plane[0].pre[which_mv].buf,
+                                      xd->plane[0].pre[which_mv].stride);
 
         // TODO(debargha): Make this work properly with the
         // implicit-compoundinter-weight experiment when implicit
         // weighting for splitmv modes is turned on.
         vp9_build_inter_predictor(
-            *base_pre + bd->pre, bd->pre_stride,
+            pre, xd->plane[0].pre[which_mv].stride,
             *(bd->base_dst) + bd->dst, bd->dst_stride,
             &bd->bmi.as_mv[which_mv], &xd->scale_factor[which_mv], 8, 8,
             which_mv, &xd->subpix);
@@ -2030,6 +2041,7 @@
         int thissme, bestsme = INT_MAX;
         BLOCKD *e;
         const struct buf_2d orig_src = x->plane[0].src;
+        const struct buf_2d orig_pre = x->e_mbd.plane[0].pre[0];
 
         /* Is the best so far sufficiently good that we cant justify doing
          * and new motion search. */
@@ -2072,6 +2084,11 @@
               raster_block_offset_uint8(&x->e_mbd, BLOCK_SIZE_MB16X16, 0, n,
                                         x->plane[0].src.buf,
                                         x->plane[0].src.stride);
+          assert(((intptr_t)x->e_mbd.plane[0].pre[0].buf & 0xf) == 0);
+          x->e_mbd.plane[0].pre[0].buf =
+              raster_block_offset_uint8(&x->e_mbd, BLOCK_SIZE_MB16X16, 0, n,
+                                        x->e_mbd.plane[0].pre[0].buf,
+                                        x->e_mbd.plane[0].pre[0].stride);
           e = &x->e_mbd.block[n];
 
           bestsme = vp9_full_pixel_diamond(cpi, x, e, &mvp_full, step_param,
@@ -2114,8 +2131,9 @@
           seg_mvs[i][mbmi->ref_frame - 1].as_int = mode_mv[NEW4X4].as_int;
         }
 
-        // restore src pointer
+        // restore src pointers
         x->plane[0].src = orig_src;
+        x->e_mbd.plane[0].pre[0] = orig_pre;
       } else if (mbmi->second_ref_frame > 0 && this_mode == NEW4X4) {
         /* NEW4X4 */
         /* motion search not completed? Then skip newmv for this block with
--- a/vp9/encoder/vp9_temporal_filter.c
+++ b/vp9/encoder/vp9_temporal_filter.c
@@ -124,6 +124,7 @@
                                               int mb_offset,
                                               int error_thresh) {
   MACROBLOCK *x = &cpi->mb;
+  MACROBLOCKD* const xd = &x->e_mbd;
   int step_param;
   int sadpb = x->sadperbit16;
   int bestsme = INT_MAX;
@@ -134,9 +135,7 @@
 
   // Save input state
   struct buf_2d src = x->plane[0].src;
-  uint8_t **base_pre = d->base_pre;
-  int pre = d->pre;
-  int pre_stride = d->pre_stride;
+  struct buf_2d pre = xd->plane[0].pre[0];
 
   best_ref_mv1.as_int = 0;
   best_ref_mv1_full.as_mv.col = best_ref_mv1.as_mv.col >> 3;
@@ -145,11 +144,9 @@
   // Setup frame pointers
   x->plane[0].src.buf = arf_frame->y_buffer + mb_offset;
   x->plane[0].src.stride = arf_frame->y_stride;
+  xd->plane[0].pre[0].buf = frame_ptr->y_buffer + mb_offset;
+  xd->plane[0].pre[0].stride = arf_frame->y_stride;
 
-  d->base_pre = &frame_ptr->y_buffer;
-  d->pre_stride = frame_ptr->y_stride;
-  d->pre = mb_offset;
-
   // Further step/diamond searches as necessary
   if (cpi->Speed < 8) {
     step_param = cpi->sf.first_step +
@@ -182,11 +179,9 @@
   }
 #endif
 
-  // Save input state
+  // Restore input state
   x->plane[0].src = src;
-  d->base_pre = base_pre;
-  d->pre = pre;
-  d->pre_stride = pre_stride;
+  xd->plane[0].pre[0] = pre;
 
   return bestsme;
 }