Coverage Report

Created: 2025-06-22 08:04

/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_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
28.2k
static void initialize_dec(void) {
39
28.2k
  av1_rtcd();
40
28.2k
  aom_dsp_rtcd();
41
28.2k
  aom_scale_rtcd();
42
28.2k
  av1_init_intra_predictors();
43
28.2k
  av1_init_wedge_masks();
44
28.2k
}
45
46
static void dec_set_mb_mi(CommonModeInfoParams *mi_params, int width,
47
35.8k
                          int height, BLOCK_SIZE min_partition_size) {
48
35.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
35.8k
  const int aligned_width = ALIGN_POWER_OF_TWO(width, 3);
55
35.8k
  const int aligned_height = ALIGN_POWER_OF_TWO(height, 3);
56
57
35.8k
  mi_params->mi_cols = aligned_width >> MI_SIZE_LOG2;
58
35.8k
  mi_params->mi_rows = aligned_height >> MI_SIZE_LOG2;
59
35.8k
  mi_params->mi_stride = calc_mi_size(mi_params->mi_cols);
60
61
35.8k
  mi_params->mb_cols = ROUND_POWER_OF_TWO(mi_params->mi_cols, 2);
62
35.8k
  mi_params->mb_rows = ROUND_POWER_OF_TWO(mi_params->mi_rows, 2);
63
35.8k
  mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols;
64
65
35.8k
  mi_params->mi_alloc_bsize = BLOCK_4X4;
66
35.8k
  mi_params->mi_alloc_stride = mi_params->mi_stride;
67
68
35.8k
  assert(mi_size_wide[mi_params->mi_alloc_bsize] ==
69
35.8k
         mi_size_high[mi_params->mi_alloc_bsize]);
70
35.8k
}
71
72
90.4k
static void dec_setup_mi(CommonModeInfoParams *mi_params) {
73
90.4k
  const int mi_grid_size =
74
90.4k
      mi_params->mi_stride * calc_mi_size(mi_params->mi_rows);
75
90.4k
  memset(mi_params->mi_grid_base, 0,
76
90.4k
         mi_grid_size * sizeof(*mi_params->mi_grid_base));
77
90.4k
}
78
79
85.1k
static void dec_free_mi(CommonModeInfoParams *mi_params) {
80
85.1k
  aom_free(mi_params->mi_alloc);
81
85.1k
  mi_params->mi_alloc = NULL;
82
85.1k
  mi_params->mi_alloc_size = 0;
83
85.1k
  aom_free(mi_params->mi_grid_base);
84
85.1k
  mi_params->mi_grid_base = NULL;
85
85.1k
  mi_params->mi_grid_size = 0;
86
85.1k
  aom_free(mi_params->tx_type_map);
87
85.1k
  mi_params->tx_type_map = NULL;
88
85.1k
}
89
90
28.2k
AV1Decoder *av1_decoder_create(BufferPool *const pool) {
91
28.2k
  AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi));
92
28.2k
  if (!pbi) return NULL;
93
28.2k
  av1_zero(*pbi);
94
95
28.2k
  AV1_COMMON *volatile const cm = &pbi->common;
96
28.2k
  cm->seq_params = &pbi->seq_params;
97
28.2k
  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
28.2k
  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
28.2k
  pbi->error.setjmp = 1;
109
110
28.2k
  CHECK_MEM_ERROR(cm, cm->fc,
111
28.2k
                  (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc)));
112
28.2k
  CHECK_MEM_ERROR(
113
28.2k
      cm, cm->default_frame_context,
114
28.2k
      (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context)));
115
28.2k
  memset(cm->fc, 0, sizeof(*cm->fc));
116
28.2k
  memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context));
117
118
28.2k
  pbi->need_resync = 1;
119
28.2k
  initialize_dec();
120
121
  // Initialize the references to not point to any frame buffers.
122
254k
  for (int i = 0; i < REF_FRAMES; i++) {
123
226k
    cm->ref_frame_map[i] = NULL;
124
226k
  }
125
126
28.2k
  cm->current_frame.frame_number = 0;
127
28.2k
  pbi->decoding_first_frame = 1;
128
28.2k
  pbi->common.buffer_pool = pool;
129
130
28.2k
  cm->seq_params->bit_depth = AOM_BITS_8;
131
132
28.2k
  cm->mi_params.free_mi = dec_free_mi;
133
28.2k
  cm->mi_params.setup_mi = dec_setup_mi;
134
28.2k
  cm->mi_params.set_mb_mi = dec_set_mb_mi;
135
136
28.2k
  av1_loop_filter_init(cm);
137
138
28.2k
  av1_qm_init(&cm->quant_params, av1_num_planes(cm));
139
28.2k
  av1_loop_restoration_precal();
140
141
#if CONFIG_ACCOUNTING
142
  pbi->acct_enabled = 1;
143
  aom_accounting_init(&pbi->accounting);
144
#endif
145
146
28.2k
  pbi->error.setjmp = 0;
147
148
28.2k
  aom_get_worker_interface()->init(&pbi->lf_worker);
149
28.2k
  pbi->lf_worker.thread_name = "aom lf worker";
150
151
28.2k
  return pbi;
152
28.2k
}
153
154
35.6k
void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) {
155
35.6k
  if (tile_mt_info != NULL) {
156
35.6k
#if CONFIG_MULTITHREAD
157
35.6k
    if (tile_mt_info->job_mutex != NULL) {
158
17.9k
      pthread_mutex_destroy(tile_mt_info->job_mutex);
159
17.9k
      aom_free(tile_mt_info->job_mutex);
160
17.9k
    }
161
35.6k
#endif
162
35.6k
    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
35.6k
    av1_zero(*tile_mt_info);
166
35.6k
  }
167
35.6k
}
168
169
47.4k
void av1_dec_free_cb_buf(AV1Decoder *pbi) {
170
47.4k
  aom_free(pbi->cb_buffer_base);
171
47.4k
  pbi->cb_buffer_base = NULL;
172
47.4k
  pbi->cb_buffer_alloc_size = 0;
173
47.4k
}
174
175
28.2k
void av1_decoder_remove(AV1Decoder *pbi) {
176
28.2k
  int i;
177
178
28.2k
  if (!pbi) return;
179
180
  // Free the tile list output buffer.
181
28.2k
  aom_free_frame_buffer(&pbi->tile_list_outbuf);
182
183
28.2k
  aom_get_worker_interface()->end(&pbi->lf_worker);
184
28.2k
  aom_free(pbi->lf_worker.data1);
185
186
28.2k
  if (pbi->thread_data) {
187
567k
    for (int worker_idx = 1; worker_idx < pbi->num_workers; worker_idx++) {
188
550k
      DecWorkerData *const thread_data = pbi->thread_data + worker_idx;
189
550k
      if (thread_data->td != NULL) {
190
550k
        av1_free_mc_tmp_buf(thread_data->td);
191
550k
        aom_free(thread_data->td);
192
550k
      }
193
550k
    }
194
17.7k
    aom_free(pbi->thread_data);
195
17.7k
  }
196
28.2k
  aom_free(pbi->dcb.xd.seg_mask);
197
198
596k
  for (i = 0; i < pbi->num_workers; ++i) {
199
567k
    AVxWorker *const worker = &pbi->tile_workers[i];
200
567k
    aom_get_worker_interface()->end(worker);
201
567k
  }
202
28.2k
#if CONFIG_MULTITHREAD
203
28.2k
  if (pbi->row_mt_mutex_ != NULL) {
204
17.6k
    pthread_mutex_destroy(pbi->row_mt_mutex_);
205
17.6k
    aom_free(pbi->row_mt_mutex_);
206
17.6k
  }
207
28.2k
  if (pbi->row_mt_cond_ != NULL) {
208
17.6k
    pthread_cond_destroy(pbi->row_mt_cond_);
209
17.6k
    aom_free(pbi->row_mt_cond_);
210
17.6k
  }
211
28.2k
#endif
212
58.6k
  for (i = 0; i < pbi->allocated_tiles; i++) {
213
30.3k
    TileDataDec *const tile_data = pbi->tile_data + i;
214
30.3k
    av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync);
215
30.3k
  }
216
28.2k
  aom_free(pbi->tile_data);
217
28.2k
  aom_free(pbi->tile_workers);
218
219
28.2k
  if (pbi->num_workers > 0) {
220
17.7k
    av1_loop_filter_dealloc(&pbi->lf_row_sync);
221
17.7k
    av1_loop_restoration_dealloc(&pbi->lr_row_sync);
222
17.7k
    av1_dealloc_dec_jobs(&pbi->tile_mt_info);
223
17.7k
  }
224
225
28.2k
  av1_dec_free_cb_buf(pbi);
226
#if CONFIG_ACCOUNTING
227
  aom_accounting_clear(&pbi->accounting);
228
#endif
229
28.2k
  av1_free_mc_tmp_buf(&pbi->td);
230
28.2k
  aom_img_metadata_array_free(pbi->metadata);
231
28.2k
  av1_remove_common(&pbi->common);
232
28.2k
  aom_free(pbi);
233
28.2k
}
234
235
void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd,
236
16.7M
                       aom_reader *r, palette_visitor_fn_t visit) {
237
16.7M
  if (!is_inter_block(xd->mi[0])) {
238
47.6M
    for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common));
239
31.6M
         ++plane) {
240
31.6M
      if (plane == 0 || xd->is_chroma_ref) {
241
30.8M
        if (xd->mi[0]->palette_mode_info.palette_size[plane])
242
2.95M
          visit(xd, plane, r);
243
30.8M
      } else {
244
774k
        assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0);
245
774k
      }
246
31.6M
    }
247
16.0M
  }
248
16.7M
}
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
24.1k
static void release_current_frame(AV1Decoder *pbi) {
343
24.1k
  AV1_COMMON *const cm = &pbi->common;
344
24.1k
  BufferPool *const pool = cm->buffer_pool;
345
346
24.1k
  cm->cur_frame->buf.corrupted = 1;
347
24.1k
  lock_buffer_pool(pool);
348
24.1k
  decrease_ref_count(cm->cur_frame, pool);
349
24.1k
  unlock_buffer_pool(pool);
350
24.1k
  cm->cur_frame = NULL;
351
24.1k
}
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
34.2k
static void update_frame_buffers(AV1Decoder *pbi, int frame_decoded) {
359
34.2k
  int ref_index = 0, mask;
360
34.2k
  AV1_COMMON *const cm = &pbi->common;
361
34.2k
  BufferPool *const pool = cm->buffer_pool;
362
363
34.2k
  if (frame_decoded) {
364
34.1k
    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
34.1k
    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
281k
      for (mask = cm->current_frame.refresh_frame_flags; mask; mask >>= 1) {
373
247k
        if (mask & 1) {
374
185k
          decrease_ref_count(cm->ref_frame_map[ref_index], pool);
375
185k
          cm->ref_frame_map[ref_index] = cm->cur_frame;
376
185k
          ++cm->cur_frame->ref_count;
377
185k
        }
378
247k
        ++ref_index;
379
247k
      }
380
34.1k
    }
381
382
34.1k
    if (cm->show_existing_frame || cm->show_frame) {
383
23.0k
      if (pbi->output_all_layers) {
384
        // Append this frame to the output queue
385
200
        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
3
          cm->cur_frame->buf.corrupted = 1;
389
3
          decrease_ref_count(cm->cur_frame, pool);
390
3
          pbi->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
391
197
        } else {
392
197
          pbi->output_frames[pbi->num_output_frames] = cm->cur_frame;
393
197
          pbi->num_output_frames++;
394
197
        }
395
22.8k
      } else {
396
        // Replace any existing output frame
397
22.8k
        assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1);
398
22.8k
        if (pbi->num_output_frames > 0) {
399
14.7k
          decrease_ref_count(pbi->output_frames[0], pool);
400
14.7k
        }
401
22.8k
        pbi->output_frames[0] = cm->cur_frame;
402
22.8k
        pbi->num_output_frames = 1;
403
22.8k
      }
404
23.0k
    } else {
405
11.1k
      decrease_ref_count(cm->cur_frame, pool);
406
11.1k
    }
407
408
34.1k
    unlock_buffer_pool(pool);
409
34.1k
  } else {
410
    // Nothing was decoded, so just drop this frame buffer
411
153
    lock_buffer_pool(pool);
412
153
    decrease_ref_count(cm->cur_frame, pool);
413
153
    unlock_buffer_pool(pool);
414
153
  }
415
34.2k
  cm->cur_frame = NULL;
416
417
34.2k
  if (!pbi->camera_frame_header_ready) {
418
    // Invalidate these references until the next frame starts.
419
274k
    for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) {
420
240k
      cm->remapped_ref_idx[ref_index] = INVALID_IDX;
421
240k
    }
422
34.2k
  }
423
34.2k
}
424
425
int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
426
58.4k
                                const uint8_t **psource) {
427
58.4k
  AV1_COMMON *volatile const cm = &pbi->common;
428
58.4k
  const uint8_t *source = *psource;
429
58.4k
  pbi->error.error_code = AOM_CODEC_OK;
430
58.4k
  pbi->error.has_detail = 0;
431
432
58.4k
  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
58.4k
  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
58.4k
  if (setjmp(pbi->error.jmp)) {
454
21.2k
    const AVxWorkerInterface *const winterface = aom_get_worker_interface();
455
21.2k
    int i;
456
457
21.2k
    pbi->error.setjmp = 0;
458
459
    // Synchronize all threads immediately as a subsequent decode call may
460
    // cause a resize invalidating some allocations.
461
21.2k
    winterface->sync(&pbi->lf_worker);
462
429k
    for (i = 0; i < pbi->num_workers; ++i) {
463
408k
      winterface->sync(&pbi->tile_workers[i]);
464
408k
    }
465
466
21.2k
    release_current_frame(pbi);
467
21.2k
    return -1;
468
21.2k
  }
469
470
37.1k
  pbi->error.setjmp = 1;
471
472
37.1k
  int frame_decoded =
473
37.1k
      aom_decode_frame_from_obus(pbi, source, source + size, psource);
474
475
37.1k
  if (frame_decoded < 0) {
476
2.90k
    assert(pbi->error.error_code != AOM_CODEC_OK);
477
2.90k
    release_current_frame(pbi);
478
2.90k
    pbi->error.setjmp = 0;
479
2.90k
    return 1;
480
2.90k
  }
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
34.2k
  update_frame_buffers(pbi, frame_decoded);
494
495
34.2k
  if (frame_decoded) {
496
34.1k
    pbi->decoding_first_frame = 0;
497
34.1k
  }
498
499
34.2k
  if (pbi->error.error_code != AOM_CODEC_OK) {
500
3
    pbi->error.setjmp = 0;
501
3
    return 1;
502
3
  }
503
504
34.2k
  if (!cm->show_existing_frame) {
505
33.9k
    if (cm->seg.enabled) {
506
10.9k
      if (cm->prev_frame &&
507
10.9k
          (cm->mi_params.mi_rows == cm->prev_frame->mi_rows) &&
508
10.9k
          (cm->mi_params.mi_cols == cm->prev_frame->mi_cols)) {
509
5.46k
        cm->last_frame_seg_map = cm->prev_frame->seg_map;
510
5.49k
      } else {
511
5.49k
        cm->last_frame_seg_map = NULL;
512
5.49k
      }
513
10.9k
    }
514
33.9k
  }
515
516
  // Update progress in frame parallel decode.
517
34.2k
  pbi->error.setjmp = 0;
518
519
34.2k
  return 0;
520
34.2k
}
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
3.49k
                      aom_film_grain_t **grain_params) {
525
3.49k
  if (index >= pbi->num_output_frames) return -1;
526
3.39k
  *sd = &pbi->output_frames[index]->buf;
527
3.39k
  *grain_params = &pbi->output_frames[index]->film_grain_params;
528
3.39k
  return 0;
529
3.49k
}
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
}