2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <gst/gstelement.h>
21 #include <gst/gstplugin.h>
24 /* global list of registered elementfactories */
25 GList* _gst_elementfactories;
27 void _gst_elementfactory_initialize() {
28 _gst_elementfactories = NULL;
32 * gst_elementfactory_register:
33 * @elementfactory: factory to register
35 * Adds the elementfactory to the global list, so it can be retrieved by
38 void gst_elementfactory_register(GstElementFactory *elementfactory) {
39 g_return_if_fail(elementfactory != NULL);
41 _gst_elementfactories = g_list_prepend(_gst_elementfactories,elementfactory);
45 * gst_elementfactory_find:
46 * @name: name of factory to find
48 * Search for an elementfactory of the given name.
50 * Returns: #GstElementFactory if found, NULL otherwise
52 GstElementFactory *gst_elementfactory_find(gchar *name) {
53 GList *walk = _gst_elementfactories;
54 GstElementFactory *factory;
57 factory = (GstElementFactory *)(walk->data);
58 if (!strcmp(name,factory->name))
60 walk = g_list_next(walk);
67 * gst_elementfactory_get_list:
69 * Get the global list of elementfactories.
71 * Returns: <type>GList</type> of type #GstElementFactory
73 GList *gst_elementfactory_get_list() {
74 return _gst_elementfactories;
79 * gst_elementfactory_new:
80 * @name: name of new elementfactory
81 * @type: GtkType of new element
82 * @details: #GstElementDetails structure with element details
84 * Create a new elementfactory capable of insantiating objects of the
87 * Returns: new elementfactory
89 GstElementFactory *gst_elementfactory_new(gchar *name,GtkType type,
90 GstElementDetails *details) {
91 GstElementFactory *factory = g_new0(GstElementFactory, 1);
92 factory->name = g_strdup(name);
94 factory->details = details;
95 factory->src_types = NULL;
96 factory->sink_types = NULL;
101 * gst_elementfactory_create:
102 * @factory: factory to instantiate
103 * @name: name of new element
105 * Create a new element of the type defined by the given elementfactory.
106 * It wll be given the name supplied, since all elements require a name as
107 * their first argument.
109 * Returns: new #GstElement
111 GstElement *gst_elementfactory_create(GstElementFactory *factory,
114 GstElementClass *oclass;
116 g_return_val_if_fail(factory != NULL, NULL);
118 factory = gst_plugin_load_elementfactory(factory->name);
120 g_return_val_if_fail(factory->type != 0, NULL);
122 // create an instance of the element
123 element = GST_ELEMENT(gtk_type_new(factory->type));
124 g_assert(element != NULL);
125 gst_object_ref(GST_OBJECT(element));
127 // attempt to set the elemenfactory class pointer if necessary
128 oclass = GST_ELEMENT_CLASS(GTK_OBJECT(element)->klass);
129 if (oclass->elementfactory == NULL)
130 oclass->elementfactory = factory;
132 gst_element_set_name(GST_ELEMENT(element),name);
138 * gst_elementfactory_make:
139 * @factoryname: a named factory to instantiate
140 * @name: name of new element
142 * Create a new element of the type defined by the given elementfactory.
143 * It wll be given the name supplied, since all elements require a name as
144 * their first argument.
146 * Returns: new #GstElement
148 GstElement *gst_elementfactory_make(gchar *factoryname,gchar *name) {
149 GstElementFactory *factory;
152 gst_plugin_load_elementfactory(factoryname);
153 factory = gst_elementfactory_find(factoryname);
154 if (factory == NULL) return NULL;
155 element = gst_elementfactory_create(factory,name);
160 * gst_elementfactory_add_src:
161 * @elementfactory: factory to add the src id to
162 * @id: the mime id of the src
164 * Use this function to indicate that this factory can src
167 void gst_elementfactory_add_src(GstElementFactory *elementfactory, guint16 id) {
170 elementfactory->src_types = g_list_prepend(elementfactory->src_types, GUINT_TO_POINTER(type));
174 * gst_elementfactory_add_sink:
175 * @elementfactory: factory to add the sink id to
176 * @id: the type id of the sink
178 * Use this function to indicate that this factory can sink
181 void gst_elementfactory_add_sink(GstElementFactory *elementfactory, guint16 id) {
184 elementfactory->sink_types = g_list_prepend(elementfactory->sink_types, GUINT_TO_POINTER(type));
188 * gst_elementfactory_save_thyself:
189 * @factory: factory to save
190 * @parent: the parent xmlNodePtr
192 * Saves the factory into an XML tree
194 * Returns: the new xmlNodePtr
196 xmlNodePtr gst_elementfactory_save_thyself(GstElementFactory *factory, xmlNodePtr parent) {
200 xmlNewChild(parent,NULL,"name",factory->name);
201 xmlNewChild(parent,NULL,"longname", factory->details->longname);
202 xmlNewChild(parent,NULL,"class", factory->details->class);
203 xmlNewChild(parent,NULL,"description", factory->details->description);
204 xmlNewChild(parent,NULL,"version", factory->details->version);
205 xmlNewChild(parent,NULL,"author", factory->details->author);
206 xmlNewChild(parent,NULL,"copyright", factory->details->copyright);
208 types = factory->src_types;
210 subtree = xmlNewChild(parent,NULL,"sources",NULL);
212 guint16 typeid = GPOINTER_TO_UINT(types->data);
213 GstType *type = gst_type_find_by_id(typeid);
215 gst_type_save_thyself(type, subtree);
217 types = g_list_next(types);
220 types = factory->sink_types;
222 subtree = xmlNewChild(parent,NULL,"sinks",NULL);
224 guint16 typeid = GPOINTER_TO_UINT(types->data);
225 GstType *type = gst_type_find_by_id(typeid);
227 gst_type_save_thyself(type, subtree);
229 types = g_list_next(types);
237 * gst_elementfactory_load_thyself:
238 * @parent: the parent xmlNodePtr
240 * Creates a new factory from an xmlNodePtr
242 * Returns: the new factory
244 GstElementFactory *gst_elementfactory_load_thyself(xmlNodePtr parent) {
245 GstElementFactory *factory = g_new0(GstElementFactory, 1);
246 xmlNodePtr children = parent->childs;
247 factory->details = g_new0(GstElementDetails, 1);
248 factory->sink_types = NULL;
249 factory->src_types = NULL;
252 if (!strcmp(children->name, "name")) {
253 factory->name = g_strdup(xmlNodeGetContent(children));
255 if (!strcmp(children->name, "longname")) {
256 factory->details->longname = g_strdup(xmlNodeGetContent(children));
258 if (!strcmp(children->name, "class")) {
259 factory->details->class = g_strdup(xmlNodeGetContent(children));
261 if (!strcmp(children->name, "description")) {
262 factory->details->description = g_strdup(xmlNodeGetContent(children));
264 if (!strcmp(children->name, "version")) {
265 factory->details->version = g_strdup(xmlNodeGetContent(children));
267 if (!strcmp(children->name, "author")) {
268 factory->details->author = g_strdup(xmlNodeGetContent(children));
270 if (!strcmp(children->name, "copyright")) {
271 factory->details->copyright = g_strdup(xmlNodeGetContent(children));
273 if (!strcmp(children->name, "sources")) {
274 guint16 typeid = gst_type_load_thyself(children);
276 gst_type_add_src(typeid, factory);
278 if (!strcmp(children->name, "sinks")) {
279 guint16 typeid = gst_type_load_thyself(children);
281 gst_type_add_sink(typeid, factory);
284 children = children->next;