testProgs/playSIP.cpp File Reference

#include "playCommon.hh"
#include "SIPClient.hh"

Include dependency graph for playSIP.cpp:

Go to the source code of this file.

Functions

static char * getLine (char *startOfLine)
MediumcreateClient (UsageEnvironment &env, char const *, int verbosityLevel, char const *applicationName)
void getOptions (RTSPClient::responseHandler *afterFunc)
void getSDPDescription (RTSPClient::responseHandler *afterFunc)
void setupSubsession (MediaSubsession *subsession, Boolean, RTSPClient::responseHandler *afterFunc)
void startPlayingSession (MediaSession *, double, double, float, RTSPClient::responseHandler *afterFunc)
void startPlayingSession (MediaSession *, const char *, const char *, float, RTSPClient::responseHandler *afterFunc)
void tearDownSession (MediaSession *, RTSPClient::responseHandler *afterFunc)

Variables

SIPClientourSIPClient = NULL
Boolean allowProxyServers = True
Boolean controlConnectionUsesTCP = False
Boolean supportCodecSelection = True
char const * clientProtocolName = "SIP"


Function Documentation

Medium* createClient ( UsageEnvironment env,
char const *  ,
int  verbosityLevel,
char const *  applicationName 
)

Definition at line 38 of file playSIP.cpp.

References RTSPClient::createNew(), SIPClient::createNew(), desiredAudioRTPPayloadFormat, env, mimeSubtype, ourRTSPClient, ourSIPClient, and tunnelOverHTTPPortNum.

00038                                                                                                                   {
00039   // First, trim any directory prefixes from "applicationName":
00040   char const* suffix = &applicationName[strlen(applicationName)];
00041   while (suffix != applicationName) {
00042     if (*suffix == '/' || *suffix == '\\') {
00043       applicationName = ++suffix;
00044       break;
00045     }
00046     --suffix;
00047   }
00048 
00049   extern unsigned char desiredAudioRTPPayloadFormat;
00050   extern char* mimeSubtype;
00051   return ourSIPClient = SIPClient::createNew(env, desiredAudioRTPPayloadFormat, mimeSubtype, verbosityLevel, applicationName);
00052 }

static char* getLine ( char *  startOfLine  )  [static]

Definition at line 23 of file playSIP.cpp.

References NULL.

00023                                         {
00024   // returns the start of the next line, or NULL if none
00025   for (char* ptr = startOfLine; *ptr != '\0'; ++ptr) {
00026     if (*ptr == '\r' || *ptr == '\n') {
00027       // We found the end of the line
00028       *ptr++ = '\0';
00029       if (*ptr == '\n') ++ptr;
00030       return ptr;
00031     }
00032   }
00033   
00034   return NULL;
00035 }

void getOptions ( RTSPClient::responseHandler afterFunc  ) 

Definition at line 54 of file playSIP.cpp.

References Medium::envir(), UsageEnvironment::getResultMsg(), NULL, ourAuthenticator, ourRTSPClient, ourSIPClient, RTSPClient::sendOptionsCommand(), UsageEnvironment::setResultMsg(), and strDup().

00054                                                       { 
00055   ourSIPClient->envir().setResultMsg("NOT SUPPORTED IN CLIENT");
00056   afterFunc(NULL, -1, strDup(ourSIPClient->envir().getResultMsg()));
00057 }

void getSDPDescription ( RTSPClient::responseHandler afterFunc  ) 

Definition at line 59 of file playSIP.cpp.

References NetAddress::data(), desiredPortNum, Medium::envir(), NetAddressList::firstAddress(), SIPClient::invite(), SIPClient::inviteWithPassword(), NULL, NetAddressList::numAddresses(), ourAuthenticator, ourRTSPClient, ourSIPClient, Authenticator::password(), password, proxyServerName, proxyServerPortNum, RTSPClient::sendDescribeCommand(), SIPClient::setClientStartPortNum(), SIPClient::setProxyServer(), strDup(), streamURL, Authenticator::username(), and username.

00059                                                              {
00060   extern char* proxyServerName;
00061   if (proxyServerName != NULL) {
00062     // Tell the SIP client about the proxy:
00063     NetAddressList addresses(proxyServerName);
00064     if (addresses.numAddresses() == 0) {
00065       ourSIPClient->envir() << "Failed to find network address for \"" << proxyServerName << "\"\n";
00066     } else {
00067       NetAddress address = *(addresses.firstAddress());
00068       unsigned proxyServerAddress // later, allow for IPv6 #####
00069         = *(unsigned*)(address.data());
00070       extern unsigned short proxyServerPortNum;
00071       if (proxyServerPortNum == 0) proxyServerPortNum = 5060; // default
00072 
00073       ourSIPClient->setProxyServer(proxyServerAddress, proxyServerPortNum);
00074     }
00075   }
00076 
00077   extern unsigned short desiredPortNum;
00078   unsigned short clientStartPortNum = desiredPortNum;
00079   if (clientStartPortNum == 0) clientStartPortNum = 8000; // default
00080   ourSIPClient->setClientStartPortNum(clientStartPortNum);
00081 
00082   extern char const* streamURL;
00083   char const* username = ourAuthenticator == NULL ? NULL : ourAuthenticator->username();
00084   char const* password = ourAuthenticator == NULL ? NULL : ourAuthenticator->password();
00085   char* result;
00086   if (username != NULL && password != NULL) {
00087     result = ourSIPClient->inviteWithPassword(streamURL, username, password);
00088   } else {
00089     result = ourSIPClient->invite(streamURL);
00090   }
00091 
00092   int resultCode = result == NULL ? -1 : 0;
00093   afterFunc(NULL, resultCode, strDup(result));
00094 }

void setupSubsession ( MediaSubsession subsession,
Boolean  ,
RTSPClient::responseHandler afterFunc 
)

Definition at line 96 of file playSIP.cpp.

References MediaSubsession::connectionEndpointAddress(), MediaSubsession::connectionEndpointName(), False, SIPClient::getInviteSdpReply(), getLine(), NULL, ourAuthenticator, ourRTSPClient, ourSIPClient, MediaSubsession::rtcpChannelId, MediaSubsession::rtpChannelId, RTSPClient::sendSetupCommand(), MediaSubsession::serverPortNum, MediaSubsession::setDestinations(), MediaSubsession::setSessionId(), strDup(), strDupSize(), and subsession.

00096                                                                                                                     {
00097   subsession->setSessionId("mumble"); // anything that's non-NULL will work
00098 
00100   // Parse the "Transport:" header parameters:
00101   // We do not send audio, but we need port for RTCP
00102   char* serverAddressStr;
00103   portNumBits serverPortNum;
00104   unsigned char rtpChannelId, rtcpChannelId;
00105 
00106   rtpChannelId = rtcpChannelId = 0xff;
00107   serverPortNum = 0;
00108   serverAddressStr = NULL;
00109 
00110   char* sdp = strDup(ourSIPClient->getInviteSdpReply());
00111 
00112   char* lineStart;
00113   char* nextLineStart = sdp;
00114   while (1) {
00115     lineStart = nextLineStart;
00116     if (lineStart == NULL) {
00117       break;
00118     }
00119     nextLineStart = getLine(lineStart);
00120 
00121     char* toTagStr = strDupSize(lineStart);
00122 
00123     if (sscanf(lineStart, "m=audio %[^/\r\n]", toTagStr) == 1) {
00124       sscanf(toTagStr, "%hu", &serverPortNum);
00125     } else if (sscanf(lineStart, "c=IN IP4 %[^/\r\n]", toTagStr) == 1) {
00126       serverAddressStr = strDup(toTagStr);
00127     }
00128     delete[] toTagStr;
00129   }
00130 
00131   if(sdp != NULL) {
00132     delete[] sdp;
00133   }
00134 
00135   delete[] subsession->connectionEndpointName();
00136   subsession->connectionEndpointName() = serverAddressStr;
00137   subsession->serverPortNum = serverPortNum;
00138   subsession->rtpChannelId = rtpChannelId;
00139   subsession->rtcpChannelId = rtcpChannelId;
00140 
00141   // Set the RTP and RTCP sockets' destination address and port from the information in the SETUP response (if present):
00142   netAddressBits destAddress = subsession->connectionEndpointAddress();
00143   if (destAddress != 0) {
00144     subsession->setDestinations(destAddress);
00145   }
00147 
00148   afterFunc(NULL, 0, NULL);
00149 }

void startPlayingSession ( MediaSession ,
const char *  ,
const char *  ,
float  ,
RTSPClient::responseHandler afterFunc 
)

Definition at line 161 of file playSIP.cpp.

References NULL, ourAuthenticator, ourRTSPClient, RTSPClient::sendPlayCommand(), session, and startPlayingSession().

00161                                                                                                                                                        {
00162         startPlayingSession(NULL,(double)0,(double)0,0,afterFunc);
00163 }

void startPlayingSession ( MediaSession ,
double  ,
double  ,
float  ,
RTSPClient::responseHandler afterFunc 
)

Definition at line 151 of file playSIP.cpp.

References Medium::envir(), UsageEnvironment::getResultMsg(), NULL, ourSIPClient, SIPClient::sendACK(), and strDup().

00151                                                                                                                                              {
00152   if (ourSIPClient->sendACK()) {
00153     //##### This isn't quite right, because we should really be allowing
00154     //##### for the possibility of this ACK getting lost, by retransmitting
00155     //##### it *each time* we get a 2xx response from the server.
00156     afterFunc(NULL, 0, NULL);
00157   } else {
00158     afterFunc(NULL, -1, strDup(ourSIPClient->envir().getResultMsg()));
00159   }
00160 }

void tearDownSession ( MediaSession ,
RTSPClient::responseHandler afterFunc 
)

Definition at line 165 of file playSIP.cpp.

References Medium::envir(), UsageEnvironment::getResultMsg(), NULL, ourAuthenticator, ourRTSPClient, ourSIPClient, SIPClient::sendBYE(), RTSPClient::sendTeardownCommand(), session, and strDup().

00165                                                                                       {
00166   if (ourSIPClient == NULL || ourSIPClient->sendBYE()) {
00167     afterFunc(NULL, 0, NULL);
00168   } else {
00169     afterFunc(NULL, -1, strDup(ourSIPClient->envir().getResultMsg()));
00170   }
00171 }


Variable Documentation

Boolean allowProxyServers = True

Definition at line 173 of file playSIP.cpp.

char const* clientProtocolName = "SIP"

Definition at line 176 of file playSIP.cpp.

Boolean controlConnectionUsesTCP = False

Definition at line 174 of file playSIP.cpp.

SIPClient* ourSIPClient = NULL

Definition at line 37 of file playSIP.cpp.

Referenced by createClient(), getOptions(), getSDPDescription(), setupSubsession(), startPlayingSession(), and tearDownSession().

Boolean supportCodecSelection = True

Definition at line 175 of file playSIP.cpp.


Generated on Mon Apr 29 13:30:51 2013 for live by  doxygen 1.5.2