liveMedia/include/MPEG2TransportStreamIndexFile.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-2013 Live Networks, Inc.  All rights reserved.
00018 // A class that encapsulates MPEG-2 Transport Stream 'index files'/
00019 // These index files are used to implement 'trick play' operations
00020 // (seek-by-time, fast forward, reverse play) on Transport Stream files.
00021 //
00022 // C++ header
00023 
00024 #ifndef _MPEG2_TRANSPORT_STREAM_INDEX_FILE_HH
00025 #define _MPEG2_TRANSPORT_STREAM_INDEX_FILE_HH
00026 
00027 #ifndef _MEDIA_HH
00028 #include "Media.hh"
00029 #endif
00030 
00031 #define INDEX_RECORD_SIZE 11
00032 
00033 class MPEG2TransportStreamIndexFile: public Medium {
00034 public:
00035   static MPEG2TransportStreamIndexFile* createNew(UsageEnvironment& env,
00036                                                   char const* indexFileName);
00037 
00038   virtual ~MPEG2TransportStreamIndexFile();
00039 
00040   // Functions that map between a playing time and a Transport packet number
00041   // in the original Transport Stream file:
00042 
00043   void lookupTSPacketNumFromNPT(float& npt, unsigned long& tsPacketNumber,
00044                             unsigned long& indexRecordNumber);
00045     // Looks up the Transport Stream Packet number corresponding to "npt".
00046         // (This may modify "npt" to a more exact value.)
00047         // (We also return the index record number that we looked up.)
00048 
00049   void lookupPCRFromTSPacketNum(unsigned long& tsPacketNumber, Boolean reverseToPreviousCleanPoint,
00050                                 float& pcr, unsigned long& indexRecordNumber);
00051     // Looks up the PCR timestamp for the transport packet "tsPacketNumber".
00052         // (Adjust "tsPacketNumber" only if "reverseToPreviousCleanPoint" is True.)
00053         // (We also return the index record number that we looked up.)
00054 
00055   // Miscellaneous functions used to implement 'trick play':
00056   Boolean readIndexRecordValues(unsigned long indexRecordNum,
00057                                 unsigned long& transportPacketNum, u_int8_t& offset,
00058                                 u_int8_t& size, float& pcr, u_int8_t& recordType);
00059   float getPlayingDuration();
00060   void stopReading() { closeFid(); }
00061 
00062   int mpegVersion();
00063       // returns the best guess for the version of MPEG being used for data within the underlying Transport Stream file.
00064       // (1,2,4, or 5 (representing H.264).  0 means 'don't know' (usually because the index file is empty))
00065 
00066 private:
00067   MPEG2TransportStreamIndexFile(UsageEnvironment& env, char const* indexFileName);
00068 
00069   Boolean openFid();
00070   Boolean seekToIndexRecord(unsigned long indexRecordNumber);
00071   Boolean readIndexRecord(unsigned long indexRecordNum); // into "fBuf"
00072   Boolean readOneIndexRecord(unsigned long indexRecordNum); // closes "fFid" at end
00073   void closeFid();
00074 
00075   u_int8_t recordTypeFromBuf() { return fBuf[0]; }
00076   u_int8_t offsetFromBuf() { return fBuf[1]; }
00077   u_int8_t sizeFromBuf() { return fBuf[2]; }
00078   float pcrFromBuf(); // after "fBuf" has been read
00079   unsigned long tsPacketNumFromBuf();
00080   void setMPEGVersionFromRecordType(u_int8_t recordType);
00081 
00082   Boolean rewindToCleanPoint(unsigned long&ixFound);
00083       // used to implement "lookupTSPacketNumber()"
00084 
00085 private:
00086   char* fFileName;
00087   FILE* fFid; // used internally when reading from the file
00088   int fMPEGVersion;
00089   unsigned long fCurrentIndexRecordNum; // within "fFid"
00090   float fCachedPCR;
00091   unsigned long fCachedTSPacketNumber, fCachedIndexRecordNumber;
00092   unsigned long fNumIndexRecords;
00093   unsigned char fBuf[INDEX_RECORD_SIZE]; // used for reading index records from file
00094 };
00095 
00096 #endif

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