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_mem/aom_mem.h"
21 #include "aom_ports/system_state.h"
22 #include "aom_ports/aom_once.h"
23 #include "aom_ports/aom_timer.h"
24 #include "aom_scale/aom_scale.h"
25 #include "aom_util/aom_thread.h"
26
27 #include "av1/common/alloccommon.h"
28 #include "av1/common/av1_loopfilter.h"
29 #include "av1/common/onyxc_int.h"
30 #include "av1/common/quant_common.h"
31 #include "av1/common/reconinter.h"
32 #include "av1/common/reconintra.h"
33
34 #include "av1/decoder/decodeframe.h"
35 #include "av1/decoder/decoder.h"
36 #include "av1/decoder/detokenize.h"
37 #include "av1/decoder/obu.h"
38
initialize_dec(void)39 static void initialize_dec(void) {
40 av1_rtcd();
41 aom_dsp_rtcd();
42 aom_scale_rtcd();
43 av1_init_intra_predictors();
44 av1_init_wedge_masks();
45 }
46
dec_setup_mi(AV1_COMMON * cm)47 static void dec_setup_mi(AV1_COMMON *cm) {
48 cm->mi = cm->mip;
49 cm->mi_grid_visible = cm->mi_grid_base;
50 memset(cm->mi_grid_base, 0,
51 cm->mi_stride * cm->mi_rows * sizeof(*cm->mi_grid_base));
52 }
53
av1_dec_alloc_mi(AV1_COMMON * cm,int mi_size)54 static int av1_dec_alloc_mi(AV1_COMMON *cm, int mi_size) {
55 cm->mip = aom_calloc(mi_size, sizeof(*cm->mip));
56 if (!cm->mip) return 1;
57 cm->mi_alloc_size = mi_size;
58 cm->mi_grid_base =
59 (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *));
60 if (!cm->mi_grid_base) return 1;
61 return 0;
62 }
63
dec_free_mi(AV1_COMMON * cm)64 static void dec_free_mi(AV1_COMMON *cm) {
65 aom_free(cm->mip);
66 cm->mip = NULL;
67 aom_free(cm->mi_grid_base);
68 cm->mi_grid_base = NULL;
69 cm->mi_alloc_size = 0;
70 }
71
av1_decoder_create(BufferPool * const pool)72 AV1Decoder *av1_decoder_create(BufferPool *const pool) {
73 AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi));
74 AV1_COMMON *volatile const cm = pbi ? &pbi->common : NULL;
75
76 if (!cm) return NULL;
77
78 av1_zero(*pbi);
79
80 // The jmp_buf is valid only for the duration of the function that calls
81 // setjmp(). Therefore, this function must reset the 'setjmp' field to 0
82 // before it returns.
83 if (setjmp(cm->error.jmp)) {
84 cm->error.setjmp = 0;
85 av1_decoder_remove(pbi);
86 return NULL;
87 }
88
89 cm->error.setjmp = 1;
90
91 CHECK_MEM_ERROR(cm, cm->fc,
92 (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc)));
93 CHECK_MEM_ERROR(cm, cm->frame_contexts,
94 (FRAME_CONTEXT *)aom_memalign(
95 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)));
96 memset(cm->fc, 0, sizeof(*cm->fc));
97 memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts));
98
99 pbi->need_resync = 1;
100 aom_once(initialize_dec);
101
102 // Initialize the references to not point to any frame buffers.
103 memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
104 memset(&cm->next_ref_frame_map, -1, sizeof(cm->next_ref_frame_map));
105
106 cm->current_video_frame = 0;
107 pbi->decoding_first_frame = 1;
108 pbi->common.buffer_pool = pool;
109
110 cm->seq_params.bit_depth = AOM_BITS_8;
111 cm->dequant_bit_depth = AOM_BITS_8;
112
113 cm->alloc_mi = av1_dec_alloc_mi;
114 cm->free_mi = dec_free_mi;
115 cm->setup_mi = dec_setup_mi;
116
117 av1_loop_filter_init(cm);
118
119 av1_qm_init(cm);
120 av1_loop_restoration_precal();
121 #if CONFIG_ACCOUNTING
122 pbi->acct_enabled = 1;
123 aom_accounting_init(&pbi->accounting);
124 #endif
125
126 cm->error.setjmp = 0;
127
128 aom_get_worker_interface()->init(&pbi->lf_worker);
129
130 return pbi;
131 }
132
av1_dealloc_dec_jobs(struct AV1DecTileMTData * tile_mt_info)133 void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) {
134 if (tile_mt_info != NULL) {
135 #if CONFIG_MULTITHREAD
136 if (tile_mt_info->job_mutex != NULL) {
137 pthread_mutex_destroy(tile_mt_info->job_mutex);
138 aom_free(tile_mt_info->job_mutex);
139 }
140 #endif
141 aom_free(tile_mt_info->job_queue);
142 // clear the structure as the source of this call may be a resize in which
143 // case this call will be followed by an _alloc() which may fail.
144 av1_zero(*tile_mt_info);
145 }
146 }
147
av1_dec_free_cb_buf(AV1Decoder * pbi)148 void av1_dec_free_cb_buf(AV1Decoder *pbi) {
149 aom_free(pbi->cb_buffer_base);
150 pbi->cb_buffer_base = NULL;
151 pbi->cb_buffer_alloc_size = 0;
152 }
153
av1_decoder_remove(AV1Decoder * pbi)154 void av1_decoder_remove(AV1Decoder *pbi) {
155 int i;
156
157 if (!pbi) return;
158
159 // Free the tile list output buffer.
160 if (pbi->tile_list_output != NULL) aom_free(pbi->tile_list_output);
161 pbi->tile_list_output = NULL;
162
163 aom_get_worker_interface()->end(&pbi->lf_worker);
164 aom_free(pbi->lf_worker.data1);
165
166 if (pbi->thread_data) {
167 for (int worker_idx = 0; worker_idx < pbi->max_threads - 1; worker_idx++) {
168 DecWorkerData *const thread_data = pbi->thread_data + worker_idx;
169 av1_free_mc_tmp_buf(thread_data->td);
170 aom_free(thread_data->td);
171 }
172 aom_free(pbi->thread_data);
173 }
174
175 for (i = 0; i < pbi->num_workers; ++i) {
176 AVxWorker *const worker = &pbi->tile_workers[i];
177 aom_get_worker_interface()->end(worker);
178 }
179 #if CONFIG_MULTITHREAD
180 if (pbi->row_mt_mutex_ != NULL) {
181 pthread_mutex_destroy(pbi->row_mt_mutex_);
182 aom_free(pbi->row_mt_mutex_);
183 }
184 if (pbi->row_mt_cond_ != NULL) {
185 pthread_cond_destroy(pbi->row_mt_cond_);
186 aom_free(pbi->row_mt_cond_);
187 }
188 #endif
189 for (i = 0; i < pbi->allocated_tiles; i++) {
190 TileDataDec *const tile_data = pbi->tile_data + i;
191 av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync);
192 }
193 aom_free(pbi->tile_data);
194 aom_free(pbi->tile_workers);
195
196 if (pbi->num_workers > 0) {
197 av1_loop_filter_dealloc(&pbi->lf_row_sync);
198 av1_loop_restoration_dealloc(&pbi->lr_row_sync, pbi->num_workers);
199 av1_dealloc_dec_jobs(&pbi->tile_mt_info);
200 }
201
202 av1_dec_free_cb_buf(pbi);
203 #if CONFIG_ACCOUNTING
204 aom_accounting_clear(&pbi->accounting);
205 #endif
206 av1_free_mc_tmp_buf(&pbi->td);
207
208 aom_free(pbi);
209 }
210
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)211 void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, int mi_row,
212 int mi_col, aom_reader *r, BLOCK_SIZE bsize,
213 palette_visitor_fn_t visit) {
214 if (!is_inter_block(xd->mi[0])) {
215 for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common));
216 ++plane) {
217 const struct macroblockd_plane *const pd = &xd->plane[plane];
218 if (is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x,
219 pd->subsampling_y)) {
220 if (xd->mi[0]->palette_mode_info.palette_size[plane])
221 visit(xd, plane, r);
222 } else {
223 assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0);
224 }
225 }
226 }
227 }
228
equal_dimensions(const YV12_BUFFER_CONFIG * a,const YV12_BUFFER_CONFIG * b)229 static int equal_dimensions(const YV12_BUFFER_CONFIG *a,
230 const YV12_BUFFER_CONFIG *b) {
231 return a->y_height == b->y_height && a->y_width == b->y_width &&
232 a->uv_height == b->uv_height && a->uv_width == b->uv_width;
233 }
234
av1_copy_reference_dec(AV1Decoder * pbi,int idx,YV12_BUFFER_CONFIG * sd)235 aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi, int idx,
236 YV12_BUFFER_CONFIG *sd) {
237 AV1_COMMON *cm = &pbi->common;
238 const int num_planes = av1_num_planes(cm);
239
240 const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, idx);
241 if (cfg == NULL) {
242 aom_internal_error(&cm->error, AOM_CODEC_ERROR, "No reference frame");
243 return AOM_CODEC_ERROR;
244 }
245 if (!equal_dimensions(cfg, sd))
246 aom_internal_error(&cm->error, AOM_CODEC_ERROR,
247 "Incorrect buffer dimensions");
248 else
249 aom_yv12_copy_frame(cfg, sd, num_planes);
250
251 return cm->error.error_code;
252 }
253
equal_dimensions_and_border(const YV12_BUFFER_CONFIG * a,const YV12_BUFFER_CONFIG * b)254 static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a,
255 const YV12_BUFFER_CONFIG *b) {
256 return a->y_height == b->y_height && a->y_width == b->y_width &&
257 a->uv_height == b->uv_height && a->uv_width == b->uv_width &&
258 a->y_stride == b->y_stride && a->uv_stride == b->uv_stride &&
259 a->border == b->border &&
260 (a->flags & YV12_FLAG_HIGHBITDEPTH) ==
261 (b->flags & YV12_FLAG_HIGHBITDEPTH);
262 }
263
av1_set_reference_dec(AV1_COMMON * cm,int idx,int use_external_ref,YV12_BUFFER_CONFIG * sd)264 aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx,
265 int use_external_ref,
266 YV12_BUFFER_CONFIG *sd) {
267 const int num_planes = av1_num_planes(cm);
268 YV12_BUFFER_CONFIG *ref_buf = NULL;
269
270 // Get the destination reference buffer.
271 ref_buf = get_ref_frame(cm, idx);
272
273 if (ref_buf == NULL) {
274 aom_internal_error(&cm->error, AOM_CODEC_ERROR, "No reference frame");
275 return AOM_CODEC_ERROR;
276 }
277
278 if (!use_external_ref) {
279 if (!equal_dimensions(ref_buf, sd)) {
280 aom_internal_error(&cm->error, AOM_CODEC_ERROR,
281 "Incorrect buffer dimensions");
282 } else {
283 // Overwrite the reference frame buffer.
284 aom_yv12_copy_frame(sd, ref_buf, num_planes);
285 }
286 } else {
287 if (!equal_dimensions_and_border(ref_buf, sd)) {
288 aom_internal_error(&cm->error, AOM_CODEC_ERROR,
289 "Incorrect buffer dimensions");
290 } else {
291 // Overwrite the reference frame buffer pointers.
292 // Once we no longer need the external reference buffer, these pointers
293 // are restored.
294 ref_buf->store_buf_adr[0] = ref_buf->y_buffer;
295 ref_buf->store_buf_adr[1] = ref_buf->u_buffer;
296 ref_buf->store_buf_adr[2] = ref_buf->v_buffer;
297 ref_buf->y_buffer = sd->y_buffer;
298 ref_buf->u_buffer = sd->u_buffer;
299 ref_buf->v_buffer = sd->v_buffer;
300 ref_buf->use_external_reference_buffers = 1;
301 }
302 }
303
304 return cm->error.error_code;
305 }
306
av1_copy_new_frame_dec(AV1_COMMON * cm,YV12_BUFFER_CONFIG * new_frame,YV12_BUFFER_CONFIG * sd)307 aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm,
308 YV12_BUFFER_CONFIG *new_frame,
309 YV12_BUFFER_CONFIG *sd) {
310 const int num_planes = av1_num_planes(cm);
311
312 if (!equal_dimensions_and_border(new_frame, sd))
313 aom_internal_error(&cm->error, AOM_CODEC_ERROR,
314 "Incorrect buffer dimensions");
315 else
316 aom_yv12_copy_frame(new_frame, sd, num_planes);
317
318 return cm->error.error_code;
319 }
320
321 /* If any buffer updating is signaled it should be done here.
322 Consumes a reference to cm->new_fb_idx.
323 */
swap_frame_buffers(AV1Decoder * pbi,int frame_decoded)324 static void swap_frame_buffers(AV1Decoder *pbi, int frame_decoded) {
325 int ref_index = 0, mask;
326 AV1_COMMON *const cm = &pbi->common;
327 BufferPool *const pool = cm->buffer_pool;
328 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
329
330 if (frame_decoded) {
331 lock_buffer_pool(pool);
332
333 // In ext-tile decoding, the camera frame header is only decoded once. So,
334 // we don't release the references here.
335 if (!pbi->camera_frame_header_ready) {
336 for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
337 const int old_idx = cm->ref_frame_map[ref_index];
338 // Current thread releases the holding of reference frame.
339 decrease_ref_count(old_idx, frame_bufs, pool);
340
341 // Release the reference frame holding in the reference map for the
342 // decoding of the next frame.
343 if (mask & 1) decrease_ref_count(old_idx, frame_bufs, pool);
344 cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
345 ++ref_index;
346 }
347
348 // Current thread releases the holding of reference frame.
349 const int check_on_show_existing_frame =
350 !cm->show_existing_frame || cm->reset_decoder_state;
351 for (; ref_index < REF_FRAMES && check_on_show_existing_frame;
352 ++ref_index) {
353 const int old_idx = cm->ref_frame_map[ref_index];
354 decrease_ref_count(old_idx, frame_bufs, pool);
355 cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
356 }
357 }
358
359 YV12_BUFFER_CONFIG *cur_frame = get_frame_new_buffer(cm);
360
361 if (cm->show_existing_frame || cm->show_frame) {
362 if (pbi->output_all_layers) {
363 // Append this frame to the output queue
364 if (pbi->num_output_frames >= MAX_NUM_SPATIAL_LAYERS) {
365 // We can't store the new frame anywhere, so drop it and return an
366 // error
367 decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
368 cm->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
369 } else {
370 pbi->output_frames[pbi->num_output_frames] = cur_frame;
371 pbi->output_frame_index[pbi->num_output_frames] = cm->new_fb_idx;
372 pbi->num_output_frames++;
373 }
374 } else {
375 // Replace any existing output frame
376 assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1);
377 if (pbi->num_output_frames > 0) {
378 decrease_ref_count((int)pbi->output_frame_index[0], frame_bufs, pool);
379 }
380 pbi->output_frames[0] = cur_frame;
381 pbi->output_frame_index[0] = cm->new_fb_idx;
382 pbi->num_output_frames = 1;
383 }
384 } else {
385 decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
386 }
387
388 unlock_buffer_pool(pool);
389 } else {
390 // Nothing was decoded, so just drop this frame buffer
391 lock_buffer_pool(pool);
392 decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
393 unlock_buffer_pool(pool);
394 }
395
396 if (!pbi->camera_frame_header_ready) {
397 pbi->hold_ref_buf = 0;
398
399 // Invalidate these references until the next frame starts.
400 for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) {
401 cm->frame_refs[ref_index].idx = INVALID_IDX;
402 cm->frame_refs[ref_index].buf = NULL;
403 }
404 }
405 }
406
av1_receive_compressed_data(AV1Decoder * pbi,size_t size,const uint8_t ** psource)407 int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
408 const uint8_t **psource) {
409 AV1_COMMON *volatile const cm = &pbi->common;
410 BufferPool *volatile const pool = cm->buffer_pool;
411 RefCntBuffer *volatile const frame_bufs = cm->buffer_pool->frame_bufs;
412 const uint8_t *source = *psource;
413 cm->error.error_code = AOM_CODEC_OK;
414
415 if (size == 0) {
416 // This is used to signal that we are missing frames.
417 // We do not know if the missing frame(s) was supposed to update
418 // any of the reference buffers, but we act conservative and
419 // mark only the last buffer as corrupted.
420 //
421 // TODO(jkoleszar): Error concealment is undefined and non-normative
422 // at this point, but if it becomes so, [0] may not always be the correct
423 // thing to do here.
424 if (cm->frame_refs[0].idx > 0) {
425 assert(cm->frame_refs[0].buf != NULL);
426 cm->frame_refs[0].buf->corrupted = 1;
427 }
428 }
429
430 // Find a free buffer for the new frame, releasing the reference previously
431 // held.
432
433 // Find a free frame buffer. Return error if can not find any.
434 cm->new_fb_idx = get_free_fb(cm);
435 if (cm->new_fb_idx == INVALID_IDX) {
436 cm->error.error_code = AOM_CODEC_MEM_ERROR;
437 return 1;
438 }
439
440 // Assign a MV array to the frame buffer.
441 cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
442
443 if (!pbi->camera_frame_header_ready) pbi->hold_ref_buf = 0;
444
445 pbi->cur_buf = &frame_bufs[cm->new_fb_idx];
446
447 // The jmp_buf is valid only for the duration of the function that calls
448 // setjmp(). Therefore, this function must reset the 'setjmp' field to 0
449 // before it returns.
450 if (setjmp(cm->error.jmp)) {
451 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
452 int i;
453
454 cm->error.setjmp = 0;
455
456 // Synchronize all threads immediately as a subsequent decode call may
457 // cause a resize invalidating some allocations.
458 winterface->sync(&pbi->lf_worker);
459 for (i = 0; i < pbi->num_workers; ++i) {
460 winterface->sync(&pbi->tile_workers[i]);
461 }
462
463 lock_buffer_pool(pool);
464 // Release all the reference buffers if worker thread is holding them.
465 if (pbi->hold_ref_buf == 1) {
466 int ref_index = 0, mask;
467 for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
468 const int old_idx = cm->ref_frame_map[ref_index];
469 // Current thread releases the holding of reference frame.
470 decrease_ref_count(old_idx, frame_bufs, pool);
471
472 // Release the reference frame holding in the reference map for the
473 // decoding of the next frame.
474 if (mask & 1) decrease_ref_count(old_idx, frame_bufs, pool);
475 ++ref_index;
476 }
477
478 // Current thread releases the holding of reference frame.
479 const int check_on_show_existing_frame =
480 !cm->show_existing_frame || cm->reset_decoder_state;
481 for (; ref_index < REF_FRAMES && check_on_show_existing_frame;
482 ++ref_index) {
483 const int old_idx = cm->ref_frame_map[ref_index];
484 decrease_ref_count(old_idx, frame_bufs, pool);
485 }
486 pbi->hold_ref_buf = 0;
487 }
488 // Release current frame.
489 decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
490 unlock_buffer_pool(pool);
491
492 aom_clear_system_state();
493 return -1;
494 }
495
496 cm->error.setjmp = 1;
497
498 int frame_decoded =
499 aom_decode_frame_from_obus(pbi, source, source + size, psource);
500
501 if (cm->error.error_code != AOM_CODEC_OK) {
502 lock_buffer_pool(pool);
503 decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
504 unlock_buffer_pool(pool);
505 cm->error.setjmp = 0;
506 return 1;
507 }
508
509 #if TXCOEFF_TIMER
510 cm->cum_txcoeff_timer += cm->txcoeff_timer;
511 fprintf(stderr,
512 "txb coeff block number: %d, frame time: %ld, cum time %ld in us\n",
513 cm->txb_count, cm->txcoeff_timer, cm->cum_txcoeff_timer);
514 cm->txcoeff_timer = 0;
515 cm->txb_count = 0;
516 #endif
517
518 // Note: At this point, this function holds a reference to cm->new_fb_idx
519 // in the buffer pool. This reference is consumed by swap_frame_buffers().
520 swap_frame_buffers(pbi, frame_decoded);
521
522 if (frame_decoded) {
523 pbi->decoding_first_frame = 0;
524 }
525
526 if (cm->error.error_code != AOM_CODEC_OK) {
527 cm->error.setjmp = 0;
528 return 1;
529 }
530
531 aom_clear_system_state();
532
533 if (!cm->show_existing_frame) {
534 cm->last_show_frame = cm->show_frame;
535
536 if (cm->seg.enabled) {
537 if (cm->prev_frame && (cm->mi_rows == cm->prev_frame->mi_rows) &&
538 (cm->mi_cols == cm->prev_frame->mi_cols)) {
539 cm->last_frame_seg_map = cm->prev_frame->seg_map;
540 } else {
541 cm->last_frame_seg_map = NULL;
542 }
543 }
544 }
545
546 // Update progress in frame parallel decode.
547 cm->last_width = cm->width;
548 cm->last_height = cm->height;
549 cm->last_tile_cols = cm->tile_cols;
550 cm->last_tile_rows = cm->tile_rows;
551 cm->error.setjmp = 0;
552
553 return 0;
554 }
555
556 // Get the frame at a particular index in the output queue
av1_get_raw_frame(AV1Decoder * pbi,size_t index,YV12_BUFFER_CONFIG ** sd,aom_film_grain_t ** grain_params)557 int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd,
558 aom_film_grain_t **grain_params) {
559 RefCntBuffer *const frame_bufs = pbi->common.buffer_pool->frame_bufs;
560
561 if (index >= pbi->num_output_frames) return -1;
562 *sd = pbi->output_frames[index];
563 *grain_params = &frame_bufs[pbi->output_frame_index[index]].film_grain_params;
564 aom_clear_system_state();
565 return 0;
566 }
567
568 // Get the highest-spatial-layer output
569 // TODO(david.barker): What should this do?
av1_get_frame_to_show(AV1Decoder * pbi,YV12_BUFFER_CONFIG * frame)570 int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) {
571 if (pbi->num_output_frames == 0) return -1;
572
573 *frame = *pbi->output_frames[pbi->num_output_frames - 1];
574 return 0;
575 }
576