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;
179 char* qualityString = NULL;
185 qualityString = malloc(4096);
186 buffer = malloc(8192);
187 while (!pathconsumed) {
190 while (!currentgiven) {
191 if (*(currentpath + index) ==
'\0') {
194 if ((*(currentpath + index) ==
':') || (*(currentpath + index) ==
'\0')) {
196 if (*(currentpath + index - 1) !=
'/') {
197 actual = malloc(index + 2);
198 *(actual + index) =
'/';
199 *(actual+index + 1) =
'\0';
201 actual = malloc(index + 1);
202 *(actual+index) =
'\0';
204 strncpy(actual, currentpath, index);
205 currentpath = currentpath + index + 1;
210 dirp = opendir(actual);
212 printf(
"\n Scanning directory %s\n", actual);
219 while((dp = readdir(dirp)) != NULL) {
220 int len = strlen(dp->d_name);
225 if(strncmp(dp->d_name+len-3,
".so", 3) == 0){
226 char lib_absolute_path[strlen(actual) + len + 1];
228 strcpy(lib_absolute_path, actual);
229 strcat(lib_absolute_path, dp->d_name);
231 if((handle = dlopen(lib_absolute_path, RTLD_NOW)) == NULL) {
232 DEBUG(
DEB_LEV_ERR,
"could not load %s: %s\n", lib_absolute_path, dlerror());
235 printf(
"\n Scanning library %s\n", lib_absolute_path);
237 if ((fptr = dlsym(handle,
"omx_component_library_Setup")) == NULL) {
238 DEBUG(
DEB_LEV_SIMPLE_SEQ,
"the library %s is not compatible with ST static component loader - %s\n", lib_absolute_path, dlerror());
242 num_of_comp = fptr(NULL);
244 for (i = 0; i<num_of_comp; i++) {
250 err = fwrite(lib_absolute_path, 1, strlen(lib_absolute_path), omxregistryfp);
251 err = fwrite(
"\n", 1, 1, omxregistryfp);
254 for (i = 0; i<num_of_comp; i++) {
256 if (tempName != NULL) {
258 if (!strcmp(tempName->
name, stComponents[i]->
name)) {
259 DEBUG(
DEB_LEV_ERR,
"Component %s already registered. Skip\n", stComponents[i]->name);
262 tempName = tempName->
next;
263 }
while(tempName != NULL);
264 if (tempName != NULL) {
268 if (allNames == NULL) {
269 allNames = malloc(
sizeof(
nameList));
270 currentName = allNames;
273 currentName = currentName->
next;
275 currentName->
next = NULL;
276 currentName->
name = malloc(strlen(stComponents[i]->name) + 1);
277 strcpy(currentName->
name, stComponents[i]->
name);
278 *(currentName->
name + strlen(currentName->
name)) =
'\0';
281 stComponents[i]->name,
282 stComponents[i]->componentVersion.s.nVersionMajor,
288 printf(
"Component %s registered with %i quality levels\n", stComponents[i]->name, (
int)stComponents[i]->nqualitylevels);
290 if (stComponents[i]->nqualitylevels > 0) {
292 sprintf((qualityString + index_string),
"%i ", (
int)stComponents[i]->nqualitylevels);
293 index_string = index_string +
int2strlen(stComponents[i]->nqualitylevels) + 1;
295 sprintf((qualityString + index_string),
"%i,%i ",
296 stComponents[i]->multiResourceLevel[qi]->CPUResourceRequested,
297 stComponents[i]->multiResourceLevel[qi]->MemoryResourceRequested);
298 index_string = index_string + 2 +
299 int2strlen(stComponents[i]->multiResourceLevel[qi]->CPUResourceRequested) +
300 int2strlen(stComponents[i]->multiResourceLevel[qi]->MemoryResourceRequested);
303 *(qualityString + index_string) =
'\0';
306 strcpy(buffer, arrow);
307 strcat(buffer, stComponents[i]->name);
308 if (stComponents[i]->name_specific_length>0) {
310 strcat(buffer, arrow);
313 printf(
" Specific role %s registered\n", stComponents[i]->name_specific[j]);
315 strcat(buffer, stComponents[i]->name_specific[j]);
320 if ((qualityString != NULL) && (qualityString[0] !=
'\0')) {
321 strcat(buffer, arrow);
322 strcat(buffer, qualityString);
324 qualityString[0] =
'\0';
325 strcat(buffer,
"\n");
326 err = fwrite(buffer, 1, strlen(buffer), omxregistryfp);
329 for (i = 0; i < num_of_comp; i++) {
330 free(stComponents[i]->name);
332 free(stComponents[i]->name_specific[k]);
333 free(stComponents[i]->role_specific[k]);
335 if (stComponents[i]->name_specific_length > 0) {
336 free(stComponents[i]->name_specific);
337 free(stComponents[i]->role_specific);
340 free(stComponents[i]->multiResourceLevel[k]);
342 if (stComponents[i]->multiResourceLevel) {
343 free(stComponents[i]->multiResourceLevel);
345 free(stComponents[i]);
356 printf(
"\n %i OpenMAX IL ST static components in %i libraries succesfully scanned\n", ncomponents, num_of_libraries);
358 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);
365 static void usage(
const char *app) {
366 char *registry_filename;
370 "Usage: %s [-l] [-v] [-h] [componentspath[:other_components_path]]...\n"
374 "This programs scans for a given list of directory searching for any OpenMAX\n"
375 "component compatible with the ST static component loader.\n"
376 "The registry is saved under %s. (can be changed via OMX_BELLAGIO_REGISTRY\n"
377 "environment variable)\n"
379 "The following options are supported:\n"
381 " -v display a verbose output, listing all the components registered\n"
382 " -l list only the components already registered. If -l is specified \n"
383 " all the other parameters are ignored and only the register file\n"
385 " -h display this message\n"
387 " componentspath: a searching path for components can be specified.\n"
388 " If this parameter is omitted, the components are searched in the\n"
389 " locations specified by the environment variable BELLAGIO_SEARCH_PATH.If it \n"
390 " is not defined the components are searched in the default %s directory \n"
392 app, registry_filename, OMXILCOMPONENTSPATH);
394 free(registry_filename);
402 int main(
int argc,
char *argv[]) {
407 char *registry_filename;
412 for(i = 1; i < argc; i++) {
413 if(*(argv[i]) !=
'-') {
416 if (*(argv[i]+1) ==
'v') {
418 }
else if (*(argv[i]+1) ==
'l') {
422 exit(*(argv[i]+1) ==
'h' ? 0 : -EINVAL);
429 dir = strdup(registry_filename);
433 dirp = strrchr(dir,
'/');
444 omxregistryfp = fopen(registry_filename,
"r");
446 omxregistryfp = fopen(registry_filename,
"w");
448 if (omxregistryfp == NULL){
449 DEBUG(
DEB_LEV_ERR,
"Cannot open OpenMAX registry file %s\n", registry_filename);
453 free(registry_filename);
455 err = showComponentsList(omxregistryfp);
462 for(i = 1, found = 0; i < argc; i++) {
463 if(*(argv[i]) ==
'-') {
468 err = buildComponentsList(omxregistryfp, argv[i], verbose);
470 DEBUG(
DEB_LEV_ERR,
"Error registering OpenMAX components with ST static component loader %s\n", strerror(err));
476 buffer=getenv(
"BELLAGIO_SEARCH_PATH");
477 if (buffer!=NULL&&*buffer!=
'\0') {
478 err = buildComponentsList(omxregistryfp, buffer, verbose);
480 DEBUG(
DEB_LEV_ERR,
"Error registering OpenMAX components with ST static component loader %s\n", strerror(err));
483 err = buildComponentsList(omxregistryfp, OMXILCOMPONENTSPATH, verbose);
485 DEBUG(
DEB_LEV_ERR,
"Error registering OpenMAX components with ST static component loader %s\n", strerror(err));
490 fclose(omxregistryfp);