device: gst_device_create_element() is `transfer floating`, not `transfer full`
[platform/upstream/gstreamer.git] / gst / gstdevice.c
index 1237dca..6040782 100644 (file)
@@ -21,6 +21,7 @@
 
 /**
  * SECTION:gstdevice
+ * @title: GstDevice
  * @short_description: Object representing a device
  * @see_also: #GstDeviceProvider
  *
@@ -29,7 +30,7 @@
  * representing the media types it can produce or handle.
  *
  * #GstDevice are created by #GstDeviceProvider objects which can be
- * aggregated by #GstGlobalDeviceMonitor objects.
+ * aggregated by #GstDeviceMonitor objects.
  *
  * Since: 1.4
  */
@@ -46,7 +47,8 @@ enum
 {
   PROP_DISPLAY_NAME = 1,
   PROP_CAPS,
-  PROP_DEVICE_CLASS
+  PROP_DEVICE_CLASS,
+  PROP_PROPERTIES
 };
 
 enum
@@ -60,12 +62,13 @@ struct _GstDevicePrivate
   GstCaps *caps;
   gchar *device_class;
   gchar *display_name;
+  GstStructure *properties;
 };
 
 
 static guint signals[LAST_SIGNAL];
 
-G_DEFINE_ABSTRACT_TYPE (GstDevice, gst_device, GST_TYPE_OBJECT);
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GstDevice, gst_device, GST_TYPE_OBJECT);
 
 static void gst_device_get_property (GObject * object, guint property_id,
     GValue * value, GParamSpec * pspec);
@@ -79,8 +82,6 @@ gst_device_class_init (GstDeviceClass * klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  g_type_class_add_private (klass, sizeof (GstDevicePrivate));
-
   object_class->get_property = gst_device_get_property;
   object_class->set_property = gst_device_set_property;
   object_class->finalize = gst_device_finalize;
@@ -97,6 +98,10 @@ gst_device_class_init (GstDeviceClass * klass)
       g_param_spec_string ("device-class", "Device Class",
           "The Class of the device", "",
           G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (object_class, PROP_PROPERTIES,
+      g_param_spec_boxed ("properties", "Properties",
+          "The extra properties of the device", GST_TYPE_STRUCTURE,
+          G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
   signals[REMOVED] = g_signal_new ("removed", G_TYPE_FROM_CLASS (klass),
       G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
@@ -105,8 +110,7 @@ gst_device_class_init (GstDeviceClass * klass)
 static void
 gst_device_init (GstDevice * device)
 {
-  device->priv = G_TYPE_INSTANCE_GET_PRIVATE (device, GST_TYPE_DEVICE,
-      GstDevicePrivate);
+  device->priv = gst_device_get_instance_private (device);
 }
 
 static void
@@ -116,6 +120,8 @@ gst_device_finalize (GObject * object)
 
   gst_caps_replace (&device->priv->caps, NULL);
 
+  if (device->priv->properties)
+    gst_structure_free (device->priv->properties);
   g_free (device->priv->display_name);
   g_free (device->priv->device_class);
 
@@ -141,6 +147,10 @@ gst_device_get_property (GObject * object, guint prop_id,
     case PROP_DEVICE_CLASS:
       g_value_take_string (value, gst_device_get_device_class (gstdevice));
       break;
+    case PROP_PROPERTIES:
+      if (gstdevice->priv->properties)
+        g_value_take_boxed (value, gst_device_get_properties (gstdevice));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -166,6 +176,11 @@ gst_device_set_property (GObject * object, guint prop_id,
     case PROP_DEVICE_CLASS:
       gstdevice->priv->device_class = g_value_dup_string (value);
       break;
+    case PROP_PROPERTIES:
+      if (gstdevice->priv->properties)
+        gst_structure_free (gstdevice->priv->properties);
+      gstdevice->priv->properties = g_value_dup_boxed (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -178,10 +193,11 @@ gst_device_set_property (GObject * object, guint prop_id,
  * @name: (allow-none): name of new element, or %NULL to automatically
  * create a unique name.
  *
- * Creates the element with all of the required paramaters set to use
+ * Creates the element with all of the required parameters set to use
  * this device.
  *
- * Returns: (transfer full): a new #GstElement configured to use this device
+ * Returns: (transfer floating) (nullable): a new #GstElement configured to use
+ * this device
  *
  * Since: 1.4
  */
@@ -204,7 +220,7 @@ gst_device_create_element (GstDevice * device, const gchar * name)
  *
  * Getter for the #GstCaps that this device supports.
  *
- * Returns: The #GstCaps supported by this device. Unref with
+ * Returns: (nullable): The #GstCaps supported by this device. Unref with
  * gst_caps_unref() when done.
  *
  * Since: 1.4
@@ -263,6 +279,28 @@ gst_device_get_device_class (GstDevice * device)
 }
 
 /**
+ * gst_device_get_properties:
+ * @device: a #GstDevice
+ *
+ * Gets the extra properties of a device.
+ *
+ * Returns: (nullable): The extra properties or %NULL when there are none.
+ *          Free with gst_structure_free() after use.
+ *
+ * Since: 1.6
+ */
+GstStructure *
+gst_device_get_properties (GstDevice * device)
+{
+  g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
+
+  if (device->priv->properties != NULL)
+    return gst_structure_copy (device->priv->properties);
+  else
+    return NULL;
+}
+
+/**
  * gst_device_reconfigure_element:
  * @device: a #GstDevice
  * @element: a #GstElement
@@ -295,8 +333,8 @@ gst_device_reconfigure_element (GstDevice * device, GstElement * element)
 /**
  * gst_device_has_classesv:
  * @device: a #GstDevice
- * @classes: (array zero-terminated=1): a %NULL terminated array of classes to match, only match if all
- *   classes are matched
+ * @classes: (array zero-terminated=1): a %NULL terminated array of classes
+ *   to match, only match if all classes are matched
  *
  * Check if @factory matches all of the given classes
  *
@@ -313,20 +351,21 @@ gst_device_has_classesv (GstDevice * device, gchar ** classes)
     return TRUE;
 
   for (; classes[0]; classes++) {
+    const gchar *klass = classes[0];
     const gchar *found;
     guint len;
 
-    if (classes[0] == '\0')
+    if (*klass == '\0')
       continue;
 
-    found = strstr (device->priv->device_class, classes[0]);
+    found = strstr (device->priv->device_class, klass);
 
     if (!found)
       return FALSE;
     if (found != device->priv->device_class && *(found - 1) != '/')
       return FALSE;
 
-    len = strlen (classes[0]);
+    len = strlen (klass);
     if (found[len] != 0 && found[len] != '/')
       return FALSE;
   }
@@ -337,7 +376,7 @@ gst_device_has_classesv (GstDevice * device, gchar ** classes)
 /**
  * gst_device_has_classes:
  * @device: a #GstDevice
- * @classes: a "/" separate list of device classes to match, only match if
+ * @classes: a "/"-separated list of device classes to match, only match if
  *  all classes are matched
  *
  * Check if @device matches all of the given classes