libs: va: Move the VA common logic as a lib.
authorHe Junyan <junyan.he@intel.com>
Thu, 6 May 2021 10:23:23 +0000 (18:23 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Tue, 18 May 2021 10:15:30 +0000 (12:15 +0200)
The VA acceleration now has more usages in linux-like platforms,
such as the MSDK. The different plugins based on the VA acceleration
need to share some common logic and types. We now move the display
related functions and types into a common va lib.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2196>

26 files changed:
gst-libs/gst/meson.build
gst-libs/gst/va/gstvadisplay.c [moved from sys/va/gstvadisplay.c with 75% similarity]
gst-libs/gst/va/gstvadisplay.h [new file with mode: 0644]
gst-libs/gst/va/gstvadisplay_drm.c [moved from sys/va/gstvadisplay_drm.c with 97% similarity]
gst-libs/gst/va/gstvadisplay_drm.h [new file with mode: 0644]
gst-libs/gst/va/gstvadisplay_wrapped.c [moved from sys/va/gstvadisplay_wrapped.c with 94% similarity]
gst-libs/gst/va/gstvadisplay_wrapped.h [new file with mode: 0644]
gst-libs/gst/va/meson.build [new file with mode: 0644]
gst-libs/gst/va/va-prelude.h [new file with mode: 0644]
gst-libs/gst/va/va_fwd.h [moved from sys/va/gstvadisplay_drm.h with 67% similarity]
sys/va/gstvaallocator.h
sys/va/gstvacaps.c
sys/va/gstvacaps.h
sys/va/gstvadecoder.c
sys/va/gstvadecoder.h
sys/va/gstvadevice.c
sys/va/gstvadevice.h
sys/va/gstvadisplay.h [deleted file]
sys/va/gstvadisplay_priv.c [new file with mode: 0644]
sys/va/gstvadisplay_priv.h [moved from sys/va/gstvadisplay_wrapped.h with 70% similarity]
sys/va/gstvafilter.c
sys/va/gstvafilter.h
sys/va/gstvautils.c
sys/va/gstvautils.h
sys/va/gstvavpp.c
sys/va/meson.build

index 809ab4a..a2862a3 100644 (file)
@@ -18,3 +18,4 @@ subdir('transcoder')
 subdir('vulkan')
 subdir('wayland')
 subdir('webrtc')
+subdir('va')
similarity index 75%
rename from sys/va/gstvadisplay.c
rename to gst-libs/gst/va/gstvadisplay.c
index a5139b1..65a0511 100644 (file)
@@ -23,8 +23,7 @@
 #endif
 
 #include "gstvadisplay.h"
-#include "gstvaprofile.h"
-#include "gstvavideoformat.h"
+#include <va/va.h>
 
 GST_DEBUG_CATEGORY (gst_va_display_debug);
 #define GST_CAT_DEFAULT gst_va_display_debug
@@ -208,6 +207,15 @@ gst_va_display_init (GstVaDisplay * self)
   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)
 {
@@ -220,6 +228,15 @@ gst_va_display_lock (GstVaDisplay * 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)
 {
@@ -282,6 +299,8 @@ _va_info (gpointer object, const char *message)
  *
  * Returns: %TRUE if the VA driver can be initialized; %FALSE
  *     otherwise
+ *
+ * Since: 1.20
  **/
 gboolean
 gst_va_display_initialize (GstVaDisplay * self)
@@ -321,127 +340,37 @@ gst_va_display_initialize (GstVaDisplay * self)
   return TRUE;
 }
 
-VADisplay
+/**
+ * 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 = 0;
-
-  g_return_val_if_fail (GST_IS_VA_DISPLAY (self), 0);
-
-  g_object_get (self, "va-display", &dpy, NULL);
-  return dpy;
-}
-
-GArray *
-gst_va_display_get_profiles (GstVaDisplay * self, guint32 codec,
-    VAEntrypoint entrypoint)
-{
-  GArray *ret = NULL;
   VADisplay dpy;
-  VAEntrypoint *entrypoints;
-  VAProfile *profiles;
-  VAStatus status;
-  gint i, j, num_entrypoints = 0, num_profiles = 0;
 
   g_return_val_if_fail (GST_IS_VA_DISPLAY (self), NULL);
 
-  dpy = gst_va_display_get_va_dpy (self);
-
-  gst_va_display_lock (self);
-  num_profiles = vaMaxNumProfiles (dpy);
-  num_entrypoints = vaMaxNumEntrypoints (dpy);
-  gst_va_display_unlock (self);
-
-  profiles = g_new (VAProfile, num_profiles);
-  entrypoints = g_new (VAEntrypoint, num_entrypoints);
-
-  gst_va_display_lock (self);
-  status = vaQueryConfigProfiles (dpy, profiles, &num_profiles);
-  gst_va_display_unlock (self);
-  if (status != VA_STATUS_SUCCESS) {
-    GST_ERROR ("vaQueryConfigProfile: %s", vaErrorStr (status));
-    goto bail;
-  }
-
-  for (i = 0; i < num_profiles; i++) {
-    if (codec != gst_va_profile_codec (profiles[i]))
-      continue;
-
-    gst_va_display_lock (self);
-    status = vaQueryConfigEntrypoints (dpy, profiles[i], entrypoints,
-        &num_entrypoints);
-    gst_va_display_unlock (self);
-    if (status != VA_STATUS_SUCCESS) {
-      GST_ERROR ("vaQueryConfigEntrypoints: %s", vaErrorStr (status));
-      goto bail;
-    }
-
-    for (j = 0; j < num_entrypoints; j++) {
-      if (entrypoints[j] == entrypoint) {
-        if (!ret)
-          ret = g_array_new (FALSE, FALSE, sizeof (VAProfile));
-        g_array_append_val (ret, profiles[i]);
-        break;
-      }
-    }
-  }
-
-bail:
-  g_free (entrypoints);
-  g_free (profiles);
-  return ret;
-}
-
-GArray *
-gst_va_display_get_image_formats (GstVaDisplay * self)
-{
-  GArray *ret = NULL;
-  GstVideoFormat format;
-  VADisplay dpy;
-  VAImageFormat *va_formats;
-  VAStatus status;
-  int i, max, num = 0;
-
-  g_return_val_if_fail (GST_IS_VA_DISPLAY (self), NULL);
-
-  dpy = gst_va_display_get_va_dpy (self);
-
-  gst_va_display_lock (self);
-  max = vaMaxNumImageFormats (dpy);
-  gst_va_display_unlock (self);
-  if (max == 0)
-    return NULL;
-
-  va_formats = g_new (VAImageFormat, max);
-
-  gst_va_display_lock (self);
-  status = vaQueryImageFormats (dpy, va_formats, &num);
-  gst_va_display_unlock (self);
-
-  gst_va_video_format_fix_map (va_formats, num);
-
-  if (status != VA_STATUS_SUCCESS) {
-    GST_ERROR ("vaQueryImageFormats: %s", vaErrorStr (status));
-    goto bail;
-  }
-
-  ret = g_array_sized_new (FALSE, FALSE, sizeof (GstVideoFormat), num);
-  for (i = 0; i < num; i++) {
-    format = gst_va_video_format_from_va_image_format (&va_formats[i]);
-    if (format != GST_VIDEO_FORMAT_UNKNOWN)
-      g_array_append_val (ret, format);
-  }
-
-  if (ret->len == 0) {
-    g_array_unref (ret);
-    ret = NULL;
-  }
-
-bail:
-  g_free (va_formats);
-  return ret;
+  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)
 {
diff --git a/gst-libs/gst/va/gstvadisplay.h b/gst-libs/gst/va/gstvadisplay.h
new file mode 100644 (file)
index 0000000..09def14
--- /dev/null
@@ -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
similarity index 97%
rename from sys/va/gstvadisplay_drm.c
rename to gst-libs/gst/va/gstvadisplay_drm.c
index 93625ea..092bab5 100644 (file)
@@ -41,6 +41,12 @@ struct _GstVaDisplayDrm
   gint fd;
 };
 
+struct _GstVaDisplayDrmClass
+{
+  /*< private > */
+  GstVaDisplayClass parent_class;
+};
+
 GST_DEBUG_CATEGORY_EXTERN (gst_va_display_debug);
 #define GST_CAT_DEFAULT gst_va_display_debug
 
@@ -170,6 +176,8 @@ gst_va_display_drm_init (GstVaDisplayDrm * self)
  * 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)
diff --git a/gst-libs/gst/va/gstvadisplay_drm.h b/gst-libs/gst/va/gstvadisplay_drm.h
new file mode 100644 (file)
index 0000000..6cf9326
--- /dev/null
@@ -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
similarity index 94%
rename from sys/va/gstvadisplay_wrapped.c
rename to gst-libs/gst/va/gstvadisplay_wrapped.c
index dd98251..9a3fea1 100644 (file)
@@ -29,6 +29,12 @@ 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);
@@ -51,6 +57,8 @@ gst_va_display_wrapped_init (GstVaDisplayWrapped * self)
  * VADisplay.
  *
  * Returns: a new #GstVaDisplay if @handle is valid, Otherwise %NULL.
+ *
+ * Since: 1.20
  **/
 GstVaDisplay *
 gst_va_display_wrapped_new (guintptr handle)
diff --git a/gst-libs/gst/va/gstvadisplay_wrapped.h b/gst-libs/gst/va/gstvadisplay_wrapped.h
new file mode 100644 (file)
index 0000000..93f36c9
--- /dev/null
@@ -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 (file)
index 0000000..9999fbd
--- /dev/null
@@ -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 (file)
index 0000000..3c901b2
--- /dev/null
@@ -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
similarity index 67%
rename from sys/va/gstvadisplay_drm.h
rename to gst-libs/gst/va/va_fwd.h
index 1b3121a..0b1b8cb 100644 (file)
@@ -1,6 +1,5 @@
 /* GStreamer
- * Copyright (C) 2020 Igalia, S.L.
- *     Author: Víctor Jáquez <vjaquez@igalia.com>
+ * 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
 
 #pragma once
 
-#include "gstvadisplay.h"
+#include <gst/gst.h>
 
 G_BEGIN_DECLS
 
-#define GST_TYPE_VA_DISPLAY_DRM (gst_va_display_drm_get_type())
-G_DECLARE_FINAL_TYPE (GstVaDisplayDrm, gst_va_display_drm, GST, VA_DISPLAY_DRM,
-    GstVaDisplay)
+typedef struct _GstVaDisplay GstVaDisplay;
+typedef struct _GstVaDisplayClass GstVaDisplayClass;
 
-GstVaDisplay *        gst_va_display_drm_new_from_path    (const gchar * path);
+typedef struct _GstVaDisplayDrm GstVaDisplayDrm;
+typedef struct _GstVaDisplayDrmClass GstVaDisplayDrmClass;
+
+typedef struct _GstVaDisplayWrapped GstVaDisplayWrapped;
+typedef struct _GstVaDisplayWrappedClass GstVaDisplayWrappedClass;
 
 G_END_DECLS
index e4123c2..de97fd6 100644 (file)
@@ -21,9 +21,9 @@
 #pragma once
 
 #include <gst/allocators/allocators.h>
+#include <gst/va/gstvadisplay.h>
 #include <gst/video/video.h>
-
-#include "gstvadisplay.h"
+#include <va/va.h>
 
 G_BEGIN_DECLS
 
index e421c81..1b0dd65 100644 (file)
 
 #include <va/va_drmcommon.h>
 
-#include "gstvadisplay.h"
+#include "gstvadisplay_priv.h"
 #include "gstvaprofile.h"
 #include "gstvavideoformat.h"
 
-GST_DEBUG_CATEGORY_EXTERN (gst_va_display_debug);
-#define GST_CAT_DEFAULT gst_va_display_debug
+GST_DEBUG_CATEGORY_EXTERN (gstva_debug);
+#define GST_CAT_DEFAULT gstva_debug
 
 static const guint va_rt_format_list[] = {
 #define R(name) G_PASTE (VA_RT_FORMAT_, name)
index c36ef05..096e656 100644 (file)
@@ -20,7 +20,8 @@
 
 #pragma once
 
-#include "gstvadisplay.h"
+#include <gst/va/gstvadisplay.h>
+#include <va/va.h>
 
 G_BEGIN_DECLS
 
index f477282..17c814a 100644 (file)
@@ -26,8 +26,9 @@
 
 #include "gstvaallocator.h"
 #include "gstvacaps.h"
-#include "gstvadisplay_wrapped.h"
+#include "gstvadisplay_priv.h"
 #include "gstvavideoformat.h"
+#include <gst/va/gstvadisplay_wrapped.h>
 
 struct _GstVaDecoder
 {
index c3a16a3..c6e31e2 100644 (file)
@@ -20,7 +20,8 @@
 
 #pragma once
 
-#include "gstvadisplay.h"
+#include <gst/va/gstvadisplay.h>
+#include <va/va.h>
 
 G_BEGIN_DECLS
 
index 0e251e1..1faa61f 100644 (file)
@@ -25,7 +25,6 @@
 #include "gstvadevice.h"
 
 #include <gudev/gudev.h>
-#include "gstvadisplay_drm.h"
 
 #define GST_CAT_DEFAULT gstva_debug
 GST_DEBUG_CATEGORY_EXTERN (gstva_debug);
index f5bc7df..774741a 100644 (file)
@@ -24,7 +24,7 @@
 
 G_BEGIN_DECLS
 
-#include "gstvadisplay.h"
+#include <gst/va/gstvadisplay_drm.h>
 
 #define GST_TYPE_VA_DEVICE    (gst_va_device_get_type())
 #define GST_IS_VA_DEVICE(obj) (GST_IS_MINI_OBJECT_TYPE((obj), GST_TYPE_VA_DEVICE))
diff --git a/sys/va/gstvadisplay.h b/sys/va/gstvadisplay.h
deleted file mode 100644 (file)
index a30c4bb..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/* 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/gst.h>
-#include <va/va.h>
-
-G_BEGIN_DECLS
-
-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;
-
-#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())
-G_DECLARE_DERIVABLE_TYPE (GstVaDisplay, gst_va_display, GST, VA_DISPLAY, GstObject)
-
-struct _GstVaDisplayClass
-{
-  /*< private > */
-  GstObjectClass parent_class;
-
-  /*< public > */
-  gpointer (*create_va_display) (GstVaDisplay * self);
-};
-
-void                  gst_va_display_lock                 (GstVaDisplay * self);
-void                  gst_va_display_unlock               (GstVaDisplay * self);
-gboolean              gst_va_display_initialize           (GstVaDisplay * self);
-VADisplay             gst_va_display_get_va_dpy           (GstVaDisplay * self);
-GArray *              gst_va_display_get_profiles         (GstVaDisplay * self,
-                                                           guint32 codec,
-                                                           VAEntrypoint entrypoint);
-GArray *              gst_va_display_get_image_formats    (GstVaDisplay * self);
-GstVaImplementation   gst_va_display_get_implementation   (GstVaDisplay * self);
-
-static inline gboolean
-gst_va_display_is_implementation (GstVaDisplay * self, GstVaImplementation impl)
-{
-  return (gst_va_display_get_implementation (self) == impl);
-}
-
-G_END_DECLS
diff --git a/sys/va/gstvadisplay_priv.c b/sys/va/gstvadisplay_priv.c
new file mode 100644 (file)
index 0000000..b9f970f
--- /dev/null
@@ -0,0 +1,137 @@
+/* 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_priv.h"
+#include "gstvaprofile.h"
+#include "gstvavideoformat.h"
+
+GArray *
+gst_va_display_get_profiles (GstVaDisplay * self, guint32 codec,
+    VAEntrypoint entrypoint)
+{
+  GArray *ret = NULL;
+  VADisplay dpy;
+  VAEntrypoint *entrypoints;
+  VAProfile *profiles;
+  VAStatus status;
+  gint i, j, num_entrypoints = 0, num_profiles = 0;
+
+  g_return_val_if_fail (GST_IS_VA_DISPLAY (self), NULL);
+
+  dpy = gst_va_display_get_va_dpy (self);
+
+  gst_va_display_lock (self);
+  num_profiles = vaMaxNumProfiles (dpy);
+  num_entrypoints = vaMaxNumEntrypoints (dpy);
+  gst_va_display_unlock (self);
+
+  profiles = g_new (VAProfile, num_profiles);
+  entrypoints = g_new (VAEntrypoint, num_entrypoints);
+
+  gst_va_display_lock (self);
+  status = vaQueryConfigProfiles (dpy, profiles, &num_profiles);
+  gst_va_display_unlock (self);
+  if (status != VA_STATUS_SUCCESS) {
+    GST_ERROR ("vaQueryConfigProfile: %s", vaErrorStr (status));
+    goto bail;
+  }
+
+  for (i = 0; i < num_profiles; i++) {
+    if (codec != gst_va_profile_codec (profiles[i]))
+      continue;
+
+    gst_va_display_lock (self);
+    status = vaQueryConfigEntrypoints (dpy, profiles[i], entrypoints,
+        &num_entrypoints);
+    gst_va_display_unlock (self);
+    if (status != VA_STATUS_SUCCESS) {
+      GST_ERROR ("vaQueryConfigEntrypoints: %s", vaErrorStr (status));
+      goto bail;
+    }
+
+    for (j = 0; j < num_entrypoints; j++) {
+      if (entrypoints[j] == entrypoint) {
+        if (!ret)
+          ret = g_array_new (FALSE, FALSE, sizeof (VAProfile));
+        g_array_append_val (ret, profiles[i]);
+        break;
+      }
+    }
+  }
+
+bail:
+  g_free (entrypoints);
+  g_free (profiles);
+  return ret;
+}
+
+GArray *
+gst_va_display_get_image_formats (GstVaDisplay * self)
+{
+  GArray *ret = NULL;
+  GstVideoFormat format;
+  VADisplay dpy;
+  VAImageFormat *va_formats;
+  VAStatus status;
+  int i, max, num = 0;
+
+  g_return_val_if_fail (GST_IS_VA_DISPLAY (self), NULL);
+
+  dpy = gst_va_display_get_va_dpy (self);
+
+  gst_va_display_lock (self);
+  max = vaMaxNumImageFormats (dpy);
+  gst_va_display_unlock (self);
+  if (max == 0)
+    return NULL;
+
+  va_formats = g_new (VAImageFormat, max);
+
+  gst_va_display_lock (self);
+  status = vaQueryImageFormats (dpy, va_formats, &num);
+  gst_va_display_unlock (self);
+
+  gst_va_video_format_fix_map (va_formats, num);
+
+  if (status != VA_STATUS_SUCCESS) {
+    GST_ERROR ("vaQueryImageFormats: %s", vaErrorStr (status));
+    goto bail;
+  }
+
+  ret = g_array_sized_new (FALSE, FALSE, sizeof (GstVideoFormat), num);
+  for (i = 0; i < num; i++) {
+    format = gst_va_video_format_from_va_image_format (&va_formats[i]);
+    if (format != GST_VIDEO_FORMAT_UNKNOWN)
+      g_array_append_val (ret, format);
+  }
+
+  if (ret->len == 0) {
+    g_array_unref (ret);
+    ret = NULL;
+  }
+
+bail:
+  g_free (va_formats);
+  return ret;
+}
similarity index 70%
rename from sys/va/gstvadisplay_wrapped.h
rename to sys/va/gstvadisplay_priv.h
index 752ecb5..86e5a6d 100644 (file)
 
 #pragma once
 
-#include "gstvadisplay.h"
+#include <gst/va/gstvadisplay.h>
+#include <va/va.h>
 
 G_BEGIN_DECLS
-
-#define GST_TYPE_VA_DISPLAY_WRAPPED gst_va_display_wrapped_get_type()
-G_DECLARE_FINAL_TYPE (GstVaDisplayWrapped, gst_va_display_wrapped, GST,
-    VA_DISPLAY_WRAPPED, GstVaDisplay)
-
-GstVaDisplay *        gst_va_display_wrapped_new  (guintptr handle);
+GArray *              gst_va_display_get_profiles         (GstVaDisplay * self,
+                                                           guint32 codec,
+                                                           VAEntrypoint entrypoint);
+GArray *              gst_va_display_get_image_formats    (GstVaDisplay * self);
 
 G_END_DECLS
index afd1f58..35e946a 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "gstvaallocator.h"
 #include "gstvacaps.h"
+#include "gstvadisplay_priv.h"
 #include "gstvavideoformat.h"
 
 struct _GstVaFilter
index 896694b..d6dbfb3 100644 (file)
 
 #pragma once
 
-#include "gstvadisplay.h"
-
+#include <gst/va/gstvadisplay.h>
 #include <gst/video/video.h>
 
+#include <va/va.h>
 #include <va/va_vpp.h>
 
 G_BEGIN_DECLS
index 6014f32..b11f501 100644 (file)
@@ -22,9 +22,9 @@
 #include "config.h"
 #endif
 
-#include "gstvadisplay_drm.h"
-#include "gstvadisplay_wrapped.h"
 #include "gstvautils.h"
+#include <gst/va/gstvadisplay_drm.h>
+#include <gst/va/gstvadisplay_wrapped.h>
 
 GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
 
@@ -164,7 +164,7 @@ gst_va_element_propagate_display_context (GstElement * element,
 
   _init_context_debug ();
 
-  ctxt = gst_context_new ("gst.va.display.handle", TRUE);
+  ctxt = gst_context_new (GST_VA_DISPLAY_HANDLE_CONTEXT_TYPE_STR, TRUE);
   gst_context_set_va_display (ctxt, display);
 
   GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
@@ -189,7 +189,7 @@ gst_va_ensure_element_data (gpointer element, const gchar * render_device_path,
   if (gst_va_display_found (element, g_atomic_pointer_get (display_ptr)))
     goto done;
 
-  _gst_context_query (element, "gst.va.display.handle");
+  _gst_context_query (element, GST_VA_DISPLAY_HANDLE_CONTEXT_TYPE_STR);
 
   /* Neighbour found and it updated the display */
   if (gst_va_display_found (element, g_atomic_pointer_get (display_ptr)))
@@ -222,7 +222,7 @@ gst_va_handle_set_context (GstElement * element, GstContext * context,
 
   context_type = gst_context_get_context_type (context);
 
-  if (g_strcmp0 (context_type, "gst.va.display.handle") == 0) {
+  if (g_strcmp0 (context_type, GST_VA_DISPLAY_HANDLE_CONTEXT_TYPE_STR) == 0) {
     type_name = G_OBJECT_TYPE_NAME (element);
     if (!gst_context_get_va_display (context, type_name, render_device_path,
             &display_replacement)) {
@@ -258,7 +258,8 @@ gst_va_handle_context_query (GstElement * element, GstQuery * query,
       "handle context query %" GST_PTR_FORMAT, query);
   gst_query_parse_context_type (query, &context_type);
 
-  if (!display || g_strcmp0 (context_type, "gst.va.display.handle") != 0)
+  if (!display
+      || g_strcmp0 (context_type, GST_VA_DISPLAY_HANDLE_CONTEXT_TYPE_STR) != 0)
     return FALSE;
 
   gst_query_parse_context (query, &old_ctxt);
@@ -266,7 +267,7 @@ gst_va_handle_context_query (GstElement * element, GstQuery * query,
   if (old_ctxt)
     ctxt = gst_context_copy (old_ctxt);
   else
-    ctxt = gst_context_new ("gst.va.display.handle", TRUE);
+    ctxt = gst_context_new (GST_VA_DISPLAY_HANDLE_CONTEXT_TYPE_STR, TRUE);
 
   gst_context_set_va_display (ctxt, display);
   gst_query_set_context (query, ctxt);
index 44ef7a9..3bca0b8 100644 (file)
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include "gstvadisplay.h"
+#include <gst/va/gstvadisplay.h>
 
 G_BEGIN_DECLS
 
index a7ce71b..70642c5 100644 (file)
@@ -77,7 +77,7 @@
 
 #include "gstvaallocator.h"
 #include "gstvacaps.h"
-#include "gstvadisplay_drm.h"
+#include "gstvadisplay_priv.h"
 #include "gstvafilter.h"
 #include "gstvapool.h"
 #include "gstvautils.h"
index 803b7e2..55b664b 100644 (file)
@@ -4,10 +4,8 @@ va_sources = [
   'gstvabasedec.c',
   'gstvacaps.c',
   'gstvadecoder.c',
-  'gstvadisplay.c',
-  'gstvadisplay_drm.c',
-  'gstvadisplay_wrapped.c',
   'gstvadevice.c',
+  'gstvadisplay_priv.c',
   'gstvafilter.c',
   'gstvah264dec.c',
   'gstvah265dec.c',
@@ -21,19 +19,17 @@ va_sources = [
   'gstvavpp.c'
 ]
 
-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'])
+if not gstva_dep.found()
+  if va_option.enabled()
+    error('The va plugin was enabled explicity, but required dependencies were not found.')
+  endif
+  subdir_done()
+endif
 
 libva_av1_req = ['>= 1.8']
 libva_av1_dep = dependency('libva', version: libva_av1_req, required: va_option)
@@ -41,14 +37,6 @@ if libva_av1_dep.found()
   va_sources += 'gstvaav1dec.c'
 endif
 
-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 plugin was enabled explicity, but required dependencies were not found.')
-  endif
-  subdir_done()
-endif
-
 cdata.set10('HAVE_LIBDRM', libdrm_dep.found())
 
 driverdir = libva_dep.get_pkgconfig_variable('driverdir')
@@ -61,7 +49,7 @@ gstva = library('gstva',
   va_sources,
   c_args : gst_plugins_bad_args + extra_c_args + gstva_cargs + ['-std=c99'],
   include_directories : [configinc],
-  dependencies : [gstbase_dep, gstvideo_dep, gstcodecs_dep, libva_dep, gstallocators_dep, libva_drm_dep, libgudev_dep, libdrm_dep] + extra_dep,
+  dependencies : [libva_dep, gstvideo_dep, gstcodecs_dep, gstallocators_dep, gstva_dep] + extra_dep,
   install : true,
   install_dir : plugins_install_dir,
 )