Coverage Report

Created: 2026-03-31 06:59

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
9.66k
static void initialize_dec(void) {
39
9.66k
  av1_rtcd();
40
9.66k
  aom_dsp_rtcd();
41
9.66k
  aom_scale_rtcd();
42
9.66k
  av1_init_intra_predictors();
43
9.66k
  av1_init_wedge_masks();
44
9.66k
}
45
46
static void dec_set_mb_mi(CommonModeInfoParams *mi_params, int width,
47
61.8k
                          int height, BLOCK_SIZE min_partition_size) {
48
61.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
61.8k
  const int aligned_width = ALIGN_POWER_OF_TWO(width, 3);
55
61.8k
  const int aligned_height = ALIGN_POWER_OF_TWO(height, 3);
56
57
61.8k
  mi_params->mi_cols = aligned_width >> MI_SIZE_LOG2;
58
61.8k
  mi_params->mi_rows = aligned_height >> MI_SIZE_LOG2;
59
61.8k
  mi_params->mi_stride = calc_mi_size(mi_params->mi_cols);
60
61
61.8k
  mi_params->mb_cols = ROUND_POWER_OF_TWO(mi_params->mi_cols, 2);
62
61.8k
  mi_params->mb_rows = ROUND_POWER_OF_TWO(mi_params->mi_rows, 2);
63
61.8k
  mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols;
64
65
61.8k
  mi_params->mi_alloc_bsize = BLOCK_4X4;
66
61.8k
  mi_params->mi_alloc_stride = mi_params->mi_stride;
67
68
61.8k
  assert(mi_size_wide[mi_params->mi_alloc_bsize] ==
69
61.8k
         mi_size_high[mi_params->mi_alloc_bsize]);
70
61.8k
}
71
72
186k
static void dec_setup_mi(CommonModeInfoParams *mi_params) {
73
186k
  const int mi_grid_size =
74
186k
      mi_params->mi_stride * calc_mi_size(mi_params->mi_rows);
75
186k
  memset(mi_params->mi_grid_base, 0,
76
186k
         mi_grid_size * sizeof(*mi_params->mi_grid_base));
77
186k
}
78
79
31.0k
static void dec_free_mi(CommonModeInfoParams *mi_params) {
80
31.0k
  aom_free(mi_params->mi_alloc);
81
31.0k
  mi_params->mi_alloc = NULL;
82
31.0k
  mi_params->mi_alloc_size = 0;
83
31.0k
  aom_free(mi_params->mi_grid_base);
84
31.0k
  mi_params->mi_grid_base = NULL;
85
31.0k
  mi_params->mi_grid_size = 0;
86
31.0k
  aom_free(mi_params->tx_type_map);
87
31.0k
  mi_params->tx_type_map = NULL;
88
31.0k
}
89
90
9.66k
AV1Decoder *av1_decoder_create(BufferPool *const pool) {
91
9.66k
  AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi));
92
9.66k
  if (!pbi) return NULL;
93
9.66k
  av1_zero(*pbi);
94
95
9.66k
  AV1_COMMON *volatile const cm = &pbi->common;
96
9.66k
  cm->seq_params = &pbi->seq_params;
97
9.66k
  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
9.66k
  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
9.66k
  pbi->error.setjmp = 1;
109
110
9.66k
  CHECK_MEM_ERROR(cm, cm->fc,
111
9.66k
                  (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc)));
112
9.66k
  CHECK_MEM_ERROR(
113
9.66k
      cm, cm->default_frame_context,
114
9.66k
      (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context)));
115
9.66k
  memset(cm->fc, 0, sizeof(*cm->fc));
116
9.66k
  memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context));
117
118
9.66k
  pbi->need_resync = 1;
119
9.66k
  initialize_dec();
120
121
  // Initialize the references to not point to any frame buffers.
122
86.9k
  for (int i = 0; i < REF_FRAMES; i++) {
123
77.3k
    cm->ref_frame_map[i] = NULL;
124
77.3k
  }
125
126
9.66k
  cm->current_frame.frame_number = 0;
127
9.66k
  pbi->decoding_first_frame = 1;
128
9.66k
  pbi->common.buffer_pool = pool;
129
130
9.66k
  cm->seq_params->bit_depth = AOM_BITS_8;
131
132
9.66k
  cm->mi_params.free_mi = dec_free_mi;
133
9.66k
  cm->mi_params.setup_mi = dec_setup_mi;
134
9.66k
  cm->mi_params.set_mb_mi = dec_set_mb_mi;
135
136
9.66k
  av1_loop_filter_init(cm);
137
138
9.66k
  av1_qm_init(&cm->quant_params, av1_num_planes(cm));
139
9.66k
  av1_loop_restoration_precal();
140
141
#if CONFIG_ACCOUNTING
142
  pbi->acct_enabled = 1;
143
  aom_accounting_init(&pbi->accounting);
144
#endif
145
146
9.66k
  pbi->error.setjmp = 0;
147
148
9.66k
  aom_get_worker_interface()->init(&pbi->lf_worker);
149
9.66k
  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
9.66k
  return pbi;
157
9.66k
}
158
159
5.46k
void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) {
160
5.46k
  if (tile_mt_info != NULL) {
161
5.46k
#if CONFIG_MULTITHREAD
162
5.46k
    if (tile_mt_info->job_mutex != NULL) {
163
3.23k
      pthread_mutex_destroy(tile_mt_info->job_mutex);
164
3.23k
      aom_free(tile_mt_info->job_mutex);
165
3.23k
    }
166
5.46k
#endif
167
5.46k
    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.46k
    av1_zero(*tile_mt_info);
171
5.46k
  }
172
5.46k
}
173
174
12.4k
void av1_dec_free_cb_buf(AV1Decoder *pbi) {
175
12.4k
  aom_free(pbi->cb_buffer_base);
176
12.4k
  pbi->cb_buffer_base = NULL;
177
12.4k
  pbi->cb_buffer_alloc_size = 0;
178
12.4k
}
179
180
9.66k
void av1_decoder_remove(AV1Decoder *pbi) {
181
9.66k
  int i;
182
183
9.66k
  if (!pbi) return;
184
185
  // Free the tile list output buffer.
186
9.66k
  aom_free_frame_buffer(&pbi->tile_list_outbuf);
187
188
9.66k
  aom_get_worker_interface()->end(&pbi->lf_worker);
189
9.66k
  aom_free(pbi->lf_worker.data1);
190
191
9.66k
  if (pbi->thread_data) {
192
78.1k
    for (int worker_idx = 1; worker_idx < pbi->num_workers; worker_idx++) {
193
75.8k
      DecWorkerData *const thread_data = pbi->thread_data + worker_idx;
194
75.8k
      if (thread_data->td != NULL) {
195
75.8k
        av1_free_mc_tmp_buf(thread_data->td);
196
75.8k
        aom_free(thread_data->td);
197
75.8k
      }
198
75.8k
    }
199
2.22k
    aom_free(pbi->thread_data);
200
2.22k
  }
201
9.66k
  aom_free(pbi->dcb.xd.seg_mask);
202
203
87.7k
  for (i = 0; i < pbi->num_workers; ++i) {
204
78.1k
    AVxWorker *const worker = &pbi->tile_workers[i];
205
78.1k
    aom_get_worker_interface()->end(worker);
206
78.1k
  }
207
9.66k
#if CONFIG_MULTITHREAD
208
9.66k
  if (pbi->row_mt_mutex_ != NULL) {
209
2.11k
    pthread_mutex_destroy(pbi->row_mt_mutex_);
210
2.11k
    aom_free(pbi->row_mt_mutex_);
211
2.11k
  }
212
9.66k
  if (pbi->row_mt_cond_ != NULL) {
213
2.11k
    pthread_cond_destroy(pbi->row_mt_cond_);
214
2.11k
    aom_free(pbi->row_mt_cond_);
215
2.11k
  }
216
9.66k
#endif
217
32.1k
  for (i = 0; i < pbi->allocated_tiles; i++) {
218
22.5k
    TileDataDec *const tile_data = pbi->tile_data + i;
219
22.5k
    av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync);
220
22.5k
  }
221
9.66k
  aom_free(pbi->tile_data);
222
9.66k
  aom_free(pbi->tile_workers);
223
224
9.66k
  if (pbi->num_workers > 0) {
225
2.22k
    av1_loop_filter_dealloc(&pbi->lf_row_sync);
226
2.22k
    av1_loop_restoration_dealloc(&pbi->lr_row_sync);
227
2.22k
    av1_dealloc_dec_jobs(&pbi->tile_mt_info);
228
2.22k
  }
229
230
9.66k
  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
9.66k
  av1_free_mc_tmp_buf(&pbi->td);
238
9.66k
  aom_img_metadata_array_free(pbi->metadata);
239
9.66k
  av1_remove_common(&pbi->common);
240
9.66k
  aom_free(pbi);
241
9.66k
}
242
243
void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd,
244
29.3M
                       aom_reader *r, palette_visitor_fn_t visit) {
245
29.3M
  if (!is_inter_block(xd->mi[0])) {
246
59.2M
    for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common));
247
39.0M
         ++plane) {
248
39.0M
      if (plane == 0 || xd->is_chroma_ref) {
249
37.7M
        if (xd->mi[0]->palette_mode_info.palette_size[plane])
250
209k
          visit(xd, plane, r);
251
37.7M
      } else {
252
1.24M
        assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0);
253
1.24M
      }
254
39.0M
    }
255
20.1M
  }
256
29.3M
}
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
38
                                       const YV12_BUFFER_CONFIG *b) {
286
38
  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
38
}
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
232
    aom_internal_error(cm->error, AOM_CODEC_ERROR, "No reference frame");
305
232
  }
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
38
      aom_internal_error(cm->error, AOM_CODEC_ERROR,
317
38
                         "Incorrect buffer dimensions");
318
38
    }
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
150k
static void release_current_frame(AV1Decoder *pbi) {
350
150k
  AV1_COMMON *const cm = &pbi->common;
351
150k
  BufferPool *const pool = cm->buffer_pool;
352
353
150k
  cm->cur_frame->buf.corrupted = 1;
354
150k
  lock_buffer_pool(pool);
355
150k
  decrease_ref_count(cm->cur_frame, pool);
356
150k
  unlock_buffer_pool(pool);
357
150k
  cm->cur_frame = NULL;
358
150k
}
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
79.4k
static void update_frame_buffers(AV1Decoder *pbi, int frame_decoded) {
366
79.4k
  int ref_index = 0, mask;
367
79.4k
  AV1_COMMON *const cm = &pbi->common;
368
79.4k
  BufferPool *const pool = cm->buffer_pool;
369
370
79.4k
  if (frame_decoded) {
371
79.0k
    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
79.0k
    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
469k
      for (mask = cm->current_frame.refresh_frame_flags; mask; mask >>= 1) {
380
399k
        if (mask & 1) {
381
278k
          decrease_ref_count(cm->ref_frame_map[ref_index], pool);
382
278k
          cm->ref_frame_map[ref_index] = cm->cur_frame;
383
278k
          ++cm->cur_frame->ref_count;
384
278k
        }
385
399k
        ++ref_index;
386
399k
      }
387
69.8k
    }
388
389
79.0k
    if (cm->show_existing_frame || cm->show_frame) {
390
60.2k
      if (pbi->output_all_layers) {
391
        // Append this frame to the output queue
392
18.3k
        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
7
          cm->cur_frame->buf.corrupted = 1;
396
7
          decrease_ref_count(cm->cur_frame, pool);
397
7
          pbi->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
398
18.3k
        } else {
399
18.3k
          pbi->output_frames[pbi->num_output_frames] = cm->cur_frame;
400
18.3k
          pbi->num_output_frames++;
401
18.3k
        }
402
41.8k
      } else {
403
        // Replace any existing output frame
404
41.8k
        assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1);
405
41.8k
        if (pbi->num_output_frames > 0) {
406
9.71k
          decrease_ref_count(pbi->output_frames[0], pool);
407
9.71k
        }
408
41.8k
        pbi->output_frames[0] = cm->cur_frame;
409
41.8k
        pbi->num_output_frames = 1;
410
41.8k
      }
411
60.2k
    } else {
412
18.7k
      decrease_ref_count(cm->cur_frame, pool);
413
18.7k
    }
414
415
79.0k
    unlock_buffer_pool(pool);
416
79.0k
  } else {
417
    // Nothing was decoded, so just drop this frame buffer
418
408
    lock_buffer_pool(pool);
419
408
    decrease_ref_count(cm->cur_frame, pool);
420
408
    unlock_buffer_pool(pool);
421
408
  }
422
79.4k
  cm->cur_frame = NULL;
423
424
79.4k
  if (!pbi->camera_frame_header_ready) {
425
    // Invalidate these references until the next frame starts.
426
561k
    for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) {
427
491k
      cm->remapped_ref_idx[ref_index] = INVALID_IDX;
428
491k
    }
429
70.1k
  }
430
79.4k
}
431
432
int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
433
229k
                                const uint8_t **psource) {
434
229k
  AV1_COMMON *volatile const cm = &pbi->common;
435
229k
  const uint8_t *source = *psource;
436
229k
  pbi->error.error_code = AOM_CODEC_OK;
437
229k
  pbi->error.has_detail = 0;
438
439
229k
  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
223
    RefCntBuffer *ref_buf = get_ref_frame_buf(cm, LAST_FRAME);
449
223
    if (ref_buf != NULL) ref_buf->buf.corrupted = 1;
450
223
  }
451
452
229k
  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
229k
  if (setjmp(pbi->error.jmp)) {
461
110k
    const AVxWorkerInterface *const winterface = aom_get_worker_interface();
462
110k
    int i;
463
464
110k
    pbi->error.setjmp = 0;
465
466
    // Synchronize all threads immediately as a subsequent decode call may
467
    // cause a resize invalidating some allocations.
468
110k
    winterface->sync(&pbi->lf_worker);
469
1.26M
    for (i = 0; i < pbi->num_workers; ++i) {
470
1.15M
      winterface->sync(&pbi->tile_workers[i]);
471
1.15M
    }
472
473
110k
    release_current_frame(pbi);
474
110k
    return -1;
475
110k
  }
476
477
119k
  pbi->error.setjmp = 1;
478
479
119k
  int frame_decoded =
480
119k
      aom_decode_frame_from_obus(pbi, source, source + size, psource);
481
482
119k
  if (frame_decoded < 0) {
483
39.6k
    assert(pbi->error.error_code != AOM_CODEC_OK);
484
39.6k
    release_current_frame(pbi);
485
39.6k
    pbi->error.setjmp = 0;
486
39.6k
    return 1;
487
39.6k
  }
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
79.4k
  update_frame_buffers(pbi, frame_decoded);
501
502
79.4k
  if (frame_decoded) {
503
79.0k
    pbi->decoding_first_frame = 0;
504
79.0k
  }
505
506
79.4k
  if (pbi->error.error_code != AOM_CODEC_OK) {
507
7
    pbi->error.setjmp = 0;
508
7
    return 1;
509
7
  }
510
511
79.4k
  if (!cm->show_existing_frame) {
512
79.2k
    if (cm->seg.enabled) {
513
15.5k
      if (cm->prev_frame &&
514
8.83k
          (cm->mi_params.mi_rows == cm->prev_frame->mi_rows) &&
515
8.01k
          (cm->mi_params.mi_cols == cm->prev_frame->mi_cols)) {
516
7.79k
        cm->last_frame_seg_map = cm->prev_frame->seg_map;
517
7.79k
      } else {
518
7.77k
        cm->last_frame_seg_map = NULL;
519
7.77k
      }
520
15.5k
    }
521
79.2k
  }
522
523
  // Update progress in frame parallel decode.
524
79.4k
  pbi->error.setjmp = 0;
525
526
79.4k
  return 0;
527
79.4k
}
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
132k
                      aom_film_grain_t **grain_params) {
532
132k
  if (index >= pbi->num_output_frames) return -1;
533
47.4k
  *sd = &pbi->output_frames[index]->buf;
534
47.4k
  *grain_params = &pbi->output_frames[index]->film_grain_params;
535
47.4k
  return 0;
536
132k
}
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
}