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.dv";
00027 DVVideoStreamFramer* 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
00058 OutPacketBuffer::maxSize = 300000;
00059 videoSink = DVVideoRTPSink::createNew(*env, &rtpGroupsock, 96);
00060
00061
00062 const unsigned estimatedSessionBandwidth = 50000;
00063 const unsigned maxCNAMElen = 100;
00064 unsigned char CNAME[maxCNAMElen+1];
00065 gethostname((char*)CNAME, maxCNAMElen);
00066 CNAME[maxCNAMElen] = '\0';
00067 RTCPInstance* rtcp
00068 = RTCPInstance::createNew(*env, &rtcpGroupsock,
00069 estimatedSessionBandwidth, CNAME,
00070 videoSink, NULL ,
00071 True );
00072
00073
00074 RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554);
00075 if (rtspServer == NULL) {
00076 *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
00077 exit(1);
00078 }
00079 ServerMediaSession* sms
00080 = ServerMediaSession::createNew(*env, "testStream", inputFileName,
00081 "Session streamed by \"testDVVideoStreamer\"",
00082 True );
00083 sms->addSubsession(PassiveServerMediaSubsession::createNew(*videoSink, rtcp));
00084 rtspServer->addServerMediaSession(sms);
00085
00086 char* url = rtspServer->rtspURL(sms);
00087 *env << "Play this stream using the URL \"" << url << "\"\n";
00088 delete[] url;
00089
00090
00091 *env << "Beginning streaming...\n";
00092 play();
00093
00094 env->taskScheduler().doEventLoop();
00095
00096 return 0;
00097 }
00098
00099 void afterPlaying(void* ) {
00100 *env << "...done reading from file\n";
00101
00102 videoSink->stopPlaying();
00103 Medium::close(videoSource);
00104
00105
00106
00107 play();
00108 }
00109
00110 void play() {
00111
00112 ByteStreamFileSource* fileSource
00113 = ByteStreamFileSource::createNew(*env, inputFileName);
00114 if (fileSource == NULL) {
00115 *env << "Unable to open file \"" << inputFileName
00116 << "\" as a byte-stream file source\n";
00117 exit(1);
00118 }
00119
00120 FramedSource* videoES = fileSource;
00121
00122
00123 videoSource = DVVideoStreamFramer::createNew(*env, videoES);
00124
00125
00126 *env << "Beginning to read from file...\n";
00127 videoSink->startPlaying(*videoSource, afterPlaying, videoSink);
00128 }