Home | History | Annotate | Download | only in default
      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 #ifndef ANDROID_HARDWARE_AUDIO_EFFECT_AUTOMATICGAINCONTROLEFFECT_H
     18 #define ANDROID_HARDWARE_AUDIO_EFFECT_AUTOMATICGAINCONTROLEFFECT_H
     19 
     20 #include PATH(android/hardware/audio/effect/FILE_VERSION/IAutomaticGainControlEffect.h)
     21 
     22 #include "Effect.h"
     23 
     24 #include <system/audio_effects/effect_agc.h>
     25 
     26 #include <hidl/Status.h>
     27 
     28 #include <hidl/MQDescriptor.h>
     29 
     30 #include "VersionUtils.h"
     31 
     32 namespace android {
     33 namespace hardware {
     34 namespace audio {
     35 namespace effect {
     36 namespace CPP_VERSION {
     37 namespace implementation {
     38 
     39 using ::android::sp;
     40 using ::android::hardware::hidl_string;
     41 using ::android::hardware::hidl_vec;
     42 using ::android::hardware::Return;
     43 using ::android::hardware::Void;
     44 using ::android::hardware::audio::effect::CPP_VERSION::IAutomaticGainControlEffect;
     45 using ::android::hardware::audio::effect::CPP_VERSION::Result;
     46 
     47 struct AutomaticGainControlEffect : public IAutomaticGainControlEffect {
     48     explicit AutomaticGainControlEffect(effect_handle_t handle);
     49 
     50     // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
     51     Return<Result> init() override;
     52     Return<Result> setConfig(
     53         const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
     54         const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
     55     Return<Result> reset() override;
     56     Return<Result> enable() override;
     57     Return<Result> disable() override;
     58     Return<Result> setDevice(AudioDeviceBitfield device) override;
     59     Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
     60                                  setAndGetVolume_cb _hidl_cb) override;
     61     Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
     62     Return<Result> setAudioMode(AudioMode mode) override;
     63     Return<Result> setConfigReverse(
     64         const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
     65         const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
     66     Return<Result> setInputDevice(AudioDeviceBitfield device) override;
     67     Return<void> getConfig(getConfig_cb _hidl_cb) override;
     68     Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
     69     Return<void> getSupportedAuxChannelsConfigs(
     70         uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
     71     Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
     72     Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
     73     Return<Result> setAudioSource(AudioSource source) override;
     74     Return<Result> offload(const EffectOffloadParameter& param) override;
     75     Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
     76     Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
     77     Return<Result> setProcessBuffers(const AudioBuffer& inBuffer,
     78                                      const AudioBuffer& outBuffer) override;
     79     Return<void> command(uint32_t commandId, const hidl_vec<uint8_t>& data, uint32_t resultMaxSize,
     80                          command_cb _hidl_cb) override;
     81     Return<Result> setParameter(const hidl_vec<uint8_t>& parameter,
     82                                 const hidl_vec<uint8_t>& value) override;
     83     Return<void> getParameter(const hidl_vec<uint8_t>& parameter, uint32_t valueMaxSize,
     84                               getParameter_cb _hidl_cb) override;
     85     Return<void> getSupportedConfigsForFeature(uint32_t featureId, uint32_t maxConfigs,
     86                                                uint32_t configSize,
     87                                                getSupportedConfigsForFeature_cb _hidl_cb) override;
     88     Return<void> getCurrentConfigForFeature(uint32_t featureId, uint32_t configSize,
     89                                             getCurrentConfigForFeature_cb _hidl_cb) override;
     90     Return<Result> setCurrentConfigForFeature(uint32_t featureId,
     91                                               const hidl_vec<uint8_t>& configData) override;
     92     Return<Result> close() override;
     93     Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
     94 
     95     // Methods from
     96     // ::android::hardware::audio::effect::CPP_VERSION::IAutomaticGainControlEffect follow.
     97     Return<Result> setTargetLevel(int16_t targetLevelMb) override;
     98     Return<void> getTargetLevel(getTargetLevel_cb _hidl_cb) override;
     99     Return<Result> setCompGain(int16_t compGainMb) override;
    100     Return<void> getCompGain(getCompGain_cb _hidl_cb) override;
    101     Return<Result> setLimiterEnabled(bool enabled) override;
    102     Return<void> isLimiterEnabled(isLimiterEnabled_cb _hidl_cb) override;
    103     Return<Result> setAllProperties(
    104         const IAutomaticGainControlEffect::AllProperties& properties) override;
    105     Return<void> getAllProperties(getAllProperties_cb _hidl_cb) override;
    106 
    107    private:
    108     sp<Effect> mEffect;
    109 
    110     virtual ~AutomaticGainControlEffect();
    111 
    112     void propertiesFromHal(const t_agc_settings& halProperties,
    113                            IAutomaticGainControlEffect::AllProperties* properties);
    114     void propertiesToHal(const IAutomaticGainControlEffect::AllProperties& properties,
    115                          t_agc_settings* halProperties);
    116 };
    117 
    118 }  // namespace implementation
    119 }  // namespace CPP_VERSION
    120 }  // namespace effect
    121 }  // namespace audio
    122 }  // namespace hardware
    123 }  // namespace android
    124 
    125 #endif  // ANDROID_HARDWARE_AUDIO_EFFECT_AUTOMATICGAINCONTROLEFFECT_H
    126