MP3Parser.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: MP3Parser.hpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #if !defined(AFX_MP3PARSER_HPP__E08F3107_12A3_4E12_8A7F_63B15BE916FF__INCLUDED_) 00045 #define AFX_MP3PARSER_HPP__E08F3107_12A3_4E12_8A7F_63B15BE916FF__INCLUDED_ 00046 00047 #if _MSC_VER > 1000 00048 #pragma once 00049 #endif // _MSC_VER > 1000 00050 00051 00052 #include "string.h" 00053 #include "AudioAdaptor.hpp" 00054 #ifdef ISOMP4 00055 #include "ISOMovies.h" 00056 #endif 00057 00069 enum MpegAudioVersionID { 00070 MPEG_VESION_2_5, 00071 RESERVED, 00072 MPEG_VERSION_2, 00073 MPEG_VERSION_1, 00074 }; 00075 00076 enum MpegAudioLayerNo { 00077 RESERVed, 00078 LAYER_III, 00079 LAYER_II, 00080 LAYER_I, 00081 }; 00082 00083 enum ChannelMod { 00084 STEREO, 00085 JOINT_STEREO, 00086 DUAL_CHANNEL, 00087 SINGLE_CHANNEL, 00088 }; 00089 00090 enum Emphasis { 00091 NONE_, 00092 MS5015, 00093 RESERVEd, 00094 CCIT_J_17, 00095 }; 00096 00101 typedef struct { 00102 /* Frame sync is the Mpeg audio Frame Header Startcode*/ 00103 int frame_sync; 00104 /* MPEG Audio version ID 00105 00 - MPEG Version 2.5 00106 01 - reserved 00107 10 - MPEG Version 2 (ISO/IEC 13818-3) 00108 11 - MPEG Version 1 (ISO/IEC 11172-3) */ 00109 enum MpegAudioVersionID mpeg_audio_version_ID; 00110 /* Layer description 00111 00 - reserved 00112 01 - Layer III 00113 10 - Layer II 00114 11 - Layer I */ 00115 enum MpegAudioLayerNo mpeg_audio_layer_no; 00116 /*Protection bit 00117 0 - Protected by CRC (16bit crc follows header) 00118 1 - Not protected */ 00119 bool protection; 00120 /*Bitrate index 00121 NOTE: bitrate in kbps 00122 see Bitrate index Table */ 00123 unsigned int bitrate; 00124 /* Bitrate index Table 00125 bitrate is obtainded by mapping into this table */ 00126 unsigned int mpeg_audio_bitrate_index_table[80]; 00127 /* Sampling rate frequency index (values are in Hz) 00128 see Sampling rate frequency Table*/ 00129 unsigned int sampling_rate; 00130 /* Duration of a frame in mediaTimeScale units 00131 * this is not obtained from header but calculated from other values 00132 */ 00133 unsigned int frame_duration; 00134 /* bits per sample of the uncompressed WAV frame */ 00135 unsigned int bits_per_sample; 00136 /* Sampling rate frequency Table 00137 */ 00138 unsigned int mpeg_audio_sampling_rate_index_table[12]; 00139 /* Padding bit 00140 0 - frame is not padded 00141 1 - frame is padded with one extra slot */ 00142 bool padding; 00143 /* calculate frame size 00144 */ 00145 unsigned int frame_size_in_bytes; 00146 /* Private bit. It may be freely used for specific needs of an application, 00147 i.e. if it has to trigger some application specific events.*/ 00148 bool private_bit; 00149 /* Channel Mode 00150 00 - Stereo 00151 01 - Joint stereo (Stereo) 00152 10 - Dual channel (Stereo) 00153 11 - Single channel (Mono) */ 00154 enum ChannelMod channel_mod; 00155 /* Mode extension (Only if Joint stereo) 00156 */ 00157 unsigned int mode_extension; 00158 /* Copyright info 00159 0 - Audio is not copyrighted 00160 1 - Audio is copyrighted*/ 00161 bool copyright; 00162 /* Original 00163 0 - Copy of original media 00164 1 - Original media */ 00165 bool original; 00166 /* Emphasis 00167 00 - none 00168 01 - 50/15 ms 00169 10 - reserved 00170 11 - CCIT J.17 */ 00171 enum Emphasis emphasis; 00172 00173 } structMPEGaudioHeader; 00174 00175 00176 class MP3Parser { 00177 public: 00178 MP3Parser(); 00182 virtual ~ MP3Parser(); 00183 00184 structMPEGaudioHeader parseMPEGaudioHeader(u8 * pFramem, u32 iSize); 00185 00186 00187 private: 00188 00195 structMPEGaudioHeader mp3Header; 00196 00205 u8 mcByte; 00206 00214 u8 *mpcData; 00215 00222 int miSize; 00223 00232 bool mbEOD; 00240 int miCurrentNoBytes; 00250 int miCurrentBit; 00251 00260 int miBookmarkedCurrentBit; 00261 00269 int miBookmarkedByte; 00270 00278 int miBookmarkedCurrentNoBytes; 00279 00288 void initializeParser(u8 * pFramem, u32 iSize); 00289 00296 void initializeMPEGaudioHeaderStruct(); 00297 00306 void nextByte(); 00307 00314 bool bytealigned(); 00315 00325 int getBit(); 00326 00336 int getBits(int iNumber); 00337 00347 int nextBits(int iNumber); 00348 00352 void nextStartCode(); 00353 00357 void loadQuantizerMatrix(unsigned int puiMatrix[]); 00358 00364 void readMarkerBitFunc(int iLine); 00365 00370 void bookmark(); 00371 00376 void restore(); 00377 00378 }; 00379 00380 #endif // !defined(AFX_MP4DECODER_HPP__E08F3107_12A3_4E12_8A7F_63B15BE916FF__INCLUDED_)