value: fix subset between arrays
- Adding gst_value_is_subset_array_array to test if an array is a subset of another array. - Check gst_caps_is_subset() between containing arrays work. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9184>
This commit is contained in:
parent
848d55b96a
commit
b44f19ccbc
@ -4511,6 +4511,41 @@ gst_value_is_subset_list (const GValue * value1, const GValue * value2)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_value_is_subset_array_array (const GValue * val_sub, const GValue * val_sup)
|
||||
{
|
||||
/* Check if each element of the subset is within the subset while
|
||||
* respecting order. Not all element of superset has to be present in
|
||||
* subset.*/
|
||||
|
||||
GstValueList *superset = VALUE_LIST_ARRAY (val_sup);
|
||||
GstValueList *subset = VALUE_LIST_ARRAY (val_sub);
|
||||
gint it1, it2, len1, len2;
|
||||
gboolean is_subset;
|
||||
|
||||
len2 = superset->len;
|
||||
len1 = subset->len;
|
||||
is_subset = len1 <= len2;
|
||||
|
||||
for (it1 = 0, it2 = 0; is_subset && it1 < len1; it1++, it2++) {
|
||||
const GValue *child1 = &subset->fields[it1];
|
||||
const GValue *child2 = &superset->fields[it2];
|
||||
|
||||
is_subset = gst_value_is_subset (child1, child2);
|
||||
if (is_subset == FALSE) {
|
||||
/* try to find an element in superset that is a superset of subset[it1] */
|
||||
for (it2 = it2 + 1; it2 < len2 && it2 + len1 <= len2; it2++) {
|
||||
child2 = &superset->fields[it2];
|
||||
if ((is_subset = gst_value_is_subset (child1, child2)) == TRUE)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return is_subset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gst_value_is_subset:
|
||||
* @value1: a #GValue
|
||||
@ -4548,6 +4583,8 @@ gst_value_is_subset (const GValue * value1, const GValue * value2)
|
||||
} else if (type2 == GST_TYPE_CAPS) {
|
||||
return gst_caps_is_subset (gst_value_get_caps (value1),
|
||||
gst_value_get_caps (value2));
|
||||
} else if (type1 == GST_TYPE_ARRAY && type2 == GST_TYPE_ARRAY) {
|
||||
return gst_value_is_subset_array_array (value1, value2);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1959,6 +1959,24 @@ GST_START_TEST (test_nested)
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_array_subset)
|
||||
{
|
||||
GstCaps *caps1, *caps2;
|
||||
|
||||
caps1 = gst_caps_from_string ("tensor/strided,"
|
||||
"dims=<(int)[0,1], (int)[1,9999]>");
|
||||
|
||||
caps2 = gst_caps_from_string ("tensor/strided, dims=<1, 1000>");
|
||||
|
||||
fail_unless (gst_caps_is_subset (caps2, caps1));
|
||||
|
||||
gst_caps_unref (caps1);
|
||||
gst_caps_unref (caps2);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
static Suite *
|
||||
gst_caps_suite (void)
|
||||
{
|
||||
@ -1998,6 +2016,7 @@ gst_caps_suite (void)
|
||||
tcase_add_test (tc_chain, test_remains_any);
|
||||
tcase_add_test (tc_chain, test_fixed);
|
||||
tcase_add_test (tc_chain, test_nested);
|
||||
tcase_add_test (tc_chain, test_array_subset);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user