[Spice-commits] configure.ac meson.build src/channel-display-gst.c src/Makefile.am src/spice-widget.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jan 15 14:39:22 UTC 2019


 configure.ac              |    5 ++++
 meson.build               |    5 ++++
 src/Makefile.am           |    2 +
 src/channel-display-gst.c |    8 ++++--
 src/spice-widget.c        |   57 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 75 insertions(+), 2 deletions(-)

New commits:
commit 61f6138bb5c88acda418555a0ebe17b7ffff9a6b
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Nov 23 13:32:14 2018 +0000

    Fix overlay for vaapisink
    
    The vaapisink plugin to support overlay requires the application
    to provide the proper context. If you don't do so the plugin will
    cause a crash of the application.
    To avoid possible thread errors from X11 create a new Display
    connection to pass to vaapisink.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Snir Sheriber <ssheribe at redhat.com>

diff --git a/configure.ac b/configure.ac
index 5d6a1a0..2f63422 100644
--- a/configure.ac
+++ b/configure.ac
@@ -175,6 +175,11 @@ PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
 
 PKG_CHECK_MODULES(JSON, json-glib-1.0)
 
+PKG_CHECK_EXISTS([libva-x11], [
+    PKG_CHECK_MODULES(LIBVA, libva-x11)
+    AC_DEFINE([HAVE_LIBVA], [1], [Define if libva is available])
+])
+
 AC_ARG_ENABLE([webdav],
   AS_HELP_STRING([--enable-webdav=@<:@auto/yes/no@:>@],
                  [Enable webdav support @<:@default=auto@:>@]),
diff --git a/meson.build b/meson.build
index 94d660a..d7062af 100644
--- a/meson.build
+++ b/meson.build
@@ -134,6 +134,11 @@ if d.found()
   if host_machine.system() != 'windows'
     spice_gtk_deps += dependency('epoxy')
     spice_gtk_deps += dependency('x11')
+    d = dependency('libva-x11', required: false)
+    if d.found()
+      spice_gtk_deps += d
+      spice_gtk_config_data.set('HAVE_LIBVA', '1')
+    endif
   endif
   spice_gtk_has_gtk = true
 endif
diff --git a/src/Makefile.am b/src/Makefile.am
index abc2f69..a9617d4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -89,6 +89,7 @@ SPICE_COMMON_CPPFLAGS =						\
 	$(GUDEV_CFLAGS)						\
 	$(SOUP_CFLAGS)						\
 	$(PHODAV_CFLAGS)					\
+	$(LIBVA_CFLAGS)						\
 	$(X11_CFLAGS)					\
 	$(LZ4_CFLAGS)					\
 	$(NULL)
@@ -112,6 +113,7 @@ SPICE_GTK_LIBADD_COMMON =		\
 	$(CAIRO_LIBS)			\
 	$(X11_LIBS)			\
 	$(LIBM)				\
+	$(LIBVA_LIBS)			\
 	$(NULL)
 
 SPICE_GTK_SOURCES_COMMON =		\
diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
index 2f556fe..5b7b776 100644
--- a/src/channel-display-gst.c
+++ b/src/channel-display-gst.c
@@ -406,14 +406,17 @@ static gboolean create_pipeline(SpiceGstDecoder *decoder)
     } else {
         /* handle has received, it means playbin will render directly into
          * widget using the gstvideooverlay interface instead of app-sink.
-         * Also avoid using vaapisink if exist since vaapisink could be
+         */
+        SPICE_DEBUG("Video is presented using gstreamer's GstVideoOverlay interface");
+
+#if !GST_CHECK_VERSION(1,14,0)
+        /* Avoid using vaapisink if exist since vaapisink could be
          * buggy when it is combined with playbin. changing its rank to
          * none will make playbin to avoid of using it.
          */
         GstRegistry *registry = NULL;
         GstPluginFeature *vaapisink = NULL;
 
-        SPICE_DEBUG("Video is presented using gstreamer's GstVideoOverlay interface");
         registry = gst_registry_get();
         if (registry) {
             vaapisink = gst_registry_lookup_feature(registry, "vaapisink");
@@ -422,6 +425,7 @@ static gboolean create_pipeline(SpiceGstDecoder *decoder)
             gst_plugin_feature_set_rank(vaapisink, GST_RANK_NONE);
             gst_object_unref(vaapisink);
         }
+#endif
     }
 
     g_signal_connect(playbin, "source-setup", G_CALLBACK(app_source_setup), decoder);
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 0c6f16f..8adcc38 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -28,6 +28,9 @@
 #ifdef GDK_WINDOWING_X11
 #include <X11/Xlib.h>
 #include <gdk/gdkx.h>
+#ifdef HAVE_LIBVA
+#include <va/va_x11.h>
+#endif
 #endif
 #ifdef G_OS_WIN32
 #include <windows.h>
@@ -2566,6 +2569,40 @@ static void queue_draw_area(SpiceDisplay *display, gint x, gint y,
 }
 
 #if defined(GDK_WINDOWING_X11)
+
+#if defined(HAVE_LIBVA)
+static GstContext *create_vaapi_context(void)
+{
+    static Display *x11_display = NULL;
+    static VADisplay va_display = NULL;
+
+    // note that if VAAPI do not get the context for the
+    // overlay it crashes the entire program!
+    GdkDisplay *display = gdk_display_get_default();
+    g_assert_nonnull(display);
+
+    // Compute display pointers
+    if (!x11_display && GDK_IS_X11_DISPLAY(display)) {
+        x11_display = gdk_x11_display_get_xdisplay(display);
+        // for thread problems we need a different Display,
+        // VAAPI access the Display from another thread
+        x11_display = XOpenDisplay(XDisplayString(x11_display));
+        g_assert_nonnull(x11_display);
+        va_display = vaGetDisplay(x11_display);
+        g_assert_nonnull(va_display);
+    }
+
+    GstContext *context = gst_context_new("gst.vaapi.app.Display", FALSE);
+    GstStructure *structure = gst_context_writable_structure(context);
+    if (x11_display) {
+        gst_structure_set(structure, "x11-display", G_TYPE_POINTER, x11_display, NULL);
+    }
+    gst_structure_set(structure, "va-display", G_TYPE_POINTER, va_display, NULL);
+
+    return context;
+}
+#endif
+
 static void gst_sync_bus_call(GstBus *bus, GstMessage *msg, SpiceDisplay *display)
 {
     switch(GST_MESSAGE_TYPE(msg)) {
@@ -2587,6 +2624,26 @@ static void gst_sync_bus_call(GstBus *bus, GstMessage *msg, SpiceDisplay *displa
         }
         break;
     }
+    case GST_MESSAGE_NEED_CONTEXT:
+    {
+        const gchar *context_type;
+
+        gst_message_parse_context_type(msg, &context_type);
+        SPICE_DEBUG("GStreamer: got need context %s from %s", context_type,
+                    GST_MESSAGE_SRC_NAME(msg));
+
+#if defined(HAVE_LIBVA)
+        if (g_strcmp0(context_type, "gst.vaapi.app.Display") == 0) {
+            GstContext *context = create_vaapi_context();
+
+            if (context) {
+                gst_element_set_context(GST_ELEMENT(msg->src), context);
+                gst_context_unref(context);
+            }
+        }
+#endif
+        break;
+    }
     default:
         /* not being handled */
         break;


More information about the Spice-commits mailing list