Getting tired of debugging. Disabled all the unreffing of plugins and features,...
[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_ERROR ("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 && plugin->module) {
339     g_static_mutex_unlock (&gst_plugin_loading_mutex);
340     return plugin;
341   }
342
343
344   GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
345       filename);
346
347   if (g_module_supported () == FALSE) {
348     GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
349     g_set_error (error,
350         GST_PLUGIN_ERROR,
351         GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
352     goto return_error;
353   }
354
355   if (stat (filename, &file_status)) {
356     GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
357     g_set_error (error,
358         GST_PLUGIN_ERROR,
359         GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s\n", filename,
360         strerror (errno));
361     goto return_error;
362   }
363
364   module = g_module_open (filename, G_MODULE_BIND_LOCAL);
365   if (module == NULL) {
366     GST_CAT_ERROR (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
367         g_module_error ());
368     g_set_error (error,
369         GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed");
370     goto return_error;
371   }
372
373   plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
374
375   plugin->module = module;
376   plugin->filename = strdup (filename);
377   plugin->file_mtime = file_status.st_mtime;
378   plugin->file_size = file_status.st_size;
379
380   ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
381   if (!ret) {
382     GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
383     g_set_error (error,
384         GST_PLUGIN_ERROR,
385         GST_PLUGIN_ERROR_MODULE,
386         "Could not find plugin entry point in \"%s\"", filename);
387     goto return_error;
388   }
389   plugin->orig_desc = (GstPluginDesc *) ptr;
390
391   GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
392       plugin, filename);
393
394   /* this is where we load the actual .so, so let's trap SIGSEGV */
395   _gst_plugin_fault_handler_setup ();
396   _gst_plugin_fault_handler_filename = plugin->filename;
397
398   GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
399       plugin, filename);
400
401   if (!gst_plugin_register_func (plugin, module, plugin->orig_desc)) {
402     /* remove signal handler */
403     _gst_plugin_fault_handler_restore ();
404     GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
405     /* plugin == NULL */
406     g_set_error (error,
407         GST_PLUGIN_ERROR,
408         GST_PLUGIN_ERROR_MODULE,
409         "gst_plugin_register_func failed for plugin \"%s\"", filename);
410     g_module_close (module);
411     goto return_error;
412   }
413
414   /* remove signal handler */
415   _gst_plugin_fault_handler_restore ();
416   _gst_plugin_fault_handler_filename = NULL;
417   GST_INFO ("plugin \"%s\" loaded", plugin->filename);
418
419   gst_object_ref (plugin);
420   gst_default_registry_add_plugin (plugin);
421
422   g_static_mutex_unlock (&gst_plugin_loading_mutex);
423   return plugin;
424 return_error:
425   g_static_mutex_unlock (&gst_plugin_loading_mutex);
426   return NULL;
427 }
428
429 static void
430 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
431 {
432   dest->major_version = src->major_version;
433   dest->minor_version = src->minor_version;
434   dest->name = g_strdup (src->name);
435   dest->description = g_strdup (src->description);
436   dest->plugin_init = src->plugin_init;
437   dest->version = g_strdup (src->version);
438   dest->license = g_strdup (src->license);
439   dest->source = g_strdup (src->source);
440   dest->package = g_strdup (src->package);
441   dest->origin = g_strdup (src->origin);
442 }
443
444 #if 0
445 /* unused */
446 static void
447 gst_plugin_desc_free (GstPluginDesc * desc)
448 {
449   g_free (desc->name);
450   g_free (desc->description);
451   g_free (desc->version);
452   g_free (desc->license);
453   g_free (desc->source);
454   g_free (desc->package);
455   g_free (desc->origin);
456
457   memset (desc, 0, sizeof (GstPluginDesc));
458 }
459 #endif
460
461 /**
462  * gst_plugin_get_name:
463  * @plugin: plugin to get the name of
464  *
465  * Get the short name of the plugin
466  *
467  * Returns: the name of the plugin
468  */
469 const gchar *
470 gst_plugin_get_name (GstPlugin * plugin)
471 {
472   g_return_val_if_fail (plugin != NULL, NULL);
473
474   return plugin->desc.name;
475 }
476
477 /**
478  * gst_plugin_get_description:
479  * @plugin: plugin to get long name of
480  *
481  * Get the long descriptive name of the plugin
482  *
483  * Returns: the long name of the plugin
484  */
485 G_CONST_RETURN gchar *
486 gst_plugin_get_description (GstPlugin * plugin)
487 {
488   g_return_val_if_fail (plugin != NULL, NULL);
489
490   return plugin->desc.description;
491 }
492
493 /**
494  * gst_plugin_get_filename:
495  * @plugin: plugin to get the filename of
496  *
497  * get the filename of the plugin
498  *
499  * Returns: the filename of the plugin
500  */
501 G_CONST_RETURN gchar *
502 gst_plugin_get_filename (GstPlugin * plugin)
503 {
504   g_return_val_if_fail (plugin != NULL, NULL);
505
506   return plugin->filename;
507 }
508
509 /**
510  * gst_plugin_get_version:
511  * @plugin: plugin to get the version of
512  *
513  * get the version of the plugin
514  *
515  * Returns: the version of the plugin
516  */
517 G_CONST_RETURN gchar *
518 gst_plugin_get_version (GstPlugin * plugin)
519 {
520   g_return_val_if_fail (plugin != NULL, NULL);
521
522   return plugin->desc.version;
523 }
524
525 /**
526  * gst_plugin_get_license:
527  * @plugin: plugin to get the license of
528  *
529  * get the license of the plugin
530  *
531  * Returns: the license of the plugin
532  */
533 G_CONST_RETURN gchar *
534 gst_plugin_get_license (GstPlugin * plugin)
535 {
536   g_return_val_if_fail (plugin != NULL, NULL);
537
538   return plugin->desc.license;
539 }
540
541 /**
542  * gst_plugin_get_source:
543  * @plugin: plugin to get the source of
544  *
545  * get the source module the plugin belongs to.
546  *
547  * Returns: the source of the plugin
548  */
549 G_CONST_RETURN gchar *
550 gst_plugin_get_source (GstPlugin * plugin)
551 {
552   g_return_val_if_fail (plugin != NULL, NULL);
553
554   return plugin->desc.source;
555 }
556
557 /**
558  * gst_plugin_get_package:
559  * @plugin: plugin to get the package of
560  *
561  * get the package the plugin belongs to.
562  *
563  * Returns: the package of the plugin
564  */
565 G_CONST_RETURN gchar *
566 gst_plugin_get_package (GstPlugin * plugin)
567 {
568   g_return_val_if_fail (plugin != NULL, NULL);
569
570   return plugin->desc.package;
571 }
572
573 /**
574  * gst_plugin_get_origin:
575  * @plugin: plugin to get the origin of
576  *
577  * get the URL where the plugin comes from
578  *
579  * Returns: the origin of the plugin
580  */
581 G_CONST_RETURN gchar *
582 gst_plugin_get_origin (GstPlugin * plugin)
583 {
584   g_return_val_if_fail (plugin != NULL, NULL);
585
586   return plugin->desc.origin;
587 }
588
589 /**
590  * gst_plugin_get_module:
591  * @plugin: plugin to query
592  *
593  * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is 
594  * returned.
595  *
596  * Returns: module belonging to the plugin or NULL if the plugin isn't 
597  *          loaded yet.
598  */
599 GModule *
600 gst_plugin_get_module (GstPlugin * plugin)
601 {
602   g_return_val_if_fail (plugin != NULL, NULL);
603
604   return plugin->module;
605 }
606
607 /**
608  * gst_plugin_is_loaded:
609  * @plugin: plugin to query
610  *
611  * queries if the plugin is loaded into memory
612  *
613  * Returns: TRUE is loaded, FALSE otherwise
614  */
615 gboolean
616 gst_plugin_is_loaded (GstPlugin * plugin)
617 {
618   g_return_val_if_fail (plugin != NULL, FALSE);
619
620   return (plugin->module != NULL);
621 }
622
623 /**
624  * gst_plugin_feature_list:
625  * @plugin: plugin to query
626  * @filter: the filter to use
627  * @first: only return first match
628  * @user_data: user data passed to the filter function
629  *
630  * Runs a filter against all plugin features and returns a GList with
631  * the results. If the first flag is set, only the first match is
632  * returned (as a list with a single object).
633  *
634  * Returns: a GList of features, g_list_free after use.
635  */
636 GList *
637 gst_plugin_feature_filter (GstPlugin * plugin,
638     GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
639 {
640   GList *list;
641   GList *g;
642
643   list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
644       user_data);
645   for (g = list; g; g = g->next) {
646     gst_object_ref (plugin);
647   }
648
649   return list;
650 }
651
652 typedef struct
653 {
654   GstPluginFeatureFilter filter;
655   gboolean first;
656   gpointer user_data;
657   GList *result;
658 }
659 FeatureFilterData;
660
661 static gboolean
662 _feature_filter (GstPlugin * plugin, gpointer user_data)
663 {
664   GList *result;
665   FeatureFilterData *data = (FeatureFilterData *) user_data;
666
667   result = gst_plugin_feature_filter (plugin, data->filter, data->first,
668       data->user_data);
669   if (result) {
670     data->result = g_list_concat (data->result, result);
671     return TRUE;
672   }
673   return FALSE;
674 }
675
676 /**
677  * gst_plugin_list_feature_filter:
678  * @list: a #GList of plugins to query
679  * @filter: the filter function to use
680  * @first: only return first match
681  * @user_data: user data passed to the filter function
682  *
683  * Runs a filter against all plugin features of the plugins in the given
684  * list and returns a GList with the results.
685  * If the first flag is set, only the first match is
686  * returned (as a list with a single object).
687  *
688  * Returns: a GList of features, g_list_free after use.
689  */
690 GList *
691 gst_plugin_list_feature_filter (GList * list,
692     GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
693 {
694   FeatureFilterData data;
695   GList *result;
696
697   data.filter = filter;
698   data.first = first;
699   data.user_data = user_data;
700   data.result = NULL;
701
702   result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
703   g_list_free (result);
704
705   return data.result;
706 }
707
708 /**
709  * gst_plugin_name_filter:
710  * @plugin: the plugin to check
711  * @name: the name of the plugin
712  *
713  * A standard filter that returns TRUE when the plugin is of the
714  * given name.
715  *
716  * Returns: TRUE if the plugin is of the given name.
717  */
718 gboolean
719 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
720 {
721   return (plugin->desc.name && !strcmp (plugin->desc.name, name));
722 }
723
724 /**
725  * gst_plugin_find_feature:
726  * @plugin: plugin to get the feature from
727  * @name: The name of the feature to find
728  * @type: The type of the feature to find
729  *
730  * Find a feature of the given name and type in the given plugin.
731  *
732  * Returns: a GstPluginFeature or NULL if the feature was not found.
733  */
734 GstPluginFeature *
735 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
736 {
737   GList *walk;
738   GstPluginFeature *result = NULL;
739   GstTypeNameData data;
740
741   g_return_val_if_fail (name != NULL, NULL);
742
743   data.type = type;
744   data.name = name;
745
746   walk = gst_filter_run (plugin->features,
747       (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
748
749   if (walk) {
750     result = GST_PLUGIN_FEATURE (walk->data);
751
752     gst_object_ref (result->plugin);
753     gst_plugin_feature_list_free (walk);
754   }
755
756   return result;
757 }
758
759 static gboolean
760 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
761 {
762   return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
763 }
764
765 /**
766  * gst_plugin_find_feature_by_name:
767  * @plugin: plugin to get the feature from
768  * @name: The name of the feature to find
769  *
770  * Find a feature of the given name in the given plugin.
771  *
772  * Returns: a GstPluginFeature or NULL if the feature was not found.
773  */
774 GstPluginFeature *
775 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
776 {
777   GList *walk;
778   GstPluginFeature *result = NULL;
779
780   g_return_val_if_fail (name != NULL, NULL);
781
782   walk = gst_filter_run (plugin->features,
783       (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
784
785   if (walk) {
786     result = GST_PLUGIN_FEATURE (walk->data);
787
788     gst_object_ref (result->plugin);
789     gst_plugin_feature_list_free (walk);
790   }
791
792   return result;
793 }
794
795 /**
796  * gst_plugin_add_feature:
797  * @plugin: plugin to add feature to
798  * @feature: feature to add
799  *
800  * Add feature to the list of those provided by the plugin.
801  * There is a separate namespace for each plugin feature type.
802  * See #gst_plugin_get_feature_list
803  */
804 void
805 gst_plugin_add_feature (GstPlugin * plugin, GstPluginFeature * feature)
806 {
807   /* FIXME 0.9: get reference counting somewhat right in here,
808    * GstPluginFeatures should probably be GstObjects that are sinked when
809    * adding them to a plugin */
810   g_return_if_fail (plugin != NULL);
811   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
812   g_return_if_fail (feature != NULL);
813   g_return_if_fail (feature->plugin == NULL);
814
815   /* gst_object_sink (feature); */
816   feature->plugin = plugin;
817   plugin->features = g_list_prepend (plugin->features, feature);
818   plugin->numfeatures++;
819 }
820
821 /**
822  * gst_plugin_get_feature_list:
823  * @plugin: the plugin to get the features from
824  *
825  * get a list of all the features that this plugin provides
826  *
827  * Returns: a GList of features, use g_list_free to free the list.
828  */
829 GList *
830 gst_plugin_get_feature_list (GstPlugin * plugin)
831 {
832   GList *list;
833   GList *g;
834
835   g_return_val_if_fail (plugin != NULL, NULL);
836
837   list = g_list_copy (plugin->features);
838   for (g = list; g; g = g->next) {
839     gst_object_ref (plugin);
840   }
841
842   return list;
843 }
844
845 /* FIXME is this function necessary? */
846 /**
847  * gst_plugin_load_1:
848  * @name: name of plugin to load
849  *
850  * Load the named plugin.  
851  *
852  * Returns: whether the plugin was loaded or not
853  */
854 gboolean
855 gst_plugin_load_1 (const gchar * name)
856 {
857   GstPlugin *plugin;
858   GError *error = NULL;
859
860   plugin = gst_registry_find_plugin (gst_registry_get_default (), name);
861   if (plugin) {
862     plugin = gst_plugin_load_file (plugin->filename, &error);
863     if (!plugin) {
864       GST_WARNING ("load_plugin error: %s\n", error->message);
865       g_error_free (error);
866       return FALSE;
867     }
868     return TRUE;;
869   }
870
871   GST_DEBUG ("Could not find %s in registry pool", name);
872   return FALSE;
873 }
874
875 GstPlugin *
876 gst_plugin_load (GstPlugin * plugin)
877 {
878   GError *error = NULL;
879   GstPlugin *newplugin;
880
881   if (gst_plugin_is_loaded (plugin)) {
882     return plugin;
883   }
884
885   if (!plugin->filename) {
886     return plugin;
887   }
888
889   newplugin = gst_plugin_load_file (plugin->filename, &error);
890   if (newplugin == NULL) {
891     GST_WARNING ("load_plugin error: %s\n", error->message);
892     g_error_free (error);
893     //gst_object_unref (plugin);
894     return NULL;
895   }
896
897   /* FIXME hack to keep plugins from disappearing */
898   //gst_object_unref (plugin);
899
900   return newplugin;
901 }
902
903 void
904 gst_plugin_list_free (GList * list)
905 {
906   GList *g;
907
908   for (g = list; g; g = g->next) {
909     //gst_object_unref (GST_PLUGIN(g->data));
910   }
911   g_list_free (list);
912 }