Example #1
0
static void usage(const char *app) {
	char *registry_filename;
	registry_filename = registryGetFilename();

	printf(
      "Usage: %s [-v] [-h] [componentspath]...\n"
      "This programs scans for a given list of directory searching for any OpenMAX\n"
      "component compatible with the ST static component loader.\n"
			"The registry is saved under %s. (can be changed via OMX_BELLAGIO_REGISTRY\n"
			"environment variable)\n"
      "\n"
      "The following options are supported:\n"
      "\n"
      "        -v   display a verbose output, listing all the components registered\n"
      "        -h   display this message\n"
      "\n"
      "         componentspath: a searching path for components can be specified.\n"
      "         If this parameter is omitted, the components are searched in the\n"
      "         default %s directory\n"
      "\n",
			app, registry_filename, OMXILCOMPONENTSPATH);

  free(registry_filename);
}
/** @brief the ST static loader contructor
 *
 * This function creates the ST static component loader, and creates
 * the list of available components, based on a registry file
 * created by a separate appication. It is called omxregister,
 * and must be called before the use of this loader
 */
OMX_ERRORTYPE BOSA_ST_InitComponentLoader(BOSA_COMPONENTLOADER *loader) {
  FILE* omxregistryfp;
  char* line = NULL;
  char *libname;
  int num_of_comp=0;
  int read;
  stLoaderComponentType** templateList;
  stLoaderComponentType** stComponentsTemp;
  void* handle;
  size_t len;
  int (*fptr)(stLoaderComponentType **stComponents);
  int i;
  int index;
  int listindex;
  char *registry_filename;

  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);

  registry_filename = registryGetFilename();
  omxregistryfp = fopen(registry_filename, "r");
  if (omxregistryfp == NULL){
    DEBUG(DEB_LEV_ERR, "Cannot open OpenMAX registry file %s\n", registry_filename);
    return ENOENT;
  }
  free(registry_filename);
  libname = malloc(OMX_MAX_STRINGNAME_SIZE * 2);

  templateList = malloc(sizeof (stLoaderComponentType*));
  templateList[0] = NULL;

  fseek(omxregistryfp, 0, 0);
  listindex = 0;
  while((read = getline(&line, &len, omxregistryfp)) != -1) {
    if ((*line == ' ') && (*(line+1) == '=')) {
      // not a library line. skip
      continue;
    }
    index = 0;
    while (*(line+index)!= '\n') index++;
    *(line+index) = 0;
    strcpy(libname, line);
    DEBUG(DEB_LEV_FULL_SEQ, "libname: %s\n",libname);
    if((handle = dlopen(libname, RTLD_NOW)) == NULL) {
      DEBUG(DEB_LEV_ERR, "could not load %s: %s\n", libname, dlerror());
    } else {
      handleLibList[numLib]=handle;
      numLib++;
      if ((fptr = dlsym(handle, "omx_component_library_Setup")) == NULL) {
        DEBUG(DEB_LEV_ERR, "the library %s is not compatible with ST static component loader - %s\n", libname, dlerror());
      } else {
        num_of_comp = (int)(*fptr)(NULL);
        templateList = realloc(templateList, (listindex + num_of_comp + 1) * sizeof (stLoaderComponentType*));
        templateList[listindex + num_of_comp] = NULL;
        stComponentsTemp = calloc(num_of_comp,sizeof(stLoaderComponentType*));
        for (i = 0; i<num_of_comp; i++) {
          stComponentsTemp[i] = calloc(1,sizeof(stLoaderComponentType));
        }
        (*fptr)(stComponentsTemp);
        for (i = 0; i<num_of_comp; i++) {
          templateList[listindex + i] = stComponentsTemp[i];
          DEBUG(DEB_LEV_FULL_SEQ, "In %s comp name[%d]=%s\n",__func__,listindex + i,templateList[listindex + i]->name);
        }
        free(stComponentsTemp);
        stComponentsTemp = NULL;
        listindex+= i;
      }
    }
  }
  if(line) {
    free(line);
    line = NULL;
  }
  free(libname);
  libname = NULL;
  fclose(omxregistryfp);
  loader->loaderPrivate = templateList;
  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
  return OMX_ErrorNone;
}
Example #3
0
/** @brief execution of registration function
 *
 * This register by default searches for openmax libraries in OMXILCOMPONENTSPATH
 * If specified it can search in a different directory
 */
int main(int argc, char *argv[]) {
	int found;
	int err, i;
	int verbose=0;
	FILE *omxregistryfp;
	char *registry_filename;
	char *dir,*dirp;

	for(i = 1; i < argc; i++) {
		if(*(argv[i]) != '-') {
			continue;
		}
		if (*(argv[i]+1) == 'v') {
			verbose = 1;
		} else {
			usage(argv[0]);
			exit(*(argv[i]+1) == 'h' ? 0 : -EINVAL);
		}
  }

	registry_filename = registryGetFilename();

	/* make sure the registry directory exists */
	dir = strdup(registry_filename);
	if (dir == NULL)
		exit(EXIT_FAILURE);
	dirp = strrchr(dir, '/');
	if (dirp != NULL) {
		*dirp = '\0';
		if (makedir(dir)) {
			DEBUG(DEB_LEV_ERR, "Cannot create OpenMAX registry directory %s\n", dir);
			exit(EXIT_FAILURE);
		}
	}
	free (dir);

	omxregistryfp = fopen(registry_filename, "w");
	if (omxregistryfp == NULL){
		DEBUG(DEB_LEV_ERR, "Cannot open OpenMAX registry file %s\n", registry_filename);
		exit(EXIT_FAILURE);
	}

	free(registry_filename);

	for(i = 1, found = 0; i < argc; i++) {
		if(*(argv[i]) == '-') {
			continue;
		}

		found = 1;
		err = buildComponentsList(omxregistryfp, argv[i], verbose);
		if(err) {
			DEBUG(DEB_LEV_ERR, "Error registering OpenMAX components with ST static component loader %s\n", strerror(err));
			continue;
		}
	}

	if (found == 0) {
		err = buildComponentsList(omxregistryfp, OMXILCOMPONENTSPATH, verbose);
		if(err) {
			DEBUG(DEB_LEV_ERR, "Error registering OpenMAX components with ST static component loader %s\n", strerror(err));
		}
	}

	fclose(omxregistryfp);

	return 0;
}