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