00001
00031 #include <omxcore.h>
00032 #include <omx_base_audio_port.h>
00033 #include <omx_vorbisdec_component.h>
00035 #include <OMX_Audio.h>
00036
00037 #define MAX_COMPONENT_VORBISDEC 4
00038
00039 static OMX_U32 noVorbisDecInstance = 0;
00040
00045 OMX_ERRORTYPE omx_vorbisdec_component_Constructor( OMX_COMPONENTTYPE *openmaxStandComp, OMX_STRING cComponentName) {
00046
00047 OMX_ERRORTYPE err = OMX_ErrorNone;
00048 omx_vorbisdec_component_PrivateType* omx_vorbisdec_component_Private;
00049 omx_base_audio_PortType *inPort,*outPort;
00050 OMX_U32 i;
00051
00052 if (!openmaxStandComp->pComponentPrivate) {
00053 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s, allocating component\n", __func__);
00054 openmaxStandComp->pComponentPrivate = calloc(1, sizeof(omx_vorbisdec_component_PrivateType));
00055 if(openmaxStandComp->pComponentPrivate == NULL) {
00056 return OMX_ErrorInsufficientResources;
00057 }
00058 } else {
00059 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s, Error Component %x Already Allocated\n", __func__, (int)openmaxStandComp->pComponentPrivate);
00060 }
00061
00062 omx_vorbisdec_component_Private = openmaxStandComp->pComponentPrivate;
00063 omx_vorbisdec_component_Private->ports = NULL;
00064
00068 err = omx_base_filter_Constructor(openmaxStandComp,cComponentName);
00069
00076 if (omx_vorbisdec_component_Private->sPortTypesParam.nPorts && !omx_vorbisdec_component_Private->ports) {
00077 omx_vorbisdec_component_Private->ports = calloc(omx_vorbisdec_component_Private->sPortTypesParam.nPorts, sizeof(omx_base_PortType *));
00078 if (!omx_vorbisdec_component_Private->ports) {
00079 return OMX_ErrorInsufficientResources;
00080 }
00081 for (i=0; i < omx_vorbisdec_component_Private->sPortTypesParam.nPorts; i++) {
00082 omx_vorbisdec_component_Private->ports[i] = calloc(1, sizeof(omx_base_audio_PortType));
00083 if (!omx_vorbisdec_component_Private->ports[i]) {
00084 return OMX_ErrorInsufficientResources;
00085 }
00086 }
00087 }
00088
00089 base_audio_port_Constructor(openmaxStandComp, &omx_vorbisdec_component_Private->ports[0], 0, OMX_TRUE);
00090 base_audio_port_Constructor(openmaxStandComp, &omx_vorbisdec_component_Private->ports[1], 1, OMX_FALSE);
00091
00092 inPort = (omx_base_audio_PortType *) omx_vorbisdec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
00093
00094 inPort->sPortParam.nBufferSize = DEFAULT_IN_BUFFER_SIZE;
00095 strcpy(inPort->sPortParam.format.audio.cMIMEType, "audio/vorbis");
00096 inPort->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingVORBIS;
00097
00098 inPort->sAudioParam.eEncoding = OMX_AUDIO_CodingVORBIS;
00099
00100 setHeader(&omx_vorbisdec_component_Private->pAudioVorbis,sizeof(OMX_AUDIO_PARAM_VORBISTYPE));
00101 omx_vorbisdec_component_Private->pAudioVorbis.nPortIndex = 0;
00102 omx_vorbisdec_component_Private->pAudioVorbis.nChannels = 2;
00103 omx_vorbisdec_component_Private->pAudioVorbis.nBitRate = 28000;
00104 omx_vorbisdec_component_Private->pAudioVorbis.nSampleRate = 44100;
00105 omx_vorbisdec_component_Private->pAudioVorbis.nAudioBandWidth = 0;
00106 omx_vorbisdec_component_Private->pAudioVorbis.nQuality = 3;
00107
00110 outPort = (omx_base_audio_PortType *) omx_vorbisdec_component_Private->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
00111
00112 outPort->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
00113 outPort->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
00114
00115 outPort->sAudioParam.eEncoding = OMX_AUDIO_CodingPCM;
00116
00120 setHeader(&omx_vorbisdec_component_Private->pAudioPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00121 omx_vorbisdec_component_Private->pAudioPcmMode.nPortIndex = 1;
00122 omx_vorbisdec_component_Private->pAudioPcmMode.nChannels = 2;
00123 omx_vorbisdec_component_Private->pAudioPcmMode.eNumData = OMX_NumericalDataSigned;
00124 omx_vorbisdec_component_Private->pAudioPcmMode.eEndian = OMX_EndianLittle;
00125 omx_vorbisdec_component_Private->pAudioPcmMode.bInterleaved = OMX_TRUE;
00126 omx_vorbisdec_component_Private->pAudioPcmMode.nBitPerSample = 16;
00127 omx_vorbisdec_component_Private->pAudioPcmMode.nSamplingRate = 44100;
00128 omx_vorbisdec_component_Private->pAudioPcmMode.ePCMMode = OMX_AUDIO_PCMModeLinear;
00129 omx_vorbisdec_component_Private->pAudioPcmMode.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
00130 omx_vorbisdec_component_Private->pAudioPcmMode.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
00131
00133 omx_vorbisdec_component_Private->BufferMgmtCallback = omx_vorbisdec_component_BufferMgmtCallbackVorbis;
00134 omx_vorbisdec_component_Private->messageHandler = omx_vorbis_decoder_MessageHandler;
00135 omx_vorbisdec_component_Private->destructor = omx_vorbisdec_component_Destructor;
00136 openmaxStandComp->SetParameter = omx_vorbisdec_component_SetParameter;
00137 openmaxStandComp->GetParameter = omx_vorbisdec_component_GetParameter;
00138
00140 noVorbisDecInstance++;
00141
00145 if(!strcmp(cComponentName, AUDIO_DEC_VORBIS_NAME)) {
00146 omx_vorbisdec_component_Private->audio_coding_type = OMX_AUDIO_CodingVORBIS;
00147 } else if (!strcmp(cComponentName, AUDIO_DEC_BASE_NAME)) {
00148 omx_vorbisdec_component_Private->audio_coding_type = OMX_AUDIO_CodingUnused;
00149 } else {
00151 return OMX_ErrorInvalidComponentName;
00152 }
00153
00154 if(!omx_vorbisdec_component_Private->avCodecSyncSem) {
00155 omx_vorbisdec_component_Private->avCodecSyncSem = calloc(1, sizeof(tsem_t));
00156 if(omx_vorbisdec_component_Private->avCodecSyncSem == NULL) {
00157 return OMX_ErrorInsufficientResources;
00158 }
00159 tsem_init(omx_vorbisdec_component_Private->avCodecSyncSem, 0);
00160 }
00161 if(noVorbisDecInstance > MAX_COMPONENT_VORBISDEC) {
00162 return OMX_ErrorInsufficientResources;
00163 }
00164
00165 return err;
00166 }
00167
00168
00171 OMX_ERRORTYPE omx_vorbisdec_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp) {
00172 omx_vorbisdec_component_PrivateType* omx_vorbisdec_component_Private = openmaxStandComp->pComponentPrivate;
00173 OMX_U32 i;
00174
00175 if(omx_vorbisdec_component_Private->avCodecSyncSem) {
00176 tsem_deinit(omx_vorbisdec_component_Private->avCodecSyncSem);
00177 free(omx_vorbisdec_component_Private->avCodecSyncSem);
00178 omx_vorbisdec_component_Private->avCodecSyncSem = NULL;
00179 }
00180
00181
00182 if (omx_vorbisdec_component_Private->ports) {
00183 for (i=0; i < omx_vorbisdec_component_Private->sPortTypesParam.nPorts; i++) {
00184 if(omx_vorbisdec_component_Private->ports[i])
00185 omx_vorbisdec_component_Private->ports[i]->PortDestructor(omx_vorbisdec_component_Private->ports[i]);
00186 }
00187 free(omx_vorbisdec_component_Private->ports);
00188 omx_vorbisdec_component_Private->ports=NULL;
00189 }
00190
00191 DEBUG(DEB_LEV_FUNCTION_NAME, "Destructor of vorbisdecoder component is called\n");
00192
00193 omx_base_filter_Destructor(openmaxStandComp);
00194
00195 noVorbisDecInstance--;
00196
00197 return OMX_ErrorNone;
00198 }
00199
00202 void omx_vorbisdec_component_SetInternalParameters(OMX_COMPONENTTYPE *openmaxStandComp) {
00203 omx_vorbisdec_component_PrivateType* omx_vorbisdec_component_Private;
00204 omx_base_audio_PortType *pPort;
00205
00206 omx_vorbisdec_component_Private = openmaxStandComp->pComponentPrivate;
00207
00208 if(omx_vorbisdec_component_Private->audio_coding_type == OMX_AUDIO_CodingVORBIS) {
00209 strcpy(omx_vorbisdec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.format.audio.cMIMEType, "audio/vorbis");
00210 omx_vorbisdec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingVORBIS;
00211
00212 setHeader(&omx_vorbisdec_component_Private->pAudioVorbis,sizeof(OMX_AUDIO_PARAM_VORBISTYPE));
00213 omx_vorbisdec_component_Private->pAudioVorbis.nPortIndex = 0;
00214 omx_vorbisdec_component_Private->pAudioVorbis.nChannels = 2;
00215 omx_vorbisdec_component_Private->pAudioVorbis.nBitRate = 28000;
00216 omx_vorbisdec_component_Private->pAudioVorbis.nSampleRate = 44100;
00217 omx_vorbisdec_component_Private->pAudioVorbis.nAudioBandWidth = 0;
00218 omx_vorbisdec_component_Private->pAudioVorbis.nQuality = 3;
00219
00220 pPort = (omx_base_audio_PortType *) omx_vorbisdec_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
00221 setHeader(&pPort->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00222 pPort->sAudioParam.nPortIndex = 0;
00223 pPort->sAudioParam.nIndex = 0;
00224 pPort->sAudioParam.eEncoding = OMX_AUDIO_CodingVORBIS;
00225 }
00226 }
00227
00230 OMX_ERRORTYPE omx_vorbisdec_component_Init(OMX_COMPONENTTYPE *openmaxStandComp) {
00231 omx_vorbisdec_component_PrivateType* omx_vorbisdec_component_Private = openmaxStandComp->pComponentPrivate;
00232 OMX_ERRORTYPE err = OMX_ErrorNone;
00233 OMX_U32 nBufferSize;
00234
00236 omx_vorbisdec_component_Private->inputCurrBuffer = NULL;
00237 omx_vorbisdec_component_Private->inputCurrLength = 0;
00238 nBufferSize = omx_vorbisdec_component_Private->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]->sPortParam.nBufferSize * 2;
00239 omx_vorbisdec_component_Private->internalOutputBuffer = malloc(nBufferSize);
00240 memset(omx_vorbisdec_component_Private->internalOutputBuffer, 0, nBufferSize);
00241 omx_vorbisdec_component_Private->packetNumber = 0;
00242 omx_vorbisdec_component_Private->positionInOutBuf = 0;
00243 omx_vorbisdec_component_Private->isNewBuffer = 1;
00244
00246 ogg_sync_init(&omx_vorbisdec_component_Private->oy);
00247 omx_vorbisdec_component_Private->convsize = 0;
00248
00249 return err;
00250 };
00251
00254 OMX_ERRORTYPE omx_vorbisdec_component_Deinit(OMX_COMPONENTTYPE *openmaxStandComp) {
00255 omx_vorbisdec_component_PrivateType* omx_vorbisdec_component_Private = openmaxStandComp->pComponentPrivate;
00256 OMX_ERRORTYPE err = OMX_ErrorNone;
00257
00258 free(omx_vorbisdec_component_Private->internalOutputBuffer);
00259 omx_vorbisdec_component_Private->internalOutputBuffer = NULL;
00260
00262 ogg_stream_clear(&omx_vorbisdec_component_Private->os);
00263 vorbis_block_clear(&omx_vorbisdec_component_Private->vb);
00264 vorbis_dsp_clear(&omx_vorbisdec_component_Private->vd);
00265 vorbis_comment_clear(&omx_vorbisdec_component_Private->vc);
00266 vorbis_info_clear(&omx_vorbisdec_component_Private->vi);
00267 ogg_sync_clear(&omx_vorbisdec_component_Private->oy);
00268
00269 return err;
00270 }
00271
00272
00277 void omx_vorbisdec_component_BufferMgmtCallbackVorbis(OMX_COMPONENTTYPE *openmaxStandComp, OMX_BUFFERHEADERTYPE* inputbuffer, OMX_BUFFERHEADERTYPE* outputbuffer) {
00278
00279 omx_vorbisdec_component_PrivateType* omx_vorbisdec_component_Private = openmaxStandComp->pComponentPrivate;
00280 OMX_U8* outputCurrBuffer;
00281 OMX_U32 outputLength;
00282 OMX_S32 result;
00283 float **pcm;
00284 OMX_S32 samples;
00285 OMX_S32 i, j;
00286 OMX_S32 bout;
00287 OMX_S32 clipflag=0;
00288 int val;
00289 float *mono;
00290 int eos=0;
00291 char *vorbis_buffer;
00292 ogg_int16_t convbuffer[4096];
00293
00294
00295 DEBUG(DEB_LEV_FULL_SEQ, "input buf %x filled len : %d \n", (int)inputbuffer->pBuffer, (int)inputbuffer->nFilledLen);
00297 if(omx_vorbisdec_component_Private->isNewBuffer) {
00298 omx_vorbisdec_component_Private->inputCurrBuffer = inputbuffer->pBuffer;
00299 omx_vorbisdec_component_Private->inputCurrLength = inputbuffer->nFilledLen;
00300 omx_vorbisdec_component_Private->positionInOutBuf = 0;
00301
00302 DEBUG(DEB_LEV_SIMPLE_SEQ, "new -- input buf %x filled len : %d \n", (int)inputbuffer->pBuffer, (int)inputbuffer->nFilledLen);
00303
00305 vorbis_buffer = ogg_sync_buffer(&omx_vorbisdec_component_Private->oy, inputbuffer->nAllocLen);
00306 memcpy(vorbis_buffer, inputbuffer->pBuffer, inputbuffer->nFilledLen);
00307 ogg_sync_wrote(&omx_vorbisdec_component_Private->oy, inputbuffer->nFilledLen);
00308 DEBUG(DEB_LEV_FULL_SEQ,"***** bytes read to buffer (of first header): %d \n",(int)inputbuffer->nFilledLen);
00309 }
00310 outputCurrBuffer = outputbuffer->pBuffer;
00311 outputLength = outputbuffer->nAllocLen;
00312 outputbuffer->nFilledLen = 0;
00313 outputbuffer->nOffset = 0;
00314
00315 if(omx_vorbisdec_component_Private->packetNumber < 3) {
00316 omx_vorbisdec_component_Private->isNewBuffer = 0;
00317 if(omx_vorbisdec_component_Private->packetNumber == 0) {
00318 DEBUG(DEB_LEV_SIMPLE_SEQ, "in processing the first header buffer\n");
00319 if(ogg_sync_pageout(&omx_vorbisdec_component_Private->oy, &omx_vorbisdec_component_Private->og) != 1) {
00320 DEBUG(DEB_LEV_ERR, "this input stream is not an Ogg stream\n");
00321 exit(1);
00322 }
00323 ogg_stream_init(&omx_vorbisdec_component_Private->os, ogg_page_serialno(&omx_vorbisdec_component_Private->og));
00324 vorbis_info_init(&omx_vorbisdec_component_Private->vi);
00325 vorbis_comment_init(&omx_vorbisdec_component_Private->vc);
00326
00327 if(ogg_stream_pagein(&omx_vorbisdec_component_Private->os, &omx_vorbisdec_component_Private->og) < 0) {
00328 DEBUG(DEB_LEV_ERR, "Error reading first page of Ogg bitstream data.\n");
00329 exit(1);
00330 }
00331 if(ogg_stream_packetout(&omx_vorbisdec_component_Private->os, &omx_vorbisdec_component_Private->op) != 1) {
00332 DEBUG(DEB_LEV_ERR, "Error reading initial header packet.\n");
00333 exit(1);
00334 }
00335
00336 omx_vorbisdec_component_Private->packetNumber++;
00337
00338 if(vorbis_synthesis_headerin(&omx_vorbisdec_component_Private->vi, &omx_vorbisdec_component_Private->vc, &omx_vorbisdec_component_Private->op) < 0) {
00339 DEBUG(DEB_LEV_ERR, "This Ogg bitstream does not contain Vorbis audio data\n");
00340 exit(1);
00341 }
00342 }
00343
00344 while(omx_vorbisdec_component_Private->packetNumber < 3)
00345 {
00346 int result=ogg_sync_pageout(&omx_vorbisdec_component_Private->oy,&omx_vorbisdec_component_Private->og);
00347 if(result==0) {
00348 omx_vorbisdec_component_Private->isNewBuffer = 1;
00349 inputbuffer->nFilledLen = 0;
00350 return;
00351 }
00352
00353
00354 if(result==1)
00355 {
00356 ogg_stream_pagein(&omx_vorbisdec_component_Private->os,&omx_vorbisdec_component_Private->og);
00357
00358 while(omx_vorbisdec_component_Private->packetNumber < 3) {
00359 result=ogg_stream_packetout(&omx_vorbisdec_component_Private->os,&omx_vorbisdec_component_Private->op);
00360 if(result==0)break;
00361 if(result<0) {
00362
00363
00364 DEBUG(DEB_LEV_ERR,"Corrupt secondary header. Exiting.\n");
00365 exit(1);
00366 }
00367 omx_vorbisdec_component_Private->packetNumber++;
00368 vorbis_synthesis_headerin(&omx_vorbisdec_component_Private->vi,&omx_vorbisdec_component_Private->vc,&omx_vorbisdec_component_Private->op);
00369 }
00370 }
00371 }
00372
00373 omx_vorbisdec_component_Private->isNewBuffer = 1;
00374 inputbuffer->nFilledLen = 0;
00375 return;
00376
00377 }
00378
00379
00380
00381 if(omx_vorbisdec_component_Private->packetNumber == 3) {
00382
00383 {
00384
00385 char **ptr=omx_vorbisdec_component_Private->vc.user_comments;
00386 while(*ptr){
00387 DEBUG(DEB_LEV_ERR,"%s\n",*ptr);
00388 ++ptr;
00389 }
00390 DEBUG(DEB_LEV_ERR,"Bitstream is %d channel, %ldHz\n",omx_vorbisdec_component_Private->vi.channels,omx_vorbisdec_component_Private->vi.rate);
00391 DEBUG(DEB_LEV_ERR,"Encoded by: %s\n\n",omx_vorbisdec_component_Private->vc.vendor);
00392 }
00393
00394
00395 omx_vorbisdec_component_Private->pAudioVorbis.nSampleRate = omx_vorbisdec_component_Private->vi.rate;
00396 omx_vorbisdec_component_Private->pAudioVorbis.nChannels = omx_vorbisdec_component_Private->vi.channels;
00397
00398
00399 if ((omx_vorbisdec_component_Private->pAudioPcmMode.nSamplingRate != omx_vorbisdec_component_Private->pAudioVorbis.nSampleRate) ||
00400 (omx_vorbisdec_component_Private->pAudioPcmMode.nChannels != omx_vorbisdec_component_Private->pAudioVorbis.nChannels)) {
00401 omx_vorbisdec_component_Private->pAudioPcmMode.nSamplingRate = omx_vorbisdec_component_Private->pAudioVorbis.nSampleRate;
00402 omx_vorbisdec_component_Private->pAudioPcmMode.nChannels = omx_vorbisdec_component_Private->pAudioVorbis.nChannels;
00403
00404
00405 (*(omx_vorbisdec_component_Private->callbacks->EventHandler))
00406 (openmaxStandComp,
00407 omx_vorbisdec_component_Private->callbackData,
00408 OMX_EventPortSettingsChanged,
00409 0,
00410 1,
00411 NULL);
00412 }
00413
00414 omx_vorbisdec_component_Private->convsize=inputbuffer->nFilledLen/omx_vorbisdec_component_Private->vi.channels;
00415
00416
00417 vorbis_synthesis_init(&omx_vorbisdec_component_Private->vd,&omx_vorbisdec_component_Private->vi);
00418 vorbis_block_init(&omx_vorbisdec_component_Private->vd,&omx_vorbisdec_component_Private->vb);
00419
00420
00421
00422
00423 }
00424 DEBUG(DEB_LEV_FULL_SEQ,"***** now the decoding will start *****\n");
00425
00426 if(omx_vorbisdec_component_Private->isNewBuffer) {
00427 omx_vorbisdec_component_Private->isNewBuffer=0;
00428 int result=ogg_sync_pageout(&omx_vorbisdec_component_Private->oy,&omx_vorbisdec_component_Private->og);
00429 DEBUG(DEB_LEV_FULL_SEQ," ---> page (read in decoding) - header len : %ld body len : %ld \n",omx_vorbisdec_component_Private->og.header_len,omx_vorbisdec_component_Private->og.body_len);
00430 if(result == 0) {
00431 omx_vorbisdec_component_Private->isNewBuffer = 1;
00432 inputbuffer->nFilledLen = 0;
00433 return;
00434 }
00435 if(result<0)
00436 {
00437
00438 DEBUG(DEB_LEV_ERR,"Corrupt or missing data in bitstream; continuing...\n");
00439 }
00440 else {
00441 ogg_stream_pagein(&omx_vorbisdec_component_Private->os,&omx_vorbisdec_component_Private->og);
00442 }
00443 }
00444
00445 result=ogg_stream_packetout(&omx_vorbisdec_component_Private->os,&omx_vorbisdec_component_Private->op);
00446 DEBUG(DEB_LEV_FULL_SEQ," packet length (read in decoding a particular page): %ld \n",omx_vorbisdec_component_Private->op.bytes);
00447 if(result == 0) {
00448 omx_vorbisdec_component_Private->isNewBuffer = 1;
00449 inputbuffer->nFilledLen = 0;
00450 return;
00451 }
00452 if(result<0)
00453 {
00454
00455
00456 DEBUG(DEB_LEV_ERR,"Corrupt or missing data in bitstream; continuing...\n");
00457 } else {
00458
00459 omx_vorbisdec_component_Private->packetNumber++;
00460
00461 if(vorbis_synthesis(&omx_vorbisdec_component_Private->vb,&omx_vorbisdec_component_Private->op)==0)
00462 vorbis_synthesis_blockin(&omx_vorbisdec_component_Private->vd,&omx_vorbisdec_component_Private->vb);
00468 while((samples=vorbis_synthesis_pcmout(&omx_vorbisdec_component_Private->vd,&pcm))>0)
00469 {
00470 bout=(samples<omx_vorbisdec_component_Private->convsize?samples:omx_vorbisdec_component_Private->convsize);
00471
00472
00473 for(i=0;i<omx_vorbisdec_component_Private->vi.channels;i++)
00474 {
00475 ogg_int16_t *ptr=convbuffer+i;
00476 mono=pcm[i];
00477 for(j=0;j<bout;j++)
00478 {
00479 #if 1
00480 val=mono[j]*32767.f;
00481 #else
00482 val=mono[j]*32767.f+drand48()-0.5f;
00483 #endif
00484
00485 if(val>32767)
00486 {
00487 val=32767;
00488 clipflag=1;
00489 }
00490 if(val<-32768)
00491 {
00492 val=-32768;
00493 clipflag=1;
00494 }
00495 *ptr=val;
00496 ptr+=omx_vorbisdec_component_Private->vi.channels;
00497 }
00498 }
00499
00500 outputbuffer->nFilledLen=2*omx_vorbisdec_component_Private->vi.channels*bout;
00501 memcpy(outputCurrBuffer,(char *)convbuffer,outputbuffer->nFilledLen);
00502
00503 if(clipflag) {
00504 DEBUG(DEB_LEV_FULL_SEQ,"Clipping in frame %ld\n",(long)(omx_vorbisdec_component_Private->vd.sequence));
00505 }
00506 vorbis_synthesis_read(&omx_vorbisdec_component_Private->vd,bout);
00507 }
00508 }
00509 if(ogg_page_eos(&omx_vorbisdec_component_Private->og)) {
00510 DEBUG(DEB_LEV_FULL_SEQ, "In %s EOS Detected\n",__func__);
00511 eos=1;
00512 }
00513
00514 DEBUG(DEB_LEV_FULL_SEQ, "One output buffer %x len=%d is full returning\n", (int)outputbuffer->pBuffer, (int)outputbuffer->nFilledLen);
00515 }
00516
00522 OMX_ERRORTYPE omx_vorbisdec_component_SetParameter(
00523 OMX_IN OMX_HANDLETYPE hComponent,
00524 OMX_IN OMX_INDEXTYPE nParamIndex,
00525 OMX_IN OMX_PTR ComponentParameterStructure) {
00526
00527 OMX_ERRORTYPE err = OMX_ErrorNone;
00528 OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
00529 OMX_AUDIO_PARAM_PCMMODETYPE* pAudioPcmMode;
00530 OMX_AUDIO_PARAM_VORBISTYPE *pAudioVorbis;
00531 OMX_PARAM_COMPONENTROLETYPE * pComponentRole;
00532 OMX_U32 portIndex;
00533
00535 OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
00536 omx_vorbisdec_component_PrivateType* omx_vorbisdec_component_Private = openmaxStandComp->pComponentPrivate;
00537 omx_base_audio_PortType *port;
00538 if (ComponentParameterStructure == NULL) {
00539 return OMX_ErrorBadParameter;
00540 }
00541
00542 DEBUG(DEB_LEV_SIMPLE_SEQ, " Setting parameter %i\n", nParamIndex);
00543 switch (nParamIndex) {
00544 case OMX_IndexParamAudioPortFormat:
00545 pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00546 portIndex = pAudioPortFormat->nPortIndex;
00548 err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00549 if(err!=OMX_ErrorNone) {
00550 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00551 break;
00552 }
00553 if (portIndex <= 1) {
00554 port = (omx_base_audio_PortType *) omx_vorbisdec_component_Private->ports[portIndex];
00555 memcpy(&port->sAudioParam,pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00556 } else {
00557 return OMX_ErrorBadPortIndex;
00558 }
00559 break;
00560
00561 case OMX_IndexParamAudioPcm:
00562 pAudioPcmMode = (OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure;
00563 portIndex = pAudioPcmMode->nPortIndex;
00564
00565 err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pAudioPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00566 if(err!=OMX_ErrorNone) {
00567 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00568 break;
00569 }
00570 memcpy(&omx_vorbisdec_component_Private->pAudioPcmMode, pAudioPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00571 break;
00572
00573 case OMX_IndexParamAudioVorbis:
00574 pAudioVorbis = (OMX_AUDIO_PARAM_VORBISTYPE*)ComponentParameterStructure;
00575 portIndex = pAudioVorbis->nPortIndex;
00576 err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pAudioVorbis, sizeof(OMX_AUDIO_PARAM_VORBISTYPE));
00577 if(err!=OMX_ErrorNone) {
00578 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00579 break;
00580 }
00581 if(pAudioVorbis->nPortIndex == 0) {
00582 memcpy(&omx_vorbisdec_component_Private->pAudioVorbis, pAudioVorbis, sizeof(OMX_AUDIO_PARAM_VORBISTYPE));
00583 } else {
00584 return OMX_ErrorBadPortIndex;
00585 }
00586 break;
00587
00588 case OMX_IndexParamStandardComponentRole:
00589 pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)ComponentParameterStructure;
00590 if (!strcmp( (char*) pComponentRole->cRole, AUDIO_DEC_VORBIS_ROLE)) {
00591 omx_vorbisdec_component_Private->audio_coding_type = OMX_AUDIO_CodingVORBIS;
00592 } else {
00593 return OMX_ErrorBadParameter;
00594 }
00595 omx_vorbisdec_component_SetInternalParameters(openmaxStandComp);
00596 break;
00597
00598 default:
00599 return omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00600 }
00601 return err;
00602 }
00603
00609 OMX_ERRORTYPE omx_vorbisdec_component_GetParameter(
00610 OMX_IN OMX_HANDLETYPE hComponent,
00611 OMX_IN OMX_INDEXTYPE nParamIndex,
00612 OMX_INOUT OMX_PTR ComponentParameterStructure) {
00613
00614 OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
00615 OMX_AUDIO_PARAM_PCMMODETYPE *pAudioPcmMode;
00616 OMX_AUDIO_PARAM_VORBISTYPE *pAudioVorbis;
00617 OMX_PARAM_COMPONENTROLETYPE * pComponentRole;
00618 omx_base_audio_PortType *port;
00619 OMX_ERRORTYPE err = OMX_ErrorNone;
00620 OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
00621 omx_vorbisdec_component_PrivateType* omx_vorbisdec_component_Private = (omx_vorbisdec_component_PrivateType*)openmaxStandComp->pComponentPrivate;
00622 if (ComponentParameterStructure == NULL) {
00623 return OMX_ErrorBadParameter;
00624 }
00625 DEBUG(DEB_LEV_SIMPLE_SEQ, " Getting parameter %i\n", nParamIndex);
00626
00627 switch(nParamIndex) {
00628
00629 case OMX_IndexParamAudioInit:
00630 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
00631 break;
00632 }
00633 memcpy(ComponentParameterStructure, &omx_vorbisdec_component_Private->sPortTypesParam, sizeof(OMX_PORT_PARAM_TYPE));
00634 break;
00635
00636 case OMX_IndexParamAudioPortFormat:
00637 pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00638 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
00639 break;
00640 }
00641 if (pAudioPortFormat->nPortIndex <= 1) {
00642 port = (omx_base_audio_PortType *)omx_vorbisdec_component_Private->ports[pAudioPortFormat->nPortIndex];
00643 memcpy(pAudioPortFormat, &port->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00644 } else {
00645 return OMX_ErrorBadPortIndex;
00646 }
00647 break;
00648
00649 case OMX_IndexParamAudioPcm:
00650 pAudioPcmMode = (OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure;
00651 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE))) != OMX_ErrorNone) {
00652 break;
00653 }
00654 if (pAudioPcmMode->nPortIndex > 1) {
00655 return OMX_ErrorBadPortIndex;
00656 }
00657 memcpy(pAudioPcmMode, &omx_vorbisdec_component_Private->pAudioPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00658 break;
00659
00660 case OMX_IndexParamAudioVorbis:
00661 pAudioVorbis = (OMX_AUDIO_PARAM_VORBISTYPE*)ComponentParameterStructure;
00662 if(pAudioVorbis->nPortIndex != 0) {
00663 return OMX_ErrorBadPortIndex;
00664 }
00665 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_VORBISTYPE))) != OMX_ErrorNone) {
00666 break;
00667 }
00668 memcpy(pAudioVorbis, &omx_vorbisdec_component_Private->pAudioVorbis, sizeof(OMX_AUDIO_PARAM_VORBISTYPE));
00669 break;
00670
00671 case OMX_IndexParamStandardComponentRole:
00672 pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)ComponentParameterStructure;
00673 if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PARAM_COMPONENTROLETYPE))) != OMX_ErrorNone) {
00674 break;
00675 }
00676 if (omx_vorbisdec_component_Private->audio_coding_type == OMX_AUDIO_CodingVORBIS) {
00677 strcpy( (char*) pComponentRole->cRole, AUDIO_DEC_VORBIS_ROLE);
00678 } else {
00679 strcpy( (char*) pComponentRole->cRole, "\0");;
00680 }
00681 break;
00682
00683 default:
00684 return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00685 }
00686 return err;
00687 }
00688
00692 OMX_ERRORTYPE omx_vorbis_decoder_MessageHandler(OMX_COMPONENTTYPE* openmaxStandComp,internalRequestMessageType *message) {
00693 omx_vorbisdec_component_PrivateType* omx_vorbisdec_component_Private = (omx_vorbisdec_component_PrivateType*)openmaxStandComp->pComponentPrivate;
00694 OMX_ERRORTYPE err;
00695
00696 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s\n", __func__);
00697
00698 if (message->messageType == OMX_CommandStateSet){
00699 if ((message->messageParam == OMX_StateIdle) && (omx_vorbisdec_component_Private->state == OMX_StateLoaded)) {
00700 err = omx_vorbisdec_component_Init(openmaxStandComp);
00701 if(err!=OMX_ErrorNone) {
00702 DEBUG(DEB_LEV_ERR, "In %s Vorbis Decoder Init Failed=%x\n",__func__,err);
00703 return err;
00704 }
00705 } else if ((message->messageParam == OMX_StateLoaded) && (omx_vorbisdec_component_Private->state == OMX_StateIdle)) {
00706 err = omx_vorbisdec_component_Deinit(openmaxStandComp);
00707 if(err!=OMX_ErrorNone) {
00708 DEBUG(DEB_LEV_ERR, "In %s Vorbis Decoder Deinit Failed=%x\n",__func__,err);
00709 return err;
00710 }
00711 }
00712 }
00713
00714 return omx_base_component_MessageHandler(openmaxStandComp, message);
00715 }