00001
00026 #include "omxaudiomixertest.h"
00027 #include "ctype.h"
00028
00029 #define SINK_NAME "OMX.nokia.outputstream.component"
00030 #define BUFFER_COUNT_ACTUAL 2
00031 #define FRAME_SIZE 1152*2*2 // 1152 samples* 2 channels * 2byte/16bits per channel
00032
00033 static void setHeader(OMX_PTR header, OMX_U32 size) {
00034 OMX_VERSIONTYPE* ver = (OMX_VERSIONTYPE*)((char*)header + sizeof(OMX_U32));
00035 *((OMX_U32*)header) = size;
00036
00037 ver->s.nVersionMajor = VERSIONMAJOR;
00038 ver->s.nVersionMinor = VERSIONMINOR;
00039 ver->s.nRevision = VERSIONREVISION;
00040 ver->s.nStep = VERSIONSTEP;
00041 }
00042
00043
00044 appPrivateType* appPriv;
00045 int fd = 0,fd1=0;
00046 unsigned int filesize,filesize1;
00047 int flagIsGain[4];
00048 int flagPlaybackOn;
00049 int flagSetupTunnel;
00050 int flagSampleRate;
00051 int flagChannel;
00052 char *input_file[2], *output_file;
00053 static OMX_BOOL bEOS1=OMX_FALSE,bEOS2=OMX_FALSE;
00054
00055 OMX_BUFFERHEADERTYPE *inBuffer[4], *outBuffer[2],*inBufferSink[2];
00056 static OMX_BOOL isPortDisabled[4];
00057 static int iBufferDropped[2];
00058
00059 int main(int argc, char** argv) {
00060
00061 OMX_CALLBACKTYPE callbacks;
00062 OMX_CALLBACKTYPE audiosinkcallbacks;
00063 OMX_PORT_PARAM_TYPE sParam;
00064 OMX_U32 data_read,j;
00065 OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
00066 OMX_AUDIO_CONFIG_VOLUMETYPE sVolume;
00067 OMX_AUDIO_PARAM_PCMMODETYPE sPcmModeType;
00068 int gain[4];
00069 int i=0;
00070 OMX_U32 srate=0,nchannel=0;
00071 OMX_ERRORTYPE err;
00072
00073 callbacks.EventHandler = audiomixerEventHandler;
00074 callbacks.EmptyBufferDone = audiomixerEmptyBufferDone;
00075 callbacks.FillBufferDone = audiomixerFillBufferDone;
00076
00077 audiosinkcallbacks.EventHandler = audiosinkEventHandler;
00078 audiosinkcallbacks.EmptyBufferDone = audiosinkEmptyBufferDone;
00079 audiosinkcallbacks.FillBufferDone = NULL;
00080
00081 gain[0]=gain[1]=gain[2]=gain[3]=50;
00082
00083 flagIsGain[0] = 1;
00084 flagIsGain[1] = 1;
00085 flagIsGain[2] = 1;
00086 flagIsGain[3] = 1;
00087 flagPlaybackOn = 1;
00088 flagSetupTunnel = 1;
00089 srate = 44100;
00090 nchannel = 2;
00091
00092 if (flagSetupTunnel)
00093 {
00094 flagPlaybackOn = 1;
00095 }
00096
00097 fd = open("C:\\spede_44k.raw", O_RDONLY);
00098 if(fd < 0){
00099 perror("Error opening input file 1\n");
00100 exit(1);
00101 }
00102
00103 fd1 = open("C:\\vesku_44k.raw", O_RDONLY);
00104 if(fd1 < 0){
00105 perror("Error opening input file 2\n");
00106 exit(1);
00107 }
00108
00109 filesize = getFileSize(fd);
00110 filesize1 = getFileSize(fd1);
00111
00112
00113 appPriv = malloc(sizeof(appPrivateType));
00114 pthread_cond_init(&appPriv->condition, NULL);
00115 pthread_mutex_init(&appPriv->mutex, NULL);
00116 appPriv->eventSem = malloc(sizeof(tsem_t));
00117 tsem_init(appPriv->eventSem, 0);
00118 appPriv->eofSem = malloc(sizeof(tsem_t));
00119 tsem_init(appPriv->eofSem, 0);
00120
00121 if (flagPlaybackOn) {
00122 appPriv->sinkEventSem = malloc(sizeof(tsem_t));
00123 tsem_init(appPriv->sinkEventSem, 0);
00124 }
00125 iBufferDropped[0] = 0;
00126 iBufferDropped[1] = 0;
00127
00128 err = OMX_Init();
00129 if(err != OMX_ErrorNone) {
00130 DEBUG(DEB_LEV_ERR, "OMX_Init() failed\n");
00131 exit(1);
00132 }
00133
00135 err = OMX_GetHandle(&appPriv->handle, "OMX.st.audio.mixer", NULL , &callbacks);
00136 if(err != OMX_ErrorNone) {
00137 DEBUG(DEB_LEV_ERR, "Audio Mixer OMX_GetHandle failed\n");
00138 exit(1);
00139 }
00140 if (flagPlaybackOn) {
00141 err = OMX_GetHandle(&appPriv->audiosinkhandle, SINK_NAME, NULL , &audiosinkcallbacks);
00142 if(err != OMX_ErrorNone){
00143 DEBUG(DEB_LEV_ERR, "No sink found. Exiting...\n");
00144 exit(1);
00145 }
00146 }
00147
00148
00149 for(j=0;j<4;j++) {
00150 isPortDisabled[i] = OMX_FALSE;
00151 if((gain[j] >= 0) && (gain[j] <100)) {
00152 sVolume.nPortIndex = j;
00153 err = OMX_GetConfig(appPriv->handle, OMX_IndexConfigAudioVolume, &sVolume);
00154 if(err!=OMX_ErrorNone) {
00155 DEBUG(DEB_LEV_ERR,"Error %08x In OMX_GetConfig 0 \n",err);
00156 }
00157 sVolume.sVolume.nValue = gain[j];
00158 DEBUG(DEFAULT_MESSAGES, "Setting Gain[%i] %d \n",(int)j, gain[j]);
00159 err = OMX_SetConfig(appPriv->handle, OMX_IndexConfigAudioVolume, &sVolume);
00160 if(err!=OMX_ErrorNone) {
00161 DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetConfig 0 \n",err);
00162 }
00163 }
00164 }
00165
00166
00167 if(srate && nchannel && flagPlaybackOn) {
00168 DEBUG(DEFAULT_MESSAGES, "Sample Rate=%d,NChannel=%d\n",(int)srate,(int)nchannel);
00169 sPcmModeType.nPortIndex=0;
00170 setHeader(&sPcmModeType, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00171 err = OMX_GetParameter(appPriv->audiosinkhandle, OMX_IndexParamAudioPcm, &sPcmModeType);
00172
00173 sPcmModeType.nChannels = nchannel;
00174 sPcmModeType.nSamplingRate = srate;
00175 err = OMX_SetParameter(appPriv->audiosinkhandle, OMX_IndexParamAudioPcm, &sPcmModeType);
00176 if(err!=OMX_ErrorNone) {
00177 DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetParameter 0 \n",err);
00178 }
00179 }
00180
00181 if (flagSetupTunnel) {
00182 err = OMX_SetupTunnel(appPriv->handle, 4, appPriv->audiosinkhandle, 0);
00183 if(err != OMX_ErrorNone) {
00184 DEBUG(DEB_LEV_ERR, "Set up Tunnel Failed\n");
00185 exit(1);
00186 }
00187 DEBUG(DEFAULT_MESSAGES, "Set up Tunnel Completed\n");
00188 }
00189
00191 setHeader(&sParam, sizeof(OMX_PORT_PARAM_TYPE));
00192 err = OMX_GetParameter(appPriv->handle, OMX_IndexParamAudioInit, &sParam);
00193 if(err != OMX_ErrorNone){
00194 DEBUG(DEB_LEV_ERR, "Error in getting OMX_PORT_PARAM_TYPE parameter\n");
00195 exit(1);
00196 }
00197 DEBUG(DEFAULT_MESSAGES, "Audio Mixer has %d ports\n",(int)sParam.nPorts);
00198
00199 setHeader(&sPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00200 sPortDef.nPortIndex = 0;
00201 err = OMX_GetParameter(appPriv->handle, OMX_IndexParamPortDefinition, &sPortDef);
00202
00203 sPortDef.nBufferCountActual = 2;
00204 err = OMX_SetParameter(appPriv->handle, OMX_IndexParamPortDefinition, &sPortDef);
00205 if(err != OMX_ErrorNone){
00206 DEBUG(DEB_LEV_ERR, "Error in getting OMX_PORT_PARAM_TYPE parameter\n");
00207 exit(1);
00208 }
00209 sPortDef.nPortIndex = 1;
00210 err = OMX_GetParameter(appPriv->handle, OMX_IndexParamPortDefinition, &sPortDef);
00211
00212 sPortDef.nBufferCountActual = 2;
00213 err = OMX_SetParameter(appPriv->handle, OMX_IndexParamPortDefinition, &sPortDef);
00214 if(err != OMX_ErrorNone){
00215 DEBUG(DEB_LEV_ERR, "Error in getting OMX_PORT_PARAM_TYPE parameter\n");
00216 exit(1);
00217 }
00218
00219
00220 isPortDisabled[2] = OMX_TRUE;
00221 isPortDisabled[3] = OMX_TRUE;
00222 err = OMX_SendCommand(appPriv->handle, OMX_CommandPortDisable, 2, NULL);
00223 err = OMX_SendCommand(appPriv->handle, OMX_CommandPortDisable, 3, NULL);
00224 tsem_down(appPriv->eventSem);
00225 tsem_down(appPriv->eventSem);
00226
00227
00228 err = OMX_SendCommand(appPriv->handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00229 if (flagPlaybackOn) {
00230 err = OMX_SendCommand(appPriv->audiosinkhandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00231 }
00232
00233 inBuffer[0] = inBuffer[1] = inBuffer[2] = inBuffer[3]= outBuffer[0] = outBuffer[1] = NULL;
00234
00235 for(j=0;j<BUFFER_COUNT_ACTUAL;j++) {
00236 err = OMX_AllocateBuffer(appPriv->handle, &inBuffer[j], 0, NULL, BUFFER_IN_SIZE);
00237 if (err != OMX_ErrorNone) {
00238 DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer in %i %i\n",(int)j, err);
00239 exit(1);
00240 }
00241 err = OMX_AllocateBuffer(appPriv->handle, &inBuffer[j+ 2], 1, NULL, BUFFER_IN_SIZE);
00242 if (err != OMX_ErrorNone) {
00243 DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer in %i %i\n",(int)j+2, err);
00244 exit(1);
00245 }
00246 }
00247
00248 if (flagPlaybackOn) {
00249 tsem_down(appPriv->sinkEventSem);
00250 DEBUG(DEB_LEV_SIMPLE_SEQ,"audio sink state idle\n");
00251 }
00252 tsem_down(appPriv->eventSem);
00253
00254 err = OMX_SendCommand(appPriv->handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00255
00256
00257 tsem_down(appPriv->eventSem);
00258
00259 if (flagPlaybackOn) {
00260 DEBUG(DEB_LEV_SIMPLE_SEQ,"sending audio sink state executing\n");
00261 err = OMX_SendCommand(appPriv->audiosinkhandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00262 if(err != OMX_ErrorNone) {
00263 DEBUG(DEB_LEV_ERR,"audio sink state executing failed\n");
00264 exit(1);
00265 }
00266 DEBUG(DEB_LEV_SIMPLE_SEQ,"waiting for audio sink state executing\n");
00267 tsem_down(appPriv->sinkEventSem);
00268 DEBUG(DEB_LEV_SIMPLE_SEQ, "audio sink state executing successful\n");
00269 }
00270 DEBUG(DEB_LEV_PARAMS, "Had buffers at:\n0x%08x\n0x%08x\n0x%08x\n0x%08x\n",
00271 (int)inBuffer[0]->pBuffer, (int)inBuffer[1]->pBuffer, (int)outBuffer[0]->pBuffer, (int)outBuffer[1]->pBuffer);
00272 DEBUG(DEB_LEV_PARAMS, "After switch to executing\n");
00273
00274 for(j=0;j<BUFFER_COUNT_ACTUAL;j++) {
00275 data_read = read(fd, inBuffer[j]->pBuffer, FRAME_SIZE);
00276 inBuffer[0]->nFilledLen = data_read;
00277 filesize -= data_read;
00278
00279 data_read = read(fd1, inBuffer[j+2]->pBuffer, FRAME_SIZE);
00280 inBuffer[2]->nFilledLen = data_read;
00281 filesize1 -= data_read;
00282 }
00283
00284 for(j=0;j<BUFFER_COUNT_ACTUAL*2;j++) {
00285 DEBUG(DEB_LEV_PARAMS, "Empty %i buffer %x\n",(int)j, (int)inBuffer[j]);
00286 err = OMX_EmptyThisBuffer(appPriv->handle, inBuffer[j]);
00287 }
00288
00289 DEBUG(DEFAULT_MESSAGES, "Waiting for EOS\n");
00290 if(isPortDisabled[0] == OMX_FALSE) {
00291 tsem_down(appPriv->eofSem);
00292 DEBUG(DEFAULT_MESSAGES, "Received EOS 1\n");
00293 }
00294 if(isPortDisabled[1] == OMX_FALSE) {
00295 tsem_down(appPriv->eofSem);
00296 DEBUG(DEFAULT_MESSAGES, "Received EOS 2\n");
00297 }
00298
00299 err = OMX_SendCommand(appPriv->handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00300 if (flagPlaybackOn) {
00301 err = OMX_SendCommand(appPriv->audiosinkhandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00302 }
00303
00304 printf("waiting for sink to idle callback\n");
00305
00306 if (flagPlaybackOn) {
00307 tsem_down(appPriv->sinkEventSem);
00308 }
00309
00310
00311 printf("waiting for decoder to idle callback\n");
00312
00313 tsem_down(appPriv->eventSem);
00314
00315 err = OMX_SendCommand(appPriv->handle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
00316 if (flagPlaybackOn) {
00317 err = OMX_SendCommand(appPriv->audiosinkhandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
00318 }
00319
00320 for(j=0;j<BUFFER_COUNT_ACTUAL;j++) {
00321 if(isPortDisabled[0] == OMX_FALSE) {
00322 err = OMX_FreeBuffer(appPriv->handle, 0, inBuffer[j]);
00323 }
00324 if(isPortDisabled[1] == OMX_FALSE) {
00325 err = OMX_FreeBuffer(appPriv->handle, 1, inBuffer[j+2]);
00326 }
00327 }
00328
00329 printf("waiting for sink to loaded callback\n");
00330
00331 if (flagPlaybackOn) {
00332 tsem_down(appPriv->sinkEventSem);
00333 }
00334
00335 printf("waiting for decoder to loaded callback\n");
00336
00337
00338 tsem_down(appPriv->eventSem);
00339
00340 OMX_FreeHandle(appPriv->handle);
00341
00342 free(appPriv->eventSem);
00343 free(appPriv);
00344 if (flagPlaybackOn) {
00345 free(appPriv->sinkEventSem);
00346 appPriv->sinkEventSem = NULL;
00347 }
00348
00349 close(fd);
00350 close(fd1);
00351 free(input_file[0]);
00352 free(input_file[1]);
00353
00354
00355
00356 return 0;
00357 }
00358
00359
00360 OMX_ERRORTYPE audiomixerEventHandler(
00361 OMX_OUT OMX_HANDLETYPE hComponent,
00362 OMX_OUT OMX_PTR pAppData,
00363 OMX_OUT OMX_EVENTTYPE eEvent,
00364 OMX_OUT OMX_U32 Data1,
00365 OMX_OUT OMX_U32 Data2,
00366 OMX_IN OMX_PTR pEventData) {
00367
00368 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
00369 if(eEvent == OMX_EventCmdComplete) {
00370 if (Data1 == OMX_CommandStateSet) {
00371 DEBUG(DEB_LEV_SIMPLE_SEQ, "Volume Component State changed in ");
00372 switch ((int)Data2) {
00373 case OMX_StateInvalid:
00374 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00375 break;
00376 case OMX_StateLoaded:
00377 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00378 break;
00379 case OMX_StateIdle:
00380 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
00381 break;
00382 case OMX_StateExecuting:
00383 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00384 break;
00385 case OMX_StatePause:
00386 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00387 break;
00388 case OMX_StateWaitForResources:
00389 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00390 break;
00391 }
00392 tsem_up(appPriv->eventSem);
00393 } else if (Data1 == OMX_CommandPortEnable){
00394 tsem_up(appPriv->eventSem);
00395 } else if (Data1 == OMX_CommandPortDisable){
00396 tsem_up(appPriv->eventSem);
00397 }
00398 } else if(eEvent == OMX_EventBufferFlag) {
00399 if((int)Data2 == OMX_BUFFERFLAG_EOS) {
00400 tsem_up(appPriv->eofSem);
00401 }
00402 } else {
00403 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
00404 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
00405 }
00406
00407 return OMX_ErrorNone;
00408 }
00409
00410 OMX_ERRORTYPE audiomixerEmptyBufferDone(
00411 OMX_OUT OMX_HANDLETYPE hComponent,
00412 OMX_OUT OMX_PTR pAppData,
00413 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00414
00415 int data_read;
00416 OMX_ERRORTYPE err = OMX_ErrorNone;
00417
00418
00419 DEBUG(DEB_LEV_FULL_SEQ, "Hi there, I am in the %s callback.\n", __func__);
00420 if(pBuffer->nInputPortIndex==0) {
00421
00422 if(isPortDisabled[0] == OMX_FALSE) {
00423 data_read = read(fd, pBuffer->pBuffer, FRAME_SIZE);
00424 pBuffer->nFilledLen = data_read;
00425 pBuffer->nOffset = 0;
00426 filesize -= data_read;
00427 DEBUG(DEB_LEV_SIMPLE_SEQ, "Sending from file 1 data read=%d\n",data_read);
00428 if (data_read <= 0) {
00429 DEBUG(DEB_LEV_SIMPLE_SEQ, "In the %s no more input data available\n", __func__);
00430 ++iBufferDropped[0];
00431 if(iBufferDropped[0]==2) {
00432 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Dropping Empty This buffer to Audio Mixer Stream 1\n", __func__);
00433 tsem_up(appPriv->eofSem);
00434 return OMX_ErrorNone;
00435 } else if(iBufferDropped[0]>2) {
00436 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Dropping Empty This buffer to Audio Mixer Stream 1\n", __func__);
00437 return OMX_ErrorNone;
00438 }
00439 pBuffer->nFilledLen=0;
00440 pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
00441 bEOS1=OMX_TRUE;
00442 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Sending EOS for Stream 1\n", __func__);
00443 err = OMX_EmptyThisBuffer(hComponent, pBuffer);
00444 return OMX_ErrorNone;
00445 }
00446 } else {
00447 ++iBufferDropped[0];
00448 return OMX_ErrorNone;
00449 }
00450 } else if(pBuffer->nInputPortIndex==1) {
00451
00452 if(isPortDisabled[1] == OMX_FALSE) {
00453 data_read = read(fd1, pBuffer->pBuffer, FRAME_SIZE);
00454 pBuffer->nFilledLen = data_read;
00455 pBuffer->nOffset = 0;
00456 filesize1 -= data_read;
00457 DEBUG(DEB_LEV_SIMPLE_SEQ, "Sending from file 2 data read=%d\n",data_read);
00458 if (data_read <= 0) {
00459 DEBUG(DEB_LEV_SIMPLE_SEQ, "In the %s no more input data available\n", __func__);
00460 ++iBufferDropped[1];
00461 if(iBufferDropped[1]==2) {
00462 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Dropping Empty This buffer to Audio Mixer Stream 2\n", __func__);
00463 tsem_up(appPriv->eofSem);
00464 return OMX_ErrorNone;
00465 } else if(iBufferDropped[1]>2) {
00466 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Dropping Empty This buffer to Audio Mixer Stream 2\n", __func__);
00467 return OMX_ErrorNone;
00468 }
00469 pBuffer->nFilledLen=0;
00470 pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
00471 bEOS2=OMX_TRUE;
00472 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Sending EOS for Stream 2\n", __func__);
00473 err = OMX_EmptyThisBuffer(hComponent, pBuffer);
00474 return OMX_ErrorNone;
00475 }
00476 }else {
00477 ++iBufferDropped[1];
00478 return OMX_ErrorNone;
00479 }
00480 }
00481 if(!bEOS1 || !bEOS2 ) {
00482 DEBUG(DEB_LEV_FULL_SEQ, "Empty buffer %x\n", (int)pBuffer);
00483 err = OMX_EmptyThisBuffer(hComponent, pBuffer);
00484 }else {
00485 DEBUG(DEB_LEV_FULL_SEQ, "In %s Dropping Empty This buffer to Audio Mixer\n", __func__);
00486 }
00487
00488 return err;
00489 }
00490
00491 OMX_ERRORTYPE audiomixerFillBufferDone(
00492 OMX_OUT OMX_HANDLETYPE hComponent,
00493 OMX_OUT OMX_PTR pAppData,
00494 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00495
00496 OMX_ERRORTYPE err;
00497 int i;
00498
00499 DEBUG(DEB_LEV_FULL_SEQ, "Hi there, I am in the %s callback. Got buflen %i for buffer at 0x%08x\n",
00500 __func__, (int)pBuffer->nFilledLen, (int)pBuffer);
00501
00502
00503 if(pBuffer != NULL) {
00504 if (pBuffer->nFilledLen == 0) {
00505 DEBUG(DEB_LEV_ERR, "Ouch! In %s: no data in the output buffer!\n", __func__);
00506 return OMX_ErrorNone;
00507 } else if (flagPlaybackOn) {
00508 if(inBufferSink[0]->pBuffer == pBuffer->pBuffer) {
00509 inBufferSink[0]->nFilledLen = pBuffer->nFilledLen;
00510 err = OMX_EmptyThisBuffer(appPriv->audiosinkhandle, inBufferSink[0]);
00511 } else {
00512 inBufferSink[1]->nFilledLen = pBuffer->nFilledLen;
00513 err = OMX_EmptyThisBuffer(appPriv->audiosinkhandle, inBufferSink[1]);
00514 }
00515 if(err != OMX_ErrorNone) {
00516 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling EmptyThisBuffer\n", __func__,err);
00517 }
00518 } else {
00519 for(i=0;i<pBuffer->nFilledLen;i++) {
00520 putchar(*(char*)(pBuffer->pBuffer + i));
00521 }
00522 pBuffer->nFilledLen = 0;
00523
00524 if(!bEOS1 || !bEOS2) {
00525 err = OMX_FillThisBuffer(hComponent, pBuffer);
00526 } else {
00527 DEBUG(DEB_LEV_FULL_SEQ, "In %s Dropping Fill This buffer to Audio Mixer\n", __func__);
00528 }
00529 }
00530 } else {
00531 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
00532 }
00533
00534 return OMX_ErrorNone;
00535 }
00536
00537 OMX_ERRORTYPE audiosinkEventHandler(
00538 OMX_OUT OMX_HANDLETYPE hComponent,
00539 OMX_OUT OMX_PTR pAppData,
00540 OMX_OUT OMX_EVENTTYPE eEvent,
00541 OMX_OUT OMX_U32 Data1,
00542 OMX_OUT OMX_U32 Data2,
00543 OMX_OUT OMX_PTR pEventData) {
00544 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
00545 if (Data1 == OMX_CommandStateSet) {
00546 DEBUG(DEB_LEV_SIMPLE_SEQ, "Audio Sink State changed in ");
00547 switch ((int)Data2) {
00548 case OMX_StateInvalid:
00549 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00550 break;
00551 case OMX_StateLoaded:
00552 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00553 break;
00554 case OMX_StateIdle:
00555 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
00556 break;
00557 case OMX_StateExecuting:
00558 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00559 break;
00560 case OMX_StatePause:
00561 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00562 break;
00563 case OMX_StateWaitForResources:
00564 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00565 break;
00566 }
00567 tsem_up(appPriv->sinkEventSem);
00568 } else if (Data1 == OMX_CommandPortEnable){
00569 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Received Port Enable Event\n",__func__);
00570 tsem_up(appPriv->sinkEventSem);
00571 } else if (Data1 == OMX_CommandPortDisable){
00572 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Received Port Disable Event\n",__func__);
00573 tsem_up(appPriv->sinkEventSem);
00574 } else {
00575 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
00576 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
00577 }
00578
00579 return OMX_ErrorNone;
00580 }
00581
00582 OMX_ERRORTYPE audiosinkEmptyBufferDone(
00583 OMX_OUT OMX_HANDLETYPE hComponent,
00584 OMX_OUT OMX_PTR pAppData,
00585 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer)
00586 {
00587 OMX_ERRORTYPE err;
00588 static int alsaSinkBufferDropped=0;
00589 DEBUG(DEB_LEV_FULL_SEQ, "Hi there, I am in the %s callback.\n", __func__);
00590
00591 DEBUG(DEB_LEV_PARAMS, "Empty buffer %x\n", (int)pBuffer);
00592 if(!bEOS1 || !bEOS2) {
00593 if(outBuffer[0]->pBuffer == pBuffer->pBuffer) {
00594 outBuffer[0]->nFilledLen=0;
00595 err = OMX_FillThisBuffer(appPriv->handle, outBuffer[0]);
00596 } else {
00597 outBuffer[1]->nFilledLen=0;
00598 err = OMX_FillThisBuffer(appPriv->handle, outBuffer[1]);
00599 }
00600 if(err != OMX_ErrorNone) {
00601 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling FillThisBuffer\n", __func__,err);
00602 }
00603 } else {
00604 DEBUG(DEFAULT_MESSAGES,"In %s EOS reached\n",__func__);
00605 alsaSinkBufferDropped++;
00606 tsem_up(appPriv->eofSem);
00607 }
00608
00609 return OMX_ErrorNone;
00610 }
00611
00616 static int getFileSize(int fd) {
00617
00618 struct stat input_file_stat;
00619 int err;
00620
00621
00622 err = fstat(fd, &input_file_stat);
00623 if(err){
00624 DEBUG(DEB_LEV_ERR, "fstat failed");
00625 exit(-1);
00626 }
00627 return input_file_stat.st_size;
00628 }