diff options
Diffstat (limited to 'media/libaom/src/av1/decoder/decoder.c')
-rw-r--r-- | media/libaom/src/av1/decoder/decoder.c | 268 |
1 files changed, 116 insertions, 152 deletions
diff --git a/media/libaom/src/av1/decoder/decoder.c b/media/libaom/src/av1/decoder/decoder.c index a5f4fd67fa..fc5f2cd20d 100644 --- a/media/libaom/src/av1/decoder/decoder.c +++ b/media/libaom/src/av1/decoder/decoder.c @@ -17,6 +17,7 @@ #include "config/aom_dsp_rtcd.h" #include "config/aom_scale_rtcd.h" +#include "aom_dsp/aom_dsp_common.h" #include "aom_mem/aom_mem.h" #include "aom_ports/system_state.h" #include "aom_ports/aom_once.h" @@ -25,8 +26,8 @@ #include "aom_util/aom_thread.h" #include "av1/common/alloccommon.h" +#include "av1/common/av1_common_int.h" #include "av1/common/av1_loopfilter.h" -#include "av1/common/onyxc_int.h" #include "av1/common/quant_common.h" #include "av1/common/reconinter.h" #include "av1/common/reconintra.h" @@ -44,39 +45,59 @@ static void initialize_dec(void) { av1_init_wedge_masks(); } -static void dec_setup_mi(AV1_COMMON *cm) { - cm->mi = cm->mip; - cm->mi_grid_visible = cm->mi_grid_base; - memset(cm->mi_grid_base, 0, - cm->mi_stride * cm->mi_rows * sizeof(*cm->mi_grid_base)); +static void dec_set_mb_mi(CommonModeInfoParams *mi_params, int width, + int height) { + // Ensure that the decoded width and height are both multiples of + // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if + // subsampling is used). + // This simplifies the implementation of various experiments, + // eg. cdef, which operates on units of 8x8 luma pixels. + const int aligned_width = ALIGN_POWER_OF_TWO(width, 3); + const int aligned_height = ALIGN_POWER_OF_TWO(height, 3); + + mi_params->mi_cols = aligned_width >> MI_SIZE_LOG2; + mi_params->mi_rows = aligned_height >> MI_SIZE_LOG2; + mi_params->mi_stride = calc_mi_size(mi_params->mi_cols); + + mi_params->mb_cols = (mi_params->mi_cols + 2) >> 2; + mi_params->mb_rows = (mi_params->mi_rows + 2) >> 2; + mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols; + + mi_params->mi_alloc_bsize = BLOCK_4X4; + mi_params->mi_alloc_stride = mi_params->mi_stride; + + assert(mi_size_wide[mi_params->mi_alloc_bsize] == + mi_size_high[mi_params->mi_alloc_bsize]); + +#if CONFIG_LPF_MASK + av1_alloc_loop_filter_mask(mi_params); +#endif } -static int av1_dec_alloc_mi(AV1_COMMON *cm, int mi_size) { - cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); - if (!cm->mip) return 1; - cm->mi_alloc_size = mi_size; - cm->mi_grid_base = - (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); - if (!cm->mi_grid_base) return 1; - return 0; +static void dec_setup_mi(CommonModeInfoParams *mi_params) { + const int mi_grid_size = + mi_params->mi_stride * calc_mi_size(mi_params->mi_rows); + memset(mi_params->mi_grid_base, 0, + mi_grid_size * sizeof(*mi_params->mi_grid_base)); } -static void dec_free_mi(AV1_COMMON *cm) { - aom_free(cm->mip); - cm->mip = NULL; - aom_free(cm->mi_grid_base); - cm->mi_grid_base = NULL; - cm->mi_alloc_size = 0; +static void dec_free_mi(CommonModeInfoParams *mi_params) { + aom_free(mi_params->mi_alloc); + mi_params->mi_alloc = NULL; + aom_free(mi_params->mi_grid_base); + mi_params->mi_grid_base = NULL; + mi_params->mi_alloc_size = 0; + aom_free(mi_params->tx_type_map); + mi_params->tx_type_map = NULL; } AV1Decoder *av1_decoder_create(BufferPool *const pool) { AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi)); - AV1_COMMON *volatile const cm = pbi ? &pbi->common : NULL; - - if (!cm) return NULL; - + if (!pbi) return NULL; av1_zero(*pbi); + AV1_COMMON *volatile const cm = &pbi->common; + // The jmp_buf is valid only for the duration of the function that calls // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 // before it returns. @@ -90,33 +111,33 @@ AV1Decoder *av1_decoder_create(BufferPool *const pool) { CHECK_MEM_ERROR(cm, cm->fc, (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); - CHECK_MEM_ERROR(cm, cm->frame_contexts, - (FRAME_CONTEXT *)aom_memalign( - 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); + CHECK_MEM_ERROR( + cm, cm->default_frame_context, + (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context))); memset(cm->fc, 0, sizeof(*cm->fc)); - memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); + memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context)); pbi->need_resync = 1; aom_once(initialize_dec); // Initialize the references to not point to any frame buffers. - memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); - memset(&cm->next_ref_frame_map, -1, sizeof(cm->next_ref_frame_map)); + for (int i = 0; i < REF_FRAMES; i++) { + cm->ref_frame_map[i] = NULL; + } - cm->current_video_frame = 0; + cm->current_frame.frame_number = 0; pbi->decoding_first_frame = 1; pbi->common.buffer_pool = pool; cm->seq_params.bit_depth = AOM_BITS_8; - cm->dequant_bit_depth = AOM_BITS_8; - cm->alloc_mi = av1_dec_alloc_mi; - cm->free_mi = dec_free_mi; - cm->setup_mi = dec_setup_mi; + cm->mi_params.free_mi = dec_free_mi; + cm->mi_params.setup_mi = dec_setup_mi; + cm->mi_params.set_mb_mi = dec_set_mb_mi; av1_loop_filter_init(cm); - av1_qm_init(cm); + av1_qm_init(&cm->quant_params, av1_num_planes(cm)); av1_loop_restoration_precal(); #if CONFIG_ACCOUNTING pbi->acct_enabled = 1; @@ -126,6 +147,7 @@ AV1Decoder *av1_decoder_create(BufferPool *const pool) { cm->error.setjmp = 0; aom_get_worker_interface()->init(&pbi->lf_worker); + pbi->lf_worker.thread_name = "aom lf worker"; return pbi; } @@ -157,8 +179,7 @@ void av1_decoder_remove(AV1Decoder *pbi) { if (!pbi) return; // Free the tile list output buffer. - if (pbi->tile_list_output != NULL) aom_free(pbi->tile_list_output); - pbi->tile_list_output = NULL; + aom_free_frame_buffer(&pbi->tile_list_outbuf); aom_get_worker_interface()->end(&pbi->lf_worker); aom_free(pbi->lf_worker.data1); @@ -204,19 +225,16 @@ void av1_decoder_remove(AV1Decoder *pbi) { aom_accounting_clear(&pbi->accounting); #endif av1_free_mc_tmp_buf(&pbi->td); - + aom_img_metadata_array_free(pbi->metadata); aom_free(pbi); } -void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, int mi_row, - int mi_col, aom_reader *r, BLOCK_SIZE bsize, - palette_visitor_fn_t visit) { +void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, + aom_reader *r, palette_visitor_fn_t visit) { if (!is_inter_block(xd->mi[0])) { for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common)); ++plane) { - const struct macroblockd_plane *const pd = &xd->plane[plane]; - if (is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x, - pd->subsampling_y)) { + if (plane == 0 || xd->is_chroma_ref) { if (xd->mi[0]->palette_mode_info.palette_size[plane]) visit(xd, plane, r); } else { @@ -318,88 +336,85 @@ aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm, return cm->error.error_code; } -/* If any buffer updating is signaled it should be done here. - Consumes a reference to cm->new_fb_idx. -*/ -static void swap_frame_buffers(AV1Decoder *pbi, int frame_decoded) { +static void release_current_frame(AV1Decoder *pbi) { + AV1_COMMON *const cm = &pbi->common; + BufferPool *const pool = cm->buffer_pool; + + cm->cur_frame->buf.corrupted = 1; + lock_buffer_pool(pool); + decrease_ref_count(cm->cur_frame, pool); + unlock_buffer_pool(pool); + cm->cur_frame = NULL; +} + +// If any buffer updating is signaled it should be done here. +// Consumes a reference to cm->cur_frame. +// +// This functions returns void. It reports failure by setting +// cm->error.error_code. +static void update_frame_buffers(AV1Decoder *pbi, int frame_decoded) { int ref_index = 0, mask; AV1_COMMON *const cm = &pbi->common; BufferPool *const pool = cm->buffer_pool; - RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; if (frame_decoded) { lock_buffer_pool(pool); // In ext-tile decoding, the camera frame header is only decoded once. So, - // we don't release the references here. + // we don't update the references here. if (!pbi->camera_frame_header_ready) { - for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) { - const int old_idx = cm->ref_frame_map[ref_index]; - // Current thread releases the holding of reference frame. - decrease_ref_count(old_idx, frame_bufs, pool); - - // Release the reference frame holding in the reference map for the - // decoding of the next frame. - if (mask & 1) decrease_ref_count(old_idx, frame_bufs, pool); - cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index]; + // The following for loop needs to release the reference stored in + // cm->ref_frame_map[ref_index] before storing a reference to + // cm->cur_frame in cm->ref_frame_map[ref_index]. + for (mask = cm->current_frame.refresh_frame_flags; mask; mask >>= 1) { + if (mask & 1) { + decrease_ref_count(cm->ref_frame_map[ref_index], pool); + cm->ref_frame_map[ref_index] = cm->cur_frame; + ++cm->cur_frame->ref_count; + } ++ref_index; } - - // Current thread releases the holding of reference frame. - const int check_on_show_existing_frame = - !cm->show_existing_frame || cm->reset_decoder_state; - for (; ref_index < REF_FRAMES && check_on_show_existing_frame; - ++ref_index) { - const int old_idx = cm->ref_frame_map[ref_index]; - decrease_ref_count(old_idx, frame_bufs, pool); - cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index]; - } } - YV12_BUFFER_CONFIG *cur_frame = get_frame_new_buffer(cm); - if (cm->show_existing_frame || cm->show_frame) { if (pbi->output_all_layers) { // Append this frame to the output queue if (pbi->num_output_frames >= MAX_NUM_SPATIAL_LAYERS) { // We can't store the new frame anywhere, so drop it and return an // error - decrease_ref_count(cm->new_fb_idx, frame_bufs, pool); + cm->cur_frame->buf.corrupted = 1; + decrease_ref_count(cm->cur_frame, pool); cm->error.error_code = AOM_CODEC_UNSUP_BITSTREAM; } else { - pbi->output_frames[pbi->num_output_frames] = cur_frame; - pbi->output_frame_index[pbi->num_output_frames] = cm->new_fb_idx; + pbi->output_frames[pbi->num_output_frames] = cm->cur_frame; pbi->num_output_frames++; } } else { // Replace any existing output frame assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1); if (pbi->num_output_frames > 0) { - decrease_ref_count((int)pbi->output_frame_index[0], frame_bufs, pool); + decrease_ref_count(pbi->output_frames[0], pool); } - pbi->output_frames[0] = cur_frame; - pbi->output_frame_index[0] = cm->new_fb_idx; + pbi->output_frames[0] = cm->cur_frame; pbi->num_output_frames = 1; } } else { - decrease_ref_count(cm->new_fb_idx, frame_bufs, pool); + decrease_ref_count(cm->cur_frame, pool); } unlock_buffer_pool(pool); } else { // Nothing was decoded, so just drop this frame buffer lock_buffer_pool(pool); - decrease_ref_count(cm->new_fb_idx, frame_bufs, pool); + decrease_ref_count(cm->cur_frame, pool); unlock_buffer_pool(pool); } + cm->cur_frame = NULL; if (!pbi->camera_frame_header_ready) { - pbi->hold_ref_buf = 0; - // Invalidate these references until the next frame starts. for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) { - cm->frame_refs[ref_index].idx = INVALID_IDX; - cm->frame_refs[ref_index].buf = NULL; + cm->remapped_ref_idx[ref_index] = INVALID_IDX; } } } @@ -407,10 +422,9 @@ static void swap_frame_buffers(AV1Decoder *pbi, int frame_decoded) { int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, const uint8_t **psource) { AV1_COMMON *volatile const cm = &pbi->common; - BufferPool *volatile const pool = cm->buffer_pool; - RefCntBuffer *volatile const frame_bufs = cm->buffer_pool->frame_bufs; const uint8_t *source = *psource; cm->error.error_code = AOM_CODEC_OK; + cm->error.has_detail = 0; if (size == 0) { // This is used to signal that we are missing frames. @@ -421,29 +435,15 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, // TODO(jkoleszar): Error concealment is undefined and non-normative // at this point, but if it becomes so, [0] may not always be the correct // thing to do here. - if (cm->frame_refs[0].idx > 0) { - assert(cm->frame_refs[0].buf != NULL); - cm->frame_refs[0].buf->corrupted = 1; - } + RefCntBuffer *ref_buf = get_ref_frame_buf(cm, LAST_FRAME); + if (ref_buf != NULL) ref_buf->buf.corrupted = 1; } - // Find a free buffer for the new frame, releasing the reference previously - // held. - - // Find a free frame buffer. Return error if can not find any. - cm->new_fb_idx = get_free_fb(cm); - if (cm->new_fb_idx == INVALID_IDX) { + if (assign_cur_frame_new_fb(cm) == NULL) { cm->error.error_code = AOM_CODEC_MEM_ERROR; return 1; } - // Assign a MV array to the frame buffer. - cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; - - if (!pbi->camera_frame_header_ready) pbi->hold_ref_buf = 0; - - pbi->cur_buf = &frame_bufs[cm->new_fb_idx]; - // The jmp_buf is valid only for the duration of the function that calls // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 // before it returns. @@ -460,35 +460,7 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, winterface->sync(&pbi->tile_workers[i]); } - lock_buffer_pool(pool); - // Release all the reference buffers if worker thread is holding them. - if (pbi->hold_ref_buf == 1) { - int ref_index = 0, mask; - for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) { - const int old_idx = cm->ref_frame_map[ref_index]; - // Current thread releases the holding of reference frame. - decrease_ref_count(old_idx, frame_bufs, pool); - - // Release the reference frame holding in the reference map for the - // decoding of the next frame. - if (mask & 1) decrease_ref_count(old_idx, frame_bufs, pool); - ++ref_index; - } - - // Current thread releases the holding of reference frame. - const int check_on_show_existing_frame = - !cm->show_existing_frame || cm->reset_decoder_state; - for (; ref_index < REF_FRAMES && check_on_show_existing_frame; - ++ref_index) { - const int old_idx = cm->ref_frame_map[ref_index]; - decrease_ref_count(old_idx, frame_bufs, pool); - } - pbi->hold_ref_buf = 0; - } - // Release current frame. - decrease_ref_count(cm->new_fb_idx, frame_bufs, pool); - unlock_buffer_pool(pool); - + release_current_frame(pbi); aom_clear_system_state(); return -1; } @@ -498,10 +470,9 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, int frame_decoded = aom_decode_frame_from_obus(pbi, source, source + size, psource); - if (cm->error.error_code != AOM_CODEC_OK) { - lock_buffer_pool(pool); - decrease_ref_count(cm->new_fb_idx, frame_bufs, pool); - unlock_buffer_pool(pool); + if (frame_decoded < 0) { + assert(cm->error.error_code != AOM_CODEC_OK); + release_current_frame(pbi); cm->error.setjmp = 0; return 1; } @@ -515,9 +486,9 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, cm->txb_count = 0; #endif - // Note: At this point, this function holds a reference to cm->new_fb_idx - // in the buffer pool. This reference is consumed by swap_frame_buffers(). - swap_frame_buffers(pbi, frame_decoded); + // Note: At this point, this function holds a reference to cm->cur_frame + // in the buffer pool. This reference is consumed by update_frame_buffers(). + update_frame_buffers(pbi, frame_decoded); if (frame_decoded) { pbi->decoding_first_frame = 0; @@ -531,11 +502,10 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, aom_clear_system_state(); if (!cm->show_existing_frame) { - cm->last_show_frame = cm->show_frame; - if (cm->seg.enabled) { - if (cm->prev_frame && (cm->mi_rows == cm->prev_frame->mi_rows) && - (cm->mi_cols == cm->prev_frame->mi_cols)) { + if (cm->prev_frame && + (cm->mi_params.mi_rows == cm->prev_frame->mi_rows) && + (cm->mi_params.mi_cols == cm->prev_frame->mi_cols)) { cm->last_frame_seg_map = cm->prev_frame->seg_map; } else { cm->last_frame_seg_map = NULL; @@ -544,10 +514,6 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, } // Update progress in frame parallel decode. - cm->last_width = cm->width; - cm->last_height = cm->height; - cm->last_tile_cols = cm->tile_cols; - cm->last_tile_rows = cm->tile_rows; cm->error.setjmp = 0; return 0; @@ -556,11 +522,9 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, // Get the frame at a particular index in the output queue int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd, aom_film_grain_t **grain_params) { - RefCntBuffer *const frame_bufs = pbi->common.buffer_pool->frame_bufs; - if (index >= pbi->num_output_frames) return -1; - *sd = pbi->output_frames[index]; - *grain_params = &frame_bufs[pbi->output_frame_index[index]].film_grain_params; + *sd = &pbi->output_frames[index]->buf; + *grain_params = &pbi->output_frames[index]->film_grain_params; aom_clear_system_state(); return 0; } @@ -570,6 +534,6 @@ int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd, int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) { if (pbi->num_output_frames == 0) return -1; - *frame = *pbi->output_frames[pbi->num_output_frames - 1]; + *frame = pbi->output_frames[pbi->num_output_frames - 1]->buf; return 0; } |