1 /* GStreamer
2 * Copyright (C) 2012-2016 Matthew Waters <ystreet00@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <gst/check/gstcheck.h>
24 #include <gst/gl/gstglconfig.h>
25
26 #ifndef GST_DISABLE_PARSE
27
28 static GstElement *
setup_pipeline(const gchar * pipe_descr)29 setup_pipeline (const gchar * pipe_descr)
30 {
31 GstElement *pipeline;
32
33 pipeline = gst_parse_launch (pipe_descr, NULL);
34 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL);
35 return pipeline;
36 }
37
38 /*
39 * run_pipeline:
40 * @pipe: the pipeline to run
41 * @desc: the description for use in messages
42 * @events: is a mask of expected events
43 * @tevent: is the expected terminal event.
44 *
45 * the poll call will time out after half a second.
46 */
47 static void
run_pipeline(GstElement * pipe,const gchar * descr,GstMessageType events,GstMessageType tevent,GstState target_state)48 run_pipeline (GstElement * pipe, const gchar * descr,
49 GstMessageType events, GstMessageType tevent, GstState target_state)
50 {
51 GstBus *bus;
52 GstMessage *message;
53 GstMessageType revent;
54 GstStateChangeReturn ret;
55
56 g_assert (pipe);
57 bus = gst_element_get_bus (pipe);
58 g_assert (bus);
59
60 fail_if (gst_element_set_state (pipe, target_state) ==
61 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to playing", descr);
62 ret = gst_element_get_state (pipe, NULL, NULL, 10 * GST_SECOND);
63 if (ret == GST_STATE_CHANGE_ASYNC) {
64 g_critical ("Pipeline '%s' failed to go to PAUSED fast enough", descr);
65 goto done;
66 } else if ((ret != GST_STATE_CHANGE_SUCCESS)
67 && (ret != GST_STATE_CHANGE_NO_PREROLL)) {
68 g_critical ("Pipeline '%s' failed to go into PAUSED state (%s)", descr,
69 gst_element_state_change_return_get_name (ret));
70 goto done;
71 }
72
73 while (1) {
74 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
75
76 /* always have to pop the message before getting back into poll */
77 if (message) {
78 revent = GST_MESSAGE_TYPE (message);
79 gst_message_unref (message);
80 } else {
81 revent = GST_MESSAGE_UNKNOWN;
82 }
83
84 if (revent == tevent) {
85 break;
86 } else if (revent == GST_MESSAGE_UNKNOWN) {
87 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
88 tevent, descr);
89 break;
90 } else if (revent & events) {
91 continue;
92 }
93 g_critical
94 ("Unexpected message received of type %d, '%s', looking for %d: %s",
95 revent, gst_message_type_get_name (revent), tevent, descr);
96 }
97
98 done:
99 fail_if (gst_element_set_state (pipe, GST_STATE_NULL) ==
100 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to NULL", descr);
101 gst_element_get_state (pipe, NULL, NULL, GST_CLOCK_TIME_NONE);
102 gst_object_unref (pipe);
103
104 gst_bus_set_flushing (bus, TRUE);
105 gst_object_unref (bus);
106 }
107
GST_START_TEST(test_glimagesink)108 GST_START_TEST (test_glimagesink)
109 {
110 const gchar *s;
111 GstState target_state = GST_STATE_PLAYING;
112
113 s = "videotestsrc num-buffers=10 ! glimagesink";
114 run_pipeline (setup_pipeline (s), s,
115 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
116 GST_MESSAGE_UNKNOWN, target_state);
117 }
118
119 GST_END_TEST
GST_START_TEST(test_glfiltercube)120 GST_START_TEST (test_glfiltercube)
121 {
122 const gchar *s;
123 GstState target_state = GST_STATE_PLAYING;
124
125 s = "videotestsrc num-buffers=10 ! glupload ! glfiltercube ! fakesink";
126 run_pipeline (setup_pipeline (s), s,
127 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
128 GST_MESSAGE_UNKNOWN, target_state);
129 }
130
131 GST_END_TEST
132 #define N_EFFECTS 18
GST_START_TEST(test_gleffects)133 GST_START_TEST (test_gleffects)
134 {
135 gchar *s;
136 GstState target_state = GST_STATE_PLAYING;
137 guint i;
138
139 for (i = 0; i < N_EFFECTS; i++) {
140 s = g_strdup_printf ("videotestsrc num-buffers=10 ! glupload ! "
141 "gleffects effect=%i ! fakesink", i);
142 run_pipeline (setup_pipeline (s), s,
143 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
144 GST_MESSAGE_UNKNOWN, target_state);
145 g_free (s);
146 }
147 }
148
149 GST_END_TEST
150 #undef N_EFFECTS
GST_START_TEST(test_glshader)151 GST_START_TEST (test_glshader)
152 {
153 const gchar *s;
154 GstState target_state = GST_STATE_PLAYING;
155
156 s = "videotestsrc num-buffers=10 ! glupload ! glshader ! fakesink";
157 run_pipeline (setup_pipeline (s), s,
158 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
159 GST_MESSAGE_UNKNOWN, target_state);
160
161 s = "gltestsrc num-buffers=10 ! glshader ! fakesink";
162 run_pipeline (setup_pipeline (s), s,
163 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
164 GST_MESSAGE_UNKNOWN, target_state);
165 }
166
167 GST_END_TEST
GST_START_TEST(test_glfilterapp)168 GST_START_TEST (test_glfilterapp)
169 {
170 const gchar *s;
171 GstState target_state = GST_STATE_PLAYING;
172
173 s = "videotestsrc num-buffers=10 ! glupload ! glfilterapp ! fakesink";
174 run_pipeline (setup_pipeline (s), s,
175 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
176 GST_MESSAGE_UNKNOWN, target_state);
177
178 s = "gltestsrc num-buffers=10 ! glfilterapp ! fakesink";
179 run_pipeline (setup_pipeline (s), s,
180 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
181 GST_MESSAGE_UNKNOWN, target_state);
182 }
183
184 GST_END_TEST
GST_START_TEST(test_glmosaic)185 GST_START_TEST (test_glmosaic)
186 {
187 const gchar *s;
188 GstState target_state = GST_STATE_PLAYING;
189
190 s = "videotestsrc num-buffers=10 ! glupload ! glmosaic ! fakesink";
191 run_pipeline (setup_pipeline (s), s,
192 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
193 GST_MESSAGE_UNKNOWN, target_state);
194
195 s = "gltestsrc num-buffers=10 ! glmosaic ! fakesink";
196 run_pipeline (setup_pipeline (s), s,
197 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
198 GST_MESSAGE_UNKNOWN, target_state);
199 }
200
201 GST_END_TEST
GST_START_TEST(test_gloverlay)202 GST_START_TEST (test_gloverlay)
203 {
204 const gchar *s;
205 GstState target_state = GST_STATE_PLAYING;
206
207 s = "videotestsrc num-buffers=10 ! glupload ! gloverlay ! fakesink";
208 run_pipeline (setup_pipeline (s), s,
209 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
210 GST_MESSAGE_UNKNOWN, target_state);
211
212 s = "gltestsrc num-buffers=10 ! gloverlay ! fakesink";
213 run_pipeline (setup_pipeline (s), s,
214 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
215 GST_MESSAGE_UNKNOWN, target_state);
216 }
217
218 GST_END_TEST
219 #define N_SRCS 13
GST_START_TEST(test_gltestsrc)220 GST_START_TEST (test_gltestsrc)
221 {
222 gchar *s;
223 GstState target_state = GST_STATE_PLAYING;
224 guint i;
225
226 for (i = 0; i < N_SRCS; i++) {
227 s = g_strdup_printf ("gltestsrc pattern=%i num-buffers=10 ! fakesink", i);
228 run_pipeline (setup_pipeline (s), s,
229 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
230 GST_MESSAGE_UNKNOWN, target_state);
231 g_free (s);
232 }
233 }
234
235 GST_END_TEST
236 #undef N_SRCS
237 #if GST_GL_HAVE_OPENGL
GST_START_TEST(test_glfilterglass)238 GST_START_TEST (test_glfilterglass)
239 {
240 const gchar *s;
241 GstState target_state = GST_STATE_PLAYING;
242
243 s = "videotestsrc num-buffers=10 ! glupload ! glfilterglass ! fakesink";
244 run_pipeline (setup_pipeline (s), s,
245 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
246 GST_MESSAGE_UNKNOWN, target_state);
247
248 s = "gltestsrc num-buffers=10 ! glfilterglass ! fakesink";
249 run_pipeline (setup_pipeline (s), s,
250 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
251 GST_MESSAGE_UNKNOWN, target_state);
252 }
253
254 GST_END_TEST
255 #if 0
256 GST_START_TEST (test_glfilterreflectedscreen)
257 {
258 const gchar *s;
259 GstState target_state = GST_STATE_PLAYING;
260
261 s = "videotestsrc num-buffers=10 ! glupload ! glfilterreflectedscreen ! "
262 "fakesink";
263 run_pipeline (setup_pipeline (s), s,
264 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
265 GST_MESSAGE_UNKNOWN, target_state);
266
267 s = "gltestsrc num-buffers=10 ! glfilterreflectedscreen ! fakesink";
268 run_pipeline (setup_pipeline (s), s,
269 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
270 GST_MESSAGE_UNKNOWN, target_state);
271 }
272
273 GST_END_TEST
274 #endif
GST_START_TEST(test_gldeinterlace)275 GST_START_TEST (test_gldeinterlace)
276 {
277 const gchar *s;
278 GstState target_state = GST_STATE_PLAYING;
279
280 s = "videotestsrc num-buffers=10 ! glupload ! gldeinterlace ! fakesink";
281 run_pipeline (setup_pipeline (s), s,
282 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
283 GST_MESSAGE_UNKNOWN, target_state);
284
285 s = "gltestsrc num-buffers=10 ! gldeinterlace ! fakesink";
286 run_pipeline (setup_pipeline (s), s,
287 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
288 GST_MESSAGE_UNKNOWN, target_state);
289 }
290
291 GST_END_TEST
GST_START_TEST(test_gldifferencematte)292 GST_START_TEST (test_gldifferencematte)
293 {
294 const gchar *s;
295 GstState target_state = GST_STATE_PLAYING;
296
297 s = "videotestsrc num-buffers=10 ! glupload ! gldifferencematte ! fakesink";
298 run_pipeline (setup_pipeline (s), s,
299 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
300 GST_MESSAGE_UNKNOWN, target_state);
301
302 s = "gltestsrc num-buffers=10 ! gldifferencematte ! fakesink";
303 run_pipeline (setup_pipeline (s), s,
304 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
305 GST_MESSAGE_UNKNOWN, target_state);
306 }
307
308 GST_END_TEST
309 #endif /* GST_GL_HAVE_OPENGL */
310 #endif /* !GST_DISABLE_PARSE */
311 static Suite *
gl_launch_lines_suite(void)312 gl_launch_lines_suite (void)
313 {
314 gboolean have_gldifferencematte;
315 gboolean have_gloverlay;
316
317 Suite *s = suite_create ("OpenGL pipelines");
318 TCase *tc_chain = tcase_create ("linear");
319
320 /* time out after 60s, not the default 3 */
321 tcase_set_timeout (tc_chain, 60);
322
323 have_gldifferencematte =
324 gst_registry_check_feature_version (gst_registry_get (),
325 "gldifferencematte", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
326
327 have_gloverlay =
328 gst_registry_check_feature_version (gst_registry_get (),
329 "gloverlay", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
330
331 suite_add_tcase (s, tc_chain);
332 #ifndef GST_DISABLE_PARSE
333 tcase_add_test (tc_chain, test_glimagesink);
334 tcase_add_test (tc_chain, test_glfiltercube);
335 tcase_add_test (tc_chain, test_gleffects);
336 tcase_add_test (tc_chain, test_glshader);
337 tcase_add_test (tc_chain, test_glfilterapp);
338 tcase_add_test (tc_chain, test_glmosaic);
339 if (have_gloverlay) {
340 tcase_add_test (tc_chain, test_gloverlay);
341 }
342 tcase_add_test (tc_chain, test_gltestsrc);
343
344 #if GST_GL_HAVE_OPENGL
345 tcase_add_test (tc_chain, test_glfilterglass);
346 /* tcase_add_test (tc_chain, test_glfilterreflectedscreen);*/
347 tcase_add_test (tc_chain, test_gldeinterlace);
348
349 if (have_gldifferencematte) {
350 tcase_add_test (tc_chain, test_gldifferencematte);
351 }
352 /* tcase_add_test (tc_chain, test_glbumper);*/
353 #endif /* GST_GL_HAVE_OPENGL */
354 #endif /* !GST_DISABLE_PARSE */
355 return s;
356 }
357
358 GST_CHECK_MAIN (gl_launch_lines);
359