Commit 85a9bc04 authored by Yunqing Wang's avatar Yunqing Wang

vp9_dthread: pass frame counts to decoder functions

The current multi-threaded tile decoder requires that the videoes
are encoded with frame_parallel_decoding_mode = 1. This requirement
is not necessary, and is better to be removed. This patch includes
the first part of the work.

Change-Id: Ic7695fb3cfe13f9022582c9f0edd2aa6e2e36d28
parent 4ed539f2
......@@ -299,6 +299,7 @@ static void inverse_transform_block(MACROBLOCKD* xd, int plane, int block,
struct intra_args {
VP9_COMMON *cm;
MACROBLOCKD *xd;
FRAME_COUNTS *counts;
vp9_reader *r;
};
......@@ -323,7 +324,7 @@ static void predict_and_reconstruct_intra_block(int plane, int block,
x, y, plane);
if (!mi->mbmi.skip) {
const int eob = vp9_decode_block_tokens(cm, xd, plane, block,
const int eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block,
plane_bsize, x, y, tx_size,
args->r);
inverse_transform_block(xd, plane, block, tx_size, dst, pd->dst.stride,
......@@ -335,6 +336,7 @@ struct inter_args {
VP9_COMMON *cm;
MACROBLOCKD *xd;
vp9_reader *r;
FRAME_COUNTS *counts;
int *eobtotal;
};
......@@ -347,8 +349,8 @@ static void reconstruct_inter_block(int plane, int block,
struct macroblockd_plane *const pd = &xd->plane[plane];
int x, y, eob;
txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y);
eob = vp9_decode_block_tokens(cm, xd, plane, block, plane_bsize, x, y,
tx_size, args->r);
eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block, plane_bsize,
x, y, tx_size, args->r);
inverse_transform_block(xd, plane, block, tx_size,
&pd->dst.buf[4 * y * pd->dst.stride + 4 * x],
pd->dst.stride, eob);
......@@ -385,13 +387,14 @@ static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd,
}
static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd,
FRAME_COUNTS *counts,
const TileInfo *const tile,
int mi_row, int mi_col,
vp9_reader *r, BLOCK_SIZE bsize) {
VP9_COMMON *const cm = &pbi->common;
const int less8x8 = bsize < BLOCK_8X8;
MB_MODE_INFO *mbmi = set_offsets(cm, xd, tile, bsize, mi_row, mi_col);
vp9_read_mode_info(pbi, xd, tile, mi_row, mi_col, r);
vp9_read_mode_info(pbi, xd, counts, tile, mi_row, mi_col, r);
if (less8x8)
bsize = BLOCK_8X8;
......@@ -405,7 +408,7 @@ static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd,
}
if (!is_inter_block(mbmi)) {
struct intra_args arg = { cm, xd, r };
struct intra_args arg = { cm, xd, counts, r };
vp9_foreach_transformed_block(xd, bsize,
predict_and_reconstruct_intra_block, &arg);
} else {
......@@ -415,7 +418,7 @@ static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd,
// Reconstruction
if (!mbmi->skip) {
int eobtotal = 0;
struct inter_args arg = { cm, xd, r, &eobtotal };
struct inter_args arg = { cm, xd, r, counts, &eobtotal };
vp9_foreach_transformed_block(xd, bsize, reconstruct_inter_block, &arg);
if (!less8x8 && eobtotal == 0)
mbmi->skip = 1; // skip loopfilter
......@@ -425,7 +428,8 @@ static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd,
xd->corrupted |= vp9_reader_has_error(r);
}
static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, int hbs,
static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd,
FRAME_COUNTS *counts, int hbs,
int mi_row, int mi_col, BLOCK_SIZE bsize,
vp9_reader *r) {
const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
......@@ -444,12 +448,13 @@ static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, int hbs,
p = PARTITION_SPLIT;
if (!cm->frame_parallel_decoding_mode)
++cm->counts.partition[ctx][p];
++counts->partition[ctx][p];
return p;
}
static void decode_partition(VP9Decoder *const pbi, MACROBLOCKD *const xd,
FRAME_COUNTS *counts,
const TileInfo *const tile,
int mi_row, int mi_col,
vp9_reader* r, BLOCK_SIZE bsize) {
......@@ -461,34 +466,37 @@ static void decode_partition(VP9Decoder *const pbi, MACROBLOCKD *const xd,
if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
return;
partition = read_partition(cm, xd, hbs, mi_row, mi_col, bsize, r);
partition = read_partition(cm, xd, counts, hbs, mi_row, mi_col, bsize, r);
subsize = get_subsize(bsize, partition);
uv_subsize = ss_size_lookup[subsize][cm->subsampling_x][cm->subsampling_y];
if (subsize >= BLOCK_8X8 && uv_subsize == BLOCK_INVALID)
vpx_internal_error(xd->error_info,
VPX_CODEC_CORRUPT_FRAME, "Invalid block size.");
if (subsize < BLOCK_8X8) {
decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize);
decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
} else {
switch (partition) {
case PARTITION_NONE:
decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize);
decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
break;
case PARTITION_HORZ:
decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize);
decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
if (mi_row + hbs < cm->mi_rows)
decode_block(pbi, xd, tile, mi_row + hbs, mi_col, r, subsize);
decode_block(pbi, xd, counts, tile, mi_row + hbs, mi_col, r, subsize);
break;
case PARTITION_VERT:
decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize);
decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
if (mi_col + hbs < cm->mi_cols)
decode_block(pbi, xd, tile, mi_row, mi_col + hbs, r, subsize);
decode_block(pbi, xd, counts, tile, mi_row, mi_col + hbs, r, subsize);
break;
case PARTITION_SPLIT:
decode_partition(pbi, xd, tile, mi_row, mi_col, r, subsize);
decode_partition(pbi, xd, tile, mi_row, mi_col + hbs, r, subsize);
decode_partition(pbi, xd, tile, mi_row + hbs, mi_col, r, subsize);
decode_partition(pbi, xd, tile, mi_row + hbs, mi_col + hbs, r, subsize);
decode_partition(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
decode_partition(pbi, xd, counts, tile, mi_row, mi_col + hbs, r,
subsize);
decode_partition(pbi, xd, counts, tile, mi_row + hbs, mi_col, r,
subsize);
decode_partition(pbi, xd, counts, tile, mi_row + hbs, mi_col + hbs, r,
subsize);
break;
default:
assert(0 && "Invalid partition type");
......@@ -983,8 +991,8 @@ static const uint8_t *decode_tiles(VP9Decoder *pbi,
vp9_zero(tile_data->xd.left_seg_context);
for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end;
mi_col += MI_BLOCK_SIZE) {
decode_partition(pbi, &tile_data->xd, &tile, mi_row, mi_col,
&tile_data->bit_reader, BLOCK_64X64);
decode_partition(pbi, &tile_data->xd, &cm->counts, &tile, mi_row,
mi_col, &tile_data->bit_reader, BLOCK_64X64);
}
pbi->mb.corrupted |= tile_data->xd.corrupted;
if (pbi->mb.corrupted)
......@@ -1056,8 +1064,10 @@ static int tile_worker_hook(TileWorkerData *const tile_data,
vp9_zero(tile_data->xd.left_seg_context);
for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end;
mi_col += MI_BLOCK_SIZE) {
decode_partition(tile_data->pbi, &tile_data->xd, tile,
mi_row, mi_col, &tile_data->bit_reader, BLOCK_64X64);
decode_partition(tile_data->pbi, &tile_data->xd,
&tile_data->pbi->common.counts,
tile, mi_row, mi_col, &tile_data->bit_reader,
BLOCK_64X64);
}
}
return !tile_data->xd.corrupted;
......
This diff is collapsed.
......@@ -21,6 +21,7 @@ extern "C" {
struct TileInfo;
void vp9_read_mode_info(VP9Decoder *const pbi, MACROBLOCKD *xd,
FRAME_COUNTS *counts,
const struct TileInfo *const tile,
int mi_row, int mi_col, vp9_reader *r);
......
......@@ -56,13 +56,13 @@ static const vp9_tree_index coeff_subtree_high[TREE_SIZE(ENTROPY_TOKENS)] = {
-CATEGORY5_TOKEN, -CATEGORY6_TOKEN /* 7 = CAT_FIVE */
};
static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, PLANE_TYPE type,
static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd,
FRAME_COUNTS *counts, PLANE_TYPE type,
tran_low_t *dqcoeff, TX_SIZE tx_size, const int16_t *dq,
int ctx, const int16_t *scan, const int16_t *nb,
vp9_reader *r) {
const int max_eob = 16 << (tx_size << 1);
const FRAME_CONTEXT *const fc = cm->fc;
FRAME_COUNTS *const counts = &cm->counts;
const int ref = is_inter_block(&xd->mi[0].src_mi->mbmi);
int band, c = 0;
const vp9_prob (*coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] =
......@@ -213,13 +213,14 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, PLANE_TYPE type,
}
int vp9_decode_block_tokens(VP9_COMMON *cm, MACROBLOCKD *xd,
int plane, int block, BLOCK_SIZE plane_bsize,
int x, int y, TX_SIZE tx_size, vp9_reader *r) {
FRAME_COUNTS *counts, int plane, int block,
BLOCK_SIZE plane_bsize, int x, int y,
TX_SIZE tx_size, vp9_reader *r) {
struct macroblockd_plane *const pd = &xd->plane[plane];
const int ctx = get_entropy_context(tx_size, pd->above_context + x,
pd->left_context + y);
const scan_order *so = get_scan(xd, tx_size, pd->plane_type, block);
const int eob = decode_coefs(cm, xd, pd->plane_type,
const int eob = decode_coefs(cm, xd, counts, pd->plane_type,
BLOCK_OFFSET(pd->dqcoeff, block), tx_size,
pd->dequant, ctx, so->scan, so->neighbors, r);
vp9_set_contexts(xd, pd, plane_bsize, tx_size, eob > 0, x, y);
......
......@@ -20,8 +20,9 @@ extern "C" {
#endif
int vp9_decode_block_tokens(VP9_COMMON *cm, MACROBLOCKD *xd,
int plane, int block, BLOCK_SIZE plane_bsize,
int x, int y, TX_SIZE tx_size, vp9_reader *r);
FRAME_COUNTS *counts, int plane, int block,
BLOCK_SIZE plane_bsize, int x, int y,
TX_SIZE tx_size, vp9_reader *r);
#ifdef __cplusplus
} // extern "C"
......
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