device: add generic struct with properties
authorWim Taymans <wtaymans@redhat.com>
Wed, 15 Jul 2015 16:21:13 +0000 (18:21 +0200)
committerWim Taymans <wtaymans@redhat.com>
Wed, 15 Jul 2015 16:21:13 +0000 (18:21 +0200)
Add a generic structure to hold any additional properties about the
device.

gst/gstdevice.c
gst/gstdevice.h
win32/common/libgstreamer.def

index 6274c93..ee92619 100644 (file)
@@ -46,7 +46,8 @@ enum
 {
   PROP_DISPLAY_NAME = 1,
   PROP_CAPS,
-  PROP_DEVICE_CLASS
+  PROP_DEVICE_CLASS,
+  PROP_PROPERTIES
 };
 
 enum
@@ -60,6 +61,7 @@ struct _GstDevicePrivate
   GstCaps *caps;
   gchar *device_class;
   gchar *display_name;
+  GstStructure *properties;
 };
 
 
@@ -97,6 +99,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);
@@ -116,6 +122,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 +149,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 +178,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;
@@ -263,6 +280,28 @@ gst_device_get_device_class (GstDevice * device)
 }
 
 /**
+ * gst_device_get_properties:
+ * @device: a #GstDevice
+ *
+ * Gets the extra properties of a device.
+ *
+ * Returns: 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
index b055aa0..79eb908 100644 (file)
@@ -77,28 +77,29 @@ struct _GstDevice {
 struct _GstDeviceClass {
   GstObjectClass    parent_class;
 
-  GstElement * (*create_element) (GstDevice * device, const gchar * name);
-  gboolean (*reconfigure_element) (GstDevice * device, GstElement * element);
+  GstElement * (*create_element)      (GstDevice * device, const gchar * name);
+  gboolean     (*reconfigure_element) (GstDevice * device, GstElement * element);
 
   /*< private >*/
   gpointer _gst_reserved[GST_PADDING];
 };
 
-GType        gst_device_get_type (void);
+GType          gst_device_get_type (void);
 
-GstElement * gst_device_create_element (GstDevice * device, const gchar * name);
+GstElement *   gst_device_create_element      (GstDevice * device, const gchar * name);
 
-GstCaps *    gst_device_get_caps (GstDevice * device);
-gchar *      gst_device_get_display_name (GstDevice * device);
-gchar *      gst_device_get_device_class (GstDevice * device);
-gboolean     gst_device_reconfigure_element (GstDevice * device,
-                                             GstElement * element);
+GstCaps *      gst_device_get_caps            (GstDevice * device);
+gchar *        gst_device_get_display_name    (GstDevice * device);
+gchar *        gst_device_get_device_class    (GstDevice * device);
+GstStructure * gst_device_get_properties      (GstDevice * device);
+gboolean       gst_device_reconfigure_element (GstDevice * device,
+                                               GstElement * element);
 
-gboolean      gst_device_has_classesv (GstDevice * device,
-                                       gchar ** classes);
+gboolean        gst_device_has_classesv       (GstDevice * device,
+                                               gchar ** classes);
 
-gboolean      gst_device_has_classes (GstDevice * device,
-                                      const gchar * classes);
+gboolean        gst_device_has_classes        (GstDevice * device,
+                                               const gchar * classes);
 
 
 G_END_DECLS
index 7f02bae..f5edbda 100644 (file)
@@ -428,6 +428,7 @@ EXPORTS
        gst_device_get_caps
        gst_device_get_device_class
        gst_device_get_display_name
+       gst_device_get_properties
        gst_device_get_type
        gst_device_has_classes
        gst_device_has_classesv