diff --git a/audio/effect/model/include/effect_core.h b/audio/effect/model/include/effect_core.h index 6ae86e64593cfd89f0c09b060fb181cceac48acb..f27cbf0e4309eda7baa86503183cc2ad6aaad77d 100644 --- a/audio/effect/model/include/effect_core.h +++ b/audio/effect/model/include/effect_core.h @@ -40,10 +40,4 @@ struct ControllerManagerNode { /* declare the function here */ bool IsEffectLibExist(void); -int32_t RegisterEffectLibToList(void *handle, struct EffectFactory *factLib); -struct EffectFactory *GetEffectLibFromList(const char *effectLibName); -void ReleaseLibFromList(void); -int32_t RegisterControllerToList(struct ControllerManager *ctrlMgr); -struct ControllerManager *GetControllerFromList(char *effectId); - #endif diff --git a/audio/effect/model/include/effect_host_common.h b/audio/effect/model/include/effect_host_common.h index 75e58fb48c4c30eede1fd436184924c9af207f03..ebc345b9ad02c2fced0f2164403a00bc6813efe6 100644 --- a/audio/effect/model/include/effect_host_common.h +++ b/audio/effect/model/include/effect_host_common.h @@ -54,8 +54,7 @@ struct EffectModelService { struct ControllerManager { struct IEffectControl ctrlImpls; struct IEffectControlVdi *ctrlOps; - char *effectId; - char libName[HDF_EFFECT_LIB_NAME_LEN]; + char *libName; }; /* declare functions */ diff --git a/audio/effect/model/src/effect_control.c b/audio/effect/model/src/effect_control.c index 5500384173eb4b06fc07a034b3cb1b0fa72a906f..0dc359146694e8c090557fffca9daf28d5f0754d 100644 --- a/audio/effect/model/src/effect_control.c +++ b/audio/effect/model/src/effect_control.c @@ -20,6 +20,7 @@ #include "v1_0/effect_types_vdi.h" #include "v1_0/ieffect_control_vdi.h" #include "audio_uhdf_log.h" +#include "osal_mem.h" #include "audio_dfx_util.h" #define HDF_LOG_TAG HDF_AUDIO_EFFECT @@ -37,7 +38,16 @@ int32_t EffectControlEffectProcess(struct IEffectControl *self, const struct Aud HDF_LOGE("%{public}s: controller has no options", __func__); return HDF_FAILURE; } - + if (strcmp(manager->libName, "liboffline_record_algo") == 0) { + output->frameCount = input->frameCount; + output->datatag = input->datatag; + output->rawDataLen = input->rawDataLen; + output->rawData = (int8_t *)OsalMemCalloc(sizeof(int8_t) * output->rawDataLen); + if (output->rawData == NULL) { + HDF_LOGE("%{public}s: OsalMemCalloc fail", __func__); + return HDF_FAILURE; + } + } struct AudioEffectBufferVdi *inputVdi = (struct AudioEffectBufferVdi *)input; struct AudioEffectBufferVdi *outputVdi = (struct AudioEffectBufferVdi *)output; HdfAudioStartTrace(__func__, 0); diff --git a/audio/effect/model/src/effect_core.c b/audio/effect/model/src/effect_core.c index 457656bc9d2749cedf106b09eca07bfd42f579a2..fecd4dc175b10dff770ed1a93d0897372c6b2627 100644 --- a/audio/effect/model/src/effect_core.c +++ b/audio/effect/model/src/effect_core.c @@ -36,69 +36,6 @@ AEM_GET_INITED_DLIST(g_libList); /* list to manager the effect controller */ AEM_GET_INITED_DLIST(g_controllerList); -/* reist the effect lib */ -int32_t RegisterEffectLibToList(void *handle, struct EffectFactory *factLib) -{ - struct EffectFactoryLibListNode *node = NULL; - if (factLib == NULL) { - HDF_LOGE("%{public}s: input params is null", __func__); - return HDF_FAILURE; - } - - node = (struct EffectFactoryLibListNode *)OsalMemCalloc(sizeof(struct EffectFactoryLibListNode)); - if (node == NULL) { - HDF_LOGE("%{public}s: memlloc failed", __func__); - return HDF_FAILURE; - } - - node->factLib = factLib; - node->handle = handle; - DListInsertHead(&node->list, &g_libList); - - return HDF_SUCCESS; -} - -// release the effect lib using at the release process -void ReleaseLibFromList(void) -{ - struct EffectFactoryLibListNode *targetNode; - struct EffectFactoryLibListNode *tmpNode; - - DLIST_FOR_EACH_ENTRY_SAFE(targetNode, tmpNode, &g_libList, struct EffectFactoryLibListNode, list) { - DListRemove(&targetNode->list); - dlclose(targetNode->handle); - OsalMemFree(targetNode); - } - - HDF_LOGI("lib remove from the list successfully"); -} - -// get the lib by libname -struct EffectFactory *GetEffectLibFromList(const char *effectLibName) -{ - struct EffectFactoryLibListNode *tmpNode = NULL; - if (effectLibName == NULL) { - HDF_LOGE("effectLibName is NULL."); - return NULL; - } - - if (DListIsEmpty(&g_libList)) { - HDF_LOGE("g_libList is empty."); - return NULL; - } - - DLIST_FOR_EACH_ENTRY(tmpNode, &g_libList, struct EffectFactoryLibListNode, list) { - if (tmpNode->factLib != NULL && tmpNode->factLib->effectLibName != NULL) { - if (strcmp(tmpNode->factLib->effectLibName, effectLibName) == 0) { - return tmpNode->factLib; - } - } - } - - HDF_LOGE("effectLibName %{public}s not exit in list", effectLibName); - return NULL; -} - bool IsEffectLibExist(void) { bool isSupply = true; @@ -110,56 +47,3 @@ bool IsEffectLibExist(void) return isSupply; } - - -// effect controller; -int32_t RegisterControllerToList(struct ControllerManager *ctrlMgr) -{ - struct ControllerManagerNode *node = NULL; - if (ctrlMgr == NULL) { - HDF_LOGE("%{public}s: input params is null", __func__); - return HDF_FAILURE; - } - - node = (struct ControllerManagerNode *)OsalMemCalloc(sizeof(struct ControllerManagerNode)); - if (node == NULL) { - HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__); - return HDF_FAILURE; - } - - node->ctrlMgr = ctrlMgr; - DListInsertHead(&node->list, &g_controllerList); - - return HDF_SUCCESS; -} - -// get the contoller using at the desroy process -struct ControllerManager *GetControllerFromList(char *effectId) -{ - struct ControllerManagerNode *getNode = NULL; - struct ControllerManagerNode *tmpNode = NULL; - struct ControllerManager *ctrlMgr = NULL; - if (effectId == NULL) { - HDF_LOGE("effectLibName is NULL."); - return NULL; - } - - if (DListIsEmpty(&g_controllerList)) { - HDF_LOGE("g_controllerList is empty."); - return NULL; - } - // get the ctrlMgr and remove it from the list and release the node - DLIST_FOR_EACH_ENTRY_SAFE(getNode, tmpNode, &g_controllerList, struct ControllerManagerNode, list) { - if (getNode->ctrlMgr != NULL && getNode->ctrlMgr->effectId != NULL) { - if (strcmp(getNode->ctrlMgr->effectId, effectId) == 0) { - ctrlMgr = getNode->ctrlMgr; - DListRemove(&getNode->list); - OsalMemFree(getNode); - return ctrlMgr; - } - } - } - - HDF_LOGE("effectId %s not exit in list", effectId); - return NULL; -} diff --git a/audio/effect/model/src/effect_model.c b/audio/effect/model/src/effect_model.c index c39c2ac70789c1664ddaebff575167872562acef..caa61caab6583bed31fbfe8c42302864502c943f 100644 --- a/audio/effect/model/src/effect_model.c +++ b/audio/effect/model/src/effect_model.c @@ -25,7 +25,173 @@ #define AUDIO_EFFECT_PLAFORM_CONFIG HDF_CONFIG_DIR"/audio_effect.json" #define AUDIO_EFFECT_PRODUCT_CONFIG HDF_CHIP_PROD_CONFIG_DIR"/audio_effect.json" #define HDF_LOG_TAG HDF_AUDIO_EFFECT +#define AUDIO_EFFECT_NUM_MAX 10 struct ConfigDescriptor *g_cfgDescs = NULL; +struct AudioEffectLibInfo { + char *libName; + uint8_t *libHandle; + struct EffectFactory *libEffect; + struct ControllerManager *ctrlMgr; + int32_t effectCnt; +}; +struct AudioEffectLibInfo *g_libInfos[AUDIO_EFFECT_NUM_MAX] = { NULL }; + +static struct AudioEffectLibInfo* GetEffectLibInfoByName(const char *libName) +{ + if (libName == NULL) { + HDF_LOGE("%{public}s: invailid input params", __func__); + return NULL; + } + struct AudioEffectLibInfo *libInfo = NULL; + for (int i = 0; i <= AUDIO_EFFECT_NUM_MAX; i++) { + if (i == AUDIO_EFFECT_NUM_MAX) { + HDF_LOGE("%{public}s: can not find %{public}s", __func__, libName); + return NULL; + } + if (g_libInfos[i] == NULL || strcmp(g_libInfos[i]->libName, libName) != 0) { + continue; + } + libInfo = g_libInfos[i]; + break; + } + return libInfo; +} + +static int32_t LoadLibraryByName(const char *libName, uint8_t **libHandle, struct EffectFactory **factLib) +{ + if (libName == NULL || factLib == NULL || libHandle == NULL) { + HDF_LOGE("%{public}s: invailid input params", __func__); + return HDF_ERR_INVALID_PARAM; + } + int32_t ret = 0; + struct EffectFactory *(*getFactoryLib)(void); + char path[PATH_MAX]; + ret = snprintf_s(path, PATH_MAX, PATH_MAX, "%s.z.so", libName); + if (ret < 0) { + HDF_LOGE("%{public}s: get libPath failed", __func__); + return HDF_FAILURE; + } + + void *handle = dlopen(path, RTLD_LAZY); + if (handle == NULL) { + HDF_LOGE("%{public}s: open so failed, reason:%{public}s", __func__, dlerror()); + return HDF_FAILURE; + } + + getFactoryLib = dlsym(handle, "GetEffectoyFactoryLib"); + if (getFactoryLib == NULL) { + HDF_LOGE("%{public}s: dlsym failed %{public}s", __func__, dlerror()); + dlclose(handle); + return HDF_FAILURE; + } + *factLib = getFactoryLib(); + if (*factLib == NULL) { + HDF_LOGE("%{public}s: get fact lib failed %{public}s", __func__, dlerror()); + dlclose(handle); + return HDF_FAILURE; + } + *libHandle = handle; + return HDF_SUCCESS; +} + +static struct AudioEffectLibInfo* AddEffectLibInfo(const char *libName, uint8_t *libHandle, + struct EffectFactory *factLib) +{ + if (libName == NULL || factLib == NULL || libHandle == NULL) { + HDF_LOGE("%{public}s: invailid input params", __func__); + return NULL; + } + struct AudioEffectLibInfo *libInfo = NULL; + libInfo = (struct AudioEffectLibInfo *)OsalMemCalloc(sizeof(struct AudioEffectLibInfo)); + if (libInfo == NULL) { + HDF_LOGE("%{public}s: OsalMemCalloc fail", __func__); + return NULL; + } + libInfo->libName = strdup(libName); + if (libInfo->libName == NULL) { + HDF_LOGE("%{public}s: strdup fail", __func__); + OsalMemFree(libInfo); + libInfo = NULL; + return NULL; + } + libInfo->libHandle = libHandle; + libInfo->libEffect = factLib; + libInfo->ctrlMgr = NULL; + libInfo->effectCnt = 1; + return libInfo; +} + +static int32_t LoadEffectLibrary(const char *libName, struct EffectFactory **factLib, + struct ControllerManager** ctrlMgr) +{ + if (libName == NULL || factLib == NULL || ctrlMgr == NULL) { + HDF_LOGE("%{public}s: invailid input params", __func__); + return HDF_ERR_INVALID_PARAM; + } + uint8_t *libHandle = NULL; + int32_t index = 0; + for (int i = 0; i <= AUDIO_EFFECT_NUM_MAX; i++) { + if (i == AUDIO_EFFECT_NUM_MAX) { + HDF_LOGE("%{public}s: over effect max num", __func__); + return HDF_FAILURE; + } + if (g_libInfos[i] == NULL) { + index = i; + break; + } + if (strcmp(g_libInfos[i]->libName, libName) != 0) { + continue; + } + g_libInfos[i]->effectCnt++; + *factLib = g_libInfos[i]->libEffect; + *ctrlMgr = g_libInfos[i]->ctrlMgr; + HDF_LOGI("%{public}s: %{public}s increase, cnt=[%{public}d]", __func__, libName, g_libInfos[i]->effectCnt); + return HDF_SUCCESS; + } + int32_t ret = LoadLibraryByName(libName, &libHandle, factLib); + if (ret != HDF_SUCCESS || libHandle == NULL || *factLib == NULL) { + HDF_LOGE("%{public}s: load lib fail, libName:[%{public}s]", __func__, libName); + return HDF_FAILURE; + } + g_libInfos[index] = AddEffectLibInfo(libName, libHandle, *factLib); + if (g_libInfos[index] == NULL) { + HDF_LOGE("%{public}s: AddEffectLibInfo fail", __func__); + dlclose((void *)libHandle); + return HDF_FAILURE; + } + HDF_LOGI("%{public}s: %{public}s create, cnt=[%{public}d]", __func__, libName, g_libInfos[index]->effectCnt); + return HDF_SUCCESS; +} + +static int32_t DeleteEffectLibrary(const char *libName) +{ + if (libName == NULL) { + HDF_LOGE("%{public}s: invailid input params", __func__); + return HDF_ERR_INVALID_PARAM; + } + for (int i = 0; i <= AUDIO_EFFECT_NUM_MAX; i++) { + if (i == AUDIO_EFFECT_NUM_MAX) { + HDF_LOGE("%{public}s: fail to destroy effect, can not find %{public}s", __func__, libName); + return HDF_FAILURE; + } + if (g_libInfos[i] == NULL || strcmp(g_libInfos[i]->libName, libName) != 0) { + continue; + } + if (g_libInfos[i]->effectCnt > 1) { + g_libInfos[i]->effectCnt--; + HDF_LOGI("%{public}s: %{public}s decrease, cnt=[%{public}d]", __func__, libName, g_libInfos[i]->effectCnt); + return HDF_SUCCESS; + } + dlclose((void*)g_libInfos[i]->libHandle); + OsalMemFree(g_libInfos[i]->libName); + OsalMemFree(g_libInfos[i]->ctrlMgr); + OsalMemFree(g_libInfos[i]); + g_libInfos[i] = NULL; + break; + } + HDF_LOGI("%{public}s: %{public}s delete", __func__, libName); + return HDF_SUCCESS; +} static int32_t EffectModelIsSupplyEffectLibs(struct IEffectModel *self, bool *supply) { @@ -46,6 +212,7 @@ static int32_t EffectModelGetAllEffectDescriptors(struct IEffectModel *self, uint32_t i; uint32_t descNum = 0; struct EffectFactory *factLib = NULL; + struct ControllerManager *ctrlMgr = NULL; if (self == NULL || descs == NULL || descsLen == NULL) { HDF_LOGE("%{public}s: invailid input params", __func__); @@ -58,16 +225,19 @@ static int32_t EffectModelGetAllEffectDescriptors(struct IEffectModel *self, } struct EffectControllerDescriptorVdi *descsVdi = (struct EffectControllerDescriptorVdi *)descs; for (i = 0; i < g_cfgDescs->effectNum; i++) { - factLib = GetEffectLibFromList(g_cfgDescs->effectCfgDescs[i].library); - if (factLib == NULL) { + ret = LoadEffectLibrary(g_cfgDescs->effectCfgDescs[i].library, &factLib, &ctrlMgr); + if (ret != HDF_SUCCESS || factLib == NULL) { HDF_LOGE("%{public}s: GetEffectLibFromList fail!", __func__); continue; } ret = factLib->GetDescriptor(factLib, g_cfgDescs->effectCfgDescs[i].effectId, &descsVdi[descNum]); if (ret != HDF_SUCCESS) { + DeleteEffectLibrary(g_cfgDescs->effectCfgDescs[i].library); HDF_LOGE("%{public}s: GetDescriptor fail!", __func__); continue; } + DeleteEffectLibrary(g_cfgDescs->effectCfgDescs[i].library); + factLib = NULL; descNum++; } *descsLen = descNum; @@ -82,6 +252,7 @@ static int32_t EffectModelGetEffectDescriptor(struct IEffectModel *self, const c HDF_LOGD("enter to %{public}s", __func__); uint32_t i; struct EffectFactory *factLib = NULL; + struct ControllerManager *ctrlMgr = NULL; if (self == NULL || uuid == NULL || desc == NULL) { HDF_LOGE("%{public}s: invailid input params", __func__); return HDF_ERR_INVALID_PARAM; @@ -92,16 +263,18 @@ static int32_t EffectModelGetEffectDescriptor(struct IEffectModel *self, const c continue; } - factLib = GetEffectLibFromList(g_cfgDescs->effectCfgDescs[i].library); + LoadEffectLibrary(g_cfgDescs->effectCfgDescs[i].library, &factLib, &ctrlMgr); if (factLib == NULL) { HDF_LOGE("%{public}s: GetEffectLibFromList fail!", __func__); return HDF_FAILURE; } if (factLib->GetDescriptor(factLib, uuid, descVdi) != HDF_SUCCESS) { + DeleteEffectLibrary(g_cfgDescs->effectCfgDescs[i].library); HDF_LOGE("%{public}s: GetDescriptor fail!", __func__); return HDF_FAILURE; } + DeleteEffectLibrary(g_cfgDescs->effectCfgDescs[i].library); HDF_LOGD("%{public}s success", __func__); return HDF_SUCCESS; } @@ -110,33 +283,25 @@ static int32_t EffectModelGetEffectDescriptor(struct IEffectModel *self, const c return HDF_FAILURE; } -static int32_t EffectModelCreateEffectController(struct IEffectModel *self, const struct EffectInfo *info, - struct IEffectControl **contoller, struct ControllerId *contollerId) +static int32_t CreateEffectController(const struct EffectInfo *info, struct IEffectControl **contoller, + struct ControllerId *contollerId, struct IEffectControlVdi *ctrlOps) { - if (self == NULL || info == NULL || contoller == NULL || contollerId == NULL) { + if (info == NULL || contoller == NULL || contollerId == NULL) { HDF_LOGE("%{public}s: invailid input params", __func__); return HDF_ERR_INVALID_PARAM; } - - struct EffectFactory *lib = NULL; - struct ControllerManager *ctrlMgr = NULL; - struct IEffectControlVdi *ctrlOps = NULL; - - lib = GetEffectLibFromList(info->libName); - CHECK_NULL_PTR_RETURN_VALUE(lib, HDF_FAILURE); - CHECK_NULL_PTR_RETURN_VALUE(lib->CreateController, HDF_FAILURE); - - struct EffectInfoVdi *infoVdi = (struct EffectInfoVdi *)info; - lib->CreateController(lib, infoVdi, &ctrlOps); - CHECK_NULL_PTR_RETURN_VALUE(ctrlOps, HDF_FAILURE); - - /* ctrlMgr mark it and using it in release process */ - ctrlMgr = (struct ControllerManager *)OsalMemCalloc(sizeof(struct ControllerManager)); + struct ControllerManager *ctrlMgr = (struct ControllerManager *)OsalMemCalloc(sizeof(struct ControllerManager)); CHECK_NULL_PTR_RETURN_VALUE(ctrlMgr, HDF_FAILURE); - + struct AudioEffectLibInfo *libInfo = GetEffectLibInfoByName(info->libName); + if (libInfo == NULL) { + HDF_LOGE("%{public}s: GetEffectLibInfoByName failed", __func__); + OsalMemFree(ctrlMgr); + return HDF_FAILURE; + } + libInfo->ctrlMgr = ctrlMgr; ctrlMgr->ctrlOps = ctrlOps; - ctrlMgr->effectId = strdup(info->effectId); - if (ctrlMgr->effectId == NULL) { + ctrlMgr->libName = strdup(info->libName); + if (ctrlMgr->libName == NULL) { HDF_LOGE("%{public}s: strdup failed, info->effectId = %{public}s", __func__, info->effectId); OsalMemFree(ctrlMgr); return HDF_FAILURE; @@ -146,20 +311,12 @@ static int32_t EffectModelCreateEffectController(struct IEffectModel *self, cons ctrlMgr->ctrlImpls.GetEffectDescriptor = EffectGetOwnDescriptor; ctrlMgr->ctrlImpls.EffectReverse = EffectControlEffectReverse; *contoller = &ctrlMgr->ctrlImpls; - if (RegisterControllerToList(ctrlMgr) != HDF_SUCCESS) { - HDF_LOGE("%{public}s: register ctroller to list failed.", __func__); - OsalMemFree(ctrlMgr->effectId); - OsalMemFree(ctrlMgr); - *contoller = NULL; - return HDF_FAILURE; - } - // free after send reply contollerId->libName = strdup(info->libName); contollerId->effectId = strdup(info->effectId); if (contollerId->libName == NULL || contollerId->effectId == NULL) { HDF_LOGE("%{public}s: strdup failed, info->libName = %{public}s", __func__, info->libName); - OsalMemFree(ctrlMgr->effectId); + OsalMemFree(ctrlMgr->libName); OsalMemFree(ctrlMgr); *contoller = NULL; return HDF_FAILURE; @@ -167,121 +324,82 @@ static int32_t EffectModelCreateEffectController(struct IEffectModel *self, cons return HDF_SUCCESS; } -int32_t EffectModelDestroyEffectController(struct IEffectModel *self, const struct ControllerId *contollerId) +static int32_t EffectModelCreateEffectController(struct IEffectModel *self, const struct EffectInfo *info, + struct IEffectControl **contoller, struct ControllerId *contollerId) { - if (self == NULL || contollerId == NULL) { + if (self == NULL || info == NULL || contoller == NULL || contollerId == NULL) { HDF_LOGE("%{public}s: invailid input params", __func__); return HDF_ERR_INVALID_PARAM; } + struct EffectFactory *lib = NULL; struct ControllerManager *ctrlMgr = NULL; + struct IEffectControlVdi *ctrlOps = NULL; - lib = GetEffectLibFromList(contollerId->libName); - if (lib == NULL) { - HDF_LOGE("%{public}s: not match any lib", __func__); + int32_t ret = LoadEffectLibrary(info->libName, &lib, &ctrlMgr); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: LoadEffectLibrary fail", __func__); return HDF_FAILURE; } - - ctrlMgr = GetControllerFromList(contollerId->effectId); - if (ctrlMgr == NULL) { - HDF_LOGE("%{public}s: controller manager not found", __func__); - return HDF_FAILURE; + if (ctrlMgr != NULL) { + contollerId->libName = strdup(info->libName); + contollerId->effectId = strdup(info->effectId); + if (contollerId->libName == NULL || contollerId->effectId == NULL) { + HDF_LOGE("%{public}s: strdup failed", __func__); + return HDF_FAILURE; + } + *contoller = &ctrlMgr->ctrlImpls; + return HDF_SUCCESS; } + CHECK_NULL_PTR_RETURN_VALUE(lib, HDF_FAILURE); + CHECK_NULL_PTR_RETURN_VALUE(lib->CreateController, HDF_FAILURE); + + struct EffectInfoVdi *infoVdi = (struct EffectInfoVdi *)info; + lib->CreateController(lib, infoVdi, &ctrlOps); + CHECK_NULL_PTR_RETURN_VALUE(ctrlOps, HDF_FAILURE); - if (ctrlMgr->ctrlOps == NULL) { - HDF_LOGE("%{public}s: controller has no options", __func__); - OsalMemFree(ctrlMgr); - ctrlMgr = NULL; + ret = CreateEffectController(info, contoller, contollerId, ctrlOps); + if (ret != HDF_SUCCESS) { + DeleteEffectLibrary(info->libName); return HDF_FAILURE; } - - if (ctrlMgr->effectId != NULL) { - OsalMemFree(ctrlMgr->effectId); - ctrlMgr->effectId = NULL; - } - - /* call the lib destroy method,then free controller manager */ - lib->DestroyController(lib, ctrlMgr->ctrlOps); - OsalMemFree(ctrlMgr); - ctrlMgr = NULL; - + + HDF_LOGI("%{public}s: create effect succeed, libName = %{public}s", __func__, info->libName); return HDF_SUCCESS; } -static int32_t RegLibraryInstByName(char *libPath) +int32_t EffectModelDestroyEffectController(struct IEffectModel *self, const struct ControllerId *contollerId) { - struct EffectFactory *factLib = NULL; - struct EffectFactory *(*GetFactoryLib)(void); - void *libHandle = NULL; - if (libPath == NULL) { - HDF_LOGE("%{public}s: invalid input param", __func__); - return HDF_FAILURE; - } - - char pathBuf[PATH_MAX] = {'\0'}; - if (realpath(libPath, pathBuf) == NULL) { - HDF_LOGE("%{public}s: path conversion failed", __func__); - return HDF_FAILURE; - } - - if (strncmp(HDF_LIBRARY_DIR, pathBuf, strlen(HDF_LIBRARY_DIR)) != 0) { - HDF_LOGE("%{public}s: The file path is incorrect", __func__); - return HDF_FAILURE; + if (self == NULL || contollerId == NULL) { + HDF_LOGE("%{public}s: invailid input params", __func__); + return HDF_ERR_INVALID_PARAM; } - libHandle = dlopen(pathBuf, RTLD_LAZY); - if (libHandle == NULL) { - HDF_LOGE("%{public}s: open so failed, reason:%{public}s", __func__, dlerror()); - return HDF_FAILURE; + struct AudioEffectLibInfo *libInfo = GetEffectLibInfoByName(contollerId->libName); + CHECK_NULL_PTR_RETURN_VALUE(libInfo, HDF_FAILURE); + if (libInfo->effectCnt > 1) { + libInfo->effectCnt--; + return HDF_SUCCESS; } + struct EffectFactory *lib = libInfo->libEffect; + CHECK_NULL_PTR_RETURN_VALUE(lib, HDF_FAILURE); + struct ControllerManager *ctrlMgr = libInfo->ctrlMgr; + CHECK_NULL_PTR_RETURN_VALUE(ctrlMgr, HDF_FAILURE); - GetFactoryLib = dlsym(libHandle, "GetEffectoyFactoryLib"); - factLib = GetFactoryLib(); - if (factLib == NULL) { - HDF_LOGE("%{public}s: get fact lib failed %{public}s", __func__, dlerror()); - dlclose(libHandle); - return HDF_FAILURE; + if (ctrlMgr->libName != NULL) { + OsalMemFree(ctrlMgr->libName); + ctrlMgr->libName = NULL; } - if (RegisterEffectLibToList(libHandle, factLib) != HDF_SUCCESS) { - HDF_LOGE("%{public}s: register lib to list failed", __func__); - dlclose(libHandle); + if (ctrlMgr->ctrlOps == NULL) { + HDF_LOGE("%{public}s: controller has no options", __func__); return HDF_FAILURE; } - return HDF_SUCCESS; -} - -static int32_t RegLibraryInst(struct LibraryConfigDescriptor **libCfgDescs, const uint32_t libNum) -{ - int32_t ret; - uint32_t i; - char path[PATH_MAX]; - char pathBuf[PATH_MAX]; - if (libCfgDescs == NULL || libNum == 0 || libNum > HDF_EFFECT_LIB_NUM_MAX) { - HDF_LOGE("Invalid parameter!"); - return HDF_ERR_INVALID_PARAM; - } - for (i = 0; i < libNum; i++) { -#if (defined(__aarch64__) || defined(__x86_64__)) -ret = snprintf_s(path, PATH_MAX, PATH_MAX, "/vendor/lib64/%s.z.so", (*libCfgDescs)[i].libPath); -#else -ret = snprintf_s(path, PATH_MAX, PATH_MAX, "/vendor/lib/%s.z.so", (*libCfgDescs)[i].libPath); -#endif - if (ret < 0) { - HDF_LOGE("%{public}s: get libPath failed", __func__); - continue; - } - - if (realpath(path, pathBuf) == NULL) { - HDF_LOGE("%{public}s: realpath is null! [%{public}d]", __func__, errno); - continue; - } - - if (RegLibraryInstByName(path) != HDF_SUCCESS) { - HDF_LOGE("%{public}s: regist library[%{private}s] failed", __func__, path); - } - } + /* call the lib destroy method,then free controller manager */ + lib->DestroyController(lib, ctrlMgr->ctrlOps); + DeleteEffectLibrary(contollerId->libName); + HDF_LOGI("%{public}s: destroy effect succeed, libName = %{public}s", __func__, contollerId->libName); return HDF_SUCCESS; } @@ -308,14 +426,7 @@ void ModelInit(void) HDF_LOGE("cfgDesc is null!"); return; } - g_cfgDescs = cfgDesc; - if (RegLibraryInst(&(cfgDesc->libCfgDescs), cfgDesc->libNum) != HDF_SUCCESS) { - HDF_LOGE("%{public}s: RegLibraryInst failed", __func__); - AudioEffectReleaseCfgDesc(cfgDesc); - return; - } - HDF_LOGD("%{public}s end!", __func__); } @@ -344,7 +455,6 @@ void EffectModelImplRelease(struct IEffectModel *instance) } AudioEffectReleaseCfgDesc(g_cfgDescs); - ReleaseLibFromList(); struct EffectModelService *service = CONTAINER_OF(instance, struct EffectModelService, interface); if (service == NULL) { return;