From: Thomas Vander Stichele Date: Tue, 5 Feb 2002 17:42:40 +0000 (+0000) Subject: this fix makes sure that we actually request a pad from the template with an unused... X-Git-Tag: RELEASE-0_3_3-GUADECBYFOOT~146 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c3ee55473fd4f5f24ac44593c7de951e63b05d61;p=platform%2Fupstream%2Fgstreamer.git this fix makes sure that we actually request a pad from the template with an unused name this isn't optimal but gets ... Original commit message from CVS: 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 ? --- diff --git a/gst/elements/gsttee.c b/gst/elements/gsttee.c index 2f817dd..d421ff8 100644 --- a/gst/elements/gsttee.c +++ b/gst/elements/gsttee.c @@ -155,12 +155,25 @@ gst_tee_init (GstTee *tee) 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 @@ gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar 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); diff --git a/plugins/elements/gsttee.c b/plugins/elements/gsttee.c index 2f817dd..d421ff8 100644 --- a/plugins/elements/gsttee.c +++ b/plugins/elements/gsttee.c @@ -155,12 +155,25 @@ gst_tee_init (GstTee *tee) 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 @@ gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar 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);