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