mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-19 06:46:38 +00:00
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.
This commit is contained in:
parent
d706ca0859
commit
0cf2dfd0ba
2 changed files with 30 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue