OpenMAXBellagio  0.9.3
ste_dynamic_component_loader.c
Go to the documentation of this file.
1 
26 #define _GNU_SOURCE
27 #ifndef OMX_COMPONENT_PATH
28 #define OMX_COMPONENT_PATH "/usr/lib/bellagio/"
29 #endif
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <dlfcn.h>
34 #include <sys/types.h>
35 #include <dirent.h>
36 #include <strings.h>
37 #include <errno.h>
38 #include <assert.h>
39 
40 #include "common.h"
44 
51 void *handleLibList[100];
55 static struct BOSA_COMPONENTLOADER *ste_static_loader;
56 
62  ste_static_loader = loader;
65  ste_static_loader->BOSA_CreateComponent = &BOSA_STE_CreateComponent;
70 }
71 
80  DIR *dirp;
81  struct dirent *dp;
82  int num_of_comp=0;
83  steLoaderComponentType** templateList;
84  steLoaderComponentType** stComponentsTemp;
85  void* handle;
86  int (*fptr)(steLoaderComponentType **stComponents);
87  int i;
88  int listindex;
89 
90  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
91 
92  /* Populate the registry file */
93  dirp = opendir(OMX_COMPONENT_PATH);
94  if(dirp == NULL){
95  DEBUG(DEB_LEV_ERR, "Failed to open directory %s\n", OMX_COMPONENT_PATH);
96  return OMX_ErrorUndefined;
97  }
98 
99  templateList = malloc(sizeof (steLoaderComponentType*));
100  templateList[0] = NULL;
101 
102  listindex = 0;
103  while((dp = readdir(dirp)) != NULL) {
104  int len = strlen(dp->d_name);
105 
106  if(len <= 3)
107  continue;
108 
109  if(strncmp(dp->d_name+len-3, ".so", 3) == 0) {
110  char lib_absolute_path[strlen(OMX_COMPONENT_PATH) + len + 1];
111 
112  strcpy(lib_absolute_path, OMX_COMPONENT_PATH);
113  strcat(lib_absolute_path, dp->d_name);
114 
115  if((handle = dlopen(lib_absolute_path, RTLD_NOW)) == NULL) {
116  DEBUG(DEB_LEV_ERR, "could not load %s: %s\n", lib_absolute_path, dlerror());
117  } else {
119  numLib++;
120  if ((fptr = dlsym(handle, "omx_component_library_Setup")) == NULL) {
121  DEBUG(DEB_LEV_ERR, "the library %s is not compatible with ST static component loader - %s\n", lib_absolute_path, dlerror());
122  } else {
123  num_of_comp = (int)(*fptr)(NULL);
124  templateList = realloc(templateList, (listindex + num_of_comp + 1) * sizeof (steLoaderComponentType*));
125  templateList[listindex + num_of_comp] = NULL;
126  stComponentsTemp = calloc(num_of_comp,sizeof(steLoaderComponentType*));
127  for (i = 0; i<num_of_comp; i++) {
128  stComponentsTemp[i] = calloc(1,sizeof(steLoaderComponentType));
129  }
130  (*fptr)(stComponentsTemp);
131  for (i = 0; i<num_of_comp; i++) {
132  templateList[listindex + i] = stComponentsTemp[i];
133  DEBUG(DEB_LEV_FULL_SEQ, "In %s comp name[%d]=%s\n",__func__,listindex + i,templateList[listindex + i]->name);
134  }
135 
136  free(stComponentsTemp);
137  stComponentsTemp = NULL;
138  listindex+= i;
139  }
140  }
141  }
142  }
143 
144  loader->loaderPrivate = templateList;
145 
146  RM_Init();
147  closedir(dirp);
148  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
149  return OMX_ErrorNone;
150 }
151 
157  unsigned int i, j;
158  int err;
159  steLoaderComponentType** templateList;
160  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
161  templateList = (steLoaderComponentType**)loader->loaderPrivate;
162 
163  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
164 
165  i = 0;
166  while(templateList[i]) {
167  if(templateList[i]->name_requested){
168  free(templateList[i]->name_requested);
169  templateList[i]->name_requested=NULL;
170  }
171 
172  for(j = 0 ; j < templateList[i]->name_specific_length; j++){
173  if(templateList[i]->name_specific[j]) {
174  free(templateList[i]->name_specific[j]);
175  templateList[i]->name_specific[j]=NULL;
176  }
177  if(templateList[i]->role_specific[j]){
178  free(templateList[i]->role_specific[j]);
179  templateList[i]->role_specific[j]=NULL;
180  }
181  }
182 
183  if(templateList[i]->name_specific){
184  free(templateList[i]->name_specific);
185  templateList[i]->name_specific=NULL;
186  }
187  if(templateList[i]->role_specific){
188  free(templateList[i]->role_specific);
189  templateList[i]->role_specific=NULL;
190  }
191  if(templateList[i]->name){
192  free(templateList[i]->name);
193  templateList[i]->name=NULL;
194  }
195  free(templateList[i]);
196  templateList[i] = NULL;
197  i++;
198  }
199  if(templateList) {
200  free(templateList);
201  templateList=NULL;
202  }
203 
204  for(i=0;i<numLib;i++) {
205  err = dlclose(handleLibList[i]);
206  if(err!=0) {
207  DEBUG(DEB_LEV_ERR, "In %s Error %d in dlclose of lib %i\n", __func__,err,i);
208  }
209  }
210  numLib=0;
211 
212  RM_Deinit();
213 
214  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
215  return OMX_ErrorNone;
216 }
217 
226  BOSA_COMPONENTLOADER *loader,
227  OMX_HANDLETYPE* pHandle,
228  OMX_STRING cComponentName,
229  OMX_PTR pAppData,
230  OMX_CALLBACKTYPE* pCallBacks) {
231 
232  int i;
233  unsigned int j;
234  int componentPosition = -1;
235  OMX_ERRORTYPE eError = OMX_ErrorNone;
236  steLoaderComponentType** templateList;
237  OMX_COMPONENTTYPE *openmaxStandComp;
239 
240  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
241  templateList = (steLoaderComponentType**)loader->loaderPrivate;
242  i = 0;
243  while(templateList[i]) {
244  if(!strcmp(templateList[i]->name, cComponentName)) {
245  //given component name matches with the general component names
246  componentPosition = i;
247  break;
248  } else {
249  for(j=0;j<templateList[i]->name_specific_length;j++) {
250  if(!strcmp(templateList[i]->name_specific[j], cComponentName)) {
251  //given component name matches with specific component names
252  componentPosition = i;
253  break;
254  }
255  }
256  if(componentPosition != -1) {
257  break;
258  }
259  }
260  i++;
261  }
262  if (componentPosition == -1) {
263  DEBUG(DEB_LEV_ERR, "Component not found with current ST static component loader.\n");
265  }
266 
267  //component name matches with general component name field
268  DEBUG(DEB_LEV_PARAMS, "Found base requested template %s\n", cComponentName);
269  /* Build ST component from template and fill fields */
270  if (templateList[componentPosition]->name_requested == NULL)
271  { /* This check is to prevent memory leak in case two instances of the same component are loaded */
272  templateList[componentPosition]->name_requested = strndup (cComponentName, OMX_MAX_STRINGNAME_SIZE);
273  }
274 
275  openmaxStandComp = calloc(1,sizeof(OMX_COMPONENTTYPE));
276  if (!openmaxStandComp) {
278  }
279  eError = templateList[componentPosition]->constructor(openmaxStandComp,cComponentName);
280  if (eError != OMX_ErrorNone) {
281  if (eError == OMX_ErrorInsufficientResources) {
282  *pHandle = openmaxStandComp;
283  priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
284  priv->loader = loader;
286  }
287  DEBUG(DEB_LEV_ERR, "Error during component construction\n");
288  openmaxStandComp->ComponentDeInit(openmaxStandComp);
289  free(openmaxStandComp);
290  openmaxStandComp = NULL;
292  }
293  priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
294  priv->loader = loader;
295 
296  *pHandle = openmaxStandComp;
297  ((OMX_COMPONENTTYPE*)*pHandle)->SetCallbacks(*pHandle, pCallBacks, pAppData);
298 
299  DEBUG(DEB_LEV_FULL_SEQ, "Template %s found returning from OMX_GetHandle\n", cComponentName);
300  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
301  return OMX_ErrorNone;
302 }
303 
305  BOSA_COMPONENTLOADER *loader,
306  OMX_HANDLETYPE hComponent) {
308  omx_base_component_PrivateType * priv = (omx_base_component_PrivateType *) ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
309 
310  /* check if this component was actually loaded from this loader */
311  if (priv->loader != loader) {
313  }
314 
315  err = ((OMX_COMPONENTTYPE*)hComponent)->ComponentDeInit(hComponent);
316 
317  free((OMX_COMPONENTTYPE*)hComponent);
318  hComponent = NULL;
319 
320  return err;
321 }
322 
329  BOSA_COMPONENTLOADER *loader,
330  OMX_STRING cComponentName,
331  OMX_U32 nNameLength,
332  OMX_U32 nIndex) {
333 
334  steLoaderComponentType** templateList;
335  int i;
336  unsigned int j, index = 0;
337  int found = 0;
338  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
339 
340  templateList = (steLoaderComponentType**)loader->loaderPrivate;
341  i = 0;
342  while(templateList[i]) {
343  if (index == nIndex) {
344  strncpy(cComponentName, templateList[i]->name, nNameLength);
345  found = 1;
346  break;
347  }
348  index++;
349  if (templateList[i]->name_specific_length > 0) {
350  for (j = 0; j<templateList[i]->name_specific_length; j++) {
351  if (index == nIndex) {
352  strncpy(cComponentName,templateList[i]->name_specific[j], nNameLength);
353  found = 1;
354  break;
355  }
356  index++;
357  }
358  }
359  if (found) {
360  break;
361  }
362  i++;
363  }
364  if (!found) {
365  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s with OMX_ErrorNoMore\n", __func__);
366  return OMX_ErrorNoMore;
367  }
368  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
369  return OMX_ErrorNone;
370 }
371 
379  BOSA_COMPONENTLOADER *loader,
380  OMX_STRING compName,
381  OMX_U32 *pNumRoles,
382  OMX_U8 **roles) {
383 
384  steLoaderComponentType** templateList;
385  int i;
386  unsigned int j, index;
387  unsigned int max_roles = *pNumRoles;
388  int found = 0;
389  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
390  templateList = (steLoaderComponentType**)loader->loaderPrivate;
391  *pNumRoles = 0;
392  i = 0;
393  while (templateList[i]) {
394  if(!strcmp(templateList[i]->name, compName)) {
395  DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested template %s IN GENERAL COMPONENT\n", compName);
396  // set the no of roles field
397  *pNumRoles = templateList[i]->name_specific_length;
398  if(roles == NULL) {
399  return OMX_ErrorNone;
400  }
401  //append the roles
402  for (index = 0; index < templateList[i]->name_specific_length; index++) {
403  if (index < max_roles) {
404  strcpy ((char*)*(roles+index), templateList[i]->role_specific[index]);
405  }
406  }
407  found = 1;
408  } else {
409  for(j=0;j<templateList[i]->name_specific_length;j++) {
410  if(!strcmp(templateList[i]-> name_specific[j], compName)) {
411  DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested component %s IN SPECIFIC COMPONENT \n", compName);
412  *pNumRoles = 1;
413  found = 1;
414  if(roles == NULL) {
415  return OMX_ErrorNone;
416  }
417  if (max_roles > 0) {
418  strcpy ((char*)*roles , templateList[i]->role_specific[j]);
419  }
420  }
421  }
422  }
423  i++;
424  if(found) {
425  break;
426  }
427  }
428  if(!found) {
429  DEBUG(DEB_LEV_ERR, "no component match in whole template list has been found\n");
430  *pNumRoles = 0;
432  }
433  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
434  return OMX_ErrorNone;
435 }
436 
444  BOSA_COMPONENTLOADER *loader,
445  OMX_STRING role,
446  OMX_U32 *pNumComps,
447  OMX_U8 **compNames) {
448 
449  steLoaderComponentType** templateList;
450  int i = 0;
451  unsigned int j = 0;
452  int num_comp = 0;
453  int max_entries = *pNumComps;
454 
455  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
456  templateList = (steLoaderComponentType**)loader->loaderPrivate;
457  i = 0;
458  while(templateList[i]) {
459  for (j = 0; j<templateList[i]->name_specific_length; j++) {
460  if (!strcmp(templateList[i]->role_specific[j], role)) {
461  if (compNames != NULL) {
462  if (num_comp < max_entries) {
463  strcpy((char*)(compNames[num_comp]), templateList[i]->name);
464  }
465  }
466  num_comp++;
467  }
468  }
469  i++;
470  }
471 
472  *pNumComps = num_comp;
473  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
474  return OMX_ErrorNone;
475 }
OMX_COMPONENTTYPE::pComponentPrivate
OMX_PTR pComponentPrivate
Definition: OMX_Component.h:326
DEB_LEV_FUNCTION_NAME
#define DEB_LEV_FUNCTION_NAME
Definition: omx_comp_debug_levels.h:59
omx_reference_resource_manager.h
DEBUG
#define DEBUG(n, fmt, args...)
Definition: omx_comp_debug_levels.h:77
BOSA_COMPONENTLOADER::BOSA_DestroyComponent
OMX_ERRORTYPE(* BOSA_DestroyComponent)(struct BOSA_COMPONENTLOADER *loader, OMX_HANDLETYPE hComponent)
The component destructor of the current component loader.
Definition: component_loader.h:111
DEB_LEV_FULL_SEQ
#define DEB_LEV_FULL_SEQ
Definition: omx_comp_debug_levels.h:54
BOSA_STE_CreateComponent
OMX_ERRORTYPE BOSA_STE_CreateComponent(BOSA_COMPONENTLOADER *loader, OMX_HANDLETYPE *pHandle, OMX_STRING cComponentName, OMX_PTR pAppData, OMX_CALLBACKTYPE *pCallBacks)
creator of the requested OpenMAX component
Definition: ste_dynamic_component_loader.c:225
steLoaderComponentType::name_specific_length
unsigned int name_specific_length
Definition: ste_dynamic_component_loader.h:42
omx_base_component_PrivateType
Definition: omx_base_component.h:122
OMX_ERRORTYPE
OMX_ERRORTYPE
Definition: OMX_Core.h:127
handleLibList
void * handleLibList[100]
Definition: ste_dynamic_component_loader.c:51
OMX_U32
unsigned long OMX_U32
Definition: OMX_Types.h:145
BOSA_STE_ComponentNameEnum
OMX_ERRORTYPE BOSA_STE_ComponentNameEnum(BOSA_COMPONENTLOADER *loader, OMX_STRING cComponentName, OMX_U32 nNameLength, OMX_U32 nIndex)
This function search for the index from 0 to end of the list.
Definition: ste_dynamic_component_loader.c:328
BOSA_COMPONENTLOADER::loaderPrivate
void * loaderPrivate
The reference to the current component loader private data.
Definition: component_loader.h:219
BOSA_COMPONENTLOADER::BOSA_ComponentNameEnum
OMX_ERRORTYPE(* BOSA_ComponentNameEnum)(struct BOSA_COMPONENTLOADER *loader, OMX_STRING cComponentName, OMX_U32 nNameLength, OMX_U32 nIndex)
An enumerator of the components handled by the current component loader.
Definition: component_loader.h:141
BOSA_STE_DestroyComponent
OMX_ERRORTYPE BOSA_STE_DestroyComponent(BOSA_COMPONENTLOADER *loader, OMX_HANDLETYPE hComponent)
destructor of the requested OpenMAX component
Definition: ste_dynamic_component_loader.c:304
OMX_CALLBACKTYPE
Definition: OMX_Core.h:498
DEB_LEV_ERR
#define DEB_LEV_ERR
Definition: omx_comp_debug_levels.h:39
RM_Init
OMX_ERRORTYPE RM_Init()
Definition: omx_reference_resource_manager.c:42
OMX_HANDLETYPE
void * OMX_HANDLETYPE
Definition: OMX_Types.h:295
BOSA_COMPONENTLOADER::BOSA_CreateComponent
OMX_ERRORTYPE(* BOSA_CreateComponent)(struct BOSA_COMPONENTLOADER *loader, OMX_HANDLETYPE *pHandle, OMX_STRING cComponentName, OMX_PTR pAppData, OMX_CALLBACKTYPE *pCallBacks)
The component constructor of the current component loader.
Definition: component_loader.h:84
setup_component_loader
void setup_component_loader(BOSA_COMPONENTLOADER *loader)
The initialization of the ST specific component loader.
Definition: ste_dynamic_component_loader.c:61
OMX_COMPONENTTYPE::ComponentDeInit
OMX_ERRORTYPE(* ComponentDeInit)(OMX_IN OMX_HANDLETYPE hComponent)
Definition: OMX_Component.h:556
BOSA_COMPONENTLOADER::BOSA_GetComponentsOfRole
OMX_ERRORTYPE(* BOSA_GetComponentsOfRole)(struct BOSA_COMPONENTLOADER *loader, OMX_STRING role, OMX_U32 *pNumComps, OMX_U8 **compNames)
This function implements the OMX_GetComponentsOfRole standard function for the current component load...
Definition: component_loader.h:208
OMX_ErrorUndefined
@ OMX_ErrorUndefined
Definition: OMX_Core.h:134
DEB_LEV_SIMPLE_SEQ
#define DEB_LEV_SIMPLE_SEQ
Definition: omx_comp_debug_levels.h:48
omx_base_component.h
BOSA_STE_GetRolesOfComponent
OMX_ERRORTYPE BOSA_STE_GetRolesOfComponent(BOSA_COMPONENTLOADER *loader, OMX_STRING compName, OMX_U32 *pNumRoles, OMX_U8 **roles)
The specific version of OMX_GetRolesOfComponent.
Definition: ste_dynamic_component_loader.c:378
OMX_PTR
void * OMX_PTR
Definition: OMX_Types.h:199
OMX_ErrorInsufficientResources
@ OMX_ErrorInsufficientResources
Definition: OMX_Core.h:131
OMX_COMPONENTTYPE
Definition: OMX_Component.h:308
BOSA_COMPONENTLOADER::BOSA_DeInitComponentLoader
OMX_ERRORTYPE(* BOSA_DeInitComponentLoader)(struct BOSA_COMPONENTLOADER *loader)
The destructor of the component loader.
Definition: component_loader.h:62
OMX_COMPONENT_PATH
#define OMX_COMPONENT_PATH
Definition: ste_dynamic_component_loader.c:28
handle
OMX_HANDLETYPE handle
Definition: omxvolcontroltest.c:35
OMX_ErrorNoMore
@ OMX_ErrorNoMore
Definition: OMX_Core.h:175
BOSA_COMPONENTLOADER::BOSA_InitComponentLoader
OMX_ERRORTYPE(* BOSA_InitComponentLoader)(struct BOSA_COMPONENTLOADER *loader)
The constructor of the component loader.
Definition: component_loader.h:50
steLoaderComponentType::name_specific
char ** name_specific
Definition: ste_dynamic_component_loader.h:43
steLoaderComponentType
the private data structure handled by the ST static loader that described an OpenMAX component
Definition: ste_dynamic_component_loader.h:39
BOSA_COMPONENTLOADER::BOSA_GetRolesOfComponent
OMX_ERRORTYPE(* BOSA_GetRolesOfComponent)(struct BOSA_COMPONENTLOADER *loader, OMX_STRING compName, OMX_U32 *pNumRoles, OMX_U8 **roles)
This function implements the OMX_GetRolesOfComponent standard function for the current component load...
Definition: component_loader.h:173
numLib
OMX_U32 numLib
Definition: ste_dynamic_component_loader.c:54
steLoaderComponentType::constructor
OMX_ERRORTYPE(* constructor)(OMX_COMPONENTTYPE *, OMX_STRING cComponentName)
Definition: ste_dynamic_component_loader.h:46
BOSA_STE_DeInitComponentLoader
OMX_ERRORTYPE BOSA_STE_DeInitComponentLoader(BOSA_COMPONENTLOADER *loader)
The destructor of the ST specific component loader.
Definition: ste_dynamic_component_loader.c:156
err
OMX_ERRORTYPE err
Definition: omxvolcontroltest.c:34
common.h
OMX_STRING
char * OMX_STRING
Definition: OMX_Types.h:206
steLoaderComponentType::name_requested
char * name_requested
Definition: ste_dynamic_component_loader.h:45
BOSA_STE_InitComponentLoader
OMX_ERRORTYPE BOSA_STE_InitComponentLoader(BOSA_COMPONENTLOADER *loader)
the ST static loader constructor
Definition: ste_dynamic_component_loader.c:79
omx_base_component_PrivateType::loader
void * loader
Definition: omx_base_component.h:158
OMX_MAX_STRINGNAME_SIZE
#define OMX_MAX_STRINGNAME_SIZE
Definition: OMX_Core.h:281
OMX_ErrorComponentNotFound
@ OMX_ErrorComponentNotFound
Definition: OMX_Core.h:140
OMX_ErrorNone
@ OMX_ErrorNone
Definition: OMX_Core.h:128
steLoaderComponentType::name
char * name
Definition: ste_dynamic_component_loader.h:41
OMX_U8
unsigned char OMX_U8
Definition: OMX_Types.h:133
ste_dynamic_component_loader.h
steLoaderComponentType::role_specific
char ** role_specific
Definition: ste_dynamic_component_loader.h:44
RM_Deinit
OMX_ERRORTYPE RM_Deinit()
Definition: omx_reference_resource_manager.c:93
BOSA_COMPONENTLOADER
Component loader entry points.
Definition: component_loader.h:39
DEB_LEV_PARAMS
#define DEB_LEV_PARAMS
Definition: omx_comp_debug_levels.h:43
BOSA_STE_GetComponentsOfRole
OMX_ERRORTYPE BOSA_STE_GetComponentsOfRole(BOSA_COMPONENTLOADER *loader, OMX_STRING role, OMX_U32 *pNumComps, OMX_U8 **compNames)
The specific version of OMX_GetComponentsOfRole.
Definition: ste_dynamic_component_loader.c:443

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