Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Krishna Rapaka | 7319db5 | 2021-09-28 20:35:29 -0700 | [diff] [blame] | 2 | * Copyright (c) 2021, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Vibhoothi | 41c6dd7 | 2021-10-12 18:48:26 +0000 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 3-Clause Clear License |
| 5 | * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear |
| 6 | * License was not distributed with this source code in the LICENSE file, you |
| 7 | * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the |
| 8 | * Alliance for Open Media Patent License 1.0 was not distributed with this |
| 9 | * source code in the PATENTS file, you can obtain it at |
| 10 | * aomedia.org/license/patent-license/. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <assert.h> |
| 14 | #include <limits.h> |
| 15 | #include <stdio.h> |
| 16 | |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 17 | #include "config/av1_rtcd.h" |
| 18 | #include "config/aom_dsp_rtcd.h" |
| 19 | #include "config/aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | |
Wan-Teh Chang | e9bfe12 | 2018-10-02 11:50:07 -0700 | [diff] [blame] | 21 | #include "aom_dsp/aom_dsp_common.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 22 | #include "aom_mem/aom_mem.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | #include "aom_ports/system_state.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 24 | #include "aom_ports/aom_once.h" |
| 25 | #include "aom_ports/aom_timer.h" |
| 26 | #include "aom_scale/aom_scale.h" |
| 27 | #include "aom_util/aom_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 28 | |
| 29 | #include "av1/common/alloccommon.h" |
Wan-Teh Chang | f2d15ee | 2020-03-10 09:24:43 -0700 | [diff] [blame] | 30 | #include "av1/common/av1_common_int.h" |
Tom Finegan | 17ce8b1 | 2017-02-08 12:46:31 -0800 | [diff] [blame] | 31 | #include "av1/common/av1_loopfilter.h" |
Lester Lu | 5467307 | 2022-03-18 19:17:51 +0000 | [diff] [blame] | 32 | #include "av1/common/pred_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 33 | #include "av1/common/quant_common.h" |
| 34 | #include "av1/common/reconinter.h" |
| 35 | #include "av1/common/reconintra.h" |
| 36 | |
| 37 | #include "av1/decoder/decodeframe.h" |
| 38 | #include "av1/decoder/decoder.h" |
| 39 | #include "av1/decoder/detokenize.h" |
Sebastien Alaiwan | e9644be | 2017-12-19 18:20:12 +0100 | [diff] [blame] | 40 | #include "av1/decoder/obu.h" |
Sebastien Alaiwan | e9644be | 2017-12-19 18:20:12 +0100 | [diff] [blame] | 41 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 42 | static void initialize_dec(void) { |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 43 | av1_rtcd(); |
| 44 | aom_dsp_rtcd(); |
| 45 | aom_scale_rtcd(); |
| 46 | av1_init_intra_predictors(); |
| 47 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Vishnu Teja Manyam | c168689 | 2020-12-01 20:00:52 +0530 | [diff] [blame] | 50 | static void update_subgop_stats(const AV1_COMMON *const cm, |
| 51 | SubGOPStatsDec *const subgop_stats, |
| 52 | unsigned int display_order_hint, |
| 53 | unsigned int enable_subgop_stats) { |
| 54 | if (!enable_subgop_stats) return; |
| 55 | // Update subgop related frame data. |
| 56 | subgop_stats->disp_frame_idx[subgop_stats->stat_count] = display_order_hint; |
| 57 | subgop_stats->show_existing_frame[subgop_stats->stat_count] = |
| 58 | cm->show_existing_frame; |
| 59 | subgop_stats->show_frame[subgop_stats->stat_count] = cm->show_frame; |
Vishnu Teja Manyam | 4d1db46 | 2020-12-02 09:07:12 +0530 | [diff] [blame] | 60 | subgop_stats->qindex[subgop_stats->stat_count] = cm->quant_params.base_qindex; |
Vishnu Teja Manyam | d42d562 | 2020-12-02 10:17:29 +0530 | [diff] [blame] | 61 | subgop_stats->refresh_frame_flags[subgop_stats->stat_count] = |
| 62 | cm->current_frame.refresh_frame_flags; |
| 63 | |
| 64 | for (MV_REFERENCE_FRAME ref_frame = 0; ref_frame < REF_FRAMES; ++ref_frame) |
| 65 | subgop_stats->ref_frame_map[subgop_stats->stat_count][ref_frame] = |
| 66 | cm->ref_frame_map[ref_frame]->order_hint; |
| 67 | |
Vishnu Teja Manyam | c168689 | 2020-12-01 20:00:52 +0530 | [diff] [blame] | 68 | assert(subgop_stats->stat_count < MAX_SUBGOP_STATS_SIZE); |
| 69 | subgop_stats->stat_count++; |
| 70 | } |
| 71 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 72 | static void dec_set_mb_mi(CommonModeInfoParams *mi_params, int width, |
| 73 | int height) { |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 74 | // Ensure that the decoded width and height are both multiples of |
| 75 | // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if |
| 76 | // subsampling is used). |
| 77 | // This simplifies the implementation of various experiments, |
| 78 | // eg. cdef, which operates on units of 8x8 luma pixels. |
| 79 | const int aligned_width = ALIGN_POWER_OF_TWO(width, 3); |
| 80 | const int aligned_height = ALIGN_POWER_OF_TWO(height, 3); |
| 81 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 82 | mi_params->mi_cols = aligned_width >> MI_SIZE_LOG2; |
| 83 | mi_params->mi_rows = aligned_height >> MI_SIZE_LOG2; |
| 84 | mi_params->mi_stride = calc_mi_size(mi_params->mi_cols); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 85 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 86 | mi_params->mb_cols = (mi_params->mi_cols + 2) >> 2; |
| 87 | mi_params->mb_rows = (mi_params->mi_rows + 2) >> 2; |
| 88 | mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 89 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 90 | mi_params->mi_alloc_bsize = BLOCK_4X4; |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 91 | mi_params->mi_alloc_stride = mi_params->mi_stride; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 92 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 93 | assert(mi_size_wide[mi_params->mi_alloc_bsize] == |
| 94 | mi_size_high[mi_params->mi_alloc_bsize]); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 95 | |
| 96 | #if CONFIG_LPF_MASK |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 97 | av1_alloc_loop_filter_mask(mi_params); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 98 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 101 | static void dec_setup_mi(CommonModeInfoParams *mi_params) { |
| 102 | const int mi_grid_size = |
| 103 | mi_params->mi_stride * calc_mi_size(mi_params->mi_rows); |
| 104 | memset(mi_params->mi_grid_base, 0, |
| 105 | mi_grid_size * sizeof(*mi_params->mi_grid_base)); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 108 | static void dec_free_mi(CommonModeInfoParams *mi_params) { |
Urvang Joshi | d2998cd | 2020-03-26 02:27:48 -0700 | [diff] [blame] | 109 | aom_free(mi_params->mi_alloc); |
| 110 | mi_params->mi_alloc = NULL; |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 111 | aom_free(mi_params->mi_grid_base); |
| 112 | mi_params->mi_grid_base = NULL; |
| 113 | mi_params->mi_alloc_size = 0; |
| 114 | aom_free(mi_params->tx_type_map); |
| 115 | mi_params->tx_type_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Yeqing Wu | ecfcdea | 2022-04-13 05:57:39 +0000 | [diff] [blame^] | 118 | #if CONFIG_TIP |
| 119 | static INLINE void dec_init_tip_ref_frame(AV1_COMMON *const cm) { |
| 120 | TIP *tip_ref = &cm->tip_ref; |
| 121 | tip_ref->tip_frame = aom_calloc(1, sizeof(*tip_ref->tip_frame)); |
| 122 | } |
| 123 | |
| 124 | static INLINE void dec_free_tip_ref_frame(AV1_COMMON *const cm) { |
| 125 | aom_free(cm->tip_ref.available_flag); |
| 126 | cm->tip_ref.available_flag = NULL; |
| 127 | aom_free(cm->tip_ref.mf_need_clamp); |
| 128 | cm->tip_ref.mf_need_clamp = NULL; |
| 129 | |
| 130 | aom_free_frame_buffer(&cm->tip_ref.tip_frame->buf); |
| 131 | aom_free(cm->tip_ref.tip_frame); |
| 132 | cm->tip_ref.tip_frame = NULL; |
| 133 | } |
| 134 | #endif // CONFIG_TIP |
| 135 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 136 | AV1Decoder *av1_decoder_create(BufferPool *const pool) { |
| 137 | AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi)); |
Wan-Teh Chang | abff671 | 2018-09-26 12:10:38 -0700 | [diff] [blame] | 138 | if (!pbi) return NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 139 | av1_zero(*pbi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 140 | |
Wan-Teh Chang | abff671 | 2018-09-26 12:10:38 -0700 | [diff] [blame] | 141 | AV1_COMMON *volatile const cm = &pbi->common; |
| 142 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 143 | // The jmp_buf is valid only for the duration of the function that calls |
| 144 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 145 | // before it returns. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 146 | if (setjmp(cm->error.jmp)) { |
| 147 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 148 | av1_decoder_remove(pbi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 149 | return NULL; |
| 150 | } |
| 151 | |
| 152 | cm->error.setjmp = 1; |
| 153 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 154 | CHECK_MEM_ERROR(cm, cm->fc, |
| 155 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 156 | CHECK_MEM_ERROR( |
| 157 | cm, cm->default_frame_context, |
| 158 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context))); |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 159 | memset(cm->fc, 0, sizeof(*cm->fc)); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 160 | memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 161 | |
| 162 | pbi->need_resync = 1; |
Wan-Teh Chang | 5396c55 | 2018-06-29 10:33:50 -0700 | [diff] [blame] | 163 | aom_once(initialize_dec); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 164 | |
| 165 | // Initialize the references to not point to any frame buffers. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 166 | for (int i = 0; i < REF_FRAMES; i++) { |
| 167 | cm->ref_frame_map[i] = NULL; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 168 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 169 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 170 | cm->current_frame.frame_number = 0; |
David Barker | f6f8fa1 | 2018-06-20 14:46:05 +0100 | [diff] [blame] | 171 | pbi->decoding_first_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | pbi->common.buffer_pool = pool; |
| 173 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 174 | cm->seq_params.bit_depth = AOM_BITS_8; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 175 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 176 | cm->mi_params.free_mi = dec_free_mi; |
| 177 | cm->mi_params.setup_mi = dec_setup_mi; |
| 178 | cm->mi_params.set_mb_mi = dec_set_mb_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 179 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 180 | av1_loop_filter_init(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 181 | |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 182 | av1_qm_init(&cm->quant_params, av1_num_planes(cm)); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 183 | av1_loop_restoration_precal(); |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 184 | #if CONFIG_ACCOUNTING |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 185 | pbi->acct_enabled = 1; |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 186 | aom_accounting_init(&pbi->accounting); |
| 187 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 188 | |
Yeqing Wu | ecfcdea | 2022-04-13 05:57:39 +0000 | [diff] [blame^] | 189 | #if CONFIG_TIP |
| 190 | dec_init_tip_ref_frame(cm); |
| 191 | #endif // CONFIG_TIP |
| 192 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 193 | cm->error.setjmp = 0; |
| 194 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 195 | aom_get_worker_interface()->init(&pbi->lf_worker); |
Wan-Teh Chang | 4d29ee8 | 2018-09-20 10:07:52 -0700 | [diff] [blame] | 196 | pbi->lf_worker.thread_name = "aom lf worker"; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 197 | |
Ryan Lei | ccc6ea7 | 2021-01-06 11:43:56 -0800 | [diff] [blame] | 198 | #if DEBUG_EXTQUANT |
| 199 | cm->fDecCoeffLog = fopen("DecCoeffLog.txt", "wt"); |
| 200 | #endif |
| 201 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 202 | return pbi; |
| 203 | } |
| 204 | |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 205 | void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) { |
| 206 | if (tile_mt_info != NULL) { |
| 207 | #if CONFIG_MULTITHREAD |
| 208 | if (tile_mt_info->job_mutex != NULL) { |
| 209 | pthread_mutex_destroy(tile_mt_info->job_mutex); |
| 210 | aom_free(tile_mt_info->job_mutex); |
| 211 | } |
| 212 | #endif |
| 213 | aom_free(tile_mt_info->job_queue); |
| 214 | // clear the structure as the source of this call may be a resize in which |
| 215 | // case this call will be followed by an _alloc() which may fail. |
| 216 | av1_zero(*tile_mt_info); |
| 217 | } |
| 218 | } |
| 219 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 220 | void av1_dec_free_cb_buf(AV1Decoder *pbi) { |
| 221 | aom_free(pbi->cb_buffer_base); |
| 222 | pbi->cb_buffer_base = NULL; |
| 223 | pbi->cb_buffer_alloc_size = 0; |
| 224 | } |
| 225 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 226 | void av1_decoder_remove(AV1Decoder *pbi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 227 | int i; |
| 228 | |
| 229 | if (!pbi) return; |
| 230 | |
Yunqing Wang | a2f1728 | 2018-06-18 22:43:08 -0700 | [diff] [blame] | 231 | // Free the tile list output buffer. |
Yunqing Wang | 6ff4809 | 2018-11-13 14:10:48 -0800 | [diff] [blame] | 232 | aom_free_frame_buffer(&pbi->tile_list_outbuf); |
Yunqing Wang | a2f1728 | 2018-06-18 22:43:08 -0700 | [diff] [blame] | 233 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 234 | aom_get_worker_interface()->end(&pbi->lf_worker); |
| 235 | aom_free(pbi->lf_worker.data1); |
Cherma Rajan A | e4121f6 | 2018-04-18 17:30:55 +0530 | [diff] [blame] | 236 | |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 237 | if (pbi->thread_data) { |
| 238 | for (int worker_idx = 0; worker_idx < pbi->max_threads - 1; worker_idx++) { |
| 239 | DecWorkerData *const thread_data = pbi->thread_data + worker_idx; |
Wan-Teh Chang | 8d728cc | 2018-08-30 15:34:47 -0700 | [diff] [blame] | 240 | av1_free_mc_tmp_buf(thread_data->td); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 241 | aom_free(thread_data->td); |
| 242 | } |
| 243 | aom_free(pbi->thread_data); |
| 244 | } |
| 245 | |
| 246 | for (i = 0; i < pbi->num_workers; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 247 | AVxWorker *const worker = &pbi->tile_workers[i]; |
| 248 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 249 | } |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 250 | #if CONFIG_MULTITHREAD |
| 251 | if (pbi->row_mt_mutex_ != NULL) { |
| 252 | pthread_mutex_destroy(pbi->row_mt_mutex_); |
| 253 | aom_free(pbi->row_mt_mutex_); |
| 254 | } |
| 255 | if (pbi->row_mt_cond_ != NULL) { |
| 256 | pthread_cond_destroy(pbi->row_mt_cond_); |
| 257 | aom_free(pbi->row_mt_cond_); |
| 258 | } |
| 259 | #endif |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 260 | for (i = 0; i < pbi->allocated_tiles; i++) { |
| 261 | TileDataDec *const tile_data = pbi->tile_data + i; |
| 262 | av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync); |
| 263 | } |
Cherma Rajan A | e4121f6 | 2018-04-18 17:30:55 +0530 | [diff] [blame] | 264 | aom_free(pbi->tile_data); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 265 | aom_free(pbi->tile_workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 266 | |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 267 | if (pbi->num_workers > 0) { |
| 268 | av1_loop_filter_dealloc(&pbi->lf_row_sync); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 269 | av1_loop_restoration_dealloc(&pbi->lr_row_sync, pbi->num_workers); |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 270 | av1_dealloc_dec_jobs(&pbi->tile_mt_info); |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 271 | } |
| 272 | |
Yeqing Wu | ecfcdea | 2022-04-13 05:57:39 +0000 | [diff] [blame^] | 273 | #if CONFIG_TIP |
| 274 | dec_free_tip_ref_frame(&pbi->common); |
| 275 | #endif // CONFIG_TIP |
| 276 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 277 | av1_dec_free_cb_buf(pbi); |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 278 | #if CONFIG_ACCOUNTING |
| 279 | aom_accounting_clear(&pbi->accounting); |
| 280 | #endif |
Wan-Teh Chang | 8d728cc | 2018-08-30 15:34:47 -0700 | [diff] [blame] | 281 | av1_free_mc_tmp_buf(&pbi->td); |
Daniel Max Valenzuela | cc6cf05 | 2019-12-17 11:13:15 -0800 | [diff] [blame] | 282 | aom_img_metadata_array_free(pbi->metadata); |
Ryan Lei | ccc6ea7 | 2021-01-06 11:43:56 -0800 | [diff] [blame] | 283 | |
| 284 | #if DEBUG_EXTQUANT |
| 285 | if (pbi->common.fDecCoeffLog != NULL) { |
| 286 | fclose(pbi->common.fDecCoeffLog); |
| 287 | } |
| 288 | #endif |
| 289 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 290 | aom_free(pbi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Hui Su | 95e9c0c | 2019-12-09 15:21:35 -0800 | [diff] [blame] | 293 | void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, |
Hui Su | 474e1e1 | 2020-02-27 15:46:36 -0800 | [diff] [blame] | 294 | aom_reader *r, palette_visitor_fn_t visit) { |
leolzhao | 3ab5984 | 2021-05-11 10:07:48 -0700 | [diff] [blame] | 295 | if (!is_inter_block(xd->mi[0], xd->tree_type)) { |
Leo (Liang) Zhao | 03c65e8 | 2022-03-09 22:23:31 +0000 | [diff] [blame] | 296 | const int plane_start = get_partition_plane_start(xd->tree_type); |
| 297 | const int plane_end = get_partition_plane_end( |
| 298 | xd->tree_type, AOMMIN(2, av1_num_planes(&pbi->common))); |
leolzhao | 3db7cca | 2021-01-26 16:53:07 -0800 | [diff] [blame] | 299 | for (int plane = plane_start; plane < plane_end; ++plane) { |
Hui Su | 474e1e1 | 2020-02-27 15:46:36 -0800 | [diff] [blame] | 300 | if (plane == 0 || xd->is_chroma_ref) { |
Deepa K G | 99f7ddb | 2018-06-20 11:21:21 +0530 | [diff] [blame] | 301 | if (xd->mi[0]->palette_mode_info.palette_size[plane]) |
| 302 | visit(xd, plane, r); |
| 303 | } else { |
| 304 | assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0); |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 310 | static int equal_dimensions(const YV12_BUFFER_CONFIG *a, |
| 311 | const YV12_BUFFER_CONFIG *b) { |
| 312 | return a->y_height == b->y_height && a->y_width == b->y_width && |
| 313 | a->uv_height == b->uv_height && a->uv_width == b->uv_width; |
| 314 | } |
| 315 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 316 | aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi, int idx, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 317 | YV12_BUFFER_CONFIG *sd) { |
| 318 | AV1_COMMON *cm = &pbi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 319 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 320 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 321 | const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, idx); |
| 322 | if (cfg == NULL) { |
| 323 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, "No reference frame"); |
| 324 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 325 | } |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 326 | if (!equal_dimensions(cfg, sd)) |
| 327 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 328 | "Incorrect buffer dimensions"); |
| 329 | else |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 330 | aom_yv12_copy_frame(cfg, sd, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 331 | |
| 332 | return cm->error.error_code; |
| 333 | } |
| 334 | |
Yunqing Wang | 4450c76 | 2018-04-24 13:49:25 -0700 | [diff] [blame] | 335 | static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a, |
| 336 | const YV12_BUFFER_CONFIG *b) { |
| 337 | return a->y_height == b->y_height && a->y_width == b->y_width && |
| 338 | a->uv_height == b->uv_height && a->uv_width == b->uv_width && |
| 339 | a->y_stride == b->y_stride && a->uv_stride == b->uv_stride && |
| 340 | a->border == b->border && |
| 341 | (a->flags & YV12_FLAG_HIGHBITDEPTH) == |
| 342 | (b->flags & YV12_FLAG_HIGHBITDEPTH); |
| 343 | } |
| 344 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 345 | aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx, |
Yunqing Wang | 4450c76 | 2018-04-24 13:49:25 -0700 | [diff] [blame] | 346 | int use_external_ref, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 347 | YV12_BUFFER_CONFIG *sd) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 348 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 349 | YV12_BUFFER_CONFIG *ref_buf = NULL; |
| 350 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 351 | // Get the destination reference buffer. |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 352 | ref_buf = get_ref_frame(cm, idx); |
| 353 | |
| 354 | if (ref_buf == NULL) { |
| 355 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, "No reference frame"); |
| 356 | return AOM_CODEC_ERROR; |
| 357 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 358 | |
Yunqing Wang | 4450c76 | 2018-04-24 13:49:25 -0700 | [diff] [blame] | 359 | if (!use_external_ref) { |
| 360 | if (!equal_dimensions(ref_buf, sd)) { |
| 361 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 362 | "Incorrect buffer dimensions"); |
| 363 | } else { |
| 364 | // Overwrite the reference frame buffer. |
| 365 | aom_yv12_copy_frame(sd, ref_buf, num_planes); |
| 366 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 367 | } else { |
Yunqing Wang | 4450c76 | 2018-04-24 13:49:25 -0700 | [diff] [blame] | 368 | if (!equal_dimensions_and_border(ref_buf, sd)) { |
| 369 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 370 | "Incorrect buffer dimensions"); |
| 371 | } else { |
| 372 | // Overwrite the reference frame buffer pointers. |
| 373 | // Once we no longer need the external reference buffer, these pointers |
| 374 | // are restored. |
| 375 | ref_buf->store_buf_adr[0] = ref_buf->y_buffer; |
| 376 | ref_buf->store_buf_adr[1] = ref_buf->u_buffer; |
| 377 | ref_buf->store_buf_adr[2] = ref_buf->v_buffer; |
| 378 | ref_buf->y_buffer = sd->y_buffer; |
| 379 | ref_buf->u_buffer = sd->u_buffer; |
| 380 | ref_buf->v_buffer = sd->v_buffer; |
Frederic Barbier | 870462d | 2018-06-27 16:53:40 +0200 | [diff] [blame] | 381 | ref_buf->use_external_reference_buffers = 1; |
Yunqing Wang | 4450c76 | 2018-04-24 13:49:25 -0700 | [diff] [blame] | 382 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | return cm->error.error_code; |
| 386 | } |
| 387 | |
Yunqing Wang | 20a336d | 2018-04-25 10:19:53 -0700 | [diff] [blame] | 388 | aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm, |
| 389 | YV12_BUFFER_CONFIG *new_frame, |
| 390 | YV12_BUFFER_CONFIG *sd) { |
| 391 | const int num_planes = av1_num_planes(cm); |
| 392 | |
| 393 | if (!equal_dimensions_and_border(new_frame, sd)) |
| 394 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 395 | "Incorrect buffer dimensions"); |
| 396 | else |
| 397 | aom_yv12_copy_frame(new_frame, sd, num_planes); |
| 398 | |
| 399 | return cm->error.error_code; |
| 400 | } |
| 401 | |
Wan-Teh Chang | 6f954e7 | 2019-08-30 12:01:26 -0700 | [diff] [blame] | 402 | static void release_current_frame(AV1Decoder *pbi) { |
Wan-Teh Chang | 16c9aff | 2018-09-28 16:08:21 -0700 | [diff] [blame] | 403 | AV1_COMMON *const cm = &pbi->common; |
| 404 | BufferPool *const pool = cm->buffer_pool; |
Wan-Teh Chang | 16c9aff | 2018-09-28 16:08:21 -0700 | [diff] [blame] | 405 | |
Wan-Teh Chang | c482489 | 2018-11-20 17:22:41 -0800 | [diff] [blame] | 406 | cm->cur_frame->buf.corrupted = 1; |
Wan-Teh Chang | 16c9aff | 2018-09-28 16:08:21 -0700 | [diff] [blame] | 407 | lock_buffer_pool(pool); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 408 | decrease_ref_count(cm->cur_frame, pool); |
Wan-Teh Chang | 16c9aff | 2018-09-28 16:08:21 -0700 | [diff] [blame] | 409 | unlock_buffer_pool(pool); |
Wan-Teh Chang | c482489 | 2018-11-20 17:22:41 -0800 | [diff] [blame] | 410 | cm->cur_frame = NULL; |
Wan-Teh Chang | 16c9aff | 2018-09-28 16:08:21 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Wan-Teh Chang | e9bfe12 | 2018-10-02 11:50:07 -0700 | [diff] [blame] | 413 | // If any buffer updating is signaled it should be done here. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 414 | // Consumes a reference to cm->cur_frame. |
Wan-Teh Chang | e9bfe12 | 2018-10-02 11:50:07 -0700 | [diff] [blame] | 415 | // |
| 416 | // This functions returns void. It reports failure by setting |
| 417 | // cm->error.error_code. |
Wan-Teh Chang | 6f954e7 | 2019-08-30 12:01:26 -0700 | [diff] [blame] | 418 | static void update_frame_buffers(AV1Decoder *pbi, int frame_decoded) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 419 | int ref_index = 0, mask; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 420 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 421 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 422 | |
David Barker | 6cc60e2 | 2018-05-29 17:38:47 +0100 | [diff] [blame] | 423 | if (frame_decoded) { |
Frank Bossen | d8f457a | 2018-04-30 21:44:12 -0400 | [diff] [blame] | 424 | lock_buffer_pool(pool); |
Yunqing Wang | d7546d4 | 2018-06-06 15:08:05 -0700 | [diff] [blame] | 425 | |
| 426 | // In ext-tile decoding, the camera frame header is only decoded once. So, |
Wan-Teh Chang | 6f954e7 | 2019-08-30 12:01:26 -0700 | [diff] [blame] | 427 | // we don't update the references here. |
Yunqing Wang | d7546d4 | 2018-06-06 15:08:05 -0700 | [diff] [blame] | 428 | if (!pbi->camera_frame_header_ready) { |
Wan-Teh Chang | 6f954e7 | 2019-08-30 12:01:26 -0700 | [diff] [blame] | 429 | // The following for loop needs to release the reference stored in |
| 430 | // cm->ref_frame_map[ref_index] before storing a reference to |
| 431 | // cm->cur_frame in cm->ref_frame_map[ref_index]. |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 432 | for (mask = cm->current_frame.refresh_frame_flags; mask; mask >>= 1) { |
Wan-Teh Chang | 6f954e7 | 2019-08-30 12:01:26 -0700 | [diff] [blame] | 433 | if (mask & 1) { |
| 434 | decrease_ref_count(cm->ref_frame_map[ref_index], pool); |
| 435 | cm->ref_frame_map[ref_index] = cm->cur_frame; |
| 436 | ++cm->cur_frame->ref_count; |
| 437 | } |
Yunqing Wang | d7546d4 | 2018-06-06 15:08:05 -0700 | [diff] [blame] | 438 | ++ref_index; |
| 439 | } |
Vishnu Teja Manyam | c168689 | 2020-12-01 20:00:52 +0530 | [diff] [blame] | 440 | update_subgop_stats(cm, &pbi->subgop_stats, cm->cur_frame->order_hint, |
| 441 | pbi->enable_subgop_stats); |
Frank Bossen | d8f457a | 2018-04-30 21:44:12 -0400 | [diff] [blame] | 442 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 443 | |
David Barker | e8df7ba | 2018-06-06 16:22:11 +0100 | [diff] [blame] | 444 | if (cm->show_existing_frame || cm->show_frame) { |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 445 | if (pbi->output_all_layers) { |
| 446 | // Append this frame to the output queue |
| 447 | if (pbi->num_output_frames >= MAX_NUM_SPATIAL_LAYERS) { |
| 448 | // We can't store the new frame anywhere, so drop it and return an |
| 449 | // error |
Wan-Teh Chang | c482489 | 2018-11-20 17:22:41 -0800 | [diff] [blame] | 450 | cm->cur_frame->buf.corrupted = 1; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 451 | decrease_ref_count(cm->cur_frame, pool); |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 452 | cm->error.error_code = AOM_CODEC_UNSUP_BITSTREAM; |
| 453 | } else { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 454 | pbi->output_frames[pbi->num_output_frames] = cm->cur_frame; |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 455 | pbi->num_output_frames++; |
| 456 | } |
| 457 | } else { |
| 458 | // Replace any existing output frame |
| 459 | assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1); |
| 460 | if (pbi->num_output_frames > 0) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 461 | decrease_ref_count(pbi->output_frames[0], pool); |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 462 | } |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 463 | pbi->output_frames[0] = cm->cur_frame; |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 464 | pbi->num_output_frames = 1; |
David Barker | e8df7ba | 2018-06-06 16:22:11 +0100 | [diff] [blame] | 465 | } |
David Barker | e8df7ba | 2018-06-06 16:22:11 +0100 | [diff] [blame] | 466 | } else { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 467 | decrease_ref_count(cm->cur_frame, pool); |
David Barker | e8df7ba | 2018-06-06 16:22:11 +0100 | [diff] [blame] | 468 | } |
| 469 | |
Frank Bossen | d8f457a | 2018-04-30 21:44:12 -0400 | [diff] [blame] | 470 | unlock_buffer_pool(pool); |
David Barker | e8df7ba | 2018-06-06 16:22:11 +0100 | [diff] [blame] | 471 | } else { |
| 472 | // Nothing was decoded, so just drop this frame buffer |
| 473 | lock_buffer_pool(pool); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 474 | decrease_ref_count(cm->cur_frame, pool); |
David Barker | e8df7ba | 2018-06-06 16:22:11 +0100 | [diff] [blame] | 475 | unlock_buffer_pool(pool); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 476 | } |
Wan-Teh Chang | c482489 | 2018-11-20 17:22:41 -0800 | [diff] [blame] | 477 | cm->cur_frame = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 478 | |
Yunqing Wang | d7546d4 | 2018-06-06 15:08:05 -0700 | [diff] [blame] | 479 | if (!pbi->camera_frame_header_ready) { |
Yunqing Wang | d7546d4 | 2018-06-06 15:08:05 -0700 | [diff] [blame] | 480 | // Invalidate these references until the next frame starts. |
| 481 | for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 482 | cm->remapped_ref_idx[ref_index] = INVALID_IDX; |
Yunqing Wang | d7546d4 | 2018-06-06 15:08:05 -0700 | [diff] [blame] | 483 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 487 | int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, |
| 488 | const uint8_t **psource) { |
| 489 | AV1_COMMON *volatile const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 490 | const uint8_t *source = *psource; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 491 | cm->error.error_code = AOM_CODEC_OK; |
Wan-Teh Chang | 97129d1 | 2018-10-01 15:56:38 -0700 | [diff] [blame] | 492 | cm->error.has_detail = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 493 | |
| 494 | if (size == 0) { |
| 495 | // This is used to signal that we are missing frames. |
| 496 | // We do not know if the missing frame(s) was supposed to update |
| 497 | // any of the reference buffers, but we act conservative and |
| 498 | // mark only the last buffer as corrupted. |
| 499 | // |
| 500 | // TODO(jkoleszar): Error concealment is undefined and non-normative |
| 501 | // at this point, but if it becomes so, [0] may not always be the correct |
| 502 | // thing to do here. |
Lester Lu | 5467307 | 2022-03-18 19:17:51 +0000 | [diff] [blame] | 503 | #if CONFIG_NEW_REF_SIGNALING |
| 504 | const int last_frame = get_closest_pastcur_ref_index(cm); |
| 505 | RefCntBuffer *ref_buf = get_ref_frame_buf(cm, last_frame); |
| 506 | #else |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 507 | RefCntBuffer *ref_buf = get_ref_frame_buf(cm, LAST_FRAME); |
Lester Lu | 5467307 | 2022-03-18 19:17:51 +0000 | [diff] [blame] | 508 | #endif // CONFIG_NEW_REF_SIGNALING |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 509 | if (ref_buf != NULL) ref_buf->buf.corrupted = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 510 | } |
| 511 | |
David Turner | 0308a5a | 2019-01-07 10:36:16 +0000 | [diff] [blame] | 512 | if (assign_cur_frame_new_fb(cm) == NULL) { |
Wan-Teh Chang | 332b2ae | 2018-07-09 14:30:20 -0700 | [diff] [blame] | 513 | cm->error.error_code = AOM_CODEC_MEM_ERROR; |
| 514 | return 1; |
| 515 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 516 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 517 | // The jmp_buf is valid only for the duration of the function that calls |
| 518 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 519 | // before it returns. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 520 | if (setjmp(cm->error.jmp)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 521 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 522 | int i; |
| 523 | |
| 524 | cm->error.setjmp = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 525 | |
| 526 | // Synchronize all threads immediately as a subsequent decode call may |
| 527 | // cause a resize invalidating some allocations. |
| 528 | winterface->sync(&pbi->lf_worker); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 529 | for (i = 0; i < pbi->num_workers; ++i) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 530 | winterface->sync(&pbi->tile_workers[i]); |
| 531 | } |
| 532 | |
Wan-Teh Chang | 6f954e7 | 2019-08-30 12:01:26 -0700 | [diff] [blame] | 533 | release_current_frame(pbi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 534 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 535 | return -1; |
| 536 | } |
| 537 | |
| 538 | cm->error.setjmp = 1; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 539 | |
David Barker | 6cc60e2 | 2018-05-29 17:38:47 +0100 | [diff] [blame] | 540 | int frame_decoded = |
| 541 | aom_decode_frame_from_obus(pbi, source, source + size, psource); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 542 | |
Wan-Teh Chang | f0f76ca | 2018-09-26 11:36:52 -0700 | [diff] [blame] | 543 | if (frame_decoded < 0) { |
| 544 | assert(cm->error.error_code != AOM_CODEC_OK); |
Wan-Teh Chang | 6f954e7 | 2019-08-30 12:01:26 -0700 | [diff] [blame] | 545 | release_current_frame(pbi); |
Wan-Teh Chang | 88e4b0a | 2018-07-03 14:39:50 -0700 | [diff] [blame] | 546 | cm->error.setjmp = 0; |
Hui Su | b390df9 | 2018-07-03 10:59:07 -0700 | [diff] [blame] | 547 | return 1; |
| 548 | } |
Hui Su | b4d6b1c | 2018-01-08 13:43:12 -0800 | [diff] [blame] | 549 | |
Jingning Han | 53c0896 | 2017-11-16 14:03:41 -0800 | [diff] [blame] | 550 | #if TXCOEFF_TIMER |
| 551 | cm->cum_txcoeff_timer += cm->txcoeff_timer; |
| 552 | fprintf(stderr, |
| 553 | "txb coeff block number: %d, frame time: %ld, cum time %ld in us\n", |
| 554 | cm->txb_count, cm->txcoeff_timer, cm->cum_txcoeff_timer); |
| 555 | cm->txcoeff_timer = 0; |
| 556 | cm->txb_count = 0; |
| 557 | #endif |
| 558 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 559 | // Note: At this point, this function holds a reference to cm->cur_frame |
Wan-Teh Chang | 6f954e7 | 2019-08-30 12:01:26 -0700 | [diff] [blame] | 560 | // in the buffer pool. This reference is consumed by update_frame_buffers(). |
| 561 | update_frame_buffers(pbi, frame_decoded); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 562 | |
David Barker | f6f8fa1 | 2018-06-20 14:46:05 +0100 | [diff] [blame] | 563 | if (frame_decoded) { |
| 564 | pbi->decoding_first_frame = 0; |
| 565 | } |
| 566 | |
Wan-Teh Chang | 88e4b0a | 2018-07-03 14:39:50 -0700 | [diff] [blame] | 567 | if (cm->error.error_code != AOM_CODEC_OK) { |
| 568 | cm->error.setjmp = 0; |
| 569 | return 1; |
| 570 | } |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 571 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 572 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 573 | |
| 574 | if (!cm->show_existing_frame) { |
Debargha Mukherjee | 5521a18 | 2018-03-06 12:29:01 -0800 | [diff] [blame] | 575 | if (cm->seg.enabled) { |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 576 | if (cm->prev_frame && |
| 577 | (cm->mi_params.mi_rows == cm->prev_frame->mi_rows) && |
| 578 | (cm->mi_params.mi_cols == cm->prev_frame->mi_cols)) { |
Jonathan Matthews | 74e8a99 | 2018-02-01 11:31:08 +0000 | [diff] [blame] | 579 | cm->last_frame_seg_map = cm->prev_frame->seg_map; |
| 580 | } else { |
| 581 | cm->last_frame_seg_map = NULL; |
| 582 | } |
Jonathan Matthews | 74e8a99 | 2018-02-01 11:31:08 +0000 | [diff] [blame] | 583 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | // Update progress in frame parallel decode. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 587 | cm->error.setjmp = 0; |
Frank Bossen | d8f457a | 2018-04-30 21:44:12 -0400 | [diff] [blame] | 588 | |
Sebastien Alaiwan | 56fcf7c | 2018-01-02 11:21:54 +0100 | [diff] [blame] | 589 | return 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 590 | } |
| 591 | |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 592 | // Get the frame at a particular index in the output queue |
| 593 | int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd, |
| 594 | aom_film_grain_t **grain_params) { |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 595 | if (index >= pbi->num_output_frames) return -1; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 596 | *sd = &pbi->output_frames[index]->buf; |
| 597 | *grain_params = &pbi->output_frames[index]->film_grain_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 598 | aom_clear_system_state(); |
Sebastien Alaiwan | 56fcf7c | 2018-01-02 11:21:54 +0100 | [diff] [blame] | 599 | return 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 600 | } |
| 601 | |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 602 | // Get the highest-spatial-layer output |
Rachel Barker | 8bde145 | 2021-12-16 18:13:47 +0000 | [diff] [blame] | 603 | // TODO(rachelbarker): What should this do? |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 604 | int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) { |
David Barker | f1c07ce | 2018-06-06 17:50:18 +0100 | [diff] [blame] | 605 | if (pbi->num_output_frames == 0) return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 606 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 607 | *frame = pbi->output_frames[pbi->num_output_frames - 1]->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 608 | return 0; |
| 609 | } |