summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Boulton <richard@tartarus.org>2001-04-21 12:43:25 +0000
committerRichard Boulton <richard@tartarus.org>2001-04-21 12:43:25 +0000
commit3a3b69bdc6a9431234fda285591c0262b86adc2c (patch)
tree6a4e25ad18612a6e1ca5bd69e40ead14d806f3b1
parent72e5e1342c3ec546976fa8509e6c0c4995a82f2b (diff)
Use plugin descriptions, which start with the major and minor version numbers, instead of relying on each plugin to c...BRANCH-PLUGINVER1-20010422-FREEZE
Original commit message from CVS: Use plugin descriptions, which start with the major and minor version numbers, instead of relying on each plugin to call gst_plugin_new appropriately, and check the return value, and tidy up if there's a failure. This seems to work fine, and factors out some code common to all plugins.
-rw-r--r--examples/plugins/example.c33
-rw-r--r--gst/autoplug/gststaticautoplug.c17
-rw-r--r--gst/autoplug/gststaticautoplugrender.c17
-rw-r--r--gst/elements/gstelements.c17
-rw-r--r--gst/gstplugin.c19
-rw-r--r--gst/gstplugin.h11
-rw-r--r--gst/types/gsttypes.c17
-rw-r--r--plugins/elements/gstelements.c17
-rw-r--r--tests/old/examples/plugins/example.c33
9 files changed, 119 insertions, 62 deletions
diff --git a/examples/plugins/example.c b/examples/plugins/example.c
index 340436bb8..a2dad208c 100644
--- a/examples/plugins/example.c
+++ b/examples/plugins/example.c
@@ -335,23 +335,17 @@ gst_example_get_arg (GtkObject *object,GtkArg *arg,guint id)
/* This is the entry into the plugin itself. When the plugin loads,
* this function is called to register everything that the plugin provides.
*/
-GstPlugin*
-plugin_init (GModule *module)
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
{
- GstPlugin *plugin;
GstElementFactory *factory;
- /* First we try to create a new Plugin structure. */
- plugin = gst_plugin_new("example", GST_VERSION_MAJOR, GST_VERSION_MINOR);
- /* If we get a NULL back, chances are we're already loaded. */
- g_return_val_if_fail(plugin != NULL, NULL);
-
/* We need to create an ElementFactory for each element we provide.
* This consists of the name of the element, the GtkType identifier,
* and a pointer to the details structure at the top of the file.
*/
factory = gst_elementfactory_new("example", GST_TYPE_EXAMPLE, &example_details);
- g_return_val_if_fail(factory != NULL, NULL);
+ g_return_val_if_fail(factory != NULL, FALSE);
/* The pad templates can be easily generated from the factories above,
* and then added to the list of padtemplates for the elementfactory.
@@ -367,10 +361,27 @@ plugin_init (GModule *module)
/* The very last thing is to register the elementfactory with the plugin. */
gst_plugin_add_factory (plugin, factory);
- /* Now we can return the pointer to the newly created Plugin object. */
- return plugin;
+ /* Now we can return successfully. */
+ return TRUE;
/* At this point, the GStreamer core registers the plugin, its
* elementfactories, padtemplates, etc., for use in you application.
*/
}
+
+/* This structure describes the plugin to the system for dynamically loading
+ * plugins, so that the version number and name can be checked in a uniform
+ * way.
+ *
+ * The symbol pointing to this structure is the only symbol looked up when
+ * loading the plugin.
+ */
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR, /* The major version of the core that this was built with */
+ GST_VERSION_MINOR, /* The minor version of the core that this was built with */
+ "example", /* The name of the plugin. This must be unique: plugins with
+ * the same name will be assumed to be identical, and only
+ * one will be loaded. */
+ plugin_init /* Pointer to the initialisation function for the plugin. */
+};
+
diff --git a/gst/autoplug/gststaticautoplug.c b/gst/autoplug/gststaticautoplug.c
index a6ea72691..11403a069 100644
--- a/gst/autoplug/gststaticautoplug.c
+++ b/gst/autoplug/gststaticautoplug.c
@@ -80,15 +80,11 @@ gst_static_autoplug_class_init(GstStaticAutoplugClass *klass)
static void gst_static_autoplug_init(GstStaticAutoplug *autoplug) {
}
-GstPlugin*
-plugin_init (GModule *module)
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
{
- GstPlugin *plugin;
GstAutoplugFactory *factory;
- plugin = gst_plugin_new("gststaticautoplug", GST_VERSION_MAJOR, GST_VERSION_MINOR);
- g_return_val_if_fail(plugin != NULL,NULL);
-
gst_plugin_set_longname (plugin, "A static autoplugger");
factory = gst_autoplugfactory_new ("static",
@@ -98,9 +94,16 @@ plugin_init (GModule *module)
if (factory != NULL) {
gst_plugin_add_autoplugger (plugin, factory);
}
- return plugin;
+ return TRUE;
}
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "gststaticautoplug",
+ plugin_init
+};
+
static gboolean
gst_autoplug_can_match (GstElementFactory *src, GstElementFactory *dest)
{
diff --git a/gst/autoplug/gststaticautoplugrender.c b/gst/autoplug/gststaticautoplugrender.c
index da9b4f710..caf5ef5fb 100644
--- a/gst/autoplug/gststaticautoplugrender.c
+++ b/gst/autoplug/gststaticautoplugrender.c
@@ -80,15 +80,11 @@ gst_static_autoplug_render_class_init(GstStaticAutoplugRenderClass *klass)
static void gst_static_autoplug_render_init(GstStaticAutoplugRender *autoplug) {
}
-GstPlugin*
-plugin_init (GModule *module)
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
{
- GstPlugin *plugin;
GstAutoplugFactory *factory;
- plugin = gst_plugin_new("gststaticautoplugrender", GST_VERSION_MAJOR, GST_VERSION_MINOR);
- g_return_val_if_fail(plugin != NULL,NULL);
-
gst_plugin_set_longname (plugin, "A static autoplugger");
factory = gst_autoplugfactory_new ("staticrender",
@@ -98,9 +94,16 @@ plugin_init (GModule *module)
if (factory != NULL) {
gst_plugin_add_autoplugger (plugin, factory);
}
- return plugin;
+ return TRUE;
}
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "gststaticautoplugrender",
+ plugin_init
+};
+
static gboolean
gst_autoplug_can_match (GstElementFactory *src, GstElementFactory *dest)
{
diff --git a/gst/elements/gstelements.c b/gst/elements/gstelements.c
index fc326270b..afd086212 100644
--- a/gst/elements/gstelements.c
+++ b/gst/elements/gstelements.c
@@ -67,15 +67,12 @@ static struct _elements_entry _elements[] = {
{ NULL, 0 },
};
-GstPlugin *plugin_init (GModule *module)
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
{
- GstPlugin *plugin;
GstElementFactory *factory;
gint i = 0;
- plugin = gst_plugin_new("gstelements", GST_VERSION_MAJOR, GST_VERSION_MINOR);
- g_return_val_if_fail(plugin != NULL,NULL);
-
gst_plugin_set_longname (plugin, "Standard GST Elements");
while (_elements[i].name) {
@@ -94,5 +91,13 @@ GstPlugin *plugin_init (GModule *module)
// INFO (GST_INFO_PLUGIN_LOAD,"gstelements: loaded %d standard elements", i);
- return plugin;
+ return TRUE;
}
+
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "gstelements",
+ plugin_init
+};
+
diff --git a/gst/gstplugin.c b/gst/gstplugin.c
index a42da9910..fdbbd22b6 100644
--- a/gst/gstplugin.c
+++ b/gst/gstplugin.c
@@ -348,7 +348,7 @@ gboolean
gst_plugin_load_absolute (const gchar *name)
{
GModule *module;
- GstPluginInitFunc initfunc;
+ GstPluginDesc *desc;
GstPlugin *plugin;
struct stat file_status;
@@ -364,10 +364,19 @@ gst_plugin_load_absolute (const gchar *name)
module = g_module_open(name,G_MODULE_BIND_LAZY);
if (module != NULL) {
- if (g_module_symbol(module,"plugin_init",(gpointer *)&initfunc)) {
- GST_INFO (GST_CAT_PLUGIN_LOADING,"loading plugin \"%s\"...",
- name);
- if ((plugin = (initfunc)(module))) {
+ if (g_module_symbol(module,"plugin_desc",(gpointer *)&desc)) {
+ GST_INFO (GST_CAT_PLUGIN_LOADING,"loading plugin \"%s\"...", name);
+ plugin = gst_plugin_new(desc->name, desc->major_version, desc->minor_version);
+ if (plugin != NULL) {
+ if (!((desc->plugin_init)(module, plugin))) {
+ GST_INFO (GST_CAT_PLUGIN_LOADING,"plugin \"%s\" failed to initialise",
+ plugin->name);
+ g_free(plugin);
+ plugin = NULL;
+ }
+ }
+
+ if (plugin != NULL) {
GST_INFO (GST_CAT_PLUGIN_LOADING,"plugin \"%s\" loaded: %d elements, %d types",
plugin->name,plugin->numelements,plugin->numtypes);
plugin->filename = g_strdup(name);
diff --git a/gst/gstplugin.h b/gst/gstplugin.h
index ce4fe2999..48b9c9466 100644
--- a/gst/gstplugin.h
+++ b/gst/gstplugin.h
@@ -40,7 +40,7 @@
typedef struct _GstPlugin GstPlugin;
-typedef struct _GstPluginElement GstPluginElement;
+typedef struct _GstPluginDesc GstPluginDesc;
struct _GstPlugin {
gchar *name; /* name of the plugin */
@@ -57,8 +57,15 @@ struct _GstPlugin {
gboolean loaded; /* if the plugin is in memory */
};
+/* Initialiser function: returns TRUE if plugin initialised successfully */
+typedef gboolean (*GstPluginInitFunc) (GModule *module, GstPlugin *plugin);
-typedef GstPlugin* (*GstPluginInitFunc) (GModule *module);
+struct _GstPluginDesc {
+ gint major_version; /* major version of core that plugin was compiled for */
+ gint minor_version; /* minor version of core that plugin was compiled for */
+ gchar *name; /* name of plugin */
+ GstPluginInitFunc plugin_init; /* pointer to plugin_init function */
+};
void _gst_plugin_initialize (void);
diff --git a/gst/types/gsttypes.c b/gst/types/gsttypes.c
index 59449fdc1..0723f3db0 100644
--- a/gst/types/gsttypes.c
+++ b/gst/types/gsttypes.c
@@ -28,15 +28,11 @@ GstTypeFactory _factories[] = {
};
-GstPlugin*
-plugin_init (GModule *module)
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
{
- GstPlugin *plugin;
gint i = 0;
- plugin = gst_plugin_new ("gsttypes", GST_VERSION_MAJOR, GST_VERSION_MINOR);
- g_return_val_if_fail (plugin != NULL,NULL);
-
while (_factories[i].mime) {
gst_type_register (&_factories[i]);
gst_plugin_add_type (plugin, &_factories[i]);
@@ -46,5 +42,12 @@ plugin_init (GModule *module)
//gst_info ("gsttypes: loaded %d standard types\n",i);
- return plugin;
+ return TRUE;
}
+
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "gsttypes",
+ plugin_init
+};
diff --git a/plugins/elements/gstelements.c b/plugins/elements/gstelements.c
index fc326270b..afd086212 100644
--- a/plugins/elements/gstelements.c
+++ b/plugins/elements/gstelements.c
@@ -67,15 +67,12 @@ static struct _elements_entry _elements[] = {
{ NULL, 0 },
};
-GstPlugin *plugin_init (GModule *module)
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
{
- GstPlugin *plugin;
GstElementFactory *factory;
gint i = 0;
- plugin = gst_plugin_new("gstelements", GST_VERSION_MAJOR, GST_VERSION_MINOR);
- g_return_val_if_fail(plugin != NULL,NULL);
-
gst_plugin_set_longname (plugin, "Standard GST Elements");
while (_elements[i].name) {
@@ -94,5 +91,13 @@ GstPlugin *plugin_init (GModule *module)
// INFO (GST_INFO_PLUGIN_LOAD,"gstelements: loaded %d standard elements", i);
- return plugin;
+ return TRUE;
}
+
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "gstelements",
+ plugin_init
+};
+
diff --git a/tests/old/examples/plugins/example.c b/tests/old/examples/plugins/example.c
index 340436bb8..a2dad208c 100644
--- a/tests/old/examples/plugins/example.c
+++ b/tests/old/examples/plugins/example.c
@@ -335,23 +335,17 @@ gst_example_get_arg (GtkObject *object,GtkArg *arg,guint id)
/* This is the entry into the plugin itself. When the plugin loads,
* this function is called to register everything that the plugin provides.
*/
-GstPlugin*
-plugin_init (GModule *module)
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
{
- GstPlugin *plugin;
GstElementFactory *factory;
- /* First we try to create a new Plugin structure. */
- plugin = gst_plugin_new("example", GST_VERSION_MAJOR, GST_VERSION_MINOR);
- /* If we get a NULL back, chances are we're already loaded. */
- g_return_val_if_fail(plugin != NULL, NULL);
-
/* We need to create an ElementFactory for each element we provide.
* This consists of the name of the element, the GtkType identifier,
* and a pointer to the details structure at the top of the file.
*/
factory = gst_elementfactory_new("example", GST_TYPE_EXAMPLE, &example_details);
- g_return_val_if_fail(factory != NULL, NULL);
+ g_return_val_if_fail(factory != NULL, FALSE);
/* The pad templates can be easily generated from the factories above,
* and then added to the list of padtemplates for the elementfactory.
@@ -367,10 +361,27 @@ plugin_init (GModule *module)
/* The very last thing is to register the elementfactory with the plugin. */
gst_plugin_add_factory (plugin, factory);
- /* Now we can return the pointer to the newly created Plugin object. */
- return plugin;
+ /* Now we can return successfully. */
+ return TRUE;
/* At this point, the GStreamer core registers the plugin, its
* elementfactories, padtemplates, etc., for use in you application.
*/
}
+
+/* This structure describes the plugin to the system for dynamically loading
+ * plugins, so that the version number and name can be checked in a uniform
+ * way.
+ *
+ * The symbol pointing to this structure is the only symbol looked up when
+ * loading the plugin.
+ */
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR, /* The major version of the core that this was built with */
+ GST_VERSION_MINOR, /* The minor version of the core that this was built with */
+ "example", /* The name of the plugin. This must be unique: plugins with
+ * the same name will be assumed to be identical, and only
+ * one will be loaded. */
+ plugin_init /* Pointer to the initialisation function for the plugin. */
+};
+