gldownloadelement: Fix element description
[platform/upstream/gstreamer.git] / ext / gl / gstgldownloadelement.c
1 /*
2  * GStreamer
3  * Copyright (C) 2012 Matthew Waters <ystree00@gmail.com>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gst/gl/gl.h>
26 #include "gstgldownloadelement.h"
27
28 GST_DEBUG_CATEGORY_STATIC (gst_gl_download_element_debug);
29 #define GST_CAT_DEFAULT gst_gl_download_element_debug
30
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");
36     );
37
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);
44 static GstFlowReturn
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);
49
50 static GstStaticPadTemplate gst_gl_download_element_src_pad_template =
51     GST_STATIC_PAD_TEMPLATE ("src",
52     GST_PAD_SRC,
53     GST_PAD_ALWAYS,
54     GST_STATIC_CAPS ("video/x-raw; video/x-raw(memory:GLMemory)"));
55
56 static GstStaticPadTemplate gst_gl_download_element_sink_pad_template =
57 GST_STATIC_PAD_TEMPLATE ("sink",
58     GST_PAD_SINK,
59     GST_PAD_ALWAYS,
60     GST_STATIC_CAPS ("video/x-raw(memory:GLMemory)"));
61
62 static void
63 gst_gl_download_element_class_init (GstGLDownloadElementClass * klass)
64 {
65   GstBaseTransformClass *bt_class = GST_BASE_TRANSFORM_CLASS (klass);
66   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
67
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;
74
75   bt_class->passthrough_on_same_caps = TRUE;
76
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));
81
82   gst_element_class_set_metadata (element_class,
83       "OpenGL uploader", "Filter/Video",
84       "Downloads data into OpenGL", "Matthew Waters <matthew@centricular.com>");
85 }
86
87 static void
88 gst_gl_download_element_init (GstGLDownloadElement * download)
89 {
90   gst_base_transform_set_prefer_passthrough (GST_BASE_TRANSFORM (download),
91       TRUE);
92 }
93
94 static gboolean
95 gst_gl_download_element_set_caps (GstBaseTransform * bt, GstCaps * in_caps,
96     GstCaps * out_caps)
97 {
98   GstVideoInfo out_info;
99
100   if (!gst_video_info_from_caps (&out_info, out_caps))
101     return FALSE;
102
103   return TRUE;
104 }
105
106 static GstCaps *
107 _set_caps_features (const GstCaps * caps, const gchar * feature_name)
108 {
109   GstCaps *tmp = gst_caps_copy (caps);
110   guint n = gst_caps_get_size (tmp);
111   guint i = 0;
112
113   for (i = 0; i < n; i++)
114     gst_caps_set_features (tmp, i,
115         gst_caps_features_from_string (feature_name));
116
117   return tmp;
118 }
119
120 static GstCaps *
121 gst_gl_download_element_transform_caps (GstBaseTransform * bt,
122     GstPadDirection direction, GstCaps * caps, GstCaps * filter)
123 {
124   GstCaps *result, *tmp;
125
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);
129   } else {
130     tmp = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
131     tmp = gst_caps_merge (gst_caps_ref (caps), tmp);
132   }
133
134   if (filter) {
135     result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
136     gst_caps_unref (tmp);
137   } else {
138     result = tmp;
139   }
140
141   GST_DEBUG_OBJECT (bt, "returning caps %" GST_PTR_FORMAT, result);
142
143   return result;
144 }
145
146 static gboolean
147 gst_gl_download_element_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
148     gsize * size)
149 {
150   gboolean ret = FALSE;
151   GstVideoInfo info;
152
153   ret = gst_video_info_from_caps (&info, caps);
154   if (ret)
155     *size = GST_VIDEO_INFO_SIZE (&info);
156
157   return TRUE;
158 }
159
160 static GstFlowReturn
161 gst_gl_download_element_prepare_output_buffer (GstBaseTransform * bt,
162     GstBuffer * inbuf, GstBuffer ** outbuf)
163 {
164   *outbuf = inbuf;
165
166   return GST_FLOW_OK;
167 }
168
169 static GstFlowReturn
170 gst_gl_download_element_transform (GstBaseTransform * bt,
171     GstBuffer * inbuf, GstBuffer * outbuf)
172 {
173   return GST_FLOW_OK;
174 }