OpenMAX Bellagio 0.9.3
omxrmtest.c
Go to the documentation of this file.
1
26
27#include "omxrmtest.h"
28#include <string.h>
29#include <bellagio/extension_struct.h>
30
31#define MAX_COMPONENTS 5
32#define TIMEOUT 500
33/* Application private date: should go in the component field (segs...) */
34
35
37
39 .EmptyBufferDone = rmEmptyBufferDone,
40 .FillBufferDone = rmFillBufferDone,
41};
42
43static void setHeader(OMX_PTR header, OMX_U32 size) {
44 OMX_VERSIONTYPE* ver = (OMX_VERSIONTYPE*)(header + sizeof(OMX_U32));
45 *((OMX_U32*)header) = size;
46
50 ver->s.nStep = VERSIONSTEP;
51}
52
53int convertStr2Int(char* str) {
54 int val = 0;
55 int len = strlen(str);
56 int i = 0;
57 while(i < len) {
58 if ((*(str+i)<'0') || (*(str+i)>'9')) {
59 return 0;
60 }
61 val = (val*10) + ((*(str+i))-'0');
62 i++;
63 }
64 return val;
65}
66
68 printf("\n");
69 printf("Usage: omxrmtest OMX_name [-i max_comp]\n");
70 printf("\n");
71 exit(1);
72}
73
75int main(int argc, char** argv) {
76 int getMaxValue = 0;
77 int flagInputReceived = 0;
78 int argn_dec = 1;
79 int i, j;
80 int num_of_components;
81 OMX_STATETYPE state;
82 char* componentName;
83 int global_err = 0;
86 int indexaudiostart = -1;
87 int audioports = 0;
88 int indexvideostart = -1;
89 int videoports = 0;
90 int indeximagestart = -1;
91 int imageports = 0;
92 int indexotherstart = -1;
93 int otherports = 0;
94
95 max_value = 0;
96 if(argc < 2){
98 } else {
99 while (argn_dec < argc) {
100 if (*(argv[argn_dec]) == '-') {
101 switch (*(argv[argn_dec] + 1)) {
102 case 'h':
103 display_help();
104 break;
105 case 'i':
106 getMaxValue = 1;
107 break;
108 default:
109 display_help();
110 }
111 } else {
112 if (getMaxValue) {
113 max_value = convertStr2Int(argv[argn_dec]);
114 if (max_value == 0) {
115 display_help();
116 }
117 } else {
118 componentName = malloc(strlen(argv[argn_dec]) * sizeof(char) + 1);
119 strcpy(componentName, argv[argn_dec]);
121 }
122 }
123 argn_dec++;
124 }
125 }
126 if (!flagInputReceived) {
127 display_help();
128 }
129 if (max_value == 0) {
131 }
132 handle = malloc(sizeof(OMX_HANDLETYPE*) * max_value);
133 /* Obtain file descriptor */
134 eventSem = malloc(sizeof(tsem_t));
137 err = OMX_Init();
138 if(err != OMX_ErrorNone) {
139 DEBUG(DEB_LEV_ERR, "OMX_Init() failed\n");
140 exit(1);
141 }
142 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_Init()\n");
143
144 for (i = 0; i<max_value; i++) {
145 err = OMX_GetHandle(&handle[i], componentName, NULL, &callbacks);
146 if(err != OMX_ErrorNone) {
147 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
148 DEBUG(DEFAULT_MESSAGES, "The OLD STYLE resource manager on %s\n", componentName);
149 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
150 exit(1);
151 }
152 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_GetHandle() %i\n", i);
153 }
154 setHeader(&sParam, sizeof(OMX_PORT_PARAM_TYPE));
156 if (sParam.nPorts > 0) {
157 indexaudiostart = sParam.nStartPortNumber;
158 audioports = sParam.nPorts;
159 }
161 if (sParam.nPorts > 0) {
162 indexvideostart = sParam.nStartPortNumber;
163 videoports = sParam.nPorts;
164 }
166 if (sParam.nPorts > 0) {
167 indeximagestart = sParam.nStartPortNumber;
168 imageports = sParam.nPorts;
169 }
171 if (sParam.nPorts > 0) {
172 indexotherstart = sParam.nStartPortNumber;
173 otherports = sParam.nPorts;
174 }
175
176 for (i = 0; i<max_value; i++) {
177 // todo this test is valid only for 2 ports components, not like mixer, sinks, sources
178 if (indexaudiostart >= 0) {
179 for (j = 0; j< audioports; j++) {
180 err = OMX_SendCommand(handle[i], OMX_CommandPortDisable, j + indexaudiostart, 0);
181 }
182 }
183 if (indexvideostart >= 0) {
184 for (j = 0; j< videoports; j++) {
185 err = OMX_SendCommand(handle[i], OMX_CommandPortDisable, j + indexvideostart, 0);
186 }
187 }
188 if (indeximagestart >= 0) {
189 for (j = 0; j< imageports; j++) {
190 err = OMX_SendCommand(handle[i], OMX_CommandPortDisable, j + indeximagestart, 0);
191 }
192 }
193 if (indexotherstart >= 0) {
194 for (j = 0; j< otherports; j++) {
195 err = OMX_SendCommand(handle[i], OMX_CommandPortDisable, j + indexotherstart, 0);
196 }
197 }
199 if(err != OMX_ErrorNone) {
200 DEBUG(DEB_LEV_ERR, "The component %s can't go to Idle\n", componentName);
201 break;
202 }
203 global_err = tsem_timed_down(eventSem, TIMEOUT);
204 if (global_err != 0) {
205 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
206 DEBUG(DEFAULT_MESSAGES, "The resource manager does not handle component %s\n", componentName);
207 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
208 break;
209 } else {
210 DEBUG(DEB_LEV_SIMPLE_SEQ, "The component %i is set to Idle\n", i);
211
213 DEBUG(DEB_LEV_SIMPLE_SEQ, "The resources are exhausted\n");
214 DEBUG(DEB_LEV_SIMPLE_SEQ, "Send component %i to WaitForResources\n", i);
217 DEBUG(DEB_LEV_SIMPLE_SEQ, "Send component %i to Loaded\n", i-1);
220 DEBUG(DEB_LEV_SIMPLE_SEQ, "Wait for component %i to go to Idle\n", i);
222 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
223 DEBUG(DEFAULT_MESSAGES, "The resource manager has operated on %s\n", componentName);
224 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
225 break;
226 }
227 }
228 }
229 num_of_components = i;
230
231 DEBUG(DEB_LEV_SIMPLE_SEQ, "Dispose the system\n");
232 for (i = 0; i<num_of_components; i++) {
233 err = OMX_GetState(handle[i], &state);
234 if (state == OMX_StateIdle) {
237 DEBUG(DEB_LEV_SIMPLE_SEQ, "Component %i sent to Loaded\n", i);
238 } else if (state == OMX_StateLoaded) {
239 DEBUG(DEB_LEV_SIMPLE_SEQ, "Component %i already loaded\n", i);
240 } else {
241 DEBUG(DEB_LEV_SIMPLE_SEQ, "Component %i in the wrong state!\n", i);
242 }
243 }
244 DEBUG(DEB_LEV_SIMPLE_SEQ, "All %i to loaded\n", num_of_components);
245
246 for (i = 0; i<max_value; i++) {
248 if(err != OMX_ErrorNone) {
249 DEBUG(DEB_LEV_ERR, "OMX_FreeHandle [%i] failed\n", i);
250 exit(1);
251 }
252 }
253
254 err = OMX_Deinit();
255 if(err != OMX_ErrorNone) {
256 DEBUG(DEB_LEV_ERR, "OMX_Deinit() failed\n");
257 exit(1);
258 }
259 free(eventSem);
260 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_Deinit()\n");
261 return 0;
262}
263
264/* Callbacks implementation */
266 OMX_HANDLETYPE hComponent,
267 OMX_PTR pAppData,
268 OMX_EVENTTYPE eEvent,
269 OMX_U32 Data1,
270 OMX_U32 Data2,
271 OMX_PTR pEventData) {
272
273 if(eEvent == OMX_EventCmdComplete) {
274 if (Data1 == OMX_CommandStateSet) {
275 DEBUG(DEB_LEV_SIMPLE_SEQ, "Volume Component %p State changed in ", hComponent);
276 switch ((int)Data2) {
277 case OMX_StateInvalid:
278 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
279 break;
280 case OMX_StateLoaded:
281 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
282 break;
283 case OMX_StateIdle:
284 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
285 break;
287 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
288 break;
289 case OMX_StatePause:
290 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
291 break;
293 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
294 break;
295 }
297 } else if (Data1 == OMX_CommandPortDisable) {
298 DEBUG(DEB_LEV_SIMPLE_SEQ, "Disabled port %i\n", (int)Data2);
299 }
300 } else if (eEvent == OMX_EventError) {
301 if (Data1 == OMX_ErrorInsufficientResources) {
302 DEBUG(DEB_LEV_SIMPLE_SEQ, "Received error OMX_ErrorInsufficientResources\n");
305 } else if (Data1 == OMX_ErrorResourcesLost) {
306 DEBUG(DEFAULT_MESSAGES, "Received error OMX_ErrorResourcesLost\n");
307 } else if (Data1 == OMX_ErrorResourcesPreempted) {
308 DEBUG(DEFAULT_MESSAGES, "Received error OMX_ErrorResourcesPreempted\n");
309 } else {
310 DEBUG(DEFAULT_MESSAGES, "Received error %i\n", (int)Data1);
311 }
312 } else if(eEvent == OMX_EventResourcesAcquired) {
313 DEBUG(DEFAULT_MESSAGES, "Received message OMX_EventResourcesAcquired\n");
314 } else {
315 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
316 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
317 }
318 return OMX_ErrorNone;
319}
320
322 OMX_HANDLETYPE hComponent,
323 OMX_PTR pAppData,
324 OMX_BUFFERHEADERTYPE* pBuffer) {
325
326 return OMX_ErrorNone;
327}
328
330 OMX_HANDLETYPE hComponent,
331 OMX_PTR pAppData,
332 OMX_BUFFERHEADERTYPE* pBuffer) {
333
334 return OMX_ErrorNone;
335}
OMX_ERRORTYPE
Definition OMX_Core.h:127
@ OMX_ErrorInsufficientResources
Definition OMX_Core.h:131
@ OMX_ErrorNone
Definition OMX_Core.h:128
@ OMX_ErrorResourcesPreempted
Definition OMX_Core.h:191
@ OMX_ErrorResourcesLost
Definition OMX_Core.h:172
@ OMX_IndexParamVideoInit
Definition OMX_Index.h:66
@ OMX_IndexParamImageInit
Definition OMX_Index.h:65
@ OMX_IndexParamAudioInit
Definition OMX_Index.h:64
@ OMX_IndexParamOtherInit
Definition OMX_Index.h:67
unsigned long OMX_U32
Definition OMX_Types.h:145
@ 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_GetParameter( hComponent, nParamIndex, pComponentParameterStructure)
Definition OMX_Core.h:786
#define OMX_GetState( hComponent, pState)
Definition OMX_Core.h:958
OMX_STATETYPE
Definition OMX_Core.h:93
#define OMX_SendCommand( hComponent, Cmd, nParam, pCmdData)
Definition OMX_Core.h:745
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_EventResourcesAcquired
Definition OMX_Core.h:486
@ OMX_EventCmdComplete
Definition OMX_Core.h:481
@ OMX_EventError
Definition OMX_Core.h:482
OMX_ERRORTYPE OMX_Deinit(void)
The OMX_Deinit standard function.
Definition omxcore.c:123
OMX_ERRORTYPE OMX_FreeHandle(OMX_HANDLETYPE hComponent)
The OMX_FreeHandle standard function.
Definition omxcore.c:190
OMX_ERRORTYPE OMX_Init(void)
The OMX_Init standard function.
Definition omxcore.c:94
OMX_ERRORTYPE OMX_GetHandle(OMX_HANDLETYPE *pHandle, OMX_STRING cComponentName, OMX_PTR pAppData, OMX_CALLBACKTYPE *pCallBacks)
the OMX_GetHandle standard function
Definition omxcore.c:153
@ OMX_CommandPortDisable
Definition OMX_Core.h:53
@ 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 DEFAULT_MESSAGES
#define DEB_LEV_ERR
#define DEB_LEV_SIMPLE_SEQ
#define DEBUG(n, fmt, args...)
int flagInputReceived
OMX_CALLBACKTYPE callbacks
#define VERSIONREVISION
#define VERSIONMINOR
#define VERSIONMAJOR
#define VERSIONSTEP
OMX_ERRORTYPE rmEventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 Data1, OMX_U32 Data2, OMX_PTR pEventData)
#define TIMEOUT
#define MAX_COMPONENTS
OMX_ERRORTYPE rmEmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
OMX_ERRORTYPE rmFillBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
int max_value
tsem_t * eventSem
OMX_BOOL bResourceErrorReceived
OMX_ERRORTYPE rmEventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 Data1, OMX_U32 Data2, OMX_PTR pEventData)
Definition omxrmtest.c:265
int main(int argc, char **argv)
Definition omxrmtest.c:75
OMX_ERRORTYPE rmEmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
Definition omxrmtest.c:321
void display_help()
Definition omxrmtest.c:67
int convertStr2Int(char *str)
Definition omxrmtest.c:53
OMX_ERRORTYPE rmFillBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
Definition omxrmtest.c:329
OMX_HANDLETYPE handle
OMX_ERRORTYPE err
OMX_U32 nStartPortNumber
Definition OMX_Core.h:475
int tsem_timed_down(tsem_t *tsem, unsigned int milliSecondsDelay)
Definition tsemaphore.c:69
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
struct OMX_VERSIONTYPE::@007121123372367275323052312060102065267355012353 s
OMX_U8 nVersionMajor
Definition OMX_Types.h:344
OMX_U8 nVersionMinor
Definition OMX_Types.h:345

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