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 = componentsRegistryGetFilename();
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 < MAX_LINE_LENGTH) {
109  *(line+index_readline) = fgetc(omxregistryfp);
110  if ((*(line+index_readline) == '\n') || (*(line+index_readline) == '\0')) {
111  break;
112  }
113  index_readline++;
114  }
115  *(line+index_readline) = '\0';
116  if ((index_readline >= MAX_LINE_LENGTH) || (index_readline == 0)) {
117  break;
118  }
119  if ((*line == ' ') && (*(line+1) == '=')) {
120  // not a library line. skip
121  continue;
122  }
123  strcpy(libname, line);
124  DEBUG(DEB_LEV_FULL_SEQ, "libname: >%s<\n",libname);
125  if((handle = dlopen(libname, RTLD_NOW)) == NULL) {
126  DEBUG(DEB_LEV_ERR, "could not load %s: %s\n", libname, dlerror());
127  } else {
129  numLib++;
130  if ((fptr = dlsym(handle, "omx_component_library_Setup")) == NULL) {
131  DEBUG(DEB_LEV_ERR, "the library %s is not compatible with ST static component loader - %s\n", libname, dlerror());
132  } else {
133  num_of_comp = (int)(*fptr)(NULL);
134  templateList = realloc(templateList, (listindex + num_of_comp + 1) * sizeof (stLoaderComponentType*));
135  templateList[listindex + num_of_comp] = NULL;
136  stComponentsTemp = calloc(num_of_comp,sizeof(stLoaderComponentType*));
137  for (i = 0; i<num_of_comp; i++) {
138  stComponentsTemp[i] = calloc(1,sizeof(stLoaderComponentType));
139  }
140  (*fptr)(stComponentsTemp);
141  for (i = 0; i<num_of_comp; i++) {
142  templateList[listindex + i] = stComponentsTemp[i];
143  DEBUG(DEB_LEV_FULL_SEQ, "In %s comp name[%d]=%s\n",__func__,listindex + i,templateList[listindex + i]->name);
144  }
145  free(stComponentsTemp);
146  stComponentsTemp = NULL;
147  listindex+= i;
148  }
149  }
150  }
151  if(line) {
152  free(line);
153  line = NULL;
154  }
155  free(libname);
156  libname = NULL;
157  fclose(omxregistryfp);
158  loader->loaderPrivate = templateList;
159 
160  RM_Init();
161 
162  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
163  return OMX_ErrorNone;
164 }
165 
171  unsigned int i, j;
172  int err;
173  stLoaderComponentType** templateList;
174  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
175  templateList = (stLoaderComponentType**)loader->loaderPrivate;
176 
177  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
178 
179  i = 0;
180  while(templateList[i]) {
181  if(templateList[i]->name_requested){
182  free(templateList[i]->name_requested);
183  templateList[i]->name_requested=NULL;
184  }
185 
186  for(j = 0 ; j < templateList[i]->name_specific_length; j++){
187  if(templateList[i]->name_specific[j]) {
188  free(templateList[i]->name_specific[j]);
189  templateList[i]->name_specific[j]=NULL;
190  }
191  if(templateList[i]->role_specific[j]){
192  free(templateList[i]->role_specific[j]);
193  templateList[i]->role_specific[j]=NULL;
194  }
195  }
196 
197  if(templateList[i]->name_specific){
198  free(templateList[i]->name_specific);
199  templateList[i]->name_specific=NULL;
200  }
201  if(templateList[i]->role_specific){
202  free(templateList[i]->role_specific);
203  templateList[i]->role_specific=NULL;
204  }
205  if(templateList[i]->name){
206  free(templateList[i]->name);
207  templateList[i]->name=NULL;
208  }
209  free(templateList[i]);
210  templateList[i] = NULL;
211  i++;
212  }
213  if(templateList) {
214  free(templateList);
215  templateList=NULL;
216  }
217 
218  for(i=0;i<numLib;i++) {
219  err = dlclose(handleLibList[i]);
220  if(err!=0) {
221  DEBUG(DEB_LEV_ERR, "In %s Error %d in dlclose of lib %i\n", __func__,err,i);
222  }
223  }
224  numLib=0;
225 
226  RM_Deinit();
227 
228  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
229  return OMX_ErrorNone;
230 }
231 
240  BOSA_COMPONENTLOADER *loader,
241  OMX_HANDLETYPE* pHandle,
242  OMX_STRING cComponentName,
243  OMX_PTR pAppData,
244  OMX_CALLBACKTYPE* pCallBacks) {
245 
246  int i;
247  unsigned int j;
248  int componentPosition = -1;
249  OMX_ERRORTYPE eError = OMX_ErrorNone;
250  stLoaderComponentType** templateList;
251  OMX_COMPONENTTYPE *openmaxStandComp;
253 
254  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
255  templateList = (stLoaderComponentType**)loader->loaderPrivate;
256  i = 0;
257  while(templateList[i]) {
258  if(!strcmp(templateList[i]->name, cComponentName)) {
259  //given component name matches with the general component names
260  componentPosition = i;
261  break;
262  } else {
263  for(j=0;j<templateList[i]->name_specific_length;j++) {
264  if(!strcmp(templateList[i]->name_specific[j], cComponentName)) {
265  //given component name matches with specific component names
266  componentPosition = i;
267  break;
268  }
269  }
270  if(componentPosition != -1) {
271  break;
272  }
273  }
274  i++;
275  }
276  if (componentPosition == -1) {
277  DEBUG(DEB_LEV_ERR, "Component not found with current ST static component loader.\n");
279  }
280 
281  //component name matches with general component name field
282  DEBUG(DEB_LEV_PARAMS, "Found base requested template %s\n", cComponentName);
283  /* Build ST component from template and fill fields */
284  if (templateList[componentPosition]->name_requested == NULL)
285  { /* This check is to prevent memory leak in case two instances of the same component are loaded */
286  templateList[componentPosition]->name_requested = strndup (cComponentName, OMX_MAX_STRINGNAME_SIZE);
287  }
288 
289  openmaxStandComp = calloc(1,sizeof(OMX_COMPONENTTYPE));
290  if (!openmaxStandComp) {
292  }
293  eError = templateList[componentPosition]->constructor(openmaxStandComp,cComponentName);
294  if (eError != OMX_ErrorNone) {
295  if (eError == OMX_ErrorInsufficientResources) {
296  *pHandle = openmaxStandComp;
297  priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
298  priv->loader = loader;
300  }
301  DEBUG(DEB_LEV_ERR, "Error during component construction\n");
302  openmaxStandComp->ComponentDeInit(openmaxStandComp);
303  free(openmaxStandComp);
304  openmaxStandComp = NULL;
306  }
307  priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
308  priv->loader = loader;
309 
310  *pHandle = openmaxStandComp;
311  ((OMX_COMPONENTTYPE*)*pHandle)->SetCallbacks(*pHandle, pCallBacks, pAppData);
312 
313  DEBUG(DEB_LEV_FULL_SEQ, "Template %s found returning from OMX_GetHandle\n", cComponentName);
314  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
315  return OMX_ErrorNone;
316 }
317 
319  BOSA_COMPONENTLOADER *loader,
320  OMX_HANDLETYPE hComponent) {
322  omx_base_component_PrivateType * priv = (omx_base_component_PrivateType *) ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
323 
324  /* check if this component was actually loaded from this loader */
325  if (priv->loader != loader) {
327  }
328 
329  err = ((OMX_COMPONENTTYPE*)hComponent)->ComponentDeInit(hComponent);
330 
331  free((OMX_COMPONENTTYPE*)hComponent);
332  hComponent = NULL;
333 
334  return err;
335 }
336 
343  BOSA_COMPONENTLOADER *loader,
344  OMX_STRING cComponentName,
345  OMX_U32 nNameLength,
346  OMX_U32 nIndex) {
347 
348  stLoaderComponentType** templateList;
349  int i;
350  unsigned int j, index = 0;
351  int found = 0;
352  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
353 
354  templateList = (stLoaderComponentType**)loader->loaderPrivate;
355  i = 0;
356  while(templateList[i]) {
357  if (index == nIndex) {
358  strncpy(cComponentName, templateList[i]->name, nNameLength);
359  found = 1;
360  break;
361  }
362  index++;
363  if (templateList[i]->name_specific_length > 0) {
364  for (j = 0; j<templateList[i]->name_specific_length; j++) {
365  if (index == nIndex) {
366  strncpy(cComponentName,templateList[i]->name_specific[j], nNameLength);
367  found = 1;
368  break;
369  }
370  index++;
371  }
372  }
373  if (found) {
374  break;
375  }
376  i++;
377  }
378  if (!found) {
379  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s with OMX_ErrorNoMore\n", __func__);
380  return OMX_ErrorNoMore;
381  }
382  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
383  return OMX_ErrorNone;
384 }
385 
393  BOSA_COMPONENTLOADER *loader,
394  OMX_STRING compName,
395  OMX_U32 *pNumRoles,
396  OMX_U8 **roles) {
397 
398  stLoaderComponentType** templateList;
399  int i;
400  unsigned int j, index;
401  unsigned int max_roles = *pNumRoles;
402  int found = 0;
403  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
404  templateList = (stLoaderComponentType**)loader->loaderPrivate;
405  *pNumRoles = 0;
406  i = 0;
407  while (templateList[i]) {
408  if(!strcmp(templateList[i]->name, compName)) {
409  DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested template %s IN GENERAL COMPONENT\n", compName);
410  // set the no of roles field
411  *pNumRoles = templateList[i]->name_specific_length;
412  if(roles == NULL) {
413  return OMX_ErrorNone;
414  }
415  //append the roles
416  for (index = 0; index < templateList[i]->name_specific_length; index++) {
417  if (index < max_roles) {
418  strcpy ((char*)*(roles+index), templateList[i]->role_specific[index]);
419  }
420  }
421  found = 1;
422  } else {
423  for(j=0;j<templateList[i]->name_specific_length;j++) {
424  if(!strcmp(templateList[i]-> name_specific[j], compName)) {
425  DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested component %s IN SPECIFIC COMPONENT \n", compName);
426  *pNumRoles = 1;
427  found = 1;
428  if(roles == NULL) {
429  return OMX_ErrorNone;
430  }
431  if (max_roles > 0) {
432  strcpy ((char*)*roles , templateList[i]->role_specific[j]);
433  }
434  }
435  }
436  }
437  i++;
438  if(found) {
439  break;
440  }
441  }
442  if(!found) {
443  DEBUG(DEB_LEV_ERR, "no component match in whole template list has been found\n");
444  *pNumRoles = 0;
446  }
447  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
448  return OMX_ErrorNone;
449 }
450 
458  BOSA_COMPONENTLOADER *loader,
459  OMX_STRING role,
460  OMX_U32 *pNumComps,
461  OMX_U8 **compNames) {
462 
463  stLoaderComponentType** templateList;
464  int i = 0;
465  unsigned int j = 0;
466  int num_comp = 0;
467  int max_entries = *pNumComps;
468 
469  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
470  templateList = (stLoaderComponentType**)loader->loaderPrivate;
471  i = 0;
472  while(templateList[i]) {
473  for (j = 0; j<templateList[i]->name_specific_length; j++) {
474  if (!strcmp(templateList[i]->role_specific[j], role)) {
475  if (compNames != NULL) {
476  if (num_comp < max_entries) {
477  strcpy((char*)(compNames[num_comp]), templateList[i]->name);
478  }
479  }
480  num_comp++;
481  }
482  }
483  i++;
484  }
485 
486  *pNumComps = num_comp;
487  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
488  return OMX_ErrorNone;
489 }
void * handleLibList[100]
OMX_ERRORTYPE BOSA_ST_GetComponentsOfRole(BOSA_COMPONENTLOADER *loader, OMX_STRING role, OMX_U32 *pNumComps, OMX_U8 **compNames)
The specific version of OMX_GetComponentsOfRole.
void * OMX_HANDLETYPE
Definition: OMX_Types.h:295
#define DEB_LEV_PARAMS
unsigned long OMX_U32
Definition: OMX_Types.h:145
OMX_ERRORTYPE BOSA_ST_DeInitComponentLoader(BOSA_COMPONENTLOADER *loader)
The destructor of the ST specific component loader.
void st_static_setup_component_loader(BOSA_COMPONENTLOADER *st_static_loader)
The initialization of the ST specific component loader.
OMX_ERRORTYPE(* BOSA_DeInitComponentLoader)(struct BOSA_COMPONENTLOADER *loader)
The destructor of the component loader.
#define DEB_LEV_SIMPLE_SEQ
char * componentsRegistryGetFilename()
Get registry filename This function returns the name of the registry file for the components loaded w...
Definition: common.c:46
OMX_HANDLETYPE handle
OMX_ERRORTYPE BOSA_ST_InitComponentLoader(BOSA_COMPONENTLOADER *loader)
the ST static loader constructor
#define DEBUG(n, fmt, args...)
char * OMX_STRING
Definition: OMX_Types.h:206
void * OMX_PTR
Definition: OMX_Types.h:199
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...
Component loader entry points.
#define DEB_LEV_ERR
OMX_ERRORTYPE RM_Init()
void * loaderPrivate
The reference to the current component loader private data.
OMX_ERRORTYPE BOSA_ST_GetRolesOfComponent(BOSA_COMPONENTLOADER *loader, OMX_STRING compName, OMX_U32 *pNumRoles, OMX_U8 **roles)
The specific version of OMX_GetRolesOfComponent.
OMX_ERRORTYPE BOSA_ST_DestroyComponent(BOSA_COMPONENTLOADER *loader, OMX_HANDLETYPE hComponent)
destructor of the requested OpenMAX component
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.
OMX_U32 numLib
OMX_ERRORTYPE(* ComponentDeInit)(OMX_IN OMX_HANDLETYPE hComponent)
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
the private data structure handled by the ST static loader that described an OpenMAX component ...
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...
OMX_ERRORTYPE(* constructor)(OMX_COMPONENTTYPE *, OMX_STRING cComponentName)
#define OMX_MAX_STRINGNAME_SIZE
Definition: OMX_Core.h:281
unsigned char OMX_U8
Definition: OMX_Types.h:133
OMX_ERRORTYPE err
#define DEB_LEV_FULL_SEQ
OMX_ERRORTYPE RM_Deinit()
OMX_PTR pComponentPrivate
#define DEB_LEV_FUNCTION_NAME
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.
OMX_ERRORTYPE(* BOSA_DestroyComponent)(struct BOSA_COMPONENTLOADER *loader, OMX_HANDLETYPE hComponent)
The component destructor of the current component loader.
OMX_ERRORTYPE(* BOSA_InitComponentLoader)(struct BOSA_COMPONENTLOADER *loader)
The constructor of the component loader.
#define MAX_LINE_LENGTH
Definition: common.h:30
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.
OMX_ERRORTYPE
Definition: OMX_Core.h:126

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