live
MPEG2TransportStreamParser.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 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:
34enum PIDType { PAT, PMT, STREAM };
35
36class PIDState {
37protected: // we're a virtual base class
38 PIDState(MPEG2TransportStreamParser& parser, u_int16_t pid, PIDType pidType);
39public:
40 virtual ~PIDState();
41
42public:
44 u_int16_t PID;
46};
47
48class PIDState_PAT : public PIDState {
49public:
51protected:
52 virtual ~PIDState_PAT();
53};
54
55class PIDState_PMT : public PIDState {
56public:
57 PIDState_PMT(MPEG2TransportStreamParser& parser, u_int16_t pid, u_int16_t programNumber);
58protected:
59 virtual ~PIDState_PMT();
60
61public:
62 u_int16_t program_number;
63};
64
65class PIDState_STREAM : public PIDState {
66public:
67 PIDState_STREAM(MPEG2TransportStreamParser& parser, u_int16_t pid, u_int16_t programNumber, u_int8_t streamType);
68protected:
70
71public:
72 u_int16_t program_number;
73 u_int8_t stream_type;
77};
78
79
80// Descriptions of known "stream_type"s:
82public:
83 char const* description;
85 char const* filenameSuffix;
86
87public:
88 StreamType(char const* description = "unknown", enum dataType dataType = UNKNOWN,
89 char const* filenameSuffix = "");
90};
91
92
94public:
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
105private:
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
119private: // redefined virtual functions
121
122private:
123 // General state for parsing:
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