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