1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "AEC_Effect_HAL"
18
19 #include "AcousticEchoCancelerEffect.h"
20
21 #include <android/log.h>
22 #include <system/audio_effects/effect_aec.h>
23
24 #include "VersionUtils.h"
25
26 namespace android {
27 namespace hardware {
28 namespace audio {
29 namespace effect {
30 namespace CPP_VERSION {
31 namespace implementation {
32
AcousticEchoCancelerEffect(effect_handle_t handle)33 AcousticEchoCancelerEffect::AcousticEchoCancelerEffect(effect_handle_t handle)
34 : mEffect(new Effect(true /*isInput*/, handle)) {}
35
36 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
init()37 Return<Result> AcousticEchoCancelerEffect::init() {
38 return mEffect->init();
39 }
40
setConfig(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)41 Return<Result> AcousticEchoCancelerEffect::setConfig(
42 const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
43 const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
44 return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider);
45 }
46
reset()47 Return<Result> AcousticEchoCancelerEffect::reset() {
48 return mEffect->reset();
49 }
50
enable()51 Return<Result> AcousticEchoCancelerEffect::enable() {
52 return mEffect->enable();
53 }
54
disable()55 Return<Result> AcousticEchoCancelerEffect::disable() {
56 return mEffect->disable();
57 }
58
59 #if MAJOR_VERSION <= 6
setAudioSource(AudioSource source)60 Return<Result> AcousticEchoCancelerEffect::setAudioSource(AudioSource source) {
61 return mEffect->setAudioSource(source);
62 }
63
setDevice(AudioDeviceBitfield device)64 Return<Result> AcousticEchoCancelerEffect::setDevice(AudioDeviceBitfield device) {
65 return mEffect->setDevice(device);
66 }
67
setInputDevice(AudioDeviceBitfield device)68 Return<Result> AcousticEchoCancelerEffect::setInputDevice(AudioDeviceBitfield device) {
69 return mEffect->setInputDevice(device);
70 }
71 #else
setAudioSource(const AudioSource & source)72 Return<Result> AcousticEchoCancelerEffect::setAudioSource(const AudioSource& source) {
73 return mEffect->setAudioSource(source);
74 }
75
setDevice(const DeviceAddress & device)76 Return<Result> AcousticEchoCancelerEffect::setDevice(const DeviceAddress& device) {
77 return mEffect->setDevice(device);
78 }
79
setInputDevice(const DeviceAddress & device)80 Return<Result> AcousticEchoCancelerEffect::setInputDevice(const DeviceAddress& device) {
81 return mEffect->setInputDevice(device);
82 }
83 #endif
84
setAndGetVolume(const hidl_vec<uint32_t> & volumes,setAndGetVolume_cb _hidl_cb)85 Return<void> AcousticEchoCancelerEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
86 setAndGetVolume_cb _hidl_cb) {
87 return mEffect->setAndGetVolume(volumes, _hidl_cb);
88 }
89
volumeChangeNotification(const hidl_vec<uint32_t> & volumes)90 Return<Result> AcousticEchoCancelerEffect::volumeChangeNotification(
91 const hidl_vec<uint32_t>& volumes) {
92 return mEffect->volumeChangeNotification(volumes);
93 }
94
setAudioMode(AudioMode mode)95 Return<Result> AcousticEchoCancelerEffect::setAudioMode(AudioMode mode) {
96 return mEffect->setAudioMode(mode);
97 }
98
setConfigReverse(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)99 Return<Result> AcousticEchoCancelerEffect::setConfigReverse(
100 const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
101 const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
102 return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
103 }
104
getConfig(getConfig_cb _hidl_cb)105 Return<void> AcousticEchoCancelerEffect::getConfig(getConfig_cb _hidl_cb) {
106 return mEffect->getConfig(_hidl_cb);
107 }
108
getConfigReverse(getConfigReverse_cb _hidl_cb)109 Return<void> AcousticEchoCancelerEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) {
110 return mEffect->getConfigReverse(_hidl_cb);
111 }
112
getSupportedAuxChannelsConfigs(uint32_t maxConfigs,getSupportedAuxChannelsConfigs_cb _hidl_cb)113 Return<void> AcousticEchoCancelerEffect::getSupportedAuxChannelsConfigs(
114 uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) {
115 return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb);
116 }
117
getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb)118 Return<void> AcousticEchoCancelerEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) {
119 return mEffect->getAuxChannelsConfig(_hidl_cb);
120 }
121
setAuxChannelsConfig(const EffectAuxChannelsConfig & config)122 Return<Result> AcousticEchoCancelerEffect::setAuxChannelsConfig(
123 const EffectAuxChannelsConfig& config) {
124 return mEffect->setAuxChannelsConfig(config);
125 }
126
offload(const EffectOffloadParameter & param)127 Return<Result> AcousticEchoCancelerEffect::offload(const EffectOffloadParameter& param) {
128 return mEffect->offload(param);
129 }
130
getDescriptor(getDescriptor_cb _hidl_cb)131 Return<void> AcousticEchoCancelerEffect::getDescriptor(getDescriptor_cb _hidl_cb) {
132 return mEffect->getDescriptor(_hidl_cb);
133 }
134
prepareForProcessing(prepareForProcessing_cb _hidl_cb)135 Return<void> AcousticEchoCancelerEffect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) {
136 return mEffect->prepareForProcessing(_hidl_cb);
137 }
138
setProcessBuffers(const AudioBuffer & inBuffer,const AudioBuffer & outBuffer)139 Return<Result> AcousticEchoCancelerEffect::setProcessBuffers(const AudioBuffer& inBuffer,
140 const AudioBuffer& outBuffer) {
141 return mEffect->setProcessBuffers(inBuffer, outBuffer);
142 }
143
command(uint32_t commandId,const hidl_vec<uint8_t> & data,uint32_t resultMaxSize,command_cb _hidl_cb)144 Return<void> AcousticEchoCancelerEffect::command(uint32_t commandId, const hidl_vec<uint8_t>& data,
145 uint32_t resultMaxSize, command_cb _hidl_cb) {
146 return mEffect->command(commandId, data, resultMaxSize, _hidl_cb);
147 }
148
setParameter(const hidl_vec<uint8_t> & parameter,const hidl_vec<uint8_t> & value)149 Return<Result> AcousticEchoCancelerEffect::setParameter(const hidl_vec<uint8_t>& parameter,
150 const hidl_vec<uint8_t>& value) {
151 return mEffect->setParameter(parameter, value);
152 }
153
getParameter(const hidl_vec<uint8_t> & parameter,uint32_t valueMaxSize,getParameter_cb _hidl_cb)154 Return<void> AcousticEchoCancelerEffect::getParameter(const hidl_vec<uint8_t>& parameter,
155 uint32_t valueMaxSize,
156 getParameter_cb _hidl_cb) {
157 return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb);
158 }
159
getSupportedConfigsForFeature(uint32_t featureId,uint32_t maxConfigs,uint32_t configSize,getSupportedConfigsForFeature_cb _hidl_cb)160 Return<void> AcousticEchoCancelerEffect::getSupportedConfigsForFeature(
161 uint32_t featureId, uint32_t maxConfigs, uint32_t configSize,
162 getSupportedConfigsForFeature_cb _hidl_cb) {
163 return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb);
164 }
165
getCurrentConfigForFeature(uint32_t featureId,uint32_t configSize,getCurrentConfigForFeature_cb _hidl_cb)166 Return<void> AcousticEchoCancelerEffect::getCurrentConfigForFeature(
167 uint32_t featureId, uint32_t configSize, getCurrentConfigForFeature_cb _hidl_cb) {
168 return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb);
169 }
170
setCurrentConfigForFeature(uint32_t featureId,const hidl_vec<uint8_t> & configData)171 Return<Result> AcousticEchoCancelerEffect::setCurrentConfigForFeature(
172 uint32_t featureId, const hidl_vec<uint8_t>& configData) {
173 return mEffect->setCurrentConfigForFeature(featureId, configData);
174 }
175
close()176 Return<Result> AcousticEchoCancelerEffect::close() {
177 return mEffect->close();
178 }
179
debug(const hidl_handle & fd,const hidl_vec<hidl_string> & options)180 Return<void> AcousticEchoCancelerEffect::debug(const hidl_handle& fd,
181 const hidl_vec<hidl_string>& options) {
182 return mEffect->debug(fd, options);
183 }
184
185 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IAcousticEchoCancelerEffect
186 // follow.
setEchoDelay(uint32_t echoDelayMs)187 Return<Result> AcousticEchoCancelerEffect::setEchoDelay(uint32_t echoDelayMs) {
188 return mEffect->setParam(AEC_PARAM_ECHO_DELAY, echoDelayMs);
189 }
190
getEchoDelay(getEchoDelay_cb _hidl_cb)191 Return<void> AcousticEchoCancelerEffect::getEchoDelay(getEchoDelay_cb _hidl_cb) {
192 return mEffect->getIntegerParam(AEC_PARAM_ECHO_DELAY, _hidl_cb);
193 }
194
195 } // namespace implementation
196 } // namespace CPP_VERSION
197 } // namespace effect
198 } // namespace audio
199 } // namespace hardware
200 } // namespace android
201