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