• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <securec.h>
16 #include <string.h>
17 #include <pthread.h>
18 #include "effect_core.h"
19 #include "effect_host_common.h"
20 #include "v1_0/effect_types_vdi.h"
21 #include "v1_0/effect_factory.h"
22 #include "osal_mem.h"
23 #include "parse_effect_config.h"
24 #include "audio_uhdf_log.h"
25 
26 #define AUDIO_EFFECT_PLAFORM_CONFIG HDF_CONFIG_DIR"/audio_effect.json"
27 #define AUDIO_EFFECT_PRODUCT_CONFIG HDF_CHIP_PROD_CONFIG_DIR"/audio_effect.json"
28 #define HDF_LOG_TAG HDF_AUDIO_EFFECT
29 #define AUDIO_EFFECT_NUM_MAX 10
30 pthread_rwlock_t g_rwEffectLock = PTHREAD_RWLOCK_INITIALIZER;
31 struct ConfigDescriptor *g_cfgDescs = NULL;
32 struct AudioEffectLibInfo {
33     char *libName;
34     uint8_t *libHandle;
35     struct EffectFactory *libEffect;
36     struct ControllerManager *ctrlMgr;
37     int32_t effectCnt;
38 };
39 struct AudioEffectLibInfo *g_libInfos[AUDIO_EFFECT_NUM_MAX] = { NULL };
40 
GetEffectLibInfoByName(const char * libName)41 static struct AudioEffectLibInfo* GetEffectLibInfoByName(const char *libName)
42 {
43     if (libName == NULL) {
44         HDF_LOGE("%{public}s: invailid input params", __func__);
45         return NULL;
46     }
47     struct AudioEffectLibInfo *libInfo = NULL;
48     for (int i = 0; i <= AUDIO_EFFECT_NUM_MAX; i++) {
49         if (i == AUDIO_EFFECT_NUM_MAX) {
50             HDF_LOGE("%{public}s: can not find %{public}s", __func__, libName);
51             return NULL;
52         }
53         if (g_libInfos[i] == NULL || strcmp(g_libInfos[i]->libName, libName) != 0) {
54             continue;
55         }
56         libInfo = g_libInfos[i];
57         break;
58     }
59     return libInfo;
60 }
61 
LoadLibraryByName(const char * libName,uint8_t ** libHandle,struct EffectFactory ** factLib)62 static int32_t LoadLibraryByName(const char *libName, uint8_t **libHandle, struct EffectFactory **factLib)
63 {
64     if (libName == NULL || factLib == NULL || libHandle == NULL) {
65         HDF_LOGE("%{public}s: invailid input params", __func__);
66         return HDF_ERR_INVALID_PARAM;
67     }
68     int32_t ret = 0;
69     struct EffectFactory *(*getFactoryLib)(void);
70     char path[PATH_MAX];
71     char pathBuf[PATH_MAX];
72 #if (defined(__aarch64__) || defined(__x86_64__))
73     ret = snprintf_s(path, PATH_MAX, PATH_MAX, "/vendor/lib64/%s.z.so", libName);
74 #else
75     ret = snprintf_s(path, PATH_MAX, PATH_MAX, "/vendor/lib/%s.z.so", libName);
76 #endif
77     if (ret < 0) {
78         HDF_LOGE("%{public}s: get libPath failed", __func__);
79         return HDF_FAILURE;
80     }
81     if (realpath(path, pathBuf) == NULL) {
82         HDF_LOGE("%{public}s: realpath is null! [%{public}d]", __func__, errno);
83         return HDF_FAILURE;
84     }
85     if (strncmp(HDF_LIBRARY_DIR, pathBuf, strlen(HDF_LIBRARY_DIR)) != 0) {
86         HDF_LOGE("%{public}s: The file path is incorrect", __func__);
87         return HDF_FAILURE;
88     }
89 
90     void *handle = dlopen(pathBuf, RTLD_LAZY);
91     if (handle == NULL) {
92         HDF_LOGE("%{public}s: open so failed, reason:%{public}s", __func__, dlerror());
93         return HDF_FAILURE;
94     }
95 
96     getFactoryLib = dlsym(handle, "GetEffectoyFactoryLib");
97     if (getFactoryLib == NULL) {
98         HDF_LOGE("%{public}s: dlsym failed %{public}s", __func__, dlerror());
99         dlclose(handle);
100         return HDF_FAILURE;
101     }
102     *factLib = getFactoryLib();
103     if (*factLib == NULL) {
104         HDF_LOGE("%{public}s: get fact lib failed %{public}s", __func__, dlerror());
105         dlclose(handle);
106         return HDF_FAILURE;
107     }
108     *libHandle = handle;
109     return HDF_SUCCESS;
110 }
111 
AddEffectLibInfo(const char * libName,uint8_t * libHandle,struct EffectFactory * factLib)112 static struct AudioEffectLibInfo* AddEffectLibInfo(const char *libName, uint8_t *libHandle,
113     struct EffectFactory *factLib)
114 {
115     if (libName == NULL || factLib == NULL || libHandle == NULL) {
116         HDF_LOGE("%{public}s: invailid input params", __func__);
117         return NULL;
118     }
119     struct AudioEffectLibInfo *libInfo = NULL;
120     libInfo = (struct AudioEffectLibInfo *)OsalMemCalloc(sizeof(struct AudioEffectLibInfo));
121     if (libInfo == NULL) {
122         HDF_LOGE("%{public}s: OsalMemCalloc fail", __func__);
123         return NULL;
124     }
125     libInfo->libName = strdup(libName);
126     if (libInfo->libName == NULL) {
127         HDF_LOGE("%{public}s: strdup fail", __func__);
128         OsalMemFree(libInfo);
129         libInfo = NULL;
130         return NULL;
131     }
132     libInfo->libHandle = libHandle;
133     libInfo->libEffect = factLib;
134     libInfo->ctrlMgr = NULL;
135     libInfo->effectCnt = 1;
136     return libInfo;
137 }
138 
LoadEffectLibrary(const char * libName,struct EffectFactory ** factLib,struct ControllerManager ** ctrlMgr)139 static int32_t LoadEffectLibrary(const char *libName, struct EffectFactory **factLib,
140     struct ControllerManager** ctrlMgr)
141 {
142     if (libName == NULL || factLib == NULL || ctrlMgr == NULL) {
143         HDF_LOGE("%{public}s: invailid input params", __func__);
144         return HDF_ERR_INVALID_PARAM;
145     }
146     uint8_t *libHandle = NULL;
147     int32_t index = 0;
148     pthread_rwlock_wrlock(&g_rwEffectLock);
149     for (int i = 0; i <= AUDIO_EFFECT_NUM_MAX; i++) {
150         if (i == AUDIO_EFFECT_NUM_MAX) {
151             HDF_LOGE("%{public}s: over effect max num", __func__);
152             pthread_rwlock_unlock(&g_rwEffectLock);
153             return HDF_FAILURE;
154         }
155         if (g_libInfos[i] == NULL) {
156             index = i;
157             break;
158         }
159         if (strcmp(g_libInfos[i]->libName, libName) != 0) {
160             continue;
161         }
162         g_libInfos[i]->effectCnt++;
163         *factLib = g_libInfos[i]->libEffect;
164         *ctrlMgr = g_libInfos[i]->ctrlMgr;
165         HDF_LOGI("%{public}s: %{public}s increase, cnt=[%{public}d]", __func__, libName, g_libInfos[i]->effectCnt);
166         pthread_rwlock_unlock(&g_rwEffectLock);
167         return HDF_SUCCESS;
168     }
169     int32_t ret = LoadLibraryByName(libName, &libHandle, factLib);
170     if (ret != HDF_SUCCESS || libHandle == NULL || *factLib == NULL) {
171         HDF_LOGE("%{public}s: load lib fail, libName:[%{public}s]", __func__, libName);
172         pthread_rwlock_unlock(&g_rwEffectLock);
173         return HDF_FAILURE;
174     }
175     g_libInfos[index] = AddEffectLibInfo(libName, libHandle, *factLib);
176     if (g_libInfos[index] == NULL) {
177         HDF_LOGE("%{public}s: AddEffectLibInfo fail", __func__);
178         dlclose((void *)libHandle);
179         pthread_rwlock_unlock(&g_rwEffectLock);
180         return HDF_FAILURE;
181     }
182     HDF_LOGI("%{public}s: %{public}s create, cnt=[%{public}d]", __func__, libName, g_libInfos[index]->effectCnt);
183     pthread_rwlock_unlock(&g_rwEffectLock);
184     return HDF_SUCCESS;
185 }
186 
DeleteEffectLibrary(const char * libName)187 static int32_t DeleteEffectLibrary(const char *libName)
188 {
189     if (libName == NULL) {
190         HDF_LOGE("%{public}s: invailid input params", __func__);
191         return HDF_ERR_INVALID_PARAM;
192     }
193     pthread_rwlock_wrlock(&g_rwEffectLock);
194     for (int i = 0; i <= AUDIO_EFFECT_NUM_MAX; i++) {
195         if (i == AUDIO_EFFECT_NUM_MAX) {
196             HDF_LOGE("%{public}s: fail to destroy effect, can not find %{public}s", __func__, libName);
197             pthread_rwlock_unlock(&g_rwEffectLock);
198             return HDF_FAILURE;
199         }
200         if (g_libInfos[i] == NULL || strcmp(g_libInfos[i]->libName, libName) != 0) {
201             continue;
202         }
203         if (g_libInfos[i]->effectCnt > 1) {
204             g_libInfos[i]->effectCnt--;
205             HDF_LOGI("%{public}s: %{public}s decrease, cnt=[%{public}d]", __func__, libName, g_libInfos[i]->effectCnt);
206             pthread_rwlock_unlock(&g_rwEffectLock);
207             return HDF_SUCCESS;
208         }
209         dlclose((void*)g_libInfos[i]->libHandle);
210         OsalMemFree(g_libInfos[i]->libName);
211         OsalMemFree(g_libInfos[i]->ctrlMgr);
212         OsalMemFree(g_libInfos[i]);
213         g_libInfos[i] = NULL;
214         break;
215     }
216     HDF_LOGI("%{public}s: %{public}s delete", __func__, libName);
217     pthread_rwlock_unlock(&g_rwEffectLock);
218     return HDF_SUCCESS;
219 }
220 
IsSupplyEffect(const char * libName)221 static int32_t IsSupplyEffect(const char *libName)
222 {
223     if (g_cfgDescs == NULL) {
224         HDF_LOGE("%{public}s: point is null!", __func__);
225         return HDF_FAILURE;
226     }
227     for (uint32_t i = 0; i < g_cfgDescs->effectNum; i++) {
228         if (strcmp(g_cfgDescs->effectCfgDescs[i].library, libName) == 0) {
229             return HDF_SUCCESS;
230         }
231     }
232     return HDF_FAILURE;
233 }
234 
EffectModelIsSupplyEffectLibs(struct IEffectModel * self,bool * supply)235 static int32_t EffectModelIsSupplyEffectLibs(struct IEffectModel *self, bool *supply)
236 {
237     if (self == NULL || supply == NULL) {
238         HDF_LOGE("%{public}s: invailid input params", __func__);
239         return HDF_ERR_INVALID_PARAM;
240     }
241 
242     *supply = IsEffectLibExist();
243     return HDF_SUCCESS;
244 }
245 
EffectModelGetAllEffectDescriptors(struct IEffectModel * self,struct EffectControllerDescriptor * descs,uint32_t * descsLen)246 static int32_t EffectModelGetAllEffectDescriptors(struct IEffectModel *self,
247                                                   struct EffectControllerDescriptor *descs, uint32_t *descsLen)
248 {
249     HDF_LOGD("enter to %{public}s", __func__);
250     int32_t ret;
251     uint32_t i;
252     uint32_t descNum = 0;
253     struct EffectFactory *factLib = NULL;
254     struct ControllerManager *ctrlMgr = NULL;
255 
256     if (self == NULL || descs == NULL || descsLen == NULL) {
257         HDF_LOGE("%{public}s: invailid input params", __func__);
258         return HDF_ERR_INVALID_PARAM;
259     }
260 
261     if (g_cfgDescs == NULL) {
262         HDF_LOGE("%{public}s: point is null!", __func__);
263         return HDF_FAILURE;
264     }
265     struct EffectControllerDescriptorVdi *descsVdi = (struct EffectControllerDescriptorVdi *)descs;
266     for (i = 0; i < g_cfgDescs->effectNum; i++) {
267         ret = LoadEffectLibrary(g_cfgDescs->effectCfgDescs[i].library, &factLib, &ctrlMgr);
268         if (ret != HDF_SUCCESS || factLib == NULL) {
269             HDF_LOGE("%{public}s: GetEffectLibFromList fail!", __func__);
270             continue;
271         }
272         if (ConstructDescriptor(&descsVdi[descNum]) != HDF_SUCCESS) {
273             HDF_LOGE("%{public}s: ConstructDescriptor fail!", __func__);
274             continue;
275         }
276         ret = factLib->GetDescriptor(factLib, g_cfgDescs->effectCfgDescs[i].effectId, &descsVdi[descNum]);
277         if (ret != HDF_SUCCESS) {
278             descNum++;
279             DeleteEffectLibrary(g_cfgDescs->effectCfgDescs[i].library);
280             HDF_LOGE("%{public}s: GetDescriptor fail!", __func__);
281             continue;
282         }
283         DeleteEffectLibrary(g_cfgDescs->effectCfgDescs[i].library);
284         factLib = NULL;
285         descNum++;
286     }
287     *descsLen = descNum;
288     descs = (struct EffectControllerDescriptor *)descsVdi;
289     HDF_LOGD("%{public}s success", __func__);
290     return HDF_SUCCESS;
291 }
292 
EffectModelGetEffectDescriptor(struct IEffectModel * self,const char * uuid,struct EffectControllerDescriptor * desc)293 static int32_t EffectModelGetEffectDescriptor(struct IEffectModel *self, const char *uuid,
294     struct EffectControllerDescriptor *desc)
295 {
296     HDF_LOGD("enter to %{public}s", __func__);
297     uint32_t i;
298     struct EffectFactory *factLib = NULL;
299     struct ControllerManager *ctrlMgr = NULL;
300     if (self == NULL || uuid == NULL || desc == NULL) {
301         HDF_LOGE("%{public}s: invailid input params", __func__);
302         return HDF_ERR_INVALID_PARAM;
303     }
304     struct EffectControllerDescriptorVdi *descVdi = (struct EffectControllerDescriptorVdi *)desc;
305     for (i = 0; i < g_cfgDescs->effectNum; i++) {
306         if (strcmp(uuid, g_cfgDescs->effectCfgDescs[i].effectId) != 0) {
307             continue;
308         }
309 
310         LoadEffectLibrary(g_cfgDescs->effectCfgDescs[i].library, &factLib, &ctrlMgr);
311         if (factLib == NULL) {
312             HDF_LOGE("%{public}s: GetEffectLibFromList fail!", __func__);
313             return HDF_FAILURE;
314         }
315         if (ConstructDescriptor(descVdi) != HDF_SUCCESS) {
316             HDF_LOGE("%{public}s: ConstructDescriptor fail!", __func__);
317             return HDF_FAILURE;
318         }
319         if (factLib->GetDescriptor(factLib, uuid, descVdi) != HDF_SUCCESS) {
320             DeleteEffectLibrary(g_cfgDescs->effectCfgDescs[i].library);
321             HDF_LOGE("%{public}s: GetDescriptor fail!", __func__);
322             return HDF_FAILURE;
323         }
324         DeleteEffectLibrary(g_cfgDescs->effectCfgDescs[i].library);
325         HDF_LOGD("%{public}s success", __func__);
326         return HDF_SUCCESS;
327     }
328     desc = (struct EffectControllerDescriptor *)descVdi;
329     HDF_LOGE("%{public}s fail!", __func__);
330     return HDF_FAILURE;
331 }
332 
CreateEffectController(const struct EffectInfo * info,struct IEffectControl ** contoller,struct ControllerId * contollerId,struct IEffectControlVdi * ctrlOps)333 static int32_t CreateEffectController(const struct EffectInfo *info, struct IEffectControl **contoller,
334     struct ControllerId *contollerId, struct IEffectControlVdi *ctrlOps)
335 {
336     if (info == NULL || contoller == NULL || contollerId == NULL) {
337         HDF_LOGE("%{public}s: invailid input params", __func__);
338         return HDF_ERR_INVALID_PARAM;
339     }
340     struct ControllerManager *ctrlMgr = (struct ControllerManager *)OsalMemCalloc(sizeof(struct ControllerManager));
341     CHECK_NULL_PTR_RETURN_VALUE(ctrlMgr, HDF_FAILURE);
342     pthread_rwlock_rdlock(&g_rwEffectLock);
343     struct AudioEffectLibInfo *libInfo = GetEffectLibInfoByName(info->libName);
344     if (libInfo == NULL) {
345         HDF_LOGE("%{public}s: GetEffectLibInfoByName failed", __func__);
346         OsalMemFree(ctrlMgr);
347         pthread_rwlock_unlock(&g_rwEffectLock);
348         return HDF_FAILURE;
349     }
350     libInfo->ctrlMgr = ctrlMgr;
351     pthread_rwlock_unlock(&g_rwEffectLock);
352     ctrlMgr->ctrlOps = ctrlOps;
353     ctrlMgr->libName = strdup(info->libName);
354     if (ctrlMgr->libName == NULL) {
355         HDF_LOGE("%{public}s: strdup failed, info->effectId = %{public}s", __func__, info->effectId);
356         OsalMemFree(ctrlMgr);
357         return HDF_FAILURE;
358     }
359     ctrlMgr->ctrlImpls.EffectProcess = EffectControlEffectProcess;
360     ctrlMgr->ctrlImpls.SendCommand = EffectControlSendCommand;
361     ctrlMgr->ctrlImpls.GetEffectDescriptor = EffectGetOwnDescriptor;
362     ctrlMgr->ctrlImpls.EffectReverse = EffectControlEffectReverse;
363     *contoller = &ctrlMgr->ctrlImpls;
364     // free after send reply
365     contollerId->libName = strdup(info->libName);
366     contollerId->effectId = strdup(info->effectId);
367     if (contollerId->libName == NULL || contollerId->effectId == NULL) {
368         HDF_LOGE("%{public}s: strdup failed, info->libName = %{public}s", __func__, info->libName);
369         OsalMemFree(ctrlMgr->libName);
370         OsalMemFree(ctrlMgr);
371         *contoller = NULL;
372         return HDF_FAILURE;
373     }
374     return HDF_SUCCESS;
375 }
376 
EffectModelCreateEffectController(struct IEffectModel * self,const struct EffectInfo * info,struct IEffectControl ** contoller,struct ControllerId * contollerId)377 static int32_t EffectModelCreateEffectController(struct IEffectModel *self, const struct EffectInfo *info,
378     struct IEffectControl **contoller, struct ControllerId *contollerId)
379 {
380     if (self == NULL || info == NULL || contoller == NULL || contollerId == NULL) {
381         HDF_LOGE("%{public}s: invailid input params", __func__);
382         return HDF_ERR_INVALID_PARAM;
383     }
384     if (IsSupplyEffect(info->libName) != HDF_SUCCESS) {
385         HDF_LOGE("%{public}s: not support effect [%{public}s]", __func__, info->libName);
386         return HDF_FAILURE;
387     }
388     struct EffectFactory *lib = NULL;
389     struct ControllerManager *ctrlMgr = NULL;
390     struct IEffectControlVdi *ctrlOps = NULL;
391 
392     int32_t ret = LoadEffectLibrary(info->libName, &lib, &ctrlMgr);
393     if (ret != HDF_SUCCESS) {
394         HDF_LOGE("%{public}s: LoadEffectLibrary fail", __func__);
395         return HDF_FAILURE;
396     }
397     if (ctrlMgr != NULL) {
398         contollerId->libName = strdup(info->libName);
399         contollerId->effectId = strdup(info->effectId);
400         if (contollerId->libName == NULL || contollerId->effectId == NULL) {
401             HDF_LOGE("%{public}s: strdup failed", __func__);
402             return HDF_FAILURE;
403         }
404         *contoller = &ctrlMgr->ctrlImpls;
405         return HDF_SUCCESS;
406     }
407     CHECK_NULL_PTR_RETURN_VALUE(lib, HDF_FAILURE);
408     CHECK_NULL_PTR_RETURN_VALUE(lib->CreateController, HDF_FAILURE);
409 
410     struct EffectInfoVdi *infoVdi = (struct EffectInfoVdi *)info;
411     lib->CreateController(lib, infoVdi, &ctrlOps);
412     CHECK_NULL_PTR_RETURN_VALUE(ctrlOps, HDF_FAILURE);
413 
414     ret = CreateEffectController(info, contoller, contollerId, ctrlOps);
415     if (ret != HDF_SUCCESS) {
416         DeleteEffectLibrary(info->libName);
417         return HDF_FAILURE;
418     }
419 
420     HDF_LOGI("%{public}s: create effect succeed, libName = %{public}s", __func__, info->libName);
421     return HDF_SUCCESS;
422 }
423 
EffectModelDestroyEffectController(struct IEffectModel * self,const struct ControllerId * contollerId)424 int32_t EffectModelDestroyEffectController(struct IEffectModel *self, const struct ControllerId *contollerId)
425 {
426     if (self == NULL || contollerId == NULL) {
427         HDF_LOGE("%{public}s: invailid input params", __func__);
428         return HDF_ERR_INVALID_PARAM;
429     }
430     pthread_rwlock_rdlock(&g_rwEffectLock);
431     struct AudioEffectLibInfo *libInfo = GetEffectLibInfoByName(contollerId->libName);
432     if (libInfo == NULL) {
433         HDF_LOGE("%{public}s: GetEffectLibInfoByName failed", __func__);
434         pthread_rwlock_unlock(&g_rwEffectLock);
435         return HDF_FAILURE;
436     }
437     if (libInfo->effectCnt > 1) {
438         libInfo->effectCnt--;
439         pthread_rwlock_unlock(&g_rwEffectLock);
440         return HDF_SUCCESS;
441     }
442     struct EffectFactory *lib = libInfo->libEffect;
443     if (lib == NULL) {
444         HDF_LOGE("%{public}s: lib is null", __func__);
445         pthread_rwlock_unlock(&g_rwEffectLock);
446         return HDF_FAILURE;
447     }
448     struct ControllerManager *ctrlMgr = libInfo->ctrlMgr;
449     pthread_rwlock_unlock(&g_rwEffectLock);
450     CHECK_NULL_PTR_RETURN_VALUE(ctrlMgr, HDF_FAILURE);
451 
452     if (ctrlMgr->libName != NULL) {
453         OsalMemFree(ctrlMgr->libName);
454         ctrlMgr->libName = NULL;
455     }
456 
457     if (ctrlMgr->ctrlOps == NULL) {
458         HDF_LOGE("%{public}s: controller has no options", __func__);
459         return HDF_FAILURE;
460     }
461 
462     /* call the lib destroy method,then free controller manager */
463     lib->DestroyController(lib, ctrlMgr->ctrlOps);
464     DeleteEffectLibrary(contollerId->libName);
465     HDF_LOGI("%{public}s: destroy effect succeed, libName = %{public}s", __func__, contollerId->libName);
466     return HDF_SUCCESS;
467 }
468 
ModelInit(void)469 void ModelInit(void)
470 {
471     FILE *file;
472     struct ConfigDescriptor *cfgDesc = NULL;
473     int32_t ret;
474     file = fopen(AUDIO_EFFECT_PRODUCT_CONFIG, "r");
475     if (file == NULL) {
476         ret = AudioEffectGetConfigDescriptor(AUDIO_EFFECT_PLAFORM_CONFIG, &cfgDesc);
477         HDF_LOGI("%{public}s: %{public}s!", __func__, AUDIO_EFFECT_PLAFORM_CONFIG);
478     } else {
479         ret = AudioEffectGetConfigDescriptor(AUDIO_EFFECT_PRODUCT_CONFIG, &cfgDesc);
480         HDF_LOGI("%{public}s: %{public}s!", __func__, AUDIO_EFFECT_PRODUCT_CONFIG);
481         (void)fclose(file);
482     }
483     if (ret != HDF_SUCCESS) {
484         HDF_LOGE("%{public}s: AudioEffectGetConfigDescriptor fail!", __func__);
485         return;
486     }
487 
488     if (cfgDesc == NULL || cfgDesc->effectCfgDescs == NULL || cfgDesc->libCfgDescs == NULL) {
489         HDF_LOGE("cfgDesc is null!");
490         return;
491     }
492     g_cfgDescs = cfgDesc;
493     HDF_LOGD("%{public}s end!", __func__);
494 }
495 
EffectModelImplGetInstance(void)496 struct IEffectModel *EffectModelImplGetInstance(void)
497 {
498     struct EffectModelService *service = (struct EffectModelService *)OsalMemCalloc(sizeof(struct EffectModelService));
499     if (service == NULL) {
500         HDF_LOGE("%{public}s: malloc EffectModelService obj failed!", __func__);
501         return NULL;
502     }
503 
504     ModelInit();
505     service->interface.IsSupplyEffectLibs = EffectModelIsSupplyEffectLibs;
506     service->interface.GetAllEffectDescriptors = EffectModelGetAllEffectDescriptors;
507     service->interface.CreateEffectController = EffectModelCreateEffectController;
508     service->interface.DestroyEffectController = EffectModelDestroyEffectController;
509     service->interface.GetEffectDescriptor = EffectModelGetEffectDescriptor;
510 
511     return &service->interface;
512 }
513 
EffectModelImplRelease(struct IEffectModel * instance)514 void EffectModelImplRelease(struct IEffectModel *instance)
515 {
516     if (instance == NULL) {
517         return;
518     }
519 
520     AudioEffectReleaseCfgDesc(g_cfgDescs);
521     struct EffectModelService *service = CONTAINER_OF(instance, struct EffectModelService, interface);
522     if (service == NULL) {
523         return;
524     }
525     OsalMemFree(service);
526     service = NULL;
527 }
528