3
* inptstrm.hpp: Input stream classes for MPEG multiplexing
5
* Copyright (C) 2001 Andrew Stevens <andrew.stevens@philips.com>
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of version 2 of the GNU General Public License
10
* as published by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#ifndef __INPUTSTRM_H__
23
#define __INPUTSTRM_H__
29
#include "mjpeg_types.h"
30
#include "mpegconsts.h"
31
#include "format_codes.h"
32
#include "mjpeg_logging.h"
34
#include "mplexconsts.hpp"
36
#include "aunitbuffer.hpp"
37
#include "decodebufmodel.hpp"
44
InputStream( IBitStream &istream ) :
53
void SetBufSize( unsigned int buf_size )
55
bs.SetBufSize( buf_size );
58
bitcount_t stream_length;
65
unsigned int last_buffered_AU; // decode seq num of last buffered frame + 1
68
bitcount_t prev_offset;
69
unsigned int decoding_order;
70
unsigned int old_frames;
82
void Init( const int strm_id,
83
const unsigned int _buf_scale,
84
const unsigned int buf_size,
85
const unsigned int _zero_stuffing,
86
const bool bufs_in_first,
87
const bool always_bufs
90
unsigned int BufferSizeCode();
91
inline unsigned int BufferSize() { return buffer_size; }
92
inline unsigned int BufferScale() { return buffer_scale; }
95
inline void SetMaxPacketData( unsigned int max )
97
max_packet_data = max;
99
inline void SetMinPacketData( unsigned int min )
101
min_packet_data = min;
103
inline unsigned int MaxPacketData() { return max_packet_data; }
104
inline unsigned int MinPacketData() { return min_packet_data; }
105
inline bool NewAUNextSector() { return new_au_next_sec; }
108
// Read the next packet payload (sub-stream headers plus
109
// parsed and spliced stream data) for a packet with the
110
// specified payload capacity. Update the AU info.
113
virtual unsigned int ReadPacketPayload(uint8_t *dst, unsigned int to_read) = 0;
116
// Return the size of the substream headers...
118
virtual unsigned int StreamHeaderSize() { return 0; }
120
public: // TODO should go protected once encapsulation complete
122
unsigned int buffer_scale;
123
unsigned int buffer_size;
124
DecodeBufModel bufmodel;
125
unsigned int max_packet_data;
126
unsigned int min_packet_data;
127
unsigned int zero_stuffing;
129
unsigned int min_pes_header_len;
130
bool buffers_in_header;
131
bool always_buffers_in_header;
132
bool new_au_next_sec;
136
class DummyMuxStream : public MuxStream
139
DummyMuxStream( const int strm_id,
140
const unsigned int buf_scale,
141
unsigned int buf_size )
144
buffer_scale = buf_scale;
145
buffer_size = buf_size;
148
unsigned int ReadPacketPayload(uint8_t *dst, unsigned int to_read)
156
class ElementaryStream : public InputStream,
160
enum stream_kind { audio, video, dummy };
161
ElementaryStream( IBitStream &ibs,
165
virtual ~ElementaryStream () { }
166
virtual void Close() = 0;
169
AUnit *Lookahead( unsigned int n = 0);
170
unsigned int BytesToMuxAUEnd(unsigned int sector_transport_size);
172
virtual bool MuxPossible(clockticks currentSCR );
173
void DemuxedTo( clockticks SCR );
174
void SetTSOffset( clockticks baseTS );
176
inline stream_kind Kind() { return kind; }
177
inline unsigned int BufferMin() { return buffer_min; }
178
inline unsigned int BufferMax() { return buffer_max; }
179
inline clockticks BaseDTS() { return au->DTS; };
180
inline clockticks BasePTS() { return au->PTS; };
182
inline int DecodeOrder() { return au->dorder; }
184
inline clockticks RequiredDTS( const AUnit *unit )
185
{ return unit->DTS + timestamp_delay; };
186
inline clockticks RequiredPTS( const AUnit *unit )
187
{ return unit->PTS + timestamp_delay; };
188
inline clockticks RequiredDTS()
189
{ return RequiredDTS(au); };
190
inline clockticks RequiredPTS()
191
{ return RequiredPTS(au); };
192
inline clockticks NextRequiredDTS()
194
AUnit *next = Lookahead();
196
return RequiredDTS(next);
200
inline clockticks NextRequiredPTS()
202
AUnit *next = Lookahead();
204
return RequiredPTS(next);
209
void UpdateBufferMinMax();
211
void SetSyncOffset( clockticks timestamp_delay );
213
void BufferAndOutputSector();
215
inline bool BuffersInHeader() { return buffers_in_header; }
216
virtual unsigned int NominalBitRate() = 0;
217
virtual bool RunOutComplete() = 0;
220
/******************************************************************
221
* Reads the stream data from actual input stream, updates decode
222
* buffer model and current access unit information from the
223
* look-ahead scanning buffer to account for bytes_muxed bytes being
225
* TODO: No longer needs to be virtual
227
******************************************************************/
228
virtual unsigned int ReadPacketPayload(uint8_t *dst, unsigned int to_read);
230
/********************************************************************
231
* Update stream-specific mux state information to reflect muxing of
232
* current AU. first_in_sector is set true if AU is first muxed into
233
* the current sector.
235
*******************************************************************/
237
virtual void AUMuxed( bool first_in_sector ) {}
239
/**************************************************************
240
* The size of the stream-specific sub-header (if any)
241
*************************************************************/
242
virtual unsigned int StreamHeaderSize() { return 0; }
244
/*****************************************************************
245
* Reads/generates the stream-specific sub-header for AUs muxed
246
* since last call AUMuxed( true );
247
****************************************************************/
249
virtual void ReadStreamHeader( uint8_t *dst, unsigned int len ) {}
251
bitcount_t bytes_read;
253
void AUBufferLookaheadFill( unsigned int look_ahead);
257
virtual void FillAUbuffer(unsigned int frames_to_buffer) = 0;
258
virtual void OutputSector() = 0;
260
void Muxed( unsigned int bytes_muxed );
262
clockticks timestamp_delay;
264
unsigned int au_unsent;
266
Multiplexor &muxinto;
268
unsigned int buffer_min;
269
unsigned int buffer_max;
276
#endif // __INPUTSTRM_H__
281
* c-file-style: "stroustrup"
283
* indent-tabs-mode: nil