mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 10:41:04 +00:00
caps: split callback for structure intersect into two functions
We call this separately. there is no much benefit in reusing the callback. Splitting is let us remove a branch also.
This commit is contained in:
parent
f5314ecae1
commit
baaf7e5319
1 changed files with 20 additions and 8 deletions
|
@ -1109,21 +1109,20 @@ typedef struct
|
||||||
{
|
{
|
||||||
GstStructure *dest;
|
GstStructure *dest;
|
||||||
const GstStructure *intersect;
|
const GstStructure *intersect;
|
||||||
gboolean first_run;
|
|
||||||
}
|
}
|
||||||
IntersectData;
|
IntersectData;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_caps_structure_intersect_field (GQuark id, const GValue * val1,
|
gst_caps_structure_intersect_field1 (GQuark id, const GValue * val1,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
IntersectData *idata = (IntersectData *) data;
|
IntersectData *idata = (IntersectData *) data;
|
||||||
GValue dest_value = { 0 };
|
|
||||||
const GValue *val2 = gst_structure_id_get_value (idata->intersect, id);
|
const GValue *val2 = gst_structure_id_get_value (idata->intersect, id);
|
||||||
|
|
||||||
if (G_UNLIKELY (val2 == NULL)) {
|
if (G_UNLIKELY (val2 == NULL)) {
|
||||||
gst_structure_id_set_value (idata->dest, id, val1);
|
gst_structure_id_set_value (idata->dest, id, val1);
|
||||||
} else if (idata->first_run) {
|
} else {
|
||||||
|
GValue dest_value = { 0 };
|
||||||
if (gst_value_intersect (&dest_value, val1, val2)) {
|
if (gst_value_intersect (&dest_value, val1, val2)) {
|
||||||
gst_structure_id_set_value (idata->dest, id, &dest_value);
|
gst_structure_id_set_value (idata->dest, id, &dest_value);
|
||||||
g_value_unset (&dest_value);
|
g_value_unset (&dest_value);
|
||||||
|
@ -1131,7 +1130,19 @@ gst_caps_structure_intersect_field (GQuark id, const GValue * val1,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_caps_structure_intersect_field2 (GQuark id, const GValue * val1,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
IntersectData *idata = (IntersectData *) data;
|
||||||
|
const GValue *val2 = gst_structure_id_get_value (idata->intersect, id);
|
||||||
|
|
||||||
|
if (G_UNLIKELY (val2 == NULL)) {
|
||||||
|
gst_structure_id_set_value (idata->dest, id, val1);
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1147,17 +1158,18 @@ gst_caps_structure_intersect (const GstStructure * struct1,
|
||||||
if (G_UNLIKELY (struct1->name != struct2->name))
|
if (G_UNLIKELY (struct1->name != struct2->name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
/* copy fields from struct1 which we have not in struct2 to target
|
||||||
|
* intersect if we have the field in both */
|
||||||
data.dest = gst_structure_id_empty_new (struct1->name);
|
data.dest = gst_structure_id_empty_new (struct1->name);
|
||||||
data.intersect = struct2;
|
data.intersect = struct2;
|
||||||
data.first_run = TRUE;
|
|
||||||
if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct1,
|
if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct1,
|
||||||
gst_caps_structure_intersect_field, &data)))
|
gst_caps_structure_intersect_field1, &data)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
/* copy fields from struct2 which we have not in struct1 to target */
|
||||||
data.intersect = struct1;
|
data.intersect = struct1;
|
||||||
data.first_run = FALSE;
|
|
||||||
if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct2,
|
if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct2,
|
||||||
gst_caps_structure_intersect_field, &data)))
|
gst_caps_structure_intersect_field2, &data)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return data.dest;
|
return data.dest;
|
||||||
|
|
Loading…
Reference in a new issue