testProgs/testMPEG1or2AudioVideoStreamer.cpp File Reference

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

Include dependency graph for testMPEG1or2AudioVideoStreamer.cpp:

Go to the source code of this file.

Functions

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

Variables

UsageEnvironmentenv
char const * inputFileName = "test.mpg"
MPEG1or2DemuxmpegDemux
FramedSourceaudioSource
FramedSourcevideoSource
RTPSinkaudioSink
RTPSinkvideoSink
Boolean const isSSM = False
Boolean iFramesOnly = False


Function Documentation

void afterPlaying ( void *  clientData  ) 

Definition at line 153 of file testMPEG1or2AudioVideoStreamer.cpp.

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

00153                                     {
00154   // One of the sinks has ended playing.
00155   // Check whether any of the sources have a pending read.  If so,
00156   // wait until its sink ends playing also:
00157   if (audioSource->isCurrentlyAwaitingData()
00158       || videoSource->isCurrentlyAwaitingData()) return;
00159 
00160   // Now that both sinks have ended, close both input sources,
00161   // and start playing again:
00162   *env << "...done reading from file\n";
00163 
00164   audioSink->stopPlaying();
00165   videoSink->stopPlaying();
00166       // ensures that both are shut down
00167   Medium::close(audioSource);
00168   Medium::close(videoSource);
00169   Medium::close(mpegDemux);
00170   // Note: This also closes the input file that this source read from.
00171 
00172   // Start playing once again:
00173   play();
00174 }

int main ( int  argc,
char **  argv 
)

Definition at line 52 of file testMPEG1or2AudioVideoStreamer.cpp.

References RTSPServer::addServerMediaSession(), ServerMediaSession::addSubsession(), audioRTCP, audioSink, PassiveServerMediaSubsession::createNew(), ServerMediaSession::createNew(), RTSPServer::createNew(), MPEG1or2VideoRTPSink::createNew(), RTCPInstance::createNew(), MPEG1or2AudioRTPSink::createNew(), BasicUsageEnvironment::createNew(), BasicTaskScheduler::createNew(), TaskScheduler::doEventLoop(), env, UsageEnvironment::getResultMsg(), inputFileName, isSSM, Groupsock::multicastSendOnly(), NULL, our_inet_addr(), play(), rtcpGroupsockAudio, rtcpGroupsockVideo, rtpGroupsockAudio, rtpGroupsockVideo, rtspServer, RTSPServer::rtspURL(), UsageEnvironment::taskScheduler(), videoRTCP, and videoSink.

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

void play (  ) 


Variable Documentation

RTPSink* audioSink

Definition at line 31 of file testMPEG1or2AudioVideoStreamer.cpp.

FramedSource* audioSource

Definition at line 29 of file testMPEG1or2AudioVideoStreamer.cpp.

UsageEnvironment* env

Definition at line 26 of file testMPEG1or2AudioVideoStreamer.cpp.

Boolean iFramesOnly = False

Definition at line 50 of file testMPEG1or2AudioVideoStreamer.cpp.

Referenced by main().

char const* inputFileName = "test.mpg"

Definition at line 27 of file testMPEG1or2AudioVideoStreamer.cpp.

Boolean const isSSM = False

Definition at line 41 of file testMPEG1or2AudioVideoStreamer.cpp.

MPEG1or2Demux* mpegDemux

Definition at line 28 of file testMPEG1or2AudioVideoStreamer.cpp.

Referenced by afterPlaying().

RTPSink* videoSink

Definition at line 32 of file testMPEG1or2AudioVideoStreamer.cpp.

Referenced by afterPlaying(), and main().

FramedSource* videoSource

Definition at line 30 of file testMPEG1or2AudioVideoStreamer.cpp.

Referenced by afterPlaying().


Generated on Tue Oct 7 15:39:25 2008 for live by  doxygen 1.5.2