/src/aom/av1/decoder/decoder.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2016, Alliance for Open Media. All rights reserved. |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 2 Clause License and |
5 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
6 | | * was not distributed with this source code in the LICENSE file, you can |
7 | | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
8 | | * Media Patent License 1.0 was not distributed with this source code in the |
9 | | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
10 | | */ |
11 | | |
12 | | #include <assert.h> |
13 | | #include <limits.h> |
14 | | #include <stdio.h> |
15 | | |
16 | | #include "config/av1_rtcd.h" |
17 | | #include "config/aom_dsp_rtcd.h" |
18 | | #include "config/aom_scale_rtcd.h" |
19 | | |
20 | | #include "aom_dsp/aom_dsp_common.h" |
21 | | #include "aom_mem/aom_mem.h" |
22 | | #include "aom_ports/aom_timer.h" |
23 | | #include "aom_util/aom_pthread.h" |
24 | | #include "aom_util/aom_thread.h" |
25 | | |
26 | | #include "av1/common/alloccommon.h" |
27 | | #include "av1/common/av1_common_int.h" |
28 | | #include "av1/common/av1_loopfilter.h" |
29 | | #include "av1/common/quant_common.h" |
30 | | #include "av1/common/reconinter.h" |
31 | | #include "av1/common/reconintra.h" |
32 | | |
33 | | #include "av1/decoder/decodeframe.h" |
34 | | #include "av1/decoder/decoder.h" |
35 | | #include "av1/decoder/detokenize.h" |
36 | | #include "av1/decoder/obu.h" |
37 | | |
38 | 15.8k | static void initialize_dec(void) { |
39 | 15.8k | av1_rtcd(); |
40 | 15.8k | aom_dsp_rtcd(); |
41 | 15.8k | aom_scale_rtcd(); |
42 | 15.8k | av1_init_intra_predictors(); |
43 | 15.8k | av1_init_wedge_masks(); |
44 | 15.8k | } |
45 | | |
46 | | static void dec_set_mb_mi(CommonModeInfoParams *mi_params, int width, |
47 | 78.1k | int height, BLOCK_SIZE min_partition_size) { |
48 | 78.1k | (void)min_partition_size; |
49 | | // Ensure that the decoded width and height are both multiples of |
50 | | // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if |
51 | | // subsampling is used). |
52 | | // This simplifies the implementation of various experiments, |
53 | | // eg. cdef, which operates on units of 8x8 luma pixels. |
54 | 78.1k | const int aligned_width = ALIGN_POWER_OF_TWO(width, 3); |
55 | 78.1k | const int aligned_height = ALIGN_POWER_OF_TWO(height, 3); |
56 | | |
57 | 78.1k | mi_params->mi_cols = aligned_width >> MI_SIZE_LOG2; |
58 | 78.1k | mi_params->mi_rows = aligned_height >> MI_SIZE_LOG2; |
59 | 78.1k | mi_params->mi_stride = calc_mi_size(mi_params->mi_cols); |
60 | | |
61 | 78.1k | mi_params->mb_cols = ROUND_POWER_OF_TWO(mi_params->mi_cols, 2); |
62 | 78.1k | mi_params->mb_rows = ROUND_POWER_OF_TWO(mi_params->mi_rows, 2); |
63 | 78.1k | mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols; |
64 | | |
65 | 78.1k | mi_params->mi_alloc_bsize = BLOCK_4X4; |
66 | 78.1k | mi_params->mi_alloc_stride = mi_params->mi_stride; |
67 | | |
68 | 78.1k | assert(mi_size_wide[mi_params->mi_alloc_bsize] == |
69 | 78.1k | mi_size_high[mi_params->mi_alloc_bsize]); |
70 | 78.1k | } |
71 | | |
72 | 216k | static void dec_setup_mi(CommonModeInfoParams *mi_params) { |
73 | 216k | const int mi_grid_size = |
74 | 216k | mi_params->mi_stride * calc_mi_size(mi_params->mi_rows); |
75 | 216k | memset(mi_params->mi_grid_base, 0, |
76 | 216k | mi_grid_size * sizeof(*mi_params->mi_grid_base)); |
77 | 216k | } |
78 | | |
79 | 50.5k | static void dec_free_mi(CommonModeInfoParams *mi_params) { |
80 | 50.5k | aom_free(mi_params->mi_alloc); |
81 | 50.5k | mi_params->mi_alloc = NULL; |
82 | 50.5k | mi_params->mi_alloc_size = 0; |
83 | 50.5k | aom_free(mi_params->mi_grid_base); |
84 | 50.5k | mi_params->mi_grid_base = NULL; |
85 | 50.5k | mi_params->mi_grid_size = 0; |
86 | 50.5k | aom_free(mi_params->tx_type_map); |
87 | 50.5k | mi_params->tx_type_map = NULL; |
88 | 50.5k | } |
89 | | |
90 | 15.8k | AV1Decoder *av1_decoder_create(BufferPool *const pool) { |
91 | 15.8k | AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi)); |
92 | 15.8k | if (!pbi) return NULL; |
93 | 15.8k | av1_zero(*pbi); |
94 | | |
95 | 15.8k | AV1_COMMON *volatile const cm = &pbi->common; |
96 | 15.8k | cm->seq_params = &pbi->seq_params; |
97 | 15.8k | cm->error = &pbi->error; |
98 | | |
99 | | // The jmp_buf is valid only for the duration of the function that calls |
100 | | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
101 | | // before it returns. |
102 | 15.8k | if (setjmp(pbi->error.jmp)) { |
103 | 0 | pbi->error.setjmp = 0; |
104 | 0 | av1_decoder_remove(pbi); |
105 | 0 | return NULL; |
106 | 0 | } |
107 | | |
108 | 15.8k | pbi->error.setjmp = 1; |
109 | | |
110 | 15.8k | CHECK_MEM_ERROR(cm, cm->fc, |
111 | 15.8k | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
112 | 15.8k | CHECK_MEM_ERROR( |
113 | 15.8k | cm, cm->default_frame_context, |
114 | 15.8k | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context))); |
115 | 15.8k | memset(cm->fc, 0, sizeof(*cm->fc)); |
116 | 15.8k | memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context)); |
117 | | |
118 | 15.8k | pbi->need_resync = 1; |
119 | 15.8k | initialize_dec(); |
120 | | |
121 | | // Initialize the references to not point to any frame buffers. |
122 | 142k | for (int i = 0; i < REF_FRAMES; i++) { |
123 | 126k | cm->ref_frame_map[i] = NULL; |
124 | 126k | } |
125 | | |
126 | 15.8k | cm->current_frame.frame_number = 0; |
127 | 15.8k | pbi->decoding_first_frame = 1; |
128 | 15.8k | pbi->common.buffer_pool = pool; |
129 | | |
130 | 15.8k | cm->seq_params->bit_depth = AOM_BITS_8; |
131 | | |
132 | 15.8k | cm->mi_params.free_mi = dec_free_mi; |
133 | 15.8k | cm->mi_params.setup_mi = dec_setup_mi; |
134 | 15.8k | cm->mi_params.set_mb_mi = dec_set_mb_mi; |
135 | | |
136 | 15.8k | av1_loop_filter_init(cm); |
137 | | |
138 | 15.8k | av1_qm_init(&cm->quant_params, av1_num_planes(cm)); |
139 | 15.8k | av1_loop_restoration_precal(); |
140 | | |
141 | | #if CONFIG_ACCOUNTING |
142 | | pbi->acct_enabled = 1; |
143 | | aom_accounting_init(&pbi->accounting); |
144 | | #endif |
145 | | |
146 | 15.8k | pbi->error.setjmp = 0; |
147 | | |
148 | 15.8k | aom_get_worker_interface()->init(&pbi->lf_worker); |
149 | 15.8k | pbi->lf_worker.thread_name = "aom lf worker"; |
150 | | |
151 | 15.8k | return pbi; |
152 | 15.8k | } |
153 | | |
154 | 7.54k | void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) { |
155 | 7.54k | if (tile_mt_info != NULL) { |
156 | 7.54k | #if CONFIG_MULTITHREAD |
157 | 7.54k | if (tile_mt_info->job_mutex != NULL) { |
158 | 4.27k | pthread_mutex_destroy(tile_mt_info->job_mutex); |
159 | 4.27k | aom_free(tile_mt_info->job_mutex); |
160 | 4.27k | } |
161 | 7.54k | #endif |
162 | 7.54k | aom_free(tile_mt_info->job_queue); |
163 | | // clear the structure as the source of this call may be a resize in which |
164 | | // case this call will be followed by an _alloc() which may fail. |
165 | 7.54k | av1_zero(*tile_mt_info); |
166 | 7.54k | } |
167 | 7.54k | } |
168 | | |
169 | 19.9k | void av1_dec_free_cb_buf(AV1Decoder *pbi) { |
170 | 19.9k | aom_free(pbi->cb_buffer_base); |
171 | 19.9k | pbi->cb_buffer_base = NULL; |
172 | 19.9k | pbi->cb_buffer_alloc_size = 0; |
173 | 19.9k | } |
174 | | |
175 | 15.8k | void av1_decoder_remove(AV1Decoder *pbi) { |
176 | 15.8k | int i; |
177 | | |
178 | 15.8k | if (!pbi) return; |
179 | | |
180 | | // Free the tile list output buffer. |
181 | 15.8k | aom_free_frame_buffer(&pbi->tile_list_outbuf); |
182 | | |
183 | 15.8k | aom_get_worker_interface()->end(&pbi->lf_worker); |
184 | 15.8k | aom_free(pbi->lf_worker.data1); |
185 | | |
186 | 15.8k | if (pbi->thread_data) { |
187 | 119k | for (int worker_idx = 1; worker_idx < pbi->num_workers; worker_idx++) { |
188 | 115k | DecWorkerData *const thread_data = pbi->thread_data + worker_idx; |
189 | 115k | if (thread_data->td != NULL) { |
190 | 115k | av1_free_mc_tmp_buf(thread_data->td); |
191 | 115k | aom_free(thread_data->td); |
192 | 115k | } |
193 | 115k | } |
194 | 3.27k | aom_free(pbi->thread_data); |
195 | 3.27k | } |
196 | 15.8k | aom_free(pbi->dcb.xd.seg_mask); |
197 | | |
198 | 135k | for (i = 0; i < pbi->num_workers; ++i) { |
199 | 119k | AVxWorker *const worker = &pbi->tile_workers[i]; |
200 | 119k | aom_get_worker_interface()->end(worker); |
201 | 119k | } |
202 | 15.8k | #if CONFIG_MULTITHREAD |
203 | 15.8k | if (pbi->row_mt_mutex_ != NULL) { |
204 | 3.11k | pthread_mutex_destroy(pbi->row_mt_mutex_); |
205 | 3.11k | aom_free(pbi->row_mt_mutex_); |
206 | 3.11k | } |
207 | 15.8k | if (pbi->row_mt_cond_ != NULL) { |
208 | 3.11k | pthread_cond_destroy(pbi->row_mt_cond_); |
209 | 3.11k | aom_free(pbi->row_mt_cond_); |
210 | 3.11k | } |
211 | 15.8k | #endif |
212 | 44.9k | for (i = 0; i < pbi->allocated_tiles; i++) { |
213 | 29.1k | TileDataDec *const tile_data = pbi->tile_data + i; |
214 | 29.1k | av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync); |
215 | 29.1k | } |
216 | 15.8k | aom_free(pbi->tile_data); |
217 | 15.8k | aom_free(pbi->tile_workers); |
218 | | |
219 | 15.8k | if (pbi->num_workers > 0) { |
220 | 3.27k | av1_loop_filter_dealloc(&pbi->lf_row_sync); |
221 | 3.27k | av1_loop_restoration_dealloc(&pbi->lr_row_sync); |
222 | 3.27k | av1_dealloc_dec_jobs(&pbi->tile_mt_info); |
223 | 3.27k | } |
224 | | |
225 | 15.8k | av1_dec_free_cb_buf(pbi); |
226 | | #if CONFIG_ACCOUNTING |
227 | | aom_accounting_clear(&pbi->accounting); |
228 | | #endif |
229 | 15.8k | av1_free_mc_tmp_buf(&pbi->td); |
230 | 15.8k | aom_img_metadata_array_free(pbi->metadata); |
231 | 15.8k | av1_remove_common(&pbi->common); |
232 | 15.8k | aom_free(pbi); |
233 | 15.8k | } |
234 | | |
235 | | void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, |
236 | 35.0M | aom_reader *r, palette_visitor_fn_t visit) { |
237 | 35.0M | if (!is_inter_block(xd->mi[0])) { |
238 | 69.4M | for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common)); |
239 | 45.7M | ++plane) { |
240 | 45.7M | if (plane == 0 || xd->is_chroma_ref) { |
241 | 44.4M | if (xd->mi[0]->palette_mode_info.palette_size[plane]) |
242 | 165k | visit(xd, plane, r); |
243 | 44.4M | } else { |
244 | 1.31M | assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0); |
245 | 1.31M | } |
246 | 45.7M | } |
247 | 23.7M | } |
248 | 35.0M | } |
249 | | |
250 | | static int equal_dimensions(const YV12_BUFFER_CONFIG *a, |
251 | 0 | const YV12_BUFFER_CONFIG *b) { |
252 | 0 | return a->y_height == b->y_height && a->y_width == b->y_width && |
253 | 0 | a->uv_height == b->uv_height && a->uv_width == b->uv_width; |
254 | 0 | } |
255 | | |
256 | | aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi, int idx, |
257 | 0 | YV12_BUFFER_CONFIG *sd) { |
258 | 0 | AV1_COMMON *cm = &pbi->common; |
259 | 0 | const int num_planes = av1_num_planes(cm); |
260 | |
|
261 | 0 | const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, idx); |
262 | 0 | if (cfg == NULL) { |
263 | 0 | aom_set_error(&pbi->error, AOM_CODEC_ERROR, "No reference frame"); |
264 | 0 | return pbi->error.error_code; |
265 | 0 | } |
266 | 0 | if (!equal_dimensions(cfg, sd)) { |
267 | 0 | aom_set_error(&pbi->error, AOM_CODEC_ERROR, "Incorrect buffer dimensions"); |
268 | 0 | return pbi->error.error_code; |
269 | 0 | } |
270 | | |
271 | 0 | aom_yv12_copy_frame(cfg, sd, num_planes); |
272 | |
|
273 | 0 | return AOM_CODEC_OK; |
274 | 0 | } |
275 | | |
276 | | static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a, |
277 | 43 | const YV12_BUFFER_CONFIG *b) { |
278 | 43 | return a->y_height == b->y_height && a->y_width == b->y_width && |
279 | 0 | a->uv_height == b->uv_height && a->uv_width == b->uv_width && |
280 | 0 | a->y_stride == b->y_stride && a->uv_stride == b->uv_stride && |
281 | 0 | a->border == b->border && |
282 | 0 | (a->flags & YV12_FLAG_HIGHBITDEPTH) == |
283 | 0 | (b->flags & YV12_FLAG_HIGHBITDEPTH); |
284 | 43 | } |
285 | | |
286 | | aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx, |
287 | | int use_external_ref, |
288 | 424 | YV12_BUFFER_CONFIG *sd) { |
289 | 424 | const int num_planes = av1_num_planes(cm); |
290 | | // Ensure that aom_internal_error() calls longjmp(). |
291 | 424 | assert(cm->error->setjmp); |
292 | | // Get the destination reference buffer. |
293 | 424 | YV12_BUFFER_CONFIG *ref_buf = get_ref_frame(cm, idx); |
294 | | |
295 | 424 | if (ref_buf == NULL) { |
296 | 381 | aom_internal_error(cm->error, AOM_CODEC_ERROR, "No reference frame"); |
297 | 381 | } |
298 | | |
299 | 424 | if (!use_external_ref) { |
300 | 0 | if (!equal_dimensions(ref_buf, sd)) { |
301 | 0 | aom_internal_error(cm->error, AOM_CODEC_ERROR, |
302 | 0 | "Incorrect buffer dimensions"); |
303 | 0 | } |
304 | | // Overwrite the reference frame buffer. |
305 | 0 | aom_yv12_copy_frame(sd, ref_buf, num_planes); |
306 | 424 | } else { |
307 | 424 | if (!equal_dimensions_and_border(ref_buf, sd)) { |
308 | 43 | aom_internal_error(cm->error, AOM_CODEC_ERROR, |
309 | 43 | "Incorrect buffer dimensions"); |
310 | 43 | } |
311 | | // Overwrite the reference frame buffer pointers. |
312 | | // Once we no longer need the external reference buffer, these pointers |
313 | | // are restored. |
314 | 424 | ref_buf->store_buf_adr[0] = ref_buf->y_buffer; |
315 | 424 | ref_buf->store_buf_adr[1] = ref_buf->u_buffer; |
316 | 424 | ref_buf->store_buf_adr[2] = ref_buf->v_buffer; |
317 | 424 | ref_buf->y_buffer = sd->y_buffer; |
318 | 424 | ref_buf->u_buffer = sd->u_buffer; |
319 | 424 | ref_buf->v_buffer = sd->v_buffer; |
320 | 424 | ref_buf->use_external_reference_buffers = 1; |
321 | 424 | } |
322 | | |
323 | 424 | return AOM_CODEC_OK; |
324 | 424 | } |
325 | | |
326 | | aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm, |
327 | | YV12_BUFFER_CONFIG *new_frame, |
328 | 0 | YV12_BUFFER_CONFIG *sd) { |
329 | 0 | const int num_planes = av1_num_planes(cm); |
330 | |
|
331 | 0 | if (!equal_dimensions_and_border(new_frame, sd)) { |
332 | 0 | aom_set_error(cm->error, AOM_CODEC_ERROR, "Incorrect buffer dimensions"); |
333 | 0 | return cm->error->error_code; |
334 | 0 | } |
335 | | |
336 | 0 | aom_yv12_copy_frame(new_frame, sd, num_planes); |
337 | |
|
338 | 0 | return AOM_CODEC_OK; |
339 | 0 | } |
340 | | |
341 | 160k | static void release_current_frame(AV1Decoder *pbi) { |
342 | 160k | AV1_COMMON *const cm = &pbi->common; |
343 | 160k | BufferPool *const pool = cm->buffer_pool; |
344 | | |
345 | 160k | cm->cur_frame->buf.corrupted = 1; |
346 | 160k | lock_buffer_pool(pool); |
347 | 160k | decrease_ref_count(cm->cur_frame, pool); |
348 | 160k | unlock_buffer_pool(pool); |
349 | 160k | cm->cur_frame = NULL; |
350 | 160k | } |
351 | | |
352 | | // If any buffer updating is signaled it should be done here. |
353 | | // Consumes a reference to cm->cur_frame. |
354 | | // |
355 | | // This functions returns void. It reports failure by setting |
356 | | // pbi->error.error_code. |
357 | 90.0k | static void update_frame_buffers(AV1Decoder *pbi, int frame_decoded) { |
358 | 90.0k | int ref_index = 0, mask; |
359 | 90.0k | AV1_COMMON *const cm = &pbi->common; |
360 | 90.0k | BufferPool *const pool = cm->buffer_pool; |
361 | | |
362 | 90.0k | if (frame_decoded) { |
363 | 89.7k | lock_buffer_pool(pool); |
364 | | |
365 | | // In ext-tile decoding, the camera frame header is only decoded once. So, |
366 | | // we don't update the references here. |
367 | 89.7k | if (!pbi->camera_frame_header_ready) { |
368 | | // The following for loop needs to release the reference stored in |
369 | | // cm->ref_frame_map[ref_index] before storing a reference to |
370 | | // cm->cur_frame in cm->ref_frame_map[ref_index]. |
371 | 589k | for (mask = cm->current_frame.refresh_frame_flags; mask; mask >>= 1) { |
372 | 505k | if (mask & 1) { |
373 | 362k | decrease_ref_count(cm->ref_frame_map[ref_index], pool); |
374 | 362k | cm->ref_frame_map[ref_index] = cm->cur_frame; |
375 | 362k | ++cm->cur_frame->ref_count; |
376 | 362k | } |
377 | 505k | ++ref_index; |
378 | 505k | } |
379 | 84.5k | } |
380 | | |
381 | 89.7k | if (cm->show_existing_frame || cm->show_frame) { |
382 | 65.4k | if (pbi->output_all_layers) { |
383 | | // Append this frame to the output queue |
384 | 16.6k | if (pbi->num_output_frames >= MAX_NUM_SPATIAL_LAYERS) { |
385 | | // We can't store the new frame anywhere, so drop it and return an |
386 | | // error |
387 | 3 | cm->cur_frame->buf.corrupted = 1; |
388 | 3 | decrease_ref_count(cm->cur_frame, pool); |
389 | 3 | pbi->error.error_code = AOM_CODEC_UNSUP_BITSTREAM; |
390 | 16.6k | } else { |
391 | 16.6k | pbi->output_frames[pbi->num_output_frames] = cm->cur_frame; |
392 | 16.6k | pbi->num_output_frames++; |
393 | 16.6k | } |
394 | 48.8k | } else { |
395 | | // Replace any existing output frame |
396 | 48.8k | assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1); |
397 | 48.8k | if (pbi->num_output_frames > 0) { |
398 | 11.8k | decrease_ref_count(pbi->output_frames[0], pool); |
399 | 11.8k | } |
400 | 48.8k | pbi->output_frames[0] = cm->cur_frame; |
401 | 48.8k | pbi->num_output_frames = 1; |
402 | 48.8k | } |
403 | 65.4k | } else { |
404 | 24.2k | decrease_ref_count(cm->cur_frame, pool); |
405 | 24.2k | } |
406 | | |
407 | 89.7k | unlock_buffer_pool(pool); |
408 | 89.7k | } else { |
409 | | // Nothing was decoded, so just drop this frame buffer |
410 | 316 | lock_buffer_pool(pool); |
411 | 316 | decrease_ref_count(cm->cur_frame, pool); |
412 | 316 | unlock_buffer_pool(pool); |
413 | 316 | } |
414 | 90.0k | cm->cur_frame = NULL; |
415 | | |
416 | 90.0k | if (!pbi->camera_frame_header_ready) { |
417 | | // Invalidate these references until the next frame starts. |
418 | 678k | for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) { |
419 | 593k | cm->remapped_ref_idx[ref_index] = INVALID_IDX; |
420 | 593k | } |
421 | 84.8k | } |
422 | 90.0k | } |
423 | | |
424 | | int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, |
425 | 250k | const uint8_t **psource) { |
426 | 250k | AV1_COMMON *volatile const cm = &pbi->common; |
427 | 250k | const uint8_t *source = *psource; |
428 | 250k | pbi->error.error_code = AOM_CODEC_OK; |
429 | 250k | pbi->error.has_detail = 0; |
430 | | |
431 | 250k | if (size == 0) { |
432 | | // This is used to signal that we are missing frames. |
433 | | // We do not know if the missing frame(s) was supposed to update |
434 | | // any of the reference buffers, but we act conservative and |
435 | | // mark only the last buffer as corrupted. |
436 | | // |
437 | | // TODO(jkoleszar): Error concealment is undefined and non-normative |
438 | | // at this point, but if it becomes so, [0] may not always be the correct |
439 | | // thing to do here. |
440 | 239 | RefCntBuffer *ref_buf = get_ref_frame_buf(cm, LAST_FRAME); |
441 | 239 | if (ref_buf != NULL) ref_buf->buf.corrupted = 1; |
442 | 239 | } |
443 | | |
444 | 250k | if (assign_cur_frame_new_fb(cm) == NULL) { |
445 | 0 | pbi->error.error_code = AOM_CODEC_MEM_ERROR; |
446 | 0 | return 1; |
447 | 0 | } |
448 | | |
449 | | // The jmp_buf is valid only for the duration of the function that calls |
450 | | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
451 | | // before it returns. |
452 | 250k | if (setjmp(pbi->error.jmp)) { |
453 | 106k | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
454 | 106k | int i; |
455 | | |
456 | 106k | pbi->error.setjmp = 0; |
457 | | |
458 | | // Synchronize all threads immediately as a subsequent decode call may |
459 | | // cause a resize invalidating some allocations. |
460 | 106k | winterface->sync(&pbi->lf_worker); |
461 | 1.12M | for (i = 0; i < pbi->num_workers; ++i) { |
462 | 1.02M | winterface->sync(&pbi->tile_workers[i]); |
463 | 1.02M | } |
464 | | |
465 | 106k | release_current_frame(pbi); |
466 | 106k | return -1; |
467 | 106k | } |
468 | | |
469 | 143k | pbi->error.setjmp = 1; |
470 | | |
471 | 143k | int frame_decoded = |
472 | 143k | aom_decode_frame_from_obus(pbi, source, source + size, psource); |
473 | | |
474 | 143k | if (frame_decoded < 0) { |
475 | 53.7k | assert(pbi->error.error_code != AOM_CODEC_OK); |
476 | 53.7k | release_current_frame(pbi); |
477 | 53.7k | pbi->error.setjmp = 0; |
478 | 53.7k | return 1; |
479 | 53.7k | } |
480 | | |
481 | | #if TXCOEFF_TIMER |
482 | | cm->cum_txcoeff_timer += cm->txcoeff_timer; |
483 | | fprintf(stderr, |
484 | | "txb coeff block number: %d, frame time: %ld, cum time %ld in us\n", |
485 | | cm->txb_count, cm->txcoeff_timer, cm->cum_txcoeff_timer); |
486 | | cm->txcoeff_timer = 0; |
487 | | cm->txb_count = 0; |
488 | | #endif |
489 | | |
490 | | // Note: At this point, this function holds a reference to cm->cur_frame |
491 | | // in the buffer pool. This reference is consumed by update_frame_buffers(). |
492 | 90.0k | update_frame_buffers(pbi, frame_decoded); |
493 | | |
494 | 90.0k | if (frame_decoded) { |
495 | 89.7k | pbi->decoding_first_frame = 0; |
496 | 89.7k | } |
497 | | |
498 | 90.0k | if (pbi->error.error_code != AOM_CODEC_OK) { |
499 | 3 | pbi->error.setjmp = 0; |
500 | 3 | return 1; |
501 | 3 | } |
502 | | |
503 | 90.0k | if (!cm->show_existing_frame) { |
504 | 89.9k | if (cm->seg.enabled) { |
505 | 17.3k | if (cm->prev_frame && |
506 | 8.87k | (cm->mi_params.mi_rows == cm->prev_frame->mi_rows) && |
507 | 7.59k | (cm->mi_params.mi_cols == cm->prev_frame->mi_cols)) { |
508 | 7.57k | cm->last_frame_seg_map = cm->prev_frame->seg_map; |
509 | 9.75k | } else { |
510 | 9.75k | cm->last_frame_seg_map = NULL; |
511 | 9.75k | } |
512 | 17.3k | } |
513 | 89.9k | } |
514 | | |
515 | | // Update progress in frame parallel decode. |
516 | 90.0k | pbi->error.setjmp = 0; |
517 | | |
518 | 90.0k | return 0; |
519 | 90.0k | } |
520 | | |
521 | | // Get the frame at a particular index in the output queue |
522 | | int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd, |
523 | 158k | aom_film_grain_t **grain_params) { |
524 | 158k | if (index >= pbi->num_output_frames) return -1; |
525 | 49.1k | *sd = &pbi->output_frames[index]->buf; |
526 | 49.1k | *grain_params = &pbi->output_frames[index]->film_grain_params; |
527 | 49.1k | return 0; |
528 | 158k | } |
529 | | |
530 | | // Get the highest-spatial-layer output |
531 | | // TODO(rachelbarker): What should this do? |
532 | 0 | int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) { |
533 | 0 | if (pbi->num_output_frames == 0) return -1; |
534 | | |
535 | 0 | *frame = pbi->output_frames[pbi->num_output_frames - 1]->buf; |
536 | 0 | return 0; |
537 | 0 | } |