1 /* GStreamer
2 *
3 * Copyright (C) 2020 Matthew Waters <matthew@centricular.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
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <gst/gst.h>
27 #include <gst/gl/gl.h>
28 #include <gst/check/gstcheck.h>
29 #include <gst/check/gstharness.h>
30
31 static void
replace_display(GstHarness * h)32 replace_display (GstHarness * h)
33 {
34 GstContext *new_context;
35 GstGLDisplay *new_display;
36 GstGLContext *expected, *gl_context;
37 GstBuffer *buf;
38
39 /* replaces the GstGLDisplay used by @h with verification */
40
41 fail_unless_equals_int (GST_FLOW_OK, gst_harness_push_from_src (h));
42 /* need a second buffer to pull one, videoaggregator has one frame latency */
43 fail_unless_equals_int (GST_FLOW_OK, gst_harness_push_from_src (h));
44 buf = gst_harness_pull (h);
45 fail_unless (buf != NULL);
46 gst_clear_buffer (&buf);
47
48 g_object_get (G_OBJECT (h->element), "context", &gl_context, NULL);
49 fail_unless (gl_context != NULL);
50 gst_clear_object (&gl_context);
51
52 new_display = gst_gl_display_new ();
53 fail_unless (gst_gl_display_create_context (new_display, NULL, &expected,
54 NULL));
55 fail_unless (expected != NULL);
56 fail_unless (gst_gl_display_add_context (new_display, expected));
57
58 new_context = gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
59 gst_context_set_gl_display (new_context, new_display);
60
61 gst_element_set_context (h->element, new_context);
62 gst_context_unref (new_context);
63 new_context = NULL;
64
65 fail_unless_equals_int (GST_FLOW_OK, gst_harness_push_from_src (h));
66 buf = gst_harness_pull (h);
67 fail_unless (buf != NULL);
68 gst_clear_buffer (&buf);
69
70 g_object_get (G_OBJECT (h->element), "context", &gl_context, NULL);
71 fail_unless (gl_context != NULL);
72
73 fail_unless (gl_context == expected);
74 fail_unless (new_display == gl_context->display);
75
76 gst_object_unref (expected);
77 gst_object_unref (gl_context);
78 gst_object_unref (new_display);
79 }
80
GST_START_TEST(test_glvideomixer_negotiate)81 GST_START_TEST (test_glvideomixer_negotiate)
82 {
83 GstHarness *mix;
84 GstBuffer *buf;
85
86 mix = gst_harness_new_with_padnames ("glvideomixer", "sink_0", "src");
87 gst_harness_set_live (mix, FALSE);
88 gst_harness_set_blocking_push_mode (mix);
89 gst_harness_set_caps_str (mix,
90 "video/x-raw(memory:GLMemory),format=RGBA,width=1,height=1,framerate=25/1,texture-target=2D",
91 "video/x-raw(memory:GLMemory),format=RGBA,width=1,height=1,framerate=25/1,texture-target=2D");
92 gst_harness_add_src (mix, "gltestsrc", FALSE);
93 gst_harness_set_live (mix->src_harness, FALSE);
94 gst_harness_set_blocking_push_mode (mix->src_harness);
95
96 fail_unless_equals_int (GST_FLOW_OK, gst_harness_push_from_src (mix));
97 fail_unless (gst_harness_push_event (mix, gst_event_new_eos ()));
98
99 buf = gst_harness_pull (mix);
100 fail_unless (buf != NULL);
101 gst_clear_buffer (&buf);
102
103 gst_harness_teardown (mix);
104 }
105
106 GST_END_TEST;
107
GST_START_TEST(test_glvideomixer_display_replace)108 GST_START_TEST (test_glvideomixer_display_replace)
109 {
110 GstHarness *mix;
111
112 mix = gst_harness_new_with_padnames ("glvideomixer", "sink_0", "src");
113 gst_harness_set_live (mix, FALSE);
114 gst_harness_set_blocking_push_mode (mix);
115 gst_harness_set_caps_str (mix,
116 "video/x-raw(memory:GLMemory),format=RGBA,width=1,height=1,framerate=25/1,texture-target=2D",
117 "video/x-raw(memory:GLMemory),format=RGBA,width=1,height=1,framerate=25/1,texture-target=2D");
118 gst_harness_add_src (mix, "gltestsrc", FALSE);
119 gst_harness_set_live (mix->src_harness, FALSE);
120 gst_harness_set_blocking_push_mode (mix->src_harness);
121
122 replace_display (mix);
123
124 gst_harness_teardown (mix);
125 }
126
127 GST_END_TEST;
128
129 static Suite *
glmixer_suite(void)130 glmixer_suite (void)
131 {
132 Suite *s = suite_create ("glmixer");
133 TCase *tc = tcase_create ("general");
134
135 tcase_add_test (tc, test_glvideomixer_negotiate);
136 tcase_add_test (tc, test_glvideomixer_display_replace);
137 suite_add_tcase (s, tc);
138
139 return s;
140 }
141
142 int
main(int argc,char ** argv)143 main (int argc, char **argv)
144 {
145 Suite *s;
146 g_setenv ("GST_GL_XINITTHREADS", "1", TRUE);
147 gst_check_init (&argc, &argv);
148 s = glmixer_suite ();
149 return gst_check_run_suite (s, "glmixer", __FILE__);
150 }
151