liveMedia/DVVideoFileServerMediaSubsession.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-2012 Live Networks, Inc.  All rights reserved.
00018 // A 'ServerMediaSubsession' object that creates new, unicast, "RTPSink"s
00019 // on demand, from a DV video file.
00020 // Implementation
00021 
00022 #include "DVVideoFileServerMediaSubsession.hh"
00023 #include "DVVideoRTPSink.hh"
00024 #include "ByteStreamFileSource.hh"
00025 #include "DVVideoStreamFramer.hh"
00026 
00027 DVVideoFileServerMediaSubsession*
00028 DVVideoFileServerMediaSubsession::createNew(UsageEnvironment& env, char const* fileName, Boolean reuseFirstSource) {
00029   return new DVVideoFileServerMediaSubsession(env, fileName, reuseFirstSource);
00030 }
00031 
00032 DVVideoFileServerMediaSubsession
00033 ::DVVideoFileServerMediaSubsession(UsageEnvironment& env, char const* fileName, Boolean reuseFirstSource)
00034   : FileServerMediaSubsession(env, fileName, reuseFirstSource),
00035     fFileDuration(0.0) {
00036 }
00037 
00038 DVVideoFileServerMediaSubsession::~DVVideoFileServerMediaSubsession() {
00039 }
00040 
00041 FramedSource* DVVideoFileServerMediaSubsession
00042 ::createNewStreamSource(unsigned /*clientSessionId*/, unsigned& estBitrate) {
00043   // Create the video source:
00044   ByteStreamFileSource* fileSource = ByteStreamFileSource::createNew(envir(), fFileName);
00045   if (fileSource == NULL) return NULL;
00046   fFileSize = fileSource->fileSize();
00047 
00048   // Create a framer for the Video Elementary Stream:
00049   DVVideoStreamFramer* framer = DVVideoStreamFramer::createNew(envir(), fileSource, True/*the file source is seekable*/);
00050   
00051   // Use the framer to figure out the file's duration:
00052   unsigned frameSize;
00053   double frameDuration;
00054   if (framer->getFrameParameters(frameSize, frameDuration)) {
00055     fFileDuration = (float)(((int64_t)fFileSize*frameDuration)/(frameSize*1000000.0));
00056     estBitrate = (unsigned)((8000.0*frameSize)/frameDuration); // in kbps
00057   } else {
00058     estBitrate = 50000; // kbps, estimate
00059   }
00060 
00061   return framer;
00062 }
00063 
00064 RTPSink* DVVideoFileServerMediaSubsession::createNewRTPSink(Groupsock* rtpGroupsock,
00065                                                             unsigned char rtpPayloadTypeIfDynamic,
00066                                                             FramedSource* /*inputSource*/) {
00067   return DVVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic);
00068 }
00069 
00070 char const* DVVideoFileServerMediaSubsession::getAuxSDPLine(RTPSink* rtpSink, FramedSource* inputSource) {
00071   return ((DVVideoRTPSink*)rtpSink)->auxSDPLineFromFramer((DVVideoStreamFramer*)inputSource);
00072 }
00073 
00074 float DVVideoFileServerMediaSubsession::duration() const {
00075   return fFileDuration;
00076 }
00077 
00078 void DVVideoFileServerMediaSubsession
00079 ::seekStreamSource(FramedSource* inputSource, double& seekNPT, double streamDuration, u_int64_t& numBytes) {
00080   // First, get the file source from "inputSource" (a framer):
00081   DVVideoStreamFramer* framer = (DVVideoStreamFramer*)inputSource;
00082   ByteStreamFileSource* fileSource = (ByteStreamFileSource*)(framer->inputSource());
00083 
00084   // Then figure out where to seek to within the file:
00085   if (fFileDuration > 0.0) {
00086     u_int64_t seekByteNumber = (u_int64_t)(((int64_t)fFileSize*seekNPT)/fFileDuration);
00087     numBytes = (u_int64_t)(((int64_t)fFileSize*streamDuration)/fFileDuration);
00088     fileSource->seekToByteAbsolute(seekByteNumber, numBytes);
00089   }
00090 }

Generated on Thu May 10 20:25:11 2012 for live by  doxygen 1.5.2