[farsight2/master] Factor out duplicated generated pad linking function

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:25:47 PST 2008


---
 gst/fsrtpconference/fs-rtp-codec-negotiation.c |   83 ++++++++++--------------
 1 files changed, 34 insertions(+), 49 deletions(-)

diff --git a/gst/fsrtpconference/fs-rtp-codec-negotiation.c b/gst/fsrtpconference/fs-rtp-codec-negotiation.c
index c09946e..3d5db51 100644
--- a/gst/fsrtpconference/fs-rtp-codec-negotiation.c
+++ b/gst/fsrtpconference/fs-rtp-codec-negotiation.c
@@ -49,28 +49,26 @@ static CodecAssociation *
 lookup_codec_association_custom_intern (GList *codec_associations,
     gboolean want_disabled, CAFindFunc func, gpointer user_data);
 
-
-GstElement *
-parse_bin_from_description_all_linked (const gchar *bin_description,
-    guint *src_pad_count, guint *sink_pad_count, GError **error)
+static gboolean
+link_unlinked_pads (GstElement *bin,
+    GstPadDirection dir,
+    const gchar *first_pad_name,
+    const gchar *extra_pad_format,
+    guint *pad_count,
+    GError **error)
 {
-  GstElement *bin =
-    gst_parse_bin_from_description (bin_description, FALSE, error);
   GstPad *pad = NULL;
   guint i = 0;
 
-  if (!bin)
-    return NULL;
-
-  while ((pad = gst_bin_find_unlinked_pad (GST_BIN (bin), GST_PAD_SRC)))
+  while ((pad = gst_bin_find_unlinked_pad (GST_BIN (bin), dir)))
   {
     GstPad *ghostpad;
     gchar *tmp;
 
     if (i)
-      tmp = g_strdup_printf ("src%u", i);
+      tmp = g_strdup_printf (extra_pad_format, i);
     else
-      tmp = g_strdup_printf ("src");
+      tmp = g_strdup_printf (first_pad_name);
     i++;
 
     ghostpad = gst_ghost_pad_new (tmp, pad);
@@ -79,56 +77,43 @@ parse_bin_from_description_all_linked (const gchar *bin_description,
 
     if (!ghostpad)
     {
-      GST_ERROR ("Could not create ghostpad for pad %s:%s",
+      g_set_error (error, FS_ERROR, FS_ERROR_CONSTRUCTION,
+          "Could not create ghostpad for pad %s:%s",
           GST_DEBUG_PAD_NAME (pad));
-      goto error;
+      return FALSE;
     }
 
     if (!gst_element_add_pad (bin, ghostpad))
     {
-      GST_ERROR ("Could not add pad %s to bin", GST_OBJECT_NAME (ghostpad));
-      goto error;
+      g_set_error (error, FS_ERROR, FS_ERROR_CONSTRUCTION,
+          "Could not add pad %s to bin", GST_OBJECT_NAME (ghostpad));
+      return FALSE;
     }
   }
 
-  if (src_pad_count)
-    *src_pad_count = i;
-
-
-  i = 0;
-
-  while ((pad = gst_bin_find_unlinked_pad (GST_BIN (bin), GST_PAD_SINK)))
-  {
-    GstPad *ghostpad;
-    gchar *tmp;
-
-    if (i)
-      tmp = g_strdup_printf ("sink%u", i);
-    else
-      tmp = g_strdup_printf ("sink");
-    i++;
+  if (pad_count)
+    *pad_count = i;
 
-    ghostpad = gst_ghost_pad_new (tmp, pad);
-    gst_object_unref (pad);
-    g_free (tmp);
+  return TRUE;
+}
 
-    if (!ghostpad)
-    {
-      GST_ERROR ("Could not create ghostpad for pad %s:%s",
-          GST_DEBUG_PAD_NAME (pad));
-      goto error;
-    }
+GstElement *
+parse_bin_from_description_all_linked (const gchar *bin_description,
+    guint *src_pad_count, guint *sink_pad_count, GError **error)
+{
+  GstElement *bin =
+    gst_parse_bin_from_description (bin_description, FALSE, error);
 
-    if (!gst_element_add_pad (bin, ghostpad))
-    {
-      GST_ERROR ("Could not add pad %s to bin", GST_OBJECT_NAME (ghostpad));
-      goto error;
-    }
-  }
+  if (!bin)
+    return NULL;
 
-  if (sink_pad_count)
-    *sink_pad_count = i;
+  if (!link_unlinked_pads (bin, GST_PAD_SRC, "src", "src%d", src_pad_count,
+          error))
+    goto error;
 
+  if (!link_unlinked_pads (bin, GST_PAD_SINK, "sink", "sink%d", sink_pad_count,
+          error))
+    goto error;
 
   return bin;
  error:
-- 
1.5.6.5




More information about the farsight-commits mailing list