From b5b28e2e3910610145adcff9f0272aebe0b1e201 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 20 Jan 2006 09:53:24 +0000 Subject: [PATCH] gst/gstcaps.c: Clarify behaviour of _is_equal() when passing NULL parameters. Original commit message from CVS: * gst/gstcaps.c: Clarify behaviour of _is_equal() when passing NULL parameters. * gst/gstpad.c: (gst_pad_link_check_compatible_unlocked), (gst_pad_set_caps): Cleanups. Don't unref NULL caps. When setting the same caps, protect caps of the pad with proper lock. Use full functionality of _is_equal() when comparing caps. --- ChangeLog | 12 ++++++++++++ gst/gstcaps.c | 4 +++- gst/gstpad.c | 39 +++++++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c83d3c..f917bd1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2006-01-20 Wim Taymans + + * gst/gstcaps.c: + Clarify behaviour of _is_equal() when passing NULL parameters. + + * gst/gstpad.c: (gst_pad_link_check_compatible_unlocked), + (gst_pad_set_caps): + Cleanups. Don't unref NULL caps. + When setting the same caps, protect caps of the pad with + proper lock. + Use full functionality of _is_equal() when comparing caps. + 2006-01-20 Jan Schmidt * libs/gst/base/gstcollectpads.c: (gst_collect_pads_is_collected): diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 3680367..e407f99 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -875,7 +875,9 @@ gst_caps_is_subset (const GstCaps * subset, const GstCaps * superset) * This function does not work reliably if optional properties for caps * are included on one caps and omitted on the other. * - * Returns: TRUE if both caps are equal + * This function deals correctly with passing NULL for any of the caps. + * + * Returns: TRUE if both caps are equal. */ gboolean gst_caps_is_equal (const GstCaps * caps1, const GstCaps * caps2) diff --git a/gst/gstpad.c b/gst/gstpad.c index 8efe281..a1e9993 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -1510,10 +1510,12 @@ gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink) srccaps = gst_pad_get_caps_unlocked (src); sinkcaps = gst_pad_get_caps_unlocked (sink); + GST_CAT_DEBUG (GST_CAT_CAPS, "src caps %" GST_PTR_FORMAT, srccaps); GST_CAT_DEBUG (GST_CAT_CAPS, "sink caps %" GST_PTR_FORMAT, sinkcaps); - /* if we have caps on both pads we can check the intersection */ + /* if we have caps on both pads we can check the intersection. If one + * of the caps is NULL, we return TRUE. */ if (srccaps && sinkcaps) { GstCaps *icaps; @@ -1521,18 +1523,31 @@ gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink) gst_caps_unref (srccaps); gst_caps_unref (sinkcaps); + if (icaps == NULL) + goto was_null; + GST_CAT_DEBUG (GST_CAT_CAPS, "intersection caps %p %" GST_PTR_FORMAT, icaps, icaps); - if (!icaps || gst_caps_is_empty (icaps)) { - GST_CAT_DEBUG (GST_CAT_CAPS, "intersection is empty"); - gst_caps_unref (icaps); - return FALSE; - } + if (gst_caps_is_empty (icaps)) + goto was_empty; + gst_caps_unref (icaps); } - return TRUE; + + /* incompatible cases */ +was_null: + { + GST_CAT_DEBUG (GST_CAT_CAPS, "intersection gave NULL"); + return FALSE; + } +was_empty: + { + GST_CAT_DEBUG (GST_CAT_CAPS, "intersection is EMPTY"); + gst_caps_unref (icaps); + return FALSE; + } } /* check if the grandparents of both pads are the same. @@ -2136,12 +2151,11 @@ gst_pad_set_caps (GstPad * pad, GstCaps * caps) setcaps = GST_PAD_SETCAPSFUNC (pad); existing = GST_PAD_CAPS (pad); - if (caps == existing) - goto setting_same_caps; - else if (caps && existing && gst_caps_is_equal (caps, existing)) + if (gst_caps_is_equal (caps, existing)) goto setting_same_caps; - /* call setcaps function to configure the pad */ + /* call setcaps function to configure the pad only if the + * caps is not NULL */ if (setcaps != NULL && caps) { if (!GST_PAD_IS_IN_SETCAPS (pad)) { GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_SETCAPS); @@ -2167,10 +2181,11 @@ gst_pad_set_caps (GstPad * pad, GstCaps * caps) setting_same_caps: { - GST_OBJECT_UNLOCK (pad); gst_caps_replace (&GST_PAD_CAPS (pad), caps); GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "caps %" GST_PTR_FORMAT " same as existing, updating ptr only", caps); + GST_OBJECT_UNLOCK (pad); + return TRUE; } /* errors */ -- 2.7.4