From e63099d199b492710cd2d74f02f56071ba8a6749 Mon Sep 17 00:00:00 2001
From: Jingning Han <jingning@google.com>
Date: Tue, 9 Apr 2013 20:34:25 -0700
Subject: [PATCH] Make SB Decoding units size-independent

Unify the sb32x32 and sb64x64 decoding units, which also allow for
other rectangular block sizes.

Change-Id: Ia5187ab2af56f98c3f99272bdf4dbcabe798ad5d
---
 vp9/decoder/vp9_decodframe.c |  6 +++---
 vp9/decoder/vp9_detokenize.c | 30 ++++++++++--------------------
 vp9/decoder/vp9_detokenize.h | 14 ++++----------
 3 files changed, 17 insertions(+), 33 deletions(-)

diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c
index 1e95e2207..5aecbe933 100644
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -625,7 +625,7 @@ static void decode_sb64(VP9D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col,
   }
 
   // dequantization and idct
-  eobtotal = vp9_decode_sb64_tokens(pbi, xd, bc);
+  eobtotal = vp9_decode_tokens(pbi, xd, bc, BLOCK_SIZE_SB64X64);
   if (eobtotal == 0) {  // skip loopfilter
     for (n = 0; n < 16; n++) {
       const int x_idx = n & 3, y_idx = n >> 2;
@@ -704,7 +704,7 @@ static void decode_sb32(VP9D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col,
   }
 
   // dequantization and idct
-  eobtotal = vp9_decode_sb_tokens(pbi, xd, bc);
+  eobtotal = vp9_decode_tokens(pbi, xd, bc, BLOCK_SIZE_SB32X32);
   if (eobtotal == 0) {  // skip loopfilter
     mi->mbmi.mb_skip_coeff = 1;
     if (mb_col + 1 < pc->mb_cols)
@@ -766,7 +766,7 @@ static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd,
 #if CONFIG_NEWBINTRAMODES
     if (mode != B_PRED)
 #endif
-      eobtotal = vp9_decode_mb_tokens(pbi, xd, bc);
+      eobtotal = vp9_decode_tokens(pbi, xd, bc, BLOCK_SIZE_MB16X16);
   }
 
   //mode = xd->mode_info_context->mbmi.mode;
diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c
index 9077fcde1..f9e9da9bc 100644
--- a/vp9/decoder/vp9_detokenize.c
+++ b/vp9/decoder/vp9_detokenize.c
@@ -401,26 +401,26 @@ static INLINE int block_idx_4x4(MACROBLOCKD* const xd, int block_size_b,
 static INLINE int decode_block_plane(VP9D_COMP* const pbi,
                                      MACROBLOCKD* const xd,
                                      BOOL_DECODER* const bc,
-                                     BLOCK_SIZE_LG2 block_size,
+                                     int block_size,
                                      int segment_id,
                                      int plane,
                                      int is_split) {
   // block and transform sizes, in number of 4x4 blocks log 2 ("*_b")
   // 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8
   const TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
-  const BLOCK_SIZE_LG2 block_size_b = block_size;
-  const BLOCK_SIZE_LG2 txfrm_size_b = tx_size * 2;
+  const int block_size_b = block_size;
+  const int txfrm_size_b = tx_size * 2;
 
   // subsampled size of the block
   const int ss_sum = xd->plane[plane].subsampling_x +
                      xd->plane[plane].subsampling_y;
-  const BLOCK_SIZE_LG2 ss_block_size = block_size_b - ss_sum;
+  const int ss_block_size = block_size_b - ss_sum;
 
   // size of the transform to use. scale the transform down if it's larger
   // than the size of the subsampled data, or forced externally by the mb mode.
   const int ss_max = MAX(xd->plane[plane].subsampling_x,
                          xd->plane[plane].subsampling_y);
-  const BLOCK_SIZE_LG2 ss_txfrm_size = txfrm_size_b > ss_block_size || is_split
+  const int ss_txfrm_size = txfrm_size_b > ss_block_size || is_split
                                        ? txfrm_size_b - ss_max * 2
                                        : txfrm_size_b;
   const TX_SIZE ss_tx_size = ss_txfrm_size / 2;
@@ -477,22 +477,12 @@ static INLINE int decode_blocks(VP9D_COMP* const pbi,
       tx_size == TX_8X8 && (mode == I8X8_PRED || mode == SPLITMV));
 }
 
-int vp9_decode_sb64_tokens(VP9D_COMP* const pbi,
-                           MACROBLOCKD* const xd,
-                           BOOL_DECODER* const bc) {
-  return decode_blocks(pbi, xd, bc, BLOCK_64X64_LG2);
-}
-
-int vp9_decode_sb_tokens(VP9D_COMP* const pbi,
+int vp9_decode_tokens(VP9D_COMP* const pbi,
                          MACROBLOCKD* const xd,
-                         BOOL_DECODER* const bc) {
-  return decode_blocks(pbi, xd, bc, BLOCK_32X32_LG2);
-}
-
-int vp9_decode_mb_tokens(VP9D_COMP* const pbi,
-                         MACROBLOCKD* const xd,
-                         BOOL_DECODER* const bc) {
-  return decode_blocks(pbi, xd, bc, BLOCK_16X16_LG2);
+                         BOOL_DECODER* const bc,
+                         BLOCK_SIZE_TYPE bsize) {
+  const int bwl = mb_width_log2(bsize) + 2, bhl = mb_height_log2(bsize) + 2;
+  return decode_blocks(pbi, xd, bc, bwl + bhl);
 }
 
 #if CONFIG_NEWBINTRAMODES
diff --git a/vp9/decoder/vp9_detokenize.h b/vp9/decoder/vp9_detokenize.h
index 97de72b9a..e0c29686f 100644
--- a/vp9/decoder/vp9_detokenize.h
+++ b/vp9/decoder/vp9_detokenize.h
@@ -14,16 +14,10 @@
 
 #include "vp9/decoder/vp9_onyxd_int.h"
 
-int vp9_decode_mb_tokens(VP9D_COMP* const, MACROBLOCKD* const,
-                         BOOL_DECODER* const);
-
-int vp9_decode_sb_tokens(VP9D_COMP* const pbi,
-                         MACROBLOCKD* const xd,
-                         BOOL_DECODER* const bc);
-
-int vp9_decode_sb64_tokens(VP9D_COMP* const pbi,
-                           MACROBLOCKD* const xd,
-                           BOOL_DECODER* const bc);
+int vp9_decode_tokens(VP9D_COMP* const pbi,
+                      MACROBLOCKD* const xd,
+                      BOOL_DECODER* const bc,
+                      BLOCK_SIZE_TYPE bsize);
 
 int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx, MACROBLOCKD* const xd,
                                 BOOL_DECODER* const bc);