From aebe4a3c13d62eea6365f3b7bd5b69df7791d599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 4 May 2011 11:29:15 +0200 Subject: [PATCH] basetransform: In getcaps() prefer the caps order and caps of downstream if possible --- libs/gst/base/gstbasetransform.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c index 4c4fdbec50..74af3d08a2 100644 --- a/libs/gst/base/gstbasetransform.c +++ b/libs/gst/base/gstbasetransform.c @@ -652,26 +652,25 @@ gst_base_transform_getcaps (GstPad * pad) { GstBaseTransform *trans; GstPad *otherpad; - GstCaps *caps; + GstCaps *peercaps, *caps; trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad)); otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad; /* we can do what the peer can */ - caps = gst_pad_peer_get_caps (otherpad); - if (caps) { + peercaps = gst_pad_peer_get_caps (otherpad); + if (peercaps) { GstCaps *temp; const GstCaps *templ; - GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, caps); + GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps); /* filtered against our padtemplate on the other side */ templ = gst_pad_get_pad_template_caps (otherpad); GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ); - temp = gst_caps_intersect (caps, templ); + temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST); GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp); - gst_caps_unref (caps); /* then see what we can transform this to */ caps = gst_base_transform_transform_caps (trans, @@ -688,8 +687,16 @@ gst_base_transform_getcaps (GstPad * pad) temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST); GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp); gst_caps_unref (caps); - /* this is what we can do */ caps = temp; + + /* Now try if we can put the untransformed downstream caps first */ + temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST); + if (!gst_caps_is_empty (temp)) { + gst_caps_merge (temp, caps); + caps = temp; + } else { + gst_caps_unref (temp); + } } else { /* no peer or the peer can do anything, our padtemplate is enough then */ caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); @@ -698,6 +705,9 @@ gst_base_transform_getcaps (GstPad * pad) done: GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps); + if (peercaps) + gst_caps_unref (peercaps); + gst_object_unref (trans); return caps;