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 #include "effect_host_common.h"
17
18 #include "hdf_base.h"
19 #include "v1_0/effect_types.h"
20 #include "v1_0/effect_types_vdi.h"
21 #include "v1_0/ieffect_control_vdi.h"
22 #include "audio_uhdf_log.h"
23 #include "osal_mem.h"
24 #include "effect_core.h"
25
26 #define HDF_LOG_TAG HDF_AUDIO_EFFECT
27
EffectControlEffectProcess(struct IEffectControl * self,const struct AudioEffectBuffer * input,struct AudioEffectBuffer * output)28 int32_t EffectControlEffectProcess(struct IEffectControl *self, const struct AudioEffectBuffer *input,
29 struct AudioEffectBuffer *output)
30 {
31 if (self == NULL || input == NULL || output == NULL) {
32 HDF_LOGE("%{public}s: invailid input params", __func__);
33 return HDF_ERR_INVALID_PARAM;
34 }
35
36 struct ControllerManager *manager = (struct ControllerManager *)self;
37 if (manager->ctrlOps == NULL || manager->ctrlOps->EffectProcess == NULL) {
38 HDF_LOGE("%{public}s: controller has no options", __func__);
39 return HDF_FAILURE;
40 }
41 if (strcmp(manager->libName, "libmock_effect_lib") != 0) {
42 output->frameCount = input->frameCount;
43 output->datatag = input->datatag;
44 output->rawDataLen = input->rawDataLen;
45 output->rawData = (int8_t *)OsalMemCalloc(sizeof(int8_t) * output->rawDataLen);
46 if (output->rawData == NULL) {
47 HDF_LOGE("%{public}s: OsalMemCalloc fail", __func__);
48 return HDF_FAILURE;
49 }
50 }
51 struct AudioEffectBufferVdi *inputVdi = (struct AudioEffectBufferVdi *)input;
52 struct AudioEffectBufferVdi *outputVdi = (struct AudioEffectBufferVdi *)output;
53 int32_t ret = manager->ctrlOps->EffectProcess(manager->ctrlOps, inputVdi, outputVdi);
54 if (ret != HDF_SUCCESS) {
55 HDF_LOGE("AudioEffectProcess failed, ret=%{public}d", ret);
56 return ret;
57 }
58
59 output = (struct AudioEffectBuffer *)outputVdi;
60 return ret;
61 }
62
EffectControlSendCommand(struct IEffectControl * self,enum EffectCommandTableIndex cmdId,const int8_t * cmdData,uint32_t cmdDataLen,int8_t * replyData,uint32_t * replyDataLen)63 int32_t EffectControlSendCommand(struct IEffectControl *self, enum EffectCommandTableIndex cmdId, const int8_t *cmdData,
64 uint32_t cmdDataLen, int8_t *replyData, uint32_t *replyDataLen)
65 {
66 if (self == NULL || cmdData == NULL || replyData == NULL || replyDataLen == NULL) {
67 HDF_LOGE("%{public}s: invailid input params", __func__);
68 return HDF_ERR_INVALID_PARAM;
69 }
70
71 struct ControllerManager *manager = (struct ControllerManager *)self;
72 if (manager->ctrlOps == NULL || manager->ctrlOps->SendCommand == NULL) {
73 HDF_LOGE("%{public}s: controller has no options", __func__);
74 return HDF_FAILURE;
75 }
76 enum EffectCommandTableIndexVdi cmdIdVdi = (enum EffectCommandTableIndexVdi)cmdId;
77 int32_t ret = manager->ctrlOps->SendCommand(manager->ctrlOps, cmdIdVdi, (void *)cmdData, cmdDataLen,
78 (void *)replyData, replyDataLen);
79 if (ret != HDF_SUCCESS) {
80 HDF_LOGE("SendCommand failed, ret=%{public}d", ret);
81 return ret;
82 }
83 return ret;
84 }
85
EffectGetOwnDescriptor(struct IEffectControl * self,struct EffectControllerDescriptor * desc)86 int32_t EffectGetOwnDescriptor(struct IEffectControl *self, struct EffectControllerDescriptor *desc)
87 {
88 if (self == NULL || desc == NULL) {
89 HDF_LOGE("%{public}s: invailid input params", __func__);
90 return HDF_ERR_INVALID_PARAM;
91 }
92
93 struct ControllerManager *manager = (struct ControllerManager *)self;
94 if (manager->ctrlOps == NULL || manager->ctrlOps->GetEffectDescriptor == NULL) {
95 HDF_LOGE("%{public}s: controller has no options", __func__);
96 return HDF_FAILURE;
97 }
98 struct EffectControllerDescriptorVdi *descVdi = (struct EffectControllerDescriptorVdi *)desc;
99 if (ConstructDescriptor(descVdi) != HDF_SUCCESS) {
100 HDF_LOGE("%{public}s: ConstructDescriptor fail!", __func__);
101 return HDF_FAILURE;
102 }
103 int32_t ret = manager->ctrlOps->GetEffectDescriptor(manager->ctrlOps, descVdi);
104 if (ret != HDF_SUCCESS) {
105 HDF_LOGE("EffectGetOwnDescriptor failed, ret=%{public}d", ret);
106 return ret;
107 }
108
109 desc = (struct EffectControllerDescriptor *)descVdi;
110 return ret;
111 }
112
EffectControlEffectReverse(struct IEffectControl * self,const struct AudioEffectBuffer * input,struct AudioEffectBuffer * output)113 int32_t EffectControlEffectReverse(struct IEffectControl *self, const struct AudioEffectBuffer *input,
114 struct AudioEffectBuffer *output)
115 {
116 if (self == NULL || input == NULL || output == NULL) {
117 HDF_LOGE("%{public}s: invailid input params", __func__);
118 return HDF_ERR_INVALID_PARAM;
119 }
120
121 struct ControllerManager *manager = (struct ControllerManager *)self;
122 if (manager->ctrlOps == NULL || manager->ctrlOps->EffectReverse == NULL) {
123 HDF_LOGE("%{public}s: controller has no options", __func__);
124 return HDF_FAILURE;
125 }
126 struct AudioEffectBufferVdi *inputVdi = (struct AudioEffectBufferVdi *)input;
127 struct AudioEffectBufferVdi *outputVdi = (struct AudioEffectBufferVdi *)output;
128 int32_t ret = manager->ctrlOps->EffectReverse(manager->ctrlOps, inputVdi, outputVdi);
129 if (ret != HDF_SUCCESS) {
130 HDF_LOGE("EffectReverse failed, ret=%{public}d", ret);
131 return ret;
132 }
133 output = (struct AudioEffectBuffer *)outputVdi;
134 return ret;
135 }
136