[Live-devel] RTSP blocked

Luca Zappella luca at filibusta.crema.unimi.it
Fri Feb 11 17:37:19 PST 2005


Hi Ross,
I'm facing with another problem during the streaming of live camera.

The problem is that when the machine where I do the encoding end the
streaming is overloaded (cpu at 99%) something gets wrong: the encoder
still be alive and still sending frames to the rtsp but the rtsp never
calls again doGetNextFrame and the strem on the remote machine is
blocked.


Here the most important code:

void M4VSource::takeFrame(const unsigned char* buf, const unsigned
size) 
{
    //Gain the lock, if locked wait untill is unlocked
    boost::recursive_try_mutex::scoped_lock lock(dataMutex);
    
    //Copy from buf into myfTo
    actual_size = size;
    frame_time = time;
    memcpy(myfTo, buf, size);

    //New frame avaiable        
    newframe=true;

    if (framerequired)
    {
	deliverFrame();
	//Request satisfyed
	framerequired = false;
	//Frame sended, no new frame now
	newframe=false;
    }
}
Takeframe is invoked by my application which has a pointer to this
function.

void M4VSource::doGetNextFrame() 
{
    try
    {
        //Gain the lock, if locked trows the exception
        boost::recursive_try_mutex::scoped_try_lock lock(dataMutex);

        if (newframe)
        {
            //Unlocked and New frame avaiable
            deliverFrame();     
            //Request satisfyed
   	    framerequired = false;
            //Frame consumed
            newframe=false;
        }
        else
        {
	    framerequired = true;
        }

    catch(boost::lock_error&)
    {
        //locked, return without waiting            
        return;
    }
}

void M4VSource::deliverFrame() 
{
    if (!isCurrentlyAwaitingData()) return;     

    if (actual_size > fMaxSize) 
    {
        fNumTruncatedBytes = actual_size - fMaxSize;
        fFrameSize = fMaxSize;
    }
    else
    {
        fNumTruncatedBytes = 0;
        fFrameSize = actual_size;
    }

    fPresentationTime = frame_time;
    fDurationInMicroseconds = (1.0 / fps) * 1000000;

    //Copy frame from encoded buffer 
    memcpy(fTo, myfTo, fFrameSize);

    // After delivering the data, switch to another task, and inform
    // the reader that he has data:
    nextTask()
	= envir().taskScheduler().scheduleDelayedTask(0,
(TaskFunc*)afterGetting,this);
}

Usually the encoder calls the take frame and exit end the rtsp call the
doGetNextFrame and if finds a new frame calls the deliverFrame. If no
new frame is available he sets requiredframe to true and the next time
the encoder calls the takeframe he can see the requiredframe flag set
and directly calls deliverframe.
All this works until the machine has not a big job to do, when this
happen I can see by the output messages that everything is working (and
the connection is up and running) but not the rtsp that seems to be
blocked in somewhere (no one is calling doGetNextFrame so the frames are
not sent).... could you imagine where and why?

Another question: could be useful compute the attended
fDurationInMicroseconds based on the recent history intead of using the
formal fps? 

Thanks so much!
Luca




More information about the live-devel mailing list