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 "AGC_Effect_HAL"
18
19 #include "AutomaticGainControlEffect.h"
20
21 #include <android/log.h>
22
23 #include "VersionUtils.h"
24
25 namespace android {
26 namespace hardware {
27 namespace audio {
28 namespace effect {
29 namespace CPP_VERSION {
30 namespace implementation {
31
AutomaticGainControlEffect(effect_handle_t handle)32 AutomaticGainControlEffect::AutomaticGainControlEffect(effect_handle_t handle)
33 : mEffect(new Effect(true /*isInput*/, handle)) {}
34
propertiesFromHal(const t_agc_settings & halProperties,IAutomaticGainControlEffect::AllProperties * properties)35 void AutomaticGainControlEffect::propertiesFromHal(
36 const t_agc_settings& halProperties, IAutomaticGainControlEffect::AllProperties* properties) {
37 properties->targetLevelMb = halProperties.targetLevel;
38 properties->compGainMb = halProperties.compGain;
39 properties->limiterEnabled = halProperties.limiterEnabled;
40 }
41
propertiesToHal(const IAutomaticGainControlEffect::AllProperties & properties,t_agc_settings * halProperties)42 void AutomaticGainControlEffect::propertiesToHal(
43 const IAutomaticGainControlEffect::AllProperties& properties, t_agc_settings* halProperties) {
44 halProperties->targetLevel = properties.targetLevelMb;
45 halProperties->compGain = properties.compGainMb;
46 halProperties->limiterEnabled = properties.limiterEnabled;
47 }
48
49 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
init()50 Return<Result> AutomaticGainControlEffect::init() {
51 return mEffect->init();
52 }
53
setConfig(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)54 Return<Result> AutomaticGainControlEffect::setConfig(
55 const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
56 const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
57 return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider);
58 }
59
reset()60 Return<Result> AutomaticGainControlEffect::reset() {
61 return mEffect->reset();
62 }
63
enable()64 Return<Result> AutomaticGainControlEffect::enable() {
65 return mEffect->enable();
66 }
67
disable()68 Return<Result> AutomaticGainControlEffect::disable() {
69 return mEffect->disable();
70 }
71
72 #if MAJOR_VERSION <= 6
setAudioSource(AudioSource source)73 Return<Result> AutomaticGainControlEffect::setAudioSource(AudioSource source) {
74 return mEffect->setAudioSource(source);
75 }
76
setDevice(AudioDeviceBitfield device)77 Return<Result> AutomaticGainControlEffect::setDevice(AudioDeviceBitfield device) {
78 return mEffect->setDevice(device);
79 }
80
setInputDevice(AudioDeviceBitfield device)81 Return<Result> AutomaticGainControlEffect::setInputDevice(AudioDeviceBitfield device) {
82 return mEffect->setInputDevice(device);
83 }
84 #else
setAudioSource(const AudioSource & source)85 Return<Result> AutomaticGainControlEffect::setAudioSource(const AudioSource& source) {
86 return mEffect->setAudioSource(source);
87 }
88
setDevice(const DeviceAddress & device)89 Return<Result> AutomaticGainControlEffect::setDevice(const DeviceAddress& device) {
90 return mEffect->setDevice(device);
91 }
92
setInputDevice(const DeviceAddress & device)93 Return<Result> AutomaticGainControlEffect::setInputDevice(const DeviceAddress& device) {
94 return mEffect->setInputDevice(device);
95 }
96 #endif
97
setAndGetVolume(const hidl_vec<uint32_t> & volumes,setAndGetVolume_cb _hidl_cb)98 Return<void> AutomaticGainControlEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
99 setAndGetVolume_cb _hidl_cb) {
100 return mEffect->setAndGetVolume(volumes, _hidl_cb);
101 }
102
volumeChangeNotification(const hidl_vec<uint32_t> & volumes)103 Return<Result> AutomaticGainControlEffect::volumeChangeNotification(
104 const hidl_vec<uint32_t>& volumes) {
105 return mEffect->volumeChangeNotification(volumes);
106 }
107
setAudioMode(AudioMode mode)108 Return<Result> AutomaticGainControlEffect::setAudioMode(AudioMode mode) {
109 return mEffect->setAudioMode(mode);
110 }
111
setConfigReverse(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)112 Return<Result> AutomaticGainControlEffect::setConfigReverse(
113 const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
114 const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
115 return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
116 }
117
getConfig(getConfig_cb _hidl_cb)118 Return<void> AutomaticGainControlEffect::getConfig(getConfig_cb _hidl_cb) {
119 return mEffect->getConfig(_hidl_cb);
120 }
121
getConfigReverse(getConfigReverse_cb _hidl_cb)122 Return<void> AutomaticGainControlEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) {
123 return mEffect->getConfigReverse(_hidl_cb);
124 }
125
getSupportedAuxChannelsConfigs(uint32_t maxConfigs,getSupportedAuxChannelsConfigs_cb _hidl_cb)126 Return<void> AutomaticGainControlEffect::getSupportedAuxChannelsConfigs(
127 uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) {
128 return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb);
129 }
130
getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb)131 Return<void> AutomaticGainControlEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) {
132 return mEffect->getAuxChannelsConfig(_hidl_cb);
133 }
134
setAuxChannelsConfig(const EffectAuxChannelsConfig & config)135 Return<Result> AutomaticGainControlEffect::setAuxChannelsConfig(
136 const EffectAuxChannelsConfig& config) {
137 return mEffect->setAuxChannelsConfig(config);
138 }
139
offload(const EffectOffloadParameter & param)140 Return<Result> AutomaticGainControlEffect::offload(const EffectOffloadParameter& param) {
141 return mEffect->offload(param);
142 }
143
getDescriptor(getDescriptor_cb _hidl_cb)144 Return<void> AutomaticGainControlEffect::getDescriptor(getDescriptor_cb _hidl_cb) {
145 return mEffect->getDescriptor(_hidl_cb);
146 }
147
prepareForProcessing(prepareForProcessing_cb _hidl_cb)148 Return<void> AutomaticGainControlEffect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) {
149 return mEffect->prepareForProcessing(_hidl_cb);
150 }
151
setProcessBuffers(const AudioBuffer & inBuffer,const AudioBuffer & outBuffer)152 Return<Result> AutomaticGainControlEffect::setProcessBuffers(const AudioBuffer& inBuffer,
153 const AudioBuffer& outBuffer) {
154 return mEffect->setProcessBuffers(inBuffer, outBuffer);
155 }
156
command(uint32_t commandId,const hidl_vec<uint8_t> & data,uint32_t resultMaxSize,command_cb _hidl_cb)157 Return<void> AutomaticGainControlEffect::command(uint32_t commandId, const hidl_vec<uint8_t>& data,
158 uint32_t resultMaxSize, command_cb _hidl_cb) {
159 return mEffect->command(commandId, data, resultMaxSize, _hidl_cb);
160 }
161
setParameter(const hidl_vec<uint8_t> & parameter,const hidl_vec<uint8_t> & value)162 Return<Result> AutomaticGainControlEffect::setParameter(const hidl_vec<uint8_t>& parameter,
163 const hidl_vec<uint8_t>& value) {
164 return mEffect->setParameter(parameter, value);
165 }
166
getParameter(const hidl_vec<uint8_t> & parameter,uint32_t valueMaxSize,getParameter_cb _hidl_cb)167 Return<void> AutomaticGainControlEffect::getParameter(const hidl_vec<uint8_t>& parameter,
168 uint32_t valueMaxSize,
169 getParameter_cb _hidl_cb) {
170 return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb);
171 }
172
getSupportedConfigsForFeature(uint32_t featureId,uint32_t maxConfigs,uint32_t configSize,getSupportedConfigsForFeature_cb _hidl_cb)173 Return<void> AutomaticGainControlEffect::getSupportedConfigsForFeature(
174 uint32_t featureId, uint32_t maxConfigs, uint32_t configSize,
175 getSupportedConfigsForFeature_cb _hidl_cb) {
176 return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb);
177 }
178
getCurrentConfigForFeature(uint32_t featureId,uint32_t configSize,getCurrentConfigForFeature_cb _hidl_cb)179 Return<void> AutomaticGainControlEffect::getCurrentConfigForFeature(
180 uint32_t featureId, uint32_t configSize, getCurrentConfigForFeature_cb _hidl_cb) {
181 return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb);
182 }
183
setCurrentConfigForFeature(uint32_t featureId,const hidl_vec<uint8_t> & configData)184 Return<Result> AutomaticGainControlEffect::setCurrentConfigForFeature(
185 uint32_t featureId, const hidl_vec<uint8_t>& configData) {
186 return mEffect->setCurrentConfigForFeature(featureId, configData);
187 }
188
close()189 Return<Result> AutomaticGainControlEffect::close() {
190 return mEffect->close();
191 }
192
debug(const hidl_handle & fd,const hidl_vec<hidl_string> & options)193 Return<void> AutomaticGainControlEffect::debug(const hidl_handle& fd,
194 const hidl_vec<hidl_string>& options) {
195 return mEffect->debug(fd, options);
196 }
197
198 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IAutomaticGainControlEffect
199 // follow.
setTargetLevel(int16_t targetLevelMb)200 Return<Result> AutomaticGainControlEffect::setTargetLevel(int16_t targetLevelMb) {
201 return mEffect->setParam(AGC_PARAM_TARGET_LEVEL, targetLevelMb);
202 }
203
getTargetLevel(getTargetLevel_cb _hidl_cb)204 Return<void> AutomaticGainControlEffect::getTargetLevel(getTargetLevel_cb _hidl_cb) {
205 return mEffect->getIntegerParam(AGC_PARAM_TARGET_LEVEL, _hidl_cb);
206 }
207
setCompGain(int16_t compGainMb)208 Return<Result> AutomaticGainControlEffect::setCompGain(int16_t compGainMb) {
209 return mEffect->setParam(AGC_PARAM_COMP_GAIN, compGainMb);
210 }
211
getCompGain(getCompGain_cb _hidl_cb)212 Return<void> AutomaticGainControlEffect::getCompGain(getCompGain_cb _hidl_cb) {
213 return mEffect->getIntegerParam(AGC_PARAM_COMP_GAIN, _hidl_cb);
214 }
215
setLimiterEnabled(bool enabled)216 Return<Result> AutomaticGainControlEffect::setLimiterEnabled(bool enabled) {
217 return mEffect->setParam(AGC_PARAM_LIMITER_ENA, enabled);
218 }
219
isLimiterEnabled(isLimiterEnabled_cb _hidl_cb)220 Return<void> AutomaticGainControlEffect::isLimiterEnabled(isLimiterEnabled_cb _hidl_cb) {
221 return mEffect->getIntegerParam(AGC_PARAM_LIMITER_ENA, _hidl_cb);
222 }
223
setAllProperties(const IAutomaticGainControlEffect::AllProperties & properties)224 Return<Result> AutomaticGainControlEffect::setAllProperties(
225 const IAutomaticGainControlEffect::AllProperties& properties) {
226 t_agc_settings halProperties;
227 propertiesToHal(properties, &halProperties);
228 return mEffect->setParam(AGC_PARAM_PROPERTIES, halProperties);
229 }
230
getAllProperties(getAllProperties_cb _hidl_cb)231 Return<void> AutomaticGainControlEffect::getAllProperties(getAllProperties_cb _hidl_cb) {
232 t_agc_settings halProperties;
233 Result retval = mEffect->getParam(AGC_PARAM_PROPERTIES, halProperties);
234 AllProperties properties;
235 propertiesFromHal(halProperties, &properties);
236 _hidl_cb(retval, properties);
237 return Void();
238 }
239
240 } // namespace implementation
241 } // namespace CPP_VERSION
242 } // namespace effect
243 } // namespace audio
244 } // namespace hardware
245 } // namespace android
246