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