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