Coverage Report

Created: 2026-02-14 07:00

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
10.6k
static void initialize_dec(void) {
39
10.6k
  av1_rtcd();
40
10.6k
  aom_dsp_rtcd();
41
10.6k
  aom_scale_rtcd();
42
10.6k
  av1_init_intra_predictors();
43
10.6k
  av1_init_wedge_masks();
44
10.6k
}
45
46
static void dec_set_mb_mi(CommonModeInfoParams *mi_params, int width,
47
66.1k
                          int height, BLOCK_SIZE min_partition_size) {
48
66.1k
  (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
66.1k
  const int aligned_width = ALIGN_POWER_OF_TWO(width, 3);
55
66.1k
  const int aligned_height = ALIGN_POWER_OF_TWO(height, 3);
56
57
66.1k
  mi_params->mi_cols = aligned_width >> MI_SIZE_LOG2;
58
66.1k
  mi_params->mi_rows = aligned_height >> MI_SIZE_LOG2;
59
66.1k
  mi_params->mi_stride = calc_mi_size(mi_params->mi_cols);
60
61
66.1k
  mi_params->mb_cols = ROUND_POWER_OF_TWO(mi_params->mi_cols, 2);
62
66.1k
  mi_params->mb_rows = ROUND_POWER_OF_TWO(mi_params->mi_rows, 2);
63
66.1k
  mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols;
64
65
66.1k
  mi_params->mi_alloc_bsize = BLOCK_4X4;
66
66.1k
  mi_params->mi_alloc_stride = mi_params->mi_stride;
67
68
66.1k
  assert(mi_size_wide[mi_params->mi_alloc_bsize] ==
69
66.1k
         mi_size_high[mi_params->mi_alloc_bsize]);
70
66.1k
}
71
72
202k
static void dec_setup_mi(CommonModeInfoParams *mi_params) {
73
202k
  const int mi_grid_size =
74
202k
      mi_params->mi_stride * calc_mi_size(mi_params->mi_rows);
75
202k
  memset(mi_params->mi_grid_base, 0,
76
202k
         mi_grid_size * sizeof(*mi_params->mi_grid_base));
77
202k
}
78
79
34.0k
static void dec_free_mi(CommonModeInfoParams *mi_params) {
80
34.0k
  aom_free(mi_params->mi_alloc);
81
34.0k
  mi_params->mi_alloc = NULL;
82
34.0k
  mi_params->mi_alloc_size = 0;
83
34.0k
  aom_free(mi_params->mi_grid_base);
84
34.0k
  mi_params->mi_grid_base = NULL;
85
34.0k
  mi_params->mi_grid_size = 0;
86
34.0k
  aom_free(mi_params->tx_type_map);
87
34.0k
  mi_params->tx_type_map = NULL;
88
34.0k
}
89
90
10.6k
AV1Decoder *av1_decoder_create(BufferPool *const pool) {
91
10.6k
  AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi));
92
10.6k
  if (!pbi) return NULL;
93
10.6k
  av1_zero(*pbi);
94
95
10.6k
  AV1_COMMON *volatile const cm = &pbi->common;
96
10.6k
  cm->seq_params = &pbi->seq_params;
97
10.6k
  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
10.6k
  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
10.6k
  pbi->error.setjmp = 1;
109
110
10.6k
  CHECK_MEM_ERROR(cm, cm->fc,
111
10.6k
                  (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc)));
112
10.6k
  CHECK_MEM_ERROR(
113
10.6k
      cm, cm->default_frame_context,
114
10.6k
      (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context)));
115
10.6k
  memset(cm->fc, 0, sizeof(*cm->fc));
116
10.6k
  memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context));
117
118
10.6k
  pbi->need_resync = 1;
119
10.6k
  initialize_dec();
120
121
  // Initialize the references to not point to any frame buffers.
122
95.6k
  for (int i = 0; i < REF_FRAMES; i++) {
123
85.0k
    cm->ref_frame_map[i] = NULL;
124
85.0k
  }
125
126
10.6k
  cm->current_frame.frame_number = 0;
127
10.6k
  pbi->decoding_first_frame = 1;
128
10.6k
  pbi->common.buffer_pool = pool;
129
130
10.6k
  cm->seq_params->bit_depth = AOM_BITS_8;
131
132
10.6k
  cm->mi_params.free_mi = dec_free_mi;
133
10.6k
  cm->mi_params.setup_mi = dec_setup_mi;
134
10.6k
  cm->mi_params.set_mb_mi = dec_set_mb_mi;
135
136
10.6k
  av1_loop_filter_init(cm);
137
138
10.6k
  av1_qm_init(&cm->quant_params, av1_num_planes(cm));
139
10.6k
  av1_loop_restoration_precal();
140
141
#if CONFIG_ACCOUNTING
142
  pbi->acct_enabled = 1;
143
  aom_accounting_init(&pbi->accounting);
144
#endif
145
146
10.6k
  pbi->error.setjmp = 0;
147
148
10.6k
  aom_get_worker_interface()->init(&pbi->lf_worker);
149
10.6k
  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
10.6k
  return pbi;
157
10.6k
}
158
159
5.87k
void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) {
160
5.87k
  if (tile_mt_info != NULL) {
161
5.87k
#if CONFIG_MULTITHREAD
162
5.87k
    if (tile_mt_info->job_mutex != NULL) {
163
3.45k
      pthread_mutex_destroy(tile_mt_info->job_mutex);
164
3.45k
      aom_free(tile_mt_info->job_mutex);
165
3.45k
    }
166
5.87k
#endif
167
5.87k
    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
5.87k
    av1_zero(*tile_mt_info);
171
5.87k
  }
172
5.87k
}
173
174
13.6k
void av1_dec_free_cb_buf(AV1Decoder *pbi) {
175
13.6k
  aom_free(pbi->cb_buffer_base);
176
13.6k
  pbi->cb_buffer_base = NULL;
177
13.6k
  pbi->cb_buffer_alloc_size = 0;
178
13.6k
}
179
180
10.6k
void av1_decoder_remove(AV1Decoder *pbi) {
181
10.6k
  int i;
182
183
10.6k
  if (!pbi) return;
184
185
  // Free the tile list output buffer.
186
10.6k
  aom_free_frame_buffer(&pbi->tile_list_outbuf);
187
188
10.6k
  aom_get_worker_interface()->end(&pbi->lf_worker);
189
10.6k
  aom_free(pbi->lf_worker.data1);
190
191
10.6k
  if (pbi->thread_data) {
192
85.5k
    for (int worker_idx = 1; worker_idx < pbi->num_workers; worker_idx++) {
193
83.1k
      DecWorkerData *const thread_data = pbi->thread_data + worker_idx;
194
83.1k
      if (thread_data->td != NULL) {
195
83.1k
        av1_free_mc_tmp_buf(thread_data->td);
196
83.1k
        aom_free(thread_data->td);
197
83.1k
      }
198
83.1k
    }
199
2.42k
    aom_free(pbi->thread_data);
200
2.42k
  }
201
10.6k
  aom_free(pbi->dcb.xd.seg_mask);
202
203
96.1k
  for (i = 0; i < pbi->num_workers; ++i) {
204
85.5k
    AVxWorker *const worker = &pbi->tile_workers[i];
205
85.5k
    aom_get_worker_interface()->end(worker);
206
85.5k
  }
207
10.6k
#if CONFIG_MULTITHREAD
208
10.6k
  if (pbi->row_mt_mutex_ != NULL) {
209
2.30k
    pthread_mutex_destroy(pbi->row_mt_mutex_);
210
2.30k
    aom_free(pbi->row_mt_mutex_);
211
2.30k
  }
212
10.6k
  if (pbi->row_mt_cond_ != NULL) {
213
2.30k
    pthread_cond_destroy(pbi->row_mt_cond_);
214
2.30k
    aom_free(pbi->row_mt_cond_);
215
2.30k
  }
216
10.6k
#endif
217
32.3k
  for (i = 0; i < pbi->allocated_tiles; i++) {
218
21.6k
    TileDataDec *const tile_data = pbi->tile_data + i;
219
21.6k
    av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync);
220
21.6k
  }
221
10.6k
  aom_free(pbi->tile_data);
222
10.6k
  aom_free(pbi->tile_workers);
223
224
10.6k
  if (pbi->num_workers > 0) {
225
2.42k
    av1_loop_filter_dealloc(&pbi->lf_row_sync);
226
2.42k
    av1_loop_restoration_dealloc(&pbi->lr_row_sync);
227
2.42k
    av1_dealloc_dec_jobs(&pbi->tile_mt_info);
228
2.42k
  }
229
230
10.6k
  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
10.6k
  av1_free_mc_tmp_buf(&pbi->td);
238
10.6k
  aom_img_metadata_array_free(pbi->metadata);
239
10.6k
  av1_remove_common(&pbi->common);
240
10.6k
  aom_free(pbi);
241
10.6k
}
242
243
void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd,
244
33.1M
                       aom_reader *r, palette_visitor_fn_t visit) {
245
33.1M
  if (!is_inter_block(xd->mi[0])) {
246
65.4M
    for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common));
247
43.1M
         ++plane) {
248
43.1M
      if (plane == 0 || xd->is_chroma_ref) {
249
41.7M
        if (xd->mi[0]->palette_mode_info.palette_size[plane])
250
167k
          visit(xd, plane, r);
251
41.7M
      } else {
252
1.38M
        assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0);
253
1.38M
      }
254
43.1M
    }
255
22.3M
  }
256
33.1M
}
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
39
                                       const YV12_BUFFER_CONFIG *b) {
286
39
  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
39
}
293
294
aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx,
295
                                      int use_external_ref,
296
270
                                      YV12_BUFFER_CONFIG *sd) {
297
270
  const int num_planes = av1_num_planes(cm);
298
  // Ensure that aom_internal_error() calls longjmp().
299
270
  assert(cm->error->setjmp);
300
  // Get the destination reference buffer.
301
270
  YV12_BUFFER_CONFIG *ref_buf = get_ref_frame(cm, idx);
302
303
270
  if (ref_buf == NULL) {
304
231
    aom_internal_error(cm->error, AOM_CODEC_ERROR, "No reference frame");
305
231
  }
306
307
270
  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
270
  } else {
315
270
    if (!equal_dimensions_and_border(ref_buf, sd)) {
316
39
      aom_internal_error(cm->error, AOM_CODEC_ERROR,
317
39
                         "Incorrect buffer dimensions");
318
39
    }
319
    // Overwrite the reference frame buffer pointers.
320
    // Once we no longer need the external reference buffer, these pointers
321
    // are restored.
322
270
    ref_buf->store_buf_adr[0] = ref_buf->y_buffer;
323
270
    ref_buf->store_buf_adr[1] = ref_buf->u_buffer;
324
270
    ref_buf->store_buf_adr[2] = ref_buf->v_buffer;
325
270
    ref_buf->y_buffer = sd->y_buffer;
326
270
    ref_buf->u_buffer = sd->u_buffer;
327
270
    ref_buf->v_buffer = sd->v_buffer;
328
270
    ref_buf->use_external_reference_buffers = 1;
329
270
  }
330
331
270
  return AOM_CODEC_OK;
332
270
}
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
149k
static void release_current_frame(AV1Decoder *pbi) {
350
149k
  AV1_COMMON *const cm = &pbi->common;
351
149k
  BufferPool *const pool = cm->buffer_pool;
352
353
149k
  cm->cur_frame->buf.corrupted = 1;
354
149k
  lock_buffer_pool(pool);
355
149k
  decrease_ref_count(cm->cur_frame, pool);
356
149k
  unlock_buffer_pool(pool);
357
149k
  cm->cur_frame = NULL;
358
149k
}
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
92.6k
static void update_frame_buffers(AV1Decoder *pbi, int frame_decoded) {
366
92.6k
  int ref_index = 0, mask;
367
92.6k
  AV1_COMMON *const cm = &pbi->common;
368
92.6k
  BufferPool *const pool = cm->buffer_pool;
369
370
92.6k
  if (frame_decoded) {
371
92.1k
    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
92.1k
    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
550k
      for (mask = cm->current_frame.refresh_frame_flags; mask; mask >>= 1) {
380
467k
        if (mask & 1) {
381
322k
          decrease_ref_count(cm->ref_frame_map[ref_index], pool);
382
322k
          cm->ref_frame_map[ref_index] = cm->cur_frame;
383
322k
          ++cm->cur_frame->ref_count;
384
322k
        }
385
467k
        ++ref_index;
386
467k
      }
387
82.1k
    }
388
389
92.1k
    if (cm->show_existing_frame || cm->show_frame) {
390
70.4k
      if (pbi->output_all_layers) {
391
        // Append this frame to the output queue
392
22.7k
        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
22.7k
        } else {
399
22.7k
          pbi->output_frames[pbi->num_output_frames] = cm->cur_frame;
400
22.7k
          pbi->num_output_frames++;
401
22.7k
        }
402
47.6k
      } else {
403
        // Replace any existing output frame
404
47.6k
        assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1);
405
47.6k
        if (pbi->num_output_frames > 0) {
406
11.1k
          decrease_ref_count(pbi->output_frames[0], pool);
407
11.1k
        }
408
47.6k
        pbi->output_frames[0] = cm->cur_frame;
409
47.6k
        pbi->num_output_frames = 1;
410
47.6k
      }
411
70.4k
    } else {
412
21.7k
      decrease_ref_count(cm->cur_frame, pool);
413
21.7k
    }
414
415
92.1k
    unlock_buffer_pool(pool);
416
92.1k
  } else {
417
    // Nothing was decoded, so just drop this frame buffer
418
437
    lock_buffer_pool(pool);
419
437
    decrease_ref_count(cm->cur_frame, pool);
420
437
    unlock_buffer_pool(pool);
421
437
  }
422
92.6k
  cm->cur_frame = NULL;
423
424
92.6k
  if (!pbi->camera_frame_header_ready) {
425
    // Invalidate these references until the next frame starts.
426
660k
    for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) {
427
577k
      cm->remapped_ref_idx[ref_index] = INVALID_IDX;
428
577k
    }
429
82.5k
  }
430
92.6k
}
431
432
int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
433
242k
                                const uint8_t **psource) {
434
242k
  AV1_COMMON *volatile const cm = &pbi->common;
435
242k
  const uint8_t *source = *psource;
436
242k
  pbi->error.error_code = AOM_CODEC_OK;
437
242k
  pbi->error.has_detail = 0;
438
439
242k
  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
249
    RefCntBuffer *ref_buf = get_ref_frame_buf(cm, LAST_FRAME);
449
249
    if (ref_buf != NULL) ref_buf->buf.corrupted = 1;
450
249
  }
451
452
242k
  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
242k
  if (setjmp(pbi->error.jmp)) {
461
105k
    const AVxWorkerInterface *const winterface = aom_get_worker_interface();
462
105k
    int i;
463
464
105k
    pbi->error.setjmp = 0;
465
466
    // Synchronize all threads immediately as a subsequent decode call may
467
    // cause a resize invalidating some allocations.
468
105k
    winterface->sync(&pbi->lf_worker);
469
1.21M
    for (i = 0; i < pbi->num_workers; ++i) {
470
1.10M
      winterface->sync(&pbi->tile_workers[i]);
471
1.10M
    }
472
473
105k
    release_current_frame(pbi);
474
105k
    return -1;
475
105k
  }
476
477
136k
  pbi->error.setjmp = 1;
478
479
136k
  int frame_decoded =
480
136k
      aom_decode_frame_from_obus(pbi, source, source + size, psource);
481
482
136k
  if (frame_decoded < 0) {
483
44.0k
    assert(pbi->error.error_code != AOM_CODEC_OK);
484
44.0k
    release_current_frame(pbi);
485
44.0k
    pbi->error.setjmp = 0;
486
44.0k
    return 1;
487
44.0k
  }
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
92.6k
  update_frame_buffers(pbi, frame_decoded);
501
502
92.6k
  if (frame_decoded) {
503
92.1k
    pbi->decoding_first_frame = 0;
504
92.1k
  }
505
506
92.6k
  if (pbi->error.error_code != AOM_CODEC_OK) {
507
9
    pbi->error.setjmp = 0;
508
9
    return 1;
509
9
  }
510
511
92.6k
  if (!cm->show_existing_frame) {
512
92.3k
    if (cm->seg.enabled) {
513
17.7k
      if (cm->prev_frame &&
514
11.8k
          (cm->mi_params.mi_rows == cm->prev_frame->mi_rows) &&
515
10.8k
          (cm->mi_params.mi_cols == cm->prev_frame->mi_cols)) {
516
10.8k
        cm->last_frame_seg_map = cm->prev_frame->seg_map;
517
10.8k
      } else {
518
6.91k
        cm->last_frame_seg_map = NULL;
519
6.91k
      }
520
17.7k
    }
521
92.3k
  }
522
523
  // Update progress in frame parallel decode.
524
92.6k
  pbi->error.setjmp = 0;
525
526
92.6k
  return 0;
527
92.6k
}
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
233k
                      aom_film_grain_t **grain_params) {
532
233k
  if (index >= pbi->num_output_frames) return -1;
533
55.9k
  *sd = &pbi->output_frames[index]->buf;
534
55.9k
  *grain_params = &pbi->output_frames[index]->film_grain_params;
535
55.9k
  return 0;
536
233k
}
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
}