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;
80 extern GQuark __gst_elementclass_skip_doc;
84 GST_DEBUG_CATEGORY_INIT (element_factory_debug, "GST_ELEMENT_FACTORY", \
85 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, \
86 "element factories keep information about installed elements"); \
89 G_DEFINE_TYPE_WITH_CODE (GstElementFactory, gst_element_factory,
90 GST_TYPE_PLUGIN_FEATURE, _do_init);
92 #ifdef TIZEN_PROFILE_TV
93 static GMutex pool_mutex;
94 static GList *pool = NULL;
98 gst_element_factory_class_init (GstElementFactoryClass * klass)
100 GObjectClass *gobject_class = (GObjectClass *) klass;
102 gobject_class->finalize = gst_element_factory_finalize;
106 gst_element_factory_init (GstElementFactory * factory)
108 factory->staticpadtemplates = NULL;
109 factory->numpadtemplates = 0;
111 factory->uri_type = GST_URI_UNKNOWN;
112 factory->uri_protocols = NULL;
114 factory->interfaces = NULL;
118 gst_element_factory_finalize (GObject * object)
120 GstElementFactory *factory = GST_ELEMENT_FACTORY (object);
122 gst_element_factory_cleanup (factory);
123 G_OBJECT_CLASS (gst_element_factory_parent_class)->finalize (object);
127 * gst_element_factory_find:
128 * @name: name of factory to find
130 * Search for an element factory of the given name. Refs the returned
131 * element factory; caller is responsible for unreffing.
133 * Returns: (transfer full) (nullable): #GstElementFactory if found,
137 gst_element_factory_find (const gchar * name)
139 GstPluginFeature *feature;
141 g_return_val_if_fail (name != NULL, NULL);
143 feature = gst_registry_find_feature (gst_registry_get (), name,
144 GST_TYPE_ELEMENT_FACTORY);
146 return GST_ELEMENT_FACTORY (feature);
148 /* this isn't an error, for instance when you query if an element factory is
150 GST_LOG ("no such element factory \"%s\"", name);
155 gst_element_factory_cleanup (GstElementFactory * factory)
159 if (factory->metadata) {
160 gst_structure_free ((GstStructure *) factory->metadata);
161 factory->metadata = NULL;
164 factory->type = G_TYPE_INVALID;
167 for (item = factory->staticpadtemplates; item; item = item->next) {
168 GstStaticPadTemplate *templ = item->data;
170 gst_static_caps_cleanup (&templ->static_caps);
171 g_slice_free (GstStaticPadTemplate, templ);
173 g_list_free (factory->staticpadtemplates);
174 factory->staticpadtemplates = NULL;
175 factory->numpadtemplates = 0;
176 factory->uri_type = GST_URI_UNKNOWN;
177 if (factory->uri_protocols) {
178 g_strfreev (factory->uri_protocols);
179 factory->uri_protocols = NULL;
182 g_list_free (factory->interfaces);
183 factory->interfaces = NULL;
186 #define CHECK_METADATA_FIELD(klass, name, key) \
188 const gchar *metafield = gst_element_class_get_metadata (klass, key); \
189 if (G_UNLIKELY (metafield == NULL || *metafield == '\0')) { \
190 g_warning ("Element factory metadata for '%s' has no valid %s field", name, key); \
196 * gst_element_register:
197 * @plugin: (allow-none): #GstPlugin to register the element with, or %NULL for
199 * @name: name of elements of this type
200 * @rank: rank of element (higher rank means more importance when autoplugging)
201 * @type: GType of element to register
203 * Create a new elementfactory capable of instantiating objects of the
204 * @type and add the factory to @plugin.
206 * Returns: %TRUE, if the registering succeeded, %FALSE on error
209 gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
212 GstPluginFeature *existing_feature;
213 GstRegistry *registry;
214 GstElementFactory *factory;
216 guint n_interfaces, i;
217 GstElementClass *klass;
220 g_return_val_if_fail (name != NULL, FALSE);
221 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_ELEMENT), FALSE);
223 registry = gst_registry_get ();
225 /* check if feature already exists, if it exists there is no need to update it
226 * when the registry is getting updated, outdated plugins and all their
227 * features are removed and readded.
229 existing_feature = gst_registry_lookup_feature (registry, name);
230 if (existing_feature && existing_feature->plugin == plugin) {
231 GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)",
232 existing_feature, name);
233 factory = GST_ELEMENT_FACTORY_CAST (existing_feature);
234 factory->type = type;
235 existing_feature->loaded = TRUE;
236 g_type_set_qdata (type, __gst_elementclass_factory, factory);
237 gst_object_unref (existing_feature);
239 } else if (existing_feature) {
240 gst_object_unref (existing_feature);
243 factory = g_object_new (GST_TYPE_ELEMENT_FACTORY, NULL);
244 gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
245 GST_LOG_OBJECT (factory, "Created new elementfactory for type %s",
248 /* provide info needed during class structure setup */
249 g_type_set_qdata (type, __gst_elementclass_factory, factory);
250 klass = GST_ELEMENT_CLASS (g_type_class_ref (type));
252 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_LONGNAME);
253 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_KLASS);
254 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_DESCRIPTION);
255 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_AUTHOR);
257 factory->type = type;
258 factory->metadata = gst_structure_copy ((GstStructure *) klass->metadata);
260 for (item = klass->padtemplates; item; item = item->next) {
261 GstPadTemplate *templ = item->data;
262 GstStaticPadTemplate *newt;
263 gchar *caps_string = gst_caps_to_string (templ->caps);
265 newt = g_slice_new (GstStaticPadTemplate);
266 newt->name_template = g_intern_string (templ->name_template);
267 newt->direction = templ->direction;
268 newt->presence = templ->presence;
269 newt->static_caps.caps = NULL;
270 newt->static_caps.string = g_intern_string (caps_string);
271 factory->staticpadtemplates =
272 g_list_append (factory->staticpadtemplates, newt);
274 g_free (caps_string);
276 factory->numpadtemplates = klass->numpadtemplates;
278 /* special stuff for URI handling */
279 if (g_type_is_a (type, GST_TYPE_URI_HANDLER)) {
280 GstURIHandlerInterface *iface = (GstURIHandlerInterface *)
281 g_type_interface_peek (klass, GST_TYPE_URI_HANDLER);
283 if (!iface || !iface->get_type || !iface->get_protocols)
286 factory->uri_type = iface->get_type (factory->type);
287 if (!GST_URI_TYPE_IS_VALID (factory->uri_type))
289 if (iface->get_protocols) {
290 const gchar *const *protocols;
292 protocols = iface->get_protocols (factory->type);
293 factory->uri_protocols = g_strdupv ((gchar **) protocols);
295 if (!factory->uri_protocols)
299 interfaces = g_type_interfaces (type, &n_interfaces);
300 for (i = 0; i < n_interfaces; i++) {
301 __gst_element_factory_add_interface (factory, g_type_name (interfaces[i]));
305 if (plugin && plugin->desc.name) {
306 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name;
307 GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
308 g_object_add_weak_pointer ((GObject *) plugin,
309 (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
311 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
312 GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
314 gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank);
315 GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;
317 gst_registry_add_feature (registry, GST_PLUGIN_FEATURE_CAST (factory));
324 GST_WARNING_OBJECT (factory, "error with uri handler!");
325 gst_element_factory_cleanup (factory);
331 gst_element_factory_cleanup (factory);
337 * gst_element_type_set_skip_documentation:
338 * @type: a #GType of element
340 * Marks @type as "documentation should be skipped".
341 * Can be useful for dynamically registered element to be excluded from
342 * plugin documentation system.
347 * GTypeInfo my_type_info;
349 * // Fill "my_type_info"
352 * my_type = g_type_register_static (GST_TYPE_MY_ELEMENT, "my-type-name",
354 * gst_element_type_set_skip_documentation (my_type);
355 * gst_element_register (plugin, "my-plugin-feature-name", rank, my_type);
361 gst_element_type_set_skip_documentation (GType type)
363 g_return_if_fail (g_type_is_a (type, GST_TYPE_ELEMENT));
365 g_type_set_qdata (type, __gst_elementclass_skip_doc, GINT_TO_POINTER (1));
369 * gst_element_factory_get_skip_documentation:
370 * @factory: a #GstElementFactory to query documentation skip
372 * Queries whether registered element managed by @factory needs to
373 * be excluded from documentation system or not.
375 * Returns: %TRUE if documentation should be skipped
380 gst_element_factory_get_skip_documentation (GstElementFactory * factory)
382 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), TRUE);
384 if (g_type_get_qdata (factory->type, __gst_elementclass_skip_doc))
391 gst_element_factory_property_valist_to_array (const gchar * first,
392 va_list properties, GType object_type, guint * n, const gchar ** names[],
398 guint n_params_alloc = 16;
399 GValue *values_array;
400 const gchar **names_array;
405 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), FALSE);
407 class = g_type_class_ref (object_type);
412 names_array = g_new0 (const gchar *, n_params_alloc);
413 values_array = g_new0 (GValue, n_params_alloc);
419 pspec = g_object_class_find_property (class, name);
423 if (G_UNLIKELY (n_params == n_params_alloc)) {
424 n_params_alloc *= 2u;
426 g_realloc (names_array, sizeof (const gchar *) * n_params_alloc);
427 values_array = g_realloc (values_array, sizeof (GValue) * n_params_alloc);
428 memset (&values_array[n_params], 0,
429 sizeof (GValue) * (n_params_alloc - n_params));
432 names_array[n_params] = name;
434 G_VALUE_COLLECT_INIT (&values_array[n_params], pspec->value_type,
435 properties, 0, &error);
438 g_critical ("%s", error);
444 name = va_arg (properties, const gchar *);
448 *names = names_array;
449 *values = values_array;
450 g_type_class_unref (class);
454 g_free (names_array);
455 g_free (values_array);
456 g_type_class_unref (class);
461 * gst_element_factory_create_with_properties:
462 * @factory: factory to instantiate
463 * @n: count of properties
464 * @names: (nullable) (array length=n): array of properties names
465 * @values: (nullable) (array length=n): array of associated properties values
467 * Create a new element of the type defined by the given elementfactory.
468 * The supplied list of properties, will be passed at object construction.
470 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
471 * if the element couldn't be created
476 gst_element_factory_create_with_properties (GstElementFactory * factory,
477 guint n, const gchar * names[], const GValue values[])
480 GstElementClass *oclass;
481 GstElementFactory *newfactory;
483 g_return_val_if_fail (factory != NULL, NULL);
486 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
489 if (newfactory == NULL)
492 factory = newfactory;
494 GST_INFO ("creating element \"%s\"", GST_OBJECT_NAME (factory));
496 if (factory->type == G_TYPE_INVALID)
499 element = (GstElement *) g_object_new_with_properties (factory->type, n,
501 if (G_UNLIKELY (!element)) {
502 gst_object_unref (factory);
503 g_return_val_if_fail (element != NULL, NULL);
506 /* fill in the pointer to the factory in the element class. The
507 * class will not be unreffed currently.
508 * Be thread safe as there might be 2 threads creating the first instance of
509 * an element at the same moment
511 oclass = GST_ELEMENT_GET_CLASS (element);
512 if (!g_atomic_pointer_compare_and_exchange (&oclass->elementfactory,
513 (GstElementFactory *) NULL, factory))
514 gst_object_unref (factory);
516 /* This ref will never be dropped as the class is never destroyed */
517 GST_OBJECT_FLAG_SET (factory, GST_OBJECT_FLAG_MAY_BE_LEAKED);
519 if (!g_object_is_floating ((GObject *) element)) {
520 /* The reference we receive here should be floating, but we can't force
521 * it at our level. Simply raise a critical to make the issue obvious to bindings
522 * users / developers */
523 g_critical ("The created element should be floating, "
524 "this is probably caused by faulty bindings");
528 GST_DEBUG ("created element \"%s\"", GST_OBJECT_NAME (factory));
535 GST_WARNING_OBJECT (factory, "loading plugin returned NULL!");
540 GST_WARNING_OBJECT (factory, "factory has no type");
541 gst_object_unref (factory);
547 * gst_element_factory_create_valist:
548 * @factory: factory to instantiate
549 * @first: (nullable): name of the first property
550 * @properties: (nullable): list of properties
552 * Create a new element of the type defined by the given elementfactory.
553 * The supplied list of properties, will be passed at object construction.
555 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
556 * if the element couldn't be created
561 gst_element_factory_create_valist (GstElementFactory * factory,
562 const gchar * first, va_list properties)
564 GstElementFactory *newfactory;
566 const gchar **names = NULL;
567 GValue *values = NULL;
570 g_return_val_if_fail (factory != NULL, NULL);
573 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
576 if (newfactory == NULL)
579 factory = newfactory;
581 if (factory->type == G_TYPE_INVALID)
586 gst_element_factory_create_with_properties (factory, 0, NULL, NULL);
590 if (!gst_element_factory_property_valist_to_array (first, properties,
591 factory->type, &n, &names, &values)) {
592 GST_ERROR_OBJECT (factory, "property parsing failed");
597 element = gst_element_factory_create_with_properties (factory, n, names,
602 g_value_unset (&values[n]);
606 gst_object_unref (factory);
612 GST_WARNING_OBJECT (factory, "loading plugin returned NULL!");
617 GST_WARNING_OBJECT (factory, "factory has no type");
618 gst_object_unref (factory);
624 * gst_element_factory_create_full:
625 * @factory: factory to instantiate
626 * @first: (nullable): name of the first property
627 * @...: (nullable): %NULL terminated list of properties
629 * Create a new element of the type defined by the given elementfactory.
630 * The supplied list of properties, will be passed at object construction.
632 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
633 * if the element couldn't be created
638 gst_element_factory_create_full (GstElementFactory * factory,
639 const gchar * first, ...)
644 va_start (properties, first);
645 element = gst_element_factory_create_valist (factory, first, properties);
652 * gst_element_factory_create:
653 * @factory: factory to instantiate
654 * @name: (nullable): name of new element, or %NULL to automatically create
657 * Create a new element of the type defined by the given elementfactory.
658 * It will be given the name supplied, since all elements require a name as
659 * their first argument.
661 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
662 * if the element couldn't be created
665 gst_element_factory_create (GstElementFactory * factory, const gchar * name)
668 return gst_element_factory_create_full (factory, "name", name, NULL);
670 return gst_element_factory_create_with_properties (factory, 0, NULL, NULL);
674 * gst_element_factory_make_with_properties:
675 * @factoryname: a named factory to instantiate
676 * @n: count of properties
677 * @names: (nullable) (array length=n): array of properties names
678 * @values: (nullable) (array length=n): array of associated properties values
680 * Create a new element of the type defined by the given elementfactory.
681 * The supplied list of properties, will be passed at object construction.
683 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
684 * if the element couldn't be created
689 gst_element_factory_make_with_properties (const gchar * factoryname,
690 guint n, const gchar * names[], const GValue values[])
692 GstElementFactory *factory;
695 g_return_val_if_fail (factoryname != NULL, NULL);
696 g_return_val_if_fail (gst_is_initialized (), NULL);
698 GST_LOG ("gstelementfactory: make \"%s\"", factoryname);
700 factory = gst_element_factory_find (factoryname);
704 GST_LOG_OBJECT (factory, "found factory %p", factory);
705 element = gst_element_factory_create_with_properties (factory, n, names,
710 gst_object_unref (factory);
717 GST_WARNING ("no such element factory \"%s\"!", factoryname);
722 GST_INFO_OBJECT (factory, "couldn't create instance!");
723 gst_object_unref (factory);
729 * gst_element_factory_make_valist:
730 * @factoryname: a named factory to instantiate
731 * @first: (nullable): name of first property
732 * @properties: (nullable): list of properties
734 * Create a new element of the type defined by the given element factory.
735 * The supplied list of properties, will be passed at object construction.
737 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
738 * if unable to create element
743 gst_element_factory_make_valist (const gchar * factoryname,
744 const gchar * first, va_list properties)
746 GstElementFactory *factory;
749 g_return_val_if_fail (factoryname != NULL, NULL);
750 g_return_val_if_fail (gst_is_initialized (), NULL);
752 GST_LOG ("gstelementfactory: make \"%s\"", factoryname);
754 factory = gst_element_factory_find (factoryname);
758 GST_LOG_OBJECT (factory, "found factory %p", factory);
759 element = gst_element_factory_create_valist (factory, first, properties);
763 gst_object_unref (factory);
770 GST_WARNING ("no such element factory \"%s\"!", factoryname);
775 GST_INFO_OBJECT (factory, "couldn't create instance!");
776 gst_object_unref (factory);
782 * gst_element_factory_make_full:
783 * @factoryname: a named factory to instantiate
784 * @first: (nullable): name of first property
785 * @...: (nullable): %NULL terminated list of properties
787 * Create a new element of the type defined by the given element factory.
788 * The supplied list of properties, will be passed at object construction.
790 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
791 * if unable to create element
796 gst_element_factory_make_full (const gchar * factoryname,
797 const gchar * first, ...)
802 va_start (properties, first);
804 element = gst_element_factory_make_valist (factoryname, first, properties);
811 * gst_element_factory_make:
812 * @factoryname: a named factory to instantiate
813 * @name: (nullable): name of new element, or %NULL to automatically create
816 * Create a new element of the type defined by the given element factory.
817 * If name is %NULL, then the element will receive a guaranteed unique name,
818 * consisting of the element factory name and a number.
819 * If name is given, it will be given the name supplied.
821 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
822 * if unable to create element
825 gst_element_factory_make (const gchar * factoryname, const gchar * name)
828 return gst_element_factory_make_full (factoryname, "name", name, NULL);
830 return gst_element_factory_make_with_properties (factoryname, 0, NULL,
835 __gst_element_factory_add_static_pad_template (GstElementFactory * factory,
836 GstStaticPadTemplate * templ)
838 g_return_if_fail (factory != NULL);
839 g_return_if_fail (templ != NULL);
841 factory->staticpadtemplates =
842 g_list_append (factory->staticpadtemplates, templ);
843 factory->numpadtemplates++;
847 * gst_element_factory_get_element_type:
848 * @factory: factory to get managed #GType from
850 * Get the #GType for elements managed by this factory. The type can
851 * only be retrieved if the element factory is loaded, which can be
852 * assured with gst_plugin_feature_load().
854 * Returns: the #GType for elements managed by this factory or 0 if
855 * the factory is not loaded.
858 gst_element_factory_get_element_type (GstElementFactory * factory)
860 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), 0);
862 return factory->type;
866 * gst_element_factory_get_metadata:
867 * @factory: a #GstElementFactory
870 * Get the metadata on @factory with @key.
872 * Returns: (nullable): the metadata with @key on @factory or %NULL
873 * when there was no metadata with the given @key.
876 gst_element_factory_get_metadata (GstElementFactory * factory,
879 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
881 return gst_structure_get_string ((GstStructure *) factory->metadata, key);
885 * gst_element_factory_get_metadata_keys:
886 * @factory: a #GstElementFactory
888 * Get the available keys for the metadata on @factory.
890 * Returns: (transfer full) (element-type utf8) (array zero-terminated=1) (nullable):
891 * a %NULL-terminated array of key strings, or %NULL when there is no
892 * metadata. Free with g_strfreev() when no longer needed.
895 gst_element_factory_get_metadata_keys (GstElementFactory * factory)
897 GstStructure *metadata;
901 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
903 metadata = (GstStructure *) factory->metadata;
904 if (metadata == NULL)
907 num = gst_structure_n_fields (metadata);
911 arr = g_new (gchar *, num + 1);
912 for (i = 0; i < num; ++i) {
913 arr[i] = g_strdup (gst_structure_nth_field_name (metadata, i));
920 * gst_element_factory_get_num_pad_templates:
921 * @factory: a #GstElementFactory
923 * Gets the number of pad_templates in this factory.
925 * Returns: the number of pad_templates
928 gst_element_factory_get_num_pad_templates (GstElementFactory * factory)
930 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), 0);
932 return factory->numpadtemplates;
936 * __gst_element_factory_add_interface:
937 * @elementfactory: The elementfactory to add the interface to
938 * @interfacename: Name of the interface
940 * Adds the given interfacename to the list of implemented interfaces of the
944 __gst_element_factory_add_interface (GstElementFactory * elementfactory,
945 const gchar * interfacename)
947 g_return_if_fail (GST_IS_ELEMENT_FACTORY (elementfactory));
948 g_return_if_fail (interfacename != NULL);
949 g_return_if_fail (interfacename[0] != '\0'); /* no empty string */
951 elementfactory->interfaces =
952 g_list_prepend (elementfactory->interfaces,
953 (gpointer) g_intern_string (interfacename));
957 * gst_element_factory_get_static_pad_templates:
958 * @factory: a #GstElementFactory
960 * Gets the #GList of #GstStaticPadTemplate for this factory.
962 * Returns: (transfer none) (element-type Gst.StaticPadTemplate): the
963 * static pad templates
966 gst_element_factory_get_static_pad_templates (GstElementFactory * factory)
968 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
970 return factory->staticpadtemplates;
974 * gst_element_factory_get_uri_type:
975 * @factory: a #GstElementFactory
977 * Gets the type of URIs the element supports or #GST_URI_UNKNOWN if none.
979 * Returns: type of URIs this element supports
982 gst_element_factory_get_uri_type (GstElementFactory * factory)
984 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), GST_URI_UNKNOWN);
986 return factory->uri_type;
990 * gst_element_factory_get_uri_protocols:
991 * @factory: a #GstElementFactory
993 * Gets a %NULL-terminated array of protocols this element supports or %NULL if
994 * no protocols are supported. You may not change the contents of the returned
995 * array, as it is still owned by the element factory. Use g_strdupv() to
996 * make a copy of the protocol string array if you need to.
998 * Returns: (transfer none) (array zero-terminated=1): the supported protocols
1001 const gchar *const *
1002 gst_element_factory_get_uri_protocols (GstElementFactory * factory)
1004 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
1006 return (const gchar * const *) factory->uri_protocols;
1010 * gst_element_factory_has_interface:
1011 * @factory: a #GstElementFactory
1012 * @interfacename: an interface name
1014 * Check if @factory implements the interface with name @interfacename.
1016 * Returns: %TRUE when @factory implement the interface.
1019 gst_element_factory_has_interface (GstElementFactory * factory,
1020 const gchar * interfacename)
1024 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), FALSE);
1026 for (walk = factory->interfaces; walk; walk = g_list_next (walk)) {
1027 gchar *iname = (gchar *) walk->data;
1029 if (!strcmp (iname, interfacename))
1038 GstElementFactoryListType type;
1044 * gst_element_factory_list_is_type:
1045 * @factory: a #GstElementFactory
1046 * @type: a #GstElementFactoryListType
1048 * Check if @factory is of the given types.
1050 * Returns: %TRUE if @factory is of @type.
1053 gst_element_factory_list_is_type (GstElementFactory * factory,
1054 GstElementFactoryListType type)
1056 gboolean res = FALSE;
1060 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1062 if (klass == NULL) {
1063 GST_ERROR_OBJECT (factory, "element factory is missing klass identifiers");
1067 /* Filter by element type first, as soon as it matches
1068 * one type, we skip all other tests */
1069 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_SINK))
1070 res = (strstr (klass, "Sink") != NULL);
1072 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_SRC))
1073 res = (strstr (klass, "Source") != NULL);
1075 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DECODER))
1076 res = (strstr (klass, "Decoder") != NULL);
1078 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_ENCODER))
1079 res = (strstr (klass, "Encoder") != NULL);
1081 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_MUXER))
1082 res = (strstr (klass, "Muxer") != NULL);
1084 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DEMUXER))
1085 res = (strstr (klass, "Demux") != NULL);
1087 /* FIXME : We're actually parsing two Classes here... */
1088 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_PARSER))
1089 res = ((strstr (klass, "Parser") != NULL)
1090 && (strstr (klass, "Codec") != NULL));
1092 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER))
1093 res = (strstr (klass, "Depayloader") != NULL);
1095 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_PAYLOADER))
1096 res = (strstr (klass, "Payloader") != NULL);
1098 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_FORMATTER))
1099 res = (strstr (klass, "Formatter") != NULL);
1101 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DECRYPTOR))
1102 res = (strstr (klass, "Decryptor") != NULL);
1104 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_ENCRYPTOR))
1105 res = (strstr (klass, "Encryptor") != NULL);
1107 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_HARDWARE))
1108 res = (strstr (klass, "Hardware") != NULL);
1110 /* Filter by media type now, we only test if it
1111 * matched any of the types above or only checking the media
1112 * type was requested. */
1113 if ((res || !(type & (GST_ELEMENT_FACTORY_TYPE_MAX_ELEMENTS - 1)))
1114 && (type & (GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO |
1115 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
1116 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE |
1117 GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE |
1118 GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)))
1119 res = ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)
1120 && (strstr (klass, "Audio") != NULL))
1121 || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO)
1122 && (strstr (klass, "Video") != NULL))
1123 || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)
1124 && (strstr (klass, "Image") != NULL)) ||
1125 ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE)
1126 && (strstr (klass, "Subtitle") != NULL)) ||
1127 ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)
1128 && (strstr (klass, "Metadata") != NULL));
1134 element_filter (GstPluginFeature * feature, FilterData * data)
1138 /* we only care about element factories */
1139 if (G_UNLIKELY (!GST_IS_ELEMENT_FACTORY (feature)))
1142 res = (gst_plugin_feature_get_rank (feature) >= data->minrank) &&
1143 gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (feature),
1150 * gst_element_factory_list_get_elements:
1151 * @type: a #GstElementFactoryListType
1152 * @minrank: Minimum rank
1154 * Get a list of factories that match the given @type. Only elements
1155 * with a rank greater or equal to @minrank will be returned.
1156 * The list of factories is returned by decreasing rank.
1158 * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
1159 * #GstElementFactory elements. Use gst_plugin_feature_list_free() after
1163 gst_element_factory_list_get_elements (GstElementFactoryListType type,
1171 data.minrank = minrank;
1173 /* get the feature list using the filter */
1174 result = gst_registry_feature_filter (gst_registry_get (),
1175 (GstPluginFeatureFilter) element_filter, FALSE, &data);
1177 /* sort on rank and name */
1178 result = g_list_sort (result, gst_plugin_feature_rank_compare_func);
1184 * gst_element_factory_list_filter:
1185 * @list: (transfer none) (element-type Gst.ElementFactory): a #GList of
1186 * #GstElementFactory to filter
1188 * @direction: a #GstPadDirection to filter on
1189 * @subsetonly: whether to filter on caps subsets or not.
1191 * Filter out all the elementfactories in @list that can handle @caps in
1192 * the given direction.
1194 * If @subsetonly is %TRUE, then only the elements whose pads templates
1195 * are a complete superset of @caps will be returned. Else any element
1196 * whose pad templates caps can intersect with @caps will be returned.
1198 * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
1199 * #GstElementFactory elements that match the given requisites.
1200 * Use #gst_plugin_feature_list_free after usage.
1203 gst_element_factory_list_filter (GList * list,
1204 const GstCaps * caps, GstPadDirection direction, gboolean subsetonly)
1206 GQueue results = G_QUEUE_INIT;
1208 GST_DEBUG ("finding factories");
1210 /* loop over all the factories */
1211 for (; list; list = list->next) {
1212 GstElementFactory *factory;
1213 const GList *templates;
1216 factory = (GstElementFactory *) list->data;
1218 GST_DEBUG ("Trying %s",
1219 gst_plugin_feature_get_name ((GstPluginFeature *) factory));
1221 /* get the templates from the element factory */
1222 templates = gst_element_factory_get_static_pad_templates (factory);
1223 for (walk = (GList *) templates; walk; walk = g_list_next (walk)) {
1224 GstStaticPadTemplate *templ = walk->data;
1226 /* we only care about the sink templates */
1227 if (templ->direction == direction) {
1230 /* try to intersect the caps with the caps of the template */
1231 tmpl_caps = gst_static_caps_get (&templ->static_caps);
1233 /* FIXME, intersect is not the right method, we ideally want to check
1234 * for a subset here */
1236 /* check if the intersection is empty */
1237 if ((subsetonly && gst_caps_is_subset (caps, tmpl_caps)) ||
1238 (!subsetonly && gst_caps_can_intersect (caps, tmpl_caps))) {
1239 /* non empty intersection, we can use this element */
1240 g_queue_push_tail (&results, gst_object_ref (factory));
1241 gst_caps_unref (tmpl_caps);
1244 gst_caps_unref (tmpl_caps);
1248 return results.head;
1251 #ifdef TIZEN_PROFILE_TV
1253 * gst_element_factory_pool_push:
1255 * Pushes the element to the pool. This function increase the refcount of @element.
1256 * And the pool will take a reference forever.
1260 gst_element_factory_pool_push (GstElement * element)
1262 gboolean ret = FALSE;
1263 g_return_val_if_fail (element != NULL, FALSE);
1264 g_return_val_if_fail (GST_IS_ELEMENT (element) == TRUE, FALSE);
1265 g_return_val_if_fail (GST_IS_BIN (element) == FALSE, FALSE);
1266 g_return_val_if_fail (GST_IS_PIPELINE (element) == FALSE, FALSE);
1268 g_mutex_lock (&pool_mutex);
1269 if (!g_list_find (pool, (gconstpointer) element)) {
1270 gst_object_ref (element);
1271 pool = g_list_prepend (pool, element);
1274 //GST_INFO("ret[ %d ], [ %s / %p ] - refcount[ %d ], state[ %d ]", ret, GST_ELEMENT_NAME(element), element, GST_OBJECT_REFCOUNT(element), GST_STATE (element));
1275 g_mutex_unlock (&pool_mutex);
1280 is_available_element (gconstpointer data, gconstpointer factory_)
1282 GstElement *element = GST_ELEMENT_CAST (data);
1283 const GstElementFactory *factory = (const GstElementFactory *) factory_;
1284 gboolean found = FALSE;
1285 if (gst_element_get_factory (element) == factory
1286 && GST_ELEMENT_PARENT (element) == NULL
1287 && GST_OBJECT_REFCOUNT (element) == 1
1288 && (GST_STATE (element) == GST_STATE_NULL
1289 || GST_STATE (element) == GST_STATE_VOID_PENDING)) {
1292 //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));
1301 * gst_element_factory_pool_get:
1303 * Get a element which is created by given @factoryname
1304 * You can search any element by this API before you use gst_element_factory_create.
1305 * Returns: (transfer full): a pointer to the #GstElement.
1306 * This function guarantee that the refcount of returned #GstElement is 1,
1307 * and it's state is NULL-STATE.
1312 gst_element_factory_pool_get (GstElementFactory * factory,
1313 const gchar * new_element_name)
1315 GstElement *element = NULL;
1316 GList *found = NULL;
1317 g_return_val_if_fail (factory != NULL, NULL);
1318 g_return_val_if_fail (pool != NULL, NULL);
1320 g_mutex_lock (&pool_mutex);
1321 found = g_list_find_custom (pool, factory, is_available_element);
1323 element = GST_ELEMENT_CAST (found->data);
1324 gst_object_ref (element);
1325 if (new_element_name)
1326 gst_element_set_name (element, new_element_name);
1328 g_mutex_unlock (&pool_mutex);
1332 /* First, Try to get element from pool. */
1334 gst_element_factory_get (GstElementFactory * factory, const gchar * name)
1336 GstElement *element = NULL;
1337 g_return_val_if_fail (factory != NULL, NULL);
1338 element = gst_element_factory_pool_get (factory, name);
1340 element = gst_element_factory_create (factory, name);
1342 GST_ERROR ("[ %s / %p ], new element name[ %s ]",
1343 GST_OBJECT_NAME (factory), factory, name);
1346 gst_element_factory_pool_push (element);
1348 gst_set_family_id_to_child (element, 0);
1351 //GST_INFO("[ %s / %p ] - refcount[ %d ], state[ %d ]", GST_ELEMENT_NAME(element), element, GST_OBJECT_REFCOUNT(element), GST_STATE (element));