• 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 
16 /**
17  * @addtogroup Effect
18  * @{
19  *
20  * @brief defines the effect core methods
21  *
22  * @since 4.0
23  * @version 1.0
24  */
25 
26 #include "effect_core.h"
27 #include "hdf_base.h"
28 #include "osal_mem.h"
29 #include "audio_uhdf_log.h"
30 
31 #define HDF_LOG_TAG HDF_AUDIO_EFFECT
32 
33 /* list to manager the effect factory libs */
34 AEM_GET_INITED_DLIST(g_libList);
35 
36 /* list to manager the effect controller */
37 AEM_GET_INITED_DLIST(g_controllerList);
38 
39 /* reist the effect lib */
RegisterEffectLibToList(void * handle,struct EffectFactory * factLib)40 int32_t RegisterEffectLibToList(void *handle, struct EffectFactory *factLib)
41 {
42     struct EffectFactoryLibListNode *node = NULL;
43     if (factLib == NULL) {
44         HDF_LOGE("%{public}s: input params is null", __func__);
45         return HDF_FAILURE;
46     }
47 
48     node = (struct EffectFactoryLibListNode *)OsalMemCalloc(sizeof(struct EffectFactoryLibListNode));
49     if (node == NULL) {
50         HDF_LOGE("%{public}s: memlloc failed", __func__);
51         return HDF_FAILURE;
52     }
53 
54     node->factLib = factLib;
55     node->handle = handle;
56     DListInsertHead(&node->list, &g_libList);
57 
58     return HDF_SUCCESS;
59 }
60 
61 // release the effect lib using at the release process
ReleaseLibFromList(void)62 void ReleaseLibFromList(void)
63 {
64     struct EffectFactoryLibListNode *targetNode;
65     struct EffectFactoryLibListNode *tmpNode;
66 
67     DLIST_FOR_EACH_ENTRY_SAFE(targetNode, tmpNode, &g_libList, struct EffectFactoryLibListNode, list) {
68         DListRemove(&targetNode->list);
69         dlclose(targetNode->handle);
70         OsalMemFree(targetNode);
71     }
72 
73     HDF_LOGI("lib remove from the list successfully");
74 }
75 
76 // get the lib by libname
GetEffectLibFromList(const char * effectLibName)77 struct EffectFactory *GetEffectLibFromList(const char *effectLibName)
78 {
79     struct EffectFactoryLibListNode *tmpNode = NULL;
80     if (effectLibName == NULL) {
81         HDF_LOGE("effectLibName is NULL.");
82         return NULL;
83     }
84 
85     if (DListIsEmpty(&g_libList)) {
86         HDF_LOGE("g_libList is empty.");
87         return NULL;
88     }
89 
90     DLIST_FOR_EACH_ENTRY(tmpNode, &g_libList, struct EffectFactoryLibListNode, list) {
91         if (tmpNode->factLib != NULL && tmpNode->factLib->effectLibName != NULL) {
92             if (strcmp(tmpNode->factLib->effectLibName, effectLibName) == 0) {
93                 return tmpNode->factLib;
94             }
95         }
96     }
97 
98     HDF_LOGE("effectLibName %{public}s not exit in list", effectLibName);
99     return NULL;
100 }
101 
IsEffectLibExist(void)102 bool IsEffectLibExist(void)
103 {
104     bool isSupply = true;
105 
106     if (DListIsEmpty(&g_libList)) {
107         HDF_LOGE("effect lib list is empty, no effect lib");
108         isSupply = false;
109     }
110 
111     return isSupply;
112 }
113 
114 
115 // effect controller;
RegisterControllerToList(struct ControllerManager * ctrlMgr)116 int32_t RegisterControllerToList(struct ControllerManager *ctrlMgr)
117 {
118     struct ControllerManagerNode *node = NULL;
119     if (ctrlMgr == NULL) {
120         HDF_LOGE("%{public}s: input params is null", __func__);
121         return HDF_FAILURE;
122     }
123 
124     node = (struct ControllerManagerNode *)OsalMemCalloc(sizeof(struct ControllerManagerNode));
125     if (node == NULL) {
126         HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__);
127         return HDF_FAILURE;
128     }
129 
130     node->ctrlMgr = ctrlMgr;
131     DListInsertHead(&node->list, &g_controllerList);
132 
133     return HDF_SUCCESS;
134 }
135 
136 // get the contoller using at the desroy process
GetControllerFromList(char * effectId)137 struct ControllerManager *GetControllerFromList(char *effectId)
138 {
139     struct ControllerManagerNode *getNode = NULL;
140     struct ControllerManagerNode *tmpNode = NULL;
141     struct ControllerManager *ctrlMgr = NULL;
142     if (effectId == NULL) {
143         HDF_LOGE("effectLibName is NULL.");
144         return NULL;
145     }
146 
147     if (DListIsEmpty(&g_controllerList)) {
148         HDF_LOGE("g_controllerList is empty.");
149         return NULL;
150     }
151     // get the ctrlMgr and remove it from the list and release the node
152     DLIST_FOR_EACH_ENTRY_SAFE(getNode, tmpNode, &g_controllerList, struct ControllerManagerNode, list) {
153         if (getNode->ctrlMgr != NULL && getNode->ctrlMgr->effectId != NULL) {
154             if (strcmp(getNode->ctrlMgr->effectId, effectId) == 0) {
155                 ctrlMgr = getNode->ctrlMgr;
156                 DListRemove(&getNode->list);
157                 OsalMemFree(getNode);
158                 return ctrlMgr;
159             }
160         }
161     }
162 
163     HDF_LOGE("effectId %s not exit in list", effectId);
164     return NULL;
165 }
166