summaryrefslogtreecommitdiff
path: root/gst-libs/gst
diff options
context:
space:
mode:
Diffstat (limited to 'gst-libs/gst')
-rw-r--r--gst-libs/gst/meson.build1
-rw-r--r--gst-libs/gst/va/gstvadisplay.c384
-rw-r--r--gst-libs/gst/va/gstvadisplay.h134
-rw-r--r--gst-libs/gst/va/gstvadisplay_drm.c196
-rw-r--r--gst-libs/gst/va/gstvadisplay_drm.h39
-rw-r--r--gst-libs/gst/va/gstvadisplay_wrapped.c77
-rw-r--r--gst-libs/gst/va/gstvadisplay_wrapped.h39
-rw-r--r--gst-libs/gst/va/meson.build60
-rw-r--r--gst-libs/gst/va/va-prelude.h30
-rw-r--r--gst-libs/gst/va/va_fwd.h35
10 files changed, 995 insertions, 0 deletions
diff --git a/gst-libs/gst/meson.build b/gst-libs/gst/meson.build
index 809ab4ac0..a2862a3d8 100644
--- a/gst-libs/gst/meson.build
+++ b/gst-libs/gst/meson.build
@@ -18,3 +18,4 @@ subdir('transcoder')
subdir('vulkan')
subdir('wayland')
subdir('webrtc')
+subdir('va')
diff --git a/gst-libs/gst/va/gstvadisplay.c b/gst-libs/gst/va/gstvadisplay.c
new file mode 100644
index 000000000..65a0511aa
--- /dev/null
+++ b/gst-libs/gst/va/gstvadisplay.c
@@ -0,0 +1,384 @@
+/* GStreamer
+ * Copyright (C) 2020 Igalia, S.L.
+ * Author: Víctor Jáquez <vjaquez@igalia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gstvadisplay.h"
+#include <va/va.h>
+
+GST_DEBUG_CATEGORY (gst_va_display_debug);
+#define GST_CAT_DEFAULT gst_va_display_debug
+
+typedef struct _GstVaDisplayPrivate GstVaDisplayPrivate;
+struct _GstVaDisplayPrivate
+{
+ GRecMutex lock;
+ VADisplay display;
+
+ gboolean foreign;
+ gboolean init;
+ GstVaImplementation impl;
+};
+
+#define gst_va_display_parent_class parent_class
+G_DEFINE_TYPE_WITH_CODE (GstVaDisplay, gst_va_display, GST_TYPE_OBJECT,
+ G_ADD_PRIVATE (GstVaDisplay);
+ GST_DEBUG_CATEGORY_INIT (gst_va_display_debug, "vadisplay", 0,
+ "VA Display"));
+enum
+{
+ PROP_VA_DISPLAY = 1,
+ N_PROPERTIES
+};
+
+static GParamSpec *g_properties[N_PROPERTIES];
+
+#define GET_PRIV(obj) gst_va_display_get_instance_private (GST_VA_DISPLAY (obj))
+
+static GstVaImplementation
+_get_implementation (const char *vendor)
+{
+ if (g_str_has_prefix (vendor, "Mesa Gallium driver"))
+ return GST_VA_IMPLEMENTATION_MESA_GALLIUM;
+ else if (g_str_has_prefix (vendor, "Intel i965 driver"))
+ return GST_VA_IMPLEMENTATION_INTEL_I965;
+ else if (g_str_has_prefix (vendor, "Intel iHD driver"))
+ return GST_VA_IMPLEMENTATION_INTEL_IHD;
+
+ return GST_VA_IMPLEMENTATION_OTHER;
+}
+
+static gboolean
+_gst_va_display_filter_driver (GstVaDisplay * self, gpointer foreign_display)
+{
+ GstVaDisplayPrivate *priv = GET_PRIV (self);
+ VADisplay dpy;
+ const char *vendor;
+
+ g_assert ((foreign_display != NULL) ^ (priv->display != NULL));
+ dpy = foreign_display ? foreign_display : priv->display;
+
+ vendor = vaQueryVendorString (dpy);
+ GST_INFO ("VA-API driver vendor: %s", vendor);
+
+ /* XXX(victor): driver allow list */
+
+ if (foreign_display) {
+ priv->display = foreign_display;
+ priv->foreign = TRUE;
+ }
+ priv->impl = _get_implementation (vendor);
+
+ return TRUE;
+}
+
+static void
+gst_va_display_set_display (GstVaDisplay * self, gpointer display)
+{
+ GstVaDisplayPrivate *priv = GET_PRIV (self);
+
+ if (!display)
+ return;
+
+ if (vaDisplayIsValid (display) == 0) {
+ GST_WARNING_OBJECT (self,
+ "User's VA display is invalid. An internal one will be tried.");
+ return;
+ }
+
+ /* assume driver is already initialized */
+ priv->init = TRUE;
+
+ _gst_va_display_filter_driver (self, display);
+}
+
+static void
+gst_va_display_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstVaDisplay *self = GST_VA_DISPLAY (object);
+
+ switch (prop_id) {
+ case PROP_VA_DISPLAY:{
+ gpointer display = g_value_get_pointer (value);
+ gst_va_display_set_display (self, display);
+ break;
+ }
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_va_display_get_property (GObject * object, guint prop_id, GValue * value,
+ GParamSpec * pspec)
+{
+ GstVaDisplayPrivate *priv = GET_PRIV (object);
+
+ switch (prop_id) {
+ case PROP_VA_DISPLAY:
+ g_value_set_pointer (value, priv->display);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_va_display_constructed (GObject * object)
+{
+ GstVaDisplay *self = GST_VA_DISPLAY (object);
+ GstVaDisplayPrivate *priv = GET_PRIV (object);
+ GstVaDisplayClass *klass = GST_VA_DISPLAY_GET_CLASS (object);
+
+ if (!priv->display && klass->create_va_display)
+ priv->display = klass->create_va_display (self);
+
+ G_OBJECT_CLASS (parent_class)->constructed (object);
+}
+
+static void
+gst_va_display_dispose (GObject * object)
+{
+ GstVaDisplayPrivate *priv = GET_PRIV (object);
+
+ if (priv->display && !priv->foreign)
+ vaTerminate (priv->display);
+ priv->display = NULL;
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+gst_va_display_finalize (GObject * object)
+{
+ GstVaDisplayPrivate *priv = GET_PRIV (object);
+
+ g_rec_mutex_clear (&priv->lock);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+gst_va_display_class_init (GstVaDisplayClass * klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->set_property = gst_va_display_set_property;
+ gobject_class->get_property = gst_va_display_get_property;
+ gobject_class->constructed = gst_va_display_constructed;
+ gobject_class->dispose = gst_va_display_dispose;
+ gobject_class->finalize = gst_va_display_finalize;
+
+ g_properties[PROP_VA_DISPLAY] =
+ g_param_spec_pointer ("va-display", "VADisplay", "VA Display handler",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (gobject_class, N_PROPERTIES, g_properties);
+}
+
+static void
+gst_va_display_init (GstVaDisplay * self)
+{
+ GstVaDisplayPrivate *priv = GET_PRIV (self);
+
+ g_rec_mutex_init (&priv->lock);
+ priv->impl = GST_VA_IMPLEMENTATION_INVALID;
+}
+
+/**
+ * gst_va_display_lock:
+ * @self: a #GstVaDisplay
+ *
+ * Lock the display. It will be used before we call the
+ * VA API functions to serialize the VA commands.
+ *
+ * Since: 1.20
+ **/
+void
+gst_va_display_lock (GstVaDisplay * self)
+{
+ GstVaDisplayPrivate *priv;
+
+ g_return_if_fail (GST_IS_VA_DISPLAY (self));
+
+ priv = GET_PRIV (self);
+
+ g_rec_mutex_lock (&priv->lock);
+}
+
+/**
+ * gst_va_display_unlock:
+ * @self: a #GstVaDisplay
+ *
+ * Unlock the display. It will be used after we call the
+ * VA API functions.
+ *
+ * Since: 1.20
+ **/
+void
+gst_va_display_unlock (GstVaDisplay * self)
+{
+ GstVaDisplayPrivate *priv;
+
+ g_return_if_fail (GST_IS_VA_DISPLAY (self));
+
+ priv = GET_PRIV (self);
+
+ g_rec_mutex_unlock (&priv->lock);
+}
+
+#ifndef GST_DISABLE_GST_DEBUG
+static gchar *
+_strip_msg (const char *message)
+{
+ gchar *msg = g_strdup (message);
+ if (!msg)
+ return NULL;
+ return g_strstrip (msg);
+}
+
+static void
+_va_warning (gpointer object, const char *message)
+{
+ GstVaDisplay *self = GST_VA_DISPLAY (object);
+ gchar *msg;
+
+ if ((msg = _strip_msg (message))) {
+ GST_WARNING_OBJECT (self, "VA error: %s", msg);
+ g_free (msg);
+ }
+}
+
+static void
+_va_info (gpointer object, const char *message)
+{
+ GstVaDisplay *self = GST_VA_DISPLAY (object);
+ gchar *msg;
+
+ if ((msg = _strip_msg (message))) {
+ GST_INFO_OBJECT (self, "VA info: %s", msg);
+ g_free (msg);
+ }
+}
+#endif
+
+/**
+ * gst_va_display_initialize:
+ * @self: a #GstVaDisplay
+ *
+ * If the display is set by the user (foreign) it is assumed that the
+ * driver is already initialized, thus this function is noop.
+ *
+ * If the display is opened internally, this function will initialize
+ * the driver and it will set driver's message callbacks.
+ *
+ * NOTE: this function is supposed to be private, only used by
+ * GstVaDisplay descendants.
+ *
+ * Returns: %TRUE if the VA driver can be initialized; %FALSE
+ * otherwise
+ *
+ * Since: 1.20
+ **/
+gboolean
+gst_va_display_initialize (GstVaDisplay * self)
+{
+ GstVaDisplayPrivate *priv;
+ VAStatus status;
+ int major_version = -1, minor_version = -1;
+
+ g_return_val_if_fail (GST_IS_VA_DISPLAY (self), FALSE);
+
+ priv = GET_PRIV (self);
+
+ if (priv->init)
+ return TRUE;
+
+ if (!priv->display)
+ return FALSE;
+
+#ifndef GST_DISABLE_GST_DEBUG
+ vaSetErrorCallback (priv->display, _va_warning, self);
+ vaSetInfoCallback (priv->display, _va_info, self);
+#endif
+
+ status = vaInitialize (priv->display, &major_version, &minor_version);
+ if (status != VA_STATUS_SUCCESS) {
+ GST_ERROR_OBJECT (self, "vaInitialize: %s", vaErrorStr (status));
+ return FALSE;
+ }
+
+ GST_INFO_OBJECT (self, "VA-API version %d.%d", major_version, minor_version);
+
+ priv->init = TRUE;
+
+ if (!_gst_va_display_filter_driver (self, NULL))
+ return FALSE;
+
+ return TRUE;
+}
+
+/**
+ * gst_va_display_get_va_dpy:
+ * @self: a #GstVaDisplay type display.
+ *
+ * Get the VA display handle of the @self.
+ *
+ * Returns: the VA display handle.
+ *
+ * Since: 1.20
+ */
+gpointer
+gst_va_display_get_va_dpy (GstVaDisplay * self)
+{
+ VADisplay dpy;
+
+ g_return_val_if_fail (GST_IS_VA_DISPLAY (self), NULL);
+
+ g_object_get (self, "va-display", &dpy, NULL);
+ return dpy;
+}
+
+/**
+ * gst_va_display_get_implementation:
+ * @self: a #GstVaDisplay type display.
+ *
+ * Get the the #GstVaImplementation type of @self.
+ *
+ * Returns: #GstVaImplementation.
+ *
+ * Since: 1.20
+ */
+GstVaImplementation
+gst_va_display_get_implementation (GstVaDisplay * self)
+{
+ GstVaDisplayPrivate *priv;
+
+ g_return_val_if_fail (GST_IS_VA_DISPLAY (self),
+ GST_VA_IMPLEMENTATION_INVALID);
+
+ priv = GET_PRIV (self);
+ return priv->impl;
+}
diff --git a/gst-libs/gst/va/gstvadisplay.h b/gst-libs/gst/va/gstvadisplay.h
new file mode 100644
index 000000000..09def14da
--- /dev/null
+++ b/gst-libs/gst/va/gstvadisplay.h
@@ -0,0 +1,134 @@
+/* GStreamer
+ * Copyright (C) 2020 Igalia, S.L.
+ * Author: Víctor Jáquez <vjaquez@igalia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include <gst/va/va_fwd.h>
+#include <gst/va/va-prelude.h>
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+/**
+ * GstVaImplementation:
+ * @GST_VA_IMPLEMENTATION_MESA_GALLIUM: The mesa gallium implementation.
+ * @GST_VA_IMPLEMENTATION_INTEL_I965: The legacy i965 intel implementation.
+ * @GST_VA_IMPLEMENTATION_INTEL_IHD: The iHD intel implementation.
+ * @GST_VA_IMPLEMENTATION_OTHER: Other implementation.
+ * @GST_VA_IMPLEMENTATION_INVALID: Invalid implementation.
+ *
+ * Types of different VA API implemented drivers. These are the typical and
+ * the most widely used VA drivers.
+ *
+ * Since: 1.20
+ */
+typedef enum
+{
+ GST_VA_IMPLEMENTATION_MESA_GALLIUM,
+ GST_VA_IMPLEMENTATION_INTEL_I965,
+ GST_VA_IMPLEMENTATION_INTEL_IHD,
+ GST_VA_IMPLEMENTATION_OTHER,
+ GST_VA_IMPLEMENTATION_INVALID,
+} GstVaImplementation;
+
+/**
+ * GST_VA_DISPLAY_HANDLE_CONTEXT_TYPE_STR:
+ *
+ * Since: 1.20
+ */
+#define GST_VA_DISPLAY_HANDLE_CONTEXT_TYPE_STR "gst.va.display.handle"
+
+/**
+ * GST_VA_DISPLAY_IS_IMPLEMENTATION: (skip)
+ *
+ * Check whether the display is the implementation of the specified
+ * #GstVaImplementation type.
+ */
+#define GST_VA_DISPLAY_IS_IMPLEMENTATION(display, impl) \
+ (gst_va_display_is_implementation (display, G_PASTE (GST_VA_IMPLEMENTATION_, impl)))
+
+#define GST_TYPE_VA_DISPLAY (gst_va_display_get_type())
+#define GST_VA_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_VA_DISPLAY, GstVaDisplay))
+#define GST_VA_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_VA_DISPLAY, GstVaDisplayClass))
+#define GST_IS_VA_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VA_DISPLAY))
+#define GST_IS_VA_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VA_DISPLAY))
+#define GST_VA_DISPLAY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_VA_DISPLAY, GstVaDisplayClass))
+
+/**
+ * GstVaDisplay:
+ *
+ * The common VA display object structure.
+ *
+ * Since: 1.20
+ */
+struct _GstVaDisplay
+{
+ /*< private > */
+ GstObject parent;
+};
+
+/**
+ * GstVaDisplayClass:
+ *
+ * The common VA display object class structure.
+ * @create_va_display: The function to create the real VA display.
+ *
+ * Since: 1.20
+ */
+struct _GstVaDisplayClass
+{
+ /*< private > */
+ GstObjectClass parent_class;
+
+ /*< public > */
+ gpointer (*create_va_display) (GstVaDisplay * self);
+};
+
+GST_VA_API
+GType gst_va_display_get_type (void);
+GST_VA_API
+void gst_va_display_lock (GstVaDisplay * self);
+GST_VA_API
+void gst_va_display_unlock (GstVaDisplay * self);
+GST_VA_API
+gboolean gst_va_display_initialize (GstVaDisplay * self);
+GST_VA_API
+gpointer gst_va_display_get_va_dpy (GstVaDisplay * self);
+GST_VA_API
+GstVaImplementation gst_va_display_get_implementation (GstVaDisplay * self);
+
+/**
+ * gst_va_display_is_implementation:
+ * @display: the #GstVaDisplay to check.
+ * @impl: the specified #GstVaImplementation.
+ *
+ * Check whether the @display is the implementation of the @impl type.
+ *
+ * Returns: %TRUE if the @display is the implementation of the @impl type.
+ *
+ * Since: 1.20
+ */
+static inline gboolean
+gst_va_display_is_implementation (GstVaDisplay * display, GstVaImplementation impl)
+{
+ return (gst_va_display_get_implementation (display) == impl);
+}
+
+G_END_DECLS
diff --git a/gst-libs/gst/va/gstvadisplay_drm.c b/gst-libs/gst/va/gstvadisplay_drm.c
new file mode 100644
index 000000000..092bab58b
--- /dev/null
+++ b/gst-libs/gst/va/gstvadisplay_drm.c
@@ -0,0 +1,196 @@
+/* GStreamer
+ * Copyright (C) 2020 Igalia, S.L.
+ * Author: Víctor Jáquez <vjaquez@igalia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gstvadisplay_drm.h"
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <va/va_drm.h>
+
+#if HAVE_LIBDRM
+#include <xf86drm.h>
+#endif
+
+struct _GstVaDisplayDrm
+{
+ GstVaDisplay parent;
+
+ gchar *path;
+ gint fd;
+};
+
+struct _GstVaDisplayDrmClass
+{
+ /*< private > */
+ GstVaDisplayClass parent_class;
+};
+
+GST_DEBUG_CATEGORY_EXTERN (gst_va_display_debug);
+#define GST_CAT_DEFAULT gst_va_display_debug
+
+#define gst_va_display_drm_parent_class parent_class
+G_DEFINE_TYPE (GstVaDisplayDrm, gst_va_display_drm, GST_TYPE_VA_DISPLAY);
+
+enum
+{
+ PROP_PATH = 1,
+ N_PROPERTIES
+};
+
+static GParamSpec *g_properties[N_PROPERTIES];
+
+#define MAX_DEVICES 8
+
+static void
+gst_va_display_drm_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstVaDisplayDrm *self = GST_VA_DISPLAY_DRM (object);
+
+ switch (prop_id) {
+ case PROP_PATH:
+ self->path = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_va_display_drm_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
+{
+ GstVaDisplayDrm *self = GST_VA_DISPLAY_DRM (object);
+
+ switch (prop_id) {
+ case PROP_PATH:
+ g_value_set_string (value, self->path);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_va_display_drm_finalize (GObject * object)
+{
+ GstVaDisplayDrm *self = GST_VA_DISPLAY_DRM (object);
+
+ g_free (self->path);
+ if (self->fd > -1)
+ close (self->fd);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static gpointer
+gst_va_display_drm_create_va_display (GstVaDisplay * display)
+{
+ int fd, saved_errno = 0;
+ GstVaDisplayDrm *self = GST_VA_DISPLAY_DRM (display);
+
+ fd = open (self->path, O_RDWR);
+ saved_errno = errno;
+ if (fd < 0) {
+ GST_WARNING_OBJECT (self, "Failed to open %s: %s", self->path,
+ g_strerror (saved_errno));
+ close (fd);
+ return 0;
+ }
+#if HAVE_LIBDRM
+ {
+ drmVersion *version;
+
+ version = drmGetVersion (fd);
+ if (!version) {
+ GST_ERROR_OBJECT (self, "Device %s is not a DRM render node", self->path);
+ return 0;
+ }
+ GST_INFO_OBJECT (self, "DRM render node with kernel driver %s",
+ version->name);
+ drmFreeVersion (version);
+ }
+#endif
+
+ self->fd = fd;
+ return vaGetDisplayDRM (self->fd);
+}
+
+static void
+gst_va_display_drm_class_init (GstVaDisplayDrmClass * klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GstVaDisplayClass *vadisplay_class = GST_VA_DISPLAY_CLASS (klass);
+
+ gobject_class->set_property = gst_va_display_drm_set_property;
+ gobject_class->get_property = gst_va_display_drm_get_property;
+ gobject_class->finalize = gst_va_display_drm_finalize;
+
+ vadisplay_class->create_va_display = gst_va_display_drm_create_va_display;
+
+ g_properties[PROP_PATH] =
+ g_param_spec_string ("path", "render-path", "The path of DRM device",
+ "/dev/dri/renderD128",
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (gobject_class, N_PROPERTIES, g_properties);
+}
+
+static void
+gst_va_display_drm_init (GstVaDisplayDrm * self)
+{
+ self->fd = -1;
+}
+
+/**
+ * gst_va_display_drm_new_from_path:
+ * @path: the path to the DRM device
+ *
+ * Creates a new #GstVaDisplay from a DRM device . It will try to open
+ * and operate the device in @path.
+ *
+ * Returns: a newly allocated #GstVaDisplay if the specified DRM
+ * render device could be opened and initialized; otherwise %NULL
+ * is returned.
+ *
+ * Since: 1.20
+ **/
+GstVaDisplay *
+gst_va_display_drm_new_from_path (const gchar * path)
+{
+ GstVaDisplay *dpy;
+
+ g_return_val_if_fail (path, NULL);
+
+ dpy = g_object_new (GST_TYPE_VA_DISPLAY_DRM, "path", path, NULL);
+ if (!gst_va_display_initialize (dpy)) {
+ gst_object_unref (dpy);
+ return NULL;
+ }
+
+ return gst_object_ref_sink (dpy);
+}
diff --git a/gst-libs/gst/va/gstvadisplay_drm.h b/gst-libs/gst/va/gstvadisplay_drm.h
new file mode 100644
index 000000000..6cf9326c4
--- /dev/null
+++ b/gst-libs/gst/va/gstvadisplay_drm.h
@@ -0,0 +1,39 @@
+/* GStreamer
+ * Copyright (C) 2020 Igalia, S.L.
+ * Author: Víctor Jáquez <vjaquez@igalia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include "gstvadisplay.h"
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_VA_DISPLAY_DRM (gst_va_display_drm_get_type())
+#define GST_VA_DISPLAY_DRM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_VA_DISPLAY_DRM, GstVaDisplayDrm))
+#define GST_VA_DISPLAY_DRM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_VA_DISPLAY_DRM, GstVaDisplayDrmClass))
+#define GST_IS_VA_DISPLAY_DRM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VA_DISPLAY_DRM))
+#define GST_IS_VA_DISPLAY_DRM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VA_DISPLAY_DRM))
+#define GST_VA_DISPLAY_DRM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_VA_DISPLAY_DRM, GstVaDisplayDrmClass))
+
+GST_VA_API
+GType gst_va_display_drm_get_type (void);
+GST_VA_API
+GstVaDisplay * gst_va_display_drm_new_from_path (const gchar * path);
+
+G_END_DECLS
diff --git a/gst-libs/gst/va/gstvadisplay_wrapped.c b/gst-libs/gst/va/gstvadisplay_wrapped.c
new file mode 100644
index 000000000..9a3fea112
--- /dev/null
+++ b/gst-libs/gst/va/gstvadisplay_wrapped.c
@@ -0,0 +1,77 @@
+/* GStreamer
+ * Copyright (C) 2020 Igalia, S.L.
+ * Author: Víctor Jáquez <vjaquez@igalia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gstvadisplay_wrapped.h"
+
+struct _GstVaDisplayWrapped
+{
+ GstVaDisplay parent;
+};
+
+struct _GstVaDisplayWrappedClass
+{
+ /*< private > */
+ GstVaDisplayClass parent_class;
+};
+
+#define gst_va_display_wrapped_parent_class parent_class
+G_DEFINE_TYPE (GstVaDisplayWrapped, gst_va_display_wrapped,
+ GST_TYPE_VA_DISPLAY);
+
+static void
+gst_va_display_wrapped_class_init (GstVaDisplayWrappedClass * klass)
+{
+}
+
+static void
+gst_va_display_wrapped_init (GstVaDisplayWrapped * self)
+{
+}
+
+/**
+ * gst_va_display_wrapped_new:
+ * @handle: a #VADisplay to wrap
+ *
+ * Creates a #GstVaDisplay wrapping an already created and initialized
+ * VADisplay.
+ *
+ * Returns: a new #GstVaDisplay if @handle is valid, Otherwise %NULL.
+ *
+ * Since: 1.20
+ **/
+GstVaDisplay *
+gst_va_display_wrapped_new (guintptr handle)
+{
+ GstVaDisplay *dpy;
+
+ g_return_val_if_fail (handle, NULL);
+
+ dpy = g_object_new (GST_TYPE_VA_DISPLAY_WRAPPED, "va-display", handle, NULL);
+ if (!gst_va_display_initialize (dpy)) {
+ gst_object_unref (dpy);
+ return NULL;
+ }
+
+ return gst_object_ref_sink (dpy);
+}
diff --git a/gst-libs/gst/va/gstvadisplay_wrapped.h b/gst-libs/gst/va/gstvadisplay_wrapped.h
new file mode 100644
index 000000000..93f36c969
--- /dev/null
+++ b/gst-libs/gst/va/gstvadisplay_wrapped.h
@@ -0,0 +1,39 @@
+/* GStreamer
+ * Copyright (C) 2020 Igalia, S.L.
+ * Author: Víctor Jáquez <vjaquez@igalia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include "gstvadisplay.h"
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_VA_DISPLAY_WRAPPED (gst_va_display_wrapped_get_type())
+#define GST_VA_DISPLAY_WRAPPED(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_VA_DISPLAY_WRAPPED, GstVaDisplayWrapped))
+#define GST_VA_DISPLAY_WRAPPED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_VA_DISPLAY_WRAPPED, GstVaDisplayWrappedClass))
+#define GST_IS_VA_DISPLAY_WRAPPED(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VA_DISPLAY_WRAPPED))
+#define GST_IS_VA_DISPLAY_WRAPPED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VA_DISPLAY_WRAPPED))
+#define GST_VA_DISPLAY_WRAPPED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_VA_DISPLAY_WRAPPED, GstVaDisplayWrappedClass))
+
+GST_VA_API
+GType gst_va_display_wrapped_get_type (void);
+GST_VA_API
+GstVaDisplay * gst_va_display_wrapped_new (guintptr handle);
+
+G_END_DECLS
diff --git a/gst-libs/gst/va/meson.build b/gst-libs/gst/va/meson.build
new file mode 100644
index 000000000..9999fbd92
--- /dev/null
+++ b/gst-libs/gst/va/meson.build
@@ -0,0 +1,60 @@
+va_sources = [
+ 'gstvadisplay.c',
+ 'gstvadisplay_drm.c',
+ 'gstvadisplay_wrapped.c',
+]
+
+va_headers = [
+ 'gstvadisplay.h',
+ 'gstvadisplay_drm.h',
+ 'gstvadisplay_wrapped.h',
+ 'va_fwd.h',
+ 'va-prelude.h',
+]
+
+gstva_dep = dependency('', required : false)
+
+have_va = false
+va_option = get_option('va')
+if va_option.disabled() or host_system != 'linux'
+ subdir_done()
+endif
+
+libva_req = ['>= 1.6']
+
+libva_dep = dependency('libva', version: libva_req, required: va_option)
+libva_drm_dep = dependency('libva-drm', version: libva_req, required: va_option)
+libgudev_dep = dependency('gudev-1.0', required: va_option)
+libdrm_dep = dependency('libdrm', required: false, fallback: ['libdrm', 'ext_libdrm'])
+
+have_va = libva_dep.found() and libva_drm_dep.found()
+if not (have_va and libgudev_dep.found())
+ if va_option.enabled()
+ error('The va lib was enabled explicity, but required dependencies were not found.')
+ endif
+ subdir_done()
+endif
+
+
+gstva = library('gstva-' + api_version,
+ va_sources,
+ c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API', '-DBUILDING_GST_VA'],
+ include_directories : [configinc, libsinc],
+ version : libversion,
+ soversion : soversion,
+ install : true,
+ dependencies : [gst_dep, libva_dep, libva_drm_dep, libgudev_dep, libdrm_dep],
+)
+
+pkgconfig.generate(gstva,
+ libraries : gst_dep,
+ variables : pkgconfig_variables,
+ subdirs : pkgconfig_subdirs,
+ name : 'gstreamer-va-1.0',
+ description : 'GStreamer VA support',
+)
+
+gstva_dep = declare_dependency(link_with : gstva,
+ include_directories : [libsinc],
+ dependencies : [gst_dep, libva_dep, libva_drm_dep, libgudev_dep, libdrm_dep])
+meson.override_dependency('gstreamer-va-1.0', gstva_dep)
diff --git a/gst-libs/gst/va/va-prelude.h b/gst-libs/gst/va/va-prelude.h
new file mode 100644
index 000000000..3c901b2a8
--- /dev/null
+++ b/gst-libs/gst/va/va-prelude.h
@@ -0,0 +1,30 @@
+/* GStreamer
+ * Copyright (C) 2021 GStreamer developers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include <gst/gst.h>
+
+#ifndef GST_VA_API
+# ifdef BUILDING_GST_VA
+# define GST_VA_API GST_API_EXPORT /* from config.h */
+# else
+# define GST_VA_API GST_API_IMPORT
+# endif
+#endif
diff --git a/gst-libs/gst/va/va_fwd.h b/gst-libs/gst/va/va_fwd.h
new file mode 100644
index 000000000..0b1b8cb33
--- /dev/null
+++ b/gst-libs/gst/va/va_fwd.h
@@ -0,0 +1,35 @@
+/* GStreamer
+ * Copyright (C) 2021 GStreamer developers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GstVaDisplay GstVaDisplay;
+typedef struct _GstVaDisplayClass GstVaDisplayClass;
+
+typedef struct _GstVaDisplayDrm GstVaDisplayDrm;
+typedef struct _GstVaDisplayDrmClass GstVaDisplayDrmClass;
+
+typedef struct _GstVaDisplayWrapped GstVaDisplayWrapped;
+typedef struct _GstVaDisplayWrappedClass GstVaDisplayWrappedClass;
+
+G_END_DECLS