OpenMAX Bellagio 0.9.3
omxprioritytest.c
Go to the documentation of this file.
1
27#include "omxprioritytest.h"
28#include <string.h>
29#include <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: omxprioritytest 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=0;
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 OMX_PRIORITYMGMTTYPE oPriority;
95
96 max_value = 0;
97 if(argc < 2){
99 } else {
100 while (argn_dec < argc) {
101 if (*(argv[argn_dec]) == '-') {
102 switch (*(argv[argn_dec] + 1)) {
103 case 'h':
104 display_help();
105 break;
106 case 'i':
107 getMaxValue = 1;
108 break;
109 default:
110 display_help();
111 }
112 } else {
113 if (getMaxValue) {
114 max_value = convertStr2Int(argv[argn_dec]);
115 if (max_value == 0) {
116 display_help();
117 }
118 } else {
119 componentName = malloc(strlen(argv[argn_dec]) * sizeof(char) + 1);
120 strcpy(componentName, argv[argn_dec]);
122 }
123 }
124 argn_dec++;
125 }
126 }
127 if (!flagInputReceived) {
128 display_help();
129 }
130 if (max_value == 0) {
132 }
133 handle = malloc(sizeof(OMX_HANDLETYPE*) * max_value);
134 /* Obtain file descriptor */
135 eventSem = malloc(sizeof(tsem_t));
138 err = OMX_Init();
139 if(err != OMX_ErrorNone) {
140 DEBUG(DEB_LEV_ERR, "OMX_Init() failed\n");
141 exit(1);
142 }
143 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_Init()\n");
144
145 for (i = 0; i<max_value; i++) {
146 err = OMX_GetHandle(&handle[i], componentName, NULL, &callbacks);
147 if(err != OMX_ErrorNone) {
148 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
149 DEBUG(DEFAULT_MESSAGES, "The OLD STYLE resource manager on %s\n", componentName);
150 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
151 exit(1);
152 }
153 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_GetHandle() %i\n", i);
154 }
155 setHeader(&sParam, sizeof(OMX_PORT_PARAM_TYPE));
157 if (sParam.nPorts > 0) {
158 indexaudiostart = sParam.nStartPortNumber;
159 audioports = sParam.nPorts;
160 }
162 if (sParam.nPorts > 0) {
163 indexvideostart = sParam.nStartPortNumber;
164 videoports = sParam.nPorts;
165 }
167 if (sParam.nPorts > 0) {
168 indeximagestart = sParam.nStartPortNumber;
169 imageports = sParam.nPorts;
170 }
172 if (sParam.nPorts > 0) {
173 indexotherstart = sParam.nStartPortNumber;
174 otherports = sParam.nPorts;
175 }
176
177 for (i = 0; i<max_value; i++) {
178 // todo this test is valid only for 2 ports components, not like mixer, sinks, sources
179 if (indexaudiostart >= 0) {
180 for (j = 0; j< audioports; j++) {
181 err = OMX_SendCommand(handle[i], OMX_CommandPortDisable, j + indexaudiostart, 0);
182 }
183 }
184 if (indexvideostart >= 0) {
185 for (j = 0; j< videoports; j++) {
186 err = OMX_SendCommand(handle[i], OMX_CommandPortDisable, j + indexvideostart, 0);
187 }
188 }
189 if (indeximagestart >= 0) {
190 for (j = 0; j< imageports; j++) {
191 err = OMX_SendCommand(handle[i], OMX_CommandPortDisable, j + indeximagestart, 0);
192 }
193 }
194 if (indexotherstart >= 0) {
195 for (j = 0; j< otherports; j++) {
196 err = OMX_SendCommand(handle[i], OMX_CommandPortDisable, j + indexotherstart, 0);
197 }
198 }
200 if(err != OMX_ErrorNone) {
201 DEBUG(DEB_LEV_ERR, "The component %s can't go to Idle\n", componentName);
202 break;
203 }
204 global_err = tsem_timed_down(eventSem, TIMEOUT);
205 if (global_err != 0) {
206 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
207 DEBUG(DEFAULT_MESSAGES, "The resource manager does not handle component %s\n", componentName);
208 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
209 break;
210 } else {
211 DEBUG(DEB_LEV_SIMPLE_SEQ, "The component %i is set to Idle\n", i);
212
216 DEBUG(DEB_LEV_SIMPLE_SEQ, "The resources are exhausted\n");
217 DEBUG(DEB_LEV_SIMPLE_SEQ, "Raising the priority of component %i\n", i);
218 setHeader(&oPriority, sizeof(OMX_PRIORITYMGMTTYPE));
219 oPriority.nGroupPriority = 1;
223 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
224 DEBUG(DEFAULT_MESSAGES, "The resource manager has operated on %s\n", componentName);
225 DEBUG(DEFAULT_MESSAGES, "#########################################################################\n");
226 break;
227 }
228 }
229 }
230 num_of_components = i;
231
232 DEBUG(DEB_LEV_SIMPLE_SEQ, "Dispose the system\n");
233 for (i = 0; i<num_of_components; i++) {
234 err = OMX_GetState(handle[i], &state);
235 if (state == OMX_StateIdle) {
238 DEBUG(DEB_LEV_SIMPLE_SEQ, "Component %i sent to Loaded\n", i);
239 } else if (state == OMX_StateLoaded) {
240 DEBUG(DEB_LEV_SIMPLE_SEQ, "Component %i already loaded\n", i);
241 } else {
242 DEBUG(DEB_LEV_SIMPLE_SEQ, "Component %i in the wrong state!\n", i);
243 }
244 }
245 DEBUG(DEB_LEV_SIMPLE_SEQ, "All %i to loaded\n", num_of_components);
246
247 for (i = 0; i<max_value; i++) {
249 if(err != OMX_ErrorNone) {
250 DEBUG(DEB_LEV_ERR, "OMX_FreeHandle [%i] failed\n", i);
251 exit(1);
252 }
253 }
254
255 err = OMX_Deinit();
256 if(err != OMX_ErrorNone) {
257 DEBUG(DEB_LEV_ERR, "OMX_Deinit() failed\n");
258 exit(1);
259 }
260 free(eventSem);
261 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_Deinit()\n");
262 return 0;
263}
264
265/* Callbacks implementation */
267 OMX_HANDLETYPE hComponent,
268 OMX_PTR pAppData,
269 OMX_EVENTTYPE eEvent,
270 OMX_U32 Data1,
271 OMX_U32 Data2,
272 OMX_PTR pEventData) {
273
274 if(eEvent == OMX_EventCmdComplete) {
275 if (Data1 == OMX_CommandStateSet) {
276 DEBUG(DEB_LEV_SIMPLE_SEQ, "Volume Component %p State changed in ", hComponent);
277 switch ((int)Data2) {
278 case OMX_StateInvalid:
279 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
280 break;
281 case OMX_StateLoaded:
282 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
283 break;
284 case OMX_StateIdle:
285 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
286 break;
288 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
289 break;
290 case OMX_StatePause:
291 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
292 break;
294 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
295 break;
296 }
298 } else if (Data1 == OMX_CommandPortDisable) {
299 DEBUG(DEB_LEV_SIMPLE_SEQ, "Disabled port %i\n", (int)Data2);
300 }
301 } else if (eEvent == OMX_EventError) {
302 if (Data1 == OMX_ErrorInsufficientResources) {
303 DEBUG(DEB_LEV_SIMPLE_SEQ, "Received error OMX_ErrorInsufficientResources\n");
306 } else if (Data1 == OMX_ErrorResourcesLost) {
307 DEBUG(DEFAULT_MESSAGES, "Received error OMX_ErrorResourcesLost\n");
308 } else if (Data1 == OMX_ErrorResourcesPreempted) {
309 DEBUG(DEFAULT_MESSAGES, "Received error OMX_ErrorResourcesPreempted\n");
310 } else {
311 DEBUG(DEFAULT_MESSAGES, "Received error %i\n", (int)Data1);
312 }
313 } else if(eEvent == OMX_EventResourcesAcquired) {
314 DEBUG(DEFAULT_MESSAGES, "Received message OMX_EventResourcesAcquired\n");
315 } else {
316 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
317 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
318 }
319 return OMX_ErrorNone;
320}
321
323 OMX_HANDLETYPE hComponent,
324 OMX_PTR pAppData,
325 OMX_BUFFERHEADERTYPE* pBuffer) {
326
327 return OMX_ErrorNone;
328}
329
331 OMX_HANDLETYPE hComponent,
332 OMX_PTR pAppData,
333 OMX_BUFFERHEADERTYPE* pBuffer) {
334
335 return OMX_ErrorNone;
336}
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_IndexParamPriorityMgmt
Definition OMX_Index.h:63
@ 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
#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_EventResourcesAcquired
Definition OMX_Core.h:486
@ OMX_EventCmdComplete
Definition OMX_Core.h:481
@ OMX_EventError
Definition OMX_Core.h:482
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Deinit(void)
The OMX_Deinit standard function.
Definition omxcore.c:123
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_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
#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)
OMX_CALLBACKTYPE callbacks
int main(int argc, char **argv)
#define TIMEOUT
OMX_HANDLETYPE * handle
#define MAX_COMPONENTS
OMX_ERRORTYPE rmEmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
void display_help()
int convertStr2Int(char *str)
OMX_ERRORTYPE rmFillBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
int max_value
tsem_t * eventSem
OMX_BOOL bResourceErrorReceived
OMX_ERRORTYPE err
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
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
OMX_U8 nVersionMajor
Definition OMX_Types.h:332
struct OMX_VERSIONTYPE::@1 s
OMX_U8 nVersionMinor
Definition OMX_Types.h:333

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