HLS comment connection deletion that make crash

pull/33/head
mpromonet 9 years ago
parent 8a593ab42f
commit 5ff2e9abb4

@ -34,14 +34,6 @@ class HLSServer : public RTSPServer
: RTSPServer::RTSPClientConnection(ourServer, clientSocket, clientAddr), fClientSessionId(0), fTCPSink(NULL) {
}
~HLSClientConnection() {
if (fTCPSink != NULL)
{
fTCPSink->stopPlaying();
Medium::close(fTCPSink);
}
}
private:
void sendHeader(const char* contentType, unsigned int contentLength)
@ -68,9 +60,11 @@ class HLSServer : public RTSPServer
{
if (fTCPSink != NULL)
{
FramedSource* oldSource = fTCPSink->source();
fTCPSink->stopPlaying();
Medium::close(fTCPSink);
fTCPSink = NULL;
Medium::close(oldSource);
}
if (source != NULL)
{
@ -79,25 +73,28 @@ class HLSServer : public RTSPServer
}
}
void sendPlayList(char const* urlSuffix)
ServerMediaSubsession* getSubsesion(const char* urlSuffix)
{
// First, make sure that the named file exists, and is streamable:
ServerMediaSubsession* subsession = NULL;
ServerMediaSession* session = fOurServer.lookupServerMediaSession(urlSuffix);
if (session == NULL) {
handleHTTPCmd_notFound();
return;
if (session != NULL)
{
ServerMediaSubsessionIterator iter(*session);
subsession = iter.next();
}
return subsession;
}
// To be able to construct a playlist for the requested file, we need to know its duration:
float duration = session->duration();
if (duration <= 0.0) {
void sendPlayList(char const* urlSuffix)
{
ServerMediaSubsession* subsession = this->getSubsesion(urlSuffix);
if (subsession == NULL) {
handleHTTPCmd_notSupported();
return;
}
ServerMediaSubsessionIterator iter(*session);
ServerMediaSubsession* subsession = iter.next();
if (subsession == NULL) {
float duration = subsession->duration();
if (duration <= 0.0) {
handleHTTPCmd_notSupported();
return;
}
@ -127,32 +124,29 @@ class HLSServer : public RTSPServer
this->streamSource(ByteStreamMemoryBufferSource::createNew(envir(), playListBuffer, playList.size()));
}
void handleHTTPCmd_StreamingGET(char const* urlSuffix, char const* /*fullRequestStr*/) {
// If "urlSuffix" ends with "?segment=<offset-in-seconds>,<duration-in-seconds>", then strip this off, and send the
// specified segment. Otherwise, construct and send a playlist that consists of segments from the specified file.
do {
void handleHTTPCmd_StreamingGET(char const* urlSuffix, char const* /*fullRequestStr*/)
{
char const* questionMarkPos = strrchr(urlSuffix, '?');
if (questionMarkPos == NULL) break;
if (questionMarkPos == NULL)
{
this->sendPlayList(urlSuffix);
}
else
{
unsigned offsetInSeconds;
if (sscanf(questionMarkPos, "?segment=%u", &offsetInSeconds) != 1) break;
if (sscanf(questionMarkPos, "?segment=%u", &offsetInSeconds) != 1)
{
handleHTTPCmd_notSupported();
return;
}
char* streamName = strDup(urlSuffix);
streamName[questionMarkPos-urlSuffix] = '\0';
do {
ServerMediaSession* session = fOurServer.lookupServerMediaSession(streamName);
if (session == NULL) {
handleHTTPCmd_notFound();
break;
}
// We can't send multi-subsession streams over HTTP (because there's no defined way to multiplex more than one subsession).
// Therefore, use the first (and presumed only) substream:
ServerMediaSubsessionIterator iter(*session);
ServerMediaSubsession* subsession = iter.next();
ServerMediaSubsession* subsession = this->getSubsesion(streamName);
if (subsession == NULL) {
// Treat an 'empty' ServerMediaSession the same as one that doesn't exist at all:
handleHTTPCmd_notFound();
handleHTTPCmd_notSupported();
break;
}
@ -182,14 +176,10 @@ class HLSServer : public RTSPServer
// stream body
this->streamSource(subsession->getStreamSource(streamToken));
} while(0);
delete[] streamName;
return;
} while (0);
this->sendPlayList(urlSuffix);
}
}
static void afterStreaming(void* clientData)
@ -201,7 +191,7 @@ class HLSServer : public RTSPServer
clientConnection->fIsActive = False; // will cause the object to get deleted at the end of handling the request
} else {
// We're no longer handling a request; delete the object now:
delete clientConnection;
// delete clientConnection;
}
}
private:

Loading…
Cancel
Save