gstvalue: add stepped ranges

int and int64 ranges can now have an optional step (defaulting to 1).
Members of the range are those values within the min and max bounds
which are a multiple of this step.

https://bugzilla.gnome.org/show_bug.cgi?id=665294
This commit is contained in:
Vincent Penquerc'h 2011-11-30 14:45:12 +00:00
parent 7319b52a2e
commit 39533f4364
4 changed files with 673 additions and 145 deletions

View file

@ -1900,8 +1900,9 @@ gst_structure_parse_range (gchar * s, gchar ** after, GValue * value,
{
GValue value1 = { 0 };
GValue value2 = { 0 };
GValue value3 = { 0 };
GType range_type;
gboolean ret;
gboolean ret, have_step = FALSE;
if (*s != '[')
return FALSE;
@ -1928,12 +1929,34 @@ gst_structure_parse_range (gchar * s, gchar ** after, GValue * value,
while (g_ascii_isspace (*s))
s++;
/* optional step for int and int64 */
if (G_VALUE_TYPE (&value1) == G_TYPE_INT
|| G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
if (*s == ',') {
s++;
while (g_ascii_isspace (*s))
s++;
ret = gst_structure_parse_value (s, &s, &value3, type);
if (ret == FALSE)
return FALSE;
while (g_ascii_isspace (*s))
s++;
have_step = TRUE;
}
}
if (*s != ']')
return FALSE;
s++;
if (G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value2))
return FALSE;
if (have_step && G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value3))
return FALSE;
if (G_VALUE_TYPE (&value1) == G_TYPE_DOUBLE) {
range_type = GST_TYPE_DOUBLE_RANGE;
@ -1944,12 +1967,25 @@ gst_structure_parse_range (gchar * s, gchar ** after, GValue * value,
} else if (G_VALUE_TYPE (&value1) == G_TYPE_INT) {
range_type = GST_TYPE_INT_RANGE;
g_value_init (value, range_type);
if (have_step)
gst_value_set_int_range_step (value,
gst_g_value_get_int_unchecked (&value1),
gst_g_value_get_int_unchecked (&value2),
gst_g_value_get_int_unchecked (&value3));
else
gst_value_set_int_range (value, gst_g_value_get_int_unchecked (&value1),
gst_g_value_get_int_unchecked (&value2));
} else if (G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
range_type = GST_TYPE_INT64_RANGE;
g_value_init (value, range_type);
gst_value_set_int64_range (value, gst_g_value_get_int64_unchecked (&value1),
if (have_step)
gst_value_set_int64_range_step (value,
gst_g_value_get_int64_unchecked (&value1),
gst_g_value_get_int64_unchecked (&value2),
gst_g_value_get_int64_unchecked (&value3));
else
gst_value_set_int64_range (value,
gst_g_value_get_int64_unchecked (&value1),
gst_g_value_get_int64_unchecked (&value2));
} else if (G_VALUE_TYPE (&value1) == GST_TYPE_FRACTION) {
range_type = GST_TYPE_FRACTION_RANGE;
@ -3132,32 +3168,7 @@ gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value,
if (comparison != GST_VALUE_UNORDERED)
return FALSE;
/*
* 1 - [1,2] = empty
* -> !subset
*
* [1,2] - 1 = 2
* -> 1 - [1,2] = empty
* -> subset
*
* [1,3] - [1,2] = 3
* -> [1,2] - [1,3] = empty
* -> subset
*
* {1,2} - {1,3} = 2
* -> {1,3} - {1,2} = 3
* -> !subset
*
* First caps subtraction needs to return a non-empty set, second
* subtractions needs to give en empty set.
* Both substractions are switched below, as it's faster that way.
*/
if (!gst_value_subtract (NULL, value, other)) {
if (gst_value_subtract (NULL, other, value)) {
return TRUE;
}
}
return FALSE;
return gst_value_is_subset (value, other);
}
/**

File diff suppressed because it is too large Load diff

View file

@ -476,15 +476,25 @@ const GValue * gst_value_array_get_value (const GValue *value,
void gst_value_set_int_range (GValue *value,
gint start,
gint end);
void gst_value_set_int_range_step (GValue *value,
gint start,
gint end,
gint step);
gint gst_value_get_int_range_min (const GValue *value);
gint gst_value_get_int_range_max (const GValue *value);
gint gst_value_get_int_range_step (const GValue *value);
/* int64 range */
void gst_value_set_int64_range (GValue *value,
gint64 start,
gint64 end);
void gst_value_set_int64_range_step (GValue *value,
gint64 start,
gint64 end,
gint64 step);
gint64 gst_value_get_int64_range_min (const GValue *value);
gint64 gst_value_get_int64_range_max (const GValue *value);
gint64 gst_value_get_int64_range_step (const GValue *value);
/* double range */
void gst_value_set_double_range (GValue *value,
@ -539,6 +549,9 @@ gint gst_value_compare (const GValue *value1,
const GValue *value2);
gboolean gst_value_can_compare (const GValue *value1,
const GValue *value2);
gboolean gst_value_is_subset (const GValue *value1,
const GValue *value2);
/* union */
gboolean gst_value_union (GValue *dest,
const GValue *value1,

View file

@ -1155,6 +1155,7 @@ EXPORTS
gst_util_gdouble_to_guint64
gst_util_get_timestamp
gst_util_greatest_common_divisor
gst_util_greatest_common_divisor_int64
gst_util_guint64_to_gdouble
gst_util_seqnum_compare
gst_util_seqnum_next
@ -1190,12 +1191,15 @@ EXPORTS
gst_value_get_fraction_range_min
gst_value_get_int64_range_max
gst_value_get_int64_range_min
gst_value_get_int64_range_step
gst_value_get_int_range_max
gst_value_get_int_range_min
gst_value_get_int_range_step
gst_value_get_structure
gst_value_init_and_copy
gst_value_intersect
gst_value_is_fixed
gst_value_is_subset
gst_value_list_append_value
gst_value_list_concat
gst_value_list_get_size
@ -1215,7 +1219,9 @@ EXPORTS
gst_value_set_fraction_range
gst_value_set_fraction_range_full
gst_value_set_int64_range
gst_value_set_int64_range_step
gst_value_set_int_range
gst_value_set_int_range_step
gst_value_set_structure
gst_value_subtract
gst_value_union