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