From a95645eaba1d467254a1eec14a93f47d502f8854 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Fri, 26 Aug 2016 03:17:41 +1000 Subject: [PATCH] value: Implement can_intersect for GstFlagSet types Make sure that gst_value_can_intersect returns TRUE for GstFlagSet combinations that can successfully intersect --- gst/gstvalue.c | 14 ++++++++++++++ tests/check/gst/gstvalue.c | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/gst/gstvalue.c b/gst/gstvalue.c index b9f76de92b..6c96bfbfbb 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -4951,6 +4951,20 @@ gst_value_can_intersect (const GValue * value1, const GValue * value2) if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST) return TRUE; + if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) && + GST_VALUE_HOLDS_FLAG_SET (value2))) { + GType type1, type2, flagset_type; + + type1 = G_VALUE_TYPE (value1); + type2 = G_VALUE_TYPE (value2); + flagset_type = GST_TYPE_FLAG_SET; + + /* Allow intersection with the generic FlagSet type, on one + * side, but not 2 different subtypes - that makes no sense */ + if (type1 == type2 || type1 == flagset_type || type2 == flagset_type) + return TRUE; + } + /* check registered intersect functions */ len = gst_value_intersect_funcs->len; for (i = 0; i < len; i++) { diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c index 7bb8955d24..64082c4b9e 100644 --- a/tests/check/gst/gstvalue.c +++ b/tests/check/gst/gstvalue.c @@ -662,17 +662,22 @@ GST_START_TEST (test_flagset) /* GstFlagSet should always intersect with itself */ g_value_unset (&dest); + fail_unless (gst_value_can_intersect (&value, &value)); fail_unless (gst_value_intersect (&dest, &value, &value)); /* GstFlagSet subtype should intersect with itself */ g_value_unset (&dest); + fail_unless (gst_value_can_intersect (&value2, &value2)); fail_unless (gst_value_intersect (&dest, &value2, &value2)); /* Check we can intersect custom flagset subtype with flagset */ g_value_unset (&dest); + fail_unless (gst_value_can_intersect (&value2, &value)); fail_unless (gst_value_intersect (&dest, &value2, &value)); + /* and in the other order */ g_value_unset (&dest); + fail_unless (gst_value_can_intersect (&value, &value2)); fail_unless (gst_value_intersect (&dest, &value, &value2)); fail_unless (gst_value_get_flagset_flags (&dest) == test_flags,