OpenMAXBellagio  0.9.3
st_static_component_loader.c
Go to the documentation of this file.
1 
26 #define _GNU_SOURCE
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <dlfcn.h>
31 #include <sys/types.h>
32 #include <dirent.h>
33 #include <strings.h>
34 #include <errno.h>
35 #include <assert.h>
36 
37 #include "common.h"
41 
48 void *handleLibList[100];
52 
60  st_static_loader->BOSA_CreateComponent = &BOSA_ST_CreateComponent;
65 
66 }
67 
76  FILE* omxregistryfp;
77  char* line = NULL;
78  char *libname;
79  int num_of_comp=0;
80  stLoaderComponentType** templateList;
81  stLoaderComponentType** stComponentsTemp;
82  void* handle;
83  int (*fptr)(stLoaderComponentType **stComponents);
84  int i;
85  int listindex;
86  char *registry_filename;
87  int index_readline = 0;
88 
89  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
90 
91  registry_filename = componentsRegistryGetFilenameCheck(1);
92  omxregistryfp = fopen(registry_filename, "r");
93  if (omxregistryfp == NULL){
94  DEBUG(DEB_LEV_ERR, "Cannot open OpenMAX registry file %s\n", registry_filename);
95  return ENOENT;
96  }
97  free(registry_filename);
98  libname = malloc(OMX_MAX_STRINGNAME_SIZE * 2);
99 
100  templateList = malloc(sizeof (stLoaderComponentType*));
101  templateList[0] = NULL;
102  line = malloc(MAX_LINE_LENGTH);
103  fseek(omxregistryfp, 0, 0);
104  listindex = 0;
105 
106  while(1) {
107  index_readline = 0;
108  while(index_readline+1 < MAX_LINE_LENGTH) {
109  int c1;
110  c1 = fgetc(omxregistryfp);
111  if (c1 == EOF) break;
112  *(line+index_readline) = c1;
113  if ((*(line+index_readline) == '\n') || (*(line+index_readline) == '\0')) {
114  break;
115  }
116  index_readline++;
117  }
118  *(line+index_readline) = '\0';
119  if ((index_readline >= MAX_LINE_LENGTH) || (index_readline == 0)) {
120  break;
121  }
122  if ((*line == ' ') && (*(line+1) == '=')) {
123  // not a library line. skip
124  continue;
125  }
126  strcpy(libname, line);
127  DEBUG(DEB_LEV_FULL_SEQ, "libname: >%s<\n",libname);
128  if((handle = dlopen(libname, RTLD_NOW)) == NULL) {
129  DEBUG(DEB_LEV_ERR, "could not load %s: %s\n", libname, dlerror());
130  } else {
132  numLib++;
133  if ((fptr = dlsym(handle, "omx_component_library_Setup")) == NULL) {
134  DEBUG(DEB_LEV_ERR, "the library %s is not compatible with ST static component loader - %s\n", libname, dlerror());
135  } else {
136  num_of_comp = (int)(*fptr)(NULL);
137  templateList = realloc(templateList, (listindex + num_of_comp + 1) * sizeof (stLoaderComponentType*));
138  templateList[listindex + num_of_comp] = NULL;
139  stComponentsTemp = calloc(num_of_comp,sizeof(stLoaderComponentType*));
140  for (i = 0; i<num_of_comp; i++) {
141  stComponentsTemp[i] = calloc(1,sizeof(stLoaderComponentType));
142  }
143  (*fptr)(stComponentsTemp);
144  for (i = 0; i<num_of_comp; i++) {
145  templateList[listindex + i] = stComponentsTemp[i];
146  DEBUG(DEB_LEV_FULL_SEQ, "In %s comp name[%d]=%s\n",__func__,listindex + i,templateList[listindex + i]->name);
147  }
148  free(stComponentsTemp);
149  stComponentsTemp = NULL;
150  listindex+= i;
151  }
152  }
153  }
154  if(line) {
155  free(line);
156  line = NULL;
157  }
158  free(libname);
159  libname = NULL;
160  fclose(omxregistryfp);
161  loader->loaderPrivate = templateList;
162 
163  RM_Init();
164 
165  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
166  return OMX_ErrorNone;
167 }
168 
174  unsigned int i, j;
175  int err;
176  stLoaderComponentType** templateList;
177  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
178  templateList = (stLoaderComponentType**)loader->loaderPrivate;
179 
180  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
181 
182  i = 0;
183  while(templateList[i]) {
184  if(templateList[i]->name_requested){
185  free(templateList[i]->name_requested);
186  templateList[i]->name_requested=NULL;
187  }
188 
189  for(j = 0 ; j < templateList[i]->name_specific_length; j++){
190  if(templateList[i]->name_specific[j]) {
191  free(templateList[i]->name_specific[j]);
192  templateList[i]->name_specific[j]=NULL;
193  }
194  if(templateList[i]->role_specific[j]){
195  free(templateList[i]->role_specific[j]);
196  templateList[i]->role_specific[j]=NULL;
197  }
198  }
199 
200  if(templateList[i]->name_specific){
201  free(templateList[i]->name_specific);
202  templateList[i]->name_specific=NULL;
203  }
204  if(templateList[i]->role_specific){
205  free(templateList[i]->role_specific);
206  templateList[i]->role_specific=NULL;
207  }
208  if(templateList[i]->name){
209  free(templateList[i]->name);
210  templateList[i]->name=NULL;
211  }
212  free(templateList[i]);
213  templateList[i] = NULL;
214  i++;
215  }
216  if(templateList) {
217  free(templateList);
218  templateList=NULL;
219  }
220 
221  for(i=0;i<numLib;i++) {
222  err = dlclose(handleLibList[i]);
223  if(err!=0) {
224  DEBUG(DEB_LEV_ERR, "In %s Error %d in dlclose of lib %i\n", __func__,err,i);
225  }
226  }
227  numLib=0;
228 
229  RM_Deinit();
230 
231  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
232  return OMX_ErrorNone;
233 }
234 
243  BOSA_COMPONENTLOADER *loader,
244  OMX_HANDLETYPE* pHandle,
245  OMX_STRING cComponentName,
246  OMX_PTR pAppData,
247  OMX_CALLBACKTYPE* pCallBacks) {
248 
249  int i;
250  unsigned int j;
251  int componentPosition = -1;
252  OMX_ERRORTYPE eError = OMX_ErrorNone;
253  stLoaderComponentType** templateList;
254  OMX_COMPONENTTYPE *openmaxStandComp;
256 
257  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
258  templateList = (stLoaderComponentType**)loader->loaderPrivate;
259  i = 0;
260  while(templateList[i]) {
261  if(!strcmp(templateList[i]->name, cComponentName)) {
262  //given component name matches with the general component names
263  componentPosition = i;
264  break;
265  } else {
266  for(j=0;j<templateList[i]->name_specific_length;j++) {
267  if(!strcmp(templateList[i]->name_specific[j], cComponentName)) {
268  //given component name matches with specific component names
269  componentPosition = i;
270  break;
271  }
272  }
273  if(componentPosition != -1) {
274  break;
275  }
276  }
277  i++;
278  }
279  if (componentPosition == -1) {
280  DEBUG(DEB_LEV_ERR, "Component not found with current ST static component loader.\n");
282  }
283 
284  //component name matches with general component name field
285  DEBUG(DEB_LEV_PARAMS, "Found base requested template %s\n", cComponentName);
286  /* Build ST component from template and fill fields */
287  if (templateList[componentPosition]->name_requested == NULL)
288  { /* This check is to prevent memory leak in case two instances of the same component are loaded */
289  templateList[componentPosition]->name_requested = strndup (cComponentName, OMX_MAX_STRINGNAME_SIZE);
290  }
291 
292  openmaxStandComp = calloc(1,sizeof(OMX_COMPONENTTYPE));
293  if (!openmaxStandComp) {
295  }
296  eError = templateList[componentPosition]->constructor(openmaxStandComp,cComponentName);
297  if (eError != OMX_ErrorNone) {
298  if (eError == OMX_ErrorInsufficientResources) {
299  *pHandle = openmaxStandComp;
300  priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
301  priv->loader = loader;
303  }
304  DEBUG(DEB_LEV_ERR, "Error during component construction\n");
305  openmaxStandComp->ComponentDeInit(openmaxStandComp);
306  free(openmaxStandComp);
307  openmaxStandComp = NULL;
309  }
310  priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
311  priv->loader = loader;
312 
313  *pHandle = openmaxStandComp;
314  ((OMX_COMPONENTTYPE*)*pHandle)->SetCallbacks(*pHandle, pCallBacks, pAppData);
315 
316  DEBUG(DEB_LEV_FULL_SEQ, "Template %s found returning from OMX_GetHandle\n", cComponentName);
317  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
318  return OMX_ErrorNone;
319 }
320 
322  BOSA_COMPONENTLOADER *loader,
323  OMX_HANDLETYPE hComponent) {
325  omx_base_component_PrivateType * priv = (omx_base_component_PrivateType *) ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
326 
327  /* check if this component was actually loaded from this loader */
328  if (priv->loader != loader) {
330  }
331 
332  err = ((OMX_COMPONENTTYPE*)hComponent)->ComponentDeInit(hComponent);
333 
334  free((OMX_COMPONENTTYPE*)hComponent);
335  hComponent = NULL;
336 
337  return err;
338 }
339 
346  BOSA_COMPONENTLOADER *loader,
347  OMX_STRING cComponentName,
348  OMX_U32 nNameLength,
349  OMX_U32 nIndex) {
350 
351  stLoaderComponentType** templateList;
352  int i;
353  unsigned int j, index = 0;
354  int found = 0;
355  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
356 
357  templateList = (stLoaderComponentType**)loader->loaderPrivate;
358  i = 0;
359  while(templateList[i]) {
360  if (index == nIndex) {
361  strncpy(cComponentName, templateList[i]->name, nNameLength);
362  found = 1;
363  break;
364  }
365  index++;
366  if (templateList[i]->name_specific_length > 0) {
367  for (j = 0; j<templateList[i]->name_specific_length; j++) {
368  if (index == nIndex) {
369  strncpy(cComponentName,templateList[i]->name_specific[j], nNameLength);
370  found = 1;
371  break;
372  }
373  index++;
374  }
375  }
376  if (found) {
377  break;
378  }
379  i++;
380  }
381  if (!found) {
382  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s with OMX_ErrorNoMore\n", __func__);
383  return OMX_ErrorNoMore;
384  }
385  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
386  return OMX_ErrorNone;
387 }
388 
396  BOSA_COMPONENTLOADER *loader,
397  OMX_STRING compName,
398  OMX_U32 *pNumRoles,
399  OMX_U8 **roles) {
400 
401  stLoaderComponentType** templateList;
402  int i;
403  unsigned int j, index;
404  unsigned int max_roles = *pNumRoles;
405  int found = 0;
406  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
407  templateList = (stLoaderComponentType**)loader->loaderPrivate;
408  *pNumRoles = 0;
409  i = 0;
410  while (templateList[i]) {
411  if(!strcmp(templateList[i]->name, compName)) {
412  DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested template %s IN GENERAL COMPONENT\n", compName);
413  // set the no of roles field
414  *pNumRoles = templateList[i]->name_specific_length;
415  if(roles == NULL) {
416  return OMX_ErrorNone;
417  }
418  //append the roles
419  for (index = 0; index < templateList[i]->name_specific_length; index++) {
420  if (index < max_roles) {
421  strcpy ((char*)*(roles+index), templateList[i]->role_specific[index]);
422  }
423  }
424  found = 1;
425  } else {
426  for(j=0;j<templateList[i]->name_specific_length;j++) {
427  if(!strcmp(templateList[i]-> name_specific[j], compName)) {
428  DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested component %s IN SPECIFIC COMPONENT \n", compName);
429  *pNumRoles = 1;
430  found = 1;
431  if(roles == NULL) {
432  return OMX_ErrorNone;
433  }
434  if (max_roles > 0) {
435  strcpy ((char*)*roles , templateList[i]->role_specific[j]);
436  }
437  }
438  }
439  }
440  i++;
441  if(found) {
442  break;
443  }
444  }
445  if(!found) {
446  DEBUG(DEB_LEV_ERR, "no component match in whole template list has been found\n");
447  *pNumRoles = 0;
449  }
450  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
451  return OMX_ErrorNone;
452 }
453 
461  BOSA_COMPONENTLOADER *loader,
462  OMX_STRING role,
463  OMX_U32 *pNumComps,
464  OMX_U8 **compNames) {
465 
466  stLoaderComponentType** templateList;
467  int i = 0;
468  unsigned int j = 0;
469  int num_comp = 0;
470  int max_entries = *pNumComps;
471 
472  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
473  templateList = (stLoaderComponentType**)loader->loaderPrivate;
474  i = 0;
475  while(templateList[i]) {
476  for (j = 0; j<templateList[i]->name_specific_length; j++) {
477  if (!strcmp(templateList[i]->role_specific[j], role)) {
478  if (compNames != NULL) {
479  if (num_comp < max_entries) {
480  strcpy((char*)(compNames[num_comp]), templateList[i]->name);
481  }
482  }
483  num_comp++;
484  }
485  }
486  i++;
487  }
488 
489  *pNumComps = num_comp;
490  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
491  return OMX_ErrorNone;
492 }
OMX_COMPONENTTYPE::pComponentPrivate
OMX_PTR pComponentPrivate
Definition: OMX_Component.h:326
BOSA_ST_GetRolesOfComponent
OMX_ERRORTYPE BOSA_ST_GetRolesOfComponent(BOSA_COMPONENTLOADER *loader, OMX_STRING compName, OMX_U32 *pNumRoles, OMX_U8 **roles)
The specific version of OMX_GetRolesOfComponent.
Definition: st_static_component_loader.c:395
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
stLoaderComponentType::name_specific
char ** name_specific
Definition: st_static_component_loader.h:43
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
stLoaderComponentType::name
char * name
Definition: st_static_component_loader.h:41
omx_base_component_PrivateType
Definition: omx_base_component.h:124
OMX_ERRORTYPE
OMX_ERRORTYPE
Definition: OMX_Core.h:127
stLoaderComponentType::role_specific
char ** role_specific
Definition: st_static_component_loader.h:44
BOSA_ST_CreateComponent
OMX_ERRORTYPE BOSA_ST_CreateComponent(BOSA_COMPONENTLOADER *loader, OMX_HANDLETYPE *pHandle, OMX_STRING cComponentName, OMX_PTR pAppData, OMX_CALLBACKTYPE *pCallBacks)
creator of the requested OpenMAX component
Definition: st_static_component_loader.c:242
OMX_U32
unsigned long OMX_U32
Definition: OMX_Types.h:145
BOSA_ST_ComponentNameEnum
OMX_ERRORTYPE BOSA_ST_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: st_static_component_loader.c:345
BOSA_COMPONENTLOADER::loaderPrivate
void * loaderPrivate
The reference to the current component loader private data.
Definition: component_loader.h:219
BOSA_ST_DestroyComponent
OMX_ERRORTYPE BOSA_ST_DestroyComponent(BOSA_COMPONENTLOADER *loader, OMX_HANDLETYPE hComponent)
destructor of the requested OpenMAX component
Definition: st_static_component_loader.c:321
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_ST_InitComponentLoader
OMX_ERRORTYPE BOSA_ST_InitComponentLoader(BOSA_COMPONENTLOADER *loader)
the ST static loader constructor
Definition: st_static_component_loader.c:75
handleLibList
void * handleLibList[100]
Definition: st_static_component_loader.c:48
OMX_CALLBACKTYPE
Definition: OMX_Core.h:498
DEB_LEV_ERR
#define DEB_LEV_ERR
Definition: omx_comp_debug_levels.h:39
numLib
OMX_U32 numLib
Definition: st_static_component_loader.c:51
RM_Init
OMX_ERRORTYPE RM_Init()
Definition: omx_reference_resource_manager.c:47
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
st_static_component_loader.h
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
DEB_LEV_SIMPLE_SEQ
#define DEB_LEV_SIMPLE_SEQ
Definition: omx_comp_debug_levels.h:48
st_static_setup_component_loader
void st_static_setup_component_loader(BOSA_COMPONENTLOADER *st_static_loader)
The initialization of the ST specific component loader.
Definition: st_static_component_loader.c:57
omx_base_component.h
MAX_LINE_LENGTH
#define MAX_LINE_LENGTH
Definition: common.h:30
OMX_PTR
void * OMX_PTR
Definition: OMX_Types.h:199
BOSA_ST_GetComponentsOfRole
OMX_ERRORTYPE BOSA_ST_GetComponentsOfRole(BOSA_COMPONENTLOADER *loader, OMX_STRING role, OMX_U32 *pNumComps, OMX_U8 **compNames)
The specific version of OMX_GetComponentsOfRole.
Definition: st_static_component_loader.c:460
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
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
stLoaderComponentType::name_requested
char * name_requested
Definition: st_static_component_loader.h:45
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
BOSA_ST_DeInitComponentLoader
OMX_ERRORTYPE BOSA_ST_DeInitComponentLoader(BOSA_COMPONENTLOADER *loader)
The destructor of the ST specific component loader.
Definition: st_static_component_loader.c:173
err
OMX_ERRORTYPE err
Definition: omxvolcontroltest.c:34
common.h
OMX_STRING
char * OMX_STRING
Definition: OMX_Types.h:206
omx_base_component_PrivateType::loader
void * loader
Definition: omx_base_component.h:160
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
OMX_U8
unsigned char OMX_U8
Definition: OMX_Types.h:133
stLoaderComponentType::name_specific_length
unsigned int name_specific_length
Definition: st_static_component_loader.h:42
componentsRegistryGetFilenameCheck
char * componentsRegistryGetFilenameCheck(int check_exists)
Definition: common.c:51
RM_Deinit
OMX_ERRORTYPE RM_Deinit()
Definition: omx_reference_resource_manager.c:98
stLoaderComponentType::constructor
OMX_ERRORTYPE(* constructor)(OMX_COMPONENTTYPE *, OMX_STRING cComponentName)
Definition: st_static_component_loader.h:46
BOSA_COMPONENTLOADER
Component loader entry points.
Definition: component_loader.h:39
stLoaderComponentType
the private data structure handled by the ST static loader that described an OpenMAX component
Definition: st_static_component_loader.h:39
DEB_LEV_PARAMS
#define DEB_LEV_PARAMS
Definition: omx_comp_debug_levels.h:43

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