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>
21 #include <gst/check/gstharness.h>
22 #include <gst/video/video.h>
26 test_buffer_meta_common (const gchar * in_caps, const gchar * out_caps,
27 const gchar * pipeline)
30 GstElement *capsfilter;
31 GstCaps *caps, *srccaps;
32 GstBuffer *in_buf, *out_buf = NULL;
35 GstVideoTimeCodeMeta *meta = NULL;
37 h = gst_harness_new_parse (pipeline);
38 fail_unless (h != NULL);
40 capsfilter = gst_harness_find_element (h, "capsfilter");
44 srccaps = gst_caps_from_string (in_caps);
45 fail_unless (srccaps != NULL);
46 fail_unless (gst_video_info_from_caps (&info, srccaps));
48 gst_harness_set_src_caps (h, srccaps);
50 /* enforce cuda memory */
51 caps = gst_caps_from_string (out_caps);
52 g_object_set (capsfilter, "caps", caps, NULL);
53 gst_caps_unref (caps);
54 gst_object_unref (capsfilter);
56 in_buf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&info));
57 gst_buffer_memset (in_buf, 0, 0, GST_VIDEO_INFO_SIZE (&info));
59 GST_BUFFER_DURATION (in_buf) = GST_SECOND;
60 GST_BUFFER_PTS (in_buf) = 0;
61 GST_BUFFER_DTS (in_buf) = GST_CLOCK_TIME_NONE;
63 gst_buffer_add_video_time_code_meta_full (in_buf, 30, 1,
64 NULL, GST_VIDEO_TIME_CODE_FLAGS_NONE, 0, 0, 1, 1, 0);
66 ret = gst_harness_push (h, gst_buffer_ref (in_buf));
67 fail_unless (ret == GST_FLOW_OK, "GstFlowReturn was %s",
68 gst_flow_get_name (ret));
70 out_buf = gst_harness_try_pull (h);
71 fail_unless (out_buf != NULL, "No output buffer");
73 meta = gst_buffer_get_video_time_code_meta (out_buf);
74 fail_unless (meta != NULL, "output buffer has no meta");
75 fail_unless_equals_int (meta->tc.config.fps_n, 30);
76 fail_unless_equals_int (meta->tc.config.fps_d, 1);
77 fail_unless_equals_int (meta->tc.seconds, 1);
79 gst_buffer_unref (in_buf);
80 gst_buffer_unref (out_buf);
82 gst_harness_teardown (h);
85 GST_START_TEST (test_buffer_meta)
87 /* test whether buffer meta would be preserved or not */
89 test_buffer_meta_common
90 ("video/x-raw,format=(string)NV12,width=340,height=240",
91 "video/x-raw(memory:CUDAMemory)", "cudaupload ! capsfilter");
92 test_buffer_meta_common
93 ("video/x-raw,format=(string)NV12,width=340,height=240", "video/x-raw",
94 "cudaupload ! cudadownload ! capsfilter");
95 test_buffer_meta_common
96 ("video/x-raw,format=(string)NV12,width=340,height=240",
97 "video/x-raw,format=(string)I420,width=340,height=240",
98 "cudaupload ! cudaconvert ! cudadownload ! capsfilter");
99 test_buffer_meta_common
100 ("video/x-raw,format=(string)NV12,width=340,height=240",
101 "video/x-raw,format=(string)NV12,width=640,height=480",
102 "cudaupload ! cudaconvert ! cudascale ! cudaconvert ! cudadownload ! capsfilter");
108 check_cuda_available (void)
112 elem = gst_element_factory_make ("cudaupload", NULL);
114 GST_WARNING ("cudaupload is not available, possibly driver load failure");
117 gst_object_unref (elem);
119 elem = gst_element_factory_make ("cudadownload", NULL);
121 GST_WARNING ("cudadownload is not available, possibly driver load failure");
124 gst_object_unref (elem);
126 elem = gst_element_factory_make ("cudaconvert", NULL);
128 GST_WARNING ("cudaconvert is not available, possibly driver load failure");
131 gst_object_unref (elem);
133 elem = gst_element_factory_make ("cudadownload", NULL);
135 GST_WARNING ("cudascale is not available, possibly driver load failure");
138 gst_object_unref (elem);
144 cudafilter_suite (void)
149 /* HACK: cuda device init/deinit with fork seems to problematic */
150 g_setenv ("CK_FORK", "no", TRUE);
152 s = suite_create ("cudafilter");
153 tc_chain = tcase_create ("general");
155 suite_add_tcase (s, tc_chain);
157 if (!check_cuda_available ()) {
158 GST_DEBUG ("Skip cuda filter test since cannot open device");
162 tcase_add_test (tc_chain, test_buffer_meta);
168 GST_CHECK_MAIN (cudafilter);