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