Coverage Report

Created: 2026-11-12 08:20

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