GitLab will be down for maintenance this Sunday 13th June, from approx 7-11am UTC. This is for a PostgreSQL migration. See the tracker issue for more informations.

Commit 8b23eed2 authored by Wim Taymans's avatar Wim Taymans
Browse files

gst/gstelement.c: Better pad activation code: Reset the collect value too on resync.

Original commit message from CVS:
* gst/gstelement.c: (activate_pads),
(iterator_activate_fold_with_resync), (gst_element_pads_activate):
Better pad activation code: Reset the collect value too on resync.
Add some comments.
parent 9d81fe82
2006-07-09 Wim Taymans <wim@fluendo.com>
* gst/gstelement.c: (activate_pads),
(iterator_activate_fold_with_resync), (gst_element_pads_activate):
Better pad activation code: Reset the collect value too on resync.
Add some comments.
2006-07-09 Wim Taymans <wim@fluendo.com> 2006-07-09 Wim Taymans <wim@fluendo.com>
   
* gst/gstpad.c: (gst_pad_init), (gst_pad_activate_pull), * gst/gstpad.c: (gst_pad_init), (gst_pad_activate_pull),
......
...@@ -2252,8 +2252,10 @@ invalid_return: ...@@ -2252,8 +2252,10 @@ invalid_return:
} }
} }
/* gst_iterator_fold functions for pads_activate */ /* gst_iterator_fold functions for pads_activate
* Note how we don't stop the iterator when we fail an activation. This is
* probably a FIXME since when one pad activation fails, we don't want to
* continue our state change. */
static gboolean static gboolean
activate_pads (GstPad * pad, GValue * ret, gboolean * active) activate_pads (GstPad * pad, GValue * ret, gboolean * active)
{ {
...@@ -2262,67 +2264,70 @@ activate_pads (GstPad * pad, GValue * ret, gboolean * active) ...@@ -2262,67 +2264,70 @@ activate_pads (GstPad * pad, GValue * ret, gboolean * active)
else if (!*active) else if (!*active)
gst_pad_set_caps (pad, NULL); gst_pad_set_caps (pad, NULL);
/* unref the object that was reffed for us by _fold */
gst_object_unref (pad); gst_object_unref (pad);
return TRUE; return TRUE;
} }
/* returns false on error or early cutout of the fold, true otherwise */ /* returns false on error or early cutout (will never happen because the fold
* function always returns TRUE, see FIXME above) of the fold, true if all
* pads in @iter were (de)activated successfully. */
static gboolean static gboolean
iterator_fold_with_resync (GstIterator * iter, GstIteratorFoldFunction func, iterator_activate_fold_with_resync (GstIterator * iter, gpointer user_data)
GValue * ret, gpointer user_data)
{ {
GstIteratorResult ires; GstIteratorResult ires;
gboolean res = TRUE; GValue ret = { 0 };
while (1) { /* no need to unset this later, it's just a boolean */
ires = gst_iterator_fold (iter, func, ret, user_data); g_value_init (&ret, G_TYPE_BOOLEAN);
g_value_set_boolean (&ret, TRUE);
while (1) {
ires = gst_iterator_fold (iter, (GstIteratorFoldFunction) activate_pads,
&ret, user_data);
switch (ires) { switch (ires) {
case GST_ITERATOR_RESYNC: case GST_ITERATOR_RESYNC:
/* need to reset the result again */
g_value_set_boolean (&ret, TRUE);
gst_iterator_resync (iter); gst_iterator_resync (iter);
break; break;
case GST_ITERATOR_DONE: case GST_ITERATOR_DONE:
res = TRUE; /* all pads iterated, return collected value */
goto done; goto done;
default: default:
res = FALSE; /* iterator returned _ERROR or premature end with _OK,
* mark an error and exit */
g_value_set_boolean (&ret, FALSE);
goto done; goto done;
} }
} }
done: done:
return res; /* return collected value */
return g_value_get_boolean (&ret);
} }
/* is called with STATE_LOCK /* is called with STATE_LOCK
*
* Pads are activated from source pads to sinkpads.
*/ */
static gboolean static gboolean
gst_element_pads_activate (GstElement * element, gboolean active) gst_element_pads_activate (GstElement * element, gboolean active)
{ {
GValue ret = { 0, };
GstIterator *iter; GstIterator *iter;
gboolean fold_ok; gboolean res;
GST_DEBUG_OBJECT (element, "pads_activate with active %d", active); GST_DEBUG_OBJECT (element, "pads_activate with active %d", active);
/* no need to unset this later, it's just a boolean */
g_value_init (&ret, G_TYPE_BOOLEAN);
g_value_set_boolean (&ret, TRUE);
iter = gst_element_iterate_src_pads (element); iter = gst_element_iterate_src_pads (element);
res = iterator_activate_fold_with_resync (iter, &active);
fold_ok = iterator_fold_with_resync
(iter, (GstIteratorFoldFunction) activate_pads, &ret, &active);
gst_iterator_free (iter); gst_iterator_free (iter);
if (G_UNLIKELY (!fold_ok || !g_value_get_boolean (&ret))) if (G_UNLIKELY (!res))
goto src_failed; goto src_failed;
iter = gst_element_iterate_sink_pads (element); iter = gst_element_iterate_sink_pads (element);
res = iterator_activate_fold_with_resync (iter, &active);
fold_ok = iterator_fold_with_resync
(iter, (GstIteratorFoldFunction) activate_pads, &ret, &active);
gst_iterator_free (iter); gst_iterator_free (iter);
if (G_UNLIKELY (!fold_ok || !g_value_get_boolean (&ret))) if (G_UNLIKELY (!res))
goto sink_failed; goto sink_failed;
GST_DEBUG_OBJECT (element, "pads_activate successful"); GST_DEBUG_OBJECT (element, "pads_activate successful");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment