vpx: Use new gst_video_decoder_set_needs_format() API
[platform/upstream/gst-plugins-good.git] / ext / vpx / gstvp9dec.c
1 /* VP9
2  * Copyright (C) 2006 David Schleef <ds@schleef.org>
3  * Copyright (C) 2008,2009,2010 Entropy Wave Inc
4  * Copyright (C) 2010-2013 Sebastian Dröge <slomo@circular-chaos.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 /**
23  * SECTION:element-vp9dec
24  * @see_also: vp9enc, matroskademux
25  *
26  * This element decodes VP9 streams into raw video.
27  * <ulink url="http://www.webmproject.org">VP9</ulink> is a royalty-free
28  * video codec maintained by <ulink url="http://www.google.com/">Google
29  * </ulink>. It's the successor of On2 VP3, which was the base of the
30  * Theora video codec.
31  *
32  * <refsect2>
33  * <title>Example pipeline</title>
34  * |[
35  * gst-launch -v filesrc location=videotestsrc.webm ! matroskademux ! vp9dec ! xvimagesink
36  * ]| This example pipeline will decode a WebM stream and decodes the VP9 video.
37  * </refsect2>
38  */
39
40 #ifdef HAVE_CONFIG_H
41 #include "config.h"
42 #endif
43
44 #ifdef HAVE_VP9_DECODER
45
46 #include <string.h>
47
48 #include "gstvp8utils.h"
49 #include "gstvp9dec.h"
50
51 #include <gst/video/gstvideometa.h>
52 #include <gst/video/gstvideopool.h>
53
54 GST_DEBUG_CATEGORY_STATIC (gst_vp9dec_debug);
55 #define GST_CAT_DEFAULT gst_vp9dec_debug
56
57 #define DEFAULT_POST_PROCESSING FALSE
58 #define DEFAULT_POST_PROCESSING_FLAGS (VP8_DEBLOCK | VP8_DEMACROBLOCK)
59 #define DEFAULT_DEBLOCKING_LEVEL 4
60 #define DEFAULT_NOISE_LEVEL 0
61 #define DEFAULT_THREADS 1
62
63 enum
64 {
65   PROP_0,
66   PROP_POST_PROCESSING,
67   PROP_POST_PROCESSING_FLAGS,
68   PROP_DEBLOCKING_LEVEL,
69   PROP_NOISE_LEVEL,
70   PROP_THREADS
71 };
72
73 #define C_FLAGS(v) ((guint) v)
74 #define GST_VP9_DEC_TYPE_POST_PROCESSING_FLAGS (gst_vp9_dec_post_processing_flags_get_type())
75 static GType
76 gst_vp9_dec_post_processing_flags_get_type (void)
77 {
78   static const GFlagsValue values[] = {
79     {C_FLAGS (VP8_DEBLOCK), "Deblock", "deblock"},
80     {C_FLAGS (VP8_DEMACROBLOCK), "Demacroblock", "demacroblock"},
81     {C_FLAGS (VP8_ADDNOISE), "Add noise", "addnoise"},
82     {C_FLAGS (VP8_MFQE), "Multi-frame quality enhancement", "mfqe"},
83     {0, NULL, NULL}
84   };
85   static volatile GType id = 0;
86
87   if (g_once_init_enter ((gsize *) & id)) {
88     GType _id;
89
90     _id = g_flags_register_static ("GstVP9DecPostProcessingFlags", values);
91
92     g_once_init_leave ((gsize *) & id, _id);
93   }
94
95   return id;
96 }
97
98 #undef C_FLAGS
99
100 static void gst_vp9_dec_set_property (GObject * object, guint prop_id,
101     const GValue * value, GParamSpec * pspec);
102 static void gst_vp9_dec_get_property (GObject * object, guint prop_id,
103     GValue * value, GParamSpec * pspec);
104
105 static gboolean gst_vp9_dec_start (GstVideoDecoder * decoder);
106 static gboolean gst_vp9_dec_stop (GstVideoDecoder * decoder);
107 static gboolean gst_vp9_dec_set_format (GstVideoDecoder * decoder,
108     GstVideoCodecState * state);
109 static gboolean gst_vp9_dec_flush (GstVideoDecoder * decoder);
110 static GstFlowReturn gst_vp9_dec_handle_frame (GstVideoDecoder * decoder,
111     GstVideoCodecFrame * frame);
112 static gboolean gst_vp9_dec_decide_allocation (GstVideoDecoder * decoder,
113     GstQuery * query);
114
115 static GstStaticPadTemplate gst_vp9_dec_sink_template =
116 GST_STATIC_PAD_TEMPLATE ("sink",
117     GST_PAD_SINK,
118     GST_PAD_ALWAYS,
119     GST_STATIC_CAPS ("video/x-vp9")
120     );
121
122 static GstStaticPadTemplate gst_vp9_dec_src_template =
123 GST_STATIC_PAD_TEMPLATE ("src",
124     GST_PAD_SRC,
125     GST_PAD_ALWAYS,
126     GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ I420, YV12, Y42B, Y444 }"))
127     );
128
129 #define parent_class gst_vp9_dec_parent_class
130 G_DEFINE_TYPE (GstVP9Dec, gst_vp9_dec, GST_TYPE_VIDEO_DECODER);
131
132 static void
133 gst_vp9_dec_class_init (GstVP9DecClass * klass)
134 {
135   GObjectClass *gobject_class;
136   GstElementClass *element_class;
137   GstVideoDecoderClass *base_video_decoder_class;
138
139   gobject_class = G_OBJECT_CLASS (klass);
140   element_class = GST_ELEMENT_CLASS (klass);
141   base_video_decoder_class = GST_VIDEO_DECODER_CLASS (klass);
142
143   gobject_class->set_property = gst_vp9_dec_set_property;
144   gobject_class->get_property = gst_vp9_dec_get_property;
145
146   g_object_class_install_property (gobject_class, PROP_POST_PROCESSING,
147       g_param_spec_boolean ("post-processing", "Post Processing",
148           "Enable post processing", DEFAULT_POST_PROCESSING,
149           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
150
151   g_object_class_install_property (gobject_class, PROP_POST_PROCESSING_FLAGS,
152       g_param_spec_flags ("post-processing-flags", "Post Processing Flags",
153           "Flags to control post processing",
154           GST_VP9_DEC_TYPE_POST_PROCESSING_FLAGS, DEFAULT_POST_PROCESSING_FLAGS,
155           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
156
157   g_object_class_install_property (gobject_class, PROP_DEBLOCKING_LEVEL,
158       g_param_spec_uint ("deblocking-level", "Deblocking Level",
159           "Deblocking level",
160           0, 16, DEFAULT_DEBLOCKING_LEVEL,
161           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
162
163   g_object_class_install_property (gobject_class, PROP_NOISE_LEVEL,
164       g_param_spec_uint ("noise-level", "Noise Level",
165           "Noise level",
166           0, 16, DEFAULT_NOISE_LEVEL,
167           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
168
169   g_object_class_install_property (gobject_class, PROP_THREADS,
170       g_param_spec_uint ("threads", "Max Threads",
171           "Maximum number of decoding threads",
172           1, 16, DEFAULT_THREADS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
173
174   gst_element_class_add_pad_template (element_class,
175       gst_static_pad_template_get (&gst_vp9_dec_src_template));
176   gst_element_class_add_pad_template (element_class,
177       gst_static_pad_template_get (&gst_vp9_dec_sink_template));
178
179   gst_element_class_set_static_metadata (element_class,
180       "On2 VP9 Decoder",
181       "Codec/Decoder/Video",
182       "Decode VP9 video streams", "David Schleef <ds@entropywave.com>, "
183       "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
184
185   base_video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_vp9_dec_start);
186   base_video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_vp9_dec_stop);
187   base_video_decoder_class->flush = GST_DEBUG_FUNCPTR (gst_vp9_dec_flush);
188   base_video_decoder_class->set_format =
189       GST_DEBUG_FUNCPTR (gst_vp9_dec_set_format);
190   base_video_decoder_class->handle_frame =
191       GST_DEBUG_FUNCPTR (gst_vp9_dec_handle_frame);
192   base_video_decoder_class->decide_allocation = gst_vp9_dec_decide_allocation;
193
194   GST_DEBUG_CATEGORY_INIT (gst_vp9dec_debug, "vp9dec", 0, "VP9 Decoder");
195 }
196
197 static void
198 gst_vp9_dec_init (GstVP9Dec * gst_vp9_dec)
199 {
200   GstVideoDecoder *decoder = (GstVideoDecoder *) gst_vp9_dec;
201
202   GST_DEBUG_OBJECT (gst_vp9_dec, "gst_vp9_dec_init");
203   gst_video_decoder_set_packetized (decoder, TRUE);
204   gst_vp9_dec->post_processing = DEFAULT_POST_PROCESSING;
205   gst_vp9_dec->post_processing_flags = DEFAULT_POST_PROCESSING_FLAGS;
206   gst_vp9_dec->deblocking_level = DEFAULT_DEBLOCKING_LEVEL;
207   gst_vp9_dec->noise_level = DEFAULT_NOISE_LEVEL;
208
209   gst_video_decoder_set_needs_format (decoder, TRUE);
210 }
211
212 static void
213 gst_vp9_dec_set_property (GObject * object, guint prop_id,
214     const GValue * value, GParamSpec * pspec)
215 {
216   GstVP9Dec *dec;
217
218   g_return_if_fail (GST_IS_VP9_DEC (object));
219   dec = GST_VP9_DEC (object);
220
221   GST_DEBUG_OBJECT (object, "gst_vp9_dec_set_property");
222   switch (prop_id) {
223     case PROP_POST_PROCESSING:
224       dec->post_processing = g_value_get_boolean (value);
225       break;
226     case PROP_POST_PROCESSING_FLAGS:
227       dec->post_processing_flags = g_value_get_flags (value);
228       break;
229     case PROP_DEBLOCKING_LEVEL:
230       dec->deblocking_level = g_value_get_uint (value);
231       break;
232     case PROP_NOISE_LEVEL:
233       dec->noise_level = g_value_get_uint (value);
234       break;
235     case PROP_THREADS:
236       dec->threads = g_value_get_uint (value);
237       break;
238     default:
239       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
240       break;
241   }
242 }
243
244 static void
245 gst_vp9_dec_get_property (GObject * object, guint prop_id, GValue * value,
246     GParamSpec * pspec)
247 {
248   GstVP9Dec *dec;
249
250   g_return_if_fail (GST_IS_VP9_DEC (object));
251   dec = GST_VP9_DEC (object);
252
253   switch (prop_id) {
254     case PROP_POST_PROCESSING:
255       g_value_set_boolean (value, dec->post_processing);
256       break;
257     case PROP_POST_PROCESSING_FLAGS:
258       g_value_set_flags (value, dec->post_processing_flags);
259       break;
260     case PROP_DEBLOCKING_LEVEL:
261       g_value_set_uint (value, dec->deblocking_level);
262       break;
263     case PROP_NOISE_LEVEL:
264       g_value_set_uint (value, dec->noise_level);
265       break;
266     case PROP_THREADS:
267       g_value_set_uint (value, dec->threads);
268       break;
269     default:
270       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
271       break;
272   }
273 }
274
275 static gboolean
276 gst_vp9_dec_start (GstVideoDecoder * decoder)
277 {
278   GstVP9Dec *gst_vp9_dec = GST_VP9_DEC (decoder);
279
280   GST_DEBUG_OBJECT (gst_vp9_dec, "start");
281   gst_vp9_dec->decoder_inited = FALSE;
282
283   return TRUE;
284 }
285
286 static gboolean
287 gst_vp9_dec_stop (GstVideoDecoder * base_video_decoder)
288 {
289   GstVP9Dec *gst_vp9_dec = GST_VP9_DEC (base_video_decoder);
290
291   GST_DEBUG_OBJECT (gst_vp9_dec, "stop");
292
293   if (gst_vp9_dec->output_state) {
294     gst_video_codec_state_unref (gst_vp9_dec->output_state);
295     gst_vp9_dec->output_state = NULL;
296   }
297
298   if (gst_vp9_dec->input_state) {
299     gst_video_codec_state_unref (gst_vp9_dec->input_state);
300     gst_vp9_dec->input_state = NULL;
301   }
302
303   if (gst_vp9_dec->decoder_inited)
304     vpx_codec_destroy (&gst_vp9_dec->decoder);
305   gst_vp9_dec->decoder_inited = FALSE;
306
307   return TRUE;
308 }
309
310 static gboolean
311 gst_vp9_dec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
312 {
313   GstVP9Dec *gst_vp9_dec = GST_VP9_DEC (decoder);
314
315   GST_DEBUG_OBJECT (gst_vp9_dec, "set_format");
316
317   if (gst_vp9_dec->decoder_inited)
318     vpx_codec_destroy (&gst_vp9_dec->decoder);
319   gst_vp9_dec->decoder_inited = FALSE;
320
321   if (gst_vp9_dec->input_state)
322     gst_video_codec_state_unref (gst_vp9_dec->input_state);
323   gst_vp9_dec->input_state = gst_video_codec_state_ref (state);
324
325   return TRUE;
326 }
327
328 static gboolean
329 gst_vp9_dec_flush (GstVideoDecoder * base_video_decoder)
330 {
331   GstVP9Dec *decoder;
332
333   GST_DEBUG_OBJECT (base_video_decoder, "flush");
334
335   decoder = GST_VP9_DEC (base_video_decoder);
336
337   if (decoder->output_state) {
338     gst_video_codec_state_unref (decoder->output_state);
339     decoder->output_state = NULL;
340   }
341
342   if (decoder->decoder_inited)
343     vpx_codec_destroy (&decoder->decoder);
344   decoder->decoder_inited = FALSE;
345
346   return TRUE;
347 }
348
349 static void
350 gst_vp9_dec_send_tags (GstVP9Dec * dec)
351 {
352   GstTagList *list;
353
354   list = gst_tag_list_new_empty ();
355   gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
356       GST_TAG_VIDEO_CODEC, "VP9 video", NULL);
357
358   gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (dec),
359       gst_event_new_tag (list));
360 }
361
362 static void
363 gst_vp9_dec_image_to_buffer (GstVP9Dec * dec, const vpx_image_t * img,
364     GstBuffer * buffer)
365 {
366   int deststride, srcstride, height, width, line, comp;
367   guint8 *dest, *src;
368   GstVideoFrame frame;
369   GstVideoInfo *info = &dec->output_state->info;
370
371   if (!gst_video_frame_map (&frame, info, buffer, GST_MAP_WRITE)) {
372     GST_ERROR_OBJECT (dec, "Could not map video buffer");
373   }
374
375   for (comp = 0; comp < 3; comp++) {
376     dest = GST_VIDEO_FRAME_COMP_DATA (&frame, comp);
377     src = img->planes[comp];
378     width = GST_VIDEO_FRAME_COMP_WIDTH (&frame, comp);
379     height = GST_VIDEO_FRAME_COMP_HEIGHT (&frame, comp);
380     deststride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, comp);
381     srcstride = img->stride[comp];
382
383     /* FIXME (Edward) : Do a plane memcpy is srcstride == deststride instead
384      * of copying line by line */
385     for (line = 0; line < height; line++) {
386       memcpy (dest, src, width);
387       dest += deststride;
388       src += srcstride;
389     }
390   }
391
392   gst_video_frame_unmap (&frame);
393 }
394
395 static GstFlowReturn
396 open_codec (GstVP9Dec * dec, GstVideoCodecFrame * frame)
397 {
398   int flags = 0;
399   vpx_codec_stream_info_t stream_info;
400   vpx_codec_caps_t caps;
401   vpx_codec_dec_cfg_t cfg;
402   vpx_codec_err_t status;
403   GstMapInfo minfo;
404
405   memset (&stream_info, 0, sizeof (stream_info));
406   memset (&cfg, 0, sizeof (cfg));
407   stream_info.sz = sizeof (stream_info);
408
409   if (!gst_buffer_map (frame->input_buffer, &minfo, GST_MAP_READ)) {
410     GST_ERROR_OBJECT (dec, "Failed to map input buffer");
411     return GST_FLOW_ERROR;
412   }
413
414   status = vpx_codec_peek_stream_info (&vpx_codec_vp9_dx_algo,
415       minfo.data, minfo.size, &stream_info);
416
417   gst_buffer_unmap (frame->input_buffer, &minfo);
418
419   if (status != VPX_CODEC_OK) {
420     GST_WARNING_OBJECT (dec, "VPX preprocessing error: %s",
421         gst_vpx_error_name (status));
422     gst_video_decoder_finish_frame (GST_VIDEO_DECODER (dec), frame);
423     return GST_FLOW_CUSTOM_SUCCESS_1;
424   }
425   if (!stream_info.is_kf) {
426     GST_WARNING_OBJECT (dec, "No keyframe, skipping");
427     gst_video_decoder_finish_frame (GST_VIDEO_DECODER (dec), frame);
428     return GST_FLOW_CUSTOM_SUCCESS_1;
429   }
430
431   /* FIXME: peek_stream_info() does not return valid values, take input caps */
432   stream_info.w = dec->input_state->info.width;
433   stream_info.h = dec->input_state->info.height;
434
435   cfg.w = stream_info.w;
436   cfg.h = stream_info.h;
437   cfg.threads = dec->threads;
438
439   caps = vpx_codec_get_caps (&vpx_codec_vp9_dx_algo);
440
441   if (dec->post_processing) {
442     if (!(caps & VPX_CODEC_CAP_POSTPROC)) {
443       GST_WARNING_OBJECT (dec, "Decoder does not support post processing");
444     } else {
445       flags |= VPX_CODEC_USE_POSTPROC;
446     }
447   }
448
449   status =
450       vpx_codec_dec_init (&dec->decoder, &vpx_codec_vp9_dx_algo, &cfg, flags);
451   if (status != VPX_CODEC_OK) {
452     GST_ELEMENT_ERROR (dec, LIBRARY, INIT,
453         ("Failed to initialize VP9 decoder"), ("%s",
454             gst_vpx_error_name (status)));
455     return GST_FLOW_ERROR;
456   }
457
458   if ((caps & VPX_CODEC_CAP_POSTPROC) && dec->post_processing) {
459     vp8_postproc_cfg_t pp_cfg = { 0, };
460
461     pp_cfg.post_proc_flag = dec->post_processing_flags;
462     pp_cfg.deblocking_level = dec->deblocking_level;
463     pp_cfg.noise_level = dec->noise_level;
464
465     status = vpx_codec_control (&dec->decoder, VP8_SET_POSTPROC, &pp_cfg);
466     if (status != VPX_CODEC_OK) {
467       GST_WARNING_OBJECT (dec, "Couldn't set postprocessing settings: %s",
468           gst_vpx_error_name (status));
469     }
470   }
471
472   dec->decoder_inited = TRUE;
473
474   return GST_FLOW_OK;
475 }
476
477 static GstFlowReturn
478 gst_vp9_dec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
479 {
480   GstVP9Dec *dec;
481   GstFlowReturn ret = GST_FLOW_OK;
482   vpx_codec_err_t status;
483   vpx_codec_iter_t iter = NULL;
484   vpx_image_t *img;
485   long decoder_deadline = 0;
486   GstClockTimeDiff deadline;
487   GstMapInfo minfo;
488
489   GST_DEBUG_OBJECT (decoder, "handle_frame");
490
491   dec = GST_VP9_DEC (decoder);
492
493   if (!dec->decoder_inited) {
494     ret = open_codec (dec, frame);
495     if (ret == GST_FLOW_CUSTOM_SUCCESS_1)
496       return GST_FLOW_OK;
497     else if (ret != GST_FLOW_OK)
498       return ret;
499   }
500
501   deadline = gst_video_decoder_get_max_decode_time (decoder, frame);
502   if (deadline < 0) {
503     decoder_deadline = 1;
504   } else if (deadline == G_MAXINT64) {
505     decoder_deadline = 0;
506   } else {
507     decoder_deadline = MAX (1, deadline / GST_MSECOND);
508   }
509
510   if (!gst_buffer_map (frame->input_buffer, &minfo, GST_MAP_READ)) {
511     GST_ERROR_OBJECT (dec, "Failed to map input buffer");
512     return GST_FLOW_ERROR;
513   }
514
515   status = vpx_codec_decode (&dec->decoder,
516       minfo.data, minfo.size, NULL, decoder_deadline);
517
518   gst_buffer_unmap (frame->input_buffer, &minfo);
519
520   if (status) {
521     GST_VIDEO_DECODER_ERROR (decoder, 1, LIBRARY, ENCODE,
522         ("Failed to decode frame"), ("%s", gst_vpx_error_name (status)), ret);
523     return ret;
524   }
525
526   img = vpx_codec_get_frame (&dec->decoder, &iter);
527   if (img) {
528     GstVideoFormat fmt;
529
530     switch (img->fmt) {
531       case VPX_IMG_FMT_I420:
532         fmt = GST_VIDEO_FORMAT_I420;
533         break;
534       case VPX_IMG_FMT_YV12:
535         fmt = GST_VIDEO_FORMAT_YV12;
536         break;
537       case VPX_IMG_FMT_I422:
538         fmt = GST_VIDEO_FORMAT_Y42B;
539         break;
540       case VPX_IMG_FMT_I444:
541         fmt = GST_VIDEO_FORMAT_Y444;
542         break;
543       default:
544         vpx_img_free (img);
545         GST_ELEMENT_ERROR (decoder, LIBRARY, ENCODE,
546             ("Failed to decode frame"), ("Unsupported color format %d",
547                 img->fmt));
548         return GST_FLOW_ERROR;
549         break;
550     }
551
552     /* FIXME: Width/height in the img is wrong */
553     if (!dec->output_state || dec->output_state->info.finfo->format != fmt      /*||
554                                                                                    dec->output_state->info.width != img->w ||
555                                                                                    dec->output_state->info.height != img->h */ ) {
556       gboolean send_tags = !dec->output_state;
557
558       if (dec->output_state)
559         gst_video_codec_state_unref (dec->output_state);
560
561       /* FIXME: The width/height in the img is wrong */
562       dec->output_state =
563           gst_video_decoder_set_output_state (GST_VIDEO_DECODER (dec),
564           fmt, dec->input_state->info.width, dec->input_state->info.height,
565           dec->input_state);
566       gst_video_decoder_negotiate (GST_VIDEO_DECODER (dec));
567
568       if (send_tags)
569         gst_vp9_dec_send_tags (dec);
570     }
571
572     if (deadline < 0) {
573       GST_LOG_OBJECT (dec, "Skipping late frame (%f s past deadline)",
574           (double) -deadline / GST_SECOND);
575       gst_video_decoder_drop_frame (decoder, frame);
576     } else {
577       ret = gst_video_decoder_allocate_output_frame (decoder, frame);
578
579       if (ret == GST_FLOW_OK) {
580         gst_vp9_dec_image_to_buffer (dec, img, frame->output_buffer);
581         ret = gst_video_decoder_finish_frame (decoder, frame);
582       } else {
583         gst_video_decoder_finish_frame (decoder, frame);
584       }
585     }
586
587     vpx_img_free (img);
588
589     while ((img = vpx_codec_get_frame (&dec->decoder, &iter))) {
590       GST_WARNING_OBJECT (decoder, "Multiple decoded frames... dropping");
591       vpx_img_free (img);
592     }
593   } else {
594     /* Invisible frame */
595     GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY (frame);
596     gst_video_decoder_finish_frame (decoder, frame);
597   }
598
599   return ret;
600 }
601
602 static gboolean
603 gst_vp9_dec_decide_allocation (GstVideoDecoder * bdec, GstQuery * query)
604 {
605   GstBufferPool *pool;
606   GstStructure *config;
607
608   if (!GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (bdec, query))
609     return FALSE;
610
611   g_assert (gst_query_get_n_allocation_pools (query) > 0);
612   gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
613   g_assert (pool != NULL);
614
615   config = gst_buffer_pool_get_config (pool);
616   if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
617     gst_buffer_pool_config_add_option (config,
618         GST_BUFFER_POOL_OPTION_VIDEO_META);
619   }
620   gst_buffer_pool_set_config (pool, config);
621   gst_object_unref (pool);
622
623   return TRUE;
624 }
625
626 #endif /* HAVE_VP9_DECODER */