2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstautoplug.c: Autoplugging of pipelines
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.
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.
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.
23 /* #define GST_DEBUG_ENABLED */
25 #include <gst/gstconfig.h>
27 #include "gst_private.h"
29 #include "gstautoplug.h"
30 #include "gstregistry.h"
43 static void gst_autoplug_class_init (GstAutoplugClass *klass);
44 static void gst_autoplug_init (GstAutoplug *autoplug);
46 static GstObjectClass *parent_class = NULL;
47 static guint gst_autoplug_signals[LAST_SIGNAL] = { 0 };
49 GType gst_autoplug_get_type(void)
51 static GType autoplug_type = 0;
54 static const GTypeInfo autoplug_info = {
55 sizeof(GstAutoplugClass),
58 (GClassInitFunc)gst_autoplug_class_init,
63 (GInstanceInitFunc)gst_autoplug_init,
66 autoplug_type = g_type_register_static (GST_TYPE_OBJECT, "GstAutoplug", &autoplug_info, G_TYPE_FLAG_ABSTRACT);
72 gst_autoplug_class_init(GstAutoplugClass *klass)
74 GObjectClass *gobject_class;
75 GstObjectClass *gstobject_class;
77 gobject_class = (GObjectClass*) klass;
78 gstobject_class = (GstObjectClass*) klass;
80 parent_class = g_type_class_ref (GST_TYPE_OBJECT);
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,
90 static void gst_autoplug_init(GstAutoplug *autoplug)
95 * gst_autoplug_signal_new_object:
96 * @autoplug: The autoplugger to emit the signal
97 * @object: The object that is passed to the signal
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.
105 gst_autoplug_signal_new_object (GstAutoplug *autoplug, GstObject *object)
107 g_signal_emit (G_OBJECT (autoplug), gst_autoplug_signals[NEW_OBJECT], 0, object);
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
118 * Perform the autoplugging procedure on the given autoplugger.
119 * The src caps will be connected to the sink caps.
121 * Returns: A new Element that connects the src caps to the sink caps.
124 gst_autoplug_to_caps (GstAutoplug *autoplug, GstCaps *srccaps, GstCaps *sinkcaps, ...)
126 GstAutoplugClass *oclass;
127 GstElement *element = NULL;
130 va_start (args, sinkcaps);
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);
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
148 * Perform the autoplugging procedure on the given autoplugger.
149 * The src caps will be connected to the target elements.
151 * Returns: A new Element that connects the src caps to the target elements.
154 gst_autoplug_to_renderers (GstAutoplug *autoplug, GstCaps *srccaps, GstElement *target, ...)
156 GstAutoplugClass *oclass;
157 GstElement *element = NULL;
160 va_start (args, target);
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);
171 static void gst_autoplug_factory_class_init (GstAutoplugFactoryClass *klass);
172 static void gst_autoplug_factory_init (GstAutoplugFactory *factory);
174 static GstPluginFeatureClass *factory_parent_class = NULL;
175 /* static guint gst_autoplug_factory_signals[LAST_SIGNAL] = { 0 }; */
178 gst_autoplug_factory_get_type (void)
180 static GType autoplugfactory_type = 0;
182 if (!autoplugfactory_type) {
183 static const GTypeInfo autoplugfactory_info = {
184 sizeof (GstAutoplugFactoryClass),
187 (GClassInitFunc) gst_autoplug_factory_class_init,
190 sizeof(GstAutoplugFactory),
192 (GInstanceInitFunc) gst_autoplug_factory_init,
195 autoplugfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
196 "GstAutoplugFactory", &autoplugfactory_info, 0);
198 return autoplugfactory_type;
202 gst_autoplug_factory_class_init (GstAutoplugFactoryClass *klass)
204 GObjectClass *gobject_class;
205 GstObjectClass *gstobject_class;
206 GstPluginFeatureClass *gstpluginfeature_class;
208 gobject_class = (GObjectClass*)klass;
209 gstobject_class = (GstObjectClass*)klass;
210 gstpluginfeature_class = (GstPluginFeatureClass*) klass;
212 factory_parent_class = g_type_class_ref (GST_TYPE_PLUGIN_FEATURE);
216 gst_autoplug_factory_init (GstAutoplugFactory *factory)
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
227 * Create a new autoplugfactory with the given parameters
229 * Returns: a new #GstAutoplugFactory.
232 gst_autoplug_factory_new (const gchar *name, const gchar *longdesc, GType type)
234 GstAutoplugFactory *factory;
236 g_return_val_if_fail(name != NULL, NULL);
237 factory = gst_autoplug_factory_find (name);
239 factory = GST_AUTOPLUG_FACTORY (g_object_new (GST_TYPE_AUTOPLUG_FACTORY, NULL));
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;
252 * gst_autoplug_factory_destroy:
253 * @factory: factory to destroy
255 * Removes the autoplug from the global list.
258 gst_autoplug_factory_destroy (GstAutoplugFactory *factory)
260 g_return_if_fail (factory != NULL);
262 /* we don't free the struct bacause someone might have a handle to it.. */
266 * gst_autoplug_factory_find:
267 * @name: name of autoplugfactory to find
269 * Search for an autoplugfactory of the given name.
271 * Returns: #GstAutoplugFactory if found, NULL otherwise
274 gst_autoplug_factory_find (const gchar *name)
276 GstPluginFeature *feature;
278 g_return_val_if_fail (name != NULL, NULL);
280 GST_DEBUG (0,"gstautoplug: find \"%s\"", name);
282 feature = gst_registry_pool_find_feature (name, GST_TYPE_AUTOPLUG_FACTORY);
284 return GST_AUTOPLUG_FACTORY (feature);
290 * gst_autoplug_factory_create:
291 * @factory: the factory used to create the instance
293 * Create a new #GstAutoplug instance from the
294 * given autoplugfactory.
296 * Returns: A new #GstAutoplug instance.
299 gst_autoplug_factory_create (GstAutoplugFactory *factory)
301 GstAutoplug *new = NULL;
303 g_return_val_if_fail (factory != NULL, NULL);
305 if (gst_plugin_feature_ensure_loaded (GST_PLUGIN_FEATURE (factory))) {
306 g_return_val_if_fail (factory->type != 0, NULL);
308 new = GST_AUTOPLUG (g_object_new(factory->type,NULL));
315 * gst_autoplug_factory_make:
316 * @name: the name of the factory used to create the instance
318 * Create a new #GstAutoplug instance from the
319 * autoplugfactory with the given name.
321 * Returns: A new #GstAutoplug instance.
324 gst_autoplug_factory_make (const gchar *name)
326 GstAutoplugFactory *factory;
328 g_return_val_if_fail (name != NULL, NULL);
330 factory = gst_autoplug_factory_find (name);
335 return gst_autoplug_factory_create (factory);