mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
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
This commit is contained in:
parent
ae46eb3a38
commit
64725facb5
5 changed files with 64 additions and 47 deletions
|
@ -2210,6 +2210,7 @@ gst_structure_n_fields
|
||||||
gst_structure_has_field
|
gst_structure_has_field
|
||||||
gst_structure_has_field_typed
|
gst_structure_has_field_typed
|
||||||
gst_structure_is_equal
|
gst_structure_is_equal
|
||||||
|
gst_structure_can_intersect
|
||||||
gst_structure_id_has_field
|
gst_structure_id_has_field
|
||||||
gst_structure_id_has_field_typed
|
gst_structure_id_has_field_typed
|
||||||
gst_structure_get_boolean
|
gst_structure_get_boolean
|
||||||
|
|
|
@ -1265,52 +1265,6 @@ error:
|
||||||
return NULL;
|
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:
|
* 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);
|
struct1 = gst_caps_get_structure_unchecked (caps1, j);
|
||||||
struct2 = gst_caps_get_structure_unchecked (caps2, k);
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
/* move down left */
|
/* move down left */
|
||||||
|
|
|
@ -2961,3 +2961,62 @@ gst_structure_is_equal (const GstStructure * structure1,
|
||||||
return gst_structure_foreach (structure1, gst_structure_is_equal_foreach,
|
return gst_structure_foreach (structure1, gst_structure_is_equal_foreach,
|
||||||
structure2);
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -250,6 +250,8 @@ gboolean gst_structure_fixate_field_nearest_fraction (GstStructu
|
||||||
|
|
||||||
gboolean gst_structure_is_equal(const GstStructure *structure1,
|
gboolean gst_structure_is_equal(const GstStructure *structure1,
|
||||||
GstStructure *structure2);
|
GstStructure *structure2);
|
||||||
|
gboolean gst_structure_can_intersect(const GstStructure *struct1,
|
||||||
|
const GstStructure *struct2);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -964,6 +964,7 @@ EXPORTS
|
||||||
gst_stream_error_get_type
|
gst_stream_error_get_type
|
||||||
gst_stream_error_quark
|
gst_stream_error_quark
|
||||||
gst_stream_status_type_get_type
|
gst_stream_status_type_get_type
|
||||||
|
gst_structure_can_intersect
|
||||||
gst_structure_change_type_get_type
|
gst_structure_change_type_get_type
|
||||||
gst_structure_copy
|
gst_structure_copy
|
||||||
gst_structure_empty_new
|
gst_structure_empty_new
|
||||||
|
|
Loading…
Reference in a new issue