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);
92 gst_element_factory_class_init (GstElementFactoryClass * klass)
94 GObjectClass *gobject_class = (GObjectClass *) klass;
96 gobject_class->finalize = gst_element_factory_finalize;
100 gst_element_factory_init (GstElementFactory * factory)
102 factory->staticpadtemplates = NULL;
103 factory->numpadtemplates = 0;
105 factory->uri_type = GST_URI_UNKNOWN;
106 factory->uri_protocols = NULL;
108 factory->interfaces = NULL;
112 gst_element_factory_finalize (GObject * object)
114 GstElementFactory *factory = GST_ELEMENT_FACTORY (object);
116 gst_element_factory_cleanup (factory);
117 G_OBJECT_CLASS (gst_element_factory_parent_class)->finalize (object);
121 * gst_element_factory_find:
122 * @name: name of factory to find
124 * Search for an element factory of the given name. Refs the returned
125 * element factory; caller is responsible for unreffing.
127 * Returns: (transfer full) (nullable): #GstElementFactory if found,
131 gst_element_factory_find (const gchar * name)
133 GstPluginFeature *feature;
135 g_return_val_if_fail (name != NULL, NULL);
137 feature = gst_registry_find_feature (gst_registry_get (), name,
138 GST_TYPE_ELEMENT_FACTORY);
140 return GST_ELEMENT_FACTORY (feature);
142 /* this isn't an error, for instance when you query if an element factory is
144 GST_LOG ("no such element factory \"%s\"", name);
149 gst_element_factory_cleanup (GstElementFactory * factory)
153 if (factory->metadata) {
154 gst_structure_free ((GstStructure *) factory->metadata);
155 factory->metadata = NULL;
158 factory->type = G_TYPE_INVALID;
161 for (item = factory->staticpadtemplates; item; item = item->next) {
162 GstStaticPadTemplate *templ = item->data;
164 gst_static_caps_cleanup (&templ->static_caps);
165 g_slice_free (GstStaticPadTemplate, templ);
167 g_list_free (factory->staticpadtemplates);
168 factory->staticpadtemplates = NULL;
169 factory->numpadtemplates = 0;
170 factory->uri_type = GST_URI_UNKNOWN;
171 if (factory->uri_protocols) {
172 g_strfreev (factory->uri_protocols);
173 factory->uri_protocols = NULL;
176 g_list_free (factory->interfaces);
177 factory->interfaces = NULL;
180 #define CHECK_METADATA_FIELD(klass, name, key) \
182 const gchar *metafield = gst_element_class_get_metadata (klass, key); \
183 if (G_UNLIKELY (metafield == NULL || *metafield == '\0')) { \
184 g_warning ("Element factory metadata for '%s' has no valid %s field", name, key); \
190 * gst_element_register:
191 * @plugin: (allow-none): #GstPlugin to register the element with, or %NULL for
193 * @name: name of elements of this type
194 * @rank: rank of element (higher rank means more importance when autoplugging)
195 * @type: GType of element to register
197 * Create a new elementfactory capable of instantiating objects of the
198 * @type and add the factory to @plugin.
200 * Returns: %TRUE, if the registering succeeded, %FALSE on error
203 gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
206 GstPluginFeature *existing_feature;
207 GstRegistry *registry;
208 GstElementFactory *factory;
210 guint n_interfaces, i;
211 GstElementClass *klass;
214 g_return_val_if_fail (name != NULL, FALSE);
215 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_ELEMENT), FALSE);
217 registry = gst_registry_get ();
219 /* check if feature already exists, if it exists there is no need to update it
220 * when the registry is getting updated, outdated plugins and all their
221 * features are removed and readded.
223 existing_feature = gst_registry_lookup_feature (registry, name);
224 if (existing_feature && existing_feature->plugin == plugin) {
225 GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)",
226 existing_feature, name);
227 factory = GST_ELEMENT_FACTORY_CAST (existing_feature);
228 factory->type = type;
229 existing_feature->loaded = TRUE;
230 g_type_set_qdata (type, __gst_elementclass_factory, factory);
231 gst_object_unref (existing_feature);
233 } else if (existing_feature) {
234 gst_object_unref (existing_feature);
237 factory = g_object_new (GST_TYPE_ELEMENT_FACTORY, NULL);
238 gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
239 GST_LOG_OBJECT (factory, "Created new elementfactory for type %s",
242 /* provide info needed during class structure setup */
243 g_type_set_qdata (type, __gst_elementclass_factory, factory);
244 klass = GST_ELEMENT_CLASS (g_type_class_ref (type));
246 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_LONGNAME);
247 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_KLASS);
248 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_DESCRIPTION);
249 CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_AUTHOR);
251 factory->type = type;
252 factory->metadata = gst_structure_copy ((GstStructure *) klass->metadata);
254 for (item = klass->padtemplates; item; item = item->next) {
255 GstPadTemplate *templ = item->data;
256 GstStaticPadTemplate *newt;
257 gchar *caps_string = gst_caps_to_string (templ->caps);
259 newt = g_slice_new (GstStaticPadTemplate);
260 newt->name_template = g_intern_string (templ->name_template);
261 newt->direction = templ->direction;
262 newt->presence = templ->presence;
263 newt->static_caps.caps = NULL;
264 newt->static_caps.string = g_intern_string (caps_string);
265 factory->staticpadtemplates =
266 g_list_append (factory->staticpadtemplates, newt);
268 g_free (caps_string);
270 factory->numpadtemplates = klass->numpadtemplates;
272 /* special stuff for URI handling */
273 if (g_type_is_a (type, GST_TYPE_URI_HANDLER)) {
274 GstURIHandlerInterface *iface = (GstURIHandlerInterface *)
275 g_type_interface_peek (klass, GST_TYPE_URI_HANDLER);
277 if (!iface || !iface->get_type || !iface->get_protocols)
280 factory->uri_type = iface->get_type (factory->type);
281 if (!GST_URI_TYPE_IS_VALID (factory->uri_type))
283 if (iface->get_protocols) {
284 const gchar *const *protocols;
286 protocols = iface->get_protocols (factory->type);
287 factory->uri_protocols = g_strdupv ((gchar **) protocols);
289 if (!factory->uri_protocols)
293 interfaces = g_type_interfaces (type, &n_interfaces);
294 for (i = 0; i < n_interfaces; i++) {
295 __gst_element_factory_add_interface (factory, g_type_name (interfaces[i]));
299 if (plugin && plugin->desc.name) {
300 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name;
301 GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
302 g_object_add_weak_pointer ((GObject *) plugin,
303 (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
305 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
306 GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
308 gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank);
309 GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;
311 gst_registry_add_feature (registry, GST_PLUGIN_FEATURE_CAST (factory));
318 GST_WARNING_OBJECT (factory, "error with uri handler!");
319 gst_element_factory_cleanup (factory);
325 gst_element_factory_cleanup (factory);
331 gst_element_factory_property_valist_to_array (const gchar * first,
332 va_list properties, GType object_type, guint * n, const gchar ** names[],
338 guint n_params_alloc = 16;
339 GValue *values_array;
340 const gchar **names_array;
345 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), FALSE);
347 class = g_type_class_ref (object_type);
352 names_array = g_new0 (const gchar *, n_params_alloc);
353 values_array = g_new0 (GValue, n_params_alloc);
359 pspec = g_object_class_find_property (class, name);
363 if (G_UNLIKELY (n_params == n_params_alloc)) {
364 n_params_alloc *= 2u;
366 g_realloc (names_array, sizeof (const gchar *) * n_params_alloc);
367 values_array = g_realloc (values_array, sizeof (GValue) * n_params_alloc);
368 memset (&values_array[n_params], 0,
369 sizeof (GValue) * (n_params_alloc - n_params));
372 names_array[n_params] = name;
374 G_VALUE_COLLECT_INIT (&values_array[n_params], pspec->value_type,
375 properties, 0, &error);
378 g_critical ("%s", error);
384 name = va_arg (properties, const gchar *);
388 *names = names_array;
389 *values = values_array;
390 g_type_class_unref (class);
394 g_free (names_array);
395 g_free (values_array);
396 g_type_class_unref (class);
401 * gst_element_factory_create_with_properties:
402 * @factory: factory to instantiate
403 * @n: count of properties
404 * @names: (nullable): array of properties names
405 * @values: (nullable): array of associated properties values
407 * Create a new element of the type defined by the given elementfactory.
408 * The supplied list of properties, will be passed at object construction.
410 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
411 * if the element couldn't be created
416 gst_element_factory_create_with_properties (GstElementFactory * factory,
417 guint n, const gchar * names[], const GValue values[])
420 GstElementClass *oclass;
421 GstElementFactory *newfactory;
423 g_return_val_if_fail (factory != NULL, NULL);
426 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
429 if (newfactory == NULL)
432 factory = newfactory;
434 GST_INFO ("creating element \"%s\"", GST_OBJECT_NAME (factory));
436 if (factory->type == 0)
439 element = (GstElement *) g_object_new_with_properties (factory->type, n,
442 if (G_UNLIKELY (element == NULL))
445 /* fill in the pointer to the factory in the element class. The
446 * class will not be unreffed currently.
447 * Be thread safe as there might be 2 threads creating the first instance of
448 * an element at the same moment
450 oclass = GST_ELEMENT_GET_CLASS (element);
451 if (!g_atomic_pointer_compare_and_exchange (&oclass->elementfactory,
452 (GstElementFactory *) NULL, factory))
453 gst_object_unref (factory);
455 /* This ref will never be dropped as the class is never destroyed */
456 GST_OBJECT_FLAG_SET (factory, GST_OBJECT_FLAG_MAY_BE_LEAKED);
458 if (!g_object_is_floating ((GObject *) element)) {
459 /* The reference we receive here should be floating, but we can't force
460 * it at our level. Simply raise a critical to make the issue obvious to bindings
461 * users / developers */
462 g_critical ("The created element should be floating, "
463 "this is probably caused by faulty bindings");
467 GST_DEBUG ("created element \"%s\"", GST_OBJECT_NAME (factory));
474 GST_WARNING_OBJECT (factory, "loading plugin returned NULL!");
479 GST_WARNING_OBJECT (factory, "factory has no type");
480 gst_object_unref (factory);
485 GST_WARNING_OBJECT (factory, "could not create element");
486 gst_object_unref (factory);
492 * gst_element_factory_create_valist:
493 * @factory: factory to instantiate
494 * @first: (nullable): name of the first property
495 * @properties: (nullable): list of properties
497 * Create a new element of the type defined by the given elementfactory.
498 * The supplied list of properties, will be passed at object construction.
500 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
501 * if the element couldn't be created
506 gst_element_factory_create_valist (GstElementFactory * factory,
507 const gchar * first, va_list properties)
509 GstElementFactory *newfactory;
511 const gchar **names = NULL;
512 GValue *values = NULL;
515 g_return_val_if_fail (factory != NULL, NULL);
518 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
521 g_return_val_if_fail (newfactory != NULL, NULL);
522 g_return_val_if_fail (newfactory->type != 0, NULL);
524 factory = newfactory;
528 gst_element_factory_create_with_properties (factory, 0, NULL, NULL);
532 if (!gst_element_factory_property_valist_to_array (first, properties,
533 factory->type, &n, &names, &values)) {
534 GST_ERROR_OBJECT (factory, "property parsing failed");
539 element = gst_element_factory_create_with_properties (factory, n, names,
544 g_value_unset (&values[n]);
548 gst_object_unref (factory);
553 * gst_element_factory_create_full:
554 * @factory: factory to instantiate
555 * @first: (nullable): name of the first property
556 * @...: (nullable): %NULL terminated list of properties
558 * Create a new element of the type defined by the given elementfactory.
559 * The supplied list of properties, will be passed at object construction.
561 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
562 * if the element couldn't be created
567 gst_element_factory_create_full (GstElementFactory * factory,
568 const gchar * first, ...)
573 va_start (properties, first);
574 element = gst_element_factory_create_valist (factory, first, properties);
581 * gst_element_factory_create:
582 * @factory: factory to instantiate
583 * @name: (nullable): name of new element, or %NULL to automatically create
586 * Create a new element of the type defined by the given elementfactory.
587 * It will be given the name supplied, since all elements require a name as
588 * their first argument.
590 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
591 * if the element couldn't be created
594 gst_element_factory_create (GstElementFactory * factory, const gchar * name)
597 return gst_element_factory_create_full (factory, "name", name, NULL);
599 return gst_element_factory_create_with_properties (factory, 0, NULL, NULL);
603 * gst_element_factory_make_with_properties:
604 * @factoryname: a named factory to instantiate
605 * @n: count of properties
606 * @names: (nullable): array of properties names
607 * @values: (nullable): array of associated properties values
609 * Create a new element of the type defined by the given elementfactory.
610 * The supplied list of properties, will be passed at object construction.
612 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
613 * if the element couldn't be created
618 gst_element_factory_make_with_properties (const gchar * factoryname,
619 guint n, const gchar * names[], const GValue values[])
621 GstElementFactory *factory;
624 g_return_val_if_fail (factoryname != NULL, NULL);
625 g_return_val_if_fail (gst_is_initialized (), NULL);
627 GST_LOG ("gstelementfactory: make \"%s\"", factoryname);
629 factory = gst_element_factory_find (factoryname);
633 GST_LOG_OBJECT (factory, "found factory %p", factory);
634 element = gst_element_factory_create_with_properties (factory, n, names,
639 gst_object_unref (factory);
646 GST_WARNING ("no such element factory \"%s\"!", factoryname);
651 GST_INFO_OBJECT (factory, "couldn't create instance!");
652 gst_object_unref (factory);
658 * gst_element_factory_make_valist:
659 * @factoryname: a named factory to instantiate
660 * @first: (nullable): name of first property
661 * @properties: (nullable): list of properties
663 * Create a new element of the type defined by the given element factory.
664 * The supplied list of properties, will be passed at object construction.
666 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
667 * if unable to create element
672 gst_element_factory_make_valist (const gchar * factoryname,
673 const gchar * first, va_list properties)
675 GstElementFactory *factory;
678 g_return_val_if_fail (factoryname != NULL, NULL);
679 g_return_val_if_fail (gst_is_initialized (), NULL);
681 GST_LOG ("gstelementfactory: make \"%s\"", factoryname);
683 factory = gst_element_factory_find (factoryname);
687 GST_LOG_OBJECT (factory, "found factory %p", factory);
688 element = gst_element_factory_create_valist (factory, first, properties);
692 gst_object_unref (factory);
699 GST_WARNING ("no such element factory \"%s\"!", factoryname);
704 GST_INFO_OBJECT (factory, "couldn't create instance!");
705 gst_object_unref (factory);
711 * gst_element_factory_make_full:
712 * @factoryname: a named factory to instantiate
713 * @first: (nullable): name of first property
714 * @...: (nullable): %NULL terminated list of properties
716 * Create a new element of the type defined by the given element factory.
717 * The supplied list of properties, will be passed at object construction.
719 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
720 * if unable to create element
725 gst_element_factory_make_full (const gchar * factoryname,
726 const gchar * first, ...)
731 va_start (properties, first);
733 element = gst_element_factory_make_valist (factoryname, first, properties);
740 * gst_element_factory_make:
741 * @factoryname: a named factory to instantiate
742 * @name: (nullable): name of new element, or %NULL to automatically create
745 * Create a new element of the type defined by the given element factory.
746 * If name is %NULL, then the element will receive a guaranteed unique name,
747 * consisting of the element factory name and a number.
748 * If name is given, it will be given the name supplied.
750 * Returns: (transfer floating) (nullable): new #GstElement or %NULL
751 * if unable to create element
754 gst_element_factory_make (const gchar * factoryname, const gchar * name)
757 return gst_element_factory_make_full (factoryname, "name", name, NULL);
759 return gst_element_factory_make_with_properties (factoryname, 0, NULL,
764 __gst_element_factory_add_static_pad_template (GstElementFactory * factory,
765 GstStaticPadTemplate * templ)
767 g_return_if_fail (factory != NULL);
768 g_return_if_fail (templ != NULL);
770 factory->staticpadtemplates =
771 g_list_append (factory->staticpadtemplates, templ);
772 factory->numpadtemplates++;
776 * gst_element_factory_get_element_type:
777 * @factory: factory to get managed #GType from
779 * Get the #GType for elements managed by this factory. The type can
780 * only be retrieved if the element factory is loaded, which can be
781 * assured with gst_plugin_feature_load().
783 * Returns: the #GType for elements managed by this factory or 0 if
784 * the factory is not loaded.
787 gst_element_factory_get_element_type (GstElementFactory * factory)
789 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), 0);
791 return factory->type;
795 * gst_element_factory_get_metadata:
796 * @factory: a #GstElementFactory
799 * Get the metadata on @factory with @key.
801 * Returns: (nullable): the metadata with @key on @factory or %NULL
802 * when there was no metadata with the given @key.
805 gst_element_factory_get_metadata (GstElementFactory * factory,
808 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
810 return gst_structure_get_string ((GstStructure *) factory->metadata, key);
814 * gst_element_factory_get_metadata_keys:
815 * @factory: a #GstElementFactory
817 * Get the available keys for the metadata on @factory.
819 * Returns: (transfer full) (element-type utf8) (array zero-terminated=1) (nullable):
820 * a %NULL-terminated array of key strings, or %NULL when there is no
821 * metadata. Free with g_strfreev() when no longer needed.
824 gst_element_factory_get_metadata_keys (GstElementFactory * factory)
826 GstStructure *metadata;
830 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
832 metadata = (GstStructure *) factory->metadata;
833 if (metadata == NULL)
836 num = gst_structure_n_fields (metadata);
840 arr = g_new (gchar *, num + 1);
841 for (i = 0; i < num; ++i) {
842 arr[i] = g_strdup (gst_structure_nth_field_name (metadata, i));
849 * gst_element_factory_get_num_pad_templates:
850 * @factory: a #GstElementFactory
852 * Gets the number of pad_templates in this factory.
854 * Returns: the number of pad_templates
857 gst_element_factory_get_num_pad_templates (GstElementFactory * factory)
859 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), 0);
861 return factory->numpadtemplates;
865 * __gst_element_factory_add_interface:
866 * @elementfactory: The elementfactory to add the interface to
867 * @interfacename: Name of the interface
869 * Adds the given interfacename to the list of implemented interfaces of the
873 __gst_element_factory_add_interface (GstElementFactory * elementfactory,
874 const gchar * interfacename)
876 g_return_if_fail (GST_IS_ELEMENT_FACTORY (elementfactory));
877 g_return_if_fail (interfacename != NULL);
878 g_return_if_fail (interfacename[0] != '\0'); /* no empty string */
880 elementfactory->interfaces =
881 g_list_prepend (elementfactory->interfaces,
882 (gpointer) g_intern_string (interfacename));
886 * gst_element_factory_get_static_pad_templates:
887 * @factory: a #GstElementFactory
889 * Gets the #GList of #GstStaticPadTemplate for this factory.
891 * Returns: (transfer none) (element-type Gst.StaticPadTemplate): the
892 * static pad templates
895 gst_element_factory_get_static_pad_templates (GstElementFactory * factory)
897 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
899 return factory->staticpadtemplates;
903 * gst_element_factory_get_uri_type:
904 * @factory: a #GstElementFactory
906 * Gets the type of URIs the element supports or #GST_URI_UNKNOWN if none.
908 * Returns: type of URIs this element supports
911 gst_element_factory_get_uri_type (GstElementFactory * factory)
913 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), GST_URI_UNKNOWN);
915 return factory->uri_type;
919 * gst_element_factory_get_uri_protocols:
920 * @factory: a #GstElementFactory
922 * Gets a %NULL-terminated array of protocols this element supports or %NULL if
923 * no protocols are supported. You may not change the contents of the returned
924 * array, as it is still owned by the element factory. Use g_strdupv() to
925 * make a copy of the protocol string array if you need to.
927 * Returns: (transfer none) (array zero-terminated=1): the supported protocols
931 gst_element_factory_get_uri_protocols (GstElementFactory * factory)
933 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
935 return (const gchar * const *) factory->uri_protocols;
939 * gst_element_factory_has_interface:
940 * @factory: a #GstElementFactory
941 * @interfacename: an interface name
943 * Check if @factory implements the interface with name @interfacename.
945 * Returns: %TRUE when @factory implement the interface.
948 gst_element_factory_has_interface (GstElementFactory * factory,
949 const gchar * interfacename)
953 g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), FALSE);
955 for (walk = factory->interfaces; walk; walk = g_list_next (walk)) {
956 gchar *iname = (gchar *) walk->data;
958 if (!strcmp (iname, interfacename))
967 GstElementFactoryListType type;
973 * gst_element_factory_list_is_type:
974 * @factory: a #GstElementFactory
975 * @type: a #GstElementFactoryListType
977 * Check if @factory is of the given types.
979 * Returns: %TRUE if @factory is of @type.
982 gst_element_factory_list_is_type (GstElementFactory * factory,
983 GstElementFactoryListType type)
985 gboolean res = FALSE;
989 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
992 GST_ERROR_OBJECT (factory, "element factory is missing klass identifiers");
996 /* Filter by element type first, as soon as it matches
997 * one type, we skip all other tests */
998 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_SINK))
999 res = (strstr (klass, "Sink") != NULL);
1001 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_SRC))
1002 res = (strstr (klass, "Source") != NULL);
1004 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DECODER))
1005 res = (strstr (klass, "Decoder") != NULL);
1007 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_ENCODER))
1008 res = (strstr (klass, "Encoder") != NULL);
1010 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_MUXER))
1011 res = (strstr (klass, "Muxer") != NULL);
1013 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DEMUXER))
1014 res = (strstr (klass, "Demux") != NULL);
1016 /* FIXME : We're actually parsing two Classes here... */
1017 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_PARSER))
1018 res = ((strstr (klass, "Parser") != NULL)
1019 && (strstr (klass, "Codec") != NULL));
1021 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER))
1022 res = (strstr (klass, "Depayloader") != NULL);
1024 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_PAYLOADER))
1025 res = (strstr (klass, "Payloader") != NULL);
1027 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_FORMATTER))
1028 res = (strstr (klass, "Formatter") != NULL);
1030 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_DECRYPTOR))
1031 res = (strstr (klass, "Decryptor") != NULL);
1033 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_ENCRYPTOR))
1034 res = (strstr (klass, "Encryptor") != NULL);
1036 if (!res && (type & GST_ELEMENT_FACTORY_TYPE_HARDWARE))
1037 res = (strstr (klass, "Hardware") != NULL);
1039 /* Filter by media type now, we only test if it
1040 * matched any of the types above or only checking the media
1041 * type was requested. */
1042 if ((res || !(type & (GST_ELEMENT_FACTORY_TYPE_MAX_ELEMENTS - 1)))
1043 && (type & (GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO |
1044 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
1045 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE |
1046 GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE |
1047 GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)))
1048 res = ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)
1049 && (strstr (klass, "Audio") != NULL))
1050 || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO)
1051 && (strstr (klass, "Video") != NULL))
1052 || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)
1053 && (strstr (klass, "Image") != NULL)) ||
1054 ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE)
1055 && (strstr (klass, "Subtitle") != NULL)) ||
1056 ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)
1057 && (strstr (klass, "Metadata") != NULL));
1063 element_filter (GstPluginFeature * feature, FilterData * data)
1067 /* we only care about element factories */
1068 if (G_UNLIKELY (!GST_IS_ELEMENT_FACTORY (feature)))
1071 res = (gst_plugin_feature_get_rank (feature) >= data->minrank) &&
1072 gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (feature),
1079 * gst_element_factory_list_get_elements:
1080 * @type: a #GstElementFactoryListType
1081 * @minrank: Minimum rank
1083 * Get a list of factories that match the given @type. Only elements
1084 * with a rank greater or equal to @minrank will be returned.
1085 * The list of factories is returned by decreasing rank.
1087 * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
1088 * #GstElementFactory elements. Use gst_plugin_feature_list_free() after
1092 gst_element_factory_list_get_elements (GstElementFactoryListType type,
1100 data.minrank = minrank;
1102 /* get the feature list using the filter */
1103 result = gst_registry_feature_filter (gst_registry_get (),
1104 (GstPluginFeatureFilter) element_filter, FALSE, &data);
1106 /* sort on rank and name */
1107 result = g_list_sort (result, gst_plugin_feature_rank_compare_func);
1113 * gst_element_factory_list_filter:
1114 * @list: (transfer none) (element-type Gst.ElementFactory): a #GList of
1115 * #GstElementFactory to filter
1117 * @direction: a #GstPadDirection to filter on
1118 * @subsetonly: whether to filter on caps subsets or not.
1120 * Filter out all the elementfactories in @list that can handle @caps in
1121 * the given direction.
1123 * If @subsetonly is %TRUE, then only the elements whose pads templates
1124 * are a complete superset of @caps will be returned. Else any element
1125 * whose pad templates caps can intersect with @caps will be returned.
1127 * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
1128 * #GstElementFactory elements that match the given requisites.
1129 * Use #gst_plugin_feature_list_free after usage.
1132 gst_element_factory_list_filter (GList * list,
1133 const GstCaps * caps, GstPadDirection direction, gboolean subsetonly)
1135 GQueue results = G_QUEUE_INIT;
1137 GST_DEBUG ("finding factories");
1139 /* loop over all the factories */
1140 for (; list; list = list->next) {
1141 GstElementFactory *factory;
1142 const GList *templates;
1145 factory = (GstElementFactory *) list->data;
1147 GST_DEBUG ("Trying %s",
1148 gst_plugin_feature_get_name ((GstPluginFeature *) factory));
1150 /* get the templates from the element factory */
1151 templates = gst_element_factory_get_static_pad_templates (factory);
1152 for (walk = (GList *) templates; walk; walk = g_list_next (walk)) {
1153 GstStaticPadTemplate *templ = walk->data;
1155 /* we only care about the sink templates */
1156 if (templ->direction == direction) {
1159 /* try to intersect the caps with the caps of the template */
1160 tmpl_caps = gst_static_caps_get (&templ->static_caps);
1162 /* FIXME, intersect is not the right method, we ideally want to check
1163 * for a subset here */
1165 /* check if the intersection is empty */
1166 if ((subsetonly && gst_caps_is_subset (caps, tmpl_caps)) ||
1167 (!subsetonly && gst_caps_can_intersect (caps, tmpl_caps))) {
1168 /* non empty intersection, we can use this element */
1169 g_queue_push_tail (&results, gst_object_ref (factory));
1170 gst_caps_unref (tmpl_caps);
1173 gst_caps_unref (tmpl_caps);
1177 return results.head;