liveMedia/MPEG1or2FileServerDemux.cpp File Reference

#include "MPEG1or2FileServerDemux.hh"
#include "MPEG1or2DemuxedServerMediaSubsession.hh"
#include "ByteStreamFileSource.hh"

Include dependency graph for MPEG1or2FileServerDemux.cpp:

Go to the source code of this file.

Data Structures

class  MFSD_DummySink

Defines

#define MFSD_DUMMY_SINK_BUFFER_SIZE   (6+65535)

Functions

static float MPEG1or2ProgramStreamFileDuration (UsageEnvironment &env, char const *fileName, unsigned &fileSize)
static Boolean getMPEG1or2TimeCode (FramedSource *dataSource, MPEG1or2Demux &parentDemux, Boolean returnFirstSeenCode, float &timeCode)
static void afterPlayingMFSD_DummySink (MFSD_DummySink *sink)
static float computeSCRTimeCode (MPEG1or2Demux::SCR const &scr)


Define Documentation

#define MFSD_DUMMY_SINK_BUFFER_SIZE   (6+65535)

Definition at line 166 of file MPEG1or2FileServerDemux.cpp.


Function Documentation

static void afterPlayingMFSD_DummySink ( MFSD_DummySink sink  )  [static]

Definition at line 250 of file MPEG1or2FileServerDemux.cpp.

References sink.

Referenced by getMPEG1or2TimeCode().

00250                                                              {
00251   // Return from the "doEventLoop()" call:
00252   sink->watchVariable = ~0;
00253 }

static float computeSCRTimeCode ( MPEG1or2Demux::SCR const &  scr  )  [static]

Definition at line 255 of file MPEG1or2FileServerDemux.cpp.

References MPEG1or2Demux::SCR::extension, MPEG1or2Demux::SCR::highBit, and MPEG1or2Demux::SCR::remainingBits.

Referenced by getMPEG1or2TimeCode().

00255                                                              {
00256   double result = scr.remainingBits/90000.0 + scr.extension/300.0;
00257   if (scr.highBit) {
00258     // Add (2^32)/90000 == (2^28)/5625
00259     double const highBitValue = (256*1024*1024)/5625.0;
00260     result += highBitValue;
00261   }
00262 
00263   return (float)result;
00264 }

static Boolean getMPEG1or2TimeCode ( FramedSource dataSource,
MPEG1or2Demux parentDemux,
Boolean  returnFirstSeenCode,
float &  timeCode 
) [static]

Definition at line 195 of file MPEG1or2FileServerDemux.cpp.

References afterPlayingMFSD_DummySink(), computeSCRTimeCode(), TaskScheduler::doEventLoop(), env, Medium::envir(), False, MPEG1or2Demux::lastSeenSCR(), sink, MediaSink::startPlaying(), and UsageEnvironment::taskScheduler().

Referenced by MPEG1or2ProgramStreamFileDuration().

00198                                                     {
00199   // Start reading through "dataSource", until we see a SCR time code:
00200   parentDemux.lastSeenSCR().isValid = False;
00201   UsageEnvironment& env = dataSource->envir(); // alias
00202   MFSD_DummySink sink(parentDemux, returnFirstSeenCode);
00203   sink.startPlaying(*dataSource,
00204                     (MediaSink::afterPlayingFunc*)afterPlayingMFSD_DummySink, &sink);
00205   env.taskScheduler().doEventLoop(&sink.watchVariable);
00206 
00207   timeCode = computeSCRTimeCode(parentDemux.lastSeenSCR());
00208   return parentDemux.lastSeenSCR().isValid;
00209 }

static float MPEG1or2ProgramStreamFileDuration ( UsageEnvironment env,
char const *  fileName,
unsigned &  fileSize 
) [static]

Definition at line 117 of file MPEG1or2FileServerDemux.cpp.

References Medium::close(), MPEG1or2Demux::createNew(), ByteStreamFileSource::createNew(), duration, env, False, ByteStreamFileSource::fileSize(), MPEG1or2Demux::flushInput(), getMPEG1or2TimeCode(), MPEG1or2Demux::newRawPESStream(), NULL, ByteStreamFileSource::seekToByteAbsolute(), and True.

Referenced by MPEG1or2FileServerDemux::MPEG1or2FileServerDemux().

00119                                                                    {
00120   FramedSource* dataSource = NULL;
00121   float duration = 0.0; // until we learn otherwise
00122   fileSize = 0; // ditto
00123 
00124   do {
00125     // Open the input file as a 'byte-stream file source':
00126     ByteStreamFileSource* fileSource = ByteStreamFileSource::createNew(env, fileName);
00127     if (fileSource == NULL) break;
00128     dataSource = fileSource;
00129 
00130     fileSize = (unsigned)(fileSource->fileSize());
00131     if (fileSize == 0) break;
00132 
00133     // Create a MPEG demultiplexor that reads from that source.
00134     MPEG1or2Demux* baseDemux = MPEG1or2Demux::createNew(env, dataSource, True);
00135     if (baseDemux == NULL) break;
00136 
00137     // Create, from this, a source that returns raw PES packets:
00138     dataSource = baseDemux->newRawPESStream();
00139 
00140     // Read the first time code from the file:
00141     float firstTimeCode;
00142     if (!getMPEG1or2TimeCode(dataSource, *baseDemux, True, firstTimeCode)) break;
00143 
00144     // Then, read the last time code from the file.
00145     // (Before doing this, flush the demux's input buffers,
00146     //  and seek towards the end of the file, for efficiency.)
00147     baseDemux->flushInput();
00148     unsigned const startByteFromEnd = 100000;
00149     unsigned newFilePosition
00150       = fileSize < startByteFromEnd ? 0 : fileSize - startByteFromEnd;
00151     if (newFilePosition > 0) fileSource->seekToByteAbsolute(newFilePosition);
00152 
00153     float lastTimeCode;
00154     if (!getMPEG1or2TimeCode(dataSource, *baseDemux, False, lastTimeCode)) break;
00155 
00156     // Take the difference between these time codes as being the file duration:
00157     float timeCodeDiff = lastTimeCode - firstTimeCode;
00158     if (timeCodeDiff < 0) break;
00159     duration = timeCodeDiff;
00160   } while (0);
00161 
00162   Medium::close(dataSource);
00163   return duration;
00164 }


Generated on Tue Mar 25 14:38:13 2014 for live by  doxygen 1.5.2