00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "liveMedia.hh"
00022 #include "BasicUsageEnvironment.hh"
00023 #include "GroupsockHelper.hh"
00024
00025 UsageEnvironment* env;
00026 char const* inputFileName = "test.m4e";
00027 MPEG4VideoStreamFramer* videoSource;
00028 RTPSink* videoSink;
00029
00030 void play();
00031
00032 int main(int argc, char** argv) {
00033
00034 TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00035 env = BasicUsageEnvironment::createNew(*scheduler);
00036
00037
00038 struct in_addr destinationAddress;
00039 destinationAddress.s_addr = chooseRandomIPv4SSMAddress(*env);
00040
00041
00042
00043
00044 const unsigned short rtpPortNum = 18888;
00045 const unsigned short rtcpPortNum = rtpPortNum+1;
00046 const unsigned char ttl = 255;
00047
00048 const Port rtpPort(rtpPortNum);
00049 const Port rtcpPort(rtcpPortNum);
00050
00051 Groupsock rtpGroupsock(*env, destinationAddress, rtpPort, ttl);
00052 rtpGroupsock.multicastSendOnly();
00053 Groupsock rtcpGroupsock(*env, destinationAddress, rtcpPort, ttl);
00054 rtcpGroupsock.multicastSendOnly();
00055
00056
00057 videoSink = MPEG4ESVideoRTPSink::createNew(*env, &rtpGroupsock, 96);
00058
00059
00060 const unsigned estimatedSessionBandwidth = 500;
00061 const unsigned maxCNAMElen = 100;
00062 unsigned char CNAME[maxCNAMElen+1];
00063 gethostname((char*)CNAME, maxCNAMElen);
00064 CNAME[maxCNAMElen] = '\0';
00065 RTCPInstance* rtcp
00066 = RTCPInstance::createNew(*env, &rtcpGroupsock,
00067 estimatedSessionBandwidth, CNAME,
00068 videoSink, NULL ,
00069 True );
00070
00071
00072 RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554);
00073 if (rtspServer == NULL) {
00074 *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
00075 exit(1);
00076 }
00077 ServerMediaSession* sms
00078 = ServerMediaSession::createNew(*env, "testStream", inputFileName,
00079 "Session streamed by \"testMPEG4VideoStreamer\"",
00080 True );
00081 sms->addSubsession(PassiveServerMediaSubsession::createNew(*videoSink, rtcp));
00082 rtspServer->addServerMediaSession(sms);
00083
00084 char* url = rtspServer->rtspURL(sms);
00085 *env << "Play this stream using the URL \"" << url << "\"\n";
00086 delete[] url;
00087
00088
00089 *env << "Beginning streaming...\n";
00090 play();
00091
00092 env->taskScheduler().doEventLoop();
00093
00094 return 0;
00095 }
00096
00097 void afterPlaying(void* ) {
00098 *env << "...done reading from file\n";
00099
00100 videoSink->stopPlaying();
00101 Medium::close(videoSource);
00102
00103
00104
00105 play();
00106 }
00107
00108 void play() {
00109
00110 ByteStreamFileSource* fileSource
00111 = ByteStreamFileSource::createNew(*env, inputFileName);
00112 if (fileSource == NULL) {
00113 *env << "Unable to open file \"" << inputFileName
00114 << "\" as a byte-stream file source\n";
00115 exit(1);
00116 }
00117
00118 FramedSource* videoES = fileSource;
00119
00120
00121 videoSource = MPEG4VideoStreamFramer::createNew(*env, videoES);
00122
00123
00124 *env << "Beginning to read from file...\n";
00125 videoSink->startPlaying(*videoSource, afterPlaying, videoSink);
00126 }