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
24 #define HDF_LOG_TAG HDF_AUDIO_EFFECT
25
EffectControlEffectProcess(struct IEffectControl *self, const struct AudioEffectBuffer *input, struct AudioEffectBuffer *output)26 int32_t EffectControlEffectProcess(struct IEffectControl *self, const struct AudioEffectBuffer *input,
27 struct AudioEffectBuffer *output)
28 {
29 if (self == NULL || input == NULL || output == NULL) {
30 HDF_LOGE("%{public}s: invailid input params", __func__);
31 return HDF_ERR_INVALID_PARAM;
32 }
33
34 struct ControllerManager *manager = (struct ControllerManager *)self;
35 if (manager->ctrlOps == NULL || manager->ctrlOps->EffectProcess == NULL) {
36 HDF_LOGE("%{public}s: controller has no options", __func__);
37 return HDF_FAILURE;
38 }
39
40 struct AudioEffectBufferVdi *inputVdi = (struct AudioEffectBufferVdi *)input;
41 struct AudioEffectBufferVdi *outputVdi = (struct AudioEffectBufferVdi *)output;
42 int32_t ret = manager->ctrlOps->EffectProcess(manager->ctrlOps, inputVdi, outputVdi);
43 if (ret != HDF_SUCCESS) {
44 HDF_LOGE("AudioEffectProcess failed, ret=%{public}d", ret);
45 return ret;
46 }
47
48 output = (struct AudioEffectBuffer *)outputVdi;
49 return ret;
50 }
51
EffectControlSendCommand(struct IEffectControl *self, enum EffectCommandTableIndex cmdId, const int8_t *cmdData, uint32_t cmdDataLen, int8_t *replyData, uint32_t *replyDataLen)52 int32_t EffectControlSendCommand(struct IEffectControl *self, enum EffectCommandTableIndex cmdId, const int8_t *cmdData,
53 uint32_t cmdDataLen, int8_t *replyData, uint32_t *replyDataLen)
54 {
55 if (self == NULL || cmdData == NULL || replyData == NULL || replyDataLen == NULL) {
56 HDF_LOGE("%{public}s: invailid input params", __func__);
57 return HDF_ERR_INVALID_PARAM;
58 }
59
60 struct ControllerManager *manager = (struct ControllerManager *)self;
61 if (manager->ctrlOps == NULL || manager->ctrlOps->SendCommand == NULL) {
62 HDF_LOGE("%{public}s: controller has no options", __func__);
63 return HDF_FAILURE;
64 }
65 enum EffectCommandTableIndexVdi cmdIdVdi = (enum EffectCommandTableIndexVdi)cmdId;
66 int32_t ret = manager->ctrlOps->SendCommand(manager->ctrlOps, cmdIdVdi, (void *)cmdData, cmdDataLen,
67 (void *)replyData, replyDataLen);
68 if (ret != HDF_SUCCESS) {
69 HDF_LOGE("SendCommand failed, ret=%{public}d", ret);
70 return ret;
71 }
72 return ret;
73 }
74
EffectGetOwnDescriptor(struct IEffectControl *self, struct EffectControllerDescriptor *desc)75 int32_t EffectGetOwnDescriptor(struct IEffectControl *self, struct EffectControllerDescriptor *desc)
76 {
77 if (self == NULL || desc == NULL) {
78 HDF_LOGE("%{public}s: invailid input params", __func__);
79 return HDF_ERR_INVALID_PARAM;
80 }
81
82 struct ControllerManager *manager = (struct ControllerManager *)self;
83 if (manager->ctrlOps == NULL || manager->ctrlOps->GetEffectDescriptor == NULL) {
84 HDF_LOGE("%{public}s: controller has no options", __func__);
85 return HDF_FAILURE;
86 }
87 struct EffectControllerDescriptorVdi *descVdi = (struct EffectControllerDescriptorVdi *)desc;
88 int32_t ret = manager->ctrlOps->GetEffectDescriptor(manager->ctrlOps, descVdi);
89 if (ret != HDF_SUCCESS) {
90 HDF_LOGE("EffectGetOwnDescriptor failed, ret=%{public}d", ret);
91 return ret;
92 }
93
94 desc = (struct EffectControllerDescriptor *)descVdi;
95 return ret;
96 }
97
EffectControlEffectReverse(struct IEffectControl *self, const struct AudioEffectBuffer *input, struct AudioEffectBuffer *output)98 int32_t EffectControlEffectReverse(struct IEffectControl *self, const struct AudioEffectBuffer *input,
99 struct AudioEffectBuffer *output)
100 {
101 if (self == NULL || input == NULL || output == NULL) {
102 HDF_LOGE("%{public}s: invailid input params", __func__);
103 return HDF_ERR_INVALID_PARAM;
104 }
105
106 struct ControllerManager *manager = (struct ControllerManager *)self;
107 if (manager->ctrlOps == NULL || manager->ctrlOps->EffectReverse == NULL) {
108 HDF_LOGE("%{public}s: controller has no options", __func__);
109 return HDF_FAILURE;
110 }
111 struct AudioEffectBufferVdi *inputVdi = (struct AudioEffectBufferVdi *)input;
112 struct AudioEffectBufferVdi *outputVdi = (struct AudioEffectBufferVdi *)output;
113 int32_t ret = manager->ctrlOps->EffectReverse(manager->ctrlOps, inputVdi, outputVdi);
114 if (ret != HDF_SUCCESS) {
115 HDF_LOGE("EffectReverse failed, ret=%{public}d", ret);
116 return ret;
117 }
118 output = (struct AudioEffectBuffer *)outputVdi;
119 return ret;
120 }
121