OpenMAXBellagio  0.9.3
omxaudiomixertest.c
Go to the documentation of this file.
00001 
00028 #include "omxaudiomixertest.h"
00029 
00030 #define BUFFER_COUNT_ACTUAL 2
00031 #define FRAME_SIZE 1152*2*2 // 1152 samples* 2 channels * 2byte/16bits per channel
00032 
00033 OMX_CALLBACKTYPE callbacks = { .EventHandler = audiomixerEventHandler,
00034                                .EmptyBufferDone = audiomixerEmptyBufferDone,
00035                                .FillBufferDone = audiomixerFillBufferDone,
00036 };
00037 
00038 static void setHeader(OMX_PTR header, OMX_U32 size) {
00039   OMX_VERSIONTYPE* ver = (OMX_VERSIONTYPE*)(header + sizeof(OMX_U32));
00040   *((OMX_U32*)header) = size;
00041 
00042   ver->s.nVersionMajor = VERSIONMAJOR;
00043   ver->s.nVersionMinor = VERSIONMINOR;
00044   ver->s.nRevision = VERSIONREVISION;
00045   ver->s.nStep = VERSIONSTEP;
00046 }
00047 
00048 void display_help() {
00049   printf("\n");
00050   printf("Usage: omxaudiomixertest [-o outfile] [-gi gain] -t -r 44100 -n 2 filename0 [filename1 filename2 filename3]\n");
00051   printf("\n");
00052   printf("       -o outfile: If this option is specified, the output stream is written to outfile\n");
00053   printf("                   otherwise redirected to std output\n");
00054   printf("       -gi       : Gain of stream i[0..3] data [0...100]\n");
00055   printf("       -r 44100  : Sample Rate [Default 44100]\n");
00056   printf("       -n 2      : Number of channel [Default 2]\n\n");
00057   printf("       -h        : Displays this help\n");
00058   printf("\n");
00059   exit(1);
00060 }
00061 
00062 /* Application private date: should go in the component field (segs...) */
00063 appPrivateType* appPriv;
00064 int fd[4];
00065 unsigned int filesize[4];
00066 int flagIsOutputExpected;
00067 int flagOutputReceived;
00068 int flagInputReceived;
00069 int flagIsGain[4];
00070 int flagSampleRate;
00071 int flagChannel;
00072 char *input_file[4], *output_file;
00073 OMX_BOOL bEOS[4];
00074 FILE *outfile;
00075 
00076 OMX_BUFFERHEADERTYPE *inBuffer[8], *outBuffer[2],*inBufferSink[2];
00077 static OMX_BOOL isPortDisabled[4];
00078 static int iBufferDropped[4];
00079 
00080 int main(int argc, char** argv) {
00081 
00082   OMX_PORT_PARAM_TYPE sParam;
00083   OMX_U32 data_read;
00084   int j;
00085   int i=0;
00086   OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
00087   OMX_AUDIO_CONFIG_VOLUMETYPE sVolume;
00088   int gain[4];
00089   int argn_dec;
00090   int index_files = 0, index_gain = 0;
00091   OMX_ERRORTYPE err;
00092   char c;
00093 
00094   gain[0]=gain[1]=gain[2]=gain[3]=100;
00095   fd[0] = fd[1] = fd[2] = fd[3] = 0;
00096   bEOS[0] = bEOS[1] = bEOS[2] = bEOS[3] = OMX_FALSE;
00097   /* Obtain file descriptor */
00098   if(argc < 2){
00099     display_help();
00100   } else {
00101     flagIsOutputExpected = 0;
00102     flagOutputReceived = 0;
00103     flagInputReceived = 0;
00104     flagIsGain[0] = 0;
00105     flagIsGain[1] = 0;
00106     flagIsGain[2] = 0;
00107     flagIsGain[3] = 0;
00108     flagSampleRate = 0;
00109     flagChannel = 0;
00110 
00111     argn_dec = 1;
00112     while (argn_dec<argc) {
00113       if (*(argv[argn_dec]) =='-') {
00114         if (flagIsOutputExpected) {
00115           display_help();
00116         }
00117         switch (*(argv[argn_dec]+1)) {
00118         case 'h':
00119           display_help();
00120           break;
00121         case 'o':
00122           flagIsOutputExpected = 1;
00123           break;
00124         case 'g':
00125             index_gain = atoi(argv[argn_dec]+2);
00126             if(index_gain > 3) {
00127                 DEBUG(DEFAULT_MESSAGES, "-g%i is not valid\n", index_gain);
00128                 index_gain = 0;
00129             }
00130             flagIsGain[index_gain] = 1;
00131         break;
00132         case 'r':
00133           flagSampleRate = 1;
00134           break;
00135         case 'n':
00136           flagChannel = 1;
00137           break;
00138         default:
00139           display_help();
00140         }
00141       } else {
00142         if (flagIsGain[index_gain]) {
00143           gain[index_gain] = (int)atoi(argv[argn_dec]);
00144           DEBUG(DEFAULT_MESSAGES, "gain[%d]=%d\n", index_gain, gain[index_gain]);
00145           flagIsGain[index_gain] = 0;
00146           if(gain[index_gain] > 100) {
00147             DEBUG(DEFAULT_MESSAGES, "Gain of stream %i should be between [0..100]\n", index_gain);
00148             gain[index_gain] = 100;
00149           }
00150           index_gain = 0;
00151         } else if (flagIsOutputExpected) {
00152           output_file = malloc(strlen(argv[argn_dec]) * sizeof(char) + 1);
00153           strcpy(output_file,argv[argn_dec]);
00154           flagIsOutputExpected = 0;
00155           flagOutputReceived = 1;
00156         } else if (flagSampleRate) {
00157           flagSampleRate = 0;
00158         } else if (flagChannel) {
00159           flagChannel = 0;
00160         } else {
00161             if (index_files>3) {
00162                 DEBUG(DEB_LEV_ERR, "Too many input files. Only first four are accepted\n");
00163             } else {
00164                 input_file[index_files] = malloc(strlen(argv[argn_dec]) * sizeof(char) + 1);
00165                 strcpy(input_file[index_files],argv[argn_dec]);
00166                 flagInputReceived = 1;
00167                 index_files++;
00168             }
00169         }
00170       }
00171       argn_dec++;
00172     }
00173     if (!flagInputReceived) {
00174       display_help();
00175     }
00176     DEBUG(DEFAULT_MESSAGES, "Input files %s %s %s %s \n", input_file[0], input_file[1], input_file[2], input_file[3]);
00177     DEBUG(DEFAULT_MESSAGES, " to ");
00178     if (flagOutputReceived) {
00179       DEBUG(DEFAULT_MESSAGES, " %s\n", output_file);
00180     } else {
00181       DEBUG(DEFAULT_MESSAGES, " Audio Sink\n");
00182     }
00183   }
00184 
00185   if(input_file[0]== NULL)  {
00186     DEBUG(DEB_LEV_ERR, "Provide at least an input file\n");
00187     exit(1);
00188   }
00189 
00190   for (i = 0; i<index_files; i++) {
00191       fd[i] = open(input_file[i], O_RDONLY);
00192       if(fd[i] < 0){
00193           DEBUG(DEB_LEV_ERR, "Error opening input file %i\n", i);
00194           exit(1);
00195       }
00196   }
00197 
00198   if (flagOutputReceived) {
00199     outfile = fopen(output_file,"wb");
00200     if(outfile == NULL) {
00201       DEBUG(DEB_LEV_ERR, "Error at opening the output file");
00202       exit(1);
00203     }
00204   }
00205 
00206 
00207   for (i = 0; i<index_files; i++) {
00208       filesize[i] = getFileSize(fd[i]);
00209   }
00210 
00211   /* Initialize application private data */
00212   appPriv = malloc(sizeof(appPrivateType));
00213   pthread_cond_init(&appPriv->condition, NULL);
00214   pthread_mutex_init(&appPriv->mutex, NULL);
00215   appPriv->eventSem = malloc(sizeof(tsem_t));
00216   tsem_init(appPriv->eventSem, 0);
00217   appPriv->eofSem = malloc(sizeof(tsem_t));
00218   tsem_init(appPriv->eofSem, 0);
00219   iBufferDropped[0] = 0;
00220   iBufferDropped[1] = 0;
00221   iBufferDropped[2] = 0;
00222   iBufferDropped[3] = 0;
00223 
00224   err = OMX_Init();
00225   if(err != OMX_ErrorNone) {
00226     DEBUG(DEB_LEV_ERR, "OMX_Init() failed\n");
00227     exit(1);
00228   }
00230   err = OMX_GetHandle(&appPriv->handle, "OMX.st.audio.mixer", NULL , &callbacks);
00231   if(err != OMX_ErrorNone) {
00232     DEBUG(DEB_LEV_ERR, "Audio Mixer OMX_GetHandle failed\n");
00233     exit(1);
00234   }
00235 
00236   /*Max 4 input stream*/
00237   for(j=0;j<4;j++) {
00238     isPortDisabled[j] = OMX_FALSE;
00239     if((gain[j] >= 0) && (gain[j] <100)) {
00240       sVolume.nPortIndex = j;
00241       err = OMX_GetConfig(appPriv->handle, OMX_IndexConfigAudioVolume, &sVolume);
00242       if(err!=OMX_ErrorNone) {
00243         DEBUG(DEB_LEV_ERR,"Error %08x In OMX_GetConfig %i \n",err, j);
00244       }
00245       sVolume.sVolume.nValue = gain[j];
00246       DEBUG(DEFAULT_MESSAGES, "Setting Gain[%i] %d \n",(int)j, gain[j]);
00247       err = OMX_SetConfig(appPriv->handle, OMX_IndexConfigAudioVolume, &sVolume);
00248       if(err!=OMX_ErrorNone) {
00249         DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetConfig %i \n",err, j);
00250       }
00251     }
00252   }
00253 
00255   setHeader(&sParam, sizeof(OMX_PORT_PARAM_TYPE));
00256   err = OMX_GetParameter(appPriv->handle, OMX_IndexParamAudioInit, &sParam);
00257   if(err != OMX_ErrorNone){
00258     DEBUG(DEB_LEV_ERR, "Error in getting OMX_PORT_PARAM_TYPE parameter\n");
00259     exit(1);
00260   }
00261   DEBUG(DEFAULT_MESSAGES, "Audio Mixer has %d ports\n",(int)sParam.nPorts);
00262 
00263 // disable unused ports
00264   for (j = index_files; j<4; j++) {
00265       isPortDisabled[j] = OMX_TRUE;
00266       err = OMX_SendCommand(appPriv->handle, OMX_CommandPortDisable, j, NULL);
00267       tsem_down(appPriv->eventSem);
00268       DEBUG(DEFAULT_MESSAGES, "Port %i disabled\n", j);
00269   }
00270   for (j = 0; j < index_files; j++) {
00271       setHeader(&sPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00272       sPortDef.nPortIndex = j;
00273       err = OMX_GetParameter(appPriv->handle, OMX_IndexParamPortDefinition, &sPortDef);
00274 
00275       sPortDef.nBufferCountActual = 2;
00276       err = OMX_SetParameter(appPriv->handle, OMX_IndexParamPortDefinition, &sPortDef);
00277       if(err != OMX_ErrorNone){
00278           DEBUG(DEB_LEV_ERR, "Error in getting OMX_PORT_PARAM_TYPE parameter\n");
00279           exit(1);
00280       }
00281   }
00282 
00283   err = OMX_SendCommand(appPriv->handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00284 
00285   for (j=0; j<8; j++) {
00286       inBuffer[j] = 0;
00287   }
00288   outBuffer[0] = outBuffer[1] = NULL;
00289 
00290 
00291   for(j=0; j<index_files; j++) {
00292     err = OMX_AllocateBuffer(appPriv->handle, &inBuffer[j*2], j, NULL, BUFFER_IN_SIZE);
00293     if (err != OMX_ErrorNone) {
00294       DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer %i %p on port %i\n", j*2, inBuffer[j*2], j);
00295       exit(1);
00296     }
00297     err = OMX_AllocateBuffer(appPriv->handle, &inBuffer[j * 2 + 1], j, NULL, BUFFER_IN_SIZE);
00298     if (err != OMX_ErrorNone) {
00299       DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer %i %p on port %i\n", j*2+1, inBuffer[j*2+1], j);
00300       exit(1);
00301     }
00302   }
00303 
00304    err = OMX_AllocateBuffer(appPriv->handle, &outBuffer[0], 4, NULL, BUFFER_IN_SIZE);
00305    if (err != OMX_ErrorNone) {
00306      DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer 0 %p on port 4\n", outBuffer[0]);
00307      exit(1);
00308    }
00309    err = OMX_AllocateBuffer(appPriv->handle, &outBuffer[1], 4, NULL, BUFFER_IN_SIZE);
00310    if (err != OMX_ErrorNone) {
00311      DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer 1 %p on port 4\n", outBuffer[1]);
00312      exit(1);
00313    }
00314 
00315   tsem_down(appPriv->eventSem);
00316 
00317   err = OMX_SendCommand(appPriv->handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00318 
00319   /* Wait for commands to complete */
00320   tsem_down(appPriv->eventSem);
00321 
00322   for (i = 0; i<index_files; i++) {
00323         data_read = read(fd[i], inBuffer[i*2]->pBuffer, FRAME_SIZE);
00324         inBuffer[i*2]->nFilledLen = data_read;
00325         filesize[i] -= data_read;
00326         data_read = read(fd[i], inBuffer[i*2+1]->pBuffer, FRAME_SIZE);
00327         inBuffer[i*2+1]->nFilledLen = data_read;
00328         filesize[i] -= data_read;
00329   }
00330 
00331 
00332   for (i = 0; i<index_files; i++) {
00333       err = OMX_EmptyThisBuffer(appPriv->handle, inBuffer[i*2]);
00334       err = OMX_EmptyThisBuffer(appPriv->handle, inBuffer[i*2+1]);
00335   }
00336 
00340   err = OMX_FillThisBuffer(appPriv->handle, outBuffer[0]);
00341   err = OMX_FillThisBuffer(appPriv->handle, outBuffer[1]);
00342 
00343   /*Port Disable option available in case of direct play out only*/
00344   if(!flagOutputReceived) {
00345       DEBUG(DEFAULT_MESSAGES, "\nIf you want to disabled port enter port number[0..3]: else Enter 'q' \n\n");
00346       while(!bEOS[0] || !bEOS[1] || !bEOS[2] || !bEOS[3]) {
00347           DEBUG(DEFAULT_MESSAGES, "Port status 0=%i, 1=%i, 2=%i, 3=%i\n",isPortDisabled[0], isPortDisabled[1], isPortDisabled[2], isPortDisabled[3]);
00348           DEBUG(DEFAULT_MESSAGES, "Port play   0=%i, 1=%i, 2=%i, 3=%i\n",bEOS[0], bEOS[1], bEOS[2], bEOS[3]);
00349           DEBUG(DEFAULT_MESSAGES, "Entry : ");
00350           c = getchar();
00351           if(c=='\n') {
00352               continue;
00353           } else if(c == 'q') {
00354               DEBUG(DEFAULT_MESSAGES,"No port to disable\n");
00355               break;
00356           } else {
00357               i= (int)atoi(&c);
00358               if(i>=0 && i<4) {
00359                   DEBUG(DEFAULT_MESSAGES,"Disabling/Enabling Port %i\n", i);
00360                   if (isPortDisabled[i] == OMX_TRUE) {
00361                         err = OMX_SendCommand(appPriv->handle, OMX_CommandPortEnable, i, NULL);
00362                         err = OMX_AllocateBuffer(appPriv->handle, &inBuffer[i*2], i, NULL, BUFFER_IN_SIZE);
00363                         err = OMX_AllocateBuffer(appPriv->handle, &inBuffer[i*2+1], i, NULL, BUFFER_IN_SIZE);
00364                         tsem_down(appPriv->eventSem);
00365                         isPortDisabled[i] = OMX_FALSE;
00366                         data_read = read(fd[i], inBuffer[i*2]->pBuffer, FRAME_SIZE);
00367                         inBuffer[i*2]->nFilledLen = data_read;
00368                         data_read = read(fd[i], inBuffer[i*2+1]->pBuffer, FRAME_SIZE);
00369                         inBuffer[i*2+1]->nFilledLen = data_read;
00370                         //Sending Empty buffer
00371                         err = OMX_EmptyThisBuffer(appPriv->handle, inBuffer[i*2]);
00372                         err = OMX_EmptyThisBuffer(appPriv->handle, inBuffer[i*2+1]);
00373                   } else {
00374                       isPortDisabled[i] = OMX_TRUE;
00375                       err = OMX_SendCommand(appPriv->handle, OMX_CommandPortDisable, i, NULL);
00376                       while(iBufferDropped[i]!=2) {
00377                           usleep(10000);
00378                       }
00379                       for(j=0;j<BUFFER_COUNT_ACTUAL;j++) {
00380                           err = OMX_FreeBuffer(appPriv->handle, i, inBuffer[j+i]);
00381                       }
00382                       tsem_down(appPriv->eventSem);
00383                       iBufferDropped[i] = 0;
00384                   }
00385               } else {
00386                   DEBUG(DEFAULT_MESSAGES,"Either Port %i is already disabled or not valid\n",i);
00387               }
00388           }
00389       }
00390   }
00391 
00392   DEBUG(DEFAULT_MESSAGES, "Waiting for EOS\n");
00393   if(isPortDisabled[0] == OMX_FALSE) {
00394     tsem_down(appPriv->eofSem);
00395     DEBUG(DEFAULT_MESSAGES, "Received EOS 1\n");
00396   }
00397   if(isPortDisabled[1] == OMX_FALSE) {
00398     tsem_down(appPriv->eofSem);
00399     DEBUG(DEFAULT_MESSAGES, "Received EOS 2\n");
00400   }
00401   if(isPortDisabled[2] == OMX_FALSE) {
00402     tsem_down(appPriv->eofSem);
00403     DEBUG(DEFAULT_MESSAGES, "Received EOS 3\n");
00404   }
00405   if(isPortDisabled[3] == OMX_FALSE) {
00406     tsem_down(appPriv->eofSem);
00407     DEBUG(DEFAULT_MESSAGES, "Received EOS 4\n");
00408   }
00409 
00410   err = OMX_SendCommand(appPriv->handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00411   /* Wait for commands to complete */
00412   tsem_down(appPriv->eventSem);
00413 
00414   err = OMX_SendCommand(appPriv->handle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
00415   for(j=0; j<index_files; j++) {
00416     if(isPortDisabled[j] == OMX_FALSE) {
00417       err = OMX_FreeBuffer(appPriv->handle, j, inBuffer[j*2]);
00418       err = OMX_FreeBuffer(appPriv->handle, j, inBuffer[j*2+1]);
00419     }
00420   }
00421 
00422    for(j=0;j<BUFFER_COUNT_ACTUAL;j++) {
00423      err = OMX_FreeBuffer(appPriv->handle, 4, outBuffer[j]);
00424    }
00425 
00426   /* Wait for commands to complete */
00427   tsem_down(appPriv->eventSem);
00428 
00429   OMX_FreeHandle(appPriv->handle);
00430 
00431   free(appPriv->eventSem);
00432   free(appPriv);
00433 
00434   if (flagOutputReceived) {
00435     if(fclose(outfile) != 0) {
00436       DEBUG(DEB_LEV_ERR,"Error in closing output file\n");
00437       exit(1);
00438     }
00439     free(output_file);
00440   }
00441   for (i = 0; i<index_files; i++) {
00442       close(fd[i]);
00443       free(input_file[i]);
00444   }
00445 
00446   return 0;
00447 }
00448 
00449 /* Callbacks implementation */
00450 OMX_ERRORTYPE audiomixerEventHandler(
00451   OMX_HANDLETYPE hComponent,
00452   OMX_PTR pAppData,
00453   OMX_EVENTTYPE eEvent,
00454   OMX_U32 Data1,
00455   OMX_U32 Data2,
00456   OMX_PTR pEventData) {
00457 
00458   DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
00459   if(eEvent == OMX_EventCmdComplete) {
00460     if (Data1 == OMX_CommandStateSet) {
00461       DEBUG(DEB_LEV_SIMPLE_SEQ, "Volume Component State changed in ");
00462       switch ((int)Data2) {
00463       case OMX_StateInvalid:
00464         DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00465         break;
00466       case OMX_StateLoaded:
00467         DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00468         break;
00469       case OMX_StateIdle:
00470         DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
00471         break;
00472       case OMX_StateExecuting:
00473         DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00474         break;
00475       case OMX_StatePause:
00476         DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00477         break;
00478       case OMX_StateWaitForResources:
00479         DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00480         break;
00481       }
00482       tsem_up(appPriv->eventSem);
00483     } else  if (Data1 == OMX_CommandPortEnable){
00484       tsem_up(appPriv->eventSem);
00485     } else if (Data1 == OMX_CommandPortDisable){
00486       tsem_up(appPriv->eventSem);
00487     }
00488   } else if(eEvent == OMX_EventBufferFlag) {
00489       DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_EventBufferFlag\n");
00490     if((int)Data2 == OMX_BUFFERFLAG_EOS) {
00491       tsem_up(appPriv->eofSem);
00492     }
00493   } else {
00494     DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
00495     DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
00496   }
00497 
00498   return OMX_ErrorNone;
00499 }
00500 
00501 OMX_ERRORTYPE audiomixerEmptyBufferDone(
00502   OMX_HANDLETYPE hComponent,
00503   OMX_PTR pAppData,
00504   OMX_BUFFERHEADERTYPE* pBuffer) {
00505 
00506   int data_read;
00507 
00508 
00509   DEBUG(DEB_LEV_FULL_SEQ, "Hi there, I am in the %s callback from the port %i\n", __func__, (int)pBuffer->nInputPortIndex);
00510 
00511   if(isPortDisabled[pBuffer->nInputPortIndex] == OMX_FALSE) {
00512     data_read = read(fd[pBuffer->nInputPortIndex], pBuffer->pBuffer, FRAME_SIZE);
00513     pBuffer->nFilledLen = data_read;
00514     pBuffer->nOffset = 0;
00515     filesize[pBuffer->nInputPortIndex] -= data_read;
00516     DEBUG(DEB_LEV_SIMPLE_SEQ, "Sending from file %i data read=%d\n", (int)pBuffer->nInputPortIndex, data_read);
00517     if (data_read <= 0) {
00518       DEBUG(DEB_LEV_SIMPLE_SEQ, "In the %s no more input data available\n", __func__);
00519       ++iBufferDropped[pBuffer->nInputPortIndex];
00520       if(iBufferDropped[pBuffer->nInputPortIndex]==2) {
00521         DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Dropping Empty This buffer to Audio Mixer Stream %i\n", __func__, (int)pBuffer->nInputPortIndex);
00522         return OMX_ErrorNone;
00523       } else if(iBufferDropped[pBuffer->nInputPortIndex]>2) {
00524         DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Dropping Empty This buffer to Audio Mixer Stream %i\n", __func__, (int)pBuffer->nInputPortIndex);
00525         return OMX_ErrorNone;
00526       }
00527       pBuffer->nFilledLen=0;
00528       pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
00529       bEOS[pBuffer->nInputPortIndex]=OMX_TRUE;
00530       DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Sending EOS for Stream %i\n", __func__, (int)pBuffer->nInputPortIndex);
00531       OMX_EmptyThisBuffer(hComponent, pBuffer);
00532       return OMX_ErrorNone;
00533     }
00534   } else {
00535     ++iBufferDropped[pBuffer->nInputPortIndex];
00536     return OMX_ErrorNone;
00537   }
00538   if(!bEOS[pBuffer->nInputPortIndex]) {
00539     DEBUG(DEB_LEV_FULL_SEQ, "Empty buffer %p\n", pBuffer);
00540     OMX_EmptyThisBuffer(hComponent, pBuffer);
00541   }else {
00542     DEBUG(DEB_LEV_FULL_SEQ, "In %s Dropping Empty This buffer to Audio Mixer\n", __func__);
00543   }
00544 
00545   return OMX_ErrorNone;
00546 }
00547 
00548 OMX_ERRORTYPE audiomixerFillBufferDone(
00549   OMX_HANDLETYPE hComponent,
00550   OMX_PTR pAppData,
00551   OMX_BUFFERHEADERTYPE* pBuffer) {
00552 
00553   int i;
00554 
00555   DEBUG(DEB_LEV_FULL_SEQ, "Hi there, I am in the %s callback. Got buflen %i for buffer at 0x%p\n",
00556                           __func__, (int)pBuffer->nFilledLen, pBuffer);
00557 
00558   /* Output data to standard output */
00559   if(pBuffer != NULL) {
00560     if (pBuffer->nFilledLen == 0) {
00561       DEBUG(DEB_LEV_ERR, "Ouch! In %s: no data in the output buffer!\n", __func__);
00562       return OMX_ErrorNone;
00563     }
00564     if (flagOutputReceived) {
00565       if(pBuffer->nFilledLen > 0) {
00566         fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, outfile);
00567       }
00568     } else {
00569       for(i=0;i<pBuffer->nFilledLen;i++) {
00570         putchar(*(char*)(pBuffer->pBuffer + i));
00571       }
00572     }
00573     pBuffer->nFilledLen = 0;
00574     /* Reschedule the fill buffer request */
00575     if(!bEOS[0] || !bEOS[1] || !bEOS[2] || !bEOS[3]) {
00576         OMX_FillThisBuffer(hComponent, pBuffer);
00577     } else {
00578         DEBUG(DEB_LEV_FULL_SEQ, "In %s Dropping Fill This buffer to Audio Mixer\n", __func__);
00579     }
00580   } else {
00581     DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
00582   }
00583   return OMX_ErrorNone;
00584 }
00585 
00590 static int getFileSize(int fd) {
00591 
00592   struct stat input_file_stat;
00593   int err;
00594 
00595   /* Obtain input file length */
00596   err = fstat(fd, &input_file_stat);
00597   if(err){
00598     DEBUG(DEB_LEV_ERR, "fstat failed");
00599     exit(-1);
00600   }
00601   return input_file_stat.st_size;
00602 }