live
MPEG2TransportStreamIndexFile.hh
Go to the documentation of this file.
1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2024 Live Networks, Inc. All rights reserved.
18// A class that encapsulates MPEG-2 Transport Stream 'index files'/
19// These index files are used to implement 'trick play' operations
20// (seek-by-time, fast forward, reverse play) on Transport Stream files.
21//
22// C++ header
23
24#ifndef _MPEG2_TRANSPORT_STREAM_INDEX_FILE_HH
25#define _MPEG2_TRANSPORT_STREAM_INDEX_FILE_HH
26
27#ifndef _MEDIA_HH
28#include "Media.hh"
29#endif
30
31#define INDEX_RECORD_SIZE 11
32
34public:
36 char const* indexFileName);
37
39
40 // Functions that map between a playing time and a Transport packet number
41 // in the original Transport Stream file:
42
43 void lookupTSPacketNumFromNPT(float& npt, unsigned long& tsPacketNumber,
44 unsigned long& indexRecordNumber);
45 // Looks up the Transport Stream Packet number corresponding to "npt".
46 // (This may modify "npt" to a more exact value.)
47 // (We also return the index record number that we looked up.)
48
49 void lookupPCRFromTSPacketNum(unsigned long& tsPacketNumber, Boolean reverseToPreviousCleanPoint,
50 float& pcr, unsigned long& indexRecordNumber);
51 // Looks up the PCR timestamp for the transport packet "tsPacketNumber".
52 // (Adjust "tsPacketNumber" only if "reverseToPreviousCleanPoint" is True.)
53 // (We also return the index record number that we looked up.)
54
55 // Miscellaneous functions used to implement 'trick play':
56 Boolean readIndexRecordValues(unsigned long indexRecordNum,
57 unsigned long& transportPacketNum, u_int8_t& offset,
58 u_int8_t& size, float& pcr, u_int8_t& recordType);
60 void stopReading() { closeFid(); }
61
63 // returns the best guess for the version of MPEG being used for data within the underlying Transport Stream file.
64 // (1,2,4, or 5 (representing H.264). 0 means 'don't know' (usually because the index file is empty))
65
66private:
67 MPEG2TransportStreamIndexFile(UsageEnvironment& env, char const* indexFileName);
68
70 Boolean seekToIndexRecord(unsigned long indexRecordNumber);
71 Boolean readIndexRecord(unsigned long indexRecordNum); // into "fBuf"
72 Boolean readOneIndexRecord(unsigned long indexRecordNum); // closes "fFid" at end
73 void closeFid();
74
75 u_int8_t recordTypeFromBuf() { return fBuf[0]; }
76 u_int8_t offsetFromBuf() { return fBuf[1]; }
77 u_int8_t sizeFromBuf() { return fBuf[2]; }
78 float pcrFromBuf(); // after "fBuf" has been read
79 unsigned long tsPacketNumFromBuf();
80 void setMPEGVersionFromRecordType(u_int8_t recordType);
81
82 Boolean rewindToCleanPoint(unsigned long&ixFound);
83 // used to implement "lookupTSPacketNumber()"
84
85private:
86 char* fFileName;
87 FILE* fFid; // used internally when reading from the file
89 unsigned long fCurrentIndexRecordNum; // within "fFid"
92 unsigned long fNumIndexRecords;
93 unsigned char fBuf[INDEX_RECORD_SIZE]; // used for reading index records from file
94};
95
96#endif
unsigned char Boolean
Definition: Boolean.hh:25
#define INDEX_RECORD_SIZE
void lookupTSPacketNumFromNPT(float &npt, unsigned long &tsPacketNumber, unsigned long &indexRecordNumber)
void lookupPCRFromTSPacketNum(unsigned long &tsPacketNumber, Boolean reverseToPreviousCleanPoint, float &pcr, unsigned long &indexRecordNumber)
Boolean readOneIndexRecord(unsigned long indexRecordNum)
unsigned char fBuf[INDEX_RECORD_SIZE]
static MPEG2TransportStreamIndexFile * createNew(UsageEnvironment &env, char const *indexFileName)
unsigned long tsPacketNumFromBuf()
void setMPEGVersionFromRecordType(u_int8_t recordType)
Boolean readIndexRecordValues(unsigned long indexRecordNum, unsigned long &transportPacketNum, u_int8_t &offset, u_int8_t &size, float &pcr, u_int8_t &recordType)
MPEG2TransportStreamIndexFile(UsageEnvironment &env, char const *indexFileName)
Boolean seekToIndexRecord(unsigned long indexRecordNumber)
Boolean rewindToCleanPoint(unsigned long &ixFound)
Boolean readIndexRecord(unsigned long indexRecordNum)
Definition: Media.hh:50