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

Submitted by Victor Toso on Sept. 2, 2019, 4:04 p.m.

Details

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

Not browsing as part of any series.

Commit Message

Victor Toso Sept. 2, 2019, 4:04 p.m.
From: Victor Toso <me@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@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 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,