• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* VP8
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>
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-vp8dec
24  * @title: vp8dec
25  * @see_also: vp8enc, matroskademux
26  *
27  * This element decodes VP8 streams into raw video.
28  * [VP8](http://www.webmproject.org) is a royalty-free video codec maintained by
29  * [Google](http://www.google.com/). It's the successor of On2 VP3, which was
30  * the base of the Theora video codec.
31  *
32  * ## Example pipeline
33  * |[
34  * gst-launch-1.0 -v filesrc location=videotestsrc.webm ! matroskademux ! vp8dec ! videoconvert ! videoscale ! autovideosink
35  * ]| This example pipeline will decode a WebM stream and decodes the VP8 video.
36  *
37  */
38 
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
42 
43 #ifdef HAVE_VP8_DECODER
44 
45 #include <string.h>
46 
47 #include "gstvpxelements.h"
48 #include "gstvp8dec.h"
49 #include "gstvp8utils.h"
50 
51 #include <gst/video/gstvideometa.h>
52 #include <gst/video/gstvideopool.h>
53 
54 GST_DEBUG_CATEGORY_STATIC (gst_vp8dec_debug);
55 #define GST_CAT_DEFAULT gst_vp8dec_debug
56 
57 #define VP8_DECODER_VIDEO_TAG "VP8 video"
58 
59 static void gst_vp8_dec_set_default_format (GstVPXDec * dec, GstVideoFormat fmt,
60     int width, int height);
61 static void gst_vp8_dec_handle_resolution_change (GstVPXDec * dec,
62     vpx_image_t * img, GstVideoFormat fmt);
63 static gboolean gst_vp8_dec_get_needs_sync_point (GstVPXDec * dec);
64 
65 static GstStaticPadTemplate gst_vp8_dec_sink_template =
66 GST_STATIC_PAD_TEMPLATE ("sink",
67     GST_PAD_SINK,
68     GST_PAD_ALWAYS,
69     GST_STATIC_CAPS ("video/x-vp8")
70     );
71 
72 static GstStaticPadTemplate gst_vp8_dec_src_template =
73 GST_STATIC_PAD_TEMPLATE ("src",
74     GST_PAD_SRC,
75     GST_PAD_ALWAYS,
76     GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420"))
77     );
78 
79 #define parent_class gst_vp8_dec_parent_class
80 G_DEFINE_TYPE (GstVP8Dec, gst_vp8_dec, GST_TYPE_VPX_DEC);
81 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (vp8dec, "vp8dec", GST_RANK_PRIMARY,
82     gst_vp8_dec_get_type (), vpx_element_init (plugin));
83 
84 static void
gst_vp8_dec_class_init(GstVP8DecClass * klass)85 gst_vp8_dec_class_init (GstVP8DecClass * klass)
86 {
87   GstElementClass *element_class;
88   GstVPXDecClass *vpx_class;
89 
90   element_class = GST_ELEMENT_CLASS (klass);
91   vpx_class = GST_VPX_DEC_CLASS (klass);
92 
93   gst_element_class_add_static_pad_template (element_class,
94       &gst_vp8_dec_sink_template);
95   gst_element_class_add_static_pad_template (element_class,
96       &gst_vp8_dec_src_template);
97 
98   gst_element_class_set_static_metadata (element_class,
99       "On2 VP8 Decoder",
100       "Codec/Decoder/Video",
101       "Decode VP8 video streams", "David Schleef <ds@entropywave.com>, "
102       "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
103 
104   vpx_class->video_codec_tag = VP8_DECODER_VIDEO_TAG;
105   vpx_class->codec_algo = &vpx_codec_vp8_dx_algo;
106   vpx_class->set_default_format =
107       GST_DEBUG_FUNCPTR (gst_vp8_dec_set_default_format);
108   vpx_class->handle_resolution_change =
109       GST_DEBUG_FUNCPTR (gst_vp8_dec_handle_resolution_change);
110   vpx_class->get_needs_sync_point =
111       GST_DEBUG_FUNCPTR (gst_vp8_dec_get_needs_sync_point);
112 
113   GST_DEBUG_CATEGORY_INIT (gst_vp8dec_debug, "vp8dec", 0, "VP8 Decoder");
114 }
115 
116 static void
gst_vp8_dec_init(GstVP8Dec * gst_vp8_dec)117 gst_vp8_dec_init (GstVP8Dec * gst_vp8_dec)
118 {
119   GST_DEBUG_OBJECT (gst_vp8_dec, "gst_vp8_dec_init");
120 }
121 
122 static void
gst_vp8_dec_set_default_format(GstVPXDec * dec,GstVideoFormat fmt,int width,int height)123 gst_vp8_dec_set_default_format (GstVPXDec * dec, GstVideoFormat fmt, int width,
124     int height)
125 {
126   GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
127   g_assert (dec->output_state == NULL);
128   dec->output_state =
129       gst_video_decoder_set_output_state (GST_VIDEO_DECODER (dec),
130       GST_VIDEO_FORMAT_I420, width, height, dec->input_state);
131   gst_video_decoder_negotiate (GST_VIDEO_DECODER (dec));
132   vpxclass->send_tags (dec);
133 }
134 
135 static void
gst_vp8_dec_handle_resolution_change(GstVPXDec * dec,vpx_image_t * img,GstVideoFormat fmt)136 gst_vp8_dec_handle_resolution_change (GstVPXDec * dec, vpx_image_t * img,
137     GstVideoFormat fmt)
138 {
139   GstVideoInfo *info;
140   GstVideoCodecState *new_output_state;
141 
142   info = &dec->output_state->info;
143   if (GST_VIDEO_INFO_WIDTH (info) != img->d_w
144       || GST_VIDEO_INFO_HEIGHT (info) != img->d_h) {
145     GST_DEBUG_OBJECT (dec,
146         "Changed output resolution was %d x %d now is got %u x %u (display %u x %u)",
147         GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info), img->w,
148         img->h, img->d_w, img->d_h);
149 
150     new_output_state =
151         gst_video_decoder_set_output_state (GST_VIDEO_DECODER (dec),
152         GST_VIDEO_FORMAT_I420, img->d_w, img->d_h, dec->output_state);
153     if (dec->output_state) {
154       gst_video_codec_state_unref (dec->output_state);
155     }
156     dec->output_state = new_output_state;
157     /* No need to call negotiate() here, it will be automatically called
158      * by allocate_output_frame()*/
159   }
160 }
161 
162 static gboolean
gst_vp8_dec_get_needs_sync_point(GstVPXDec * dec)163 gst_vp8_dec_get_needs_sync_point (GstVPXDec * dec)
164 {
165   return FALSE;
166 }
167 
168 #endif /* HAVE_VP8_DECODER */
169