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