1 /* GStreamer
2 *
3 * Unit tests for glimagesink
4 *
5 * Copyright (C) 2014 Julien Isorce <j.isorce@samsung.com>
6 * Copyright (C) 2016 Matthew Waters <matthew@centricular.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 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <gst/gst.h>
30 #include <gst/check/gstcheck.h>
31
32 typedef void (*ElementOperation) (GstElement * e, gpointer user_data);
33 typedef GstElement *(*CreateElement) (GstElement * src, gpointer unused);
34
35 #define CREATE_ELEMENT(e,c,d) \
36 g_signal_connect (e, "create-element", G_CALLBACK (c), d)
37
38 static GstElement *
_create_element_floating_cb(GstElement * src,const gchar * name)39 _create_element_floating_cb (GstElement * src, const gchar * name)
40 {
41 return gst_element_factory_make (name, NULL);
42 }
43
44 static GstElement *
_create_element_full_cb(GstElement * src,const gchar * name)45 _create_element_full_cb (GstElement * src, const gchar * name)
46 {
47 return gst_object_ref_sink (gst_element_factory_make (name, NULL));
48 }
49
50 struct src_data
51 {
52 const gchar *prop;
53 const gchar *element_name;
54 };
55
56 static void
_set_element_floating(GstElement * e,struct src_data * d)57 _set_element_floating (GstElement * e, struct src_data *d /* static */ )
58 {
59 g_object_set (e, d->prop, _create_element_floating_cb (e, d->element_name),
60 NULL);
61 }
62
63 static void
_set_element_full(GstElement * e,struct src_data * d)64 _set_element_full (GstElement * e, struct src_data *d /* static */ )
65 {
66 GstElement *element = _create_element_full_cb (e, d->element_name);
67 g_object_set (e, d->prop, element, NULL);
68 gst_object_unref (element);
69 }
70
71 static void
_set_element_floating_floating(GstElement * e,struct src_data * d)72 _set_element_floating_floating (GstElement * e,
73 struct src_data *d /* static */ )
74 {
75 _set_element_floating (e, d);
76 _set_element_floating (e, d);
77 }
78
79 static void
_set_element_floating_full(GstElement * e,struct src_data * d)80 _set_element_floating_full (GstElement * e, struct src_data *d /* static */ )
81 {
82 _set_element_floating (e, d);
83 _set_element_full (e, d);
84 }
85
86 static void
_set_element_full_full(GstElement * e,struct src_data * d)87 _set_element_full_full (GstElement * e, struct src_data *d /* static */ )
88 {
89 _set_element_full (e, d);
90 _set_element_full (e, d);
91 }
92
93 static void
_set_element_full_floating(GstElement * e,struct src_data * d)94 _set_element_full_floating (GstElement * e, struct src_data *d /* static */ )
95 {
96 _set_element_full (e, d);
97 _set_element_floating (e, d);
98 }
99
100 static void
_create_element_floating(GstElement * e,const gchar * name)101 _create_element_floating (GstElement * e, const gchar * name /* static */ )
102 {
103 CREATE_ELEMENT (e, _create_element_floating_cb, (gchar *) name);
104 }
105
106 static void
_create_element_full(GstElement * e,const gchar * name)107 _create_element_full (GstElement * e, const gchar * name /* static */ )
108 {
109 CREATE_ELEMENT (e, _create_element_full_cb, (gchar *) name);
110 }
111
112 static void
_test_glsrcbin(ElementOperation op,gpointer user_data)113 _test_glsrcbin (ElementOperation op, gpointer user_data)
114 {
115 GstElement *pipe = gst_pipeline_new (NULL);
116 GstElement *src = gst_element_factory_make ("glsrcbin", NULL);
117 GstElement *sink = gst_element_factory_make ("glimagesink", NULL);
118
119 gst_bin_add_many (GST_BIN (pipe), src, sink, NULL);
120 gst_element_link (src, sink);
121
122 op (src, user_data);
123
124 gst_element_set_state (pipe, GST_STATE_READY);
125 gst_element_set_state (pipe, GST_STATE_NULL);
126
127 gst_object_unref (pipe);
128 }
129
GST_START_TEST(test_glsrcbin_set_element_floating)130 GST_START_TEST (test_glsrcbin_set_element_floating)
131 {
132 struct src_data d = { "src", "gltestsrc" };
133 _test_glsrcbin ((ElementOperation) _set_element_floating, &d);
134 }
135
136 GST_END_TEST;
137
GST_START_TEST(test_glsrcbin_set_element_full)138 GST_START_TEST (test_glsrcbin_set_element_full)
139 {
140 struct src_data d = { "src", "gltestsrc" };
141 _test_glsrcbin ((ElementOperation) _set_element_full, &d);
142 }
143
144 GST_END_TEST;
145
GST_START_TEST(test_glsrcbin_set_element_floating_floating)146 GST_START_TEST (test_glsrcbin_set_element_floating_floating)
147 {
148 struct src_data d = { "src", "gltestsrc" };
149 _test_glsrcbin ((ElementOperation) _set_element_floating_floating, &d);
150 }
151
152 GST_END_TEST;
153
GST_START_TEST(test_glsrcbin_set_element_floating_full)154 GST_START_TEST (test_glsrcbin_set_element_floating_full)
155 {
156 struct src_data d = { "src", "gltestsrc" };
157 _test_glsrcbin ((ElementOperation) _set_element_floating_full, &d);
158 }
159
160 GST_END_TEST;
161
GST_START_TEST(test_glsrcbin_set_element_full_floating)162 GST_START_TEST (test_glsrcbin_set_element_full_floating)
163 {
164 struct src_data d = { "src", "gltestsrc" };
165 _test_glsrcbin ((ElementOperation) _set_element_full_floating, &d);
166 }
167
168 GST_END_TEST;
169
GST_START_TEST(test_glsrcbin_set_element_full_full)170 GST_START_TEST (test_glsrcbin_set_element_full_full)
171 {
172 struct src_data d = { "src", "gltestsrc" };
173 _test_glsrcbin ((ElementOperation) _set_element_full_full, &d);
174 }
175
176 GST_END_TEST;
177
GST_START_TEST(test_glsrcbin_create_element_floating)178 GST_START_TEST (test_glsrcbin_create_element_floating)
179 {
180 _test_glsrcbin ((ElementOperation) _create_element_floating,
181 (gchar *) "gltestsrc");
182 }
183
184 GST_END_TEST;
185
GST_START_TEST(test_glsrcbin_create_element_full)186 GST_START_TEST (test_glsrcbin_create_element_full)
187 {
188 _test_glsrcbin ((ElementOperation) _create_element_full,
189 (gchar *) "gltestsrc");
190 }
191
192 GST_END_TEST;
193
194 static void
_test_glsinkbin(ElementOperation op,gpointer user_data)195 _test_glsinkbin (ElementOperation op, gpointer user_data)
196 {
197 GstElement *pipe = gst_pipeline_new (NULL);
198 GstElement *src = gst_element_factory_make ("gltestsrc", NULL);
199 GstElement *sink = gst_element_factory_make ("glsinkbin", NULL);
200
201 gst_bin_add_many (GST_BIN (pipe), src, sink, NULL);
202 gst_element_link (src, sink);
203
204 op (sink, user_data);
205
206 gst_element_set_state (pipe, GST_STATE_READY);
207 gst_element_set_state (pipe, GST_STATE_NULL);
208
209 gst_object_unref (pipe);
210 }
211
GST_START_TEST(test_glsinkbin_set_element_floating)212 GST_START_TEST (test_glsinkbin_set_element_floating)
213 {
214 struct src_data d = { "sink", "glimagesinkelement" };
215
216 _test_glsinkbin ((ElementOperation) _set_element_floating, &d);
217 }
218
219 GST_END_TEST;
220
GST_START_TEST(test_glsinkbin_set_element_full)221 GST_START_TEST (test_glsinkbin_set_element_full)
222 {
223 struct src_data d = { "sink", "glimagesinkelement" };
224
225 _test_glsinkbin ((ElementOperation) _set_element_full, &d);
226 }
227
228 GST_END_TEST;
229
GST_START_TEST(test_glsinkbin_create_element_floating)230 GST_START_TEST (test_glsinkbin_create_element_floating)
231 {
232 _test_glsinkbin ((ElementOperation) _create_element_floating,
233 (gchar *) "glimagesinkelement");
234 }
235
236 GST_END_TEST;
237
GST_START_TEST(test_glsinkbin_create_element_full)238 GST_START_TEST (test_glsinkbin_create_element_full)
239 {
240 _test_glsinkbin ((ElementOperation) _create_element_full,
241 (gchar *) "glimagesinkelement");
242 }
243
244 GST_END_TEST;
245
GST_START_TEST(test_glsinkbin_set_element_floating_floating)246 GST_START_TEST (test_glsinkbin_set_element_floating_floating)
247 {
248 struct src_data d = { "sink", "glimagesinkelement" };
249 _test_glsinkbin ((ElementOperation) _set_element_floating_floating, &d);
250 }
251
252 GST_END_TEST;
253
GST_START_TEST(test_glsinkbin_set_element_floating_full)254 GST_START_TEST (test_glsinkbin_set_element_floating_full)
255 {
256 struct src_data d = { "sink", "glimagesinkelement" };
257 _test_glsinkbin ((ElementOperation) _set_element_floating_full, &d);
258 }
259
260 GST_END_TEST;
261
GST_START_TEST(test_glsinkbin_set_element_full_floating)262 GST_START_TEST (test_glsinkbin_set_element_full_floating)
263 {
264 struct src_data d = { "sink", "glimagesinkelement" };
265 _test_glsinkbin ((ElementOperation) _set_element_full_floating, &d);
266 }
267
268 GST_END_TEST;
269
GST_START_TEST(test_glsinkbin_set_element_full_full)270 GST_START_TEST (test_glsinkbin_set_element_full_full)
271 {
272 struct src_data d = { "sink", "glimagesinkelement" };
273 _test_glsinkbin ((ElementOperation) _set_element_full_full, &d);
274 }
275
276 GST_END_TEST;
277
278 static void
_test_glfilterbin(ElementOperation op,gpointer user_data)279 _test_glfilterbin (ElementOperation op, gpointer user_data)
280 {
281 GstElement *pipe = gst_pipeline_new (NULL);
282 GstElement *src = gst_element_factory_make ("gltestsrc", NULL);
283 GstElement *filter = gst_element_factory_make ("glfilterbin", NULL);
284 GstElement *sink = gst_element_factory_make ("glimagesinkelement", NULL);
285
286 gst_bin_add_many (GST_BIN (pipe), src, filter, sink, NULL);
287 gst_element_link_many (src, filter, sink, NULL);
288
289 op (filter, user_data);
290
291 gst_element_set_state (pipe, GST_STATE_READY);
292 gst_element_set_state (pipe, GST_STATE_NULL);
293
294 gst_object_unref (pipe);
295 }
296
GST_START_TEST(test_glfilterbin_set_element_floating)297 GST_START_TEST (test_glfilterbin_set_element_floating)
298 {
299 struct src_data d = { "filter", "gleffects_identity" };
300
301 _test_glfilterbin ((ElementOperation) _set_element_floating, &d);
302 }
303
304 GST_END_TEST;
305
GST_START_TEST(test_glfilterbin_set_element_full)306 GST_START_TEST (test_glfilterbin_set_element_full)
307 {
308 struct src_data d = { "filter", "gleffects_identity" };
309
310 _test_glfilterbin ((ElementOperation) _set_element_full, &d);
311 }
312
313 GST_END_TEST;
314
GST_START_TEST(test_glfilterbin_create_element_floating)315 GST_START_TEST (test_glfilterbin_create_element_floating)
316 {
317 _test_glfilterbin ((ElementOperation) _create_element_floating,
318 (gchar *) "gleffects_identity");
319 }
320
321 GST_END_TEST;
322
GST_START_TEST(test_glfilterbin_create_element_full)323 GST_START_TEST (test_glfilterbin_create_element_full)
324 {
325 _test_glfilterbin ((ElementOperation) _create_element_full,
326 (gchar *) "gleffects_identity");
327 }
328
329 GST_END_TEST;
330
GST_START_TEST(test_glfilterbin_set_element_floating_floating)331 GST_START_TEST (test_glfilterbin_set_element_floating_floating)
332 {
333 struct src_data d = { "filter", "gleffects_identity" };
334 _test_glfilterbin ((ElementOperation) _set_element_floating_floating, &d);
335 }
336
337 GST_END_TEST;
338
GST_START_TEST(test_glfilterbin_set_element_floating_full)339 GST_START_TEST (test_glfilterbin_set_element_floating_full)
340 {
341 struct src_data d = { "filter", "gleffects_identity" };
342 _test_glfilterbin ((ElementOperation) _set_element_floating_full, &d);
343 }
344
345 GST_END_TEST;
346
GST_START_TEST(test_glfilterbin_set_element_full_floating)347 GST_START_TEST (test_glfilterbin_set_element_full_floating)
348 {
349 struct src_data d = { "filter", "gleffects_identity" };
350 _test_glfilterbin ((ElementOperation) _set_element_full_floating, &d);
351 }
352
353 GST_END_TEST;
354
GST_START_TEST(test_glfilterbin_set_element_full_full)355 GST_START_TEST (test_glfilterbin_set_element_full_full)
356 {
357 struct src_data d = { "filter", "gleffects_identity" };
358 _test_glfilterbin ((ElementOperation) _set_element_full_full, &d);
359 }
360
361 GST_END_TEST;
362
363 #if 0
364 /* FIXME: add when gl mixers are added to base */
365 static void
366 _test_glmixerbin (ElementOperation op, gpointer user_data)
367 {
368 GstElement *pipe = gst_pipeline_new (NULL);
369 GstElement *src = gst_element_factory_make ("gltestsrc", NULL);
370 GstElement *mixer = gst_element_factory_make ("glmixerbin", NULL);
371 GstElement *sink = gst_element_factory_make ("glimagesinkelement", NULL);
372
373 gst_bin_add_many (GST_BIN (pipe), src, mixer, sink, NULL);
374 gst_element_link_many (src, mixer, sink, NULL);
375
376 op (mixer, user_data);
377
378 gst_element_set_state (pipe, GST_STATE_READY);
379 gst_element_set_state (pipe, GST_STATE_NULL);
380
381 gst_object_unref (pipe);
382 }
383
384 GST_START_TEST (test_glmixerbin_set_element_floating)
385 {
386 struct src_data d = { "mixer", "glvideomixerelement" };
387
388 _test_glmixerbin ((ElementOperation) _set_element_floating, &d);
389 }
390
391 GST_END_TEST;
392
393 GST_START_TEST (test_glmixerbin_set_element_full)
394 {
395 struct src_data d = { "mixer", "glvideomixerelement" };
396
397 _test_glmixerbin ((ElementOperation) _set_element_full, &d);
398 }
399
400 GST_END_TEST;
401
402 GST_START_TEST (test_glmixerbin_create_element_floating)
403 {
404 _test_glmixerbin ((ElementOperation) _create_element_floating,
405 (gchar *) "glvideomixerelement");
406 }
407
408 GST_END_TEST;
409
410 GST_START_TEST (test_glmixerbin_create_element_full)
411 {
412 _test_glmixerbin ((ElementOperation) _create_element_full,
413 (gchar *) "glvideomixerelement");
414 }
415
416 GST_END_TEST;
417
418 GST_START_TEST (test_glmixerbin_set_element_floating_floating)
419 {
420 struct src_data d = { "mixer", "glvideomixerelement" };
421 _test_glmixerbin ((ElementOperation) _set_element_floating_floating, &d);
422 }
423
424 GST_END_TEST;
425
426 GST_START_TEST (test_glmixerbin_set_element_floating_full)
427 {
428 struct src_data d = { "mixer", "glvideomixerelement" };
429 _test_glmixerbin ((ElementOperation) _set_element_floating_full, &d);
430 }
431
432 GST_END_TEST;
433
434 GST_START_TEST (test_glmixerbin_set_element_full_floating)
435 {
436 struct src_data d = { "mixer", "glvideomixerelement" };
437 _test_glmixerbin ((ElementOperation) _set_element_full_floating, &d);
438 }
439
440 GST_END_TEST;
441
442 GST_START_TEST (test_glmixerbin_set_element_full_full)
443 {
444 struct src_data d = { "mixer", "glvideomixerelement" };
445 _test_glmixerbin ((ElementOperation) _set_element_full_full, &d);
446 }
447
448 GST_END_TEST;
449 #endif
450 static Suite *
glbin_suite(void)451 glbin_suite (void)
452 {
453 Suite *s = suite_create ("glbin");
454 TCase *tc;
455
456 tc = tcase_create ("glsrcbin");
457 tcase_add_test (tc, test_glsrcbin_create_element_floating);
458 tcase_add_test (tc, test_glsrcbin_create_element_full);
459 tcase_add_test (tc, test_glsrcbin_set_element_floating);
460 tcase_add_test (tc, test_glsrcbin_set_element_full);
461 tcase_add_test (tc, test_glsrcbin_set_element_floating_floating);
462 tcase_add_test (tc, test_glsrcbin_set_element_full_floating);
463 tcase_add_test (tc, test_glsrcbin_set_element_floating_full);
464 tcase_add_test (tc, test_glsrcbin_set_element_full_full);
465 suite_add_tcase (s, tc);
466
467 tc = tcase_create ("glsinkbin");
468 tcase_add_test (tc, test_glsinkbin_create_element_floating);
469 tcase_add_test (tc, test_glsinkbin_create_element_full);
470 tcase_add_test (tc, test_glsinkbin_set_element_floating);
471 tcase_add_test (tc, test_glsinkbin_set_element_full);
472 tcase_add_test (tc, test_glsinkbin_set_element_floating_floating);
473 tcase_add_test (tc, test_glsinkbin_set_element_full_floating);
474 tcase_add_test (tc, test_glsinkbin_set_element_floating_full);
475 tcase_add_test (tc, test_glsinkbin_set_element_full_full);
476 suite_add_tcase (s, tc);
477
478 tc = tcase_create ("glfilterbin");
479 tcase_add_test (tc, test_glfilterbin_create_element_floating);
480 tcase_add_test (tc, test_glfilterbin_create_element_full);
481 tcase_add_test (tc, test_glfilterbin_set_element_floating);
482 tcase_add_test (tc, test_glfilterbin_set_element_full);
483 tcase_add_test (tc, test_glfilterbin_set_element_floating_floating);
484 tcase_add_test (tc, test_glfilterbin_set_element_full_floating);
485 tcase_add_test (tc, test_glfilterbin_set_element_floating_full);
486 tcase_add_test (tc, test_glfilterbin_set_element_full_full);
487 suite_add_tcase (s, tc);
488
489 #if 0
490 tc = tcase_create ("glmixerbin");
491 tcase_add_test (tc, test_glmixerbin_create_element_floating);
492 tcase_add_test (tc, test_glmixerbin_create_element_full);
493 tcase_add_test (tc, test_glmixerbin_set_element_floating);
494 tcase_add_test (tc, test_glmixerbin_set_element_full);
495 tcase_add_test (tc, test_glmixerbin_set_element_floating_floating);
496 tcase_add_test (tc, test_glmixerbin_set_element_full_floating);
497 tcase_add_test (tc, test_glmixerbin_set_element_floating_full);
498 tcase_add_test (tc, test_glmixerbin_set_element_full_full);
499 suite_add_tcase (s, tc);
500 #endif
501 return s;
502 }
503
504 GST_CHECK_MAIN (glbin)
505