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