[spice-gtk,v2,3/3] gstaudio: rely on SpiceSession init of GStreamer

Submitted by Victor Toso on Sept. 9, 2019, 10:29 a.m.

Details

Message ID 20190909102949.17504-4-victortoso@redhat.com
State New
Headers show
Series "Initialize GStreamer on SpiceSession" ( rev: 2 ) in Spice

Not browsing as part of any series.

Commit Message

Victor Toso Sept. 9, 2019, 10:29 a.m.
From: Victor Toso <me@victortoso.com>

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

A small code refactor was done in spice_gstaudio_new() to make an
early return on error. The previous warning around GStreamer not being
initialized was demoted to a debug message as the warning should be
issued in SpiceSession initialization.

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

Patch hide | download patch | download mbox

diff --git a/src/spice-gstaudio.c b/src/spice-gstaudio.c
index 4dd3d81..517d612 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()) {
+        spice_debug("GStreamer is 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,