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 }

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