2002-01-28 01:47:31 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999-2002 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000-2002 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstsearchfuncs.c: functions needed when doing searches while
|
|
|
|
* autoplugging
|
|
|
|
*
|
|
|
|
* 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 "gstsearchfuncs.h"
|
|
|
|
|
|
|
|
/* function that really misses in GLib
|
2002-02-05 17:08:08 +00:00
|
|
|
* though the GLib version should take a function as argument...
|
2002-01-28 01:47:31 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_list_free_list_and_elements (GList *list)
|
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *walk = list;
|
|
|
|
|
|
|
|
while (walk)
|
|
|
|
{
|
|
|
|
g_free (walk->data);
|
|
|
|
walk = g_list_next (walk);
|
|
|
|
}
|
|
|
|
g_list_free (list);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
2002-02-05 20:56:11 +00:00
|
|
|
/**
|
2002-10-01 12:14:13 +00:00
|
|
|
* gst_autoplug_caps_intersect:
|
|
|
|
* @src: a source #GstCaps
|
|
|
|
* @sink: the sink #GstCaps
|
2002-02-05 20:56:11 +00:00
|
|
|
*
|
2002-10-01 12:14:13 +00:00
|
|
|
* Checks if the given caps have a non-null intersection.
|
2002-02-05 20:56:11 +00:00
|
|
|
*
|
2003-05-18 15:03:34 +00:00
|
|
|
* Returns: TRUE, if both caps intersect.
|
2002-02-05 20:56:11 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2002-10-01 12:14:13 +00:00
|
|
|
gst_autoplug_caps_intersect (GstCaps *src, GstCaps *sink)
|
2002-02-05 20:56:11 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
2003-01-09 22:59:37 +00:00
|
|
|
/* if there are no caps, we can link */
|
2002-02-05 20:56:11 +00:00
|
|
|
if ((src == NULL) && (sink == NULL))
|
|
|
|
return TRUE;
|
|
|
|
|
2002-10-01 12:14:13 +00:00
|
|
|
/* get an intersection */
|
2002-02-05 20:56:11 +00:00
|
|
|
caps = gst_caps_intersect (src, sink);
|
|
|
|
|
2003-01-09 22:59:37 +00:00
|
|
|
/* if the caps can't link, there is no intersection */
|
2002-02-05 20:56:11 +00:00
|
|
|
if (caps == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2003-01-09 22:59:37 +00:00
|
|
|
/* hurrah, we can link, now remove the intersection */
|
2002-03-06 08:30:05 +00:00
|
|
|
gst_caps_unref (caps);
|
2002-02-05 20:56:11 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_autoplug_can_connect_src:
|
|
|
|
* @fac: factory to connect to
|
|
|
|
* @src: caps to check
|
|
|
|
*
|
|
|
|
* Checks if a factory's sink can connect to the given caps
|
|
|
|
*
|
2003-05-18 15:03:34 +00:00
|
|
|
* Returns: #GstPadTemplate that can connect to the given caps
|
2002-01-28 01:47:31 +00:00
|
|
|
*/
|
|
|
|
GstPadTemplate *
|
|
|
|
gst_autoplug_can_connect_src (GstElementFactory *fac, GstCaps *src)
|
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *templs;
|
|
|
|
|
|
|
|
templs = fac->padtemplates;
|
|
|
|
|
|
|
|
while (templs)
|
|
|
|
{
|
2002-10-01 13:02:22 +00:00
|
|
|
if ((GST_PAD_TEMPLATE_DIRECTION (templs->data) == GST_PAD_SINK) &&
|
|
|
|
gst_autoplug_caps_intersect (src,
|
|
|
|
GST_PAD_TEMPLATE_CAPS (templs->data)))
|
2002-02-05 17:08:08 +00:00
|
|
|
{
|
2002-04-11 20:35:18 +00:00
|
|
|
return GST_PAD_TEMPLATE (templs->data);
|
2002-02-05 17:08:08 +00:00
|
|
|
}
|
2002-01-28 01:47:31 +00:00
|
|
|
templs = g_list_next (templs);
|
2002-02-05 17:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* gst_autoplug_can_connect_sink:
|
|
|
|
* @fac: factory to connect to
|
2003-05-18 15:03:34 +00:00
|
|
|
* @sink: caps to check
|
2002-01-28 01:47:31 +00:00
|
|
|
*
|
|
|
|
* Checks if a factory's src can connect to the given caps
|
|
|
|
*
|
2003-05-18 15:03:34 +00:00
|
|
|
* Returns: #GstPadTemplate that can connect to the given caps
|
2002-01-28 01:47:31 +00:00
|
|
|
*/
|
|
|
|
GstPadTemplate *
|
|
|
|
gst_autoplug_can_connect_sink (GstElementFactory *fac, GstCaps *sink)
|
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *templs;
|
|
|
|
|
|
|
|
templs = fac->padtemplates;
|
|
|
|
|
|
|
|
while (templs)
|
|
|
|
{
|
2002-10-01 13:02:22 +00:00
|
|
|
GstCaps *caps = GST_PAD_TEMPLATE_CAPS (templs->data);
|
|
|
|
if ((GST_PAD_TEMPLATE_DIRECTION (templs->data) == GST_PAD_SRC) &&
|
2002-10-01 13:03:23 +00:00
|
|
|
gst_autoplug_caps_intersect (caps, sink))
|
2002-02-05 17:08:08 +00:00
|
|
|
{
|
2002-04-11 20:35:18 +00:00
|
|
|
return GST_PAD_TEMPLATE (templs->data);
|
2002-02-05 17:08:08 +00:00
|
|
|
}
|
2002-01-28 01:47:31 +00:00
|
|
|
templs = g_list_next (templs);
|
2002-02-05 17:08:08 +00:00
|
|
|
}
|
2002-10-01 13:02:22 +00:00
|
|
|
|
2002-02-05 17:08:08 +00:00
|
|
|
return NULL;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
GstPadTemplate *
|
|
|
|
gst_autoplug_can_match (GstElementFactory *src, GstElementFactory *dest)
|
|
|
|
{
|
|
|
|
GList *srctemps, *desttemps;
|
|
|
|
|
|
|
|
srctemps = src->padtemplates;
|
|
|
|
|
|
|
|
while (srctemps) {
|
|
|
|
GstPadTemplate *srctemp = (GstPadTemplate *)srctemps->data;
|
|
|
|
|
|
|
|
desttemps = dest->padtemplates;
|
|
|
|
|
|
|
|
while (desttemps) {
|
|
|
|
GstPadTemplate *desttemp = (GstPadTemplate *)desttemps->data;
|
|
|
|
|
|
|
|
if (srctemp->direction == GST_PAD_SRC &&
|
|
|
|
desttemp->direction == GST_PAD_SINK) {
|
2002-10-01 12:14:13 +00:00
|
|
|
if (gst_autoplug_caps_intersect (gst_pad_template_get_caps (srctemp),
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_pad_template_get_caps (desttemp))) {
|
2002-01-28 01:47:31 +00:00
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT,
|
2003-01-23 19:36:47 +00:00
|
|
|
"factory \"%s\" can connect with factory \"%s\"",
|
2002-02-05 17:08:08 +00:00
|
|
|
GST_OBJECT_NAME (src), GST_OBJECT_NAME (dest));
|
2002-01-28 01:47:31 +00:00
|
|
|
return desttemp;
|
2002-02-05 17:08:08 +00:00
|
|
|
}
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
desttemps = g_list_next (desttemps);
|
|
|
|
}
|
|
|
|
srctemps = g_list_next (srctemps);
|
|
|
|
}
|
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT,
|
2003-01-23 19:36:47 +00:00
|
|
|
"factory \"%s\" cannot connect with factory \"%s\"",
|
2002-02-05 17:08:08 +00:00
|
|
|
GST_OBJECT_NAME (src), GST_OBJECT_NAME (dest));
|
2002-01-28 01:47:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns TRUE if the factory has padtemplates with the specified direction */
|
|
|
|
gboolean
|
|
|
|
gst_autoplug_factory_has_direction (GstElementFactory *fac, GstPadDirection dir)
|
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *templs = fac->padtemplates;
|
|
|
|
|
|
|
|
while (templs)
|
|
|
|
{
|
2002-04-11 20:35:18 +00:00
|
|
|
if (GST_PAD_TEMPLATE_DIRECTION (templs->data) == dir)
|
2002-02-05 17:08:08 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
templs = g_list_next (templs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Decisions are based on the padtemplates.
|
|
|
|
* These functions return a new list so be sure to free it.
|
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
gst_autoplug_factories_sinks (GList *factories)
|
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *ret = NULL;
|
|
|
|
|
|
|
|
while (factories)
|
|
|
|
{
|
|
|
|
if (gst_autoplug_factory_has_sink (factories->data))
|
|
|
|
ret = g_list_prepend (ret, factories->data);
|
|
|
|
factories = g_list_next (factories);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
2002-02-05 17:08:08 +00:00
|
|
|
return ret;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
GList *
|
|
|
|
gst_autoplug_factories_srcs (GList *factories)
|
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *ret = NULL;
|
|
|
|
|
|
|
|
while (factories)
|
|
|
|
{
|
|
|
|
if (gst_autoplug_factory_has_src (factories->data))
|
|
|
|
ret = g_list_prepend (ret, factories->data);
|
|
|
|
factories = g_list_next (factories);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
2002-02-05 17:08:08 +00:00
|
|
|
return ret;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *
|
2002-01-28 01:47:31 +00:00
|
|
|
gst_autoplug_factories_filters (GList *factories)
|
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *ret = NULL;
|
|
|
|
|
|
|
|
while (factories)
|
|
|
|
{
|
|
|
|
/* if you want it faster do src/sink check at once, don't call two functions */
|
|
|
|
if (gst_autoplug_factory_has_src (factories->data) && gst_autoplug_factory_has_sink (factories->data))
|
|
|
|
ret = g_list_prepend (ret, factories->data);
|
|
|
|
factories = g_list_next (factories);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
2002-02-05 17:08:08 +00:00
|
|
|
return ret;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-31 08:32:49 +00:00
|
|
|
static gint
|
|
|
|
gst_autoplug_rank_compare (const GstElementFactory *a, const GstElementFactory *b)
|
|
|
|
{
|
|
|
|
if (a->rank > b->rank) return -1;
|
|
|
|
return (a->rank < b->rank) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
/* returns all factories which have sinks with non-NULL caps and srcs with
|
2002-05-31 08:32:49 +00:00
|
|
|
* any caps. also only returns factories with a non-zero rank, and sorts by
|
|
|
|
* rank descending.
|
2002-01-28 01:47:31 +00:00
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
gst_autoplug_factories_filters_with_sink_caps (GList *factories)
|
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *ret = NULL;
|
2002-05-31 08:32:49 +00:00
|
|
|
GstElementFactory *factory;
|
|
|
|
GList *templs;
|
2002-02-05 17:08:08 +00:00
|
|
|
|
|
|
|
while (factories)
|
|
|
|
{
|
2002-05-31 08:32:49 +00:00
|
|
|
factory = (GstElementFactory *) factories->data;
|
|
|
|
templs = factory->padtemplates;
|
|
|
|
if (factory->rank > 0){
|
|
|
|
gboolean have_src = FALSE;
|
|
|
|
gboolean have_sink = FALSE;
|
|
|
|
|
|
|
|
while (templs)
|
2002-02-05 17:08:08 +00:00
|
|
|
{
|
2002-05-31 08:32:49 +00:00
|
|
|
if (GST_PAD_TEMPLATE_DIRECTION (templs->data) == GST_PAD_SRC)
|
|
|
|
{
|
|
|
|
have_src = TRUE;
|
|
|
|
}
|
|
|
|
if ((GST_PAD_TEMPLATE_DIRECTION (templs->data) == GST_PAD_SINK) && (GST_PAD_TEMPLATE_CAPS (templs->data) != NULL))
|
|
|
|
{
|
|
|
|
have_sink = TRUE;
|
|
|
|
}
|
|
|
|
if (have_src && have_sink)
|
|
|
|
{
|
|
|
|
ret = g_list_prepend (ret, factory);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
templs = g_list_next (templs);
|
2002-02-05 17:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
factories = g_list_next (factories);
|
|
|
|
}
|
2002-05-31 08:32:49 +00:00
|
|
|
return g_list_sort(ret, (GCompareFunc)gst_autoplug_rank_compare);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* returns all factories which have a maximum of maxtemplates GstPadTemplates in direction dir
|
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
gst_autoplug_factories_at_most_templates(GList *factories, GstPadDirection dir, guint maxtemplates)
|
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *ret = NULL;
|
|
|
|
|
|
|
|
while (factories)
|
|
|
|
{
|
|
|
|
guint count = 0;
|
|
|
|
GList *templs = ((GstElementFactory *) factories->data)->padtemplates;
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2002-02-05 17:08:08 +00:00
|
|
|
while (templs)
|
|
|
|
{
|
2002-04-11 20:35:18 +00:00
|
|
|
if (GST_PAD_TEMPLATE_DIRECTION (templs->data) == dir)
|
2002-02-05 17:08:08 +00:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (count > maxtemplates)
|
|
|
|
break;
|
|
|
|
templs = g_list_next (templs);
|
|
|
|
}
|
|
|
|
if (count <= maxtemplates)
|
|
|
|
ret = g_list_prepend (ret, factories->data);
|
|
|
|
|
|
|
|
factories = g_list_next (factories);
|
|
|
|
}
|
|
|
|
return ret;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* SHORTEST PATH ALGORITHM
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* gst_autoplug_sp:
|
2003-05-18 15:03:34 +00:00
|
|
|
* @src_caps: a #GstCaps to plug from.
|
|
|
|
* @sink_caps: the #GstCaps to plug to.
|
2002-10-01 12:14:13 +00:00
|
|
|
* @factories: a #GList containing all allowed #GstElementFactory entries.
|
2002-01-28 01:47:31 +00:00
|
|
|
*
|
2002-10-01 12:14:13 +00:00
|
|
|
* Finds the shortest path of elements that together make up a possible
|
|
|
|
* connection between the source and sink caps.
|
2002-01-28 01:47:31 +00:00
|
|
|
*
|
2002-10-01 12:14:13 +00:00
|
|
|
* Returns: a #GList of #GstElementFactory items which have to be connected
|
|
|
|
* to get the shortest path.
|
2002-01-28 01:47:31 +00:00
|
|
|
*/
|
|
|
|
GList *
|
2003-05-18 16:28:15 +00:00
|
|
|
gst_autoplug_sp (GstCaps *srccaps, GstCaps *sinkcaps, GList *factories)
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *factory_nodes = NULL;
|
|
|
|
guint curcost = GST_AUTOPLUG_MAX_COST; /* below this cost, there is no path */
|
|
|
|
GstAutoplugNode *bestnode = NULL; /* best (unconnected) endpoint currently */
|
|
|
|
|
2002-02-11 08:18:09 +00:00
|
|
|
g_return_val_if_fail (srccaps != NULL, NULL);
|
|
|
|
g_return_val_if_fail (sinkcaps != NULL, NULL);
|
|
|
|
|
2002-10-01 12:14:13 +00:00
|
|
|
GST_INFO (GST_CAT_AUTOPLUG_ATTEMPT,
|
2002-10-01 13:02:22 +00:00
|
|
|
"attempting to autoplug via shortest path from %s to %s",
|
2002-10-01 12:14:13 +00:00
|
|
|
gst_caps_get_mime (srccaps), gst_caps_get_mime (sinkcaps));
|
2002-10-01 13:02:22 +00:00
|
|
|
gst_caps_debug (srccaps, "source caps");
|
|
|
|
gst_caps_debug (sinkcaps, "sink caps");
|
2002-02-05 17:08:08 +00:00
|
|
|
/* wrap all factories as GstAutoplugNode
|
|
|
|
* initialize the cost */
|
|
|
|
while (factories)
|
|
|
|
{
|
|
|
|
GstAutoplugNode *node = g_new0 (GstAutoplugNode, 1);
|
|
|
|
node->prev = NULL;
|
|
|
|
node->fac = (GstElementFactory *) factories->data;
|
2002-10-01 13:02:22 +00:00
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT,
|
|
|
|
"trying with %s", node->fac->details->longname);
|
2002-02-05 17:08:08 +00:00
|
|
|
node->templ = gst_autoplug_can_connect_src (node->fac, srccaps);
|
2002-10-01 12:14:13 +00:00
|
|
|
node->cost = (node->templ ? gst_autoplug_get_cost (node->fac)
|
|
|
|
: GST_AUTOPLUG_MAX_COST);
|
2002-02-05 17:08:08 +00:00
|
|
|
node->endpoint = gst_autoplug_can_connect_sink (node->fac, sinkcaps);
|
2002-10-01 13:02:22 +00:00
|
|
|
if (node->templ && node->endpoint)
|
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT, "%s makes connection possible",
|
|
|
|
node->fac->details->longname);
|
|
|
|
else
|
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT,
|
|
|
|
"direct connection with %s not possible",
|
|
|
|
node->fac->details->longname);
|
2002-10-01 12:14:13 +00:00
|
|
|
if ((node->endpoint != NULL) &&
|
|
|
|
((bestnode == NULL) || (node->cost < bestnode->cost)))
|
2002-02-05 17:08:08 +00:00
|
|
|
{
|
|
|
|
bestnode = node;
|
|
|
|
}
|
|
|
|
factory_nodes = g_list_prepend (factory_nodes, node);
|
|
|
|
/* make curcost the minimum cost of any plugin */
|
|
|
|
curcost = node->cost < curcost ? node->cost : curcost;
|
|
|
|
factories = g_list_next (factories);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we even have possible endpoints */
|
|
|
|
if (bestnode == NULL)
|
|
|
|
{
|
2002-10-01 12:14:13 +00:00
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT,
|
|
|
|
"no factory found that could connect to sink caps");
|
2002-02-05 17:08:08 +00:00
|
|
|
g_list_free_list_and_elements (factory_nodes);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iterate until we found the best path */
|
|
|
|
while (curcost < GST_AUTOPLUG_MAX_COST)
|
|
|
|
{
|
|
|
|
GList *nodes = factory_nodes;
|
|
|
|
guint nextcost = GST_AUTOPLUG_MAX_COST; /* next cost to check */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT, "iterating at current cost %d, bestnode %s at %d", curcost, GST_OBJECT_NAME (bestnode->fac), bestnode->cost);
|
2002-02-05 17:08:08 +00:00
|
|
|
/* check if we already have a valid best connection to the sink */
|
|
|
|
if (bestnode->cost <= curcost)
|
|
|
|
{
|
|
|
|
GList *ret;
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT, "found a way to connect via %s", GST_OBJECT_NAME ((GstObject *) bestnode->fac));
|
2002-02-05 17:08:08 +00:00
|
|
|
/* enter all factories into the return list */
|
|
|
|
ret = g_list_prepend (NULL, bestnode->fac);
|
|
|
|
bestnode = bestnode->prev;
|
|
|
|
while (bestnode != NULL)
|
|
|
|
{
|
|
|
|
ret = g_list_prepend (ret, bestnode->fac);
|
|
|
|
bestnode = bestnode->prev;
|
|
|
|
}
|
|
|
|
g_list_free_list_and_elements (factory_nodes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iterate over all factories we have
|
|
|
|
* if they have the current cost, calculate if this
|
|
|
|
* factory supplies shorter paths to other elements
|
|
|
|
*/
|
|
|
|
while (nodes)
|
|
|
|
{
|
|
|
|
if (((GstAutoplugNode *) nodes->data)->cost == curcost)
|
|
|
|
{
|
|
|
|
/* now check all elements if we got a shorter path */
|
|
|
|
GList *sinknodes = factory_nodes;
|
|
|
|
GstAutoplugNode *srcnode = (GstAutoplugNode *) nodes->data;
|
|
|
|
while (sinknodes)
|
|
|
|
{
|
|
|
|
GstAutoplugNode *sinknode = (GstAutoplugNode *) sinknodes->data;
|
|
|
|
GstPadTemplate *templ;
|
|
|
|
if ((sinknode->cost > srcnode->cost + gst_autoplug_get_cost (sinknode->fac)) && (templ = gst_autoplug_can_match(srcnode->fac, sinknode->fac)))
|
|
|
|
{
|
|
|
|
/* we got a shorter path
|
|
|
|
* now enter that path to that node */
|
|
|
|
sinknode->prev = srcnode;
|
|
|
|
sinknode->templ = templ;
|
|
|
|
sinknode->cost = srcnode->cost + gst_autoplug_get_cost (sinknode->fac);
|
|
|
|
/* make sure to set which cost to view next */
|
|
|
|
nextcost = (nextcost > sinknode->cost) ? sinknode->cost : nextcost;
|
|
|
|
/* did we get a new best node? */
|
|
|
|
if (sinknode->endpoint && (sinknode->cost < bestnode->cost))
|
|
|
|
{
|
|
|
|
bestnode = sinknode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sinknodes = g_list_next (sinknodes);
|
|
|
|
}
|
|
|
|
/* FIXME: for speed remove the item we just iterated with from the factory_nodes
|
|
|
|
* but don't free it yet and don't forget to free it.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
nodes = g_list_next (nodes);
|
|
|
|
}
|
|
|
|
curcost = nextcost;
|
|
|
|
}
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_AUTOPLUG_ATTEMPT, "found no path from source caps to sink caps");
|
2002-02-05 17:08:08 +00:00
|
|
|
g_list_free_list_and_elements (factory_nodes);
|
|
|
|
return NULL;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|