live
MPEG2TransportStreamParser.hh
Go to the documentation of this file.
1 /**********
2 This library is free software; you can redistribute it and/or modify it under
3 the terms of the GNU Lesser General Public License as published by the
4 Free Software Foundation; either version 3 of the License, or (at your
5 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6 
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10 more details.
11 
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 **********/
16 // "liveMedia"
17 // Copyright (c) 1996-2022 Live Networks, Inc. All rights reserved.
18 // A parser for a MPEG Transport Stream
19 // C++ header
20 
21 #ifndef _MPEG2_TRANSPORT_STREAM_PARSER_HH
22 
23 #ifndef _STREAM_PARSER_HH
24 #include "StreamParser.hh"
25 #endif
26 #ifndef _MPEG2_TRANSPORT_STREAM_DEMUXED_TRACK_HH
28 #endif
29 #ifndef _MEDIA_SINK_HH
30 #include "MediaSink.hh"
31 #endif
32 
33 // A descriptor that describes the state of each known PID:
34 enum PIDType { PAT, PMT, STREAM };
35 
36 class PIDState {
37 protected: // we're a virtual base class
38  PIDState(MPEG2TransportStreamParser& parser, u_int16_t pid, PIDType pidType);
39 public:
40  virtual ~PIDState();
41 
42 public:
44  u_int16_t PID;
46 };
47 
48 class PIDState_PAT : public PIDState {
49 public:
50  PIDState_PAT(MPEG2TransportStreamParser& parser, u_int16_t pid);
51 protected:
52  virtual ~PIDState_PAT();
53 };
54 
55 class PIDState_PMT : public PIDState {
56 public:
57  PIDState_PMT(MPEG2TransportStreamParser& parser, u_int16_t pid, u_int16_t programNumber);
58 protected:
59  virtual ~PIDState_PMT();
60 
61 public:
62  u_int16_t program_number;
63 };
64 
65 class PIDState_STREAM : public PIDState {
66 public:
67  PIDState_STREAM(MPEG2TransportStreamParser& parser, u_int16_t pid, u_int16_t programNumber, u_int8_t streamType);
68 protected:
69  virtual ~PIDState_STREAM();
70 
71 public:
72  u_int16_t program_number;
73  u_int8_t stream_type;
74  double lastSeenPTS;
77 };
78 
79 
80 // Descriptions of known "stream_type"s:
81 class StreamType {
82 public:
83  char const* description;
85  char const* filenameSuffix;
86 
87 public:
88  StreamType(char const* description = "unknown", enum dataType dataType = UNKNOWN,
89  char const* filenameSuffix = "");
90 };
91 
92 
94 public:
96  FramedSource::onCloseFunc* onEndFunc, void* onEndClientData);
98 
100 
101  // StreamParser 'client continue' function:
102  static void continueParsing(void* clientData, unsigned char* ptr, unsigned size, struct timeval presentationTime);
104 
105 private:
106  // Parsing functions:
108  Boolean parse(); // returns True iff we have finished parsing all BOS pages (on initialization)
109 
111  Boolean processDataBytes(u_int16_t PID, Boolean pusi, unsigned numDataBytes);
112 
113  void parsePAT(Boolean pusi, unsigned numDataBytes);
114  void parsePMT(PIDState_PMT* pidState, Boolean pusi, unsigned numDataBytes);
115  void parseStreamDescriptors(unsigned numDescriptorBytes);
116  Boolean processStreamPacket(PIDState_STREAM* pidState, Boolean pusi, unsigned numDataBytes);
117  unsigned parsePESHeader(PIDState_STREAM* pidState, unsigned numDataBytes);
118 
119 private: // redefined virtual functions
120  virtual void restoreSavedParserState();
121 
122 private:
123  // General state for parsing:
129  double fLastSeenPCR;
130 };
131 
132 #endif
unsigned char Boolean
Definition: Boolean.hh:25
void() onCloseFunc(void *clientData)
Definition: FramedSource.hh:40
UsageEnvironment & envir()
void parsePMT(PIDState_PMT *pidState, Boolean pusi, unsigned numDataBytes)
FramedSource::onCloseFunc * fOnEndFunc
void parseStreamDescriptors(unsigned numDescriptorBytes)
Boolean processStreamPacket(PIDState_STREAM *pidState, Boolean pusi, unsigned numDataBytes)
virtual ~MPEG2TransportStreamParser()
static void continueParsing(void *clientData, unsigned char *ptr, unsigned size, struct timeval presentationTime)
Boolean processDataBytes(u_int16_t PID, Boolean pusi, unsigned numDataBytes)
void parsePAT(Boolean pusi, unsigned numDataBytes)
unsigned parsePESHeader(PIDState_STREAM *pidState, unsigned numDataBytes)
MPEG2TransportStreamParser(FramedSource *inputSource, FramedSource::onCloseFunc *onEndFunc, void *onEndClientData)
virtual void restoreSavedParserState()
PIDState_PAT(MPEG2TransportStreamParser &parser, u_int16_t pid)
virtual ~PIDState_PAT()
virtual ~PIDState_PMT()
PIDState_PMT(MPEG2TransportStreamParser &parser, u_int16_t pid, u_int16_t programNumber)
MPEG2TransportStreamDemuxedTrack * streamSource
virtual ~PIDState_STREAM()
PIDState_STREAM(MPEG2TransportStreamParser &parser, u_int16_t pid, u_int16_t programNumber, u_int8_t streamType)
MPEG2TransportStreamParser & ourParser
virtual ~PIDState()
PIDState(MPEG2TransportStreamParser &parser, u_int16_t pid, PIDType pidType)
StreamType(char const *description="unknown", enum dataType dataType=UNKNOWN, char const *filenameSuffix="")
char const * filenameSuffix