gstreamer_core/gst/gstplugin.c
changeset 0 0e761a78d257
child 7 567bb019e3e3
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     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 /**
       
    24  * SECTION:gstplugin
       
    25  * @short_description: Container for features loaded from a shared object module
       
    26  * @see_also: #GstPluginFeature, #GstElementFactory
       
    27  *
       
    28  * GStreamer is extensible, so #GstElement instances can be loaded at runtime.
       
    29  * A plugin system can provide one or more of the basic
       
    30  * <application>GStreamer</application> #GstPluginFeature subclasses.
       
    31  *
       
    32  * A plugin should export a symbol <symbol>gst_plugin_desc</symbol> that is a
       
    33  * struct of type #GstPluginDesc.
       
    34  * the plugin loader will check the version of the core library the plugin was
       
    35  * linked against and will create a new #GstPlugin. It will then call the
       
    36  * #GstPluginInitFunc function that was provided in the
       
    37  * <symbol>gst_plugin_desc</symbol>.
       
    38  *
       
    39  * Once you have a handle to a #GstPlugin (e.g. from the #GstRegistryPool), you
       
    40  * can add any object that subclasses #GstPluginFeature.
       
    41  *
       
    42  * Use gst_plugin_find_feature() and gst_plugin_get_feature_list() to find
       
    43  * features in a plugin.
       
    44  *
       
    45  * Usually plugins are always automaticlly loaded so you don't need to call
       
    46  * gst_plugin_load() explicitly to bring it into memory. There are options to
       
    47  * statically link plugins to an app or even use GStreamer without a plugin
       
    48  * repository in which case gst_plugin_load() can be needed to bring the plugin
       
    49  * into memory.
       
    50  */
       
    51 
       
    52 #ifdef HAVE_CONFIG_H
       
    53 #include "config.h"
       
    54 #endif
       
    55 #include <glib/gstdio.h>
       
    56 #include <sys/types.h>
       
    57 #ifdef HAVE_DIRENT_H
       
    58 #include <dirent.h>
       
    59 #endif
       
    60 #ifdef HAVE_UNISTD_H
       
    61 #include <unistd.h>
       
    62 #endif
       
    63 #include <signal.h>
       
    64 #include <errno.h>
       
    65 
       
    66 #include "gst_private.h"
       
    67 #include "glib-compat-private.h"
       
    68 
       
    69 #include <gst/gst.h>
       
    70 
       
    71 #ifdef __SYMBIAN32__
       
    72 #include <glib_global.h>
       
    73 #endif
       
    74 
       
    75 #define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
       
    76 
       
    77 static guint _num_static_plugins;       /* 0    */
       
    78 static GstPluginDesc *_static_plugins;  /* NULL */
       
    79 static gboolean _gst_plugin_inited;
       
    80 
       
    81 /* static variables for segfault handling of plugin loading */
       
    82 static char *_gst_plugin_fault_handler_filename = NULL;
       
    83 
       
    84 #ifndef HAVE_WIN32
       
    85 static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
       
    86 #endif
       
    87 
       
    88 /* list of valid licenses.
       
    89  * One of these must be specified or the plugin won't be loaded
       
    90  * Contact gstreamer-devel@lists.sourceforge.net if your license should be
       
    91  * added.
       
    92  *
       
    93  * GPL: http://www.gnu.org/copyleft/gpl.html
       
    94  * LGPL: http://www.gnu.org/copyleft/lesser.html
       
    95  * QPL: http://www.trolltech.com/licenses/qpl.html
       
    96  * MPL: http://www.opensource.org/licenses/mozilla1.1.php
       
    97  * MIT/X11: http://www.opensource.org/licenses/mit-license.php
       
    98  * 3-clause BSD: http://www.opensource.org/licenses/bsd-license.php
       
    99  */
       
   100 static const gchar *valid_licenses[] = {
       
   101   "LGPL",                       /* GNU Lesser General Public License */
       
   102   "GPL",                        /* GNU General Public License */
       
   103   "QPL",                        /* Trolltech Qt Public License */
       
   104   "GPL/QPL",                    /* Combi-license of GPL + QPL */
       
   105   "MPL",                        /* MPL 1.1 license */
       
   106   "BSD",                        /* 3-clause BSD license */
       
   107   "MIT/X11",                    /* MIT/X11 license */
       
   108   "Proprietary",                /* Proprietary license */
       
   109   GST_LICENSE_UNKNOWN,          /* some other license */
       
   110   NULL
       
   111 };
       
   112 
       
   113 static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
       
   114     const GstPluginDesc * desc);
       
   115 static void gst_plugin_desc_copy (GstPluginDesc * dest,
       
   116     const GstPluginDesc * src);
       
   117 static void gst_plugin_desc_free (GstPluginDesc * desc);
       
   118 
       
   119 
       
   120 G_DEFINE_TYPE (GstPlugin, gst_plugin, GST_TYPE_OBJECT);
       
   121 
       
   122 static void
       
   123 gst_plugin_init (GstPlugin * plugin)
       
   124 {
       
   125   /* do nothing, needed because of G_DEFINE_TYPE */
       
   126 }
       
   127 
       
   128 static void
       
   129 gst_plugin_finalize (GObject * object)
       
   130 {
       
   131   GstPlugin *plugin = GST_PLUGIN_CAST (object);
       
   132   GstRegistry *registry = gst_registry_get_default ();
       
   133   GList *g;
       
   134 
       
   135   GST_DEBUG ("finalizing plugin %p", plugin);
       
   136   for (g = registry->plugins; g; g = g->next) {
       
   137     if (g->data == (gpointer) plugin) {
       
   138       g_warning ("removing plugin that is still in registry");
       
   139     }
       
   140   }
       
   141   g_free (plugin->filename);
       
   142   g_free (plugin->basename);
       
   143   gst_plugin_desc_free (&plugin->desc);
       
   144 
       
   145   G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
       
   146 }
       
   147 
       
   148 static void
       
   149 gst_plugin_class_init (GstPluginClass * klass)
       
   150 {
       
   151   G_OBJECT_CLASS (klass)->finalize = GST_DEBUG_FUNCPTR (gst_plugin_finalize);
       
   152 }
       
   153 #ifdef __SYMBIAN32__
       
   154 EXPORT_C
       
   155 #endif
       
   156 
       
   157 
       
   158 GQuark
       
   159 gst_plugin_error_quark (void)
       
   160 {
       
   161   static GQuark quark = 0;
       
   162 
       
   163   if (!quark)
       
   164     quark = g_quark_from_static_string ("gst_plugin_error");
       
   165   return quark;
       
   166 }
       
   167 
       
   168 #ifndef GST_REMOVE_DEPRECATED
       
   169 /* this function can be called in the GCC constructor extension, before
       
   170  * the _gst_plugin_initialize() was called. In that case, we store the
       
   171  * plugin description in a list to initialize it when we open the main
       
   172  * module later on.
       
   173  * When the main module is known, we can register the plugin right away.
       
   174  */
       
   175 #ifdef __SYMBIAN32__
       
   176 EXPORT_C
       
   177 #endif
       
   178 
       
   179 void
       
   180 _gst_plugin_register_static (GstPluginDesc * desc)
       
   181 {
       
   182   g_return_if_fail (desc != NULL);
       
   183 
       
   184   if (!_gst_plugin_inited) {
       
   185     /* We can't use any GLib functions here, since g_thread_init hasn't been
       
   186      * called yet, and we can't call it here either, or programs that don't
       
   187      * guard their g_thread_init calls in main() will just abort */
       
   188     ++_num_static_plugins;
       
   189     _static_plugins =
       
   190         realloc (_static_plugins, _num_static_plugins * sizeof (GstPluginDesc));
       
   191     /* assume strings in the GstPluginDesc are static const or live forever */
       
   192     _static_plugins[_num_static_plugins - 1] = *desc;
       
   193   } else {
       
   194     gst_plugin_register_static (desc->major_version, desc->minor_version,
       
   195         desc->name, desc->description, desc->plugin_init, desc->version,
       
   196         desc->license, desc->source, desc->package, desc->origin);
       
   197   }
       
   198 }
       
   199 #endif
       
   200 
       
   201 /**
       
   202  * gst_plugin_register_static:
       
   203  * @major_version: the major version number of the GStreamer core that the
       
   204  *     plugin was compiled for, you can just use GST_VERSION_MAJOR here
       
   205  * @minor_version: the minor version number of the GStreamer core that the
       
   206  *     plugin was compiled for, you can just use GST_VERSION_MINOR here
       
   207  * @name: a unique name of the plugin (ideally prefixed with an application- or
       
   208  *     library-specific namespace prefix in order to avoid name conflicts in
       
   209  *     case a similar plugin with the same name ever gets added to GStreamer)
       
   210  * @description: description of the plugin
       
   211  * @init_func: pointer to the init function of this plugin.
       
   212  * @version: version string of the plugin
       
   213  * @license: effective license of plugin. Must be one of the approved licenses
       
   214  *     (see #GstPluginDesc above) or the plugin will not be registered.
       
   215  * @source: source module plugin belongs to
       
   216  * @package: shipped package plugin belongs to
       
   217  * @origin: URL to provider of plugin
       
   218  *
       
   219  * Registers a static plugin, ie. a plugin which is private to an application
       
   220  * or library and contained within the application or library (as opposed to
       
   221  * being shipped as a separate module file).
       
   222  *
       
   223  * You must make sure that GStreamer has been initialised (with gst_init() or
       
   224  * via gst_init_get_option_group()) before calling this function.
       
   225  *
       
   226  * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
       
   227  *
       
   228  * Since: 0.10.16
       
   229  */
       
   230 #ifdef __SYMBIAN32__
       
   231 EXPORT_C
       
   232 #endif
       
   233 
       
   234 gboolean
       
   235 gst_plugin_register_static (gint major_version, gint minor_version,
       
   236     const gchar * name, gchar * description, GstPluginInitFunc init_func,
       
   237     const gchar * version, const gchar * license, const gchar * source,
       
   238     const gchar * package, const gchar * origin)
       
   239 {
       
   240 #ifdef __SYMBIAN32__
       
   241   GstPluginDesc desc;
       
   242   GstPlugin *plugin;
       
   243   gboolean res = FALSE;
       
   244 
       
   245   desc.major_version = major_version;
       
   246   desc.minor_version = minor_version;
       
   247   desc.name = name;
       
   248   desc.description = description;
       
   249   desc.plugin_init = init_func;
       
   250   desc.version = version;
       
   251   desc.license = license;
       
   252   desc.source = source;
       
   253   desc.package = package;
       
   254   desc.origin = origin;
       
   255 #else
       
   256   GstPluginDesc desc = { major_version, minor_version, name, description,
       
   257     init_func, version, license, source, package, origin,
       
   258   };
       
   259   GstPlugin *plugin;
       
   260   gboolean res = FALSE;
       
   261 #endif
       
   262 
       
   263   g_return_val_if_fail (name != NULL, FALSE);
       
   264   g_return_val_if_fail (description != NULL, FALSE);
       
   265   g_return_val_if_fail (init_func != NULL, FALSE);
       
   266   g_return_val_if_fail (version != NULL, FALSE);
       
   267   g_return_val_if_fail (license != NULL, FALSE);
       
   268   g_return_val_if_fail (source != NULL, FALSE);
       
   269   g_return_val_if_fail (package != NULL, FALSE);
       
   270   g_return_val_if_fail (origin != NULL, FALSE);
       
   271 
       
   272   /* make sure gst_init() has been called */
       
   273   g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
       
   274 
       
   275   GST_LOG ("attempting to load static plugin \"%s\" now...", name);
       
   276   plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
       
   277   if (gst_plugin_register_func (plugin, &desc) != NULL) {
       
   278     GST_INFO ("registered static plugin \"%s\"", name);
       
   279     res = gst_default_registry_add_plugin (plugin);
       
   280     GST_INFO ("added static plugin \"%s\", result: %d", name, res);
       
   281   }
       
   282   return res;
       
   283 }
       
   284 #ifdef __SYMBIAN32__
       
   285 EXPORT_C
       
   286 #endif
       
   287 
       
   288 
       
   289 void
       
   290 _gst_plugin_initialize (void)
       
   291 {
       
   292   guint i;
       
   293 
       
   294   _gst_plugin_inited = TRUE;
       
   295 
       
   296   /* now register all static plugins */
       
   297   GST_INFO ("registering %u static plugins", _num_static_plugins);
       
   298   for (i = 0; i < _num_static_plugins; ++i) {
       
   299     gst_plugin_register_static (_static_plugins[i].major_version,
       
   300         _static_plugins[i].minor_version, _static_plugins[i].name,
       
   301         _static_plugins[i].description, _static_plugins[i].plugin_init,
       
   302         _static_plugins[i].version, _static_plugins[i].license,
       
   303         _static_plugins[i].source, _static_plugins[i].package,
       
   304         _static_plugins[i].origin);
       
   305   }
       
   306 
       
   307   if (_static_plugins) {
       
   308     free (_static_plugins);
       
   309     _static_plugins = NULL;
       
   310     _num_static_plugins = 0;
       
   311   }
       
   312 }
       
   313 
       
   314 /* this function could be extended to check if the plugin license matches the
       
   315  * applications license (would require the app to register its license somehow).
       
   316  * We'll wait for someone who's interested in it to code it :)
       
   317  */
       
   318 static gboolean
       
   319 gst_plugin_check_license (const gchar * license)
       
   320 {
       
   321   const gchar **check_license = valid_licenses;
       
   322 
       
   323   g_assert (check_license);
       
   324 
       
   325   while (*check_license) {
       
   326     if (strcmp (license, *check_license) == 0)
       
   327       return TRUE;
       
   328     check_license++;
       
   329   }
       
   330   return FALSE;
       
   331 }
       
   332 
       
   333 static gboolean
       
   334 gst_plugin_check_version (gint major, gint minor)
       
   335 {
       
   336   /* return NULL if the major and minor version numbers are not compatible */
       
   337   /* with ours. */
       
   338   if (major != GST_VERSION_MAJOR || minor != GST_VERSION_MINOR)
       
   339     return FALSE;
       
   340 
       
   341   return TRUE;
       
   342 }
       
   343 
       
   344 static GstPlugin *
       
   345 gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc)
       
   346 {
       
   347   if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
       
   348     if (GST_CAT_DEFAULT)
       
   349       GST_WARNING ("plugin \"%s\" has incompatible version, not loading",
       
   350           plugin->filename);
       
   351     return NULL;
       
   352   }
       
   353 
       
   354   if (!desc->license || !desc->description || !desc->source ||
       
   355       !desc->package || !desc->origin) {
       
   356     if (GST_CAT_DEFAULT)
       
   357       GST_WARNING ("plugin \"%s\" has incorrect GstPluginDesc, not loading",
       
   358           plugin->filename);
       
   359     return NULL;
       
   360   }
       
   361 
       
   362   if (!gst_plugin_check_license (desc->license)) {
       
   363     if (GST_CAT_DEFAULT)
       
   364       GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
       
   365           plugin->filename, desc->license);
       
   366     return NULL;
       
   367   }
       
   368 
       
   369   if (GST_CAT_DEFAULT)
       
   370     GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
       
   371 
       
   372   gst_plugin_desc_copy (&plugin->desc, desc);
       
   373 
       
   374   if (!((desc->plugin_init) (plugin))) {
       
   375     if (GST_CAT_DEFAULT)
       
   376       GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
       
   377     plugin->module = NULL;
       
   378     return NULL;
       
   379   }
       
   380 
       
   381   if (GST_CAT_DEFAULT)
       
   382     GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
       
   383 
       
   384   return plugin;
       
   385 }
       
   386 
       
   387 #ifdef HAVE_SIGACTION
       
   388 static struct sigaction oldaction;
       
   389 
       
   390 /*
       
   391  * _gst_plugin_fault_handler_restore:
       
   392  * segfault handler restorer
       
   393  */
       
   394 static void
       
   395 _gst_plugin_fault_handler_restore (void)
       
   396 {
       
   397   if (!_gst_plugin_fault_handler_is_setup)
       
   398     return;
       
   399 
       
   400   _gst_plugin_fault_handler_is_setup = FALSE;
       
   401 
       
   402   sigaction (SIGSEGV, &oldaction, NULL);
       
   403 }
       
   404 
       
   405 /*
       
   406  * _gst_plugin_fault_handler_sighandler:
       
   407  * segfault handler implementation
       
   408  */
       
   409 static void
       
   410 _gst_plugin_fault_handler_sighandler (int signum)
       
   411 {
       
   412   /* We need to restore the fault handler or we'll keep getting it */
       
   413   _gst_plugin_fault_handler_restore ();
       
   414 
       
   415   switch (signum) {
       
   416     case SIGSEGV:
       
   417       g_print ("\nERROR: ");
       
   418       g_print ("Caught a segmentation fault while loading plugin file:\n");
       
   419       g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
       
   420       g_print ("Please either:\n");
       
   421       g_print ("- remove it and restart.\n");
       
   422       g_print ("- run with --gst-disable-segtrap and debug.\n");
       
   423       exit (-1);
       
   424       break;
       
   425     default:
       
   426       g_print ("Caught unhandled signal on plugin loading\n");
       
   427       break;
       
   428   }
       
   429 }
       
   430 
       
   431 /*
       
   432  * _gst_plugin_fault_handler_setup:
       
   433  * sets up the segfault handler
       
   434  */
       
   435 static void
       
   436 _gst_plugin_fault_handler_setup (void)
       
   437 {
       
   438   struct sigaction action;
       
   439 
       
   440   /* if asked to leave segfaults alone, just return */
       
   441   if (!gst_segtrap_is_enabled ())
       
   442     return;
       
   443 
       
   444   if (_gst_plugin_fault_handler_is_setup)
       
   445     return;
       
   446 
       
   447   _gst_plugin_fault_handler_is_setup = TRUE;
       
   448 
       
   449   memset (&action, 0, sizeof (action));
       
   450   action.sa_handler = _gst_plugin_fault_handler_sighandler;
       
   451 
       
   452   sigaction (SIGSEGV, &action, &oldaction);
       
   453 }
       
   454 #else
       
   455 static void
       
   456 _gst_plugin_fault_handler_restore (void)
       
   457 {
       
   458 }
       
   459 
       
   460 static void
       
   461 _gst_plugin_fault_handler_setup (void)
       
   462 {
       
   463 }
       
   464 #endif
       
   465 
       
   466 static void _gst_plugin_fault_handler_setup ();
       
   467 
       
   468 static GStaticMutex gst_plugin_loading_mutex = G_STATIC_MUTEX_INIT;
       
   469 
       
   470 /**
       
   471  * gst_plugin_load_file:
       
   472  * @filename: the plugin filename to load
       
   473  * @error: pointer to a NULL-valued GError
       
   474  *
       
   475  * Loads the given plugin and refs it.  Caller needs to unref after use.
       
   476  *
       
   477  * Returns: a reference to the existing loaded GstPlugin, a reference to the
       
   478  * newly-loaded GstPlugin, or NULL if an error occurred.
       
   479  */
       
   480 #ifdef __SYMBIAN32__
       
   481 EXPORT_C
       
   482 #endif
       
   483 
       
   484 GstPlugin *
       
   485 gst_plugin_load_file (const gchar * filename, GError ** error)
       
   486 {
       
   487   GstPlugin *plugin;
       
   488   GModule *module;
       
   489   gboolean ret;
       
   490   gpointer ptr;
       
   491   struct stat file_status;
       
   492   GstRegistry *registry;
       
   493    #ifdef __SYMBIAN32__
       
   494    GstPluginDesc* (*fn)(void)=NULL;
       
   495    void *temp;
       
   496    
       
   497    #endif
       
   498 
       
   499   g_return_val_if_fail (filename != NULL, NULL);
       
   500 
       
   501   registry = gst_registry_get_default ();
       
   502   g_static_mutex_lock (&gst_plugin_loading_mutex);
       
   503 
       
   504   plugin = gst_registry_lookup (registry, filename);
       
   505   if (plugin) {
       
   506     if (plugin->module) {
       
   507       g_static_mutex_unlock (&gst_plugin_loading_mutex);
       
   508       return plugin;
       
   509     } else {
       
   510       gst_object_unref (plugin);
       
   511       plugin = NULL;
       
   512     }
       
   513   }
       
   514 
       
   515   GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
       
   516       filename);
       
   517 
       
   518   if (g_module_supported () == FALSE) {
       
   519     GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
       
   520     g_set_error (error,
       
   521         GST_PLUGIN_ERROR,
       
   522         GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
       
   523     goto return_error;
       
   524   }
       
   525 
       
   526   if (g_stat (filename, &file_status)) {
       
   527     GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
       
   528     g_set_error (error,
       
   529         GST_PLUGIN_ERROR,
       
   530         GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
       
   531         g_strerror (errno));
       
   532     goto return_error;
       
   533   }
       
   534 
       
   535   module = g_module_open (filename, G_MODULE_BIND_LOCAL);
       
   536   if (module == NULL) {
       
   537     GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
       
   538         g_module_error ());
       
   539     g_set_error (error,
       
   540         GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
       
   541         g_module_error ());
       
   542     /* If we failed to open the shared object, then it's probably because a
       
   543      * plugin is linked against the wrong libraries. Print out an easy-to-see
       
   544      * message in this case. */
       
   545     g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
       
   546     goto return_error;
       
   547   }
       
   548 
       
   549   plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
       
   550 
       
   551   plugin->module = module;
       
   552   plugin->filename = g_strdup (filename);
       
   553   plugin->basename = g_path_get_basename (filename);
       
   554   plugin->file_mtime = file_status.st_mtime;
       
   555   plugin->file_size = file_status.st_size;
       
   556 
       
   557 #ifdef __SYMBIAN32__
       
   558    ret = g_module_symbol (module, "1", &ptr);
       
   559 #else   
       
   560   ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
       
   561 #endif   
       
   562   if (!ret) {
       
   563     GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
       
   564     g_set_error (error,
       
   565         GST_PLUGIN_ERROR,
       
   566         GST_PLUGIN_ERROR_MODULE,
       
   567         "File \"%s\" is not a GStreamer plugin", filename);
       
   568     g_module_close (module);
       
   569     goto return_error;
       
   570   }
       
   571    #ifdef __SYMBIAN32__
       
   572    fn=ptr;
       
   573    temp=fn();
       
   574    plugin->orig_desc = (GstPluginDesc *) temp;
       
   575    #else
       
   576   plugin->orig_desc = (GstPluginDesc *) ptr;
       
   577    #endif
       
   578 
       
   579   GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
       
   580       plugin, filename);
       
   581 
       
   582   /* this is where we load the actual .so, so let's trap SIGSEGV */
       
   583   _gst_plugin_fault_handler_setup ();
       
   584   _gst_plugin_fault_handler_filename = plugin->filename;
       
   585 
       
   586   GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
       
   587       plugin, filename);
       
   588 
       
   589   if (!gst_plugin_register_func (plugin, plugin->orig_desc)) {
       
   590     /* remove signal handler */
       
   591     _gst_plugin_fault_handler_restore ();
       
   592     GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
       
   593     /* plugin == NULL */
       
   594     g_set_error (error,
       
   595         GST_PLUGIN_ERROR,
       
   596         GST_PLUGIN_ERROR_MODULE,
       
   597         "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
       
   598         filename);
       
   599     g_module_close (module);
       
   600     goto return_error;
       
   601   }
       
   602 
       
   603   /* remove signal handler */
       
   604   _gst_plugin_fault_handler_restore ();
       
   605   _gst_plugin_fault_handler_filename = NULL;
       
   606   GST_INFO ("plugin \"%s\" loaded", plugin->filename);
       
   607 
       
   608   gst_object_ref (plugin);
       
   609   gst_default_registry_add_plugin (plugin);
       
   610 
       
   611   g_static_mutex_unlock (&gst_plugin_loading_mutex);
       
   612   return plugin;
       
   613 
       
   614 return_error:
       
   615   {
       
   616     if (plugin)
       
   617       gst_object_unref (plugin);
       
   618     g_static_mutex_unlock (&gst_plugin_loading_mutex);
       
   619     return NULL;
       
   620   }
       
   621 }
       
   622 
       
   623 static void
       
   624 gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
       
   625 {
       
   626   dest->major_version = src->major_version;
       
   627   dest->minor_version = src->minor_version;
       
   628   dest->name = g_intern_string (src->name);
       
   629   /* maybe intern the description too, just for convenience? */
       
   630   dest->description = g_strdup (src->description);
       
   631   dest->plugin_init = src->plugin_init;
       
   632   dest->version = g_intern_string (src->version);
       
   633   dest->license = g_intern_string (src->license);
       
   634   dest->source = g_intern_string (src->source);
       
   635   dest->package = g_intern_string (src->package);
       
   636   dest->origin = g_intern_string (src->origin);
       
   637 }
       
   638 
       
   639 /* unused */
       
   640 static void
       
   641 gst_plugin_desc_free (GstPluginDesc * desc)
       
   642 {
       
   643   g_free (desc->description);
       
   644   memset (desc, 0, sizeof (GstPluginDesc));
       
   645 }
       
   646 
       
   647 /**
       
   648  * gst_plugin_get_name:
       
   649  * @plugin: plugin to get the name of
       
   650  *
       
   651  * Get the short name of the plugin
       
   652  *
       
   653  * Returns: the name of the plugin
       
   654  */
       
   655 #ifdef __SYMBIAN32__
       
   656 EXPORT_C
       
   657 #endif
       
   658 
       
   659 const gchar *
       
   660 gst_plugin_get_name (GstPlugin * plugin)
       
   661 {
       
   662   g_return_val_if_fail (plugin != NULL, NULL);
       
   663 
       
   664   return plugin->desc.name;
       
   665 }
       
   666 
       
   667 /**
       
   668  * gst_plugin_get_description:
       
   669  * @plugin: plugin to get long name of
       
   670  *
       
   671  * Get the long descriptive name of the plugin
       
   672  *
       
   673  * Returns: the long name of the plugin
       
   674  */
       
   675 #ifdef __SYMBIAN32__
       
   676 EXPORT_C
       
   677 #endif
       
   678 
       
   679 G_CONST_RETURN gchar *
       
   680 gst_plugin_get_description (GstPlugin * plugin)
       
   681 {
       
   682   g_return_val_if_fail (plugin != NULL, NULL);
       
   683 
       
   684   return plugin->desc.description;
       
   685 }
       
   686 
       
   687 /**
       
   688  * gst_plugin_get_filename:
       
   689  * @plugin: plugin to get the filename of
       
   690  *
       
   691  * get the filename of the plugin
       
   692  *
       
   693  * Returns: the filename of the plugin
       
   694  */
       
   695 #ifdef __SYMBIAN32__
       
   696 EXPORT_C
       
   697 #endif
       
   698 
       
   699 G_CONST_RETURN gchar *
       
   700 gst_plugin_get_filename (GstPlugin * plugin)
       
   701 {
       
   702   g_return_val_if_fail (plugin != NULL, NULL);
       
   703 
       
   704   return plugin->filename;
       
   705 }
       
   706 
       
   707 /**
       
   708  * gst_plugin_get_version:
       
   709  * @plugin: plugin to get the version of
       
   710  *
       
   711  * get the version of the plugin
       
   712  *
       
   713  * Returns: the version of the plugin
       
   714  */
       
   715 #ifdef __SYMBIAN32__
       
   716 EXPORT_C
       
   717 #endif
       
   718 
       
   719 G_CONST_RETURN gchar *
       
   720 gst_plugin_get_version (GstPlugin * plugin)
       
   721 {
       
   722   g_return_val_if_fail (plugin != NULL, NULL);
       
   723 
       
   724   return plugin->desc.version;
       
   725 }
       
   726 
       
   727 /**
       
   728  * gst_plugin_get_license:
       
   729  * @plugin: plugin to get the license of
       
   730  *
       
   731  * get the license of the plugin
       
   732  *
       
   733  * Returns: the license of the plugin
       
   734  */
       
   735 #ifdef __SYMBIAN32__
       
   736 EXPORT_C
       
   737 #endif
       
   738 
       
   739 G_CONST_RETURN gchar *
       
   740 gst_plugin_get_license (GstPlugin * plugin)
       
   741 {
       
   742   g_return_val_if_fail (plugin != NULL, NULL);
       
   743 
       
   744   return plugin->desc.license;
       
   745 }
       
   746 
       
   747 /**
       
   748  * gst_plugin_get_source:
       
   749  * @plugin: plugin to get the source of
       
   750  *
       
   751  * get the source module the plugin belongs to.
       
   752  *
       
   753  * Returns: the source of the plugin
       
   754  */
       
   755 #ifdef __SYMBIAN32__
       
   756 EXPORT_C
       
   757 #endif
       
   758 
       
   759 G_CONST_RETURN gchar *
       
   760 gst_plugin_get_source (GstPlugin * plugin)
       
   761 {
       
   762   g_return_val_if_fail (plugin != NULL, NULL);
       
   763 
       
   764   return plugin->desc.source;
       
   765 }
       
   766 
       
   767 /**
       
   768  * gst_plugin_get_package:
       
   769  * @plugin: plugin to get the package of
       
   770  *
       
   771  * get the package the plugin belongs to.
       
   772  *
       
   773  * Returns: the package of the plugin
       
   774  */
       
   775 #ifdef __SYMBIAN32__
       
   776 EXPORT_C
       
   777 #endif
       
   778 
       
   779 G_CONST_RETURN gchar *
       
   780 gst_plugin_get_package (GstPlugin * plugin)
       
   781 {
       
   782   g_return_val_if_fail (plugin != NULL, NULL);
       
   783 
       
   784   return plugin->desc.package;
       
   785 }
       
   786 
       
   787 /**
       
   788  * gst_plugin_get_origin:
       
   789  * @plugin: plugin to get the origin of
       
   790  *
       
   791  * get the URL where the plugin comes from
       
   792  *
       
   793  * Returns: the origin of the plugin
       
   794  */
       
   795 #ifdef __SYMBIAN32__
       
   796 EXPORT_C
       
   797 #endif
       
   798 
       
   799 G_CONST_RETURN gchar *
       
   800 gst_plugin_get_origin (GstPlugin * plugin)
       
   801 {
       
   802   g_return_val_if_fail (plugin != NULL, NULL);
       
   803 
       
   804   return plugin->desc.origin;
       
   805 }
       
   806 
       
   807 /**
       
   808  * gst_plugin_get_module:
       
   809  * @plugin: plugin to query
       
   810  *
       
   811  * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is
       
   812  * returned.
       
   813  *
       
   814  * Returns: module belonging to the plugin or NULL if the plugin isn't
       
   815  *          loaded yet.
       
   816  */
       
   817 #ifdef __SYMBIAN32__
       
   818 EXPORT_C
       
   819 #endif
       
   820 
       
   821 GModule *
       
   822 gst_plugin_get_module (GstPlugin * plugin)
       
   823 {
       
   824   g_return_val_if_fail (plugin != NULL, NULL);
       
   825 
       
   826   return plugin->module;
       
   827 }
       
   828 
       
   829 /**
       
   830  * gst_plugin_is_loaded:
       
   831  * @plugin: plugin to query
       
   832  *
       
   833  * queries if the plugin is loaded into memory
       
   834  *
       
   835  * Returns: TRUE is loaded, FALSE otherwise
       
   836  */
       
   837 #ifdef __SYMBIAN32__
       
   838 EXPORT_C
       
   839 #endif
       
   840 
       
   841 gboolean
       
   842 gst_plugin_is_loaded (GstPlugin * plugin)
       
   843 {
       
   844   g_return_val_if_fail (plugin != NULL, FALSE);
       
   845 
       
   846   return (plugin->module != NULL || plugin->filename == NULL);
       
   847 }
       
   848 
       
   849 #if 0
       
   850 /**
       
   851  * gst_plugin_feature_list:
       
   852  * @plugin: plugin to query
       
   853  * @filter: the filter to use
       
   854  * @first: only return first match
       
   855  * @user_data: user data passed to the filter function
       
   856  *
       
   857  * Runs a filter against all plugin features and returns a GList with
       
   858  * the results. If the first flag is set, only the first match is
       
   859  * returned (as a list with a single object).
       
   860  *
       
   861  * Returns: a GList of features, g_list_free after use.
       
   862  */
       
   863 GList *
       
   864 gst_plugin_feature_filter (GstPlugin * plugin,
       
   865     GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
       
   866 {
       
   867   GList *list;
       
   868   GList *g;
       
   869 
       
   870   list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
       
   871       user_data);
       
   872   for (g = list; g; g = g->next) {
       
   873     gst_object_ref (plugin);
       
   874   }
       
   875 
       
   876   return list;
       
   877 }
       
   878 
       
   879 typedef struct
       
   880 {
       
   881   GstPluginFeatureFilter filter;
       
   882   gboolean first;
       
   883   gpointer user_data;
       
   884   GList *result;
       
   885 }
       
   886 FeatureFilterData;
       
   887 
       
   888 static gboolean
       
   889 _feature_filter (GstPlugin * plugin, gpointer user_data)
       
   890 {
       
   891   GList *result;
       
   892   FeatureFilterData *data = (FeatureFilterData *) user_data;
       
   893 
       
   894   result = gst_plugin_feature_filter (plugin, data->filter, data->first,
       
   895       data->user_data);
       
   896   if (result) {
       
   897     data->result = g_list_concat (data->result, result);
       
   898     return TRUE;
       
   899   }
       
   900   return FALSE;
       
   901 }
       
   902 
       
   903 /**
       
   904  * gst_plugin_list_feature_filter:
       
   905  * @list: a #GList of plugins to query
       
   906  * @filter: the filter function to use
       
   907  * @first: only return first match
       
   908  * @user_data: user data passed to the filter function
       
   909  *
       
   910  * Runs a filter against all plugin features of the plugins in the given
       
   911  * list and returns a GList with the results.
       
   912  * If the first flag is set, only the first match is
       
   913  * returned (as a list with a single object).
       
   914  *
       
   915  * Returns: a GList of features, g_list_free after use.
       
   916  */
       
   917 GList *
       
   918 gst_plugin_list_feature_filter (GList * list,
       
   919     GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
       
   920 {
       
   921   FeatureFilterData data;
       
   922   GList *result;
       
   923 
       
   924   data.filter = filter;
       
   925   data.first = first;
       
   926   data.user_data = user_data;
       
   927   data.result = NULL;
       
   928 
       
   929   result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
       
   930   g_list_free (result);
       
   931 
       
   932   return data.result;
       
   933 }
       
   934 #endif
       
   935 
       
   936 /**
       
   937  * gst_plugin_name_filter:
       
   938  * @plugin: the plugin to check
       
   939  * @name: the name of the plugin
       
   940  *
       
   941  * A standard filter that returns TRUE when the plugin is of the
       
   942  * given name.
       
   943  *
       
   944  * Returns: TRUE if the plugin is of the given name.
       
   945  */
       
   946 #ifdef __SYMBIAN32__
       
   947 EXPORT_C
       
   948 #endif
       
   949 
       
   950 gboolean
       
   951 gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
       
   952 {
       
   953   return (plugin->desc.name && !strcmp (plugin->desc.name, name));
       
   954 }
       
   955 
       
   956 #if 0
       
   957 /**
       
   958  * gst_plugin_find_feature:
       
   959  * @plugin: plugin to get the feature from
       
   960  * @name: The name of the feature to find
       
   961  * @type: The type of the feature to find
       
   962  *
       
   963  * Find a feature of the given name and type in the given plugin.
       
   964  *
       
   965  * Returns: a GstPluginFeature or NULL if the feature was not found.
       
   966  */
       
   967 GstPluginFeature *
       
   968 gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
       
   969 {
       
   970   GList *walk;
       
   971   GstPluginFeature *result = NULL;
       
   972   GstTypeNameData data;
       
   973 
       
   974   g_return_val_if_fail (name != NULL, NULL);
       
   975 
       
   976   data.type = type;
       
   977   data.name = name;
       
   978 
       
   979   walk = gst_filter_run (plugin->features,
       
   980       (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
       
   981 
       
   982   if (walk) {
       
   983     result = GST_PLUGIN_FEATURE (walk->data);
       
   984 
       
   985     gst_object_ref (result);
       
   986     gst_plugin_feature_list_free (walk);
       
   987   }
       
   988 
       
   989   return result;
       
   990 }
       
   991 #endif
       
   992 
       
   993 #if 0
       
   994 static gboolean
       
   995 gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
       
   996 {
       
   997   return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
       
   998 }
       
   999 #endif
       
  1000 
       
  1001 #if 0
       
  1002 /**
       
  1003  * gst_plugin_find_feature_by_name:
       
  1004  * @plugin: plugin to get the feature from
       
  1005  * @name: The name of the feature to find
       
  1006  *
       
  1007  * Find a feature of the given name in the given plugin.
       
  1008  *
       
  1009  * Returns: a GstPluginFeature or NULL if the feature was not found.
       
  1010  */
       
  1011 GstPluginFeature *
       
  1012 gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
       
  1013 {
       
  1014   GList *walk;
       
  1015   GstPluginFeature *result = NULL;
       
  1016 
       
  1017   g_return_val_if_fail (name != NULL, NULL);
       
  1018 
       
  1019   walk = gst_filter_run (plugin->features,
       
  1020       (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
       
  1021 
       
  1022   if (walk) {
       
  1023     result = GST_PLUGIN_FEATURE (walk->data);
       
  1024 
       
  1025     gst_object_ref (result);
       
  1026     gst_plugin_feature_list_free (walk);
       
  1027   }
       
  1028 
       
  1029   return result;
       
  1030 }
       
  1031 #endif
       
  1032 
       
  1033 /**
       
  1034  * gst_plugin_load_by_name:
       
  1035  * @name: name of plugin to load
       
  1036  *
       
  1037  * Load the named plugin. Refs the plugin.
       
  1038  *
       
  1039  * Returns: A reference to a loaded plugin, or NULL on error.
       
  1040  */
       
  1041 #ifdef __SYMBIAN32__
       
  1042 EXPORT_C
       
  1043 #endif
       
  1044 
       
  1045 GstPlugin *
       
  1046 gst_plugin_load_by_name (const gchar * name)
       
  1047 {
       
  1048   GstPlugin *plugin, *newplugin;
       
  1049   GError *error = NULL;
       
  1050 
       
  1051   GST_DEBUG ("looking up plugin %s in default registry", name);
       
  1052   plugin = gst_registry_find_plugin (gst_registry_get_default (), name);
       
  1053   if (plugin) {
       
  1054     GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
       
  1055     newplugin = gst_plugin_load_file (plugin->filename, &error);
       
  1056     gst_object_unref (plugin);
       
  1057 
       
  1058     if (!newplugin) {
       
  1059       GST_WARNING ("load_plugin error: %s", error->message);
       
  1060       g_error_free (error);
       
  1061       return NULL;
       
  1062     }
       
  1063     /* newplugin was reffed by load_file */
       
  1064     return newplugin;
       
  1065   }
       
  1066 
       
  1067   GST_DEBUG ("Could not find plugin %s in registry", name);
       
  1068   return NULL;
       
  1069 }
       
  1070 
       
  1071 /**
       
  1072  * gst_plugin_load:
       
  1073  * @plugin: plugin to load
       
  1074  *
       
  1075  * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
       
  1076  * untouched. The normal use pattern of this function goes like this:
       
  1077  *
       
  1078  * <programlisting>
       
  1079  * GstPlugin *loaded_plugin;
       
  1080  * loaded_plugin = gst_plugin_load (plugin);
       
  1081  * // presumably, we're no longer interested in the potentially-unloaded plugin
       
  1082  * gst_object_unref (plugin);
       
  1083  * plugin = loaded_plugin;
       
  1084  * </programlisting>
       
  1085  *
       
  1086  * Returns: A reference to a loaded plugin, or NULL on error.
       
  1087  */
       
  1088 #ifdef __SYMBIAN32__
       
  1089 EXPORT_C
       
  1090 #endif
       
  1091 
       
  1092 GstPlugin *
       
  1093 gst_plugin_load (GstPlugin * plugin)
       
  1094 {
       
  1095   GError *error = NULL;
       
  1096   GstPlugin *newplugin;
       
  1097 
       
  1098   if (gst_plugin_is_loaded (plugin)) {
       
  1099     return plugin;
       
  1100   }
       
  1101 
       
  1102   if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
       
  1103     goto load_error;
       
  1104 
       
  1105   return newplugin;
       
  1106 
       
  1107 load_error:
       
  1108   {
       
  1109     GST_WARNING ("load_plugin error: %s", error->message);
       
  1110     g_error_free (error);
       
  1111     return NULL;
       
  1112   }
       
  1113 }
       
  1114 
       
  1115 /**
       
  1116  * gst_plugin_list_free:
       
  1117  * @list: list of #GstPlugin
       
  1118  *
       
  1119  * Unrefs each member of @list, then frees the list.
       
  1120  */
       
  1121 #ifdef __SYMBIAN32__
       
  1122 EXPORT_C
       
  1123 #endif
       
  1124 
       
  1125 void
       
  1126 gst_plugin_list_free (GList * list)
       
  1127 {
       
  1128   GList *g;
       
  1129 
       
  1130   for (g = list; g; g = g->next) {
       
  1131     gst_object_unref (GST_PLUGIN_CAST (g->data));
       
  1132   }
       
  1133   g_list_free (list);
       
  1134 }