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;
95 gain[0]=gain[1]=gain[2]=gain[3]=100;
96 fd[0] = fd[1] = fd[2] = fd[3] = 0;
97 bEOS[0] = bEOS[1] = bEOS[2] = bEOS[3] =
OMX_FALSE;
102 flagIsOutputExpected = 0;
103 flagOutputReceived = 0;
104 flagInputReceived = 0;
113 while (argn_dec<argc) {
114 if (*(argv[argn_dec]) ==
'-') {
115 if (flagIsOutputExpected) {
118 switch (*(argv[argn_dec]+1)) {
123 flagIsOutputExpected = 1;
126 index_gain = atoi(argv[argn_dec]+2);
131 flagIsGain[index_gain] = 1;
143 if (flagIsGain[index_gain]) {
144 gain[index_gain] = (int)atoi(argv[argn_dec]);
146 flagIsGain[index_gain] = 0;
147 if(gain[index_gain] > 100) {
149 gain[index_gain] = 100;
152 }
else if (flagIsOutputExpected) {
153 output_file = malloc(strlen(argv[argn_dec]) *
sizeof(
char) + 1);
154 strcpy(output_file,argv[argn_dec]);
155 flagIsOutputExpected = 0;
156 flagOutputReceived = 1;
157 }
else if (flagSampleRate) {
158 srate = (int)atoi(argv[argn_dec]);
160 }
else if (flagChannel) {
161 nchannel = (int)atoi(argv[argn_dec]);
167 input_file[index_files] = malloc(strlen(argv[argn_dec]) *
sizeof(
char) + 1);
168 strcpy(input_file[index_files],argv[argn_dec]);
169 flagInputReceived = 1;
176 if (!flagInputReceived) {
179 DEBUG(
DEFAULT_MESSAGES,
"Input files %s %s %s %s \n", input_file[0], input_file[1], input_file[2], input_file[3]);
181 if (flagOutputReceived) {
188 if(input_file[0]== NULL) {
193 for (i = 0; i<index_files; i++) {
194 fd[i] = open(input_file[i], O_RDONLY);
201 if (flagOutputReceived) {
202 outfile = fopen(output_file,
"wb");
203 if(outfile == NULL) {
210 for (i = 0; i<index_files; i++) {
211 filesize[i] = getFileSize(fd[i]);
216 pthread_cond_init(&appPriv->
condition, NULL);
217 pthread_mutex_init(&appPriv->
mutex, NULL);
222 iBufferDropped[0] = 0;
223 iBufferDropped[1] = 0;
224 iBufferDropped[2] = 0;
225 iBufferDropped[3] = 0;
242 if((gain[j] >= 0) && (gain[j] <100)) {
267 for (j = index_files; j<4; j++) {
273 for (j = 0; j < index_files; j++) {
288 for (j=0; j<8; j++) {
291 outBuffer[0] = outBuffer[1] = NULL;
294 for(j=0; j<index_files; j++) {
297 DEBUG(
DEB_LEV_ERR,
"Error on AllocateBuffer %i %p on port %i\n", j*2, inBuffer[j*2], j);
302 DEBUG(
DEB_LEV_ERR,
"Error on AllocateBuffer %i %p on port %i\n", j*2+1, inBuffer[j*2+1], j);
309 DEBUG(
DEB_LEV_ERR,
"Error on AllocateBuffer 0 %p on port 4\n", outBuffer[0]);
314 DEBUG(
DEB_LEV_ERR,
"Error on AllocateBuffer 1 %p on port 4\n", outBuffer[1]);
325 for (i = 0; i<index_files; i++) {
326 data_read = read(fd[i], inBuffer[i*2]->pBuffer,
FRAME_SIZE);
328 filesize[i] -= data_read;
329 data_read = read(fd[i], inBuffer[i*2+1]->pBuffer,
FRAME_SIZE);
331 filesize[i] -= data_read;
335 for (i = 0; i<index_files; i++) {
347 if(!flagOutputReceived) {
348 DEBUG(
DEFAULT_MESSAGES,
"\nIf you want to disabled port enter port number[0..3]: else Enter 'q' \n\n");
349 while(!bEOS[0] || !bEOS[1] || !bEOS[2] || !bEOS[3]) {
350 DEBUG(
DEFAULT_MESSAGES,
"Port status 0=%i, 1=%i, 2=%i, 3=%i\n",isPortDisabled[0], isPortDisabled[1], isPortDisabled[2], isPortDisabled[3]);
356 }
else if(c ==
'q') {
363 if (isPortDisabled[i] ==
OMX_TRUE) {
369 data_read = read(fd[i], inBuffer[i*2]->pBuffer,
FRAME_SIZE);
371 data_read = read(fd[i], inBuffer[i*2+1]->pBuffer,
FRAME_SIZE);
379 while(iBufferDropped[i]!=2) {
386 iBufferDropped[i] = 0;
418 for(j=0; j<index_files; j++) {
437 if (flagOutputReceived) {
438 if(fclose(outfile) != 0) {
444 for (i = 0; i<index_files; i++) {
465 switch ((
int)Data2) {
521 if (data_read <= 0) {
564 if(pBuffer != NULL) {
566 DEBUG(
DEB_LEV_ERR,
"Ouch! In %s: no data in the output buffer!\n", __func__);
569 if (flagOutputReceived) {
575 putchar(*(
char*)(pBuffer->
pBuffer + i));
580 if(!bEOS[0] || !bEOS[1] || !bEOS[2] || !bEOS[3]) {
586 DEBUG(
DEB_LEV_ERR,
"Ouch! In %s: had NULL buffer to output...\n", __func__);
595 static int getFileSize(
int fd) {
597 struct stat input_file_stat;
601 err = fstat(fd, &input_file_stat);
606 return input_file_stat.st_size;