gboolean
gst_caps_is_subset (const GstCaps * subset, const GstCaps * superset)
{
- GstCaps *caps;
- gboolean ret;
+ GstStructure *s1, *s2;
+ gboolean ret = TRUE;
+ gint i, j;
g_return_val_if_fail (subset != NULL, FALSE);
g_return_val_if_fail (superset != NULL, FALSE);
if (CAPS_IS_ANY (subset) || CAPS_IS_EMPTY (superset))
return FALSE;
- caps = gst_caps_subtract (subset, superset);
- ret = CAPS_IS_EMPTY_SIMPLE (caps);
- gst_caps_unref (caps);
+ for (i = subset->structs->len - 1; i >= 0; i--) {
+ for (j = superset->structs->len - 1; j >= 0; j--) {
+ s1 = gst_caps_get_structure_unchecked (subset, i);
+ s2 = gst_caps_get_structure_unchecked (superset, j);
+ if (gst_caps_structure_is_subset (s2, s1)) {
+ /* If we found a superset, continue with the next
+ * subset structure */
+ break;
+ }
+ }
+ /* If we found no superset for this subset structure
+ * we return FALSE immediately */
+ if (j == -1) {
+ ret = FALSE;
+ break;
+ }
+ }
+
return ret;
}
GST_END_TEST;
+GST_START_TEST (test_subset)
+{
+ GstCaps *c1, *c2;
+
+ c1 = gst_caps_from_string ("video/x-raw-yuv; video/x-raw-rgb");
+ c2 = gst_caps_from_string ("video/x-raw-yuv, format=(fourcc)YUY2");
+ fail_unless (gst_caps_is_subset (c2, c1));
+ fail_if (gst_caps_is_subset (c1, c2));
+ gst_caps_unref (c1);
+ gst_caps_unref (c2);
+
+ c1 = gst_caps_from_string
+ ("audio/x-raw-int, channels=(int)[ 1, 2 ], rate=(int)44100");
+ c2 = gst_caps_from_string
+ ("audio/x-raw-int, channels=(int)1, rate=(int)44100");
+ fail_unless (gst_caps_is_subset (c2, c1));
+ fail_if (gst_caps_is_subset (c1, c2));
+ gst_caps_unref (c1);
+ gst_caps_unref (c2);
+}
+
+GST_END_TEST;
+
GST_START_TEST (test_merge_fundamental)
{
GstCaps *c1, *c2;
tcase_add_test (tc_chain, test_static_caps);
tcase_add_test (tc_chain, test_simplify);
tcase_add_test (tc_chain, test_truncate);
+ tcase_add_test (tc_chain, test_subset);
tcase_add_test (tc_chain, test_merge_fundamental);
tcase_add_test (tc_chain, test_merge_same);
tcase_add_test (tc_chain, test_merge_subset);