OMX_ERRORTYPE SEC_OMX_ComponentUnload(SEC_OMX_COMPONENT *sec_component) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_COMPONENTTYPE *pOMXComponent = NULL; FunctionIn(); if (!sec_component) { ret = OMX_ErrorBadParameter; goto EXIT; } pOMXComponent = sec_component->pOMXComponent; if (pOMXComponent != NULL) { pOMXComponent->ComponentDeInit(pOMXComponent); SEC_OSAL_Free(pOMXComponent); sec_component->pOMXComponent = NULL; } if (sec_component->libHandle != NULL) { SEC_OSAL_dlclose(sec_component->libHandle); sec_component->libHandle = NULL; } EXIT: FunctionOut(); return ret; }
/** @brief The OMX_FreeHandle standard function * * This function executes the BOSA_DestroyComponent of the component loaders * * @param hComponent the component handle to be freed * * @return The error of the BOSA_DestroyComponent function or OMX_ErrorNone */ OSCL_EXPORT_REF OMX_ERRORTYPE OMX_FreeHandle(OMX_HANDLETYPE hComponent) { OMX_ERRORTYPE err; OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) hComponent; if (pthread_mutex_lock(&mutex) != 0) { return OMX_ErrorUndefined; } err = pHandle->ComponentDeInit(pHandle); dlclose(((ACT_OMX_COMPONENTTYPE*) pHandle)->pModule); free(pHandle); if (err == OMX_ErrorNone) { // the component has been found and destroyed if (pthread_mutex_unlock(&mutex) != 0) { return OMX_ErrorUndefined; } return OMX_ErrorNone; } if (pthread_mutex_unlock(&mutex) != 0) { return OMX_ErrorUndefined; } ALOGV("Out of %s\n", __func__); return OMX_ErrorComponentNotFound; }
OMX_ERRORTYPE Exynos_OMX_ComponentUnload(EXYNOS_OMX_COMPONENT *exynos_component) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_COMPONENTTYPE *pOMXComponent = NULL; FunctionIn(); if (!exynos_component) { ret = OMX_ErrorBadParameter; goto EXIT; } pOMXComponent = exynos_component->pOMXComponent; if (pOMXComponent != NULL) { pOMXComponent->ComponentDeInit(pOMXComponent); Exynos_OSAL_Free(pOMXComponent); exynos_component->pOMXComponent = NULL; } if (exynos_component->libHandle != NULL) { Exynos_OSAL_dlclose(exynos_component->libHandle); exynos_component->libHandle = NULL; } EXIT: FunctionOut(); return ret; }
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; }
/******************************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; }
/** @brief creator of the requested OpenMAX component * * This function searches for the requested component in the internal list. * If the component is found, its constructor is called, * and the standard callbacks are assigned. * A pointer to a standard OpenMAX component is returned. */ OMX_ERRORTYPE BOSA_ST_CreateComponent( BOSA_COMPONENTLOADER *loader, OMX_HANDLETYPE* pHandle, OMX_STRING cComponentName, OMX_PTR pAppData, OMX_CALLBACKTYPE* pCallBacks) { int i; unsigned int j; int componentPosition = -1; OMX_ERRORTYPE eError = OMX_ErrorNone; stLoaderComponentType** templateList; OMX_COMPONENTTYPE *openmaxStandComp; omx_base_component_PrivateType * priv; DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__); templateList = (stLoaderComponentType**)loader->loaderPrivate; i = 0; while(templateList[i]) { if(!strcmp(templateList[i]->name, cComponentName)) { //given component name matches with the general component names componentPosition = i; break; } else { for(j=0;j<templateList[i]->name_specific_length;j++) { if(!strcmp(templateList[i]->name_specific[j], cComponentName)) { //given component name matches with specific component names componentPosition = i; break; } } if(componentPosition != -1) { break; } } i++; } if (componentPosition == -1) { DEBUG(DEB_LEV_ERR, "Component not found with current ST static component loader.\n"); return OMX_ErrorComponentNotFound; } //component name matches with general component name field DEBUG(DEB_LEV_PARAMS, "Found base requested template %s\n", cComponentName); /* Build ST component from template and fill fields */ templateList[componentPosition]->name_requested = strndup (cComponentName, OMX_MAX_STRINGNAME_SIZE); openmaxStandComp = calloc(1,sizeof(OMX_COMPONENTTYPE)); if (!openmaxStandComp) { return OMX_ErrorInsufficientResources; } eError = templateList[componentPosition]->constructor(openmaxStandComp,cComponentName); if (eError != OMX_ErrorNone) { if (eError == OMX_ErrorInsufficientResources) { *pHandle = openmaxStandComp; priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate; priv->loader = loader; return OMX_ErrorInsufficientResources; } DEBUG(DEB_LEV_ERR, "Error during component construction\n"); openmaxStandComp->ComponentDeInit(openmaxStandComp); free(openmaxStandComp); openmaxStandComp = NULL; return OMX_ErrorComponentNotFound; } priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate; priv->loader = loader; *pHandle = openmaxStandComp; ((OMX_COMPONENTTYPE*)*pHandle)->SetCallbacks(*pHandle, pCallBacks, pAppData); DEBUG(DEB_LEV_FULL_SEQ, "Template %s found returning from OMX_GetHandle\n", cComponentName); DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__); return eError; }
/* OMX_GetHandle */ OMX_ERRORTYPE OMX_APIENTRY OMX_GetHandle( OMX_OUT OMX_HANDLETYPE* pHandle, OMX_IN OMX_STRING cComponentName, OMX_IN OMX_PTR pAppData, OMX_IN OMX_CALLBACKTYPE* pCallBacks) { OMX_ERRORTYPE eError; OMX_COMPONENTTYPE *pComp; OMX_HANDLETYPE hHandle = 0; if (pHandle == NULL || cComponentName == NULL || pCallBacks == NULL || ilcs_service == NULL) { if(pHandle) *pHandle = NULL; return OMX_ErrorBadParameter; } { pComp = (OMX_COMPONENTTYPE *)malloc(sizeof(OMX_COMPONENTTYPE)); if (!pComp) { vcos_assert(0); return OMX_ErrorInsufficientResources; } memset(pComp, 0, sizeof(OMX_COMPONENTTYPE)); hHandle = (OMX_HANDLETYPE)pComp; pComp->nSize = sizeof(OMX_COMPONENTTYPE); pComp->nVersion.nVersion = OMX_VERSION; eError = vcil_out_create_component(ilcs_get_common(ilcs_service), hHandle, cComponentName); if (eError == OMX_ErrorNone) { // Check that all function pointers have been filled in. // All fields should be non-zero. int i; uint32_t *p = (uint32_t *) pComp; for(i=0; i<sizeof(OMX_COMPONENTTYPE)>>2; i++) if(*p++ == 0) eError = OMX_ErrorInvalidComponent; if(eError != OMX_ErrorNone && pComp->ComponentDeInit) pComp->ComponentDeInit(hHandle); } if (eError == OMX_ErrorNone) { eError = pComp->SetCallbacks(hHandle,pCallBacks,pAppData); if (eError != OMX_ErrorNone) pComp->ComponentDeInit(hHandle); } if (eError == OMX_ErrorNone) { *pHandle = hHandle; } else { *pHandle = NULL; free(pComp); } } if (eError == OMX_ErrorNone) { vcos_mutex_lock(&lock); nActiveHandles++; vcos_mutex_unlock(&lock); } return eError; }
/******************************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 retVal = OMX_ErrorUndefined; OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)hComponent; OMX_U32 refIndex = 0; OMX_S32 handleIndex = 0; OMX_U32 i = 0; if(pthread_mutex_lock(&g_Mutex) != 0) { DEBUG_PRINT_ERROR("%s :: Core: Error in Mutex lock\n", __func__); return OMX_ErrorUndefined; } /* Locate the component handle in the array of handles */ for(i = 0; i < COUNTOF(pModules); i++) { if(pComponents[i] == hComponent) { break; } } if(i == COUNTOF(pModules)) { DEBUG_PRINT_ERROR("%s :: Core: component %p is not found\n", __func__, hComponent); retVal = OMX_ErrorBadParameter; goto EXIT; } /* call component deinit method */ retVal = pHandle->ComponentDeInit(hComponent); if (retVal != OMX_ErrorNone) { DEBUG_PRINT_ERROR("%s :: ComponentDeInit failed %d\n", __func__, retVal); goto EXIT; } for (refIndex=0; refIndex < MAX_TABLE_SIZE; refIndex++) { for (handleIndex=0; handleIndex < g_ComponentTable[refIndex].refCount; handleIndex++) { /* get the position for the component in the table */ if (g_ComponentTable[refIndex].pHandle[handleIndex] == hComponent) { if (g_ComponentTable[refIndex].refCount) { g_ComponentTable[refIndex].refCount -= 1; } g_ComponentTable[refIndex].pHandle[handleIndex] = NULL; #ifdef DYNAMIC_LOAD dlclose(pModules[i]); #endif pModules[i] = NULL; free(pComponents[i]); pComponents[i] = NULL; retVal = OMX_ErrorNone; goto EXIT; } } } // If we are here, we have not found the matching component retVal = OMX_ErrorComponentNotFound; EXIT: /* The unload is now complete, so set the error code to pass and exit */ if(pthread_mutex_unlock(&g_Mutex) != 0) { DEBUG_PRINT_ERROR("%s :: Core: Error in Mutex unlock\n", __func__); return OMX_ErrorUndefined; } return retVal; }