2 * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
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.
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.
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.
20 #include <gst/check/gstcheck.h>
23 bus_cb (GstBus * bus, GstMessage * message, gpointer data)
25 GMainLoop *loop = (GMainLoop *) data;
26 switch (GST_MESSAGE_TYPE (message)) {
27 case GST_MESSAGE_ERROR:{
31 gst_message_parse_error (message, &err, &debug);
33 GST_ERROR ("Error: %s : %s", err->message, debug);
37 fail_if (TRUE, "failed");
38 g_main_loop_quit (loop);
42 g_main_loop_quit (loop);
51 run_convert_pipelne (const gchar * in_format, const gchar * out_format)
54 GMainLoop *loop = g_main_loop_new (NULL, FALSE);
56 g_strdup_printf ("videotestsrc num-buffers=1 is-live=true ! "
57 "video/x-raw,format=%s,framerate=3/1 ! cudaupload ! "
58 "cudaconvert ! cudadownload ! video/x-raw,format=%s ! "
59 "videoconvert ! autovideosink", in_format, out_format);
62 pipeline = gst_parse_launch (pipeline_str, NULL);
63 fail_unless (pipeline != NULL);
64 g_free (pipeline_str);
66 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
67 gst_bus_add_watch (bus, (GstBusFunc) bus_cb, loop);
69 gst_element_set_state (pipeline, GST_STATE_PLAYING);
70 g_main_loop_run (loop);
71 gst_element_set_state (pipeline, GST_STATE_NULL);
73 gst_bus_remove_watch (bus);
74 gst_object_unref (bus);
75 gst_object_unref (pipeline);
76 g_main_loop_unref (loop);
79 GST_START_TEST (test_convert_yuv_yuv)
81 const gchar *format_list[] = {
82 "I420", "YV12", "NV12", "NV21", "P010_10LE", "I420_10LE",
88 for (i = 0; i < G_N_ELEMENTS (format_list); i++) {
89 for (j = 0; j < G_N_ELEMENTS (format_list); j++) {
93 GST_DEBUG ("run conversion %s to %s", format_list[i], format_list[j]);
94 run_convert_pipelne (format_list[i], format_list[j]);
101 GST_START_TEST (test_convert_yuv_rgb)
103 const gchar *in_format_list[] = {
104 "I420", "YV12", "NV12", "NV21", "P010_10LE", "I420_10LE",
107 const gchar *out_format_list[] = {
108 "BGRA", "RGBA", "RGBx", "BGRx", "ARGB", "ABGR", "RGB", "BGR", "BGR10A2_LE",
114 for (i = 0; i < G_N_ELEMENTS (in_format_list); i++) {
115 for (j = 0; j < G_N_ELEMENTS (out_format_list); j++) {
116 GST_DEBUG ("run conversion %s to %s", in_format_list[i],
118 run_convert_pipelne (in_format_list[i], out_format_list[j]);
125 GST_START_TEST (test_convert_rgb_yuv)
127 const gchar *in_format_list[] = {
128 "BGRA", "RGBA", "RGBx", "BGRx", "ARGB", "ABGR", "RGB", "BGR", "BGR10A2_LE",
131 const gchar *out_format_list[] = {
132 "I420", "YV12", "NV12", "NV21", "P010_10LE", "I420_10LE",
138 for (i = 0; i < G_N_ELEMENTS (in_format_list); i++) {
139 for (j = 0; j < G_N_ELEMENTS (out_format_list); j++) {
140 GST_DEBUG ("run conversion %s to %s", in_format_list[i],
142 run_convert_pipelne (in_format_list[i], out_format_list[j]);
149 GST_START_TEST (test_convert_rgb_rgb)
151 const gchar *format_list[] = {
152 "BGRA", "RGBA", "RGBx", "BGRx", "ARGB", "ABGR", "RGB", "BGR", "BGR10A2_LE",
158 for (i = 0; i < G_N_ELEMENTS (format_list); i++) {
159 for (j = 0; j < G_N_ELEMENTS (format_list); j++) {
163 GST_DEBUG ("run conversion %s to %s", format_list[i], format_list[j]);
164 run_convert_pipelne (format_list[i], format_list[j]);
172 check_cuda_convert_available (void)
177 upload = gst_element_factory_make ("cudaconvert", NULL);
179 GST_WARNING ("cudaconvert is not available, possibly driver load failure");
183 gst_object_unref (upload);
189 cudaconvert_suite (void)
194 /* HACK: cuda device init/deinit with fork seems to problematic */
195 g_setenv ("CK_FORK", "no", TRUE);
197 s = suite_create ("cudaconvert");
198 tc_chain = tcase_create ("general");
200 suite_add_tcase (s, tc_chain);
202 if (!check_cuda_convert_available ()) {
203 GST_DEBUG ("Skip cudaconvert test since cannot open device");
207 tcase_add_test (tc_chain, test_convert_yuv_yuv);
208 tcase_add_test (tc_chain, test_convert_yuv_rgb);
209 tcase_add_test (tc_chain, test_convert_rgb_yuv);
210 tcase_add_test (tc_chain, test_convert_rgb_rgb);
216 GST_CHECK_MAIN (cudaconvert);