Handle the case where the pad change mid-switch.

Original commit message from CVS:
Handle the case where the pad change mid-switch.
Handle the case where the entry poin is removed from the scheduler.
This commit is contained in:
Wim Taymans 2002-05-29 15:09:36 +00:00
parent fddb92b5e2
commit b07791a06b

View file

@ -300,13 +300,13 @@ gst_basic_scheduler_chain_wrapper (int argc, char *argv[])
} }
} while (!GST_ELEMENT_IS_COTHREAD_STOPPING (element)); } while (!GST_ELEMENT_IS_COTHREAD_STOPPING (element));
GST_FLAG_UNSET (element, GST_ELEMENT_COTHREAD_STOPPING); GST_FLAG_UNSET (element, GST_ELEMENT_COTHREAD_STOPPING);
gst_object_unref (GST_OBJECT (element));
/* this will return to cothread 0, so we need to unlock the current element */ /* this will return to cothread 0, so we need to unlock the current element */
if (element->post_run_func) if (element->post_run_func)
element->post_run_func (element); element->post_run_func (element);
GST_DEBUG_LEAVE ("(%d,'%s')", argc, name); GST_DEBUG_LEAVE ("(%d,'%s')", argc, name);
gst_object_unref (GST_OBJECT (element));
return 0; return 0;
} }
@ -381,6 +381,8 @@ gst_basic_scheduler_chainhandler_proxy (GstPad * pad, GstBuffer * buf)
GST_DEBUG (GST_CAT_DATAFLOW, "new pad in mid-switch!"); GST_DEBUG (GST_CAT_DATAFLOW, "new pad in mid-switch!");
pad = (GstPad *) GST_RPAD_PEER (peer); pad = (GstPad *) GST_RPAD_PEER (peer);
} }
parent = GST_PAD_PARENT (pad);
peer = GST_RPAD_PEER (pad);
} }
if (loop_count == 0) { if (loop_count == 0) {
@ -432,14 +434,15 @@ gst_basic_scheduler_gethandler_proxy (GstPad * pad)
GstElement *parent; GstElement *parent;
GstRealPad *peer; GstRealPad *peer;
GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
parent = GST_PAD_PARENT (pad); parent = GST_PAD_PARENT (pad);
peer = GST_RPAD_PEER (pad); peer = GST_RPAD_PEER (pad);
GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
/* FIXME this should be bounded */ /* FIXME this should be bounded */
/* we will loop switching to the peer until it's filled up the bufferpen */ /* we will loop switching to the peer until it's filled up the bufferpen */
while (GST_RPAD_BUFPEN (pad) == NULL) { while (GST_RPAD_BUFPEN (pad) == NULL) {
GST_DEBUG (GST_CAT_DATAFLOW, "switching to \"%s\": %p to fill bufpen", GST_DEBUG (GST_CAT_DATAFLOW, "switching to \"%s\": %p to fill bufpen",
GST_ELEMENT_NAME (parent), GST_ELEMENT_NAME (parent),
GST_ELEMENT_THREADSTATE (parent)); GST_ELEMENT_THREADSTATE (parent));
@ -453,6 +456,8 @@ gst_basic_scheduler_gethandler_proxy (GstPad * pad)
if (!pad) { if (!pad) {
gst_element_error (parent, "pad unconnected"); gst_element_error (parent, "pad unconnected");
} }
parent = GST_PAD_PARENT (pad);
peer = GST_RPAD_PEER (pad);
} }
} }
GST_DEBUG (GST_CAT_DATAFLOW, "done switching"); GST_DEBUG (GST_CAT_DATAFLOW, "done switching");
@ -962,6 +967,13 @@ gst_basic_scheduler_remove_element (GstScheduler * sched, GstElement * element)
GST_INFO (GST_CAT_SCHEDULING, "removing element \"%s\" from scheduler", GST_INFO (GST_CAT_SCHEDULING, "removing element \"%s\" from scheduler",
GST_ELEMENT_NAME (element)); GST_ELEMENT_NAME (element));
/* if we are removing the currently scheduled element */
if (bsched->current == element) {
GST_FLAG_SET(element, GST_ELEMENT_COTHREAD_STOPPING);
if (element->post_run_func)
element->post_run_func (element);
bsched->current = NULL;
}
/* find what chain the element is in */ /* find what chain the element is in */
chain = gst_basic_scheduler_find_chain (bsched, element); chain = gst_basic_scheduler_find_chain (bsched, element);
@ -974,7 +986,6 @@ gst_basic_scheduler_remove_element (GstScheduler * sched, GstElement * element)
/* unset the scheduler pointer in the element */ /* unset the scheduler pointer in the element */
GST_ELEMENT_SCHED (element) = NULL; GST_ELEMENT_SCHED (element) = NULL;
} }
} }
@ -1265,8 +1276,15 @@ gst_basic_scheduler_iterate (GstScheduler * sched)
entry->pre_run_func (entry); entry->pre_run_func (entry);
bsched->current = entry; bsched->current = entry;
do_cothread_switch (GST_ELEMENT_THREADSTATE (entry)); do_cothread_switch (GST_ELEMENT_THREADSTATE (entry));
/*
if (bsched->current && bsched->current->post_run_func) {
bsched->current->post_run_func (bsched->current);
}
*/
state = GST_SCHEDULER_STATE (sched); state = GST_SCHEDULER_STATE (sched);
/* if something changed, return - go on else */ /* if something changed, return - go on else */
if (GST_FLAG_IS_SET(bsched, GST_BASIC_SCHEDULER_CHANGE) && if (GST_FLAG_IS_SET(bsched, GST_BASIC_SCHEDULER_CHANGE) &&