3 * Copyright (C) 2012 Matthew Waters <ystree00@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include <gst/gl/gl.h>
26 #include "gstgldownloadelement.h"
28 GST_DEBUG_CATEGORY_STATIC (gst_gl_download_element_debug);
29 #define GST_CAT_DEFAULT gst_gl_download_element_debug
31 #define gst_gl_download_element_parent_class parent_class
32 G_DEFINE_TYPE_WITH_CODE (GstGLDownloadElement, gst_gl_download_element,
33 GST_TYPE_GL_BASE_FILTER,
34 GST_DEBUG_CATEGORY_INIT (gst_gl_download_element_debug, "gldownloadelement",
35 0, "download element");
38 static gboolean gst_gl_download_element_get_unit_size (GstBaseTransform * trans,
39 GstCaps * caps, gsize * size);
40 static GstCaps *gst_gl_download_element_transform_caps (GstBaseTransform * bt,
41 GstPadDirection direction, GstCaps * caps, GstCaps * filter);
42 static gboolean gst_gl_download_element_set_caps (GstBaseTransform * bt,
43 GstCaps * in_caps, GstCaps * out_caps);
45 gst_gl_download_element_prepare_output_buffer (GstBaseTransform * bt,
46 GstBuffer * buffer, GstBuffer ** outbuf);
47 static GstFlowReturn gst_gl_download_element_transform (GstBaseTransform * bt,
48 GstBuffer * buffer, GstBuffer * outbuf);
50 static GstStaticPadTemplate gst_gl_download_element_src_pad_template =
51 GST_STATIC_PAD_TEMPLATE ("src",
54 GST_STATIC_CAPS ("video/x-raw; video/x-raw(memory:GLMemory)"));
56 static GstStaticPadTemplate gst_gl_download_element_sink_pad_template =
57 GST_STATIC_PAD_TEMPLATE ("sink",
60 GST_STATIC_CAPS ("video/x-raw(memory:GLMemory)"));
63 gst_gl_download_element_class_init (GstGLDownloadElementClass * klass)
65 GstBaseTransformClass *bt_class = GST_BASE_TRANSFORM_CLASS (klass);
66 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
68 bt_class->transform_caps = gst_gl_download_element_transform_caps;
69 bt_class->set_caps = gst_gl_download_element_set_caps;
70 bt_class->get_unit_size = gst_gl_download_element_get_unit_size;
71 bt_class->prepare_output_buffer =
72 gst_gl_download_element_prepare_output_buffer;
73 bt_class->transform = gst_gl_download_element_transform;
75 bt_class->passthrough_on_same_caps = TRUE;
77 gst_element_class_add_pad_template (element_class,
78 gst_static_pad_template_get (&gst_gl_download_element_src_pad_template));
79 gst_element_class_add_pad_template (element_class,
80 gst_static_pad_template_get (&gst_gl_download_element_sink_pad_template));
82 gst_element_class_set_metadata (element_class,
83 "OpenGL uploader", "Filter/Video",
84 "Downloads data into OpenGL", "Matthew Waters <matthew@centricular.com>");
88 gst_gl_download_element_init (GstGLDownloadElement * download)
90 gst_base_transform_set_prefer_passthrough (GST_BASE_TRANSFORM (download),
95 gst_gl_download_element_set_caps (GstBaseTransform * bt, GstCaps * in_caps,
98 GstVideoInfo out_info;
100 if (!gst_video_info_from_caps (&out_info, out_caps))
107 _set_caps_features (const GstCaps * caps, const gchar * feature_name)
109 GstCaps *tmp = gst_caps_copy (caps);
110 guint n = gst_caps_get_size (tmp);
113 for (i = 0; i < n; i++)
114 gst_caps_set_features (tmp, i,
115 gst_caps_features_from_string (feature_name));
121 gst_gl_download_element_transform_caps (GstBaseTransform * bt,
122 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
124 GstCaps *result, *tmp;
126 if (direction == GST_PAD_SRC) {
127 tmp = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
128 tmp = gst_caps_merge (gst_caps_ref (caps), tmp);
130 tmp = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
131 tmp = gst_caps_merge (gst_caps_ref (caps), tmp);
135 result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
136 gst_caps_unref (tmp);
141 GST_DEBUG_OBJECT (bt, "returning caps %" GST_PTR_FORMAT, result);
147 gst_gl_download_element_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
150 gboolean ret = FALSE;
153 ret = gst_video_info_from_caps (&info, caps);
155 *size = GST_VIDEO_INFO_SIZE (&info);
161 gst_gl_download_element_prepare_output_buffer (GstBaseTransform * bt,
162 GstBuffer * inbuf, GstBuffer ** outbuf)
170 gst_gl_download_element_transform (GstBaseTransform * bt,
171 GstBuffer * inbuf, GstBuffer * outbuf)