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 #GstRegistryPool), you
40 * can add any object that subclasses #GstPluginFeature.
42 * Use gst_plugin_find_feature() and gst_plugin_get_feature_list() to find
43 * features in a plugin.
45 * Usually plugins are always automaticlly loaded so you don't need to call
46 * gst_plugin_load() explicitly to bring it into memory. There are options to
47 * statically link plugins to an app or even use GStreamer without a plugin
48 * repository in which case gst_plugin_load() can be needed to bring the plugin
55 #include <glib/gstdio.h>
56 #include <sys/types.h>
66 #include "gst_private.h"
67 #include "glib-compat-private.h"
71 #define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
73 static guint _num_static_plugins; /* 0 */
74 static GstPluginDesc *_static_plugins; /* NULL */
75 static gboolean _gst_plugin_inited;
77 /* static variables for segfault handling of plugin loading */
78 static char *_gst_plugin_fault_handler_filename = NULL;
81 static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
84 /* list of valid licenses.
85 * One of these must be specified or the plugin won't be loaded
86 * Contact gstreamer-devel@lists.sourceforge.net if your license should be
89 * GPL: http://www.gnu.org/copyleft/gpl.html
90 * LGPL: http://www.gnu.org/copyleft/lesser.html
91 * QPL: http://www.trolltech.com/licenses/qpl.html
92 * MPL: http://www.opensource.org/licenses/mozilla1.1.php
93 * MIT/X11: http://www.opensource.org/licenses/mit-license.php
94 * 3-clause BSD: http://www.opensource.org/licenses/bsd-license.php
96 static const gchar *valid_licenses[] = {
97 "LGPL", /* GNU Lesser General Public License */
98 "GPL", /* GNU General Public License */
99 "QPL", /* Trolltech Qt Public License */
100 "GPL/QPL", /* Combi-license of GPL + QPL */
101 "MPL", /* MPL 1.1 license */
102 "BSD", /* 3-clause BSD license */
103 "MIT/X11", /* MIT/X11 license */
104 "Proprietary", /* Proprietary license */
105 GST_LICENSE_UNKNOWN, /* some other license */
109 static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
110 const GstPluginDesc * desc);
111 static void gst_plugin_desc_copy (GstPluginDesc * dest,
112 const GstPluginDesc * src);
113 static void gst_plugin_desc_free (GstPluginDesc * desc);
116 G_DEFINE_TYPE (GstPlugin, gst_plugin, GST_TYPE_OBJECT);
119 gst_plugin_init (GstPlugin * plugin)
121 /* do nothing, needed because of G_DEFINE_TYPE */
125 gst_plugin_finalize (GObject * object)
127 GstPlugin *plugin = GST_PLUGIN_CAST (object);
128 GstRegistry *registry = gst_registry_get_default ();
131 GST_DEBUG ("finalizing plugin %p", plugin);
132 for (g = registry->plugins; g; g = g->next) {
133 if (g->data == (gpointer) plugin) {
134 g_warning ("removing plugin that is still in registry");
137 g_free (plugin->filename);
138 g_free (plugin->basename);
139 gst_plugin_desc_free (&plugin->desc);
141 G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
145 gst_plugin_class_init (GstPluginClass * klass)
147 G_OBJECT_CLASS (klass)->finalize = GST_DEBUG_FUNCPTR (gst_plugin_finalize);
151 gst_plugin_error_quark (void)
153 static GQuark quark = 0;
156 quark = g_quark_from_static_string ("gst_plugin_error");
160 #ifndef GST_REMOVE_DEPRECATED
161 /* this function can be called in the GCC constructor extension, before
162 * the _gst_plugin_initialize() was called. In that case, we store the
163 * plugin description in a list to initialize it when we open the main
165 * When the main module is known, we can register the plugin right away.
168 _gst_plugin_register_static (GstPluginDesc * desc)
170 g_return_if_fail (desc != NULL);
172 if (!_gst_plugin_inited) {
173 /* We can't use any GLib functions here, since g_thread_init hasn't been
174 * called yet, and we can't call it here either, or programs that don't
175 * guard their g_thread_init calls in main() will just abort */
176 ++_num_static_plugins;
178 realloc (_static_plugins, _num_static_plugins * sizeof (GstPluginDesc));
179 /* assume strings in the GstPluginDesc are static const or live forever */
180 _static_plugins[_num_static_plugins - 1] = *desc;
182 gst_plugin_register_static (desc->major_version, desc->minor_version,
183 desc->name, desc->description, desc->plugin_init, desc->version,
184 desc->license, desc->source, desc->package, desc->origin);
190 * gst_plugin_register_static:
191 * @major_version: the major version number of the GStreamer core that the
192 * plugin was compiled for, you can just use GST_VERSION_MAJOR here
193 * @minor_version: the minor version number of the GStreamer core that the
194 * plugin was compiled for, you can just use GST_VERSION_MINOR here
195 * @name: a unique name of the plugin (ideally prefixed with an application- or
196 * library-specific namespace prefix in order to avoid name conflicts in
197 * case a similar plugin with the same name ever gets added to GStreamer)
198 * @description: description of the plugin
199 * @init_func: pointer to the init function of this plugin.
200 * @version: version string of the plugin
201 * @license: effective license of plugin. Must be one of the approved licenses
202 * (see #GstPluginDesc above) or the plugin will not be registered.
203 * @source: source module plugin belongs to
204 * @package: shipped package plugin belongs to
205 * @origin: URL to provider of plugin
207 * Registers a static plugin, ie. a plugin which is private to an application
208 * or library and contained within the application or library (as opposed to
209 * being shipped as a separate module file).
211 * You must make sure that GStreamer has been initialised (with gst_init() or
212 * via gst_init_get_option_group()) before calling this function.
214 * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
219 gst_plugin_register_static (gint major_version, gint minor_version,
220 const gchar * name, gchar * description, GstPluginInitFunc init_func,
221 const gchar * version, const gchar * license, const gchar * source,
222 const gchar * package, const gchar * origin)
224 GstPluginDesc desc = { major_version, minor_version, name, description,
225 init_func, version, license, source, package, origin,
228 gboolean res = FALSE;
230 g_return_val_if_fail (name != NULL, FALSE);
231 g_return_val_if_fail (description != NULL, FALSE);
232 g_return_val_if_fail (init_func != NULL, FALSE);
233 g_return_val_if_fail (version != NULL, FALSE);
234 g_return_val_if_fail (license != NULL, FALSE);
235 g_return_val_if_fail (source != NULL, FALSE);
236 g_return_val_if_fail (package != NULL, FALSE);
237 g_return_val_if_fail (origin != NULL, FALSE);
239 /* make sure gst_init() has been called */
240 g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
242 GST_LOG ("attempting to load static plugin \"%s\" now...", name);
243 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
244 if (gst_plugin_register_func (plugin, &desc) != NULL) {
245 GST_INFO ("registered static plugin \"%s\"", name);
246 res = gst_default_registry_add_plugin (plugin);
247 GST_INFO ("added static plugin \"%s\", result: %d", name, res);
253 _gst_plugin_initialize (void)
257 _gst_plugin_inited = TRUE;
259 /* now register all static plugins */
260 GST_INFO ("registering %u static plugins", _num_static_plugins);
261 for (i = 0; i < _num_static_plugins; ++i) {
262 gst_plugin_register_static (_static_plugins[i].major_version,
263 _static_plugins[i].minor_version, _static_plugins[i].name,
264 _static_plugins[i].description, _static_plugins[i].plugin_init,
265 _static_plugins[i].version, _static_plugins[i].license,
266 _static_plugins[i].source, _static_plugins[i].package,
267 _static_plugins[i].origin);
270 if (_static_plugins) {
271 free (_static_plugins);
272 _static_plugins = NULL;
273 _num_static_plugins = 0;
277 /* this function could be extended to check if the plugin license matches the
278 * applications license (would require the app to register its license somehow).
279 * We'll wait for someone who's interested in it to code it :)
282 gst_plugin_check_license (const gchar * license)
284 const gchar **check_license = valid_licenses;
286 g_assert (check_license);
288 while (*check_license) {
289 if (strcmp (license, *check_license) == 0)
297 gst_plugin_check_version (gint major, gint minor)
299 /* return NULL if the major and minor version numbers are not compatible */
301 if (major != GST_VERSION_MAJOR || minor != GST_VERSION_MINOR)
308 gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc)
310 if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
312 GST_WARNING ("plugin \"%s\" has incompatible version, not loading",
317 if (!desc->license || !desc->description || !desc->source ||
318 !desc->package || !desc->origin) {
320 GST_WARNING ("plugin \"%s\" has incorrect GstPluginDesc, not loading",
325 if (!gst_plugin_check_license (desc->license)) {
327 GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
328 plugin->filename, desc->license);
333 GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
335 gst_plugin_desc_copy (&plugin->desc, desc);
337 if (!((desc->plugin_init) (plugin))) {
339 GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
340 plugin->module = NULL;
345 GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
350 #ifdef HAVE_SIGACTION
351 static struct sigaction oldaction;
354 * _gst_plugin_fault_handler_restore:
355 * segfault handler restorer
358 _gst_plugin_fault_handler_restore (void)
360 if (!_gst_plugin_fault_handler_is_setup)
363 _gst_plugin_fault_handler_is_setup = FALSE;
365 sigaction (SIGSEGV, &oldaction, NULL);
369 * _gst_plugin_fault_handler_sighandler:
370 * segfault handler implementation
373 _gst_plugin_fault_handler_sighandler (int signum)
375 /* We need to restore the fault handler or we'll keep getting it */
376 _gst_plugin_fault_handler_restore ();
380 g_print ("\nERROR: ");
381 g_print ("Caught a segmentation fault while loading plugin file:\n");
382 g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
383 g_print ("Please either:\n");
384 g_print ("- remove it and restart.\n");
385 g_print ("- run with --gst-disable-segtrap and debug.\n");
389 g_print ("Caught unhandled signal on plugin loading\n");
395 * _gst_plugin_fault_handler_setup:
396 * sets up the segfault handler
399 _gst_plugin_fault_handler_setup (void)
401 struct sigaction action;
403 /* if asked to leave segfaults alone, just return */
404 if (!gst_segtrap_is_enabled ())
407 if (_gst_plugin_fault_handler_is_setup)
410 _gst_plugin_fault_handler_is_setup = TRUE;
412 memset (&action, 0, sizeof (action));
413 action.sa_handler = _gst_plugin_fault_handler_sighandler;
415 sigaction (SIGSEGV, &action, &oldaction);
419 _gst_plugin_fault_handler_restore (void)
424 _gst_plugin_fault_handler_setup (void)
429 static void _gst_plugin_fault_handler_setup ();
431 static GStaticMutex gst_plugin_loading_mutex = G_STATIC_MUTEX_INIT;
434 * gst_plugin_load_file:
435 * @filename: the plugin filename to load
436 * @error: pointer to a NULL-valued GError
438 * Loads the given plugin and refs it. Caller needs to unref after use.
440 * Returns: a reference to the existing loaded GstPlugin, a reference to the
441 * newly-loaded GstPlugin, or NULL if an error occurred.
444 gst_plugin_load_file (const gchar * filename, GError ** error)
450 struct stat file_status;
451 GstRegistry *registry;
453 g_return_val_if_fail (filename != NULL, NULL);
455 registry = gst_registry_get_default ();
456 g_static_mutex_lock (&gst_plugin_loading_mutex);
458 plugin = gst_registry_lookup (registry, filename);
460 if (plugin->module) {
461 g_static_mutex_unlock (&gst_plugin_loading_mutex);
464 gst_object_unref (plugin);
469 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
472 if (g_module_supported () == FALSE) {
473 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
476 GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
480 if (g_stat (filename, &file_status)) {
481 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
484 GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
489 module = g_module_open (filename, G_MODULE_BIND_LOCAL);
490 if (module == NULL) {
491 GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
494 GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
496 /* If we failed to open the shared object, then it's probably because a
497 * plugin is linked against the wrong libraries. Print out an easy-to-see
498 * message in this case. */
499 g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
503 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
505 plugin->module = module;
506 plugin->filename = g_strdup (filename);
507 plugin->basename = g_path_get_basename (filename);
508 plugin->file_mtime = file_status.st_mtime;
509 plugin->file_size = file_status.st_size;
511 ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
513 GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
516 GST_PLUGIN_ERROR_MODULE,
517 "File \"%s\" is not a GStreamer plugin", filename);
518 g_module_close (module);
521 plugin->orig_desc = (GstPluginDesc *) ptr;
523 GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
526 /* this is where we load the actual .so, so let's trap SIGSEGV */
527 _gst_plugin_fault_handler_setup ();
528 _gst_plugin_fault_handler_filename = plugin->filename;
530 GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
533 if (!gst_plugin_register_func (plugin, plugin->orig_desc)) {
534 /* remove signal handler */
535 _gst_plugin_fault_handler_restore ();
536 GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
540 GST_PLUGIN_ERROR_MODULE,
541 "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
543 g_module_close (module);
547 /* remove signal handler */
548 _gst_plugin_fault_handler_restore ();
549 _gst_plugin_fault_handler_filename = NULL;
550 GST_INFO ("plugin \"%s\" loaded", plugin->filename);
552 gst_object_ref (plugin);
553 gst_default_registry_add_plugin (plugin);
555 g_static_mutex_unlock (&gst_plugin_loading_mutex);
561 gst_object_unref (plugin);
562 g_static_mutex_unlock (&gst_plugin_loading_mutex);
568 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
570 dest->major_version = src->major_version;
571 dest->minor_version = src->minor_version;
572 dest->name = g_intern_string (src->name);
573 /* maybe intern the description too, just for convenience? */
574 dest->description = g_strdup (src->description);
575 dest->plugin_init = src->plugin_init;
576 dest->version = g_intern_string (src->version);
577 dest->license = g_intern_string (src->license);
578 dest->source = g_intern_string (src->source);
579 dest->package = g_intern_string (src->package);
580 dest->origin = g_intern_string (src->origin);
585 gst_plugin_desc_free (GstPluginDesc * desc)
587 g_free (desc->description);
588 memset (desc, 0, sizeof (GstPluginDesc));
592 * gst_plugin_get_name:
593 * @plugin: plugin to get the name of
595 * Get the short name of the plugin
597 * Returns: the name of the plugin
600 gst_plugin_get_name (GstPlugin * plugin)
602 g_return_val_if_fail (plugin != NULL, NULL);
604 return plugin->desc.name;
608 * gst_plugin_get_description:
609 * @plugin: plugin to get long name of
611 * Get the long descriptive name of the plugin
613 * Returns: the long name of the plugin
615 G_CONST_RETURN gchar *
616 gst_plugin_get_description (GstPlugin * plugin)
618 g_return_val_if_fail (plugin != NULL, NULL);
620 return plugin->desc.description;
624 * gst_plugin_get_filename:
625 * @plugin: plugin to get the filename of
627 * get the filename of the plugin
629 * Returns: the filename of the plugin
631 G_CONST_RETURN gchar *
632 gst_plugin_get_filename (GstPlugin * plugin)
634 g_return_val_if_fail (plugin != NULL, NULL);
636 return plugin->filename;
640 * gst_plugin_get_version:
641 * @plugin: plugin to get the version of
643 * get the version of the plugin
645 * Returns: the version of the plugin
647 G_CONST_RETURN gchar *
648 gst_plugin_get_version (GstPlugin * plugin)
650 g_return_val_if_fail (plugin != NULL, NULL);
652 return plugin->desc.version;
656 * gst_plugin_get_license:
657 * @plugin: plugin to get the license of
659 * get the license of the plugin
661 * Returns: the license of the plugin
663 G_CONST_RETURN gchar *
664 gst_plugin_get_license (GstPlugin * plugin)
666 g_return_val_if_fail (plugin != NULL, NULL);
668 return plugin->desc.license;
672 * gst_plugin_get_source:
673 * @plugin: plugin to get the source of
675 * get the source module the plugin belongs to.
677 * Returns: the source of the plugin
679 G_CONST_RETURN gchar *
680 gst_plugin_get_source (GstPlugin * plugin)
682 g_return_val_if_fail (plugin != NULL, NULL);
684 return plugin->desc.source;
688 * gst_plugin_get_package:
689 * @plugin: plugin to get the package of
691 * get the package the plugin belongs to.
693 * Returns: the package of the plugin
695 G_CONST_RETURN gchar *
696 gst_plugin_get_package (GstPlugin * plugin)
698 g_return_val_if_fail (plugin != NULL, NULL);
700 return plugin->desc.package;
704 * gst_plugin_get_origin:
705 * @plugin: plugin to get the origin of
707 * get the URL where the plugin comes from
709 * Returns: the origin of the plugin
711 G_CONST_RETURN gchar *
712 gst_plugin_get_origin (GstPlugin * plugin)
714 g_return_val_if_fail (plugin != NULL, NULL);
716 return plugin->desc.origin;
720 * gst_plugin_get_module:
721 * @plugin: plugin to query
723 * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is
726 * Returns: module belonging to the plugin or NULL if the plugin isn't
730 gst_plugin_get_module (GstPlugin * plugin)
732 g_return_val_if_fail (plugin != NULL, NULL);
734 return plugin->module;
738 * gst_plugin_is_loaded:
739 * @plugin: plugin to query
741 * queries if the plugin is loaded into memory
743 * Returns: TRUE is loaded, FALSE otherwise
746 gst_plugin_is_loaded (GstPlugin * plugin)
748 g_return_val_if_fail (plugin != NULL, FALSE);
750 return (plugin->module != NULL || plugin->filename == NULL);
755 * gst_plugin_feature_list:
756 * @plugin: plugin to query
757 * @filter: the filter to use
758 * @first: only return first match
759 * @user_data: user data passed to the filter function
761 * Runs a filter against all plugin features and returns a GList with
762 * the results. If the first flag is set, only the first match is
763 * returned (as a list with a single object).
765 * Returns: a GList of features, g_list_free after use.
768 gst_plugin_feature_filter (GstPlugin * plugin,
769 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
774 list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
776 for (g = list; g; g = g->next) {
777 gst_object_ref (plugin);
785 GstPluginFeatureFilter filter;
793 _feature_filter (GstPlugin * plugin, gpointer user_data)
796 FeatureFilterData *data = (FeatureFilterData *) user_data;
798 result = gst_plugin_feature_filter (plugin, data->filter, data->first,
801 data->result = g_list_concat (data->result, result);
808 * gst_plugin_list_feature_filter:
809 * @list: a #GList of plugins to query
810 * @filter: the filter function to use
811 * @first: only return first match
812 * @user_data: user data passed to the filter function
814 * Runs a filter against all plugin features of the plugins in the given
815 * list and returns a GList with the results.
816 * If the first flag is set, only the first match is
817 * returned (as a list with a single object).
819 * Returns: a GList of features, g_list_free after use.
822 gst_plugin_list_feature_filter (GList * list,
823 GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
825 FeatureFilterData data;
828 data.filter = filter;
830 data.user_data = user_data;
833 result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
834 g_list_free (result);
841 * gst_plugin_name_filter:
842 * @plugin: the plugin to check
843 * @name: the name of the plugin
845 * A standard filter that returns TRUE when the plugin is of the
848 * Returns: TRUE if the plugin is of the given name.
851 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
853 return (plugin->desc.name && !strcmp (plugin->desc.name, name));
858 * gst_plugin_find_feature:
859 * @plugin: plugin to get the feature from
860 * @name: The name of the feature to find
861 * @type: The type of the feature to find
863 * Find a feature of the given name and type in the given plugin.
865 * Returns: a GstPluginFeature or NULL if the feature was not found.
868 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
871 GstPluginFeature *result = NULL;
872 GstTypeNameData data;
874 g_return_val_if_fail (name != NULL, NULL);
879 walk = gst_filter_run (plugin->features,
880 (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
883 result = GST_PLUGIN_FEATURE (walk->data);
885 gst_object_ref (result);
886 gst_plugin_feature_list_free (walk);
895 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
897 return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
903 * gst_plugin_find_feature_by_name:
904 * @plugin: plugin to get the feature from
905 * @name: The name of the feature to find
907 * Find a feature of the given name in the given plugin.
909 * Returns: a GstPluginFeature or NULL if the feature was not found.
912 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
915 GstPluginFeature *result = NULL;
917 g_return_val_if_fail (name != NULL, NULL);
919 walk = gst_filter_run (plugin->features,
920 (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
923 result = GST_PLUGIN_FEATURE (walk->data);
925 gst_object_ref (result);
926 gst_plugin_feature_list_free (walk);
934 * gst_plugin_load_by_name:
935 * @name: name of plugin to load
937 * Load the named plugin. Refs the plugin.
939 * Returns: A reference to a loaded plugin, or NULL on error.
942 gst_plugin_load_by_name (const gchar * name)
944 GstPlugin *plugin, *newplugin;
945 GError *error = NULL;
947 GST_DEBUG ("looking up plugin %s in default registry", name);
948 plugin = gst_registry_find_plugin (gst_registry_get_default (), name);
950 GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
951 newplugin = gst_plugin_load_file (plugin->filename, &error);
952 gst_object_unref (plugin);
955 GST_WARNING ("load_plugin error: %s", error->message);
956 g_error_free (error);
959 /* newplugin was reffed by load_file */
963 GST_DEBUG ("Could not find plugin %s in registry", name);
969 * @plugin: plugin to load
971 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
972 * untouched. The normal use pattern of this function goes like this:
975 * GstPlugin *loaded_plugin;
976 * loaded_plugin = gst_plugin_load (plugin);
977 * // presumably, we're no longer interested in the potentially-unloaded plugin
978 * gst_object_unref (plugin);
979 * plugin = loaded_plugin;
982 * Returns: A reference to a loaded plugin, or NULL on error.
985 gst_plugin_load (GstPlugin * plugin)
987 GError *error = NULL;
988 GstPlugin *newplugin;
990 if (gst_plugin_is_loaded (plugin)) {
994 if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
1001 GST_WARNING ("load_plugin error: %s", error->message);
1002 g_error_free (error);
1008 * gst_plugin_list_free:
1009 * @list: list of #GstPlugin
1011 * Unrefs each member of @list, then frees the list.
1014 gst_plugin_list_free (GList * list)
1018 for (g = list; g; g = g->next) {
1019 gst_object_unref (GST_PLUGIN_CAST (g->data));