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