2001-03-07 21:52:56 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gststaticautoplug.c: A static Autoplugger of pipelines
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gststaticautoplugrender.h"
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
#define GST_AUTOPLUG_MAX_COST 999999
|
|
|
|
|
|
|
|
typedef guint (*GstAutoplugCostFunction) (gpointer src, gpointer dest, gpointer data);
|
|
|
|
typedef GList* (*GstAutoplugListFunction) (gpointer data);
|
|
|
|
|
|
|
|
|
|
|
|
static void gst_static_autoplug_render_class_init (GstStaticAutoplugRenderClass *klass);
|
|
|
|
static void gst_static_autoplug_render_init (GstStaticAutoplugRender *autoplug);
|
|
|
|
|
|
|
|
static GList* gst_autoplug_func (gpointer src, gpointer sink,
|
|
|
|
GstAutoplugListFunction list_function,
|
|
|
|
GstAutoplugCostFunction cost_function,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static GstElement* gst_static_autoplug_to_render (GstAutoplug *autoplug,
|
2001-03-12 21:02:12 +00:00
|
|
|
GstCaps *srccaps, GstElement *target, va_list args);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
static GstAutoplugClass *parent_class = NULL;
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
GType gst_static_autoplug_render_get_type(void)
|
2001-03-07 21:52:56 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType static_autoplug_type = 0;
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
if (!static_autoplug_type) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static const GTypeInfo static_autoplug_info = {
|
2001-03-07 21:52:56 +00:00
|
|
|
sizeof(GstElementClass),
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_static_autoplug_render_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstElement),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_static_autoplug_render_init,
|
2001-03-07 21:52:56 +00:00
|
|
|
};
|
2001-06-25 01:20:11 +00:00
|
|
|
static_autoplug_type = g_type_register_static (GST_TYPE_AUTOPLUG, "GstStaticAutoplugRender", &static_autoplug_info, 0);
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
return static_autoplug_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_static_autoplug_render_class_init(GstStaticAutoplugRenderClass *klass)
|
|
|
|
{
|
|
|
|
GstAutoplugClass *gstautoplug_class;
|
|
|
|
|
|
|
|
gstautoplug_class = (GstAutoplugClass*) klass;
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
parent_class = g_type_class_ref(GST_TYPE_AUTOPLUG);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
gstautoplug_class->autoplug_to_renderers = gst_static_autoplug_to_render;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gst_static_autoplug_render_init(GstStaticAutoplugRender *autoplug) {
|
|
|
|
}
|
|
|
|
|
2001-04-22 12:30:14 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module, GstPlugin *plugin)
|
2001-03-07 21:52:56 +00:00
|
|
|
{
|
|
|
|
GstAutoplugFactory *factory;
|
|
|
|
|
|
|
|
gst_plugin_set_longname (plugin, "A static autoplugger");
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
factory = gst_autoplug_factory_new ("staticrender",
|
2001-03-07 21:52:56 +00:00
|
|
|
"A static autoplugger, it constructs the complete element before running it",
|
|
|
|
gst_static_autoplug_render_get_type ());
|
|
|
|
|
|
|
|
if (factory != NULL) {
|
2001-08-21 20:16:48 +00:00
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
else {
|
|
|
|
g_warning ("could not register autoplugger: staticrender");
|
|
|
|
}
|
2001-04-22 12:30:14 +00:00
|
|
|
return TRUE;
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
|
2001-04-22 12:30:14 +00:00
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"gststaticautoplugrender",
|
|
|
|
plugin_init
|
|
|
|
};
|
|
|
|
|
2001-07-18 19:04:29 +00:00
|
|
|
static GstPadTemplate*
|
|
|
|
gst_autoplug_match_caps (GstElementFactory *factory, GstPadDirection direction, GstCaps *caps)
|
|
|
|
{
|
|
|
|
GList *templates;
|
|
|
|
|
|
|
|
templates = factory->padtemplates;
|
|
|
|
|
|
|
|
while (templates) {
|
|
|
|
GstPadTemplate *template = (GstPadTemplate *)templates->data;
|
|
|
|
|
|
|
|
if (template->direction == direction && direction == GST_PAD_SRC) {
|
2002-10-02 07:51:54 +00:00
|
|
|
if (gst_caps_is_always_compatible (GST_PAD_TEMPLATE_CAPS (template), caps))
|
2001-07-18 19:04:29 +00:00
|
|
|
return template;
|
|
|
|
}
|
|
|
|
else if (template->direction == direction && direction == GST_PAD_SINK) {
|
2002-10-02 07:51:54 +00:00
|
|
|
if (gst_caps_is_always_compatible (caps, GST_PAD_TEMPLATE_CAPS (template)))
|
2001-07-18 19:04:29 +00:00
|
|
|
return template;
|
|
|
|
}
|
|
|
|
templates = g_list_next (templates);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static gboolean
|
|
|
|
gst_autoplug_can_match (GstElementFactory *src, GstElementFactory *dest)
|
|
|
|
{
|
|
|
|
GList *srctemps, *desttemps;
|
|
|
|
|
|
|
|
srctemps = src->padtemplates;
|
|
|
|
|
|
|
|
while (srctemps) {
|
|
|
|
GstPadTemplate *srctemp = (GstPadTemplate *)srctemps->data;
|
2001-07-18 19:04:29 +00:00
|
|
|
srctemps = g_list_next (srctemps);
|
|
|
|
|
|
|
|
if (srctemp->direction != GST_PAD_SRC)
|
|
|
|
continue;
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
desttemps = dest->padtemplates;
|
|
|
|
|
|
|
|
while (desttemps) {
|
|
|
|
GstPadTemplate *desttemp = (GstPadTemplate *)desttemps->data;
|
2001-07-18 19:04:29 +00:00
|
|
|
desttemps = g_list_next (desttemps);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-07-18 19:04:29 +00:00
|
|
|
if (desttemp->direction == GST_PAD_SINK && desttemp->presence != GST_PAD_REQUEST) {
|
2002-10-02 07:51:54 +00:00
|
|
|
if (gst_caps_is_always_compatible (GST_PAD_TEMPLATE_CAPS (srctemp), GST_PAD_TEMPLATE_CAPS (desttemp))) {
|
2001-04-15 22:52:45 +00:00
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT,
|
2002-05-08 20:40:48 +00:00
|
|
|
"factory \"%s\" can connect with factory \"%s\"",
|
2001-08-21 20:16:48 +00:00
|
|
|
GST_OBJECT_NAME (src), GST_OBJECT_NAME (dest));
|
2001-03-07 21:52:56 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2001-04-15 22:52:45 +00:00
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT,
|
2002-05-08 20:40:48 +00:00
|
|
|
"factory \"%s\" cannot connect with factory \"%s\"",
|
2001-08-21 20:16:48 +00:00
|
|
|
GST_OBJECT_NAME (src), GST_OBJECT_NAME (dest));
|
2001-03-07 21:52:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_autoplug_pads_autoplug_func (GstElement *src, GstPad *pad, GstElement *sink)
|
|
|
|
{
|
2002-09-12 20:52:03 +00:00
|
|
|
const GList *sinkpads;
|
2001-03-07 21:52:56 +00:00
|
|
|
gboolean connected = FALSE;
|
2001-12-25 02:15:46 +00:00
|
|
|
GstElementState state = GST_STATE (gst_element_get_parent (src));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"gstpipeline: autoplug pad connect function for %s %s:%s to \"%s\"",
|
2001-03-18 16:17:39 +00:00
|
|
|
GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME(pad), GST_ELEMENT_NAME(sink));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-12-25 02:15:46 +00:00
|
|
|
if (state == GST_STATE_PLAYING)
|
|
|
|
gst_element_set_state (GST_ELEMENT (gst_element_get_parent (src)), GST_STATE_PAUSED);
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
sinkpads = gst_element_get_pad_list(sink);
|
|
|
|
while (sinkpads) {
|
|
|
|
GstPad *sinkpad = (GstPad *)sinkpads->data;
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* if we have a match, connect the pads */
|
2001-03-12 21:02:12 +00:00
|
|
|
if (gst_pad_get_direction(sinkpad) == GST_PAD_SINK &&
|
2002-01-13 22:22:42 +00:00
|
|
|
!GST_PAD_IS_CONNECTED (pad) && !GST_PAD_IS_CONNECTED(sinkpad))
|
2001-03-07 21:52:56 +00:00
|
|
|
{
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
if ((connected = gst_pad_connect (pad, sinkpad))) {
|
2001-03-12 21:02:12 +00:00
|
|
|
break;
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"pads incompatible %s, %s", GST_PAD_NAME (pad), GST_PAD_NAME (sinkpad));
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sinkpads = g_list_next(sinkpads);
|
|
|
|
}
|
|
|
|
|
2001-12-25 02:15:46 +00:00
|
|
|
if (state == GST_STATE_PLAYING)
|
|
|
|
gst_element_set_state (GST_ELEMENT (gst_element_get_parent (src)), GST_STATE_PLAYING);
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
if (!connected) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"gstpipeline: no path to sinks for type");
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
return connected;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplug_pads_autoplug (GstElement *src, GstElement *sink)
|
|
|
|
{
|
2002-09-12 20:52:03 +00:00
|
|
|
const GList *srcpads;
|
2001-03-07 21:52:56 +00:00
|
|
|
gboolean connected = FALSE;
|
|
|
|
|
|
|
|
srcpads = gst_element_get_pad_list(src);
|
|
|
|
|
|
|
|
while (srcpads && !connected) {
|
|
|
|
GstPad *srcpad = (GstPad *)srcpads->data;
|
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
if (gst_pad_get_direction(srcpad) == GST_PAD_SRC) {
|
2001-03-07 21:52:56 +00:00
|
|
|
connected = gst_autoplug_pads_autoplug_func (src, srcpad, sink);
|
2001-03-12 21:02:12 +00:00
|
|
|
if (connected)
|
|
|
|
break;
|
|
|
|
}
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
srcpads = g_list_next(srcpads);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!connected) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"gstpipeline: delaying pad connections for \"%s\" to \"%s\"",
|
2001-03-07 21:52:56 +00:00
|
|
|
GST_ELEMENT_NAME(src), GST_ELEMENT_NAME(sink));
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_connect (G_OBJECT(src),"new_pad",
|
|
|
|
G_CALLBACK (gst_autoplug_pads_autoplug_func), sink);
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList*
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_autoplug_element_factory_get_list (gpointer data)
|
2001-03-07 21:52:56 +00:00
|
|
|
{
|
2002-05-08 20:40:48 +00:00
|
|
|
return (GList *) gst_registry_pool_feature_list (GST_TYPE_ELEMENT_FACTORY);
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
2001-03-12 21:02:12 +00:00
|
|
|
GstCaps *src;
|
|
|
|
GstCaps *sink;
|
2001-03-07 21:52:56 +00:00
|
|
|
} caps_struct;
|
|
|
|
|
|
|
|
#define IS_CAPS(cap) (((cap) == caps->src) || (cap) == caps->sink)
|
|
|
|
static guint
|
|
|
|
gst_autoplug_caps_find_cost (gpointer src, gpointer dest, gpointer data)
|
|
|
|
{
|
|
|
|
caps_struct *caps = (caps_struct *)data;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
if (IS_CAPS (src) && IS_CAPS (dest)) {
|
2002-10-02 07:51:54 +00:00
|
|
|
res = gst_caps_is_always_compatible ((GstCaps *)src, (GstCaps *)dest);
|
2001-12-17 22:26:56 +00:00
|
|
|
/*GST_INFO (GST_CAT_AUTOPLUG_ATTEMPT,"caps %d to caps %d %d", ((GstCaps *)src)->id, ((GstCaps *)dest)->id, res); */
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
else if (IS_CAPS (src)) {
|
2001-07-18 19:04:29 +00:00
|
|
|
GstPadTemplate *templ;
|
|
|
|
|
|
|
|
templ = gst_autoplug_match_caps ((GstElementFactory *)dest, GST_PAD_SINK, (GstCaps *)src);
|
|
|
|
|
|
|
|
if (templ && templ->presence != GST_PAD_REQUEST)
|
|
|
|
res = TRUE;
|
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/*GST_INFO (GST_CAT_AUTOPLUG_ATTEMPT,"factory %s to src caps %d %d", ((GstElementFactory *)dest)->name, ((GstCaps *)src)->id, res);*/
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
else if (IS_CAPS (dest)) {
|
2001-07-18 19:04:29 +00:00
|
|
|
GstPadTemplate *templ;
|
|
|
|
|
|
|
|
templ = gst_autoplug_match_caps ((GstElementFactory *)src, GST_PAD_SRC, (GstCaps *)dest);
|
|
|
|
|
|
|
|
if (templ && templ->presence != GST_PAD_REQUEST)
|
|
|
|
res = TRUE;
|
|
|
|
else
|
|
|
|
res = FALSE;
|
2001-12-17 22:26:56 +00:00
|
|
|
/*GST_INFO (GST_CAT_AUTOPLUG_ATTEMPT,"factory %s to sink caps %d %d", ((GstElementFactory *)src)->name, ((GstCaps *)dest)->id, res);*/
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
res = gst_autoplug_can_match ((GstElementFactory *)src, (GstElementFactory *)dest);
|
2001-07-18 19:04:29 +00:00
|
|
|
GST_INFO (GST_CAT_AUTOPLUG_ATTEMPT,"factory %s to factory %s %d",
|
2001-08-21 20:16:48 +00:00
|
|
|
GST_OBJECT_NAME (src), GST_OBJECT_NAME (dest), res);
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return GST_AUTOPLUG_MAX_COST;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement*
|
2001-03-12 21:02:12 +00:00
|
|
|
gst_static_autoplug_to_render (GstAutoplug *autoplug, GstCaps *srccaps, GstElement *target, va_list args)
|
2001-03-07 21:52:56 +00:00
|
|
|
{
|
|
|
|
caps_struct caps;
|
|
|
|
GstElement *targetelement;
|
|
|
|
GstElement *result = NULL, *srcelement = NULL;
|
|
|
|
GList **factories;
|
|
|
|
GList *chains = NULL;
|
|
|
|
GList *endelements = NULL;
|
|
|
|
guint numsinks = 0, i;
|
|
|
|
gboolean have_common = FALSE;
|
|
|
|
|
|
|
|
targetelement = target;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We first create a list of elements that are needed
|
|
|
|
* to convert the srcpad caps to the different sinkpad caps.
|
|
|
|
* and add the list of elementfactories to a list (chains).
|
|
|
|
*/
|
|
|
|
caps.src = srccaps;
|
|
|
|
|
|
|
|
while (targetelement) {
|
|
|
|
GList *elements;
|
2001-04-12 18:11:19 +00:00
|
|
|
GstRealPad *pad;
|
2001-03-12 21:02:12 +00:00
|
|
|
GstPadTemplate *templ;
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-04-12 18:11:19 +00:00
|
|
|
pad = GST_PAD_REALIZE (gst_element_get_pad_list (targetelement)->data);
|
2002-04-11 20:35:18 +00:00
|
|
|
templ = GST_PAD_PAD_TEMPLATE (pad);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-04-21 17:45:56 +00:00
|
|
|
if (templ)
|
2002-04-11 20:35:18 +00:00
|
|
|
caps.sink = GST_PAD_TEMPLATE_CAPS (templ);
|
2001-04-21 17:45:56 +00:00
|
|
|
else
|
|
|
|
goto next;
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_AUTOPLUG_ATTEMPT,"autoplugging two caps structures");
|
|
|
|
|
|
|
|
elements = gst_autoplug_func (caps.src, caps.sink,
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_autoplug_element_factory_get_list,
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_autoplug_caps_find_cost,
|
|
|
|
&caps);
|
|
|
|
|
|
|
|
if (elements) {
|
|
|
|
chains = g_list_append (chains, elements);
|
|
|
|
endelements = g_list_append (endelements, targetelement);
|
|
|
|
numsinks++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
}
|
2001-04-21 17:45:56 +00:00
|
|
|
next:
|
2001-03-07 21:52:56 +00:00
|
|
|
targetelement = va_arg (args, GstElement *);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no list could be found the pipeline cannot be autoplugged and
|
|
|
|
* we return a NULL element
|
|
|
|
*/
|
|
|
|
if (numsinks == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We now have a list of lists. We will turn this into an array
|
|
|
|
* of lists, this will make it much more easy to manipulate it
|
|
|
|
* in the next steps.
|
|
|
|
*/
|
|
|
|
factories = g_new0 (GList *, numsinks);
|
|
|
|
|
|
|
|
for (i = 0; chains; i++) {
|
|
|
|
GList *elements = (GList *) chains->data;
|
|
|
|
|
|
|
|
factories[i] = elements;
|
|
|
|
|
|
|
|
chains = g_list_next (chains);
|
|
|
|
}
|
2001-12-17 22:26:56 +00:00
|
|
|
/*FIXME, free the list */
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
result = gst_bin_new ("autoplug_bin");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We now hav a list of lists that is probably like:
|
|
|
|
*
|
|
|
|
* !
|
|
|
|
* A -> B -> C
|
|
|
|
* !
|
|
|
|
* A -> D -> E
|
|
|
|
*
|
|
|
|
* we now try to find the common elements (A) and add them to
|
|
|
|
* the bin. We remove them from both lists too.
|
|
|
|
*/
|
|
|
|
while (factories[0]) {
|
|
|
|
GstElementFactory *factory;
|
|
|
|
GstElement *element;
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* fase 3: add common elements */
|
2001-03-07 21:52:56 +00:00
|
|
|
factory = (GstElementFactory *) (factories[0]->data);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* check to other paths for matching elements (factories) */
|
2001-03-07 21:52:56 +00:00
|
|
|
for (i=1; i<numsinks; i++) {
|
|
|
|
if (factory != (GstElementFactory *) (factories[i]->data)) {
|
|
|
|
goto differ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"common factory \"%s\"", GST_OBJECT_NAME (factory));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
element = gst_element_factory_create (factory, g_strdup (GST_OBJECT_NAME (factory)));
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_bin_add (GST_BIN(result), element);
|
|
|
|
|
|
|
|
if (srcelement != NULL) {
|
|
|
|
gst_autoplug_pads_autoplug (srcelement, element);
|
|
|
|
}
|
2001-12-17 22:26:56 +00:00
|
|
|
/* this is the first element, find a good ghostpad */
|
2001-03-07 21:52:56 +00:00
|
|
|
else {
|
2002-09-12 20:52:03 +00:00
|
|
|
const GList *pads;
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
pads = gst_element_get_pad_list (element);
|
|
|
|
|
|
|
|
while (pads) {
|
|
|
|
GstPad *pad = GST_PAD (pads->data);
|
2002-04-11 20:35:18 +00:00
|
|
|
GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2002-10-02 07:51:54 +00:00
|
|
|
if (gst_caps_is_always_compatible (srccaps, GST_PAD_TEMPLATE_CAPS (templ))) {
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_element_add_ghost_pad (result, pad, "sink");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_autoplug_signal_new_object (GST_AUTOPLUG (autoplug), GST_OBJECT (element));
|
|
|
|
|
|
|
|
srcelement = element;
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* advance the pointer in all lists */
|
2001-03-07 21:52:56 +00:00
|
|
|
for (i=0; i<numsinks; i++) {
|
|
|
|
factories[i] = g_list_next (factories[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
have_common = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
differ:
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* loop over all the sink elements */
|
2001-03-07 21:52:56 +00:00
|
|
|
for (i = 0; i < numsinks; i++) {
|
|
|
|
GstElement *thesrcelement = srcelement;
|
|
|
|
GstElement *thebin = GST_ELEMENT(result);
|
|
|
|
GstElement *sinkelement;
|
|
|
|
gboolean use_thread;
|
|
|
|
|
|
|
|
sinkelement = GST_ELEMENT (endelements->data);
|
|
|
|
endelements = g_list_next (endelements);
|
|
|
|
|
|
|
|
use_thread = have_common;
|
|
|
|
|
|
|
|
while (factories[i] || sinkelement) {
|
2001-12-17 22:26:56 +00:00
|
|
|
/* fase 4: add other elements... */
|
2001-03-07 21:52:56 +00:00
|
|
|
GstElementFactory *factory;
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
if (factories[i]) {
|
|
|
|
factory = (GstElementFactory *)(factories[i]->data);
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"factory \"%s\"", GST_OBJECT_NAME (factory));
|
2002-04-11 20:35:18 +00:00
|
|
|
element = gst_element_factory_create(factory, g_strdup (GST_OBJECT_NAME (factory)));
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
element = sinkelement;
|
|
|
|
sinkelement = NULL;
|
|
|
|
}
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* this element suggests the use of a thread, so we set one up... */
|
2001-03-07 21:52:56 +00:00
|
|
|
if (GST_ELEMENT_IS_THREAD_SUGGESTED(element) || use_thread) {
|
|
|
|
GstElement *queue;
|
2001-03-12 21:02:12 +00:00
|
|
|
GstPad *srcpad;
|
2001-12-04 22:12:50 +00:00
|
|
|
GstElement *current_bin = thebin;
|
2001-03-07 21:52:56 +00:00
|
|
|
|
|
|
|
use_thread = FALSE;
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"sugest new thread for \"%s\" %08x", GST_ELEMENT_NAME (element), GST_FLAGS(element));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* create a new queue and add to the previous bin */
|
2002-04-11 20:35:18 +00:00
|
|
|
queue = gst_element_factory_make("queue", g_strconcat("queue_", GST_ELEMENT_NAME(element), NULL));
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"adding element \"%s\"", GST_ELEMENT_NAME (element));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* this will be the new bin for all following elements */
|
2002-04-11 20:35:18 +00:00
|
|
|
thebin = gst_element_factory_make("thread", g_strconcat("thread_", GST_ELEMENT_NAME(element), NULL));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add(GST_BIN(thebin), queue);
|
|
|
|
gst_autoplug_signal_new_object (GST_AUTOPLUG (autoplug), GST_OBJECT (queue));
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
srcpad = gst_element_get_pad(queue, "src");
|
|
|
|
|
|
|
|
gst_autoplug_pads_autoplug(thesrcelement, queue);
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"adding element %s", GST_ELEMENT_NAME (element));
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_bin_add(GST_BIN(thebin), element);
|
|
|
|
gst_autoplug_signal_new_object (GST_AUTOPLUG (autoplug), GST_OBJECT (element));
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"adding element %s", GST_ELEMENT_NAME (thebin));
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_bin_add(GST_BIN(current_bin), thebin);
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_autoplug_signal_new_object (GST_AUTOPLUG (autoplug), GST_OBJECT (thebin));
|
|
|
|
thesrcelement = queue;
|
|
|
|
}
|
2001-12-17 22:26:56 +00:00
|
|
|
/* no thread needed, easy case */
|
2001-03-07 21:52:56 +00:00
|
|
|
else {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"adding element %s", GST_ELEMENT_NAME (element));
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_bin_add(GST_BIN(thebin), element);
|
|
|
|
gst_autoplug_signal_new_object (GST_AUTOPLUG (autoplug), GST_OBJECT (element));
|
|
|
|
}
|
|
|
|
gst_autoplug_pads_autoplug(thesrcelement, element);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* this element is now the new source element */
|
2001-03-07 21:52:56 +00:00
|
|
|
thesrcelement = element;
|
|
|
|
|
|
|
|
factories[i] = g_list_next(factories[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* shortest path algorithm
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct _gst_autoplug_node
|
|
|
|
{
|
|
|
|
gpointer iNode;
|
|
|
|
gpointer iPrev;
|
|
|
|
gint iDist;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _gst_autoplug_node gst_autoplug_node;
|
|
|
|
|
|
|
|
static gint
|
|
|
|
find_factory (gst_autoplug_node *rgnNodes, gpointer factory)
|
|
|
|
{
|
|
|
|
gint i=0;
|
|
|
|
|
|
|
|
while (rgnNodes[i].iNode) {
|
|
|
|
if (rgnNodes[i].iNode == factory) return i;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList*
|
|
|
|
construct_path (gst_autoplug_node *rgnNodes, gpointer factory)
|
|
|
|
{
|
|
|
|
GstElementFactory *current;
|
|
|
|
GList *factories = NULL;
|
|
|
|
|
|
|
|
current = rgnNodes[find_factory(rgnNodes, factory)].iPrev;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_AUTOPLUG_ATTEMPT,"factories found in autoplugging (reversed order)");
|
|
|
|
|
|
|
|
while (current != NULL)
|
|
|
|
{
|
|
|
|
gpointer next = NULL;
|
|
|
|
|
|
|
|
next = rgnNodes[find_factory(rgnNodes, current)].iPrev;
|
|
|
|
if (next) {
|
|
|
|
factories = g_list_prepend (factories, current);
|
2001-08-21 20:16:48 +00:00
|
|
|
GST_INFO (GST_CAT_AUTOPLUG_ATTEMPT,"factory: \"%s\"", GST_OBJECT_NAME (current));
|
2001-03-07 21:52:56 +00:00
|
|
|
}
|
|
|
|
current = next;
|
|
|
|
}
|
|
|
|
return factories;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList*
|
|
|
|
gst_autoplug_enqueue (GList *queue, gpointer iNode, gint iDist, gpointer iPrev)
|
|
|
|
{
|
|
|
|
gst_autoplug_node *node = g_malloc (sizeof (gst_autoplug_node));
|
|
|
|
|
|
|
|
node->iNode = iNode;
|
|
|
|
node->iDist = iDist;
|
|
|
|
node->iPrev = iPrev;
|
|
|
|
|
|
|
|
queue = g_list_append (queue, node);
|
|
|
|
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList*
|
|
|
|
gst_autoplug_dequeue (GList *queue, gpointer *iNode, gint *iDist, gpointer *iPrev)
|
|
|
|
{
|
|
|
|
GList *head;
|
|
|
|
gst_autoplug_node *node;
|
|
|
|
|
|
|
|
head = g_list_first (queue);
|
|
|
|
|
|
|
|
if (head) {
|
|
|
|
node = (gst_autoplug_node *)head->data;
|
|
|
|
*iNode = node->iNode;
|
|
|
|
*iPrev = node->iPrev;
|
|
|
|
*iDist = node->iDist;
|
|
|
|
head = g_list_remove (queue, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList*
|
|
|
|
gst_autoplug_func (gpointer src, gpointer sink,
|
|
|
|
GstAutoplugListFunction list_function,
|
|
|
|
GstAutoplugCostFunction cost_function,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gst_autoplug_node *rgnNodes;
|
|
|
|
GList *queue = NULL;
|
|
|
|
gpointer iNode, iPrev;
|
|
|
|
gint iDist, i, iCost;
|
|
|
|
|
|
|
|
GList *elements = g_list_copy (list_function(data));
|
|
|
|
GList *factories;
|
|
|
|
guint num_factories;
|
|
|
|
|
|
|
|
elements = g_list_append (elements, sink);
|
|
|
|
elements = g_list_append (elements, src);
|
|
|
|
|
|
|
|
factories = elements;
|
|
|
|
|
|
|
|
num_factories = g_list_length (factories);
|
|
|
|
|
|
|
|
rgnNodes = g_new0 (gst_autoplug_node, num_factories+1);
|
|
|
|
|
|
|
|
for (i=0; i< num_factories; i++) {
|
|
|
|
gpointer fact = factories->data;
|
|
|
|
|
|
|
|
rgnNodes[i].iNode = fact;
|
|
|
|
rgnNodes[i].iPrev = NULL;
|
|
|
|
|
|
|
|
if (fact == src) {
|
|
|
|
rgnNodes[i].iDist = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rgnNodes[i].iDist = GST_AUTOPLUG_MAX_COST;
|
|
|
|
}
|
|
|
|
|
|
|
|
factories = g_list_next (factories);
|
|
|
|
}
|
|
|
|
rgnNodes[num_factories].iNode = NULL;
|
|
|
|
|
|
|
|
queue = gst_autoplug_enqueue (queue, src, 0, NULL);
|
|
|
|
|
|
|
|
while (g_list_length (queue) > 0) {
|
|
|
|
GList *factories2 = elements;
|
|
|
|
|
|
|
|
queue = gst_autoplug_dequeue (queue, &iNode, &iDist, &iPrev);
|
|
|
|
|
|
|
|
for (i=0; i< num_factories; i++) {
|
|
|
|
gpointer current = factories2->data;
|
|
|
|
|
|
|
|
iCost = cost_function (iNode, current, data);
|
|
|
|
if (iCost != GST_AUTOPLUG_MAX_COST) {
|
|
|
|
if ((GST_AUTOPLUG_MAX_COST == rgnNodes[i].iDist) ||
|
|
|
|
(rgnNodes[i].iDist > (iCost + iDist))) {
|
|
|
|
rgnNodes[i].iDist = iDist + iCost;
|
|
|
|
rgnNodes[i].iPrev = iNode;
|
|
|
|
|
|
|
|
queue = gst_autoplug_enqueue (queue, current, iDist + iCost, iNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
factories2 = g_list_next (factories2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return construct_path (rgnNodes, sink);
|
|
|
|
}
|
|
|
|
|