From 8b0f1ffe114540ba056e2a502e16da6404dfe51f Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Wed, 5 Oct 2005 21:34:42 +0000 Subject: [PATCH] gst/gstutils.c: fix a bug in the case where neither element has a pad 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 | 7 +++++++ check/gst/gstelement.c | 20 ++++++++++++++++++-- gst/gstutils.c | 23 ++++++++++++++++++----- tests/check/gst/gstelement.c | 20 ++++++++++++++++++-- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index a050eb9..6c3c387 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2005-10-05 Thomas Vander Stichele + * 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 + * 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. diff --git a/check/gst/gstelement.c b/check/gst/gstelement.c index aeff42d..44fbc7d 100644 --- a/check/gst/gstelement.c +++ b/check/gst/gstelement.c @@ -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; } diff --git a/gst/gstutils.c b/gst/gstutils.c index 27dd2bd..9920454 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -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; } diff --git a/tests/check/gst/gstelement.c b/tests/check/gst/gstelement.c index aeff42d..44fbc7d 100644 --- a/tests/check/gst/gstelement.c +++ b/tests/check/gst/gstelement.c @@ -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; } -- 2.7.4