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 #ifndef ANDROID_HARDWARE_AUDIO_EFFECT_NOISESUPPRESSIONEFFECT_H
18 #define ANDROID_HARDWARE_AUDIO_EFFECT_NOISESUPPRESSIONEFFECT_H
19 
20 #include PATH(android/hardware/audio/effect/FILE_VERSION/INoiseSuppressionEffect.h)
21 
22 #include "Effect.h"
23 
24 #include <system/audio_effects/effect_ns.h>
25 
26 #include <hidl/Status.h>
27 
28 #include <hidl/MQDescriptor.h>
29 
30 #include "VersionUtils.h"
31 
32 namespace android {
33 namespace hardware {
34 namespace audio {
35 namespace effect {
36 namespace CPP_VERSION {
37 namespace implementation {
38 
39 using ::android::sp;
40 using ::android::hardware::hidl_string;
41 using ::android::hardware::hidl_vec;
42 using ::android::hardware::Return;
43 using ::android::hardware::Void;
44 using namespace ::android::hardware::audio::common::CPP_VERSION;
45 using namespace ::android::hardware::audio::effect::CPP_VERSION;
46 
47 struct NoiseSuppressionEffect : public INoiseSuppressionEffect {
48     explicit NoiseSuppressionEffect(effect_handle_t handle);
49 
50     // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
51     Return<Result> init() override;
52     Return<Result> setConfig(
53         const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
54         const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
55     Return<Result> reset() override;
56     Return<Result> enable() override;
57     Return<Result> disable() override;
58     Return<Result> setDevice(AudioDeviceBitfield device) override;
59     Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
60                                  setAndGetVolume_cb _hidl_cb) override;
61     Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
62     Return<Result> setAudioMode(AudioMode mode) override;
63     Return<Result> setConfigReverse(
64         const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
65         const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
66     Return<Result> setInputDevice(AudioDeviceBitfield device) override;
67     Return<void> getConfig(getConfig_cb _hidl_cb) override;
68     Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
69     Return<void> getSupportedAuxChannelsConfigs(
70         uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
71     Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
72     Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
73     Return<Result> setAudioSource(AudioSource source) override;
74     Return<Result> offload(const EffectOffloadParameter& param) override;
75     Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
76     Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
77     Return<Result> setProcessBuffers(const AudioBuffer& inBuffer,
78                                      const AudioBuffer& outBuffer) override;
79     Return<void> command(uint32_t commandId, const hidl_vec<uint8_t>& data, uint32_t resultMaxSize,
80                          command_cb _hidl_cb) override;
81     Return<Result> setParameter(const hidl_vec<uint8_t>& parameter,
82                                 const hidl_vec<uint8_t>& value) override;
83     Return<void> getParameter(const hidl_vec<uint8_t>& parameter, uint32_t valueMaxSize,
84                               getParameter_cb _hidl_cb) override;
85     Return<void> getSupportedConfigsForFeature(uint32_t featureId, uint32_t maxConfigs,
86                                                uint32_t configSize,
87                                                getSupportedConfigsForFeature_cb _hidl_cb) override;
88     Return<void> getCurrentConfigForFeature(uint32_t featureId, uint32_t configSize,
89                                             getCurrentConfigForFeature_cb _hidl_cb) override;
90     Return<Result> setCurrentConfigForFeature(uint32_t featureId,
91                                               const hidl_vec<uint8_t>& configData) override;
92     Return<Result> close() override;
93     Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
94 
95     // Methods from ::android::hardware::audio::effect::CPP_VERSION::INoiseSuppressionEffect
96     // follow.
97     Return<Result> setSuppressionLevel(INoiseSuppressionEffect::Level level) override;
98     Return<void> getSuppressionLevel(getSuppressionLevel_cb _hidl_cb) override;
99     Return<Result> setSuppressionType(INoiseSuppressionEffect::Type type) override;
100     Return<void> getSuppressionType(getSuppressionType_cb _hidl_cb) override;
101     Return<Result> setAllProperties(
102         const INoiseSuppressionEffect::AllProperties& properties) override;
103     Return<void> getAllProperties(getAllProperties_cb _hidl_cb) override;
104 
105    private:
106     sp<Effect> mEffect;
107 
108     virtual ~NoiseSuppressionEffect();
109 
110     void propertiesFromHal(const t_ns_settings& halProperties,
111                            INoiseSuppressionEffect::AllProperties* properties);
112     void propertiesToHal(const INoiseSuppressionEffect::AllProperties& properties,
113                          t_ns_settings* halProperties);
114 };
115 
116 }  // namespace implementation
117 }  // namespace CPP_VERSION
118 }  // namespace effect
119 }  // namespace audio
120 }  // namespace hardware
121 }  // namespace android
122 
123 #endif  // ANDROID_HARDWARE_AUDIO_EFFECT_NOISESUPPRESSIONEFFECT_H
124