2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
6 * gstelementfactory.c: GstElementFactory object, support routines
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 * SECTION:gstelementfactory
26 * @title: GstElementFactory
27 * @short_description: Create GstElements from a factory
28 * @see_also: #GstElement, #GstPlugin, #GstPluginFeature, #GstPadTemplate.
30 * #GstElementFactory is used to create instances of elements. A
31 * GstElementFactory can be added to a #GstPlugin as it is also a
34 * Use the gst_element_factory_find() and gst_element_factory_create()
35 * functions to create element instances or use gst_element_factory_make() as a
36 * convenient shortcut.
38 * The following code example shows you how to create a GstFileSrc element.
40 * ## Using an element factory
41 * |[<!-- language="C" -->
42 * #include <gst/gst.h>
45 * GstElementFactory *srcfactory;
47 * gst_init (&argc, &argv);
49 * srcfactory = gst_element_factory_find ("filesrc");
50 * g_return_if_fail (srcfactory != NULL);
51 * src = gst_element_factory_create (srcfactory, "src");
52 * g_return_if_fail (src != NULL);
57 #include "gst_private.h"
59 #include "gstelement.h"
60 #include "gstelementmetadata.h"
63 #include "gstregistry.h"
66 #include "glib-compat-private.h"
68 #include <gobject/gvaluecollector.h>
70 GST_DEBUG_CATEGORY_STATIC (element_factory_debug);
71 #define GST_CAT_DEFAULT element_factory_debug
73 static void gst_element_factory_finalize (GObject * object);
74 static void gst_element_factory_cleanup (GstElementFactory * factory);
76 /* static guint gst_element_factory_signals[LAST_SIGNAL] = { 0 }; */
78 /* this is defined in gstelement.c */
79 extern GQuark __gst_elementclass_factory;
83 GST_DEBUG_CATEGORY_INIT (element_factory_debug, "GST_ELEMENT_FACTORY", \
84 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, \
85 "element factories keep information about installed elements"); \
88 G_DEFINE_TYPE_WITH_CODE (GstElementFactory, gst_element_factory,
89 GST_TYPE_PLUGIN_FEATURE, _do_init);
91 #ifdef TIZEN_PROFILE_TV
92 static GMutex pool_mutex;
93 static GList *pool = NULL;
97 gst_element_factory_class_init (GstElementFactoryClass * klass)
99 GObjectClass *gobject_class = (GObjectClass *) klass;
101 gobject_class->finalize = gst_element_factory_finalize;
105 gst_element_factory_init (GstElementFactory * factory)
107 factory->staticpadtemplates = NULL;
108 factory->numpadtemplates = 0;
110 factory->uri_type = GST_URI_UNKNOWN;
111 factory->uri_protocols = NULL;
113 factory->interfaces = NULL;
117 gst_element_factory_finalize (GObject * object)
119 GstElementFactory *factory = GST_ELEMENT_FACTORY (object);
121 gst_element_factory_cleanup (factory);
122 G_OBJECT_CLASS (gst_element_factory_parent_class)->finalize (object);
126 * gst_element_factory_find:
127 * @name: name of factory to find
129 * Search for an element factory of the given name. Refs the returned
130 * element factory; caller is responsible for unreffing.
132 * Returns: (transfer full) (nullable): #GstElementFactory if found,
136 gst_element_factory_find (const gchar * name)
138 GstPluginFeature *feature;
140 g_return_val_if_fail (name != NULL, NULL);
142 feature = gst_registry_find_feature (gst_registry_get (), name,
143 GST_TYPE_ELEMENT_FACTORY);
145 return GST_ELEMENT_FACTORY (feature);
147 /* this isn't an error, for instance when you query if an element factory is
149 GST_LOG ("no such element factory \"%s\"", name);
154 gst_element_factory_cleanup (GstElementFactory * factory)
158 if (factory->metadata) {
159 gst_structure_free ((GstStructure *) factory->metadata);
160 factory->metadata = NULL;
163 factory->type = G_TYPE_INVALID;
166 for (item = factory->staticpadtemplates; item; item = item->next) {
167 GstStaticPadTemplate *templ = item->data;
169 gst_static_caps_cleanup (&templ->static_caps);
170 g_slice_free (GstStaticPadTemplate, templ);
172 g_list_free (factory->staticpadtemplates);
173 factory->staticpadtemplates = NULL;
174 factory->numpadtemplates = 0;
175 factory->uri_type = GST_URI_UNKNOWN;
176 if (factory->uri_protocols) {
177 g_strfreev (factory->uri_protocols);
178 factory->uri_protocols = NULL;
181 g_list_free (factory->interfaces);
182 factory->interfaces = NULL;
185 #define CHECK_METADATA_FIELD(klass, name, key) \
187 const gchar *metafield = gst_element_class_get_metadata (klass, key); \
188 if (G_UNLIKELY (metafield == NULL || *metafield == '\0')) { \
189 g_warning ("Element factory metadata for '%s' has no valid %s field", name, key); \
195 * gst_element_register:
196 * @plugin: (allow-none): #GstPlugin to register the element with, or %NULL for
198 * @name: name of elements of this type
199 * @rank: rank of element (higher rank means more importance when autoplugging)
200 * @type: GType of element to register
202 * Create a new elementfactory capable of instantiating objects of the
203 * @type and add the factory to @plugin.
205 * Returns: %TRUE, if the registering succeeded, %FALSE on error
208 gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
211 GstPluginFeature *existing_feature;
212 GstRegistry *registry;
213 GstElementFactory *factory;
215 guint n_interfaces, i;
216 GstElementClass *klass;
219 g_return_val_if_fail (name != NULL, FALSE);
220 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_ELEMENT), FALSE);
222 registry = gst_registry_get ();
224 /* check if feature already exists, if it exists there is no need to update it
225 * when the registry is getting updated, outdated plugins and all their
226 * features are removed and readded.
228 existing_feature = gst_registry_lookup_feature (registry, name);
229 if (existing_feature && existing_feature->plugin == plugin) {
230 GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)",
231 existing_feature, name);
232 factory = GST_ELEMENT_FACTORY_CAST (existing_feature);
233 factory->type = type;
234 existing_feature->loaded = TRUE;
235 g_type_set_qdata (type, __gst_elementclass_factory, factory);
236 gst_object_unref (existing_feature);
238 } else if (existing_feature) {
239 gst_object_unref (existing_feature);
242 factory = g_object_new (GST_TYPE_ELEMENT_FACTORY, NULL);
243 gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
244 GST_LOG_OBJECT (factory, "Created new elementfactory for type %s",
247 /* provide info needed during class structure setup */
248 g_type_set_qdata (type, __gst_elementclass_factory, factory);
249 klass = GST_ELEMENT_CLASS (g_type_class_ref (type));
251 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_LONGNAME);
252 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_KLASS);
253 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_DESCRIPTION);
254 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_AUTHOR);
256 factory->type = type;
257 factory->metadata = gst_structure_copy ((GstStructure *) klass->metadata);
259 for (item = klass->padtemplates; item; item = item->next) {
260 GstPadTemplate *templ = item->data;
261 GstStaticPadTemplate *newt;
262 gchar *caps_string = gst_caps_to_string (templ->caps);
264 newt = g_slice_new (GstStaticPadTemplate);
265 newt->name_template = g_intern_string (templ->name_template);
266 newt->direction = templ->direction;
267 newt->presence = templ->presence;
268 newt->static_caps.caps = NULL;
269 newt->static_caps.string = g_intern_string (caps_string);
270 factory->staticpadtemplates =
271 g_list_append (factory->staticpadtemplates, newt);
273 g_free (caps_string);
275 factory->numpadtemplates = klass->numpadtemplates;
277 /* special stuff for URI handling */
278 if (g_type_is_a (type, GST_TYPE_URI_HANDLER)) {
279 GstURIHandlerInterface *iface = (GstURIHandlerInterface *)
280 g_type_interface_peek (klass, GST_TYPE_URI_HANDLER);
282 if (!iface || !iface->get_type || !iface->get_protocols)
285 factory->uri_type = iface->get_type (factory->type);
286 if (!GST_URI_TYPE_IS_VALID (factory->uri_type))
288 if (iface->get_protocols) {
289 const gchar *const *protocols;
291 protocols = iface->get_protocols (factory->type);
292 factory->uri_protocols = g_strdupv ((gchar **) protocols);
294 if (!factory->uri_protocols)
298 interfaces = g_type_interfaces (type, &n_interfaces);
299 for (i = 0; i < n_interfaces; i++) {
300 __gst_element_factory_add_interface (factory, g_type_name (interfaces[i]));
304 if (plugin && plugin->desc.name) {
305 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name;
306 GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
307 g_object_add_weak_pointer ((GObject *) plugin,
308 (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
310 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
311 GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
313 gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank);
314 GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;
316 gst_registry_add_feature (registry, GST_PLUGIN_FEATURE_CAST (factory));
323 GST_WARNING_OBJECT (factory, "error with uri handler!");
324 gst_element_factory_cleanup (factory);
330 gst_element_factory_cleanup (factory);
336 gst_element_factory_property_valist_to_array (const gchar * first,
337 va_list properties, GType object_type, guint * n, const gchar ** names[],
343 guint n_params_alloc = 16;
344 GValue *values_array;
345 const gchar **names_array;
350 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), FALSE);
352 class = g_type_class_ref (object_type);
357 names_array = g_new0 (const gchar *, n_params_alloc);
358 values_array = g_new0 (GValue, n_params_alloc);
364 pspec = g_object_class_find_property (class, name);
368 if (G_UNLIKELY (n_params == n_params_alloc)) {
369 n_params_alloc *= 2u;
371 g_realloc (names_array, sizeof (const gchar *) * n_params_alloc);
372 values_array = g_realloc (values_array, sizeof (GValue) * n_params_alloc);
373 memset (&values_array[n_params], 0,
374 sizeof (GValue) * (n_params_alloc - n_params));
377 names_array[n_params] = name;
379 G_VALUE_COLLECT_INIT (&values_array[n_params], pspec->value_type,
380 properties, 0, &error);
383 g_critical ("%s", error);
389 name = va_arg (properties, const gchar *);
393 *names = names_array;
394 *values = values_array;
395 g_type_class_unref (class);
399 g_free (names_array);
400 g_free (values_array);
401 g_type_class_unref (class);
406 * gst_element_factory_create_with_properties:
407 * @factory: factory to instantiate
408 * @n: count of properties
409 * @names: (nullable): array of properties names
410 * @values: (nullable): array of associated properties values
412 * Create a new element of the type defined by the given elementfactory.
413 * The supplied list of properties, will be passed at object construction.
415 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
416 * if the element couldn't be created
421 gst_element_factory_create_with_properties (GstElementFactory * factory,
422 guint n, const gchar * names[], const GValue values[])
425 GstElementClass *oclass;
426 GstElementFactory *newfactory;
428 g_return_val_if_fail (factory != NULL, NULL);
431 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
434 if (newfactory == NULL)
437 factory = newfactory;
439 GST_INFO ("creating element \"%s\"", GST_OBJECT_NAME (factory));
441 if (factory->type == 0)
444 element = (GstElement *) g_object_new_with_properties (factory->type, n,
447 if (G_UNLIKELY (element == NULL))
450 /* fill in the pointer to the factory in the element class. The
451 * class will not be unreffed currently.
452 * Be thread safe as there might be 2 threads creating the first instance of
453 * an element at the same moment
455 oclass = GST_ELEMENT_GET_CLASS (element);
456 if (!g_atomic_pointer_compare_and_exchange (&oclass->elementfactory,
457 (GstElementFactory *) NULL, factory))
458 gst_object_unref (factory);
460 /* This ref will never be dropped as the class is never destroyed */
461 GST_OBJECT_FLAG_SET (factory, GST_OBJECT_FLAG_MAY_BE_LEAKED);
463 if (!g_object_is_floating ((GObject *) element)) {
464 /* The reference we receive here should be floating, but we can't force
465 * it at our level. Simply raise a critical to make the issue obvious to bindings
466 * users / developers */
467 g_critical ("The created element should be floating, "
468 "this is probably caused by faulty bindings");
472 GST_DEBUG ("created element \"%s\"", GST_OBJECT_NAME (factory));
479 GST_WARNING_OBJECT (factory, "loading plugin returned NULL!");
484 GST_WARNING_OBJECT (factory, "factory has no type");
485 gst_object_unref (factory);
490 GST_WARNING_OBJECT (factory, "could not create element");
491 gst_object_unref (factory);
497 * gst_element_factory_create_valist:
498 * @factory: factory to instantiate
499 * @first: (nullable): name of the first property
500 * @properties: (nullable): list of properties
502 * Create a new element of the type defined by the given elementfactory.
503 * The supplied list of properties, will be passed at object construction.
505 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
506 * if the element couldn't be created
511 gst_element_factory_create_valist (GstElementFactory * factory,
512 const gchar * first, va_list properties)
514 GstElementFactory *newfactory;
516 const gchar **names = NULL;
517 GValue *values = NULL;
520 g_return_val_if_fail (factory != NULL, NULL);
523 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
526 g_return_val_if_fail (newfactory != NULL, NULL);
527 g_return_val_if_fail (newfactory->type != 0, NULL);
529 factory = newfactory;
533 gst_element_factory_create_with_properties (factory, 0, NULL, NULL);
537 if (!gst_element_factory_property_valist_to_array (first, properties,
538 factory->type, &n, &names, &values)) {
539 GST_ERROR_OBJECT (factory, "property parsing failed");
544 element = gst_element_factory_create_with_properties (factory, n, names,
549 g_value_unset (&values[n]);
553 gst_object_unref (factory);
558 * gst_element_factory_create_full:
559 * @factory: factory to instantiate
560 * @first: (nullable): name of the first property
561 * @...: (nullable): %NULL terminated list of properties
563 * Create a new element of the type defined by the given elementfactory.
564 * The supplied list of properties, will be passed at object construction.
566 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
567 * if the element couldn't be created
572 gst_element_factory_create_full (GstElementFactory * factory,
573 const gchar * first, ...)
578 va_start (properties, first);
579 element = gst_element_factory_create_valist (factory, first, properties);
586 * gst_element_factory_create:
587 * @factory: factory to instantiate
588 * @name: (nullable): name of new element, or %NULL to automatically create
591 * Create a new element of the type defined by the given elementfactory.
592 * It will be given the name supplied, since all elements require a name as
593 * their first argument.
595 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
596 * if the element couldn't be created
599 gst_element_factory_create (GstElementFactory * factory, const gchar * name)
602 return gst_element_factory_create_full (factory, "name", name, NULL);
604 return gst_element_factory_create_with_properties (factory, 0, NULL, NULL);
608 * gst_element_factory_make_with_properties:
609 * @factoryname: a named factory to instantiate
610 * @n: count of properties
611 * @names: (nullable): array of properties names
612 * @values: (nullable): array of associated properties values
614 * Create a new element of the type defined by the given elementfactory.
615 * The supplied list of properties, will be passed at object construction.
617 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
618 * if the element couldn't be created
623 gst_element_factory_make_with_properties (const gchar * factoryname,
624 guint n, const gchar * names[], const GValue values[])
626 GstElementFactory *factory;
629 g_return_val_if_fail (factoryname != NULL, NULL);
630 g_return_val_if_fail (gst_is_initialized (), NULL);
632 GST_LOG ("gstelementfactory: make \"%s\"", factoryname);
634 factory = gst_element_factory_find (factoryname);
638 GST_LOG_OBJECT (factory, "found factory %p", factory);
639 element = gst_element_factory_create_with_properties (factory, n, names,
644 gst_object_unref (factory);
651 GST_WARNING ("no such element factory \"%s\"!", factoryname);
656 GST_INFO_OBJECT (factory, "couldn't create instance!");
657 gst_object_unref (factory);
663 * gst_element_factory_make_valist:
664 * @factoryname: a named factory to instantiate
665 * @first: (nullable): name of first property
666 * @properties: (nullable): list of properties
668 * Create a new element of the type defined by the given element factory.
669 * The supplied list of properties, will be passed at object construction.
671 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
672 * if unable to create element
677 gst_element_factory_make_valist (const gchar * factoryname,
678 const gchar * first, va_list properties)
680 GstElementFactory *factory;
683 g_return_val_if_fail (factoryname != NULL, NULL);
684 g_return_val_if_fail (gst_is_initialized (), NULL);
686 GST_LOG ("gstelementfactory: make \"%s\"", factoryname);
688 factory = gst_element_factory_find (factoryname);
692 GST_LOG_OBJECT (factory, "found factory %p", factory);
693 element = gst_element_factory_create_valist (factory, first, properties);
697 gst_object_unref (factory);
704 GST_WARNING ("no such element factory \"%s\"!", factoryname);
709 GST_INFO_OBJECT (factory, "couldn't create instance!");
710 gst_object_unref (factory);
716 * gst_element_factory_make_full:
717 * @factoryname: a named factory to instantiate
718 * @first: (nullable): name of first property
719 * @...: (nullable): %NULL terminated list of properties
721 * Create a new element of the type defined by the given element factory.
722 * The supplied list of properties, will be passed at object construction.
724 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
725 * if unable to create element
730 gst_element_factory_make_full (const gchar * factoryname,
731 const gchar * first, ...)
736 va_start (properties, first);
738 element = gst_element_factory_make_valist (factoryname, first, properties);
745 * gst_element_factory_make:
746 * @factoryname: a named factory to instantiate
747 * @name: (nullable): name of new element, or %NULL to automatically create
750 * Create a new element of the type defined by the given element factory.
751 * If name is %NULL, then the element will receive a guaranteed unique name,
752 * consisting of the element factory name and a number.
753 * If name is given, it will be given the name supplied.
755 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
756 * if unable to create element
759 gst_element_factory_make (const gchar * factoryname, const gchar * name)
762 return gst_element_factory_make_full (factoryname, "name", name, NULL);
764 return gst_element_factory_make_with_properties (factoryname, 0, NULL,
769 __gst_element_factory_add_static_pad_template (GstElementFactory * factory,
770 GstStaticPadTemplate * templ)
772 g_return_if_fail (factory != NULL);
773 g_return_if_fail (templ != NULL);
775 factory->staticpadtemplates =
776 g_list_append (factory->staticpadtemplates, templ);
777 factory->numpadtemplates++;
781 * gst_element_factory_get_element_type:
782 * @factory: factory to get managed #GType from
784 * Get the #GType for elements managed by this factory. The type can
785 * only be retrieved if the element factory is loaded, which can be
786 * assured with gst_plugin_feature_load().
788 * Returns: the #GType for elements managed by this factory or 0 if
789 * the factory is not loaded.
792 gst_element_factory_get_element_type (GstElementFactory * factory)
794 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), 0);
796 return factory->type;
800 * gst_element_factory_get_metadata:
801 * @factory: a #GstElementFactory
804 * Get the metadata on @factory with @key.
806 * Returns: (nullable): the metadata with @key on @factory or %NULL
807 * when there was no metadata with the given @key.
810 gst_element_factory_get_metadata (GstElementFactory * factory,
813 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
815 return gst_structure_get_string ((GstStructure *) factory->metadata, key);
819 * gst_element_factory_get_metadata_keys:
820 * @factory: a #GstElementFactory
822 * Get the available keys for the metadata on @factory.
824 * Returns: (transfer full) (element-type utf8) (array zero-terminated=1) (nullable):
825 * a %NULL-terminated array of key strings, or %NULL when there is no
826 * metadata. Free with g_strfreev() when no longer needed.
829 gst_element_factory_get_metadata_keys (GstElementFactory * factory)
831 GstStructure *metadata;
835 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
837 metadata = (GstStructure *) factory->metadata;
838 if (metadata == NULL)
841 num = gst_structure_n_fields (metadata);
845 arr = g_new (gchar *, num + 1);
846 for (i = 0; i < num; ++i) {
847 arr[i] = g_strdup (gst_structure_nth_field_name (metadata, i));
854 * gst_element_factory_get_num_pad_templates:
855 * @factory: a #GstElementFactory
857 * Gets the number of pad_templates in this factory.
859 * Returns: the number of pad_templates
862 gst_element_factory_get_num_pad_templates (GstElementFactory * factory)
864 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), 0);
866 return factory->numpadtemplates;
870 * __gst_element_factory_add_interface:
871 * @elementfactory: The elementfactory to add the interface to
872 * @interfacename: Name of the interface
874 * Adds the given interfacename to the list of implemented interfaces of the
878 __gst_element_factory_add_interface (GstElementFactory * elementfactory,
879 const gchar * interfacename)
881 g_return_if_fail (GST_IS_ELEMENT_FACTORY (elementfactory));
882 g_return_if_fail (interfacename != NULL);
883 g_return_if_fail (interfacename[0] != '\0'); /* no empty string */
885 elementfactory->interfaces =
886 g_list_prepend (elementfactory->interfaces,
887 (gpointer) g_intern_string (interfacename));
891 * gst_element_factory_get_static_pad_templates:
892 * @factory: a #GstElementFactory
894 * Gets the #GList of #GstStaticPadTemplate for this factory.
896 * Returns: (transfer none) (element-type Gst.StaticPadTemplate): the
897 * static pad templates
900 gst_element_factory_get_static_pad_templates (GstElementFactory * factory)
902 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
904 return factory->staticpadtemplates;
908 * gst_element_factory_get_uri_type:
909 * @factory: a #GstElementFactory
911 * Gets the type of URIs the element supports or #GST_URI_UNKNOWN if none.
913 * Returns: type of URIs this element supports
916 gst_element_factory_get_uri_type (GstElementFactory * factory)
918 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), GST_URI_UNKNOWN);
920 return factory->uri_type;
924 * gst_element_factory_get_uri_protocols:
925 * @factory: a #GstElementFactory
927 * Gets a %NULL-terminated array of protocols this element supports or %NULL if
928 * no protocols are supported. You may not change the contents of the returned
929 * array, as it is still owned by the element factory. Use g_strdupv() to
930 * make a copy of the protocol string array if you need to.
932 * Returns: (transfer none) (array zero-terminated=1): the supported protocols
936 gst_element_factory_get_uri_protocols (GstElementFactory * factory)
938 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
940 return (const gchar * const *) factory->uri_protocols;
944 * gst_element_factory_has_interface:
945 * @factory: a #GstElementFactory
946 * @interfacename: an interface name
948 * Check if @factory implements the interface with name @interfacename.
950 * Returns: %TRUE when @factory implement the interface.
953 gst_element_factory_has_interface (GstElementFactory * factory,
954 const gchar * interfacename)
958 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), FALSE);
960 for (walk = factory->interfaces; walk; walk = g_list_next (walk)) {
961 gchar *iname = (gchar *) walk->data;
963 if (!strcmp (iname, interfacename))
972 GstElementFactoryListType type;
978 * gst_element_factory_list_is_type:
979 * @factory: a #GstElementFactory
980 * @type: a #GstElementFactoryListType
982 * Check if @factory is of the given types.
984 * Returns: %TRUE if @factory is of @type.
987 gst_element_factory_list_is_type (GstElementFactory * factory,
988 GstElementFactoryListType type)
990 gboolean res = FALSE;
994 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
997 GST_ERROR_OBJECT (factory, "element factory is missing klass identifiers");
1001 /* Filter by element type first, as soon as it matches
1002 * one type, we skip all other tests */
1003 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_SINK))
1004 res = (strstr (klass, "Sink") != NULL);
1006 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_SRC))
1007 res = (strstr (klass, "Source") != NULL);
1009 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DECODER))
1010 res = (strstr (klass, "Decoder") != NULL);
1012 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_ENCODER))
1013 res = (strstr (klass, "Encoder") != NULL);
1015 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_MUXER))
1016 res = (strstr (klass, "Muxer") != NULL);
1018 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DEMUXER))
1019 res = (strstr (klass, "Demux") != NULL);
1021 /* FIXME : We're actually parsing two Classes here... */
1022 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_PARSER))
1023 res = ((strstr (klass, "Parser") != NULL)
1024 && (strstr (klass, "Codec") != NULL));
1026 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER))
1027 res = (strstr (klass, "Depayloader") != NULL);
1029 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_PAYLOADER))
1030 res = (strstr (klass, "Payloader") != NULL);
1032 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_FORMATTER))
1033 res = (strstr (klass, "Formatter") != NULL);
1035 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DECRYPTOR))
1036 res = (strstr (klass, "Decryptor") != NULL);
1038 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_ENCRYPTOR))
1039 res = (strstr (klass, "Encryptor") != NULL);
1041 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_HARDWARE))
1042 res = (strstr (klass, "Hardware") != NULL);
1044 /* Filter by media type now, we only test if it
1045 * matched any of the types above or only checking the media
1046 * type was requested. */
1047 if ((res || !(type & (GST_ELEMENT_FACTORY_TYPE_MAX_ELEMENTS - 1)))
1048 && (type & (GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO |
1049 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
1050 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE |
1051 GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE |
1052 GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)))
1053 res = ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)
1054 && (strstr (klass, "Audio") != NULL))
1055 || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO)
1056 && (strstr (klass, "Video") != NULL))
1057 || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)
1058 && (strstr (klass, "Image") != NULL)) ||
1059 ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE)
1060 && (strstr (klass, "Subtitle") != NULL)) ||
1061 ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)
1062 && (strstr (klass, "Metadata") != NULL));
1068 element_filter (GstPluginFeature * feature, FilterData * data)
1072 /* we only care about element factories */
1073 if (G_UNLIKELY (!GST_IS_ELEMENT_FACTORY (feature)))
1076 res = (gst_plugin_feature_get_rank (feature) >= data->minrank) &&
1077 gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (feature),
1084 * gst_element_factory_list_get_elements:
1085 * @type: a #GstElementFactoryListType
1086 * @minrank: Minimum rank
1088 * Get a list of factories that match the given @type. Only elements
1089 * with a rank greater or equal to @minrank will be returned.
1090 * The list of factories is returned by decreasing rank.
1092 * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
1093 * #GstElementFactory elements. Use gst_plugin_feature_list_free() after
1097 gst_element_factory_list_get_elements (GstElementFactoryListType type,
1105 data.minrank = minrank;
1107 /* get the feature list using the filter */
1108 result = gst_registry_feature_filter (gst_registry_get (),
1109 (GstPluginFeatureFilter) element_filter, FALSE, &data);
1111 /* sort on rank and name */
1112 result = g_list_sort (result, gst_plugin_feature_rank_compare_func);
1118 * gst_element_factory_list_filter:
1119 * @list: (transfer none) (element-type Gst.ElementFactory): a #GList of
1120 * #GstElementFactory to filter
1122 * @direction: a #GstPadDirection to filter on
1123 * @subsetonly: whether to filter on caps subsets or not.
1125 * Filter out all the elementfactories in @list that can handle @caps in
1126 * the given direction.
1128 * If @subsetonly is %TRUE, then only the elements whose pads templates
1129 * are a complete superset of @caps will be returned. Else any element
1130 * whose pad templates caps can intersect with @caps will be returned.
1132 * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
1133 * #GstElementFactory elements that match the given requisites.
1134 * Use #gst_plugin_feature_list_free after usage.
1137 gst_element_factory_list_filter (GList * list,
1138 const GstCaps * caps, GstPadDirection direction, gboolean subsetonly)
1140 GQueue results = G_QUEUE_INIT;
1142 GST_DEBUG ("finding factories");
1144 /* loop over all the factories */
1145 for (; list; list = list->next) {
1146 GstElementFactory *factory;
1147 const GList *templates;
1150 factory = (GstElementFactory *) list->data;
1152 GST_DEBUG ("Trying %s",
1153 gst_plugin_feature_get_name ((GstPluginFeature *) factory));
1155 /* get the templates from the element factory */
1156 templates = gst_element_factory_get_static_pad_templates (factory);
1157 for (walk = (GList *) templates; walk; walk = g_list_next (walk)) {
1158 GstStaticPadTemplate *templ = walk->data;
1160 /* we only care about the sink templates */
1161 if (templ->direction == direction) {
1164 /* try to intersect the caps with the caps of the template */
1165 tmpl_caps = gst_static_caps_get (&templ->static_caps);
1167 /* FIXME, intersect is not the right method, we ideally want to check
1168 * for a subset here */
1170 /* check if the intersection is empty */
1171 if ((subsetonly && gst_caps_is_subset (caps, tmpl_caps)) ||
1172 (!subsetonly && gst_caps_can_intersect (caps, tmpl_caps))) {
1173 /* non empty intersection, we can use this element */
1174 g_queue_push_tail (&results, gst_object_ref (factory));
1175 gst_caps_unref (tmpl_caps);
1178 gst_caps_unref (tmpl_caps);
1182 return results.head;
1185 #ifdef TIZEN_PROFILE_TV
1187 * gst_element_factory_pool_push:
1189 * Pushes the element to the pool. This function increase the refcount of @element.
1190 * And the pool will take a reference forever.
1194 gst_element_factory_pool_push (GstElement * element)
1196 gboolean ret = FALSE;
1197 g_return_val_if_fail (element != NULL, FALSE);
1198 g_return_val_if_fail (GST_IS_ELEMENT (element) == TRUE, FALSE);
1199 g_return_val_if_fail (GST_IS_BIN (element) == FALSE, FALSE);
1200 g_return_val_if_fail (GST_IS_PIPELINE (element) == FALSE, FALSE);
1202 g_mutex_lock (&pool_mutex);
1203 if (!g_list_find (pool, (gconstpointer) element)) {
1204 gst_object_ref (element);
1205 pool = g_list_prepend (pool, element);
1208 //GST_INFO("ret[ %d ], [ %s / %p ] - refcount[ %d ], state[ %d ]", ret, GST_ELEMENT_NAME(element), element, GST_OBJECT_REFCOUNT(element), GST_STATE (element));
1209 g_mutex_unlock (&pool_mutex);
1214 is_available_element (gconstpointer data, gconstpointer factory_)
1216 GstElement *element = GST_ELEMENT_CAST (data);
1217 const GstElementFactory *factory = (const GstElementFactory *) factory_;
1218 gboolean found = FALSE;
1219 if (gst_element_get_factory (element) == factory
1220 && GST_ELEMENT_PARENT (element) == NULL
1221 && GST_OBJECT_REFCOUNT (element) == 1
1222 && (GST_STATE (element) == GST_STATE_NULL
1223 || GST_STATE (element) == GST_STATE_VOID_PENDING)) {
1226 //GST_DEBUG("PARENT[ %p ], [ %s / %p ] - refcount[ %d ], state[ %d ]", GST_ELEMENT_PARENT(element), GST_ELEMENT_NAME(element), element, GST_OBJECT_REFCOUNT(element), GST_STATE (element));
1235 * gst_element_factory_pool_get:
1237 * Get a element which is created by given @factoryname
1238 * You can search any element by this API before you use gst_element_factory_create.
1239 * Returns: (transfer full): a pointer to the #GstElement.
1240 * This function guarantee that the refcount of returned #GstElement is 1,
1241 * and it's state is NULL-STATE.
1246 gst_element_factory_pool_get (GstElementFactory * factory,
1247 const gchar * new_element_name)
1249 GstElement *element = NULL;
1250 GList *found = NULL;
1251 g_return_val_if_fail (factory != NULL, NULL);
1252 g_return_val_if_fail (pool != NULL, NULL);
1254 g_mutex_lock (&pool_mutex);
1255 found = g_list_find_custom (pool, factory, is_available_element);
1257 element = GST_ELEMENT_CAST (found->data);
1258 gst_object_ref (element);
1259 if (new_element_name)
1260 gst_element_set_name (element, new_element_name);
1262 g_mutex_unlock (&pool_mutex);
1266 /* First, Try to get element from pool. */
1268 gst_element_factory_get (GstElementFactory * factory, const gchar * name)
1270 GstElement *element = NULL;
1271 g_return_val_if_fail (factory != NULL, NULL);
1272 element = gst_element_factory_pool_get (factory, name);
1274 element = gst_element_factory_create (factory, name);
1276 GST_ERROR ("[ %s / %p ], new element name[ %s ]",
1277 GST_OBJECT_NAME (factory), factory, name);
1280 gst_element_factory_pool_push (element);
1282 gst_set_family_id_to_child (element, 0);
1285 //GST_INFO("[ %s / %p ] - refcount[ %d ], state[ %d ]", GST_ELEMENT_NAME(element), element, GST_OBJECT_REFCOUNT(element), GST_STATE (element));