liveMedia/H264VideoFileServerMediaSubsession.cpp

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2013 Live Networks, Inc.  All rights reserved.
00018 // A 'ServerMediaSubsession' object that creates new, unicast, "RTPSink"s
00019 // on demand, from a H264 video file.
00020 // Implementation
00021 
00022 #include "H264VideoFileServerMediaSubsession.hh"
00023 #include "H264VideoRTPSink.hh"
00024 #include "ByteStreamFileSource.hh"
00025 #include "H264VideoStreamFramer.hh"
00026 
00027 H264VideoFileServerMediaSubsession*
00028 H264VideoFileServerMediaSubsession::createNew(UsageEnvironment& env,
00029                                               char const* fileName,
00030                                               Boolean reuseFirstSource) {
00031   return new H264VideoFileServerMediaSubsession(env, fileName, reuseFirstSource);
00032 }
00033 
00034 H264VideoFileServerMediaSubsession::H264VideoFileServerMediaSubsession(UsageEnvironment& env,
00035                                                                        char const* fileName, Boolean reuseFirstSource)
00036   : FileServerMediaSubsession(env, fileName, reuseFirstSource),
00037     fAuxSDPLine(NULL), fDoneFlag(0), fDummyRTPSink(NULL) {
00038 }
00039 
00040 H264VideoFileServerMediaSubsession::~H264VideoFileServerMediaSubsession() {
00041   delete[] fAuxSDPLine;
00042 }
00043 
00044 static void afterPlayingDummy(void* clientData) {
00045   H264VideoFileServerMediaSubsession* subsess = (H264VideoFileServerMediaSubsession*)clientData;
00046   subsess->afterPlayingDummy1();
00047 }
00048 
00049 void H264VideoFileServerMediaSubsession::afterPlayingDummy1() {
00050   // Unschedule any pending 'checking' task:
00051   envir().taskScheduler().unscheduleDelayedTask(nextTask());
00052   // Signal the event loop that we're done:
00053   setDoneFlag();
00054 }
00055 
00056 static void checkForAuxSDPLine(void* clientData) {
00057   H264VideoFileServerMediaSubsession* subsess = (H264VideoFileServerMediaSubsession*)clientData;
00058   subsess->checkForAuxSDPLine1();
00059 }
00060 
00061 void H264VideoFileServerMediaSubsession::checkForAuxSDPLine1() {
00062   char const* dasl;
00063 
00064   if (fAuxSDPLine != NULL) {
00065     // Signal the event loop that we're done:
00066     setDoneFlag();
00067   } else if (fDummyRTPSink != NULL && (dasl = fDummyRTPSink->auxSDPLine()) != NULL) {
00068     fAuxSDPLine = strDup(dasl);
00069     fDummyRTPSink = NULL;
00070 
00071     // Signal the event loop that we're done:
00072     setDoneFlag();
00073   } else {
00074     // try again after a brief delay:
00075     int uSecsToDelay = 100000; // 100 ms
00076     nextTask() = envir().taskScheduler().scheduleDelayedTask(uSecsToDelay,
00077                               (TaskFunc*)checkForAuxSDPLine, this);
00078   }
00079 }
00080 
00081 char const* H264VideoFileServerMediaSubsession::getAuxSDPLine(RTPSink* rtpSink, FramedSource* inputSource) {
00082   if (fAuxSDPLine != NULL) return fAuxSDPLine; // it's already been set up (for a previous client)
00083 
00084   if (fDummyRTPSink == NULL) { // we're not already setting it up for another, concurrent stream
00085     // Note: For H264 video files, the 'config' information ("profile-level-id" and "sprop-parameter-sets") isn't known
00086     // until we start reading the file.  This means that "rtpSink"s "auxSDPLine()" will be NULL initially,
00087     // and we need to start reading data from our file until this changes.
00088     fDummyRTPSink = rtpSink;
00089 
00090     // Start reading the file:
00091     fDummyRTPSink->startPlaying(*inputSource, afterPlayingDummy, this);
00092 
00093     // Check whether the sink's 'auxSDPLine()' is ready:
00094     checkForAuxSDPLine(this);
00095   }
00096 
00097   envir().taskScheduler().doEventLoop(&fDoneFlag);
00098 
00099   return fAuxSDPLine;
00100 }
00101 
00102 FramedSource* H264VideoFileServerMediaSubsession::createNewStreamSource(unsigned /*clientSessionId*/, unsigned& estBitrate) {
00103   estBitrate = 500; // kbps, estimate
00104 
00105   // Create the video source:
00106   ByteStreamFileSource* fileSource = ByteStreamFileSource::createNew(envir(), fFileName);
00107   if (fileSource == NULL) return NULL;
00108   fFileSize = fileSource->fileSize();
00109 
00110   // Create a framer for the Video Elementary Stream:
00111   return H264VideoStreamFramer::createNew(envir(), fileSource);
00112 }
00113 
00114 RTPSink* H264VideoFileServerMediaSubsession
00115 ::createNewRTPSink(Groupsock* rtpGroupsock,
00116                    unsigned char rtpPayloadTypeIfDynamic,
00117                    FramedSource* /*inputSource*/) {
00118   return H264VideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic);
00119 }

Generated on Mon Apr 29 13:28:01 2013 for live by  doxygen 1.5.2