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, GBR }"))
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 if (img->cs == VPX_CS_SRGB)
149 *fmt = GST_VIDEO_FORMAT_GBR;
151 *fmt = GST_VIDEO_FORMAT_Y444;
153 #ifdef VPX_IMG_FMT_I440
154 case VPX_IMG_FMT_I440:
155 /* Planar, half height, full width U/V */
156 GST_FIXME_OBJECT (dec, "Please add a 4:4:0 planar frame format");
157 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
158 (NULL), ("Unsupported frame format - 4:4:0 planar"));
161 #ifdef VPX_IMG_FMT_I42016
162 case VPX_IMG_FMT_I42016:
163 /* VPX_IMG_FMT_I420 | VPX_IMG_FMT_HIGHBITDEPTH */
164 GST_FIXME_OBJECT (dec, "Please add 16-bit I420 format");
165 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
166 (NULL), ("Unsupported frame format - 16-bit 4:2:0 planar"));
169 #ifdef VPX_IMG_FMT_I42216
170 case VPX_IMG_FMT_I42216:
171 /* VPX_IMG_FMT_I422 | VPX_IMG_FMT_HIGHBITDEPTH */
172 GST_FIXME_OBJECT (dec, "Please add 16-bit Y42B format");
173 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
174 (NULL), ("Unsupported frame format - 16-bit 4:2:2 planar"));
177 #ifdef VPX_IMG_FMT_I44416
178 case VPX_IMG_FMT_I44416:
179 /* VPX_IMG_FMT_I444 | VPX_IMG_FMT_HIGHBITDEPTH */
180 GST_FIXME_OBJECT (dec, "Please add 16-bit Y444 format");
181 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
182 (NULL), ("Unsupported frame format - 16-bit 4:4:4 planar"));
185 #ifdef VPX_IMG_FMT_I44016
186 case VPX_IMG_FMT_I44016:
187 /* VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH */
188 GST_FIXME_OBJECT (dec, "Please add 16-bit 4:4:0 planar frame format");
189 GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
190 (NULL), ("Unsupported frame format - 16-bit 4:4:0 planar"));
199 gst_vp9_dec_handle_resolution_change (GstVPXDec * dec, vpx_image_t * img,
202 GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
204 if (!dec->output_state || dec->output_state->info.finfo->format != fmt ||
205 dec->output_state->info.width != img->d_w ||
206 dec->output_state->info.height != img->d_h) {
207 gboolean send_tags = !dec->output_state;
209 if (dec->output_state)
210 gst_video_codec_state_unref (dec->output_state);
213 gst_video_decoder_set_output_state (GST_VIDEO_DECODER (dec),
214 fmt, img->d_w, img->d_h, dec->input_state);
215 gst_video_decoder_negotiate (GST_VIDEO_DECODER (dec));
218 vpxclass->send_tags (dec);
222 #endif /* HAVE_VP9_DECODER */