2000-12-28 22:12:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstautoplug.c: Autoplugging of pipelines
|
2000-12-19 13:44:23 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2000-12-29 19:45:45 +00:00
|
|
|
//#define GST_DEBUG_ENABLED
|
2000-12-28 22:12:02 +00:00
|
|
|
#include "gst_private.h"
|
|
|
|
|
2000-12-19 13:44:23 +00:00
|
|
|
#include "gstautoplug.h"
|
2001-03-07 21:52:56 +00:00
|
|
|
#include "gstplugin.h"
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
GList* _gst_autoplugfactories;
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
enum {
|
|
|
|
NEW_OBJECT,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
/* FILL ME */
|
2000-12-19 13:44:23 +00:00
|
|
|
};
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void gst_autoplug_class_init (GstAutoplugClass *klass);
|
|
|
|
static void gst_autoplug_init (GstAutoplug *autoplug);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2000-12-22 16:14:33 +00:00
|
|
|
static GstObjectClass *parent_class = NULL;
|
2001-03-07 21:52:56 +00:00
|
|
|
static guint gst_autoplug_signals[LAST_SIGNAL] = { 0 };
|
2000-12-22 16:14:33 +00:00
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
GType gst_autoplug_get_type(void)
|
2001-03-07 21:52:56 +00:00
|
|
|
{
|
2001-06-13 21:52:36 +00:00
|
|
|
static GType autoplug_type = 0;
|
2000-12-22 16:14:33 +00:00
|
|
|
|
|
|
|
if (!autoplug_type) {
|
2001-06-13 21:52:36 +00:00
|
|
|
static const GTypeInfo autoplug_info = {
|
2001-03-07 21:52:56 +00:00
|
|
|
sizeof(GstAutoplugClass),
|
2001-06-13 21:52:36 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_autoplug_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstAutoplug),
|
|
|
|
4,
|
|
|
|
(GInstanceInitFunc)gst_autoplug_init,
|
2000-12-22 16:14:33 +00:00
|
|
|
};
|
2001-06-13 21:52:36 +00:00
|
|
|
autoplug_type = g_type_register_static (GST_TYPE_OBJECT, "GstAutoplug", &autoplug_info, 0);
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
2000-12-22 16:14:33 +00:00
|
|
|
return autoplug_type;
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2000-12-22 16:14:33 +00:00
|
|
|
static void
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_autoplug_class_init(GstAutoplugClass *klass)
|
|
|
|
{
|
2001-06-13 21:52:36 +00:00
|
|
|
GObjectClass *gobject_class;
|
2001-03-07 21:52:56 +00:00
|
|
|
GstObjectClass *gstobject_class;
|
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
gobject_class = (GObjectClass*) klass;
|
2001-03-07 21:52:56 +00:00
|
|
|
gstobject_class = (GstObjectClass*) klass;
|
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_OBJECT);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
gst_autoplug_signals[NEW_OBJECT] =
|
2001-06-13 21:52:36 +00:00
|
|
|
g_signal_newc ("new_object", G_OBJECT_TYPE(gobject_class), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstAutoplugClass, new_object), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
|
2001-03-07 21:52:56 +00:00
|
|
|
GST_TYPE_OBJECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gst_autoplug_init(GstAutoplug *autoplug)
|
|
|
|
{
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
void
|
|
|
|
_gst_autoplug_initialize (void)
|
|
|
|
{
|
|
|
|
_gst_autoplugfactories = NULL;
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-21 21:43:56 +00:00
|
|
|
/**
|
|
|
|
* gst_autoplug_signal_new_object:
|
|
|
|
* @autoplug: The autoplugger to emit the signal
|
|
|
|
* @object: The object that is passed to the signal
|
|
|
|
*
|
|
|
|
* Emit a new_object signal. autopluggers are supposed to
|
|
|
|
* emit this signal whenever a new object has been added to
|
|
|
|
* the autoplugged pipeline.
|
|
|
|
*
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
void
|
|
|
|
gst_autoplug_signal_new_object (GstAutoplug *autoplug, GstObject *object)
|
2000-12-19 13:44:23 +00:00
|
|
|
{
|
2001-06-13 21:52:36 +00:00
|
|
|
g_signal_emit (G_OBJECT (autoplug), gst_autoplug_signals[NEW_OBJECT], 0, object);
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
2000-12-19 13:44:23 +00:00
|
|
|
|
|
|
|
|
2001-03-21 21:43:56 +00:00
|
|
|
/**
|
|
|
|
* gst_autoplug_to_caps:
|
|
|
|
* @autoplug: The autoplugger perform the autoplugging
|
|
|
|
* @srccaps: The source cpabilities
|
|
|
|
* @sinkcaps: The target capabilities
|
|
|
|
* @...: more target capabilities
|
|
|
|
*
|
|
|
|
* Perform the autoplugging procedure on the given autoplugger.
|
|
|
|
* The src caps will be connected to the sink caps.
|
|
|
|
*
|
|
|
|
* Returns: A new Element that connects the src caps to the sink caps.
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
GstElement*
|
2001-03-12 21:02:12 +00:00
|
|
|
gst_autoplug_to_caps (GstAutoplug *autoplug, GstCaps *srccaps, GstCaps *sinkcaps, ...)
|
2001-03-07 21:52:56 +00:00
|
|
|
{
|
|
|
|
GstAutoplugClass *oclass;
|
|
|
|
GstElement *element = NULL;
|
|
|
|
va_list args;
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
va_start (args, sinkcaps);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
oclass = GST_AUTOPLUG_CLASS (G_OBJECT_GET_CLASS(autoplug));
|
2001-03-07 21:52:56 +00:00
|
|
|
if (oclass->autoplug_to_caps)
|
|
|
|
element = (oclass->autoplug_to_caps) (autoplug, srccaps, sinkcaps, args);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
va_end (args);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
return element;
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
2001-01-21 23:20:46 +00:00
|
|
|
|
2001-03-21 21:43:56 +00:00
|
|
|
/**
|
|
|
|
* gst_autoplug_to_renderers:
|
|
|
|
* @autoplug: The autoplugger perform the autoplugging
|
|
|
|
* @srccaps: The source cpabilities
|
|
|
|
* @target: The target element
|
|
|
|
* @...: more target elements
|
|
|
|
*
|
|
|
|
* Perform the autoplugging procedure on the given autoplugger.
|
|
|
|
* The src caps will be connected to the target elements.
|
|
|
|
*
|
|
|
|
* Returns: A new Element that connects the src caps to the target elements.
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
GstElement*
|
2001-03-12 21:02:12 +00:00
|
|
|
gst_autoplug_to_renderers (GstAutoplug *autoplug, GstCaps *srccaps, GstElement *target, ...)
|
2000-12-19 13:44:23 +00:00
|
|
|
{
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplugClass *oclass;
|
|
|
|
GstElement *element = NULL;
|
|
|
|
va_list args;
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
va_start (args, target);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
oclass = GST_AUTOPLUG_CLASS (G_OBJECT_GET_CLASS(autoplug));
|
2001-03-07 21:52:56 +00:00
|
|
|
if (oclass->autoplug_to_renderers)
|
|
|
|
element = (oclass->autoplug_to_renderers) (autoplug, srccaps, target, args);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
va_end (args);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
return element;
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2000-12-31 17:02:47 +00:00
|
|
|
/**
|
2001-03-07 21:52:56 +00:00
|
|
|
* gst_autoplugfactory_new:
|
|
|
|
* @name: name of autoplugfactory to create
|
|
|
|
* @longdesc: long description of autoplugfactory to create
|
|
|
|
* @type: the gtk type of the GstAutoplug element of this factory
|
2000-12-31 17:02:47 +00:00
|
|
|
*
|
2001-03-07 21:52:56 +00:00
|
|
|
* Create a new autoplugfactory with the given parameters
|
2000-12-31 17:02:47 +00:00
|
|
|
*
|
2001-03-07 21:52:56 +00:00
|
|
|
* Returns: a new #GstAutoplugFactory.
|
2000-12-31 17:02:47 +00:00
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplugFactory*
|
2001-06-13 21:52:36 +00:00
|
|
|
gst_autoplugfactory_new (const gchar *name, const gchar *longdesc, GType type)
|
2000-12-19 13:44:23 +00:00
|
|
|
{
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplugFactory *factory;
|
|
|
|
|
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
factory = g_new0(GstAutoplugFactory, 1);
|
2000-12-31 16:12:48 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
factory->name = g_strdup(name);
|
|
|
|
factory->longdesc = g_strdup (longdesc);
|
|
|
|
factory->type = type;
|
2000-12-31 16:12:48 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
_gst_autoplugfactories = g_list_prepend (_gst_autoplugfactories, factory);
|
|
|
|
|
|
|
|
return factory;
|
2000-12-31 16:12:48 +00:00
|
|
|
}
|
|
|
|
|
2000-12-31 17:02:47 +00:00
|
|
|
/**
|
2001-03-07 21:52:56 +00:00
|
|
|
* gst_autoplugfactory_destroy:
|
2001-03-21 21:43:56 +00:00
|
|
|
* @factory: factory to destroy
|
2000-12-31 17:02:47 +00:00
|
|
|
*
|
2001-03-07 21:52:56 +00:00
|
|
|
* Removes the autoplug from the global list.
|
2000-12-31 17:02:47 +00:00
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
void
|
2001-03-21 21:43:56 +00:00
|
|
|
gst_autoplugfactory_destroy (GstAutoplugFactory *factory)
|
2000-12-31 16:12:48 +00:00
|
|
|
{
|
2001-03-21 21:43:56 +00:00
|
|
|
g_return_if_fail (factory != NULL);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-21 21:43:56 +00:00
|
|
|
_gst_autoplugfactories = g_list_remove (_gst_autoplugfactories, factory);
|
2000-12-30 16:13:17 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
// we don't free the struct bacause someone might have a handle to it..
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2000-12-31 17:02:47 +00:00
|
|
|
/**
|
2001-03-21 21:43:56 +00:00
|
|
|
* gst_autoplugfactory_find:
|
|
|
|
* @name: name of autoplugfactory to find
|
2000-12-31 17:02:47 +00:00
|
|
|
*
|
2001-03-21 21:43:56 +00:00
|
|
|
* Search for an autoplugfactory of the given name.
|
2000-12-31 17:02:47 +00:00
|
|
|
*
|
2001-03-21 21:43:56 +00:00
|
|
|
* Returns: #GstAutoplugFactory if found, NULL otherwise
|
2000-12-31 17:02:47 +00:00
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplugFactory*
|
|
|
|
gst_autoplugfactory_find (const gchar *name)
|
2000-12-31 16:12:48 +00:00
|
|
|
{
|
2001-03-07 21:52:56 +00:00
|
|
|
GList *walk;
|
|
|
|
GstAutoplugFactory *factory;
|
|
|
|
|
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
2000-12-31 16:12:48 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
GST_DEBUG (0,"gstautoplug: find \"%s\"\n", name);
|
2000-12-31 16:12:48 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
walk = _gst_autoplugfactories;
|
|
|
|
while (walk) {
|
|
|
|
factory = (GstAutoplugFactory *)(walk->data);
|
|
|
|
if (!strcmp (name, factory->name))
|
|
|
|
return factory;
|
|
|
|
walk = g_list_next (walk);
|
|
|
|
}
|
2000-12-31 16:12:48 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
return NULL;
|
2000-12-31 16:12:48 +00:00
|
|
|
}
|
2000-12-22 16:14:33 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
/**
|
|
|
|
* gst_autoplugfactory_get_list:
|
|
|
|
*
|
2001-03-21 21:43:56 +00:00
|
|
|
* Get the global list of autoplugfactories.
|
2001-03-07 21:52:56 +00:00
|
|
|
*
|
2001-03-21 21:43:56 +00:00
|
|
|
* Returns: GList of type #GstAutoplugFactory
|
2001-03-07 21:52:56 +00:00
|
|
|
*/
|
|
|
|
GList*
|
|
|
|
gst_autoplugfactory_get_list (void)
|
|
|
|
{
|
|
|
|
return _gst_autoplugfactories;
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-21 21:43:56 +00:00
|
|
|
/**
|
|
|
|
* gst_autoplugfactory_create:
|
|
|
|
* @factory: the factory used to create the instance
|
|
|
|
*
|
|
|
|
* Create a new #GstAutoplug instance from the
|
|
|
|
* given autoplugfactory.
|
|
|
|
*
|
|
|
|
* Returns: A new #GstAutoplug instance.
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplug*
|
|
|
|
gst_autoplugfactory_create (GstAutoplugFactory *factory)
|
2000-12-19 13:44:23 +00:00
|
|
|
{
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplug *new = NULL;
|
2001-01-21 23:20:46 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
g_return_val_if_fail (factory != NULL, NULL);
|
2000-12-22 16:14:33 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
if (factory->type == 0){
|
|
|
|
factory = gst_plugin_load_autoplugfactory (factory->name);
|
|
|
|
}
|
|
|
|
g_return_val_if_fail (factory != NULL, NULL);
|
|
|
|
g_return_val_if_fail (factory->type != 0, NULL);
|
2000-12-30 16:13:17 +00:00
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
new = GST_AUTOPLUG (g_object_new(factory->type,NULL));
|
2001-01-21 23:20:46 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
return new;
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-21 21:43:56 +00:00
|
|
|
/**
|
|
|
|
* gst_autoplugfactory_make:
|
|
|
|
* @name: the name of the factory used to create the instance
|
|
|
|
*
|
|
|
|
* Create a new #GstAutoplug instance from the
|
|
|
|
* autoplugfactory with the given name.
|
|
|
|
*
|
|
|
|
* Returns: A new #GstAutoplug instance.
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplug*
|
|
|
|
gst_autoplugfactory_make (const gchar *name)
|
2000-12-19 13:44:23 +00:00
|
|
|
{
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplugFactory *factory;
|
|
|
|
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2000-12-22 16:14:33 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
factory = gst_autoplugfactory_find (name);
|
2000-12-22 16:14:33 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
if (factory == NULL)
|
|
|
|
return NULL;
|
2000-12-22 16:14:33 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
return gst_autoplugfactory_create (factory);;
|
2000-12-22 16:14:33 +00:00
|
|
|
}
|
|
|
|
|
2001-03-21 21:43:56 +00:00
|
|
|
/**
|
|
|
|
* gst_autoplugfactory_save_thyself:
|
|
|
|
* @factory: The facory to save
|
|
|
|
* @parent: the parent XML node pointer
|
|
|
|
*
|
|
|
|
* Save the autoplugfactory into an XML representation
|
|
|
|
*
|
|
|
|
* Returns: The new XML parent.
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
xmlNodePtr
|
|
|
|
gst_autoplugfactory_save_thyself (GstAutoplugFactory *factory, xmlNodePtr parent)
|
2000-12-22 16:14:33 +00:00
|
|
|
{
|
2001-03-07 21:52:56 +00:00
|
|
|
g_return_val_if_fail(factory != NULL, NULL);
|
2000-12-22 16:14:33 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
xmlNewChild(parent,NULL,"name",factory->name);
|
|
|
|
xmlNewChild(parent,NULL,"longdesc", factory->longdesc);
|
2000-12-22 16:14:33 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
return parent;
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-21 21:43:56 +00:00
|
|
|
/**
|
|
|
|
* gst_autoplugfactory_load_thyself:
|
|
|
|
* @parent: the parent XML node pointer
|
|
|
|
*
|
|
|
|
* Load an autoplugfactory from the given XML parent node.
|
|
|
|
*
|
|
|
|
* Returns: A new factory based on the XML node.
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplugFactory*
|
|
|
|
gst_autoplugfactory_load_thyself (xmlNodePtr parent)
|
2000-12-19 13:44:23 +00:00
|
|
|
{
|
2001-03-07 21:52:56 +00:00
|
|
|
GstAutoplugFactory *factory = g_new0(GstAutoplugFactory, 1);
|
|
|
|
xmlNodePtr children = parent->xmlChildrenNode;
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
while (children) {
|
|
|
|
if (!strcmp(children->name, "name")) {
|
|
|
|
factory->name = xmlNodeGetContent(children);
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
2001-03-07 21:52:56 +00:00
|
|
|
if (!strcmp(children->name, "longdesc")) {
|
|
|
|
factory->longdesc = xmlNodeGetContent(children);
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
2001-03-07 21:52:56 +00:00
|
|
|
children = children->next;
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
_gst_autoplugfactories = g_list_prepend (_gst_autoplugfactories, factory);
|
2000-12-19 13:44:23 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
return factory;
|
2000-12-19 13:44:23 +00:00
|
|
|
}
|
|
|
|
|