* Boston, MA 02111-1307, USA.
*/
+/**
+ * SECTION:gstdevice
+ * @title: GstDevice
+ * @short_description: Object representing a device
+ * @see_also: #GstDeviceProvider
+ *
+ * #GstDevice are objects representing a device, they contain
+ * relevant metadata about the device, such as its class and the #GstCaps
+ * representing the media types it can produce or handle.
+ *
+ * #GstDevice are created by #GstDeviceProvider objects which can be
+ * aggregated by #GstDeviceMonitor objects.
+ *
+ * Since: 1.4
+ */
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include "gst/gst_private.h"
+#include "gst_private.h"
-#include <gst/gstdevice.h>
-#include <gst/gst.h>
+#include "gstdevice.h"
enum
{
PROP_DISPLAY_NAME = 1,
- PROP_CAPS
+ PROP_CAPS,
+ PROP_DEVICE_CLASS,
+ PROP_PROPERTIES
};
enum
struct _GstDevicePrivate
{
GstCaps *caps;
+ gchar *device_class;
gchar *display_name;
+ GstStructure *properties;
};
g_param_spec_boxed ("caps", "Device Caps",
"The possible caps of a device", GST_TYPE_CAPS,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class, PROP_DEVICE_CLASS,
+ 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);
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);
G_OBJECT_CLASS (gst_device_parent_class)->finalize (object);
}
if (gstdevice->priv->caps)
g_value_take_boxed (value, gst_device_get_caps (gstdevice));
break;
+ 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;
case PROP_CAPS:
gst_caps_replace (&gstdevice->priv->caps, g_value_get_boxed (value));
break;
+ 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;
/**
* gst_device_create_element:
* @device: a #GstDevice
- * @name: (allow-none): name of new element, or NULL to automatically
+ * @name: (allow-none): name of new element, or %NULL to automatically
* create a unique name.
*
+ * 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
*
* Since: 1.4
{
GstDeviceClass *klass = GST_DEVICE_GET_CLASS (device);
+ g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
+
if (klass->create_element)
return klass->create_element (device, name);
else
GstCaps *
gst_device_get_caps (GstDevice * device)
{
+ g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
+
if (device->priv->caps)
return gst_caps_ref (device->priv->caps);
else
gchar *
gst_device_get_display_name (GstDevice * device)
{
- return g_strdup (device->priv->display_name);
+ g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
+
+ return
+ g_strdup (device->priv->display_name ? device->priv->display_name : "");
+}
+
+/**
+ * gst_device_get_device_class:
+ * @device: a #GstDevice
+ *
+ * Gets the "class" of a device. This is a "/" separated list of
+ * classes that represent this device. They are a subset of the
+ * classes of the #GstDeviceProvider that produced this device.
+ *
+ * Returns: The device class. Free with g_free() after use.
+ *
+ * Since: 1.4
+ */
+gchar *
+gst_device_get_device_class (GstDevice * device)
+{
+ g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
+
+ if (device->priv->device_class != NULL)
+ return g_strdup (device->priv->device_class);
+ else
+ return g_strdup ("");
+}
+
+/**
+ * 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;
}
/**
{
GstDeviceClass *klass = GST_DEVICE_GET_CLASS (device);
+ g_return_val_if_fail (GST_IS_DEVICE (device), FALSE);
+
if (klass->reconfigure_element)
return klass->reconfigure_element (device, element);
else
return FALSE;
}
+
+/**
+ * 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
+ *
+ * Check if @factory matches all of the given classes
+ *
+ * Returns: %TRUE if @device matches.
+ *
+ * Since: 1.4
+ */
+gboolean
+gst_device_has_classesv (GstDevice * device, gchar ** classes)
+{
+ g_return_val_if_fail (GST_IS_DEVICE (device), FALSE);
+
+ if (!classes)
+ return TRUE;
+
+ for (; classes[0]; classes++) {
+ const gchar *klass = classes[0];
+ const gchar *found;
+ guint len;
+
+ if (*klass == '\0')
+ continue;
+
+ found = strstr (device->priv->device_class, klass);
+
+ if (!found)
+ return FALSE;
+ if (found != device->priv->device_class && *(found - 1) != '/')
+ return FALSE;
+
+ len = strlen (klass);
+ if (found[len] != 0 && found[len] != '/')
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ * gst_device_has_classes:
+ * @device: a #GstDevice
+ * @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
+ *
+ * Returns: %TRUE if @device matches.
+ *
+ * Since: 1.4
+ */
+gboolean
+gst_device_has_classes (GstDevice * device, const gchar * classes)
+{
+ gchar **classesv;
+ gboolean res;
+
+ g_return_val_if_fail (GST_IS_DEVICE (device), FALSE);
+
+ if (!classes)
+ return TRUE;
+
+ classesv = g_strsplit (classes, "/", 0);
+
+ res = gst_device_has_classesv (device, classesv);
+
+ g_strfreev (classesv);
+
+ return res;
+}