Commit b8078e26 authored by Olivier Crête's avatar Olivier Crête

devicemonitor: Make classes into pure strings

Instead of having strings & flags, make them just strings
parent 4d7d3a1c
......@@ -456,64 +456,91 @@ gst_device_monitor_factory_get_metadata_keys (GstDeviceMonitorFactory * factory)
return arr;
}
typedef struct
{
GstDeviceMonitorFactoryListType type;
GstRank minrank;
} FilterData;
/**
* gst_device_monitor_factory_list_is_type:
* gst_device_monitor_factory_has_classesv:
* @factory: a #GstDeviceMonitorFactory
* @type: a #GstDeviceMonitorFactoryListType
* @classes: a %NULL terminated array of klasses to match, only match if all
* classes are matched
*
* Check if @factory is of the given types.
* Check if @factory matches all of the given classes
*
* Returns: %TRUE if @factory is of @type.
* Returns: %TRUE if @factory matches.
*
* Since: 1.4
*/
gboolean
gst_device_monitor_factory_list_is_type (GstDeviceMonitorFactory * factory,
GstDeviceMonitorFactoryListType type)
gst_device_monitor_factory_has_classesv (GstDeviceMonitorFactory * factory,
gchar ** classes)
{
gboolean res = FALSE;
const gchar *klass;
g_return_val_if_fail (GST_IS_DEVICE_MONITOR_FACTORY (factory), FALSE);
klass = gst_device_monitor_factory_get_metadata (factory,
GST_ELEMENT_METADATA_KLASS);
if (klass == NULL) {
GST_ERROR_OBJECT (factory,
"device monitor factory is missing klass identifiers");
return res;
return FALSE;
}
for (; classes[0]; classes++) {
const gchar *found;
guint len;
if (classes[0] == '\0')
continue;
found = strstr (klass, classes[0]);
if (!found)
return FALSE;
if (found != klass && *(found - 1) != '/')
return FALSE;
len = strlen (classes[0]);
if (found[len] != 0 && found[len] != '/')
return FALSE;
}
/* Filter by device monitor type first, as soon as it matches
* one type, we skip all other tests */
if (!res && (type & GST_DEVICE_MONITOR_FACTORY_TYPE_SINK))
res = (strstr (klass, "Sink") != NULL);
if (!res && (type & GST_DEVICE_MONITOR_FACTORY_TYPE_SRC))
res = (strstr (klass, "Source") != NULL);
/* Filter by media type now, we only test if it
* matched any of the types above. */
if (res
&& (type & (GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_AUDIO |
GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_VIDEO |
GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_IMAGE)))
res = ((type & GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_AUDIO)
&& (strstr (klass, "Audio") != NULL))
|| ((type & GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_VIDEO)
&& (strstr (klass, "Video") != NULL))
|| ((type & GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_IMAGE)
&& (strstr (klass, "Image") != NULL));
return TRUE;
}
/**
* gst_device_monitor_factory_has_classes:
* @factory: a #GstDeviceMonitorFactory
* @classes: a "/" separate list of klasses to match, only match if all classes
* are matched
*
* Check if @factory matches all of the given @classes
*
* Returns: %TRUE if @factory matches.
*
* Since: 1.4
*/
gboolean
gst_device_monitor_factory_has_classes (GstDeviceMonitorFactory * factory,
const gchar * classes)
{
gchar **classesv;
gboolean res;
classesv = g_strsplit (classes, "/", 0);
res = gst_device_monitor_factory_has_classesv (factory, classesv);
g_strfreev (classesv);
return res;
}
typedef struct
{
const char *classes;
GstRank minrank;
} FilterData;
static gboolean
device_monitor_filter (GstPluginFeature * feature, FilterData * data)
{
......@@ -524,20 +551,21 @@ device_monitor_filter (GstPluginFeature * feature, FilterData * data)
return FALSE;
res = (gst_plugin_feature_get_rank (feature) >= data->minrank) &&
gst_device_monitor_factory_list_is_type (GST_DEVICE_MONITOR_FACTORY_CAST
(feature), data->type);
gst_device_monitor_factory_has_classes (GST_DEVICE_MONITOR_FACTORY_CAST
(feature), data->classes);
return res;
}
/**
* gst_device_monitor_factory_list_get_device_monitors:
* @type: a #GstDeviceMonitorFactoryListType
* @classes: a "/" separate list of klasses to match, only match if all classes
* are matched
* @minrank: Minimum rank
*
* Get a list of factories that match the given @type. Only device monitors
* with a rank greater or equal to @minrank will be returned.
* The list of factories is returned by decreasing rank.
* Get a list of factories that match all of the given @classes. Only
* device monitors with a rank greater or equal to @minrank will be
* returned. The list of factories is returned by decreasing rank.
*
* Returns: (transfer full) (element-type Gst.DeviceMonitorFactory): a #GList of
* #GstDeviceMonitorFactory device monitors. Use gst_plugin_feature_list_free() after
......@@ -546,13 +574,13 @@ device_monitor_filter (GstPluginFeature * feature, FilterData * data)
* Since: 1.4
*/
GList *gst_device_monitor_factory_list_get_device_monitors
(GstDeviceMonitorFactoryListType type, GstRank minrank)
(const gchar * classes, GstRank minrank)
{
GList *result;
FilterData data;
/* prepare type */
data.type = type;
data.classes = classes;
data.minrank = minrank;
/* get the feature list using the filter */
......
......@@ -68,55 +68,13 @@ gboolean gst_device_monitor_register (GstPlugin
guint rank,
GType type);
/* Factory list functions */
gboolean gst_device_monitor_factory_has_classesv (GstDeviceMonitorFactory * factory,
gchar ** classes);
/**
* GstDeviceMonitorFactoryListType:
* @GST_DEVICE_MONITOR_FACTORY_TYPE_SINK: Sink elements
* @GST_DEVICE_MONITOR_FACTORY_TYPE_SRC: Source elements
* @GST_DEVICE_MONITOR_FACTORY_TYPE_MAX_DEVICE_MONITORS: Private, do not use
* @GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_VIDEO: Elements handling video media types
* @GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_AUDIO: Elements handling audio media types
* @GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_IMAGE: Elements handling image media types
* @GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_SUBTITLE: Elements handling subtitle media types
* @GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_METADATA: Elements handling metadata media types
*
* The type of #GstDeviceMonitorFactory to filter.
*
* All @GstDeviceMonitorFactoryListType up to @GST_DEVICE_MONITOR_FACTORY_TYPE_MAX_DEVICE_MONITORS are exclusive.
*
* If one or more of the MEDIA types are specified, then only elements
* matching the specified media types will be selected.
*
* Since: 1.4
*/
typedef guint64 GstDeviceMonitorFactoryListType;
#define GST_DEVICE_MONITOR_FACTORY_TYPE_SINK (G_GUINT64_CONSTANT (1) << 0)
#define GST_DEVICE_MONITOR_FACTORY_TYPE_SRC (G_GUINT64_CONSTANT (1) << 1)
#define GST_DEVICE_MONITOR_FACTORY_TYPE_MAX_DEVICE_MONITORS (G_GUINT64_CONSTANT (1) << 48)
#define GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_VIDEO (G_GUINT64_CONSTANT (1) << 49)
#define GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_AUDIO (G_GUINT64_CONSTANT (1) << 50)
#define GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_IMAGE (G_GUINT64_CONSTANT (1) << 51)
#define GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_SUBTITLE (G_GUINT64_CONSTANT (1) << 52)
#define GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_METADATA (G_GUINT64_CONSTANT (1) << 53)
/* Element klass defines */
#define GST_DEVICE_MONITOR_FACTORY_KLASS_DECODER "Decoder"
#define GST_DEVICE_MONITOR_FACTORY_KLASS_ENCODER "Encoder"
#define GST_DEVICE_MONITOR_FACTORY_KLASS_MEDIA_VIDEO "Video"
#define GST_DEVICE_MONITOR_FACTORY_KLASS_MEDIA_AUDIO "Audio"
#define GST_DEVICE_MONITOR_FACTORY_KLASS_MEDIA_IMAGE "Image"
#define GST_DEVICE_MONITOR_FACTORY_KLASS_MEDIA_SUBTITLE "Subtitle"
#define GST_DEVICE_MONITOR_FACTORY_KLASS_MEDIA_METADATA "Metadata"
gboolean gst_device_monitor_factory_list_is_type (GstDeviceMonitorFactory *factory,
GstDeviceMonitorFactoryListType type);
gboolean gst_device_monitor_factory_has_classes (GstDeviceMonitorFactory *factory,
const gchar * classes);
GList * gst_device_monitor_factory_list_get_device_monitors (GstDeviceMonitorFactoryListType type,
GList * gst_device_monitor_factory_list_get_device_monitors (const gchar *types,
GstRank minrank) G_GNUC_MALLOC;
G_END_DECLS
......
......@@ -38,7 +38,7 @@ struct _GstGlobalDeviceMonitorPrivate
guint cookie;
GstCaps *caps;
GstDeviceMonitorFactoryListType type;
gchar *classes;
};
......@@ -98,11 +98,11 @@ gst_global_device_monitor_init (GstGlobalDeviceMonitor * self)
self->priv->monitors = g_ptr_array_new ();
self->priv->caps = gst_caps_new_any ();
self->priv->type = GST_DEVICE_MONITOR_FACTORY_TYPE_SINK |
GST_DEVICE_MONITOR_FACTORY_TYPE_SRC;
self->priv->classes = g_strdup ("");
factories =
gst_device_monitor_factory_list_get_device_monitors (self->priv->type, 1);
gst_device_monitor_factory_list_get_device_monitors (self->priv->classes,
1);
while (factories) {
GstDeviceMonitorFactory *factory = factories->data;
......@@ -155,6 +155,7 @@ gst_global_device_monitor_dispose (GObject * object)
}
gst_caps_replace (&self->priv->caps, NULL);
g_free (self->priv->classes);
gst_object_replace ((GstObject **) & self->priv->bus, NULL);
G_OBJECT_CLASS (gst_global_device_monitor_parent_class)->dispose (object);
......@@ -293,28 +294,27 @@ gst_global_device_monitor_stop (GstGlobalDeviceMonitor * self)
}
void
gst_global_device_monitor_set_type_filter (GstGlobalDeviceMonitor * self,
GstDeviceMonitorFactoryListType type)
gst_global_device_monitor_set_classes_filter (GstGlobalDeviceMonitor * self,
const gchar * classes)
{
GList *factories = NULL;
guint i;
g_return_if_fail (GST_IS_GLOBAL_DEVICE_MONITOR (self));
g_return_if_fail (!self->priv->started);
g_return_if_fail (type &
(GST_DEVICE_MONITOR_FACTORY_TYPE_SINK |
GST_DEVICE_MONITOR_FACTORY_TYPE_SRC));
GST_OBJECT_LOCK (self);
if (self->priv->type == type) {
if (!strcmp (self->priv->classes, classes)) {
GST_OBJECT_UNLOCK (self);
return;
}
self->priv->type = type;
g_free (self->priv->classes);
self->priv->classes = g_strdup (classes);
factories =
gst_device_monitor_factory_list_get_device_monitors (self->priv->type, 1);
gst_device_monitor_factory_list_get_device_monitors (self->priv->classes,
1);
for (i = 0; i < self->priv->monitors->len; i++) {
GstDeviceMonitor *monitor = g_ptr_array_index (self->priv->monitors, i);
......@@ -363,15 +363,15 @@ gst_global_device_monitor_set_type_filter (GstGlobalDeviceMonitor * self,
GST_OBJECT_UNLOCK (self);
}
GstDeviceMonitorFactoryListType
gst_global_device_monitor_get_type_filter (GstGlobalDeviceMonitor * self)
gchar *
gst_global_device_monitor_get_classes_filter (GstGlobalDeviceMonitor * self)
{
GstDeviceMonitorFactoryListType res;
gchar *res;
g_return_val_if_fail (GST_IS_GLOBAL_DEVICE_MONITOR (self), 0);
GST_OBJECT_LOCK (self);
res = self->priv->type;
res = g_strdup (self->priv->classes);
GST_OBJECT_UNLOCK (self);
return res;
......
......@@ -70,11 +70,10 @@ gboolean gst_global_device_monitor_start (GstGlobalDeviceMonitor * monitor);
void gst_global_device_monitor_stop (GstGlobalDeviceMonitor * monitor);
void gst_global_device_monitor_set_type_filter (
GstGlobalDeviceMonitor * monitor,
GstDeviceMonitorFactoryListType type);
void gst_global_device_monitor_set_classes_filter (
GstGlobalDeviceMonitor * monitor, const gchar *classes);
GstDeviceMonitorFactoryListType gst_global_device_monitor_get_type_filter (
gchar *gst_global_device_monitor_get_classes_filter (
GstGlobalDeviceMonitor * monitor);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment