2 * Copyright (C) 2006 David Schleef <ds@schleef.org>
3 * Copyright (C) 2008,2009,2010 Entropy Wave Inc
4 * Copyright (C) 2010-2012 Sebastian Dröge <sebastian.droege@collabora.co.uk>
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.
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.
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.
25 #if defined(HAVE_VP8_DECODER) || defined(HAVE_VP9_DECODER)
29 #include "gstvpxdec.h"
30 #include "gstvp8utils.h"
32 #include <gst/video/gstvideometa.h>
33 #include <gst/video/gstvideopool.h>
35 GST_DEBUG_CATEGORY_STATIC (gst_vpxdec_debug);
36 #define GST_CAT_DEFAULT gst_vpxdec_debug
38 #define DEFAULT_POST_PROCESSING FALSE
39 #define DEFAULT_POST_PROCESSING_FLAGS (VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE)
40 #define DEFAULT_DEBLOCKING_LEVEL 4
41 #define DEFAULT_NOISE_LEVEL 0
42 #define DEFAULT_THREADS 0
43 #define DEFAULT_VIDEO_CODEC_TAG NULL
44 #define DEFAULT_CODEC_ALGO NULL
50 PROP_POST_PROCESSING_FLAGS,
51 PROP_DEBLOCKING_LEVEL,
56 #define C_FLAGS(v) ((guint) v)
57 #define GST_VPX_DEC_TYPE_POST_PROCESSING_FLAGS (gst_vpx_dec_post_processing_flags_get_type())
59 gst_vpx_dec_post_processing_flags_get_type (void)
61 static const GFlagsValue values[] = {
62 {C_FLAGS (VP8_DEBLOCK), "Deblock", "deblock"},
63 {C_FLAGS (VP8_DEMACROBLOCK), "Demacroblock", "demacroblock"},
64 {C_FLAGS (VP8_ADDNOISE), "Add noise", "addnoise"},
65 {C_FLAGS (VP8_MFQE), "Multi-frame quality enhancement", "mfqe"},
68 static volatile GType id = 0;
70 if (g_once_init_enter ((gsize *) & id)) {
73 _id = g_flags_register_static ("GstVPXDecPostProcessingFlags", values);
75 g_once_init_leave ((gsize *) & id, _id);
83 static void gst_vpx_dec_set_property (GObject * object, guint prop_id,
84 const GValue * value, GParamSpec * pspec);
85 static void gst_vpx_dec_get_property (GObject * object, guint prop_id,
86 GValue * value, GParamSpec * pspec);
88 static gboolean gst_vpx_dec_start (GstVideoDecoder * decoder);
89 static gboolean gst_vpx_dec_stop (GstVideoDecoder * decoder);
90 static gboolean gst_vpx_dec_set_format (GstVideoDecoder * decoder,
91 GstVideoCodecState * state);
92 static gboolean gst_vpx_dec_flush (GstVideoDecoder * decoder);
94 gst_vpx_dec_handle_frame (GstVideoDecoder * decoder,
95 GstVideoCodecFrame * frame);
96 static gboolean gst_vpx_dec_decide_allocation (GstVideoDecoder * decoder,
99 static void gst_vpx_dec_image_to_buffer (GstVPXDec * dec,
100 const vpx_image_t * img, GstBuffer * buffer);
101 static GstFlowReturn gst_vpx_dec_open_codec (GstVPXDec * dec,
102 GstVideoCodecFrame * frame);
103 static void gst_vpx_dec_default_send_tags (GstVPXDec * dec);
104 static void gst_vpx_dec_set_stream_info (GstVPXDec * dec,
105 vpx_codec_stream_info_t * stream_info);
106 static void gst_vpx_dec_set_default_format (GstVPXDec * dec, GstVideoFormat fmt,
107 int width, int height);
108 static gboolean gst_vpx_dec_default_frame_format (GstVPXDec * dec,
109 vpx_image_t * img, GstVideoFormat * fmt);
110 static void gst_vpx_dec_handle_resolution_change (GstVPXDec * dec,
111 vpx_image_t * img, GstVideoFormat fmt);
113 #define parent_class gst_vpx_dec_parent_class
114 G_DEFINE_TYPE (GstVPXDec, gst_vpx_dec, GST_TYPE_VIDEO_DECODER);
117 gst_vpx_dec_class_init (GstVPXDecClass * klass)
119 GObjectClass *gobject_class;
120 GstVideoDecoderClass *base_video_decoder_class;
122 gobject_class = G_OBJECT_CLASS (klass);
123 base_video_decoder_class = GST_VIDEO_DECODER_CLASS (klass);
125 gobject_class->set_property = gst_vpx_dec_set_property;
126 gobject_class->get_property = gst_vpx_dec_get_property;
128 g_object_class_install_property (gobject_class, PROP_POST_PROCESSING,
129 g_param_spec_boolean ("post-processing", "Post Processing",
130 "Enable post processing", DEFAULT_POST_PROCESSING,
131 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
133 g_object_class_install_property (gobject_class, PROP_POST_PROCESSING_FLAGS,
134 g_param_spec_flags ("post-processing-flags", "Post Processing Flags",
135 "Flags to control post processing",
136 GST_VPX_DEC_TYPE_POST_PROCESSING_FLAGS, DEFAULT_POST_PROCESSING_FLAGS,
137 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
139 g_object_class_install_property (gobject_class, PROP_DEBLOCKING_LEVEL,
140 g_param_spec_uint ("deblocking-level", "Deblocking Level",
142 0, 16, DEFAULT_DEBLOCKING_LEVEL,
143 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
145 g_object_class_install_property (gobject_class, PROP_NOISE_LEVEL,
146 g_param_spec_uint ("noise-level", "Noise Level",
148 0, 16, DEFAULT_NOISE_LEVEL,
149 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
151 g_object_class_install_property (gobject_class, PROP_THREADS,
152 g_param_spec_uint ("threads", "Max Threads",
153 "Maximum number of decoding threads",
154 0, 16, DEFAULT_THREADS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
156 base_video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_vpx_dec_start);
157 base_video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_vpx_dec_stop);
158 base_video_decoder_class->flush = GST_DEBUG_FUNCPTR (gst_vpx_dec_flush);
159 base_video_decoder_class->set_format =
160 GST_DEBUG_FUNCPTR (gst_vpx_dec_set_format);
161 base_video_decoder_class->handle_frame =
162 GST_DEBUG_FUNCPTR (gst_vpx_dec_handle_frame);;
163 base_video_decoder_class->decide_allocation =
164 GST_DEBUG_FUNCPTR (gst_vpx_dec_decide_allocation);
166 klass->video_codec_tag = DEFAULT_VIDEO_CODEC_TAG;
167 klass->codec_algo = DEFAULT_CODEC_ALGO;
168 klass->open_codec = GST_DEBUG_FUNCPTR (gst_vpx_dec_open_codec);
169 klass->send_tags = GST_DEBUG_FUNCPTR (gst_vpx_dec_default_send_tags);
170 klass->set_stream_info = NULL;
171 klass->set_default_format = NULL;
172 klass->handle_resolution_change = NULL;
173 klass->get_frame_format =
174 GST_DEBUG_FUNCPTR (gst_vpx_dec_default_frame_format);
176 GST_DEBUG_CATEGORY_INIT (gst_vpxdec_debug, "vpxdec", 0, "VPX Decoder");
180 gst_vpx_dec_init (GstVPXDec * gst_vpx_dec)
182 GstVideoDecoder *decoder = (GstVideoDecoder *) gst_vpx_dec;
184 GST_DEBUG_OBJECT (gst_vpx_dec, "gst_vpx_dec_init");
185 gst_video_decoder_set_packetized (decoder, TRUE);
186 gst_vpx_dec->post_processing = DEFAULT_POST_PROCESSING;
187 gst_vpx_dec->post_processing_flags = DEFAULT_POST_PROCESSING_FLAGS;
188 gst_vpx_dec->deblocking_level = DEFAULT_DEBLOCKING_LEVEL;
189 gst_vpx_dec->noise_level = DEFAULT_NOISE_LEVEL;
191 gst_video_decoder_set_needs_format (decoder, TRUE);
192 gst_video_decoder_set_use_default_pad_acceptcaps (decoder, TRUE);
193 GST_PAD_SET_ACCEPT_TEMPLATE (GST_VIDEO_DECODER_SINK_PAD (decoder));
197 gst_vpx_dec_set_property (GObject * object, guint prop_id,
198 const GValue * value, GParamSpec * pspec)
202 g_return_if_fail (GST_IS_VPX_DEC (object));
203 dec = GST_VPX_DEC (object);
205 GST_DEBUG_OBJECT (object, "gst_vpx_dec_set_property");
207 case PROP_POST_PROCESSING:
208 dec->post_processing = g_value_get_boolean (value);
210 case PROP_POST_PROCESSING_FLAGS:
211 dec->post_processing_flags = g_value_get_flags (value);
213 case PROP_DEBLOCKING_LEVEL:
214 dec->deblocking_level = g_value_get_uint (value);
216 case PROP_NOISE_LEVEL:
217 dec->noise_level = g_value_get_uint (value);
220 dec->threads = g_value_get_uint (value);
223 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
229 gst_vpx_dec_get_property (GObject * object, guint prop_id, GValue * value,
234 g_return_if_fail (GST_IS_VPX_DEC (object));
235 dec = GST_VPX_DEC (object);
238 case PROP_POST_PROCESSING:
239 g_value_set_boolean (value, dec->post_processing);
241 case PROP_POST_PROCESSING_FLAGS:
242 g_value_set_flags (value, dec->post_processing_flags);
244 case PROP_DEBLOCKING_LEVEL:
245 g_value_set_uint (value, dec->deblocking_level);
247 case PROP_NOISE_LEVEL:
248 g_value_set_uint (value, dec->noise_level);
251 g_value_set_uint (value, dec->threads);
254 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
260 gst_vpx_dec_start (GstVideoDecoder * decoder)
262 GstVPXDec *gst_vpx_dec = GST_VPX_DEC (decoder);
264 GST_DEBUG_OBJECT (gst_vpx_dec, "start");
265 gst_vpx_dec->decoder_inited = FALSE;
271 gst_vpx_dec_stop (GstVideoDecoder * base_video_decoder)
273 GstVPXDec *gst_vpx_dec = GST_VPX_DEC (base_video_decoder);
275 GST_DEBUG_OBJECT (gst_vpx_dec, "stop");
277 if (gst_vpx_dec->output_state) {
278 gst_video_codec_state_unref (gst_vpx_dec->output_state);
279 gst_vpx_dec->output_state = NULL;
282 if (gst_vpx_dec->input_state) {
283 gst_video_codec_state_unref (gst_vpx_dec->input_state);
284 gst_vpx_dec->input_state = NULL;
287 if (gst_vpx_dec->decoder_inited)
288 vpx_codec_destroy (&gst_vpx_dec->decoder);
289 gst_vpx_dec->decoder_inited = FALSE;
291 if (gst_vpx_dec->pool) {
292 gst_buffer_pool_set_active (gst_vpx_dec->pool, FALSE);
293 gst_object_unref (gst_vpx_dec->pool);
294 gst_vpx_dec->pool = NULL;
295 gst_vpx_dec->buf_size = 0;
302 gst_vpx_dec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
304 GstVPXDec *gst_vpx_dec = GST_VPX_DEC (decoder);
306 GST_DEBUG_OBJECT (gst_vpx_dec, "set_format");
308 if (gst_vpx_dec->decoder_inited)
309 vpx_codec_destroy (&gst_vpx_dec->decoder);
310 gst_vpx_dec->decoder_inited = FALSE;
312 if (gst_vpx_dec->output_state) {
313 gst_video_codec_state_unref (gst_vpx_dec->output_state);
314 gst_vpx_dec->output_state = NULL;
317 if (gst_vpx_dec->input_state) {
318 gst_video_codec_state_unref (gst_vpx_dec->input_state);
321 gst_vpx_dec->input_state = gst_video_codec_state_ref (state);
327 gst_vpx_dec_flush (GstVideoDecoder * base_video_decoder)
331 GST_DEBUG_OBJECT (base_video_decoder, "flush");
333 decoder = GST_VPX_DEC (base_video_decoder);
335 if (decoder->output_state) {
336 gst_video_codec_state_unref (decoder->output_state);
337 decoder->output_state = NULL;
340 if (decoder->decoder_inited)
341 vpx_codec_destroy (&decoder->decoder);
342 decoder->decoder_inited = FALSE;
348 gst_vpx_dec_default_send_tags (GstVPXDec * dec)
351 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
353 if (vpxclass->video_codec_tag == NULL)
356 list = gst_tag_list_new_empty ();
357 gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
358 GST_TAG_VIDEO_CODEC, vpxclass->video_codec_tag, NULL);
360 gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (dec),
361 gst_event_new_tag (list));
372 gst_vpx_dec_prepare_image (GstVPXDec * dec, const vpx_image_t * img)
377 struct Frame *frame = img->fb_priv;
378 GstVideoInfo *info = &dec->output_state->info;
380 buffer = gst_buffer_ref (frame->buffer);
382 vmeta = gst_buffer_get_video_meta (buffer);
383 vmeta->format = GST_VIDEO_INFO_FORMAT (info);
384 vmeta->width = GST_VIDEO_INFO_WIDTH (info);
385 vmeta->height = GST_VIDEO_INFO_HEIGHT (info);
386 vmeta->n_planes = GST_VIDEO_INFO_N_PLANES (info);
388 for (comp = 0; comp < 4; comp++) {
389 vmeta->stride[comp] = img->stride[comp];
390 vmeta->offset[comp] =
391 img->planes[comp] ? img->planes[comp] - frame->info.data : 0;
394 /* FIXME This is a READ/WRITE mapped buffer see bug #754826 */
400 gst_vpx_dec_get_buffer_cb (gpointer priv, gsize min_size,
401 vpx_codec_frame_buffer_t * fb)
403 GstVPXDec *dec = priv;
404 GstBuffer *buffer = NULL;
408 if (!dec->pool || dec->buf_size != min_size) {
410 GstStructure *config;
412 GstAllocator *allocator;
413 GstAllocationParams params;
416 gst_buffer_pool_set_active (dec->pool, FALSE);
417 gst_object_unref (dec->pool);
422 gst_video_decoder_get_allocator (GST_VIDEO_DECODER (dec), &allocator,
426 GST_OBJECT_FLAG_IS_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC)) {
427 gst_object_unref (allocator);
431 pool = gst_buffer_pool_new ();
432 config = gst_buffer_pool_get_config (pool);
433 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
434 caps = gst_caps_from_string ("video/internal");
435 gst_buffer_pool_config_set_params (config, caps, min_size, 2, 0);
436 gst_caps_unref (caps);
437 gst_buffer_pool_set_config (pool, config);
440 gst_object_unref (allocator);
442 if (!gst_buffer_pool_set_active (pool, TRUE)) {
443 GST_WARNING ("Failed to create internal pool");
444 gst_object_unref (pool);
449 dec->buf_size = min_size;
452 ret = gst_buffer_pool_acquire_buffer (dec->pool, &buffer, NULL);
453 if (ret != GST_FLOW_OK) {
454 GST_WARNING ("Failed to acquire buffer from internal pool.");
458 /* Add it now, while the buffer is writable */
459 gst_buffer_add_video_meta (buffer, GST_VIDEO_FRAME_FLAG_NONE,
460 GST_VIDEO_FORMAT_ENCODED, 0, 0);
462 frame = g_new0 (struct Frame, 1);
463 if (!gst_buffer_map (buffer, &frame->info, GST_MAP_READWRITE)) {
464 gst_buffer_unref (buffer);
466 GST_WARNING ("Failed to map buffer from internal pool.");
470 fb->size = frame->info.size;
471 fb->data = frame->info.data;
472 frame->buffer = buffer;
475 GST_TRACE_OBJECT (priv, "Allocated buffer %p", frame->buffer);
481 gst_vpx_dec_release_buffer_cb (gpointer priv, vpx_codec_frame_buffer_t * fb)
483 struct Frame *frame = fb->priv;
485 /* We're sometimes called without a frame */
489 GST_TRACE_OBJECT (priv, "Release buffer %p", frame->buffer);
491 gst_buffer_unmap (frame->buffer, &frame->info);
492 gst_buffer_unref (frame->buffer);
501 gst_vpx_dec_image_to_buffer (GstVPXDec * dec, const vpx_image_t * img,
504 int deststride, srcstride, height, width, line, comp;
507 GstVideoInfo *info = &dec->output_state->info;
509 if (!gst_video_frame_map (&frame, info, buffer, GST_MAP_WRITE)) {
510 GST_ERROR_OBJECT (dec, "Could not map video buffer");
514 for (comp = 0; comp < 3; comp++) {
515 dest = GST_VIDEO_FRAME_COMP_DATA (&frame, comp);
516 src = img->planes[comp];
517 width = GST_VIDEO_FRAME_COMP_WIDTH (&frame, comp)
518 * GST_VIDEO_FRAME_COMP_PSTRIDE (&frame, comp);
519 height = GST_VIDEO_FRAME_COMP_HEIGHT (&frame, comp);
520 deststride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, comp);
521 srcstride = img->stride[comp];
523 if (srcstride == deststride) {
524 GST_TRACE_OBJECT (dec, "Stride matches. Comp %d: %d, copying full plane",
526 memcpy (dest, src, srcstride * height);
528 GST_TRACE_OBJECT (dec, "Stride mismatch. Comp %d: %d != %d, copying "
529 "line by line.", comp, srcstride, deststride);
530 for (line = 0; line < height; line++) {
531 memcpy (dest, src, width);
538 gst_video_frame_unmap (&frame);
542 gst_vpx_dec_open_codec (GstVPXDec * dec, GstVideoCodecFrame * frame)
545 vpx_codec_stream_info_t stream_info;
546 vpx_codec_caps_t caps;
547 vpx_codec_dec_cfg_t cfg;
548 vpx_codec_err_t status;
550 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
552 g_return_val_if_fail (vpxclass->codec_algo != NULL, GST_FLOW_ERROR);
554 memset (&stream_info, 0, sizeof (stream_info));
555 memset (&cfg, 0, sizeof (cfg));
556 stream_info.sz = sizeof (stream_info);
558 if (!gst_buffer_map (frame->input_buffer, &minfo, GST_MAP_READ)) {
559 GST_ERROR_OBJECT (dec, "Failed to map input buffer");
560 return GST_FLOW_ERROR;
563 status = vpx_codec_peek_stream_info (vpxclass->codec_algo,
564 minfo.data, minfo.size, &stream_info);
566 gst_buffer_unmap (frame->input_buffer, &minfo);
568 if (status != VPX_CODEC_OK) {
569 GST_WARNING_OBJECT (dec, "VPX preprocessing error: %s",
570 gst_vpx_error_name (status));
571 return GST_FLOW_CUSTOM_SUCCESS_1;
573 if (!stream_info.is_kf) {
574 GST_WARNING_OBJECT (dec, "No keyframe, skipping");
575 return GST_FLOW_CUSTOM_SUCCESS_1;
578 gst_vpx_dec_set_stream_info (dec, &stream_info);
579 gst_vpx_dec_set_default_format (dec, GST_VIDEO_FORMAT_I420, stream_info.w,
582 cfg.w = stream_info.w;
583 cfg.h = stream_info.h;
585 if (dec->threads > 0)
586 cfg.threads = dec->threads;
588 cfg.threads = g_get_num_processors ();
590 caps = vpx_codec_get_caps (vpxclass->codec_algo);
592 if (dec->post_processing) {
593 if (!(caps & VPX_CODEC_CAP_POSTPROC)) {
594 GST_WARNING_OBJECT (dec, "Decoder does not support post processing");
596 flags |= VPX_CODEC_USE_POSTPROC;
601 vpx_codec_dec_init (&dec->decoder, vpxclass->codec_algo, &cfg, flags);
602 if (status != VPX_CODEC_OK) {
603 GST_ELEMENT_ERROR (dec, LIBRARY, INIT,
604 ("Failed to initialize VP8 decoder"), ("%s",
605 gst_vpx_error_name (status)));
606 return GST_FLOW_ERROR;
609 if ((caps & VPX_CODEC_CAP_POSTPROC) && dec->post_processing) {
610 vp8_postproc_cfg_t pp_cfg = { 0, };
612 pp_cfg.post_proc_flag = dec->post_processing_flags;
613 pp_cfg.deblocking_level = dec->deblocking_level;
614 pp_cfg.noise_level = dec->noise_level;
616 status = vpx_codec_control (&dec->decoder, VP8_SET_POSTPROC, &pp_cfg);
617 if (status != VPX_CODEC_OK) {
618 GST_WARNING_OBJECT (dec, "Couldn't set postprocessing settings: %s",
619 gst_vpx_error_name (status));
623 vpx_codec_set_frame_buffer_functions (&dec->decoder,
624 gst_vpx_dec_get_buffer_cb, gst_vpx_dec_release_buffer_cb, dec);
627 dec->decoder_inited = TRUE;
633 gst_vpx_dec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
636 GstFlowReturn ret = GST_FLOW_OK;
637 vpx_codec_err_t status;
638 vpx_codec_iter_t iter = NULL;
640 long decoder_deadline = 0;
641 GstClockTimeDiff deadline;
643 GstVPXDecClass *vpxclass;
646 GST_LOG_OBJECT (decoder, "handle_frame");
648 dec = GST_VPX_DEC (decoder);
649 vpxclass = GST_VPX_DEC_GET_CLASS (dec);
651 if (!dec->decoder_inited) {
652 ret = vpxclass->open_codec (dec, frame);
653 if (ret == GST_FLOW_CUSTOM_SUCCESS_1) {
654 gst_video_decoder_drop_frame (decoder, frame);
656 } else if (ret != GST_FLOW_OK) {
657 gst_video_codec_frame_unref (frame);
662 deadline = gst_video_decoder_get_max_decode_time (decoder, frame);
664 decoder_deadline = 1;
665 } else if (deadline == G_MAXINT64) {
666 decoder_deadline = 0;
668 decoder_deadline = MAX (1, deadline / GST_MSECOND);
671 if (!gst_buffer_map (frame->input_buffer, &minfo, GST_MAP_READ)) {
672 GST_ERROR_OBJECT (dec, "Failed to map input buffer");
673 gst_video_codec_frame_unref (frame);
674 return GST_FLOW_ERROR;
677 status = vpx_codec_decode (&dec->decoder,
678 minfo.data, minfo.size, NULL, decoder_deadline);
680 gst_buffer_unmap (frame->input_buffer, &minfo);
683 GST_VIDEO_DECODER_ERROR (decoder, 1, LIBRARY, ENCODE,
684 ("Failed to decode frame"), ("%s", gst_vpx_error_name (status)), ret);
685 gst_video_codec_frame_unref (frame);
689 img = vpx_codec_get_frame (&dec->decoder, &iter);
691 if (vpxclass->get_frame_format (dec, img, &fmt) == FALSE) {
693 GST_ELEMENT_ERROR (decoder, LIBRARY, ENCODE,
694 ("Failed to decode frame"), ("Unsupported color format %d",
696 gst_video_codec_frame_unref (frame);
697 return GST_FLOW_ERROR;
701 GST_LOG_OBJECT (dec, "Skipping late frame (%f s past deadline)",
702 (double) -deadline / GST_SECOND);
703 gst_video_decoder_drop_frame (decoder, frame);
705 gst_vpx_dec_handle_resolution_change (dec, img, fmt);
707 if (img->fb_priv && dec->have_video_meta) {
708 frame->output_buffer = gst_vpx_dec_prepare_image (dec, img);
709 ret = gst_video_decoder_finish_frame (decoder, frame);
713 ret = gst_video_decoder_allocate_output_frame (decoder, frame);
715 if (ret == GST_FLOW_OK) {
716 gst_vpx_dec_image_to_buffer (dec, img, frame->output_buffer);
717 ret = gst_video_decoder_finish_frame (decoder, frame);
719 gst_video_decoder_drop_frame (decoder, frame);
726 while ((img = vpx_codec_get_frame (&dec->decoder, &iter))) {
727 GST_WARNING_OBJECT (decoder, "Multiple decoded frames... dropping");
731 /* Invisible frame */
732 GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY (frame);
733 gst_video_decoder_finish_frame (decoder, frame);
740 gst_vpx_dec_decide_allocation (GstVideoDecoder * bdec, GstQuery * query)
742 GstVPXDec *dec = GST_VPX_DEC (bdec);
744 GstStructure *config;
746 if (!GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (bdec, query))
749 g_assert (gst_query_get_n_allocation_pools (query) > 0);
750 gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
751 g_assert (pool != NULL);
753 config = gst_buffer_pool_get_config (pool);
754 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
755 gst_buffer_pool_config_add_option (config,
756 GST_BUFFER_POOL_OPTION_VIDEO_META);
757 dec->have_video_meta = TRUE;
759 gst_buffer_pool_set_config (pool, config);
760 gst_object_unref (pool);
766 gst_vpx_dec_set_stream_info (GstVPXDec * dec,
767 vpx_codec_stream_info_t * stream_info)
769 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
770 if (vpxclass->set_stream_info != NULL) {
771 vpxclass->set_stream_info (dec, stream_info);
776 gst_vpx_dec_set_default_format (GstVPXDec * dec, GstVideoFormat fmt, int width,
779 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
780 if (vpxclass->set_default_format != NULL) {
781 vpxclass->set_default_format (dec, fmt, width, height);
786 gst_vpx_dec_default_frame_format (GstVPXDec * dec, vpx_image_t * img,
787 GstVideoFormat * fmt)
789 if (img->fmt == VPX_IMG_FMT_I420) {
790 *fmt = GST_VIDEO_FORMAT_I420;
799 gst_vpx_dec_handle_resolution_change (GstVPXDec * dec, vpx_image_t * img,
802 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
803 if (vpxclass->handle_resolution_change != NULL) {
804 vpxclass->handle_resolution_change (dec, img, fmt);
808 #endif /* HAVE_VP8_DECODER || HAVE_VP9_DECODER */