diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2011-05-27 13:58:26 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2011-05-27 13:58:26 +0200 |
commit | 30a7fd7b4d187dc4209941c52b4430d842f88876 (patch) | |
tree | a9fc97ecc88debf98fc11b9f825e98dd42ce2822 /gst/gststructure.c | |
parent | 26ca7546a732fb9db0f84ad0afed039813dc1d56 (diff) | |
parent | 57df18875761d6abe6ba88bc7290e29535396742 (diff) | |
download | gstreamer-30a7fd7b4d187dc4209941c52b4430d842f88876.tar.gz |
Merge branch 'master' into 0.11
Diffstat (limited to 'gst/gststructure.c')
-rw-r--r-- | gst/gststructure.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/gst/gststructure.c b/gst/gststructure.c index 6ff9432b01..a1b58a9ea0 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -3122,3 +3122,74 @@ gst_structure_can_intersect (const GstStructure * struct1, return TRUE; } + +static gboolean +gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value, + gpointer user_data) +{ + GstStructure *superset = user_data; + GValue subtraction = { 0, }; + const GValue *other; + + if (!(other = gst_structure_id_get_value (superset, field_id))) + /* field is missing in the superset => is subset */ + return TRUE; + + /* equal values are subset */ + if (gst_value_compare (other, value) == GST_VALUE_EQUAL) + return TRUE; + + /* + * 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. + */ + if (gst_value_subtract (&subtraction, other, value)) { + g_value_unset (&subtraction); + /* !empty result, swapping must be empty */ + if (!gst_value_subtract (&subtraction, value, other)) + return TRUE; + + g_value_unset (&subtraction); + } + return FALSE; +} + +/** + * gst_structure_is_subset: + * @subset: a #GstStructure + * @superset: a potentially greater #GstStructure + * + * Checks if @subset is a subset of @superset, i.e. has the same + * structure name and for all fields that are existing in @superset, + * @subset has a value that is a subset of the value in @superset. + * + * Returns: %TRUE if @subset is a subset of @superset + * + * Since: 0.10.35 + */ +gboolean +gst_structure_is_subset (const GstStructure * subset, + const GstStructure * superset) +{ + if ((superset->name != subset->name) || + (gst_structure_n_fields (superset) > gst_structure_n_fields (subset))) + return FALSE; + + return gst_structure_foreach ((GstStructure *) subset, + gst_caps_structure_is_subset_field, (gpointer) superset); +} |