testProgs/testMPEG1or2VideoStreamer.cpp File Reference

#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"
#include "GroupsockHelper.hh"

Include dependency graph for testMPEG1or2VideoStreamer.cpp:

Go to the source code of this file.

Functions

void play ()
int main (int argc, char **argv)
void afterPlaying (void *)

Variables

Boolean const isSSM = False
Boolean iFramesOnly = False
UsageEnvironmentenv
char const * inputFileName = "test.mpg"
MediaSourcevideoSource
RTPSinkvideoSink


Function Documentation

void afterPlaying ( void *   ) 

Definition at line 134 of file testMPEG1or2VideoStreamer.cpp.

References Medium::close(), env, mpegDemux, play(), MediaSink::stopPlaying(), videoSink, and videoSource.

00134                                         {
00135   *env << "...done reading from file\n";
00136 
00137   videoSink->stopPlaying();
00138   Medium::close(videoSource);
00139 #ifdef SOURCE_IS_PROGRAM_STREAM
00140   Medium::close(mpegDemux);
00141 #endif
00142   // Note that this also closes the input file that this source read from.
00143 
00144   play();
00145 }

int main ( int  argc,
char **  argv 
)

Definition at line 55 of file testMPEG1or2VideoStreamer.cpp.

References RTSPServer::addServerMediaSession(), ServerMediaSession::addSubsession(), PassiveServerMediaSubsession::createNew(), ServerMediaSession::createNew(), RTSPServer::createNew(), RTCPInstance::createNew(), MPEG1or2VideoRTPSink::createNew(), BasicUsageEnvironment::createNew(), BasicTaskScheduler::createNew(), TaskScheduler::doEventLoop(), env, exit, UsageEnvironment::getResultMsg(), inputFileName, isSSM, Groupsock::multicastSendOnly(), NULL, our_inet_addr(), play(), rtspServer, RTSPServer::rtspURL(), UsageEnvironment::taskScheduler(), and videoSink.

00055                                 {
00056   // Begin by setting up our usage environment:
00057   TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00058   env = BasicUsageEnvironment::createNew(*scheduler);
00059 
00060   // Create 'groupsocks' for RTP and RTCP:
00061   char const* destinationAddressStr
00062 #ifdef USE_SSM
00063     = "232.255.42.42";
00064 #else
00065     = "239.255.42.42";
00066   // Note: This is a multicast address.  If you wish to stream using
00067   // unicast instead, then replace this string with the unicast address
00068   // of the (single) destination.  (You may also need to make a similar
00069   // change to the receiver program.)
00070 #endif
00071   const unsigned short rtpPortNum = 8888;
00072   const unsigned short rtcpPortNum = rtpPortNum+1;
00073   const unsigned char ttl = 7; // low, in case routers don't admin scope
00074 
00075   struct in_addr destinationAddress;
00076   destinationAddress.s_addr = our_inet_addr(destinationAddressStr);
00077   const Port rtpPort(rtpPortNum);
00078   const Port rtcpPort(rtcpPortNum);
00079 
00080   Groupsock rtpGroupsock(*env, destinationAddress, rtpPort, ttl);
00081   Groupsock rtcpGroupsock(*env, destinationAddress, rtcpPort, ttl);
00082 #ifdef USE_SSM
00083   rtpGroupsock.multicastSendOnly();
00084   rtcpGroupsock.multicastSendOnly();
00085 #endif
00086 
00087   // Create a 'MPEG Video RTP' sink from the RTP 'groupsock':
00088   videoSink = MPEG1or2VideoRTPSink::createNew(*env, &rtpGroupsock);
00089 
00090   // Create (and start) a 'RTCP instance' for this RTP sink:
00091   const unsigned estimatedSessionBandwidth = 4500; // in kbps; for RTCP b/w share
00092   const unsigned maxCNAMElen = 100;
00093   unsigned char CNAME[maxCNAMElen+1];
00094   gethostname((char*)CNAME, maxCNAMElen);
00095   CNAME[maxCNAMElen] = '\0'; // just in case
00096 #ifdef IMPLEMENT_RTSP_SERVER
00097   RTCPInstance* rtcp =
00098 #endif
00099     RTCPInstance::createNew(*env, &rtcpGroupsock,
00100                               estimatedSessionBandwidth, CNAME,
00101                               videoSink, NULL /* we're a server */, isSSM);
00102   // Note: This starts RTCP running automatically
00103 
00104 #ifdef IMPLEMENT_RTSP_SERVER
00105   RTSPServer* rtspServer = RTSPServer::createNew(*env);
00106   // Note that this (attempts to) start a server on the default RTSP server
00107   // port: 554.  To use a different port number, add it as an extra
00108   // (optional) parameter to the "RTSPServer::createNew()" call above.
00109   if (rtspServer == NULL) {
00110     *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
00111     exit(1);
00112   }
00113   ServerMediaSession* sms
00114     = ServerMediaSession::createNew(*env, "testStream", inputFileName,
00115                    "Session streamed by \"testMPEG1or2VideoStreamer\"",
00116                                            isSSM);
00117   sms->addSubsession(PassiveServerMediaSubsession::createNew(*videoSink, rtcp));
00118   rtspServer->addServerMediaSession(sms);
00119 
00120   char* url = rtspServer->rtspURL(sms);
00121   *env << "Play this stream using the URL \"" << url << "\"\n";
00122   delete[] url;
00123 #endif
00124 
00125   // Finally, start the streaming:
00126   *env << "Beginning streaming...\n";
00127   play();
00128 
00129   env->taskScheduler().doEventLoop(); // does not return
00130 
00131   return 0; // only to prevent compiler warning
00132 }

void play (  ) 


Variable Documentation

UsageEnvironment* env

Definition at line 45 of file testMPEG1or2VideoStreamer.cpp.

Boolean iFramesOnly = False

Definition at line 43 of file testMPEG1or2VideoStreamer.cpp.

char const* inputFileName = "test.mpg"

Definition at line 46 of file testMPEG1or2VideoStreamer.cpp.

Boolean const isSSM = False

Definition at line 34 of file testMPEG1or2VideoStreamer.cpp.

RTPSink* videoSink

Definition at line 51 of file testMPEG1or2VideoStreamer.cpp.

MediaSource* videoSource

Definition at line 50 of file testMPEG1or2VideoStreamer.cpp.


Generated on Thu May 17 07:14:43 2012 for live by  doxygen 1.5.2