50#define DEFAULT_LINE_LENGHT 500
54static const char arrow[] =
" ==> ";
58 if (value<0)
return -1;
68static int showComponentsList(FILE* omxregistryfp) {
70 char* temp_buffer, *temp_rules;
71 char *comp_name, *temp_name, *comp_rules;
75 long int start_pos, end_pos;
79 buffer = malloc(allocation_length+1);
83 checkChar = malloc(2);
85 printf(
"*********************************\n");
86 printf(
"* List of registered components *\n");
87 printf(
"*********************************\n");
90 start_pos = ftell(omxregistryfp);
92 data_read = fread(checkChar, 1, 1, omxregistryfp);
93 }
while ((*checkChar !=
'\n') && (data_read > 0));
94 if (feof(omxregistryfp)) {
97 end_pos = ftell(omxregistryfp);
98 offset = (end_pos - start_pos);
99 fseek(omxregistryfp, start_pos, SEEK_SET);
100 data_read = fread(buffer, offset, 1, omxregistryfp);
101 buffer[offset] =
'\0';
102 if (buffer[0] ==
'/') {
105 temp_buffer = buffer+5;
107 while ((temp_buffer[i] !=
'\0') && (temp_buffer[i] !=
' ')) {
111 strncpy(comp_name, temp_buffer, i);
115 if (*temp_buffer !=
'\0') {
118 while ((temp_buffer[i] !=
'\n') && (temp_buffer[i] !=
' ')) {
121 strncpy(comp_rules, temp_buffer, i);
122 comp_rules[i] =
'\0';
124 comp_rules[0] =
'\0';
126 printf(
"Component %s\n", comp_name);
127 if (comp_rules[0] !=
'\0') {
128 temp_rules = comp_rules;
129 printf(
" supported formats:\n");
131 while (*(temp_rules+i) !=
'\0') {
133 if (*(temp_rules+i) ==
':') {
134 strncpy(temp_name, temp_rules, i);
137 printf(
" %s\n", temp_name);
161static int buildComponentsList(FILE* omxregistryfp,
char *componentspath,
int verbose) {
165 int i, num_of_comp, k, qi;
166 int num_of_libraries = 0;
171 int ncomponents = 0, nroles=0;
172 int pathconsumed = 0;
175 char* currentpath = componentspath;
180 char* qualityString = NULL;
186 qualityString = malloc(4096);
187 buffer = malloc(8192);
188 while (!pathconsumed) {
191 while (!currentgiven) {
192 if (*(currentpath + index) ==
'\0') {
195 if ((*(currentpath + index) ==
':') || (*(currentpath + index) ==
'\0')) {
197 if (*(currentpath + index - 1) !=
'/') {
198 actual = malloc(index + 2);
199 *(actual + index) =
'/';
200 *(actual+index + 1) =
'\0';
202 actual = malloc(index + 1);
203 *(actual+index) =
'\0';
205 strncpy(actual, currentpath, index);
206 currentpath = currentpath + index + 1;
211 dirp = opendir(actual);
213 printf(
"\n Scanning directory %s\n", actual);
220 while((dp = readdir(dirp)) != NULL) {
221 int len = strlen(dp->d_name);
226 if(strncmp(dp->d_name+len-3,
".so", 3) == 0){
227 char lib_absolute_path[strlen(actual) + len + 1];
229 strcpy(lib_absolute_path, actual);
230 strcat(lib_absolute_path, dp->d_name);
232 if((
handle = dlopen(lib_absolute_path, RTLD_NOW)) == NULL) {
233 DEBUG(
DEB_LEV_ERR,
"could not load %s: %s\n", lib_absolute_path, dlerror());
236 printf(
"\n Scanning library %s\n", lib_absolute_path);
238 if ((fptr = dlsym(
handle,
"omx_component_library_Setup")) == NULL) {
239 DEBUG(
DEB_LEV_SIMPLE_SEQ,
"the library %s is not compatible with ST static component loader - %s\n", lib_absolute_path, dlerror());
243 num_of_comp = fptr(NULL);
245 for (i = 0; i<num_of_comp; i++) {
251 fwrite(lib_absolute_path, 1, strlen(lib_absolute_path), omxregistryfp);
252 fwrite(
"\n", 1, 1, omxregistryfp);
255 for (i = 0; i<num_of_comp; i++) {
257 if (tempName != NULL) {
259 if (!strcmp(tempName->
name, stComponents[i]->name)) {
260 DEBUG(
DEB_LEV_ERR,
"Component %s already registered. Skip\n", stComponents[i]->name);
263 tempName = tempName->
next;
264 }
while(tempName != NULL);
265 if (tempName != NULL) {
269 if (allNames == NULL) {
270 allNames = malloc(
sizeof(
nameList));
271 currentName = allNames;
274 currentName = currentName->
next;
276 currentName->
next = NULL;
277 currentName->
name = malloc(strlen(stComponents[i]->name) + 1);
278 strcpy(currentName->
name, stComponents[i]->name);
279 *(currentName->
name + strlen(currentName->
name)) =
'\0';
282 stComponents[i]->name,
283 stComponents[i]->componentVersion.s.nVersionMajor,
284 stComponents[i]->componentVersion.s.nVersionMinor,
285 stComponents[i]->componentVersion.s.nRevision,
286 stComponents[i]->componentVersion.s.nStep,
289 printf(
"Component %s registered with %i quality levels\n", stComponents[i]->name, (
int)stComponents[i]->nqualitylevels);
291 if (stComponents[i]->nqualitylevels > 0) {
293 sprintf((qualityString + index_string),
"%i ", (
int)stComponents[i]->nqualitylevels);
294 index_string = index_string +
int2strlen(stComponents[i]->nqualitylevels) + 1;
296 sprintf((qualityString + index_string),
"%i,%i ",
297 stComponents[i]->multiResourceLevel[qi]->CPUResourceRequested,
298 stComponents[i]->multiResourceLevel[qi]->MemoryResourceRequested);
299 index_string = index_string + 2 +
300 int2strlen(stComponents[i]->multiResourceLevel[qi]->CPUResourceRequested) +
301 int2strlen(stComponents[i]->multiResourceLevel[qi]->MemoryResourceRequested);
304 *(qualityString + index_string) =
'\0';
307 strcpy(buffer, arrow);
308 strcat(buffer, stComponents[i]->name);
309 if (stComponents[i]->name_specific_length>0) {
311 strcat(buffer, arrow);
314 printf(
" Specific role %s registered\n", stComponents[i]->name_specific[j]);
316 strcat(buffer, stComponents[i]->name_specific[j]);
321 if ((qualityString != NULL) && (qualityString[0] !=
'\0')) {
322 strcat(buffer, arrow);
323 strcat(buffer, qualityString);
325 qualityString[0] =
'\0';
326 strcat(buffer,
"\n");
327 fwrite(buffer, 1, strlen(buffer), omxregistryfp);
330 for (i = 0; i < num_of_comp; i++) {
331 free(stComponents[i]->name);
333 free(stComponents[i]->name_specific[k]);
334 free(stComponents[i]->role_specific[k]);
336 if (stComponents[i]->name_specific_length > 0) {
337 free(stComponents[i]->name_specific);
338 free(stComponents[i]->role_specific);
341 free(stComponents[i]->multiResourceLevel[k]);
343 if (stComponents[i]->multiResourceLevel) {
344 free(stComponents[i]->multiResourceLevel);
346 free(stComponents[i]);
357 printf(
"\n %i OpenMAX IL ST static components in %i libraries succesfully scanned\n", ncomponents, num_of_libraries);
359 DEBUG(
DEB_LEV_SIMPLE_SEQ,
"\n %i OpenMAX IL ST static components with %i roles in %i libraries succesfully scanned\n", ncomponents, nroles, num_of_libraries);
366static void usage(
const char *app) {
367 char *registry_filename;
371 "Usage: %s [-l] [-v] [-h] [componentspath[:other_components_path]]...\n"
375 "This programs scans for a given list of directory searching for any OpenMAX\n"
376 "component compatible with the ST static component loader.\n"
377 "The registry is saved under %s. (can be changed via OMX_BELLAGIO_REGISTRY\n"
378 "environment variable)\n"
380 "The following options are supported:\n"
382 " -v display a verbose output, listing all the components registered\n"
383 " -l list only the components already registered. If -l is specified \n"
384 " all the other parameters are ignored and only the register file\n"
386 " -h display this message\n"
388 " componentspath: a searching path for components can be specified.\n"
389 " If this parameter is omitted, the components are searched in the\n"
390 " locations specified by the environment variable BELLAGIO_SEARCH_PATH.If it \n"
391 " is not defined the components are searched in the default %s directory \n"
393 app, registry_filename, OMXILCOMPONENTSPATH);
395 free(registry_filename);
403int main(
int argc,
char *argv[]) {
408 char *registry_filename;
413 for(i = 1; i < argc; i++) {
414 if(*(argv[i]) !=
'-') {
417 if (*(argv[i]+1) ==
'v') {
419 }
else if (*(argv[i]+1) ==
'l') {
423 exit(*(argv[i]+1) ==
'h' ? 0 : -EINVAL);
430 dir = strdup(registry_filename);
434 dirp = strrchr(dir,
'/');
445 omxregistryfp = fopen(registry_filename,
"r");
447 omxregistryfp = fopen(registry_filename,
"w");
449 if (omxregistryfp == NULL){
450 DEBUG(
DEB_LEV_ERR,
"Cannot open OpenMAX registry file %s\n", registry_filename);
454 free(registry_filename);
456 err = showComponentsList(omxregistryfp);
463 for(i = 1, found = 0; i < argc; i++) {
464 if(*(argv[i]) ==
'-') {
469 err = buildComponentsList(omxregistryfp, argv[i], verbose);
471 DEBUG(
DEB_LEV_ERR,
"Error registering OpenMAX components with ST static component loader %s\n", strerror(
err));
477 buffer=getenv(
"BELLAGIO_SEARCH_PATH");
478 if (buffer!=NULL&&*buffer!=
'\0') {
479 err = buildComponentsList(omxregistryfp, buffer, verbose);
481 DEBUG(
DEB_LEV_ERR,
"Error registering OpenMAX components with ST static component loader %s\n", strerror(
err));
484 err = buildComponentsList(omxregistryfp, OMXILCOMPONENTSPATH, verbose);
486 DEBUG(
DEB_LEV_ERR,
"Error registering OpenMAX components with ST static component loader %s\n", strerror(
err));
491 fclose(omxregistryfp);
char * componentsRegistryGetFilename(void)
Get registry filename This function returns the name of the registry file for the components loaded w...
int makedir(const char *newdir)
#define DEB_LEV_SIMPLE_SEQ
#define DEBUG(n, fmt, args...)
int int2strlen(int value)
int main(int argc, char *argv[])
execution of registration function
#define DEFAULT_LINE_LENGHT
the private data structure handled by the ST static loader that described an OpenMAX component
multiResourceDescriptor ** multiResourceLevel
unsigned int name_specific_length