[Spice-devel] [spice-gtk v1 3/6] gstaudio: rely on SpiceSession init of GStreamer

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


From: Victor Toso <me at victortoso.com>

This means we can drop gstvideo_init() function and replace its calls
with gst_is_initialized().

A small code refactor was done in spice_gstaudio_new() to make a early
return on error.

Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/spice-gstaudio.c | 59 ++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/src/spice-gstaudio.c b/src/spice-gstaudio.c
index 5f4a2fe..9be647b 100644
--- a/src/spice-gstaudio.c
+++ b/src/spice-gstaudio.c
@@ -552,45 +552,40 @@ static gboolean connect_channel(SpiceAudio *audio, SpiceChannel *channel)
 SpiceGstaudio *spice_gstaudio_new(SpiceSession *session, GMainContext *context,
                                   const char *name)
 {
-    GError *err = NULL;
-
-    if (gst_init_check(NULL, NULL, &err)) {
-        GstPluginFeature *pulsesrc;
-
-        pulsesrc = gst_registry_lookup_feature(gst_registry_get(), "pulsesrc");
-        if (pulsesrc) {
-            unsigned major, minor, micro;
-            GstPlugin *plugin = gst_plugin_feature_get_plugin(pulsesrc);
-
-            if (sscanf(gst_plugin_get_version(plugin), "%u.%u.%u",
-                       &major, &minor, &micro) != 3) {
-                g_warn_if_reached();
-                gst_object_unref(plugin);
-                gst_object_unref(pulsesrc);
-                return NULL;
-            }
-
-            if (major < 1 ||
-                (major == 1 && minor < 14) ||
-                (major == 1 && minor == 14 && micro < 5)) {
-                g_warning("Bad pulsesrc version %s, lowering its rank",
-                          gst_plugin_get_version(plugin));
-                gst_plugin_feature_set_rank(pulsesrc, GST_RANK_NONE);
-            }
+    if (!gst_is_initialized()) {
+        g_warning("GStreamer not initialized: disabling GStreamer audio support");
+        return NULL;
+    }
+
+    GstPluginFeature *pulsesrc = gst_registry_lookup_feature(gst_registry_get(), "pulsesrc");
+    if (pulsesrc) {
+        unsigned major, minor, micro;
+        GstPlugin *plugin = gst_plugin_feature_get_plugin(pulsesrc);
 
+        if (sscanf(gst_plugin_get_version(plugin), "%u.%u.%u",
+                   &major, &minor, &micro) != 3) {
+            g_warn_if_reached();
             gst_object_unref(plugin);
             gst_object_unref(pulsesrc);
+            return NULL;
+        }
+
+        if (major < 1 ||
+            (major == 1 && minor < 14) ||
+            (major == 1 && minor == 14 && micro < 5)) {
+            g_warning("Bad pulsesrc version %s, lowering its rank",
+                      gst_plugin_get_version(plugin));
+            gst_plugin_feature_set_rank(pulsesrc, GST_RANK_NONE);
         }
 
-        return g_object_new(SPICE_TYPE_GSTAUDIO,
-                            "session", session,
-                            "main-context", context,
-                            NULL);
+        gst_object_unref(plugin);
+        gst_object_unref(pulsesrc);
     }
 
-    g_warning("Disabling GStreamer audio support: %s", err->message);
-    g_clear_error(&err);
-    return NULL;
+    return g_object_new(SPICE_TYPE_GSTAUDIO,
+                        "session", session,
+                        "main-context", context,
+                        NULL);
 }
 
 static void spice_gstaudio_get_playback_volume_info_async(SpiceAudio *audio,
-- 
2.21.0



More information about the Spice-devel mailing list