Add build option for security
[platform/upstream/libvpx.git] / vp9 / decoder / vp9_decoder.c
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #include <assert.h>
12 #include <limits.h>
13 #include <stdio.h>
14
15 #include "./vp9_rtcd.h"
16 #include "./vpx_dsp_rtcd.h"
17 #include "./vpx_scale_rtcd.h"
18
19 #include "vpx_mem/vpx_mem.h"
20 #include "vpx_ports/system_state.h"
21 #include "vpx_ports/vpx_once.h"
22 #include "vpx_ports/vpx_timer.h"
23 #include "vpx_scale/vpx_scale.h"
24 #include "vpx_util/vpx_thread.h"
25
26 #include "vp9/common/vp9_alloccommon.h"
27 #include "vp9/common/vp9_loopfilter.h"
28 #include "vp9/common/vp9_onyxc_int.h"
29 #if CONFIG_VP9_POSTPROC
30 #include "vp9/common/vp9_postproc.h"
31 #endif
32 #include "vp9/common/vp9_quant_common.h"
33 #include "vp9/common/vp9_reconintra.h"
34
35 #include "vp9/decoder/vp9_decodeframe.h"
36 #include "vp9/decoder/vp9_decoder.h"
37 #include "vp9/decoder/vp9_detokenize.h"
38
39 static void initialize_dec(void) {
40   static volatile int init_done = 0;
41
42   if (!init_done) {
43     vp9_rtcd();
44     vpx_dsp_rtcd();
45     vpx_scale_rtcd();
46     vp9_init_intra_predictors();
47     init_done = 1;
48   }
49 }
50
51 static void vp9_dec_setup_mi(VP9_COMMON *cm) {
52   cm->mi = cm->mip + cm->mi_stride + 1;
53   cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
54   memset(cm->mi_grid_base, 0,
55          cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base));
56 }
57
58 void vp9_dec_alloc_row_mt_mem(RowMTWorkerData *row_mt_worker_data,
59                               VP9_COMMON *cm, int num_sbs, int max_threads,
60                               int num_jobs) {
61   int plane;
62   const size_t dqcoeff_size = (num_sbs << DQCOEFFS_PER_SB_LOG2) *
63                               sizeof(*row_mt_worker_data->dqcoeff[0]);
64   row_mt_worker_data->num_jobs = num_jobs;
65 #if CONFIG_MULTITHREAD
66   {
67     int i;
68     CHECK_MEM_ERROR(
69         cm, row_mt_worker_data->recon_sync_mutex,
70         vpx_malloc(sizeof(*row_mt_worker_data->recon_sync_mutex) * num_jobs));
71     if (row_mt_worker_data->recon_sync_mutex) {
72       for (i = 0; i < num_jobs; ++i) {
73         pthread_mutex_init(&row_mt_worker_data->recon_sync_mutex[i], NULL);
74       }
75     }
76
77     CHECK_MEM_ERROR(
78         cm, row_mt_worker_data->recon_sync_cond,
79         vpx_malloc(sizeof(*row_mt_worker_data->recon_sync_cond) * num_jobs));
80     if (row_mt_worker_data->recon_sync_cond) {
81       for (i = 0; i < num_jobs; ++i) {
82         pthread_cond_init(&row_mt_worker_data->recon_sync_cond[i], NULL);
83       }
84     }
85   }
86 #endif
87   row_mt_worker_data->num_sbs = num_sbs;
88   for (plane = 0; plane < 3; ++plane) {
89     CHECK_MEM_ERROR(cm, row_mt_worker_data->dqcoeff[plane],
90                     vpx_memalign(16, dqcoeff_size));
91     memset(row_mt_worker_data->dqcoeff[plane], 0, dqcoeff_size);
92     CHECK_MEM_ERROR(cm, row_mt_worker_data->eob[plane],
93                     vpx_calloc(num_sbs << EOBS_PER_SB_LOG2,
94                                sizeof(*row_mt_worker_data->eob[plane])));
95   }
96   CHECK_MEM_ERROR(cm, row_mt_worker_data->partition,
97                   vpx_calloc(num_sbs * PARTITIONS_PER_SB,
98                              sizeof(*row_mt_worker_data->partition)));
99   CHECK_MEM_ERROR(cm, row_mt_worker_data->recon_map,
100                   vpx_calloc(num_sbs, sizeof(*row_mt_worker_data->recon_map)));
101
102   // allocate memory for thread_data
103   if (row_mt_worker_data->thread_data == NULL) {
104     const size_t thread_size =
105         max_threads * sizeof(*row_mt_worker_data->thread_data);
106     CHECK_MEM_ERROR(cm, row_mt_worker_data->thread_data,
107                     vpx_memalign(32, thread_size));
108   }
109 }
110
111 void vp9_dec_free_row_mt_mem(RowMTWorkerData *row_mt_worker_data) {
112   if (row_mt_worker_data != NULL) {
113     int plane;
114 #if CONFIG_MULTITHREAD
115     int i;
116     if (row_mt_worker_data->recon_sync_mutex != NULL) {
117       for (i = 0; i < row_mt_worker_data->num_jobs; ++i) {
118         pthread_mutex_destroy(&row_mt_worker_data->recon_sync_mutex[i]);
119       }
120       vpx_free(row_mt_worker_data->recon_sync_mutex);
121       row_mt_worker_data->recon_sync_mutex = NULL;
122     }
123     if (row_mt_worker_data->recon_sync_cond != NULL) {
124       for (i = 0; i < row_mt_worker_data->num_jobs; ++i) {
125         pthread_cond_destroy(&row_mt_worker_data->recon_sync_cond[i]);
126       }
127       vpx_free(row_mt_worker_data->recon_sync_cond);
128       row_mt_worker_data->recon_sync_cond = NULL;
129     }
130 #endif
131     for (plane = 0; plane < 3; ++plane) {
132       vpx_free(row_mt_worker_data->eob[plane]);
133       row_mt_worker_data->eob[plane] = NULL;
134       vpx_free(row_mt_worker_data->dqcoeff[plane]);
135       row_mt_worker_data->dqcoeff[plane] = NULL;
136     }
137     vpx_free(row_mt_worker_data->partition);
138     row_mt_worker_data->partition = NULL;
139     vpx_free(row_mt_worker_data->recon_map);
140     row_mt_worker_data->recon_map = NULL;
141     vpx_free(row_mt_worker_data->thread_data);
142     row_mt_worker_data->thread_data = NULL;
143   }
144 }
145
146 static int vp9_dec_alloc_mi(VP9_COMMON *cm, int mi_size) {
147   cm->mip = vpx_calloc(mi_size, sizeof(*cm->mip));
148   if (!cm->mip) return 1;
149   cm->mi_alloc_size = mi_size;
150   cm->mi_grid_base = (MODE_INFO **)vpx_calloc(mi_size, sizeof(MODE_INFO *));
151   if (!cm->mi_grid_base) return 1;
152   return 0;
153 }
154
155 static void vp9_dec_free_mi(VP9_COMMON *cm) {
156 #if CONFIG_VP9_POSTPROC
157   // MFQE allocates an additional mip and swaps it with cm->mip.
158   vpx_free(cm->postproc_state.prev_mip);
159   cm->postproc_state.prev_mip = NULL;
160 #endif
161   vpx_free(cm->mip);
162   cm->mip = NULL;
163   vpx_free(cm->mi_grid_base);
164   cm->mi_grid_base = NULL;
165   cm->mi_alloc_size = 0;
166 }
167
168 VP9Decoder *vp9_decoder_create(BufferPool *const pool) {
169   VP9Decoder *volatile const pbi = vpx_memalign(32, sizeof(*pbi));
170   VP9_COMMON *volatile const cm = pbi ? &pbi->common : NULL;
171
172   if (!cm) return NULL;
173
174   vp9_zero(*pbi);
175
176   if (setjmp(cm->error.jmp)) {
177     cm->error.setjmp = 0;
178     vp9_decoder_remove(pbi);
179     return NULL;
180   }
181
182   cm->error.setjmp = 1;
183
184   CHECK_MEM_ERROR(cm, cm->fc, (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc)));
185   CHECK_MEM_ERROR(
186       cm, cm->frame_contexts,
187       (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, sizeof(*cm->frame_contexts)));
188
189   pbi->need_resync = 1;
190   once(initialize_dec);
191
192   // Initialize the references to not point to any frame buffers.
193   memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
194   memset(&cm->next_ref_frame_map, -1, sizeof(cm->next_ref_frame_map));
195
196   init_frame_indexes(cm);
197   pbi->ready_for_new_data = 1;
198   pbi->common.buffer_pool = pool;
199
200   cm->bit_depth = VPX_BITS_8;
201   cm->dequant_bit_depth = VPX_BITS_8;
202
203   cm->alloc_mi = vp9_dec_alloc_mi;
204   cm->free_mi = vp9_dec_free_mi;
205   cm->setup_mi = vp9_dec_setup_mi;
206
207   vp9_loop_filter_init(cm);
208
209   cm->error.setjmp = 0;
210
211   vpx_get_worker_interface()->init(&pbi->lf_worker);
212
213   return pbi;
214 }
215
216 void vp9_decoder_remove(VP9Decoder *pbi) {
217   int i;
218
219   if (!pbi) return;
220
221   vpx_get_worker_interface()->end(&pbi->lf_worker);
222   vpx_free(pbi->lf_worker.data1);
223
224   for (i = 0; i < pbi->num_tile_workers; ++i) {
225     VPxWorker *const worker = &pbi->tile_workers[i];
226     vpx_get_worker_interface()->end(worker);
227   }
228
229   vpx_free(pbi->tile_worker_data);
230   vpx_free(pbi->tile_workers);
231
232   if (pbi->num_tile_workers > 0) {
233     vp9_loop_filter_dealloc(&pbi->lf_row_sync);
234   }
235
236   if (pbi->row_mt == 1) {
237     vp9_dec_free_row_mt_mem(pbi->row_mt_worker_data);
238     if (pbi->row_mt_worker_data != NULL) {
239       vp9_jobq_deinit(&pbi->row_mt_worker_data->jobq);
240       vpx_free(pbi->row_mt_worker_data->jobq_buf);
241 #if CONFIG_MULTITHREAD
242       pthread_mutex_destroy(&pbi->row_mt_worker_data->recon_done_mutex);
243 #endif
244     }
245     vpx_free(pbi->row_mt_worker_data);
246   }
247
248   vp9_remove_common(&pbi->common);
249   vpx_free(pbi);
250 }
251
252 static int equal_dimensions(const YV12_BUFFER_CONFIG *a,
253                             const YV12_BUFFER_CONFIG *b) {
254   return a->y_height == b->y_height && a->y_width == b->y_width &&
255          a->uv_height == b->uv_height && a->uv_width == b->uv_width;
256 }
257
258 vpx_codec_err_t vp9_copy_reference_dec(VP9Decoder *pbi,
259                                        VP9_REFFRAME ref_frame_flag,
260                                        YV12_BUFFER_CONFIG *sd) {
261   VP9_COMMON *cm = &pbi->common;
262
263   /* TODO(jkoleszar): The decoder doesn't have any real knowledge of what the
264    * encoder is using the frame buffers for. This is just a stub to keep the
265    * vpxenc --test-decode functionality working, and will be replaced in a
266    * later commit that adds VP9-specific controls for this functionality.
267    */
268   if (ref_frame_flag == VP9_LAST_FLAG) {
269     const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, 0);
270     if (cfg == NULL) {
271       vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
272                          "No 'last' reference frame");
273       return VPX_CODEC_ERROR;
274     }
275     if (!equal_dimensions(cfg, sd))
276       vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
277                          "Incorrect buffer dimensions");
278     else
279       vpx_yv12_copy_frame(cfg, sd);
280   } else {
281     vpx_internal_error(&cm->error, VPX_CODEC_ERROR, "Invalid reference frame");
282   }
283
284   return cm->error.error_code;
285 }
286
287 vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
288                                       VP9_REFFRAME ref_frame_flag,
289                                       YV12_BUFFER_CONFIG *sd) {
290   int idx;
291   YV12_BUFFER_CONFIG *ref_buf = NULL;
292
293   // TODO(jkoleszar): The decoder doesn't have any real knowledge of what the
294   // encoder is using the frame buffers for. This is just a stub to keep the
295   // vpxenc --test-decode functionality working, and will be replaced in a
296   // later commit that adds VP9-specific controls for this functionality.
297   // (Yunqing) The set_reference control depends on the following setting in
298   // encoder.
299   // cpi->lst_fb_idx = 0;
300   // cpi->gld_fb_idx = 1;
301   // cpi->alt_fb_idx = 2;
302   if (ref_frame_flag == VP9_LAST_FLAG) {
303     idx = cm->ref_frame_map[0];
304   } else if (ref_frame_flag == VP9_GOLD_FLAG) {
305     idx = cm->ref_frame_map[1];
306   } else if (ref_frame_flag == VP9_ALT_FLAG) {
307     idx = cm->ref_frame_map[2];
308   } else {
309     vpx_internal_error(&cm->error, VPX_CODEC_ERROR, "Invalid reference frame");
310     return cm->error.error_code;
311   }
312
313   if (idx < 0 || idx >= FRAME_BUFFERS) {
314     vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
315                        "Invalid reference frame map");
316     return cm->error.error_code;
317   }
318
319   // Get the destination reference buffer.
320   ref_buf = &cm->buffer_pool->frame_bufs[idx].buf;
321
322   if (!equal_dimensions(ref_buf, sd)) {
323     vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
324                        "Incorrect buffer dimensions");
325   } else {
326     // Overwrite the reference frame buffer.
327     vpx_yv12_copy_frame(sd, ref_buf);
328   }
329
330   return cm->error.error_code;
331 }
332
333 /* If any buffer updating is signaled it should be done here. */
334 static void swap_frame_buffers(VP9Decoder *pbi) {
335   int ref_index = 0, mask;
336   VP9_COMMON *const cm = &pbi->common;
337   BufferPool *const pool = cm->buffer_pool;
338   RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
339
340   for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
341     const int old_idx = cm->ref_frame_map[ref_index];
342     // Current thread releases the holding of reference frame.
343     decrease_ref_count(old_idx, frame_bufs, pool);
344
345     // Release the reference frame in reference map.
346     if (mask & 1) {
347       decrease_ref_count(old_idx, frame_bufs, pool);
348     }
349     cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
350     ++ref_index;
351   }
352
353   // Current thread releases the holding of reference frame.
354   for (; ref_index < REF_FRAMES && !cm->show_existing_frame; ++ref_index) {
355     const int old_idx = cm->ref_frame_map[ref_index];
356     decrease_ref_count(old_idx, frame_bufs, pool);
357     cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
358   }
359   pbi->hold_ref_buf = 0;
360   cm->frame_to_show = get_frame_new_buffer(cm);
361
362   --frame_bufs[cm->new_fb_idx].ref_count;
363
364   // Invalidate these references until the next frame starts.
365   for (ref_index = 0; ref_index < 3; ref_index++)
366     cm->frame_refs[ref_index].idx = -1;
367 }
368
369 static void release_fb_on_decoder_exit(VP9Decoder *pbi) {
370   const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
371   VP9_COMMON *volatile const cm = &pbi->common;
372   BufferPool *volatile const pool = cm->buffer_pool;
373   RefCntBuffer *volatile const frame_bufs = cm->buffer_pool->frame_bufs;
374   int i;
375
376   // Synchronize all threads immediately as a subsequent decode call may
377   // cause a resize invalidating some allocations.
378   winterface->sync(&pbi->lf_worker);
379   for (i = 0; i < pbi->num_tile_workers; ++i) {
380     winterface->sync(&pbi->tile_workers[i]);
381   }
382
383   // Release all the reference buffers if worker thread is holding them.
384   if (pbi->hold_ref_buf == 1) {
385     int ref_index = 0, mask;
386     for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
387       const int old_idx = cm->ref_frame_map[ref_index];
388       // Current thread releases the holding of reference frame.
389       decrease_ref_count(old_idx, frame_bufs, pool);
390
391       // Release the reference frame in reference map.
392       if (mask & 1) {
393         decrease_ref_count(old_idx, frame_bufs, pool);
394       }
395       ++ref_index;
396     }
397
398     // Current thread releases the holding of reference frame.
399     for (; ref_index < REF_FRAMES && !cm->show_existing_frame; ++ref_index) {
400       const int old_idx = cm->ref_frame_map[ref_index];
401       decrease_ref_count(old_idx, frame_bufs, pool);
402     }
403     pbi->hold_ref_buf = 0;
404   }
405 }
406
407 int vp9_receive_compressed_data(VP9Decoder *pbi, size_t size,
408                                 const uint8_t **psource) {
409   VP9_COMMON *volatile const cm = &pbi->common;
410   BufferPool *volatile const pool = cm->buffer_pool;
411   RefCntBuffer *volatile const frame_bufs = cm->buffer_pool->frame_bufs;
412   const uint8_t *source = *psource;
413   int retcode = 0;
414   cm->error.error_code = VPX_CODEC_OK;
415
416   if (size == 0) {
417     // This is used to signal that we are missing frames.
418     // We do not know if the missing frame(s) was supposed to update
419     // any of the reference buffers, but we act conservative and
420     // mark only the last buffer as corrupted.
421     //
422     // TODO(jkoleszar): Error concealment is undefined and non-normative
423     // at this point, but if it becomes so, [0] may not always be the correct
424     // thing to do here.
425     if (cm->frame_refs[0].idx > 0) {
426       assert(cm->frame_refs[0].buf != NULL);
427       cm->frame_refs[0].buf->corrupted = 1;
428     }
429   }
430
431   pbi->ready_for_new_data = 0;
432
433   // Check if the previous frame was a frame without any references to it.
434   if (cm->new_fb_idx >= 0 && frame_bufs[cm->new_fb_idx].ref_count == 0 &&
435       !frame_bufs[cm->new_fb_idx].released) {
436     pool->release_fb_cb(pool->cb_priv,
437                         &frame_bufs[cm->new_fb_idx].raw_frame_buffer);
438     frame_bufs[cm->new_fb_idx].released = 1;
439   }
440
441   // Find a free frame buffer. Return error if can not find any.
442   cm->new_fb_idx = get_free_fb(cm);
443   if (cm->new_fb_idx == INVALID_IDX) {
444     pbi->ready_for_new_data = 1;
445     release_fb_on_decoder_exit(pbi);
446     vpx_clear_system_state();
447     vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
448                        "Unable to find free frame buffer");
449     return cm->error.error_code;
450   }
451
452   // Assign a MV array to the frame buffer.
453   cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
454
455   pbi->hold_ref_buf = 0;
456   pbi->cur_buf = &frame_bufs[cm->new_fb_idx];
457
458   if (setjmp(cm->error.jmp)) {
459     cm->error.setjmp = 0;
460     pbi->ready_for_new_data = 1;
461     release_fb_on_decoder_exit(pbi);
462     // Release current frame.
463     decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
464     vpx_clear_system_state();
465     return -1;
466   }
467
468   cm->error.setjmp = 1;
469   vp9_decode_frame(pbi, source, source + size, psource);
470
471   swap_frame_buffers(pbi);
472
473   vpx_clear_system_state();
474
475   if (!cm->show_existing_frame) {
476     cm->last_show_frame = cm->show_frame;
477     cm->prev_frame = cm->cur_frame;
478     if (cm->seg.enabled) vp9_swap_current_and_last_seg_map(cm);
479   }
480
481   if (cm->show_frame) cm->cur_show_frame_fb_idx = cm->new_fb_idx;
482
483   // Update progress in frame parallel decode.
484   cm->last_width = cm->width;
485   cm->last_height = cm->height;
486   if (cm->show_frame) {
487     cm->current_video_frame++;
488   }
489
490   cm->error.setjmp = 0;
491   return retcode;
492 }
493
494 int vp9_get_raw_frame(VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
495                       vp9_ppflags_t *flags) {
496   VP9_COMMON *const cm = &pbi->common;
497   int ret = -1;
498 #if !CONFIG_VP9_POSTPROC
499   (void)*flags;
500 #endif
501
502   if (pbi->ready_for_new_data == 1) return ret;
503
504   pbi->ready_for_new_data = 1;
505
506   /* no raw frame to show!!! */
507   if (!cm->show_frame) return ret;
508
509   pbi->ready_for_new_data = 1;
510
511 #if CONFIG_VP9_POSTPROC
512   if (!cm->show_existing_frame) {
513     ret = vp9_post_proc_frame(cm, sd, flags, cm->width);
514   } else {
515     *sd = *cm->frame_to_show;
516     ret = 0;
517   }
518 #else
519   *sd = *cm->frame_to_show;
520   ret = 0;
521 #endif /*!CONFIG_POSTPROC*/
522   vpx_clear_system_state();
523   return ret;
524 }
525
526 vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data, size_t data_sz,
527                                            uint32_t sizes[8], int *count,
528                                            vpx_decrypt_cb decrypt_cb,
529                                            void *decrypt_state) {
530   // A chunk ending with a byte matching 0xc0 is an invalid chunk unless
531   // it is a super frame index. If the last byte of real video compression
532   // data is 0xc0 the encoder must add a 0 byte. If we have the marker but
533   // not the associated matching marker byte at the front of the index we have
534   // an invalid bitstream and need to return an error.
535
536   uint8_t marker;
537
538   assert(data_sz);
539   marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1);
540   *count = 0;
541
542   if ((marker & 0xe0) == 0xc0) {
543     const uint32_t frames = (marker & 0x7) + 1;
544     const uint32_t mag = ((marker >> 3) & 0x3) + 1;
545     const size_t index_sz = 2 + mag * frames;
546
547     // This chunk is marked as having a superframe index but doesn't have
548     // enough data for it, thus it's an invalid superframe index.
549     if (data_sz < index_sz) return VPX_CODEC_CORRUPT_FRAME;
550
551     {
552       const uint8_t marker2 =
553           read_marker(decrypt_cb, decrypt_state, data + data_sz - index_sz);
554
555       // This chunk is marked as having a superframe index but doesn't have
556       // the matching marker byte at the front of the index therefore it's an
557       // invalid chunk.
558       if (marker != marker2) return VPX_CODEC_CORRUPT_FRAME;
559     }
560
561     {
562       // Found a valid superframe index.
563       uint32_t i, j;
564       const uint8_t *x = &data[data_sz - index_sz + 1];
565
566       // Frames has a maximum of 8 and mag has a maximum of 4.
567       uint8_t clear_buffer[32];
568       assert(sizeof(clear_buffer) >= frames * mag);
569       if (decrypt_cb) {
570         decrypt_cb(decrypt_state, x, clear_buffer, frames * mag);
571         x = clear_buffer;
572       }
573
574       for (i = 0; i < frames; ++i) {
575         uint32_t this_sz = 0;
576
577         for (j = 0; j < mag; ++j) this_sz |= ((uint32_t)(*x++)) << (j * 8);
578         sizes[i] = this_sz;
579       }
580       *count = frames;
581     }
582   }
583   return VPX_CODEC_OK;
584 }