From 0cf2dfd0ba7dc835a43c05d1b043e59021c18852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 27 May 2011 13:37:06 +0200 Subject: [PATCH] caps: Fix subset check in gst_caps_merge() Caps A are a subset of caps B even if caps B doesn't have all fields of caps A. Also add a unit test for this. --- gst/gstcaps.c | 22 ++++++++++------------ tests/check/gst/gstcaps.c | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 3010d29d2e..10dbff7c00 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -569,13 +569,13 @@ static gboolean gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value, gpointer user_data) { - GstStructure *subtract_from = user_data; + GstStructure *superset = user_data; GValue subtraction = { 0, }; const GValue *other; - if (!(other = gst_structure_id_get_value (subtract_from, field_id))) - /* field is missing in one set */ - return FALSE; + if (!(other = gst_structure_id_get_value (superset, field_id))) + /* field is missing in the superset => is subset */ + return TRUE; /* equal values are subset */ if (gst_value_compare (other, value) == GST_VALUE_EQUAL) @@ -612,17 +612,15 @@ gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value, } static gboolean -gst_caps_structure_is_subset (const GstStructure * minuend, - const GstStructure * subtrahend) +gst_caps_structure_is_subset (const GstStructure * superset, + const GstStructure * subset) { - if ((minuend->name != subtrahend->name) || - (gst_structure_n_fields (minuend) != - gst_structure_n_fields (subtrahend))) { + if ((superset->name != subset->name) || + (gst_structure_n_fields (superset) > gst_structure_n_fields (subset))) return FALSE; - } - return gst_structure_foreach ((GstStructure *) subtrahend, - gst_caps_structure_is_subset_field, (gpointer) minuend); + return gst_structure_foreach ((GstStructure *) subset, + gst_caps_structure_is_subset_field, (gpointer) superset); } /** diff --git a/tests/check/gst/gstcaps.c b/tests/check/gst/gstcaps.c index a22c15f0d2..12e9e44e4f 100644 --- a/tests/check/gst/gstcaps.c +++ b/tests/check/gst/gstcaps.c @@ -573,6 +573,26 @@ GST_START_TEST (test_merge_subset) fail_unless (gst_caps_is_subset (test, c2)); gst_caps_unref (test); gst_caps_unref (c2); + + c2 = gst_caps_from_string ("audio/x-raw-int"); + c1 = gst_caps_from_string ("audio/x-raw-int,channels=1"); + gst_caps_merge (c2, c1); + GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2); + fail_unless (gst_caps_get_size (c2) == 1, NULL); + test = gst_caps_from_string ("audio/x-raw-int"); + fail_unless (gst_caps_is_equal (c2, test)); + gst_caps_unref (c2); + gst_caps_unref (test); + + c2 = gst_caps_from_string ("audio/x-raw-int,channels=1"); + c1 = gst_caps_from_string ("audio/x-raw-int"); + gst_caps_merge (c2, c1); + GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2); + fail_unless (gst_caps_get_size (c2) == 2, NULL); + test = gst_caps_from_string ("audio/x-raw-int,channels=1; audio/x-raw-int"); + fail_unless (gst_caps_is_equal (c2, test)); + gst_caps_unref (c2); + gst_caps_unref (test); } GST_END_TEST;