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);
93 gst_element_factory_class_init (GstElementFactoryClass * klass)
95 GObjectClass *gobject_class = (GObjectClass *) klass;
97 gobject_class->finalize = gst_element_factory_finalize;
101 gst_element_factory_init (GstElementFactory * factory)
103 factory->staticpadtemplates = NULL;
104 factory->numpadtemplates = 0;
106 factory->uri_type = GST_URI_UNKNOWN;
107 factory->uri_protocols = NULL;
109 factory->interfaces = NULL;
113 gst_element_factory_finalize (GObject * object)
115 GstElementFactory *factory = GST_ELEMENT_FACTORY (object);
117 gst_element_factory_cleanup (factory);
118 G_OBJECT_CLASS (gst_element_factory_parent_class)->finalize (object);
122 * gst_element_factory_find:
123 * @name: name of factory to find
125 * Search for an element factory of the given name. Refs the returned
126 * element factory; caller is responsible for unreffing.
128 * Returns: (transfer full) (nullable): #GstElementFactory if found,
132 gst_element_factory_find (const gchar * name)
134 GstPluginFeature *feature;
136 g_return_val_if_fail (name != NULL, NULL);
138 feature = gst_registry_find_feature (gst_registry_get (), name,
139 GST_TYPE_ELEMENT_FACTORY);
141 return GST_ELEMENT_FACTORY (feature);
143 /* this isn't an error, for instance when you query if an element factory is
145 GST_LOG ("no such element factory \"%s\"", name);
150 gst_element_factory_cleanup (GstElementFactory * factory)
154 if (factory->metadata) {
155 gst_structure_free ((GstStructure *) factory->metadata);
156 factory->metadata = NULL;
159 factory->type = G_TYPE_INVALID;
162 for (item = factory->staticpadtemplates; item; item = item->next) {
163 GstStaticPadTemplate *templ = item->data;
165 gst_static_caps_cleanup (&templ->static_caps);
166 g_slice_free (GstStaticPadTemplate, templ);
168 g_list_free (factory->staticpadtemplates);
169 factory->staticpadtemplates = NULL;
170 factory->numpadtemplates = 0;
171 factory->uri_type = GST_URI_UNKNOWN;
172 if (factory->uri_protocols) {
173 g_strfreev (factory->uri_protocols);
174 factory->uri_protocols = NULL;
177 g_list_free (factory->interfaces);
178 factory->interfaces = NULL;
181 #define CHECK_METADATA_FIELD(klass, name, key) \
183 const gchar *metafield = gst_element_class_get_metadata (klass, key); \
184 if (G_UNLIKELY (metafield == NULL || *metafield == '\0')) { \
185 g_warning ("Element factory metadata for '%s' has no valid %s field", name, key); \
191 * gst_element_register:
192 * @plugin: (allow-none): #GstPlugin to register the element with, or %NULL for
194 * @name: name of elements of this type
195 * @rank: rank of element (higher rank means more importance when autoplugging)
196 * @type: GType of element to register
198 * Create a new elementfactory capable of instantiating objects of the
199 * @type and add the factory to @plugin.
201 * Returns: %TRUE, if the registering succeeded, %FALSE on error
204 gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
207 GstPluginFeature *existing_feature;
208 GstRegistry *registry;
209 GstElementFactory *factory;
211 guint n_interfaces, i;
212 GstElementClass *klass;
215 g_return_val_if_fail (name != NULL, FALSE);
216 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_ELEMENT), FALSE);
218 registry = gst_registry_get ();
220 /* check if feature already exists, if it exists there is no need to update it
221 * when the registry is getting updated, outdated plugins and all their
222 * features are removed and readded.
224 existing_feature = gst_registry_lookup_feature (registry, name);
225 if (existing_feature && existing_feature->plugin == plugin) {
226 GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)",
227 existing_feature, name);
228 factory = GST_ELEMENT_FACTORY_CAST (existing_feature);
229 factory->type = type;
230 existing_feature->loaded = TRUE;
231 g_type_set_qdata (type, __gst_elementclass_factory, factory);
232 gst_object_unref (existing_feature);
234 } else if (existing_feature) {
235 gst_object_unref (existing_feature);
238 factory = g_object_new (GST_TYPE_ELEMENT_FACTORY, NULL);
239 gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
240 GST_LOG_OBJECT (factory, "Created new elementfactory for type %s",
243 /* provide info needed during class structure setup */
244 g_type_set_qdata (type, __gst_elementclass_factory, factory);
245 klass = GST_ELEMENT_CLASS (g_type_class_ref (type));
247 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_LONGNAME);
248 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_KLASS);
249 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_DESCRIPTION);
250 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_AUTHOR);
252 factory->type = type;
253 factory->metadata = gst_structure_copy ((GstStructure *) klass->metadata);
255 for (item = klass->padtemplates; item; item = item->next) {
256 GstPadTemplate *templ = item->data;
257 GstStaticPadTemplate *newt;
258 gchar *caps_string = gst_caps_to_string (templ->caps);
260 newt = g_slice_new (GstStaticPadTemplate);
261 newt->name_template = g_intern_string (templ->name_template);
262 newt->direction = templ->direction;
263 newt->presence = templ->presence;
264 newt->static_caps.caps = NULL;
265 newt->static_caps.string = g_intern_string (caps_string);
266 factory->staticpadtemplates =
267 g_list_append (factory->staticpadtemplates, newt);
269 g_free (caps_string);
271 factory->numpadtemplates = klass->numpadtemplates;
273 /* special stuff for URI handling */
274 if (g_type_is_a (type, GST_TYPE_URI_HANDLER)) {
275 GstURIHandlerInterface *iface = (GstURIHandlerInterface *)
276 g_type_interface_peek (klass, GST_TYPE_URI_HANDLER);
278 if (!iface || !iface->get_type || !iface->get_protocols)
281 factory->uri_type = iface->get_type (factory->type);
282 if (!GST_URI_TYPE_IS_VALID (factory->uri_type))
284 if (iface->get_protocols) {
285 const gchar *const *protocols;
287 protocols = iface->get_protocols (factory->type);
288 factory->uri_protocols = g_strdupv ((gchar **) protocols);
290 if (!factory->uri_protocols)
294 interfaces = g_type_interfaces (type, &n_interfaces);
295 for (i = 0; i < n_interfaces; i++) {
296 __gst_element_factory_add_interface (factory, g_type_name (interfaces[i]));
300 if (plugin && plugin->desc.name) {
301 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name;
302 GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
303 g_object_add_weak_pointer ((GObject *) plugin,
304 (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
306 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
307 GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
309 gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank);
310 GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;
312 gst_registry_add_feature (registry, GST_PLUGIN_FEATURE_CAST (factory));
319 GST_WARNING_OBJECT (factory, "error with uri handler!");
320 gst_element_factory_cleanup (factory);
326 gst_element_factory_cleanup (factory);
332 * gst_element_type_set_skip_documentation:
333 * @type: a #GType of element
335 * Marks @type as "documentation should be skipped".
336 * Can be useful for dynamically registered element to be excluded from
337 * plugin documentation system.
342 * GTypeInfo my_type_info;
344 * // Fill "my_type_info"
347 * my_type = g_type_register_static (GST_TYPE_MY_ELEMENT, "my-type-name",
349 * gst_element_type_set_skip_documentation (my_type);
350 * gst_element_register (plugin, "my-plugin-feature-name", rank, my_type);
356 gst_element_type_set_skip_documentation (GType type)
358 g_return_if_fail (g_type_is_a (type, GST_TYPE_ELEMENT));
360 g_type_set_qdata (type, __gst_elementclass_skip_doc, GINT_TO_POINTER (1));
364 * gst_element_factory_get_skip_documentation:
365 * @factory: a #GstElementFactory to query documentation skip
367 * Queries whether registered element managed by @factory needs to
368 * be excluded from documentation system or not.
370 * Returns: %TRUE if documentation should be skipped
375 gst_element_factory_get_skip_documentation (GstElementFactory * factory)
377 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), TRUE);
379 if (g_type_get_qdata (factory->type, __gst_elementclass_skip_doc))
386 gst_element_factory_property_valist_to_array (const gchar * first,
387 va_list properties, GType object_type, guint * n, const gchar ** names[],
393 guint n_params_alloc = 16;
394 GValue *values_array;
395 const gchar **names_array;
400 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), FALSE);
402 class = g_type_class_ref (object_type);
407 names_array = g_new0 (const gchar *, n_params_alloc);
408 values_array = g_new0 (GValue, n_params_alloc);
414 pspec = g_object_class_find_property (class, name);
418 if (G_UNLIKELY (n_params == n_params_alloc)) {
419 n_params_alloc *= 2u;
421 g_realloc (names_array, sizeof (const gchar *) * n_params_alloc);
422 values_array = g_realloc (values_array, sizeof (GValue) * n_params_alloc);
423 memset (&values_array[n_params], 0,
424 sizeof (GValue) * (n_params_alloc - n_params));
427 names_array[n_params] = name;
429 G_VALUE_COLLECT_INIT (&values_array[n_params], pspec->value_type,
430 properties, 0, &error);
433 g_critical ("%s", error);
439 name = va_arg (properties, const gchar *);
443 *names = names_array;
444 *values = values_array;
445 g_type_class_unref (class);
449 g_free (names_array);
450 g_free (values_array);
451 g_type_class_unref (class);
456 * gst_element_factory_create_with_properties:
457 * @factory: factory to instantiate
458 * @n: count of properties
459 * @names: (nullable) (array length=n): array of properties names
460 * @values: (nullable) (array length=n): array of associated properties values
462 * Create a new element of the type defined by the given elementfactory.
463 * The supplied list of properties, will be passed at object construction.
465 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
466 * if the element couldn't be created
471 gst_element_factory_create_with_properties (GstElementFactory * factory,
472 guint n, const gchar * names[], const GValue values[])
475 GstElementClass *oclass;
476 GstElementFactory *newfactory;
478 g_return_val_if_fail (factory != NULL, NULL);
481 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
484 if (newfactory == NULL)
487 factory = newfactory;
489 GST_INFO ("creating element \"%s\"", GST_OBJECT_NAME (factory));
491 if (factory->type == 0)
494 element = (GstElement *) g_object_new_with_properties (factory->type, n,
497 if (G_UNLIKELY (element == NULL))
500 /* fill in the pointer to the factory in the element class. The
501 * class will not be unreffed currently.
502 * Be thread safe as there might be 2 threads creating the first instance of
503 * an element at the same moment
505 oclass = GST_ELEMENT_GET_CLASS (element);
506 if (!g_atomic_pointer_compare_and_exchange (&oclass->elementfactory,
507 (GstElementFactory *) NULL, factory))
508 gst_object_unref (factory);
510 /* This ref will never be dropped as the class is never destroyed */
511 GST_OBJECT_FLAG_SET (factory, GST_OBJECT_FLAG_MAY_BE_LEAKED);
513 if (!g_object_is_floating ((GObject *) element)) {
514 /* The reference we receive here should be floating, but we can't force
515 * it at our level. Simply raise a critical to make the issue obvious to bindings
516 * users / developers */
517 g_critical ("The created element should be floating, "
518 "this is probably caused by faulty bindings");
522 GST_DEBUG ("created element \"%s\"", GST_OBJECT_NAME (factory));
529 GST_WARNING_OBJECT (factory, "loading plugin returned NULL!");
534 GST_WARNING_OBJECT (factory, "factory has no type");
535 gst_object_unref (factory);
540 GST_WARNING_OBJECT (factory, "could not create element");
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 g_return_val_if_fail (newfactory != NULL, NULL);
577 g_return_val_if_fail (newfactory->type != 0, NULL);
579 factory = newfactory;
583 gst_element_factory_create_with_properties (factory, 0, NULL, NULL);
587 if (!gst_element_factory_property_valist_to_array (first, properties,
588 factory->type, &n, &names, &values)) {
589 GST_ERROR_OBJECT (factory, "property parsing failed");
594 element = gst_element_factory_create_with_properties (factory, n, names,
599 g_value_unset (&values[n]);
603 gst_object_unref (factory);
608 * gst_element_factory_create_full:
609 * @factory: factory to instantiate
610 * @first: (nullable): name of the first property
611 * @...: (nullable): %NULL terminated list of properties
613 * Create a new element of the type defined by the given elementfactory.
614 * The supplied list of properties, will be passed at object construction.
616 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
617 * if the element couldn't be created
622 gst_element_factory_create_full (GstElementFactory * factory,
623 const gchar * first, ...)
628 va_start (properties, first);
629 element = gst_element_factory_create_valist (factory, first, properties);
636 * gst_element_factory_create:
637 * @factory: factory to instantiate
638 * @name: (nullable): name of new element, or %NULL to automatically create
641 * Create a new element of the type defined by the given elementfactory.
642 * It will be given the name supplied, since all elements require a name as
643 * their first argument.
645 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
646 * if the element couldn't be created
649 gst_element_factory_create (GstElementFactory * factory, const gchar * name)
652 return gst_element_factory_create_full (factory, "name", name, NULL);
654 return gst_element_factory_create_with_properties (factory, 0, NULL, NULL);
658 * gst_element_factory_make_with_properties:
659 * @factoryname: a named factory to instantiate
660 * @n: count of properties
661 * @names: (nullable) (array length=n): array of properties names
662 * @values: (nullable) (array length=n): array of associated properties values
664 * Create a new element of the type defined by the given elementfactory.
665 * The supplied list of properties, will be passed at object construction.
667 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
668 * if the element couldn't be created
673 gst_element_factory_make_with_properties (const gchar * factoryname,
674 guint n, const gchar * names[], const GValue values[])
676 GstElementFactory *factory;
679 g_return_val_if_fail (factoryname != NULL, NULL);
680 g_return_val_if_fail (gst_is_initialized (), NULL);
682 GST_LOG ("gstelementfactory: make \"%s\"", factoryname);
684 factory = gst_element_factory_find (factoryname);
688 GST_LOG_OBJECT (factory, "found factory %p", factory);
689 element = gst_element_factory_create_with_properties (factory, n, names,
694 gst_object_unref (factory);
701 GST_WARNING ("no such element factory \"%s\"!", factoryname);
706 GST_INFO_OBJECT (factory, "couldn't create instance!");
707 gst_object_unref (factory);
713 * gst_element_factory_make_valist:
714 * @factoryname: a named factory to instantiate
715 * @first: (nullable): name of first property
716 * @properties: (nullable): list of properties
718 * Create a new element of the type defined by the given element factory.
719 * The supplied list of properties, will be passed at object construction.
721 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
722 * if unable to create element
727 gst_element_factory_make_valist (const gchar * factoryname,
728 const gchar * first, va_list properties)
730 GstElementFactory *factory;
733 g_return_val_if_fail (factoryname != NULL, NULL);
734 g_return_val_if_fail (gst_is_initialized (), NULL);
736 GST_LOG ("gstelementfactory: make \"%s\"", factoryname);
738 factory = gst_element_factory_find (factoryname);
742 GST_LOG_OBJECT (factory, "found factory %p", factory);
743 element = gst_element_factory_create_valist (factory, first, properties);
747 gst_object_unref (factory);
754 GST_WARNING ("no such element factory \"%s\"!", factoryname);
759 GST_INFO_OBJECT (factory, "couldn't create instance!");
760 gst_object_unref (factory);
766 * gst_element_factory_make_full:
767 * @factoryname: a named factory to instantiate
768 * @first: (nullable): name of first property
769 * @...: (nullable): %NULL terminated list of properties
771 * Create a new element of the type defined by the given element factory.
772 * The supplied list of properties, will be passed at object construction.
774 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
775 * if unable to create element
780 gst_element_factory_make_full (const gchar * factoryname,
781 const gchar * first, ...)
786 va_start (properties, first);
788 element = gst_element_factory_make_valist (factoryname, first, properties);
795 * gst_element_factory_make:
796 * @factoryname: a named factory to instantiate
797 * @name: (nullable): name of new element, or %NULL to automatically create
800 * Create a new element of the type defined by the given element factory.
801 * If name is %NULL, then the element will receive a guaranteed unique name,
802 * consisting of the element factory name and a number.
803 * If name is given, it will be given the name supplied.
805 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
806 * if unable to create element
809 gst_element_factory_make (const gchar * factoryname, const gchar * name)
812 return gst_element_factory_make_full (factoryname, "name", name, NULL);
814 return gst_element_factory_make_with_properties (factoryname, 0, NULL,
819 __gst_element_factory_add_static_pad_template (GstElementFactory * factory,
820 GstStaticPadTemplate * templ)
822 g_return_if_fail (factory != NULL);
823 g_return_if_fail (templ != NULL);
825 factory->staticpadtemplates =
826 g_list_append (factory->staticpadtemplates, templ);
827 factory->numpadtemplates++;
831 * gst_element_factory_get_element_type:
832 * @factory: factory to get managed #GType from
834 * Get the #GType for elements managed by this factory. The type can
835 * only be retrieved if the element factory is loaded, which can be
836 * assured with gst_plugin_feature_load().
838 * Returns: the #GType for elements managed by this factory or 0 if
839 * the factory is not loaded.
842 gst_element_factory_get_element_type (GstElementFactory * factory)
844 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), 0);
846 return factory->type;
850 * gst_element_factory_get_metadata:
851 * @factory: a #GstElementFactory
854 * Get the metadata on @factory with @key.
856 * Returns: (nullable): the metadata with @key on @factory or %NULL
857 * when there was no metadata with the given @key.
860 gst_element_factory_get_metadata (GstElementFactory * factory,
863 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
865 return gst_structure_get_string ((GstStructure *) factory->metadata, key);
869 * gst_element_factory_get_metadata_keys:
870 * @factory: a #GstElementFactory
872 * Get the available keys for the metadata on @factory.
874 * Returns: (transfer full) (element-type utf8) (array zero-terminated=1) (nullable):
875 * a %NULL-terminated array of key strings, or %NULL when there is no
876 * metadata. Free with g_strfreev() when no longer needed.
879 gst_element_factory_get_metadata_keys (GstElementFactory * factory)
881 GstStructure *metadata;
885 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
887 metadata = (GstStructure *) factory->metadata;
888 if (metadata == NULL)
891 num = gst_structure_n_fields (metadata);
895 arr = g_new (gchar *, num + 1);
896 for (i = 0; i < num; ++i) {
897 arr[i] = g_strdup (gst_structure_nth_field_name (metadata, i));
904 * gst_element_factory_get_num_pad_templates:
905 * @factory: a #GstElementFactory
907 * Gets the number of pad_templates in this factory.
909 * Returns: the number of pad_templates
912 gst_element_factory_get_num_pad_templates (GstElementFactory * factory)
914 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), 0);
916 return factory->numpadtemplates;
920 * __gst_element_factory_add_interface:
921 * @elementfactory: The elementfactory to add the interface to
922 * @interfacename: Name of the interface
924 * Adds the given interfacename to the list of implemented interfaces of the
928 __gst_element_factory_add_interface (GstElementFactory * elementfactory,
929 const gchar * interfacename)
931 g_return_if_fail (GST_IS_ELEMENT_FACTORY (elementfactory));
932 g_return_if_fail (interfacename != NULL);
933 g_return_if_fail (interfacename[0] != '\0'); /* no empty string */
935 elementfactory->interfaces =
936 g_list_prepend (elementfactory->interfaces,
937 (gpointer) g_intern_string (interfacename));
941 * gst_element_factory_get_static_pad_templates:
942 * @factory: a #GstElementFactory
944 * Gets the #GList of #GstStaticPadTemplate for this factory.
946 * Returns: (transfer none) (element-type Gst.StaticPadTemplate): the
947 * static pad templates
950 gst_element_factory_get_static_pad_templates (GstElementFactory * factory)
952 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
954 return factory->staticpadtemplates;
958 * gst_element_factory_get_uri_type:
959 * @factory: a #GstElementFactory
961 * Gets the type of URIs the element supports or #GST_URI_UNKNOWN if none.
963 * Returns: type of URIs this element supports
966 gst_element_factory_get_uri_type (GstElementFactory * factory)
968 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), GST_URI_UNKNOWN);
970 return factory->uri_type;
974 * gst_element_factory_get_uri_protocols:
975 * @factory: a #GstElementFactory
977 * Gets a %NULL-terminated array of protocols this element supports or %NULL if
978 * no protocols are supported. You may not change the contents of the returned
979 * array, as it is still owned by the element factory. Use g_strdupv() to
980 * make a copy of the protocol string array if you need to.
982 * Returns: (transfer none) (array zero-terminated=1): the supported protocols
986 gst_element_factory_get_uri_protocols (GstElementFactory * factory)
988 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
990 return (const gchar * const *) factory->uri_protocols;
994 * gst_element_factory_has_interface:
995 * @factory: a #GstElementFactory
996 * @interfacename: an interface name
998 * Check if @factory implements the interface with name @interfacename.
1000 * Returns: %TRUE when @factory implement the interface.
1003 gst_element_factory_has_interface (GstElementFactory * factory,
1004 const gchar * interfacename)
1008 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), FALSE);
1010 for (walk = factory->interfaces; walk; walk = g_list_next (walk)) {
1011 gchar *iname = (gchar *) walk->data;
1013 if (!strcmp (iname, interfacename))
1022 GstElementFactoryListType type;
1028 * gst_element_factory_list_is_type:
1029 * @factory: a #GstElementFactory
1030 * @type: a #GstElementFactoryListType
1032 * Check if @factory is of the given types.
1034 * Returns: %TRUE if @factory is of @type.
1037 gst_element_factory_list_is_type (GstElementFactory * factory,
1038 GstElementFactoryListType type)
1040 gboolean res = FALSE;
1044 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1046 if (klass == NULL) {
1047 GST_ERROR_OBJECT (factory, "element factory is missing klass identifiers");
1051 /* Filter by element type first, as soon as it matches
1052 * one type, we skip all other tests */
1053 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_SINK))
1054 res = (strstr (klass, "Sink") != NULL);
1056 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_SRC))
1057 res = (strstr (klass, "Source") != NULL);
1059 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DECODER))
1060 res = (strstr (klass, "Decoder") != NULL);
1062 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_ENCODER))
1063 res = (strstr (klass, "Encoder") != NULL);
1065 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_MUXER))
1066 res = (strstr (klass, "Muxer") != NULL);
1068 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DEMUXER))
1069 res = (strstr (klass, "Demux") != NULL);
1071 /* FIXME : We're actually parsing two Classes here... */
1072 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_PARSER))
1073 res = ((strstr (klass, "Parser") != NULL)
1074 && (strstr (klass, "Codec") != NULL));
1076 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER))
1077 res = (strstr (klass, "Depayloader") != NULL);
1079 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_PAYLOADER))
1080 res = (strstr (klass, "Payloader") != NULL);
1082 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_FORMATTER))
1083 res = (strstr (klass, "Formatter") != NULL);
1085 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DECRYPTOR))
1086 res = (strstr (klass, "Decryptor") != NULL);
1088 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_ENCRYPTOR))
1089 res = (strstr (klass, "Encryptor") != NULL);
1091 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_HARDWARE))
1092 res = (strstr (klass, "Hardware") != NULL);
1094 /* Filter by media type now, we only test if it
1095 * matched any of the types above or only checking the media
1096 * type was requested. */
1097 if ((res || !(type & (GST_ELEMENT_FACTORY_TYPE_MAX_ELEMENTS - 1)))
1098 && (type & (GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO |
1099 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
1100 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE |
1101 GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE |
1102 GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)))
1103 res = ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)
1104 && (strstr (klass, "Audio") != NULL))
1105 || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO)
1106 && (strstr (klass, "Video") != NULL))
1107 || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)
1108 && (strstr (klass, "Image") != NULL)) ||
1109 ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE)
1110 && (strstr (klass, "Subtitle") != NULL)) ||
1111 ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)
1112 && (strstr (klass, "Metadata") != NULL));
1118 element_filter (GstPluginFeature * feature, FilterData * data)
1122 /* we only care about element factories */
1123 if (G_UNLIKELY (!GST_IS_ELEMENT_FACTORY (feature)))
1126 res = (gst_plugin_feature_get_rank (feature) >= data->minrank) &&
1127 gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (feature),
1134 * gst_element_factory_list_get_elements:
1135 * @type: a #GstElementFactoryListType
1136 * @minrank: Minimum rank
1138 * Get a list of factories that match the given @type. Only elements
1139 * with a rank greater or equal to @minrank will be returned.
1140 * The list of factories is returned by decreasing rank.
1142 * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
1143 * #GstElementFactory elements. Use gst_plugin_feature_list_free() after
1147 gst_element_factory_list_get_elements (GstElementFactoryListType type,
1155 data.minrank = minrank;
1157 /* get the feature list using the filter */
1158 result = gst_registry_feature_filter (gst_registry_get (),
1159 (GstPluginFeatureFilter) element_filter, FALSE, &data);
1161 /* sort on rank and name */
1162 result = g_list_sort (result, gst_plugin_feature_rank_compare_func);
1168 * gst_element_factory_list_filter:
1169 * @list: (transfer none) (element-type Gst.ElementFactory): a #GList of
1170 * #GstElementFactory to filter
1172 * @direction: a #GstPadDirection to filter on
1173 * @subsetonly: whether to filter on caps subsets or not.
1175 * Filter out all the elementfactories in @list that can handle @caps in
1176 * the given direction.
1178 * If @subsetonly is %TRUE, then only the elements whose pads templates
1179 * are a complete superset of @caps will be returned. Else any element
1180 * whose pad templates caps can intersect with @caps will be returned.
1182 * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
1183 * #GstElementFactory elements that match the given requisites.
1184 * Use #gst_plugin_feature_list_free after usage.
1187 gst_element_factory_list_filter (GList * list,
1188 const GstCaps * caps, GstPadDirection direction, gboolean subsetonly)
1190 GQueue results = G_QUEUE_INIT;
1192 GST_DEBUG ("finding factories");
1194 /* loop over all the factories */
1195 for (; list; list = list->next) {
1196 GstElementFactory *factory;
1197 const GList *templates;
1200 factory = (GstElementFactory *) list->data;
1202 GST_DEBUG ("Trying %s",
1203 gst_plugin_feature_get_name ((GstPluginFeature *) factory));
1205 /* get the templates from the element factory */
1206 templates = gst_element_factory_get_static_pad_templates (factory);
1207 for (walk = (GList *) templates; walk; walk = g_list_next (walk)) {
1208 GstStaticPadTemplate *templ = walk->data;
1210 /* we only care about the sink templates */
1211 if (templ->direction == direction) {
1214 /* try to intersect the caps with the caps of the template */
1215 tmpl_caps = gst_static_caps_get (&templ->static_caps);
1217 /* FIXME, intersect is not the right method, we ideally want to check
1218 * for a subset here */
1220 /* check if the intersection is empty */
1221 if ((subsetonly && gst_caps_is_subset (caps, tmpl_caps)) ||
1222 (!subsetonly && gst_caps_can_intersect (caps, tmpl_caps))) {
1223 /* non empty intersection, we can use this element */
1224 g_queue_push_tail (&results, gst_object_ref (factory));
1225 gst_caps_unref (tmpl_caps);
1228 gst_caps_unref (tmpl_caps);
1232 return results.head;