OpenMAXBellagio  0.9.3
omx_reference_resource_manager.c
Go to the documentation of this file.
1 
28 #include <string.h>
31 #include "queue.h"
32 
37 
41 static int globalTimestamp = 0;
42 
48  int i;
49  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
50  globalIndex = 0;
51  listOfcomponentRegistered = calloc(1, sizeof(struct NameIndexType) * MAX_COMPONENTS_TYPES_HANDLED);
52  for (i = 0; i<MAX_COMPONENTS_TYPES_HANDLED; i++) {
53  listOfcomponentRegistered[i].index = -1;
54  listOfcomponentRegistered[i].component_name = NULL;
55  }
56  globalComponentList = malloc(sizeof(ComponentListType*) * MAX_COMPONENTS_TYPES_HANDLED);
57  globalWaitingComponentList = malloc(sizeof(ComponentListType*) * MAX_COMPONENTS_TYPES_HANDLED);
58  memset(globalComponentList, '\0', sizeof(ComponentListType*) * MAX_COMPONENTS_TYPES_HANDLED);
59  memset(globalWaitingComponentList, '\0', sizeof(ComponentListType*) * MAX_COMPONENTS_TYPES_HANDLED);
60  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
61  return OMX_ErrorNone;
62 }
63 
67 OMX_ERRORTYPE RM_RegisterComponent(char *name, int max_components) {
68  int i = 0;
69  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
70  while (listOfcomponentRegistered[i].component_name != NULL) {
71  if (!strcmp(listOfcomponentRegistered[i].component_name, name)) {
72  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s component already registered\n", __func__);
73  return OMX_ErrorNone;
74  }
75  i++;
76  }
77  listOfcomponentRegistered[i].component_name = calloc(1, OMX_MAX_STRINGNAME_SIZE);
78  if (listOfcomponentRegistered[i].component_name == NULL) {
80  }
81  strcpy(listOfcomponentRegistered[i].component_name, name);
82  listOfcomponentRegistered[i].component_name[strlen(name)] = '\0';
83  listOfcomponentRegistered[i].index = globalIndex;
84  listOfcomponentRegistered[i].max_components = max_components;
85  globalIndex++;
86  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
87  return OMX_ErrorNone;
88 }
89 
99  int i = 0;
100  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
101  while(globalComponentList[i] != NULL) {
102  clearList(&globalComponentList[i]);
103  clearList(&globalWaitingComponentList[i]);
104  i++;
105  }
106  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
107  return OMX_ErrorNone;
108 }
109 
114 OMX_ERRORTYPE addElemToList(ComponentListType **list, OMX_COMPONENTTYPE *openmaxStandComp, int index, OMX_BOOL bIsWaiting) {
115  ComponentListType *componentTemp;
116  ComponentListType *componentNext;
117  omx_base_component_PrivateType* omx_base_component_Private;
118  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s is waiting %i\n", __func__, bIsWaiting);
119  omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
120  if (!*list) {
121  *list = malloc(sizeof(ComponentListType));
122  if (!bIsWaiting) {
123  globalComponentList[index] = *list;
124  } else {
125  globalWaitingComponentList[index] = *list;
126  }
127  if (!*list) {
128  DEBUG(DEB_LEV_ERR, "In %s OMX_ErrorInsufficientResources\n", __func__);
130  }
131  (*list)->openmaxStandComp = openmaxStandComp;
132  (*list)->timestamp = globalTimestamp;
133  globalTimestamp++;
134  (*list)->nGroupPriority = omx_base_component_Private->nGroupPriority;
135  (*list)->next = NULL;
136  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
137  return OMX_ErrorNone;
138  }
139  componentTemp = *list;
140  while(componentTemp->next) {
141  componentTemp = componentTemp->next;
142  }
143  componentNext = malloc(sizeof(ComponentListType));
144  if (!componentNext) {
145  DEBUG(DEB_LEV_ERR, "In %s OMX_ErrorInsufficientResources\n", __func__);
147  }
148  componentTemp->next = componentNext;
149  componentNext->next = NULL;
150  componentNext->openmaxStandComp = openmaxStandComp;
151  componentNext->timestamp = globalTimestamp;
152  globalTimestamp++;
153  componentNext->nGroupPriority = omx_base_component_Private->nGroupPriority;
154  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
155  return OMX_ErrorNone;
156 }
157 
163  ComponentListType *componentTemp;
164  ComponentListType *componentPrev;
165  OMX_BOOL bFound = OMX_FALSE;
166 
167  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s list %p\n", __func__, *list);
168  if (!*list) {
169  DEBUG(DEB_LEV_ERR, "In %s, the resource manager is not initialized\n", __func__);
170  return OMX_ErrorUndefined;
171  }
172  componentTemp = *list;
173  componentPrev = *list;
174  while(componentTemp) {
175  if (componentTemp->openmaxStandComp == openmaxStandComp) {
176  if (componentTemp == *list) {
177  *list = (*list)->next;
178  free(componentTemp);
179  } else {
180  componentPrev->next = componentTemp->next;
181  free(componentTemp);
182  }
183  bFound = OMX_TRUE;
184  break;
185  } else {
186  if (componentTemp != *list) {
187  componentPrev = componentPrev->next;
188  }
189  componentTemp = componentTemp->next;
190  }
191  }
192  if(!bFound) {
193  DEBUG(DEB_LEV_ERR, "In %s, the specified component does not exist\n", __func__);
195  }
196  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
197  return OMX_ErrorNone;
198 
199 }
200 
201 
208  ComponentListType *componentTemp;
209  int numElem = 0;
210  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
211  if (!list) {
212  DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s, no list no elements\n", __func__);
213  return 0;
214  }
215  componentTemp = list;
216  while(componentTemp) {
217  numElem++;
218  componentTemp = componentTemp->next;
219  }
220  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
221  return numElem;
222 }
223 
229  ComponentListType *componentTemp;
230  ComponentListType *componentPrev;
231  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
232  if (!*list) {
233  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s, no list no elements\n", __func__);
234  return OMX_ErrorNone;
235  }
236  componentTemp = *list;
237  while(componentTemp) {
238  componentPrev = componentTemp;
239  componentTemp = componentTemp->next;
240  free(componentPrev);
241  }
242  *list = NULL;
243  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
244  return OMX_ErrorNone;
245 }
246 
251 void RM_printList(ComponentListType *list, int viewFlag) {
252  ComponentListType *componentTemp = list;
253  omx_base_component_PrivateType* omx_base_component_Private;
254  int index;
255 
256  if (!list) {
257  printf("The list is empty\n");
258  return;
259  }
260  index = 0;
261  while (componentTemp) {
262  omx_base_component_Private = (omx_base_component_PrivateType*)componentTemp->openmaxStandComp->pComponentPrivate;
263  if ((viewFlag & RM_SHOW_NAME) == RM_SHOW_NAME) {
264  printf("Name %s ", omx_base_component_Private->name);
265  }
266  if ((viewFlag & RM_SHOW_ADDRESS) == RM_SHOW_ADDRESS) {
267  printf("Address %p ", componentTemp->openmaxStandComp);
268  }
269  printf("\n");
270  index++;
271  componentTemp = componentTemp->next;
272  }
273 }
274 
282 int searchLowerPriority(ComponentListType *list, int current_priority, ComponentListType **oldest_component_preemptable) {
283  ComponentListType *componentTemp;
284  ComponentListType *componentCandidate;
285  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
286  int nComp = 0;
287  if (!list) {
288  DEBUG(DEB_LEV_ERR, "In %s no list\n", __func__);
289  return OMX_ErrorUndefined;
290  }
291  componentTemp = list;
292  componentCandidate = NULL;
293  while (componentTemp) {
294  if (componentTemp->nGroupPriority > current_priority) {
295  nComp++;
296  }
297  if (nComp>0) {
298  if (componentCandidate) {
299  if (componentCandidate->timestamp > componentTemp->timestamp) {
300  componentCandidate = componentTemp;
301  }
302  } else {
303  componentCandidate = componentTemp;
304  }
305  }
306  componentTemp = componentTemp->next;
307  }
308  *oldest_component_preemptable = componentCandidate;
309  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
310  return nComp;
311 }
312 
319  omx_base_component_PrivateType* omx_base_component_Private = openmaxStandComp->pComponentPrivate;
320 
321  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
322 
323  if (omx_base_component_Private->state == OMX_StateIdle) {
324  (*(omx_base_component_Private->callbacks->EventHandler))
325  (openmaxStandComp, omx_base_component_Private->callbackData,
327  err = OMX_SendCommand(openmaxStandComp, OMX_CommandStateSet, OMX_StateLoaded, NULL);
328  if (err != OMX_ErrorNone) {
329  DEBUG(DEB_LEV_ERR, "In %s, the state cannot be changed\n", __func__);
330  return OMX_ErrorUndefined;
331  }
332  } else if ((omx_base_component_Private->state == OMX_StateExecuting) || (omx_base_component_Private->state == OMX_StatePause)) {
333  // TODO fill also this section that cover the preemption of a running component
334  // send OMX_ErrorResourcesPreempted
335  // change state to Idle
336  // send OMX_ErrorResourcesLost
337  // change state to Loaded
338  }
339  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
340  return OMX_ErrorNone;
341 }
342 
350  ComponentListType *componentCandidate;
351  omx_base_component_PrivateType* omx_base_component_Private;
352  int candidates;
354  int i = 0;
355  int indexComponent = -1;
356 
357  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
358  omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
359  while(listOfcomponentRegistered[i].component_name != NULL ) {
360  if (!strcmp(listOfcomponentRegistered[i].component_name, omx_base_component_Private->name)) {
361  // found component in the list of the resource manager
362  indexComponent = listOfcomponentRegistered[i].index;
363  break;
364  }
365  i++;
366  }
367  if (indexComponent <0) {
368  // No resource to be handled
369  DEBUG(DEB_LEV_ERR, "In %s No resource to be handled\n", __func__);
370  return OMX_ErrorNone;
371  }
372  if (numElemInList(globalComponentList[indexComponent]) >= listOfcomponentRegistered[i].max_components) {
373  candidates = searchLowerPriority(globalComponentList[indexComponent], omx_base_component_Private->nGroupPriority, &componentCandidate);
374  if (candidates) {
375  DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s candidates %i winner %p\n", __func__, candidates, componentCandidate->openmaxStandComp);
376  err = preemptComponent(componentCandidate->openmaxStandComp);
377  if (err != OMX_ErrorNone) {
378  DEBUG(DEB_LEV_ERR, "In %s the component cannot be preempted\n", __func__);
380  } else {
381  err = removeElemFromList(&globalComponentList[indexComponent], componentCandidate->openmaxStandComp);
382  err = addElemToList(&globalComponentList[indexComponent], openmaxStandComp, indexComponent, OMX_FALSE);
383  if (err != OMX_ErrorNone) {
384  DEBUG(DEB_LEV_ERR, "In %s memory error\n", __func__);
386  }
387  }
388  } else {
389  DEBUG(DEB_LEV_SIMPLE_SEQ, "Out of %s with insufficient resources\n", __func__);
391  }
392 
393  } else {
394  err = addElemToList(&globalComponentList[indexComponent], openmaxStandComp, indexComponent, OMX_FALSE);
395  }
396  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
397  return OMX_ErrorNone;
398 }
399 
405  omx_base_component_PrivateType* omx_base_component_Private;
406  OMX_COMPONENTTYPE *openmaxWaitingComp;
408 
409  int i = 0;
410  int indexComponent = -1;
411 
412  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
413  omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
414 
415  while(listOfcomponentRegistered[i].component_name != NULL ) {
416  if (!strcmp(listOfcomponentRegistered[i].component_name, omx_base_component_Private->name)) {
417  // found component in the list of the resource manager
418  indexComponent = listOfcomponentRegistered[i].index;
419  break;
420  }
421  i++;
422  }
423  if (indexComponent <0) {
424  // No resource to be handled
425  DEBUG(DEB_LEV_ERR, "In %s No resource to be handled\n", __func__);
426  return OMX_ErrorNone;
427  }
428  if (!globalComponentList[indexComponent]) {
429  DEBUG(DEB_LEV_ERR, "In %s, the resource manager is not initialized\n", __func__);
430  return OMX_ErrorUndefined;
431  }
432  err = removeElemFromList(&globalComponentList[indexComponent], openmaxStandComp);
433  if (err != OMX_ErrorNone) {
434  DEBUG(DEB_LEV_ERR, "In %s, the resource cannot be released\n", __func__);
435  return OMX_ErrorUndefined;
436  }
437  if(numElemInList(globalWaitingComponentList[indexComponent])) {
438  openmaxWaitingComp = globalWaitingComponentList[indexComponent]->openmaxStandComp;
439  removeElemFromList(&globalWaitingComponentList[indexComponent], openmaxWaitingComp);
440  err = OMX_SendCommand(openmaxWaitingComp, OMX_CommandStateSet, OMX_StateIdle, NULL);
441  if (err != OMX_ErrorNone) {
442  DEBUG(DEB_LEV_ERR, "In %s, the state cannot be changed\n", __func__);
443  }
444  }
445 
446  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
447  return OMX_ErrorNone;
448 }
449 
457  omx_base_component_PrivateType* omx_base_component_Private;
458 
459  int i = 0;
460  int indexComponent = -1;
461 
462  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
463  omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
464 
465  while(listOfcomponentRegistered[i].component_name != NULL ) {
466  if (!strcmp(listOfcomponentRegistered[i].component_name, omx_base_component_Private->name)) {
467  // found component in the list of the resource manager
468  indexComponent = listOfcomponentRegistered[i].index;
469  break;
470  }
471  i++;
472  }
473  if (indexComponent <0) {
474  // No resource to be handled
475  DEBUG(DEB_LEV_ERR, "In %s No resource to be handled\n", __func__);
476  return OMX_ErrorNone;
477  }
478 
479  addElemToList(&globalWaitingComponentList[indexComponent], openmaxStandComp, listOfcomponentRegistered[i].index, OMX_TRUE);
480 
481  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
482  return OMX_ErrorNone;
483 }
484 
491  omx_base_component_PrivateType* omx_base_component_Private;
492  int i = 0;
493  int indexComponent = -1;
494 
495  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
496  omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
497 
498  while(listOfcomponentRegistered[i].component_name != NULL ) {
499  if (!strcmp(listOfcomponentRegistered[i].component_name, omx_base_component_Private->name)) {
500  // found component in the list of the resource manager
501  removeElemFromList(&globalComponentList[indexComponent], openmaxStandComp);
502  break;
503  }
504  i++;
505  }
506  if (indexComponent <0) {
507  // No resource to be handled
508  DEBUG(DEB_LEV_ERR, "In %s No resource to be handled\n", __func__);
509  return OMX_ErrorNone;
510  }
511  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
512  return OMX_ErrorNone;
513 }
NameIndexType * listOfcomponentRegistered
OMX_ERRORTYPE clearList(ComponentListType **list)
#define DEB_LEV_SIMPLE_SEQ
#define RM_SHOW_ADDRESS
ComponentListType ** globalWaitingComponentList
#define DEBUG(n, fmt, args...)
OMX_BOOL
Definition: OMX_Types.h:189
#define RM_SHOW_NAME
#define DEB_LEV_ERR
OMX_ERRORTYPE RM_Init()
OMX_ERRORTYPE RM_RegisterComponent(char *name, int max_components)
#define OMX_SendCommand(hComponent,Cmd,nParam,pCmdData)
Definition: OMX_Core.h:745
OMX_ERRORTYPE preemptComponent(OMX_COMPONENTTYPE *openmaxStandComp)
ComponentListType ** globalComponentList
OMX_ERRORTYPE addElemToList(ComponentListType **list, OMX_COMPONENTTYPE *openmaxStandComp, int index, OMX_BOOL bIsWaiting)
#define OMX_MAX_STRINGNAME_SIZE
Definition: OMX_Core.h:281
OMX_ERRORTYPE err
OMX_ERRORTYPE RM_getResource(OMX_COMPONENTTYPE *openmaxStandComp)
OMX_ERRORTYPE RM_removeFromWaitForResource(OMX_COMPONENTTYPE *openmaxStandComp)
OMX_ERRORTYPE RM_Deinit()
OMX_PTR pComponentPrivate
#define DEB_LEV_FUNCTION_NAME
OMX_COMPONENTTYPE * openmaxStandComp
OMX_ERRORTYPE RM_waitForResource(OMX_COMPONENTTYPE *openmaxStandComp)
void RM_printList(ComponentListType *list, int viewFlag)
int numElemInList(ComponentListType *list)
OMX_ERRORTYPE RM_releaseResource(OMX_COMPONENTTYPE *openmaxStandComp)
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
#define MAX_COMPONENTS_TYPES_HANDLED
int searchLowerPriority(ComponentListType *list, int current_priority, ComponentListType **oldest_component_preemptable)
OMX_ERRORTYPE
Definition: OMX_Core.h:126
OMX_ERRORTYPE removeElemFromList(ComponentListType **list, OMX_COMPONENTTYPE *openmaxStandComp)

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