/src/aom/av1/decoder/decoder.c
Line | Count | Source (jump to first uncovered line) |
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_scale/aom_scale.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 | 14.2k | static void initialize_dec(void) { |
39 | 14.2k | av1_rtcd(); |
40 | 14.2k | aom_dsp_rtcd(); |
41 | 14.2k | aom_scale_rtcd(); |
42 | 14.2k | av1_init_intra_predictors(); |
43 | 14.2k | av1_init_wedge_masks(); |
44 | 14.2k | } |
45 | | |
46 | | static void dec_set_mb_mi(CommonModeInfoParams *mi_params, int width, |
47 | 90.9k | int height, BLOCK_SIZE min_partition_size) { |
48 | 90.9k | (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 | 90.9k | const int aligned_width = ALIGN_POWER_OF_TWO(width, 3); |
55 | 90.9k | const int aligned_height = ALIGN_POWER_OF_TWO(height, 3); |
56 | | |
57 | 90.9k | mi_params->mi_cols = aligned_width >> MI_SIZE_LOG2; |
58 | 90.9k | mi_params->mi_rows = aligned_height >> MI_SIZE_LOG2; |
59 | 90.9k | mi_params->mi_stride = calc_mi_size(mi_params->mi_cols); |
60 | | |
61 | 90.9k | mi_params->mb_cols = ROUND_POWER_OF_TWO(mi_params->mi_cols, 2); |
62 | 90.9k | mi_params->mb_rows = ROUND_POWER_OF_TWO(mi_params->mi_rows, 2); |
63 | 90.9k | mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols; |
64 | | |
65 | 90.9k | mi_params->mi_alloc_bsize = BLOCK_4X4; |
66 | 90.9k | mi_params->mi_alloc_stride = mi_params->mi_stride; |
67 | | |
68 | 90.9k | assert(mi_size_wide[mi_params->mi_alloc_bsize] == |
69 | 90.9k | mi_size_high[mi_params->mi_alloc_bsize]); |
70 | 90.9k | } |
71 | | |
72 | 235k | static void dec_setup_mi(CommonModeInfoParams *mi_params) { |
73 | 235k | const int mi_grid_size = |
74 | 235k | mi_params->mi_stride * calc_mi_size(mi_params->mi_rows); |
75 | 235k | memset(mi_params->mi_grid_base, 0, |
76 | 235k | mi_grid_size * sizeof(*mi_params->mi_grid_base)); |
77 | 235k | } |
78 | | |
79 | 45.9k | static void dec_free_mi(CommonModeInfoParams *mi_params) { |
80 | 45.9k | aom_free(mi_params->mi_alloc); |
81 | 45.9k | mi_params->mi_alloc = NULL; |
82 | 45.9k | aom_free(mi_params->mi_grid_base); |
83 | 45.9k | mi_params->mi_grid_base = NULL; |
84 | 45.9k | mi_params->mi_alloc_size = 0; |
85 | 45.9k | aom_free(mi_params->tx_type_map); |
86 | 45.9k | mi_params->tx_type_map = NULL; |
87 | 45.9k | } |
88 | | |
89 | 14.2k | AV1Decoder *av1_decoder_create(BufferPool *const pool) { |
90 | 14.2k | AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi)); |
91 | 14.2k | if (!pbi) return NULL; |
92 | 14.2k | av1_zero(*pbi); |
93 | | |
94 | 14.2k | AV1_COMMON *volatile const cm = &pbi->common; |
95 | 14.2k | cm->seq_params = &pbi->seq_params; |
96 | 14.2k | cm->error = &pbi->error; |
97 | | |
98 | | // The jmp_buf is valid only for the duration of the function that calls |
99 | | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
100 | | // before it returns. |
101 | 14.2k | if (setjmp(pbi->error.jmp)) { |
102 | 0 | pbi->error.setjmp = 0; |
103 | 0 | av1_decoder_remove(pbi); |
104 | 0 | return NULL; |
105 | 0 | } |
106 | | |
107 | 14.2k | pbi->error.setjmp = 1; |
108 | | |
109 | 14.2k | CHECK_MEM_ERROR(cm, cm->fc, |
110 | 14.2k | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
111 | 14.2k | CHECK_MEM_ERROR( |
112 | 14.2k | cm, cm->default_frame_context, |
113 | 14.2k | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context))); |
114 | 14.2k | memset(cm->fc, 0, sizeof(*cm->fc)); |
115 | 14.2k | memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context)); |
116 | | |
117 | 14.2k | pbi->need_resync = 1; |
118 | 14.2k | initialize_dec(); |
119 | | |
120 | | // Initialize the references to not point to any frame buffers. |
121 | 127k | for (int i = 0; i < REF_FRAMES; i++) { |
122 | 113k | cm->ref_frame_map[i] = NULL; |
123 | 113k | } |
124 | | |
125 | 14.2k | cm->current_frame.frame_number = 0; |
126 | 14.2k | pbi->decoding_first_frame = 1; |
127 | 14.2k | pbi->common.buffer_pool = pool; |
128 | | |
129 | 14.2k | cm->seq_params->bit_depth = AOM_BITS_8; |
130 | | |
131 | 14.2k | cm->mi_params.free_mi = dec_free_mi; |
132 | 14.2k | cm->mi_params.setup_mi = dec_setup_mi; |
133 | 14.2k | cm->mi_params.set_mb_mi = dec_set_mb_mi; |
134 | | |
135 | 14.2k | av1_loop_filter_init(cm); |
136 | | |
137 | 14.2k | av1_qm_init(&cm->quant_params, av1_num_planes(cm)); |
138 | 14.2k | av1_loop_restoration_precal(); |
139 | | |
140 | | #if CONFIG_ACCOUNTING |
141 | | pbi->acct_enabled = 1; |
142 | | aom_accounting_init(&pbi->accounting); |
143 | | #endif |
144 | | |
145 | 14.2k | pbi->error.setjmp = 0; |
146 | | |
147 | 14.2k | aom_get_worker_interface()->init(&pbi->lf_worker); |
148 | 14.2k | pbi->lf_worker.thread_name = "aom lf worker"; |
149 | | |
150 | 14.2k | return pbi; |
151 | 14.2k | } |
152 | | |
153 | 8.37k | void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) { |
154 | 8.37k | if (tile_mt_info != NULL) { |
155 | 8.37k | #if CONFIG_MULTITHREAD |
156 | 8.37k | if (tile_mt_info->job_mutex != NULL) { |
157 | 4.60k | pthread_mutex_destroy(tile_mt_info->job_mutex); |
158 | 4.60k | aom_free(tile_mt_info->job_mutex); |
159 | 4.60k | } |
160 | 8.37k | #endif |
161 | 8.37k | aom_free(tile_mt_info->job_queue); |
162 | | // clear the structure as the source of this call may be a resize in which |
163 | | // case this call will be followed by an _alloc() which may fail. |
164 | 8.37k | av1_zero(*tile_mt_info); |
165 | 8.37k | } |
166 | 8.37k | } |
167 | | |
168 | 18.7k | void av1_dec_free_cb_buf(AV1Decoder *pbi) { |
169 | 18.7k | aom_free(pbi->cb_buffer_base); |
170 | 18.7k | pbi->cb_buffer_base = NULL; |
171 | 18.7k | pbi->cb_buffer_alloc_size = 0; |
172 | 18.7k | } |
173 | | |
174 | 14.2k | void av1_decoder_remove(AV1Decoder *pbi) { |
175 | 14.2k | int i; |
176 | | |
177 | 14.2k | if (!pbi) return; |
178 | | |
179 | | // Free the tile list output buffer. |
180 | 14.2k | aom_free_frame_buffer(&pbi->tile_list_outbuf); |
181 | | |
182 | 14.2k | aom_get_worker_interface()->end(&pbi->lf_worker); |
183 | 14.2k | aom_free(pbi->lf_worker.data1); |
184 | | |
185 | 14.2k | if (pbi->thread_data) { |
186 | 112k | for (int worker_idx = 1; worker_idx < pbi->num_workers; worker_idx++) { |
187 | 108k | DecWorkerData *const thread_data = pbi->thread_data + worker_idx; |
188 | 108k | if (thread_data->td != NULL) { |
189 | 108k | av1_free_mc_tmp_buf(thread_data->td); |
190 | 108k | aom_free(thread_data->td); |
191 | 108k | } |
192 | 108k | } |
193 | 3.76k | aom_free(pbi->thread_data); |
194 | 3.76k | } |
195 | 14.2k | aom_free(pbi->dcb.xd.seg_mask); |
196 | | |
197 | 126k | for (i = 0; i < pbi->num_workers; ++i) { |
198 | 112k | AVxWorker *const worker = &pbi->tile_workers[i]; |
199 | 112k | aom_get_worker_interface()->end(worker); |
200 | 112k | } |
201 | 14.2k | #if CONFIG_MULTITHREAD |
202 | 14.2k | if (pbi->row_mt_mutex_ != NULL) { |
203 | 3.67k | pthread_mutex_destroy(pbi->row_mt_mutex_); |
204 | 3.67k | aom_free(pbi->row_mt_mutex_); |
205 | 3.67k | } |
206 | 14.2k | if (pbi->row_mt_cond_ != NULL) { |
207 | 3.67k | pthread_cond_destroy(pbi->row_mt_cond_); |
208 | 3.67k | aom_free(pbi->row_mt_cond_); |
209 | 3.67k | } |
210 | 14.2k | #endif |
211 | 31.1k | for (i = 0; i < pbi->allocated_tiles; i++) { |
212 | 16.9k | TileDataDec *const tile_data = pbi->tile_data + i; |
213 | 16.9k | av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync); |
214 | 16.9k | } |
215 | 14.2k | aom_free(pbi->tile_data); |
216 | 14.2k | aom_free(pbi->tile_workers); |
217 | | |
218 | 14.2k | if (pbi->num_workers > 0) { |
219 | 3.76k | av1_loop_filter_dealloc(&pbi->lf_row_sync); |
220 | 3.76k | av1_loop_restoration_dealloc(&pbi->lr_row_sync, pbi->num_workers); |
221 | 3.76k | av1_dealloc_dec_jobs(&pbi->tile_mt_info); |
222 | 3.76k | } |
223 | | |
224 | 14.2k | av1_dec_free_cb_buf(pbi); |
225 | | #if CONFIG_ACCOUNTING |
226 | | aom_accounting_clear(&pbi->accounting); |
227 | | #endif |
228 | 14.2k | av1_free_mc_tmp_buf(&pbi->td); |
229 | 14.2k | aom_img_metadata_array_free(pbi->metadata); |
230 | 14.2k | av1_remove_common(&pbi->common); |
231 | 14.2k | aom_free(pbi); |
232 | 14.2k | } |
233 | | |
234 | | void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, |
235 | 41.6M | aom_reader *r, palette_visitor_fn_t visit) { |
236 | 41.6M | if (!is_inter_block(xd->mi[0])) { |
237 | 70.5M | for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common)); |
238 | 46.8M | ++plane) { |
239 | 46.8M | if (plane == 0 || xd->is_chroma_ref) { |
240 | 45.3M | if (xd->mi[0]->palette_mode_info.palette_size[plane]) |
241 | 243k | visit(xd, plane, r); |
242 | 45.3M | } else { |
243 | 1.46M | assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0); |
244 | 1.46M | } |
245 | 46.8M | } |
246 | 23.7M | } |
247 | 41.6M | } |
248 | | |
249 | | static int equal_dimensions(const YV12_BUFFER_CONFIG *a, |
250 | 0 | const YV12_BUFFER_CONFIG *b) { |
251 | 0 | return a->y_height == b->y_height && a->y_width == b->y_width && |
252 | 0 | a->uv_height == b->uv_height && a->uv_width == b->uv_width; |
253 | 0 | } |
254 | | |
255 | | aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi, int idx, |
256 | 0 | YV12_BUFFER_CONFIG *sd) { |
257 | 0 | AV1_COMMON *cm = &pbi->common; |
258 | 0 | const int num_planes = av1_num_planes(cm); |
259 | |
|
260 | 0 | const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, idx); |
261 | 0 | if (cfg == NULL) { |
262 | 0 | aom_internal_error(&pbi->error, AOM_CODEC_ERROR, "No reference frame"); |
263 | 0 | return AOM_CODEC_ERROR; |
264 | 0 | } |
265 | 0 | if (!equal_dimensions(cfg, sd)) |
266 | 0 | aom_internal_error(&pbi->error, AOM_CODEC_ERROR, |
267 | 0 | "Incorrect buffer dimensions"); |
268 | 0 | else |
269 | 0 | aom_yv12_copy_frame(cfg, sd, num_planes); |
270 | |
|
271 | 0 | return pbi->error.error_code; |
272 | 0 | } |
273 | | |
274 | | static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a, |
275 | 0 | const YV12_BUFFER_CONFIG *b) { |
276 | 0 | return a->y_height == b->y_height && a->y_width == b->y_width && |
277 | 0 | a->uv_height == b->uv_height && a->uv_width == b->uv_width && |
278 | 0 | a->y_stride == b->y_stride && a->uv_stride == b->uv_stride && |
279 | 0 | a->border == b->border && |
280 | 0 | (a->flags & YV12_FLAG_HIGHBITDEPTH) == |
281 | 0 | (b->flags & YV12_FLAG_HIGHBITDEPTH); |
282 | 0 | } |
283 | | |
284 | | aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx, |
285 | | int use_external_ref, |
286 | 0 | YV12_BUFFER_CONFIG *sd) { |
287 | 0 | const int num_planes = av1_num_planes(cm); |
288 | 0 | YV12_BUFFER_CONFIG *ref_buf = NULL; |
289 | | |
290 | | // Get the destination reference buffer. |
291 | 0 | ref_buf = get_ref_frame(cm, idx); |
292 | |
|
293 | 0 | if (ref_buf == NULL) { |
294 | 0 | aom_internal_error(cm->error, AOM_CODEC_ERROR, "No reference frame"); |
295 | 0 | return AOM_CODEC_ERROR; |
296 | 0 | } |
297 | | |
298 | 0 | if (!use_external_ref) { |
299 | 0 | if (!equal_dimensions(ref_buf, sd)) { |
300 | 0 | aom_internal_error(cm->error, AOM_CODEC_ERROR, |
301 | 0 | "Incorrect buffer dimensions"); |
302 | 0 | } else { |
303 | | // Overwrite the reference frame buffer. |
304 | 0 | aom_yv12_copy_frame(sd, ref_buf, num_planes); |
305 | 0 | } |
306 | 0 | } else { |
307 | 0 | if (!equal_dimensions_and_border(ref_buf, sd)) { |
308 | 0 | aom_internal_error(cm->error, AOM_CODEC_ERROR, |
309 | 0 | "Incorrect buffer dimensions"); |
310 | 0 | } else { |
311 | | // Overwrite the reference frame buffer pointers. |
312 | | // Once we no longer need the external reference buffer, these pointers |
313 | | // are restored. |
314 | 0 | ref_buf->store_buf_adr[0] = ref_buf->y_buffer; |
315 | 0 | ref_buf->store_buf_adr[1] = ref_buf->u_buffer; |
316 | 0 | ref_buf->store_buf_adr[2] = ref_buf->v_buffer; |
317 | 0 | ref_buf->y_buffer = sd->y_buffer; |
318 | 0 | ref_buf->u_buffer = sd->u_buffer; |
319 | 0 | ref_buf->v_buffer = sd->v_buffer; |
320 | 0 | ref_buf->use_external_reference_buffers = 1; |
321 | 0 | } |
322 | 0 | } |
323 | |
|
324 | 0 | return cm->error->error_code; |
325 | 0 | } |
326 | | |
327 | | aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm, |
328 | | YV12_BUFFER_CONFIG *new_frame, |
329 | 0 | YV12_BUFFER_CONFIG *sd) { |
330 | 0 | const int num_planes = av1_num_planes(cm); |
331 | |
|
332 | 0 | if (!equal_dimensions_and_border(new_frame, sd)) |
333 | 0 | aom_internal_error(cm->error, AOM_CODEC_ERROR, |
334 | 0 | "Incorrect buffer dimensions"); |
335 | 0 | else |
336 | 0 | aom_yv12_copy_frame(new_frame, sd, num_planes); |
337 | |
|
338 | 0 | return cm->error->error_code; |
339 | 0 | } |
340 | | |
341 | 161k | static void release_current_frame(AV1Decoder *pbi) { |
342 | 161k | AV1_COMMON *const cm = &pbi->common; |
343 | 161k | BufferPool *const pool = cm->buffer_pool; |
344 | | |
345 | 161k | cm->cur_frame->buf.corrupted = 1; |
346 | 161k | lock_buffer_pool(pool); |
347 | 161k | decrease_ref_count(cm->cur_frame, pool); |
348 | 161k | unlock_buffer_pool(pool); |
349 | 161k | cm->cur_frame = NULL; |
350 | 161k | } |
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 | 88.7k | static void update_frame_buffers(AV1Decoder *pbi, int frame_decoded) { |
358 | 88.7k | int ref_index = 0, mask; |
359 | 88.7k | AV1_COMMON *const cm = &pbi->common; |
360 | 88.7k | BufferPool *const pool = cm->buffer_pool; |
361 | | |
362 | 88.7k | if (frame_decoded) { |
363 | 87.8k | 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 | 87.8k | 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 | 561k | for (mask = cm->current_frame.refresh_frame_flags; mask; mask >>= 1) { |
372 | 473k | if (mask & 1) { |
373 | 326k | decrease_ref_count(cm->ref_frame_map[ref_index], pool); |
374 | 326k | cm->ref_frame_map[ref_index] = cm->cur_frame; |
375 | 326k | ++cm->cur_frame->ref_count; |
376 | 326k | } |
377 | 473k | ++ref_index; |
378 | 473k | } |
379 | 87.8k | } |
380 | | |
381 | 87.8k | if (cm->show_existing_frame || cm->show_frame) { |
382 | 67.5k | if (pbi->output_all_layers) { |
383 | | // Append this frame to the output queue |
384 | 0 | 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 | 0 | cm->cur_frame->buf.corrupted = 1; |
388 | 0 | decrease_ref_count(cm->cur_frame, pool); |
389 | 0 | pbi->error.error_code = AOM_CODEC_UNSUP_BITSTREAM; |
390 | 0 | } else { |
391 | 0 | pbi->output_frames[pbi->num_output_frames] = cm->cur_frame; |
392 | 0 | pbi->num_output_frames++; |
393 | 0 | } |
394 | 67.5k | } else { |
395 | | // Replace any existing output frame |
396 | 67.5k | assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1); |
397 | 67.5k | if (pbi->num_output_frames > 0) { |
398 | 9.70k | decrease_ref_count(pbi->output_frames[0], pool); |
399 | 9.70k | } |
400 | 67.5k | pbi->output_frames[0] = cm->cur_frame; |
401 | 67.5k | pbi->num_output_frames = 1; |
402 | 67.5k | } |
403 | 67.5k | } else { |
404 | 20.3k | decrease_ref_count(cm->cur_frame, pool); |
405 | 20.3k | } |
406 | | |
407 | 0 | unlock_buffer_pool(pool); |
408 | 87.8k | } else { |
409 | | // Nothing was decoded, so just drop this frame buffer |
410 | 824 | lock_buffer_pool(pool); |
411 | 824 | decrease_ref_count(cm->cur_frame, pool); |
412 | 824 | unlock_buffer_pool(pool); |
413 | 824 | } |
414 | 0 | cm->cur_frame = NULL; |
415 | | |
416 | 88.7k | if (!pbi->camera_frame_header_ready) { |
417 | | // Invalidate these references until the next frame starts. |
418 | 709k | for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) { |
419 | 620k | cm->remapped_ref_idx[ref_index] = INVALID_IDX; |
420 | 620k | } |
421 | 88.7k | } |
422 | 88.7k | } |
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 | 0 | RefCntBuffer *ref_buf = get_ref_frame_buf(cm, LAST_FRAME); |
441 | 0 | if (ref_buf != NULL) ref_buf->buf.corrupted = 1; |
442 | 0 | } |
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 | 115k | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
454 | 115k | int i; |
455 | | |
456 | 115k | pbi->error.setjmp = 0; |
457 | | |
458 | | // Synchronize all threads immediately as a subsequent decode call may |
459 | | // cause a resize invalidating some allocations. |
460 | 115k | winterface->sync(&pbi->lf_worker); |
461 | 2.44M | for (i = 0; i < pbi->num_workers; ++i) { |
462 | 2.33M | winterface->sync(&pbi->tile_workers[i]); |
463 | 2.33M | } |
464 | | |
465 | 115k | release_current_frame(pbi); |
466 | 115k | return -1; |
467 | 115k | } |
468 | | |
469 | 134k | pbi->error.setjmp = 1; |
470 | | |
471 | 134k | int frame_decoded = |
472 | 134k | aom_decode_frame_from_obus(pbi, source, source + size, psource); |
473 | | |
474 | 134k | if (frame_decoded < 0) { |
475 | 46.2k | assert(pbi->error.error_code != AOM_CODEC_OK); |
476 | 0 | release_current_frame(pbi); |
477 | 46.2k | pbi->error.setjmp = 0; |
478 | 46.2k | return 1; |
479 | 46.2k | } |
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 | 88.7k | update_frame_buffers(pbi, frame_decoded); |
493 | | |
494 | 88.7k | if (frame_decoded) { |
495 | 87.8k | pbi->decoding_first_frame = 0; |
496 | 87.8k | } |
497 | | |
498 | 88.7k | if (pbi->error.error_code != AOM_CODEC_OK) { |
499 | 0 | pbi->error.setjmp = 0; |
500 | 0 | return 1; |
501 | 0 | } |
502 | | |
503 | 88.7k | if (!cm->show_existing_frame) { |
504 | 87.9k | if (cm->seg.enabled) { |
505 | 12.6k | if (cm->prev_frame && |
506 | 12.6k | (cm->mi_params.mi_rows == cm->prev_frame->mi_rows) && |
507 | 12.6k | (cm->mi_params.mi_cols == cm->prev_frame->mi_cols)) { |
508 | 4.98k | cm->last_frame_seg_map = cm->prev_frame->seg_map; |
509 | 7.63k | } else { |
510 | 7.63k | cm->last_frame_seg_map = NULL; |
511 | 7.63k | } |
512 | 12.6k | } |
513 | 87.9k | } |
514 | | |
515 | | // Update progress in frame parallel decode. |
516 | 88.7k | pbi->error.setjmp = 0; |
517 | | |
518 | 88.7k | return 0; |
519 | 88.7k | } |
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 | 120k | aom_film_grain_t **grain_params) { |
524 | 120k | if (index >= pbi->num_output_frames) return -1; |
525 | 55.1k | *sd = &pbi->output_frames[index]->buf; |
526 | 55.1k | *grain_params = &pbi->output_frames[index]->film_grain_params; |
527 | 55.1k | return 0; |
528 | 120k | } |
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 | } |