mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
utils: Unref/release pads in error cases when linking pads
Previously gst_element_link_pads_full() forgot to unreference or release request pads in several error cases. Also comments were added mentioning why releasing is not necessary in some places. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=733119
This commit is contained in:
parent
91045ccd83
commit
a041e65503
1 changed files with 75 additions and 19 deletions
|
@ -1503,6 +1503,16 @@ pad_link_maybe_ghosting (GstPad * src, GstPad * sink, GstPadLinkCheck flags)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
release_and_unref_pad (GstElement * element, GstPad * pad, gboolean requestpad)
|
||||||
|
{
|
||||||
|
if (pad) {
|
||||||
|
if (requestpad)
|
||||||
|
gst_element_release_request_pad (element, pad);
|
||||||
|
gst_object_unref (pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_element_link_pads_full:
|
* gst_element_link_pads_full:
|
||||||
* @src: a #GstElement containing the source pad.
|
* @src: a #GstElement containing the source pad.
|
||||||
|
@ -1534,6 +1544,7 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
GstPad *srcpad, *destpad;
|
GstPad *srcpad, *destpad;
|
||||||
GstPadTemplate *srctempl, *desttempl;
|
GstPadTemplate *srctempl, *desttempl;
|
||||||
GstElementClass *srcclass, *destclass;
|
GstElementClass *srcclass, *destclass;
|
||||||
|
gboolean srcrequest, destrequest;
|
||||||
|
|
||||||
/* checks */
|
/* checks */
|
||||||
g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
|
g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
|
||||||
|
@ -1544,11 +1555,16 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
|
srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
|
||||||
destpadname ? destpadname : "(any)");
|
destpadname ? destpadname : "(any)");
|
||||||
|
|
||||||
|
srcrequest = FALSE;
|
||||||
|
destrequest = FALSE;
|
||||||
|
|
||||||
/* get a src pad */
|
/* get a src pad */
|
||||||
if (srcpadname) {
|
if (srcpadname) {
|
||||||
/* name specified, look it up */
|
/* name specified, look it up */
|
||||||
if (!(srcpad = gst_element_get_static_pad (src, srcpadname)))
|
if (!(srcpad = gst_element_get_static_pad (src, srcpadname))) {
|
||||||
srcpad = gst_element_get_request_pad (src, srcpadname);
|
if ((srcpad = gst_element_get_request_pad (src, srcpadname)))
|
||||||
|
srcrequest = TRUE;
|
||||||
|
}
|
||||||
if (!srcpad) {
|
if (!srcpad) {
|
||||||
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
|
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
|
||||||
GST_ELEMENT_NAME (src), srcpadname);
|
GST_ELEMENT_NAME (src), srcpadname);
|
||||||
|
@ -1557,13 +1573,15 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
|
if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
|
||||||
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
|
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
|
||||||
GST_DEBUG_PAD_NAME (srcpad));
|
GST_DEBUG_PAD_NAME (srcpad));
|
||||||
gst_object_unref (srcpad);
|
release_and_unref_pad (src, srcpad, srcrequest);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (GST_PAD_PEER (srcpad) != NULL) {
|
if (GST_PAD_PEER (srcpad) != NULL) {
|
||||||
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
|
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
|
||||||
"pad %s:%s is already linked to %s:%s", GST_DEBUG_PAD_NAME (srcpad),
|
"pad %s:%s is already linked to %s:%s", GST_DEBUG_PAD_NAME (srcpad),
|
||||||
GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
|
GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
|
||||||
|
/* already linked request pads look like static pads, so the request pad
|
||||||
|
* was never requested a second time above, so no need to release it */
|
||||||
gst_object_unref (srcpad);
|
gst_object_unref (srcpad);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1582,17 +1600,21 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
/* get a destination pad */
|
/* get a destination pad */
|
||||||
if (destpadname) {
|
if (destpadname) {
|
||||||
/* name specified, look it up */
|
/* name specified, look it up */
|
||||||
if (!(destpad = gst_element_get_static_pad (dest, destpadname)))
|
if (!(destpad = gst_element_get_static_pad (dest, destpadname))) {
|
||||||
destpad = gst_element_get_request_pad (dest, destpadname);
|
if ((destpad = gst_element_get_request_pad (dest, destpadname)))
|
||||||
|
destrequest = TRUE;
|
||||||
|
}
|
||||||
if (!destpad) {
|
if (!destpad) {
|
||||||
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
|
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
|
||||||
GST_ELEMENT_NAME (dest), destpadname);
|
GST_ELEMENT_NAME (dest), destpadname);
|
||||||
|
release_and_unref_pad (src, srcpad, srcrequest);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
|
if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
|
||||||
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
|
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
|
||||||
GST_DEBUG_PAD_NAME (destpad));
|
GST_DEBUG_PAD_NAME (destpad));
|
||||||
gst_object_unref (destpad);
|
release_and_unref_pad (src, srcpad, srcrequest);
|
||||||
|
release_and_unref_pad (dest, destpad, destrequest);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (GST_PAD_PEER (destpad) != NULL) {
|
if (GST_PAD_PEER (destpad) != NULL) {
|
||||||
|
@ -1600,6 +1622,9 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
"pad %s:%s is already linked to %s:%s",
|
"pad %s:%s is already linked to %s:%s",
|
||||||
GST_DEBUG_PAD_NAME (destpad),
|
GST_DEBUG_PAD_NAME (destpad),
|
||||||
GST_DEBUG_PAD_NAME (GST_PAD_PEER (destpad)));
|
GST_DEBUG_PAD_NAME (GST_PAD_PEER (destpad)));
|
||||||
|
release_and_unref_pad (src, srcpad, srcrequest);
|
||||||
|
/* already linked request pads look like static pads, so the request pad
|
||||||
|
* was never requested a second time above, so no need to release it */
|
||||||
gst_object_unref (destpad);
|
gst_object_unref (destpad);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1621,9 +1646,13 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
/* two explicitly specified pads */
|
/* two explicitly specified pads */
|
||||||
result = pad_link_maybe_ghosting (srcpad, destpad, flags);
|
result = pad_link_maybe_ghosting (srcpad, destpad, flags);
|
||||||
|
|
||||||
gst_object_unref (srcpad);
|
if (result) {
|
||||||
gst_object_unref (destpad);
|
gst_object_unref (srcpad);
|
||||||
|
gst_object_unref (destpad);
|
||||||
|
} else {
|
||||||
|
release_and_unref_pad (src, srcpad, srcrequest);
|
||||||
|
release_and_unref_pad (dest, destpad, destrequest);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1637,6 +1666,7 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
GST_DEBUG_PAD_NAME (srcpad));
|
GST_DEBUG_PAD_NAME (srcpad));
|
||||||
if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
|
if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
|
||||||
(GST_PAD_PEER (srcpad) == NULL)) {
|
(GST_PAD_PEER (srcpad) == NULL)) {
|
||||||
|
gboolean temprequest = FALSE;
|
||||||
GstPad *temp;
|
GstPad *temp;
|
||||||
|
|
||||||
if (destpadname) {
|
if (destpadname) {
|
||||||
|
@ -1644,6 +1674,11 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
gst_object_ref (temp);
|
gst_object_ref (temp);
|
||||||
} else {
|
} else {
|
||||||
temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
|
temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
|
||||||
|
if (!GST_IS_GHOST_PAD (temp) &&
|
||||||
|
GST_PAD_TEMPLATE_PRESENCE (GST_PAD_PAD_TEMPLATE (temp)) ==
|
||||||
|
GST_PAD_REQUEST) {
|
||||||
|
temprequest = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp && pad_link_maybe_ghosting (srcpad, temp, flags)) {
|
if (temp && pad_link_maybe_ghosting (srcpad, temp, flags)) {
|
||||||
|
@ -1657,6 +1692,8 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp) {
|
if (temp) {
|
||||||
|
if (temprequest)
|
||||||
|
gst_element_release_request_pad (dest, temp);
|
||||||
gst_object_unref (temp);
|
gst_object_unref (temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1674,13 +1711,16 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
if (srcpadname) {
|
if (srcpadname) {
|
||||||
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
|
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_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
|
||||||
|
/* no need to release any request pad as both src- and destpadname must be
|
||||||
|
* set to end up here, but this case has already been taken care of above */
|
||||||
if (destpad)
|
if (destpad)
|
||||||
gst_object_unref (destpad);
|
gst_object_unref (destpad);
|
||||||
destpad = NULL;
|
destpad = NULL;
|
||||||
}
|
}
|
||||||
if (srcpad)
|
if (srcpad) {
|
||||||
gst_object_unref (srcpad);
|
release_and_unref_pad (src, srcpad, srcrequest);
|
||||||
srcpad = NULL;
|
srcpad = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (destpad) {
|
if (destpad) {
|
||||||
/* loop through the existing pads in the destination */
|
/* loop through the existing pads in the destination */
|
||||||
|
@ -1690,6 +1730,15 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
|
if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
|
||||||
(GST_PAD_PEER (destpad) == NULL)) {
|
(GST_PAD_PEER (destpad) == NULL)) {
|
||||||
GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
|
GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
|
||||||
|
gboolean temprequest = FALSE;
|
||||||
|
|
||||||
|
if (temp) {
|
||||||
|
if (!GST_IS_GHOST_PAD (temp) &&
|
||||||
|
GST_PAD_TEMPLATE_PRESENCE (GST_PAD_PAD_TEMPLATE (temp)) ==
|
||||||
|
GST_PAD_REQUEST) {
|
||||||
|
temprequest = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (temp && pad_link_maybe_ghosting (temp, destpad, flags)) {
|
if (temp && pad_link_maybe_ghosting (temp, destpad, flags)) {
|
||||||
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
|
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
|
||||||
|
@ -1698,9 +1747,8 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
gst_object_unref (destpad);
|
gst_object_unref (destpad);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (temp) {
|
|
||||||
gst_object_unref (temp);
|
release_and_unref_pad (src, temp, temprequest);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (destpads) {
|
if (destpads) {
|
||||||
destpads = g_list_next (destpads);
|
destpads = g_list_next (destpads);
|
||||||
|
@ -1716,11 +1764,15 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
if (destpadname) {
|
if (destpadname) {
|
||||||
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
|
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
|
||||||
GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
|
GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
|
||||||
gst_object_unref (destpad);
|
release_and_unref_pad (dest, destpad, destrequest);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
if (destpad)
|
/* no need to release any request pad as the case of unset destpatname and
|
||||||
|
* destpad being a requst pad has already been taken care of when looking
|
||||||
|
* though the destination pads above */
|
||||||
|
if (destpad) {
|
||||||
gst_object_unref (destpad);
|
gst_object_unref (destpad);
|
||||||
|
}
|
||||||
destpad = NULL;
|
destpad = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1763,10 +1815,14 @@ gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
/* it failed, so we release the request pads */
|
/* it failed, so we release the request pads */
|
||||||
if (srcpad)
|
if (srcpad) {
|
||||||
gst_element_release_request_pad (src, srcpad);
|
gst_element_release_request_pad (src, srcpad);
|
||||||
if (destpad)
|
gst_object_unref (srcpad);
|
||||||
|
}
|
||||||
|
if (destpad) {
|
||||||
gst_element_release_request_pad (dest, destpad);
|
gst_element_release_request_pad (dest, destpad);
|
||||||
|
gst_object_unref (destpad);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gst_caps_unref (srccaps);
|
gst_caps_unref (srccaps);
|
||||||
gst_caps_unref (destcaps);
|
gst_caps_unref (destcaps);
|
||||||
|
|
Loading…
Reference in a new issue