Coverage Report

Created: 2026-03-08 06:51

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