2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstplugin.c: Plugin subsystem for loading elements, types, and libs
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 * @short_description: Container for features loaded from a shared object module
26 * @see_also: #GstPluginFeature, #GstElementFactory
28 * GStreamer is extensible, so #GstElement instances can be loaded at runtime.
29 * A plugin system can provide one or more of the basic
30 * <application>GStreamer</application> #GstPluginFeature subclasses.
32 * A plugin should export a symbol <symbol>gst_plugin_desc</symbol> that is a
33 * struct of type #GstPluginDesc.
34 * the plugin loader will check the version of the core library the plugin was
35 * linked against and will create a new #GstPlugin. It will then call the
36 * #GstPluginInitFunc function that was provided in the
37 * <symbol>gst_plugin_desc</symbol>.
39 * Once you have a handle to a #GstPlugin (e.g. from the #GstRegistry), you
40 * can add any object that subclasses #GstPluginFeature.
42 * Usually plugins are always automaticlly loaded so you don't need to call
43 * gst_plugin_load() explicitly to bring it into memory. There are options to
44 * statically link plugins to an app or even use GStreamer without a plugin
45 * repository in which case gst_plugin_load() can be needed to bring the plugin
52 #include <glib/gstdio.h>
53 #include <sys/types.h>
63 #include "gst_private.h"
64 #include "glib-compat-private.h"
68 #define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
70 static guint _num_static_plugins; /* 0 */
71 static GstPluginDesc *_static_plugins; /* NULL */
72 static gboolean _gst_plugin_inited;
74 /* static variables for segfault handling of plugin loading */
75 static char *_gst_plugin_fault_handler_filename = NULL;
78 static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
81 /* list of valid licenses.
82 * One of these must be specified or the plugin won't be loaded
83 * Contact gstreamer-devel@lists.sourceforge.net if your license should be
86 * GPL: http://www.gnu.org/copyleft/gpl.html
87 * LGPL: http://www.gnu.org/copyleft/lesser.html
88 * QPL: http://www.trolltech.com/licenses/qpl.html
89 * MPL: http://www.opensource.org/licenses/mozilla1.1.php
90 * MIT/X11: http://www.opensource.org/licenses/mit-license.php
91 * 3-clause BSD: http://www.opensource.org/licenses/bsd-license.php
93 static const gchar *valid_licenses[] = {
94 "LGPL", /* GNU Lesser General Public License */
95 "GPL", /* GNU General Public License */
96 "QPL", /* Trolltech Qt Public License */
97 "GPL/QPL", /* Combi-license of GPL + QPL */
98 "MPL", /* MPL 1.1 license */
99 "BSD", /* 3-clause BSD license */
100 "MIT/X11", /* MIT/X11 license */
101 "Proprietary", /* Proprietary license */
102 GST_LICENSE_UNKNOWN, /* some other license */
106 static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
107 const GstPluginDesc * desc);
108 static void gst_plugin_desc_copy (GstPluginDesc * dest,
109 const GstPluginDesc * src);
110 static void gst_plugin_desc_free (GstPluginDesc * desc);
113 G_DEFINE_TYPE (GstPlugin, gst_plugin, GST_TYPE_OBJECT);
116 gst_plugin_init (GstPlugin * plugin)
118 /* do nothing, needed because of G_DEFINE_TYPE */
122 gst_plugin_finalize (GObject * object)
124 GstPlugin *plugin = GST_PLUGIN_CAST (object);
125 GstRegistry *registry = gst_registry_get_default ();
128 GST_DEBUG ("finalizing plugin %p", plugin);
129 for (g = registry->plugins; g; g = g->next) {
130 if (g->data == (gpointer) plugin) {
131 g_warning ("removing plugin that is still in registry");
134 g_free (plugin->filename);
135 g_free (plugin->basename);
136 gst_plugin_desc_free (&plugin->desc);
138 G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
142 gst_plugin_class_init (GstPluginClass * klass)
144 G_OBJECT_CLASS (klass)->finalize = GST_DEBUG_FUNCPTR (gst_plugin_finalize);
148 gst_plugin_error_quark (void)
150 static GQuark quark = 0;
153 quark = g_quark_from_static_string ("gst_plugin_error");
157 #ifndef GST_REMOVE_DEPRECATED
158 /* this function can be called in the GCC constructor extension, before
159 * the _gst_plugin_initialize() was called. In that case, we store the
160 * plugin description in a list to initialize it when we open the main
162 * When the main module is known, we can register the plugin right away.
165 _gst_plugin_register_static (GstPluginDesc * desc)
167 g_return_if_fail (desc != NULL);
169 if (!_gst_plugin_inited) {
170 /* We can't use any GLib functions here, since g_thread_init hasn't been
171 * called yet, and we can't call it here either, or programs that don't
172 * guard their g_thread_init calls in main() will just abort */
173 ++_num_static_plugins;
175 realloc (_static_plugins, _num_static_plugins * sizeof (GstPluginDesc));
176 /* assume strings in the GstPluginDesc are static const or live forever */
177 _static_plugins[_num_static_plugins - 1] = *desc;
179 gst_plugin_register_static (desc->major_version, desc->minor_version,
180 desc->name, desc->description, desc->plugin_init, desc->version,
181 desc->license, desc->source, desc->package, desc->origin);
187 * gst_plugin_register_static:
188 * @major_version: the major version number of the GStreamer core that the
189 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
190 * @minor_version: the minor version number of the GStreamer core that the
191 * plugin was compiled for, you can just use GST_VERSION_MINOR here
192 * @name: a unique name of the plugin (ideally prefixed with an application- or
193 * library-specific namespace prefix in order to avoid name conflicts in
194 * case a similar plugin with the same name ever gets added to GStreamer)
195 * @description: description of the plugin
196 * @init_func: pointer to the init function of this plugin.
197 * @version: version string of the plugin
198 * @license: effective license of plugin. Must be one of the approved licenses
199 * (see #GstPluginDesc above) or the plugin will not be registered.
200 * @source: source module plugin belongs to
201 * @package: shipped package plugin belongs to
202 * @origin: URL to provider of plugin
204 * Registers a static plugin, ie. a plugin which is private to an application
205 * or library and contained within the application or library (as opposed to
206 * being shipped as a separate module file).
208 * You must make sure that GStreamer has been initialised (with gst_init() or
209 * via gst_init_get_option_group()) before calling this function.
211 * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
216 gst_plugin_register_static (gint major_version, gint minor_version,
217 const gchar * name, gchar * description, GstPluginInitFunc init_func,
218 const gchar * version, const gchar * license, const gchar * source,
219 const gchar * package, const gchar * origin)
221 GstPluginDesc desc = { major_version, minor_version, name, description,
222 init_func, version, license, source, package, origin,
225 gboolean res = FALSE;
227 g_return_val_if_fail (name != NULL, FALSE);
228 g_return_val_if_fail (description != NULL, FALSE);
229 g_return_val_if_fail (init_func != NULL, FALSE);
230 g_return_val_if_fail (version != NULL, FALSE);
231 g_return_val_if_fail (license != NULL, FALSE);
232 g_return_val_if_fail (source != NULL, FALSE);
233 g_return_val_if_fail (package != NULL, FALSE);
234 g_return_val_if_fail (origin != NULL, FALSE);
236 /* make sure gst_init() has been called */
237 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
239 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
240 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
241 if (gst_plugin_register_func (plugin, &desc) != NULL) {
242 GST_INFO ("registered static plugin \"%s\"", name);
243 res = gst_default_registry_add_plugin (plugin);
244 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
250 _gst_plugin_initialize (void)
254 _gst_plugin_inited = TRUE;
256 /* now register all static plugins */
257 GST_INFO ("registering %u static plugins", _num_static_plugins);
258 for (i = 0; i < _num_static_plugins; ++i) {
259 gst_plugin_register_static (_static_plugins[i].major_version,
260 _static_plugins[i].minor_version, _static_plugins[i].name,
261 _static_plugins[i].description, _static_plugins[i].plugin_init,
262 _static_plugins[i].version, _static_plugins[i].license,
263 _static_plugins[i].source, _static_plugins[i].package,
264 _static_plugins[i].origin);
267 if (_static_plugins) {
268 free (_static_plugins);
269 _static_plugins = NULL;
270 _num_static_plugins = 0;
274 /* this function could be extended to check if the plugin license matches the
275 * applications license (would require the app to register its license somehow).
276 * We'll wait for someone who's interested in it to code it :)
279 gst_plugin_check_license (const gchar * license)
281 const gchar **check_license = valid_licenses;
283 g_assert (check_license);
285 while (*check_license) {
286 if (strcmp (license, *check_license) == 0)
294 gst_plugin_check_version (gint major, gint minor)
296 /* return NULL if the major and minor version numbers are not compatible */
298 if (major != GST_VERSION_MAJOR || minor != GST_VERSION_MINOR)
305 gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc)
307 if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
309 GST_WARNING ("plugin \"%s\" has incompatible version, not loading",
314 if (!desc->license || !desc->description || !desc->source ||
315 !desc->package || !desc->origin) {
317 GST_WARNING ("plugin \"%s\" has incorrect GstPluginDesc, not loading",
322 if (!gst_plugin_check_license (desc->license)) {
324 GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
325 plugin->filename, desc->license);
330 GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
332 gst_plugin_desc_copy (&plugin->desc, desc);
334 if (!((desc->plugin_init) (plugin))) {
336 GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
337 plugin->module = NULL;
342 GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
347 #ifdef HAVE_SIGACTION
348 static struct sigaction oldaction;
351 * _gst_plugin_fault_handler_restore:
352 * segfault handler restorer
355 _gst_plugin_fault_handler_restore (void)
357 if (!_gst_plugin_fault_handler_is_setup)
360 _gst_plugin_fault_handler_is_setup = FALSE;
362 sigaction (SIGSEGV, &oldaction, NULL);
366 * _gst_plugin_fault_handler_sighandler:
367 * segfault handler implementation
370 _gst_plugin_fault_handler_sighandler (int signum)
372 /* We need to restore the fault handler or we'll keep getting it */
373 _gst_plugin_fault_handler_restore ();
377 g_print ("\nERROR: ");
378 g_print ("Caught a segmentation fault while loading plugin file:\n");
379 g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
380 g_print ("Please either:\n");
381 g_print ("- remove it and restart.\n");
382 g_print ("- run with --gst-disable-segtrap and debug.\n");
386 g_print ("Caught unhandled signal on plugin loading\n");
392 * _gst_plugin_fault_handler_setup:
393 * sets up the segfault handler
396 _gst_plugin_fault_handler_setup (void)
398 struct sigaction action;
400 /* if asked to leave segfaults alone, just return */
401 if (!gst_segtrap_is_enabled ())
404 if (_gst_plugin_fault_handler_is_setup)
407 _gst_plugin_fault_handler_is_setup = TRUE;
409 memset (&action, 0, sizeof (action));
410 action.sa_handler = _gst_plugin_fault_handler_sighandler;
412 sigaction (SIGSEGV, &action, &oldaction);
416 _gst_plugin_fault_handler_restore (void)
421 _gst_plugin_fault_handler_setup (void)
426 static void _gst_plugin_fault_handler_setup ();
428 static GStaticMutex gst_plugin_loading_mutex = G_STATIC_MUTEX_INIT;
430 #define CHECK_PLUGIN_DESC_FIELD(desc,field,fn) \
431 if (G_UNLIKELY ((desc)->field == NULL)) { \
432 GST_ERROR ("GstPluginDesc for '%s' has no %s", fn, G_STRINGIFY (field)); \
436 * gst_plugin_load_file:
437 * @filename: the plugin filename to load
438 * @error: pointer to a NULL-valued GError
440 * Loads the given plugin and refs it. Caller needs to unref after use.
442 * Returns: a reference to the existing loaded GstPlugin, a reference to the
443 * newly-loaded GstPlugin, or NULL if an error occurred.
446 gst_plugin_load_file (const gchar * filename, GError ** error)
452 struct stat file_status;
453 GstRegistry *registry;
455 g_return_val_if_fail (filename != NULL, NULL);
457 registry = gst_registry_get_default ();
458 g_static_mutex_lock (&gst_plugin_loading_mutex);
460 plugin = gst_registry_lookup (registry, filename);
462 if (plugin->module) {
463 g_static_mutex_unlock (&gst_plugin_loading_mutex);
466 gst_object_unref (plugin);
471 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
474 if (g_module_supported () == FALSE) {
475 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
478 GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
482 if (g_stat (filename, &file_status)) {
483 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
486 GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
491 module = g_module_open (filename, G_MODULE_BIND_LOCAL);
492 if (module == NULL) {
493 GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
496 GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
498 /* If we failed to open the shared object, then it's probably because a
499 * plugin is linked against the wrong libraries. Print out an easy-to-see
500 * message in this case. */
501 g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
505 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
507 plugin->module = module;
508 plugin->filename = g_strdup (filename);
509 plugin->basename = g_path_get_basename (filename);
510 plugin->file_mtime = file_status.st_mtime;
511 plugin->file_size = file_status.st_size;
513 ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
515 GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
518 GST_PLUGIN_ERROR_MODULE,
519 "File \"%s\" is not a GStreamer plugin", filename);
520 g_module_close (module);
523 plugin->orig_desc = (GstPluginDesc *) ptr;
525 /* check plugin description: complain about bad values but accept them, to
526 * maintain backwards compatibility (FIXME: 0.11) */
527 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, name, filename);
528 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, description, filename);
529 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, version, filename);
530 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, license, filename);
531 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, source, filename);
532 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, package, filename);
533 CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, origin, filename);
535 GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
538 /* this is where we load the actual .so, so let's trap SIGSEGV */
539 _gst_plugin_fault_handler_setup ();
540 _gst_plugin_fault_handler_filename = plugin->filename;
542 GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
545 if (!gst_plugin_register_func (plugin, plugin->orig_desc)) {
546 /* remove signal handler */
547 _gst_plugin_fault_handler_restore ();
548 GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
552 GST_PLUGIN_ERROR_MODULE,
553 "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
555 g_module_close (module);
559 /* remove signal handler */
560 _gst_plugin_fault_handler_restore ();
561 _gst_plugin_fault_handler_filename = NULL;
562 GST_INFO ("plugin \"%s\" loaded", plugin->filename);
564 gst_object_ref (plugin);
565 gst_default_registry_add_plugin (plugin);
567 g_static_mutex_unlock (&gst_plugin_loading_mutex);
573 gst_object_unref (plugin);
574 g_static_mutex_unlock (&gst_plugin_loading_mutex);
580 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
582 dest->major_version = src->major_version;
583 dest->minor_version = src->minor_version;
584 dest->name = g_intern_string (src->name);
585 /* maybe intern the description too, just for convenience? */
586 dest->description = g_strdup (src->description);
587 dest->plugin_init = src->plugin_init;
588 dest->version = g_intern_string (src->version);
589 dest->license = g_intern_string (src->license);
590 dest->source = g_intern_string (src->source);
591 dest->package = g_intern_string (src->package);
592 dest->origin = g_intern_string (src->origin);
597 gst_plugin_desc_free (GstPluginDesc * desc)
599 g_free (desc->description);
600 memset (desc, 0, sizeof (GstPluginDesc));
604 * gst_plugin_get_name:
605 * @plugin: plugin to get the name of
607 * Get the short name of the plugin
609 * Returns: the name of the plugin
612 gst_plugin_get_name (GstPlugin * plugin)
614 g_return_val_if_fail (plugin != NULL, NULL);
616 return plugin->desc.name;
620 * gst_plugin_get_description:
621 * @plugin: plugin to get long name of
623 * Get the long descriptive name of the plugin
625 * Returns: the long name of the plugin
627 G_CONST_RETURN gchar *
628 gst_plugin_get_description (GstPlugin * plugin)
630 g_return_val_if_fail (plugin != NULL, NULL);
632 return plugin->desc.description;
636 * gst_plugin_get_filename:
637 * @plugin: plugin to get the filename of
639 * get the filename of the plugin
641 * Returns: the filename of the plugin
643 G_CONST_RETURN gchar *
644 gst_plugin_get_filename (GstPlugin * plugin)
646 g_return_val_if_fail (plugin != NULL, NULL);
648 return plugin->filename;
652 * gst_plugin_get_version:
653 * @plugin: plugin to get the version of
655 * get the version of the plugin
657 * Returns: the version of the plugin
659 G_CONST_RETURN gchar *
660 gst_plugin_get_version (GstPlugin * plugin)
662 g_return_val_if_fail (plugin != NULL, NULL);
664 return plugin->desc.version;
668 * gst_plugin_get_license:
669 * @plugin: plugin to get the license of
671 * get the license of the plugin
673 * Returns: the license of the plugin
675 G_CONST_RETURN gchar *
676 gst_plugin_get_license (GstPlugin * plugin)
678 g_return_val_if_fail (plugin != NULL, NULL);
680 return plugin->desc.license;
684 * gst_plugin_get_source:
685 * @plugin: plugin to get the source of
687 * get the source module the plugin belongs to.
689 * Returns: the source of the plugin
691 G_CONST_RETURN gchar *
692 gst_plugin_get_source (GstPlugin * plugin)
694 g_return_val_if_fail (plugin != NULL, NULL);
696 return plugin->desc.source;
700 * gst_plugin_get_package:
701 * @plugin: plugin to get the package of
703 * get the package the plugin belongs to.
705 * Returns: the package of the plugin
707 G_CONST_RETURN gchar *
708 gst_plugin_get_package (GstPlugin * plugin)
710 g_return_val_if_fail (plugin != NULL, NULL);
712 return plugin->desc.package;
716 * gst_plugin_get_origin:
717 * @plugin: plugin to get the origin of
719 * get the URL where the plugin comes from
721 * Returns: the origin of the plugin
723 G_CONST_RETURN gchar *
724 gst_plugin_get_origin (GstPlugin * plugin)
726 g_return_val_if_fail (plugin != NULL, NULL);
728 return plugin->desc.origin;
732 * gst_plugin_get_module:
733 * @plugin: plugin to query
735 * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is
738 * Returns: module belonging to the plugin or NULL if the plugin isn't
742 gst_plugin_get_module (GstPlugin * plugin)
744 g_return_val_if_fail (plugin != NULL, NULL);
746 return plugin->module;
750 * gst_plugin_is_loaded:
751 * @plugin: plugin to query
753 * queries if the plugin is loaded into memory
755 * Returns: TRUE is loaded, FALSE otherwise
758 gst_plugin_is_loaded (GstPlugin * plugin)
760 g_return_val_if_fail (plugin != NULL, FALSE);
762 return (plugin->module != NULL || plugin->filename == NULL);
767 * gst_plugin_feature_list:
768 * @plugin: plugin to query
769 * @filter: the filter to use
770 * @first: only return first match
771 * @user_data: user data passed to the filter function
773 * Runs a filter against all plugin features and returns a GList with
774 * the results. If the first flag is set, only the first match is
775 * returned (as a list with a single object).
777 * Returns: a GList of features, g_list_free after use.
780 gst_plugin_feature_filter (GstPlugin * plugin,
781 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
786 list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
788 for (g = list; g; g = g->next) {
789 gst_object_ref (plugin);
797 GstPluginFeatureFilter filter;
805 _feature_filter (GstPlugin * plugin, gpointer user_data)
808 FeatureFilterData *data = (FeatureFilterData *) user_data;
810 result = gst_plugin_feature_filter (plugin, data->filter, data->first,
813 data->result = g_list_concat (data->result, result);
820 * gst_plugin_list_feature_filter:
821 * @list: a #GList of plugins to query
822 * @filter: the filter function to use
823 * @first: only return first match
824 * @user_data: user data passed to the filter function
826 * Runs a filter against all plugin features of the plugins in the given
827 * list and returns a GList with the results.
828 * If the first flag is set, only the first match is
829 * returned (as a list with a single object).
831 * Returns: a GList of features, g_list_free after use.
834 gst_plugin_list_feature_filter (GList * list,
835 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
837 FeatureFilterData data;
840 data.filter = filter;
842 data.user_data = user_data;
845 result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
846 g_list_free (result);
853 * gst_plugin_name_filter:
854 * @plugin: the plugin to check
855 * @name: the name of the plugin
857 * A standard filter that returns TRUE when the plugin is of the
860 * Returns: TRUE if the plugin is of the given name.
863 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
865 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
870 * gst_plugin_find_feature:
871 * @plugin: plugin to get the feature from
872 * @name: The name of the feature to find
873 * @type: The type of the feature to find
875 * Find a feature of the given name and type in the given plugin.
877 * Returns: a GstPluginFeature or NULL if the feature was not found.
880 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
883 GstPluginFeature *result = NULL;
884 GstTypeNameData data;
886 g_return_val_if_fail (name != NULL, NULL);
891 walk = gst_filter_run (plugin->features,
892 (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
895 result = GST_PLUGIN_FEATURE (walk->data);
897 gst_object_ref (result);
898 gst_plugin_feature_list_free (walk);
907 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
909 return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
915 * gst_plugin_find_feature_by_name:
916 * @plugin: plugin to get the feature from
917 * @name: The name of the feature to find
919 * Find a feature of the given name in the given plugin.
921 * Returns: a GstPluginFeature or NULL if the feature was not found.
924 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
927 GstPluginFeature *result = NULL;
929 g_return_val_if_fail (name != NULL, NULL);
931 walk = gst_filter_run (plugin->features,
932 (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
935 result = GST_PLUGIN_FEATURE (walk->data);
937 gst_object_ref (result);
938 gst_plugin_feature_list_free (walk);
946 * gst_plugin_load_by_name:
947 * @name: name of plugin to load
949 * Load the named plugin. Refs the plugin.
951 * Returns: A reference to a loaded plugin, or NULL on error.
954 gst_plugin_load_by_name (const gchar * name)
956 GstPlugin *plugin, *newplugin;
957 GError *error = NULL;
959 GST_DEBUG ("looking up plugin %s in default registry", name);
960 plugin = gst_registry_find_plugin (gst_registry_get_default (), name);
962 GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
963 newplugin = gst_plugin_load_file (plugin->filename, &error);
964 gst_object_unref (plugin);
967 GST_WARNING ("load_plugin error: %s", error->message);
968 g_error_free (error);
971 /* newplugin was reffed by load_file */
975 GST_DEBUG ("Could not find plugin %s in registry", name);
981 * @plugin: plugin to load
983 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
984 * untouched. The normal use pattern of this function goes like this:
987 * GstPlugin *loaded_plugin;
988 * loaded_plugin = gst_plugin_load (plugin);
989 * // presumably, we're no longer interested in the potentially-unloaded plugin
990 * gst_object_unref (plugin);
991 * plugin = loaded_plugin;
994 * Returns: A reference to a loaded plugin, or NULL on error.
997 gst_plugin_load (GstPlugin * plugin)
999 GError *error = NULL;
1000 GstPlugin *newplugin;
1002 if (gst_plugin_is_loaded (plugin)) {
1006 if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
1013 GST_WARNING ("load_plugin error: %s", error->message);
1014 g_error_free (error);
1020 * gst_plugin_list_free:
1021 * @list: list of #GstPlugin
1023 * Unrefs each member of @list, then frees the list.
1026 gst_plugin_list_free (GList * list)
1030 for (g = list; g; g = g->next) {
1031 gst_object_unref (GST_PLUGIN_CAST (g->data));