Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/third_party/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_mem/aom_mem.h"
21
#include "aom_ports/system_state.h"
22
#include "aom_ports/aom_once.h"
23
#include "aom_ports/aom_timer.h"
24
#include "aom_scale/aom_scale.h"
25
#include "aom_util/aom_thread.h"
26
27
#include "av1/common/alloccommon.h"
28
#include "av1/common/av1_loopfilter.h"
29
#include "av1/common/onyxc_int.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
0
static void initialize_dec(void) {
40
0
  av1_rtcd();
41
0
  aom_dsp_rtcd();
42
0
  aom_scale_rtcd();
43
0
  av1_init_intra_predictors();
44
0
  av1_init_wedge_masks();
45
0
}
46
47
0
static void dec_setup_mi(AV1_COMMON *cm) {
48
0
  cm->mi = cm->mip;
49
0
  cm->mi_grid_visible = cm->mi_grid_base;
50
0
  memset(cm->mi_grid_base, 0,
51
0
         cm->mi_stride * cm->mi_rows * sizeof(*cm->mi_grid_base));
52
0
}
53
54
0
static int av1_dec_alloc_mi(AV1_COMMON *cm, int mi_size) {
55
0
  cm->mip = aom_calloc(mi_size, sizeof(*cm->mip));
56
0
  if (!cm->mip) return 1;
57
0
  cm->mi_alloc_size = mi_size;
58
0
  cm->mi_grid_base =
59
0
      (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *));
60
0
  if (!cm->mi_grid_base) return 1;
61
0
  return 0;
62
0
}
63
64
0
static void dec_free_mi(AV1_COMMON *cm) {
65
0
  aom_free(cm->mip);
66
0
  cm->mip = NULL;
67
0
  aom_free(cm->mi_grid_base);
68
0
  cm->mi_grid_base = NULL;
69
0
  cm->mi_alloc_size = 0;
70
0
}
71
72
0
AV1Decoder *av1_decoder_create(BufferPool *const pool) {
73
0
  AV1Decoder *volatile const pbi = aom_memalign(32, sizeof(*pbi));
74
0
  AV1_COMMON *volatile const cm = pbi ? &pbi->common : NULL;
75
0
76
0
  if (!cm) return NULL;
77
0
78
0
  av1_zero(*pbi);
79
0
80
0
  // The jmp_buf is valid only for the duration of the function that calls
81
0
  // setjmp(). Therefore, this function must reset the 'setjmp' field to 0
82
0
  // before it returns.
83
0
  if (setjmp(cm->error.jmp)) {
84
0
    cm->error.setjmp = 0;
85
0
    av1_decoder_remove(pbi);
86
0
    return NULL;
87
0
  }
88
0
89
0
  cm->error.setjmp = 1;
90
0
91
0
  CHECK_MEM_ERROR(cm, cm->fc,
92
0
                  (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc)));
93
0
  CHECK_MEM_ERROR(cm, cm->frame_contexts,
94
0
                  (FRAME_CONTEXT *)aom_memalign(
95
0
                      32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)));
96
0
  memset(cm->fc, 0, sizeof(*cm->fc));
97
0
  memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts));
98
0
99
0
  pbi->need_resync = 1;
100
0
  aom_once(initialize_dec);
101
0
102
0
  // Initialize the references to not point to any frame buffers.
103
0
  memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
104
0
  memset(&cm->next_ref_frame_map, -1, sizeof(cm->next_ref_frame_map));
105
0
106
0
  cm->current_video_frame = 0;
107
0
  pbi->decoding_first_frame = 1;
108
0
  pbi->common.buffer_pool = pool;
109
0
110
0
  cm->seq_params.bit_depth = AOM_BITS_8;
111
0
  cm->dequant_bit_depth = AOM_BITS_8;
112
0
113
0
  cm->alloc_mi = av1_dec_alloc_mi;
114
0
  cm->free_mi = dec_free_mi;
115
0
  cm->setup_mi = dec_setup_mi;
116
0
117
0
  av1_loop_filter_init(cm);
118
0
119
0
  av1_qm_init(cm);
120
0
  av1_loop_restoration_precal();
121
#if CONFIG_ACCOUNTING
122
  pbi->acct_enabled = 1;
123
  aom_accounting_init(&pbi->accounting);
124
#endif
125
126
0
  cm->error.setjmp = 0;
127
0
128
0
  aom_get_worker_interface()->init(&pbi->lf_worker);
129
0
130
0
  return pbi;
131
0
}
132
133
0
void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) {
134
0
  if (tile_mt_info != NULL) {
135
0
#if CONFIG_MULTITHREAD
136
0
    if (tile_mt_info->job_mutex != NULL) {
137
0
      pthread_mutex_destroy(tile_mt_info->job_mutex);
138
0
      aom_free(tile_mt_info->job_mutex);
139
0
    }
140
0
#endif
141
0
    aom_free(tile_mt_info->job_queue);
142
0
    // clear the structure as the source of this call may be a resize in which
143
0
    // case this call will be followed by an _alloc() which may fail.
144
0
    av1_zero(*tile_mt_info);
145
0
  }
146
0
}
147
148
0
void av1_dec_free_cb_buf(AV1Decoder *pbi) {
149
0
  aom_free(pbi->cb_buffer_base);
150
0
  pbi->cb_buffer_base = NULL;
151
0
  pbi->cb_buffer_alloc_size = 0;
152
0
}
153
154
0
void av1_decoder_remove(AV1Decoder *pbi) {
155
0
  int i;
156
0
157
0
  if (!pbi) return;
158
0
159
0
  // Free the tile list output buffer.
160
0
  if (pbi->tile_list_output != NULL) aom_free(pbi->tile_list_output);
161
0
  pbi->tile_list_output = NULL;
162
0
163
0
  aom_get_worker_interface()->end(&pbi->lf_worker);
164
0
  aom_free(pbi->lf_worker.data1);
165
0
166
0
  if (pbi->thread_data) {
167
0
    for (int worker_idx = 0; worker_idx < pbi->max_threads - 1; worker_idx++) {
168
0
      DecWorkerData *const thread_data = pbi->thread_data + worker_idx;
169
0
      av1_free_mc_tmp_buf(thread_data->td);
170
0
      aom_free(thread_data->td);
171
0
    }
172
0
    aom_free(pbi->thread_data);
173
0
  }
174
0
175
0
  for (i = 0; i < pbi->num_workers; ++i) {
176
0
    AVxWorker *const worker = &pbi->tile_workers[i];
177
0
    aom_get_worker_interface()->end(worker);
178
0
  }
179
0
#if CONFIG_MULTITHREAD
180
0
  if (pbi->row_mt_mutex_ != NULL) {
181
0
    pthread_mutex_destroy(pbi->row_mt_mutex_);
182
0
    aom_free(pbi->row_mt_mutex_);
183
0
  }
184
0
  if (pbi->row_mt_cond_ != NULL) {
185
0
    pthread_cond_destroy(pbi->row_mt_cond_);
186
0
    aom_free(pbi->row_mt_cond_);
187
0
  }
188
0
#endif
189
0
  for (i = 0; i < pbi->allocated_tiles; i++) {
190
0
    TileDataDec *const tile_data = pbi->tile_data + i;
191
0
    av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync);
192
0
  }
193
0
  aom_free(pbi->tile_data);
194
0
  aom_free(pbi->tile_workers);
195
0
196
0
  if (pbi->num_workers > 0) {
197
0
    av1_loop_filter_dealloc(&pbi->lf_row_sync);
198
0
    av1_loop_restoration_dealloc(&pbi->lr_row_sync, pbi->num_workers);
199
0
    av1_dealloc_dec_jobs(&pbi->tile_mt_info);
200
0
  }
201
0
202
0
  av1_dec_free_cb_buf(pbi);
203
#if CONFIG_ACCOUNTING
204
  aom_accounting_clear(&pbi->accounting);
205
#endif
206
  av1_free_mc_tmp_buf(&pbi->td);
207
0
208
0
  aom_free(pbi);
209
0
}
210
211
void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, int mi_row,
212
                       int mi_col, aom_reader *r, BLOCK_SIZE bsize,
213
0
                       palette_visitor_fn_t visit) {
214
0
  if (!is_inter_block(xd->mi[0])) {
215
0
    for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common));
216
0
         ++plane) {
217
0
      const struct macroblockd_plane *const pd = &xd->plane[plane];
218
0
      if (is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x,
219
0
                              pd->subsampling_y)) {
220
0
        if (xd->mi[0]->palette_mode_info.palette_size[plane])
221
0
          visit(xd, plane, r);
222
0
      } else {
223
0
        assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0);
224
0
      }
225
0
    }
226
0
  }
227
0
}
228
229
static int equal_dimensions(const YV12_BUFFER_CONFIG *a,
230
0
                            const YV12_BUFFER_CONFIG *b) {
231
0
  return a->y_height == b->y_height && a->y_width == b->y_width &&
232
0
         a->uv_height == b->uv_height && a->uv_width == b->uv_width;
233
0
}
234
235
aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi, int idx,
236
0
                                       YV12_BUFFER_CONFIG *sd) {
237
0
  AV1_COMMON *cm = &pbi->common;
238
0
  const int num_planes = av1_num_planes(cm);
239
0
240
0
  const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, idx);
241
0
  if (cfg == NULL) {
242
0
    aom_internal_error(&cm->error, AOM_CODEC_ERROR, "No reference frame");
243
0
    return AOM_CODEC_ERROR;
244
0
  }
245
0
  if (!equal_dimensions(cfg, sd))
246
0
    aom_internal_error(&cm->error, AOM_CODEC_ERROR,
247
0
                       "Incorrect buffer dimensions");
248
0
  else
249
0
    aom_yv12_copy_frame(cfg, sd, num_planes);
250
0
251
0
  return cm->error.error_code;
252
0
}
253
254
static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a,
255
0
                                       const YV12_BUFFER_CONFIG *b) {
256
0
  return a->y_height == b->y_height && a->y_width == b->y_width &&
257
0
         a->uv_height == b->uv_height && a->uv_width == b->uv_width &&
258
0
         a->y_stride == b->y_stride && a->uv_stride == b->uv_stride &&
259
0
         a->border == b->border &&
260
0
         (a->flags & YV12_FLAG_HIGHBITDEPTH) ==
261
0
             (b->flags & YV12_FLAG_HIGHBITDEPTH);
262
0
}
263
264
aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx,
265
                                      int use_external_ref,
266
0
                                      YV12_BUFFER_CONFIG *sd) {
267
0
  const int num_planes = av1_num_planes(cm);
268
0
  YV12_BUFFER_CONFIG *ref_buf = NULL;
269
0
270
0
  // Get the destination reference buffer.
271
0
  ref_buf = get_ref_frame(cm, idx);
272
0
273
0
  if (ref_buf == NULL) {
274
0
    aom_internal_error(&cm->error, AOM_CODEC_ERROR, "No reference frame");
275
0
    return AOM_CODEC_ERROR;
276
0
  }
277
0
278
0
  if (!use_external_ref) {
279
0
    if (!equal_dimensions(ref_buf, sd)) {
280
0
      aom_internal_error(&cm->error, AOM_CODEC_ERROR,
281
0
                         "Incorrect buffer dimensions");
282
0
    } else {
283
0
      // Overwrite the reference frame buffer.
284
0
      aom_yv12_copy_frame(sd, ref_buf, num_planes);
285
0
    }
286
0
  } else {
287
0
    if (!equal_dimensions_and_border(ref_buf, sd)) {
288
0
      aom_internal_error(&cm->error, AOM_CODEC_ERROR,
289
0
                         "Incorrect buffer dimensions");
290
0
    } else {
291
0
      // Overwrite the reference frame buffer pointers.
292
0
      // Once we no longer need the external reference buffer, these pointers
293
0
      // are restored.
294
0
      ref_buf->store_buf_adr[0] = ref_buf->y_buffer;
295
0
      ref_buf->store_buf_adr[1] = ref_buf->u_buffer;
296
0
      ref_buf->store_buf_adr[2] = ref_buf->v_buffer;
297
0
      ref_buf->y_buffer = sd->y_buffer;
298
0
      ref_buf->u_buffer = sd->u_buffer;
299
0
      ref_buf->v_buffer = sd->v_buffer;
300
0
      ref_buf->use_external_reference_buffers = 1;
301
0
    }
302
0
  }
303
0
304
0
  return cm->error.error_code;
305
0
}
306
307
aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm,
308
                                       YV12_BUFFER_CONFIG *new_frame,
309
0
                                       YV12_BUFFER_CONFIG *sd) {
310
0
  const int num_planes = av1_num_planes(cm);
311
0
312
0
  if (!equal_dimensions_and_border(new_frame, sd))
313
0
    aom_internal_error(&cm->error, AOM_CODEC_ERROR,
314
0
                       "Incorrect buffer dimensions");
315
0
  else
316
0
    aom_yv12_copy_frame(new_frame, sd, num_planes);
317
0
318
0
  return cm->error.error_code;
319
0
}
320
321
/* If any buffer updating is signaled it should be done here.
322
   Consumes a reference to cm->new_fb_idx.
323
*/
324
0
static void swap_frame_buffers(AV1Decoder *pbi, int frame_decoded) {
325
0
  int ref_index = 0, mask;
326
0
  AV1_COMMON *const cm = &pbi->common;
327
0
  BufferPool *const pool = cm->buffer_pool;
328
0
  RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
329
0
330
0
  if (frame_decoded) {
331
0
    lock_buffer_pool(pool);
332
0
333
0
    // In ext-tile decoding, the camera frame header is only decoded once. So,
334
0
    // we don't release the references here.
335
0
    if (!pbi->camera_frame_header_ready) {
336
0
      for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
337
0
        const int old_idx = cm->ref_frame_map[ref_index];
338
0
        // Current thread releases the holding of reference frame.
339
0
        decrease_ref_count(old_idx, frame_bufs, pool);
340
0
341
0
        // Release the reference frame holding in the reference map for the
342
0
        // decoding of the next frame.
343
0
        if (mask & 1) decrease_ref_count(old_idx, frame_bufs, pool);
344
0
        cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
345
0
        ++ref_index;
346
0
      }
347
0
348
0
      // Current thread releases the holding of reference frame.
349
0
      const int check_on_show_existing_frame =
350
0
          !cm->show_existing_frame || cm->reset_decoder_state;
351
0
      for (; ref_index < REF_FRAMES && check_on_show_existing_frame;
352
0
           ++ref_index) {
353
0
        const int old_idx = cm->ref_frame_map[ref_index];
354
0
        decrease_ref_count(old_idx, frame_bufs, pool);
355
0
        cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
356
0
      }
357
0
    }
358
0
359
0
    YV12_BUFFER_CONFIG *cur_frame = get_frame_new_buffer(cm);
360
0
361
0
    if (cm->show_existing_frame || cm->show_frame) {
362
0
      if (pbi->output_all_layers) {
363
0
        // Append this frame to the output queue
364
0
        if (pbi->num_output_frames >= MAX_NUM_SPATIAL_LAYERS) {
365
0
          // We can't store the new frame anywhere, so drop it and return an
366
0
          // error
367
0
          decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
368
0
          cm->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
369
0
        } else {
370
0
          pbi->output_frames[pbi->num_output_frames] = cur_frame;
371
0
          pbi->output_frame_index[pbi->num_output_frames] = cm->new_fb_idx;
372
0
          pbi->num_output_frames++;
373
0
        }
374
0
      } else {
375
0
        // Replace any existing output frame
376
0
        assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1);
377
0
        if (pbi->num_output_frames > 0) {
378
0
          decrease_ref_count((int)pbi->output_frame_index[0], frame_bufs, pool);
379
0
        }
380
0
        pbi->output_frames[0] = cur_frame;
381
0
        pbi->output_frame_index[0] = cm->new_fb_idx;
382
0
        pbi->num_output_frames = 1;
383
0
      }
384
0
    } else {
385
0
      decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
386
0
    }
387
0
388
0
    unlock_buffer_pool(pool);
389
0
  } else {
390
0
    // Nothing was decoded, so just drop this frame buffer
391
0
    lock_buffer_pool(pool);
392
0
    decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
393
0
    unlock_buffer_pool(pool);
394
0
  }
395
0
396
0
  if (!pbi->camera_frame_header_ready) {
397
0
    pbi->hold_ref_buf = 0;
398
0
399
0
    // Invalidate these references until the next frame starts.
400
0
    for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) {
401
0
      cm->frame_refs[ref_index].idx = INVALID_IDX;
402
0
      cm->frame_refs[ref_index].buf = NULL;
403
0
    }
404
0
  }
405
0
}
406
407
int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
408
0
                                const uint8_t **psource) {
409
0
  AV1_COMMON *volatile const cm = &pbi->common;
410
0
  BufferPool *volatile const pool = cm->buffer_pool;
411
0
  RefCntBuffer *volatile const frame_bufs = cm->buffer_pool->frame_bufs;
412
0
  const uint8_t *source = *psource;
413
0
  cm->error.error_code = AOM_CODEC_OK;
414
0
415
0
  if (size == 0) {
416
0
    // This is used to signal that we are missing frames.
417
0
    // We do not know if the missing frame(s) was supposed to update
418
0
    // any of the reference buffers, but we act conservative and
419
0
    // mark only the last buffer as corrupted.
420
0
    //
421
0
    // TODO(jkoleszar): Error concealment is undefined and non-normative
422
0
    // at this point, but if it becomes so, [0] may not always be the correct
423
0
    // thing to do here.
424
0
    if (cm->frame_refs[0].idx > 0) {
425
0
      assert(cm->frame_refs[0].buf != NULL);
426
0
      cm->frame_refs[0].buf->corrupted = 1;
427
0
    }
428
0
  }
429
0
430
0
  // Find a free buffer for the new frame, releasing the reference previously
431
0
  // held.
432
0
433
0
  // Find a free frame buffer. Return error if can not find any.
434
0
  cm->new_fb_idx = get_free_fb(cm);
435
0
  if (cm->new_fb_idx == INVALID_IDX) {
436
0
    cm->error.error_code = AOM_CODEC_MEM_ERROR;
437
0
    return 1;
438
0
  }
439
0
440
0
  // Assign a MV array to the frame buffer.
441
0
  cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
442
0
443
0
  if (!pbi->camera_frame_header_ready) pbi->hold_ref_buf = 0;
444
0
445
0
  pbi->cur_buf = &frame_bufs[cm->new_fb_idx];
446
0
447
0
  // The jmp_buf is valid only for the duration of the function that calls
448
0
  // setjmp(). Therefore, this function must reset the 'setjmp' field to 0
449
0
  // before it returns.
450
0
  if (setjmp(cm->error.jmp)) {
451
0
    const AVxWorkerInterface *const winterface = aom_get_worker_interface();
452
0
    int i;
453
0
454
0
    cm->error.setjmp = 0;
455
0
456
0
    // Synchronize all threads immediately as a subsequent decode call may
457
0
    // cause a resize invalidating some allocations.
458
0
    winterface->sync(&pbi->lf_worker);
459
0
    for (i = 0; i < pbi->num_workers; ++i) {
460
0
      winterface->sync(&pbi->tile_workers[i]);
461
0
    }
462
0
463
0
    lock_buffer_pool(pool);
464
0
    // Release all the reference buffers if worker thread is holding them.
465
0
    if (pbi->hold_ref_buf == 1) {
466
0
      int ref_index = 0, mask;
467
0
      for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
468
0
        const int old_idx = cm->ref_frame_map[ref_index];
469
0
        // Current thread releases the holding of reference frame.
470
0
        decrease_ref_count(old_idx, frame_bufs, pool);
471
0
472
0
        // Release the reference frame holding in the reference map for the
473
0
        // decoding of the next frame.
474
0
        if (mask & 1) decrease_ref_count(old_idx, frame_bufs, pool);
475
0
        ++ref_index;
476
0
      }
477
0
478
0
      // Current thread releases the holding of reference frame.
479
0
      const int check_on_show_existing_frame =
480
0
          !cm->show_existing_frame || cm->reset_decoder_state;
481
0
      for (; ref_index < REF_FRAMES && check_on_show_existing_frame;
482
0
           ++ref_index) {
483
0
        const int old_idx = cm->ref_frame_map[ref_index];
484
0
        decrease_ref_count(old_idx, frame_bufs, pool);
485
0
      }
486
0
      pbi->hold_ref_buf = 0;
487
0
    }
488
0
    // Release current frame.
489
0
    decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
490
0
    unlock_buffer_pool(pool);
491
0
492
0
    aom_clear_system_state();
493
0
    return -1;
494
0
  }
495
0
496
0
  cm->error.setjmp = 1;
497
0
498
0
  int frame_decoded =
499
0
      aom_decode_frame_from_obus(pbi, source, source + size, psource);
500
0
501
0
  if (cm->error.error_code != AOM_CODEC_OK) {
502
0
    lock_buffer_pool(pool);
503
0
    decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
504
0
    unlock_buffer_pool(pool);
505
0
    cm->error.setjmp = 0;
506
0
    return 1;
507
0
  }
508
0
509
#if TXCOEFF_TIMER
510
  cm->cum_txcoeff_timer += cm->txcoeff_timer;
511
  fprintf(stderr,
512
          "txb coeff block number: %d, frame time: %ld, cum time %ld in us\n",
513
          cm->txb_count, cm->txcoeff_timer, cm->cum_txcoeff_timer);
514
  cm->txcoeff_timer = 0;
515
  cm->txb_count = 0;
516
#endif
517
518
0
  // Note: At this point, this function holds a reference to cm->new_fb_idx
519
0
  // in the buffer pool. This reference is consumed by swap_frame_buffers().
520
0
  swap_frame_buffers(pbi, frame_decoded);
521
0
522
0
  if (frame_decoded) {
523
0
    pbi->decoding_first_frame = 0;
524
0
  }
525
0
526
0
  if (cm->error.error_code != AOM_CODEC_OK) {
527
0
    cm->error.setjmp = 0;
528
0
    return 1;
529
0
  }
530
0
531
0
  aom_clear_system_state();
532
0
533
0
  if (!cm->show_existing_frame) {
534
0
    cm->last_show_frame = cm->show_frame;
535
0
536
0
    if (cm->seg.enabled) {
537
0
      if (cm->prev_frame && (cm->mi_rows == cm->prev_frame->mi_rows) &&
538
0
          (cm->mi_cols == cm->prev_frame->mi_cols)) {
539
0
        cm->last_frame_seg_map = cm->prev_frame->seg_map;
540
0
      } else {
541
0
        cm->last_frame_seg_map = NULL;
542
0
      }
543
0
    }
544
0
  }
545
0
546
0
  // Update progress in frame parallel decode.
547
0
  cm->last_width = cm->width;
548
0
  cm->last_height = cm->height;
549
0
  cm->last_tile_cols = cm->tile_cols;
550
0
  cm->last_tile_rows = cm->tile_rows;
551
0
  cm->error.setjmp = 0;
552
0
553
0
  return 0;
554
0
}
555
556
// Get the frame at a particular index in the output queue
557
int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd,
558
0
                      aom_film_grain_t **grain_params) {
559
0
  RefCntBuffer *const frame_bufs = pbi->common.buffer_pool->frame_bufs;
560
0
561
0
  if (index >= pbi->num_output_frames) return -1;
562
0
  *sd = pbi->output_frames[index];
563
0
  *grain_params = &frame_bufs[pbi->output_frame_index[index]].film_grain_params;
564
0
  aom_clear_system_state();
565
0
  return 0;
566
0
}
567
568
// Get the highest-spatial-layer output
569
// TODO(david.barker): What should this do?
570
0
int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) {
571
0
  if (pbi->num_output_frames == 0) return -1;
572
0
573
0
  *frame = *pbi->output_frames[pbi->num_output_frames - 1];
574
0
  return 0;
575
0
}