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