diff options
Diffstat (limited to 'vp9/decoder/vp9_decodeframe.c')
-rw-r--r-- | vp9/decoder/vp9_decodeframe.c | 165 |
1 files changed, 49 insertions, 116 deletions
diff --git a/vp9/decoder/vp9_decodeframe.c b/vp9/decoder/vp9_decodeframe.c index 728d92dfb..2f15bfb52 100644 --- a/vp9/decoder/vp9_decodeframe.c +++ b/vp9/decoder/vp9_decodeframe.c @@ -187,53 +187,13 @@ static void setup_plane_dequants(VP9_COMMON *cm, MACROBLOCKD *xd, int q_index) { xd->plane[i].dequant = cm->uv_dequant[q_index]; } -// Allocate storage for each tile column. -// TODO(jzern): when max_threads <= 1 the same storage could be used for each -// tile. -static void alloc_tile_storage(VP9D_COMP *pbi, int tile_rows, int tile_cols) { - VP9_COMMON *const cm = &pbi->common; - const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); - int i, tile_row, tile_col; - - CHECK_MEM_ERROR(cm, cm->mi_streams, - vpx_realloc(cm->mi_streams, tile_rows * tile_cols * - sizeof(*cm->mi_streams))); - for (tile_row = 0; tile_row < tile_rows; ++tile_row) { - for (tile_col = 0; tile_col < tile_cols; ++tile_col) { - TileInfo tile; - vp9_tile_init(&tile, cm, tile_row, tile_col); - cm->mi_streams[tile_row * tile_cols + tile_col] = - &cm->mi[tile.mi_row_start * cm->mode_info_stride + tile.mi_col_start]; - } - } - - // 2 contexts per 'mi unit', so that we have one context per 4x4 txfm - // block where mi unit size is 8x8. - CHECK_MEM_ERROR(cm, pbi->above_context[0], - vpx_realloc(pbi->above_context[0], - sizeof(*pbi->above_context[0]) * MAX_MB_PLANE * - 2 * aligned_mi_cols)); - for (i = 1; i < MAX_MB_PLANE; ++i) { - pbi->above_context[i] = pbi->above_context[0] + - i * sizeof(*pbi->above_context[0]) * - 2 * aligned_mi_cols; - } - - // This is sized based on the entire frame. Each tile operates within its - // column bounds. - CHECK_MEM_ERROR(cm, pbi->above_seg_context, - vpx_realloc(pbi->above_seg_context, - sizeof(*pbi->above_seg_context) * - aligned_mi_cols)); -} - static void inverse_transform_block(MACROBLOCKD* xd, int plane, int block, TX_SIZE tx_size, uint8_t *dst, int stride, int eob) { struct macroblockd_plane *const pd = &xd->plane[plane]; if (eob > 0) { TX_TYPE tx_type; - const int plane_type = pd->plane_type; + const PLANE_TYPE plane_type = pd->plane_type; int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); switch (tx_size) { case TX_4X4: @@ -281,7 +241,7 @@ struct intra_args { static void predict_and_reconstruct_intra_block(int plane, int block, BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg) { - struct intra_args *const args = arg; + struct intra_args *const args = (struct intra_args *)arg; VP9_COMMON *const cm = args->cm; MACROBLOCKD *const xd = args->xd; struct macroblockd_plane *const pd = &xd->plane[plane]; @@ -317,7 +277,7 @@ struct inter_args { static void reconstruct_inter_block(int plane, int block, BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg) { - struct inter_args *args = arg; + struct inter_args *args = (struct inter_args *)arg; VP9_COMMON *const cm = args->cm; MACROBLOCKD *const xd = args->xd; struct macroblockd_plane *const pd = &xd->plane[plane]; @@ -339,13 +299,10 @@ static void set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd, const int x_mis = MIN(bw, cm->mi_cols - mi_col); const int y_mis = MIN(bh, cm->mi_rows - mi_row); const int offset = mi_row * cm->mode_info_stride + mi_col; - const int tile_offset = tile->mi_row_start * cm->mode_info_stride + - tile->mi_col_start; int x, y; xd->mi_8x8 = cm->mi_grid_visible + offset; - xd->prev_mi_8x8 = cm->prev_mi_grid_visible + offset; - xd->mi_8x8[0] = xd->mi_stream + offset - tile_offset; + xd->mi_8x8[0] = &cm->mi[offset]; xd->mi_8x8[0]->mbmi.sb_type = bsize; for (y = 0; y < y_mis; ++y) for (x = !y; x < x_mis; ++x) @@ -428,16 +385,14 @@ static void decode_block(VP9_COMMON *const cm, MACROBLOCKD *const xd, static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, int hbs, int mi_row, int mi_col, BLOCK_SIZE bsize, vp9_reader *r) { - const int ctx = partition_plane_context(xd->above_seg_context, - xd->left_seg_context, - mi_row, mi_col, bsize); + const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); const vp9_prob *const probs = get_partition_probs(cm, ctx); const int has_rows = (mi_row + hbs) < cm->mi_rows; const int has_cols = (mi_col + hbs) < cm->mi_cols; PARTITION_TYPE p; if (has_rows && has_cols) - p = vp9_read_tree(r, vp9_partition_tree, probs); + p = (PARTITION_TYPE)vp9_read_tree(r, vp9_partition_tree, probs); else if (!has_rows && has_cols) p = vp9_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ; else if (has_rows && !has_cols) @@ -495,8 +450,7 @@ static void decode_partition(VP9_COMMON *const cm, MACROBLOCKD *const xd, // update partition context if (bsize >= BLOCK_8X8 && (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT)) - update_partition_context(xd->above_seg_context, xd->left_seg_context, - mi_row, mi_col, subsize, bsize); + update_partition_context(xd, mi_row, mi_col, subsize, bsize); } static void setup_token_decoder(const uint8_t *data, @@ -664,9 +618,7 @@ static void setup_display_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { read_frame_size(rb, &cm->display_width, &cm->display_height); } -static void apply_frame_size(VP9D_COMP *pbi, int width, int height) { - VP9_COMMON *cm = &pbi->common; - +static void apply_frame_size(VP9_COMMON *cm, int width, int height) { if (cm->width != width || cm->height != height) { // Change in frame size. // TODO(agrange) Don't test width/height, check overall size. @@ -693,18 +645,15 @@ static void apply_frame_size(VP9D_COMP *pbi, int width, int height) { } } -static void setup_frame_size(VP9D_COMP *pbi, - struct vp9_read_bit_buffer *rb) { +static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { int width, height; read_frame_size(rb, &width, &height); - apply_frame_size(pbi, width, height); - setup_display_size(&pbi->common, rb); + apply_frame_size(cm, width, height); + setup_display_size(cm, rb); } -static void setup_frame_size_with_refs(VP9D_COMP *pbi, +static void setup_frame_size_with_refs(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { - VP9_COMMON *const cm = &pbi->common; - int width, height; int found = 0, i; for (i = 0; i < REFS_PER_FRAME; ++i) { @@ -724,23 +673,19 @@ static void setup_frame_size_with_refs(VP9D_COMP *pbi, vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Referenced frame with invalid size"); - apply_frame_size(pbi, width, height); + apply_frame_size(cm, width, height); setup_display_size(cm, rb); } -static void setup_tile_context(VP9D_COMP *const pbi, MACROBLOCKD *const xd, +static void setup_tile_context(VP9_COMMON *cm, MACROBLOCKD *const xd, int tile_row, int tile_col) { - VP9_COMMON *const cm = &pbi->common; - const int tile_cols = 1 << cm->log2_tile_cols; int i; - xd->mi_stream = cm->mi_streams[tile_row * tile_cols + tile_col]; + for (i = 0; i < MAX_MB_PLANE; ++i) + xd->above_context[i] = cm->above_context + + i * sizeof(*cm->above_context) * 2 * mi_cols_aligned_to_sb(cm->mi_cols); - for (i = 0; i < MAX_MB_PLANE; ++i) { - xd->above_context[i] = pbi->above_context[i]; - } - // see note in alloc_tile_storage(). - xd->above_seg_context = pbi->above_seg_context; + xd->above_seg_context = cm->above_seg_context; } static void decode_tile(VP9D_COMP *pbi, const TileInfo *const tile, @@ -848,7 +793,9 @@ typedef struct TileBuffer { int col; // only used with multi-threaded decoding } TileBuffer; -static const uint8_t *decode_tiles(VP9D_COMP *pbi, const uint8_t *data) { +static const uint8_t *decode_tiles(VP9D_COMP *pbi, + const uint8_t *data, + const uint8_t *data_end) { VP9_COMMON *const cm = &pbi->common; MACROBLOCKD *const xd = &pbi->mb; const int aligned_cols = mi_cols_aligned_to_sb(cm->mi_cols); @@ -856,7 +803,6 @@ static const uint8_t *decode_tiles(VP9D_COMP *pbi, const uint8_t *data) { const int tile_rows = 1 << cm->log2_tile_rows; TileBuffer tile_buffers[4][1 << 6]; int tile_row, tile_col; - const uint8_t *const data_end = pbi->source + pbi->source_sz; const uint8_t *end = NULL; vp9_reader r; @@ -865,11 +811,11 @@ static const uint8_t *decode_tiles(VP9D_COMP *pbi, const uint8_t *data) { // Note: this memset assumes above_context[0], [1] and [2] // are allocated as part of the same buffer. - vpx_memset(pbi->above_context[0], 0, - sizeof(*pbi->above_context[0]) * MAX_MB_PLANE * 2 * aligned_cols); + vpx_memset(cm->above_context, 0, + sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_cols); - vpx_memset(pbi->above_seg_context, 0, - sizeof(*pbi->above_seg_context) * aligned_cols); + vpx_memset(cm->above_seg_context, 0, + sizeof(*cm->above_seg_context) * aligned_cols); // Load tile data into tile_buffers for (tile_row = 0; tile_row < tile_rows; ++tile_row) { @@ -896,7 +842,7 @@ static const uint8_t *decode_tiles(VP9D_COMP *pbi, const uint8_t *data) { vp9_tile_init(&tile, cm, tile_row, col); setup_token_decoder(buf->data, data_end, buf->size, &cm->error, &r); - setup_tile_context(pbi, xd, tile_row, col); + setup_tile_context(cm, xd, tile_row, col); decode_tile(pbi, &tile, &r); if (last_tile) @@ -907,17 +853,6 @@ static const uint8_t *decode_tiles(VP9D_COMP *pbi, const uint8_t *data) { return end; } -static void setup_tile_macroblockd(TileWorkerData *const tile_data) { - MACROBLOCKD *xd = &tile_data->xd; - struct macroblockd_plane *const pd = xd->plane; - int i; - - for (i = 0; i < MAX_MB_PLANE; ++i) { - pd[i].dqcoeff = tile_data->dqcoeff[i]; - vpx_memset(xd->plane[i].dqcoeff, 0, 64 * 64 * sizeof(int16_t)); - } -} - static int tile_worker_hook(void *arg1, void *arg2) { TileWorkerData *const tile_data = (TileWorkerData*)arg1; const TileInfo *const tile = (TileInfo*)arg2; @@ -949,10 +884,11 @@ static int compare_tile_buffers(const void *a, const void *b) { } } -static const uint8_t *decode_tiles_mt(VP9D_COMP *pbi, const uint8_t *data) { +static const uint8_t *decode_tiles_mt(VP9D_COMP *pbi, + const uint8_t *data, + const uint8_t *data_end) { VP9_COMMON *const cm = &pbi->common; const uint8_t *bit_reader_end = NULL; - const uint8_t *const data_end = pbi->source + pbi->source_sz; const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); const int tile_cols = 1 << cm->log2_tile_cols; const int tile_rows = 1 << cm->log2_tile_rows; @@ -992,11 +928,10 @@ static const uint8_t *decode_tiles_mt(VP9D_COMP *pbi, const uint8_t *data) { // Note: this memset assumes above_context[0], [1] and [2] // are allocated as part of the same buffer. - vpx_memset(pbi->above_context[0], 0, - sizeof(*pbi->above_context[0]) * MAX_MB_PLANE * - 2 * aligned_mi_cols); - vpx_memset(pbi->above_seg_context, 0, - sizeof(*pbi->above_seg_context) * aligned_mi_cols); + vpx_memset(cm->above_context, 0, + sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_mi_cols); + vpx_memset(cm->above_seg_context, 0, + sizeof(*cm->above_seg_context) * aligned_mi_cols); // Load tile data into tile_buffers for (n = 0; n < tile_cols; ++n) { @@ -1044,8 +979,10 @@ static const uint8_t *decode_tiles_mt(VP9D_COMP *pbi, const uint8_t *data) { setup_token_decoder(buf->data, data_end, buf->size, &cm->error, &tile_data->bit_reader); - setup_tile_context(pbi, &tile_data->xd, 0, buf->col); - setup_tile_macroblockd(tile_data); + + setup_tile_context(cm, &tile_data->xd, 0, buf->col); + init_macroblockd(&tile_data->xd); + vp9_zero(tile_data->xd.dqcoeff); worker->had_error = 0; if (i == num_workers - 1 || n == tile_cols - 1) { @@ -1134,7 +1071,7 @@ static size_t read_uncompressed_header(VP9D_COMP *pbi, if (cm->frame_type == KEY_FRAME) { check_sync_code(cm, rb); - cm->color_space = vp9_rb_read_literal(rb, 3); // colorspace + cm->color_space = (COLOR_SPACE)vp9_rb_read_literal(rb, 3); if (cm->color_space != SRGB) { vp9_rb_read_bit(rb); // [16,235] (including xvycc) vs [0,255] range if (cm->version == 1) { @@ -1161,7 +1098,7 @@ static size_t read_uncompressed_header(VP9D_COMP *pbi, cm->frame_refs[i].buf = get_frame_new_buffer(cm); } - setup_frame_size(pbi, rb); + setup_frame_size(cm, rb); } else { cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb); @@ -1172,7 +1109,7 @@ static size_t read_uncompressed_header(VP9D_COMP *pbi, check_sync_code(cm, rb); pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); - setup_frame_size(pbi, rb); + setup_frame_size(cm, rb); } else { pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); @@ -1184,7 +1121,7 @@ static size_t read_uncompressed_header(VP9D_COMP *pbi, cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb); } - setup_frame_size_with_refs(pbi, rb); + setup_frame_size_with_refs(cm, rb); cm->allow_high_precision_mv = vp9_rb_read_bit(rb); cm->interp_filter = read_interp_filter(rb); @@ -1332,14 +1269,12 @@ static void debug_check_frame_counts(const VP9_COMMON *const cm) { } #endif // NDEBUG -int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) { - int i; +int vp9_decode_frame(VP9D_COMP *pbi, + const uint8_t *data, const uint8_t *data_end, + const uint8_t **p_data_end) { VP9_COMMON *const cm = &pbi->common; MACROBLOCKD *const xd = &pbi->mb; - const uint8_t *data = pbi->source; - const uint8_t *const data_end = pbi->source + pbi->source_sz; - struct vp9_read_bit_buffer rb = { data, data_end, 0, cm, error_handler }; const size_t first_partition_size = read_uncompressed_header(pbi, &rb); const int keyframe = cm->frame_type == KEY_FRAME; @@ -1365,7 +1300,8 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) { pbi->do_loopfilter_inline = (cm->log2_tile_rows | cm->log2_tile_cols) == 0 && cm->lf.filter_level; if (pbi->do_loopfilter_inline && pbi->lf_worker.data1 == NULL) { - CHECK_MEM_ERROR(cm, pbi->lf_worker.data1, vpx_malloc(sizeof(LFWorkerData))); + CHECK_MEM_ERROR(cm, pbi->lf_worker.data1, + vpx_memalign(32, sizeof(LFWorkerData))); pbi->lf_worker.hook = (VP9WorkerHook)vp9_loop_filter_worker; if (pbi->oxcf.max_threads > 1 && !vp9_worker_reset(&pbi->lf_worker)) { vpx_internal_error(&cm->error, VPX_CODEC_ERROR, @@ -1373,8 +1309,6 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) { } } - alloc_tile_storage(pbi, tile_rows, tile_cols); - xd->mode_info_stride = cm->mode_info_stride; if (cm->coding_use_prev_mi) set_prev_mi(cm); @@ -1386,8 +1320,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) { cm->fc = cm->frame_contexts[cm->frame_context_idx]; vp9_zero(cm->counts); - for (i = 0; i < MAX_MB_PLANE; ++i) - vpx_memset(xd->plane[i].dqcoeff, 0, 64 * 64 * sizeof(int16_t)); + vp9_zero(xd->dqcoeff); xd->corrupted = 0; new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size); @@ -1396,9 +1329,9 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) { // single-frame tile decoding. if (pbi->oxcf.max_threads > 1 && tile_rows == 1 && tile_cols > 1 && cm->frame_parallel_decoding_mode) { - *p_data_end = decode_tiles_mt(pbi, data + first_partition_size); + *p_data_end = decode_tiles_mt(pbi, data + first_partition_size, data_end); } else { - *p_data_end = decode_tiles(pbi, data + first_partition_size); + *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end); } new_fb->corrupted |= xd->corrupted; |