Migrating MB decoding into decode_sb/atom
authorJingning Han <jingning@google.com>
Tue, 30 Apr 2013 19:08:32 +0000 (12:08 -0700)
committerJingning Han <jingning@google.com>
Wed, 1 May 2013 03:48:52 +0000 (20:48 -0700)
The decode_mb only carries I8X8_PRED decoding, which will be covered
by the regular MB intra modes when SB8X8 is on. To be removed later.

Change-Id: I3b9ee55917a30b42518b81987bc10c22b1a19e7f

vp9/decoder/vp9_decodframe.c

index 12f8948..5abbdc3 100644 (file)
@@ -204,84 +204,53 @@ static void mb_init_dequantizer(VP9_COMMON *pc, MACROBLOCKD *xd) {
 }
 
 #if !CONFIG_SB8X8
-static void decode_16x16(MACROBLOCKD *xd) {
-  const TX_TYPE tx_type = get_tx_type_16x16(xd, 0);
-
-  vp9_iht_add_16x16_c(tx_type, xd->plane[0].qcoeff, xd->plane[0].dst.buf,
-                      xd->plane[0].dst.stride, xd->plane[0].eobs[0]);
-
-  vp9_idct_add_8x8(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
-                   xd->plane[1].dst.stride, xd->plane[1].eobs[0]);
-
-  vp9_idct_add_8x8(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
-                   xd->plane[1].dst.stride, xd->plane[2].eobs[0]);
-}
-
 static void decode_8x8(MACROBLOCKD *xd) {
   const MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
   // luma
   // if the first one is DCT_DCT assume all the rest are as well
   TX_TYPE tx_type = get_tx_type_8x8(xd, 0);
-  if (tx_type != DCT_DCT || mode == I8X8_PRED) {
-    int i;
-    for (i = 0; i < 4; i++) {
-      int ib = vp9_i8x8_block[i];
-      int idx = (ib & 0x02) ? (ib + 2) : ib;
-      int16_t *q  = BLOCK_OFFSET(xd->plane[0].qcoeff, idx, 16);
-      uint8_t* const dst =
+  int i;
+  assert(mode == I8X8_PRED);
+  for (i = 0; i < 4; i++) {
+    int ib = vp9_i8x8_block[i];
+    int idx = (ib & 0x02) ? (ib + 2) : ib;
+    int16_t *q  = BLOCK_OFFSET(xd->plane[0].qcoeff, idx, 16);
+    uint8_t* const dst =
           raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 0, ib,
                                     xd->plane[0].dst.buf,
                                     xd->plane[0].dst.stride);
-      int stride = xd->plane[0].dst.stride;
-      if (mode == I8X8_PRED) {
-        int i8x8mode = xd->mode_info_context->bmi[ib].as_mode.first;
-        vp9_intra8x8_predict(xd, ib, i8x8mode, dst, stride);
-      }
-      tx_type = get_tx_type_8x8(xd, ib);
-      vp9_iht_add_8x8_c(tx_type, q, dst, stride, xd->plane[0].eobs[idx]);
+    int stride = xd->plane[0].dst.stride;
+    if (mode == I8X8_PRED) {
+      int i8x8mode = xd->mode_info_context->bmi[ib].as_mode.first;
+      vp9_intra8x8_predict(xd, ib, i8x8mode, dst, stride);
     }
-  } else {
-    vp9_idct_add_y_block_8x8(xd->plane[0].qcoeff, xd->plane[0].dst.buf,
-                             xd->plane[0].dst.stride, xd);
+    tx_type = get_tx_type_8x8(xd, ib);
+    vp9_iht_add_8x8_c(tx_type, q, dst, stride, xd->plane[0].eobs[idx]);
   }
 
   // chroma
-  if (mode == I8X8_PRED) {
-    int i;
-    for (i = 0; i < 4; i++) {
-      int ib = vp9_i8x8_block[i];
-      int i8x8mode = xd->mode_info_context->bmi[ib].as_mode.first;
-      uint8_t* dst;
-
-      dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 1, i,
-                                      xd->plane[1].dst.buf,
-                                      xd->plane[1].dst.stride);
-      vp9_intra_uv4x4_predict(xd, 16 + i, i8x8mode,
-                              dst, xd->plane[1].dst.stride);
-      xd->itxm_add(BLOCK_OFFSET(xd->plane[1].qcoeff, i, 16),
-                   dst, xd->plane[1].dst.stride,
-                   xd->plane[1].eobs[i]);
-
-      dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 2, i,
-                                      xd->plane[2].dst.buf,
-                                      xd->plane[1].dst.stride);
-      vp9_intra_uv4x4_predict(xd, 20 + i, i8x8mode,
-                              dst, xd->plane[1].dst.stride);
-      xd->itxm_add(BLOCK_OFFSET(xd->plane[2].qcoeff, i, 16),
-                   dst, xd->plane[1].dst.stride,
-                   xd->plane[2].eobs[i]);
-    }
-  } else if (mode == SPLITMV) {
-    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
-        xd->plane[1].dst.stride, xd->plane[1].eobs);
-    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
-        xd->plane[1].dst.stride, xd->plane[2].eobs);
-  } else {
-    vp9_idct_add_8x8(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
-                     xd->plane[1].dst.stride, xd->plane[1].eobs[0]);
+  for (i = 0; i < 4; i++) {
+    int ib = vp9_i8x8_block[i];
+    int i8x8mode = xd->mode_info_context->bmi[ib].as_mode.first;
+    uint8_t* dst;
 
-    vp9_idct_add_8x8(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
-                     xd->plane[1].dst.stride, xd->plane[2].eobs[0]);
+    dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 1, i,
+                                    xd->plane[1].dst.buf,
+                                    xd->plane[1].dst.stride);
+    vp9_intra_uv4x4_predict(xd, 16 + i, i8x8mode,
+                            dst, xd->plane[1].dst.stride);
+    xd->itxm_add(BLOCK_OFFSET(xd->plane[1].qcoeff, i, 16),
+                 dst, xd->plane[1].dst.stride,
+                 xd->plane[1].eobs[i]);
+
+    dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 2, i,
+                                    xd->plane[2].dst.buf,
+                                    xd->plane[1].dst.stride);
+    vp9_intra_uv4x4_predict(xd, 20 + i, i8x8mode,
+                            dst, xd->plane[1].dst.stride);
+    xd->itxm_add(BLOCK_OFFSET(xd->plane[2].qcoeff, i, 16),
+                 dst, xd->plane[1].dst.stride,
+                 xd->plane[2].eobs[i]);
   }
 }
 #endif
@@ -305,55 +274,38 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd, vp9_reader *r) {
   TX_TYPE tx_type;
   int i = 0;
   const MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
-  if (mode == I8X8_PRED) {
-    for (i = 0; i < 4; i++) {
-      int ib = vp9_i8x8_block[i];
-      const int iblock[4] = {0, 1, 4, 5};
-      int j;
-      uint8_t* dst;
-      int i8x8mode = xd->mode_info_context->bmi[ib].as_mode.first;
+  assert(mode == I8X8_PRED);
+  for (i = 0; i < 4; i++) {
+    int ib = vp9_i8x8_block[i];
+    const int iblock[4] = {0, 1, 4, 5};
+    int j;
+    uint8_t* dst;
+    int i8x8mode = xd->mode_info_context->bmi[ib].as_mode.first;
 
-      dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 0, ib,
-                                      xd->plane[0].dst.buf,
-                                      xd->plane[0].dst.stride);
-      vp9_intra8x8_predict(xd, ib, i8x8mode, dst, xd->plane[0].dst.stride);
-      for (j = 0; j < 4; j++) {
-        tx_type = get_tx_type_4x4(xd, ib + iblock[j]);
-        dequant_add_y(xd, tx_type, ib + iblock[j]);
-      }
-      dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 1, i,
-                                      xd->plane[1].dst.buf,
-                                      xd->plane[1].dst.stride);
-      vp9_intra_uv4x4_predict(xd, 16 + i, i8x8mode,
-                              dst, xd->plane[1].dst.stride);
-      xd->itxm_add(BLOCK_OFFSET(xd->plane[1].qcoeff, i, 16),
-                   dst, xd->plane[1].dst.stride,
-                   xd->plane[1].eobs[i]);
-      dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 2, i,
-                                      xd->plane[2].dst.buf,
-                                      xd->plane[2].dst.stride);
-      vp9_intra_uv4x4_predict(xd, 20 + i, i8x8mode,
-                              dst, xd->plane[1].dst.stride);
-      xd->itxm_add(BLOCK_OFFSET(xd->plane[2].qcoeff, i, 16),
-                   dst, xd->plane[1].dst.stride,
-                   xd->plane[2].eobs[i]);
-    }
-  } else if (mode == SPLITMV || get_tx_type_4x4(xd, 0) == DCT_DCT) {
-    xd->itxm_add_y_block(xd->plane[0].qcoeff, xd->plane[0].dst.buf,
-        xd->plane[0].dst.stride, xd);
-    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
-        xd->plane[1].dst.stride, xd->plane[1].eobs);
-    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
-        xd->plane[1].dst.stride, xd->plane[2].eobs);
-  } else {
-    for (i = 0; i < 16; i++) {
-      tx_type = get_tx_type_4x4(xd, i);
-      dequant_add_y(xd, tx_type, i);
+    dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 0, ib,
+                                    xd->plane[0].dst.buf,
+                                    xd->plane[0].dst.stride);
+    vp9_intra8x8_predict(xd, ib, i8x8mode, dst, xd->plane[0].dst.stride);
+    for (j = 0; j < 4; j++) {
+      tx_type = get_tx_type_4x4(xd, ib + iblock[j]);
+      dequant_add_y(xd, tx_type, ib + iblock[j]);
     }
-    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
-                          xd->plane[1].dst.stride, xd->plane[1].eobs);
-    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
-                          xd->plane[1].dst.stride, xd->plane[2].eobs);
+    dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 1, i,
+                                    xd->plane[1].dst.buf,
+                                    xd->plane[1].dst.stride);
+    vp9_intra_uv4x4_predict(xd, 16 + i, i8x8mode,
+                            dst, xd->plane[1].dst.stride);
+    xd->itxm_add(BLOCK_OFFSET(xd->plane[1].qcoeff, i, 16),
+                 dst, xd->plane[1].dst.stride,
+                 xd->plane[1].eobs[i]);
+    dst = raster_block_offset_uint8(xd, BLOCK_SIZE_MB16X16, 2, i,
+                                    xd->plane[2].dst.buf,
+                                    xd->plane[2].dst.stride);
+    vp9_intra_uv4x4_predict(xd, 20 + i, i8x8mode,
+                            dst, xd->plane[1].dst.stride);
+    xd->itxm_add(BLOCK_OFFSET(xd->plane[2].qcoeff, i, 16),
+                 dst, xd->plane[1].dst.stride,
+                 xd->plane[2].eobs[i]);
   }
 }
 #endif
@@ -525,39 +477,16 @@ static void decode_sb(VP9D_COMP *pbi, MACROBLOCKD *xd, int mi_row, int mi_col,
 }
 
 #if !CONFIG_SB8X8
-// TODO(jingning): Need to merge SB and MB decoding. The MB decoding currently
-// couples special handles on I8x8, B_PRED, and splitmv modes.
+// TODO(jingning): This only performs I8X8_PRED decoding process, which will be
+// automatically covered by decode_sb, when SB8X8 is on.
 static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd,
                      int mi_row, int mi_col,
                      vp9_reader *r) {
-  int eobtotal = 0;
   MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
-  const MB_PREDICTION_MODE mode = mbmi->mode;
   const int tx_size = mbmi->txfm_size;
 
   assert(mbmi->sb_type == BLOCK_SIZE_MB16X16);
 
-  //mode = xd->mode_info_context->mbmi.mode;
-  if (pbi->common.frame_type != KEY_FRAME)
-    vp9_setup_interp_filters(xd, mbmi->interp_filter, &pbi->common);
-
-  // do prediction
-  if (mbmi->ref_frame == INTRA_FRAME) {
-    if (mode != I8X8_PRED) {
-      vp9_build_intra_predictors_sbuv_s(xd, BLOCK_SIZE_MB16X16);
-      if (mode != I4X4_PRED)
-        vp9_build_intra_predictors_sby_s(xd, BLOCK_SIZE_MB16X16);
-    }
-  } else {
-#if 0  // def DEC_DEBUG
-  if (dec_debug)
-    printf("Decoding mb:  %d %d interp %d\n",
-           xd->mode_info_context->mbmi.mode, tx_size,
-           xd->mode_info_context->mbmi.interp_filter);
-#endif
-    vp9_build_inter_predictors_sb(xd, mi_row, mi_col, BLOCK_SIZE_MB16X16);
-  }
-
   if (mbmi->mb_skip_coeff) {
     vp9_reset_sb_tokens_context(xd, BLOCK_SIZE_MB16X16);
   } else {
@@ -565,67 +494,14 @@ static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd,
     if (xd->segmentation_enabled)
       mb_init_dequantizer(&pbi->common, xd);
 
-    if (!vp9_reader_has_error(r)) {
-#if CONFIG_NEWBINTRAMODES
-    if (mode != I4X4_PRED)
-#endif
-      eobtotal = vp9_decode_tokens(pbi, xd, r, BLOCK_SIZE_MB16X16);
-    }
-  }
-
-  if (eobtotal == 0 &&
-      mode != I4X4_PRED && mode != I8X8_PRED && mode != SPLITMV &&
-      !vp9_reader_has_error(r)) {
-    mbmi->mb_skip_coeff = 1;
-  } else {
-#if 0  // def DEC_DEBUG
-  if (dec_debug)
-    printf("Decoding mb:  %d %d\n", xd->mode_info_context->mbmi.mode, tx_size);
-#endif
-
-    if (tx_size == TX_16X16) {
-      decode_16x16(xd);
-    } else if (tx_size == TX_8X8) {
-      decode_8x8(xd);
-    } else {
-      decode_4x4(pbi, xd, r);
-    }
+    if (!vp9_reader_has_error(r))
+      vp9_decode_tokens(pbi, xd, r, BLOCK_SIZE_MB16X16);
   }
 
-#ifdef DEC_DEBUG
-  if (dec_debug) {
-    int i, j;
-    printf("\n");
-    printf("predictor y\n");
-    for (i = 0; i < 16; i++) {
-      for (j = 0; j < 16; j++)
-        printf("%3d ", xd->predictor[i * 16 + j]);
-      printf("\n");
-    }
-    printf("\n");
-    printf("final y\n");
-    for (i = 0; i < 16; i++) {
-      for (j = 0; j < 16; j++)
-        printf("%3d ", xd->plane[0].dst.buf[i * xd->plane[0].dst.stride + j]);
-      printf("\n");
-    }
-    printf("\n");
-    printf("final u\n");
-    for (i = 0; i < 8; i++) {
-      for (j = 0; j < 8; j++)
-        printf("%3d ", xd->plane[1].dst.buf[i * xd->plane[1].dst.stride + j]);
-      printf("\n");
-    }
-    printf("\n");
-    printf("final v\n");
-    for (i = 0; i < 8; i++) {
-      for (j = 0; j < 8; j++)
-        printf("%3d ", xd->plane[2].dst.buf[i * xd->plane[1].dst.stride + j]);
-      printf("\n");
-    }
-    fflush(stdout);
-  }
-#endif
+  if (tx_size == TX_8X8)
+    decode_8x8(xd);
+  else
+    decode_4x4(pbi, xd, r);
 }
 #endif
 
@@ -715,7 +591,10 @@ static void decode_modes_b(VP9D_COMP *pbi, int mi_row, int mi_col,
   set_refs(pbi, mi_row, mi_col);
 
 #if CONFIG_SB8X8
-  decode_sb(pbi, xd, mi_row, mi_col, r, bsize);
+  if (bsize >= BLOCK_SIZE_SB8X8)
+    decode_sb(pbi, xd, mi_row, mi_col, r, bsize);
+  else
+    decode_atom(pbi, xd, mi_row, mi_col, r, BLOCK_SIZE_SB8X8);
 #else
   // TODO(jingning): merge decode_sb_ and decode_mb_
   if (bsize > BLOCK_SIZE_MB16X16) {
@@ -728,9 +607,11 @@ static void decode_modes_b(VP9D_COMP *pbi, int mi_row, int mi_col,
         (xd->mode_info_context->mbmi.mode == SPLITMV &&
          xd->mode_info_context->mbmi.partitioning == PARTITIONING_4X4))
       decode_atom(pbi, xd, mi_row, mi_col, r, bsize);
+    else if (xd->mode_info_context->mbmi.mode != I8X8_PRED)
+      decode_sb(pbi, xd, mi_row, mi_col, r, bsize);
     else
-      // TODO(jingning): decode_mb still carries deocding process of I8X8_PRED
-      // and SPLITMV of 8x8, 16x8, and 8x16. To be migrated into decode_sb.
+      // TODO(jingning): decode_mb still carries deocding process of I8X8_PRED.
+      // This will be covered by decode_sb when SB8X8 is on.
       decode_mb(pbi, xd, mi_row, mi_col, r);
   }
 #endif