- Removed unused locking from the cothreads
[platform/upstream/gstreamer.git] / gst / gstautoplug.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstautoplug.c: Autoplugging of pipelines
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /* #define GST_DEBUG_ENABLED */
24
25 #include <gst/gstconfig.h>
26
27 #include "gst_private.h"
28
29 #include "gstautoplug.h"
30 #include "gstregistry.h"
31 #include "gstlog.h"
32
33 enum {
34   NEW_OBJECT,
35   LAST_SIGNAL
36 };
37
38 enum {
39   ARG_0,
40   /* FILL ME */
41 };
42
43 static void     gst_autoplug_class_init (GstAutoplugClass *klass);
44 static void     gst_autoplug_init       (GstAutoplug *autoplug);
45
46 static GstObjectClass *parent_class = NULL;
47 static guint gst_autoplug_signals[LAST_SIGNAL] = { 0 };
48
49 GType gst_autoplug_get_type(void)
50 {
51   static GType autoplug_type = 0;
52
53   if (!autoplug_type) {
54     static const GTypeInfo autoplug_info = {
55       sizeof(GstAutoplugClass),
56       NULL,
57       NULL,
58       (GClassInitFunc)gst_autoplug_class_init,
59       NULL,
60       NULL,
61       sizeof(GstAutoplug),
62       4,
63       (GInstanceInitFunc)gst_autoplug_init,
64       NULL
65     };
66     autoplug_type = g_type_register_static (GST_TYPE_OBJECT, "GstAutoplug", &autoplug_info, G_TYPE_FLAG_ABSTRACT);
67   }
68   return autoplug_type;
69 }
70
71 static void
72 gst_autoplug_class_init(GstAutoplugClass *klass)
73 {
74   GObjectClass *gobject_class;
75   GstObjectClass *gstobject_class;
76
77   gobject_class = (GObjectClass*) klass;
78   gstobject_class = (GstObjectClass*) klass;
79
80   parent_class = g_type_class_ref (GST_TYPE_OBJECT);
81
82   gst_autoplug_signals[NEW_OBJECT] =
83     g_signal_new ("new_object", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
84                     G_STRUCT_OFFSET (GstAutoplugClass, new_object), NULL, NULL,
85                     g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
86                     GST_TYPE_OBJECT);
87
88 }
89
90 static void gst_autoplug_init(GstAutoplug *autoplug)
91 {
92 }
93
94 /**
95  * gst_autoplug_signal_new_object:
96  * @autoplug: The autoplugger to emit the signal 
97  * @object: The object that is passed to the signal
98  *
99  * Emit a new_object signal. autopluggers are supposed to
100  * emit this signal whenever a new object has been added to 
101  * the autoplugged pipeline.
102  * 
103  */
104 void
105 gst_autoplug_signal_new_object (GstAutoplug *autoplug, GstObject *object)
106 {
107   g_signal_emit (G_OBJECT (autoplug), gst_autoplug_signals[NEW_OBJECT], 0, object);
108 }
109
110
111 /**
112  * gst_autoplug_to_caps:
113  * @autoplug: The autoplugger perform the autoplugging
114  * @srccaps: The source cpabilities
115  * @sinkcaps: The target capabilities
116  * @...: more target capabilities
117  *
118  * Perform the autoplugging procedure on the given autoplugger. 
119  * The src caps will be connected to the sink caps.
120  * 
121  * Returns: A new Element that connects the src caps to the sink caps.
122  */
123 GstElement*
124 gst_autoplug_to_caps (GstAutoplug *autoplug, GstCaps *srccaps, GstCaps *sinkcaps, ...)
125 {
126   GstAutoplugClass *oclass;
127   GstElement *element = NULL;
128   va_list args;
129
130   va_start (args, sinkcaps);
131
132   oclass = GST_AUTOPLUG_CLASS (G_OBJECT_GET_CLASS(autoplug));
133   if (oclass->autoplug_to_caps)
134     element = (oclass->autoplug_to_caps) (autoplug, srccaps, sinkcaps, args);
135
136   va_end (args);
137
138   return element;
139 }
140
141 /**
142  * gst_autoplug_to_renderers:
143  * @autoplug: The autoplugger perform the autoplugging
144  * @srccaps: The source cpabilities
145  * @target: The target element 
146  * @...: more target elements
147  *
148  * Perform the autoplugging procedure on the given autoplugger. 
149  * The src caps will be connected to the target elements.
150  * 
151  * Returns: A new Element that connects the src caps to the target elements.
152  */
153 GstElement*
154 gst_autoplug_to_renderers (GstAutoplug *autoplug, GstCaps *srccaps, GstElement *target, ...)
155 {
156   GstAutoplugClass *oclass;
157   GstElement *element = NULL;
158   va_list args;
159
160   va_start (args, target);
161
162   oclass = GST_AUTOPLUG_CLASS (G_OBJECT_GET_CLASS(autoplug));
163   if (oclass->autoplug_to_renderers)
164     element = (oclass->autoplug_to_renderers) (autoplug, srccaps, target, args);
165
166   va_end (args);
167
168   return element;
169 }
170
171 static void             gst_autoplug_factory_class_init                 (GstAutoplugFactoryClass *klass);
172 static void             gst_autoplug_factory_init               (GstAutoplugFactory *factory);
173
174 static GstPluginFeatureClass *factory_parent_class = NULL;
175 /* static guint gst_autoplug_factory_signals[LAST_SIGNAL] = { 0 }; */
176
177 GType 
178 gst_autoplug_factory_get_type (void) 
179 {
180   static GType autoplugfactory_type = 0;
181
182   if (!autoplugfactory_type) {
183     static const GTypeInfo autoplugfactory_info = {
184       sizeof (GstAutoplugFactoryClass),
185       NULL,
186       NULL,
187       (GClassInitFunc) gst_autoplug_factory_class_init,
188       NULL,
189       NULL,
190       sizeof(GstAutoplugFactory),
191       0,
192       (GInstanceInitFunc) gst_autoplug_factory_init,
193       NULL
194     };
195     autoplugfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE, 
196                                                   "GstAutoplugFactory", &autoplugfactory_info, 0);
197   }
198   return autoplugfactory_type;
199 }
200
201 static void
202 gst_autoplug_factory_class_init (GstAutoplugFactoryClass *klass)
203 {
204   GObjectClass *gobject_class;
205   GstObjectClass *gstobject_class;
206   GstPluginFeatureClass *gstpluginfeature_class;
207
208   gobject_class = (GObjectClass*)klass;
209   gstobject_class = (GstObjectClass*)klass;
210   gstpluginfeature_class = (GstPluginFeatureClass*) klass;
211
212   factory_parent_class = g_type_class_ref (GST_TYPE_PLUGIN_FEATURE);
213 }
214
215 static void
216 gst_autoplug_factory_init (GstAutoplugFactory *factory)
217 {
218 }
219         
220
221 /**
222  * gst_autoplug_factory_new:
223  * @name: name of autoplugfactory to create
224  * @longdesc: long description of autoplugfactory to create
225  * @type: the gtk type of the GstAutoplug element of this factory
226  *
227  * Create a new autoplugfactory with the given parameters
228  *
229  * Returns: a new #GstAutoplugFactory.
230  */
231 GstAutoplugFactory*
232 gst_autoplug_factory_new (const gchar *name, const gchar *longdesc, GType type)
233 {
234   GstAutoplugFactory *factory;
235
236   g_return_val_if_fail(name != NULL, NULL);
237   factory = gst_autoplug_factory_find (name);
238   if (!factory) {
239     factory = GST_AUTOPLUG_FACTORY (g_object_new (GST_TYPE_AUTOPLUG_FACTORY, NULL));
240   }
241
242   GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (name);
243   if (factory->longdesc)
244     g_free (factory->longdesc);
245   factory->longdesc = g_strdup (longdesc);
246   factory->type = type;
247
248   return factory;
249 }
250
251 /**
252  * gst_autoplug_factory_destroy:
253  * @factory: factory to destroy
254  *
255  * Removes the autoplug from the global list.
256  */
257 void
258 gst_autoplug_factory_destroy (GstAutoplugFactory *factory)
259 {
260   g_return_if_fail (factory != NULL);
261
262   /* we don't free the struct bacause someone might  have a handle to it.. */
263 }
264
265 /**
266  * gst_autoplug_factory_find:
267  * @name: name of autoplugfactory to find
268  *
269  * Search for an autoplugfactory of the given name.
270  *
271  * Returns: #GstAutoplugFactory if found, NULL otherwise
272  */
273 GstAutoplugFactory*
274 gst_autoplug_factory_find (const gchar *name)
275 {
276   GstPluginFeature *feature;
277
278   g_return_val_if_fail (name != NULL, NULL);
279
280   GST_DEBUG (0,"gstautoplug: find \"%s\"", name);
281
282   feature = gst_registry_pool_find_feature (name, GST_TYPE_AUTOPLUG_FACTORY);
283   if (feature)
284     return GST_AUTOPLUG_FACTORY (feature);
285
286   return NULL;
287 }
288
289 /**
290  * gst_autoplug_factory_create:
291  * @factory: the factory used to create the instance
292  *
293  * Create a new #GstAutoplug instance from the 
294  * given autoplugfactory.
295  *
296  * Returns: A new #GstAutoplug instance.
297  */
298 GstAutoplug*
299 gst_autoplug_factory_create (GstAutoplugFactory *factory)
300 {
301   GstAutoplug *new = NULL;
302
303   g_return_val_if_fail (factory != NULL, NULL);
304
305   if (gst_plugin_feature_ensure_loaded (GST_PLUGIN_FEATURE (factory))) {
306     g_return_val_if_fail (factory->type != 0, NULL);
307
308     new = GST_AUTOPLUG (g_object_new(factory->type,NULL));
309   }
310
311   return new;
312 }
313
314 /**
315  * gst_autoplug_factory_make:
316  * @name: the name of the factory used to create the instance
317  *
318  * Create a new #GstAutoplug instance from the 
319  * autoplugfactory with the given name.
320  *
321  * Returns: A new #GstAutoplug instance.
322  */
323 GstAutoplug*
324 gst_autoplug_factory_make (const gchar *name)
325 {
326   GstAutoplugFactory *factory;
327
328   g_return_val_if_fail (name != NULL, NULL);
329
330   factory = gst_autoplug_factory_find (name);
331
332   if (factory == NULL)
333     return NULL;
334
335   return gst_autoplug_factory_create (factory);
336 }