OpenMAXBellagio  0.9.3
omxprioritytest.c
Go to the documentation of this file.
1 
27 #include "omxprioritytest.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 
43 static 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 
53 int 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 
67 void display_help() {
68  printf("\n");
69  printf("Usage: omxprioritytest OMX_name [-i max_comp]\n");
70  printf("\n");
71  exit(1);
72 }
73 
75 int 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;
85  OMX_PORT_PARAM_TYPE sParam;
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){
98  display_help();
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]);
121  flagInputReceived = 1;
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));
136  tsem_init(eventSem, 0);
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++) {
248  err = OMX_FreeHandle(handle[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;
287  case OMX_StateExecuting:
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  }
297  tsem_up(eventSem);
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");
305  tsem_up(eventSem);
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 }
tsem_t * eventSem
void * OMX_HANDLETYPE
Definition: OMX_Types.h:295
OMX_ERRORTYPE rmFillBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
#define TIMEOUT
#define VERSIONMAJOR
unsigned long OMX_U32
Definition: OMX_Types.h:145
OMX_U32 nStartPortNumber
Definition: OMX_Core.h:475
int main(int argc, char **argv)
#define DEB_LEV_SIMPLE_SEQ
int max_value
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Init(void)
The OMX_Init standard function.
Definition: omxcore.c:94
OMX_U32 nGroupPriority
Definition: OMX_Core.h:276
#define DEBUG(n, fmt, args...)
struct OMX_VERSIONTYPE::@1 s
OMX_HANDLETYPE * handle
#define MAX_COMPONENTS
#define DEFAULT_MESSAGES
void * OMX_PTR
Definition: OMX_Types.h:199
OMX_CALLBACKTYPE callbacks
#define DEB_LEV_ERR
OMX_EVENTTYPE
Definition: OMX_Core.h:479
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
void tsem_up(tsem_t *tsem)
Definition: tsemaphore.c:110
void setHeader(OMX_PTR header, OMX_U32 size)
Simply fills the first two fields in any OMX structure with the size and the version.
int tsem_timed_down(tsem_t *tsem, unsigned int milliSecondsDelay)
Definition: tsemaphore.c:69
void tsem_down(tsem_t *tsem)
Definition: tsemaphore.c:97
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_ERRORTYPE err
#define VERSIONMINOR
OMX_U8 nVersionMinor
Definition: OMX_Types.h:333
OMX_U8 nVersionMajor
Definition: OMX_Types.h:332
OMX_STATETYPE
Definition: OMX_Core.h:92
OMX_BOOL bResourceErrorReceived
int tsem_init(tsem_t *tsem, unsigned int val)
Definition: tsemaphore.c:39
int convertStr2Int(char *str)
OMX_ERRORTYPE rmEmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
#define VERSIONREVISION
#define OMX_GetState( hComponent, pState)
Definition: OMX_Core.h:958
#define OMX_SetParameter( hComponent, nParamIndex, pComponentParameterStructure)
Definition: OMX_Core.h:825
#define OMX_SendCommand( hComponent, Cmd, nParam, pCmdData)
Definition: OMX_Core.h:745
#define OMX_GetParameter( hComponent, nParamIndex, pComponentParameterStructure)
Definition: OMX_Core.h:786
OMX_ERRORTYPE rmEventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 Data1, OMX_U32 Data2, OMX_PTR pEventData)
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Deinit(void)
The OMX_Deinit standard function.
Definition: omxcore.c:123
#define VERSIONSTEP
int flagInputReceived
OMX_ERRORTYPE
Definition: OMX_Core.h:126
void display_help()
OMX_U8 nRevision
Definition: OMX_Types.h:334

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