30 #define BUFFER_COUNT_ACTUAL 2
31 #define FRAME_SIZE 1152*2*2 // 1152 samples* 2 channels * 2byte/16bits per channel
50 printf(
"Usage: omxaudiomixertest [-o outfile] [-gi gain] -t -r 44100 -n 2 filename0 [filename1 filename2 filename3]\n");
52 printf(
" -o outfile: If this option is specified, the output stream is written to outfile\n");
53 printf(
" otherwise redirected to std output\n");
54 printf(
" -gi : Gain of stream i[0..3] data [0...100]\n");
55 printf(
" -r 44100 : Sample Rate [Default 44100]\n");
56 printf(
" -n 2 : Number of channel [Default 2]\n\n");
57 printf(
" -h : Displays this help\n");
78 static int iBufferDropped[4];
80 int main(
int argc,
char** argv) {
90 int index_files = 0, index_gain = 0;
94 gain[0]=gain[1]=gain[2]=gain[3]=100;
95 fd[0] = fd[1] = fd[2] = fd[3] = 0;
96 bEOS[0] = bEOS[1] = bEOS[2] = bEOS[3] =
OMX_FALSE;
101 flagIsOutputExpected = 0;
102 flagOutputReceived = 0;
103 flagInputReceived = 0;
112 while (argn_dec<argc) {
113 if (*(argv[argn_dec]) ==
'-') {
114 if (flagIsOutputExpected) {
117 switch (*(argv[argn_dec]+1)) {
122 flagIsOutputExpected = 1;
125 index_gain = atoi(argv[argn_dec]+2);
130 flagIsGain[index_gain] = 1;
142 if (flagIsGain[index_gain]) {
143 gain[index_gain] = (int)atoi(argv[argn_dec]);
145 flagIsGain[index_gain] = 0;
146 if(gain[index_gain] > 100) {
148 gain[index_gain] = 100;
151 }
else if (flagIsOutputExpected) {
152 output_file = malloc(strlen(argv[argn_dec]) *
sizeof(
char) + 1);
153 strcpy(output_file,argv[argn_dec]);
154 flagIsOutputExpected = 0;
155 flagOutputReceived = 1;
156 }
else if (flagSampleRate) {
158 }
else if (flagChannel) {
164 input_file[index_files] = malloc(strlen(argv[argn_dec]) *
sizeof(
char) + 1);
165 strcpy(input_file[index_files],argv[argn_dec]);
166 flagInputReceived = 1;
173 if (!flagInputReceived) {
176 DEBUG(
DEFAULT_MESSAGES,
"Input files %s %s %s %s \n", input_file[0], input_file[1], input_file[2], input_file[3]);
178 if (flagOutputReceived) {
185 if(input_file[0]== NULL) {
190 for (i = 0; i<index_files; i++) {
191 fd[i] = open(input_file[i], O_RDONLY);
198 if (flagOutputReceived) {
199 outfile = fopen(output_file,
"wb");
200 if(outfile == NULL) {
207 for (i = 0; i<index_files; i++) {
208 filesize[i] = getFileSize(fd[i]);
213 pthread_cond_init(&appPriv->
condition, NULL);
214 pthread_mutex_init(&appPriv->
mutex, NULL);
219 iBufferDropped[0] = 0;
220 iBufferDropped[1] = 0;
221 iBufferDropped[2] = 0;
222 iBufferDropped[3] = 0;
239 if((gain[j] >= 0) && (gain[j] <100)) {
264 for (j = index_files; j<4; j++) {
270 for (j = 0; j < index_files; j++) {
285 for (j=0; j<8; j++) {
288 outBuffer[0] = outBuffer[1] = NULL;
291 for(j=0; j<index_files; j++) {
294 DEBUG(
DEB_LEV_ERR,
"Error on AllocateBuffer %i %p on port %i\n", j*2, inBuffer[j*2], j);
299 DEBUG(
DEB_LEV_ERR,
"Error on AllocateBuffer %i %p on port %i\n", j*2+1, inBuffer[j*2+1], j);
306 DEBUG(
DEB_LEV_ERR,
"Error on AllocateBuffer 0 %p on port 4\n", outBuffer[0]);
311 DEBUG(
DEB_LEV_ERR,
"Error on AllocateBuffer 1 %p on port 4\n", outBuffer[1]);
322 for (i = 0; i<index_files; i++) {
323 data_read = read(fd[i], inBuffer[i*2]->pBuffer,
FRAME_SIZE);
325 filesize[i] -= data_read;
326 data_read = read(fd[i], inBuffer[i*2+1]->pBuffer,
FRAME_SIZE);
328 filesize[i] -= data_read;
332 for (i = 0; i<index_files; i++) {
344 if(!flagOutputReceived) {
345 DEBUG(
DEFAULT_MESSAGES,
"\nIf you want to disabled port enter port number[0..3]: else Enter 'q' \n\n");
346 while(!bEOS[0] || !bEOS[1] || !bEOS[2] || !bEOS[3]) {
347 DEBUG(
DEFAULT_MESSAGES,
"Port status 0=%i, 1=%i, 2=%i, 3=%i\n",isPortDisabled[0], isPortDisabled[1], isPortDisabled[2], isPortDisabled[3]);
353 }
else if(c ==
'q') {
360 if (isPortDisabled[i] ==
OMX_TRUE) {
366 data_read = read(fd[i], inBuffer[i*2]->pBuffer,
FRAME_SIZE);
368 data_read = read(fd[i], inBuffer[i*2+1]->pBuffer,
FRAME_SIZE);
376 while(iBufferDropped[i]!=2) {
383 iBufferDropped[i] = 0;
415 for(j=0; j<index_files; j++) {
434 if (flagOutputReceived) {
435 if(fclose(outfile) != 0) {
441 for (i = 0; i<index_files; i++) {
462 switch ((
int)Data2) {
517 if (data_read <= 0) {
559 if(pBuffer != NULL) {
561 DEBUG(
DEB_LEV_ERR,
"Ouch! In %s: no data in the output buffer!\n", __func__);
564 if (flagOutputReceived) {
570 putchar(*(
char*)(pBuffer->
pBuffer + i));
575 if(!bEOS[0] || !bEOS[1] || !bEOS[2] || !bEOS[3]) {
581 DEBUG(
DEB_LEV_ERR,
"Ouch! In %s: had NULL buffer to output...\n", __func__);
590 static int getFileSize(
int fd) {
592 struct stat input_file_stat;
596 err = fstat(fd, &input_file_stat);
601 return input_file_stat.st_size;
#define OMX_EmptyThisBuffer(hComponent,pBuffer)
#define OMX_GetConfig(hComponent,nConfigIndex,pComponentConfigStructure)
#define DEB_LEV_SIMPLE_SEQ
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Init(void)
The OMX_Init standard function.
#define DEBUG(n, fmt, args...)
struct OMX_VERSIONTYPE::@1 s
OMX_BUFFERHEADERTYPE * inBufferSink[2]
void tsem_up(tsem_t *tsem)
void setHeader(OMX_PTR header, OMX_U32 size)
Simply fills the first two fields in any OMX structure with the size and the version.
OMX_BUFFERHEADERTYPE * inBuffer[8]
void tsem_down(tsem_t *tsem)
#define OMX_GetParameter(hComponent,nParamIndex,pComponentParameterStructure)
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_GetHandle(OMX_OUT OMX_HANDLETYPE *pHandle, OMX_IN OMX_STRING cComponentName, OMX_IN OMX_PTR pAppData, OMX_IN OMX_CALLBACKTYPE *pCallBacks)
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_FreeHandle(OMX_IN OMX_HANDLETYPE hComponent)
#define OMX_BUFFERFLAG_EOS
#define OMX_SetParameter(hComponent,nParamIndex,pComponentParameterStructure)
#define OMX_SendCommand(hComponent,Cmd,nParam,pCmdData)
#define OMX_AllocateBuffer(hComponent,ppBuffer,nPortIndex,pAppPrivate,nSizeBytes)
#define OMX_FreeBuffer(hComponent,nPortIndex,pBuffer)
OMX_ERRORTYPE audiomixerFillBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
OMX_ERRORTYPE audiomixerEmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
OMX_U32 nBufferCountActual
int tsem_init(tsem_t *tsem, unsigned int val)
#define OMX_SetConfig(hComponent,nConfigIndex,pComponentConfigStructure)
OMX_ERRORTYPE audiomixerEventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 Data1, OMX_U32 Data2, OMX_PTR pEventData)
#define OMX_FillThisBuffer(hComponent,pBuffer)
int main(int argc, char **argv)
OMX_BUFFERHEADERTYPE * outBuffer[2]
#define BUFFER_COUNT_ACTUAL
OMX_CALLBACKTYPE callbacks
OMX_ERRORTYPE(* EventHandler)(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_PTR pAppData, OMX_IN OMX_EVENTTYPE eEvent, OMX_IN OMX_U32 nData1, OMX_IN OMX_U32 nData2, OMX_IN OMX_PTR pEventData)