OpenMAXBellagio  0.9.3
omxrmtest.c
Go to the documentation of this file.
1 
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 
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: omxrmtest 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 
95  max_value = 0;
96  if(argc < 2){
97  display_help();
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]);
120  flagInputReceived = 1;
121  }
122  }
123  argn_dec++;
124  }
125  }
126  if (!flagInputReceived) {
127  display_help();
128  }
129  if (max_value == 0) {
130  max_value = MAX_COMPONENTS;
131  }
132  handle = malloc(sizeof(OMX_HANDLETYPE*) * max_value);
133  /* Obtain file descriptor */
134  eventSem = malloc(sizeof(tsem_t));
135  tsem_init(eventSem, 0);
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));
155  err = OMX_GetParameter(handle[0], OMX_IndexParamAudioInit, &sParam);
156  if (sParam.nPorts > 0) {
157  indexaudiostart = sParam.nStartPortNumber;
158  audioports = sParam.nPorts;
159  }
160  err = OMX_GetParameter(handle[0], OMX_IndexParamVideoInit, &sParam);
161  if (sParam.nPorts > 0) {
162  indexvideostart = sParam.nStartPortNumber;
163  videoports = sParam.nPorts;
164  }
165  err = OMX_GetParameter(handle[0], OMX_IndexParamImageInit, &sParam);
166  if (sParam.nPorts > 0) {
167  indeximagestart = sParam.nStartPortNumber;
168  imageports = sParam.nPorts;
169  }
170  err = OMX_GetParameter(handle[0], OMX_IndexParamOtherInit, &sParam);
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++) {
247  err = OMX_FreeHandle(handle[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;
286  case OMX_StateExecuting:
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  }
296  tsem_up(eventSem);
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");
304  tsem_up(eventSem);
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 }
tsem_t * eventSem
void * OMX_HANDLETYPE
Definition: OMX_Types.h:295
OMX_ERRORTYPE rmFillBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
#define VERSIONMAJOR
unsigned long OMX_U32
Definition: OMX_Types.h:145
OMX_U32 nStartPortNumber
Definition: OMX_Core.h:475
#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_HANDLETYPE handle
#define DEBUG(n, fmt, args...)
struct OMX_VERSIONTYPE::@1 s
#define OMX_GetState(hComponent,pState)
Definition: OMX_Core.h:958
#define DEFAULT_MESSAGES
void * OMX_PTR
Definition: OMX_Types.h:199
#define DEB_LEV_ERR
OMX_EVENTTYPE
Definition: OMX_Core.h:479
#define MAX_COMPONENTS
Definition: omxrmtest.c:31
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
#define OMX_GetParameter(hComponent,nParamIndex,pComponentParameterStructure)
Definition: OMX_Core.h:786
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)
void display_help()
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_FreeHandle(OMX_IN OMX_HANDLETYPE hComponent)
#define OMX_SendCommand(hComponent,Cmd,nParam,pCmdData)
Definition: OMX_Core.h:745
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
#define TIMEOUT
Definition: omxrmtest.c:32
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)
int main(int argc, char *argv[])
execution of registration function
Definition: omxregister.c:402
#define VERSIONREVISION
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
OMX_CALLBACKTYPE callbacks
#define VERSIONSTEP
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
int flagInputReceived
OMX_ERRORTYPE
Definition: OMX_Core.h:126
OMX_U8 nRevision
Definition: OMX_Types.h:334

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