OMX_ERRORTYPE OmxComponentFactoryDynamicCreate(OMX_OUT OMX_HANDLETYPE* pHandle, OMX_IN  OMX_PTR pAppData, OMX_IN OMX_PTR pProxy, OMX_STRING aOmxLibName, OMX_PTR &aOmxLib, OMX_PTR aOsclUuid, OMX_U32 &aRefCount)
{
    OMX_ERRORTYPE returnStatus = OMX_ErrorUndefined;

    OsclSharedLibrary* lib = NULL;

    // If aOmxLib is NULL, this is the first time this method has been called
    if (NULL == aOmxLib)
    {
        OSCL_StackString<OMX_MAX_LIB_PATH> Libname(aOmxLibName);
        lib = OSCL_NEW(OsclSharedLibrary, (Libname));
    }
    else
    {
        lib = (OsclSharedLibrary *) aOmxLib;
    }


    // Load the associated library. If successful, call the corresponding
    // create function located inside the loaded library
    OsclLibStatus loadStatus = OsclLibSuccess;
    if (aRefCount == 0)
    {
        loadStatus = lib->LoadLib();
    }
    if (loadStatus == OsclLibSuccess)
    {
        aRefCount++;
        // look for the interface
        OsclAny* interfacePtr = NULL;
        if (OsclLibSuccess == lib->QueryInterface(PV_OMX_SHARED_INTERFACE, (OsclAny*&)interfacePtr))
        {
            // the interface ptr should be ok, but check just in case
            if (interfacePtr != NULL)
            {
                OmxSharedLibraryInterface* omxIntPtr =
                    OSCL_DYNAMIC_CAST(OmxSharedLibraryInterface*, interfacePtr);


                OsclUuid *temp = (OsclUuid*) aOsclUuid;
                OsclAny* createCompTemp =
                    omxIntPtr->QueryOmxComponentInterface(*temp, PV_OMX_CREATE_INTERFACE);

                // check if the component contains the correct ptr
                if (createCompTemp != NULL)
                {

                    // createComp is the function pointer to store the creation function
                    // for the omx component located inside the loaded library
                    OMX_ERRORTYPE(*createComp)(OMX_OUT OMX_HANDLETYPE* pHandle, OMX_IN  OMX_PTR pAppData, OMX_IN OMX_PTR pProxy, OMX_STRING aOmxLibName, OMX_PTR &aOmxLib, OMX_PTR aOsclUuid, OMX_U32 &aRefCount);

                    createComp = OSCL_DYNAMIC_CAST(OMX_ERRORTYPE(*)(OMX_OUT OMX_HANDLETYPE * pHandle, OMX_IN  OMX_PTR pAppData, OMX_IN OMX_PTR , OMX_STRING, OMX_PTR &, OMX_PTR , OMX_U32 &), createCompTemp);

                    // call the component AO factory inside the loaded library
                    returnStatus = (*createComp)(pHandle, pAppData, pProxy, aOmxLibName, aOmxLib, aOsclUuid, aRefCount);

                    // Store the shared library so it can be closed later
                    aOmxLib = (OMX_PTR) lib;
                }
            }
Exemplo n.º 2
0
/*-------------------------------------------------------------------*/
LCML_DSP_INTERFACE* GetLCMLHandle()
{
    OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE);
    OMX_HANDLETYPE pHandle = NULL;
    char *error = NULL;
    OMX_ERRORTYPE eError;

    pDllHandle = dlopen("libLCML.so", RTLD_LAZY);
    if (!pDllHandle) {
        fprintf(stderr,"dlopen: %s",dlerror());
        goto EXIT;
    }

    fpGetHandle = dlsym (pDllHandle, "GetHandle");
    
    if(fpGetHandle == NULL)
    {
	 dlclose(pDllHandle);
	 pDllHandle = NULL;
         if ((error = dlerror()) != NULL)  
         fprintf(stderr,"dlsym: %s", error);
	 goto EXIT;
    }
   
    eError = (*fpGetHandle)(&pHandle);
   if(eError != OMX_ErrorNone) {
        eError = OMX_ErrorUndefined;
        LOGV("eError != OMX_ErrorNone...\n");
        pHandle = NULL;
        goto EXIT;
    }

EXIT:
    return pHandle;
}
OMX_ERRORTYPE SEC_OMX_ComponentLoad(SEC_OMX_COMPONENT *sec_component)
{
    OMX_ERRORTYPE      ret = OMX_ErrorNone;
    OMX_HANDLETYPE     libHandle;
    OMX_COMPONENTTYPE *pOMXComponent;

    FunctionIn();

    OMX_ERRORTYPE (*SEC_OMX_ComponentInit)(OMX_HANDLETYPE hComponent, OMX_STRING componentName);

    libHandle = SEC_OSAL_dlopen((OMX_STRING)sec_component->libName, RTLD_NOW);
    if (!libHandle) {
        ret = OMX_ErrorInvalidComponentName;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInvalidComponentName, Line:%d", __LINE__);
        goto EXIT;
    }

    SEC_OMX_ComponentInit = SEC_OSAL_dlsym(libHandle, "SEC_OMX_ComponentInit");
    if (!SEC_OMX_ComponentInit) {
        SEC_OSAL_dlclose(libHandle);
        ret = OMX_ErrorInvalidComponent;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInvalidComponent, Line:%d", __LINE__);
        goto EXIT;
    }

    pOMXComponent = (OMX_COMPONENTTYPE *)SEC_OSAL_Malloc(sizeof(OMX_COMPONENTTYPE));
    INIT_SET_SIZE_VERSION(pOMXComponent, OMX_COMPONENTTYPE);
    ret = (*SEC_OMX_ComponentInit)((OMX_HANDLETYPE)pOMXComponent, (OMX_STRING)sec_component->componentName);
    if (ret != OMX_ErrorNone) {
        SEC_OSAL_Free(pOMXComponent);
        SEC_OSAL_dlclose(libHandle);
        ret = OMX_ErrorInvalidComponent;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInvalidComponent, Line:%d", __LINE__);
        goto EXIT;
    } else {
        if (SEC_OMX_ComponentAPICheck(pOMXComponent) != OMX_ErrorNone) {
            if (NULL != pOMXComponent->ComponentDeInit)
                pOMXComponent->ComponentDeInit(pOMXComponent);
            SEC_OSAL_Free(pOMXComponent);
            SEC_OSAL_dlclose(libHandle);
            ret = OMX_ErrorInvalidComponent;
            SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInvalidComponent, Line:%d", __LINE__);
            goto EXIT;
        }
        sec_component->libHandle = libHandle;
        sec_component->pOMXComponent = pOMXComponent;
        ret = OMX_ErrorNone;
    }

EXIT:
    FunctionOut();

    return ret;
}
OSCL_EXPORT_REF OMX_ERRORTYPE OMX_APIENTRY GlobalProxyComponentFreeHandle(OMX_IN OMX_HANDLETYPE hComponent)
{
    //ThreadLock.Lock();
    OMX_ERRORTYPE ErrorType = OMX_ErrorNone;
    int32 error;
    OMXGlobalData* data = (OMXGlobalData*)OsclSingletonRegistry::lockAndGetInstance(OSCL_SINGLETON_ID_OMX, error);
    if (!data)
    {
        OsclSingletonRegistry::registerInstanceAndUnlock(data, OSCL_SINGLETON_ID_OMX, error);
        ErrorType = OMX_ErrorInvalidState;
        return ErrorType;
    }

    OMX_HANDLETYPE* componentHandle = data->iComponentHandle;
    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)hComponent;
    OMX_U32 ii;

    // find the component index based on handle
    for (ii = 0; ii < MAX_INSTANTIATED_COMPONENTS; ii++)
    {
        if (pHandle == componentHandle[ii])
            break;
    }
    // cannot find the component handle
    if (ii == MAX_INSTANTIATED_COMPONENTS)
    {
        OsclSingletonRegistry::registerInstanceAndUnlock(data, OSCL_SINGLETON_ID_OMX, error);
        ErrorType = OMX_ErrorInvalidComponent;
        return ErrorType;
    }

    // call the component destructor through the function pointer recorder earlier
    // using hComponent as argument

    OMX_ERRORTYPE(*destroyComp)(OMX_IN OMX_HANDLETYPE pHandle, OMX_PTR &aOmxLib, OMX_PTR aOsclUuid, OMX_U32 &aRefCount);
    // First, obtain the destructor function
    destroyComp = data->ipInstantiatedComponentReg[ii]->FunctionPtrDestroyComponent;

    OMX_PTR &aOmxLib = data->ipInstantiatedComponentReg[ii]->SharedLibraryPtr;
    OMX_PTR aOsclUuid = data->ipInstantiatedComponentReg[ii]->SharedLibraryOsclUuid;
    OMX_U32 &aRefCount = data->ipInstantiatedComponentReg[ii]->SharedLibraryRefCounter;

    (*destroyComp)(pHandle, aOmxLib, aOsclUuid, aRefCount);

    data->iNumBaseInstance--;
    //ThreadLock.Unlock();

    ErrorType = OMX_ErrorNone;

    //Release the singleton.
    OsclSingletonRegistry::registerInstanceAndUnlock(data, OSCL_SINGLETON_ID_OMX, error);
    return ErrorType;
}
Exemplo n.º 5
0
/*-------------------------------------------------------------------*/
LCML_DSP_INTERFACE* GetLCMLHandle()
{
    OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE);
    OMX_HANDLETYPE pHandle = NULL;
    char *error = NULL;
    OMX_ERRORTYPE eError;

#if 1
    // Clear previous dynamic linking errors with dlerror();
    dlerror();
    pDllHandle = dlopen("libLCML.so", RTLD_LAZY);
    if (!pDllHandle) {
        fprintf(stderr,"dlopen: %s",dlerror());
        goto EXIT;
    }

    fpGetHandle = dlsym (pDllHandle, "GetHandle");
    error = (char *) dlerror();
    if ( error != NULL) {
        if(fpGetHandle){
                dlclose(pDllHandle);
                pDllHandle = NULL;
            }
        fprintf(stderr,"dlsym: %s", error);
        goto EXIT;
    }
#else

    OMX_ERRORTYPE GetHandle(OMX_HANDLETYPE *hInterface );
    fpGetHandle = GetHandle;

#endif

    if (fpGetHandle) {
        eError = (*fpGetHandle)(&pHandle);
        if(eError != OMX_ErrorNone) {
            eError = OMX_ErrorUndefined;
            ALOGV("eError != OMX_ErrorNone...\n");
            pHandle = NULL;
            goto EXIT;
        }
    } else {
       fprintf(stderr,"ERROR: fpGetHandle is NULL.\n");
    }

EXIT:
    return pHandle;
}
Exemplo n.º 6
0
OMX_ERRORTYPE OMX_GetHandle( 
           OMX_HANDLETYPE* pHandle, 
           OMX_STRING cComponentName, 
           OMX_PTR pAppData, 
           OMX_CALLBACKTYPE* pCallBacks)
{
	static const char prefix[] = "lib";
	static const char postfix[] = ".so";

	OMX_ERRORTYPE (*pComponentInit)(OMX_HANDLETYPE, OMX_STRING);
	OMX_ERRORTYPE err = OMX_ErrorNone;
	OMX_COMPONENTTYPE *componentType;

#ifdef DYNAMIC_LOAD
	const char *pErr = dlerror();
#endif
	OMX_U32 refIndex = 0;

	OMX_U32 i = 0;

	DEBUG_PRINT("%s :: enter!\n", __func__);
	DEBUG_PRINT("%s :: component name:%s !\n", __func__, cComponentName);

	if(pthread_mutex_lock(&g_Mutex) != 0)
	{
		DEBUG_PRINT_ERROR("%s :: Core: Error in Mutex lock\n",__func__);
		return OMX_ErrorUndefined;
	}

	if ((NULL == cComponentName) || (NULL == pHandle) || (NULL == pCallBacks))
	{
		err = OMX_ErrorBadParameter;
		DEBUG_PRINT_ERROR("%s :: invalid param!\n", __func__);
		goto UNLOCK_MUTEX;
	}

	/* Verify that the name is not too long and could cause a crash.  Notice
	* that the comparison is a greater than or equals.  This is to make
	* sure that there is room for the terminating NULL at the end of the
	* name. */

	if(strlen(cComponentName) >= MAX_COMP_NAME_LEN)
	{
		err = OMX_ErrorInvalidComponentName;
		DEBUG_PRINT_ERROR("%s :: invalid component name!\n", __func__);
		goto UNLOCK_MUTEX;
	}

	/* Locate the first empty slot for a component.  If no slots
	* are available, error out */
	for(i = 0; i < COUNTOF(pModules); i++)
	{
		if(pModules[i] == NULL)
              {      
			break;
              }
	}

	if(i == COUNTOF(pModules))
	{
		err = OMX_ErrorInsufficientResources;
		DEBUG_PRINT_ERROR("%s :: modules load too much!\n", __func__);
		goto UNLOCK_MUTEX;
	}

	for (refIndex = 0; refIndex < MAX_TABLE_SIZE; refIndex++)
	{
		char buf[sizeof(prefix) + MAX_COMP_NAME_LEN + sizeof(postfix)];

		//get the index for the component in the table
		if (strcmp(g_ComponentTable[refIndex].name, cComponentName) != 0)
              {      
			continue;
              }

		/* check if the component is already loaded */
		if (g_ComponentTable[refIndex].refCount >= MAX_COMP_INSTANCES)
		{
			err = OMX_ErrorInsufficientResources;
			DEBUG_PRINT_ERROR("%s :: Max instances of component %s already created.\n", __func__, cComponentName);
			goto UNLOCK_MUTEX;
		}

		/* load the component and check for an error.  If filename is not an
		* absolute path (i.e., it does not  begin with a "/"), then the
		* file is searched for in the following locations:
		*
		*     The LD_LIBRARY_PATH environment variable locations
		*     The library cache, /etc/ld.so.cache.
		*     /lib
		*     /usr/lib
		*
		* If there is an error, we can't go on, so set the error code and exit */

		/* the lengths are defined herein or have been
		* checked already, so strcpy and strcat are
		* are safe to use in this context. */
		strncpy(buf, prefix, sizeof(prefix));
		strncat(buf, cComponentName, strlen(cComponentName));
		strncat(buf, postfix, sizeof(postfix));

		DEBUG_PRINT("%s :: prepare to load  %s\n", __func__, buf);

#ifdef DYNAMIC_LOAD
		pModules[i] = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
		if( pModules[i] == NULL )
		{
			DEBUG_PRINT_ERROR("%s :: dlopen %s failed because %s\n", __func__, buf, dlerror());
			err = OMX_ErrorComponentNotFound;
			goto UNLOCK_MUTEX;
		}

		/* Get a function pointer to the "OMX_ComponentInit" function.  If
		* there is an error, we can't go on, so set the error code and exit */
		pComponentInit = dlsym(pModules[i], "component_init");
		pErr = dlerror();

		if( (pErr != NULL) || (pComponentInit == NULL) )
		{
			DEBUG_PRINT_ERROR("%s:: dlsym failed for module %p\n", __func__, pModules[i]);
			err = OMX_ErrorComponentNotFound;
			goto CLEAN_UP;
		}
#else
		extern OMX_ERRORTYPE component_init(OMX_HANDLETYPE, OMX_STRING);
		pComponentInit = OMX_ComponentInit;
#endif

		DEBUG_PRINT("%s :: load  %s ok\n", __func__, buf);

		*pHandle = malloc(sizeof(OMX_COMPONENTTYPE));
		if(*pHandle == NULL)
		{
			err = OMX_ErrorInsufficientResources;
			DEBUG_PRINT_ERROR("%s:: malloc of pHandle* failed\n", __func__);
			goto CLEAN_UP;
		}

		/* We now can access the dll.  So, we need to call the "OMX_ComponentInit"
		 * method to load up the "handle" (which is just a list of functions to
		 * call) and we should be all set.*/
		pComponents[i] = *pHandle;
		componentType = (OMX_COMPONENTTYPE*) *pHandle;
		componentType->nSize = sizeof(OMX_COMPONENTTYPE);
		err = (*pComponentInit)(*pHandle, cComponentName);
		if (err != OMX_ErrorNone)
		{
			DEBUG_PRINT_ERROR("%s :: OMX_ComponentInit failed 0x%08x\n", __func__, err);
			goto CLEAN_UP;
		}

		err = (componentType->SetCallbacks)(*pHandle, pCallBacks, pAppData);
		if (err != OMX_ErrorNone)
		{
			DEBUG_PRINT_ERROR("%s :: Core: SetCallBack failed %d\n", __func__, err);
			goto CLEAN_UP;
		}

		/* finally, OMX_ComponentInit() was successful and
		   SetCallbacks was successful, we have a valid instance,
		   so now we increase refCount */
		g_ComponentTable[refIndex].pHandle[g_ComponentTable[refIndex].refCount] = *pHandle;
		g_ComponentTable[refIndex].refCount += 1;
		goto UNLOCK_MUTEX;  // Component is found, and thus we are done

	}

	// If we are here, we have not found the component
	err = OMX_ErrorComponentNotFound;
	goto UNLOCK_MUTEX;

CLEAN_UP:
	if(*pHandle != NULL)
	{
		free(*pHandle);
		*pHandle = NULL;
	}

	pComponents[i] = NULL;

#ifdef DYNAMIC_LOAD
	dlclose(pModules[i]);
#endif

	pModules[i] = NULL;

UNLOCK_MUTEX:
	if(pthread_mutex_unlock(&g_Mutex) != 0)
	{
		DEBUG_PRINT_ERROR("%s :: Core: Error in Mutex unlock\n", __func__);
		err = OMX_ErrorUndefined;
	}

	return (err);
}
Exemplo n.º 7
0
gint
main (gint argc, gchar ** argv)
{
  gchar *filename;
  GModule *core_module;
  OMX_ERRORTYPE err;
  OMX_ERRORTYPE (*omx_init) (void);
  OMX_ERRORTYPE (*omx_component_name_enum) (OMX_STRING cComponentName,
      OMX_U32 nNameLength, OMX_U32 nIndex);
  OMX_ERRORTYPE (*omx_get_roles_of_component) (OMX_STRING compName,
      OMX_U32 * pNumRoles, OMX_U8 ** roles);
  guint32 i;

  if (argc != 2) {
    g_printerr ("Usage: %s /path/to/libopenmaxil.so\n", argv[0]);
    return -1;
  }

  filename = argv[1];

  if (!g_path_is_absolute (filename)) {
    g_printerr ("'%s' is not an absolute filename\n", filename);
    return -1;
  }

  /* Hack for the Broadcom OpenMAX IL implementation */
  if (g_str_has_suffix (filename, "vc/lib/libopenmaxil.so")) {
    gchar *bcm_host_filename;
    gchar *bcm_host_path;
    GModule *bcm_host_module;
    void (*bcm_host_init) (void);

    bcm_host_path = g_path_get_dirname (filename);
    bcm_host_filename =
        g_build_filename (bcm_host_path, "libbcm_host.so", NULL);

    bcm_host_module = g_module_open (bcm_host_filename, G_MODULE_BIND_LAZY);

    g_free (bcm_host_filename);
    g_free (bcm_host_path);

    if (!bcm_host_module) {
      g_printerr ("Failed to load 'libbcm_host.so'\n");
      return -1;
    }

    if (!g_module_symbol (bcm_host_module, "bcm_host_init",
            (gpointer *) & bcm_host_init)) {
      g_printerr ("Failed to find 'bcm_host_init' in 'libbcm_host.so'\n");
      return -1;
    }

    bcm_host_init ();
  }

  core_module = g_module_open (filename, G_MODULE_BIND_LAZY);
  if (!core_module) {
    g_printerr ("Failed to load '%s'\n", filename);
    return -1;
  }

  if (!g_module_symbol (core_module, "OMX_Init", (gpointer *) & omx_init)) {
    g_printerr ("Failed to find '%s' in '%s'\n", "OMX_Init", filename);
    return -1;
  }

  if (!g_module_symbol (core_module, "OMX_ComponentNameEnum",
          (gpointer *) & omx_component_name_enum)) {
    g_printerr ("Failed to find '%s' in '%s'\n", "OMX_ComponentNameEnum",
        filename);
    return -1;
  }

  if (!g_module_symbol (core_module, "OMX_GetRolesOfComponent",
          (gpointer *) & omx_get_roles_of_component)) {
    g_printerr ("Failed to find '%s' in '%s'\n", "OMX_GetRolesOfComponent",
        filename);
    return -1;
  }


  if ((err = omx_init ()) != OMX_ErrorNone) {
    g_printerr ("Failed to initialize core: %d\n", err);
    return -1;
  }

  i = 0;
  while (err == OMX_ErrorNone) {
    gchar component_name[1024];

    err = omx_component_name_enum (component_name, sizeof (component_name), i);
    if (err == OMX_ErrorNone || err == OMX_ErrorNoMore) {
      guint32 nroles;

      g_print ("Component %d: %s\n", i, component_name);

      if (omx_get_roles_of_component (component_name, (OMX_U32 *) & nroles,
              NULL) == OMX_ErrorNone && nroles > 0) {
        gchar **roles = g_new (gchar *, nroles);
        gint j;

        roles[0] = g_new0 (gchar, 129 * nroles);
        for (j = 1; j < nroles; j++) {
          roles[j] = roles[j - 1] + 129;
        }

        if (omx_get_roles_of_component (component_name, (OMX_U32 *) & nroles,
                (OMX_U8 **) roles) == OMX_ErrorNone) {
          for (j = 0; j < nroles; j++) {
            g_print ("  Role %d: %s\n", j, roles[j]);
          }
        }
        g_free (roles[0]);
        g_free (roles);
      }
    }