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