testProgs/vobStreamer.cpp File Reference

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

Include dependency graph for vobStreamer.cpp:

Go to the source code of this file.

Functions

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

Variables

char const * programName
Boolean iFramesOnly = False
unsigned const VOB_AUDIO = 1<<0
unsigned const VOB_VIDEO = 1<<1
unsigned mediaToStream = VOB_AUDIO|VOB_VIDEO
char const ** inputFileNames
char const ** curInputFileName
Boolean haveReadOneFile = False
UsageEnvironmentenv
MPEG1or2DemuxmpegDemux
AC3AudioStreamFrameraudioSource = NULL
FramedSourcevideoSource = NULL
RTPSinkaudioSink = NULL
RTCPInstanceaudioRTCP = NULL
RTPSinkvideoSink = NULL
RTCPInstancevideoRTCP = NULL
RTSPServerrtspServer = NULL
unsigned short const defaultRTSPServerPortNum = 554
unsigned short rtspServerPortNum = defaultRTSPServerPortNum
GroupsockrtpGroupsockAudio
GroupsockrtcpGroupsockAudio
GroupsockrtpGroupsockVideo
GroupsockrtcpGroupsockVideo


Function Documentation

void afterPlaying ( void *  clientData  ) 

Definition at line 224 of file vobStreamer.cpp.

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

00224                                     {
00225   // One of the sinks has ended playing.
00226   // Check whether any of the sources have a pending read.  If so,
00227   // wait until its sink ends playing also:
00228   if ((audioSource != NULL && audioSource->isCurrentlyAwaitingData()) ||
00229       (videoSource != NULL && videoSource->isCurrentlyAwaitingData())) {
00230     return;
00231   }
00232 
00233   // Now that both sinks have ended, close both input sources,
00234   // and start playing again:
00235   *env << "...done reading from file\n";
00236 
00237   if (audioSink != NULL) audioSink->stopPlaying();
00238   if (videoSink != NULL) videoSink->stopPlaying();
00239       // ensures that both are shut down
00240   Medium::close(audioSource);
00241   Medium::close(videoSource);
00242   Medium::close(mpegDemux);
00243   // Note: This also closes the input file that this source read from.
00244 
00245   // Move to the next file name (if any):
00246   ++curInputFileName;
00247 
00248   // Start playing once again:
00249   play();
00250 }

int main ( int  argc,
char const **  argv 
)

Definition at line 66 of file vobStreamer.cpp.

References RTSPServer::addServerMediaSession(), ServerMediaSession::addSubsession(), audioRTCP, audioSink, chooseRandomIPv4SSMAddress(), PassiveServerMediaSubsession::createNew(), ServerMediaSession::createNew(), RTSPServer::createNew(), MPEG1or2VideoRTPSink::createNew(), RTCPInstance::createNew(), AC3AudioRTPSink::createNew(), BasicUsageEnvironment::createNew(), BasicTaskScheduler::createNew(), curInputFileName, TaskScheduler::doEventLoop(), env, exit, UsageEnvironment::getResultMsg(), iFramesOnly, inputFileNames, mediaToStream, Groupsock::multicastSendOnly(), NULL, play(), programName, rtcpGroupsockAudio, rtcpGroupsockVideo, rtpGroupsockAudio, rtpGroupsockVideo, rtspServer, rtspServerPortNum, RTSPServer::rtspURL(), UsageEnvironment::taskScheduler(), True, usage(), videoRTCP, videoSink, VOB_AUDIO, and VOB_VIDEO.

00066                                       {
00067   // Begin by setting up our usage environment:
00068   TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00069   env = BasicUsageEnvironment::createNew(*scheduler);
00070 
00071   // Parse command-line options:
00072   // (Unfortunately we can't use getopt() here; Windoze doesn't have it)
00073   programName = argv[0];
00074   while (argc > 2) {
00075     char const* const opt = argv[1];
00076     if (opt[0] != '-') break;
00077     switch (opt[1]) {
00078 
00079     case 'i': { // transmit video I-frames only
00080       iFramesOnly = True;
00081       break;
00082     }
00083 
00084     case 'a': { // transmit audio, but not video
00085       mediaToStream &=~ VOB_VIDEO;
00086       break;
00087     }
00088 
00089     case 'v': { // transmit video, but not audio
00090       mediaToStream &=~ VOB_AUDIO;
00091       break;
00092     }
00093 
00094     case 'p': { // specify port number for built-in RTSP server
00095       int portArg;
00096       if (sscanf(argv[2], "%d", &portArg) != 1) {
00097         usage();
00098       }
00099       if (portArg <= 0 || portArg >= 65536) {
00100         *env << "bad port number: " << portArg
00101              << " (must be in the range (0,65536))\n";
00102         usage();
00103       }
00104       rtspServerPortNum = (unsigned short)portArg;
00105       ++argv; --argc;
00106       break;
00107     }
00108 
00109     default: {
00110       usage();
00111       break;
00112     }
00113     }
00114 
00115     ++argv; --argc;
00116   }
00117   if (argc < 2) usage();
00118   if (mediaToStream == 0) {
00119     *env << "The -a and -v flags cannot both be used!\n";
00120     usage();
00121   }
00122   if (iFramesOnly && (mediaToStream&VOB_VIDEO) == 0) {
00123     *env << "Warning: Because we're not streaming video, the -i flag has no effect.\n";
00124   }
00125 
00126   inputFileNames = &argv[1];
00127   curInputFileName = inputFileNames;
00128 
00129   // Create 'groupsocks' for RTP and RTCP:
00130   struct in_addr destinationAddress;
00131   destinationAddress.s_addr = chooseRandomIPv4SSMAddress(*env);
00132 
00133   const unsigned short rtpPortNumAudio = 4444;
00134   const unsigned short rtcpPortNumAudio = rtpPortNumAudio+1;
00135   const unsigned short rtpPortNumVideo = 8888;
00136   const unsigned short rtcpPortNumVideo = rtpPortNumVideo+1;
00137   const unsigned char ttl = 255;
00138 
00139   const Port rtpPortAudio(rtpPortNumAudio);
00140   const Port rtcpPortAudio(rtcpPortNumAudio);
00141   const Port rtpPortVideo(rtpPortNumVideo);
00142   const Port rtcpPortVideo(rtcpPortNumVideo);
00143 
00144   const unsigned maxCNAMElen = 100;
00145   unsigned char CNAME[maxCNAMElen+1];
00146   gethostname((char*)CNAME, maxCNAMElen);
00147   CNAME[maxCNAMElen] = '\0'; // just in case
00148 
00149   if (mediaToStream&VOB_AUDIO) {
00150     rtpGroupsockAudio
00151       = new Groupsock(*env, destinationAddress, rtpPortAudio, ttl);
00152     rtpGroupsockAudio->multicastSendOnly(); // because we're a SSM source
00153 
00154     // Create an 'AC3 Audio RTP' sink from the RTP 'groupsock':
00155     audioSink
00156       = AC3AudioRTPSink::createNew(*env, rtpGroupsockAudio, 96, 0);
00157     // set the RTP timestamp frequency 'for real' later
00158 
00159     // Create (and start) a 'RTCP instance' for this RTP sink:
00160     rtcpGroupsockAudio
00161       = new Groupsock(*env, destinationAddress, rtcpPortAudio, ttl);
00162     rtcpGroupsockAudio->multicastSendOnly(); // because we're a SSM source
00163     const unsigned estimatedSessionBandwidthAudio
00164       = 160; // in kbps; for RTCP b/w share
00165     audioRTCP = RTCPInstance::createNew(*env, rtcpGroupsockAudio,
00166                                         estimatedSessionBandwidthAudio, CNAME,
00167                                         audioSink, NULL /* we're a server */,
00168                                         True /* we're a SSM source */);
00169     // Note: This starts RTCP running automatically
00170   }
00171 
00172   if (mediaToStream&VOB_VIDEO) {
00173     rtpGroupsockVideo
00174       = new Groupsock(*env, destinationAddress, rtpPortVideo, ttl);
00175     rtpGroupsockVideo->multicastSendOnly(); // because we're a SSM source
00176 
00177     // Create a 'MPEG Video RTP' sink from the RTP 'groupsock':
00178     videoSink = MPEG1or2VideoRTPSink::createNew(*env, rtpGroupsockVideo);
00179 
00180     // Create (and start) a 'RTCP instance' for this RTP sink:
00181     rtcpGroupsockVideo
00182       = new Groupsock(*env, destinationAddress, rtcpPortVideo, ttl);
00183     rtcpGroupsockVideo->multicastSendOnly(); // because we're a SSM source
00184     const unsigned estimatedSessionBandwidthVideo
00185       = 4500; // in kbps; for RTCP b/w share
00186     videoRTCP = RTCPInstance::createNew(*env, rtcpGroupsockVideo,
00187                                         estimatedSessionBandwidthVideo, CNAME,
00188                                         videoSink, NULL /* we're a server */,
00189                                         True /* we're a SSM source */);
00190     // Note: This starts RTCP running automatically
00191   }
00192 
00193   if (rtspServer == NULL) {
00194     rtspServer = RTSPServer::createNew(*env, rtspServerPortNum);
00195     if (rtspServer == NULL) {
00196       *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
00197       *env << "To change the RTSP server's port number, use the \"-p <port number>\" option.\n";
00198       exit(1);
00199     }
00200     ServerMediaSession* sms
00201       = ServerMediaSession::createNew(*env, "vobStream", *curInputFileName,
00202              "Session streamed by \"vobStreamer\"", True /*SSM*/);
00203     if (audioSink != NULL) sms->addSubsession(PassiveServerMediaSubsession::createNew(*audioSink, audioRTCP));
00204     if (videoSink != NULL) sms->addSubsession(PassiveServerMediaSubsession::createNew(*videoSink, videoRTCP));
00205     rtspServer->addServerMediaSession(sms);
00206 
00207     *env << "Created RTSP server.\n";
00208 
00209     // Display our "rtsp://" URL, for clients to connect to:
00210     char* url = rtspServer->rtspURL(sms);
00211     *env << "Access this stream using the URL:\n\t" << url << "\n";
00212     delete[] url;
00213   }
00214 
00215   // Finally, start the streaming:
00216   *env << "Beginning streaming...\n";
00217   play();
00218 
00219   env->taskScheduler().doEventLoop(); // does not return
00220 
00221   return 0; // only to prevent compiler warning
00222 }

void play (  ) 

void usage (  ) 

Definition at line 57 of file vobStreamer.cpp.

References env, exit, and programName.

00057              {
00058   *env << "usage: " << programName << " [-i] [-a|-v] "
00059           "[-p <RTSP-server-port-number>] "
00060           "<VOB-file>...<VOB-file>\n";
00061   exit(1);
00062 }


Variable Documentation

RTCPInstance* audioRTCP = NULL

Definition at line 45 of file vobStreamer.cpp.

Referenced by main().

RTPSink* audioSink = NULL

Definition at line 44 of file vobStreamer.cpp.

AC3AudioStreamFramer* audioSource = NULL

Definition at line 42 of file vobStreamer.cpp.

char const** curInputFileName

Definition at line 37 of file vobStreamer.cpp.

Referenced by afterPlaying(), and main().

unsigned short const defaultRTSPServerPortNum = 554

Definition at line 49 of file vobStreamer.cpp.

UsageEnvironment* env

Definition at line 40 of file vobStreamer.cpp.

Boolean haveReadOneFile = False

Definition at line 38 of file vobStreamer.cpp.

Boolean iFramesOnly = False

Definition at line 30 of file vobStreamer.cpp.

char const** inputFileNames

Definition at line 36 of file vobStreamer.cpp.

Referenced by main().

unsigned mediaToStream = VOB_AUDIO|VOB_VIDEO

Definition at line 34 of file vobStreamer.cpp.

Referenced by main().

MPEG1or2Demux* mpegDemux

Definition at line 41 of file vobStreamer.cpp.

char const* programName

Definition at line 27 of file vobStreamer.cpp.

Groupsock* rtcpGroupsockAudio

Definition at line 53 of file vobStreamer.cpp.

Referenced by main().

Groupsock* rtcpGroupsockVideo

Definition at line 55 of file vobStreamer.cpp.

Referenced by main().

Groupsock* rtpGroupsockAudio

Definition at line 52 of file vobStreamer.cpp.

Referenced by main().

Groupsock* rtpGroupsockVideo

Definition at line 54 of file vobStreamer.cpp.

Referenced by main().

RTSPServer* rtspServer = NULL

Definition at line 48 of file vobStreamer.cpp.

Referenced by announceStream(), and main().

unsigned short rtspServerPortNum = defaultRTSPServerPortNum

Definition at line 50 of file vobStreamer.cpp.

Referenced by main().

RTCPInstance* videoRTCP = NULL

Definition at line 47 of file vobStreamer.cpp.

Referenced by main().

RTPSink* videoSink = NULL

Definition at line 46 of file vobStreamer.cpp.

FramedSource* videoSource = NULL

Definition at line 43 of file vobStreamer.cpp.

unsigned const VOB_AUDIO = 1<<0

Definition at line 32 of file vobStreamer.cpp.

Referenced by main().

unsigned const VOB_VIDEO = 1<<1

Definition at line 33 of file vobStreamer.cpp.

Referenced by main().


Generated on Tue Jun 18 13:19:53 2013 for live by  doxygen 1.5.2