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 static void gst_vpx_dec_default_add_video_meta (GstVPXDec * dec,
115 #endif //HAVE_VPX_1_4
117 #define parent_class gst_vpx_dec_parent_class
118 G_DEFINE_TYPE (GstVPXDec, gst_vpx_dec, GST_TYPE_VIDEO_DECODER);
121 gst_vpx_dec_class_init (GstVPXDecClass * klass)
123 GObjectClass *gobject_class;
124 GstVideoDecoderClass *base_video_decoder_class;
126 gobject_class = G_OBJECT_CLASS (klass);
127 base_video_decoder_class = GST_VIDEO_DECODER_CLASS (klass);
129 gobject_class->set_property = gst_vpx_dec_set_property;
130 gobject_class->get_property = gst_vpx_dec_get_property;
132 g_object_class_install_property (gobject_class, PROP_POST_PROCESSING,
133 g_param_spec_boolean ("post-processing", "Post Processing",
134 "Enable post processing", DEFAULT_POST_PROCESSING,
135 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
137 g_object_class_install_property (gobject_class, PROP_POST_PROCESSING_FLAGS,
138 g_param_spec_flags ("post-processing-flags", "Post Processing Flags",
139 "Flags to control post processing",
140 GST_VPX_DEC_TYPE_POST_PROCESSING_FLAGS, DEFAULT_POST_PROCESSING_FLAGS,
141 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
143 g_object_class_install_property (gobject_class, PROP_DEBLOCKING_LEVEL,
144 g_param_spec_uint ("deblocking-level", "Deblocking Level",
146 0, 16, DEFAULT_DEBLOCKING_LEVEL,
147 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
149 g_object_class_install_property (gobject_class, PROP_NOISE_LEVEL,
150 g_param_spec_uint ("noise-level", "Noise Level",
152 0, 16, DEFAULT_NOISE_LEVEL,
153 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
155 g_object_class_install_property (gobject_class, PROP_THREADS,
156 g_param_spec_uint ("threads", "Max Threads",
157 "Maximum number of decoding threads",
158 0, 16, DEFAULT_THREADS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
160 base_video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_vpx_dec_start);
161 base_video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_vpx_dec_stop);
162 base_video_decoder_class->flush = GST_DEBUG_FUNCPTR (gst_vpx_dec_flush);
163 base_video_decoder_class->set_format =
164 GST_DEBUG_FUNCPTR (gst_vpx_dec_set_format);
165 base_video_decoder_class->handle_frame =
166 GST_DEBUG_FUNCPTR (gst_vpx_dec_handle_frame);;
167 base_video_decoder_class->decide_allocation =
168 GST_DEBUG_FUNCPTR (gst_vpx_dec_decide_allocation);
170 klass->video_codec_tag = DEFAULT_VIDEO_CODEC_TAG;
171 klass->codec_algo = DEFAULT_CODEC_ALGO;
172 klass->open_codec = GST_DEBUG_FUNCPTR (gst_vpx_dec_open_codec);
173 klass->send_tags = GST_DEBUG_FUNCPTR (gst_vpx_dec_default_send_tags);
174 klass->set_stream_info = NULL;
175 klass->set_default_format = NULL;
176 klass->handle_resolution_change = NULL;
177 klass->get_frame_format =
178 GST_DEBUG_FUNCPTR (gst_vpx_dec_default_frame_format);
179 klass->add_video_meta = NULL;
181 GST_DEBUG_CATEGORY_INIT (gst_vpxdec_debug, "vpxdec", 0, "VPX Decoder");
185 gst_vpx_dec_init (GstVPXDec * gst_vpx_dec)
187 GstVideoDecoder *decoder = (GstVideoDecoder *) gst_vpx_dec;
189 GST_DEBUG_OBJECT (gst_vpx_dec, "gst_vpx_dec_init");
190 gst_video_decoder_set_packetized (decoder, TRUE);
191 gst_vpx_dec->post_processing = DEFAULT_POST_PROCESSING;
192 gst_vpx_dec->post_processing_flags = DEFAULT_POST_PROCESSING_FLAGS;
193 gst_vpx_dec->deblocking_level = DEFAULT_DEBLOCKING_LEVEL;
194 gst_vpx_dec->noise_level = DEFAULT_NOISE_LEVEL;
196 gst_video_decoder_set_needs_format (decoder, TRUE);
197 gst_video_decoder_set_use_default_pad_acceptcaps (decoder, TRUE);
198 GST_PAD_SET_ACCEPT_TEMPLATE (GST_VIDEO_DECODER_SINK_PAD (decoder));
202 gst_vpx_dec_set_property (GObject * object, guint prop_id,
203 const GValue * value, GParamSpec * pspec)
207 g_return_if_fail (GST_IS_VPX_DEC (object));
208 dec = GST_VPX_DEC (object);
210 GST_DEBUG_OBJECT (object, "gst_vpx_dec_set_property");
212 case PROP_POST_PROCESSING:
213 dec->post_processing = g_value_get_boolean (value);
215 case PROP_POST_PROCESSING_FLAGS:
216 dec->post_processing_flags = g_value_get_flags (value);
218 case PROP_DEBLOCKING_LEVEL:
219 dec->deblocking_level = g_value_get_uint (value);
221 case PROP_NOISE_LEVEL:
222 dec->noise_level = g_value_get_uint (value);
225 dec->threads = g_value_get_uint (value);
228 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
234 gst_vpx_dec_get_property (GObject * object, guint prop_id, GValue * value,
239 g_return_if_fail (GST_IS_VPX_DEC (object));
240 dec = GST_VPX_DEC (object);
243 case PROP_POST_PROCESSING:
244 g_value_set_boolean (value, dec->post_processing);
246 case PROP_POST_PROCESSING_FLAGS:
247 g_value_set_flags (value, dec->post_processing_flags);
249 case PROP_DEBLOCKING_LEVEL:
250 g_value_set_uint (value, dec->deblocking_level);
252 case PROP_NOISE_LEVEL:
253 g_value_set_uint (value, dec->noise_level);
256 g_value_set_uint (value, dec->threads);
259 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
265 gst_vpx_dec_start (GstVideoDecoder * decoder)
267 GstVPXDec *gst_vpx_dec = GST_VPX_DEC (decoder);
269 GST_DEBUG_OBJECT (gst_vpx_dec, "start");
270 gst_vpx_dec->decoder_inited = FALSE;
276 gst_vpx_dec_stop (GstVideoDecoder * base_video_decoder)
278 GstVPXDec *gst_vpx_dec = GST_VPX_DEC (base_video_decoder);
280 GST_DEBUG_OBJECT (gst_vpx_dec, "stop");
282 if (gst_vpx_dec->output_state) {
283 gst_video_codec_state_unref (gst_vpx_dec->output_state);
284 gst_vpx_dec->output_state = NULL;
287 if (gst_vpx_dec->input_state) {
288 gst_video_codec_state_unref (gst_vpx_dec->input_state);
289 gst_vpx_dec->input_state = NULL;
292 if (gst_vpx_dec->decoder_inited)
293 vpx_codec_destroy (&gst_vpx_dec->decoder);
294 gst_vpx_dec->decoder_inited = FALSE;
296 if (gst_vpx_dec->pool) {
297 gst_buffer_pool_set_active (gst_vpx_dec->pool, FALSE);
298 gst_object_unref (gst_vpx_dec->pool);
299 gst_vpx_dec->pool = NULL;
300 gst_vpx_dec->buf_size = 0;
307 gst_vpx_dec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
309 GstVPXDec *gst_vpx_dec = GST_VPX_DEC (decoder);
311 GST_DEBUG_OBJECT (gst_vpx_dec, "set_format");
313 if (gst_vpx_dec->decoder_inited)
314 vpx_codec_destroy (&gst_vpx_dec->decoder);
315 gst_vpx_dec->decoder_inited = FALSE;
317 if (gst_vpx_dec->output_state) {
318 gst_video_codec_state_unref (gst_vpx_dec->output_state);
319 gst_vpx_dec->output_state = NULL;
322 if (gst_vpx_dec->input_state) {
323 gst_video_codec_state_unref (gst_vpx_dec->input_state);
326 gst_vpx_dec->input_state = gst_video_codec_state_ref (state);
332 gst_vpx_dec_flush (GstVideoDecoder * base_video_decoder)
336 GST_DEBUG_OBJECT (base_video_decoder, "flush");
338 decoder = GST_VPX_DEC (base_video_decoder);
340 if (decoder->output_state) {
341 gst_video_codec_state_unref (decoder->output_state);
342 decoder->output_state = NULL;
345 if (decoder->decoder_inited)
346 vpx_codec_destroy (&decoder->decoder);
347 decoder->decoder_inited = FALSE;
353 gst_vpx_dec_default_send_tags (GstVPXDec * dec)
356 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
358 if (vpxclass->video_codec_tag == NULL)
361 list = gst_tag_list_new_empty ();
362 gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
363 GST_TAG_VIDEO_CODEC, vpxclass->video_codec_tag, NULL);
365 gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (dec),
366 gst_event_new_tag (list));
377 gst_vpx_dec_prepare_image (GstVPXDec * dec, const vpx_image_t * img)
382 struct Frame *frame = img->fb_priv;
383 GstVideoInfo *info = &dec->output_state->info;
385 buffer = gst_buffer_ref (frame->buffer);
387 vmeta = gst_buffer_get_video_meta (buffer);
388 vmeta->format = GST_VIDEO_INFO_FORMAT (info);
389 vmeta->width = GST_VIDEO_INFO_WIDTH (info);
390 vmeta->height = GST_VIDEO_INFO_HEIGHT (info);
391 vmeta->n_planes = GST_VIDEO_INFO_N_PLANES (info);
393 for (comp = 0; comp < 4; comp++) {
394 vmeta->stride[comp] = img->stride[comp];
395 vmeta->offset[comp] =
396 img->planes[comp] ? img->planes[comp] - frame->info.data : 0;
399 /* FIXME This is a READ/WRITE mapped buffer see bug #754826 */
405 gst_vpx_dec_get_buffer_cb (gpointer priv, gsize min_size,
406 vpx_codec_frame_buffer_t * fb)
408 GstVPXDec *dec = priv;
413 if (!dec->pool || dec->buf_size != min_size) {
415 GstStructure *config;
417 GstAllocator *allocator;
418 GstAllocationParams params;
421 gst_buffer_pool_set_active (dec->pool, FALSE);
422 gst_object_unref (dec->pool);
427 gst_video_decoder_get_allocator (GST_VIDEO_DECODER (dec), &allocator,
431 GST_OBJECT_FLAG_IS_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC)) {
432 gst_object_unref (allocator);
436 pool = gst_buffer_pool_new ();
437 config = gst_buffer_pool_get_config (pool);
438 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
439 caps = gst_caps_from_string ("video/internal");
440 gst_buffer_pool_config_set_params (config, caps, min_size, 2, 0);
441 gst_caps_unref (caps);
442 gst_buffer_pool_set_config (pool, config);
445 gst_object_unref (allocator);
447 if (!gst_buffer_pool_set_active (pool, TRUE)) {
448 GST_WARNING ("Failed to create internal pool");
449 gst_object_unref (pool);
454 dec->buf_size = min_size;
457 ret = gst_buffer_pool_acquire_buffer (dec->pool, &buffer, NULL);
458 if (ret != GST_FLOW_OK) {
459 GST_WARNING ("Failed to acquire buffer from internal pool.");
463 gst_vpx_dec_default_add_video_meta (dec, buffer);
465 frame = g_new0 (struct Frame, 1);
466 if (!gst_buffer_map (buffer, &frame->info, GST_MAP_READWRITE)) {
467 gst_buffer_unref (buffer);
469 GST_WARNING ("Failed to map buffer from internal pool.");
473 fb->size = frame->info.size;
474 fb->data = frame->info.data;
475 frame->buffer = buffer;
478 GST_TRACE_OBJECT (priv, "Allocated buffer %p", frame->buffer);
484 gst_vpx_dec_release_buffer_cb (gpointer priv, vpx_codec_frame_buffer_t * fb)
486 struct Frame *frame = fb->priv;
488 GST_TRACE_OBJECT (priv, "Release buffer %p", frame->buffer);
491 gst_buffer_unmap (frame->buffer, &frame->info);
492 gst_buffer_unref (frame->buffer);
500 gst_vpx_dec_image_to_buffer (GstVPXDec * dec, const vpx_image_t * img,
503 int deststride, srcstride, height, width, line, comp;
506 GstVideoInfo *info = &dec->output_state->info;
508 if (!gst_video_frame_map (&frame, info, buffer, GST_MAP_WRITE)) {
509 GST_ERROR_OBJECT (dec, "Could not map video buffer");
513 for (comp = 0; comp < 3; comp++) {
514 dest = GST_VIDEO_FRAME_COMP_DATA (&frame, comp);
515 src = img->planes[comp];
516 width = GST_VIDEO_FRAME_COMP_WIDTH (&frame, comp)
517 * GST_VIDEO_FRAME_COMP_PSTRIDE (&frame, comp);
518 height = GST_VIDEO_FRAME_COMP_HEIGHT (&frame, comp);
519 deststride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, comp);
520 srcstride = img->stride[comp];
522 if (srcstride == deststride) {
523 GST_TRACE_OBJECT (dec, "Stride matches. Comp %d: %d, copying full plane",
525 memcpy (dest, src, srcstride * height);
527 GST_TRACE_OBJECT (dec, "Stride mismatch. Comp %d: %d != %d, copying "
528 "line by line.", comp, srcstride, deststride);
529 for (line = 0; line < height; line++) {
530 memcpy (dest, src, width);
537 gst_video_frame_unmap (&frame);
541 gst_vpx_dec_open_codec (GstVPXDec * dec, GstVideoCodecFrame * frame)
544 vpx_codec_stream_info_t stream_info;
545 vpx_codec_caps_t caps;
546 vpx_codec_dec_cfg_t cfg;
547 vpx_codec_err_t status;
549 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
551 g_return_val_if_fail (vpxclass->codec_algo != NULL, GST_FLOW_ERROR);
553 memset (&stream_info, 0, sizeof (stream_info));
554 memset (&cfg, 0, sizeof (cfg));
555 stream_info.sz = sizeof (stream_info);
557 if (!gst_buffer_map (frame->input_buffer, &minfo, GST_MAP_READ)) {
558 GST_ERROR_OBJECT (dec, "Failed to map input buffer");
559 return GST_FLOW_ERROR;
562 status = vpx_codec_peek_stream_info (vpxclass->codec_algo,
563 minfo.data, minfo.size, &stream_info);
565 gst_buffer_unmap (frame->input_buffer, &minfo);
567 if (status != VPX_CODEC_OK) {
568 GST_WARNING_OBJECT (dec, "VPX preprocessing error: %s",
569 gst_vpx_error_name (status));
570 gst_video_decoder_drop_frame (GST_VIDEO_DECODER (dec), frame);
571 return GST_FLOW_CUSTOM_SUCCESS_1;
573 if (!stream_info.is_kf) {
574 GST_WARNING_OBJECT (dec, "No keyframe, skipping");
575 gst_video_decoder_drop_frame (GST_VIDEO_DECODER (dec), frame);
576 return GST_FLOW_CUSTOM_SUCCESS_1;
579 gst_vpx_dec_set_stream_info (dec, &stream_info);
580 gst_vpx_dec_set_default_format (dec, GST_VIDEO_FORMAT_I420, stream_info.w,
583 cfg.w = stream_info.w;
584 cfg.h = stream_info.h;
585 cfg.threads = dec->threads;
587 caps = vpx_codec_get_caps (vpxclass->codec_algo);
589 if (dec->post_processing) {
590 if (!(caps & VPX_CODEC_CAP_POSTPROC)) {
591 GST_WARNING_OBJECT (dec, "Decoder does not support post processing");
593 flags |= VPX_CODEC_USE_POSTPROC;
598 vpx_codec_dec_init (&dec->decoder, vpxclass->codec_algo, &cfg, flags);
599 if (status != VPX_CODEC_OK) {
600 GST_ELEMENT_ERROR (dec, LIBRARY, INIT,
601 ("Failed to initialize VP8 decoder"), ("%s",
602 gst_vpx_error_name (status)));
603 return GST_FLOW_ERROR;
606 if ((caps & VPX_CODEC_CAP_POSTPROC) && dec->post_processing) {
607 vp8_postproc_cfg_t pp_cfg = { 0, };
609 pp_cfg.post_proc_flag = dec->post_processing_flags;
610 pp_cfg.deblocking_level = dec->deblocking_level;
611 pp_cfg.noise_level = dec->noise_level;
613 status = vpx_codec_control (&dec->decoder, VP8_SET_POSTPROC, &pp_cfg);
614 if (status != VPX_CODEC_OK) {
615 GST_WARNING_OBJECT (dec, "Couldn't set postprocessing settings: %s",
616 gst_vpx_error_name (status));
620 vpx_codec_set_frame_buffer_functions (&dec->decoder,
621 gst_vpx_dec_get_buffer_cb, gst_vpx_dec_release_buffer_cb, dec);
624 dec->decoder_inited = TRUE;
630 gst_vpx_dec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
633 GstFlowReturn ret = GST_FLOW_OK;
634 vpx_codec_err_t status;
635 vpx_codec_iter_t iter = NULL;
637 long decoder_deadline = 0;
638 GstClockTimeDiff deadline;
640 GstVPXDecClass *vpxclass;
643 GST_LOG_OBJECT (decoder, "handle_frame");
645 dec = GST_VPX_DEC (decoder);
646 vpxclass = GST_VPX_DEC_GET_CLASS (dec);
648 if (!dec->decoder_inited) {
649 ret = vpxclass->open_codec (dec, frame);
650 if (ret == GST_FLOW_CUSTOM_SUCCESS_1)
652 else if (ret != GST_FLOW_OK)
656 deadline = gst_video_decoder_get_max_decode_time (decoder, frame);
658 decoder_deadline = 1;
659 } else if (deadline == G_MAXINT64) {
660 decoder_deadline = 0;
662 decoder_deadline = MAX (1, deadline / GST_MSECOND);
665 if (!gst_buffer_map (frame->input_buffer, &minfo, GST_MAP_READ)) {
666 GST_ERROR_OBJECT (dec, "Failed to map input buffer");
667 return GST_FLOW_ERROR;
670 status = vpx_codec_decode (&dec->decoder,
671 minfo.data, minfo.size, NULL, decoder_deadline);
673 gst_buffer_unmap (frame->input_buffer, &minfo);
676 GST_VIDEO_DECODER_ERROR (decoder, 1, LIBRARY, ENCODE,
677 ("Failed to decode frame"), ("%s", gst_vpx_error_name (status)), ret);
681 img = vpx_codec_get_frame (&dec->decoder, &iter);
683 if (vpxclass->get_frame_format (dec, img, &fmt) == FALSE) {
685 GST_ELEMENT_ERROR (decoder, LIBRARY, ENCODE,
686 ("Failed to decode frame"), ("Unsupported color format %d",
688 return GST_FLOW_ERROR;
692 GST_LOG_OBJECT (dec, "Skipping late frame (%f s past deadline)",
693 (double) -deadline / GST_SECOND);
694 gst_video_decoder_drop_frame (decoder, frame);
696 gst_vpx_dec_handle_resolution_change (dec, img, fmt);
698 if (img->fb_priv && dec->have_video_meta) {
699 frame->output_buffer = gst_vpx_dec_prepare_image (dec, img);
700 ret = gst_video_decoder_finish_frame (decoder, frame);
704 ret = gst_video_decoder_allocate_output_frame (decoder, frame);
706 if (ret == GST_FLOW_OK) {
707 gst_vpx_dec_image_to_buffer (dec, img, frame->output_buffer);
708 ret = gst_video_decoder_finish_frame (decoder, frame);
710 gst_video_decoder_drop_frame (decoder, frame);
717 while ((img = vpx_codec_get_frame (&dec->decoder, &iter))) {
718 GST_WARNING_OBJECT (decoder, "Multiple decoded frames... dropping");
722 /* Invisible frame */
723 GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY (frame);
724 gst_video_decoder_finish_frame (decoder, frame);
732 gst_vpx_dec_decide_allocation (GstVideoDecoder * bdec, GstQuery * query)
735 GstStructure *config;
737 if (!GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (bdec, query))
740 g_assert (gst_query_get_n_allocation_pools (query) > 0);
741 gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
742 g_assert (pool != NULL);
744 config = gst_buffer_pool_get_config (pool);
745 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
746 gst_buffer_pool_config_add_option (config,
747 GST_BUFFER_POOL_OPTION_VIDEO_META);
749 gst_buffer_pool_set_config (pool, config);
750 gst_object_unref (pool);
756 gst_vpx_dec_set_stream_info (GstVPXDec * dec,
757 vpx_codec_stream_info_t * stream_info)
759 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
760 if (vpxclass->set_stream_info != NULL) {
761 vpxclass->set_stream_info (dec, stream_info);
766 gst_vpx_dec_set_default_format (GstVPXDec * dec, GstVideoFormat fmt, int width,
769 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
770 if (vpxclass->set_default_format != NULL) {
771 vpxclass->set_default_format (dec, fmt, width, height);
776 gst_vpx_dec_default_frame_format (GstVPXDec * dec, vpx_image_t * img,
777 GstVideoFormat * fmt)
779 if (img->fmt == VPX_IMG_FMT_I420) {
780 *fmt = GST_VIDEO_FORMAT_I420;
789 gst_vpx_dec_handle_resolution_change (GstVPXDec * dec, vpx_image_t * img,
792 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
793 if (vpxclass->handle_resolution_change != NULL) {
794 vpxclass->handle_resolution_change (dec, img, fmt);
800 gst_vpx_dec_default_add_video_meta (GstVPXDec * dec, GstBuffer * buffer)
802 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
803 if (vpxclass->add_video_meta != NULL) {
804 vpxclass->add_video_meta (dec, buffer);
807 #endif //HAVE_VPX_1_4
808 #endif /* HAVE_VP8_DECODER || HAVE_VP9_DECODER */