43f64626e38d9579d76ec803e4822c0df3c9fae6
[platform/upstream/gstreamer.git] / ext / gl / gstopengl.c
1 /*
2  * GStreamer
3  * Copyright (C) 2003 Julien Moutte <julien@moutte.net>
4  * Copyright (C) 2005,2006,2007 David A. Schleef <ds@schleef.org>
5  * Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
6  * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 /**
25  * SECTION:plugin-opengl
26  * @title: GstOpengl
27  *
28  * Cross-platform OpenGL plugin.
29  *
30  * ## Debugging
31  *
32  * ## Examples
33  * |[
34  * gst-launch-1.0 --gst-debug=gldisplay:3 videotestsrc ! glimagesink
35  * ]| A debugging pipeline.
36   |[
37  * GST_DEBUG=gl*:6 gst-launch-1.0 videotestsrc ! glimagesink
38  * ]| A debugging pipelines related to shaders.
39  *
40  */
41
42 #ifdef HAVE_CONFIG_H
43 #include "config.h"
44 #endif
45
46 #undef HAVE_VIDEO_AGGREGATOR_IN_BASE
47
48 #include "gstglimagesink.h"
49 #include "gstgluploadelement.h"
50 #include "gstgldownloadelement.h"
51 #include "gstglcolorconvertelement.h"
52 #include "gstglcolorbalance.h"
53 #include "gstglfilterbin.h"
54 #include "gstglsinkbin.h"
55 #include "gstglsrcbin.h"
56
57 #include "gstglfiltercube.h"
58 #include "gstgleffects.h"
59 #include "gstglcolorscale.h"
60
61 #ifdef HAVE_VIDEO_AGGREGATOR_IN_BASE
62 #include "gstglmixerbin.h"
63 #include "gstglvideomixer.h"
64 #include "gstglstereomix.h"
65 #endif
66
67 #include "gstglfiltershader.h"
68 #include "gstglfilterapp.h"
69 #include "gstglstereosplit.h"
70 #include "gstglviewconvert.h"
71 #include "gstgltestsrc.h"
72 #include "gstgldeinterlace.h"
73 #include "gstglalpha.h"
74 #include "gstgloverlaycompositorelement.h"
75
76 #ifdef HAVE_GRAPHENE
77 #include "gstgltransformation.h"
78 #include "gstglvideoflip.h"
79 #endif
80 #if defined(HAVE_JPEG) && defined(HAVE_PNG)
81 #include "gstgloverlay.h"
82 #endif
83
84 #if GST_GL_HAVE_OPENGL
85 #include "gstglfilterglass.h"
86 /* #include "gstglfilterreflectedscreen.h" */
87 #ifdef HAVE_VIDEO_AGGREGATOR_IN_BASE
88 #include "gstglmosaic.h"
89 #endif
90 #ifdef HAVE_PNG
91 #include "gstgldifferencematte.h"
92 /* #include "gstglbumper.h" */
93 #endif /* HAVE_PNG */
94 #endif /* GST_GL_HAVE_OPENGL */
95
96 #if GST_GL_HAVE_WINDOW_COCOA
97 /* avoid including Cocoa/CoreFoundation from a C file... */
98 extern GType gst_ca_opengl_layer_sink_bin_get_type (void);
99 #endif
100
101 #if GST_GL_HAVE_WINDOW_DISPMANX
102 extern void bcm_host_init (void);
103 #endif
104
105 #if GST_GL_HAVE_WINDOW_X11
106 #include <X11/Xlib.h>
107 #endif
108
109 #define GST_CAT_DEFAULT gst_gl_gstgl_debug
110 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
111
112 /* Register filters that make up the gstgl plugin */
113 static gboolean
114 plugin_init (GstPlugin * plugin)
115 {
116   GST_DEBUG_CATEGORY_INIT (gst_gl_gstgl_debug, "gstopengl", 0, "gstopengl");
117
118 #if GST_GL_HAVE_WINDOW_DISPMANX
119   GST_DEBUG ("Initialize BCM host");
120   bcm_host_init ();
121 #endif
122
123 #if GST_GL_HAVE_WINDOW_X11
124   if (g_getenv ("GST_GL_XINITTHREADS"))
125     XInitThreads ();
126 #endif
127
128   if (!gst_element_register (plugin, "glimagesink",
129           GST_RANK_SECONDARY, gst_gl_image_sink_bin_get_type ())) {
130     return FALSE;
131   }
132
133   if (!gst_element_register (plugin, "glimagesinkelement",
134           GST_RANK_NONE, gst_glimage_sink_get_type ())) {
135     return FALSE;
136   }
137
138   if (!gst_element_register (plugin, "glupload",
139           GST_RANK_NONE, GST_TYPE_GL_UPLOAD_ELEMENT)) {
140     return FALSE;
141   }
142
143   if (!gst_element_register (plugin, "gldownload",
144           GST_RANK_NONE, GST_TYPE_GL_DOWNLOAD_ELEMENT)) {
145     return FALSE;
146   }
147
148   if (!gst_element_register (plugin, "glcolorconvert",
149           GST_RANK_NONE, GST_TYPE_GL_COLOR_CONVERT_ELEMENT)) {
150     return FALSE;
151   }
152
153   if (!gst_element_register (plugin, "glcolorbalance",
154           GST_RANK_NONE, GST_TYPE_GL_COLOR_BALANCE)) {
155     return FALSE;
156   }
157
158   if (!gst_element_register (plugin, "glfilterbin",
159           GST_RANK_NONE, GST_TYPE_GL_FILTER_BIN)) {
160     return FALSE;
161   }
162
163   if (!gst_element_register (plugin, "glsinkbin",
164           GST_RANK_NONE, GST_TYPE_GL_SINK_BIN)) {
165     return FALSE;
166   }
167
168   if (!gst_element_register (plugin, "glsrcbin",
169           GST_RANK_NONE, GST_TYPE_GL_SRC_BIN)) {
170     return FALSE;
171   }
172 #ifdef HAVE_VIDEO_AGGREGATOR_IN_BASE
173   if (!gst_element_register (plugin, "glmixerbin",
174           GST_RANK_NONE, GST_TYPE_GL_MIXER_BIN)) {
175     return FALSE;
176   }
177 #endif
178
179   if (!gst_element_register (plugin, "glfiltercube",
180           GST_RANK_NONE, GST_TYPE_GL_FILTER_CUBE)) {
181     return FALSE;
182   }
183 #ifdef HAVE_GRAPHENE
184   if (!gst_element_register (plugin, "gltransformation",
185           GST_RANK_NONE, GST_TYPE_GL_TRANSFORMATION)) {
186     return FALSE;
187   }
188
189   if (!gst_element_register (plugin, "glvideoflip",
190           GST_RANK_NONE, GST_TYPE_GL_VIDEO_FLIP)) {
191     return FALSE;
192   }
193 #endif
194
195   if (!gst_gl_effects_register_filters (plugin, GST_RANK_NONE)) {
196     return FALSE;
197   };
198
199   if (!gst_element_register (plugin, "glcolorscale",
200           GST_RANK_NONE, GST_TYPE_GL_COLORSCALE)) {
201     return FALSE;
202   }
203 #ifdef HAVE_VIDEO_AGGREGATOR_IN_BASE
204   if (!gst_element_register (plugin, "glvideomixer",
205           GST_RANK_NONE, gst_gl_video_mixer_bin_get_type ())) {
206     return FALSE;
207   }
208
209   if (!gst_element_register (plugin, "glvideomixerelement",
210           GST_RANK_NONE, gst_gl_video_mixer_get_type ())) {
211     return FALSE;
212   }
213 #endif
214
215   if (!gst_element_register (plugin, "glshader",
216           GST_RANK_NONE, gst_gl_filtershader_get_type ())) {
217     return FALSE;
218   }
219
220   if (!gst_element_register (plugin, "glfilterapp",
221           GST_RANK_NONE, GST_TYPE_GL_FILTER_APP)) {
222     return FALSE;
223   }
224
225   if (!gst_element_register (plugin, "glviewconvert",
226           GST_RANK_NONE, GST_TYPE_GL_VIEW_CONVERT_ELEMENT)) {
227     return FALSE;
228   }
229
230   if (!gst_element_register (plugin, "glstereosplit",
231           GST_RANK_NONE, GST_TYPE_GL_STEREOSPLIT)) {
232     return FALSE;
233   }
234 #ifdef HAVE_VIDEO_AGGREGATOR_IN_BASE
235   if (!gst_element_register (plugin, "glstereomix",
236           GST_RANK_NONE, GST_TYPE_GL_STEREO_MIX)) {
237     return FALSE;
238   }
239 #endif
240
241   if (!gst_element_register (plugin, "gltestsrc",
242           GST_RANK_NONE, GST_TYPE_GL_TEST_SRC)) {
243     return FALSE;
244   }
245
246   if (!gst_element_register (plugin, "gldeinterlace",
247           GST_RANK_NONE, GST_TYPE_GL_DEINTERLACE)) {
248     return FALSE;
249   }
250
251   if (!gst_element_register (plugin, "glalpha",
252           GST_RANK_NONE, GST_TYPE_GL_ALPHA)) {
253     return FALSE;
254   }
255
256   if (!gst_element_register (plugin, "gloverlaycompositor",
257           GST_RANK_NONE, GST_TYPE_GL_OVERLAY_COMPOSITOR_ELEMENT)) {
258     return FALSE;
259   }
260 #if defined(HAVE_JPEG) && defined(HAVE_PNG)
261   if (!gst_element_register (plugin, "gloverlay",
262           GST_RANK_NONE, gst_gl_overlay_get_type ())) {
263     return FALSE;
264   }
265 #endif
266 #if GST_GL_HAVE_OPENGL
267   if (!gst_element_register (plugin, "glfilterglass",
268           GST_RANK_NONE, GST_TYPE_GL_FILTER_GLASS)) {
269     return FALSE;
270   }
271 #if 0
272   if (!gst_element_register (plugin, "glfilterreflectedscreen",
273           GST_RANK_NONE, GST_TYPE_GL_FILTER_REFLECTED_SCREEN)) {
274     return FALSE;
275   }
276 #endif
277 #ifdef HAVE_VIDEO_AGGREGATOR_IN_BASE
278   if (!gst_element_register (plugin, "glmosaic",
279           GST_RANK_NONE, GST_TYPE_GL_MOSAIC)) {
280     return FALSE;
281   }
282 #endif
283 #ifdef HAVE_PNG
284   if (!gst_element_register (plugin, "gldifferencematte",
285           GST_RANK_NONE, gst_gl_differencematte_get_type ())) {
286     return FALSE;
287   }
288 #if 0
289   if (!gst_element_register (plugin, "glbumper",
290           GST_RANK_NONE, gst_gl_bumper_get_type ())) {
291     return FALSE;
292   }
293 #endif
294 #endif /* HAVE_PNG */
295 #endif /* GST_GL_HAVE_OPENGL */
296 #if GST_GL_HAVE_WINDOW_COCOA
297   if (!gst_element_register (plugin, "caopengllayersink",
298           GST_RANK_NONE, gst_ca_opengl_layer_sink_bin_get_type ())) {
299     return FALSE;
300   }
301 #endif
302
303   return TRUE;
304 }
305
306 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
307     GST_VERSION_MINOR,
308     opengl,
309     "OpenGL plugin",
310     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)