Coverage Report

Created: 2025-07-09 07:14

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