summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Boulton <richard@tartarus.org>2001-04-22 12:30:14 +0000
committerRichard Boulton <richard@tartarus.org>2001-04-22 12:30:14 +0000
commit610e9e8227a28c1f18687685e6aab8ba5097983d (patch)
tree0ce535e1b2c4a461ba3c8f556139097dace979eb
parentfaf4bde938ef8225a935e2e7fc7a6e1e39d857cd (diff)
Merged from BRANCH-PLUGINVER1PLUGINVER1-20010422
Original commit message from CVS: Merged from BRANCH-PLUGINVER1
-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.c31
-rw-r--r--gst/gstplugin.h13
-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, 130 insertions, 65 deletions
diff --git a/examples/plugins/example.c b/examples/plugins/example.c
index 75e5c78ce..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");
- /* 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 ca06fe939..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");
- 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 2fb486c51..c544f7f18 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");
- 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 2b5dbf61b..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");
- 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 2e5362a2a..fdbbd22b6 100644
--- a/gst/gstplugin.c
+++ b/gst/gstplugin.c
@@ -27,6 +27,7 @@
#include "gst_private.h"
#include "gstplugin.h"
+#include "gstversion.h"
#include "config.h"
@@ -347,7 +348,7 @@ gboolean
gst_plugin_load_absolute (const gchar *name)
{
GModule *module;
- GstPluginInitFunc initfunc;
+ GstPluginDesc *desc;
GstPlugin *plugin;
struct stat file_status;
@@ -363,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);
@@ -392,16 +402,23 @@ gst_plugin_load_absolute (const gchar *name)
/**
* gst_plugin_new:
* @name: name of new plugin
+ * @major: major version number of core that plugin is compatible with
+ * @minor: minor version number of core that plugin is compatible with
*
* Create a new plugin with given name.
*
- * Returns: new plugin
+ * Returns: new plugin, or NULL if plugin couldn't be created, due to
+ * incompatible version number, or name already being allocated)
*/
GstPlugin*
-gst_plugin_new (const gchar *name)
+gst_plugin_new (const gchar *name, gint major, gint minor)
{
GstPlugin *plugin;
+ // return NULL if the major and minor version numbers are not compatible
+ // with ours.
+ if (major != GST_VERSION_MAJOR || minor != GST_VERSION_MINOR) return NULL;
+
// return NULL if the plugin is allready loaded
plugin = gst_plugin_find (name);
if (plugin) return NULL;
diff --git a/gst/gstplugin.h b/gst/gstplugin.h
index 299d10edc..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,12 +57,19 @@ 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);
-GstPlugin* gst_plugin_new (const gchar *name);
+GstPlugin* gst_plugin_new (const gchar *name, gint major, gint minor);
void gst_plugin_add_path (const gchar *path);
diff --git a/gst/types/gsttypes.c b/gst/types/gsttypes.c
index 9fe885b64..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");
- 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 2b5dbf61b..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");
- 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 75e5c78ce..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");
- /* 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. */
+};
+