/* 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.
/* 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. */
+};
+
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",
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)
{
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",
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)
{
{ 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) {
// 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
+};
+
#include "gst_private.h"
#include "gstplugin.h"
+#include "gstversion.h"
#include "config.h"
gst_plugin_load_absolute (const gchar *name)
{
GModule *module;
- GstPluginInitFunc initfunc;
+ GstPluginDesc *desc;
GstPlugin *plugin;
struct stat file_status;
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);
/**
* 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;
typedef struct _GstPlugin GstPlugin;
-typedef struct _GstPluginElement GstPluginElement;
+typedef struct _GstPluginDesc GstPluginDesc;
struct _GstPlugin {
gchar *name; /* name of the plugin */
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);
};
-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]);
//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
+};
{ 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) {
// 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
+};
+
/* 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.
/* 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. */
+};
+