testProgs/playSIP.cpp

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // Copyright (c) 1996-2012, Live Networks, Inc.  All rights reserved
00017 // A SIP client test program that opens a SIP URL argument,
00018 // and extracts the data from each incoming RTP stream.
00019 
00020 #include "playCommon.hh"
00021 #include "SIPClient.hh"
00022 
00023 SIPClient* ourSIPClient = NULL;
00024 Medium* createClient(UsageEnvironment& env, char const* /*url*/, int verbosityLevel, char const* applicationName) {
00025   // First, trim any directory prefixes from "applicationName":
00026   char const* suffix = &applicationName[strlen(applicationName)];
00027   while (suffix != applicationName) {
00028     if (*suffix == '/' || *suffix == '\\') {
00029       applicationName = ++suffix;
00030       break;
00031     }
00032     --suffix;
00033   }
00034 
00035   extern unsigned char desiredAudioRTPPayloadFormat;
00036   extern char* mimeSubtype;
00037   return ourSIPClient = SIPClient::createNew(env, desiredAudioRTPPayloadFormat, mimeSubtype, verbosityLevel, applicationName);
00038 }
00039 
00040 void getOptions(RTSPClient::responseHandler* afterFunc) { 
00041   ourSIPClient->envir().setResultMsg("NOT SUPPORTED IN CLIENT");
00042   afterFunc(NULL, -1, strDup(ourSIPClient->envir().getResultMsg()));
00043 }
00044 
00045 void getSDPDescription(RTSPClient::responseHandler* afterFunc) {
00046   extern char* proxyServerName;
00047   if (proxyServerName != NULL) {
00048     // Tell the SIP client about the proxy:
00049     NetAddressList addresses(proxyServerName);
00050     if (addresses.numAddresses() == 0) {
00051       ourSIPClient->envir() << "Failed to find network address for \"" << proxyServerName << "\"\n";
00052     } else {
00053       NetAddress address = *(addresses.firstAddress());
00054       unsigned proxyServerAddress // later, allow for IPv6 #####
00055         = *(unsigned*)(address.data());
00056       extern unsigned short proxyServerPortNum;
00057       if (proxyServerPortNum == 0) proxyServerPortNum = 5060; // default
00058 
00059       ourSIPClient->setProxyServer(proxyServerAddress, proxyServerPortNum);
00060     }
00061   }
00062 
00063   extern unsigned short desiredPortNum;
00064   unsigned short clientStartPortNum = desiredPortNum;
00065   if (clientStartPortNum == 0) clientStartPortNum = 8000; // default
00066   ourSIPClient->setClientStartPortNum(clientStartPortNum);
00067 
00068   extern char const* streamURL;
00069   char const* username = ourAuthenticator->username();
00070   char const* password = ourAuthenticator->password();
00071   char* result;
00072   if (username != NULL && password != NULL) {
00073     result = ourSIPClient->inviteWithPassword(streamURL, username, password);
00074   } else {
00075     result = ourSIPClient->invite(streamURL);
00076   }
00077 
00078   int resultCode = result == NULL ? -1 : 0;
00079   afterFunc(NULL, resultCode, strDup(result));
00080 }
00081 
00082 void setupSubsession(MediaSubsession* subsession, Boolean /*streamUsingTCP*/, RTSPClient::responseHandler* afterFunc) {
00083   subsession->setSessionId("mumble"); // anything that's non-NULL will work
00084 
00085   afterFunc(NULL, 0, NULL);
00086 }
00087 
00088 void startPlayingSession(MediaSession* /*session*/, double /*start*/, double /*end*/, float /*scale*/, RTSPClient::responseHandler* afterFunc) {
00089   if (ourSIPClient->sendACK()) {
00090     //##### This isn't quite right, because we should really be allowing
00091     //##### for the possibility of this ACK getting lost, by retransmitting
00092     //##### it *each time* we get a 2xx response from the server.
00093     afterFunc(NULL, 0, NULL);
00094   } else {
00095     afterFunc(NULL, -1, strDup(ourSIPClient->envir().getResultMsg()));
00096   }
00097 }
00098 
00099 void tearDownSession(MediaSession* /*session*/, RTSPClient::responseHandler* afterFunc) {
00100   if (ourSIPClient == NULL || ourSIPClient->sendBYE()) {
00101     afterFunc(NULL, 0, NULL);
00102   } else {
00103     afterFunc(NULL, -1, strDup(ourSIPClient->envir().getResultMsg()));
00104   }
00105 }
00106 
00107 Boolean allowProxyServers = True;
00108 Boolean controlConnectionUsesTCP = False;
00109 Boolean supportCodecSelection = True;
00110 char const* clientProtocolName = "SIP";

Generated on Thu May 17 07:11:47 2012 for live by  doxygen 1.5.2