ref: 8bf6de725ca36813c20054ab50409732fd40a121
parent: c18b2617a4cec330fb1d54e138080405f994ae9a
parent: c2bd46bf455a4986756f75e82a08063e4d43d2a2
author: John Koleszar <jkoleszar@google.com>
date: Thu Apr 11 09:36:25 EDT 2013
Merge changes I6721e42f,Iaffb1ae8 into experimental * changes: tokenize: convert skippable functions Add foreach_transformed_block
--- a/vp9/common/vp9_blockd.h
+++ b/vp9/common/vp9_blockd.h
@@ -758,5 +758,92 @@
return res;
}
+/* TODO(jkoleszar): Probably best to remove instances that require this,
+ * as the data likely becomes per-plane and stored in the per-plane structures.
+ * This is a stub to work with the existing code.
+ */
+static INLINE int old_block_idx_4x4(MACROBLOCKD* const xd, int block_size_b,
+ int plane, int i) {
+ const int luma_blocks = 1 << block_size_b;
+ assert(xd->plane[0].subsampling_x == 0);
+ assert(xd->plane[0].subsampling_y == 0);
+ assert(xd->plane[1].subsampling_x == 1);
+ assert(xd->plane[1].subsampling_y == 1);
+ assert(xd->plane[2].subsampling_x == 1);
+ assert(xd->plane[2].subsampling_y == 1);
+ return plane == 0 ? i :
+ plane == 1 ? luma_blocks + i :
+ luma_blocks * 5 / 4 + i;
+}
+
+typedef void (*foreach_transformed_block_visitor)(int plane, int block,
+ int block_size_b,
+ int ss_txfrm_size,
+ void *arg);
+static INLINE void foreach_transformed_block_in_plane(
+ const MACROBLOCKD* const xd, int block_size, int plane,
+ int is_split, foreach_transformed_block_visitor visit, void *arg) {
+ // 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 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 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 int ss_txfrm_size = txfrm_size_b > ss_block_size || is_split
+ ? txfrm_size_b - ss_max * 2
+ : txfrm_size_b;
+
+ // TODO(jkoleszar): 1 may not be correct here with larger chroma planes.
+ const int inc = is_split ? 1 : (1 << ss_txfrm_size);
+ int i;
+
+ assert(txfrm_size_b <= block_size_b);
+ assert(ss_txfrm_size <= ss_block_size);
+ for (i = 0; i < (1 << ss_block_size); i += inc) {
+ visit(plane, i, block_size_b, ss_txfrm_size, arg);
+ }
+}
+
+static INLINE void foreach_transformed_block(
+ const MACROBLOCKD* const xd, int block_size,
+ foreach_transformed_block_visitor visit, void *arg) {
+ const MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
+ const int is_split =
+ xd->mode_info_context->mbmi.txfm_size == TX_8X8 &&
+ (mode == I8X8_PRED || mode == SPLITMV);
+ int plane;
+
+ for (plane = 0; plane < MAX_MB_PLANE; plane++) {
+ const int is_split_chroma = is_split &&
+ xd->plane[plane].plane_type == PLANE_TYPE_UV;
+
+ foreach_transformed_block_in_plane(xd, block_size, plane, is_split_chroma,
+ visit, arg);
+ }
+}
+
+static INLINE void foreach_transformed_block_uv(
+ const MACROBLOCKD* const xd, int block_size,
+ foreach_transformed_block_visitor visit, void *arg) {
+ const MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
+ const int is_split =
+ xd->mode_info_context->mbmi.txfm_size == TX_8X8 &&
+ (mode == I8X8_PRED || mode == SPLITMV);
+ int plane;
+
+ for (plane = 1; plane < MAX_MB_PLANE; plane++) {
+ foreach_transformed_block_in_plane(xd, block_size, plane, is_split,
+ visit, arg);
+ }
+}
#endif // VP9_COMMON_VP9_BLOCKD_H_
--- a/vp9/decoder/vp9_detokenize.c
+++ b/vp9/decoder/vp9_detokenize.c
@@ -10,6 +10,7 @@
#include "vp9/common/vp9_blockd.h"
+#include "vp9/common/vp9_common.h"
#include "vp9/decoder/vp9_onyxd_int.h"
#include "vpx_mem/vpx_mem.h"
#include "vpx_ports/mem.h"
@@ -382,109 +383,45 @@
return vp9_get_segdata(xd, segment_id, SEG_LVL_SKIP) ? 0 : eob_max;
}
-/* TODO(jkoleszar): Probably best to remove instances that require this,
- * as the data likely becomes per-plane and stored in the per-plane structures.
- * This is a stub to work with the existing code.
- */
-static INLINE int block_idx_4x4(MACROBLOCKD* const xd, int block_size_b,
- int plane, int i) {
- const int luma_blocks = 1 << block_size_b;
- assert(xd->plane[0].subsampling_x == 0);
- assert(xd->plane[0].subsampling_y == 0);
- assert(xd->plane[1].subsampling_x == 1);
- assert(xd->plane[1].subsampling_y == 1);
- assert(xd->plane[2].subsampling_x == 1);
- assert(xd->plane[2].subsampling_y == 1);
- return plane == 0 ? i :
- plane == 1 ? luma_blocks + i :
- luma_blocks * 5 / 4 + i;
-}
-static INLINE int decode_block_plane(VP9D_COMP* const pbi,
- MACROBLOCKD* const xd,
- BOOL_DECODER* const bc,
- 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 int block_size_b = block_size;
- const int txfrm_size_b = tx_size * 2;
+struct decode_block_args {
+ VP9D_COMP *pbi;
+ MACROBLOCKD *xd;
+ BOOL_DECODER *bc;
+ int *eobtotal;
+};
+static void decode_block(int plane, int block,
+ int block_size_b,
+ int ss_txfrm_size,
+ void *argv) {
+ const struct decode_block_args* const arg = argv;
+ const int old_block_idx = old_block_idx_4x4(arg->xd, block_size_b,
+ plane, block);
- // subsampled size of the block
- const int ss_sum = xd->plane[plane].subsampling_x +
- xd->plane[plane].subsampling_y;
- 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 int ss_txfrm_size = txfrm_size_b > ss_block_size || is_split
- ? txfrm_size_b - ss_max * 2
- : txfrm_size_b;
+ // find the maximum eob for this transform size, adjusted by segment
+ const int segment_id = arg->xd->mode_info_context->mbmi.segment_id;
const TX_SIZE ss_tx_size = ss_txfrm_size / 2;
+ const int seg_eob = get_eob(arg->xd, segment_id, 16 << ss_txfrm_size);
+ int16_t* const qcoeff_base = arg->xd->plane[plane].qcoeff;
- // TODO(jkoleszar): 1 may not be correct here with larger chroma planes.
- const int inc = is_split ? 1 : (1 << ss_txfrm_size);
-
- // find the maximum eob for this transform size, adjusted by segment
- const int seg_eob = get_eob(xd, segment_id, 16 << ss_txfrm_size);
-
- int i, eobtotal = 0;
-
- assert(txfrm_size_b <= block_size_b);
- assert(ss_txfrm_size <= ss_block_size);
-
- // step through the block by the size of the transform in use.
- for (i = 0; i < (1 << ss_block_size); i += inc) {
- const int block_idx = block_idx_4x4(xd, block_size_b, plane, i);
-
- const int c = decode_coefs(pbi, xd, bc, block_idx,
- xd->plane[plane].plane_type, seg_eob,
- BLOCK_OFFSET(xd->plane[plane].qcoeff, i, 16),
+ const int eob = decode_coefs(arg->pbi, arg->xd, arg->bc, old_block_idx,
+ arg->xd->plane[plane].plane_type, seg_eob,
+ BLOCK_OFFSET(qcoeff_base, block, 16),
ss_tx_size);
- xd->plane[plane].eobs[i] = c;
- eobtotal += c;
- }
- return eobtotal;
-}
-static INLINE int decode_blocks_helper(VP9D_COMP* const pbi,
- MACROBLOCKD* const xd,
- BOOL_DECODER* const bc,
- int block_size,
- int is_split_chroma) {
- const int segment_id = xd->mode_info_context->mbmi.segment_id;
- int plane, eobtotal = 0;
-
- for (plane = 0; plane < MAX_MB_PLANE; plane++) {
- const int is_split = is_split_chroma &&
- xd->plane[plane].plane_type == PLANE_TYPE_UV;
- eobtotal += decode_block_plane(pbi, xd, bc, block_size, segment_id,
- plane, is_split);
- }
- return eobtotal;
+ arg->xd->plane[plane].eobs[block] = eob;
+ arg->eobtotal[0] += eob;
}
-static INLINE int decode_blocks(VP9D_COMP* const pbi,
- MACROBLOCKD* const xd,
- BOOL_DECODER* const bc,
- int block_size) {
- const MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
- const TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
- return decode_blocks_helper(pbi, xd, bc, block_size,
- tx_size == TX_8X8 && (mode == I8X8_PRED || mode == SPLITMV));
-}
-
int vp9_decode_tokens(VP9D_COMP* const pbi,
MACROBLOCKD* const xd,
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);
+ int eobtotal = 0;
+ struct decode_block_args args = {pbi, xd, bc, &eobtotal};
+ foreach_transformed_block(xd, bwl + bhl, decode_block, &args);
+ return eobtotal;
}
#if CONFIG_NEWBINTRAMODES
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -766,7 +766,7 @@
*distortion = vp9_sb_block_error_c(x->coeff, xd->plane[0].dqcoeff,
16 << (bwl + bhl), 2);
*rate = rdcost_sby_4x4(cm, x, bsize);
- *skippable = vp9_sby_is_skippable(xd, bsize, TX_4X4);
+ *skippable = vp9_sby_is_skippable(xd, bsize);
}
static int rdcost_sby_8x8(VP9_COMMON *const cm, MACROBLOCK *x,
@@ -806,7 +806,7 @@
*distortion = vp9_sb_block_error_c(x->coeff, xd->plane[0].dqcoeff,
64 << (bhl + bwl), 2);
*rate = rdcost_sby_8x8(cm, x, bsize);
- *skippable = vp9_sby_is_skippable(xd, bsize, TX_8X8);
+ *skippable = vp9_sby_is_skippable(xd, bsize);
}
static int rdcost_sby_16x16(VP9_COMMON *const cm, MACROBLOCK *x,
@@ -844,7 +844,7 @@
*distortion = vp9_sb_block_error_c(x->coeff, xd->plane[0].dqcoeff,
256 << (bwl + bhl), 2);
*rate = rdcost_sby_16x16(cm, x, bsize);
- *skippable = vp9_sby_is_skippable(xd, bsize, TX_16X16);
+ *skippable = vp9_sby_is_skippable(xd, bsize);
}
static int rdcost_sby_32x32(VP9_COMMON *const cm, MACROBLOCK *x,
@@ -884,7 +884,7 @@
*distortion = vp9_sb_block_error_c(x->coeff, xd->plane[0].dqcoeff,
1024 << (bwl + bhl), 0);
*rate = rdcost_sby_32x32(cm, x, bsize);
- *skippable = vp9_sby_is_skippable(xd, bsize, TX_32X32);
+ *skippable = vp9_sby_is_skippable(xd, bsize);
}
static void super_block_yrd(VP9_COMP *cpi,
@@ -1446,7 +1446,7 @@
xd->plane[1].dqcoeff,
xd->plane[2].dqcoeff,
32 << (bwl + bhl - 2), 2);
- *skip = vp9_sbuv_is_skippable(xd, bsize, TX_4X4);
+ *skip = vp9_sbuv_is_skippable(xd, bsize);
}
static int rd_cost_sbuv_8x8(VP9_COMMON *const cm, MACROBLOCK *x,
@@ -1491,7 +1491,7 @@
xd->plane[1].dqcoeff,
xd->plane[2].dqcoeff,
128 << (bwl + bhl - 2), 2);
- *skip = vp9_sbuv_is_skippable(xd, bsize, TX_8X8);
+ *skip = vp9_sbuv_is_skippable(xd, bsize);
}
static int rd_cost_sbuv_16x16(VP9_COMMON *const cm, MACROBLOCK *x,
@@ -1536,7 +1536,7 @@
xd->plane[1].dqcoeff,
xd->plane[2].dqcoeff,
512 << (bwl + bhl - 2), 2);
- *skip = vp9_sbuv_is_skippable(xd, bsize, TX_16X16);
+ *skip = vp9_sbuv_is_skippable(xd, bsize);
}
static int rd_cost_sbuv_32x32(VP9_COMMON *const cm, MACROBLOCK *x,
@@ -1582,7 +1582,7 @@
xd->plane[1].dqcoeff,
xd->plane[2].dqcoeff,
2048 << (bwl + bhl - 2), 0);
- *skip = vp9_sbuv_is_skippable(xd, bsize, TX_32X32);
+ *skip = vp9_sbuv_is_skippable(xd, bsize);
}
static void super_block_uvrd(VP9_COMMON *const cm, MACROBLOCK *x,
@@ -2507,13 +2507,6 @@
x->e_mbd.plane[0].eobs[i] = bsi.eobs[i];
}
- *returntotrate = bsi.r;
- *returndistortion = bsi.d;
- *returnyrate = bsi.segment_yrate;
- *skippable = bsi.txfm_size == TX_4X4 ?
- vp9_mby_is_skippable_4x4(&x->e_mbd) :
- vp9_mby_is_skippable_8x8(&x->e_mbd);
-
/* save partitions */
mbmi->txfm_size = bsi.txfm_size;
mbmi->partitioning = bsi.segment_num;
@@ -2535,6 +2528,11 @@
x->partition_info->bmi[15].mv.as_int = bsi.mvs[15].as_int;
if (mbmi->second_ref_frame > 0)
x->partition_info->bmi[15].second_mv.as_int = bsi.second_mvs[15].as_int;
+
+ *returntotrate = bsi.r;
+ *returndistortion = bsi.d;
+ *returnyrate = bsi.segment_yrate;
+ *skippable = vp9_sby_is_skippable(&x->e_mbd, BLOCK_SIZE_MB16X16);
return (int)(bsi.segment_rd);
}
--- a/vp9/encoder/vp9_tokenize.c
+++ b/vp9/encoder/vp9_tokenize.c
@@ -339,97 +339,40 @@
}
}
-int vp9_mby_is_skippable_4x4(MACROBLOCKD *xd) {
- int skip = 1;
- int i = 0;
-
- for (i = 0; i < 16; i++)
- skip &= (!xd->plane[0].eobs[i]);
-
- return skip;
+struct is_skippable_args {
+ MACROBLOCKD *xd;
+ int *skippable;
+};
+static void is_skippable(int plane, int block,
+ int block_size_b, int ss_txfrm_size, void *argv) {
+ struct is_skippable_args *args = argv;
+ args->skippable[0] &= (!args->xd->plane[plane].eobs[block]);
}
-int vp9_mbuv_is_skippable_4x4(MACROBLOCKD *xd) {
- int skip = 1;
- int i;
-
- for (i = 0; i < 4; i++)
- skip &= (!xd->plane[1].eobs[i]);
- for (i = 0; i < 4; i++)
- skip &= (!xd->plane[2].eobs[i]);
- return skip;
+int vp9_sb_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize) {
+ const int bwl = mb_width_log2(bsize) + 2, bhl = mb_height_log2(bsize) + 2;
+ int result = 1;
+ struct is_skippable_args args = {xd, &result};
+ foreach_transformed_block(xd, bwl + bhl, is_skippable, &args);
+ return result;
}
-static int mb_is_skippable_4x4(MACROBLOCKD *xd) {
- return (vp9_mby_is_skippable_4x4(xd) &
- vp9_mbuv_is_skippable_4x4(xd));
+int vp9_sby_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize) {
+ const int bwl = mb_width_log2(bsize) + 2, bhl = mb_height_log2(bsize) + 2;
+ int result = 1;
+ struct is_skippable_args args = {xd, &result};
+ foreach_transformed_block_in_plane(xd, bwl + bhl, 0, 0, is_skippable, &args);
+ return result;
}
-int vp9_mby_is_skippable_8x8(MACROBLOCKD *xd) {
- int skip = 1;
- int i = 0;
-
- for (i = 0; i < 16; i += 4)
- skip &= (!xd->plane[0].eobs[i]);
-
- return skip;
-}
-
-int vp9_mbuv_is_skippable_8x8(MACROBLOCKD *xd) {
- return (!xd->plane[1].eobs[0]) & (!xd->plane[2].eobs[0]);
-}
-
-static int mb_is_skippable_8x8(MACROBLOCKD *xd) {
- return (vp9_mby_is_skippable_8x8(xd) &
- vp9_mbuv_is_skippable_8x8(xd));
-}
-
-static int mb_is_skippable_8x8_4x4uv(MACROBLOCKD *xd) {
- return (vp9_mby_is_skippable_8x8(xd) &
- vp9_mbuv_is_skippable_4x4(xd));
-}
-
-int vp9_mby_is_skippable_16x16(MACROBLOCKD *xd) {
- return (!xd->plane[0].eobs[0]);
-}
-
-static int mb_is_skippable_16x16(MACROBLOCKD *xd) {
- return (vp9_mby_is_skippable_16x16(xd) & vp9_mbuv_is_skippable_8x8(xd));
-}
-
-int vp9_sby_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
- TX_SIZE sz) {
- const int inc = 1 << (sz * 2);
+int vp9_sbuv_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize) {
const int bwl = mb_width_log2(bsize) + 2, bhl = mb_height_log2(bsize) + 2;
- int skip = 1;
- int i = 0;
-
- for (i = 0; i < (1 << (bwl + bhl)); i += inc)
- skip &= (!xd->plane[0].eobs[i]);
-
- return skip;
+ int result = 1;
+ struct is_skippable_args args = {xd, &result};
+ foreach_transformed_block_uv(xd, bwl + bhl, is_skippable, &args);
+ return result;
}
-int vp9_sbuv_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize, TX_SIZE sz) {
- const int inc = 1 << (sz * 2);
- const int bwl = mb_width_log2(bsize) + 1, bhl = mb_height_log2(bsize) + 1;
- int skip = 1;
- int i = 0;
-
- for (i = 0; i < (1 << (bwl + bhl)); i += inc) {
- skip &= (!xd->plane[1].eobs[i]);
- skip &= (!xd->plane[2].eobs[i]);
- }
-
- return skip;
-}
-
-static int sb_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
- TX_SIZE ysz, TX_SIZE uvsz) {
- return vp9_sby_is_skippable(xd, bsize, ysz) &
- vp9_sbuv_is_skippable(xd, bsize, uvsz);
-}
-
void vp9_tokenize_sb(VP9_COMP *cpi,
MACROBLOCKD *xd,
TOKENEXTRA **t,
@@ -449,7 +392,7 @@
int b;
const int n_y = (1 << (bwl + bhl)), n_uv = (n_y * 3) >> 1;
- mbmi->mb_skip_coeff = sb_is_skippable(xd, bsize, txfm_size, uv_txfm_size);
+ mbmi->mb_skip_coeff = vp9_sb_is_skippable(xd, bsize);
if (mbmi->mb_skip_coeff) {
if (!dry_run)
@@ -541,26 +484,8 @@
} else
skip_inc = 0;
- switch (tx_size) {
- case TX_16X16:
-
- xd->mode_info_context->mbmi.mb_skip_coeff = mb_is_skippable_16x16(xd);
- break;
- case TX_8X8:
- if (xd->mode_info_context->mbmi.mode == I8X8_PRED ||
- xd->mode_info_context->mbmi.mode == SPLITMV)
- xd->mode_info_context->mbmi.mb_skip_coeff =
- mb_is_skippable_8x8_4x4uv(xd);
- else
- xd->mode_info_context->mbmi.mb_skip_coeff =
- mb_is_skippable_8x8(xd);
- break;
-
- default:
- xd->mode_info_context->mbmi.mb_skip_coeff =
- mb_is_skippable_4x4(xd);
- break;
- }
+ xd->mode_info_context->mbmi.mb_skip_coeff = vp9_sb_is_skippable(xd,
+ BLOCK_SIZE_MB16X16);
if (xd->mode_info_context->mbmi.mb_skip_coeff) {
if (!dry_run)
--- a/vp9/encoder/vp9_tokenize.h
+++ b/vp9/encoder/vp9_tokenize.h
@@ -31,15 +31,9 @@
typedef int64_t vp9_coeff_accum[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[MAX_ENTROPY_TOKENS + 1];
-int vp9_mby_is_skippable_4x4(MACROBLOCKD *xd);
-int vp9_mbuv_is_skippable_4x4(MACROBLOCKD *xd);
-int vp9_mby_is_skippable_8x8(MACROBLOCKD *xd);
-int vp9_mbuv_is_skippable_8x8(MACROBLOCKD *xd);
-int vp9_mby_is_skippable_16x16(MACROBLOCKD *xd);
-
-int vp9_sby_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize, TX_SIZE sz);
-int vp9_sbuv_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize, TX_SIZE sz);
-
+int vp9_sb_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize);
+int vp9_sby_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize);
+int vp9_sbuv_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize);
struct VP9_COMP;
void vp9_tokenize_mb(struct VP9_COMP *cpi, MACROBLOCKD *xd,
--
⑨