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
00026
00027 #ifdef USE_SSM
00028 Boolean const isSSM = True;
00029 #else
00030 Boolean const isSSM = False;
00031 #endif
00032
00033
00034
00035
00036
00037 #define TRANSPORT_PACKET_SIZE 188
00038 #define TRANSPORT_PACKETS_PER_NETWORK_PACKET 7
00039
00040
00041 UsageEnvironment* env;
00042 char const* inputFileName = "test.ts";
00043 FramedSource* videoSource;
00044 RTPSink* videoSink;
00045
00046 void play();
00047
00048 int main(int argc, char** argv) {
00049
00050 TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00051 env = BasicUsageEnvironment::createNew(*scheduler);
00052
00053
00054 char const* destinationAddressStr
00055 #ifdef USE_SSM
00056 = "232.255.42.42";
00057 #else
00058 = "239.255.42.42";
00059
00060
00061
00062
00063 #endif
00064 const unsigned short rtpPortNum = 1234;
00065 const unsigned short rtcpPortNum = rtpPortNum+1;
00066 const unsigned char ttl = 7;
00067
00068 struct in_addr destinationAddress;
00069 destinationAddress.s_addr = our_inet_addr(destinationAddressStr);
00070 const Port rtpPort(rtpPortNum);
00071 const Port rtcpPort(rtcpPortNum);
00072
00073 Groupsock rtpGroupsock(*env, destinationAddress, rtpPort, ttl);
00074 Groupsock rtcpGroupsock(*env, destinationAddress, rtcpPort, ttl);
00075 #ifdef USE_SSM
00076 rtpGroupsock.multicastSendOnly();
00077 rtcpGroupsock.multicastSendOnly();
00078 #endif
00079
00080
00081 videoSink =
00082 SimpleRTPSink::createNew(*env, &rtpGroupsock, 33, 90000, "video", "MP2T",
00083 1, True, False );
00084
00085
00086 const unsigned estimatedSessionBandwidth = 5000;
00087 const unsigned maxCNAMElen = 100;
00088 unsigned char CNAME[maxCNAMElen+1];
00089 gethostname((char*)CNAME, maxCNAMElen);
00090 CNAME[maxCNAMElen] = '\0';
00091 #ifdef IMPLEMENT_RTSP_SERVER
00092 RTCPInstance* rtcp =
00093 #endif
00094 RTCPInstance::createNew(*env, &rtcpGroupsock,
00095 estimatedSessionBandwidth, CNAME,
00096 videoSink, NULL , isSSM);
00097
00098
00099 #ifdef IMPLEMENT_RTSP_SERVER
00100 RTSPServer* rtspServer = RTSPServer::createNew(*env);
00101
00102
00103
00104 if (rtspServer == NULL) {
00105 *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
00106 exit(1);
00107 }
00108 ServerMediaSession* sms
00109 = ServerMediaSession::createNew(*env, "testStream", inputFileName,
00110 "Session streamed by \"testMPEG2TransportStreamer\"",
00111 isSSM);
00112 sms->addSubsession(PassiveServerMediaSubsession::createNew(*videoSink, rtcp));
00113 rtspServer->addServerMediaSession(sms);
00114
00115 char* url = rtspServer->rtspURL(sms);
00116 *env << "Play this stream using the URL \"" << url << "\"\n";
00117 delete[] url;
00118 #endif
00119
00120
00121 *env << "Beginning streaming...\n";
00122 play();
00123
00124 env->taskScheduler().doEventLoop();
00125
00126 return 0;
00127 }
00128
00129 void afterPlaying(void* ) {
00130 *env << "...done reading from file\n";
00131
00132 videoSink->stopPlaying();
00133 Medium::close(videoSource);
00134
00135
00136 play();
00137 }
00138
00139 void play() {
00140 unsigned const inputDataChunkSize
00141 = TRANSPORT_PACKETS_PER_NETWORK_PACKET*TRANSPORT_PACKET_SIZE;
00142
00143
00144 ByteStreamFileSource* fileSource
00145 = ByteStreamFileSource::createNew(*env, inputFileName, inputDataChunkSize);
00146 if (fileSource == NULL) {
00147 *env << "Unable to open file \"" << inputFileName
00148 << "\" as a byte-stream file source\n";
00149 exit(1);
00150 }
00151
00152
00153 videoSource = MPEG2TransportStreamFramer::createNew(*env, fileSource);
00154
00155
00156 *env << "Beginning to read from file...\n";
00157 videoSink->startPlaying(*videoSource, afterPlaying, videoSink);
00158 }