[Spice-devel] [spice-gtk v1 1/6] session: initialize gstreamer once

Victor Toso victortoso at redhat.com
Mon Sep 2 16:04:44 UTC 2019


From: Victor Toso <me at victortoso.com>

GStreamer is required since v0.36 with 83ab7ca "build-sys: drop
gstvideo option, make it required" in 2019-01-15 by Marc-André Lureau
<marcandre.lureau at redhat.com>

Both channel-display-gst.c and spice-gstaudio.c have to double check
that GStreamer was initialized with gst_init_check() but this can be
done once per SpiceSession and make those code path a little bit
lighter with simpler check gst_is_initialized()

This first patch does initialize a SpiceSession on it's init. As the
current code path does not call gst_deinit(), we are not doing it so
here as well but it can be later optimized to be sure resources are
cleaned correctly on GStreamer side.

Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/spice-session.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/spice-session.c b/src/spice-session.c
index 04ba124..db40a53 100644
--- a/src/spice-session.c
+++ b/src/spice-session.c
@@ -21,6 +21,7 @@
 #include <gio/gnetworking.h>
 #include <gio/gio.h>
 #include <glib.h>
+#include <gst/gst.h>
 #ifdef G_OS_UNIX
 #include <gio/gunixsocketaddress.h>
 #endif
@@ -234,6 +235,7 @@ G_STATIC_ASSERT(G_N_ELEMENTS(_spice_image_compress_values) == SPICE_IMAGE_COMPRE
 
 static const gchar* spice_session_get_shared_dir(SpiceSession *session);
 static void spice_session_set_shared_dir(SpiceSession *session, const gchar *dir);
+static void spice_session_enable_gstreamer(SpiceSession *session);
 
 GType
 spice_image_compress_get_type (void)
@@ -295,6 +297,7 @@ static void spice_session_init(SpiceSession *session)
     s->images = cache_image_new((GDestroyNotify)pixman_image_unref);
     s->glz_window = glz_decoder_window_new();
     update_proxy(session, NULL);
+    spice_session_enable_gstreamer(session);
 }
 
 static void
@@ -2868,3 +2871,22 @@ gboolean spice_session_set_migration_session(SpiceSession *session, SpiceSession
 
     return TRUE;
 }
+
+static void
+spice_session_enable_gstreamer(SpiceSession *session)
+{
+    g_return_if_fail(SPICE_IS_SESSION(session));
+    if (gst_is_initialized()) {
+        /* Either called by spice client or in previous SpiceSession */
+        return;
+    }
+
+    /* TODO: Provide argc and argv to GStreamer for command line filtering on
+     * spice-gtk level, otherwise only applications that run gst_init() first
+     * would filter command line options */
+    GError *err = NULL;
+    if (!gst_init_check(NULL, NULL, &err)) {
+        spice_warning("Disabling GStreamer video support: %s", err->message);
+        g_clear_error(&err);
+    }
+}
-- 
2.21.0



More information about the Spice-devel mailing list