Coverage Report

Created: 2024-06-18 06:48

/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_scale/aom_scale.h"
24
#include "aom_util/aom_pthread.h"
25
#include "aom_util/aom_thread.h"
26
27
#include "av1/common/alloccommon.h"
28
#include "av1/common/av1_common_int.h"
29
#include "av1/common/av1_loopfilter.h"
30
#include "av1/common/quant_common.h"
31
#include "av1/common/reconinter.h"
32
#include "av1/common/reconintra.h"
33
34
#include "av1/decoder/decodeframe.h"
35
#include "av1/decoder/decoder.h"
36
#include "av1/decoder/detokenize.h"
37
#include "av1/decoder/obu.h"
38
39
16.8k
static void initialize_dec(void) {
40
16.8k
  av1_rtcd();
41
16.8k
  aom_dsp_rtcd();
42
16.8k
  aom_scale_rtcd();
43
16.8k
  av1_init_intra_predictors();
44
16.8k
  av1_init_wedge_masks();
45
16.8k
}
46
47
static void dec_set_mb_mi(CommonModeInfoParams *mi_params, int width,
48
67.2k
                          int height, BLOCK_SIZE min_partition_size) {
49
67.2k
  (void)min_partition_size;
50
  // Ensure that the decoded width and height are both multiples of
51
  // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if
52
  // subsampling is used).
53
  // This simplifies the implementation of various experiments,
54
  // eg. cdef, which operates on units of 8x8 luma pixels.
55
67.2k
  const int aligned_width = ALIGN_POWER_OF_TWO(width, 3);
56
67.2k
  const int aligned_height = ALIGN_POWER_OF_TWO(height, 3);
57
58
67.2k
  mi_params->mi_cols = aligned_width >> MI_SIZE_LOG2;
59
67.2k
  mi_params->mi_rows = aligned_height >> MI_SIZE_LOG2;
60
67.2k
  mi_params->mi_stride = calc_mi_size(mi_params->mi_cols);
61
62
67.2k
  mi_params->mb_cols = ROUND_POWER_OF_TWO(mi_params->mi_cols, 2);
63
67.2k
  mi_params->mb_rows = ROUND_POWER_OF_TWO(mi_params->mi_rows, 2);
64
67.2k
  mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols;
65
66
67.2k
  mi_params->mi_alloc_bsize = BLOCK_4X4;
67
67.2k
  mi_params->mi_alloc_stride = mi_params->mi_stride;
68
69
67.2k
  assert(mi_size_wide[mi_params->mi_alloc_bsize] ==
70
67.2k
         mi_size_high[mi_params->mi_alloc_bsize]);
71
67.2k
}
72
73
267k
static void dec_setup_mi(CommonModeInfoParams *mi_params) {
74
267k
  const int mi_grid_size =
75
267k
      mi_params->mi_stride * calc_mi_size(mi_params->mi_rows);
76
267k
  memset(mi_params->mi_grid_base, 0,
77
267k
         mi_grid_size * sizeof(*mi_params->mi_grid_base));
78
267k
}
79
80
53.4k
static void dec_free_mi(CommonModeInfoParams *mi_params) {
81
53.4k
  aom_free(mi_params->mi_alloc);
82
53.4k
  mi_params->mi_alloc = NULL;
83
53.4k
  mi_params->mi_alloc_size = 0;
84
53.4k
  aom_free(mi_params->mi_grid_base);
85
53.4k
  mi_params->mi_grid_base = NULL;
86
53.4k
  mi_params->mi_grid_size = 0;
87
53.4k
  aom_free(mi_params->tx_type_map);
88
53.4k
  mi_params->tx_type_map = NULL;
89
53.4k
}
90
91
16.8k
AV1Decoder *av1_decoder_create(BufferPool *const pool) {
92
16.8k
  AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi));
93
16.8k
  if (!pbi) return NULL;
94
16.8k
  av1_zero(*pbi);
95
96
16.8k
  AV1_COMMON *volatile const cm = &pbi->common;
97
16.8k
  cm->seq_params = &pbi->seq_params;
98
16.8k
  cm->error = &pbi->error;
99
100
  // The jmp_buf is valid only for the duration of the function that calls
101
  // setjmp(). Therefore, this function must reset the 'setjmp' field to 0
102
  // before it returns.
103
16.8k
  if (setjmp(pbi->error.jmp)) {
104
0
    pbi->error.setjmp = 0;
105
0
    av1_decoder_remove(pbi);
106
0
    return NULL;
107
0
  }
108
109
16.8k
  pbi->error.setjmp = 1;
110
111
16.8k
  CHECK_MEM_ERROR(cm, cm->fc,
112
16.8k
                  (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc)));
113
16.8k
  CHECK_MEM_ERROR(
114
16.8k
      cm, cm->default_frame_context,
115
16.8k
      (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context)));
116
16.8k
  memset(cm->fc, 0, sizeof(*cm->fc));
117
16.8k
  memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context));
118
119
16.8k
  pbi->need_resync = 1;
120
16.8k
  initialize_dec();
121
122
  // Initialize the references to not point to any frame buffers.
123
151k
  for (int i = 0; i < REF_FRAMES; i++) {
124
134k
    cm->ref_frame_map[i] = NULL;
125
134k
  }
126
127
16.8k
  cm->current_frame.frame_number = 0;
128
16.8k
  pbi->decoding_first_frame = 1;
129
16.8k
  pbi->common.buffer_pool = pool;
130
131
16.8k
  cm->seq_params->bit_depth = AOM_BITS_8;
132
133
16.8k
  cm->mi_params.free_mi = dec_free_mi;
134
16.8k
  cm->mi_params.setup_mi = dec_setup_mi;
135
16.8k
  cm->mi_params.set_mb_mi = dec_set_mb_mi;
136
137
16.8k
  av1_loop_filter_init(cm);
138
139
16.8k
  av1_qm_init(&cm->quant_params, av1_num_planes(cm));
140
16.8k
  av1_loop_restoration_precal();
141
142
#if CONFIG_ACCOUNTING
143
  pbi->acct_enabled = 1;
144
  aom_accounting_init(&pbi->accounting);
145
#endif
146
147
16.8k
  pbi->error.setjmp = 0;
148
149
16.8k
  aom_get_worker_interface()->init(&pbi->lf_worker);
150
16.8k
  pbi->lf_worker.thread_name = "aom lf worker";
151
152
16.8k
  return pbi;
153
16.8k
}
154
155
8.72k
void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) {
156
8.72k
  if (tile_mt_info != NULL) {
157
8.72k
#if CONFIG_MULTITHREAD
158
8.72k
    if (tile_mt_info->job_mutex != NULL) {
159
4.89k
      pthread_mutex_destroy(tile_mt_info->job_mutex);
160
4.89k
      aom_free(tile_mt_info->job_mutex);
161
4.89k
    }
162
8.72k
#endif
163
8.72k
    aom_free(tile_mt_info->job_queue);
164
    // clear the structure as the source of this call may be a resize in which
165
    // case this call will be followed by an _alloc() which may fail.
166
8.72k
    av1_zero(*tile_mt_info);
167
8.72k
  }
168
8.72k
}
169
170
21.2k
void av1_dec_free_cb_buf(AV1Decoder *pbi) {
171
21.2k
  aom_free(pbi->cb_buffer_base);
172
21.2k
  pbi->cb_buffer_base = NULL;
173
21.2k
  pbi->cb_buffer_alloc_size = 0;
174
21.2k
}
175
176
16.8k
void av1_decoder_remove(AV1Decoder *pbi) {
177
16.8k
  int i;
178
179
16.8k
  if (!pbi) return;
180
181
  // Free the tile list output buffer.
182
16.8k
  aom_free_frame_buffer(&pbi->tile_list_outbuf);
183
184
16.8k
  aom_get_worker_interface()->end(&pbi->lf_worker);
185
16.8k
  aom_free(pbi->lf_worker.data1);
186
187
16.8k
  if (pbi->thread_data) {
188
132k
    for (int worker_idx = 1; worker_idx < pbi->num_workers; worker_idx++) {
189
128k
      DecWorkerData *const thread_data = pbi->thread_data + worker_idx;
190
128k
      if (thread_data->td != NULL) {
191
128k
        av1_free_mc_tmp_buf(thread_data->td);
192
128k
        aom_free(thread_data->td);
193
128k
      }
194
128k
    }
195
3.82k
    aom_free(pbi->thread_data);
196
3.82k
  }
197
16.8k
  aom_free(pbi->dcb.xd.seg_mask);
198
199
149k
  for (i = 0; i < pbi->num_workers; ++i) {
200
132k
    AVxWorker *const worker = &pbi->tile_workers[i];
201
132k
    aom_get_worker_interface()->end(worker);
202
132k
  }
203
16.8k
#if CONFIG_MULTITHREAD
204
16.8k
  if (pbi->row_mt_mutex_ != NULL) {
205
3.63k
    pthread_mutex_destroy(pbi->row_mt_mutex_);
206
3.63k
    aom_free(pbi->row_mt_mutex_);
207
3.63k
  }
208
16.8k
  if (pbi->row_mt_cond_ != NULL) {
209
3.63k
    pthread_cond_destroy(pbi->row_mt_cond_);
210
3.63k
    aom_free(pbi->row_mt_cond_);
211
3.63k
  }
212
16.8k
#endif
213
46.3k
  for (i = 0; i < pbi->allocated_tiles; i++) {
214
29.5k
    TileDataDec *const tile_data = pbi->tile_data + i;
215
29.5k
    av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync);
216
29.5k
  }
217
16.8k
  aom_free(pbi->tile_data);
218
16.8k
  aom_free(pbi->tile_workers);
219
220
16.8k
  if (pbi->num_workers > 0) {
221
3.82k
    av1_loop_filter_dealloc(&pbi->lf_row_sync);
222
3.82k
    av1_loop_restoration_dealloc(&pbi->lr_row_sync);
223
3.82k
    av1_dealloc_dec_jobs(&pbi->tile_mt_info);
224
3.82k
  }
225
226
16.8k
  av1_dec_free_cb_buf(pbi);
227
#if CONFIG_ACCOUNTING
228
  aom_accounting_clear(&pbi->accounting);
229
#endif
230
16.8k
  av1_free_mc_tmp_buf(&pbi->td);
231
16.8k
  aom_img_metadata_array_free(pbi->metadata);
232
16.8k
  av1_remove_common(&pbi->common);
233
16.8k
  aom_free(pbi);
234
16.8k
}
235
236
void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd,
237
42.7M
                       aom_reader *r, palette_visitor_fn_t visit) {
238
42.7M
  if (!is_inter_block(xd->mi[0])) {
239
76.6M
    for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common));
240
50.8M
         ++plane) {
241
50.8M
      if (plane == 0 || xd->is_chroma_ref) {
242
49.0M
        if (xd->mi[0]->palette_mode_info.palette_size[plane])
243
203k
          visit(xd, plane, r);
244
49.0M
      } else {
245
1.79M
        assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0);
246
1.79M
      }
247
50.8M
    }
248
25.7M
  }
249
42.7M
}
250
251
static int equal_dimensions(const YV12_BUFFER_CONFIG *a,
252
0
                            const YV12_BUFFER_CONFIG *b) {
253
0
  return a->y_height == b->y_height && a->y_width == b->y_width &&
254
0
         a->uv_height == b->uv_height && a->uv_width == b->uv_width;
255
0
}
256
257
aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi, int idx,
258
0
                                       YV12_BUFFER_CONFIG *sd) {
259
0
  AV1_COMMON *cm = &pbi->common;
260
0
  const int num_planes = av1_num_planes(cm);
261
262
0
  const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, idx);
263
0
  if (cfg == NULL) {
264
0
    aom_internal_error(&pbi->error, AOM_CODEC_ERROR, "No reference frame");
265
0
    return AOM_CODEC_ERROR;
266
0
  }
267
0
  if (!equal_dimensions(cfg, sd))
268
0
    aom_internal_error(&pbi->error, AOM_CODEC_ERROR,
269
0
                       "Incorrect buffer dimensions");
270
0
  else
271
0
    aom_yv12_copy_frame(cfg, sd, num_planes);
272
273
0
  return pbi->error.error_code;
274
0
}
275
276
static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a,
277
18
                                       const YV12_BUFFER_CONFIG *b) {
278
18
  return a->y_height == b->y_height && a->y_width == b->y_width &&
279
18
         a->uv_height == b->uv_height && a->uv_width == b->uv_width &&
280
18
         a->y_stride == b->y_stride && a->uv_stride == b->uv_stride &&
281
18
         a->border == b->border &&
282
18
         (a->flags & YV12_FLAG_HIGHBITDEPTH) ==
283
0
             (b->flags & YV12_FLAG_HIGHBITDEPTH);
284
18
}
285
286
aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx,
287
                                      int use_external_ref,
288
104
                                      YV12_BUFFER_CONFIG *sd) {
289
104
  const int num_planes = av1_num_planes(cm);
290
104
  YV12_BUFFER_CONFIG *ref_buf = NULL;
291
292
  // Get the destination reference buffer.
293
104
  ref_buf = get_ref_frame(cm, idx);
294
295
104
  if (ref_buf == NULL) {
296
86
    aom_internal_error(cm->error, AOM_CODEC_ERROR, "No reference frame");
297
86
    return AOM_CODEC_ERROR;
298
86
  }
299
300
18
  if (!use_external_ref) {
301
0
    if (!equal_dimensions(ref_buf, sd)) {
302
0
      aom_internal_error(cm->error, AOM_CODEC_ERROR,
303
0
                         "Incorrect buffer dimensions");
304
0
    } else {
305
      // Overwrite the reference frame buffer.
306
0
      aom_yv12_copy_frame(sd, ref_buf, num_planes);
307
0
    }
308
18
  } else {
309
18
    if (!equal_dimensions_and_border(ref_buf, sd)) {
310
18
      aom_internal_error(cm->error, AOM_CODEC_ERROR,
311
18
                         "Incorrect buffer dimensions");
312
18
    } else {
313
      // Overwrite the reference frame buffer pointers.
314
      // Once we no longer need the external reference buffer, these pointers
315
      // are restored.
316
0
      ref_buf->store_buf_adr[0] = ref_buf->y_buffer;
317
0
      ref_buf->store_buf_adr[1] = ref_buf->u_buffer;
318
0
      ref_buf->store_buf_adr[2] = ref_buf->v_buffer;
319
0
      ref_buf->y_buffer = sd->y_buffer;
320
0
      ref_buf->u_buffer = sd->u_buffer;
321
0
      ref_buf->v_buffer = sd->v_buffer;
322
0
      ref_buf->use_external_reference_buffers = 1;
323
0
    }
324
18
  }
325
326
18
  return cm->error->error_code;
327
104
}
328
329
aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm,
330
                                       YV12_BUFFER_CONFIG *new_frame,
331
0
                                       YV12_BUFFER_CONFIG *sd) {
332
0
  const int num_planes = av1_num_planes(cm);
333
334
0
  if (!equal_dimensions_and_border(new_frame, sd))
335
0
    aom_internal_error(cm->error, AOM_CODEC_ERROR,
336
0
                       "Incorrect buffer dimensions");
337
0
  else
338
0
    aom_yv12_copy_frame(new_frame, sd, num_planes);
339
340
0
  return cm->error->error_code;
341
0
}
342
343
170k
static void release_current_frame(AV1Decoder *pbi) {
344
170k
  AV1_COMMON *const cm = &pbi->common;
345
170k
  BufferPool *const pool = cm->buffer_pool;
346
347
170k
  cm->cur_frame->buf.corrupted = 1;
348
170k
  lock_buffer_pool(pool);
349
170k
  decrease_ref_count(cm->cur_frame, pool);
350
170k
  unlock_buffer_pool(pool);
351
170k
  cm->cur_frame = NULL;
352
170k
}
353
354
// If any buffer updating is signaled it should be done here.
355
// Consumes a reference to cm->cur_frame.
356
//
357
// This functions returns void. It reports failure by setting
358
// pbi->error.error_code.
359
140k
static void update_frame_buffers(AV1Decoder *pbi, int frame_decoded) {
360
140k
  int ref_index = 0, mask;
361
140k
  AV1_COMMON *const cm = &pbi->common;
362
140k
  BufferPool *const pool = cm->buffer_pool;
363
364
140k
  if (frame_decoded) {
365
139k
    lock_buffer_pool(pool);
366
367
    // In ext-tile decoding, the camera frame header is only decoded once. So,
368
    // we don't update the references here.
369
139k
    if (!pbi->camera_frame_header_ready) {
370
      // The following for loop needs to release the reference stored in
371
      // cm->ref_frame_map[ref_index] before storing a reference to
372
      // cm->cur_frame in cm->ref_frame_map[ref_index].
373
843k
      for (mask = cm->current_frame.refresh_frame_flags; mask; mask >>= 1) {
374
707k
        if (mask & 1) {
375
450k
          decrease_ref_count(cm->ref_frame_map[ref_index], pool);
376
450k
          cm->ref_frame_map[ref_index] = cm->cur_frame;
377
450k
          ++cm->cur_frame->ref_count;
378
450k
        }
379
707k
        ++ref_index;
380
707k
      }
381
135k
    }
382
383
139k
    if (cm->show_existing_frame || cm->show_frame) {
384
115k
      if (pbi->output_all_layers) {
385
        // Append this frame to the output queue
386
4.24k
        if (pbi->num_output_frames >= MAX_NUM_SPATIAL_LAYERS) {
387
          // We can't store the new frame anywhere, so drop it and return an
388
          // error
389
38
          cm->cur_frame->buf.corrupted = 1;
390
38
          decrease_ref_count(cm->cur_frame, pool);
391
38
          pbi->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
392
4.20k
        } else {
393
4.20k
          pbi->output_frames[pbi->num_output_frames] = cm->cur_frame;
394
4.20k
          pbi->num_output_frames++;
395
4.20k
        }
396
111k
      } else {
397
        // Replace any existing output frame
398
111k
        assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1);
399
111k
        if (pbi->num_output_frames > 0) {
400
14.4k
          decrease_ref_count(pbi->output_frames[0], pool);
401
14.4k
        }
402
111k
        pbi->output_frames[0] = cm->cur_frame;
403
111k
        pbi->num_output_frames = 1;
404
111k
      }
405
115k
    } else {
406
23.6k
      decrease_ref_count(cm->cur_frame, pool);
407
23.6k
    }
408
409
139k
    unlock_buffer_pool(pool);
410
139k
  } else {
411
    // Nothing was decoded, so just drop this frame buffer
412
679
    lock_buffer_pool(pool);
413
679
    decrease_ref_count(cm->cur_frame, pool);
414
679
    unlock_buffer_pool(pool);
415
679
  }
416
140k
  cm->cur_frame = NULL;
417
418
140k
  if (!pbi->camera_frame_header_ready) {
419
    // Invalidate these references until the next frame starts.
420
1.09M
    for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) {
421
955k
      cm->remapped_ref_idx[ref_index] = INVALID_IDX;
422
955k
    }
423
136k
  }
424
140k
}
425
426
int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
427
310k
                                const uint8_t **psource) {
428
310k
  AV1_COMMON *volatile const cm = &pbi->common;
429
310k
  const uint8_t *source = *psource;
430
310k
  pbi->error.error_code = AOM_CODEC_OK;
431
310k
  pbi->error.has_detail = 0;
432
433
310k
  if (size == 0) {
434
    // This is used to signal that we are missing frames.
435
    // We do not know if the missing frame(s) was supposed to update
436
    // any of the reference buffers, but we act conservative and
437
    // mark only the last buffer as corrupted.
438
    //
439
    // TODO(jkoleszar): Error concealment is undefined and non-normative
440
    // at this point, but if it becomes so, [0] may not always be the correct
441
    // thing to do here.
442
345
    RefCntBuffer *ref_buf = get_ref_frame_buf(cm, LAST_FRAME);
443
345
    if (ref_buf != NULL) ref_buf->buf.corrupted = 1;
444
345
  }
445
446
310k
  if (assign_cur_frame_new_fb(cm) == NULL) {
447
0
    pbi->error.error_code = AOM_CODEC_MEM_ERROR;
448
0
    return 1;
449
0
  }
450
451
  // The jmp_buf is valid only for the duration of the function that calls
452
  // setjmp(). Therefore, this function must reset the 'setjmp' field to 0
453
  // before it returns.
454
310k
  if (setjmp(pbi->error.jmp)) {
455
125k
    const AVxWorkerInterface *const winterface = aom_get_worker_interface();
456
125k
    int i;
457
458
125k
    pbi->error.setjmp = 0;
459
460
    // Synchronize all threads immediately as a subsequent decode call may
461
    // cause a resize invalidating some allocations.
462
125k
    winterface->sync(&pbi->lf_worker);
463
2.25M
    for (i = 0; i < pbi->num_workers; ++i) {
464
2.12M
      winterface->sync(&pbi->tile_workers[i]);
465
2.12M
    }
466
467
125k
    release_current_frame(pbi);
468
125k
    return -1;
469
125k
  }
470
471
184k
  pbi->error.setjmp = 1;
472
473
184k
  int frame_decoded =
474
184k
      aom_decode_frame_from_obus(pbi, source, source + size, psource);
475
476
184k
  if (frame_decoded < 0) {
477
44.3k
    assert(pbi->error.error_code != AOM_CODEC_OK);
478
44.3k
    release_current_frame(pbi);
479
44.3k
    pbi->error.setjmp = 0;
480
44.3k
    return 1;
481
44.3k
  }
482
483
#if TXCOEFF_TIMER
484
  cm->cum_txcoeff_timer += cm->txcoeff_timer;
485
  fprintf(stderr,
486
          "txb coeff block number: %d, frame time: %ld, cum time %ld in us\n",
487
          cm->txb_count, cm->txcoeff_timer, cm->cum_txcoeff_timer);
488
  cm->txcoeff_timer = 0;
489
  cm->txb_count = 0;
490
#endif
491
492
  // Note: At this point, this function holds a reference to cm->cur_frame
493
  // in the buffer pool. This reference is consumed by update_frame_buffers().
494
140k
  update_frame_buffers(pbi, frame_decoded);
495
496
140k
  if (frame_decoded) {
497
139k
    pbi->decoding_first_frame = 0;
498
139k
  }
499
500
140k
  if (pbi->error.error_code != AOM_CODEC_OK) {
501
38
    pbi->error.setjmp = 0;
502
38
    return 1;
503
38
  }
504
505
140k
  if (!cm->show_existing_frame) {
506
139k
    if (cm->seg.enabled) {
507
17.9k
      if (cm->prev_frame &&
508
17.9k
          (cm->mi_params.mi_rows == cm->prev_frame->mi_rows) &&
509
17.9k
          (cm->mi_params.mi_cols == cm->prev_frame->mi_cols)) {
510
7.36k
        cm->last_frame_seg_map = cm->prev_frame->seg_map;
511
10.5k
      } else {
512
10.5k
        cm->last_frame_seg_map = NULL;
513
10.5k
      }
514
17.9k
    }
515
139k
  }
516
517
  // Update progress in frame parallel decode.
518
140k
  pbi->error.setjmp = 0;
519
520
140k
  return 0;
521
140k
}
522
523
// Get the frame at a particular index in the output queue
524
int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd,
525
334k
                      aom_film_grain_t **grain_params) {
526
334k
  if (index >= pbi->num_output_frames) return -1;
527
98.1k
  *sd = &pbi->output_frames[index]->buf;
528
98.1k
  *grain_params = &pbi->output_frames[index]->film_grain_params;
529
98.1k
  return 0;
530
334k
}
531
532
// Get the highest-spatial-layer output
533
// TODO(rachelbarker): What should this do?
534
0
int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) {
535
0
  if (pbi->num_output_frames == 0) return -1;
536
537
0
  *frame = pbi->output_frames[pbi->num_output_frames - 1]->buf;
538
0
  return 0;
539
0
}