2 * Copyright (C) 2020 Igalia, S.L.
3 * Author: Víctor Jáquez <vjaquez@igalia.com>
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.
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.
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.
25 #include "gstvadevice.h"
27 #include <gudev/gudev.h>
28 #include "gstvadisplay_drm.h"
30 #define GST_CAT_DEFAULT gstva_debug
31 GST_DEBUG_CATEGORY_EXTERN (gstva_debug);
33 GST_DEFINE_MINI_OBJECT_TYPE (GstVaDevice, gst_va_device);
36 gst_va_device_free (GstVaDevice * device)
39 gst_object_unref (device->display);
40 g_free (device->render_device_path);
45 gst_va_device_new (GstVaDisplay * display, const gchar * render_device_path)
47 GstVaDevice *device = g_new0 (GstVaDevice, 1);
49 gst_mini_object_init (GST_MINI_OBJECT_CAST (device), 0, GST_TYPE_VA_DEVICE,
50 NULL, NULL, (GstMiniObjectFreeFunction) gst_va_device_free);
53 device->display = display;
54 device->render_device_path = g_strdup (render_device_path);
60 gst_va_device_find_devices (void)
63 GList *udev_devices, *dev;
64 GQueue devices = G_QUEUE_INIT;
66 client = g_udev_client_new (NULL);
67 udev_devices = g_udev_client_query_by_subsystem (client, "drm");
69 for (dev = udev_devices; dev; dev = g_list_next (dev)) {
71 GUdevDevice *udev = (GUdevDevice *) dev->data;
72 const gchar *path = g_udev_device_get_device_file (udev);
73 const gchar *name = g_udev_device_get_name (udev);
75 if (!path || !g_str_has_prefix (name, "renderD")) {
76 GST_LOG ("Ignoring %s in %s", name, path);
80 if (!(dpy = gst_va_display_drm_new_from_path (path)))
83 GST_INFO ("Found VA-API device: %s", path);
84 g_queue_push_tail (&devices, gst_va_device_new (dpy, path));
87 g_list_free_full (udev_devices, g_object_unref);
88 g_object_unref (client);
94 gst_va_device_list_free (GList * devices)
96 g_list_free_full (devices, (GDestroyNotify) gst_mini_object_unref);