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 "PresetReverb_HAL"
18 
19 #include "PresetReverbEffect.h"
20 
21 #include <android/log.h>
22 #include <system/audio_effects/effect_presetreverb.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 
PresetReverbEffect(effect_handle_t handle)33 PresetReverbEffect::PresetReverbEffect(effect_handle_t handle)
34     : mEffect(new Effect(false /*isInput*/, handle)) {}
35 
36 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
init()37 Return<Result> PresetReverbEffect::init() {
38     return mEffect->init();
39 }
40 
setConfig(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)41 Return<Result> PresetReverbEffect::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> PresetReverbEffect::reset() {
48     return mEffect->reset();
49 }
50 
enable()51 Return<Result> PresetReverbEffect::enable() {
52     return mEffect->enable();
53 }
54 
disable()55 Return<Result> PresetReverbEffect::disable() {
56     return mEffect->disable();
57 }
58 
59 #if MAJOR_VERSION <= 6
setAudioSource(AudioSource source)60 Return<Result> PresetReverbEffect::setAudioSource(AudioSource source) {
61     return mEffect->setAudioSource(source);
62 }
63 
setDevice(AudioDeviceBitfield device)64 Return<Result> PresetReverbEffect::setDevice(AudioDeviceBitfield device) {
65     return mEffect->setDevice(device);
66 }
67 
setInputDevice(AudioDeviceBitfield device)68 Return<Result> PresetReverbEffect::setInputDevice(AudioDeviceBitfield device) {
69     return mEffect->setInputDevice(device);
70 }
71 #else
setAudioSource(const AudioSource & source)72 Return<Result> PresetReverbEffect::setAudioSource(const AudioSource& source) {
73     return mEffect->setAudioSource(source);
74 }
75 
setDevice(const DeviceAddress & device)76 Return<Result> PresetReverbEffect::setDevice(const DeviceAddress& device) {
77     return mEffect->setDevice(device);
78 }
79 
setInputDevice(const DeviceAddress & device)80 Return<Result> PresetReverbEffect::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> PresetReverbEffect::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> PresetReverbEffect::volumeChangeNotification(const hidl_vec<uint32_t>& volumes) {
91     return mEffect->volumeChangeNotification(volumes);
92 }
93 
setAudioMode(AudioMode mode)94 Return<Result> PresetReverbEffect::setAudioMode(AudioMode mode) {
95     return mEffect->setAudioMode(mode);
96 }
97 
setConfigReverse(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)98 Return<Result> PresetReverbEffect::setConfigReverse(
99     const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
100     const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
101     return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
102 }
103 
getConfig(getConfig_cb _hidl_cb)104 Return<void> PresetReverbEffect::getConfig(getConfig_cb _hidl_cb) {
105     return mEffect->getConfig(_hidl_cb);
106 }
107 
getConfigReverse(getConfigReverse_cb _hidl_cb)108 Return<void> PresetReverbEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) {
109     return mEffect->getConfigReverse(_hidl_cb);
110 }
111 
getSupportedAuxChannelsConfigs(uint32_t maxConfigs,getSupportedAuxChannelsConfigs_cb _hidl_cb)112 Return<void> PresetReverbEffect::getSupportedAuxChannelsConfigs(
113     uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) {
114     return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb);
115 }
116 
getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb)117 Return<void> PresetReverbEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) {
118     return mEffect->getAuxChannelsConfig(_hidl_cb);
119 }
120 
setAuxChannelsConfig(const EffectAuxChannelsConfig & config)121 Return<Result> PresetReverbEffect::setAuxChannelsConfig(const EffectAuxChannelsConfig& config) {
122     return mEffect->setAuxChannelsConfig(config);
123 }
124 
offload(const EffectOffloadParameter & param)125 Return<Result> PresetReverbEffect::offload(const EffectOffloadParameter& param) {
126     return mEffect->offload(param);
127 }
128 
getDescriptor(getDescriptor_cb _hidl_cb)129 Return<void> PresetReverbEffect::getDescriptor(getDescriptor_cb _hidl_cb) {
130     return mEffect->getDescriptor(_hidl_cb);
131 }
132 
prepareForProcessing(prepareForProcessing_cb _hidl_cb)133 Return<void> PresetReverbEffect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) {
134     return mEffect->prepareForProcessing(_hidl_cb);
135 }
136 
setProcessBuffers(const AudioBuffer & inBuffer,const AudioBuffer & outBuffer)137 Return<Result> PresetReverbEffect::setProcessBuffers(const AudioBuffer& inBuffer,
138                                                      const AudioBuffer& outBuffer) {
139     return mEffect->setProcessBuffers(inBuffer, outBuffer);
140 }
141 
command(uint32_t commandId,const hidl_vec<uint8_t> & data,uint32_t resultMaxSize,command_cb _hidl_cb)142 Return<void> PresetReverbEffect::command(uint32_t commandId, const hidl_vec<uint8_t>& data,
143                                          uint32_t resultMaxSize, command_cb _hidl_cb) {
144     return mEffect->command(commandId, data, resultMaxSize, _hidl_cb);
145 }
146 
setParameter(const hidl_vec<uint8_t> & parameter,const hidl_vec<uint8_t> & value)147 Return<Result> PresetReverbEffect::setParameter(const hidl_vec<uint8_t>& parameter,
148                                                 const hidl_vec<uint8_t>& value) {
149     return mEffect->setParameter(parameter, value);
150 }
151 
getParameter(const hidl_vec<uint8_t> & parameter,uint32_t valueMaxSize,getParameter_cb _hidl_cb)152 Return<void> PresetReverbEffect::getParameter(const hidl_vec<uint8_t>& parameter,
153                                               uint32_t valueMaxSize, getParameter_cb _hidl_cb) {
154     return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb);
155 }
156 
getSupportedConfigsForFeature(uint32_t featureId,uint32_t maxConfigs,uint32_t configSize,getSupportedConfigsForFeature_cb _hidl_cb)157 Return<void> PresetReverbEffect::getSupportedConfigsForFeature(
158     uint32_t featureId, uint32_t maxConfigs, uint32_t configSize,
159     getSupportedConfigsForFeature_cb _hidl_cb) {
160     return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb);
161 }
162 
getCurrentConfigForFeature(uint32_t featureId,uint32_t configSize,getCurrentConfigForFeature_cb _hidl_cb)163 Return<void> PresetReverbEffect::getCurrentConfigForFeature(
164     uint32_t featureId, uint32_t configSize, getCurrentConfigForFeature_cb _hidl_cb) {
165     return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb);
166 }
167 
setCurrentConfigForFeature(uint32_t featureId,const hidl_vec<uint8_t> & configData)168 Return<Result> PresetReverbEffect::setCurrentConfigForFeature(uint32_t featureId,
169                                                               const hidl_vec<uint8_t>& configData) {
170     return mEffect->setCurrentConfigForFeature(featureId, configData);
171 }
172 
close()173 Return<Result> PresetReverbEffect::close() {
174     return mEffect->close();
175 }
176 
debug(const hidl_handle & fd,const hidl_vec<hidl_string> & options)177 Return<void> PresetReverbEffect::debug(const hidl_handle& fd,
178                                        const hidl_vec<hidl_string>& options) {
179     return mEffect->debug(fd, options);
180 }
181 
182 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IPresetReverbEffect follow.
setPreset(IPresetReverbEffect::Preset preset)183 Return<Result> PresetReverbEffect::setPreset(IPresetReverbEffect::Preset preset) {
184     return mEffect->setParam(REVERB_PARAM_PRESET, static_cast<t_reverb_presets>(preset));
185 }
186 
getPreset(getPreset_cb _hidl_cb)187 Return<void> PresetReverbEffect::getPreset(getPreset_cb _hidl_cb) {
188     t_reverb_presets halPreset = REVERB_PRESET_NONE;
189     Result retval = mEffect->getParam(REVERB_PARAM_PRESET, halPreset);
190     _hidl_cb(retval, Preset(halPreset));
191     return Void();
192 }
193 
194 }  // namespace implementation
195 }  // namespace CPP_VERSION
196 }  // namespace effect
197 }  // namespace audio
198 }  // namespace hardware
199 }  // namespace android
200