[Mplayer-cvslog] CVS: main/libmpdemux demux_rtp.cpp,1.16,1.17

Ross Finlayson CVS rsf at mplayerhq.hu
Sat May 3 08:13:14 CEST 2003


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv14312

Modified Files:
	demux_rtp.cpp 
Log Message:
Added SIP (IP telephony) client support.  (This was already supported in the
LIVE.COM libraries, so updating the MPlayer code to support it required
only relatively minor changes.)


Index: demux_rtp.cpp
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_rtp.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- demux_rtp.cpp	12 Apr 2003 09:30:19 -0000	1.16
+++ demux_rtp.cpp	3 May 2003 06:13:11 -0000	1.17
@@ -87,6 +87,7 @@
 typedef struct RTPState {
   char const* sdpDescription;
   RTSPClient* rtspClient;
+  SIPClient* sipClient;
   MediaSession* mediaSession;
   ReadBufferQueue* audioBufferQueue;
   ReadBufferQueue* videoBufferQueue;
@@ -96,6 +97,26 @@
 
 extern "C" char* network_username;
 extern "C" char* network_password;
+static char* openURL_rtsp(RTSPClient* client, char const* url) {
+  // If we were given a user name (and optional password), then use them: 
+  if (network_username != NULL) {
+    char const* password = network_password == NULL ? "" : network_password;
+    return client->describeWithPassword(url, network_username, password);
+  } else {
+    return client->describeURL(url);
+  }
+}
+
+static char* openURL_sip(SIPClient* client, char const* url) {
+  // If we were given a user name (and optional password), then use them: 
+  if (network_username != NULL) {
+    char const* password = network_password == NULL ? "" : network_password;
+    return client->inviteWithPassword(url, network_username, password);
+  } else {
+    return client->invite(url);
+  }
+}
+
 int rtspStreamOverTCP = 0; 
 
 extern "C" void demux_open_rtp(demuxer_t* demuxer) {
@@ -106,6 +127,7 @@
     if (env == NULL) break;
 
     RTSPClient* rtspClient = NULL;
+    SIPClient* sipClient = NULL;
 
     if (demuxer == NULL || demuxer->stream == NULL) break;  // shouldn't happen
     demuxer->stream->eof = 0; // just in case 
@@ -115,26 +137,31 @@
     char* sdpDescription = (char*)(demuxer->stream->priv);
     if (sdpDescription == NULL) {
       // We weren't given a SDP description directly, so assume that
-      // we were given a RTSP URL:
+      // we were given a RTSP or SIP URL:
+      char const* protocol = demuxer->stream->streaming_ctrl->url->protocol;
       char const* url = demuxer->stream->streaming_ctrl->url->url;
-
       extern int verbose;
-      rtspClient = RTSPClient::createNew(*env, verbose, "MPlayer");
-      if (rtspClient == NULL) {
-	fprintf(stderr, "Failed to create RTSP client: %s\n",
-		env->getResultMsg());
-	break;
+      if (strcmp(protocol, "rtsp") == 0) {
+	rtspClient = RTSPClient::createNew(*env, verbose, "MPlayer");
+	if (rtspClient == NULL) {
+	  fprintf(stderr, "Failed to create RTSP client: %s\n",
+		  env->getResultMsg());
+	  break;
+	}
+	sdpDescription = openURL_rtsp(rtspClient, url);
+      } else { // SIP
+	unsigned char desiredAudioType = 0; // PCMU (use 3 for GSM)
+	sipClient = SIPClient::createNew(*env, desiredAudioType, NULL,
+					 verbose, "MPlayer");
+	if (sipClient == NULL) {
+	  fprintf(stderr, "Failed to create SIP client: %s\n",
+		  env->getResultMsg());
+	  break;
+	}
+	sipClient->setClientStartPortNum(8000);
+	sdpDescription = openURL_sip(sipClient, url);
       }
 
-      // If we were given a user name (and optional password), then use them: 
-      if (network_username != NULL) {
-	char const* password
-	  = network_password == NULL ? "" : network_password;
-	sdpDescription
-	  = rtspClient->describeWithPassword(url, network_username, password);
-      } else {
-	sdpDescription = rtspClient->describeURL(url);
-      }
       if (sdpDescription == NULL) {
 	fprintf(stderr, "Failed to get a SDP description from URL \"%s\": %s\n",
 		url, env->getResultMsg());
@@ -152,6 +179,7 @@
     RTPState* rtpState = new RTPState;
     rtpState->sdpDescription = sdpDescription;
     rtpState->rtspClient = rtspClient;
+    rtpState->sipClient = sipClient;
     rtpState->mediaSession = mediaSession;
     rtpState->audioBufferQueue = rtpState->videoBufferQueue = NULL;
     rtpState->flags = 0;
@@ -201,6 +229,8 @@
     if (rtspClient != NULL) {
       // Issue a RTSP aggregate "PLAY" command on the whole session:
       if (!rtspClient->playMediaSession(*mediaSession)) break;
+    } else if (sipClient != NULL) {
+      sipClient->sendACK(); // to start the stream flowing
     }
 
     // Now that the session is ready to be read, do additional
@@ -319,7 +349,7 @@
   return True;
 }
 
-static void teardownRTSPSession(RTPState* rtpState); // forward
+static void teardownRTSPorSIPSession(RTPState* rtpState); // forward
 
 extern "C" void demux_close_rtp(demuxer_t* demuxer) {
   // Reclaim all RTP-related state:
@@ -328,7 +358,7 @@
   RTPState* rtpState = (RTPState*)(demuxer->priv);
   if (rtpState == NULL) return;
 
-  teardownRTSPSession(rtpState);
+  teardownRTSPorSIPSession(rtpState);
 
   UsageEnvironment* env = NULL;
   TaskScheduler* scheduler = NULL;
@@ -338,6 +368,7 @@
   }
   Medium::close(rtpState->mediaSession);
   Medium::close(rtpState->rtspClient);
+  Medium::close(rtpState->sipClient);
   delete rtpState->audioBufferQueue;
   delete rtpState->videoBufferQueue;
   delete rtpState->sdpDescription;
@@ -479,16 +510,18 @@
   return dp;
 }
 
-static void teardownRTSPSession(RTPState* rtpState) {
-  RTSPClient* rtspClient = rtpState->rtspClient;
+static void teardownRTSPorSIPSession(RTPState* rtpState) {
   MediaSession* mediaSession = rtpState->mediaSession;
-  if (rtspClient == NULL || mediaSession == NULL) return;
-
-  MediaSubsessionIterator iter(*mediaSession);
-  MediaSubsession* subsession;
+  if (mediaSession == NULL) return;
+  if (rtpState->rtspClient != NULL) {
+    MediaSubsessionIterator iter(*mediaSession);
+    MediaSubsession* subsession;
 
-  while ((subsession = iter.next()) != NULL) {
-    rtspClient->teardownMediaSubsession(*subsession);
+    while ((subsession = iter.next()) != NULL) {
+      rtpState->rtspClient->teardownMediaSubsession(*subsession);
+    }
+  } else if (rtpState->sipClient != NULL) {
+    rtpState->sipClient->sendBYE();
   }
 }
 



More information about the MPlayer-cvslog mailing list