• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * Copyright (C) 2019 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   buf = gst_harness_create_buffer (h, 4);
42   buf = gst_harness_push_and_pull (h, buf);
43   fail_unless (buf != NULL);
44   gst_clear_buffer (&buf);
45 
46   g_object_get (G_OBJECT (h->element), "context", &gl_context, NULL);
47   fail_unless (gl_context != NULL);
48   gst_clear_object (&gl_context);
49 
50   new_display = gst_gl_display_new ();
51   fail_unless (gst_gl_display_create_context (new_display, NULL, &expected,
52           NULL));
53   fail_unless (expected != NULL);
54   fail_unless (gst_gl_display_add_context (new_display, expected));
55 
56   new_context = gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
57   gst_context_set_gl_display (new_context, new_display);
58 
59   gst_element_set_context (h->element, new_context);
60   gst_context_unref (new_context);
61   new_context = NULL;
62 
63   buf = gst_harness_create_buffer (h, 4);
64   buf = gst_harness_push_and_pull (h, buf);
65   fail_unless (buf != NULL);
66   gst_clear_buffer (&buf);
67 
68   g_object_get (G_OBJECT (h->element), "context", &gl_context, NULL);
69   fail_unless (gl_context != NULL);
70 
71   fail_unless (gl_context == expected);
72   fail_unless (new_display == gl_context->display);
73 
74   gst_object_unref (expected);
75   gst_object_unref (gl_context);
76   gst_object_unref (new_display);
77 }
78 
GST_START_TEST(test_glupload_display_replace)79 GST_START_TEST (test_glupload_display_replace)
80 {
81   GstHarness *upload;
82 
83   upload = gst_harness_new ("glupload");
84   gst_harness_set_caps_str (upload, "video/x-raw,format=RGBA,width=1,height=1",
85       "video/x-raw(memory:GLMemory),format=RGBA,width=1,height=1");
86 
87   replace_display (upload);
88 
89   gst_harness_teardown (upload);
90 }
91 
92 GST_END_TEST;
93 
GST_START_TEST(test_glcolorconvert_display_replace)94 GST_START_TEST (test_glcolorconvert_display_replace)
95 {
96   GstHarness *convert;
97 
98   convert = gst_harness_new ("glcolorconvert");
99   gst_harness_set_caps_str (convert,
100       "video/x-raw(memory:GLMemory),format=RGBA,width=1,height=1,texture-target=2D",
101       "video/x-raw(memory:GLMemory),format=RGBA,width=1,height=1,texture-target=2D");
102 
103   replace_display (convert);
104 
105   gst_harness_teardown (convert);
106 }
107 
108 GST_END_TEST;
109 
110 static Suite *
glfilter_suite(void)111 glfilter_suite (void)
112 {
113   Suite *s = suite_create ("glfilter");
114   TCase *tc = tcase_create ("general");
115 
116   tcase_add_test (tc, test_glupload_display_replace);
117   tcase_add_test (tc, test_glcolorconvert_display_replace);
118   suite_add_tcase (s, tc);
119 
120   return s;
121 }
122 
123 int
main(int argc,char ** argv)124 main (int argc, char **argv)
125 {
126   Suite *s;
127   g_setenv ("GST_GL_XINITTHREADS", "1", TRUE);
128   gst_check_init (&argc, &argv);
129   s = glfilter_suite ();
130   return gst_check_run_suite (s, "glfilter", __FILE__);
131 }
132