API: add gst_plugin_register_static() and deprecate

Original commit message from CVS:
* docs/gst/gstreamer-sections.txt:
* gst/gst.c: (init_post):
* gst/gstplugin.c: (_gst_plugin_register_static),
(gst_plugin_register_static), (_gst_plugin_initialize),
(gst_plugin_register_func):
* gst/gstplugin.h: (GST_PLUGIN_DEFINE_STATIC):
API: add gst_plugin_register_static() and deprecate
GST_PLUGIN_DEFINE_STATIC, since it's not portable
(#498924).
Also, in _gst_plugin_register_static(), make sure to call
g_thread_init() before calling GLib functions such as
g_list_append() if we're not initialised yet, since that
may lead to random crashes with older GSlice/GLib versions.
* tests/check/gst/gstplugin.c:
Adapt unit test to above changes.
This commit is contained in:
Tim-Philipp Müller 2008-01-09 18:23:39 +00:00
parent d5d69b9475
commit 4a3f163052
6 changed files with 101 additions and 17 deletions

View file

@ -1,3 +1,22 @@
2008-01-09 Tim-Philipp Müller <tim at centricular dot net>
* docs/gst/gstreamer-sections.txt:
* gst/gst.c: (init_post):
* gst/gstplugin.c: (_gst_plugin_register_static),
(gst_plugin_register_static), (_gst_plugin_initialize),
(gst_plugin_register_func):
* gst/gstplugin.h: (GST_PLUGIN_DEFINE_STATIC):
API: add gst_plugin_register_static() and deprecate
GST_PLUGIN_DEFINE_STATIC, since it's not portable
(#498924).
Also, in _gst_plugin_register_static(), make sure to call
g_thread_init() before calling GLib functions such as
g_list_append() if we're not initialised yet, since that
may lead to random crashes with older GSlice/GLib versions.
* tests/check/gst/gstplugin.c:
Adapt unit test to above changes.
2008-01-09 Tim-Philipp Müller <tim at centricular dot net> 2008-01-09 Tim-Philipp Müller <tim at centricular dot net>
* gst/gst_private.h: (STRUCTURE_ESTIMATED_STRING_LEN): * gst/gst_private.h: (STRUCTURE_ESTIMATED_STRING_LEN):

View file

@ -1549,6 +1549,7 @@ gst_plugin_load_file
gst_plugin_load gst_plugin_load
gst_plugin_load_by_name gst_plugin_load_by_name
gst_plugin_list_free gst_plugin_list_free
gst_plugin_register_static
<SUBSECTION Standard> <SUBSECTION Standard>
GstPluginClass GstPluginClass
GST_PLUGIN GST_PLUGIN

View file

@ -993,11 +993,11 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
_gst_message_initialize (); _gst_message_initialize ();
_gst_tag_initialize (); _gst_tag_initialize ();
/* register core plugins */
_gst_plugin_register_static (&plugin_desc);
_gst_plugin_initialize (); _gst_plugin_initialize ();
/* register core plugins */
gst_plugin_register_static (&plugin_desc);
/* /*
* Any errors happening below this point are non-fatal, we therefore mark * Any errors happening below this point are non-fatal, we therefore mark
* gstreamer as being initialized, since it is the case from a plugin point of * gstreamer as being initialized, since it is the case from a plugin point of

View file

@ -106,7 +106,7 @@ static const gchar *valid_licenses[] = {
}; };
static GstPlugin *gst_plugin_register_func (GstPlugin * plugin, static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
GstPluginDesc * desc); const GstPluginDesc * desc);
static void gst_plugin_desc_copy (GstPluginDesc * dest, static void gst_plugin_desc_copy (GstPluginDesc * dest,
const GstPluginDesc * src); const GstPluginDesc * src);
static void gst_plugin_desc_free (GstPluginDesc * desc); static void gst_plugin_desc_free (GstPluginDesc * desc);
@ -156,6 +156,7 @@ gst_plugin_error_quark (void)
return quark; return quark;
} }
#ifndef GST_REMOVE_DEPRECATED
/* this function can be called in the GCC constructor extension, before /* this function can be called in the GCC constructor extension, before
* the _gst_plugin_initialize() was called. In that case, we store the * the _gst_plugin_initialize() was called. In that case, we store the
* plugin description in a list to initialize it when we open the main * plugin description in a list to initialize it when we open the main
@ -165,24 +166,58 @@ gst_plugin_error_quark (void)
void void
_gst_plugin_register_static (GstPluginDesc * desc) _gst_plugin_register_static (GstPluginDesc * desc)
{ {
g_return_if_fail (desc != NULL);
if (!_gst_plugin_inited) { if (!_gst_plugin_inited) {
/* Must call g_thread_init() before calling GLib functions such as
* g_list_prepend() ... */
if (!g_thread_supported ())
g_thread_init (NULL);
if (GST_CAT_DEFAULT) if (GST_CAT_DEFAULT)
GST_LOG ("queueing static plugin \"%s\" for loading later on", GST_LOG ("queueing static plugin \"%s\" for loading later on",
desc->name); desc->name);
_gst_plugin_static = g_list_prepend (_gst_plugin_static, desc); _gst_plugin_static = g_list_prepend (_gst_plugin_static, desc);
} else { } else {
GstPlugin *plugin; gst_plugin_register_static (desc);
if (GST_CAT_DEFAULT)
GST_LOG ("attempting to load static plugin \"%s\" now...", desc->name);
plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
if (gst_plugin_register_func (plugin, desc)) {
if (GST_CAT_DEFAULT)
GST_INFO ("loaded static plugin \"%s\"", desc->name);
gst_default_registry_add_plugin (plugin);
}
} }
} }
#endif
/**
* gst_plugin_register_static:
* @desc: a #GstPluginDesc describing the plugin.
*
* 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).
*
* 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.16
*/
gboolean
gst_plugin_register_static (const GstPluginDesc * desc)
{
GstPlugin *plugin;
gboolean res = FALSE;
g_return_val_if_fail (desc != 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...", desc->name);
plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
if (gst_plugin_register_func (plugin, desc) != NULL) {
GST_INFO ("loaded static plugin \"%s\"", desc->name);
res = gst_default_registry_add_plugin (plugin);
}
return res;
}
void void
_gst_plugin_initialize (void) _gst_plugin_initialize (void)
@ -190,8 +225,7 @@ _gst_plugin_initialize (void)
_gst_plugin_inited = TRUE; _gst_plugin_inited = TRUE;
/* now register all static plugins */ /* now register all static plugins */
g_list_foreach (_gst_plugin_static, (GFunc) _gst_plugin_register_static, g_list_foreach (_gst_plugin_static, (GFunc) gst_plugin_register_static, NULL);
NULL);
} }
/* this function could be extended to check if the plugin license matches the /* this function could be extended to check if the plugin license matches the
@ -225,7 +259,7 @@ gst_plugin_check_version (gint major, gint minor)
} }
static GstPlugin * static GstPlugin *
gst_plugin_register_func (GstPlugin * plugin, GstPluginDesc * desc) gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc)
{ {
if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) { if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
if (GST_CAT_DEFAULT) if (GST_CAT_DEFAULT)

View file

@ -197,6 +197,7 @@ GST_PLUGIN_EXPORT GstPluginDesc gst_plugin_desc = { \
GST_PADDING_INIT \ GST_PADDING_INIT \
}; };
#ifndef GST_DISABLE_DEPRECATED
/** /**
* GST_PLUGIN_DEFINE_STATIC: * GST_PLUGIN_DEFINE_STATIC:
* @major: major version number of the gstreamer-core that plugin was compiled for * @major: major version number of the gstreamer-core that plugin was compiled for
@ -212,6 +213,10 @@ GST_PLUGIN_EXPORT GstPluginDesc gst_plugin_desc = { \
* This macro needs to be used to define the entry point and meta data of a * This macro needs to be used to define the entry point and meta data of a
* local plugin. One would use this macro to define a local plugin that can only * local plugin. One would use this macro to define a local plugin that can only
* be used by the own application. * be used by the own application.
*
* Deprecated: Use gst_plugin_register_static() instead. This macro was
* deprecated because it uses constructors, which is a compiler feature not
* available on all compilers.
*/ */
#define GST_PLUGIN_DEFINE_STATIC(major,minor,name,description,init,version,license,package,origin) \ #define GST_PLUGIN_DEFINE_STATIC(major,minor,name,description,init,version,license,package,origin) \
static void GST_GNUC_CONSTRUCTOR \ static void GST_GNUC_CONSTRUCTOR \
@ -232,6 +237,7 @@ _gst_plugin_static_init__ ##init (void) \
}; \ }; \
_gst_plugin_register_static (&plugin_desc_); \ _gst_plugin_register_static (&plugin_desc_); \
} }
#endif
/** /**
* GST_LICENSE_UNKNOWN: * GST_LICENSE_UNKNOWN:
@ -258,7 +264,11 @@ typedef gboolean (*GstPluginFilter) (GstPlugin *plugin,
GType gst_plugin_get_type (void); GType gst_plugin_get_type (void);
#ifndef GST_DISABLE_DEPRECATED
void _gst_plugin_register_static (GstPluginDesc *desc); void _gst_plugin_register_static (GstPluginDesc *desc);
#endif
gboolean gst_plugin_register_static (const GstPluginDesc *desc);
G_CONST_RETURN gchar* gst_plugin_get_name (GstPlugin *plugin); 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_description (GstPlugin *plugin);

View file

@ -25,6 +25,10 @@
#include <gst/check/gstcheck.h> #include <gst/check/gstcheck.h>
#ifdef GST_DISABLE_DEPRECATED
void _gst_plugin_register_static (GstPluginDesc * desc);
#endif
static gboolean static gboolean
register_check_elements (GstPlugin * plugin) register_check_elements (GstPlugin * plugin)
{ {
@ -46,11 +50,27 @@ static GstPluginDesc plugin_desc = {
GST_PADDING_INIT GST_PADDING_INIT
}; };
static GstPluginDesc plugin_desc2 = {
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"more-elements",
"more-elements",
register_check_elements,
VERSION,
GST_LICENSE,
PACKAGE,
GST_PACKAGE_NAME,
GST_PACKAGE_ORIGIN,
GST_PADDING_INIT
};
GST_START_TEST (test_register_static) GST_START_TEST (test_register_static)
{ {
GstPlugin *plugin; GstPlugin *plugin;
_gst_plugin_register_static (&plugin_desc); _gst_plugin_register_static (&plugin_desc);
gst_plugin_register_static (&plugin_desc2);
plugin = g_object_new (GST_TYPE_PLUGIN, NULL); plugin = g_object_new (GST_TYPE_PLUGIN, NULL);