00001
00030 #include <omxcore.h>
00031 #include <omx_base_audio_port.h>
00032 #include <omx_audiodec_component.h>
00034 #include<OMX_Audio.h>
00035
00036
00037 #include <config.h>
00038
00039 #define MAX_COMPONENT_AUDIODEC 4
00040
00042 #define OUTPUT_LEN_STANDARD_FFMPEG 192000
00043
00045 static OMX_U32 noAudioDecInstance=0;
00046
00049 OMX_ERRORTYPE omx_audiodec_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName) {
00050
00051 OMX_ERRORTYPE err = OMX_ErrorNone;
00052 omx_audiodec_component_PrivateType* omx_audiodec_component_Private;
00053 OMX_U32 i;
00054
00055 if (!openmaxStandComp->pComponentPrivate) {
00056 DEBUG(DEB_LEV_FUNCTION_NAME,"In %s, allocating component\n",__func__);
00057 openmaxStandComp->pComponentPrivate = calloc(1, sizeof(omx_audiodec_component_PrivateType));
00058 if(openmaxStandComp->pComponentPrivate==NULL)
00059 return OMX_ErrorInsufficientResources;
00060 }
00061 else
00062 DEBUG(DEB_LEV_FUNCTION_NAME,"In %s, Error Component %x Already Allocated\n",__func__, (int)openmaxStandComp->pComponentPrivate);
00063
00064 omx_audiodec_component_Private = openmaxStandComp->pComponentPrivate;
00065 omx_audiodec_component_Private->ports = NULL;
00066
00068 err = omx_base_filter_Constructor(openmaxStandComp,cComponentName);
00069
00071 if (omx_audiodec_component_Private->sPortTypesParam.nPorts && !omx_audiodec_component_Private->ports) {
00072 omx_audiodec_component_Private->ports = calloc(omx_audiodec_component_Private->sPortTypesParam.nPorts, sizeof(omx_base_PortType *));
00073 if (!omx_audiodec_component_Private->ports) {
00074 return OMX_ErrorInsufficientResources;
00075 }
00076 for (i=0; i < omx_audiodec_component_Private->sPortTypesParam.nPorts; i++) {
00077 omx_audiodec_component_Private->ports[i] = calloc(1, sizeof(omx_base_audio_PortType));
00078 if (!omx_audiodec_component_Private->ports[i]) {
00079 return OMX_ErrorInsufficientResources;
00080 }
00081 }
00082 }
00083
00084 base_audio_port_Constructor(openmaxStandComp, &omx_audiodec_component_Private->ports[0], 0, OMX_TRUE);
00085 base_audio_port_Constructor(openmaxStandComp, &omx_audiodec_component_Private->ports[1], 1, OMX_FALSE);
00086
00088
00089
00090 omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.nBufferSize = DEFAULT_IN_BUFFER_SIZE;
00091
00092 omx_audiodec_component_Private->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
00093 omx_audiodec_component_Private->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
00094
00095
00096 if(!strcmp(cComponentName, AUDIO_DEC_MP3_NAME))
00097 omx_audiodec_component_Private->audio_coding_type = OMX_AUDIO_CodingMP3;
00098
00099 else if(!strcmp(cComponentName, AUDIO_DEC_VORBIS_NAME))
00100 omx_audiodec_component_Private->audio_coding_type = OMX_AUDIO_CodingVORBIS;
00101
00102 else if(!strcmp(cComponentName, AUDIO_DEC_AAC_NAME))
00103 omx_audiodec_component_Private->audio_coding_type = OMX_AUDIO_CodingAAC;
00104
00105 else if (!strcmp(cComponentName, AUDIO_DEC_BASE_NAME))
00106 omx_audiodec_component_Private->audio_coding_type = OMX_AUDIO_CodingUnused;
00107
00108 else
00109 return OMX_ErrorInvalidComponentName;
00110
00111 if(!omx_audiodec_component_Private->avCodecSyncSem) {
00112 omx_audiodec_component_Private->avCodecSyncSem = calloc(1,sizeof(tsem_t));
00113 if(omx_audiodec_component_Private->avCodecSyncSem == NULL) return OMX_ErrorInsufficientResources;
00114 tsem_init(omx_audiodec_component_Private->avCodecSyncSem, 0);
00115 }
00116
00117 omx_audiodec_component_SetInternalParameters(openmaxStandComp);
00118
00119
00120
00121 setHeader(&omx_audiodec_component_Private->pAudioPcmMode,sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00122 omx_audiodec_component_Private->pAudioPcmMode.nPortIndex = 1;
00123 omx_audiodec_component_Private->pAudioPcmMode.nChannels = 2;
00124 omx_audiodec_component_Private->pAudioPcmMode.eNumData = OMX_NumericalDataSigned;
00125 omx_audiodec_component_Private->pAudioPcmMode.eEndian = OMX_EndianLittle;
00126 omx_audiodec_component_Private->pAudioPcmMode.bInterleaved = OMX_TRUE;
00127 omx_audiodec_component_Private->pAudioPcmMode.nBitPerSample = 16;
00128 omx_audiodec_component_Private->pAudioPcmMode.nSamplingRate = 44100;
00129 omx_audiodec_component_Private->pAudioPcmMode.ePCMMode = OMX_AUDIO_PCMModeLinear;
00130 omx_audiodec_component_Private->pAudioPcmMode.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
00131 omx_audiodec_component_Private->pAudioPcmMode.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
00132
00133
00134
00135 omx_audiodec_component_Private->avCodec = NULL;
00136 omx_audiodec_component_Private->avCodecContext= NULL;
00137 omx_audiodec_component_Private->avcodecReady = OMX_FALSE;
00138 omx_audiodec_component_Private->extradata = NULL;
00139 omx_audiodec_component_Private->extradata_size = 0;
00140
00141 omx_audiodec_component_Private->BufferMgmtCallback = omx_audiodec_component_BufferMgmtCallback;
00142
00144 avcodec_init();
00145 av_register_all();
00146 omx_audiodec_component_Private->avCodecContext = avcodec_alloc_context();
00147
00148 omx_audiodec_component_Private->messageHandler = omx_audiodec_component_MessageHandler;
00149 omx_audiodec_component_Private->destructor = omx_audiodec_component_Destructor;
00150 openmaxStandComp->SetParameter = omx_audiodec_component_SetParameter;
00151 openmaxStandComp->GetParameter = omx_audiodec_component_GetParameter;
00152 openmaxStandComp->SetConfig = omx_audiodec_component_SetConfig;
00153 openmaxStandComp->ComponentRoleEnum = omx_audiodec_component_ComponentRoleEnum;
00154 openmaxStandComp->GetExtensionIndex = omx_audiodec_component_GetExtensionIndex;
00155
00156 noAudioDecInstance++;
00157
00158 if(noAudioDecInstance>MAX_COMPONENT_AUDIODEC)
00159 return OMX_ErrorInsufficientResources;
00160
00161 return err;
00162 }
00163
00166 OMX_ERRORTYPE omx_audiodec_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp)
00167 {
00168 omx_audiodec_component_PrivateType* omx_audiodec_component_Private = openmaxStandComp->pComponentPrivate;
00169 OMX_U32 i;
00170
00171 if(omx_audiodec_component_Private->extradata) {
00172 free(omx_audiodec_component_Private->extradata);
00173 }
00174
00175
00176 av_free (omx_audiodec_component_Private->avCodecContext);
00177
00178 if(omx_audiodec_component_Private->avCodecSyncSem) {
00179 tsem_deinit(omx_audiodec_component_Private->avCodecSyncSem);
00180 free(omx_audiodec_component_Private->avCodecSyncSem);
00181 omx_audiodec_component_Private->avCodecSyncSem=NULL;
00182 }
00183
00184
00185 if (omx_audiodec_component_Private->ports) {
00186 for (i=0; i < omx_audiodec_component_Private->sPortTypesParam.nPorts; i++) {
00187 if(omx_audiodec_component_Private->ports[i])
00188 omx_audiodec_component_Private->ports[i]->PortDestructor(omx_audiodec_component_Private->ports[i]);
00189 }
00190 free(omx_audiodec_component_Private->ports);
00191 omx_audiodec_component_Private->ports=NULL;
00192 }
00193
00194 DEBUG(DEB_LEV_FUNCTION_NAME, "Destructor of audiodecoder component is called\n");
00195
00196 omx_base_filter_Destructor(openmaxStandComp);
00197
00198 noAudioDecInstance--;
00199
00200 return OMX_ErrorNone;
00201 }
00202
00206 OMX_ERRORTYPE omx_audiodec_component_ffmpegLibInit(omx_audiodec_component_PrivateType* omx_audiodec_component_Private) {
00207 OMX_U32 target_codecID;
00208
00209 DEBUG(DEB_LEV_SIMPLE_SEQ, "FFMpeg Library/codec iniited\n");
00210
00211 switch(omx_audiodec_component_Private->audio_coding_type){
00212 case OMX_AUDIO_CodingMP3 :
00213 target_codecID = CODEC_ID_MP3;
00214 break;
00215 case OMX_AUDIO_CodingVORBIS :
00216 target_codecID = CODEC_ID_VORBIS;
00217 break;
00218 case OMX_AUDIO_CodingAAC :
00219 target_codecID = CODEC_ID_AAC;
00220 break;
00221 default :
00222 DEBUG(DEB_LEV_ERR, "Audio format other than not supported\nCodec not found\n");
00223 return OMX_ErrorComponentNotFound;
00224 }
00225
00226
00227 omx_audiodec_component_Private->avCodec = avcodec_find_decoder(target_codecID);
00228 if (omx_audiodec_component_Private->avCodec == NULL) {
00229 DEBUG(DEB_LEV_ERR, "Codec Not found\n");
00230 return OMX_ErrorInsufficientResources;
00231 }
00232
00233 omx_audiodec_component_Private->avCodecContext->extradata = omx_audiodec_component_Private->extradata;
00234 omx_audiodec_component_Private->avCodecContext->extradata_size = (int)omx_audiodec_component_Private->extradata_size;
00235
00236
00237 if (avcodec_open(omx_audiodec_component_Private->avCodecContext, omx_audiodec_component_Private->avCodec) < 0) {
00238 DEBUG(DEB_LEV_ERR, "Could not open codec\n");
00239 return OMX_ErrorInsufficientResources;
00240 }
00241
00242
00243
00244 omx_audiodec_component_Private->avCodecContext->flags |= CODEC_FLAG_EMU_EDGE;
00245 omx_audiodec_component_Private->avCodecContext->workaround_bugs |= FF_BUG_AUTODETECT;
00246
00247 tsem_up(omx_audiodec_component_Private->avCodecSyncSem);
00248 DEBUG(DEB_LEV_SIMPLE_SEQ, "done\n");
00249 return OMX_ErrorNone;
00250 }
00251
00255 void omx_audiodec_component_ffmpegLibDeInit(omx_audiodec_component_PrivateType* omx_audiodec_component_Private) {
00256
00257 avcodec_close(omx_audiodec_component_Private->avCodecContext);
00258 omx_audiodec_component_Private->extradata_size = 0;
00259
00260 }
00261
00262 void omx_audiodec_component_SetInternalParameters(OMX_COMPONENTTYPE *openmaxStandComp) {
00263 omx_audiodec_component_PrivateType* omx_audiodec_component_Private;
00264 omx_base_audio_PortType *pPort;
00265
00266 omx_audiodec_component_Private = openmaxStandComp->pComponentPrivate;
00267
00268 pPort = (omx_base_audio_PortType *) omx_audiodec_component_Private->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
00269
00270 pPort->sAudioParam.eEncoding = OMX_AUDIO_CodingPCM;
00271
00272 if (omx_audiodec_component_Private->audio_coding_type == OMX_AUDIO_CodingMP3) {
00273 strcpy(omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.format.audio.cMIMEType, "audio/mpeg");
00274 omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingMP3;
00275
00276 setHeader(&omx_audiodec_component_Private->pAudioMp3,sizeof(OMX_AUDIO_PARAM_MP3TYPE));
00277 omx_audiodec_component_Private->pAudioMp3.nPortIndex = 0;
00278 omx_audiodec_component_Private->pAudioMp3.nChannels = 2;
00279 omx_audiodec_component_Private->pAudioMp3.nBitRate = 28000;
00280 omx_audiodec_component_Private->pAudioMp3.nSampleRate = 44100;
00281 omx_audiodec_component_Private->pAudioMp3.nAudioBandWidth = 0;
00282 omx_audiodec_component_Private->pAudioMp3.eChannelMode = OMX_AUDIO_ChannelModeStereo;
00283
00284 setHeader(&omx_audiodec_component_Private->pAudioMp3, sizeof(OMX_AUDIO_PARAM_MP3TYPE));
00285 omx_audiodec_component_Private->pAudioMp3.nPortIndex=0;
00286 omx_audiodec_component_Private->pAudioMp3.eFormat=OMX_AUDIO_MP3StreamFormatMP1Layer3;
00287
00288 pPort = (omx_base_audio_PortType *) omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
00289
00290 pPort->sAudioParam.nIndex = OMX_IndexParamAudioMp3;
00291 pPort->sAudioParam.eEncoding = OMX_AUDIO_CodingMP3;
00292 } else if(omx_audiodec_component_Private->audio_coding_type == OMX_AUDIO_CodingVORBIS) {
00293 strcpy(omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.format.audio.cMIMEType, "audio/vorbis");
00294 omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingVORBIS;
00295
00296 setHeader(&omx_audiodec_component_Private->pAudioVorbis,sizeof(OMX_AUDIO_PARAM_VORBISTYPE));
00297 omx_audiodec_component_Private->pAudioVorbis.nPortIndex = 0;
00298 omx_audiodec_component_Private->pAudioVorbis.nChannels = 2;
00299 omx_audiodec_component_Private->pAudioVorbis.nBitRate = 28000;
00300 omx_audiodec_component_Private->pAudioVorbis.nSampleRate = 44100;
00301 omx_audiodec_component_Private->pAudioVorbis.nAudioBandWidth = 0;
00302 omx_audiodec_component_Private->pAudioVorbis.nQuality = 3;
00303
00304 pPort = (omx_base_audio_PortType *) omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
00305
00306 pPort->sAudioParam.nIndex = OMX_IndexParamAudioVorbis;
00307 pPort->sAudioParam.eEncoding = OMX_AUDIO_CodingVORBIS;
00308
00309 } else if(omx_audiodec_component_Private->audio_coding_type == OMX_AUDIO_CodingAAC) {
00310 strcpy(omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.format.audio.cMIMEType, "audio/aac");
00311 omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingAAC;
00312
00313 setHeader(&omx_audiodec_component_Private->pAudioAac,sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
00314 omx_audiodec_component_Private->pAudioAac.nPortIndex = 0;
00315 omx_audiodec_component_Private->pAudioAac.nChannels = 2;
00316 omx_audiodec_component_Private->pAudioAac.nBitRate = 28000;
00317 omx_audiodec_component_Private->pAudioAac.nSampleRate = 44100;
00318 omx_audiodec_component_Private->pAudioAac.nAudioBandWidth = 0;
00319 omx_audiodec_component_Private->pAudioAac.eChannelMode = OMX_AUDIO_ChannelModeStereo;
00320 omx_audiodec_component_Private->pAudioAac.nFrameLength = 0;
00321
00322 pPort = (omx_base_audio_PortType *) omx_audiodec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
00323
00324 pPort->sAudioParam.nIndex = OMX_IndexParamAudioAac;
00325 pPort->sAudioParam.eEncoding = OMX_AUDIO_CodingAAC;
00326
00327 } else {
00328 return;
00329 }
00330 }
00331
00334 OMX_ERRORTYPE omx_audiodec_component_Init(OMX_COMPONENTTYPE *openmaxStandComp)
00335 {
00336 omx_audiodec_component_PrivateType* omx_audiodec_component_Private = openmaxStandComp->pComponentPrivate;
00337 OMX_ERRORTYPE err = OMX_ErrorNone;
00338 OMX_U32 nBufferSize;
00339
00340
00341 omx_audiodec_component_Private->inputCurrBuffer=NULL;
00342 omx_audiodec_component_Private->inputCurrLength=0;
00343 nBufferSize=omx_audiodec_component_Private->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]->sPortParam.nBufferSize * 2;
00344 omx_audiodec_component_Private->internalOutputBuffer = malloc(nBufferSize);
00345 memset(omx_audiodec_component_Private->internalOutputBuffer, 0, nBufferSize);
00346 omx_audiodec_component_Private->positionInOutBuf = 0;
00347 omx_audiodec_component_Private->isNewBuffer=1;
00348
00349 return err;
00350
00351 };
00352
00355 OMX_ERRORTYPE omx_audiodec_component_Deinit(OMX_COMPONENTTYPE *openmaxStandComp) {
00356 omx_audiodec_component_PrivateType* omx_audiodec_component_Private = openmaxStandComp->pComponentPrivate;
00357 OMX_ERRORTYPE err = OMX_ErrorNone;
00358
00359 if (omx_audiodec_component_Private->avcodecReady) {
00360 omx_audiodec_component_ffmpegLibDeInit(omx_audiodec_component_Private);
00361 omx_audiodec_component_Private->avcodecReady = OMX_FALSE;
00362 }
00363
00364 free(omx_audiodec_component_Private->internalOutputBuffer);
00365 omx_audiodec_component_Private->internalOutputBuffer = NULL;
00366
00367 return err;
00368 }
00369
00373 void omx_audiodec_component_BufferMgmtCallback(OMX_COMPONENTTYPE *openmaxStandComp, OMX_BUFFERHEADERTYPE* pInputBuffer, OMX_BUFFERHEADERTYPE* pOutputBuffer)
00374 {
00375 omx_audiodec_component_PrivateType* omx_audiodec_component_Private = openmaxStandComp->pComponentPrivate;
00376 int output_length, len;
00377
00378
00379
00380 if(omx_audiodec_component_Private->isNewBuffer) {
00381 omx_audiodec_component_Private->isNewBuffer = 0;
00382 }
00383 pOutputBuffer->nFilledLen = 0;
00384 pOutputBuffer->nOffset=0;
00386 output_length = OUTPUT_LEN_STANDARD_FFMPEG;
00387 #if FFMPEG_DECODER_VERSION >= 2
00388 len = avcodec_decode_audio2(omx_audiodec_component_Private->avCodecContext,
00389 (short*)(pOutputBuffer->pBuffer),
00390 &output_length,
00391 pInputBuffer->pBuffer,
00392 pInputBuffer->nFilledLen);
00393 #else
00394 len = avcodec_decode_audio(omx_audiodec_component_Private->avCodecContext,
00395 (short*)(pOutputBuffer->pBuffer),
00396 &output_length,
00397 pInputBuffer->pBuffer,
00398 pInputBuffer->nFilledLen);
00399 #endif
00400 if((omx_audiodec_component_Private->pAudioPcmMode.nSamplingRate != omx_audiodec_component_Private->avCodecContext->sample_rate) ||
00401 ( omx_audiodec_component_Private->pAudioPcmMode.nChannels!=omx_audiodec_component_Private->avCodecContext->channels)) {
00402 DEBUG(DEB_LEV_FULL_SEQ, "---->Sending Port Settings Change Event\n");
00403
00404
00405 switch(omx_audiodec_component_Private->audio_coding_type) {
00406
00407 case OMX_AUDIO_CodingMP3 :
00408
00409 omx_audiodec_component_Private->pAudioMp3.nChannels = omx_audiodec_component_Private->avCodecContext->channels;
00410 omx_audiodec_component_Private->pAudioMp3.nBitRate = omx_audiodec_component_Private->avCodecContext->bit_rate;
00411 omx_audiodec_component_Private->pAudioMp3.nSampleRate = omx_audiodec_component_Private->avCodecContext->sample_rate;
00412 break;
00413 case OMX_AUDIO_CodingVORBIS:
00414 omx_audiodec_component_Private->pAudioVorbis.nChannels = omx_audiodec_component_Private->avCodecContext->channels;
00415 omx_audiodec_component_Private->pAudioVorbis.nSampleRate = omx_audiodec_component_Private->avCodecContext->sample_rate;
00416 break;
00417 case OMX_AUDIO_CodingAAC :
00418
00419 omx_audiodec_component_Private->pAudioAac.nChannels = omx_audiodec_component_Private->avCodecContext->channels;
00420 omx_audiodec_component_Private->pAudioAac.nBitRate = omx_audiodec_component_Private->avCodecContext->bit_rate;
00421 omx_audiodec_component_Private->pAudioAac.nSampleRate = omx_audiodec_component_Private->avCodecContext->sample_rate;
00422 omx_audiodec_component_Private->pAudioAac.eAACStreamFormat = OMX_AUDIO_AACStreamFormatRAW;
00423 switch(omx_audiodec_component_Private->avCodecContext->profile){
00424 case FF_PROFILE_AAC_MAIN:
00425 omx_audiodec_component_Private->pAudioAac.eAACProfile = OMX_AUDIO_AACObjectMain;
00426 break;
00427 case FF_PROFILE_AAC_LOW:
00428 omx_audiodec_component_Private->pAudioAac.eAACProfile = OMX_AUDIO_AACObjectLC;
00429 break;
00430 case FF_PROFILE_AAC_SSR:
00431 omx_audiodec_component_Private->pAudioAac.eAACProfile = OMX_AUDIO_AACObjectSSR;
00432 break;
00433 case FF_PROFILE_AAC_LTP:
00434 omx_audiodec_component_Private->pAudioAac.eAACProfile = OMX_AUDIO_AACObjectLTP;
00435 break;
00436 case FF_PROFILE_UNKNOWN:
00437 omx_audiodec_component_Private->pAudioAac.eAACProfile = OMX_AUDIO_AACObjectNull;
00438 break;
00439 }
00440 break;
00441 default :
00442 DEBUG(DEB_LEV_ERR, "Audio format other than mp3, vorbis or AAC not supported\nCodec type %lu not found\n",omx_audiodec_component_Private->audio_coding_type);
00443 break;
00444 }
00445
00446
00447 omx_audiodec_component_Private->pAudioPcmMode.nChannels = omx_audiodec_component_Private->avCodecContext->channels;
00448 if(omx_audiodec_component_Private->avCodecContext->sample_fmt==SAMPLE_FMT_S16)
00449 omx_audiodec_component_Private->pAudioPcmMode.nBitPerSample = 16;
00450 else if(omx_audiodec_component_Private->avCodecContext->sample_fmt==SAMPLE_FMT_S32)
00451 omx_audiodec_component_Private->pAudioPcmMode.nBitPerSample = 32;
00452 omx_audiodec_component_Private->pAudioPcmMode.nSamplingRate = omx_audiodec_component_Private->avCodecContext->sample_rate;
00453
00454
00455 (*(omx_audiodec_component_Private->callbacks->EventHandler))
00456 (openmaxStandComp,
00457 omx_audiodec_component_Private->callbackData,
00458 OMX_EventPortSettingsChanged,
00459 0,
00460 1,
00461 NULL);
00462 }
00463
00464 if(len < 0) {
00465 DEBUG(DEB_LEV_ERR,"error in packet decoding in audio dcoder \n");
00466 } else {
00467
00468 if((output_length != OUTPUT_LEN_STANDARD_FFMPEG) || (output_length <= pOutputBuffer->nAllocLen)) {
00469 pOutputBuffer->nFilledLen += output_length;
00470 }
00471 pInputBuffer->nFilledLen = 0;
00472 omx_audiodec_component_Private->isNewBuffer = 1;
00473 }
00474
00476 }
00477
00478 OMX_ERRORTYPE omx_audiodec_component_SetParameter(
00479 OMX_IN OMX_HANDLETYPE hComponent,
00480 OMX_IN OMX_INDEXTYPE nParamIndex,
00481 OMX_IN OMX_PTR ComponentParameterStructure)
00482 {
00483 OMX_ERRORTYPE err = OMX_ErrorNone;
00484 OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
00485 OMX_AUDIO_PARAM_PCMMODETYPE* pAudioPcmMode;
00486 OMX_AUDIO_PARAM_MP3TYPE * pAudioMp3;
00487 OMX_AUDIO_PARAM_VORBISTYPE *pAudioVorbis;
00488 OMX_AUDIO_PARAM_AACPROFILETYPE *pAudioAac;
00489 OMX_PARAM_COMPONENTROLETYPE * pComponentRole;
00490 OMX_U32 portIndex;
00491
00492
00493 OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
00494 omx_audiodec_component_PrivateType* omx_audiodec_component_Private = openmaxStandComp->pComponentPrivate;
00495 omx_base_audio_PortType *port;
00496 if (ComponentParameterStructure == NULL) {
00497 return OMX_ErrorBadParameter;
00498 }
00499
00500 DEBUG(DEB_LEV_SIMPLE_SEQ, " Setting parameter %i\n", nParamIndex);
00501 switch(nParamIndex) {
00502 case OMX_IndexParamAudioPortFormat:
00503 pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00504 portIndex = pAudioPortFormat->nPortIndex;
00505
00506 err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00507 if(err!=OMX_ErrorNone) {
00508 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00509 break;
00510 }
00511 if (portIndex <= 1) {
00512 port = (omx_base_audio_PortType *) omx_audiodec_component_Private->ports[portIndex];
00513 memcpy(&port->sAudioParam,pAudioPortFormat,sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00514 } else {
00515 return OMX_ErrorBadPortIndex;
00516 }
00517 break;
00518 case OMX_IndexParamAudioPcm:
00519 pAudioPcmMode = (OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure;
00520 portIndex = pAudioPcmMode->nPortIndex;
00521
00522 err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pAudioPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00523 if(err!=OMX_ErrorNone) {
00524 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00525 break;
00526 }
00527 memcpy(&omx_audiodec_component_Private->pAudioPcmMode,pAudioPcmMode,sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00528 break;
00529
00530 case OMX_IndexParamAudioVorbis:
00531 pAudioVorbis = (OMX_AUDIO_PARAM_VORBISTYPE*)ComponentParameterStructure;
00532 portIndex = pAudioVorbis->nPortIndex;
00533 err = omx_base_component_ParameterSanityCheck(hComponent,portIndex,pAudioVorbis,sizeof(OMX_AUDIO_PARAM_VORBISTYPE));
00534 if(err!=OMX_ErrorNone) {
00535 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00536 break;
00537 }
00538 if(pAudioVorbis->nPortIndex == 0)
00539 memcpy(&omx_audiodec_component_Private->pAudioVorbis,pAudioVorbis,sizeof(OMX_AUDIO_PARAM_VORBISTYPE));
00540 else
00541 return OMX_ErrorBadPortIndex;
00542 break;
00543 case OMX_IndexParamStandardComponentRole:
00544 pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)ComponentParameterStructure;
00545 if (!strcmp((char*)pComponentRole->cRole, AUDIO_DEC_MP3_ROLE)) {
00546 omx_audiodec_component_Private->audio_coding_type = OMX_AUDIO_CodingMP3;
00547 } else if (!strcmp((char*)pComponentRole->cRole, AUDIO_DEC_VORBIS_ROLE)) {
00548 omx_audiodec_component_Private->audio_coding_type = OMX_AUDIO_CodingVORBIS;
00549 } else if (!strcmp((char*)pComponentRole->cRole, AUDIO_DEC_AAC_ROLE)) {
00550 omx_audiodec_component_Private->audio_coding_type = OMX_AUDIO_CodingAAC;
00551 } else {
00552 return OMX_ErrorBadParameter;
00553 }
00554 omx_audiodec_component_SetInternalParameters(openmaxStandComp);
00555 break;
00556
00557 case OMX_IndexParamAudioAac:
00558 pAudioAac = (OMX_AUDIO_PARAM_AACPROFILETYPE*) ComponentParameterStructure;
00559 portIndex = pAudioAac->nPortIndex;
00560 err = omx_base_component_ParameterSanityCheck(hComponent,portIndex,pAudioAac,sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
00561 if(err!=OMX_ErrorNone) {
00562 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00563 break;
00564 }
00565 if (pAudioAac->nPortIndex == 0) {
00566 memcpy(&omx_audiodec_component_Private->pAudioAac,pAudioAac,sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
00567 } else {
00568 return OMX_ErrorBadPortIndex;
00569 }
00570 break;
00571
00572 case OMX_IndexParamAudioMp3:
00573 pAudioMp3 = (OMX_AUDIO_PARAM_MP3TYPE*) ComponentParameterStructure;
00574 portIndex = pAudioMp3->nPortIndex;
00575 err = omx_base_component_ParameterSanityCheck(hComponent,portIndex,pAudioMp3,sizeof(OMX_AUDIO_PARAM_MP3TYPE));
00576 if(err!=OMX_ErrorNone) {
00577 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00578 break;
00579 }
00580 if (pAudioMp3->nPortIndex == 0) {
00581 memcpy(&omx_audiodec_component_Private->pAudioMp3,pAudioMp3,sizeof(OMX_AUDIO_PARAM_MP3TYPE));
00582 } else {
00583 return OMX_ErrorBadPortIndex;
00584 }
00585 break;
00586 default:
00587 return omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00588 }
00589 return err;
00590 }
00591
00592 OMX_ERRORTYPE omx_audiodec_component_GetParameter(
00593 OMX_IN OMX_HANDLETYPE hComponent,
00594 OMX_IN OMX_INDEXTYPE nParamIndex,
00595 OMX_INOUT OMX_PTR ComponentParameterStructure)
00596 {
00597 OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
00598 OMX_AUDIO_PARAM_PCMMODETYPE *pAudioPcmMode;
00599 OMX_AUDIO_PARAM_VORBISTYPE *pAudioVorbis;
00600 OMX_AUDIO_PARAM_AACPROFILETYPE *pAudioAac;
00601 OMX_PARAM_COMPONENTROLETYPE * pComponentRole;
00602 OMX_AUDIO_PARAM_MP3TYPE *pAudioMp3;
00603 omx_base_audio_PortType *port;
00604 OMX_ERRORTYPE err = OMX_ErrorNone;
00605
00606 OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
00607 omx_audiodec_component_PrivateType* omx_audiodec_component_Private = (omx_audiodec_component_PrivateType*)openmaxStandComp->pComponentPrivate;
00608 if (ComponentParameterStructure == NULL) {
00609 return OMX_ErrorBadParameter;
00610 }
00611 DEBUG(DEB_LEV_SIMPLE_SEQ, " Getting parameter %i\n", nParamIndex);
00612
00613 switch(nParamIndex) {
00614 case OMX_IndexParamAudioInit:
00615 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
00616 break;
00617 }
00618 memcpy(ComponentParameterStructure, &omx_audiodec_component_Private->sPortTypesParam, sizeof(OMX_PORT_PARAM_TYPE));
00619 break;
00620 case OMX_IndexParamAudioPortFormat:
00621 pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00622 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
00623 break;
00624 }
00625 if (pAudioPortFormat->nPortIndex <= 1) {
00626 port = (omx_base_audio_PortType *)omx_audiodec_component_Private->ports[pAudioPortFormat->nPortIndex];
00627 memcpy(pAudioPortFormat, &port->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00628 } else {
00629 return OMX_ErrorBadPortIndex;
00630 }
00631 break;
00632 case OMX_IndexParamAudioPcm:
00633 pAudioPcmMode = (OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure;
00634 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE))) != OMX_ErrorNone) {
00635 break;
00636 }
00637 if (pAudioPcmMode->nPortIndex > 1) {
00638 return OMX_ErrorBadPortIndex;
00639 }
00640 memcpy(pAudioPcmMode,&omx_audiodec_component_Private->pAudioPcmMode,sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00641 break;
00642 case OMX_IndexParamAudioMp3:
00643 pAudioMp3 = (OMX_AUDIO_PARAM_MP3TYPE*)ComponentParameterStructure;
00644 if (pAudioMp3->nPortIndex != 0) {
00645 return OMX_ErrorBadPortIndex;
00646 }
00647 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_MP3TYPE))) != OMX_ErrorNone) {
00648 break;
00649 }
00650 memcpy(pAudioMp3,&omx_audiodec_component_Private->pAudioMp3,sizeof(OMX_AUDIO_PARAM_MP3TYPE));
00651 break;
00652
00653 case OMX_IndexParamAudioAac:
00654 pAudioAac = (OMX_AUDIO_PARAM_AACPROFILETYPE*)ComponentParameterStructure;
00655 if (pAudioAac->nPortIndex != 0) {
00656 return OMX_ErrorBadPortIndex;
00657 }
00658 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE))) != OMX_ErrorNone) {
00659 break;
00660 }
00661 memcpy(pAudioAac,&omx_audiodec_component_Private->pAudioAac,sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
00662 break;
00663
00664 case OMX_IndexParamAudioVorbis:
00665 pAudioVorbis = (OMX_AUDIO_PARAM_VORBISTYPE*)ComponentParameterStructure;
00666 if (pAudioVorbis->nPortIndex != 0) {
00667 return OMX_ErrorBadPortIndex;
00668 }
00669 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_VORBISTYPE))) != OMX_ErrorNone) {
00670 break;
00671 }
00672 memcpy(pAudioVorbis,&omx_audiodec_component_Private->pAudioVorbis,sizeof(OMX_AUDIO_PARAM_VORBISTYPE));
00673 break;
00674
00675 case OMX_IndexParamStandardComponentRole:
00676 pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)ComponentParameterStructure;
00677 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PARAM_COMPONENTROLETYPE))) != OMX_ErrorNone) {
00678 break;
00679 }
00680
00681 if (omx_audiodec_component_Private->audio_coding_type == OMX_AUDIO_CodingMP3) {
00682 strcpy((char*)pComponentRole->cRole, AUDIO_DEC_MP3_ROLE);
00683 } else if (omx_audiodec_component_Private->audio_coding_type == OMX_AUDIO_CodingVORBIS) {
00684 strcpy((char*)pComponentRole->cRole, AUDIO_DEC_VORBIS_ROLE);
00685 } else if (omx_audiodec_component_Private->audio_coding_type == OMX_AUDIO_CodingAAC) {
00686 strcpy((char*)pComponentRole->cRole, AUDIO_DEC_AAC_ROLE);
00687 } else {
00688 strcpy((char*)pComponentRole->cRole,"\0");;
00689 }
00690 break;
00691 default:
00692 return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00693 }
00694 return err;
00695 }
00696
00697 OMX_ERRORTYPE omx_audiodec_component_MessageHandler(OMX_COMPONENTTYPE* openmaxStandComp,internalRequestMessageType *message)
00698 {
00699 omx_audiodec_component_PrivateType* omx_audiodec_component_Private = (omx_audiodec_component_PrivateType*)openmaxStandComp->pComponentPrivate;
00700 OMX_ERRORTYPE err;
00701 OMX_STATETYPE eCurrentState = omx_audiodec_component_Private->state;
00702
00703 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s\n", __func__);
00704
00705 if (message->messageType == OMX_CommandStateSet){
00706 if ((message->messageParam == OMX_StateExecuting ) && (omx_audiodec_component_Private->state == OMX_StateIdle)) {
00707 if (!omx_audiodec_component_Private->avcodecReady ) {
00708 err = omx_audiodec_component_ffmpegLibInit(omx_audiodec_component_Private);
00709 if (err != OMX_ErrorNone) {
00710 return OMX_ErrorNotReady;
00711 }
00712 omx_audiodec_component_Private->avcodecReady = OMX_TRUE;
00713 }
00714 }
00715 else if ((message->messageParam == OMX_StateIdle ) && (omx_audiodec_component_Private->state == OMX_StateLoaded)) {
00716 err = omx_audiodec_component_Init(openmaxStandComp);
00717 if(err!=OMX_ErrorNone) {
00718 DEBUG(DEB_LEV_ERR, "In %s Audio Decoder Init Failed Error=%x\n",__func__,err);
00719 return err;
00720 }
00721 } else if ((message->messageParam == OMX_StateLoaded) && (omx_audiodec_component_Private->state == OMX_StateIdle)) {
00722 err = omx_audiodec_component_Deinit(openmaxStandComp);
00723 if(err!=OMX_ErrorNone) {
00724 DEBUG(DEB_LEV_ERR, "In %s Audio Decoder Deinit Failed Error=%x\n",__func__,err);
00725 return err;
00726 }
00727 }
00728 }
00729
00730 err = omx_base_component_MessageHandler(openmaxStandComp,message);
00731
00732 if (message->messageType == OMX_CommandStateSet){
00733 if ((message->messageParam == OMX_StateIdle ) && (eCurrentState == OMX_StateExecuting)) {
00734 if (omx_audiodec_component_Private->avcodecReady) {
00735 omx_audiodec_component_ffmpegLibDeInit(omx_audiodec_component_Private);
00736 omx_audiodec_component_Private->avcodecReady = OMX_FALSE;
00737 }
00738 }
00739 }
00740 return err;
00741 }
00742
00743 OMX_ERRORTYPE omx_audiodec_component_ComponentRoleEnum(
00744 OMX_IN OMX_HANDLETYPE hComponent,
00745 OMX_OUT OMX_U8 *cRole,
00746 OMX_IN OMX_U32 nIndex)
00747 {
00748 if (nIndex == 0) {
00749 strcpy((char*)cRole, AUDIO_DEC_MP3_ROLE);
00750 } else if (nIndex == 1) {
00751 strcpy((char*)cRole, AUDIO_DEC_VORBIS_ROLE);
00752 } else if (nIndex == 2) {
00753 strcpy((char*)cRole, AUDIO_DEC_AAC_ROLE);
00754 }else {
00755 return OMX_ErrorUnsupportedIndex;
00756 }
00757 return OMX_ErrorNone;
00758 }
00759
00760
00761 OMX_ERRORTYPE omx_audiodec_component_SetConfig(
00762 OMX_HANDLETYPE hComponent,
00763 OMX_INDEXTYPE nIndex,
00764 OMX_PTR pComponentConfigStructure) {
00765
00766 OMX_ERRORTYPE err = OMX_ErrorNone;
00767 OMX_VENDOR_EXTRADATATYPE* pExtradata;
00768
00769 OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
00770 omx_audiodec_component_PrivateType* omx_audiodec_component_Private = (omx_audiodec_component_PrivateType*)openmaxStandComp->pComponentPrivate;
00771 if (pComponentConfigStructure == NULL) {
00772 return OMX_ErrorBadParameter;
00773 }
00774 DEBUG(DEB_LEV_SIMPLE_SEQ, " Getting configuration %i\n", nIndex);
00775
00776 switch (nIndex) {
00777 case OMX_IndexVendorAudioExtraData :
00778 pExtradata = (OMX_VENDOR_EXTRADATATYPE*)pComponentConfigStructure;
00779 if (pExtradata->nPortIndex <= 1) {
00781 omx_audiodec_component_Private->extradata_size = (OMX_U32)pExtradata->nDataSize;
00782 if(omx_audiodec_component_Private->extradata_size > 0) {
00783 if(omx_audiodec_component_Private->extradata) {
00784 free(omx_audiodec_component_Private->extradata);
00785 }
00786 omx_audiodec_component_Private->extradata = malloc((int)pExtradata->nDataSize);
00787 memcpy(omx_audiodec_component_Private->extradata, pExtradata->pData,pExtradata->nDataSize);
00788 } else {
00789 DEBUG(DEB_LEV_SIMPLE_SEQ,"extradata size is 0 !!!\n");
00790 }
00791 } else {
00792 return OMX_ErrorBadPortIndex;
00793 }
00794 break;
00795
00796 default:
00797 return omx_base_component_SetConfig(hComponent, nIndex, pComponentConfigStructure);
00798 }
00799 return err;
00800 }
00801
00802 OMX_ERRORTYPE omx_audiodec_component_GetExtensionIndex(
00803 OMX_IN OMX_HANDLETYPE hComponent,
00804 OMX_IN OMX_STRING cParameterName,
00805 OMX_OUT OMX_INDEXTYPE* pIndexType) {
00806
00807 DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
00808
00809 if(strcmp(cParameterName,"OMX.ST.index.config.audioextradata") == 0) {
00810 *pIndexType = OMX_IndexVendorAudioExtraData;
00811 } else {
00812 return OMX_ErrorBadParameter;
00813 }
00814 return OMX_ErrorNone;
00815 }
00816
00817
00818