devicemonitor: Stop only the already started providers
authorPhilippe Normand <philn@igalia.com>
Wed, 21 Oct 2020 08:43:43 +0000 (09:43 +0100)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 22 Oct 2020 11:48:05 +0000 (11:48 +0000)
If a device provider fails to start (for instance the pulseaudio provider unable
to connect to the PulseAudio daemon) then the monitor should not keep track of
it in its `started` providers list. Otherwise a false positive critical warning
would be raised.

This patch also switches the started_count type from bool to int, for
consistency. This is a counter, after all.

API: gst_device_provider_is_started
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/679>

gst/gstdevicemonitor.c
gst/gstdeviceprovider.c
gst/gstdeviceprovider.h
tests/check/gst/gstdevice.c

index 43752e1..fae2f61 100644 (file)
@@ -571,7 +571,8 @@ gst_device_monitor_stop (GstDeviceMonitor * monitor)
     GstDeviceProvider *provider =
         g_ptr_array_index (monitor->priv->providers, i);
 
-    started = g_list_prepend (started, gst_object_ref (provider));
+    if (gst_device_provider_is_started (provider))
+      started = g_list_prepend (started, gst_object_ref (provider));
   }
   GST_OBJECT_UNLOCK (monitor);
 
index 4d159fe..547b7a1 100644 (file)
@@ -55,7 +55,7 @@ struct _GstDeviceProviderPrivate
 
   GMutex start_lock;
 
-  gboolean started_count;
+  gint started_count;
 
   GList *hidden_providers;
 };
@@ -165,6 +165,8 @@ gst_device_provider_init (GstDeviceProvider * provider)
 
   g_mutex_init (&provider->priv->start_lock);
 
+  provider->priv->started_count = 0;
+
   provider->priv->bus = gst_bus_new ();
   gst_bus_set_flushing (provider->priv->bus, TRUE);
 }
@@ -854,3 +856,24 @@ gst_device_provider_device_changed (GstDeviceProvider * provider,
   gst_bus_post (provider->priv->bus, message);
   gst_object_unparent (GST_OBJECT (changed_device));
 }
+
+/**
+ * gst_device_provider_is_started:
+ * @provider: a #GstDeviceProvider
+ *
+ * This function can be used to know if the @provider was successfully started.
+ *
+ * Since: 1.20
+ */
+gboolean
+gst_device_provider_is_started (GstDeviceProvider * provider)
+{
+  gboolean started = FALSE;
+
+  g_return_val_if_fail (GST_IS_DEVICE_PROVIDER (provider), FALSE);
+
+  g_mutex_lock (&provider->priv->start_lock);
+  started = provider->priv->started_count > 0;
+  g_mutex_unlock (&provider->priv->start_lock);
+  return started;
+}
index 56ad620..cafe37e 100644 (file)
@@ -139,6 +139,9 @@ GST_API
 const gchar * gst_device_provider_get_metadata       (GstDeviceProvider * provider,
                                                       const gchar * key);
 
+GST_API
+gboolean    gst_device_provider_is_started     (GstDeviceProvider * provider);
+
 /* device provider class meta data */
 
 GST_API
index 70e186a..8d47236 100644 (file)
@@ -244,12 +244,14 @@ GST_START_TEST (test_device_provider)
   g_list_free_full (devs, (GDestroyNotify) gst_object_unref);
 
   fail_if (gst_device_provider_can_monitor (dp));
+  fail_if (gst_device_provider_is_started (dp));
   fail_unless (gst_device_provider_start (dp));
 
   bus = gst_device_provider_get_bus (dp);
   fail_unless (GST_IS_BUS (bus));
   gst_object_unref (bus);
 
+  fail_unless (gst_device_provider_is_started (dp));
   gst_device_provider_stop (dp);
 
   gst_object_unref (dp);