diff options
author | Edward Hervey <bilboed@bilboed.com> | 2010-09-10 18:33:34 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2011-05-17 09:28:06 +0200 |
commit | 64725facb5d9b51570096dd3a980b19247372a57 (patch) | |
tree | d619746da5fd4470efda7f3335eab81c40ee3076 /gst | |
parent | ae46eb3a3848fa5991e987f08d59bc6a5b2bc9b5 (diff) |
gststructure: Add gst_structure_can_intersect API
Allows checking if two structures can intersect without having to
go through GstCaps
API: gst_structure_can_intersect
https://bugzilla.gnome.org/show_bug.cgi?id=629300
Diffstat (limited to 'gst')
-rw-r--r-- | gst/gstcaps.c | 48 | ||||
-rw-r--r-- | gst/gststructure.c | 59 | ||||
-rw-r--r-- | gst/gststructure.h | 2 |
3 files changed, 62 insertions, 47 deletions
diff --git a/gst/gstcaps.c b/gst/gstcaps.c index dc7735d0f..ceaaa2296 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -1265,52 +1265,6 @@ error: return NULL; } -static gboolean -gst_caps_structure_can_intersect_field (GQuark id, const GValue * val1, - gpointer data) -{ - GstStructure *other = (GstStructure *) data; - const GValue *val2 = gst_structure_id_get_value (other, id); - - if (G_LIKELY (val2)) { - if (!gst_value_can_intersect (val1, val2)) { - return FALSE; - } else { - gint eq = gst_value_compare (val1, val2); - - if (eq == GST_VALUE_UNORDERED) { - /* we need to try interseting */ - GValue dest_value = { 0 }; - if (gst_value_intersect (&dest_value, val1, val2)) { - g_value_unset (&dest_value); - } else { - return FALSE; - } - } else if (eq != GST_VALUE_EQUAL) { - return FALSE; - } - } - } - return TRUE; -} - -static gboolean -gst_caps_structure_can_intersect (const GstStructure * struct1, - const GstStructure * struct2) -{ - g_assert (struct1 != NULL); - g_assert (struct2 != NULL); - - if (G_UNLIKELY (struct1->name != struct2->name)) - return FALSE; - - /* tries to intersect if we have the field in both */ - if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct1, - gst_caps_structure_can_intersect_field, (gpointer) struct2))) - return FALSE; - - return TRUE; -} /** * gst_caps_can_intersect: @@ -1379,7 +1333,7 @@ gst_caps_can_intersect (const GstCaps * caps1, const GstCaps * caps2) struct1 = gst_caps_get_structure_unchecked (caps1, j); struct2 = gst_caps_get_structure_unchecked (caps2, k); - if (gst_caps_structure_can_intersect (struct1, struct2)) { + if (gst_structure_can_intersect (struct1, struct2)) { return TRUE; } /* move down left */ diff --git a/gst/gststructure.c b/gst/gststructure.c index 7b962c724..e97d159bd 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -2961,3 +2961,62 @@ gst_structure_is_equal (const GstStructure * structure1, return gst_structure_foreach (structure1, gst_structure_is_equal_foreach, structure2); } + +static gboolean +gst_caps_structure_can_intersect_field (GQuark id, const GValue * val1, + gpointer data) +{ + GstStructure *other = (GstStructure *) data; + const GValue *val2 = gst_structure_id_get_value (other, id); + + if (G_LIKELY (val2)) { + if (!gst_value_can_intersect (val1, val2)) { + return FALSE; + } else { + gint eq = gst_value_compare (val1, val2); + + if (eq == GST_VALUE_UNORDERED) { + /* we need to try interseting */ + GValue dest_value = { 0 }; + if (gst_value_intersect (&dest_value, val1, val2)) { + g_value_unset (&dest_value); + } else { + return FALSE; + } + } else if (eq != GST_VALUE_EQUAL) { + return FALSE; + } + } + } + return TRUE; +} + +/** + * gst_structure_can_intersect: + * @struct1: a #GstStructure + * @struct2: a #GstStructure + * + * Tries interesecting @struct1 and @struct2 and reports whether the result + * would not be empty. + * + * Returns: %TRUE if intersection would not be empty + * + * Since: 0.10.31 + */ +gboolean +gst_structure_can_intersect (const GstStructure * struct1, + const GstStructure * struct2) +{ + g_return_val_if_fail (GST_IS_STRUCTURE (struct1), FALSE); + g_return_val_if_fail (GST_IS_STRUCTURE (struct2), FALSE); + + if (G_UNLIKELY (struct1->name != struct2->name)) + return FALSE; + + /* tries to intersect if we have the field in both */ + if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct1, + gst_caps_structure_can_intersect_field, (gpointer) struct2))) + return FALSE; + + return TRUE; +} diff --git a/gst/gststructure.h b/gst/gststructure.h index 1d0d812f7..97536c330 100644 --- a/gst/gststructure.h +++ b/gst/gststructure.h @@ -250,6 +250,8 @@ gboolean gst_structure_fixate_field_nearest_fraction (GstStructu gboolean gst_structure_is_equal(const GstStructure *structure1, GstStructure *structure2); +gboolean gst_structure_can_intersect(const GstStructure *struct1, + const GstStructure *struct2); G_END_DECLS |