• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * unit test for state changes on all elements
4  *
5  * Copyright (C) <2017> Julien Isorce <julien.isorce@gmail.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26 
27 #include <gst/check/gstcheck.h>
28 
29 #include <gst/gl/gl.h>
30 #include <gst/gl/gstglfuncs.h>
31 
32 static GstGLDisplay *display;
33 static GstGLContext *context;
34 
35 static void
setup(void)36 setup (void)
37 {
38   display = gst_gl_display_new ();
39   context = gst_gl_context_new (display);
40   gst_gl_context_create (context, 0, NULL);
41 }
42 
43 static void
teardown(void)44 teardown (void)
45 {
46   gst_object_unref (context);
47   gst_object_unref (display);
48 }
49 
50 /* keep in sync with the list in gstglformat.h */
51 static const struct
52 {
53   GstGLFormat format;
54   guint gl_type;
55   guint n_bytes;
56 } formats[] = {
57   /* *INDENT-OFF* */
58   {GST_GL_LUMINANCE, GL_UNSIGNED_BYTE, 1},
59   {GST_GL_ALPHA, GL_UNSIGNED_BYTE, 1},
60   {GST_GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2},
61   {GST_GL_RED, GL_UNSIGNED_BYTE, 1},
62   {GST_GL_R8, GL_UNSIGNED_BYTE, 1},
63   {GST_GL_RG, GL_UNSIGNED_BYTE, 2},
64   {GST_GL_RG8, GL_UNSIGNED_BYTE, 2},
65   {GST_GL_RGB, GL_UNSIGNED_BYTE, 3},
66   {GST_GL_RGB8, GL_UNSIGNED_BYTE, 3},
67   {GST_GL_RGB565, GL_UNSIGNED_SHORT_5_6_5, 2},
68   {GST_GL_RGB16, GL_UNSIGNED_SHORT, 6},
69   {GST_GL_RGBA, GL_UNSIGNED_BYTE, 4},
70   {GST_GL_RGBA8, GL_UNSIGNED_BYTE, 4},
71   {GST_GL_RGBA16, GL_UNSIGNED_SHORT, 8},
72 /*  {GST_GL_DEPTH_COMPONENT16, GL_UNSIGNED_BYTE, 2},
73   {GST_GL_DEPTH24_STENCIL8, GL_UNSIGNED_BYTE, 4},*/
74   /* *INDENT-ON* */
75 };
76 
GST_START_TEST(test_format_n_bytes)77 GST_START_TEST (test_format_n_bytes)
78 {
79   int i;
80 
81   for (i = 0; i < G_N_ELEMENTS (formats); i++) {
82     GST_DEBUG ("idx %i: expected %u, args format 0x%x, gl type 0x%x", i,
83         formats[i].n_bytes, formats[i].format, formats[i].gl_type);
84     fail_unless_equals_int (formats[i].n_bytes,
85         gst_gl_format_type_n_bytes (formats[i].format, formats[i].gl_type));
86   }
87 }
88 
89 GST_END_TEST;
90 
91 /* keep in sync with the list in gstglformat.h */
92 static const struct
93 {
94   GstGLFormat format;
95   GstGLFormat unsized_format;
96   guint gl_type;
97 } sized_formats[] = {
98   /* *INDENT-OFF* */
99   {GST_GL_LUMINANCE, GST_GL_LUMINANCE, GL_UNSIGNED_BYTE},
100   {GST_GL_ALPHA, GST_GL_ALPHA, GL_UNSIGNED_BYTE},
101   {GST_GL_LUMINANCE_ALPHA, GST_GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
102 /*  {GST_GL_R8, GST_GL_RED, GL_UNSIGNED_BYTE}, can be either R8 or RED depending on extensions and GL version */
103 /*  {GST_GL_R8, GST_GL_R8, GL_UNSIGNED_BYTE}, can be either R8 or RED depending on extensions and GL version */
104 /*  {GST_GL_RG8, GST_GL_RG, GL_UNSIGNED_BYTE}, can be either RG8 or RG depending on extensions and GL version */
105 /*  {GST_GL_RG8, GST_GL_RG8, GL_UNSIGNED_BYTE}, can be either RG8 or RG depending on extensions and GL version */
106   {GST_GL_RGB8, GST_GL_RGB, GL_UNSIGNED_BYTE},
107   {GST_GL_RGB8, GST_GL_RGB8, GL_UNSIGNED_BYTE},
108   {GST_GL_RGB565, GST_GL_RGB, GL_UNSIGNED_SHORT_5_6_5},
109   {GST_GL_RGB565, GST_GL_RGB565, GL_UNSIGNED_SHORT_5_6_5},
110   {GST_GL_RGB16, GST_GL_RGB, GL_UNSIGNED_SHORT},
111   {GST_GL_RGB16, GST_GL_RGB16, GL_UNSIGNED_SHORT},
112   {GST_GL_RGBA8, GST_GL_RGBA, GL_UNSIGNED_BYTE},
113   {GST_GL_RGBA8, GST_GL_RGBA8, GL_UNSIGNED_BYTE},
114   {GST_GL_RGBA16, GST_GL_RGBA, GL_UNSIGNED_SHORT},
115   {GST_GL_RGBA16, GST_GL_RGBA16, GL_UNSIGNED_SHORT},
116 /*  {GST_GL_DEPTH_COMPONENT16, GST_GL_DEPTH_COMPONENT16, GL_UNSIGNED_BYTE},
117   {GST_GL_DEPTH24_STENCIL8, GST_GL_DEPTH24_STENCIL8, GL_UNSIGNED_BYTE},*/
118   /* *INDENT-ON* */
119 };
120 
GST_START_TEST(test_sized_from_unsized)121 GST_START_TEST (test_sized_from_unsized)
122 {
123   int i;
124 
125   for (i = 0; i < G_N_ELEMENTS (sized_formats); i++) {
126     GST_DEBUG ("idx %i: expected 0x%x, args format 0x%x, gl type 0x%x", i,
127         sized_formats[i].format, sized_formats[i].unsized_format,
128         sized_formats[i].gl_type);
129     fail_unless_equals_int (sized_formats[i].format,
130         gst_gl_sized_gl_format_from_gl_format_type (context,
131             sized_formats[i].unsized_format, sized_formats[i].gl_type));
132   }
133 }
134 
135 GST_END_TEST;
136 
137 /* keep in sync with the list in gstglformat.h */
138 static const struct
139 {
140   GstGLFormat unsized_format;
141   guint gl_type;
142   GstGLFormat format;
143 } unsized_formats[] = {
144   /* *INDENT-OFF* */
145   {GST_GL_LUMINANCE, GL_UNSIGNED_BYTE, GST_GL_LUMINANCE},
146   {GST_GL_ALPHA, GL_UNSIGNED_BYTE, GST_GL_ALPHA},
147   {GST_GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GST_GL_LUMINANCE_ALPHA},
148   {GST_GL_RED, GL_UNSIGNED_BYTE, GST_GL_RED},
149   {GST_GL_RED, GL_UNSIGNED_BYTE, GST_GL_R8},
150   {GST_GL_RG, GL_UNSIGNED_BYTE, GST_GL_RG},
151   {GST_GL_RG, GL_UNSIGNED_BYTE, GST_GL_RG8},
152   {GST_GL_RGB, GL_UNSIGNED_BYTE, GST_GL_RGB},
153   {GST_GL_RGB, GL_UNSIGNED_BYTE, GST_GL_RGB8},
154   {GST_GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GST_GL_RGB565},
155   {GST_GL_RGB, GL_UNSIGNED_SHORT, GST_GL_RGB16},
156   {GST_GL_RGBA, GL_UNSIGNED_BYTE, GST_GL_RGBA},
157   {GST_GL_RGBA, GL_UNSIGNED_BYTE, GST_GL_RGBA8},
158   {GST_GL_RGBA, GL_UNSIGNED_SHORT, GST_GL_RGBA16},
159 /*  {GST_GL_DEPTH_COMPONENT16, GL_UNSIGNED_BYTE, GST_GL_DEPTH_COMPONENT16},
160   {GST_GL_DEPTH24_STENCIL8, GL_UNSIGNED_BYTE, GST_GL_DEPTH24_STENCIL8},*/
161   /* *INDENT-ON* */
162 };
163 
GST_START_TEST(test_unsized_from_sized)164 GST_START_TEST (test_unsized_from_sized)
165 {
166   int i;
167 
168   for (i = 0; i < G_N_ELEMENTS (unsized_formats); i++) {
169     GstGLFormat unsized_format;
170     guint gl_type;
171 
172     GST_DEBUG ("idx %i: expected 0x%x 0x%x, args format 0x%x", i,
173         unsized_formats[i].unsized_format, unsized_formats[i].gl_type,
174         unsized_formats[i].format);
175     gst_gl_format_type_from_sized_gl_format (unsized_formats[i].format,
176         &unsized_format, &gl_type);
177 
178     fail_unless_equals_int (unsized_formats[i].unsized_format, unsized_format);
179     fail_unless_equals_int (unsized_formats[i].gl_type, gl_type);
180   }
181 }
182 
183 GST_END_TEST;
184 
185 static GstGLTextureTarget texture_targets[] = {
186   GST_GL_TEXTURE_TARGET_2D,
187   GST_GL_TEXTURE_TARGET_RECTANGLE,
188   GST_GL_TEXTURE_TARGET_EXTERNAL_OES,
189 };
190 
GST_START_TEST(test_texture_target_strings)191 GST_START_TEST (test_texture_target_strings)
192 {
193   int i;
194 
195   for (i = 0; i < G_N_ELEMENTS (texture_targets); i++) {
196     GstGLTextureTarget res;
197     const gchar *str;
198 
199     str = gst_gl_texture_target_to_string (texture_targets[i]);
200     res = gst_gl_texture_target_from_string (str);
201 
202     GST_DEBUG ("from %u to \'%s\' to %u", texture_targets[i], str, res);
203 
204     fail_unless_equals_int (texture_targets[i], res);
205   }
206 }
207 
208 GST_END_TEST;
209 
GST_START_TEST(test_texture_target_gl)210 GST_START_TEST (test_texture_target_gl)
211 {
212   int i;
213 
214   for (i = 0; i < G_N_ELEMENTS (texture_targets); i++) {
215     GstGLTextureTarget res;
216     guint gl;
217 
218     gl = gst_gl_texture_target_to_gl (texture_targets[i]);
219     res = gst_gl_texture_target_from_gl (gl);
220 
221     GST_DEBUG ("from %u to 0x%x to %u", texture_targets[i], gl, res);
222 
223     fail_unless_equals_int (texture_targets[i], res);
224   }
225 }
226 
227 GST_END_TEST;
228 
229 static Suite *
gst_gl_format_suite(void)230 gst_gl_format_suite (void)
231 {
232   Suite *s = suite_create ("Gst GL Formats");
233   TCase *tc_chain = tcase_create ("general");
234 
235   suite_add_tcase (s, tc_chain);
236   tcase_add_checked_fixture (tc_chain, setup, teardown);
237   tcase_add_test (tc_chain, test_format_n_bytes);
238   tcase_add_test (tc_chain, test_sized_from_unsized);
239   tcase_add_test (tc_chain, test_unsized_from_sized);
240   tcase_add_test (tc_chain, test_texture_target_strings);
241   tcase_add_test (tc_chain, test_texture_target_gl);
242 
243   return s;
244 }
245 
246 GST_CHECK_MAIN (gst_gl_format);
247