structure: Make sure that subsets have all fields of the superset
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 13 Feb 2013 09:46:37 +0000 (10:46 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 13 Feb 2013 09:46:37 +0000 (10:46 +0100)
"video/x-h264,parsed=(boolean)true" is not a superset of
"video/x-h264,stream-format=(string)byte-stream,alignment=(string)nal"
for example.

https://bugzilla.gnome.org/show_bug.cgi?id=693365

gst/gststructure.c
tests/check/gst/gstcaps.c

index 919fc57..f064029 100644 (file)
@@ -3136,6 +3136,15 @@ gst_structure_can_intersect (const GstStructure * struct1,
 }
 
 static gboolean
+gst_caps_structure_has_field (GQuark field_id, const GValue * value,
+    gpointer user_data)
+{
+  GstStructure *subset = user_data;
+
+  return gst_structure_id_get_value (subset, field_id) != NULL;
+}
+
+static gboolean
 gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value,
     gpointer user_data)
 {
@@ -3179,6 +3188,11 @@ gst_structure_is_subset (const GstStructure * subset,
       (gst_structure_n_fields (superset) > gst_structure_n_fields (subset)))
     return FALSE;
 
+  /* The subset must have all fields that are in superset */
+  if (!gst_structure_foreach ((GstStructure *) superset,
+          gst_caps_structure_has_field, (gpointer) subset))
+    return FALSE;
+
   return gst_structure_foreach ((GstStructure *) subset,
       gst_caps_structure_is_subset_field, (gpointer) superset);
 }
index 283ffde..844bff5 100644 (file)
@@ -312,6 +312,15 @@ GST_START_TEST (test_subset)
   fail_if (gst_caps_is_subset (c2, c1));
   gst_caps_unref (c1);
   gst_caps_unref (c2);
+
+  c1 = gst_caps_from_string ("video/x-h264, parsed=(boolean)true");
+  c2 = gst_caps_from_string
+      ("video/x-h264, stream-format=(string)byte-stream, alignment=(string)nal");
+  fail_if (gst_caps_is_subset (c2, c1));
+  fail_if (gst_caps_is_subset (c1, c2));
+  fail_if (gst_caps_is_equal (c1, c2));
+  gst_caps_unref (c1);
+  gst_caps_unref (c2);
 }
 
 GST_END_TEST;