figure out problem with dynamic
[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_load_file:
301  * @filename: the plugin filename to load
302  * @error: pointer to a NULL-valued GError
303  *
304  * Loads the given plugin.
305  *
306  * Returns: a new GstPlugin or NULL, if an error occurred.
307  */
308 GstPlugin *
309 gst_plugin_load_file (const gchar * filename, GError ** error)
310 {
311   GstPlugin *plugin;
312   GModule *module;
313   GstPluginDesc *desc;
314   struct stat file_status;
315   gboolean free_plugin;
316
317   g_return_val_if_fail (filename != NULL, NULL);
318
319   GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
320       filename);
321
322   if (g_module_supported () == FALSE) {
323     g_set_error (error,
324         GST_PLUGIN_ERROR,
325         GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
326     return NULL;
327   }
328
329   if (stat (filename, &file_status)) {
330     g_set_error (error,
331         GST_PLUGIN_ERROR,
332         GST_PLUGIN_ERROR_MODULE, "Problem opening file %s\n", filename);
333     return NULL;
334   }
335
336   module = g_module_open (filename, G_MODULE_BIND_LAZY);
337
338   if (module != NULL) {
339     gpointer ptr;
340
341     if (g_module_symbol (module, "gst_plugin_desc", &ptr)) {
342       desc = (GstPluginDesc *) ptr;
343
344       plugin = gst_registry_pool_find_plugin (desc->name);
345       if (!plugin) {
346         free_plugin = TRUE;
347         plugin = g_new0 (GstPlugin, 1);
348         plugin->filename = g_strdup (filename);
349         GST_DEBUG ("created new GstPlugin %p for file \"%s\"", plugin,
350             filename);
351       } else {
352         free_plugin = FALSE;
353         if (gst_plugin_is_loaded (plugin)) {
354           if (plugin->filename && strcmp (plugin->filename, filename) != 0) {
355             GST_WARNING
356                 ("plugin %p from file \"%s\" with same name %s is already "
357                 "loaded, aborting loading of \"%s\"", plugin, plugin->filename,
358                 plugin->desc.name, filename);
359             g_set_error (error, GST_PLUGIN_ERROR,
360                 GST_PLUGIN_ERROR_NAME_MISMATCH,
361                 "plugin %p from file \"%s\" with same name %s is already "
362                 "loaded, aborting loading of \"%s\"", plugin, plugin->filename,
363                 plugin->desc.name, filename);
364             if (free_plugin)
365               g_free (plugin);
366             return NULL;
367           }
368           GST_LOG ("Plugin %p for file \"%s\" already loaded, returning it now",
369               plugin, filename);
370           return plugin;
371         }
372       }
373       GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
374           plugin, filename);
375
376       if (g_module_symbol (module, "plugin_init", &ptr)) {
377         g_print
378             ("plugin %p from file \"%s\" exports a symbol named plugin_init\n",
379             plugin, plugin->filename);
380         g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_NAME_MISMATCH,
381             "plugin \"%s\" exports a symbol named plugin_init", desc->name);
382       }
383
384       /* this is where we load the actual .so, so let's trap SIGSEGV */
385       _gst_plugin_fault_handler_setup ();
386       _gst_plugin_fault_handler_filename = plugin->filename;
387
388       if (gst_plugin_register_func (plugin, module, desc)) {
389         /* remove signal handler */
390         _gst_plugin_fault_handler_restore ();
391         _gst_plugin_fault_handler_filename = NULL;
392         GST_INFO ("plugin \"%s\" loaded", plugin->filename);
393         return plugin;
394       } else {
395         /* remove signal handler */
396         _gst_plugin_fault_handler_restore ();
397         GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"",
398             filename);
399         /* plugin == NULL */
400         g_set_error (error,
401             GST_PLUGIN_ERROR,
402             GST_PLUGIN_ERROR_MODULE,
403             "gst_plugin_register_func failed for plugin \"%s\"", filename);
404         if (free_plugin)
405           g_free (plugin);
406         return NULL;
407       }
408     } else {
409       GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
410       g_set_error (error,
411           GST_PLUGIN_ERROR,
412           GST_PLUGIN_ERROR_MODULE,
413           "Could not find plugin entry point in \"%s\"", filename);
414     }
415     return NULL;
416   } else {
417     GST_DEBUG ("Error loading plugin %s, reason: %s\n", filename,
418         g_module_error ());
419     g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
420         "Error loading plugin %s, reason: %s\n", filename, g_module_error ());
421     return NULL;
422   }
423 }
424
425 static void
426 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
427 {
428   dest->major_version = src->major_version;
429   dest->minor_version = src->minor_version;
430   g_free (dest->name);
431   dest->name = g_strdup (src->name);
432   g_free (dest->description);
433   dest->description = g_strdup (src->description);
434   dest->plugin_init = src->plugin_init;
435   dest->plugin_exit = src->plugin_exit;
436   g_free (dest->version);
437   dest->version = g_strdup (src->version);
438   g_free (dest->license);
439   dest->license = g_strdup (src->license);
440   g_free (dest->package);
441   dest->package = g_strdup (src->package);
442   g_free (dest->origin);
443   dest->origin = g_strdup (src->origin);
444 }
445
446 #if 0
447 /* unused */
448 static void
449 gst_plugin_desc_free (GstPluginDesc * desc)
450 {
451   g_free (desc->name);
452   g_free (desc->description);
453   g_free (desc->version);
454   g_free (desc->license);
455   g_free (desc->package);
456   g_free (desc->origin);
457
458   memset (desc, 0, sizeof (GstPluginDesc));
459 }
460 #endif
461 /**
462  * gst_plugin_unload_plugin:
463  * @plugin: The plugin to unload
464  *
465  * Unload the given plugin.
466  *
467  * Returns: whether or not the plugin unloaded
468  */
469 gboolean
470 gst_plugin_unload_plugin (GstPlugin * plugin)
471 {
472   g_return_val_if_fail (plugin != NULL, FALSE);
473
474   if (!plugin->module)
475     return TRUE;
476
477   if (g_module_close (plugin->module)) {
478     plugin->module = NULL;
479     GST_CAT_INFO (GST_CAT_PLUGIN_LOADING, "plugin \"%s\" unloaded",
480         plugin->filename);
481     return TRUE;
482   } else {
483     GST_CAT_INFO (GST_CAT_PLUGIN_LOADING, "failed to unload plugin \"%s\"",
484         plugin->filename);
485     return FALSE;
486   }
487 }
488
489 /**
490  * gst_plugin_get_name:
491  * @plugin: plugin to get the name of
492  *
493  * Get the short name of the plugin
494  *
495  * Returns: the name of the plugin
496  */
497 const gchar *
498 gst_plugin_get_name (GstPlugin * plugin)
499 {
500   g_return_val_if_fail (plugin != NULL, NULL);
501
502   return plugin->desc.name;
503 }
504
505 /**
506  * gst_plugin_get_description:
507  * @plugin: plugin to get long name of
508  *
509  * Get the long descriptive name of the plugin
510  *
511  * Returns: the long name of the plugin
512  */
513 G_CONST_RETURN gchar *
514 gst_plugin_get_description (GstPlugin * plugin)
515 {
516   g_return_val_if_fail (plugin != NULL, NULL);
517
518   return plugin->desc.description;
519 }
520
521 /**
522  * gst_plugin_get_filename:
523  * @plugin: plugin to get the filename of
524  *
525  * get the filename of the plugin
526  *
527  * Returns: the filename of the plugin
528  */
529 G_CONST_RETURN gchar *
530 gst_plugin_get_filename (GstPlugin * plugin)
531 {
532   g_return_val_if_fail (plugin != NULL, NULL);
533
534   return plugin->filename;
535 }
536
537 /**
538  * gst_plugin_get_license:
539  * @plugin: plugin to get the license of
540  *
541  * get the license of the plugin
542  *
543  * Returns: the license of the plugin
544  */
545 G_CONST_RETURN gchar *
546 gst_plugin_get_license (GstPlugin * plugin)
547 {
548   g_return_val_if_fail (plugin != NULL, NULL);
549
550   return plugin->desc.license;
551 }
552
553 /**
554  * gst_plugin_get_package:
555  * @plugin: plugin to get the package of
556  *
557  * get the package the plugin belongs to.
558  *
559  * Returns: the package of the plugin
560  */
561 G_CONST_RETURN gchar *
562 gst_plugin_get_package (GstPlugin * plugin)
563 {
564   g_return_val_if_fail (plugin != NULL, NULL);
565
566   return plugin->desc.package;
567 }
568
569 /**
570  * gst_plugin_get_origin:
571  * @plugin: plugin to get the origin of
572  *
573  * get the URL where the plugin comes from
574  *
575  * Returns: the origin of the plugin
576  */
577 G_CONST_RETURN gchar *
578 gst_plugin_get_origin (GstPlugin * plugin)
579 {
580   g_return_val_if_fail (plugin != NULL, NULL);
581
582   return plugin->desc.origin;
583 }
584
585 /**
586  * gst_plugin_get_module:
587  * @plugin: plugin to query
588  *
589  * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is 
590  * returned.
591  *
592  * Returns: module belonging to the plugin or NULL if the plugin isn't 
593  *          loaded yet.
594  */
595 GModule *
596 gst_plugin_get_module (GstPlugin * plugin)
597 {
598   g_return_val_if_fail (plugin != NULL, FALSE);
599
600   return plugin->module;
601 }
602
603 /**
604  * gst_plugin_is_loaded:
605  * @plugin: plugin to query
606  *
607  * queries if the plugin is loaded into memory
608  *
609  * Returns: TRUE is loaded, FALSE otherwise
610  */
611 gboolean
612 gst_plugin_is_loaded (GstPlugin * plugin)
613 {
614   g_return_val_if_fail (plugin != NULL, FALSE);
615
616   return (plugin->module != NULL);
617 }
618
619 /**
620  * gst_plugin_feature_list:
621  * @plugin: plugin to query
622  * @filter: the filter to use
623  * @first: only return first match
624  * @user_data: user data passed to the filter function
625  *
626  * Runs a filter against all plugin features and returns a GList with
627  * the results. If the first flag is set, only the first match is 
628  * returned (as a list with a single object).
629  *
630  * Returns: a GList of features, g_list_free after use.
631  */
632 GList *
633 gst_plugin_feature_filter (GstPlugin * plugin,
634     GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
635 {
636   return gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
637       user_data);
638 }
639
640 typedef struct
641 {
642   GstPluginFeatureFilter filter;
643   gboolean first;
644   gpointer user_data;
645   GList *result;
646 }
647 FeatureFilterData;
648
649 static gboolean
650 _feature_filter (GstPlugin * plugin, gpointer user_data)
651 {
652   GList *result;
653   FeatureFilterData *data = (FeatureFilterData *) user_data;
654
655   result =
656       gst_plugin_feature_filter (plugin, data->filter, data->first,
657       data->user_data);
658   if (result) {
659     data->result = g_list_concat (data->result, result);
660     return TRUE;
661   }
662   return FALSE;
663 }
664
665 /**
666  * gst_plugin_list_feature_list:
667  * @list: a list of plugins to query
668  * @filter: the filter to use
669  * @first: only return first match
670  * @user_data: user data passed to the filter function
671  *
672  * Runs a filter against all plugin features of the plugins in the given
673  * list and returns a GList with the results. 
674  * If the first flag is set, only the first match is 
675  * returned (as a list with a single object).
676  *
677  * Returns: a GList of features, g_list_free after use.
678  */
679 GList *
680 gst_plugin_list_feature_filter (GList * list,
681     GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
682 {
683   FeatureFilterData data;
684   GList *result;
685
686   data.filter = filter;
687   data.first = first;
688   data.user_data = user_data;
689   data.result = NULL;
690
691   result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
692   g_list_free (result);
693
694   return data.result;
695 }
696
697 /**
698  * gst_plugin_name_filter:
699  * @plugin: the plugin to check
700  * @name: the name of the plugin
701  *
702  * A standard filter that returns TRUE when the plugin is of the
703  * given name.
704  *
705  * Returns: TRUE if the plugin is of the given name.
706  */
707 gboolean
708 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
709 {
710   return (plugin->desc.name && !strcmp (plugin->desc.name, name));
711 }
712
713 /**
714  * gst_plugin_find_feature:
715  * @plugin: plugin to get the feature from
716  * @name: The name of the feature to find
717  * @type: The type of the feature to find
718  *
719  * Find a feature of the given name and type in the given plugin.
720  *
721  * Returns: a GstPluginFeature or NULL if the feature was not found.
722  */
723 GstPluginFeature *
724 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
725 {
726   GList *walk;
727   GstPluginFeature *result = NULL;
728   GstTypeNameData data;
729
730   g_return_val_if_fail (name != NULL, NULL);
731
732   data.type = type;
733   data.name = name;
734
735   walk = gst_filter_run (plugin->features,
736       (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
737
738   if (walk)
739     result = GST_PLUGIN_FEATURE (walk->data);
740
741   return result;
742 }
743
744 /**
745  * gst_plugin_add_feature:
746  * @plugin: plugin to add feature to
747  * @feature: feature to add
748  *
749  * Add feature to the list of those provided by the plugin.
750  * There is a separate namespace for each plugin feature type.
751  * See #gst_plugin_get_feature_list
752  */
753 void
754 gst_plugin_add_feature (GstPlugin * plugin, GstPluginFeature * feature)
755 {
756   GstPluginFeature *oldfeature;
757
758   g_return_if_fail (plugin != NULL);
759   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
760   g_return_if_fail (feature != NULL);
761
762   oldfeature = gst_plugin_find_feature (plugin,
763       GST_PLUGIN_FEATURE_NAME (feature), G_OBJECT_TYPE (feature));
764
765   if (!oldfeature) {
766     feature->manager = plugin;
767     plugin->features = g_list_prepend (plugin->features, feature);
768     plugin->numfeatures++;
769   }
770 }
771
772 /**
773  * gst_plugin_get_feature_list:
774  * @plugin: the plugin to get the features from
775  *
776  * get a list of all the features that this plugin provides
777  *
778  * Returns: a GList of features, use g_list_free to free the list.
779  */
780 GList *
781 gst_plugin_get_feature_list (GstPlugin * plugin)
782 {
783   g_return_val_if_fail (plugin != NULL, NULL);
784
785   return g_list_copy (plugin->features);
786 }
787
788 /**
789  * gst_plugin_load:
790  * @name: name of plugin to load
791  *
792  * Load the named plugin.  
793  *
794  * Returns: whether the plugin was loaded or not
795  */
796 gboolean
797 gst_plugin_load (const gchar * name)
798 {
799   GstPlugin *plugin;
800   GError *error = NULL;
801
802   plugin = gst_registry_pool_find_plugin (name);
803   if (plugin) {
804     gst_plugin_load_file (plugin->filename, &error);
805     if (error) {
806       GST_WARNING ("load_plugin error: %s\n", error->message);
807       g_error_free (error);
808       return FALSE;
809     }
810     return TRUE;;
811   }
812
813   GST_DEBUG ("Could not find %s in registry pool", name);
814   return FALSE;
815 }
816
817 /**
818  * gst_library_load:
819  * @name: name of library to load
820  *
821  * Load the named library.  Name should be given as
822  * &quot;liblibrary.so&quot;.
823  *
824  * Returns: whether the library was loaded or not
825  */
826 gboolean
827 gst_library_load (const gchar * name)
828 {
829   gboolean res;
830
831   /* for now this is the same */
832   res = gst_plugin_load (name);
833
834   return res;
835 }