Commit 6f06450c authored by Dmitry Kovalev's avatar Dmitry Kovalev

Code cleanup inside the decoder code.

Change-Id: I927c7223996cdeb44f46e0e6c2e2054d458c300b
parent b1caa7c5
......@@ -199,14 +199,14 @@ static void mb_init_dequantizer(VP9_COMMON *pc, MACROBLOCKD *xd) {
static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size, void *arg) {
MACROBLOCKD* const xd = arg;
int16_t* const qcoeff = BLOCK_OFFSET(xd->plane[plane].qcoeff, block, 16);
const int stride = xd->plane[plane].dst.stride;
struct macroblockd_plane *pd = &xd->plane[plane];
int16_t* const qcoeff = BLOCK_OFFSET(pd->qcoeff, block, 16);
const int stride = pd->dst.stride;
const int raster_block = txfrm_block_to_raster_block(xd, bsize, plane,
block, ss_txfrm_size);
uint8_t* const dst = raster_block_offset_uint8(xd, bsize, plane,
raster_block,
xd->plane[plane].dst.buf,
stride);
pd->dst.buf, stride);
TX_TYPE tx_type;
......@@ -214,23 +214,20 @@ static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
case TX_4X4:
tx_type = plane == 0 ? get_tx_type_4x4(xd, raster_block) : DCT_DCT;
if (tx_type == DCT_DCT)
xd->itxm_add(qcoeff, dst, stride, xd->plane[plane].eobs[block]);
xd->itxm_add(qcoeff, dst, stride, pd->eobs[block]);
else
vp9_iht_add_c(tx_type, qcoeff, dst, stride,
xd->plane[plane].eobs[block]);
vp9_iht_add_c(tx_type, qcoeff, dst, stride, pd->eobs[block]);
break;
case TX_8X8:
tx_type = plane == 0 ? get_tx_type_8x8(xd, raster_block) : DCT_DCT;
vp9_iht_add_8x8_c(tx_type, qcoeff, dst, stride,
xd->plane[plane].eobs[block]);
vp9_iht_add_8x8_c(tx_type, qcoeff, dst, stride, pd->eobs[block]);
break;
case TX_16X16:
tx_type = plane == 0 ? get_tx_type_16x16(xd, raster_block) : DCT_DCT;
vp9_iht_add_16x16_c(tx_type, qcoeff, dst, stride,
xd->plane[plane].eobs[block]);
vp9_iht_add_16x16_c(tx_type, qcoeff, dst, stride, pd->eobs[block]);
break;
case TX_32X32:
vp9_idct_add_32x32(qcoeff, dst, stride, xd->plane[plane].eobs[block]);
vp9_idct_add_32x32(qcoeff, dst, stride, pd->eobs[block]);
break;
}
}
......@@ -238,65 +235,40 @@ static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
static void decode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size, void *arg) {
MACROBLOCKD* const xd = arg;
int16_t* const qcoeff = BLOCK_OFFSET(xd->plane[plane].qcoeff, block, 16);
const int stride = xd->plane[plane].dst.stride;
struct macroblockd_plane *pd = &xd->plane[plane];
const int raster_block = txfrm_block_to_raster_block(xd, bsize, plane,
block, ss_txfrm_size);
uint8_t* const dst = raster_block_offset_uint8(xd, bsize, plane,
raster_block,
xd->plane[plane].dst.buf,
stride);
pd->dst.buf, pd->dst.stride);
const TX_SIZE tx_size = (TX_SIZE)(ss_txfrm_size / 2);
TX_TYPE tx_type;
int mode, b_mode;
int b_mode;
int plane_b_size;
int tx_ib = raster_block >> tx_size;
mode = plane == 0? xd->mode_info_context->mbmi.mode:
xd->mode_info_context->mbmi.uv_mode;
const int tx_ib = raster_block >> tx_size;
const int mode = plane == 0 ? xd->mode_info_context->mbmi.mode
: xd->mode_info_context->mbmi.uv_mode;
if (xd->mode_info_context->mbmi.sb_type < BLOCK_SIZE_SB8X8 && plane == 0) {
if (plane == 0 && xd->mode_info_context->mbmi.sb_type < BLOCK_SIZE_SB8X8) {
assert(bsize == BLOCK_SIZE_SB8X8);
b_mode = xd->mode_info_context->bmi[raster_block].as_mode.first;
} else {
b_mode = mode;
}
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0)
extend_for_intra(xd, plane, block, bsize, ss_txfrm_size);
}
plane_b_size = b_width_log2(bsize) - xd->plane[plane].subsampling_x;
vp9_predict_intra_block(xd, tx_ib, plane_b_size, tx_size,
b_mode, dst, xd->plane[plane].dst.stride);
plane_b_size = b_width_log2(bsize) - pd->subsampling_x;
vp9_predict_intra_block(xd, tx_ib, plane_b_size, tx_size, b_mode,
dst, pd->dst.stride);
// Early exit if there are no coefficients
if (xd->mode_info_context->mbmi.mb_skip_coeff)
return;
switch (ss_txfrm_size / 2) {
case TX_4X4:
tx_type = plane == 0 ? get_tx_type_4x4(xd, raster_block) : DCT_DCT;
if (tx_type == DCT_DCT)
xd->itxm_add(qcoeff, dst, stride, xd->plane[plane].eobs[block]);
else
vp9_iht_add_c(tx_type, qcoeff, dst, stride,
xd->plane[plane].eobs[block]);
break;
case TX_8X8:
tx_type = plane == 0 ? get_tx_type_8x8(xd, raster_block) : DCT_DCT;
vp9_iht_add_8x8_c(tx_type, qcoeff, dst, stride,
xd->plane[plane].eobs[block]);
break;
case TX_16X16:
tx_type = plane == 0 ? get_tx_type_16x16(xd, raster_block) : DCT_DCT;
vp9_iht_add_16x16_c(tx_type, qcoeff, dst, stride,
xd->plane[plane].eobs[block]);
break;
case TX_32X32:
vp9_idct_add_32x32(qcoeff, dst, stride, xd->plane[plane].eobs[block]);
break;
}
decode_block(plane, block, bsize, ss_txfrm_size, arg);
}
static void decode_atom(VP9D_COMP *pbi, MACROBLOCKD *xd,
......@@ -315,13 +287,11 @@ static void decode_atom(VP9D_COMP *pbi, MACROBLOCKD *xd,
if (mbmi->mb_skip_coeff) {
vp9_reset_sb_tokens_context(xd, bsize);
} else {
// re-initialize macroblock dequantizer before detokenization
if (xd->segmentation_enabled)
mb_init_dequantizer(&pbi->common, xd);
if (!vp9_reader_has_error(r)) {
vp9_decode_tokens(pbi, xd, r, bsize);
}
if (!vp9_reader_has_error(r))
vp9_decode_tokens(pbi, r, bsize);
foreach_transformed_block(xd, bsize, decode_block, xd);
}
......@@ -334,13 +304,11 @@ static void decode_sb_intra(VP9D_COMP *pbi, MACROBLOCKD *xd,
if (mbmi->mb_skip_coeff) {
vp9_reset_sb_tokens_context(xd, bsize);
} else {
// re-initialize macroblock dequantizer before detokenization
if (xd->segmentation_enabled)
mb_init_dequantizer(&pbi->common, xd);
if (!vp9_reader_has_error(r)) {
vp9_decode_tokens(pbi, xd, r, bsize);
}
if (!vp9_reader_has_error(r))
vp9_decode_tokens(pbi, r, bsize);
}
foreach_transformed_block(xd, bsize, decode_block_intra, xd);
......@@ -374,7 +342,7 @@ static void decode_sb(VP9D_COMP *pbi, MACROBLOCKD *xd, int mi_row, int mi_col,
mb_init_dequantizer(pc, xd);
// dequantization and idct
eobtotal = vp9_decode_tokens(pbi, xd, r, bsize);
eobtotal = vp9_decode_tokens(pbi, r, bsize);
if (eobtotal == 0) { // skip loopfilter
for (n = 0; n < bw * bh; n++) {
const int x_idx = n & (bw - 1), y_idx = n >> bwl;
......@@ -390,10 +358,10 @@ static void decode_sb(VP9D_COMP *pbi, MACROBLOCKD *xd, int mi_row, int mi_col,
static void set_offsets(VP9D_COMP *pbi, BLOCK_SIZE_TYPE bsize,
int mi_row, int mi_col) {
const int bh = 1 << mi_height_log2(bsize);
const int bw = 1 << mi_width_log2(bsize);
VP9_COMMON *const cm = &pbi->common;
MACROBLOCKD *const xd = &pbi->mb;
const int bh = 1 << mi_height_log2(bsize);
const int bw = 1 << mi_width_log2(bsize);
const int mi_idx = mi_row * cm->mode_info_stride + mi_col;
int i;
......@@ -401,14 +369,14 @@ static void set_offsets(VP9D_COMP *pbi, BLOCK_SIZE_TYPE bsize,
xd->mode_info_context->mbmi.sb_type = bsize;
// Special case: if prev_mi is NULL, the previous mode info context
// cannot be used.
xd->prev_mode_info_context = cm->prev_mi ?
cm->prev_mi + mi_idx : NULL;
xd->prev_mode_info_context = cm->prev_mi ? cm->prev_mi + mi_idx : NULL;
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].above_context = cm->above_context[i] +
(mi_col * 2 >> xd->plane[i].subsampling_x);
xd->plane[i].left_context = cm->left_context[i] +
(((mi_row * 2) & 15) >> xd->plane[i].subsampling_y);
struct macroblockd_plane *pd = &xd->plane[i];
pd->above_context = cm->above_context[i] +
(mi_col * 2 >> pd->subsampling_x);
pd->left_context = cm->left_context[i] +
(((mi_row * 2) & 15) >> pd->subsampling_y);
}
xd->above_seg_context = cm->above_seg_context + mi_col;
xd->left_seg_context = cm->left_seg_context + (mi_row & MI_MASK);
......@@ -474,8 +442,7 @@ static void decode_modes_sb(VP9D_COMP *pbi, int mi_row, int mi_col,
vp9_reader* r, BLOCK_SIZE_TYPE bsize) {
VP9_COMMON *const pc = &pbi->common;
MACROBLOCKD *const xd = &pbi->mb;
int bsl = mi_width_log2(bsize), bs = (1 << bsl) / 2;
int n;
int bs = (1 << mi_width_log2(bsize)) / 2, n;
PARTITION_TYPE partition = PARTITION_NONE;
BLOCK_SIZE_TYPE subsize;
......@@ -563,26 +530,22 @@ static void setup_token_decoder(VP9D_COMP *pbi,
static void read_coef_probs_common(FRAME_CONTEXT *fc, TX_SIZE tx_size,
vp9_reader *r) {
const int entropy_nodes_update = UNCONSTRAINED_NODES;
vp9_coeff_probs_model *coef_probs = fc->coef_probs[tx_size];
int i, j, k, l, m;
if (vp9_read_bit(r)) {
int i, j, k, l, m;
for (i = 0; i < BLOCK_TYPES; i++) {
for (j = 0; j < REF_TYPES; j++) {
for (k = 0; k < COEF_BANDS; k++) {
for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
const int mstart = 0;
if (l >= 3 && k == 0)
continue;
for (m = mstart; m < entropy_nodes_update; m++) {
for (m = 0; m < UNCONSTRAINED_NODES; m++) {
vp9_prob *const p = coef_probs[i][j][k][l] + m;
if (vp9_read(r, VP9_COEF_UPDATE_PROB)) {
if (vp9_read(r, VP9_COEF_UPDATE_PROB))
*p = vp9_read_prob_diff_update(r, *p);
}
}
}
}
......@@ -1118,8 +1081,7 @@ static size_t read_uncompressed_header(VP9D_COMP *pbi,
cm->frame_context_idx = vp9_rb_read_literal(rb, NUM_FRAME_CONTEXTS_LG2);
if ((cm->frame_type == KEY_FRAME) ||
cm->error_resilient_mode || cm->intra_only)
if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || cm->intra_only)
vp9_setup_past_independence(cm, xd);
setup_loopfilter(pbi, rb);
......
......@@ -8,15 +8,16 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "vpx_mem/vpx_mem.h"
#include "vpx_ports/mem.h"
#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"
#include "vp9/decoder/vp9_detokenize.h"
#include "vp9/common/vp9_seg_common.h"
#include "vp9/decoder/vp9_detokenize.h"
#include "vp9/decoder/vp9_onyxd_int.h"
#if CONFIG_BALANCED_COEFTREE
#define ZERO_CONTEXT_NODE 0
#define EOB_CONTEXT_NODE 1
......@@ -24,6 +25,7 @@
#define EOB_CONTEXT_NODE 0
#define ZERO_CONTEXT_NODE 1
#endif
#define ONE_CONTEXT_NODE 2
#define LOW_VAL_CONTEXT_NODE 3
#define TWO_CONTEXT_NODE 4
......@@ -89,13 +91,12 @@ DECLARE_ALIGNED(16, extern const uint8_t,
val += 1 << bits_count; \
} while (0);
static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,
static int decode_coefs(FRAME_CONTEXT *fc, const MACROBLOCKD *xd,
vp9_reader *r, int block_idx,
PLANE_TYPE type, int seg_eob, int16_t *qcoeff_ptr,
TX_SIZE txfm_size, const int16_t *dq,
ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L) {
ENTROPY_CONTEXT above_ec, left_ec;
FRAME_CONTEXT *const fc = &dx->common.fc;
int pt, c = 0, pad, default_eob;
int band;
vp9_prob (*coef_probs)[PREV_COEF_CONTEXTS][UNCONSTRAINED_NODES];
......@@ -298,10 +299,10 @@ static int get_eob(MACROBLOCKD* const xd, int segment_id, int eob_max) {
struct decode_block_args {
VP9D_COMP *pbi;
MACROBLOCKD *xd;
vp9_reader *r;
int *eobtotal;
};
static void decode_block(int plane, int block,
BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size,
......@@ -310,42 +311,37 @@ static void decode_block(int plane, int block,
const int bw = b_width_log2(bsize);
// find the maximum eob for this transform size, adjusted by segment
MACROBLOCKD *xd = arg->xd;
const int segment_id = arg->xd->mode_info_context->mbmi.segment_id;
MACROBLOCKD *xd = &arg->pbi->mb;
struct macroblockd_plane* pd = &xd->plane[plane];
const int segment_id = 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;
const int seg_eob = get_eob(xd, segment_id, 16 << ss_txfrm_size);
const int off = block >> ss_txfrm_size;
const int mod = bw - ss_tx_size - arg->xd->plane[plane].subsampling_x;
const int mod = bw - ss_tx_size - pd->subsampling_x;
const int aoff = (off & ((1 << mod) - 1)) << ss_tx_size;
const int loff = (off >> mod) << ss_tx_size;
int pt;
ENTROPY_CONTEXT *A = arg->xd->plane[plane].above_context + aoff;
ENTROPY_CONTEXT *L = arg->xd->plane[plane].left_context + loff;
const int eob = decode_coefs(arg->pbi, arg->xd, arg->r, block,
arg->xd->plane[plane].plane_type, seg_eob,
BLOCK_OFFSET(qcoeff_base, block, 16),
ss_tx_size, arg->xd->plane[plane].dequant,
A,
L);
ENTROPY_CONTEXT *A = pd->above_context + aoff;
ENTROPY_CONTEXT *L = pd->left_context + loff;
const int eob = decode_coefs(&arg->pbi->common.fc, xd, arg->r, block,
pd->plane_type, seg_eob,
BLOCK_OFFSET(pd->qcoeff, block, 16),
ss_tx_size, pd->dequant, A, L);
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
set_contexts_on_border(xd, bsize, plane, ss_tx_size, eob, aoff, loff, A, L);
} else {
for (pt = 0; pt < (1 << ss_tx_size); pt++) {
int pt;
for (pt = 0; pt < (1 << ss_tx_size); pt++)
A[pt] = L[pt] = eob > 0;
}
}
arg->xd->plane[plane].eobs[block] = eob;
arg->eobtotal[0] += eob;
pd->eobs[block] = eob;
*arg->eobtotal += eob;
}
int vp9_decode_tokens(VP9D_COMP* const pbi,
MACROBLOCKD* const xd,
vp9_reader *r,
BLOCK_SIZE_TYPE bsize) {
int vp9_decode_tokens(VP9D_COMP *pbi, vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
int eobtotal = 0;
struct decode_block_args args = {pbi, xd, r, &eobtotal};
foreach_transformed_block(xd, bsize, decode_block, &args);
struct decode_block_args args = {pbi, r, &eobtotal};
foreach_transformed_block(&pbi->mb, bsize, decode_block, &args);
return eobtotal;
}
......@@ -14,9 +14,6 @@
#include "vp9/decoder/vp9_onyxd_int.h"
int vp9_decode_tokens(VP9D_COMP* const pbi,
MACROBLOCKD* const xd,
vp9_reader *r,
BLOCK_SIZE_TYPE bsize);
int vp9_decode_tokens(VP9D_COMP* pbi, vp9_reader *r, BLOCK_SIZE_TYPE bsize);
#endif // VP9_DECODER_VP9_DETOKENIZE_H_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment