value: Fix comparison of int/int64 ranges

ranges are only equal if:
* Their bounds are equal
* And their step value are equal *IF* they contain more than one value

https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/253
This commit is contained in:
Edward Hervey 2017-11-04 13:28:03 +01:00 committed by Edward Hervey
parent 742291c799
commit 79374b8d94
2 changed files with 32 additions and 46 deletions

View file

@ -1450,33 +1450,28 @@ gst_value_transform_int_range_string (const GValue * src_value,
static gint static gint
gst_value_compare_int_range (const GValue * value1, const GValue * value2) gst_value_compare_int_range (const GValue * value1, const GValue * value2)
{ {
/* calculate the number of values in each range */ #if 0
gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1; /* Compare the ranges. (Kept for clarity for the below comparision) */
gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1; if (INT_RANGE_MIN (value1) != INT_RANGE_MIN (value2) ||
INT_RANGE_MAX (value1) != INT_RANGE_MAX (value2))
/* they must be equal */
if (n1 != n2)
return GST_VALUE_UNORDERED; return GST_VALUE_UNORDERED;
#else
/* The MIN and MAX of the range are actually stored packed into one 64bit
* value. We can therefore compare them directly */
if (value1->data[0].v_uint64 != value2->data[0].v_uint64)
return GST_VALUE_UNORDERED;
#endif
/* if empty, equal */ /* The extents are equal */
if (n1 == 0) /* If there is only one value (min == max), we ignore the step for
* comparison */
if (INT_RANGE_MIN (value1) == INT_RANGE_MAX (value1))
return GST_VALUE_EQUAL; return GST_VALUE_EQUAL;
/* if more than one value, then it is only equal if the step is equal /* Else the ranges are only equal if their step is also equal */
and bounds lie on the same value */ if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2))
if (n1 > 1) { return GST_VALUE_EQUAL;
if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) && return GST_VALUE_UNORDERED;
INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
return GST_VALUE_EQUAL;
}
return GST_VALUE_UNORDERED;
} else {
/* if just one, only if the value is equal */
if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
return GST_VALUE_EQUAL;
return GST_VALUE_UNORDERED;
}
} }
static gchar * static gchar *
@ -1704,33 +1699,21 @@ gst_value_transform_int64_range_string (const GValue * src_value,
static gint static gint
gst_value_compare_int64_range (const GValue * value1, const GValue * value2) gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
{ {
/* calculate the number of values in each range */ /* Compare the ranges. */
gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1; if (INT64_RANGE_MIN (value1) != INT64_RANGE_MIN (value2) ||
gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1; INT64_RANGE_MAX (value1) != INT64_RANGE_MAX (value2))
/* they must be equal */
if (n1 != n2)
return GST_VALUE_UNORDERED; return GST_VALUE_UNORDERED;
/* if empty, equal */ /* The extents are equal */
if (n1 == 0) /* If there is only one value (min == max), we ignore the step for
* comparison */
if (INT64_RANGE_MIN (value1) == INT64_RANGE_MAX (value1))
return GST_VALUE_EQUAL; return GST_VALUE_EQUAL;
/* if more than one value, then it is only equal if the step is equal /* Else the ranges are only equal if their step is also equal */
and bounds lie on the same value */ if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2))
if (n1 > 1) { return GST_VALUE_EQUAL;
if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) && return GST_VALUE_UNORDERED;
INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
return GST_VALUE_EQUAL;
}
return GST_VALUE_UNORDERED;
} else {
/* if just one, only if the value is equal */
if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
return GST_VALUE_EQUAL;
return GST_VALUE_UNORDERED;
}
} }
static gchar * static gchar *

View file

@ -3097,6 +3097,9 @@ GST_START_TEST (test_stepped_int_range_parsing)
"[1, 2, 2]", "[1, 2, 2]",
"[2, 3, 2]", "[2, 3, 2]",
"[0, 0, 0]", "[0, 0, 0]",
"[0, 0, 1]",
"[1, 2, 0]",
"[1, 1, 1]",
}; };
/* check we can parse good ranges */ /* check we can parse good ranges */