mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-23 06:26:23 +00:00
utils: fix the proxy functions
fix the proxy functions for query_accept_caps and query_caps to use the pad forward helper functions which correctly forwards on the internally linked pads.
This commit is contained in:
parent
9b98ef4fed
commit
0796586fce
1 changed files with 46 additions and 126 deletions
172
gst/gstutils.c
172
gst/gstutils.c
|
@ -2696,19 +2696,22 @@ gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
typedef struct
|
||||||
query_accept_caps_fold_func (const GValue * vpad, GValue * ret,
|
|
||||||
GstQuery * query)
|
|
||||||
{
|
{
|
||||||
GstPad *pad = g_value_get_object (vpad);
|
GstQuery *query;
|
||||||
gboolean result = TRUE;
|
gboolean ret;
|
||||||
|
} QueryAcceptCapsData;
|
||||||
|
|
||||||
if (G_LIKELY (gst_pad_peer_query (pad, query))) {
|
static gboolean
|
||||||
gst_query_parse_accept_caps_result (query, &result);
|
query_accept_caps_func (GstPad * pad, QueryAcceptCapsData * data)
|
||||||
result &= g_value_get_boolean (ret);
|
{
|
||||||
g_value_set_boolean (ret, result);
|
if (G_LIKELY (gst_pad_peer_query (pad, data->query))) {
|
||||||
|
gboolean result;
|
||||||
|
|
||||||
|
gst_query_parse_accept_caps_result (data->query, &result);
|
||||||
|
data->ret &= result;
|
||||||
}
|
}
|
||||||
return result;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2729,9 +2732,7 @@ gboolean
|
||||||
gst_pad_proxy_query_accept_caps (GstPad * pad, GstQuery * query)
|
gst_pad_proxy_query_accept_caps (GstPad * pad, GstQuery * query)
|
||||||
{
|
{
|
||||||
GstElement *element;
|
GstElement *element;
|
||||||
GstIterator *iter;
|
QueryAcceptCapsData data;
|
||||||
GstIteratorResult res;
|
|
||||||
GValue ret = { 0, };
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
|
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
|
||||||
g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
|
g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
|
||||||
|
@ -2744,43 +2745,15 @@ gst_pad_proxy_query_accept_caps (GstPad * pad, GstQuery * query)
|
||||||
if (element == NULL)
|
if (element == NULL)
|
||||||
goto no_parent;
|
goto no_parent;
|
||||||
|
|
||||||
|
data.query = query;
|
||||||
/* value to hold the return, by default it holds TRUE */
|
/* value to hold the return, by default it holds TRUE */
|
||||||
g_value_init (&ret, G_TYPE_BOOLEAN);
|
data.ret = TRUE;
|
||||||
g_value_set_boolean (&ret, TRUE);
|
|
||||||
|
|
||||||
/* only iterate the pads in the oposite direction */
|
gst_pad_forward (pad, (GstPadForwardFunction) query_accept_caps_func, &data);
|
||||||
if (GST_PAD_IS_SRC (pad))
|
|
||||||
iter = gst_element_iterate_sink_pads (element);
|
|
||||||
else
|
|
||||||
iter = gst_element_iterate_src_pads (element);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
res =
|
|
||||||
gst_iterator_fold (iter,
|
|
||||||
(GstIteratorFoldFunction) query_accept_caps_fold_func, &ret, query);
|
|
||||||
switch (res) {
|
|
||||||
case GST_ITERATOR_RESYNC:
|
|
||||||
/* need to reset the result again to TRUE */
|
|
||||||
g_value_set_boolean (&ret, TRUE);
|
|
||||||
gst_iterator_resync (iter);
|
|
||||||
break;
|
|
||||||
case GST_ITERATOR_DONE:
|
|
||||||
/* all pads iterated, return collected value */
|
|
||||||
goto done;
|
|
||||||
case GST_ITERATOR_OK:
|
|
||||||
/* premature exit (happens if caps intersection is empty) */
|
|
||||||
goto done;
|
|
||||||
default:
|
|
||||||
/* iterator returned _ERROR, mark an error and exit */
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
done:
|
|
||||||
gst_iterator_free (iter);
|
|
||||||
gst_object_unref (element);
|
gst_object_unref (element);
|
||||||
|
|
||||||
gst_query_set_accept_caps_result (query, g_value_get_boolean (&ret));
|
gst_query_set_accept_caps_result (query, data.ret);
|
||||||
g_value_unset (&ret);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -2790,37 +2763,34 @@ no_parent:
|
||||||
GST_DEBUG_OBJECT (pad, "no parent");
|
GST_DEBUG_OBJECT (pad, "no parent");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
error:
|
|
||||||
{
|
|
||||||
g_warning ("Pad list returned error on element %s",
|
|
||||||
GST_ELEMENT_NAME (element));
|
|
||||||
gst_iterator_free (iter);
|
|
||||||
gst_object_unref (element);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
typedef struct
|
||||||
query_caps_fold_func (const GValue * vpad, GValue * ret, GstQuery * query)
|
{
|
||||||
|
GstQuery *query;
|
||||||
|
GstCaps *ret;
|
||||||
|
} QueryCapsData;
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
query_caps_func (GstPad * pad, QueryCapsData * data)
|
||||||
{
|
{
|
||||||
GstPad *pad = g_value_get_object (vpad);
|
|
||||||
gboolean empty = FALSE;
|
gboolean empty = FALSE;
|
||||||
|
|
||||||
if (G_LIKELY (gst_pad_peer_query (pad, query))) {
|
if (G_LIKELY (gst_pad_peer_query (pad, data->query))) {
|
||||||
GstCaps *existing, *peercaps, *intersection;
|
GstCaps *peercaps, *intersection;
|
||||||
|
|
||||||
existing = g_value_get_pointer (ret);
|
|
||||||
gst_query_parse_caps_result (query, &peercaps);
|
|
||||||
|
|
||||||
|
gst_query_parse_caps_result (data->query, &peercaps);
|
||||||
GST_DEBUG_OBJECT (pad, "intersect with result %" GST_PTR_FORMAT, peercaps);
|
GST_DEBUG_OBJECT (pad, "intersect with result %" GST_PTR_FORMAT, peercaps);
|
||||||
intersection = gst_caps_intersect (existing, peercaps);
|
intersection = gst_caps_intersect (data->ret, peercaps);
|
||||||
GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, intersection);
|
GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, intersection);
|
||||||
empty = gst_caps_is_empty (intersection);
|
|
||||||
|
|
||||||
g_value_set_pointer (ret, intersection);
|
gst_caps_unref (data->ret);
|
||||||
gst_caps_unref (existing);
|
data->ret = intersection;
|
||||||
|
|
||||||
|
/* stop when empty */
|
||||||
|
empty = gst_caps_is_empty (intersection);
|
||||||
}
|
}
|
||||||
return !empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2840,12 +2810,9 @@ query_caps_fold_func (const GValue * vpad, GValue * ret, GstQuery * query)
|
||||||
gboolean
|
gboolean
|
||||||
gst_pad_proxy_query_caps (GstPad * pad, GstQuery * query)
|
gst_pad_proxy_query_caps (GstPad * pad, GstQuery * query)
|
||||||
{
|
{
|
||||||
gboolean result = TRUE;
|
|
||||||
GstElement *element;
|
GstElement *element;
|
||||||
GstCaps *caps, *intersected;
|
GstCaps *intersected;
|
||||||
GstIterator *iter;
|
QueryCapsData data;
|
||||||
GstIteratorResult res;
|
|
||||||
GValue ret = { 0, };
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
|
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
|
||||||
g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
|
g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
|
||||||
|
@ -2858,64 +2825,25 @@ gst_pad_proxy_query_caps (GstPad * pad, GstQuery * query)
|
||||||
if (element == NULL)
|
if (element == NULL)
|
||||||
goto no_parent;
|
goto no_parent;
|
||||||
|
|
||||||
/* value to hold the return, by default it holds ANY, the ref is taken by
|
data.query = query;
|
||||||
* the GValue. */
|
/* value to hold the return, by default it holds ANY */
|
||||||
g_value_init (&ret, G_TYPE_POINTER);
|
data.ret = gst_caps_new_any ();
|
||||||
g_value_set_pointer (&ret, gst_caps_new_any ());
|
|
||||||
|
|
||||||
/* only iterate the pads in the oposite direction */
|
gst_pad_forward (pad, (GstPadForwardFunction) query_caps_func, &data);
|
||||||
if (GST_PAD_IS_SRC (pad))
|
|
||||||
iter = gst_element_iterate_sink_pads (element);
|
|
||||||
else
|
|
||||||
iter = gst_element_iterate_src_pads (element);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
res =
|
|
||||||
gst_iterator_fold (iter, (GstIteratorFoldFunction) query_caps_fold_func,
|
|
||||||
&ret, query);
|
|
||||||
switch (res) {
|
|
||||||
case GST_ITERATOR_RESYNC:
|
|
||||||
/* unref any value stored */
|
|
||||||
if ((caps = g_value_get_pointer (&ret)))
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
/* need to reset the result again to ANY */
|
|
||||||
g_value_set_pointer (&ret, gst_caps_new_any ());
|
|
||||||
gst_iterator_resync (iter);
|
|
||||||
break;
|
|
||||||
case GST_ITERATOR_DONE:
|
|
||||||
/* all pads iterated, return collected value */
|
|
||||||
goto done;
|
|
||||||
case GST_ITERATOR_OK:
|
|
||||||
/* premature exit (happens if caps intersection is empty) */
|
|
||||||
goto done;
|
|
||||||
default:
|
|
||||||
/* iterator returned _ERROR, mark an error and exit */
|
|
||||||
if ((caps = g_value_get_pointer (&ret)))
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
g_value_set_pointer (&ret, NULL);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
done:
|
|
||||||
gst_iterator_free (iter);
|
|
||||||
|
|
||||||
gst_object_unref (element);
|
gst_object_unref (element);
|
||||||
|
|
||||||
caps = g_value_get_pointer (&ret);
|
if (data.ret) {
|
||||||
g_value_unset (&ret);
|
|
||||||
|
|
||||||
if (caps) {
|
|
||||||
intersected =
|
intersected =
|
||||||
gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
|
gst_caps_intersect (data.ret, gst_pad_get_pad_template_caps (pad));
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (data.ret);
|
||||||
} else {
|
} else {
|
||||||
intersected = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
|
intersected = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_query_set_caps_result (query, intersected);
|
gst_query_set_caps_result (query, intersected);
|
||||||
gst_caps_unref (intersected);
|
gst_caps_unref (intersected);
|
||||||
|
|
||||||
return result;
|
return TRUE;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
no_parent:
|
no_parent:
|
||||||
|
@ -2923,14 +2851,6 @@ no_parent:
|
||||||
GST_DEBUG_OBJECT (pad, "no parent");
|
GST_DEBUG_OBJECT (pad, "no parent");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
error:
|
|
||||||
{
|
|
||||||
g_warning ("Pad list returned error on element %s",
|
|
||||||
GST_ELEMENT_NAME (element));
|
|
||||||
gst_iterator_free (iter);
|
|
||||||
gst_object_unref (element);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue