gst/gstutils.c: fix a bug in the case where neither element has a pad
authorThomas Vander Stichele <thomas@apestaart.org>
Wed, 5 Oct 2005 21:34:42 +0000 (21:34 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Wed, 5 Oct 2005 21:34:42 +0000 (21:34 +0000)
Original commit message from CVS:
* gst/gstutils.c: (gst_element_link_pads):
fix a bug in the case where neither element has a pad
* check/gst/gstelement.c: (GST_START_TEST), (gst_element_suite):
add a test for that case

ChangeLog
check/gst/gstelement.c
gst/gstutils.c
tests/check/gst/gstelement.c

index a050eb9..6c3c387 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2005-10-05  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+       * gst/gstutils.c: (gst_element_link_pads):
+         fix a bug in the case where neither element has a pad
+       * check/gst/gstelement.c: (GST_START_TEST), (gst_element_suite):
+         add a test for that case
+
+2005-10-05  Thomas Vander Stichele  <thomas at apestaart dot org>
+
        * gst/gstpad.c: (gst_pad_push), (gst_pad_push_event):
          emit have-data before checking for peers.  This allows
          for probe handlers to connect elements.  This helps autopluggers.
index aeff42d..44fbc7d 100644 (file)
@@ -94,8 +94,7 @@ GST_START_TEST (test_error_no_bus)
 
 GST_END_TEST;
 
-/* link and run two elements without putting them in a 
- * pipeline */
+/* link and run two elements without putting them in a pipeline */
 GST_START_TEST (test_link)
 {
   GstElement *src, *sink;
@@ -131,6 +130,22 @@ GST_START_TEST (test_link)
 
 GST_END_TEST;
 
+/* linking two elements without pads should fail */
+GST_START_TEST (test_link_no_pads)
+{
+  GstElement *src, *sink;
+
+  src = gst_bin_new ("src");
+  sink = gst_bin_new ("sink");
+
+  fail_if (gst_element_link (src, sink));
+
+  gst_object_unref (src);
+  gst_object_unref (sink);
+}
+
+GST_END_TEST;
+
 Suite *
 gst_element_suite (void)
 {
@@ -142,6 +157,7 @@ gst_element_suite (void)
   tcase_add_test (tc_chain, test_add_pad_unref_element);
   tcase_add_test (tc_chain, test_error_no_bus);
   tcase_add_test (tc_chain, test_link);
+  tcase_add_test (tc_chain, test_link_no_pads);
 
   return s;
 }
index 27dd2bd..9920454 100644 (file)
@@ -1024,7 +1024,8 @@ pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
  * @src: a #GstElement containing the source pad.
  * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
  * @dest: the #GstElement containing the destination pad.
- * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
+ * @destpadname: the name of the #GstPad in destination element,
+ * or NULL for any pad.
  *
  * Links the two named pads of the source and destination elements.
  * Side effect is that if one of the pads has no parent, it becomes a
@@ -1054,8 +1055,9 @@ gst_element_link_pads (GstElement * src, const gchar * srcpadname,
       srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
       destpadname ? destpadname : "(any)");
 
-  /* now get the pads we're trying to link and a list of all remaining pads */
+  /* get a src pad */
   if (srcpadname) {
+    /* name specified, look it up */
     srcpad = gst_element_get_pad (src, srcpadname);
     if (!srcpad) {
       GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
@@ -1077,6 +1079,7 @@ gst_element_link_pads (GstElement * src, const gchar * srcpadname,
     }
     srcpads = NULL;
   } else {
+    /* no name given, get the first available pad */
     GST_LOCK (src);
     srcpads = GST_ELEMENT_PADS (src);
     srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
@@ -1084,7 +1087,10 @@ gst_element_link_pads (GstElement * src, const gchar * srcpadname,
       gst_object_ref (srcpad);
     GST_UNLOCK (src);
   }
+
+  /* get a destination pad */
   if (destpadname) {
+    /* name specified, look it up */
     destpad = gst_element_get_pad (dest, destpadname);
     if (!destpad) {
       GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
@@ -1106,6 +1112,7 @@ gst_element_link_pads (GstElement * src, const gchar * srcpadname,
     }
     destpads = NULL;
   } else {
+    /* no name given, get the first available pad */
     GST_LOCK (dest);
     destpads = GST_ELEMENT_PADS (dest);
     destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
@@ -1125,6 +1132,7 @@ gst_element_link_pads (GstElement * src, const gchar * srcpadname,
 
     return result;
   }
+
   if (srcpad) {
     /* loop through the allowed pads in the source, trying to find a
      * compatible destination pad */
@@ -1172,15 +1180,18 @@ gst_element_link_pads (GstElement * src, const gchar * srcpadname,
   if (srcpadname) {
     GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
         GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
-    gst_object_unref (srcpad);
+    if (srcpad)
+      gst_object_unref (srcpad);
+    srcpad = NULL;
     if (destpad)
       gst_object_unref (destpad);
-    return FALSE;
+    destpad = NULL;
   } else {
     if (srcpad)
       gst_object_unref (srcpad);
     srcpad = NULL;
   }
+
   if (destpad) {
     /* loop through the existing pads in the destination */
     do {
@@ -1213,6 +1224,7 @@ gst_element_link_pads (GstElement * src, const gchar * srcpadname,
       }
     } while (destpads);
   }
+
   if (destpadname) {
     GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
         GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
@@ -1221,10 +1233,11 @@ gst_element_link_pads (GstElement * src, const gchar * srcpadname,
       gst_object_unref (srcpad);
     return FALSE;
   } else {
-    gst_object_unref (destpad);
     if (srcpad)
       gst_object_unref (srcpad);
     srcpad = NULL;
+    if (destpad)
+      gst_object_unref (destpad);
     destpad = NULL;
   }
 
index aeff42d..44fbc7d 100644 (file)
@@ -94,8 +94,7 @@ GST_START_TEST (test_error_no_bus)
 
 GST_END_TEST;
 
-/* link and run two elements without putting them in a 
- * pipeline */
+/* link and run two elements without putting them in a pipeline */
 GST_START_TEST (test_link)
 {
   GstElement *src, *sink;
@@ -131,6 +130,22 @@ GST_START_TEST (test_link)
 
 GST_END_TEST;
 
+/* linking two elements without pads should fail */
+GST_START_TEST (test_link_no_pads)
+{
+  GstElement *src, *sink;
+
+  src = gst_bin_new ("src");
+  sink = gst_bin_new ("sink");
+
+  fail_if (gst_element_link (src, sink));
+
+  gst_object_unref (src);
+  gst_object_unref (sink);
+}
+
+GST_END_TEST;
+
 Suite *
 gst_element_suite (void)
 {
@@ -142,6 +157,7 @@ gst_element_suite (void)
   tcase_add_test (tc_chain, test_add_pad_unref_element);
   tcase_add_test (tc_chain, test_error_no_bus);
   tcase_add_test (tc_chain, test_link);
+  tcase_add_test (tc_chain, test_link_no_pads);
 
   return s;
 }