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);
126 // attempt to set the elemenfactory class pointer if necessary
127 oclass = GST_ELEMENT_CLASS(GTK_OBJECT(element)->klass);
128 if (oclass->elementfactory == NULL)
129 oclass->elementfactory = factory;
131 gst_element_set_name(GST_ELEMENT(element),name);
136 GstElement *gst_elementfactory_make(gchar *factoryname,gchar *name) {
137 GstElementFactory *factory;
140 gst_plugin_load_elementfactory(factoryname);
141 factory = gst_elementfactory_find(factoryname);
142 if (factory == NULL) return NULL;
143 element = gst_elementfactory_create(factory,name);
147 void gst_elementfactory_add_src(GstElementFactory *elementfactory, guint16 id) {
150 elementfactory->src_types = g_list_prepend(elementfactory->src_types, GUINT_TO_POINTER(type));
153 void gst_elementfactory_add_sink(GstElementFactory *elementfactory, guint16 id) {
156 elementfactory->sink_types = g_list_prepend(elementfactory->sink_types, GUINT_TO_POINTER(type));
159 xmlNodePtr gst_elementfactory_save_thyself(GstElementFactory *factory, xmlNodePtr parent) {
163 xmlNewChild(parent,NULL,"name",factory->name);
164 xmlNewChild(parent,NULL,"longname", factory->details->longname);
165 xmlNewChild(parent,NULL,"class", factory->details->class);
166 xmlNewChild(parent,NULL,"description", factory->details->description);
167 xmlNewChild(parent,NULL,"version", factory->details->version);
168 xmlNewChild(parent,NULL,"author", factory->details->author);
169 xmlNewChild(parent,NULL,"copyright", factory->details->copyright);
171 types = factory->src_types;
173 subtree = xmlNewChild(parent,NULL,"sources",NULL);
175 guint16 typeid = GPOINTER_TO_UINT(types->data);
176 GstType *type = gst_type_find_by_id(typeid);
178 gst_type_save_thyself(type, subtree);
180 types = g_list_next(types);
183 types = factory->sink_types;
185 subtree = xmlNewChild(parent,NULL,"sinks",NULL);
187 guint16 typeid = GPOINTER_TO_UINT(types->data);
188 GstType *type = gst_type_find_by_id(typeid);
190 gst_type_save_thyself(type, subtree);
192 types = g_list_next(types);
199 GstElementFactory *gst_elementfactory_load_thyself(xmlNodePtr parent) {
200 GstElementFactory *factory = g_new0(GstElementFactory, 1);
201 xmlNodePtr children = parent->childs;
202 factory->details = g_new0(GstElementDetails, 1);
203 factory->sink_types = NULL;
204 factory->src_types = NULL;
207 if (!strcmp(children->name, "name")) {
208 factory->name = g_strdup(xmlNodeGetContent(children));
210 if (!strcmp(children->name, "longname")) {
211 factory->details->longname = g_strdup(xmlNodeGetContent(children));
213 if (!strcmp(children->name, "class")) {
214 factory->details->class = g_strdup(xmlNodeGetContent(children));
216 if (!strcmp(children->name, "description")) {
217 factory->details->description = g_strdup(xmlNodeGetContent(children));
219 if (!strcmp(children->name, "version")) {
220 factory->details->version = g_strdup(xmlNodeGetContent(children));
222 if (!strcmp(children->name, "author")) {
223 factory->details->author = g_strdup(xmlNodeGetContent(children));
225 if (!strcmp(children->name, "copyright")) {
226 factory->details->copyright = g_strdup(xmlNodeGetContent(children));
228 if (!strcmp(children->name, "sources")) {
229 guint16 typeid = gst_type_load_thyself(children);
231 gst_type_add_src(typeid, factory);
233 if (!strcmp(children->name, "sinks")) {
234 guint16 typeid = gst_type_load_thyself(children);
236 gst_type_add_sink(typeid, factory);
239 children = children->next;