1 2 /* 3 * audiostrm.hpp: Audio stream class sub-hierarchy for MPEG multiplexing 4 * 5 * Copyright (C) 2001 Andrew Stevens <andrew.stevens@philips.com> 6 * 7 * 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. 11 * 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. 16 * 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. 20 */ 21 22 #ifndef __AUDIOSTRM_H__ 23 #define __AUDIOSTRM_H__ 24 25 #include "inputstrm.hpp" 26 #include "stream_params.hpp" 27 28 // TODO AudioStream is reall NonVideoStream as it is also a base for 29 // SUBPStream (sub)classes 30 31 class AudioStream : public ElementaryStream 32 { 33 public: 34 AudioStream(IBitStream &ibs, Multiplexor &into ); 35 virtual void Init(const int stream_num) = 0; 36 virtual void Close() = 0; 37 38 void OutputSector(); 39 bool RunOutComplete(); 40 virtual unsigned int NominalBitRate() = 0; 41 42 unsigned int num_syncword; 43 44 protected: 45 virtual void FillAUbuffer(unsigned int frames_to_buffer) = 0; 46 47 /* State variables for scanning source bit-stream */ 48 AUnit access_unit; 49 unsigned int header_skip; 50 }; 51 52 class MPAStream : public AudioStream 53 { 54 public: 55 MPAStream(IBitStream &ibs, Multiplexor &into ); 56 virtual void Init(const int stream_num); 57 static bool Probe(IBitStream &bs); 58 virtual void Close(); 59 virtual unsigned int NominalBitRate(); 60 61 62 private: 63 void OutputHdrInfo(); 64 unsigned int SizeFrame( int bit_rate, int padding_bit ); 65 virtual void FillAUbuffer(unsigned int frames_to_buffer); 66 67 68 /* Stream information for logging and parsing purposes */ 69 unsigned int samples_per_second; 70 unsigned int version_id ; 71 unsigned int layer ; 72 unsigned int protection ; 73 unsigned int bit_rate_code; 74 unsigned int frequency ; 75 unsigned int mode ; 76 unsigned int mode_extension ; 77 unsigned int copyright ; 78 unsigned int original_copy ; 79 unsigned int emphasis ; 80 81 /* State variables for scanning source bit-stream */ 82 unsigned int framesize; 83 unsigned int num_frames [2]; 84 unsigned int size_frames[2]; 85 86 }; 87 88 89 90 class AC3Stream : public AudioStream 91 { 92 public: 93 AC3Stream(IBitStream &ibs,Multiplexor &into ); 94 virtual void Init(const int stream_num); 95 static bool Probe(IBitStream &bs); 96 virtual void Close(); 97 virtual unsigned int NominalBitRate(); 98 99 virtual unsigned int ReadPacketPayload(uint8_t *dst, unsigned int to_read); StreamHeaderSize()100 virtual unsigned int StreamHeaderSize() { return 4; } 101 102 103 private: 104 void OutputHdrInfo(); 105 void DisplayAc3HeaderInfo(); 106 virtual void FillAUbuffer(unsigned int frames_to_buffer); 107 108 static const unsigned int default_buffer_size; 109 /* State variables for scanning source bit-stream */ 110 unsigned int framesize; 111 unsigned int frequency; 112 unsigned int samples_per_second; 113 unsigned int bit_rate; 114 unsigned int stream_num; 115 unsigned int num_frames; 116 }; 117 118 class DTSStream : public AudioStream 119 { 120 public: 121 DTSStream(IBitStream &ibs,Multiplexor &into ); 122 virtual void Init(const int stream_num); 123 static bool Probe(IBitStream &bs); 124 virtual void Close(); 125 virtual unsigned int NominalBitRate(); 126 127 virtual unsigned int ReadPacketPayload(uint8_t *dst, unsigned int to_read); StreamHeaderSize()128 virtual unsigned int StreamHeaderSize() { return 4; } 129 130 131 private: 132 void OutputHdrInfo(); 133 #ifdef DEBUG_DTS 134 void DisplayDtsHeaderInfo(); 135 #endif 136 virtual void FillAUbuffer(unsigned int frames_to_buffer); 137 138 static const unsigned int default_buffer_size; 139 140 /* State variables for scanning source bit-stream */ 141 unsigned int framesize; 142 unsigned int samples_per_second; 143 unsigned int bit_rate; 144 unsigned int stream_num; 145 unsigned int frequency ; 146 unsigned int num_frames; 147 }; 148 149 class LPCMStream : public AudioStream 150 { 151 public: 152 LPCMStream(IBitStream &ibs, LpcmParams *parms, Multiplexor &into ); 153 virtual void Init(const int stream_num); 154 static bool Probe(IBitStream &bs); 155 virtual void Close(); 156 virtual unsigned int NominalBitRate(); 157 158 virtual unsigned int ReadPacketPayload(uint8_t *dst, unsigned int to_read); StreamHeaderSize()159 virtual unsigned int StreamHeaderSize() { return 7; } 160 161 162 private: 163 void OutputHdrInfo(); 164 virtual void FillAUbuffer(unsigned int frames_to_buffer); 165 166 static const unsigned int default_buffer_size; 167 static const unsigned int ticks_per_frame_90kHz; 168 unsigned int num_frames; 169 170 /* State variables for scanning source bit-stream */ 171 unsigned int stream_num; 172 unsigned int samples_per_second; 173 unsigned int channels; 174 unsigned int bits_per_sample; 175 unsigned int bytes_per_frame; 176 unsigned int frame_index; 177 unsigned int dynamic_range_code; 178 LpcmParams *parms; 179 }; 180 181 class SUBPStream : public AudioStream 182 { 183 public: 184 SUBPStream(IBitStream &ibs,Multiplexor &into ); 185 virtual void Init(const int stream_num); 186 virtual void Close(); 187 // TODO: rough and ready measure... NominalBitRate()188 virtual unsigned int NominalBitRate() {return 50*1024;} 189 virtual unsigned int ReadPacketPayload(uint8_t *dst, unsigned int to_read); StreamHeaderSize()190 virtual unsigned int StreamHeaderSize() { return 1; } 191 192 193 private: 194 void OutputHdrInfo(); 195 virtual void FillAUbuffer(unsigned int frames_to_buffer); 196 197 static const unsigned int default_buffer_size; 198 199 /* State variables for scanning source bit-stream */ 200 unsigned int framesize; 201 unsigned int samples_per_second; 202 unsigned int bit_rate; 203 unsigned int stream_num; 204 unsigned int frequency ; 205 unsigned int num_frames; 206 }; 207 208 209 #endif // __AUDIOSTRM_H__ 210 211 212 /* 213 * Local variables: 214 * c-file-style: "stroustrup" 215 * tab-width: 4 216 * indent-tabs-mode: nil 217 * End: 218 */ 219