liveMedia/include/ByteStreamFileSource.hh

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 file source that is a plain byte stream (rather than frames)
00019 // C++ header
00020 
00021 #ifndef _BYTE_STREAM_FILE_SOURCE_HH
00022 #define _BYTE_STREAM_FILE_SOURCE_HH
00023 
00024 #ifndef _FRAMED_FILE_SOURCE_HH
00025 #include "FramedFileSource.hh"
00026 #endif
00027 
00028 class ByteStreamFileSource: public FramedFileSource {
00029 public:
00030   static ByteStreamFileSource* createNew(UsageEnvironment& env,
00031                                          char const* fileName,
00032                                          unsigned preferredFrameSize = 0,
00033                                          unsigned playTimePerFrame = 0);
00034   // "preferredFrameSize" == 0 means 'no preference'
00035   // "playTimePerFrame" is in microseconds
00036 
00037   static ByteStreamFileSource* createNew(UsageEnvironment& env,
00038                                          FILE* fid,
00039                                          unsigned preferredFrameSize = 0,
00040                                          unsigned playTimePerFrame = 0);
00041       // an alternative version of "createNew()" that's used if you already have
00042       // an open file.
00043 
00044   u_int64_t fileSize() const { return fFileSize; }
00045       // 0 means zero-length, unbounded, or unknown
00046 
00047   void seekToByteAbsolute(u_int64_t byteNumber, u_int64_t numBytesToStream = 0);
00048     // if "numBytesToStream" is >0, then we limit the stream to that number of bytes, before treating it as EOF
00049   void seekToByteRelative(int64_t offset);
00050   void seekToEnd(); // to force EOF handling on the next read
00051 
00052 protected:
00053   ByteStreamFileSource(UsageEnvironment& env,
00054                        FILE* fid,
00055                        unsigned preferredFrameSize,
00056                        unsigned playTimePerFrame);
00057         // called only by createNew()
00058 
00059   virtual ~ByteStreamFileSource();
00060 
00061   static void fileReadableHandler(ByteStreamFileSource* source, int mask);
00062   void doReadFromFile();
00063 
00064 private:
00065   // redefined virtual functions:
00066   virtual void doGetNextFrame();
00067   virtual void doStopGettingFrames();
00068 
00069 protected:
00070   u_int64_t fFileSize;
00071 
00072 private:
00073   unsigned fPreferredFrameSize;
00074   unsigned fPlayTimePerFrame;
00075   Boolean fFidIsSeekable;
00076   unsigned fLastPlayTime;
00077   Boolean fHaveStartedReading;
00078   Boolean fLimitNumBytesToStream;
00079   u_int64_t fNumBytesToStream; // used iff "fLimitNumBytesToStream" is True
00080 };
00081 
00082 #endif

Generated on Thu May 17 07:11:45 2012 for live by  doxygen 1.5.2