[Live-devel] Properly shutting down stream after TEARDOWN

Erlandsson, Claes P (CERLANDS) CERLANDS at arinc.com
Wed Oct 10 13:44:45 PDT 2012


Lately I've seen some random exceptions when streams are being shut down. I
believe these were introduced when I changed the code so it waits for a
TEARDOWN response. This was btw done as Cisco mentioned their server
requires that.

I'm probably doing something wrong, as it appears the error happens in, or
are related to, the TEARDOWN response handler.

With the shutdownStream() function in testRTSPClient as a model I basically
added a response handler to the sendTeardownCommand() and added an
additional cleanup function that should take care of the final cleanup and
properly close the rtspClient.

- Can't I assume the rtspClient is valid after TEARDOWN?

- If not, how should I then properly execute Medium::close(rtspClient)?

- In cleanUpStream() I delete all event triggers. This needs to be done,
right, or is it somehow that's taken care of automatically?

 

The exception has never occurred while stepping through the code, but the
exception appears to occur right after sendTeardownCommand() has been
called.

Sample code below. Is that the proper way to clean up?

 

void continueAfterTEARDOWN(RTSPClient* rtspClient, int resultCode, char*
resultString)

{

     if (resultCode != 0)

     {

           UsageEnvironment& env = rtspClient->envir();

          env << *rtspClient << "TEARDOWN result code: " << resultCode <<
".\n";

     }

 

     cleanUpStream(rtspClient);

}

 

void shutdownStream(RTSPClient* rtspClient, int exitCode)

{

     UsageEnvironment& env = rtspClient->envir();

     StreamClientState& scs = ((OurRTSPClient*)rtspClient)->scs; 

 

     // First, check whether any subsessions have still to be closed:

     if (scs.session != NULL)

     { 

           Boolean someSubsessionsWereActive = False;

           MediaSubsessionIterator iter(*scs.session);

           MediaSubsession* subsession;

 

           while ((subsession = iter.next()) != NULL)

           {

                if (subsession->sink != NULL)

                {

                     Medium::close(subsession->sink);

                     subsession->sink = NULL;

 

                     if (subsession->rtcpInstance() != NULL)

                     {

                           // in case the server sends a RTCP "BYE" while
handling "TEARDOWN"

                           subsession->rtcpInstance()->setByeHandler(NULL,
NULL);

                     }

 

                     someSubsessionsWereActive = True;

                }

           }

 

           if (someSubsessionsWereActive)

           {

                // Send a RTSP "TEARDOWN" command, to tell the server to
shutdown the stream.

                // We now want to handle the response.

                rtspClient->sendTeardownCommand(*scs.session,
continueAfterTEARDOWN);

           }

           else

           {

                cleanUpStream(rtspClient);

           }

     }

     else

     {

           cleanUpStream(rtspClient);

     }

}

 

// Aka shutdownStream part 2. We do the final cleanup in a separate function
as we

// want to wait until we receive the TEARDOWN response.

void cleanUpStream(RTSPClient* rtspClient)

{

     UsageEnvironment& env = rtspClient->envir();

 

 
env.taskScheduler().deleteEventTrigger(((OurRTSPClient*)rtspClient)->myStart
StreamEvent);

 
env.taskScheduler().deleteEventTrigger(((OurRTSPClient*)rtspClient)->myStopS
treamEvent);

 
env.taskScheduler().deleteEventTrigger(((OurRTSPClient*)rtspClient)->mySeekA
bsoluteEvent);

 

     env << *rtspClient << "Closing the stream.\n";

     Medium::close(rtspClient);

     // Note that this will also cause this stream's "StreamClientState"
structure to get reclaimed.

}

 

 

/Claes

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20121010/5527a3d6/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5740 bytes
Desc: not available
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20121010/5527a3d6/attachment-0001.bin>


More information about the live-devel mailing list