From 4377823d17a38022381fbff8d33783349185f8bb Mon Sep 17 00:00:00 2001 From: Niv Sardi Date: Fri, 25 Jan 2013 06:50:27 -0300 Subject: [PATCH] gst_element_get_compatible_pad_template: use gst_pad_get_pad_template motivation comes from: /* FIXME: why not gst_pad_get_pad_template (pad); */ this code path is quite nicer, we now only revert to creating the template if gst_pad_get_pad_template fails. with this fork, we gain a non-allocation of GstCaps *templcaps Signed-off-by: Niv Sardi --- gst/gstutils.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/gst/gstutils.c b/gst/gstutils.c index 8968024..17eea83 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -993,7 +993,6 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad, { GstIterator *pads; GstPadTemplate *templ; - GstCaps *templcaps; GstPad *foundpad = NULL; gboolean done; GValue padptr = { 0, }; @@ -1101,13 +1100,21 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad, "Could not find a compatible unlinked always pad to link to %s:%s, now checking request pads", GST_DEBUG_PAD_NAME (pad)); - /* try to create a new one */ - /* requesting is a little crazy, we need a template. Let's create one */ - /* FIXME: why not gst_pad_get_pad_template (pad); */ - templcaps = gst_pad_query_caps (pad, NULL); - templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad), - GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps); - gst_caps_unref (templcaps); + /* requesting is a little crazy, we need a template. Let's get the one in that pad */ + templ = gst_pad_get_pad_template (pad); + if (!templ) { + /* that failed, try to create a new one */ + GstCaps *templcaps; + + GST_CAT_DEBUG_OBJECT (GST_CAT_ELEMENT_PADS, element, + "Couldn't extract template from pad %s:%s creating a new one", + GST_DEBUG_PAD_NAME (pad)); + + templcaps = gst_pad_query_caps (pad, NULL); + templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad), + GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps); + gst_caps_unref (templcaps); + } foundpad = gst_element_request_compatible_pad (element, templ); gst_object_unref (templ); -- 1.8.1.1