1 /* GStreamer Vulkan device provider unit test
2 *
3 * Copyright (C) 2019 Matthew Wayers <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 #include <gst/check/gstcheck.h>
22 #include <gst/vulkan/vulkan.h>
23
24 static GstDeviceMonitor *
vulkan_sink_device_provider(void)25 vulkan_sink_device_provider (void)
26 {
27 GstDeviceMonitor *monitor = gst_device_monitor_new ();
28 GstCaps *caps;
29
30 caps = gst_caps_from_string ("video/x-raw(memory:VulkanImage)");
31 gst_device_monitor_add_filter (monitor, "Video/Sink", caps);
32 gst_caps_unref (caps);
33
34 gst_device_monitor_start (monitor);
35
36 return monitor;
37 }
38
GST_START_TEST(vulkan_provider_creation)39 GST_START_TEST (vulkan_provider_creation)
40 {
41 GstDeviceMonitor *monitor;
42 GList *devices, *l;
43 gboolean found_vulkan_device = FALSE;
44
45 monitor = vulkan_sink_device_provider ();
46 devices = gst_device_monitor_get_devices (monitor);
47
48 for (l = devices; l; l = g_list_next (l)) {
49 GstDevice *device = GST_DEVICE (l->data);
50 GstVulkanPhysicalDevice *vk_phys_device;
51 GstVulkanDevice *elem_device;
52 GstElement *pipeline, *sink, *upload, *src;
53 GParamSpec *pspec;
54
55 if (!(pspec =
56 g_object_class_find_property (G_OBJECT_GET_CLASS (device),
57 "physical-device")))
58 continue;
59 if (G_PARAM_SPEC_VALUE_TYPE (pspec) != GST_TYPE_VULKAN_PHYSICAL_DEVICE)
60 continue;
61
62 found_vulkan_device = TRUE;
63 g_object_get (device, "physical-device", &vk_phys_device, NULL);
64 fail_unless (GST_IS_VULKAN_PHYSICAL_DEVICE (vk_phys_device));
65
66 pipeline = gst_pipeline_new ("vkdeviceprovider");
67 src = gst_element_factory_make ("videotestsrc", NULL);
68 upload = gst_element_factory_make ("vulkanupload", NULL);
69 sink = gst_device_create_element (device, NULL);
70
71 fail_unless (gst_bin_add (GST_BIN (pipeline), src));
72 fail_unless (gst_bin_add (GST_BIN (pipeline), upload));
73 fail_unless (gst_bin_add (GST_BIN (pipeline), sink));
74 fail_unless (gst_element_link_many (src, upload, sink, NULL));
75 gst_element_set_state (pipeline, GST_STATE_READY);
76
77 g_object_get (sink, "device", &elem_device, NULL);
78 fail_unless (GST_IS_VULKAN_DEVICE (elem_device));
79
80 GST_DEBUG ("%p =? %p", vk_phys_device, elem_device->physical_device);
81 fail_unless (vk_phys_device == elem_device->physical_device);
82
83 gst_object_unref (vk_phys_device);
84 gst_object_unref (elem_device);
85
86 gst_element_set_state (pipeline, GST_STATE_NULL);
87 gst_object_unref (pipeline);
88 }
89 g_list_free_full (devices, gst_object_unref);
90 gst_device_monitor_stop (monitor);
91 gst_object_unref (monitor);
92
93 if (!found_vulkan_device)
94 GST_WARNING ("No vulkan devices found");
95 }
96
97 GST_END_TEST;
98
99 static Suite *
vkdeviceprovider_suite(void)100 vkdeviceprovider_suite (void)
101 {
102 Suite *s = suite_create ("vkdeviceprovider");
103 TCase *tc_basic = tcase_create ("general");
104 GstVulkanInstance *instance;
105 gboolean have_instance;
106
107 suite_add_tcase (s, tc_basic);
108
109 /* FIXME: CI doesn't have a software vulkan renderer (and none exists currently) */
110 instance = gst_vulkan_instance_new ();
111 have_instance = gst_vulkan_instance_open (instance, NULL);
112 gst_object_unref (instance);
113 if (have_instance) {
114 tcase_add_test (tc_basic, vulkan_provider_creation);
115 }
116
117 return s;
118 }
119
120 GST_CHECK_MAIN (vkdeviceprovider);
121