Commit 58e5cd26 authored by Jan Schmidt's avatar Jan Schmidt
Browse files

gstvalue: Implement gst_value_is_subset() for flagsets

parent c5a3e8db
......@@ -3387,6 +3387,31 @@ gst_value_is_subset_int64_range_int64_range (const GValue * value1,
return TRUE;
}
/* A flag set is a subset of another if the superset allows the
* flags of the subset */
static gboolean
gst_value_is_subset_flagset_flagset (const GValue * value1,
const GValue * value2)
{
guint f1, f2;
guint m1, m2;
g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
f1 = value1->data[0].v_uint;
f2 = value2->data[0].v_uint;
m1 = value1->data[1].v_uint;
m2 = value2->data[1].v_uint;
/* Not a subset if masked bits of superset disagree */
if ((f1 & m1) != (f2 & (m1 & m2)))
return FALSE;
return TRUE;
}
/**
* gst_value_is_subset:
* @value1: a #GValue
......@@ -3408,6 +3433,9 @@ gst_value_is_subset (const GValue * value1, const GValue * value2)
} else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
&& GST_VALUE_HOLDS_INT64_RANGE (value2)) {
return gst_value_is_subset_int64_range_int64_range (value1, value2);
} else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
GST_VALUE_HOLDS_FLAG_SET (value2)) {
return gst_value_is_subset_flagset_flagset (value1, value2);
}
/*
......
......@@ -664,8 +664,18 @@ GST_START_TEST (test_flagset)
"resulting mask is 0x%u, not 0x%x",
gst_value_get_flagset_mask (&dest), test_mask);
gst_value_set_flagset (&value,
GST_SEEK_FLAG_ACCURATE, GST_SEEK_FLAG_ACCURATE);
gst_value_set_flagset (&value2, GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_FLUSH,
GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_SNAP_BEFORE | GST_SEEK_FLAG_FLUSH);
/* Check that accurate alone is a subset of accurate+!snap_before+flush,
* but not vice-versa */
fail_unless (gst_value_is_subset (&value, &value2));
fail_if (gst_value_is_subset (&value2, &value));
g_value_unset (&dest);
g_value_unset (&value);
g_value_unset (&value2);
}
GST_END_TEST;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment