X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstdeviceproviderfactory.c;h=3fbaa3b2f14e9be31148682dd5f9d366796cf4c0;hb=f34472822c257359d69ebf671b81d85646a40618;hp=d0586afceca1dcd1b5c14b5efb58d09396874868;hpb=7992174a1a367c2f3cf3bc53fc1bd76fd8a365d0;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstdeviceproviderfactory.c b/gst/gstdeviceproviderfactory.c index d0586af..3fbaa3b 100644 --- a/gst/gstdeviceproviderfactory.c +++ b/gst/gstdeviceproviderfactory.c @@ -23,6 +23,7 @@ /** * SECTION:gstdeviceproviderfactory + * @title: GstDeviceProviderFactory * @short_description: Create GstDeviceProviders from a factory * @see_also: #GstDeviceProvider, #GstPlugin, #GstPluginFeature, #GstPadTemplate. * @@ -30,8 +31,9 @@ * 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 @@ -195,9 +197,7 @@ gst_device_provider_register (GstPlugin * plugin, const gchar * name, 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)); @@ -274,14 +274,15 @@ gst_device_provider_factory_get (GstDeviceProviderFactory * factory) 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; @@ -291,8 +292,12 @@ gst_device_provider_factory_get (GstDeviceProviderFactory * factory) * 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); @@ -387,8 +392,7 @@ create_failed: * 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 */ @@ -396,7 +400,8 @@ GType 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; } @@ -461,8 +466,8 @@ gst_device_provider_factory_get_metadata_keys (GstDeviceProviderFactory * /** * 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 * @@ -487,11 +492,11 @@ gst_device_provider_factory_has_classesv (GstDeviceProviderFactory * factory, 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]); @@ -512,12 +517,12 @@ gst_device_provider_factory_has_classesv (GstDeviceProviderFactory * factory, /** * 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 */ @@ -528,6 +533,9 @@ gst_device_provider_factory_has_classes (GstDeviceProviderFactory * factory, gchar **classesv; gboolean res; + if (classes == NULL) + return TRUE; + classesv = g_strsplit (classes, "/", 0); res = gst_device_provider_factory_has_classesv (factory, classesv); @@ -537,57 +545,37 @@ gst_device_provider_factory_has_classes (GstDeviceProviderFactory * factory, 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);