00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "playCommon.hh"
00021 #include "SIPClient.hh"
00022
00023 static char* getLine(char* startOfLine) {
00024
00025 for (char* ptr = startOfLine; *ptr != '\0'; ++ptr) {
00026 if (*ptr == '\r' || *ptr == '\n') {
00027
00028 *ptr++ = '\0';
00029 if (*ptr == '\n') ++ptr;
00030 return ptr;
00031 }
00032 }
00033
00034 return NULL;
00035 }
00036
00037 SIPClient* ourSIPClient = NULL;
00038 Medium* createClient(UsageEnvironment& env, char const* , int verbosityLevel, char const* applicationName) {
00039
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 }
00053
00054 void getOptions(RTSPClient::responseHandler* afterFunc) {
00055 ourSIPClient->envir().setResultMsg("NOT SUPPORTED IN CLIENT");
00056 afterFunc(NULL, -1, strDup(ourSIPClient->envir().getResultMsg()));
00057 }
00058
00059 void getSDPDescription(RTSPClient::responseHandler* afterFunc) {
00060 extern char* proxyServerName;
00061 if (proxyServerName != NULL) {
00062
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
00069 = *(unsigned*)(address.data());
00070 extern unsigned short proxyServerPortNum;
00071 if (proxyServerPortNum == 0) proxyServerPortNum = 5060;
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;
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 }
00095
00096 void setupSubsession(MediaSubsession* subsession, Boolean , RTSPClient::responseHandler* afterFunc) {
00097 subsession->setSessionId("mumble");
00098
00100
00101
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
00142 netAddressBits destAddress = subsession->connectionEndpointAddress();
00143 if (destAddress != 0) {
00144 subsession->setDestinations(destAddress);
00145 }
00147
00148 afterFunc(NULL, 0, NULL);
00149 }
00150
00151 void startPlayingSession(MediaSession* , double , double , float , RTSPClient::responseHandler* afterFunc) {
00152 if (ourSIPClient->sendACK()) {
00153
00154
00155
00156 afterFunc(NULL, 0, NULL);
00157 } else {
00158 afterFunc(NULL, -1, strDup(ourSIPClient->envir().getResultMsg()));
00159 }
00160 }
00161 void startPlayingSession(MediaSession* , const char* , const char* , float , RTSPClient::responseHandler* afterFunc) {
00162 startPlayingSession(NULL,(double)0,(double)0,0,afterFunc);
00163 }
00164
00165 void tearDownSession(MediaSession* , RTSPClient::responseHandler* afterFunc) {
00166 if (ourSIPClient == NULL || ourSIPClient->sendBYE()) {
00167 afterFunc(NULL, 0, NULL);
00168 } else {
00169 afterFunc(NULL, -1, strDup(ourSIPClient->envir().getResultMsg()));
00170 }
00171 }
00172
00173 Boolean allowProxyServers = True;
00174 Boolean controlConnectionUsesTCP = False;
00175 Boolean supportCodecSelection = True;
00176 char const* clientProtocolName = "SIP";