OpenMAX Bellagio 0.9.3
omxvolcontroltest.c
Go to the documentation of this file.
1
27#include "omxvolcontroltest.h"
28#include <bellagio/extension_struct.h>
29
30/* Application private date: should go in the component field (segs...) */
32int fd = 0;
33unsigned int filesize;
36
38 .EmptyBufferDone = volcEmptyBufferDone,
39 .FillBufferDone = volcFillBufferDone,
40};
41
42static void setHeader(OMX_PTR header, OMX_U32 size) {
43 OMX_VERSIONTYPE* ver = (OMX_VERSIONTYPE*)(header + sizeof(OMX_U32));
44 *((OMX_U32*)header) = size;
45
49 ver->s.nStep = VERSIONSTEP;
50}
51
53 printf("\n");
54 printf("Usage: omxvolcontroltest [-o outfile] [-g gain] filename\n");
55 printf("\n");
56 printf(" -o outfile: If this option is specified, the output stream is written to outfile\n");
57 printf(" otherwise redirected to std output\n");
58 printf(" -g: Gain of PCM data [0...100]\n");
59 printf(" -h: Displays this help\n");
60 printf("\n");
61 exit(1);
62}
63
70FILE *outfile;
71
72int main(int argc, char** argv) {
73
75 OMX_BUFFERHEADERTYPE *inBuffer1, *inBuffer2, *outBuffer1, *outBuffer2;
76 int data_read1;
77 int data_read2;
80 int gain=100;
81 int argn_dec;
83 OMX_INDEXTYPE custom_index;
84
85 /* Obtain file descriptor */
86 if(argc < 2){
88 } else {
92 flagIsGain = 0;
93
94 argn_dec = 1;
95 while (argn_dec<argc) {
96 if (*(argv[argn_dec]) =='-') {
99 }
100 switch (*(argv[argn_dec]+1)) {
101 case 'h':
102 display_help();
103 break;
104 case 'o':
106 break;
107 case 'g':
108 flagIsGain = 1;
109 break;
110 default:
111 display_help();
112 }
113 } else {
114 if (flagIsGain) {
115 gain = (int)atoi(argv[argn_dec]);
116 flagIsGain = 0;
117 if(gain > 100) {
118 DEBUG(DEFAULT_MESSAGES, "Gain should be between [0..100]\n");
119 gain = 100;
120 }
121 } else if (flagIsOutputExpected) {
122 output_file = malloc(strlen(argv[argn_dec]) + 1);
123 strcpy(output_file,argv[argn_dec]);
126 } else {
127 input_file = malloc(strlen(argv[argn_dec]) + 1);
128 strcpy(input_file,argv[argn_dec]);
130 }
131 }
132 argn_dec++;
133 }
134 if (!flagInputReceived) {
135 display_help();
136 }
137 DEBUG(DEFAULT_MESSAGES, "Input file %s", input_file);
138 DEBUG(DEFAULT_MESSAGES, " to ");
139 if (flagOutputReceived) {
141 }
142 }
143
144
145 fd = open(input_file, O_RDONLY);
146 if(fd < 0){
147 perror("Error opening input file\n");
148 exit(1);
149 }
150
151 if (flagOutputReceived) {
152 outfile = fopen(output_file,"wb");
153 if(outfile == NULL) {
154 DEBUG(DEB_LEV_ERR, "Error at opening the output file");
155 exit(1);
156 }
157 }
158
159 filesize = getFileSize(fd);
160 /* Initialize application private data */
161 appPriv = malloc(sizeof(appPrivateType));
162 pthread_cond_init(&appPriv->condition, NULL);
163 pthread_mutex_init(&appPriv->mutex, NULL);
164 appPriv->eventSem = malloc(sizeof(tsem_t));
166 appPriv->eofSem = malloc(sizeof(tsem_t));
168
169 err = OMX_Init();
170 if(err != OMX_ErrorNone) {
171 DEBUG(DEB_LEV_ERR, "OMX_Init() failed\n");
172 exit(1);
173 }
176 err = OMX_GetHandle(&handle, "OMX.st.volume.component", NULL /*appPriv */, &callbacks);
177 if(err != OMX_ErrorNone) {
178 DEBUG(DEB_LEV_ERR, "OMX_GetHandle failed\n");
179 exit(1);
180 }
181
182 /* test the new feature of thread ID detection
183 */
184 err = OMX_GetExtensionIndex(handle, "OMX.st.index.param.BellagioThreadsID", &custom_index);
185 if(err != OMX_ErrorNone) {
186 DEBUG(DEB_LEV_ERR, "OMX_GetExtensionIndex failed\n");
187 exit(1);
188 }
189
190 setHeader(&threadsID, sizeof(OMX_PARAM_BELLAGIOTHREADS_ID));
191 err = OMX_GetParameter(handle, custom_index, &threadsID);
192 if(err != OMX_ErrorNone) {
193 DEBUG(DEB_LEV_ERR, "OMX_GetParameter of extended index failed\n");
194 } else {
195 DEBUG(DEFAULT_MESSAGES, "threadsID messages %i buffers %i\n", (int)threadsID.nThreadMessageID, (int)threadsID.nThreadBufferMngtID);
196 }
197
198 if((gain >= 0) && (gain <100)) {
200 if(err!=OMX_ErrorNone) {
201 DEBUG(DEB_LEV_ERR,"Error %08x In OMX_GetConfig 0 \n",err);
202 }
203 sVolume.sVolume.nValue = gain;
204 DEBUG(DEFAULT_MESSAGES, "Setting Gain %d \n", gain);
206 if(err!=OMX_ErrorNone) {
207 DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetConfig 0 \n",err);
208 }
209 }
210
212 param.nPorts = 2;
213 setHeader(&param, sizeof(OMX_PORT_PARAM_TYPE));
215 if(err != OMX_ErrorNone){
216 DEBUG(DEB_LEV_ERR, "Error in getting OMX_PORT_PARAM_TYPE parameter\n");
217 exit(1);
218 }
219
220 setHeader(&sPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
221 sPortDef.nPortIndex = 0;
223
224 sPortDef.nBufferCountActual = 2;
226 if(err != OMX_ErrorNone){
227 DEBUG(DEB_LEV_ERR, "Error in getting OMX_PORT_PARAM_TYPE parameter\n");
228 exit(1);
229 }
230 sPortDef.nPortIndex = 1;
232
233 sPortDef.nBufferCountActual = 2;
235 if(err != OMX_ErrorNone){
236 DEBUG(DEB_LEV_ERR, "Error in getting OMX_PORT_PARAM_TYPE parameter\n");
237 exit(1);
238 }
239
241
242 inBuffer1 = inBuffer2 = outBuffer1 = outBuffer2 = NULL;
243 err = OMX_AllocateBuffer(handle, &inBuffer1, 0, NULL, BUFFER_IN_SIZE);
244 if (err != OMX_ErrorNone) {
245 DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer in 1%i\n", err);
246 exit(1);
247 }
248 err = OMX_AllocateBuffer(handle, &inBuffer2, 0, NULL, BUFFER_IN_SIZE);
249 if (err != OMX_ErrorNone) {
250 DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer in 2 %i\n", err);
251 exit(1);
252 }
253 err = OMX_AllocateBuffer(handle, &outBuffer1, 1, NULL, BUFFER_IN_SIZE);
254 if (err != OMX_ErrorNone) {
255 DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer out 1 %i\n", err);
256 exit(1);
257 }
258 err = OMX_AllocateBuffer(handle, &outBuffer2, 1, NULL, BUFFER_IN_SIZE);
259 if (err != OMX_ErrorNone) {
260 DEBUG(DEB_LEV_ERR, "Error on AllocateBuffer out 2 %i\n", err);
261 exit(1);
262 }
263
265 /* in Idle the second thread has bee created, and the second thread ID
266 * should be available
267 */
268 err = OMX_GetParameter(handle, custom_index, &threadsID);
269 if(err != OMX_ErrorNone) {
270 DEBUG(DEB_LEV_ERR, "OMX_GetParameter of extended index failed\n");
271 } else {
272 DEBUG(DEFAULT_MESSAGES, "threadsID messages %i buffers %i\n", (int)threadsID.nThreadMessageID, (int)threadsID.nThreadBufferMngtID);
273 }
274
276
277 /* Wait for commands to complete */
279
280 DEBUG(DEB_LEV_PARAMS, "Had buffers at:\n0x%p\n0x%p\n0x%p\n0x%p\n",
281 inBuffer1->pBuffer, inBuffer2->pBuffer, outBuffer1->pBuffer, outBuffer2->pBuffer);
282 DEBUG(DEB_LEV_PARAMS, "After switch to executing\n");
283
284 data_read1 = read(fd, inBuffer1->pBuffer, BUFFER_IN_SIZE);
285 inBuffer1->nFilledLen = data_read1;
286 filesize -= data_read1;
287
288 data_read2 = read(fd, inBuffer2->pBuffer, BUFFER_IN_SIZE);
289 inBuffer2->nFilledLen = data_read2;
290 filesize -= data_read2;
291
292 DEBUG(DEB_LEV_PARAMS, "Empty first buffer %p\n", inBuffer1);
293 err = OMX_EmptyThisBuffer(handle, inBuffer1);
294 DEBUG(DEB_LEV_PARAMS, "Empty second buffer %p\n", inBuffer2);
295 err = OMX_EmptyThisBuffer(handle, inBuffer2);
296
300 err = OMX_FillThisBuffer(handle, outBuffer1);
301 err = OMX_FillThisBuffer(handle, outBuffer2);
302
304
306 /* Wait for commands to complete */
308
310 err = OMX_FreeBuffer(handle, 0, inBuffer1);
311 err = OMX_FreeBuffer(handle, 0, inBuffer2);
312 err = OMX_FreeBuffer(handle, 1, outBuffer1);
313 err = OMX_FreeBuffer(handle, 1, outBuffer2);
314
315 /* Wait for commands to complete */
317
319
320 free(appPriv->eventSem);
321 free(appPriv);
322
323 if (flagOutputReceived) {
324 if(fclose(outfile) != 0) {
325 DEBUG(DEB_LEV_ERR,"Error in closing output file\n");
326 exit(1);
327 }
328 free(output_file);
329 }
330
331 close(fd);
332 free(input_file);
333
334 return 0;
335}
336
337/* Callbacks implementation */
339 OMX_HANDLETYPE hComponent,
340 OMX_PTR pAppData,
341 OMX_EVENTTYPE eEvent,
342 OMX_U32 Data1,
343 OMX_U32 Data2,
344 OMX_PTR pEventData) {
345
346 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
347 if(eEvent == OMX_EventCmdComplete) {
348 if (Data1 == OMX_CommandStateSet) {
349 DEBUG(DEB_LEV_SIMPLE_SEQ, "Volume Component State changed in ");
350 switch ((int)Data2) {
351 case OMX_StateInvalid:
352 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
353 break;
354 case OMX_StateLoaded:
355 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
356 break;
357 case OMX_StateIdle:
358 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
359 break;
361 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
362 break;
363 case OMX_StatePause:
364 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
365 break;
367 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
368 break;
369 }
371 } else if (Data1 == OMX_CommandPortEnable){
373 } else if (Data1 == OMX_CommandPortDisable){
375 }
376 } else if(eEvent == OMX_EventBufferFlag) {
377 if((int)Data2 == OMX_BUFFERFLAG_EOS) {
379 }
380 } else {
381 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
382 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
383 }
384
385 return OMX_ErrorNone;
386}
387
389 OMX_HANDLETYPE hComponent,
390 OMX_PTR pAppData,
391 OMX_BUFFERHEADERTYPE* pBuffer) {
392
393 int data_read;
394 static int iBufferDropped=0;
395
396 DEBUG(DEB_LEV_FULL_SEQ, "Hi there, I am in the %s callback.\n", __func__);
397 data_read = read(fd, pBuffer->pBuffer, BUFFER_IN_SIZE);
398 pBuffer->nFilledLen = data_read;
399 pBuffer->nOffset = 0;
400 filesize -= data_read;
401 if (data_read <= 0) {
402 DEBUG(DEB_LEV_SIMPLE_SEQ, "In the %s no more input data available\n", __func__);
403 iBufferDropped++;
404 if(iBufferDropped>=2) {
406 return OMX_ErrorNone;
407 }
408 pBuffer->nFilledLen=0;
409 pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
411 err = OMX_EmptyThisBuffer(hComponent, pBuffer);
412 return OMX_ErrorNone;
413 }
414 if(!bEOS) {
415 DEBUG(DEB_LEV_FULL_SEQ, "Empty buffer %p\n", pBuffer);
416 err = OMX_EmptyThisBuffer(hComponent, pBuffer);
417 }else {
418 DEBUG(DEB_LEV_FULL_SEQ, "In %s Dropping Empty This buffer to Audio Dec\n", __func__);
419 }
420
421 return OMX_ErrorNone;
422}
423
425 OMX_HANDLETYPE hComponent,
426 OMX_PTR pAppData,
427 OMX_BUFFERHEADERTYPE* pBuffer) {
428
430 int i;
431
432 DEBUG(DEB_LEV_FULL_SEQ, "Hi there, I am in the %s callback. Got buflen %i for buffer at 0x%p\n",
433 __func__, (int)pBuffer->nFilledLen, pBuffer);
434
435 /* Output data to standard output */
436 if(pBuffer != NULL) {
437 if (pBuffer->nFilledLen == 0) {
438 DEBUG(DEB_LEV_ERR, "Ouch! In %s: no data in the output buffer!\n", __func__);
439 return OMX_ErrorNone;
440 }
441 if (flagOutputReceived) {
442 if(pBuffer->nFilledLen > 0) {
443 fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, outfile);
444 }
445 } else {
446 for(i=0;i<pBuffer->nFilledLen;i++) {
447 putchar(*(char*)(pBuffer->pBuffer + i));
448 }
449 }
450 pBuffer->nFilledLen = 0;
451 } else {
452 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
453 }
454 /* Reschedule the fill buffer request */
455 if(!bEOS) {
456 err = OMX_FillThisBuffer(hComponent, pBuffer);
457 }
458 return OMX_ErrorNone;
459}
460
465static int getFileSize(int fd) {
466
467 struct stat input_file_stat;
468 int err;
469
470 /* Obtain input file length */
471 err = fstat(fd, &input_file_stat);
472 if(err){
473 DEBUG(DEB_LEV_ERR, "fstat failed");
474 exit(-1);
475 }
476 return input_file_stat.st_size;
477}
OMX_ERRORTYPE
Definition: OMX_Core.h:127
@ OMX_ErrorNone
Definition: OMX_Core.h:128
OMX_INDEXTYPE
Definition: OMX_Index.h:60
@ OMX_IndexParamAudioInit
Definition: OMX_Index.h:64
@ OMX_IndexParamPortDefinition
Definition: OMX_Index.h:88
@ OMX_IndexConfigAudioVolume
Definition: OMX_Index.h:128
unsigned long OMX_U32
Definition: OMX_Types.h:145
OMX_BOOL
Definition: OMX_Types.h:189
@ OMX_TRUE
Definition: OMX_Types.h:191
@ OMX_FALSE
Definition: OMX_Types.h:190
void * OMX_PTR
Definition: OMX_Types.h:199
void * OMX_HANDLETYPE
Definition: OMX_Types.h:295
#define OMX_BUFFERFLAG_EOS
Definition: OMX_Core.h:299
#define OMX_FillThisBuffer( hComponent, pBuffer)
Definition: OMX_Core.h:1126
#define OMX_FreeBuffer( hComponent, nPortIndex, pBuffer)
Definition: OMX_Core.h:1064
#define OMX_AllocateBuffer( hComponent, ppBuffer, nPortIndex, pAppPrivate, nSizeBytes)
Definition: OMX_Core.h:1028
#define OMX_EmptyThisBuffer( hComponent, pBuffer)
Definition: OMX_Core.h:1096
#define OMX_SetConfig( hComponent, nConfigIndex, pComponentConfigStructure)
Definition: OMX_Core.h:897
#define OMX_GetConfig( hComponent, nConfigIndex, pComponentConfigStructure)
Definition: OMX_Core.h:861
#define OMX_GetExtensionIndex( hComponent, cParameterName, pIndexType)
Definition: OMX_Core.h:931
#define OMX_GetParameter( hComponent, nParamIndex, pComponentParameterStructure)
Definition: OMX_Core.h:786
#define OMX_SendCommand( hComponent, Cmd, nParam, pCmdData)
Definition: OMX_Core.h:745
#define OMX_SetParameter( hComponent, nParamIndex, pComponentParameterStructure)
Definition: OMX_Core.h:825
OMX_EVENTTYPE
Definition: OMX_Core.h:480
@ OMX_StateExecuting
Definition: OMX_Core.h:105
@ OMX_StateWaitForResources
Definition: OMX_Core.h:108
@ OMX_StateLoaded
Definition: OMX_Core.h:97
@ OMX_StateInvalid
Definition: OMX_Core.h:94
@ OMX_StateIdle
Definition: OMX_Core.h:102
@ OMX_StatePause
Definition: OMX_Core.h:107
@ OMX_EventBufferFlag
Definition: OMX_Core.h:485
@ OMX_EventCmdComplete
Definition: OMX_Core.h:481
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)
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Init(void)
The OMX_Init standard function.
Definition: omxcore.c:94
@ OMX_CommandPortDisable
Definition: OMX_Core.h:53
@ OMX_CommandPortEnable
Definition: OMX_Core.h:54
@ OMX_CommandStateSet
Definition: OMX_Core.h:51
void setHeader(OMX_PTR header, OMX_U32 size)
Simply fills the first two fields in any OMX structure with the size and the version.
#define DEB_LEV_PARAMS
#define DEFAULT_MESSAGES
#define DEB_LEV_ERR
#define DEB_LEV_SIMPLE_SEQ
#define DEB_LEV_FULL_SEQ
#define DEBUG(n, fmt, args...)
OMX_BOOL bEOS[4]
#define VERSIONREVISION
#define BUFFER_IN_SIZE
#define VERSIONMINOR
#define VERSIONMAJOR
#define VERSIONSTEP
int flagInputReceived
OMX_HANDLETYPE handle
OMX_CALLBACKTYPE callbacks
int main(int argc, char **argv)
int flagOutputReceived
OMX_ERRORTYPE volcEmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
int flagIsOutputExpected
unsigned int filesize
int flagIsGain
int fd
OMX_ERRORTYPE err
OMX_ERRORTYPE volcFillBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
OMX_ERRORTYPE volcEventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 Data1, OMX_U32 Data2, OMX_PTR pEventData)
void display_help()
char * output_file
char * input_file
FILE * outfile
appPrivateType * appPriv
OMX_S32 nValue
Definition: OMX_Types.h:263
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)
Definition: OMX_Core.h:530
pthread_mutex_t mutex
pthread_cond_t condition
void tsem_up(tsem_t *tsem)
Definition: tsemaphore.c:110
int tsem_init(tsem_t *tsem, unsigned int val)
Definition: tsemaphore.c:39
void tsem_down(tsem_t *tsem)
Definition: tsemaphore.c:97
OMX_U8 nVersionMajor
Definition: OMX_Types.h:344
struct OMX_VERSIONTYPE::@1 s
OMX_U8 nVersionMinor
Definition: OMX_Types.h:345
OMX_U8 nRevision
Definition: OMX_Types.h:346

Generated for OpenMAX Bellagio rel. 0.9.3 by  doxygen 1.5.1
SourceForge.net Logo