[Live-devel] Recursion in continuePlaying() -> stack overflow

Horst Weglanz weglanz12 at yahoo.com
Wed Nov 5 06:57:49 PST 2008


Hello

I've a problem building an output sink for LiveMedia in my application. I wanted to use the mpeg2ts muxer capabilities and build an output sink which transports every mpeg2ts frame back to my application.
This sink basically holds a reference to a synchronized queue and simply add every frame it gets to this queue. This works so far, but when using this sink the LiveMedia threads grabbing more and more stack memory. I've monitored the current stack usage and this always ends in a stack overflow as long as this thread is running.

This probably is a result of the recursion in here
| MySink::afterGettingFrame1()
| {
|     //[..]
|     // Then try getting the next frame:
|     continuePlaying();
| }
which I built after FileSink/HTTPSink or others. I don't understand how this couldn't work if this recursion here is every time calling continuePlaying() recursively.

I started the setup this way:
| FramedSource* ts = ...
| MySink* sink = MySink::createNew( *envir(), queue, bufferSize );
|
| // Start streaming:
| sink->startPlaying(*ts, NULL, NULL);
| envir()->taskScheduler().doEventLoop();

In this scenario startPlaying() doesn't return if the recursion above is executed. After startPlaying() it goes into continuePlaying() and then further and further since fSource always remains valid and the event loop is never reached. 

| Boolean MySink::continuePlaying() 
| {
|    if (fSource == NULL) return False;
|
|    fSource->getNextFrame(fBuffer, fBufferSize,
|            afterGettingFrame, this,
|            onSourceClosure, this);
|
|    return True;
| }

What am I doing wrong here? 

Thank you very much,
HW


      



More information about the live-devel mailing list