gst/gstelement.c: Slicker pad activation code.

Original commit message from CVS:
* gst/gstelement.c: (gst_element_init),
(gst_element_pads_activate), (gst_element_change_state):
Slicker pad activation code.
This commit is contained in:
Wim Taymans 2005-05-30 15:53:04 +00:00
parent e1b5b74857
commit 8d0a4e1d4f
2 changed files with 50 additions and 52 deletions

View file

@ -1,3 +1,9 @@
2005-05-30 Wim Taymans <wim@fluendo.com>
* gst/gstelement.c: (gst_element_init),
(gst_element_pads_activate), (gst_element_change_state):
Slicker pad activation code.
2005-05-30 Wim Taymans <wim@fluendo.com> 2005-05-30 Wim Taymans <wim@fluendo.com>
* gst/Makefile.am: * gst/Makefile.am:

View file

@ -206,16 +206,6 @@ gst_element_init (GstElement * element)
{ {
element->current_state = GST_STATE_NULL; element->current_state = GST_STATE_NULL;
element->pending_state = GST_STATE_VOID_PENDING; element->pending_state = GST_STATE_VOID_PENDING;
element->numpads = 0;
element->numsrcpads = 0;
element->numsinkpads = 0;
element->pads_cookie = 0;
element->pads = NULL;
element->srcpads = NULL;
element->sinkpads = NULL;
element->manager = NULL;
element->clock = NULL;
element->sched_private = NULL;
element->state_lock = g_mutex_new (); element->state_lock = g_mutex_new ();
element->state_cond = g_cond_new (); element->state_cond = g_cond_new ();
} }
@ -1847,14 +1837,16 @@ restart:
gboolean pad_loop, pad_get; gboolean pad_loop, pad_get;
gboolean done = FALSE; gboolean done = FALSE;
if (active) {
pad_get = GST_RPAD_IS_SINK (pad) && gst_pad_check_pull_range (pad);
/* see if the pad has a loop function and grab /* see if the pad has a loop function and grab
* the peer */ * the peer */
pad_get = gst_pad_check_pull_range (pad);
GST_LOCK (pad); GST_LOCK (pad);
pad_loop = GST_RPAD_LOOPFUNC (pad) != NULL; pad_loop = GST_RPAD_LOOPFUNC (pad) != NULL;
peer = GST_RPAD_PEER (pad); peer = GST_RPAD_PEER (pad);
if (peer) if (peer)
gst_object_ref (GST_OBJECT (peer)); gst_object_ref (GST_OBJECT_CAST (peer));
GST_UNLOCK (pad); GST_UNLOCK (pad);
GST_DEBUG ("pad %s:%s: get: %d, loop: %d", GST_DEBUG ("pad %s:%s: get: %d, loop: %d",
@ -1862,10 +1854,10 @@ restart:
if (peer) { if (peer) {
gboolean peer_loop, peer_get; gboolean peer_loop, peer_get;
GstActivateMode mode;
/* see if the peer has a getrange function */ /* see if the peer has a getrange function */
peer_get = gst_pad_check_pull_range (GST_PAD_CAST (peer)); peer_get = GST_RPAD_IS_SINK (peer)
&& gst_pad_check_pull_range (GST_PAD_CAST (peer));
/* see if the peer has a loop function */ /* see if the peer has a loop function */
peer_loop = GST_RPAD_LOOPFUNC (peer) != NULL; peer_loop = GST_RPAD_LOOPFUNC (peer) != NULL;
@ -1875,30 +1867,31 @@ restart:
/* If the pad is a sink with loop and the peer has a get function, /* If the pad is a sink with loop and the peer has a get function,
* we can activate the sinkpad, FIXME, logic is reversed as * we can activate the sinkpad, FIXME, logic is reversed as
* check_pull_range() checks the peer of the given pad. */ * check_pull_range() checks the peer of the given pad. */
if ((GST_PAD_IS_SINK (pad) && pad_get && pad_loop) || if ((pad_get && pad_loop) || (peer_get && peer_loop)) {
(GST_PAD_IS_SRC (pad) && peer_get && peer_loop)) {
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
"%sactivating pad %s pull mode", (active ? "" : "(de)"), "activating pad %s in pull mode", GST_OBJECT_NAME (pad));
GST_OBJECT_NAME (pad));
/* only one of pad_random and peer_random can be true */ result &= gst_pad_set_active (pad, GST_ACTIVATE_PULL);
mode = GST_ACTIVATE_PULL;
result &= gst_pad_set_active (pad, active ? mode : GST_ACTIVATE_NONE);
done = TRUE; done = TRUE;
} }
gst_object_unref (GST_OBJECT (peer)); gst_object_unref (GST_OBJECT_CAST (peer));
} }
if (!done) { if (!done) {
/* all other conditions are just push based pads */ /* all other conditions are just push based pads */
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
"%sactivating pad %s push mode", (active ? "" : "(de)"), "activating pad %s in push mode", GST_OBJECT_NAME (pad));
GST_OBJECT_NAME (pad));
result &= gst_pad_set_active (pad, result &= gst_pad_set_active (pad, GST_ACTIVATE_PUSH);
(active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE)); }
} else {
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
"deactivating pad %s", GST_OBJECT_NAME (pad));
result &= gst_pad_set_active (pad, GST_ACTIVATE_NONE);
} }
} }
gst_object_unref (GST_OBJECT (pad)); gst_object_unref (GST_OBJECT_CAST (pad));
GST_LOCK (element); GST_LOCK (element);
if (cookie != element->pads_cookie) if (cookie != element->pads_cookie)
@ -1965,7 +1958,6 @@ gst_element_change_state (GstElement * element)
element->base_time = 0; element->base_time = 0;
} }
break; break;
break;
default: default:
/* this will catch real but unhandled state changes; /* this will catch real but unhandled state changes;
* can only be caused by: * can only be caused by: