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 "LoudnessEnhancer_HAL"
18 
19 #include "LoudnessEnhancerEffect.h"
20 
21 #include <system/audio_effects/effect_loudnessenhancer.h>
22 
23 #include <android/log.h>
24 #include <system/audio_effects/effect_aec.h>
25 
26 #include "VersionUtils.h"
27 
28 namespace android {
29 namespace hardware {
30 namespace audio {
31 namespace effect {
32 namespace CPP_VERSION {
33 namespace implementation {
34 
LoudnessEnhancerEffect(effect_handle_t handle)35 LoudnessEnhancerEffect::LoudnessEnhancerEffect(effect_handle_t handle)
36     : mEffect(new Effect(handle)) {}
37 
~LoudnessEnhancerEffect()38 LoudnessEnhancerEffect::~LoudnessEnhancerEffect() {}
39 
40 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
init()41 Return<Result> LoudnessEnhancerEffect::init() {
42     return mEffect->init();
43 }
44 
setConfig(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)45 Return<Result> LoudnessEnhancerEffect::setConfig(
46     const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
47     const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
48     return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider);
49 }
50 
reset()51 Return<Result> LoudnessEnhancerEffect::reset() {
52     return mEffect->reset();
53 }
54 
enable()55 Return<Result> LoudnessEnhancerEffect::enable() {
56     return mEffect->enable();
57 }
58 
disable()59 Return<Result> LoudnessEnhancerEffect::disable() {
60     return mEffect->disable();
61 }
62 
setDevice(AudioDeviceBitfield device)63 Return<Result> LoudnessEnhancerEffect::setDevice(AudioDeviceBitfield device) {
64     return mEffect->setDevice(device);
65 }
66 
setAndGetVolume(const hidl_vec<uint32_t> & volumes,setAndGetVolume_cb _hidl_cb)67 Return<void> LoudnessEnhancerEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
68                                                      setAndGetVolume_cb _hidl_cb) {
69     return mEffect->setAndGetVolume(volumes, _hidl_cb);
70 }
71 
volumeChangeNotification(const hidl_vec<uint32_t> & volumes)72 Return<Result> LoudnessEnhancerEffect::volumeChangeNotification(const hidl_vec<uint32_t>& volumes) {
73     return mEffect->volumeChangeNotification(volumes);
74 }
75 
setAudioMode(AudioMode mode)76 Return<Result> LoudnessEnhancerEffect::setAudioMode(AudioMode mode) {
77     return mEffect->setAudioMode(mode);
78 }
79 
setConfigReverse(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)80 Return<Result> LoudnessEnhancerEffect::setConfigReverse(
81     const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
82     const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
83     return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
84 }
85 
setInputDevice(AudioDeviceBitfield device)86 Return<Result> LoudnessEnhancerEffect::setInputDevice(AudioDeviceBitfield device) {
87     return mEffect->setInputDevice(device);
88 }
89 
getConfig(getConfig_cb _hidl_cb)90 Return<void> LoudnessEnhancerEffect::getConfig(getConfig_cb _hidl_cb) {
91     return mEffect->getConfig(_hidl_cb);
92 }
93 
getConfigReverse(getConfigReverse_cb _hidl_cb)94 Return<void> LoudnessEnhancerEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) {
95     return mEffect->getConfigReverse(_hidl_cb);
96 }
97 
getSupportedAuxChannelsConfigs(uint32_t maxConfigs,getSupportedAuxChannelsConfigs_cb _hidl_cb)98 Return<void> LoudnessEnhancerEffect::getSupportedAuxChannelsConfigs(
99     uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) {
100     return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb);
101 }
102 
getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb)103 Return<void> LoudnessEnhancerEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) {
104     return mEffect->getAuxChannelsConfig(_hidl_cb);
105 }
106 
setAuxChannelsConfig(const EffectAuxChannelsConfig & config)107 Return<Result> LoudnessEnhancerEffect::setAuxChannelsConfig(const EffectAuxChannelsConfig& config) {
108     return mEffect->setAuxChannelsConfig(config);
109 }
110 
setAudioSource(AudioSource source)111 Return<Result> LoudnessEnhancerEffect::setAudioSource(AudioSource source) {
112     return mEffect->setAudioSource(source);
113 }
114 
offload(const EffectOffloadParameter & param)115 Return<Result> LoudnessEnhancerEffect::offload(const EffectOffloadParameter& param) {
116     return mEffect->offload(param);
117 }
118 
getDescriptor(getDescriptor_cb _hidl_cb)119 Return<void> LoudnessEnhancerEffect::getDescriptor(getDescriptor_cb _hidl_cb) {
120     return mEffect->getDescriptor(_hidl_cb);
121 }
122 
prepareForProcessing(prepareForProcessing_cb _hidl_cb)123 Return<void> LoudnessEnhancerEffect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) {
124     return mEffect->prepareForProcessing(_hidl_cb);
125 }
126 
setProcessBuffers(const AudioBuffer & inBuffer,const AudioBuffer & outBuffer)127 Return<Result> LoudnessEnhancerEffect::setProcessBuffers(const AudioBuffer& inBuffer,
128                                                          const AudioBuffer& outBuffer) {
129     return mEffect->setProcessBuffers(inBuffer, outBuffer);
130 }
131 
command(uint32_t commandId,const hidl_vec<uint8_t> & data,uint32_t resultMaxSize,command_cb _hidl_cb)132 Return<void> LoudnessEnhancerEffect::command(uint32_t commandId, const hidl_vec<uint8_t>& data,
133                                              uint32_t resultMaxSize, command_cb _hidl_cb) {
134     return mEffect->command(commandId, data, resultMaxSize, _hidl_cb);
135 }
136 
setParameter(const hidl_vec<uint8_t> & parameter,const hidl_vec<uint8_t> & value)137 Return<Result> LoudnessEnhancerEffect::setParameter(const hidl_vec<uint8_t>& parameter,
138                                                     const hidl_vec<uint8_t>& value) {
139     return mEffect->setParameter(parameter, value);
140 }
141 
getParameter(const hidl_vec<uint8_t> & parameter,uint32_t valueMaxSize,getParameter_cb _hidl_cb)142 Return<void> LoudnessEnhancerEffect::getParameter(const hidl_vec<uint8_t>& parameter,
143                                                   uint32_t valueMaxSize, getParameter_cb _hidl_cb) {
144     return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb);
145 }
146 
getSupportedConfigsForFeature(uint32_t featureId,uint32_t maxConfigs,uint32_t configSize,getSupportedConfigsForFeature_cb _hidl_cb)147 Return<void> LoudnessEnhancerEffect::getSupportedConfigsForFeature(
148     uint32_t featureId, uint32_t maxConfigs, uint32_t configSize,
149     getSupportedConfigsForFeature_cb _hidl_cb) {
150     return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb);
151 }
152 
getCurrentConfigForFeature(uint32_t featureId,uint32_t configSize,getCurrentConfigForFeature_cb _hidl_cb)153 Return<void> LoudnessEnhancerEffect::getCurrentConfigForFeature(
154     uint32_t featureId, uint32_t configSize, getCurrentConfigForFeature_cb _hidl_cb) {
155     return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb);
156 }
157 
setCurrentConfigForFeature(uint32_t featureId,const hidl_vec<uint8_t> & configData)158 Return<Result> LoudnessEnhancerEffect::setCurrentConfigForFeature(
159     uint32_t featureId, const hidl_vec<uint8_t>& configData) {
160     return mEffect->setCurrentConfigForFeature(featureId, configData);
161 }
162 
close()163 Return<Result> LoudnessEnhancerEffect::close() {
164     return mEffect->close();
165 }
166 
debug(const hidl_handle & fd,const hidl_vec<hidl_string> & options)167 Return<void> LoudnessEnhancerEffect::debug(const hidl_handle& fd,
168                                            const hidl_vec<hidl_string>& options) {
169     return mEffect->debug(fd, options);
170 }
171 
172 // Methods from ::android::hardware::audio::effect::CPP_VERSION::ILoudnessEnhancerEffect
173 // follow.
setTargetGain(int32_t targetGainMb)174 Return<Result> LoudnessEnhancerEffect::setTargetGain(int32_t targetGainMb) {
175     return mEffect->setParam(LOUDNESS_ENHANCER_DEFAULT_TARGET_GAIN_MB, targetGainMb);
176 }
177 
getTargetGain(getTargetGain_cb _hidl_cb)178 Return<void> LoudnessEnhancerEffect::getTargetGain(getTargetGain_cb _hidl_cb) {
179     // AOSP Loudness Enhancer expects the size of the request to not include the
180     // size of the parameter.
181     uint32_t paramId = LOUDNESS_ENHANCER_DEFAULT_TARGET_GAIN_MB;
182     uint32_t targetGainMb = 0;
183     Result retval = mEffect->getParameterImpl(
184         sizeof(paramId), &paramId, 0, sizeof(targetGainMb), [&](uint32_t, const void* valueData) {
185             memcpy(&targetGainMb, valueData, sizeof(targetGainMb));
186         });
187     _hidl_cb(retval, targetGainMb);
188     return Void();
189 }
190 
191 }  // namespace implementation
192 }  // namespace CPP_VERSION
193 }  // namespace effect
194 }  // namespace audio
195 }  // namespace hardware
196 }  // namespace android
197