I've encountered the following situation when using reuseFirstSource=True doing on-demand streaming: if the stream source ends and calls handleClosure(this), the streamState reference count is decremented to 0 BEFORE OnDemandServerMediaSubsession::deleteStream() is called. So deleteStream() doesn't delete the streamState because the reference count is not > 0 and nothing else deletes it either. This causes the first time a client reconnects after a source ends to fail because the server is trying to use a non-existent source. The second attempt works fine because the failed try increments the reference count and then allows deleteStream to delete the streamState properly.
<br><br>The fix I've written for this is to change lines 303 and 304 in OnDemandServerMediaSubsession.cpp to:<br> if (streamState != NULL && streamState ->referenceCount() >= 0) {<br> if (0 < streamState->referenceCount()) --streamState->referenceCount();
<br><br>I'm not sure if this is the best way to fix this, but it's working for me. This situation occurs for me when using a source class that I have implemented whose media source (an encoder) sometimes needs to restart, causing the source class to signal end-of-stream using handleClosure(this). It also occurs in testOnDemandRTSPServer when reuseFirstSource is set to "True".
<br><br>Scott<br>