From 7ff2f9233f024ad3a1ada64b823e84b5a65e1fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Alburquerque?= Date: Thu, 7 May 2009 16:37:37 +0200 Subject: [PATCH] API: Add gst_plugin_register_static_full() This is mainly useful for bindings that need to provide some additional user data to the registration function. Fixes bug #545787. --- docs/gst/gstreamer-sections.txt | 2 + gst/gstplugin.c | 97 ++++++++++++++++++++++++++++++--- gst/gstplugin.h | 29 ++++++++++ 3 files changed, 119 insertions(+), 9 deletions(-) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index c2714df0a1..cf2d7e22db 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -1643,6 +1643,7 @@ GstPluginError GstPlugin GstPluginDesc GstPluginInitFunc +GstPluginInitFullFunc GST_PLUGIN_DEFINE GST_PLUGIN_DEFINE_STATIC GST_LICENSE_UNKNOWN @@ -1663,6 +1664,7 @@ gst_plugin_load gst_plugin_load_by_name gst_plugin_list_free gst_plugin_register_static +gst_plugin_register_static_full GstPluginDependencyFlags gst_plugin_add_dependency diff --git a/gst/gstplugin.c b/gst/gstplugin.c index 8105d74302..f80ddac50a 100644 --- a/gst/gstplugin.c +++ b/gst/gstplugin.c @@ -100,7 +100,7 @@ static const gchar *valid_licenses[] = { }; static GstPlugin *gst_plugin_register_func (GstPlugin * plugin, - const GstPluginDesc * desc); + const GstPluginDesc * desc, gpointer user_data); static void gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src); static void gst_plugin_desc_free (GstPluginDesc * desc); @@ -242,7 +242,76 @@ gst_plugin_register_static (gint major_version, gint minor_version, GST_LOG ("attempting to load static plugin \"%s\" now...", name); plugin = g_object_new (GST_TYPE_PLUGIN, NULL); - if (gst_plugin_register_func (plugin, &desc) != NULL) { + if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) { + GST_INFO ("registered static plugin \"%s\"", name); + res = gst_default_registry_add_plugin (plugin); + GST_INFO ("added static plugin \"%s\", result: %d", name, res); + } + return res; +} + +/** + * gst_plugin_register_static_full: + * @major_version: the major version number of the GStreamer core that the + * plugin was compiled for, you can just use GST_VERSION_MAJOR here + * @minor_version: the minor version number of the GStreamer core that the + * plugin was compiled for, you can just use GST_VERSION_MINOR here + * @name: a unique name of the plugin (ideally prefixed with an application- or + * library-specific namespace prefix in order to avoid name conflicts in + * case a similar plugin with the same name ever gets added to GStreamer) + * @description: description of the plugin + * @init_full_func: pointer to the init function with user data of this plugin. + * @version: version string of the plugin + * @license: effective license of plugin. Must be one of the approved licenses + * (see #GstPluginDesc above) or the plugin will not be registered. + * @source: source module plugin belongs to + * @package: shipped package plugin belongs to + * @origin: URL to provider of plugin + * @user_data: gpointer to user data + * + * Registers a static plugin, ie. a plugin which is private to an application + * or library and contained within the application or library (as opposed to + * being shipped as a separate module file) with a #GstPluginInitFullFunc + * which allows user data to be passed to the callback function (useful + * for bindings). + * + * You must make sure that GStreamer has been initialised (with gst_init() or + * via gst_init_get_option_group()) before calling this function. + * + * Returns: TRUE if the plugin was registered correctly, otherwise FALSE. + * + * Since: 0.10.24 + * + */ +gboolean +gst_plugin_register_static_full (gint major_version, gint minor_version, + const gchar * name, gchar * description, + GstPluginInitFullFunc init_full_func, const gchar * version, + const gchar * license, const gchar * source, const gchar * package, + const gchar * origin, gpointer user_data) +{ + GstPluginDesc desc = { major_version, minor_version, name, description, + (GstPluginInitFunc) init_full_func, version, license, source, package, + origin, + }; + GstPlugin *plugin; + gboolean res = FALSE; + + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (description != NULL, FALSE); + g_return_val_if_fail (init_full_func != NULL, FALSE); + g_return_val_if_fail (version != NULL, FALSE); + g_return_val_if_fail (license != NULL, FALSE); + g_return_val_if_fail (source != NULL, FALSE); + g_return_val_if_fail (package != NULL, FALSE); + g_return_val_if_fail (origin != NULL, FALSE); + + /* make sure gst_init() has been called */ + g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE); + + GST_LOG ("attempting to load static plugin \"%s\" now...", name); + plugin = g_object_new (GST_TYPE_PLUGIN, NULL); + if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) { GST_INFO ("registered static plugin \"%s\"", name); res = gst_default_registry_add_plugin (plugin); GST_INFO ("added static plugin \"%s\", result: %d", name, res); @@ -306,7 +375,8 @@ gst_plugin_check_version (gint major, gint minor) } static GstPlugin * -gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc) +gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc, + gpointer user_data) { if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) { if (GST_CAT_DEFAULT) @@ -335,11 +405,20 @@ gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc) gst_plugin_desc_copy (&plugin->desc, desc); - if (!((desc->plugin_init) (plugin))) { - if (GST_CAT_DEFAULT) - GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename); - plugin->module = NULL; - return NULL; + if (user_data) { + if (!(((GstPluginInitFullFunc) (desc->plugin_init)) (plugin, user_data))) { + if (GST_CAT_DEFAULT) + GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename); + plugin->module = NULL; + return NULL; + } + } else { + if (!((desc->plugin_init) (plugin))) { + if (GST_CAT_DEFAULT) + GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename); + plugin->module = NULL; + return NULL; + } } if (GST_CAT_DEFAULT) @@ -547,7 +626,7 @@ gst_plugin_load_file (const gchar * filename, GError ** error) GST_LOG ("Plugin %p for file \"%s\" prepared, registering...", plugin, filename); - if (!gst_plugin_register_func (plugin, plugin->orig_desc)) { + if (!gst_plugin_register_func (plugin, plugin->orig_desc, NULL)) { /* remove signal handler */ _gst_plugin_fault_handler_restore (); GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename); diff --git a/gst/gstplugin.h b/gst/gstplugin.h index 72504cac62..d77f8579f8 100644 --- a/gst/gstplugin.h +++ b/gst/gstplugin.h @@ -109,6 +109,23 @@ typedef enum { */ typedef gboolean (*GstPluginInitFunc) (GstPlugin *plugin); +/** + * GstPluginInitFullFunc: + * @plugin: The plugin object that can be used to register #GstPluginFeatures for this plugin. + * @user_data: The user data. + * + * A plugin should provide a pointer to a function of either #GstPluginInitFunc + * or this type in the plugin_desc struct. + * The function will be called by the loader at startup. This version allows + * user data to be passed to init function (useful for bindings). + * + * Returns: %TRUE if plugin initialised successfully + * + * Since: 0.10.24 + * + */ +typedef gboolean (*GstPluginInitFullFunc) (GstPlugin *plugin, gpointer user_data); + /** * GstPluginDesc: * @major_version: the major version number of core that plugin was compiled for @@ -308,6 +325,18 @@ gboolean gst_plugin_register_static (gint major_version, const gchar *package, const gchar *origin); +gboolean gst_plugin_register_static_full (gint major_version, + gint minor_version, + const gchar *name, + gchar *description, + GstPluginInitFullFunc init_full_func, + const gchar *version, + const gchar *license, + const gchar *source, + const gchar *package, + const gchar *origin, + gpointer user_data); + G_CONST_RETURN gchar* gst_plugin_get_name (GstPlugin *plugin); G_CONST_RETURN gchar* gst_plugin_get_description (GstPlugin *plugin); G_CONST_RETURN gchar* gst_plugin_get_filename (GstPlugin *plugin);