MP4audioDecoder Class Reference

<short description=""> More...

#include <MP4audioDecoder.hpp>

Inheritance diagram for MP4audioDecoder:

AudioAdaptor Adaptor List of all members.

Public Types

typedef enum MP4audioDecoder::eCoderType meCoderType
 Codec selection enumeration, currently available is FFMPEG only.
enum  MpegAudioVersionID { MPEG_VESION_2_5, RESERVED, MPEG_VERSION_2, MPEG_VERSION_1 }
enum  MpegAudioLayerNo { RESERVed, LAYER_III, LAYER_II, LAYER_I }
enum  ChannelMod { STEREO, JOINT_STEREO, DUAL_CHANNEL, SINGLE_CHANNEL }
enum  Emphasis { NONE_, MS5015, RESERVEd, CCIT_J_17 }
enum  eCoderType { XVID = 1, FFMPEG }
 Codec selection enumeration, currently available is FFMPEG only.

Public Member Functions

 MP4audioDecoder (AudioESInfo *pESInfo, bool enableSwitching, meCoderType coderType=FFMPEG)
 Creates an uninitialized MP4audioDecoder instance.
virtual ~MP4audioDecoder ()
 Destroys the MP4audioDecoder.
list< Frame * > adapt (Frame *frm)
 Compressed frm in - uncompressed PCM frame out.
list< Frame * > close ()
 Flush all buffered uncompressed Frame objects (if any).
Adaptorclone ()
 Not implemented.
void initialize ()
 Initializes the Decoder.
void setCoderType (eCoderType coderType=FFMPEG)
 Codec selection.
u32 getTranscodingCosts () const
 returns adaptation costs (CPU only).

Static Public Member Functions

bool isValidAudioFrame (const u8 *payload)
bool isValidDecoderConfig (const u8 *payload)

Detailed Description

<short description="">

Author:
Mithilesh Kumar
Version:
Id
MP4audioDecoder.hpp,v 1.10 2005/04/28 08:55:47 mkropfbe Exp

Definition at line 76 of file MP4audioDecoder.hpp.


Constructor & Destructor Documentation

MP4audioDecoder::MP4audioDecoder AudioESInfo *  pESInfo,
bool  enableSwitching,
meCoderType  coderType = FFMPEG
 

Creates an uninitialized MP4audioDecoder instance.

Parameters:
pESInfo Pointer to ESInfo containing VOS/VO/VOL headers
enableSwitching specifies if the decoder should reinit itself, when a new header is detected. set to false in the server, set to true in the client
coderType audio codec to use.
See also:
setCoderType
Definition at line 90 of file MP4audioDecoder.cpp.

References meCoderType.

Referenced by clone().

00090 { 00091 mpDecoder = NULL; 00092 this->enableSwitching=enableSwitching; 00093 es = pESInfo; 00094 mFrameSize = 0; 00095 decConfig=NULL; 00096 decConfigSize=0; 00097 newDecConfig=NULL; 00098 meCoder = coderType; 00099 initialized = false; 00100 strcpy(name,"MP4audioDecoder"); 00101 }


Member Function Documentation

list< Frame * > MP4audioDecoder::adapt Frame frm  )  [virtual]
 

Compressed frm in - uncompressed PCM frame out.

Parameters:
frm Pointer to compressed Frame
Returns:
List of YUVFrame objects

Reimplemented from Adaptor.

Definition at line 212 of file MP4audioDecoder.cpp.

References Frame::getAU(), initialize(), and Frame::setAU().

00212 { 00213 if(es && enableSwitching) { 00214 if(decConfigSize>0) { 00215 if(newDecConfig) { 00216 delete[] newDecConfig; 00217 newDecConfig=NULL; 00218 } 00219 00220 u32 nSize=es->getHeaders(&newDecConfig); 00221 if(nSize != 0 && nSize != decConfigSize) { 00222 // we have a new decConfig 00223 if(decConfig) 00224 delete[] decConfig; 00225 decConfig=newDecConfig; 00226 newDecConfig=NULL; 00227 initialized=false; 00228 } 00229 else if(nSize == decConfigSize) { 00230 // same size but might be different 00231 if(memcmp(decConfig,newDecConfig,decConfigSize)!=0) { 00232 // is different 00233 if(decConfig) 00234 delete[] decConfig; 00235 decConfig=newDecConfig; 00236 newDecConfig=NULL; 00237 initialized=false; 00238 } 00239 } 00240 } 00241 } 00242 00243 if (!initialized) 00244 initialize(); 00245 00246 list < Frame * >frmList; 00247 if (!initialized) 00248 return frmList; 00249 00250 muiFrameNumber++; 00251 00252 #ifndef WINCE 00253 if (dec != NULL) { 00254 #endif //wince 00255 if (DecodeFrame((char *) mpDecoder, (char *) frm->getAU()->payload, frm->getAU()->size, 00256 (char *) mpBuffer, &mFrameSize) <= 0) { 00257 u8 *pload = frm->getAU()->payload; 00258 dprintf_err("MP4audioDecoder::adapt Error decoding frame %d\n", muiFrameNumber); 00259 dprintf_full("MP4audioDecoder::adapt %i %i %i %i\r\n", 00260 pload[0], pload[1],pload[2],pload[3]); 00261 } else { 00262 AU * pAU = new AU(frm->getAU()); 00263 pAU->size = mFrameSize; 00264 pAU->payload = new u8[mFrameSize]; 00265 memcpy(pAU->payload, mpBuffer, mFrameSize); 00266 dprintf_full("MP4audioDecoder::adapt Decode Frame No %d uncompressed size %d\n", 00267 muiFrameNumber, pAU->size); 00268 UncompressedAudioFrame* wavFrame = new UncompressedAudioFrame(Frame::RAW_AUDIO); 00269 wavFrame->setAU(pAU); 00270 frmList.push_back(wavFrame); 00271 } 00272 #ifndef WINCE 00273 } 00274 #endif //wince 00275 return frmList; 00276 }

Adaptor * MP4audioDecoder::clone  )  [virtual]
 

Not implemented.

Returns:
Defaults to NULL.

Implements Adaptor.

Definition at line 293 of file MP4audioDecoder.cpp.

References MP4audioDecoder().

00293 { 00294 return new MP4audioDecoder(es,enableSwitching,meCoder); 00295 }

list< Frame * > MP4audioDecoder::close  )  [virtual]
 

Flush all buffered uncompressed Frame objects (if any).

Returns:
List of YUVFrame objects

Reimplemented from Adaptor.

Definition at line 279 of file MP4audioDecoder.cpp.

00279 { 00280 list < Frame * >frmList; 00281 if (!initialized) 00282 return frmList; 00283 00284 if (initialized) { 00285 DecoderClose((char **) (&mpDecoder)); 00286 initialized = false; 00287 } 00288 00289 return frmList; 00290 }

u32 MP4audioDecoder::getTranscodingCosts  )  const [inline, virtual]
 

returns adaptation costs (CPU only).

How high are audio decoding costs? assume 25% of CIF video with 25 fps (FIXME: measure it)

Implements Adaptor.

Definition at line 168 of file MP4audioDecoder.hpp.

00168 { 00169 return 352*288*25/4; 00170 }

void MP4audioDecoder::initialize  )  [virtual]
 

Initializes the Decoder.

Implements Adaptor.

Definition at line 114 of file MP4audioDecoder.cpp.

Referenced by adapt().

00114 { 00115 if (!es) { 00116 initialized = false; 00117 return; 00118 } 00119 if(initialized) 00120 return; 00121 00122 mpDecoder = NULL; 00123 muiFrameNumber = 0; 00124 muiLastFrameStart = 0; 00125 muiLastFrameEnd = 0; 00126 decConfig=NULL; 00127 decConfigSize=0; 00128 newDecConfig=NULL; 00129 00130 muiLastFrameEnd = es->getHeaders(&decConfig); 00131 decConfigSize=muiLastFrameEnd; 00132 00133 if (decConfigSize > sizeof(mpBuffer)) { 00134 dprintf_err("MP4audioDecoder::initialize() decConfigSize %u > sizeof(mpBuffer) %u " 00135 "-- initialization FAILED!\n", decConfigSize, sizeof(mpBuffer)); 00136 return; 00137 } 00138 memcpy(mpBuffer,decConfig,decConfigSize); 00139 00140 00141 dprintf_full("MP4audioDecoder::initialize() %s\r\n",es->getEncodedDecoderConfig()); 00142 #ifdef VITOOKI_DEBUG 00143 for(uint i=0;i<(muiLastFrameEnd/4)||i<30;i+=4) { 00144 int res =0; 00145 for(int j = 0; j < 4; j++) { 00146 res = (res << 8) | mpBuffer[j+i]; 00147 } 00148 dprintf_full("%x ", res); 00149 } 00150 dprintf("\r\n"); 00151 fflush(stdout); 00152 #endif 00153 00154 #if VITOOKI_DEBUG_LEVEL >= 2 00155 dprintf_full("MP4audioDecoder::initialize:: "); 00156 for (uint iiii = 0; iiii < muiLastFrameEnd; iiii++) 00157 dprintf_full("%x", mpBuffer[iiii]); 00158 dprintf("\n"); 00159 #endif /* */ 00160 00161 if (muiLastFrameEnd == 0) { 00162 dprintf_err("MP4audioDecoder::initialize: failed to get header for ESInfo object\n"); 00163 } 00164 //initializeMPEGaudioHeaderStruct(); 00165 //initializeParser((u8 *) mpBuffer, muiLastFrameEnd); 00166 /* No need to parse the mp3 header as not a single information is required right now 00167 * we get it all from ffmpeg 00168 * HOWEVER if there are some errors in bitrate, channels etc then uncomment the following two line and 00169 * set the parameters in the "else" portion... and ONLY for #ifndef ISOMP4 00170 */ 00171 if (!parseMPEGaudioHeader((u8 *) mpBuffer, muiLastFrameEnd)) 00172 dprintf_small("MP4audioDecoder::initialize : No Audio Frame Header found\n"); 00173 00174 DecoderInit((char **) (&mpDecoder), es->getCodecID()); 00175 dprintf_small("MP4audioDecoder::initialize : Audio Decoder initialized \n"); 00176 00177 if (mpDecoder == NULL) { 00178 dprintf_err("MP4audioDecoder::initialize: Error creating decoder handle\n"); 00179 exit(-1); 00180 } 00181 else 00182 { 00183 #ifndef ISOMP4 00184 es->setMediaTimeScale(90000); 00185 if(mp4AudioHeader.sampling_rate>0) 00186 es->setSampleRate(mp4AudioHeader.sampling_rate); 00187 else { 00188 dprintf_err("MP4AudioDecoder::initialize: Wrong sampling rate for audio in %s\n",es->getContainerInfo()->getLocalFile()); 00189 es->setSampleRate(44100); 00190 } 00191 dprintf_full("MP4AudioDecoder::initialize: using sampling rate %i Hz\n",es->getSampleRate()); 00192 00193 ((AudioESInfo*)es)->setChannelMod(mp4AudioHeader.channel_mod); 00194 if(mp4AudioHeader.channel_mod == 3) 00195 es->setAudioChannels(1); 00196 else 00197 es->setAudioChannels(2); 00198 ((AudioESInfo*)es)->setAvgBandwidth(mp4AudioHeader.bitrate*1000); 00199 //es->setMaxBandwidth(mp4AudioHeader.bitrate*1000*3/2); //MAXBANDWIDTH for audio is 1.5 times AVGBANDWIDTH 00200 //es->setDuration((((es->getOrigMediaSize()*8)/(mp4AudioHeader.bitrate*1000))*mp4AudioHeader.sampling_rate)); 00201 //Process ONLY colorspaces definded in MP4audioDecoder.hpp 00202 #endif 00203 00204 mFrameSize = 4608; //XXX give it the appropiate value 00205 dprintf_full("MP4audioDecoder::initialize: Esinfo %llu BufferSize %i \n", 00206 es->getStreamId(), es->getBufferSize()); 00207 } 00208 initialized = true; 00209 }

void MP4audioDecoder::setCoderType eCoderType  coderType = FFMPEG  ) 
 

Codec selection.

Parameters:
coderType Type of codec to use. Defaults to FFMPEG
See also:
meCoderType
Definition at line 565 of file MP4audioDecoder.cpp.
00565 { 00566 meCoder = coderType; 00567 }


The documentation for this class was generated from the following files: