devicemonitor: Make classes into pure strings

Instead of having strings & flags, make them just strings
This commit is contained in:
Olivier Crête 2014-03-16 18:02:56 -04:00
parent 4d7d3a1c02
commit b8078e2656
4 changed files with 93 additions and 108 deletions

View file

@ -456,64 +456,91 @@ gst_device_monitor_factory_get_metadata_keys (GstDeviceMonitorFactory * factory)
return arr; 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 * @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 * Since: 1.4
*/ */
gboolean gboolean
gst_device_monitor_factory_list_is_type (GstDeviceMonitorFactory * factory, gst_device_monitor_factory_has_classesv (GstDeviceMonitorFactory * factory,
GstDeviceMonitorFactoryListType type) gchar ** classes)
{ {
gboolean res = FALSE;
const gchar *klass; const gchar *klass;
g_return_val_if_fail (GST_IS_DEVICE_MONITOR_FACTORY (factory), FALSE);
klass = gst_device_monitor_factory_get_metadata (factory, klass = gst_device_monitor_factory_get_metadata (factory,
GST_ELEMENT_METADATA_KLASS); GST_ELEMENT_METADATA_KLASS);
if (klass == NULL) { if (klass == NULL) {
GST_ERROR_OBJECT (factory, GST_ERROR_OBJECT (factory,
"device monitor factory is missing klass identifiers"); "device monitor factory is missing klass identifiers");
return res; return FALSE;
} }
/* Filter by device monitor type first, as soon as it matches for (; classes[0]; classes++) {
* one type, we skip all other tests */ const gchar *found;
if (!res && (type & GST_DEVICE_MONITOR_FACTORY_TYPE_SINK)) guint len;
res = (strstr (klass, "Sink") != NULL);
if (!res && (type & GST_DEVICE_MONITOR_FACTORY_TYPE_SRC)) if (classes[0] == '\0')
res = (strstr (klass, "Source") != NULL); continue;
/* Filter by media type now, we only test if it found = strstr (klass, classes[0]);
* matched any of the types above. */
if (res if (!found)
&& (type & (GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_AUDIO | return FALSE;
GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_VIDEO | if (found != klass && *(found - 1) != '/')
GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_IMAGE))) return FALSE;
res = ((type & GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_AUDIO)
&& (strstr (klass, "Audio") != NULL)) len = strlen (classes[0]);
|| ((type & GST_DEVICE_MONITOR_FACTORY_TYPE_MEDIA_VIDEO) if (found[len] != 0 && found[len] != '/')
&& (strstr (klass, "Video") != NULL)) return FALSE;
|| ((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; return res;
} }
typedef struct
{
const char *classes;
GstRank minrank;
} FilterData;
static gboolean static gboolean
device_monitor_filter (GstPluginFeature * feature, FilterData * data) device_monitor_filter (GstPluginFeature * feature, FilterData * data)
{ {
@ -524,20 +551,21 @@ device_monitor_filter (GstPluginFeature * feature, FilterData * data)
return FALSE; return FALSE;
res = (gst_plugin_feature_get_rank (feature) >= data->minrank) && res = (gst_plugin_feature_get_rank (feature) >= data->minrank) &&
gst_device_monitor_factory_list_is_type (GST_DEVICE_MONITOR_FACTORY_CAST gst_device_monitor_factory_has_classes (GST_DEVICE_MONITOR_FACTORY_CAST
(feature), data->type); (feature), data->classes);
return res; return res;
} }
/** /**
* gst_device_monitor_factory_list_get_device_monitors: * 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 * @minrank: Minimum rank
* *
* Get a list of factories that match the given @type. Only device monitors * Get a list of factories that match all of the given @classes. Only
* with a rank greater or equal to @minrank will be returned. * device monitors with a rank greater or equal to @minrank will be
* The list of factories is returned by decreasing rank. * returned. The list of factories is returned by decreasing rank.
* *
* Returns: (transfer full) (element-type Gst.DeviceMonitorFactory): a #GList of * Returns: (transfer full) (element-type Gst.DeviceMonitorFactory): a #GList of
* #GstDeviceMonitorFactory device monitors. Use gst_plugin_feature_list_free() after * #GstDeviceMonitorFactory device monitors. Use gst_plugin_feature_list_free() after
@ -546,13 +574,13 @@ device_monitor_filter (GstPluginFeature * feature, FilterData * data)
* Since: 1.4 * Since: 1.4
*/ */
GList *gst_device_monitor_factory_list_get_device_monitors GList *gst_device_monitor_factory_list_get_device_monitors
(GstDeviceMonitorFactoryListType type, GstRank minrank) (const gchar * classes, GstRank minrank)
{ {
GList *result; GList *result;
FilterData data; FilterData data;
/* prepare type */ /* prepare type */
data.type = type; data.classes = classes;
data.minrank = minrank; data.minrank = minrank;
/* get the feature list using the filter */ /* get the feature list using the filter */

View file

@ -68,55 +68,13 @@ gboolean gst_device_monitor_register (GstPlugin
guint rank, guint rank,
GType type); GType type);
/* Factory list functions */ gboolean gst_device_monitor_factory_has_classesv (GstDeviceMonitorFactory * factory,
gchar ** classes);
/** gboolean gst_device_monitor_factory_has_classes (GstDeviceMonitorFactory *factory,
* GstDeviceMonitorFactoryListType: const gchar * classes);
* @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; GList * gst_device_monitor_factory_list_get_device_monitors (const gchar *types,
#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);
GList * gst_device_monitor_factory_list_get_device_monitors (GstDeviceMonitorFactoryListType type,
GstRank minrank) G_GNUC_MALLOC; GstRank minrank) G_GNUC_MALLOC;
G_END_DECLS G_END_DECLS

View file

@ -38,7 +38,7 @@ struct _GstGlobalDeviceMonitorPrivate
guint cookie; guint cookie;
GstCaps *caps; 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->monitors = g_ptr_array_new ();
self->priv->caps = gst_caps_new_any (); self->priv->caps = gst_caps_new_any ();
self->priv->type = GST_DEVICE_MONITOR_FACTORY_TYPE_SINK | self->priv->classes = g_strdup ("");
GST_DEVICE_MONITOR_FACTORY_TYPE_SRC;
factories = 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) { while (factories) {
GstDeviceMonitorFactory *factory = factories->data; GstDeviceMonitorFactory *factory = factories->data;
@ -155,6 +155,7 @@ gst_global_device_monitor_dispose (GObject * object)
} }
gst_caps_replace (&self->priv->caps, NULL); gst_caps_replace (&self->priv->caps, NULL);
g_free (self->priv->classes);
gst_object_replace ((GstObject **) & self->priv->bus, NULL); gst_object_replace ((GstObject **) & self->priv->bus, NULL);
G_OBJECT_CLASS (gst_global_device_monitor_parent_class)->dispose (object); G_OBJECT_CLASS (gst_global_device_monitor_parent_class)->dispose (object);
@ -293,28 +294,27 @@ gst_global_device_monitor_stop (GstGlobalDeviceMonitor * self)
} }
void void
gst_global_device_monitor_set_type_filter (GstGlobalDeviceMonitor * self, gst_global_device_monitor_set_classes_filter (GstGlobalDeviceMonitor * self,
GstDeviceMonitorFactoryListType type) const gchar * classes)
{ {
GList *factories = NULL; GList *factories = NULL;
guint i; guint i;
g_return_if_fail (GST_IS_GLOBAL_DEVICE_MONITOR (self)); g_return_if_fail (GST_IS_GLOBAL_DEVICE_MONITOR (self));
g_return_if_fail (!self->priv->started); 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); GST_OBJECT_LOCK (self);
if (self->priv->type == type) { if (!strcmp (self->priv->classes, classes)) {
GST_OBJECT_UNLOCK (self); GST_OBJECT_UNLOCK (self);
return; return;
} }
self->priv->type = type; g_free (self->priv->classes);
self->priv->classes = g_strdup (classes);
factories = 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++) { for (i = 0; i < self->priv->monitors->len; i++) {
GstDeviceMonitor *monitor = g_ptr_array_index (self->priv->monitors, 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); GST_OBJECT_UNLOCK (self);
} }
GstDeviceMonitorFactoryListType gchar *
gst_global_device_monitor_get_type_filter (GstGlobalDeviceMonitor * self) 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); g_return_val_if_fail (GST_IS_GLOBAL_DEVICE_MONITOR (self), 0);
GST_OBJECT_LOCK (self); GST_OBJECT_LOCK (self);
res = self->priv->type; res = g_strdup (self->priv->classes);
GST_OBJECT_UNLOCK (self); GST_OBJECT_UNLOCK (self);
return res; return res;

View file

@ -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_stop (GstGlobalDeviceMonitor * monitor);
void gst_global_device_monitor_set_type_filter ( void gst_global_device_monitor_set_classes_filter (
GstGlobalDeviceMonitor * monitor, GstGlobalDeviceMonitor * monitor, const gchar *classes);
GstDeviceMonitorFactoryListType type);
GstDeviceMonitorFactoryListType gst_global_device_monitor_get_type_filter ( gchar *gst_global_device_monitor_get_classes_filter (
GstGlobalDeviceMonitor * monitor); GstGlobalDeviceMonitor * monitor);