/**
* SECTION:gstdeviceproviderfactory
+ * @title: GstDeviceProviderFactory
* @short_description: Create GstDeviceProviders from a factory
* @see_also: #GstDeviceProvider, #GstPlugin, #GstPluginFeature, #GstPadTemplate.
*
* GstDeviceProviderfactory can be added to a #GstPlugin as it is also a
* #GstPluginFeature.
*
- * Use the gst_device_provider_factory_find() and gst_device_provider_factory_create()
- * functions to create device provider instances or use gst_device_provider_factory_make() as a
+ * Use the gst_device_provider_factory_find() and
+ * gst_device_provider_factory_get() functions to create device
+ * provider instances or use gst_device_provider_factory_get_by_name() as a
* convenient shortcut.
*
* Since: 1.4
return TRUE;
}
- factory =
- GST_DEVICE_PROVIDER_FACTORY_CAST (g_object_newv
- (GST_TYPE_DEVICE_PROVIDER_FACTORY, 0, NULL));
+ factory = g_object_new (GST_TYPE_DEVICE_PROVIDER_FACTORY, NULL);
gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
GST_LOG_OBJECT (factory, "Created new device providerfactory for type %s",
g_type_name (type));
goto no_type;
device_provider = g_atomic_pointer_get (&newfactory->provider);
- if (device_provider)
+ if (device_provider) {
+ gst_object_unref (factory);
return gst_object_ref (device_provider);
+ }
/* create an instance of the device provider, cast so we don't assert on NULL
* also set name as early as we can
*/
- device_provider = GST_DEVICE_PROVIDER_CAST (g_object_newv (factory->type, 0,
- NULL));
+ device_provider = g_object_new (factory->type, NULL);
if (G_UNLIKELY (device_provider == NULL))
goto no_device_provider;
* an device provider at the same moment
*/
oclass = GST_DEVICE_PROVIDER_GET_CLASS (device_provider);
- if (!g_atomic_pointer_compare_and_exchange (&oclass->factory, NULL, factory))
+ if (!g_atomic_pointer_compare_and_exchange (&oclass->factory, NULL, factory)) {
gst_object_unref (factory);
+ } else {
+ /* This ref will never be dropped as the class is never destroyed */
+ GST_OBJECT_FLAG_SET (factory, GST_OBJECT_FLAG_MAY_BE_LEAKED);
+ }
gst_object_ref_sink (device_provider);
* only be retrieved if the device provider factory is loaded, which can be
* assured with gst_plugin_feature_load().
*
- * Returns: the #GType for device providers managed by this factory or 0 if
- * the factory is not loaded.
+ * Returns: the #GType for device providers managed by this factory.
*
* Since: 1.4
*/
gst_device_provider_factory_get_device_provider_type (GstDeviceProviderFactory *
factory)
{
- g_return_val_if_fail (GST_IS_DEVICE_PROVIDER_FACTORY (factory), 0);
+ g_return_val_if_fail (GST_IS_DEVICE_PROVIDER_FACTORY (factory),
+ G_TYPE_INVALID);
return factory->type;
}
/**
* gst_device_provider_factory_has_classesv:
* @factory: a #GstDeviceProviderFactory
- * @classes: (array zero-terminated=1): a %NULL terminated array of
- * klasses to match, only match if all classes are matched
+ * @classes: (array zero-terminated=1) (allow-none): a %NULL terminated array
+ * of classes to match, only match if all classes are matched
*
* Check if @factory matches all of the given classes
*
return FALSE;
}
- for (; classes[0]; classes++) {
+ for (; classes != NULL && classes[0] != NULL; classes++) {
const gchar *found;
guint len;
- if (classes[0] == '\0')
+ if (classes[0][0] == '\0')
continue;
found = strstr (klass, classes[0]);
/**
* gst_device_provider_factory_has_classes:
* @factory: a #GstDeviceProviderFactory
- * @classes: a "/" separate list of klasses to match, only match if all classes
- * are matched
+ * @classes: (allow-none): a "/" separate list of classes to match, only match
+ * if all classes are matched
*
* Check if @factory matches all of the given @classes
*
- * Returns: %TRUE if @factory matches.
+ * Returns: %TRUE if @factory matches or if @classes is %NULL.
*
* Since: 1.4
*/
gchar **classesv;
gboolean res;
+ if (classes == NULL)
+ return TRUE;
+
classesv = g_strsplit (classes, "/", 0);
res = gst_device_provider_factory_has_classesv (factory, classesv);
return res;
}
-typedef struct
-{
- const char *classes;
- GstRank minrank;
-} FilterData;
-
static gboolean
-device_provider_filter (GstPluginFeature * feature, FilterData * data)
+device_provider_filter (GstPluginFeature * feature, GstRank * minrank)
{
- gboolean res;
-
/* we only care about device provider factories */
if (G_UNLIKELY (!GST_IS_DEVICE_PROVIDER_FACTORY (feature)))
return FALSE;
- res = (gst_plugin_feature_get_rank (feature) >= data->minrank) &&
- gst_device_provider_factory_has_classes (GST_DEVICE_PROVIDER_FACTORY_CAST
- (feature), data->classes);
-
- return res;
+ return (gst_plugin_feature_get_rank (feature) >= *minrank);
}
/**
* gst_device_provider_factory_list_get_device_providers:
- * @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 all of the given @classes. Only
- * device providers 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 with a rank greater or equal to @minrank.
+ * The list of factories is returned by decreasing rank.
*
- * Returns: (transfer full) (element-type Gst.DeviceProviderFactory): a #GList of
- * #GstDeviceProviderFactory device providers. Use gst_plugin_feature_list_free() after
- * usage.
+ * Returns: (transfer full) (element-type Gst.DeviceProviderFactory):
+ * a #GList of #GstDeviceProviderFactory device providers. Use
+ * gst_plugin_feature_list_free() after usage.
*
* Since: 1.4
*/
-GList *gst_device_provider_factory_list_get_device_providers
- (const gchar * classes, GstRank minrank)
+GList *
+gst_device_provider_factory_list_get_device_providers (GstRank minrank)
{
GList *result;
- FilterData data;
-
- /* prepare type */
- data.classes = classes;
- data.minrank = minrank;
/* get the feature list using the filter */
result = gst_registry_feature_filter (gst_registry_get (),
- (GstPluginFeatureFilter) device_provider_filter, FALSE, &data);
+ (GstPluginFeatureFilter) device_provider_filter, FALSE, &minrank);
/* sort on rank and name */
result = g_list_sort (result, gst_plugin_feature_rank_compare_func);