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.
diff --git a/ChangeLog b/ChangeLog
index 6b6ca58..a9f5893 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
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>
+
* gst/gst_private.h: (STRUCTURE_ESTIMATED_STRING_LEN):
* gst/gstcaps.c: (gst_caps_to_string):
* gst/gststructure.c: (GST_ASCII_IS_STRING),
diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt
index d5700a9..3fe399b 100644
--- a/docs/gst/gstreamer-sections.txt
+++ b/docs/gst/gstreamer-sections.txt
@@ -1549,6 +1549,7 @@
gst_plugin_load
gst_plugin_load_by_name
gst_plugin_list_free
+gst_plugin_register_static
<SUBSECTION Standard>
GstPluginClass
GST_PLUGIN
diff --git a/gst/gst.c b/gst/gst.c
index 132d9fc..e084b74 100644
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -993,11 +993,11 @@
_gst_message_initialize ();
_gst_tag_initialize ();
- /* register core plugins */
- _gst_plugin_register_static (&plugin_desc);
-
_gst_plugin_initialize ();
+ /* register core plugins */
+ gst_plugin_register_static (&plugin_desc);
+
/*
* 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
diff --git a/gst/gstplugin.c b/gst/gstplugin.c
index 10f56c7..af146dd 100644
--- a/gst/gstplugin.c
+++ b/gst/gstplugin.c
@@ -106,7 +106,7 @@
};
static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
- GstPluginDesc * desc);
+ const GstPluginDesc * desc);
static void gst_plugin_desc_copy (GstPluginDesc * dest,
const GstPluginDesc * src);
static void gst_plugin_desc_free (GstPluginDesc * desc);
@@ -156,6 +156,7 @@
return quark;
}
+#ifndef GST_REMOVE_DEPRECATED
/* this function can be called in the GCC constructor extension, before
* 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
@@ -165,24 +166,58 @@
void
_gst_plugin_register_static (GstPluginDesc * desc)
{
+ g_return_if_fail (desc != NULL);
+
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)
GST_LOG ("queueing static plugin \"%s\" for loading later on",
desc->name);
_gst_plugin_static = g_list_prepend (_gst_plugin_static, desc);
} else {
- GstPlugin *plugin;
-
- 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);
- }
+ gst_plugin_register_static (desc);
}
}
+#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
_gst_plugin_initialize (void)
@@ -190,8 +225,7 @@
_gst_plugin_inited = TRUE;
/* now register all static plugins */
- g_list_foreach (_gst_plugin_static, (GFunc) _gst_plugin_register_static,
- NULL);
+ g_list_foreach (_gst_plugin_static, (GFunc) gst_plugin_register_static, NULL);
}
/* this function could be extended to check if the plugin license matches the
@@ -225,7 +259,7 @@
}
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_CAT_DEFAULT)
diff --git a/gst/gstplugin.h b/gst/gstplugin.h
index d65fccd..73ef5cd 100644
--- a/gst/gstplugin.h
+++ b/gst/gstplugin.h
@@ -197,6 +197,7 @@
GST_PADDING_INIT \
};
+#ifndef GST_DISABLE_DEPRECATED
/**
* GST_PLUGIN_DEFINE_STATIC:
* @major: major version number of the gstreamer-core that plugin was compiled for
@@ -212,6 +213,10 @@
* 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
* 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) \
static void GST_GNUC_CONSTRUCTOR \
@@ -232,6 +237,7 @@
}; \
_gst_plugin_register_static (&plugin_desc_); \
}
+#endif
/**
* GST_LICENSE_UNKNOWN:
@@ -258,7 +264,11 @@
GType gst_plugin_get_type (void);
+#ifndef GST_DISABLE_DEPRECATED
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_description (GstPlugin *plugin);
diff --git a/tests/check/gst/gstplugin.c b/tests/check/gst/gstplugin.c
index d645732..a251ff5 100644
--- a/tests/check/gst/gstplugin.c
+++ b/tests/check/gst/gstplugin.c
@@ -25,6 +25,10 @@
#include <gst/check/gstcheck.h>
+#ifdef GST_DISABLE_DEPRECATED
+void _gst_plugin_register_static (GstPluginDesc * desc);
+#endif
+
static gboolean
register_check_elements (GstPlugin * plugin)
{
@@ -46,11 +50,27 @@
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)
{
GstPlugin *plugin;
_gst_plugin_register_static (&plugin_desc);
+ gst_plugin_register_static (&plugin_desc2);
plugin = g_object_new (GST_TYPE_PLUGIN, NULL);