this fix makes sure that we actually request a pad from the template with an unused...
authorThomas Vander Stichele <thomas@apestaart.org>
Tue, 5 Feb 2002 17:42:40 +0000 (17:42 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Tue, 5 Feb 2002 17:42:40 +0000 (17:42 +0000)
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 ?

gst/elements/gsttee.c
plugins/elements/gsttee.c

index 2f817dd..d421ff8 100644 (file)
@@ -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);
index 2f817dd..d421ff8 100644 (file)
@@ -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);