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>
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.
23 * SECTION:element-vp9dec
24 * @see_also: vp9enc, matroskademux
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
33 * <title>Example pipeline</title>
35 * gst-launch-1.0 -v filesrc location=videotestsrc.webm ! matroskademux ! vp9dec ! videoconvert ! videoscale ! autovideosink
36 * ]| This example pipeline will decode a WebM stream and decodes the VP9 video.
44 #ifdef HAVE_VP9_DECODER
48 #include "gstvp8utils.h"
49 #include "gstvp9dec.h"
51 #include <gst/video/gstvideometa.h>
52 #include <gst/video/gstvideopool.h>
54 GST_DEBUG_CATEGORY_STATIC (gst_vp9dec_debug);
55 #define GST_CAT_DEFAULT gst_vp9dec_debug
57 #define VP9_DECODER_VIDEO_TAG "VP9 video"
59 static void gst_vp9_dec_set_stream_info (GstVPXDec * dec,
60 vpx_codec_stream_info_t * stream_info);
61 static gboolean gst_vp9_dec_get_valid_format (GstVPXDec * dec,
62 vpx_image_t * img, GstVideoFormat * fmt);
63 static void gst_vp9_dec_handle_resolution_change (GstVPXDec * dec,
64 vpx_image_t * img, GstVideoFormat fmt);
66 static GstStaticPadTemplate gst_vp9_dec_sink_template =
67 GST_STATIC_PAD_TEMPLATE ("sink",
70 GST_STATIC_CAPS ("video/x-vp9")
73 static GstStaticPadTemplate gst_vp9_dec_src_template =
74 GST_STATIC_PAD_TEMPLATE ("src",
77 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ I420, YV12, Y42B, Y444 }"))
80 #define parent_class gst_vp9_dec_parent_class
81 G_DEFINE_TYPE (GstVP9Dec, gst_vp9_dec, GST_TYPE_VPX_DEC);
84 gst_vp9_dec_class_init (GstVP9DecClass * klass)
86 GstElementClass *element_class;
87 GstVPXDecClass *vpx_class;
89 element_class = GST_ELEMENT_CLASS (klass);
90 vpx_class = GST_VPX_DEC_CLASS (klass);
92 gst_element_class_add_static_pad_template (element_class,
93 &gst_vp9_dec_src_template);
94 gst_element_class_add_static_pad_template (element_class,
95 &gst_vp9_dec_sink_template);
97 gst_element_class_set_static_metadata (element_class,
99 "Codec/Decoder/Video",
100 "Decode VP9 video streams", "David Schleef <ds@entropywave.com>, "
101 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
103 vpx_class->video_codec_tag = VP9_DECODER_VIDEO_TAG;
104 vpx_class->codec_algo = &vpx_codec_vp9_dx_algo;
105 vpx_class->set_stream_info = GST_DEBUG_FUNCPTR (gst_vp9_dec_set_stream_info);
106 vpx_class->get_frame_format =
107 GST_DEBUG_FUNCPTR (gst_vp9_dec_get_valid_format);
108 vpx_class->handle_resolution_change =
109 GST_DEBUG_FUNCPTR (gst_vp9_dec_handle_resolution_change);
111 GST_DEBUG_CATEGORY_INIT (gst_vp9dec_debug, "vp9dec", 0, "VP9 Decoder");
115 gst_vp9_dec_init (GstVP9Dec * gst_vp9_dec)
117 GST_DEBUG_OBJECT (gst_vp9_dec, "gst_vp9_dec_init");
121 gst_vp9_dec_set_stream_info (GstVPXDec * dec,
122 vpx_codec_stream_info_t * stream_info)
124 /* FIXME: peek_stream_info() does not return valid values, take input caps */
125 stream_info->w = dec->input_state->info.width;
126 stream_info->h = dec->input_state->info.height;
131 gst_vp9_dec_get_valid_format (GstVPXDec * dec, vpx_image_t * img,
132 GstVideoFormat * fmt)
135 case VPX_IMG_FMT_I420:
136 *fmt = GST_VIDEO_FORMAT_I420;
139 case VPX_IMG_FMT_YV12:
140 *fmt = GST_VIDEO_FORMAT_YV12;
143 case VPX_IMG_FMT_I422:
144 *fmt = GST_VIDEO_FORMAT_Y42B;
147 case VPX_IMG_FMT_I444:
148 *fmt = GST_VIDEO_FORMAT_Y444;
151 case VPX_IMG_FMT_I440:
152 /* Planar, half height, full width U/V */
153 GST_FIXME_OBJECT (dec, "Please add a 4:4:0 planar frame format");
154 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
155 (NULL), ("Unsupported frame format - 4:4:0 planar"));
157 case VPX_IMG_FMT_I42016:
158 /* VPX_IMG_FMT_I420 | VPX_IMG_FMT_HIGHBITDEPTH */
159 GST_FIXME_OBJECT (dec, "Please add 16-bit I420 format");
160 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
161 (NULL), ("Unsupported frame format - 16-bit 4:2:0 planar"));
163 case VPX_IMG_FMT_I42216:
164 /* VPX_IMG_FMT_I422 | VPX_IMG_FMT_HIGHBITDEPTH */
165 GST_FIXME_OBJECT (dec, "Please add 16-bit Y42B format");
166 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
167 (NULL), ("Unsupported frame format - 16-bit 4:2:2 planar"));
169 case VPX_IMG_FMT_I44416:
170 /* VPX_IMG_FMT_I444 | VPX_IMG_FMT_HIGHBITDEPTH */
171 GST_FIXME_OBJECT (dec, "Please add 16-bit Y444 format");
172 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
173 (NULL), ("Unsupported frame format - 16-bit 4:4:4 planar"));
175 case VPX_IMG_FMT_I44016:
176 /* VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH */
177 GST_FIXME_OBJECT (dec, "Please add 16-bit 4:4:0 planar frame format");
178 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
179 (NULL), ("Unsupported frame format - 16-bit 4:4:0 planar"));
188 gst_vp9_dec_handle_resolution_change (GstVPXDec * dec, vpx_image_t * img,
191 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
193 if (!dec->output_state || dec->output_state->info.finfo->format != fmt ||
194 dec->output_state->info.width != img->d_w ||
195 dec->output_state->info.height != img->d_h) {
196 gboolean send_tags = !dec->output_state;
198 if (dec->output_state)
199 gst_video_codec_state_unref (dec->output_state);
202 gst_video_decoder_set_output_state (GST_VIDEO_DECODER (dec),
203 fmt, img->d_w, img->d_h, dec->input_state);
204 gst_video_decoder_negotiate (GST_VIDEO_DECODER (dec));
207 vpxclass->send_tags (dec);
211 #endif /* HAVE_VP9_DECODER */