#include "gst_private.h"
#include "gstelement.h"
+#include "gstregistrypool.h"
+#include "gstlog.h"
-static void gst_elementfactory_class_init (GstElementFactoryClass *klass);
-static void gst_elementfactory_init (GstElementFactory *factory);
+static void gst_element_factory_class_init (GstElementFactoryClass *klass);
+static void gst_element_factory_init (GstElementFactory *factory);
-#ifndef GST_DISABLE_REGISTRY
-static void gst_elementfactory_restore_thyself (GstObject *object, xmlNodePtr parent);
-static xmlNodePtr gst_elementfactory_save_thyself (GstObject *object, xmlNodePtr parent);
-#endif
-
-static void gst_elementfactory_unload_thyself (GstPluginFeature *feature);
-
-/* global list of registered elementfactories */
-static GList* _gst_elementfactories;
+static void gst_element_factory_unload_thyself (GstPluginFeature *feature);
static GstPluginFeatureClass *parent_class = NULL;
-/* static guint gst_elementfactory_signals[LAST_SIGNAL] = { 0 }; */
+/* static guint gst_element_factory_signals[LAST_SIGNAL] = { 0 }; */
GType
-gst_elementfactory_get_type (void)
+gst_element_factory_get_type (void)
{
static GType elementfactory_type = 0;
sizeof (GstElementFactoryClass),
NULL,
NULL,
- (GClassInitFunc) gst_elementfactory_class_init,
+ (GClassInitFunc) gst_element_factory_class_init,
NULL,
NULL,
sizeof(GstElementFactory),
0,
- (GInstanceInitFunc) gst_elementfactory_init,
+ (GInstanceInitFunc) gst_element_factory_init,
NULL
};
elementfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
}
static void
-gst_elementfactory_class_init (GstElementFactoryClass *klass)
+gst_element_factory_class_init (GstElementFactoryClass *klass)
{
GObjectClass *gobject_class;
GstObjectClass *gstobject_class;
parent_class = g_type_class_ref (GST_TYPE_PLUGIN_FEATURE);
-#ifndef GST_DISABLE_REGISTRY
- gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_elementfactory_save_thyself);
- gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR (gst_elementfactory_restore_thyself);
-#endif
+ gstpluginfeature_class->unload_thyself = GST_DEBUG_FUNCPTR (gst_element_factory_unload_thyself);
- gstpluginfeature_class->unload_thyself = GST_DEBUG_FUNCPTR (gst_elementfactory_unload_thyself);
-
- _gst_elementfactories = NULL;
}
static void
-gst_elementfactory_init (GstElementFactory *factory)
+gst_element_factory_init (GstElementFactory *factory)
{
factory->padtemplates = NULL;
factory->numpadtemplates = 0;
-
- _gst_elementfactories = g_list_prepend (_gst_elementfactories, factory);
}
/**
- * gst_elementfactory_find:
+ * gst_element_factory_find:
* @name: name of factory to find
*
- * Search for an elementfactory of the given name.
+ * Search for an element factory of the given name.
*
* Returns: #GstElementFactory if found, NULL otherwise
*/
GstElementFactory*
-gst_elementfactory_find (const gchar *name)
+gst_element_factory_find (const gchar *name)
{
- GList *walk;
- GstElementFactory *factory;
+ GstPluginFeature *feature;
g_return_val_if_fail(name != NULL, NULL);
- walk = _gst_elementfactories;
- while (walk) {
- factory = (GstElementFactory *)(walk->data);
- if (!strcmp(name, GST_OBJECT_NAME (factory)))
- return factory;
- walk = g_list_next(walk);
- }
+ feature = gst_registry_pool_find_feature (name, GST_TYPE_ELEMENT_FACTORY);
+ if (feature)
+ return GST_ELEMENT_FACTORY (feature);
/* this should be an ERROR */
- GST_DEBUG (GST_CAT_ELEMENTFACTORY,"no such elementfactory \"%s\"\n", name);
+ GST_DEBUG (GST_CAT_ELEMENT_FACTORY,"no such elementfactory \"%s\"", name);
return NULL;
}
-/**
- * gst_elementfactory_get_list:
- *
- * Get the global list of elementfactories.
- *
- * Returns: GList of type #GstElementFactory
- */
-const GList*
-gst_elementfactory_get_list (void)
+static void
+gst_element_details_free (GstElementDetails *dp)
{
- return _gst_elementfactories;
+ g_free (dp->longname);
+ g_free (dp->klass);
+ g_free (dp->license);
+ g_free (dp->description);
+ g_free (dp->version);
+ g_free (dp->author);
+ g_free (dp->copyright);
+ g_free (dp);
}
static void
-gst_element_details_free (GstElementDetails *dp)
+gst_element_factory_cleanup (GstElementFactory *factory)
{
- g_return_if_fail (dp);
-
- if (dp->longname)
- g_free (dp->longname);
- if (dp->klass)
- g_free (dp->klass);
- if (dp->description)
- g_free (dp->description);
- if (dp->version)
- g_free (dp->version);
- if (dp->author)
- g_free (dp->author);
- if (dp->copyright)
- g_free (dp->copyright);
- g_free (dp);
+ GList *padtemplates;
+
+ if (factory->details_dynamic) {
+ gst_element_details_free (factory->details);
+ factory->details_dynamic = FALSE;
+ }
+
+ padtemplates = factory->padtemplates;
+
+ while (padtemplates) {
+ GstPadTemplate *oldtempl = GST_PAD_TEMPLATE (padtemplates->data);
+
+ gst_object_unref (GST_OBJECT (oldtempl));
+
+ padtemplates = g_list_next (padtemplates);
+ }
+ g_list_free (factory->padtemplates);
+
+ factory->padtemplates = NULL;
+ factory->numpadtemplates = 0;
+
+ g_free (GST_PLUGIN_FEATURE (factory)->name);
}
/**
- * gst_elementfactory_new:
+ * gst_element_factory_new:
* @name: name of new elementfactory
* @type: GType of new element
* @details: #GstElementDetails structure with element details
* Returns: new elementfactory
*/
GstElementFactory*
-gst_elementfactory_new (const gchar *name, GType type,
+gst_element_factory_new (const gchar *name, GType type,
GstElementDetails *details)
{
GstElementFactory *factory;
- g_return_val_if_fail(name != NULL, NULL);
+ g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (type, NULL);
g_return_val_if_fail (details, NULL);
- factory = gst_elementfactory_find (name);
+ factory = gst_element_factory_find (name);
if (!factory)
- factory = GST_ELEMENTFACTORY (g_object_new (GST_TYPE_ELEMENTFACTORY, NULL));
-
- if (factory->details_dynamic)
- {
- gst_element_details_free (factory->details);
- factory->details_dynamic = FALSE;
- }
+ factory = GST_ELEMENT_FACTORY (g_object_new (GST_TYPE_ELEMENT_FACTORY, NULL));
+ else {
+ gst_element_factory_cleanup (factory);
+ }
factory->details = details;
+ factory->details_dynamic = FALSE;
if (!factory->type)
factory->type = type;
else if (factory->type != type)
g_critical ("`%s' requested type change (!)", name);
- gst_object_set_name (GST_OBJECT (factory), name);
+ GST_PLUGIN_FEATURE (factory)->name = g_strdup (name);
return factory;
}
/**
- * gst_elementfactory_create:
+ * gst_element_factory_create:
* @factory: factory to instantiate
* @name: name of new element
*
* Create a new element of the type defined by the given elementfactory.
- * It wll be given the name supplied, since all elements require a name as
+ * It will be given the name supplied, since all elements require a name as
* their first argument.
*
* Returns: new #GstElement
*/
-GstElement *
-gst_elementfactory_create (GstElementFactory *factory,
+GstElement*
+gst_element_factory_create (GstElementFactory *factory,
const gchar *name)
{
GstElement *element;
GstElementClass *oclass;
- g_return_val_if_fail(factory != NULL, NULL);
-
- GST_DEBUG (GST_CAT_ELEMENTFACTORY,"creating element from factory \"%s\" with name \"%s\" and type %d\n",
- GST_OBJECT_NAME (factory), name, factory->type);
+ g_return_val_if_fail (factory != NULL, NULL);
if (!gst_plugin_feature_ensure_loaded (GST_PLUGIN_FEATURE (factory)))
return NULL;
+ GST_DEBUG (GST_CAT_ELEMENT_FACTORY,
+ "creating element from factory \"%s\" (name \"%s\", type %d)",
+ GST_PLUGIN_FEATURE_NAME (factory), GST_STR_NULL (name), (gint) factory->type);
+
if (factory->type == 0) {
g_critical ("Factory for `%s' has no type",
- gst_object_get_name (GST_OBJECT (factory)));
+ GST_PLUGIN_FEATURE_NAME (factory));
return NULL;
}
/* create an instance of the element */
- element = GST_ELEMENT(g_object_new(factory->type,NULL));
- g_assert(element != NULL);
+ element = GST_ELEMENT (g_object_new (factory->type, NULL));
+ g_assert (element != NULL);
/* attempt to set the elemenfactory class pointer if necessary */
- oclass = GST_ELEMENT_CLASS(G_OBJECT_GET_CLASS(element));
+ oclass = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
if (oclass->elementfactory == NULL) {
- GST_DEBUG (GST_CAT_ELEMENTFACTORY,"class %s\n", GST_OBJECT_NAME (factory));
+ GST_DEBUG (GST_CAT_ELEMENT_FACTORY, "class %s", GST_PLUGIN_FEATURE_NAME (factory));
oclass->elementfactory = factory;
- /* copy pad template pointers to the element class, allow for custom padtemplates */
- oclass->padtemplates = g_list_concat (oclass->padtemplates, factory->padtemplates);
+ /* copy pad template pointers to the element class,
+ * allow for custom padtemplates */
+ oclass->padtemplates = g_list_concat (oclass->padtemplates,
+ g_list_copy (factory->padtemplates));
oclass->numpadtemplates += factory->numpadtemplates;
}
-
- gst_object_set_name (GST_OBJECT (element),name);
+
+ gst_object_set_name (GST_OBJECT (element), name);
return element;
}
/**
- * gst_elementfactory_make:
+ * gst_element_factory_make:
* @factoryname: a named factory to instantiate
* @name: name of new element
*
- * Create a new element of the type defined by the given elementfactory.
- * It wll be given the name supplied, since all elements require a name as
- * their first argument.
+ * Create a new element of the type defined by the given element factory.
+ * If name is NULL, then the element will receive a guaranteed unique name,
+ * consisting of the element factory name and a number.
+ * If name is given, it will be given the name supplied.
*
* Returns: new #GstElement (or NULL if unable to create element)
*/
GstElement*
-gst_elementfactory_make (const gchar *factoryname, const gchar *name)
+gst_element_factory_make (const gchar *factoryname, const gchar *name)
{
GstElementFactory *factory;
GstElement *element;
g_return_val_if_fail (factoryname != NULL, NULL);
- GST_DEBUG (GST_CAT_ELEMENTFACTORY, "gstelementfactory: make \"%s\" \"%s\"\n", factoryname, name);
+ GST_DEBUG (GST_CAT_ELEMENT_FACTORY, "gstelementfactory: make \"%s\" \"%s\"",
+ factoryname, GST_STR_NULL (name));
- /* gst_plugin_load_elementfactory(factoryname); */
- factory = gst_elementfactory_find(factoryname);
+ /* gst_plugin_load_element_factory (factoryname); */
+ factory = gst_element_factory_find (factoryname);
if (factory == NULL) {
- GST_INFO (GST_CAT_ELEMENTFACTORY,"no such elementfactory \"%s\"!",factoryname);
+ GST_INFO (GST_CAT_ELEMENT_FACTORY,"no such element factory \"%s\"!",
+ factoryname);
return NULL;
}
- element = gst_elementfactory_create(factory,name);
+ element = gst_element_factory_create (factory, name);
if (element == NULL) {
- GST_INFO (GST_CAT_ELEMENTFACTORY,"couldn't create instance of elementfactory \"%s\"!",factoryname);
+ GST_INFO (GST_CAT_ELEMENT_FACTORY,
+ "couldn't create instance of element factory \"%s\"!",
+ factoryname);
return NULL;
}
}
/**
- * gst_elementfactory_add_padtemplate :
+ * gst_element_factory_make_or_warn:
+ * @factoryname: a named factory to instantiate
+ * @name: name of new element
+ *
+ * Create a new element of the type defined by the given element factory
+ * using #gst_element_factory_make.
+ * Will use g_warning if the element could not be created.
+ *
+ * Returns: new #GstElement (or NULL if unable to create element)
+ */
+GstElement*
+gst_element_factory_make_or_warn (const gchar *factoryname, const gchar *name)
+{
+ GstElement *element;
+
+ element = gst_element_factory_make (factoryname, name);
+
+ if (element == NULL)
+ g_warning ("Could not create element from factory %s !\n", factoryname);
+
+ return element;
+}
+
+/**
+ * gst_element_factory_add_pad_template :
* @elementfactory: factory to add the src id to
* @templ: the padtemplate to add
*
* Add the given padtemplate to this elementfactory.
*/
void
-gst_elementfactory_add_padtemplate (GstElementFactory *factory,
- GstPadTemplate *templ)
+gst_element_factory_add_pad_template (GstElementFactory *factory,
+ GstPadTemplate *templ)
{
- GList *padtemplates;
-
- g_return_if_fail(factory != NULL);
- g_return_if_fail(templ != NULL);
-
- padtemplates = factory->padtemplates;
+ g_return_if_fail (factory != NULL);
+ g_return_if_fail (templ != NULL);
gst_object_ref (GST_OBJECT (templ));
+ gst_object_sink (GST_OBJECT (templ));
- while (padtemplates) {
- GstPadTemplate *oldtempl = GST_PADTEMPLATE (padtemplates->data);
-
- if (!strcmp (oldtempl->name_template, templ->name_template)) {
- gst_object_unref (GST_OBJECT (oldtempl));
- padtemplates->data = templ;
- return;
- }
-
- padtemplates = g_list_next (padtemplates);
- }
factory->padtemplates = g_list_append (factory->padtemplates, templ);
factory->numpadtemplates++;
}
/**
- * gst_elementfactory_can_src_caps :
+ * gst_element_factory_can_src_caps :
* @factory: factory to query
* @caps: the caps to check
*
* Returns: true if it can src the capabilities
*/
gboolean
-gst_elementfactory_can_src_caps (GstElementFactory *factory,
+gst_element_factory_can_src_caps (GstElementFactory *factory,
GstCaps *caps)
{
GList *templates;
GstPadTemplate *template = (GstPadTemplate *)templates->data;
if (template->direction == GST_PAD_SRC) {
- if (gst_caps_check_compatibility (GST_PADTEMPLATE_CAPS (template), caps))
+ if (gst_caps_is_always_compatible (GST_PAD_TEMPLATE_CAPS (template), caps))
return TRUE;
}
templates = g_list_next (templates);
}
/**
- * gst_elementfactory_can_sink_caps :
+ * gst_element_factory_can_sink_caps :
* @factory: factory to query
* @caps: the caps to check
*
* Returns: true if it can sink the capabilities
*/
gboolean
-gst_elementfactory_can_sink_caps (GstElementFactory *factory,
+gst_element_factory_can_sink_caps (GstElementFactory *factory,
GstCaps *caps)
{
GList *templates;
GstPadTemplate *template = (GstPadTemplate *)templates->data;
if (template->direction == GST_PAD_SINK) {
- if (gst_caps_check_compatibility (caps, GST_PADTEMPLATE_CAPS (template)))
+ if (gst_caps_is_always_compatible (caps, GST_PAD_TEMPLATE_CAPS (template)))
return TRUE;
}
templates = g_list_next (templates);
return FALSE;
}
-static void
-gst_elementfactory_unload_thyself (GstPluginFeature *feature)
+/**
+ * gst_element_factory_set_rank :
+ * @factory: factory to rank
+ * @rank: rank value - higher number means more priority rank
+ *
+ * Specifies a rank for the element so that
+ * autoplugging uses the most appropriate elements.
+ *
+ */
+void
+gst_element_factory_set_rank (GstElementFactory *factory, guint16 rank)
{
- GstElementFactory *factory;
-
- factory = GST_ELEMENTFACTORY (feature);
-
- factory->type = 0;
-}
-
-#ifndef GST_DISABLE_REGISTRY
-static xmlNodePtr
-gst_elementfactory_save_thyself (GstObject *object,
- xmlNodePtr parent)
-{
- GList *pads;
- GstElementFactory *factory;
-
- factory = GST_ELEMENTFACTORY (object);
-
- if (GST_OBJECT_CLASS (parent_class)->save_thyself) {
- GST_OBJECT_CLASS (parent_class)->save_thyself (object, parent);
- }
-
- g_return_val_if_fail(factory != NULL, NULL);
-
- if (factory->details)
- {
- xmlNewChild(parent,NULL,"longname", factory->details->longname);
- xmlNewChild(parent,NULL,"class", factory->details->klass);
- xmlNewChild(parent,NULL,"description", factory->details->description);
- xmlNewChild(parent,NULL,"version", factory->details->version);
- xmlNewChild(parent,NULL,"author", factory->details->author);
- xmlNewChild(parent,NULL,"copyright", factory->details->copyright);
- }
- else
- g_warning ("elementfactory `%s' is missing details",
- object->name);
-
- pads = factory->padtemplates;
- if (pads) {
- while (pads) {
- xmlNodePtr subtree;
- GstPadTemplate *padtemplate = (GstPadTemplate *)pads->data;
-
- subtree = xmlNewChild(parent, NULL, "padtemplate", NULL);
- gst_padtemplate_save_thyself(padtemplate, subtree);
-
- pads = g_list_next (pads);
- }
- }
- return parent;
+ g_return_if_fail (factory != NULL);
+ factory->rank = rank;
}
static void
-gst_elementfactory_restore_thyself (GstObject *object, xmlNodePtr parent)
+gst_element_factory_unload_thyself (GstPluginFeature *feature)
{
- GstElementFactory *factory = GST_ELEMENTFACTORY (object);
- xmlNodePtr children = parent->xmlChildrenNode;
-
- factory->details_dynamic = TRUE;
- factory->details = g_new0(GstElementDetails, 1);
- factory->padtemplates = NULL;
-
- if (GST_OBJECT_CLASS (parent_class)->restore_thyself) {
- GST_OBJECT_CLASS (parent_class)->restore_thyself (object, parent);
- }
-
- while (children) {
- if (!strcmp(children->name, "longname")) {
- factory->details->longname = xmlNodeGetContent(children);
- }
- if (!strcmp(children->name, "class")) {
- factory->details->klass = xmlNodeGetContent(children);
- }
- if (!strcmp(children->name, "description")) {
- factory->details->description = xmlNodeGetContent(children);
- }
- if (!strcmp(children->name, "version")) {
- factory->details->version = xmlNodeGetContent(children);
- }
- if (!strcmp(children->name, "author")) {
- factory->details->author = xmlNodeGetContent(children);
- }
- if (!strcmp(children->name, "copyright")) {
- factory->details->copyright = xmlNodeGetContent(children);
- }
- if (!strcmp(children->name, "padtemplate")) {
- GstPadTemplate *template;
-
- template = gst_padtemplate_load_thyself (children);
+ GstElementFactory *factory;
- gst_elementfactory_add_padtemplate (factory, template);
- }
+ factory = GST_ELEMENT_FACTORY (feature);
- children = children->next;
- }
+ factory->type = 0;
}
-#endif /* GST_DISABLE_REGISTRY */