00001
00029 #define _GNU_SOURCE
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <dlfcn.h>
00034 #include <sys/types.h>
00035 #include <dirent.h>
00036 #include <strings.h>
00037 #include <errno.h>
00038 #include <assert.h>
00039
00040 #include "common.h"
00041 #include "st_static_component_loader.h"
00042 #include "omx_base_component.h"
00043
00050 void *handleLibList[100];
00053 OMX_U32 numLib=0;
00054
00059 void st_static_InitComponentLoader() {
00060
00061 st_static_loader = (BOSA_COMPONENTLOADER *) calloc(1, sizeof(BOSA_COMPONENTLOADER));
00062 assert(st_static_loader);
00063
00064 st_static_loader->BOSA_InitComponentLoader = &BOSA_ST_InitComponentLoader;
00065 st_static_loader->BOSA_DeInitComponentLoader = &BOSA_ST_DeInitComponentLoader;
00066 st_static_loader->BOSA_CreateComponent = &BOSA_ST_CreateComponent;
00067 st_static_loader->BOSA_DestroyComponent = &BOSA_ST_DestroyComponent;
00068 st_static_loader->BOSA_ComponentNameEnum = &BOSA_ST_ComponentNameEnum;
00069 st_static_loader->BOSA_GetRolesOfComponent = &BOSA_ST_GetRolesOfComponent;
00070 st_static_loader->BOSA_GetComponentsOfRole = &BOSA_ST_GetComponentsOfRole;
00071 }
00072
00080 OMX_ERRORTYPE BOSA_ST_InitComponentLoader(BOSA_COMPONENTLOADER *loader) {
00081 FILE* omxregistryfp;
00082 char* line = NULL;
00083 char *libname;
00084 int num_of_comp=0;
00085 int read;
00086 stLoaderComponentType** templateList;
00087 stLoaderComponentType** stComponentsTemp;
00088 void* handle;
00089 size_t len;
00090 int (*fptr)(stLoaderComponentType **stComponents);
00091 int i;
00092 int index;
00093 int listindex;
00094 char *registry_filename;
00095
00096 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00097
00098 registry_filename = registryGetFilename();
00099 omxregistryfp = fopen(registry_filename, "r");
00100 if (omxregistryfp == NULL){
00101 DEBUG(DEB_LEV_ERR, "Cannot open OpenMAX registry file%s\n", registry_filename);
00102 return ENOENT;
00103 }
00104 free(registry_filename);
00105 libname = malloc(OMX_MAX_STRINGNAME_SIZE * 2);
00106
00107 templateList = calloc(1,sizeof (stLoaderComponentType*));
00108 templateList[0] = NULL;
00109
00110 fseek(omxregistryfp, 0, 0);
00111 listindex = 0;
00112 while((read = getline(&line, &len, omxregistryfp)) != -1) {
00113 if ((*line == ' ') && (*(line+1) == '=')) {
00114
00115 continue;
00116 }
00117 index = 0;
00118 while (*(line+index)!= '\n') index++;
00119 *(line+index) = 0;
00120 strcpy(libname, line);
00121 DEBUG(DEB_LEV_FULL_SEQ, "libname: %s\n",libname);
00122 if((handle = dlopen(libname, RTLD_NOW)) == NULL) {
00123 DEBUG(DEB_LEV_ERR, "could not load %s: %s\n", libname, dlerror());
00124 } else {
00125 handleLibList[numLib]=handle;
00126 numLib++;
00127 if ((fptr = dlsym(handle, "omx_component_library_Setup")) == NULL) {
00128 DEBUG(DEB_LEV_ERR, "the library %s is not compatible with ST static component loader - %s\n", libname, dlerror());
00129 } else {
00130 num_of_comp = (int)(*fptr)(NULL);
00131 templateList = realloc(templateList, (listindex + num_of_comp + 1) * sizeof (stLoaderComponentType*));
00132 templateList[listindex + num_of_comp] = NULL;
00133 stComponentsTemp = calloc(num_of_comp,sizeof(stLoaderComponentType*));
00134 for (i = 0; i<num_of_comp; i++) {
00135 stComponentsTemp[i] = calloc(1,sizeof(stLoaderComponentType));
00136 }
00137 (*fptr)(stComponentsTemp);
00138 for (i = 0; i<num_of_comp; i++) {
00139 templateList[listindex + i] = stComponentsTemp[i];
00140 DEBUG(DEB_LEV_FULL_SEQ, "In %s comp name[%d]=%s\n",__func__,listindex + i,templateList[listindex + i]->name);
00141 }
00142 free(stComponentsTemp);
00143 stComponentsTemp = NULL;
00144 listindex+= i;
00145 }
00146 }
00147 }
00148 if(line) {
00149 free(line);
00150 line = NULL;
00151 }
00152 free(libname);
00153 libname = NULL;
00154 fclose(omxregistryfp);
00155 loader->loaderPrivate = templateList;
00156 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00157 return OMX_ErrorNone;
00158 }
00159
00164 OMX_ERRORTYPE BOSA_ST_DeInitComponentLoader(BOSA_COMPONENTLOADER *loader) {
00165 unsigned int i, j;
00166 int err;
00167 stLoaderComponentType** templateList;
00168 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00169 templateList = (stLoaderComponentType**)loader->loaderPrivate;
00170
00171 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00172
00173 i = 0;
00174 while(templateList[i]) {
00175 if(templateList[i]->name_requested){
00176 free(templateList[i]->name_requested);
00177 templateList[i]->name_requested=NULL;
00178 }
00179
00180 for(j = 0 ; j < templateList[i]->name_specific_length; j++){
00181 if(templateList[i]->name_specific[j]) {
00182 free(templateList[i]->name_specific[j]);
00183 templateList[i]->name_specific[j]=NULL;
00184 }
00185 if(templateList[i]->role_specific[j]){
00186 free(templateList[i]->role_specific[j]);
00187 templateList[i]->role_specific[j]=NULL;
00188 }
00189 }
00190
00191 if(templateList[i]->name_specific){
00192 free(templateList[i]->name_specific);
00193 templateList[i]->name_specific=NULL;
00194 }
00195 if(templateList[i]->role_specific){
00196 free(templateList[i]->role_specific);
00197 templateList[i]->role_specific=NULL;
00198 }
00199 if(templateList[i]->name){
00200 free(templateList[i]->name);
00201 templateList[i]->name=NULL;
00202 }
00203 free(templateList[i]);
00204 templateList[i] = NULL;
00205 i++;
00206 }
00207 if(templateList) {
00208 free(templateList);
00209 templateList=NULL;
00210 }
00211
00212 for(i=0;i<numLib;i++) {
00213 err = dlclose(handleLibList[i]);
00214 if(err!=0) {
00215 DEBUG(DEB_LEV_ERR, "In %s Error %d in dlclose of lib %i\n", __func__,err,i);
00216 }
00217 }
00218 numLib=0;
00219
00220 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00221 return OMX_ErrorNone;
00222 }
00223
00231 OMX_ERRORTYPE BOSA_ST_CreateComponent(
00232 BOSA_COMPONENTLOADER *loader,
00233 OMX_HANDLETYPE* pHandle,
00234 OMX_STRING cComponentName,
00235 OMX_PTR pAppData,
00236 OMX_CALLBACKTYPE* pCallBacks) {
00237
00238 int i;
00239 unsigned int j;
00240 int componentPosition = -1;
00241 OMX_ERRORTYPE eError = OMX_ErrorNone;
00242 stLoaderComponentType** templateList;
00243 OMX_COMPONENTTYPE *openmaxStandComp;
00244 omx_base_component_PrivateType * priv;
00245
00246 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00247 templateList = (stLoaderComponentType**)loader->loaderPrivate;
00248 i = 0;
00249 while(templateList[i]) {
00250 if(!strcmp(templateList[i]->name, cComponentName)) {
00251
00252 componentPosition = i;
00253 break;
00254 } else {
00255 for(j=0;j<templateList[i]->name_specific_length;j++) {
00256 if(!strcmp(templateList[i]->name_specific[j], cComponentName)) {
00257
00258 componentPosition = i;
00259 break;
00260 }
00261 }
00262 if(componentPosition != -1) {
00263 break;
00264 }
00265 }
00266 i++;
00267 }
00268 if (componentPosition == -1) {
00269 DEBUG(DEB_LEV_ERR, "Component not found with current ST static component loader.\n");
00270 return OMX_ErrorComponentNotFound;
00271 }
00272
00273
00274 DEBUG(DEB_LEV_PARAMS, "Found base requested template %s\n", cComponentName);
00275
00276 templateList[componentPosition]->name_requested = strndup (cComponentName, OMX_MAX_STRINGNAME_SIZE);
00277
00278 openmaxStandComp = calloc(1,sizeof(OMX_COMPONENTTYPE));
00279 if (!openmaxStandComp) {
00280 return OMX_ErrorInsufficientResources;
00281 }
00282 eError = templateList[componentPosition]->constructor(openmaxStandComp,cComponentName);
00283 if (eError != OMX_ErrorNone) {
00284 if (eError == OMX_ErrorInsufficientResources) {
00285 *pHandle = openmaxStandComp;
00286 priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
00287 priv->loader = loader;
00288 return OMX_ErrorInsufficientResources;
00289 }
00290 DEBUG(DEB_LEV_ERR, "Error during component construction\n");
00291 openmaxStandComp->ComponentDeInit(openmaxStandComp);
00292 free(openmaxStandComp);
00293 openmaxStandComp = NULL;
00294 return OMX_ErrorComponentNotFound;
00295 }
00296 priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
00297 priv->loader = loader;
00298
00299 *pHandle = openmaxStandComp;
00300 ((OMX_COMPONENTTYPE*)*pHandle)->SetCallbacks(*pHandle, pCallBacks, pAppData);
00301 DEBUG(DEB_LEV_FULL_SEQ, "Template %s found returning from OMX_GetHandle\n", cComponentName);
00302 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00303 return eError;
00304 }
00305
00306 OMX_ERRORTYPE BOSA_ST_DestroyComponent(
00307 BOSA_COMPONENTLOADER *loader,
00308 OMX_HANDLETYPE hComponent) {
00309 OMX_ERRORTYPE err = OMX_ErrorNone;
00310 omx_base_component_PrivateType * priv = (omx_base_component_PrivateType *) ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
00311
00312
00313 if (priv->loader != loader) {
00314 return OMX_ErrorComponentNotFound;
00315 }
00316
00317 err = ((OMX_COMPONENTTYPE*)hComponent)->ComponentDeInit(hComponent);
00318
00319 free((OMX_COMPONENTTYPE*)hComponent);
00320 hComponent = NULL;
00321
00322 return err;
00323 }
00324
00330 OMX_ERRORTYPE BOSA_ST_ComponentNameEnum(
00331 BOSA_COMPONENTLOADER *loader,
00332 OMX_STRING cComponentName,
00333 OMX_U32 nNameLength,
00334 OMX_U32 nIndex) {
00335
00336 stLoaderComponentType** templateList;
00337 int i;
00338 unsigned int j, index = 0;
00339 int found = 0;
00340 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00341
00342 templateList = (stLoaderComponentType**)loader->loaderPrivate;
00343 i = 0;
00344 while(templateList[i]) {
00345 if (index == nIndex) {
00346 strncpy(cComponentName, templateList[i]->name, nNameLength);
00347 found = 1;
00348 break;
00349 }
00350 index++;
00351 if (templateList[i]->name_specific_length > 1) {
00352 for (j = 0; j<templateList[i]->name_specific_length; j++) {
00353 if (index == nIndex) {
00354 strncpy(cComponentName,templateList[i]->name_specific[j], nNameLength);
00355 found = 1;
00356 break;
00357 }
00358 index++;
00359 }
00360 }
00361 if (found) {
00362 break;
00363 }
00364 i++;
00365 }
00366 if (!found) {
00367 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s with OMX_ErrorNoMore\n", __func__);
00368 return OMX_ErrorNoMore;
00369 }
00370 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00371 return OMX_ErrorNone;
00372 }
00373
00380 OMX_ERRORTYPE BOSA_ST_GetRolesOfComponent(
00381 BOSA_COMPONENTLOADER *loader,
00382 OMX_STRING compName,
00383 OMX_U32 *pNumRoles,
00384 OMX_U8 **roles) {
00385
00386 stLoaderComponentType** templateList;
00387 int i;
00388 unsigned int j, index;
00389 unsigned int max_roles = *pNumRoles;
00390 int found = 0;
00391 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00392 templateList = (stLoaderComponentType**)loader->loaderPrivate;
00393 *pNumRoles = 0;
00394 i = 0;
00395 while (templateList[i]) {
00396 if(!strcmp(templateList[i]->name, compName)) {
00397 DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested template %s IN GENERAL COMPONENT\n", compName);
00398
00399 *pNumRoles = templateList[i]->name_specific_length;
00400 if(roles == NULL) {
00401 return OMX_ErrorNone;
00402 }
00403
00404 for (index = 0; index < templateList[i]->name_specific_length; index++) {
00405 if (index < max_roles) {
00406 strcpy ((char*)*(roles+index), templateList[i]->role_specific[index]);
00407 }
00408 }
00409 found = 1;
00410 } else {
00411 for(j=0;j<templateList[i]->name_specific_length;j++) {
00412 if(!strcmp(templateList[i]-> name_specific[j], compName)) {
00413 DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested component %s IN SPECIFIC COMPONENT \n", compName);
00414 *pNumRoles = 1;
00415 found = 1;
00416 if(roles == NULL) {
00417 return OMX_ErrorNone;
00418 }
00419 if (max_roles > 0) {
00420 strcpy ((char*)*roles , templateList[i]->role_specific[j]);
00421 }
00422 }
00423 }
00424 }
00425 i++;
00426 if(found) {
00427 break;
00428 }
00429 }
00430 if(!found) {
00431 DEBUG(DEB_LEV_ERR, "no component match in whole template list has been found\n");
00432 *pNumRoles = 0;
00433 return OMX_ErrorComponentNotFound;
00434 }
00435 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00436 return OMX_ErrorNone;
00437 }
00438
00445 OMX_ERRORTYPE BOSA_ST_GetComponentsOfRole (
00446 BOSA_COMPONENTLOADER *loader,
00447 OMX_STRING role,
00448 OMX_U32 *pNumComps,
00449 OMX_U8 **compNames) {
00450
00451 stLoaderComponentType** templateList;
00452 int i = 0;
00453 unsigned int j = 0;
00454 int num_comp = 0;
00455 int max_entries = *pNumComps;
00456
00457 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00458 templateList = (stLoaderComponentType**)loader->loaderPrivate;
00459 i = 0;
00460 while(templateList[i]) {
00461 for (j = 0; j<templateList[i]->name_specific_length; j++) {
00462 if (!strcmp(templateList[i]->role_specific[j], role)) {
00463 if (compNames != NULL) {
00464 if (num_comp < max_entries) {
00465 strcpy((char*)(compNames[num_comp]), templateList[i]->name);
00466 }
00467 }
00468 num_comp++;
00469 }
00470 }
00471 i++;
00472 }
00473
00474 *pNumComps = num_comp;
00475 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00476 return OMX_ErrorNone;
00477 }