00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "liveMedia.hh"
00024 #include "GroupsockHelper.hh"
00025
00026 #include "BasicUsageEnvironment.hh"
00027
00029
00030
00031
00032 #ifdef USE_SSM
00033 Boolean const isSSM = True;
00034 #else
00035 Boolean const isSSM = False;
00036 #endif
00037
00038
00039
00040
00041
00042 #ifdef IMPLEMENT_RTSP_SERVER
00043 RTSPServer* rtspServer;
00044 #endif
00045
00046 UsageEnvironment* env;
00047
00048 void afterPlaying(void* clientData);
00049
00050
00051
00052 struct sessionState_t {
00053 FramedSource* source;
00054 RTPSink* sink;
00055 RTCPInstance* rtcpInstance;
00056 Groupsock* rtpGroupsock;
00057 Groupsock* rtcpGroupsock;
00058 } sessionState;
00059
00060 void play();
00061
00062 int main(int argc, char** argv) {
00063
00064 TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00065 env = BasicUsageEnvironment::createNew(*scheduler);
00066
00067
00068 char* destinationAddressStr
00069 #ifdef USE_SSM
00070 = "232.255.42.42";
00071 #else
00072 = "239.255.42.42";
00073
00074
00075
00076
00077 #endif
00078 const unsigned short rtpPortNum = 6666;
00079 const unsigned short rtcpPortNum = rtpPortNum+1;
00080 const unsigned char ttl = 1;
00081
00082 struct in_addr destinationAddress;
00083 destinationAddress.s_addr = our_inet_addr(destinationAddressStr);
00084 const Port rtpPort(rtpPortNum);
00085 const Port rtcpPort(rtcpPortNum);
00086
00087 sessionState.rtpGroupsock
00088 = new Groupsock(*env, destinationAddress, rtpPort, ttl);
00089 sessionState.rtcpGroupsock
00090 = new Groupsock(*env, destinationAddress, rtcpPort, ttl);
00091 #ifdef USE_SSM
00092 sessionState.rtpGroupsock->multicastSendOnly();
00093 sessionState.rtcpGroupsock->multicastSendOnly();
00094 #endif
00095
00096
00097 sessionState.sink
00098 = GSMAudioRTPSink::createNew(*env, sessionState.rtpGroupsock);
00099
00100
00101 const unsigned estimatedSessionBandwidth = 160;
00102 const unsigned maxCNAMElen = 100;
00103 unsigned char CNAME[maxCNAMElen+1];
00104 gethostname((char*)CNAME, maxCNAMElen);
00105 CNAME[maxCNAMElen] = '\0';
00106 sessionState.rtcpInstance
00107 = RTCPInstance::createNew(*env, sessionState.rtcpGroupsock,
00108 estimatedSessionBandwidth, CNAME,
00109 sessionState.sink, NULL ,
00110 isSSM);
00111
00112
00113 #ifdef IMPLEMENT_RTSP_SERVER
00114 rtspServer = RTSPServer::createNew(*env, 8554);
00115 if (rtspServer == NULL) {
00116 *env << "Failed to create RTSP server: " << env->getResultMsg() << "%s\n";
00117 exit(1);
00118 }
00119 ServerMediaSession* sms
00120 = ServerMediaSession::createNew(*env, "testStream", "GSM input",
00121 "Session streamed by \"testGSMStreamer\"", isSSM);
00122 sms->addSubsession(PassiveServerMediaSubsession::createNew(*sessionState.sink, sessionState.rtcpInstance));
00123 rtspServer->addServerMediaSession(sms);
00124
00125 char* url = rtspServer->rtspURL(sms);
00126 *env << "Play this stream using the URL \"" << url << "\"\n";
00127 delete[] url;
00128 #endif
00129
00130 play();
00131
00132 env->taskScheduler().doEventLoop();
00133 return 0;
00134 }
00135
00136 void play() {
00137
00138 extern FramedSource* createNewGSMAudioSource(UsageEnvironment&);
00139 sessionState.source = createNewGSMAudioSource(*env);
00140 if (sessionState.source == NULL) {
00141 *env << "Failed to create GSM source\n";
00142 exit(1);
00143 }
00144
00145
00146 *env << "Beginning streaming...\n";
00147 sessionState.sink->startPlaying(*sessionState.source, afterPlaying, NULL);
00148 }
00149
00150
00151 void afterPlaying(void* ) {
00152 *env << "...done streaming\n";
00153
00154 sessionState.sink->stopPlaying();
00155
00156
00157 #ifdef IMPLEMENT_RTSP_SERVER
00158 Medium::close(rtspServer);
00159 #endif
00160 Medium::close(sessionState.rtcpInstance);
00161 Medium::close(sessionState.sink);
00162 delete sessionState.rtpGroupsock;
00163 Medium::close(sessionState.source);
00164 delete sessionState.rtcpGroupsock;
00165
00166
00167 play();
00168 }