meson: add option to disable parse-launch pipeline string parser
[platform/upstream/gstreamer.git] / gst / gstdevicemonitor.c
index 7092fcc..bbe492c 100644 (file)
@@ -21,6 +21,7 @@
 
 /**
  * SECTION:gstdevicemonitor
+ * @title: GstDeviceMonitor
  * @short_description: A device monitor and prober
  * @see_also: #GstDevice, #GstDeviceProvider
  *
@@ -34,7 +35,6 @@
  * The device monitor will monitor all devices matching the filters that
  * the application has set.
  *
- *
  * The basic use pattern of a device monitor is as follows:
  * |[
  *   static gboolean
  *          name = gst_device_get_display_name (device);
  *          g_print("Device added: %s\n", name);
  *          g_free (name);
+ *          gst_object_unref (device);
  *          break;
  *        case GST_MESSAGE_DEVICE_REMOVED:
  *          gst_message_parse_device_removed (message, &device);
  *          name = gst_device_get_display_name (device);
  *          g_print("Device removed: %s\n", name);
  *          g_free (name);
+ *          gst_object_unref (device);
  *          break;
  *        default:
  *          break;
@@ -119,7 +121,8 @@ enum
   PROP_SHOW_ALL = 1,
 };
 
-G_DEFINE_TYPE (GstDeviceMonitor, gst_device_monitor, GST_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_PRIVATE (GstDeviceMonitor, gst_device_monitor,
+    GST_TYPE_OBJECT);
 
 static void gst_device_monitor_dispose (GObject * object);
 
@@ -180,8 +183,6 @@ gst_device_monitor_class_init (GstDeviceMonitorClass * klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  g_type_class_add_private (klass, sizeof (GstDeviceMonitorPrivate));
-
   object_class->get_property = gst_device_monitor_get_property;
   object_class->set_property = gst_device_monitor_set_property;
   object_class->dispose = gst_device_monitor_dispose;
@@ -234,7 +235,7 @@ bus_sync_message (GstBus * bus, GstMessage * message,
   GstMessageType type = GST_MESSAGE_TYPE (message);
 
   if (type == GST_MESSAGE_DEVICE_ADDED || type == GST_MESSAGE_DEVICE_REMOVED) {
-    gboolean matches;
+    gboolean matches = TRUE;
     GstDevice *device;
     GstDeviceProvider *provider;
 
@@ -248,7 +249,7 @@ bus_sync_message (GstBus * bus, GstMessage * message,
         GST_DEVICE_PROVIDER (gst_object_get_parent (GST_OBJECT (device)));
     if (is_provider_hidden (monitor, monitor->priv->hidden, provider)) {
       matches = FALSE;
-    } else if (monitor->priv->filters->len) {
+    } else {
       guint i;
 
       for (i = 0; i < monitor->priv->filters->len; i++) {
@@ -263,11 +264,10 @@ bus_sync_message (GstBus * bus, GstMessage * message,
         if (matches)
           break;
       }
-    } else {
-      matches = TRUE;
     }
     GST_OBJECT_UNLOCK (monitor);
 
+    gst_object_unref (provider);
     gst_object_unref (device);
 
     if (matches)
@@ -279,8 +279,7 @@ bus_sync_message (GstBus * bus, GstMessage * message,
 static void
 gst_device_monitor_init (GstDeviceMonitor * self)
 {
-  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
-      GST_TYPE_DEVICE_MONITOR, GstDeviceMonitorPrivate);
+  self->priv = gst_device_monitor_get_instance_private (self);
 
   self->priv->show_all = DEFAULT_SHOW_ALL;
 
@@ -341,7 +340,7 @@ gst_device_monitor_dispose (GObject * object)
  * Gets a list of devices from all of the relevant monitors. This may actually
  * probe the hardware if the monitor is not currently started.
  *
- * Returns: (transfer full) (element-type GstDevice): a #GList of
+ * Returns: (transfer full) (element-type GstDevice) (nullable): a #GList of
  *   #GstDevice
  *
  * Since: 1.4
@@ -361,13 +360,13 @@ gst_device_monitor_get_devices (GstDeviceMonitor * monitor)
   if (monitor->priv->filters->len == 0) {
     GST_OBJECT_UNLOCK (monitor);
     GST_WARNING_OBJECT (monitor, "No filters have been set");
-    return FALSE;
+    return NULL;
   }
 
   if (monitor->priv->providers->len == 0) {
     GST_OBJECT_UNLOCK (monitor);
     GST_WARNING_OBJECT (monitor, "No providers match the current filters");
-    return FALSE;
+    return NULL;
   }
 
 again:
@@ -613,7 +612,14 @@ provider_unhidden (GstDeviceProvider * provider, const gchar * hidden,
  * @caps: (allow-none): the #GstCaps to filter or %NULL for ANY
  *
  * Adds a filter for which #GstDevice will be monitored, any device that matches
- * all classes and the #GstCaps will be returned.
+ * all these classes and the #GstCaps will be returned.
+ *
+ * If this function is called multiple times to add more filters, each will be
+ * matched independently. That is, adding more filters will not further restrict
+ * what devices are matched.
+ *
+ * The #GstCaps supported by the device as returned by gst_device_get_caps() are
+ * not intersected with caps filters added using this function.
  *
  * Filters must be added before the #GstDeviceMonitor is started.
  *
@@ -694,12 +700,9 @@ gst_device_monitor_add_filter (GstDeviceMonitor * monitor,
   /* Ensure there is no leak here */
   g_assert (factories == NULL);
 
-  if (matched) {
+  if (matched)
     id = filter->id;
-    g_ptr_array_add (monitor->priv->filters, filter);
-  } else {
-    device_filter_free (filter);
-  }
+  g_ptr_array_add (monitor->priv->filters, filter);
 
   GST_OBJECT_UNLOCK (monitor);
 
@@ -785,7 +788,14 @@ gst_device_monitor_remove_filter (GstDeviceMonitor * monitor, guint filter_id)
 GstDeviceMonitor *
 gst_device_monitor_new (void)
 {
-  return g_object_new (GST_TYPE_DEVICE_MONITOR, NULL);
+  GstDeviceMonitor *monitor;
+
+  monitor = g_object_new (GST_TYPE_DEVICE_MONITOR, NULL);
+
+  /* Clear floating flag */
+  gst_object_ref_sink (monitor);
+
+  return monitor;
 }
 
 /**