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