Use plugin descriptions, which start with the major and minor version numbers, instead of relying on each plugin to c...

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.
This commit is contained in:
Richard Boulton 2001-04-21 12:43:25 +00:00
parent 72e5e1342c
commit 3a3b69bdc6
9 changed files with 119 additions and 62 deletions

View file

@ -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 is the entry into the plugin itself. When the plugin loads,
* this function is called to register everything that the plugin provides. * this function is called to register everything that the plugin provides.
*/ */
GstPlugin* static gboolean
plugin_init (GModule *module) plugin_init (GModule *module, GstPlugin *plugin)
{ {
GstPlugin *plugin;
GstElementFactory *factory; 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. /* We need to create an ElementFactory for each element we provide.
* This consists of the name of the element, the GtkType identifier, * This consists of the name of the element, the GtkType identifier,
* and a pointer to the details structure at the top of the file. * and a pointer to the details structure at the top of the file.
*/ */
factory = gst_elementfactory_new("example", GST_TYPE_EXAMPLE, &example_details); 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, /* The pad templates can be easily generated from the factories above,
* and then added to the list of padtemplates for the elementfactory. * 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. */ /* The very last thing is to register the elementfactory with the plugin. */
gst_plugin_add_factory (plugin, factory); gst_plugin_add_factory (plugin, factory);
/* Now we can return the pointer to the newly created Plugin object. */ /* Now we can return successfully. */
return plugin; return TRUE;
/* At this point, the GStreamer core registers the plugin, its /* At this point, the GStreamer core registers the plugin, its
* elementfactories, padtemplates, etc., for use in you application. * 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. */
};

View file

@ -80,15 +80,11 @@ gst_static_autoplug_class_init(GstStaticAutoplugClass *klass)
static void gst_static_autoplug_init(GstStaticAutoplug *autoplug) { static void gst_static_autoplug_init(GstStaticAutoplug *autoplug) {
} }
GstPlugin* static gboolean
plugin_init (GModule *module) plugin_init (GModule *module, GstPlugin *plugin)
{ {
GstPlugin *plugin;
GstAutoplugFactory *factory; 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"); gst_plugin_set_longname (plugin, "A static autoplugger");
factory = gst_autoplugfactory_new ("static", factory = gst_autoplugfactory_new ("static",
@ -98,9 +94,16 @@ plugin_init (GModule *module)
if (factory != NULL) { if (factory != NULL) {
gst_plugin_add_autoplugger (plugin, factory); gst_plugin_add_autoplugger (plugin, factory);
} }
return plugin; return TRUE;
} }
GstPluginDesc plugin_desc = {
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"gststaticautoplug",
plugin_init
};
static gboolean static gboolean
gst_autoplug_can_match (GstElementFactory *src, GstElementFactory *dest) gst_autoplug_can_match (GstElementFactory *src, GstElementFactory *dest)
{ {

View file

@ -80,15 +80,11 @@ gst_static_autoplug_render_class_init(GstStaticAutoplugRenderClass *klass)
static void gst_static_autoplug_render_init(GstStaticAutoplugRender *autoplug) { static void gst_static_autoplug_render_init(GstStaticAutoplugRender *autoplug) {
} }
GstPlugin* static gboolean
plugin_init (GModule *module) plugin_init (GModule *module, GstPlugin *plugin)
{ {
GstPlugin *plugin;
GstAutoplugFactory *factory; 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"); gst_plugin_set_longname (plugin, "A static autoplugger");
factory = gst_autoplugfactory_new ("staticrender", factory = gst_autoplugfactory_new ("staticrender",
@ -98,9 +94,16 @@ plugin_init (GModule *module)
if (factory != NULL) { if (factory != NULL) {
gst_plugin_add_autoplugger (plugin, factory); gst_plugin_add_autoplugger (plugin, factory);
} }
return plugin; return TRUE;
} }
GstPluginDesc plugin_desc = {
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"gststaticautoplugrender",
plugin_init
};
static gboolean static gboolean
gst_autoplug_can_match (GstElementFactory *src, GstElementFactory *dest) gst_autoplug_can_match (GstElementFactory *src, GstElementFactory *dest)
{ {

View file

@ -67,15 +67,12 @@ static struct _elements_entry _elements[] = {
{ NULL, 0 }, { NULL, 0 },
}; };
GstPlugin *plugin_init (GModule *module) static gboolean
plugin_init (GModule *module, GstPlugin *plugin)
{ {
GstPlugin *plugin;
GstElementFactory *factory; GstElementFactory *factory;
gint i = 0; 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"); gst_plugin_set_longname (plugin, "Standard GST Elements");
while (_elements[i].name) { while (_elements[i].name) {
@ -94,5 +91,13 @@ GstPlugin *plugin_init (GModule *module)
// INFO (GST_INFO_PLUGIN_LOAD,"gstelements: loaded %d standard elements", i); // 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
};

View file

@ -348,7 +348,7 @@ gboolean
gst_plugin_load_absolute (const gchar *name) gst_plugin_load_absolute (const gchar *name)
{ {
GModule *module; GModule *module;
GstPluginInitFunc initfunc; GstPluginDesc *desc;
GstPlugin *plugin; GstPlugin *plugin;
struct stat file_status; struct stat file_status;
@ -364,10 +364,19 @@ gst_plugin_load_absolute (const gchar *name)
module = g_module_open(name,G_MODULE_BIND_LAZY); module = g_module_open(name,G_MODULE_BIND_LAZY);
if (module != NULL) { if (module != NULL) {
if (g_module_symbol(module,"plugin_init",(gpointer *)&initfunc)) { if (g_module_symbol(module,"plugin_desc",(gpointer *)&desc)) {
GST_INFO (GST_CAT_PLUGIN_LOADING,"loading plugin \"%s\"...", GST_INFO (GST_CAT_PLUGIN_LOADING,"loading plugin \"%s\"...", name);
name); plugin = gst_plugin_new(desc->name, desc->major_version, desc->minor_version);
if ((plugin = (initfunc)(module))) { 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", GST_INFO (GST_CAT_PLUGIN_LOADING,"plugin \"%s\" loaded: %d elements, %d types",
plugin->name,plugin->numelements,plugin->numtypes); plugin->name,plugin->numelements,plugin->numtypes);
plugin->filename = g_strdup(name); plugin->filename = g_strdup(name);

View file

@ -40,7 +40,7 @@
typedef struct _GstPlugin GstPlugin; typedef struct _GstPlugin GstPlugin;
typedef struct _GstPluginElement GstPluginElement; typedef struct _GstPluginDesc GstPluginDesc;
struct _GstPlugin { struct _GstPlugin {
gchar *name; /* name of the plugin */ gchar *name; /* name of the plugin */
@ -57,8 +57,15 @@ struct _GstPlugin {
gboolean loaded; /* if the plugin is in memory */ 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); void _gst_plugin_initialize (void);

View file

@ -28,15 +28,11 @@ GstTypeFactory _factories[] = {
}; };
GstPlugin* static gboolean
plugin_init (GModule *module) plugin_init (GModule *module, GstPlugin *plugin)
{ {
GstPlugin *plugin;
gint i = 0; 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) { while (_factories[i].mime) {
gst_type_register (&_factories[i]); gst_type_register (&_factories[i]);
gst_plugin_add_type (plugin, &_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); //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
};

View file

@ -67,15 +67,12 @@ static struct _elements_entry _elements[] = {
{ NULL, 0 }, { NULL, 0 },
}; };
GstPlugin *plugin_init (GModule *module) static gboolean
plugin_init (GModule *module, GstPlugin *plugin)
{ {
GstPlugin *plugin;
GstElementFactory *factory; GstElementFactory *factory;
gint i = 0; 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"); gst_plugin_set_longname (plugin, "Standard GST Elements");
while (_elements[i].name) { while (_elements[i].name) {
@ -94,5 +91,13 @@ GstPlugin *plugin_init (GModule *module)
// INFO (GST_INFO_PLUGIN_LOAD,"gstelements: loaded %d standard elements", i); // 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
};

View file

@ -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 is the entry into the plugin itself. When the plugin loads,
* this function is called to register everything that the plugin provides. * this function is called to register everything that the plugin provides.
*/ */
GstPlugin* static gboolean
plugin_init (GModule *module) plugin_init (GModule *module, GstPlugin *plugin)
{ {
GstPlugin *plugin;
GstElementFactory *factory; 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. /* We need to create an ElementFactory for each element we provide.
* This consists of the name of the element, the GtkType identifier, * This consists of the name of the element, the GtkType identifier,
* and a pointer to the details structure at the top of the file. * and a pointer to the details structure at the top of the file.
*/ */
factory = gst_elementfactory_new("example", GST_TYPE_EXAMPLE, &example_details); 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, /* The pad templates can be easily generated from the factories above,
* and then added to the list of padtemplates for the elementfactory. * 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. */ /* The very last thing is to register the elementfactory with the plugin. */
gst_plugin_add_factory (plugin, factory); gst_plugin_add_factory (plugin, factory);
/* Now we can return the pointer to the newly created Plugin object. */ /* Now we can return successfully. */
return plugin; return TRUE;
/* At this point, the GStreamer core registers the plugin, its /* At this point, the GStreamer core registers the plugin, its
* elementfactories, padtemplates, etc., for use in you application. * 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. */
};