<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Hello,<BR>
<BR>
I am using the RTSP server functionality of the LiveMedia library, and I might have resolved a client session management issue. The senario is when a ServerMediaSubsession is shared [reuseFirstSource=True] and clients choose RTP-over-TCP for streaming mode, only the last requested RTP-over-TCP RTSPClientSession can be torn down. All of the objects under the ServerMediaSession will be runaways. The MediaSink keeps playing, and the RTPInstance writes with socket error. The stderr shows socket write attempts after all of the RTSP clients are closed.<BR>
<BR>
I am trying to limit the scope of the impacted code, and there seems to be two area in the RTPInstance.cpp that are contributing to the problem. #1, The RTPInterface::setServerRequestAlternativeByteHandler() function is overwriting the handler and clientData of an already assigned SocketDescriptor object. It makes all existing socket descriptor of the server media subsession to map to the latest RTSPClientSession instance. #2, When RTCPInstance::addStreamSocket() function adds a new stream channel, the RTPInterface::stopNetworkReading() function calls deregisterSocket() and wipes out the existing SocketDescriptor to RTSPClientSession mapping. Therefore, only the last newly added SocketDescriptor has a valid fServerRequestAlternativeByteHandler to notify of RTSP TEARDOWN command.<BR>
<BR>
I have not updated myself to the latest, but I am only working on an older version of the LiveMedia library from March 16, 2010. I think my proposed fix should not have any conflict with the latest code base. The changes are as the following:<BR>
<BR>
1a) Test before overwriting an assigned handler.<BR>
void RTPInterface::setServerRequestAlternativeByteHandler(ServerRequestAlternativeByteHandler* handler, void* clientData) {<BR> for (tcpStreamRecord* streams = fTCPStreams; streams != NULL;<BR> streams = streams->fNext) {<BR> // Get (or create, if necessary) a socket descriptor for "streams->fStreamSocketNum":<BR> SocketDescriptor* socketDescriptor = lookupSocketDescriptor(envir(), streams->fStreamSocketNum);<BR>
if (! socketDescriptor->hasServerRequestAlternativeByteHandler()) {<BR> // Assign a handler & clientData only when there has not been one to avoid mixing up the TCP socket with the intended RTSPClientSession object from RTSPClientSession::handleCmd_PLAY().<BR> socketDescriptor->setServerRequestAlternativeByteHandler(handler, clientData);<BR> }<BR> }<BR>}<BR><BR>
1b) Add a new public method to determine if a handler has been already installed.<BR>
Boolean SocketDescriptor::hasServerRequestAlternativeByteHandler() const {<BR> return NULL != fServerRequestAlternativeByteHandler;<BR> }<BR><BR>
2a) Preserve the mapping of handler of existing TCP client.<BR>
void RTPInterface::stopNetworkReading() {<BR> // Normal case<BR> envir().taskScheduler().turnOffBackgroundReadHandling(fGS->socketNum());<BR>
// Also turn off read handling on each of our TCP connections:<BR> for (tcpStreamRecord* streams = fTCPStreams; streams != NULL;<BR> streams = streams->fNext) {<BR> // Do not deregister because the RTP interface will lose the handler and clientData inside the SocketDescriptor.<BR> // Instead simply stop reading of the socket by turning off the read handler.<BR> envir().taskScheduler().turnOffBackgroundReadHandling(streams->fStreamSocketNum);<BR> }<BR>}<BR><BR>
2b) Register new TCP client or renew the socket handler of an existing TCP client.<BR>
void RTPInterface<BR>::startNetworkReading(TaskScheduler::BackgroundHandlerProc* handlerProc) {<BR> // Normal case: Arrange to read UDP packets:<BR> envir().taskScheduler().<BR> turnOnBackgroundReadHandling(fGS->socketNum(), handlerProc, fOwner);<BR>
// Also, receive RTP over TCP, on each of our TCP connections:<BR> fReadHandlerProc = handlerProc;<BR> for (tcpStreamRecord* streams = fTCPStreams; streams != NULL;<BR> streams = streams->fNext) {<BR> // Get a socket descriptor for "streams->fStreamSocketNum":<BR> SocketDescriptor* socketDescriptor = lookupSocketDescriptor(envir(), streams->fStreamSocketNum);<BR>
// Restart a previously stopped stock read handler or start a new one<BR> if (NULL != socketDescriptor->lookupRTPInterface(streams->fStreamChannelId)) {<BR> socketDescriptor->reregisterRTPInterface();<BR> } else {<BR> // Tell it about our subChannel:<BR> socketDescriptor->registerRTPInterface(streams->fStreamChannelId, this);<BR> }<BR> }<BR>}<BR><BR>
Cheers,<BR>
John<BR>
<BR>                                            </body>
</html>