Coverage Report

Created: 2022-08-24 06:11

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