live
MPEG1or2Demux.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// Demultiplexer for a MPEG 1 or 2 Program Stream
19// C++ header
20
21#ifndef _MPEG_1OR2_DEMUX_HH
22#define _MPEG_1OR2_DEMUX_HH
23
24#ifndef _FRAMED_SOURCE_HH
25#include "FramedSource.hh"
26#endif
27
28class MPEG1or2DemuxedElementaryStream; // forward
29
30typedef void MPEG1or2DemuxOnDeletionFunc(void* objectToNotify, class MPEG1or2Demux* demuxBeingDeleted);
31
32class MPEG1or2Demux: public Medium {
33public:
36 Boolean reclaimWhenLastESDies = False,
37 MPEG1or2DemuxOnDeletionFunc* onDeletionFunc = NULL,
38 void* objectToNotify = NULL);
39 // If "reclaimWhenLastESDies" is True, the the demux is deleted when
40 // all "MPEG1or2DemuxedElementaryStream"s that we created get deleted.
41
43
44 // Specialized versions of the above for audio and video:
47
48 // A hack for getting raw, undemuxed PES packets from the Program Stream:
50
51 void getNextFrame(u_int8_t streamIdTag,
52 unsigned char* to, unsigned maxSize,
53 FramedSource::afterGettingFunc* afterGettingFunc,
54 void* afterGettingClientData,
55 FramedSource::onCloseFunc* onCloseFunc,
56 void* onCloseClientData);
57 // similar to FramedSource::getNextFrame(), except that it also
58 // takes a stream id tag as parameter.
59
60 void stopGettingFrames(u_int8_t streamIdTag);
61 // similar to FramedSource::stopGettingFrames(), except that it also
62 // takes a stream id tag as parameter.
63
64 static void handleClosure(void* clientData);
65 // This should be called (on ourself) if the source is discovered
66 // to be closed (i.e., no longer readable)
67
69
70 class SCR {
71 public:
72 SCR();
73
74 u_int8_t highBit;
75 u_int32_t remainingBits;
76 u_int16_t extension;
77
79 };
81
82 unsigned char mpegVersion() const { return fMPEGversion; }
83
84 void flushInput(); // should be called before any 'seek' on the underlying source
85
86private:
88 FramedSource* inputSource, Boolean reclaimWhenLastESDies,
89 MPEG1or2DemuxOnDeletionFunc* onDeletionFunc, void* objectToNotify);
90 // called only by createNew()
91 virtual ~MPEG1or2Demux();
92
93 void registerReadInterest(u_int8_t streamIdTag,
94 unsigned char* to, unsigned maxSize,
95 FramedSource::afterGettingFunc* afterGettingFunc,
96 void* afterGettingClientData,
97 FramedSource::onCloseFunc* onCloseFunc,
98 void* onCloseClientData);
99
100 Boolean useSavedData(u_int8_t streamIdTag,
101 unsigned char* to, unsigned maxSize,
102 FramedSource::afterGettingFunc* afterGettingFunc,
103 void* afterGettingClientData);
104
105 static void continueReadProcessing(void* clientData,
106 unsigned char* ptr, unsigned size,
107 struct timeval presentationTime);
109
110private:
113
114private:
117 unsigned char fMPEGversion;
118
123
124 // A descriptor for each possible stream id tag:
125 typedef struct OutputDescriptor {
126 // input parameters
127 unsigned char* to; unsigned maxSize;
132
133 // output parameters
134 unsigned frameSize; struct timeval presentationTime;
135 class SavedData; // forward
136 SavedData* savedDataHead;
137 SavedData* savedDataTail;
139
140 // status parameters
146
149
152
153private: // parsing state
155 friend class MPEGProgramStreamParser; // hack
156};
157
158#endif
const Boolean False
Definition: Boolean.hh:28
unsigned char Boolean
Definition: Boolean.hh:25
void MPEG1or2DemuxOnDeletionFunc(void *objectToNotify, class MPEG1or2Demux *demuxBeingDeleted)
#define NULL
void() onCloseFunc(void *clientData)
Definition: FramedSource.hh:40
void() afterGettingFunc(void *clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds)
Definition: FramedSource.hh:36
u_int32_t remainingBits
MPEG1or2DemuxedElementaryStream * newAudioStream()
void flushInput()
unsigned char mpegVersion() const
unsigned char fMPEGversion
void noteElementaryStreamDeletion(MPEG1or2DemuxedElementaryStream *es)
static void continueReadProcessing(void *clientData, unsigned char *ptr, unsigned size, struct timeval presentationTime)
friend class MPEGProgramStreamParser
static MPEG1or2Demux * createNew(UsageEnvironment &env, FramedSource *inputSource, Boolean reclaimWhenLastESDies=False, MPEG1or2DemuxOnDeletionFunc *onDeletionFunc=NULL, void *objectToNotify=NULL)
FramedSource * inputSource() const
MPEG1or2DemuxedElementaryStream * newElementaryStream(u_int8_t streamIdTag)
Boolean fHaveUndeliveredData
MPEG1or2Demux(UsageEnvironment &env, FramedSource *inputSource, Boolean reclaimWhenLastESDies, MPEG1or2DemuxOnDeletionFunc *onDeletionFunc, void *objectToNotify)
class MPEGProgramStreamParser * fParser
void * fOnDeletionObjectToNotify
Boolean fReclaimWhenLastESDies
unsigned fNumOutstandingESs
MPEG1or2DemuxOnDeletionFunc * fOnDeletionFunc
OutputDescriptor_t fOutput[256]
unsigned char fNextAudioStreamNumber
SCR & lastSeenSCR()
unsigned char fNextVideoStreamNumber
MPEG1or2DemuxedElementaryStream * newRawPESStream()
Boolean useSavedData(u_int8_t streamIdTag, unsigned char *to, unsigned maxSize, FramedSource::afterGettingFunc *afterGettingFunc, void *afterGettingClientData)
static void handleClosure(void *clientData)
void stopGettingFrames(u_int8_t streamIdTag)
void continueReadProcessing()
MPEG1or2DemuxedElementaryStream * newVideoStream()
virtual ~MPEG1or2Demux()
unsigned fNumPendingReads
void getNextFrame(u_int8_t streamIdTag, unsigned char *to, unsigned maxSize, FramedSource::afterGettingFunc *afterGettingFunc, void *afterGettingClientData, FramedSource::onCloseFunc *onCloseFunc, void *onCloseClientData)
void registerReadInterest(u_int8_t streamIdTag, unsigned char *to, unsigned maxSize, FramedSource::afterGettingFunc *afterGettingFunc, void *afterGettingClientData, FramedSource::onCloseFunc *onCloseFunc, void *onCloseClientData)
FramedSource * fInputSource
struct MPEG1or2Demux::OutputDescriptor OutputDescriptor_t
Definition: Media.hh:50
FramedSource::onCloseFunc * fOnCloseFunc
FramedSource::afterGettingFunc * fAfterGettingFunc