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 "NS_Effect_HAL"
18
19 #include "NoiseSuppressionEffect.h"
20
21 #include <android/log.h>
22
23 #include "VersionUtils.h"
24
25 namespace android {
26 namespace hardware {
27 namespace audio {
28 namespace effect {
29 namespace CPP_VERSION {
30 namespace implementation {
31
NoiseSuppressionEffect(effect_handle_t handle)32 NoiseSuppressionEffect::NoiseSuppressionEffect(effect_handle_t handle)
33 : mEffect(new Effect(true /*isInput*/, handle)) {}
34
propertiesFromHal(const t_ns_settings & halProperties,INoiseSuppressionEffect::AllProperties * properties)35 void NoiseSuppressionEffect::propertiesFromHal(const t_ns_settings& halProperties,
36 INoiseSuppressionEffect::AllProperties* properties) {
37 properties->level = Level(halProperties.level);
38 properties->type = Type(halProperties.type);
39 }
40
propertiesToHal(const INoiseSuppressionEffect::AllProperties & properties,t_ns_settings * halProperties)41 void NoiseSuppressionEffect::propertiesToHal(
42 const INoiseSuppressionEffect::AllProperties& properties, t_ns_settings* halProperties) {
43 halProperties->level = static_cast<uint32_t>(properties.level);
44 halProperties->type = static_cast<uint32_t>(properties.type);
45 }
46
47 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
init()48 Return<Result> NoiseSuppressionEffect::init() {
49 return mEffect->init();
50 }
51
setConfig(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)52 Return<Result> NoiseSuppressionEffect::setConfig(
53 const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
54 const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
55 return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider);
56 }
57
reset()58 Return<Result> NoiseSuppressionEffect::reset() {
59 return mEffect->reset();
60 }
61
enable()62 Return<Result> NoiseSuppressionEffect::enable() {
63 return mEffect->enable();
64 }
65
disable()66 Return<Result> NoiseSuppressionEffect::disable() {
67 return mEffect->disable();
68 }
69
70 #if MAJOR_VERSION <= 6
setAudioSource(AudioSource source)71 Return<Result> NoiseSuppressionEffect::setAudioSource(AudioSource source) {
72 return mEffect->setAudioSource(source);
73 }
74
setDevice(AudioDeviceBitfield device)75 Return<Result> NoiseSuppressionEffect::setDevice(AudioDeviceBitfield device) {
76 return mEffect->setDevice(device);
77 }
78
setInputDevice(AudioDeviceBitfield device)79 Return<Result> NoiseSuppressionEffect::setInputDevice(AudioDeviceBitfield device) {
80 return mEffect->setInputDevice(device);
81 }
82 #else
setAudioSource(const AudioSource & source)83 Return<Result> NoiseSuppressionEffect::setAudioSource(const AudioSource& source) {
84 return mEffect->setAudioSource(source);
85 }
86
setDevice(const DeviceAddress & device)87 Return<Result> NoiseSuppressionEffect::setDevice(const DeviceAddress& device) {
88 return mEffect->setDevice(device);
89 }
90
setInputDevice(const DeviceAddress & device)91 Return<Result> NoiseSuppressionEffect::setInputDevice(const DeviceAddress& device) {
92 return mEffect->setInputDevice(device);
93 }
94 #endif
95
setAndGetVolume(const hidl_vec<uint32_t> & volumes,setAndGetVolume_cb _hidl_cb)96 Return<void> NoiseSuppressionEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
97 setAndGetVolume_cb _hidl_cb) {
98 return mEffect->setAndGetVolume(volumes, _hidl_cb);
99 }
100
volumeChangeNotification(const hidl_vec<uint32_t> & volumes)101 Return<Result> NoiseSuppressionEffect::volumeChangeNotification(const hidl_vec<uint32_t>& volumes) {
102 return mEffect->volumeChangeNotification(volumes);
103 }
104
setAudioMode(AudioMode mode)105 Return<Result> NoiseSuppressionEffect::setAudioMode(AudioMode mode) {
106 return mEffect->setAudioMode(mode);
107 }
108
setConfigReverse(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)109 Return<Result> NoiseSuppressionEffect::setConfigReverse(
110 const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
111 const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
112 return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
113 }
114
getConfig(getConfig_cb _hidl_cb)115 Return<void> NoiseSuppressionEffect::getConfig(getConfig_cb _hidl_cb) {
116 return mEffect->getConfig(_hidl_cb);
117 }
118
getConfigReverse(getConfigReverse_cb _hidl_cb)119 Return<void> NoiseSuppressionEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) {
120 return mEffect->getConfigReverse(_hidl_cb);
121 }
122
getSupportedAuxChannelsConfigs(uint32_t maxConfigs,getSupportedAuxChannelsConfigs_cb _hidl_cb)123 Return<void> NoiseSuppressionEffect::getSupportedAuxChannelsConfigs(
124 uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) {
125 return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb);
126 }
127
getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb)128 Return<void> NoiseSuppressionEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) {
129 return mEffect->getAuxChannelsConfig(_hidl_cb);
130 }
131
setAuxChannelsConfig(const EffectAuxChannelsConfig & config)132 Return<Result> NoiseSuppressionEffect::setAuxChannelsConfig(const EffectAuxChannelsConfig& config) {
133 return mEffect->setAuxChannelsConfig(config);
134 }
135
offload(const EffectOffloadParameter & param)136 Return<Result> NoiseSuppressionEffect::offload(const EffectOffloadParameter& param) {
137 return mEffect->offload(param);
138 }
139
getDescriptor(getDescriptor_cb _hidl_cb)140 Return<void> NoiseSuppressionEffect::getDescriptor(getDescriptor_cb _hidl_cb) {
141 return mEffect->getDescriptor(_hidl_cb);
142 }
143
prepareForProcessing(prepareForProcessing_cb _hidl_cb)144 Return<void> NoiseSuppressionEffect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) {
145 return mEffect->prepareForProcessing(_hidl_cb);
146 }
147
setProcessBuffers(const AudioBuffer & inBuffer,const AudioBuffer & outBuffer)148 Return<Result> NoiseSuppressionEffect::setProcessBuffers(const AudioBuffer& inBuffer,
149 const AudioBuffer& outBuffer) {
150 return mEffect->setProcessBuffers(inBuffer, outBuffer);
151 }
152
command(uint32_t commandId,const hidl_vec<uint8_t> & data,uint32_t resultMaxSize,command_cb _hidl_cb)153 Return<void> NoiseSuppressionEffect::command(uint32_t commandId, const hidl_vec<uint8_t>& data,
154 uint32_t resultMaxSize, command_cb _hidl_cb) {
155 return mEffect->command(commandId, data, resultMaxSize, _hidl_cb);
156 }
157
setParameter(const hidl_vec<uint8_t> & parameter,const hidl_vec<uint8_t> & value)158 Return<Result> NoiseSuppressionEffect::setParameter(const hidl_vec<uint8_t>& parameter,
159 const hidl_vec<uint8_t>& value) {
160 return mEffect->setParameter(parameter, value);
161 }
162
getParameter(const hidl_vec<uint8_t> & parameter,uint32_t valueMaxSize,getParameter_cb _hidl_cb)163 Return<void> NoiseSuppressionEffect::getParameter(const hidl_vec<uint8_t>& parameter,
164 uint32_t valueMaxSize, getParameter_cb _hidl_cb) {
165 return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb);
166 }
167
getSupportedConfigsForFeature(uint32_t featureId,uint32_t maxConfigs,uint32_t configSize,getSupportedConfigsForFeature_cb _hidl_cb)168 Return<void> NoiseSuppressionEffect::getSupportedConfigsForFeature(
169 uint32_t featureId, uint32_t maxConfigs, uint32_t configSize,
170 getSupportedConfigsForFeature_cb _hidl_cb) {
171 return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb);
172 }
173
getCurrentConfigForFeature(uint32_t featureId,uint32_t configSize,getCurrentConfigForFeature_cb _hidl_cb)174 Return<void> NoiseSuppressionEffect::getCurrentConfigForFeature(
175 uint32_t featureId, uint32_t configSize, getCurrentConfigForFeature_cb _hidl_cb) {
176 return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb);
177 }
178
setCurrentConfigForFeature(uint32_t featureId,const hidl_vec<uint8_t> & configData)179 Return<Result> NoiseSuppressionEffect::setCurrentConfigForFeature(
180 uint32_t featureId, const hidl_vec<uint8_t>& configData) {
181 return mEffect->setCurrentConfigForFeature(featureId, configData);
182 }
183
close()184 Return<Result> NoiseSuppressionEffect::close() {
185 return mEffect->close();
186 }
187
debug(const hidl_handle & fd,const hidl_vec<hidl_string> & options)188 Return<void> NoiseSuppressionEffect::debug(const hidl_handle& fd,
189 const hidl_vec<hidl_string>& options) {
190 return mEffect->debug(fd, options);
191 }
192
193 // Methods from ::android::hardware::audio::effect::CPP_VERSION::INoiseSuppressionEffect
194 // follow.
setSuppressionLevel(INoiseSuppressionEffect::Level level)195 Return<Result> NoiseSuppressionEffect::setSuppressionLevel(INoiseSuppressionEffect::Level level) {
196 return mEffect->setParam(NS_PARAM_LEVEL, static_cast<int32_t>(level));
197 }
198
getSuppressionLevel(getSuppressionLevel_cb _hidl_cb)199 Return<void> NoiseSuppressionEffect::getSuppressionLevel(getSuppressionLevel_cb _hidl_cb) {
200 int32_t halLevel = 0;
201 Result retval = mEffect->getParam(NS_PARAM_LEVEL, halLevel);
202 _hidl_cb(retval, Level(halLevel));
203 return Void();
204 }
205
setSuppressionType(INoiseSuppressionEffect::Type type)206 Return<Result> NoiseSuppressionEffect::setSuppressionType(INoiseSuppressionEffect::Type type) {
207 return mEffect->setParam(NS_PARAM_TYPE, static_cast<int32_t>(type));
208 }
209
getSuppressionType(getSuppressionType_cb _hidl_cb)210 Return<void> NoiseSuppressionEffect::getSuppressionType(getSuppressionType_cb _hidl_cb) {
211 int32_t halType = 0;
212 Result retval = mEffect->getParam(NS_PARAM_TYPE, halType);
213 _hidl_cb(retval, Type(halType));
214 return Void();
215 }
216
setAllProperties(const INoiseSuppressionEffect::AllProperties & properties)217 Return<Result> NoiseSuppressionEffect::setAllProperties(
218 const INoiseSuppressionEffect::AllProperties& properties) {
219 t_ns_settings halProperties;
220 propertiesToHal(properties, &halProperties);
221 return mEffect->setParam(NS_PARAM_PROPERTIES, halProperties);
222 }
223
getAllProperties(getAllProperties_cb _hidl_cb)224 Return<void> NoiseSuppressionEffect::getAllProperties(getAllProperties_cb _hidl_cb) {
225 t_ns_settings halProperties;
226 Result retval = mEffect->getParam(NS_PARAM_PROPERTIES, halProperties);
227 AllProperties properties;
228 propertiesFromHal(halProperties, &properties);
229 _hidl_cb(retval, properties);
230 return Void();
231 }
232
233 } // namespace implementation
234 } // namespace CPP_VERSION
235 } // namespace effect
236 } // namespace audio
237 } // namespace hardware
238 } // namespace android
239