--- live-17.01.2007/liveMedia/ServerMediaSession.cpp	Wed Jan 17 22:44:26 2007
+++ live/liveMedia/ServerMediaSession.cpp	Fri Jan 26 20:21:17 2007
@@ -81,7 +81,7 @@
 }
 
 Boolean
-ServerMediaSession::addSubsession(ServerMediaSubsession* subsession) {
+ServerMediaSession::addSubsession(ServerMediaSubsession* subsession, unsigned trackNumber) {
   if (subsession->fParentSession != NULL) return False; // it's already used
 
   if (fSubsessionsTail == NULL) {
@@ -92,10 +92,47 @@
   fSubsessionsTail = subsession;
 
   subsession->fParentSession = this;
-  subsession->fTrackNumber = ++fSubsessionCounter;
+  subsession->fTrackNumber = trackNumber != 0 ? trackNumber : ++fSubsessionCounter;
   return True;
 }
 
+void
+ServerMediaSession::removeSubsession(ServerMediaSubsession* subsession) {
+  ServerMediaSubsession* previousSubsession = NULL;
+  ServerMediaSubsession* currentSubsession = fSubsessionsHead;
+
+  while (currentSubsession != NULL && currentSubsession != subsession) {
+	  previousSubsession = currentSubsession;
+	  currentSubsession = currentSubsession->fNext;
+  }
+  
+  if (currentSubsession == NULL) {
+	  return;
+  }
+
+  if (previousSubsession != NULL) {
+	  previousSubsession->fNext = subsession->fNext;
+  } else {
+	  fSubsessionsHead = subsession->fNext;
+  }
+
+  fSubsessionsTail = NULL;
+
+  fSubsessionCounter = 0;
+
+  currentSubsession = fSubsessionsHead;
+
+  while (currentSubsession != NULL) {
+	  fSubsessionsTail = currentSubsession;
+	  currentSubsession->fTrackNumber = ++fSubsessionCounter;
+	  currentSubsession = currentSubsession->fNext;
+  }
+
+  subsession->fNext = NULL;
+  subsession->fParentSession = NULL;
+  subsession->fTrackNumber = 0;
+}
+
 void ServerMediaSession::testScaleFactor(float& scale) {
   // First, try setting all subsessions to the desired scale.
   // If the subsessions' actual scales differ from each other, choose the
@@ -182,13 +219,22 @@
   return True;
 }
 
-char* ServerMediaSession::generateSDPDescription() {
+char* ServerMediaSession::generateSDPDescription(char const* streamName, char const* info, char const* description) {
   struct in_addr ourIPAddress;
   ourIPAddress.s_addr = ourSourceAddressForMulticast(envir());
   char* const ourIPAddressStr
     = strDup(our_inet_ntoa(ourIPAddress));
   unsigned ourIPAddressStrSize = strlen(ourIPAddressStr);
 
+  if (streamName == NULL)
+	  streamName = fStreamName;
+
+  if (info == NULL)
+	  info = fInfoSDPString;
+
+  if (description == NULL)
+	  description = fDescriptionSDPString;
+
   // For a SSM sessions, we need a "a=source-filter: incl ..." line also:
   char* sourceFilterLine;
   if (fIsSSM) {
@@ -250,13 +296,13 @@
       "%s";
     sdpLength += strlen(sdpPrefixFmt)
       + 20 + 6 + 20 + ourIPAddressStrSize
-      + strlen(fDescriptionSDPString)
-      + strlen(fInfoSDPString)
+      + strlen(description)
+      + strlen(info)
       + strlen(libNameStr) + strlen(libVersionStr)
       + strlen(sourceFilterLine)
       + strlen(rangeLine)
-      + strlen(fDescriptionSDPString)
-      + strlen(fInfoSDPString)
+      + strlen(description)
+      + strlen(info)
       + strlen(fMiscSDPLines);
     sdp = new char[sdpLength];
     if (sdp == NULL) break;
@@ -266,13 +312,13 @@
 	    fCreationTime.tv_sec, fCreationTime.tv_usec, // o= <session id>
 	    1, // o= <version> // (needs to change if params are modified)
 	    ourIPAddressStr, // o= <address>
-	    fDescriptionSDPString, // s= <description>
-	    fInfoSDPString, // i= <info>
+	    description, // s= <description>
+	    info, // i= <info>
 	    libNameStr, libVersionStr, // a=tool:
 	    sourceFilterLine, // a=source-filter: incl (if a SSM session)
 	    rangeLine, // a=range: line
-	    fDescriptionSDPString, // a=x-qt-text-nam: line
-	    fInfoSDPString, // a=x-qt-text-inf: line
+	    description, // a=x-qt-text-nam: line
+	    info, // a=x-qt-text-inf: line
 	    fMiscSDPLines); // miscellaneous session SDP lines (if any)
 
     // Then, add the (media-level) lines for each subsession:
--- live-17.01.2007/liveMedia/include/ServerMediaSession.hh	Wed Jan 17 22:44:26 2007
+++ live/liveMedia/include/ServerMediaSession.hh	Fri Jan 26 20:22:31 2007
@@ -48,12 +48,13 @@
                               char const* mediumName,
                               ServerMediaSession*& resultSession);
 
-  char* generateSDPDescription(); // based on the entire session
+  char* generateSDPDescription(char const* streamName = NULL, char const* info = NULL, char const* description = NULL); // based on the entire session
       // Note: The caller is responsible for freeing the returned string
 
   char const* streamName() const { return fStreamName; }
 
-  Boolean addSubsession(ServerMediaSubsession* subsession);
+  Boolean addSubsession(ServerMediaSubsession* subsession, unsigned trackNumber = 0);
+  void removeSubsession(ServerMediaSubsession* subsession);
 
   void testScaleFactor(float& scale); // sets "scale" to the actual supported scale
   float duration() const;

