4 * Copyright (C) 2015 Intel Corporation
5 * Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
23 #include "gstcompat.h"
27 #include <gst/pbutils/pbutils.h>
28 #include "gstvaapipluginutil.h"
29 #include "gstvaapidecodebin.h"
31 #define GST_PLUGIN_NAME "vaapidecodebin"
32 #define GST_PLUGIN_DESC "A Bin of VA-API elements: vaapidecode ! queue ! vaapipostproc"
34 GST_DEBUG_CATEGORY_STATIC (gst_debug_vaapi_decode_bin);
35 #define GST_CAT_DEFAULT gst_debug_vaapi_decode_bin
37 #define DEFAULT_QUEUE_MAX_SIZE_BUFFERS 0
38 #define DEFAULT_QUEUE_MAX_SIZE_BYTES 0
39 #define DEFAULT_QUEUE_MAX_SIZE_TIME 0
44 PROP_MAX_SIZE_BUFFERS,
49 #define GST_VAAPI_DECODE_BIN_SURFACE_CAPS \
50 GST_VIDEO_CAPS_MAKE_WITH_FEATURES( \
51 GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE, "{ ENCODED, I420, YV12, NV12 }")
53 /* Default templates */
54 #define GST_CAPS_CODEC(CODEC) CODEC "; "
56 static const char gst_vaapi_decode_bin_sink_caps_str[] =
57 GST_CAPS_CODEC("video/mpeg, mpegversion=2, systemstream=(boolean)false")
58 GST_CAPS_CODEC("video/mpeg, mpegversion=4")
59 GST_CAPS_CODEC("video/x-divx")
60 GST_CAPS_CODEC("video/x-xvid")
61 GST_CAPS_CODEC("video/x-h263")
62 GST_CAPS_CODEC("video/x-h264")
63 GST_CAPS_CODEC("video/x-wmv")
64 GST_CAPS_CODEC("video/x-vp8")
65 GST_CAPS_CODEC("image/jpeg")
70 static const char gst_vaapi_decode_bin_src_caps_str[] =
71 GST_VAAPI_DECODE_BIN_SURFACE_CAPS ", "
72 GST_CAPS_INTERLACED_FALSE "; "
73 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (
74 GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META, "{ RGBA, BGRA }") ", "
75 GST_CAPS_INTERLACED_FALSE "; "
76 GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) ", "
77 GST_CAPS_INTERLACED_FALSE;
80 static GstStaticPadTemplate gst_vaapi_decode_bin_sink_factory =
81 GST_STATIC_PAD_TEMPLATE ("sink",
84 GST_STATIC_CAPS (gst_vaapi_decode_bin_sink_caps_str));
86 static GstStaticPadTemplate gst_vaapi_decode_bin_src_factory =
87 GST_STATIC_PAD_TEMPLATE ("src",
90 GST_STATIC_CAPS (gst_vaapi_decode_bin_src_caps_str));
92 G_DEFINE_TYPE (GstVaapiDecodeBin, gst_vaapi_decode_bin, GST_TYPE_BIN);
95 gst_vaapi_decode_bin_set_property (GObject * object,
96 guint prop_id, const GValue * value, GParamSpec * pspec)
98 GstVaapiDecodeBin *vaapidecbin = GST_VAAPI_DECODE_BIN (object);
101 case PROP_MAX_SIZE_BYTES:
102 vaapidecbin->max_size_bytes = g_value_get_uint (value);
103 g_object_set (G_OBJECT (vaapidecbin->queue), "max-size-bytes",
104 vaapidecbin->max_size_bytes, NULL);
106 case PROP_MAX_SIZE_BUFFERS:
107 vaapidecbin->max_size_buffers = g_value_get_uint (value);
108 g_object_set (G_OBJECT (vaapidecbin->queue), "max-size-buffers",
109 vaapidecbin->max_size_buffers, NULL);
111 case PROP_MAX_SIZE_TIME:
112 vaapidecbin->max_size_time = g_value_get_uint64 (value);
113 g_object_set (G_OBJECT (vaapidecbin->queue), "max-size-time",
114 vaapidecbin->max_size_time, NULL);
117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
123 gst_vaapi_decode_bin_get_property (GObject * object,
124 guint prop_id, GValue * value, GParamSpec * pspec)
126 GstVaapiDecodeBin *vaapidecbin = GST_VAAPI_DECODE_BIN (object);
129 case PROP_MAX_SIZE_BYTES:
130 g_value_set_uint (value, vaapidecbin->max_size_bytes);
132 case PROP_MAX_SIZE_BUFFERS:
133 g_value_set_uint (value, vaapidecbin->max_size_buffers);
135 case PROP_MAX_SIZE_TIME:
136 g_value_set_uint64 (value, vaapidecbin->max_size_time);
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
145 gst_vaapi_decode_bin_class_init (GstVaapiDecodeBinClass * klass)
147 GObjectClass *gobject_class;
148 GstElementClass *element_class;
150 gobject_class = G_OBJECT_CLASS (klass);
151 element_class = GST_ELEMENT_CLASS (klass);
153 gobject_class->set_property = gst_vaapi_decode_bin_set_property;
154 gobject_class->get_property = gst_vaapi_decode_bin_get_property;
156 gst_element_class_set_static_metadata (element_class,
158 "Codec/Decoder/Video",
160 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
162 g_object_class_install_property (gobject_class, PROP_MAX_SIZE_BYTES,
163 g_param_spec_uint ("max-size-bytes", "Max. size (kB)",
164 "Max. amount of data in the queue (bytes, 0=disable)",
165 0, G_MAXUINT, DEFAULT_QUEUE_MAX_SIZE_BYTES,
166 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
167 g_object_class_install_property (gobject_class, PROP_MAX_SIZE_BUFFERS,
168 g_param_spec_uint ("max-size-buffers", "Max. size (buffers)",
169 "Max. number of buffers in the queue (0=disable)", 0, G_MAXUINT,
170 DEFAULT_QUEUE_MAX_SIZE_BUFFERS,
171 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
172 g_object_class_install_property (gobject_class, PROP_MAX_SIZE_TIME,
173 g_param_spec_uint64 ("max-size-time", "Max. size (ns)",
174 "Max. amount of data in the queue (in ns, 0=disable)", 0, G_MAXUINT64,
175 DEFAULT_QUEUE_MAX_SIZE_TIME,
176 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
178 gst_element_class_add_pad_template (element_class,
179 gst_static_pad_template_get (&gst_vaapi_decode_bin_sink_factory));
181 gst_element_class_add_pad_template (element_class,
182 gst_static_pad_template_get (&gst_vaapi_decode_bin_src_factory));
184 GST_DEBUG_CATEGORY_INIT (gst_debug_vaapi_decode_bin,
185 GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
189 gst_vaapi_decode_bin_configure (GstVaapiDecodeBin * vaapidecbin)
191 gchar *missing_factory = NULL;
193 /* create the decoder */
194 vaapidecbin->decoder =
195 gst_element_factory_make ("vaapidecode", "vaapidecode");
196 if (!vaapidecbin->decoder) {
197 missing_factory = "vaapidecode";
198 goto error_element_missing;
200 /* create the queue */
201 vaapidecbin->queue = gst_element_factory_make ("queue", "queue");
202 if (!vaapidecbin->queue) {
203 missing_factory = "queue";
204 goto error_element_missing;
206 /* create the postproc */
207 vaapidecbin->postproc =
208 gst_element_factory_make ("vaapipostproc", "vaapipostproc");
209 if (!vaapidecbin->postproc) {
210 missing_factory = "vaapipostproc";
211 goto error_element_missing;
214 g_object_set (G_OBJECT (vaapidecbin->queue),
215 "max-size-bytes", vaapidecbin->max_size_bytes,
216 "max-size-buffers", vaapidecbin->max_size_buffers,
217 "max-size-time", vaapidecbin->max_size_time, NULL);
219 gst_bin_add_many (GST_BIN (vaapidecbin),
220 vaapidecbin->decoder, vaapidecbin->queue, vaapidecbin->postproc, NULL);
222 if (!gst_element_link_pads_full (vaapidecbin->decoder, "src",
223 vaapidecbin->queue, "sink", GST_PAD_LINK_CHECK_NOTHING))
226 if (!gst_element_link_pads_full (vaapidecbin->queue, "src",
227 vaapidecbin->postproc, "sink", GST_PAD_LINK_CHECK_NOTHING))
232 error_element_missing:
235 GST_ERROR_OBJECT (vaapidecbin, "Failed to create %s element",
238 gst_missing_element_message_new (GST_ELEMENT_CAST (vaapidecbin),
240 gst_element_post_message (GST_ELEMENT_CAST (vaapidecbin), msg);
245 GST_ERROR_OBJECT (vaapidecbin, "Failed to link the child elements");
251 gst_vaapi_decode_bin_init (GstVaapiDecodeBin * vaapidecbin)
253 GstPad *element_pad, *ghost_pad;
255 if (!gst_vaapi_decode_bin_configure (vaapidecbin))
258 /* create ghost pad sink */
260 gst_element_get_static_pad (GST_ELEMENT (vaapidecbin->decoder), "sink");
262 gst_ghost_pad_new_from_template ("sink", element_pad,
263 GST_PAD_PAD_TEMPLATE (element_pad));
264 gst_object_unref (element_pad);
265 gst_element_add_pad (GST_ELEMENT (vaapidecbin), ghost_pad);
267 /* create ghost pad src */
269 gst_element_get_static_pad (GST_ELEMENT (vaapidecbin->postproc), "src");
271 gst_ghost_pad_new_from_template ("src", element_pad,
272 GST_PAD_PAD_TEMPLATE (element_pad));
273 gst_object_unref (element_pad);
274 gst_element_add_pad (GST_ELEMENT (vaapidecbin), ghost_pad);