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