1 /* Gnome-Streamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 *
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.
8 *
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.
13 *
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.
18 */
20 #include <gst/gstelement.h>
23 /* global list of registered elementfactories */
24 GList* _gst_elementfactories;
26 void _gst_elementfactory_initialize() {
27 _gst_elementfactories = NULL;
28 }
30 /**
31 * gst_elementfactory_register:
32 * @elementfactory: factory to register
33 *
34 * Adds the elementfactory to the global list, so it can be retrieved by
35 * name.
36 */
37 void gst_elementfactory_register(GstElementFactory *elementfactory) {
38 g_return_if_fail(elementfactory != NULL);
40 _gst_elementfactories = g_list_prepend(_gst_elementfactories,elementfactory);
41 }
43 /**
44 * gst_elementfactory_find:
45 * @name: name of factory to find
46 *
47 * Search for an elementfactory of the given name.
48 *
49 * Returns: #GstElementFactory if found, NULL otherwise
50 */
51 GstElementFactory *gst_elementfactory_find(gchar *name) {
52 GList *walk = _gst_elementfactories;
53 GstElementFactory *factory;
55 while (walk) {
56 factory = (GstElementFactory *)(walk->data);
57 if (!strcmp(name,factory->name))
58 return factory;
59 walk = g_list_next(walk);
60 }
62 return NULL;
63 }
65 /**
66 * gst_elementfactory_get_list:
67 *
68 * Get the global list of elementfactories.
69 *
70 * Returns: <type>GList</type> of type #GstElementFactory
71 */
72 GList *gst_elementfactory_get_list() {
73 return _gst_elementfactories;
74 }
77 /**
78 * gst_elementfactory_new:
79 * @name: name of new elementfactory
80 * @type: GtkType of new element
81 * @details: #GstElementDetails structure with element details
82 *
83 * Create a new elementfactory capable of insantiating objects of the
84 * given type.
85 *
86 * Returns: new elementfactory
87 */
88 GstElementFactory *gst_elementfactory_new(gchar *name,GtkType type,
89 GstElementDetails *details) {
90 GstElementFactory *factory = g_new0(GstElementFactory, 1);
91 factory->name = g_strdup(name);
92 factory->type = type;
93 factory->details = details;
94 return factory;
95 }
97 /**
98 * gst_elementfactory_create:
99 * @factory: factory to instantiate
100 * @name: name of new element
101 *
102 * Create a new element of the type defined by the given elementfactory.
103 * It wll be given the name supplied, since all elements require a name as
104 * their first argument.
105 *
106 * Returns: new #GstElement
107 */
108 GstElement *gst_elementfactory_create(GstElementFactory *factory,
109 gchar *name) {
110 GstElement *element;
111 GstElementClass *oclass;
113 g_return_if_fail(factory != NULL);
114 g_return_if_fail(factory->type != 0);
116 // create an instance of the element
117 element = GST_ELEMENT(gtk_type_new(factory->type));
118 g_assert(element != NULL);
120 // attempt to set the elemenfactory class pointer if necessary
121 oclass = GST_ELEMENT_CLASS(GTK_OBJECT(element)->klass);
122 if (oclass->elementfactory == NULL)
123 oclass->elementfactory = factory;
125 gst_element_set_name(GST_ELEMENT(element),name);
127 return element;
128 }
130 GstElement *gst_elementfactory_make(gchar *factoryname,gchar *name) {
131 GstElementFactory *factory;
132 GstElement *element;
134 factory = gst_elementfactory_find(factoryname);
135 if (factory == NULL) return NULL;
136 element = gst_elementfactory_create(factory,name);
137 return element;
138 }