1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#include "effect_host_common.h"
17094332d3Sopenharmony_ci
18094332d3Sopenharmony_ci#include "hdf_base.h"
19094332d3Sopenharmony_ci#include "v1_0/effect_types.h"
20094332d3Sopenharmony_ci#include "v1_0/effect_types_vdi.h"
21094332d3Sopenharmony_ci#include "v1_0/ieffect_control_vdi.h"
22094332d3Sopenharmony_ci#include "audio_uhdf_log.h"
23094332d3Sopenharmony_ci
24094332d3Sopenharmony_ci#define HDF_LOG_TAG HDF_AUDIO_EFFECT
25094332d3Sopenharmony_ci
26094332d3Sopenharmony_ciint32_t EffectControlEffectProcess(struct IEffectControl *self, const struct AudioEffectBuffer *input,
27094332d3Sopenharmony_ci    struct AudioEffectBuffer *output)
28094332d3Sopenharmony_ci{
29094332d3Sopenharmony_ci    if (self == NULL || input == NULL || output == NULL) {
30094332d3Sopenharmony_ci        HDF_LOGE("%{public}s: invailid input params", __func__);
31094332d3Sopenharmony_ci        return HDF_ERR_INVALID_PARAM;
32094332d3Sopenharmony_ci    }
33094332d3Sopenharmony_ci
34094332d3Sopenharmony_ci    struct ControllerManager *manager = (struct ControllerManager *)self;
35094332d3Sopenharmony_ci    if (manager->ctrlOps == NULL || manager->ctrlOps->EffectProcess == NULL) {
36094332d3Sopenharmony_ci        HDF_LOGE("%{public}s: controller has no options", __func__);
37094332d3Sopenharmony_ci        return HDF_FAILURE;
38094332d3Sopenharmony_ci    }
39094332d3Sopenharmony_ci
40094332d3Sopenharmony_ci    struct AudioEffectBufferVdi *inputVdi = (struct AudioEffectBufferVdi *)input;
41094332d3Sopenharmony_ci    struct AudioEffectBufferVdi *outputVdi = (struct AudioEffectBufferVdi *)output;
42094332d3Sopenharmony_ci    int32_t ret = manager->ctrlOps->EffectProcess(manager->ctrlOps, inputVdi, outputVdi);
43094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
44094332d3Sopenharmony_ci        HDF_LOGE("AudioEffectProcess failed, ret=%{public}d", ret);
45094332d3Sopenharmony_ci        return ret;
46094332d3Sopenharmony_ci    }
47094332d3Sopenharmony_ci
48094332d3Sopenharmony_ci    output = (struct AudioEffectBuffer *)outputVdi;
49094332d3Sopenharmony_ci    return ret;
50094332d3Sopenharmony_ci}
51094332d3Sopenharmony_ci
52094332d3Sopenharmony_ciint32_t EffectControlSendCommand(struct IEffectControl *self, enum EffectCommandTableIndex cmdId, const int8_t *cmdData,
53094332d3Sopenharmony_ci    uint32_t cmdDataLen, int8_t *replyData, uint32_t *replyDataLen)
54094332d3Sopenharmony_ci{
55094332d3Sopenharmony_ci    if (self == NULL || cmdData == NULL || replyData == NULL || replyDataLen == NULL) {
56094332d3Sopenharmony_ci        HDF_LOGE("%{public}s: invailid input params", __func__);
57094332d3Sopenharmony_ci        return HDF_ERR_INVALID_PARAM;
58094332d3Sopenharmony_ci    }
59094332d3Sopenharmony_ci
60094332d3Sopenharmony_ci    struct ControllerManager *manager = (struct ControllerManager *)self;
61094332d3Sopenharmony_ci    if (manager->ctrlOps == NULL || manager->ctrlOps->SendCommand == NULL) {
62094332d3Sopenharmony_ci        HDF_LOGE("%{public}s: controller has no options", __func__);
63094332d3Sopenharmony_ci        return HDF_FAILURE;
64094332d3Sopenharmony_ci    }
65094332d3Sopenharmony_ci    enum EffectCommandTableIndexVdi cmdIdVdi = (enum EffectCommandTableIndexVdi)cmdId;
66094332d3Sopenharmony_ci    int32_t ret = manager->ctrlOps->SendCommand(manager->ctrlOps, cmdIdVdi, (void *)cmdData, cmdDataLen,
67094332d3Sopenharmony_ci                                         (void *)replyData, replyDataLen);
68094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
69094332d3Sopenharmony_ci        HDF_LOGE("SendCommand failed, ret=%{public}d", ret);
70094332d3Sopenharmony_ci        return ret;
71094332d3Sopenharmony_ci    }
72094332d3Sopenharmony_ci    return ret;
73094332d3Sopenharmony_ci}
74094332d3Sopenharmony_ci
75094332d3Sopenharmony_ciint32_t EffectGetOwnDescriptor(struct IEffectControl *self, struct EffectControllerDescriptor *desc)
76094332d3Sopenharmony_ci{
77094332d3Sopenharmony_ci    if (self == NULL || desc == NULL) {
78094332d3Sopenharmony_ci        HDF_LOGE("%{public}s: invailid input params", __func__);
79094332d3Sopenharmony_ci        return HDF_ERR_INVALID_PARAM;
80094332d3Sopenharmony_ci    }
81094332d3Sopenharmony_ci
82094332d3Sopenharmony_ci    struct ControllerManager *manager = (struct ControllerManager *)self;
83094332d3Sopenharmony_ci    if (manager->ctrlOps == NULL || manager->ctrlOps->GetEffectDescriptor == NULL) {
84094332d3Sopenharmony_ci        HDF_LOGE("%{public}s: controller has no options", __func__);
85094332d3Sopenharmony_ci        return HDF_FAILURE;
86094332d3Sopenharmony_ci    }
87094332d3Sopenharmony_ci    struct EffectControllerDescriptorVdi *descVdi = (struct EffectControllerDescriptorVdi *)desc;
88094332d3Sopenharmony_ci    int32_t ret = manager->ctrlOps->GetEffectDescriptor(manager->ctrlOps, descVdi);
89094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
90094332d3Sopenharmony_ci        HDF_LOGE("EffectGetOwnDescriptor failed, ret=%{public}d", ret);
91094332d3Sopenharmony_ci        return ret;
92094332d3Sopenharmony_ci    }
93094332d3Sopenharmony_ci
94094332d3Sopenharmony_ci    desc = (struct EffectControllerDescriptor *)descVdi;
95094332d3Sopenharmony_ci    return ret;
96094332d3Sopenharmony_ci}
97094332d3Sopenharmony_ci
98094332d3Sopenharmony_ciint32_t EffectControlEffectReverse(struct IEffectControl *self, const struct AudioEffectBuffer *input,
99094332d3Sopenharmony_ci    struct AudioEffectBuffer *output)
100094332d3Sopenharmony_ci{
101094332d3Sopenharmony_ci    if (self == NULL || input == NULL || output == NULL) {
102094332d3Sopenharmony_ci        HDF_LOGE("%{public}s: invailid input params", __func__);
103094332d3Sopenharmony_ci        return HDF_ERR_INVALID_PARAM;
104094332d3Sopenharmony_ci    }
105094332d3Sopenharmony_ci
106094332d3Sopenharmony_ci    struct ControllerManager *manager = (struct ControllerManager *)self;
107094332d3Sopenharmony_ci    if (manager->ctrlOps == NULL || manager->ctrlOps->EffectReverse == NULL) {
108094332d3Sopenharmony_ci        HDF_LOGE("%{public}s: controller has no options", __func__);
109094332d3Sopenharmony_ci        return HDF_FAILURE;
110094332d3Sopenharmony_ci    }
111094332d3Sopenharmony_ci    struct AudioEffectBufferVdi *inputVdi = (struct AudioEffectBufferVdi *)input;
112094332d3Sopenharmony_ci    struct AudioEffectBufferVdi *outputVdi = (struct AudioEffectBufferVdi *)output;
113094332d3Sopenharmony_ci    int32_t ret = manager->ctrlOps->EffectReverse(manager->ctrlOps, inputVdi, outputVdi);
114094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
115094332d3Sopenharmony_ci        HDF_LOGE("EffectReverse failed, ret=%{public}d", ret);
116094332d3Sopenharmony_ci        return ret;
117094332d3Sopenharmony_ci    }
118094332d3Sopenharmony_ci    output = (struct AudioEffectBuffer *)outputVdi;
119094332d3Sopenharmony_ci    return ret;
120094332d3Sopenharmony_ci}
121