/*
* OMX_GetComponentsOfRole()
*
* Description: This method will query the component for its supported roles
*
* Parameters:
* @param[in] role     The role name to query for
* @param[in] pNumComps     The number of components supporting the given role
* @param[in] compNames      The names of the components supporting the given role
*
* Returns:    OMX_NOERROR          Successful
*
* Note
*
*/
OMX_API OMX_ERRORTYPE OMX_GetComponentsOfRole(OMX_IN OMX_STRING role,
                                              OMX_INOUT OMX_U32 *pNumComps, OMX_INOUT OMX_U8 * *compNames)
{
    OMX_ERRORTYPE    eError = OMX_ErrorNone;
    OMX_U32          i = 0;
    OMX_U32          j = 0;
    OMX_U32          k = 0;

    CORE_require(role != NULL, OMX_ErrorBadParameter, NULL);
    CORE_require(pNumComps != NULL, OMX_ErrorBadParameter, NULL);
    CORE_require(count > 0, OMX_ErrorUndefined, "OMX_GetHandle called without calling OMX_Init first");

    /* This implies that the componentTable is not filled */
    CORE_assert(componentTable[i].pRoleArray[j] != NULL, OMX_ErrorBadParameter, NULL);

    for( i = 0; i < (OMX_U32)tableCount; i++ ) {
        for( j = 0; j < componentTable[i].nRoles; j++ ) {
            if( strcmp(componentTable[i].pRoleArray[j], role) == 0 ) {
                /* the first call to this function should only count the number
                of roles so that for the second call compNames can be allocated
                with the proper size for that number of roles */
                if( compNames != NULL ) {
                    strncpy((OMX_STRING) (compNames[k]),
                            (OMX_STRING) componentTable[i].name, MAXNAMESIZE);
                }
                k++;
            }
        }
    *pNumComps = k;
    }

EXIT:
    return (eError);
}
/*
* OMX_ComponentNameEnum()
*
* Description: This method will provide the name of the component at the given nIndex
*
* Parameters:
* @param[out] cComponentName       The name of the component at nIndex
* @param[in] nNameLength                The length of the component name
* @param[in] nIndex                         The index number of the component
*
* Returns:    OMX_NOERROR          Successful
*
* Note
*
*/
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_ComponentNameEnum(OMX_OUT OMX_STRING
                                                         cComponentName, OMX_IN OMX_U32 nNameLength, OMX_IN OMX_U32 nIndex)
{
    OMX_ERRORTYPE    eError = OMX_ErrorNone;
    CORE_require(cComponentName != NULL, OMX_ErrorBadParameter, NULL);
    CORE_require(count > 0, OMX_ErrorUndefined, "OMX_GetHandle called without calling OMX_Init first");

    if( nIndex >= (OMX_U32)tableCount ) {
        eError = OMX_ErrorNoMore;
    } else {
        strcpy(cComponentName, componentTable[nIndex].name);
    }
EXIT:
    return (eError);
}
Пример #3
0
/******************************Public*Routine******************************\
* OMX_FreeHandle()
*
* Description:This method will unload the OMX component pointed by
* OMX_HANDLETYPE. It is the responsibility of the calling method to ensure that
* the Deinit method of the component has been called prior to unloading component
*
* Parameters:
* @param[in] hComponent the component to unload
*
* Returns:    OMX_NOERROR          Successful
*
* Note
*
\**************************************************************************/
OMX_ERRORTYPE OMX_FreeHandle(OMX_HANDLETYPE hComponent)
{

	OMX_ERRORTYPE eError = OMX_ErrorUndefined;
	OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) hComponent;
	int i;

	if (pthread_mutex_lock(&mutex) != 0)
	{
		TIMM_OSAL_Error("Core: Error in Mutex lock");
	}

	CORE_require(pHandle != NULL, OMX_ErrorBadParameter, NULL);
	CORE_require(count > 0, OMX_ErrorUndefined,
	    "OMX_FreeHandle called without calling OMX_Init first");

	/* Locate the component handle in the array of handles */
	for (i = 0; i < COUNTOF(pModules); i++)
	{
		if (pComponents[i] == hComponent)
			break;
	}

	CORE_assert(i != COUNTOF(pModules), OMX_ErrorBadParameter, NULL);

	eError = pHandle->ComponentDeInit(hComponent);
	if (eError != OMX_ErrorNone)
	{
		TIMM_OSAL_Error("Error From ComponentDeInit..");
	}

	/* release the component and the component handle */
	dlclose(pModules[i]);
	pModules[i] = NULL;
	free(pComponents[i]);

	pComponents[i] = NULL;
	eError = OMX_ErrorNone;

      EXIT:
	/* The unload is now complete, so set the error code to pass and exit */
	if (pthread_mutex_unlock(&mutex) != 0)
	{
		TIMM_OSAL_Error("Core: Error in Mutex unlock");
	}

	return eError;
}
Пример #4
0
/*************************************************************************
* OMX_GetRolesOfComponent()
*
* Description: This method will query the component for its supported roles
*
*Parameters:
* @param[in] cComponentName     The name of the component to query
* @param[in] pNumRoles     The number of roles supported by the component
* @param[in] roles		The roles of the component
*
* Returns:    OMX_NOERROR          Successful
*                 OMX_ErrorBadParameter		Faliure due to a bad input parameter
*
* Note
*
**************************************************************************/
OMX_API OMX_ERRORTYPE OMX_GetRolesOfComponent(OMX_IN OMX_STRING
    cComponentName, OMX_INOUT OMX_U32 * pNumRoles, OMX_OUT OMX_U8 ** roles)
{

	OMX_ERRORTYPE eError = OMX_ErrorNone;
	OMX_U32 i = 0;
	OMX_U32 j = 0;
	OMX_BOOL bFound = OMX_FALSE;

	CORE_require(cComponentName != NULL, OMX_ErrorBadParameter, NULL);
	CORE_require(pNumRoles != NULL, OMX_ErrorBadParameter, NULL);
	CORE_require(strlen(cComponentName) < MAXNAMESIZE,
	    OMX_ErrorInvalidComponentName, NULL);
	CORE_require(count > 0, OMX_ErrorUndefined,
	    "OMX_GetHandle called without calling OMX_Init first");

	while (!bFound && i < tableCount)
	{
		if (strcmp(cComponentName, componentTable[i].name) == 0)
		{
			bFound = OMX_TRUE;
		} else
		{
			i++;
		}
	}
	if (roles == NULL)
	{
		*pNumRoles = componentTable[i].nRoles;
		goto EXIT;
	} else
	{
		if (bFound && (*pNumRoles == componentTable[i].nRoles))
		{
			for (j = 0; j < componentTable[i].nRoles; j++)
			{
				strcpy((OMX_STRING) roles[j],
				    componentTable[i].pRoleArray[j]);
			}
		}
	}
      EXIT:
	return eError;
}
Пример #5
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_ERRORTYPE eError = OMX_ErrorNone;
	OMX_COMPONENTTYPE *componentType;
	int i;
	char buf[sizeof(prefix) + MAXNAMESIZE + sizeof(postfix)];
	const char *pErr = dlerror();
	char *dlError = NULL;
#ifdef CHECK_SECURE_STATE
        int secure_misc_drv_fd,ret;
        OMX_U8 mode, enable=1;
#endif
	if (pthread_mutex_lock(&mutex) != 0)
	{
		TIMM_OSAL_Error("Core: Error in Mutex lock");
	}

	CORE_require(NULL != cComponentName, OMX_ErrorBadParameter, NULL);
	CORE_require(NULL != pHandle, OMX_ErrorBadParameter, NULL);
	CORE_require(NULL != pCallBacks, OMX_ErrorBadParameter, NULL);
	CORE_require(count > 0, OMX_ErrorUndefined,
	    "OMX_GetHandle called without calling OMX_Init first");

	/* 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. */
	CORE_require(strlen(cComponentName) < MAXNAMESIZE,
	    OMX_ErrorInvalidComponentName, NULL);

	/* 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;
	}
	CORE_assert(i != COUNTOF(pModules), OMX_ErrorInsufficientResources,
	    NULL);

	/* 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 */
	strcpy(buf, prefix);	/* the lengths are defined herein or have been */
	strcat(buf, cComponentName);	/* checked already, so strcpy and strcat are  */
	strcat(buf, postfix);	/* are safe to use in this context. */

#ifdef CHECK_SECURE_STATE
        //Dont return errors from misc driver to the user if any.
        //Since this affects all usecases, secure and non-secure.
        //Do log the errors though.
        secure_misc_drv_fd = open("/dev/rproc_user", O_SYNC | O_RDONLY);
	if (secure_misc_drv_fd < 0)
	{
		TIMM_OSAL_Error("Can't open misc driver device 0x%x\n", errno);
	}

	ret = read(secure_misc_drv_fd, &mode, sizeof(mode));
	if (ret < 0)
	{
		TIMM_OSAL_Error("Can't read from the misc driver");
	}
        if(mode == enable && strstr(cComponentName,"secure") == NULL)
	{
		TIMM_OSAL_Error("non-secure component not supported in secure mode");
		eError = OMX_ErrorComponentNotFound;
	}
	ret = close(secure_misc_drv_fd);
	if (ret < 0)
	{
		TIMM_OSAL_Error("Can't close the misc driver");
	}
        //Dont allow non-secure usecases if we are in secure state.
        //Else some of the memory regions will be unexpected firewalled.
        //This provides a clean exit in case we are in secure mode.
        if(eError == OMX_ErrorComponentNotFound)
        {
                goto EXIT;
        }
#endif

//#if 0
	pModules[i] = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
	if (pModules[i] == NULL)
	{
		dlError = dlerror();
		TIMM_OSAL_Error("Failed because %s", dlError);
		eError = OMX_ErrorComponentNotFound;
		goto EXIT;
	}

	/* 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], "OMX_ComponentInit");
	pErr = dlerror();
	CORE_assert(((pErr == NULL) && (pComponentInit != NULL)),
	    OMX_ErrorInvalidComponent, NULL);
//#endif

	/* 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.*/
	*pHandle = malloc(sizeof(OMX_COMPONENTTYPE));
	CORE_assert((*pHandle != NULL), OMX_ErrorInsufficientResources,
	    "Malloc of pHandle* failed");

	pComponents[i] = *pHandle;
	componentType = (OMX_COMPONENTTYPE *) * pHandle;
	componentType->nSize = sizeof(OMX_COMPONENTTYPE);

	componentType->nVersion.s.nVersionMajor = 1;
	componentType->nVersion.s.nVersionMinor = 1;
	componentType->nVersion.s.nRevision = 0;
	componentType->nVersion.s.nStep = 0;

	eError = (*pComponentInit) (*pHandle);
//eError = OMX_ComponentInit(*pHandle);
	if (OMX_ErrorNone == eError)
	{
		eError =
		    (componentType->SetCallbacks) (*pHandle, pCallBacks,
		    pAppData);
		CORE_assert(eError == OMX_ErrorNone, eError,
		    "Core: Error returned from component SetCallBack");
	} else
	{
		/* when the component fails to initialize, release the
		   component handle structure */
		free(*pHandle);
		/* mark the component handle as NULL to prevent the caller from
		   actually trying to access the component with it, should they
		   ignore the return code */
		*pHandle = NULL;
		pComponents[i] = NULL;
		dlclose(pModules[i]);
		goto EXIT;
	}
	eError = OMX_ErrorNone;
      EXIT:
	if (pthread_mutex_unlock(&mutex) != 0)
	{
		TIMM_OSAL_Error("Core: Error in Mutex unlock");
	}
	return (eError);
}
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_ERRORTYPE        eError = OMX_ErrorNone;
    OMX_COMPONENTTYPE   *componentType;
    int                  i;
    char                 buf[sizeof(prefix) + MAXNAMESIZE + sizeof(postfix)];
    const char          *pErr = dlerror();
    char                *dlError = NULL;
    if( pthread_mutex_lock(&mutex) != 0 ) {
        OSAL_ErrorTrace("Core: Error in Mutex lock");
    }

    CORE_require(NULL != cComponentName, OMX_ErrorBadParameter, NULL);
    CORE_require(NULL != pHandle, OMX_ErrorBadParameter, NULL);
    CORE_require(NULL != pCallBacks, OMX_ErrorBadParameter, NULL);
    CORE_require(count > 0, OMX_ErrorUndefined, "OMX_GetHandle called without calling OMX_Init first");

    /* 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. */
    CORE_require(strlen(cComponentName) < MAXNAMESIZE,
    OMX_ErrorInvalidComponentName, NULL);

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

    CORE_assert(i != COUNTOF(pModules), OMX_ErrorInsufficientResources, NULL);

    /* 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 */
    strcpy(buf, prefix);    /* the lengths are defined herein or have been */
    strcat(buf, cComponentName);    /* checked already, so strcpy and strcat are  */
    strcat(buf, postfix);   /* are safe to use in this context. */

    pModules[i] = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
    if( pModules[i] == NULL ) {
        dlError = (char *)dlerror();
        OSAL_ErrorTrace("Failed because %s", dlError);
        eError = OMX_ErrorComponentNotFound;
        goto EXIT;
    }

    /* 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], "OMX_ComponentInit");
    pErr = dlerror();
    CORE_assert(((pErr == NULL) && (pComponentInit != NULL)), OMX_ErrorInvalidComponent, NULL);

    /* 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.
    */
    *pHandle = malloc(sizeof(OMX_COMPONENTTYPE));
    CORE_assert((*pHandle != NULL), OMX_ErrorInsufficientResources, "Malloc of pHandle* failed");

    pComponents[i] = *pHandle;
    componentType = (OMX_COMPONENTTYPE *) *pHandle;
    componentType->nSize = sizeof(OMX_COMPONENTTYPE);

    componentType->nVersion.s.nVersionMajor = 1;
    componentType->nVersion.s.nVersionMinor = 1;
    componentType->nVersion.s.nRevision = 0;
    componentType->nVersion.s.nStep = 0;

    eError = (*pComponentInit)(*pHandle);
    if( OMX_ErrorNone == eError ) {
        eError = (componentType->SetCallbacks)(*pHandle, pCallBacks, pAppData);
        CORE_assert(eError == OMX_ErrorNone, eError, "Core: Error returned from component SetCallBack");
    } else {
        /* when the component fails to initialize, release the
        component handle structure */
        free(*pHandle);
        /* mark the component handle as NULL to prevent the caller from
        actually trying to access the component with it, should they
        ignore the return code */
        *pHandle = NULL;
        pComponents[i] = NULL;
        dlclose(pModules[i]);
        goto EXIT;
    }
    eError = OMX_ErrorNone;
EXIT:
    if( pthread_mutex_unlock(&mutex) != 0 ) {
        OSAL_ErrorTrace("Core: Error in Mutex unlock");
    }
    return (eError);
}