Coverage Report

Created: 2025-06-13 07:07

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