Closed 22145 - gstelement.c: support hotswapping of loopfunc

Original commit message from CVS:
Closed 22145 - gstelement.c: support hotswapping of loopfunc

Added a flag GST_ELEMENT_NEW_LOOPFUNC that's set when a new loopfunc is set,
which needs to be obeyed by the loopfuncs themselves.  The assumption is
that only a loopfunc or an element that knows what it's doing will ever
change the loopfunc pointer, so they can be responsible for exitting
the loopfunc itself appropriately.

The loopfunc_wrapper function has been changed to call the loopfunc
pointer itself in a loop.  If the loopfunc changes, the current loop is
supposed to exit, which causes the loopfunc_wrapper to start up the new
loopfunc.
This commit is contained in:
Erik Walthinsen 2000-11-23 21:49:09 +00:00
parent c758337d5a
commit 9120d1bd43
2 changed files with 18 additions and 3 deletions

View file

@ -758,7 +758,14 @@ int
gst_element_loopfunc_wrapper (int argc, char **argv)
{
GstElement *element = GST_ELEMENT (argv);
element->loopfunc (element);
while (1) {
/* if NEW_LOOPFUNC is set, clear it, we're implicitly updating */
if (GST_FLAG_IS_SET(element,GST_ELEMENT_NEW_LOOPFUNC))
GST_FLAG_UNSET(element,GST_ELEMENT_NEW_LOOPFUNC);
/* start up the loop function */
element->loopfunc (element);
}
return 0;
}
@ -770,16 +777,22 @@ gst_element_loopfunc_wrapper (int argc, char **argv)
* This sets the loop function for the element. The function pointed to
* can deviate from the GstElementLoopFunction definition in type of
* pointer only.
*
* NOTE: in order for this to take effect, the current loop function *must*
* exit. Assuming the loop function itself is the only one who will cause
* a new loopfunc to be assigned, this should be no problem.
*/
void
gst_element_set_loop_function(GstElement *element,
GstElementLoopFunction loop)
{
/* set the loop function */
element->loopfunc = loop;
/* set the NEW_LOOPFUNC flag so everyone knows to go try again */
GST_FLAG_SET(element,GST_ELEMENT_NEW_LOOPFUNC);
/* if there's a threadstate, reset the function pointer */
/* FIXME: need to figure out how to make the loop functions exit when there's
* a new one, so we can hotswap them. */
if (element->threadstate != NULL)
// note that this casts a GstElement * to a char **. Ick.
cothread_setfunc (element->threadstate, gst_element_loopfunc_wrapper,

View file

@ -79,6 +79,8 @@ typedef enum {
GST_ELEMENT_MULTI_IN = (1 << 4),
GST_ELEMENT_THREAD_SUGGESTED = (1 << 5),
GST_ELEMENT_NO_SEEK = (1 << 6),
GST_ELEMENT_NEW_LOOPFUNC = (1 << 16),
} GstElementFlags;
#define GST_ELEMENT_IS_MULTI_IN(obj) (GST_FLAGS(obj) & GST_ELEMENT_MULTI_IN)