45 #include <sys/types.h>
50 #define DEFAULT_LINE_LENGHT 500
54 static const char arrow[] =
" ==> ";
58 if (value<0)
return -1;
68 static 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] !=
' ')) {
110 strncpy(comp_name, temp_buffer, i);
113 if (*temp_buffer !=
'\0') {
116 while ((temp_buffer[i] !=
'\n') && (temp_buffer[i] !=
' ')) {
119 strncpy(comp_rules, temp_buffer, i);
120 comp_rules[i] =
'\0';
122 comp_rules[0] =
'\0';
124 printf(
"Component %s\n", comp_name);
125 if (comp_rules[0] !=
'\0') {
126 temp_rules = comp_rules;
127 printf(
" supported formats:\n");
129 while (*(temp_rules+i) !=
'\0') {
131 if (*(temp_rules+i) ==
':') {
132 strncpy(temp_name, temp_rules, i);
135 printf(
" %s\n", temp_name);
159 static int buildComponentsList(FILE* omxregistryfp,
char *componentspath,
int verbose) {
163 int i, num_of_comp, k, qi;
164 int num_of_libraries = 0;
169 int ncomponents = 0, nroles=0;
170 int pathconsumed = 0;
173 char* currentpath = componentspath;
178 char* qualityString = NULL;
184 qualityString = malloc(4096);
185 buffer = malloc(8192);
186 while (!pathconsumed) {
189 while (!currentgiven) {
190 if (*(currentpath + index) ==
'\0') {
193 if ((*(currentpath + index) ==
':') || (*(currentpath + index) ==
'\0')) {
195 if (*(currentpath + index - 1) !=
'/') {
196 actual = malloc(index + 2);
197 *(actual + index) =
'/';
198 *(actual+index + 1) =
'\0';
200 actual = malloc(index + 1);
201 *(actual+index) =
'\0';
203 strncpy(actual, currentpath, index);
204 currentpath = currentpath + index + 1;
209 dirp = opendir(actual);
211 printf(
"\n Scanning directory %s\n", actual);
218 while((dp = readdir(dirp)) != NULL) {
219 int len = strlen(dp->d_name);
224 if(strncmp(dp->d_name+len-3,
".so", 3) == 0){
225 char lib_absolute_path[strlen(actual) + len + 1];
227 strcpy(lib_absolute_path, actual);
228 strcat(lib_absolute_path, dp->d_name);
230 if((
handle = dlopen(lib_absolute_path, RTLD_NOW)) == NULL) {
231 DEBUG(
DEB_LEV_ERR,
"could not load %s: %s\n", lib_absolute_path, dlerror());
234 printf(
"\n Scanning library %s\n", lib_absolute_path);
236 if ((fptr = dlsym(
handle,
"omx_component_library_Setup")) == NULL) {
237 DEBUG(
DEB_LEV_SIMPLE_SEQ,
"the library %s is not compatible with ST static component loader - %s\n", lib_absolute_path, dlerror());
241 num_of_comp = fptr(NULL);
243 for (i = 0; i<num_of_comp; i++) {
249 fwrite(lib_absolute_path, 1, strlen(lib_absolute_path), omxregistryfp);
250 fwrite(
"\n", 1, 1, omxregistryfp);
253 for (i = 0; i<num_of_comp; i++) {
255 if (tempName != NULL) {
257 if (!strcmp(tempName->
name, stComponents[i]->name)) {
258 DEBUG(
DEB_LEV_ERR,
"Component %s already registered. Skip\n", stComponents[i]->name);
261 tempName = tempName->
next;
262 }
while(tempName != NULL);
263 if (tempName != NULL) {
267 if (allNames == NULL) {
268 allNames = malloc(
sizeof(
nameList));
269 currentName = allNames;
272 currentName = currentName->
next;
274 currentName->
next = NULL;
275 currentName->
name = malloc(strlen(stComponents[i]->name) + 1);
276 strcpy(currentName->
name, stComponents[i]->name);
277 *(currentName->
name + strlen(currentName->
name)) =
'\0';
280 stComponents[i]->name,
281 stComponents[i]->componentVersion.s.nVersionMajor,
282 stComponents[i]->componentVersion.s.nVersionMinor,
283 stComponents[i]->componentVersion.s.nRevision,
284 stComponents[i]->componentVersion.s.nStep,
287 printf(
"Component %s registered with %i quality levels\n", stComponents[i]->name, (
int)stComponents[i]->nqualitylevels);
289 if (stComponents[i]->nqualitylevels > 0) {
291 sprintf((qualityString + index_string),
"%i ", (
int)stComponents[i]->nqualitylevels);
292 index_string = index_string +
int2strlen(stComponents[i]->nqualitylevels) + 1;
294 sprintf((qualityString + index_string),
"%i,%i ",
295 stComponents[i]->multiResourceLevel[qi]->CPUResourceRequested,
296 stComponents[i]->multiResourceLevel[qi]->MemoryResourceRequested);
297 index_string = index_string + 2 +
298 int2strlen(stComponents[i]->multiResourceLevel[qi]->CPUResourceRequested) +
299 int2strlen(stComponents[i]->multiResourceLevel[qi]->MemoryResourceRequested);
302 *(qualityString + index_string) =
'\0';
305 strcpy(buffer, arrow);
306 strcat(buffer, stComponents[i]->name);
307 if (stComponents[i]->name_specific_length>0) {
309 strcat(buffer, arrow);
312 printf(
" Specific role %s registered\n", stComponents[i]->name_specific[j]);
314 strcat(buffer, stComponents[i]->name_specific[j]);
319 if ((qualityString != NULL) && (qualityString[0] !=
'\0')) {
320 strcat(buffer, arrow);
321 strcat(buffer, qualityString);
323 qualityString[0] =
'\0';
324 strcat(buffer,
"\n");
325 fwrite(buffer, 1, strlen(buffer), omxregistryfp);
328 for (i = 0; i < num_of_comp; i++) {
329 free(stComponents[i]->name);
331 free(stComponents[i]->name_specific[k]);
332 free(stComponents[i]->role_specific[k]);
334 if (stComponents[i]->name_specific_length > 0) {
335 free(stComponents[i]->name_specific);
336 free(stComponents[i]->role_specific);
339 free(stComponents[i]->multiResourceLevel[k]);
341 if (stComponents[i]->multiResourceLevel) {
342 free(stComponents[i]->multiResourceLevel);
344 free(stComponents[i]);
355 printf(
"\n %i OpenMAX IL ST static components in %i libraries succesfully scanned\n", ncomponents, num_of_libraries);
357 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);
364 static void usage(
const char *app) {
365 char *registry_filename;
369 "Usage: %s [-l] [-v] [-h] [componentspath[:other_components_path]]...\n"
373 "This programs scans for a given list of directory searching for any OpenMAX\n"
374 "component compatible with the ST static component loader.\n"
375 "The registry is saved under %s. (can be changed via OMX_BELLAGIO_REGISTRY\n"
376 "environment variable)\n"
378 "The following options are supported:\n"
380 " -v display a verbose output, listing all the components registered\n"
381 " -l list only the components already registered. If -l is specified \n"
382 " all the other parameters are ignored and only the register file\n"
384 " -h display this message\n"
386 " componentspath: a searching path for components can be specified.\n"
387 " If this parameter is omitted, the components are searched in the\n"
388 " locations specified by the environment variable BELLAGIO_SEARCH_PATH.If it \n"
389 " is not defined the components are searched in the default %s directory \n"
391 app, registry_filename, OMXILCOMPONENTSPATH);
393 free(registry_filename);
401 int main(
int argc,
char *argv[]) {
406 char *registry_filename;
411 for(i = 1; i < argc; i++) {
412 if(*(argv[i]) !=
'-') {
415 if (*(argv[i]+1) ==
'v') {
417 }
else if (*(argv[i]+1) ==
'l') {
421 exit(*(argv[i]+1) ==
'h' ? 0 : -EINVAL);
428 dir = strdup(registry_filename);
432 dirp = strrchr(dir,
'/');
443 omxregistryfp = fopen(registry_filename,
"r");
445 omxregistryfp = fopen(registry_filename,
"w");
447 if (omxregistryfp == NULL){
448 DEBUG(
DEB_LEV_ERR,
"Cannot open OpenMAX registry file %s\n", registry_filename);
452 free(registry_filename);
454 err = showComponentsList(omxregistryfp);
461 for(i = 1, found = 0; i < argc; i++) {
462 if(*(argv[i]) ==
'-') {
467 err = buildComponentsList(omxregistryfp, argv[i], verbose);
469 DEBUG(
DEB_LEV_ERR,
"Error registering OpenMAX components with ST static component loader %s\n", strerror(
err));
475 buffer=getenv(
"BELLAGIO_SEARCH_PATH");
476 if (buffer!=NULL&&*buffer!=
'\0') {
477 err = buildComponentsList(omxregistryfp, buffer, verbose);
479 DEBUG(
DEB_LEV_ERR,
"Error registering OpenMAX components with ST static component loader %s\n", strerror(
err));
482 err = buildComponentsList(omxregistryfp, OMXILCOMPONENTSPATH, verbose);
484 DEBUG(
DEB_LEV_ERR,
"Error registering OpenMAX components with ST static component loader %s\n", strerror(
err));
489 fclose(omxregistryfp);