fix instances in core before making this an error
[platform/upstream/gstreamer.git] / gst / gstplugin.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstplugin.c: Plugin subsystem for loading elements, types, and libs
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #ifdef HAVE_DIRENT_H
29 #include <dirent.h>
30 #endif
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
34 #include <signal.h>
35
36 #include "gst_private.h"
37
38 #include "gstplugin.h"
39 #include "gstversion.h"
40 #include "gstregistrypool.h"
41 #include "gstinfo.h"
42 #include "gstfilter.h"
43
44
45 #define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
46
47 static GModule *main_module = NULL;
48 static GList *_gst_plugin_static = NULL;
49
50 /* static variables for segfault handling of plugin loading */
51 static char *_gst_plugin_fault_handler_filename = NULL;
52 extern gboolean *_gst_disable_segtrap;  /* see gst.c */
53
54 #ifndef HAVE_WIN32
55 static gboolean *_gst_plugin_fault_handler_is_setup = FALSE;
56 #endif
57
58 /* list of valid licenses.
59  * One of these must be specified or the plugin won't be loaded 
60  * Contact gstreamer-devel@lists.sourceforge.net if your license should be 
61  * added.
62  *
63  * GPL: http://www.gnu.org/copyleft/gpl.html
64  * LGPL: http://www.gnu.org/copyleft/lesser.html
65  * QPL: http://www.trolltech.com/licenses/qpl.html
66  */
67 static gchar *valid_licenses[] = {
68   "LGPL",                       /* GNU Lesser General Public License */
69   "GPL",                        /* GNU General Public License */
70   "QPL",                        /* Trolltech Qt Public License */
71   "GPL/QPL",                    /* Combi-license of GPL + QPL */
72   GST_LICENSE_UNKNOWN,          /* some other license */
73   NULL
74 };
75
76 static void gst_plugin_desc_copy (GstPluginDesc * dest,
77     const GstPluginDesc * src);
78
79 static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
80     GModule * module, GstPluginDesc * desc);
81
82 static GstPlugin *
83 gst_plugin_copy (GstPlugin * plugin)
84 {
85   return g_memdup (plugin, sizeof (*plugin));
86 }
87
88 GType
89 gst_plugin_get_type (void)
90 {
91   static GType plugin_type;
92
93   if (plugin_type == 0) {
94     plugin_type = g_boxed_type_register_static ("GstPlugin",
95         (GBoxedCopyFunc) gst_plugin_copy, g_free);
96   }
97
98   return plugin_type;
99 }
100
101 GQuark
102 gst_plugin_error_quark (void)
103 {
104   static GQuark quark = 0;
105
106   if (!quark)
107     quark = g_quark_from_static_string ("gst_plugin_error");
108   return quark;
109 }
110
111 /* this function can be called in the GCC constructor extension, before
112  * the _gst_plugin_initialize() was called. In that case, we store the 
113  * plugin description in a list to initialize it when we open the main
114  * module later on.
115  * When the main module is known, we can register the plugin right away.
116  * */
117 void
118 _gst_plugin_register_static (GstPluginDesc * desc)
119 {
120   if (main_module == NULL) {
121     if (GST_CAT_DEFAULT)
122       GST_LOG ("queueing static plugin \"%s\" for loading later on",
123           desc->name);
124     _gst_plugin_static = g_list_prepend (_gst_plugin_static, desc);
125   } else {
126     GstPlugin *plugin;
127
128     if (GST_CAT_DEFAULT)
129       GST_LOG ("attempting to load static plugin \"%s\" now...", desc->name);
130     plugin = g_new0 (GstPlugin, 1);
131     if (gst_plugin_register_func (plugin, main_module, desc)) {
132       if (GST_CAT_DEFAULT)
133         GST_INFO ("loaded static plugin \"%s\"", desc->name);
134       gst_registry_pool_add_plugin (plugin);
135     }
136   }
137 }
138
139 void
140 _gst_plugin_initialize (void)
141 {
142   main_module = g_module_open (NULL, G_MODULE_BIND_LAZY);
143
144   /* now register all static plugins */
145   g_list_foreach (_gst_plugin_static, (GFunc) _gst_plugin_register_static,
146       NULL);
147 }
148
149 /* this function could be extended to check if the plugin license matches the 
150  * applications license (would require the app to register its license somehow).
151  * We'll wait for someone who's interested in it to code it :)
152  */
153 static gboolean
154 gst_plugin_check_license (const gchar * license)
155 {
156   gchar **check_license = valid_licenses;
157
158   g_assert (check_license);
159
160   while (*check_license) {
161     if (strcmp (license, *check_license) == 0)
162       return TRUE;
163     check_license++;
164   }
165   return FALSE;
166 }
167
168 static gboolean
169 gst_plugin_check_version (gint major, gint minor)
170 {
171   /* return NULL if the major and minor version numbers are not compatible */
172   /* with ours. */
173   if (major != GST_VERSION_MAJOR || minor != GST_VERSION_MINOR)
174     return FALSE;
175
176   return TRUE;
177 }
178
179 static GstPlugin *
180 gst_plugin_register_func (GstPlugin * plugin, GModule * module,
181     GstPluginDesc * desc)
182 {
183   g_assert (plugin->module == NULL);
184
185   if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
186     if (GST_CAT_DEFAULT)
187       GST_INFO ("plugin \"%s\" has incompatible version, not loading",
188           plugin->filename);
189     return FALSE;
190   }
191
192   if (!desc->license || !desc->description || !desc->package || !desc->origin) {
193     if (GST_CAT_DEFAULT)
194       GST_INFO ("plugin \"%s\" has incorrect GstPluginDesc, not loading",
195           plugin->filename);
196     return FALSE;
197   }
198
199   if (!gst_plugin_check_license (desc->license)) {
200     if (GST_CAT_DEFAULT)
201       GST_INFO ("plugin \"%s\" has invalid license \"%s\", not loading",
202           plugin->filename, desc->license);
203     return FALSE;
204   }
205
206   gst_plugin_desc_copy (&plugin->desc, desc);
207   plugin->module = module;
208
209   if (!((desc->plugin_init) (plugin))) {
210     if (GST_CAT_DEFAULT)
211       GST_INFO ("plugin \"%s\" failed to initialise", plugin->filename);
212     plugin->module = NULL;
213     return FALSE;
214   }
215
216   if (GST_CAT_DEFAULT)
217     GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
218
219   return plugin;
220 }
221
222 #ifndef HAVE_WIN32
223 /*
224  * _gst_plugin_fault_handler_restore:
225  * segfault handler restorer
226  */
227 static void
228 _gst_plugin_fault_handler_restore (void)
229 {
230   struct sigaction action;
231
232   memset (&action, 0, sizeof (action));
233   action.sa_handler = SIG_DFL;
234
235   sigaction (SIGSEGV, &action, NULL);
236 }
237
238 /*
239  * _gst_plugin_fault_handler_sighandler:
240  * segfault handler implementation
241  */
242 static void
243 _gst_plugin_fault_handler_sighandler (int signum)
244 {
245   /* We need to restore the fault handler or we'll keep getting it */
246   _gst_plugin_fault_handler_restore ();
247
248   switch (signum) {
249     case SIGSEGV:
250       g_print ("\nERROR: ");
251       g_print ("Caught a segmentation fault while loading plugin file:\n");
252       g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
253       g_print ("Please either:\n");
254       g_print ("- remove it and restart.\n");
255       g_print ("- run with --gst-disable-segtrap and debug.\n");
256       exit (-1);
257       break;
258     default:
259       g_print ("Caught unhandled signal on plugin loading\n");
260       break;
261   }
262 }
263
264 /*
265  * _gst_plugin_fault_handler_setup:
266  * sets up the segfault handler
267  */
268 static void
269 _gst_plugin_fault_handler_setup (void)
270 {
271   struct sigaction action;
272
273   /* if asked to leave segfaults alone, just return */
274   if (_gst_disable_segtrap)
275     return;
276
277   if (_gst_plugin_fault_handler_is_setup)
278     return;
279
280   memset (&action, 0, sizeof (action));
281   action.sa_handler = _gst_plugin_fault_handler_sighandler;
282
283   sigaction (SIGSEGV, &action, NULL);
284 }
285 #else
286 static void
287 _gst_plugin_fault_handler_restore (void)
288 {
289 }
290
291 static void
292 _gst_plugin_fault_handler_setup (void)
293 {
294 }
295 #endif
296
297 static void _gst_plugin_fault_handler_setup ();
298
299 /**
300  * gst_plugin_check_file:
301  * @filename: the plugin filename to check for pluginness
302  * @error: pointer to a NULL-valued GError
303  *
304  * Checks if the given path represents a GStreamer plugin.
305  *
306  * Returns: TRUE if the given path is a GStreamer plugin.
307  */
308 gboolean
309 gst_plugin_check_file (const gchar * filename, GError ** error)
310 {
311   GModule *module;
312   struct stat file_status;
313   gpointer ptr;
314
315   g_return_val_if_fail (filename != NULL, FALSE);
316
317   if (g_module_supported () == FALSE) {
318     g_set_error (error,
319         GST_PLUGIN_ERROR,
320         GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
321     return FALSE;
322   }
323
324   if (stat (filename, &file_status)) {
325     g_set_error (error,
326         GST_PLUGIN_ERROR,
327         GST_PLUGIN_ERROR_MODULE, "Problem opening file %s\n", filename);
328     return FALSE;
329   }
330
331   module = g_module_open (filename, G_MODULE_BIND_LAZY);
332
333   if (module == NULL) {
334     GST_DEBUG ("Error loading plugin %s, reason: %s\n", filename,
335         g_module_error ());
336     g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
337         "Error loading plugin %s, reason: %s\n", filename, g_module_error ());
338     return FALSE;
339   }
340
341   if (!g_module_symbol (module, "gst_plugin_desc", &ptr)) {
342     GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
343     g_set_error (error,
344         GST_PLUGIN_ERROR,
345         GST_PLUGIN_ERROR_MODULE,
346         "Could not find plugin entry point in \"%s\"", filename);
347     g_module_close (module);
348     return FALSE;
349   }
350   /* it's a plugin */
351   g_module_close (module);
352   return TRUE;
353 }
354
355 /**
356  * gst_plugin_load_file:
357  * @filename: the plugin filename to load
358  * @error: pointer to a NULL-valued GError
359  *
360  * Loads the given plugin.
361  *
362  * Returns: a new GstPlugin or NULL, if an error occurred.
363  */
364 GstPlugin *
365 gst_plugin_load_file (const gchar * filename, GError ** error)
366 {
367   GstPlugin *plugin;
368   GModule *module;
369   GstPluginDesc *desc;
370   gboolean free_plugin;
371   gpointer ptr;
372
373   g_return_val_if_fail (filename != NULL, NULL);
374
375   GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
376       filename);
377
378   if (!gst_plugin_check_file (filename, error))
379     return NULL;
380
381   module = g_module_open (filename, G_MODULE_BIND_LAZY);
382
383   if (module == NULL)
384     goto load_error;
385
386   if (!g_module_symbol (module, "gst_plugin_desc", &ptr))
387     goto load_error;
388
389   desc = (GstPluginDesc *) ptr;
390
391   plugin = gst_registry_pool_find_plugin (desc->name);
392   if (!plugin) {
393     free_plugin = TRUE;
394     plugin = g_new0 (GstPlugin, 1);
395     plugin->filename = g_strdup (filename);
396     GST_DEBUG ("created new GstPlugin %p for file \"%s\"", plugin, filename);
397   } else {
398     free_plugin = FALSE;
399     if (gst_plugin_is_loaded (plugin)) {
400       if (plugin->filename && strcmp (plugin->filename, filename) != 0) {
401         GST_WARNING
402             ("plugin %p from file \"%s\" with same name %s is already "
403             "loaded, aborting loading of \"%s\"", plugin, plugin->filename,
404             plugin->desc.name, filename);
405         g_set_error (error, GST_PLUGIN_ERROR,
406             GST_PLUGIN_ERROR_NAME_MISMATCH,
407             "plugin %p from file \"%s\" with same name %s is already "
408             "loaded, aborting loading of \"%s\"", plugin, plugin->filename,
409             plugin->desc.name, filename);
410         if (free_plugin)
411           g_free (plugin);
412         return NULL;
413       }
414       GST_LOG ("Plugin %p for file \"%s\" already loaded, returning it now",
415           plugin, filename);
416       return plugin;
417     }
418   }
419   GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
420       plugin, filename);
421
422   if (g_module_symbol (module, "plugin_init", &ptr)) {
423     g_print
424         ("plugin %p from file \"%s\" exports a symbol named plugin_init\n",
425         plugin, plugin->filename);
426     g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_NAME_MISMATCH,
427         "plugin \"%s\" exports a symbol named plugin_init", desc->name);
428   }
429
430   /* this is where we load the actual .so, so let's trap SIGSEGV */
431   _gst_plugin_fault_handler_setup ();
432   _gst_plugin_fault_handler_filename = plugin->filename;
433
434   if (gst_plugin_register_func (plugin, module, desc)) {
435     /* remove signal handler */
436     _gst_plugin_fault_handler_restore ();
437     _gst_plugin_fault_handler_filename = NULL;
438     GST_INFO ("plugin \"%s\" loaded", plugin->filename);
439     return plugin;
440   } else {
441     /* remove signal handler */
442     _gst_plugin_fault_handler_restore ();
443     GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
444     /* plugin == NULL */
445     g_set_error (error,
446         GST_PLUGIN_ERROR,
447         GST_PLUGIN_ERROR_MODULE,
448         "gst_plugin_register_func failed for plugin \"%s\"", filename);
449     if (free_plugin)
450       g_free (plugin);
451     return NULL;
452   }
453 load_error:
454   g_set_error (error,
455       GST_PLUGIN_ERROR,
456       GST_PLUGIN_ERROR_MODULE, "generic load error for \"%s\"", filename);
457   return NULL;
458 }
459
460 static void
461 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
462 {
463   dest->major_version = src->major_version;
464   dest->minor_version = src->minor_version;
465   g_free (dest->name);
466   dest->name = g_strdup (src->name);
467   g_free (dest->description);
468   dest->description = g_strdup (src->description);
469   dest->plugin_init = src->plugin_init;
470   dest->plugin_exit = src->plugin_exit;
471   g_free (dest->version);
472   dest->version = g_strdup (src->version);
473   g_free (dest->license);
474   dest->license = g_strdup (src->license);
475   g_free (dest->package);
476   dest->package = g_strdup (src->package);
477   g_free (dest->origin);
478   dest->origin = g_strdup (src->origin);
479 }
480
481 #if 0
482 /* unused */
483 static void
484 gst_plugin_desc_free (GstPluginDesc * desc)
485 {
486   g_free (desc->name);
487   g_free (desc->description);
488   g_free (desc->version);
489   g_free (desc->license);
490   g_free (desc->package);
491   g_free (desc->origin);
492
493   memset (desc, 0, sizeof (GstPluginDesc));
494 }
495 #endif
496 /**
497  * gst_plugin_unload_plugin:
498  * @plugin: The plugin to unload
499  *
500  * Unload the given plugin.
501  *
502  * Returns: whether or not the plugin unloaded
503  */
504 gboolean
505 gst_plugin_unload_plugin (GstPlugin * plugin)
506 {
507   g_return_val_if_fail (plugin != NULL, FALSE);
508
509   if (!plugin->module)
510     return TRUE;
511
512   if (g_module_close (plugin->module)) {
513     plugin->module = NULL;
514     GST_CAT_INFO (GST_CAT_PLUGIN_LOADING, "plugin \"%s\" unloaded",
515         plugin->filename);
516     return TRUE;
517   } else {
518     GST_CAT_INFO (GST_CAT_PLUGIN_LOADING, "failed to unload plugin \"%s\"",
519         plugin->filename);
520     return FALSE;
521   }
522 }
523
524 /**
525  * gst_plugin_get_name:
526  * @plugin: plugin to get the name of
527  *
528  * Get the short name of the plugin
529  *
530  * Returns: the name of the plugin
531  */
532 const gchar *
533 gst_plugin_get_name (GstPlugin * plugin)
534 {
535   g_return_val_if_fail (plugin != NULL, NULL);
536
537   return plugin->desc.name;
538 }
539
540 /**
541  * gst_plugin_get_description:
542  * @plugin: plugin to get long name of
543  *
544  * Get the long descriptive name of the plugin
545  *
546  * Returns: the long name of the plugin
547  */
548 G_CONST_RETURN gchar *
549 gst_plugin_get_description (GstPlugin * plugin)
550 {
551   g_return_val_if_fail (plugin != NULL, NULL);
552
553   return plugin->desc.description;
554 }
555
556 /**
557  * gst_plugin_get_filename:
558  * @plugin: plugin to get the filename of
559  *
560  * get the filename of the plugin
561  *
562  * Returns: the filename of the plugin
563  */
564 G_CONST_RETURN gchar *
565 gst_plugin_get_filename (GstPlugin * plugin)
566 {
567   g_return_val_if_fail (plugin != NULL, NULL);
568
569   return plugin->filename;
570 }
571
572 /**
573  * gst_plugin_get_license:
574  * @plugin: plugin to get the license of
575  *
576  * get the license of the plugin
577  *
578  * Returns: the license of the plugin
579  */
580 G_CONST_RETURN gchar *
581 gst_plugin_get_license (GstPlugin * plugin)
582 {
583   g_return_val_if_fail (plugin != NULL, NULL);
584
585   return plugin->desc.license;
586 }
587
588 /**
589  * gst_plugin_get_package:
590  * @plugin: plugin to get the package of
591  *
592  * get the package the plugin belongs to.
593  *
594  * Returns: the package of the plugin
595  */
596 G_CONST_RETURN gchar *
597 gst_plugin_get_package (GstPlugin * plugin)
598 {
599   g_return_val_if_fail (plugin != NULL, NULL);
600
601   return plugin->desc.package;
602 }
603
604 /**
605  * gst_plugin_get_origin:
606  * @plugin: plugin to get the origin of
607  *
608  * get the URL where the plugin comes from
609  *
610  * Returns: the origin of the plugin
611  */
612 G_CONST_RETURN gchar *
613 gst_plugin_get_origin (GstPlugin * plugin)
614 {
615   g_return_val_if_fail (plugin != NULL, NULL);
616
617   return plugin->desc.origin;
618 }
619
620 /**
621  * gst_plugin_get_module:
622  * @plugin: plugin to query
623  *
624  * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is 
625  * returned.
626  *
627  * Returns: module belonging to the plugin or NULL if the plugin isn't 
628  *          loaded yet.
629  */
630 GModule *
631 gst_plugin_get_module (GstPlugin * plugin)
632 {
633   g_return_val_if_fail (plugin != NULL, FALSE);
634
635   return plugin->module;
636 }
637
638 /**
639  * gst_plugin_is_loaded:
640  * @plugin: plugin to query
641  *
642  * queries if the plugin is loaded into memory
643  *
644  * Returns: TRUE is loaded, FALSE otherwise
645  */
646 gboolean
647 gst_plugin_is_loaded (GstPlugin * plugin)
648 {
649   g_return_val_if_fail (plugin != NULL, FALSE);
650
651   return (plugin->module != NULL);
652 }
653
654 /**
655  * gst_plugin_feature_list:
656  * @plugin: plugin to query
657  * @filter: the filter to use
658  * @first: only return first match
659  * @user_data: user data passed to the filter function
660  *
661  * Runs a filter against all plugin features and returns a GList with
662  * the results. If the first flag is set, only the first match is 
663  * returned (as a list with a single object).
664  *
665  * Returns: a GList of features, g_list_free after use.
666  */
667 GList *
668 gst_plugin_feature_filter (GstPlugin * plugin,
669     GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
670 {
671   return gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
672       user_data);
673 }
674
675 typedef struct
676 {
677   GstPluginFeatureFilter filter;
678   gboolean first;
679   gpointer user_data;
680   GList *result;
681 }
682 FeatureFilterData;
683
684 static gboolean
685 _feature_filter (GstPlugin * plugin, gpointer user_data)
686 {
687   GList *result;
688   FeatureFilterData *data = (FeatureFilterData *) user_data;
689
690   result =
691       gst_plugin_feature_filter (plugin, data->filter, data->first,
692       data->user_data);
693   if (result) {
694     data->result = g_list_concat (data->result, result);
695     return TRUE;
696   }
697   return FALSE;
698 }
699
700 /**
701  * gst_plugin_list_feature_list:
702  * @list: a list of plugins to query
703  * @filter: the filter to use
704  * @first: only return first match
705  * @user_data: user data passed to the filter function
706  *
707  * Runs a filter against all plugin features of the plugins in the given
708  * list and returns a GList with the results. 
709  * If the first flag is set, only the first match is 
710  * returned (as a list with a single object).
711  *
712  * Returns: a GList of features, g_list_free after use.
713  */
714 GList *
715 gst_plugin_list_feature_filter (GList * list,
716     GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
717 {
718   FeatureFilterData data;
719   GList *result;
720
721   data.filter = filter;
722   data.first = first;
723   data.user_data = user_data;
724   data.result = NULL;
725
726   result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
727   g_list_free (result);
728
729   return data.result;
730 }
731
732 /**
733  * gst_plugin_name_filter:
734  * @plugin: the plugin to check
735  * @name: the name of the plugin
736  *
737  * A standard filter that returns TRUE when the plugin is of the
738  * given name.
739  *
740  * Returns: TRUE if the plugin is of the given name.
741  */
742 gboolean
743 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
744 {
745   return (plugin->desc.name && !strcmp (plugin->desc.name, name));
746 }
747
748 /**
749  * gst_plugin_find_feature:
750  * @plugin: plugin to get the feature from
751  * @name: The name of the feature to find
752  * @type: The type of the feature to find
753  *
754  * Find a feature of the given name and type in the given plugin.
755  *
756  * Returns: a GstPluginFeature or NULL if the feature was not found.
757  */
758 GstPluginFeature *
759 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
760 {
761   GList *walk;
762   GstPluginFeature *result = NULL;
763   GstTypeNameData data;
764
765   g_return_val_if_fail (name != NULL, NULL);
766
767   data.type = type;
768   data.name = name;
769
770   walk = gst_filter_run (plugin->features,
771       (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
772
773   if (walk)
774     result = GST_PLUGIN_FEATURE (walk->data);
775
776   return result;
777 }
778
779 /**
780  * gst_plugin_add_feature:
781  * @plugin: plugin to add feature to
782  * @feature: feature to add
783  *
784  * Add feature to the list of those provided by the plugin.
785  * There is a separate namespace for each plugin feature type.
786  * See #gst_plugin_get_feature_list
787  */
788 void
789 gst_plugin_add_feature (GstPlugin * plugin, GstPluginFeature * feature)
790 {
791   GstPluginFeature *oldfeature;
792
793   /* FIXME 0.9: get reference counting somewhat right in here,
794    * GstPluginFeatures should probably be GstObjects that are sinked when
795    * adding them to a plugin */
796   g_return_if_fail (plugin != NULL);
797   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
798   g_return_if_fail (feature != NULL);
799
800   oldfeature = gst_plugin_find_feature (plugin,
801       GST_PLUGIN_FEATURE_NAME (feature), G_OBJECT_TYPE (feature));
802
803   if (oldfeature == feature) {
804     GST_WARNING ("feature %s has already been added",
805         GST_PLUGIN_FEATURE_NAME (feature));
806     /* g_object_unref (feature); */
807   } else if (oldfeature) {
808     GST_WARNING ("feature %s already present in plugin",
809         GST_PLUGIN_FEATURE_NAME (feature));
810     /* g_object_unref (feature); */
811   } else {
812     feature->manager = plugin;
813     plugin->features = g_list_prepend (plugin->features, feature);
814     plugin->numfeatures++;
815   }
816 }
817
818 /**
819  * gst_plugin_get_feature_list:
820  * @plugin: the plugin to get the features from
821  *
822  * get a list of all the features that this plugin provides
823  *
824  * Returns: a GList of features, use g_list_free to free the list.
825  */
826 GList *
827 gst_plugin_get_feature_list (GstPlugin * plugin)
828 {
829   g_return_val_if_fail (plugin != NULL, NULL);
830
831   return g_list_copy (plugin->features);
832 }
833
834 /**
835  * gst_plugin_load:
836  * @name: name of plugin to load
837  *
838  * Load the named plugin.  
839  *
840  * Returns: whether the plugin was loaded or not
841  */
842 gboolean
843 gst_plugin_load (const gchar * name)
844 {
845   GstPlugin *plugin;
846   GError *error = NULL;
847
848   plugin = gst_registry_pool_find_plugin (name);
849   if (plugin) {
850     gst_plugin_load_file (plugin->filename, &error);
851     if (error) {
852       GST_WARNING ("load_plugin error: %s\n", error->message);
853       g_error_free (error);
854       return FALSE;
855     }
856     return TRUE;;
857   }
858
859   GST_DEBUG ("Could not find %s in registry pool", name);
860   return FALSE;
861 }
862
863 /**
864  * gst_library_load:
865  * @name: name of library to load
866  *
867  * Load the named library.  Name should be given as
868  * &quot;liblibrary.so&quot;.
869  *
870  * Returns: whether the library was loaded or not
871  */
872 gboolean
873 gst_library_load (const gchar * name)
874 {
875   gboolean res;
876
877   /* for now this is the same */
878   res = gst_plugin_load (name);
879
880   return res;
881 }