From: Thomas V. S. <tho...@us...> - 2002-02-05 17:42:43
|
Update of /cvsroot/gstreamer/gstreamer/gst/elements In directory usw-pr-cvs1:/tmp/cvs-serv14155 Modified Files: gsttee.c Log Message: this fix makes sure that we actually request a pad from the template with an unused name this isn't optimal but gets the job done should we move this code fragment to it's own helper function to use everywhere stuff is requested according to a template ? Index: gsttee.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gsttee.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- gsttee.c 2002/02/04 23:28:55 1.15 +++ gsttee.c 2002/02/05 17:42:40 1.16 @@ -155,12 +155,25 @@ tee->silent = FALSE; } +/* helper compare function */ +gint name_pad_compare (gconstpointer a, gconstpointer b) +{ + GstPad* pad = (GstPad*) a; + gchar *name = (gchar *) b; + + g_assert (GST_IS_PAD (pad)); + + return g_strcasecmp (name, gst_pad_get_name (pad)); /* returns 0 if match */ +} + static GstPad* gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused) { gchar *name; GstPad *srcpad; GstTee *tee; + int i = 0; + GList *pads; g_return_val_if_fail (GST_IS_TEE (element), NULL); @@ -171,7 +184,22 @@ tee = GST_TEE (element); - name = g_strdup_printf ("src%d", GST_ELEMENT (tee)->numsrcpads); + /* try names in order and find one that's not in use atm */ + pads = gst_element_get_pad_list (element); + + name = NULL; + while (!name) + { + name = g_strdup_printf ("src%d", i); + if (g_list_find_custom (pads, (gconstpointer) name, name_pad_compare) != NULL) + { + /* this name is taken, use the next one */ + ++i; + g_free (name); + name = NULL; + } + } + gst_element_info (GST_ELEMENT (tee), "new pad %s", name); srcpad = gst_pad_new_from_template (templ, name); gst_element_add_pad (GST_ELEMENT (tee), srcpad); |