[Live-devel] Removing sessions from RTSP Server
Greg Bothe
greg1 at netrats.cc
Thu Jul 1 16:58:56 PDT 2004
I ran into a small difficulty when managing a RTSP server. For my
application, sessions come and go dynamically; the RTSP server does not send
out a constant set of audio streams. The RTSPServer class has a
addServerMediaSession() method but no corresponding removeServerMediaSession()
method. I suppose on most applications this isn't a problem, as all media
sessions will get removed when RTSPServer destructs. However, for
applications such as mine, I need to tear down sessions throughout the
lifetime of the application. I may be going about this wrong, but I believe I
have solved my problem by adding the following method to RTSPServer:
Boolean RTSPServer
::removeServerMediaSession(ServerMediaSession* serverMediaSession) {
char const* sessionName = serverMediaSession->streamName();
if (sessionName == NULL) sessionName = "";
ServerMediaSession* existingSession
= (ServerMediaSession*)
(fServerMediaSessions->Lookup(sessionName));
if(existingSession != NULL) {
// Session is found, so remove it
fServerMediaSessions->Remove(sessionName);
delete existingSession;
return True;
}
else {
return False;
}
}
In doing this change, I also believe I found a bug. In HashTable.cpp, I had
to change the RemoveNext method from:
void* HashTable::RemoveNext() {
Iterator* iter = Iterator::create(*this);
char const* key;
void* removedValue = iter->next(key);
Remove(key);
return removedValue;
}
to
void* HashTable::RemoveNext() {
Iterator* iter = Iterator::create(*this);
char const* key;
void* removedValue = iter->next(key);
if (removedValue != 0) {
Remove(key);
}
return removedValue;
}
The code doesn't check to see if the next key actually exists before it tries
to remove the key. Thus, Remove() gets passed a random memory address
(because key isn't initialized to NULL) and the program crashes.
I've been using the LiveMedia code now for a couple months. It's been a GREAT
help. For the record, I have the LiveMedia code compiled on Windows as a DLL
under Visual Studio 2003 so that I can dynamically link to it. This took a
little bit of doing and it would be WONDERFUL if the standard LiveMedia
distribution supported DLL creation. (If it does already, then I must have
way missed something.) I wish I was developing under UNIX, but unfortunately,
I'm stuck on Windows for this project.
Greg Bothe
More information about the live-devel
mailing list