MP4audioDecoder.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: MP4audioDecoder.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_MP4AUDIODECODER_HPP__E08F3107_12A3_4E12_8A7F_63B15BE916FF__INCLUDED_) 00045 #define AFX_MP4AUDIODECODER_HPP__E08F3107_12A3_4E12_8A7F_63B15BE916FF__INCLUDED_ 00046 00047 #if _MSC_VER > 1000 00048 #pragma once 00049 #endif // _MSC_VER > 1000 00050 00051 00052 00053 #include "ffmpegInterface.h" 00054 00055 #include "AudioAdaptor.hpp" 00056 #ifdef ISOMP4 00057 #include "ISOMovies.h" 00058 #endif 00059 #include "IO.hpp" 00060 00061 class AudioESInfo; 00062 class YUVFrame; 00063 class Frame; 00064 00065 00076 class MP4audioDecoder:public AudioAdaptor { 00077 public: 00078 enum MpegAudioVersionID { 00079 MPEG_VESION_2_5, 00080 RESERVED, 00081 MPEG_VERSION_2, 00082 MPEG_VERSION_1, 00083 }; 00084 00085 enum MpegAudioLayerNo { 00086 RESERVed, 00087 LAYER_III, 00088 LAYER_II, 00089 LAYER_I, 00090 }; 00091 00092 enum ChannelMod { 00093 STEREO, 00094 JOINT_STEREO, 00095 DUAL_CHANNEL, 00096 SINGLE_CHANNEL, 00097 }; 00098 00099 enum Emphasis { 00100 NONE_, 00101 MS5015, 00102 RESERVEd, 00103 CCIT_J_17, 00104 }; 00105 00106 00110 typedef enum eCoderType{XVID = 1, FFMPEG} meCoderType; 00111 00120 MP4audioDecoder(AudioESInfo * pESInfo, bool enableSwitching, meCoderType coderType= FFMPEG); 00121 00122 00126 virtual ~ MP4audioDecoder(); 00127 00128 static bool isValidAudioFrame(const u8* payload); 00129 static bool isValidDecoderConfig(const u8* payload); 00130 00137 list < Frame * >adapt(Frame * frm); 00138 00144 list < Frame * >close(); 00145 00151 Adaptor *clone(); 00152 00156 void initialize(); 00157 00164 void setCoderType(eCoderType coderType = FFMPEG); 00165 00168 u32 getTranscodingCosts() const{ 00169 return 352*288*25/4; 00170 } 00171 private: 00177 eCoderType meCoder; 00178 00184 void DecoderInit(char **pDecoderHandle, CodecID codecID); 00191 void DecoderClose(char **pDecoderHandle); 00202 int DecodeFrame(char *pDecoderHandle, char *pCompressedFrame, 00203 int iCFSize, char* PCMFrame, u32 *mFrameSize); 00207 char *mpDecoder; 00208 00212 u32 mFrameSize; 00213 00217 char mpBuffer[MAX_FRAME_SIZE]; 00221 int lenDecoded; 00225 uint muiLastFrameStart; 00229 uint muiLastFrameEnd; 00233 u32 muiFrameNumber; 00234 00240 u8* decConfig; 00241 u8* newDecConfig; 00242 u32 decConfigSize; 00245 bool enableSwitching; 00246 00247 00252 typedef struct { 00253 /* Frame sync is the Mpeg audio Frame Header Startcode*/ 00254 int frame_sync; 00255 /* MPEG Audio version ID 00256 00 - MPEG Version 2.5 00257 01 - reserved 00258 10 - MPEG Version 2 (ISO/IEC 13818-3) 00259 11 - MPEG Version 1 (ISO/IEC 11172-3) */ 00260 enum MpegAudioVersionID mpeg_audio_version_ID; 00261 /* Layer description 00262 00 - reserved 00263 01 - Layer III 00264 10 - Layer II 00265 11 - Layer I */ 00266 enum MpegAudioLayerNo mpeg_audio_layer_no; 00267 /*Protection bit 00268 0 - Protected by CRC (16bit crc follows header) 00269 1 - Not protected */ 00270 bool protection; 00271 /*Bitrate index 00272 NOTE: bitrate in kbps 00273 see Bitrate index Table */ 00274 unsigned int bitrate; 00275 /* Bitrate index Table 00276 bitrate is obtainded by mapping into this table */ 00277 unsigned int mpeg_audio_bitrate_index_table[80]; 00278 /* Sampling rate frequency index (values are in Hz) 00279 see Sampling rate frequency Table*/ 00280 unsigned int sampling_rate; 00281 /* Sampling rate frequency Table 00282 */ 00283 unsigned int mpeg_audio_sampling_rate_index_table[12]; 00284 /* Padding bit 00285 0 - frame is not padded 00286 1 - frame is padded with one extra slot */ 00287 bool padding; 00288 /* calculate frame size 00289 */ 00290 unsigned int frame_size_in_bytes; 00291 /* Private bit. It may be freely used for specific needs of an application, 00292 i.e. if it has to trigger some application specific events.*/ 00293 bool private_bit; 00294 /* Channel Mode 00295 00 - Stereo 00296 01 - Joint stereo (Stereo) 00297 10 - Dual channel (Stereo) 00298 11 - Single channel (Mono) */ 00299 enum ChannelMod channel_mod; 00300 /* Mode extension (Only if Joint stereo) 00301 */ 00302 unsigned int mode_extension; 00303 /* Copyright info 00304 0 - Audio is not copyrighted 00305 1 - Audio is copyrighted*/ 00306 bool copyright; 00307 /* Original 00308 0 - Copy of original media 00309 1 - Original media */ 00310 bool original; 00311 /* Emphasis 00312 00 - none 00313 01 - 50/15 ms 00314 10 - reserved 00315 11 - CCIT J.17 */ 00316 enum Emphasis emphasis; 00317 00318 } structMPEGaudioHeader; 00319 00326 structMPEGaudioHeader mp4AudioHeader; 00327 00336 u8 mcByte; 00344 u8 *mpcData; 00351 int miSize; 00359 bool mbEOD; 00366 int miCurrentNoBytes; 00376 int miCurrentBit; 00385 int miBookmarkedCurrentBit; 00393 int miBookmarkedByte; 00401 int miBookmarkedCurrentNoBytes; 00402 00411 void initializeParser(u8 * pFramem, u32 iSize); 00418 void initializeMPEGaudioHeaderStruct(); 00427 void nextByte(); 00434 bool bytealigned(); 00444 int getBit(); 00454 int getBits(int iNumber); 00464 int nextBits(int iNumber); 00468 void nextStartCode(); 00469 00473 void loadQuantizerMatrix(unsigned int puiMatrix[]); 00474 00480 void readMarkerBitFunc(int iLine); 00485 void bookmark(); 00490 void restore(); 00491 00492 bool video_signal_type_func(); 00497 bool parseMPEGaudioHeader(u8 * pFramem, u32 iSize); 00498 00499 }; 00500 00501 #endif // !defined(AFX_MP4DECODER_HPP__E08F3107_12A3_4E12_8A7F_63B15BE916FF__INCLUDED_)