Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 048ede17 authored by Shunkai Yao's avatar Shunkai Yao Committed by Gerrit Code Review
Browse files

Merge "AudioHal: adapt effect_param_t handling with AIDL"

parents b549ebce 44bdbad7
Loading
Loading
Loading
Loading
+150 −85
Original line number Diff line number Diff line
@@ -30,7 +30,10 @@ namespace aidl {
namespace android {

using ::aidl::android::hardware::audio::effect::AcousticEchoCanceler;
using ::aidl::android::hardware::audio::effect::AutomaticGainControl;
using ::aidl::android::hardware::audio::effect::BassBoost;
using ::aidl::android::hardware::audio::effect::Descriptor;
using ::aidl::android::hardware::audio::effect::Downmix;
using ::aidl::android::hardware::audio::effect::Flags;
using ::aidl::android::hardware::audio::effect::Parameter;
using ::aidl::android::media::audio::common::AudioDeviceDescription;
@@ -38,14 +41,6 @@ using ::aidl::android::media::audio::common::AudioDeviceDescription;
using ::android::BAD_VALUE;
using ::android::base::unexpected;

////////////////////////////////////////////////////////////////////////////////////////////////////
// Utils

ConversionResult<AcousticEchoCanceler> getParameterSpecificAec(const Parameter& aidl) {
    const auto& specific = VALUE_OR_RETURN(UNION_GET(aidl, specific));
    return VALUE_OR_RETURN(UNION_GET(specific, acousticEchoCanceler));
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// Converters

@@ -65,6 +60,22 @@ ConversionResult<uint32_t> aidl2legacy_Flags_Type_uint32(Flags::Type type) {
    return unexpected(BAD_VALUE);
}

ConversionResult<Flags::Type> legacy2aidl_uint32_Flags_Type(uint32_t legacy) {
    switch (legacy & EFFECT_FLAG_TYPE_MASK) {
        case EFFECT_FLAG_TYPE_INSERT:
            return Flags::Type::INSERT;
        case EFFECT_FLAG_TYPE_AUXILIARY:
            return Flags::Type::AUXILIARY;
        case EFFECT_FLAG_TYPE_REPLACE:
            return Flags::Type::REPLACE;
        case EFFECT_FLAG_TYPE_PRE_PROC:
            return Flags::Type::PRE_PROC;
        case EFFECT_FLAG_TYPE_POST_PROC:
            return Flags::Type::POST_PROC;
    }
    return unexpected(BAD_VALUE);
}

ConversionResult<uint32_t> aidl2legacy_Flags_Insert_uint32(Flags::Insert insert) {
    switch (insert) {
        case Flags::Insert::ANY:
@@ -79,6 +90,20 @@ ConversionResult<uint32_t> aidl2legacy_Flags_Insert_uint32(Flags::Insert insert)
    return unexpected(BAD_VALUE);
}

ConversionResult<Flags::Insert> legacy2aidl_uint32_Flags_Insert(uint32_t legacy) {
    switch (legacy & EFFECT_FLAG_INSERT_MASK) {
        case EFFECT_FLAG_INSERT_ANY:
            return Flags::Insert::ANY;
        case EFFECT_FLAG_INSERT_FIRST:
            return Flags::Insert::FIRST;
        case EFFECT_FLAG_INSERT_LAST:
            return Flags::Insert::LAST;
        case EFFECT_FLAG_INSERT_EXCLUSIVE:
            return Flags::Insert::EXCLUSIVE;
    }
    return unexpected(BAD_VALUE);
}

ConversionResult<uint32_t> aidl2legacy_Flags_Volume_uint32(Flags::Volume volume) {
    switch (volume) {
        case Flags::Volume::NONE:
@@ -92,15 +117,17 @@ ConversionResult<uint32_t> aidl2legacy_Flags_Volume_uint32(Flags::Volume volume)
    }
    return unexpected(BAD_VALUE);
}
ConversionResult<uint32_t> aidl2legacy_Flags_HardwareAccelerator_uint32(
        Flags::HardwareAccelerator hwAcceleratorMode) {
    switch (hwAcceleratorMode) {
        case Flags::HardwareAccelerator::NONE:
            return 0;
        case Flags::HardwareAccelerator::SIMPLE:
            return EFFECT_FLAG_HW_ACC_SIMPLE;
        case Flags::HardwareAccelerator::TUNNEL:
            return EFFECT_FLAG_HW_ACC_TUNNEL;

ConversionResult<Flags::Volume> legacy2aidl_uint32_Flags_Volume(uint32_t legacy) {
    switch (legacy & EFFECT_FLAG_VOLUME_MASK) {
        case EFFECT_FLAG_VOLUME_CTRL:
            return Flags::Volume::CTRL;
        case EFFECT_FLAG_VOLUME_IND:
            return Flags::Volume::IND;
        case EFFECT_FLAG_VOLUME_MONITOR:
            return Flags::Volume::MONITOR;
        case EFFECT_FLAG_VOLUME_NONE:
            return Flags::Volume::NONE;
    }
    return unexpected(BAD_VALUE);
}
@@ -130,44 +157,30 @@ ConversionResult<uint32_t> aidl2legacy_Flags_uint32(Flags aidl) {
    return legacy;
}

ConversionResult<Flags::Type> legacy2aidl_uint32_Flags_Type(uint32_t legacy) {
    switch (legacy & EFFECT_FLAG_TYPE_MASK) {
        case EFFECT_FLAG_TYPE_INSERT:
            return Flags::Type::INSERT;
        case EFFECT_FLAG_TYPE_AUXILIARY:
            return Flags::Type::AUXILIARY;
        case EFFECT_FLAG_TYPE_REPLACE:
            return Flags::Type::REPLACE;
        case EFFECT_FLAG_TYPE_PRE_PROC:
            return Flags::Type::PRE_PROC;
        case EFFECT_FLAG_TYPE_POST_PROC:
            return Flags::Type::POST_PROC;
    }
    return unexpected(BAD_VALUE);
}
ConversionResult<Flags> legacy2aidl_uint32_Flags(uint32_t legacy) {
    Flags aidl;

ConversionResult<Flags::Insert> legacy2aidl_uint32_Flags_Insert(uint32_t legacy) {
    switch (legacy & EFFECT_FLAG_INSERT_MASK) {
        case EFFECT_FLAG_INSERT_ANY:
            return Flags::Insert::ANY;
        case EFFECT_FLAG_INSERT_FIRST:
            return Flags::Insert::FIRST;
        case EFFECT_FLAG_INSERT_LAST:
            return Flags::Insert::LAST;
        case EFFECT_FLAG_INSERT_EXCLUSIVE:
            return Flags::Insert::EXCLUSIVE;
    }
    return unexpected(BAD_VALUE);
    aidl.type = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_Type(legacy));
    aidl.insert = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_Insert(legacy));
    aidl.volume = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_Volume(legacy));
    aidl.hwAcceleratorMode = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_HardwareAccelerator(legacy));
    aidl.offloadIndication = (legacy & EFFECT_FLAG_OFFLOAD_SUPPORTED);
    aidl.deviceIndication = (legacy & EFFECT_FLAG_DEVICE_IND);
    aidl.audioModeIndication = (legacy & EFFECT_FLAG_AUDIO_MODE_IND);
    aidl.audioSourceIndication = (legacy & EFFECT_FLAG_AUDIO_SOURCE_IND);
    aidl.noProcessing = (legacy & EFFECT_FLAG_NO_PROCESS);
    return aidl;
}

ConversionResult<Flags::Volume> legacy2aidl_uint32_Flags_Volume(uint32_t legacy) {
    switch (legacy & EFFECT_FLAG_VOLUME_MASK) {
        case EFFECT_FLAG_VOLUME_IND:
            return Flags::Volume::IND;
        case EFFECT_FLAG_VOLUME_MONITOR:
            return Flags::Volume::MONITOR;
        case EFFECT_FLAG_VOLUME_NONE:
            return Flags::Volume::NONE;
ConversionResult<uint32_t> aidl2legacy_Flags_HardwareAccelerator_uint32(
        Flags::HardwareAccelerator hwAcceleratorMode) {
    switch (hwAcceleratorMode) {
        case Flags::HardwareAccelerator::NONE:
            return 0;
        case Flags::HardwareAccelerator::SIMPLE:
            return EFFECT_FLAG_HW_ACC_SIMPLE;
        case Flags::HardwareAccelerator::TUNNEL:
            return EFFECT_FLAG_HW_ACC_TUNNEL;
    }
    return unexpected(BAD_VALUE);
}
@@ -179,25 +192,12 @@ ConversionResult<Flags::HardwareAccelerator> legacy2aidl_uint32_Flags_HardwareAc
            return Flags::HardwareAccelerator::SIMPLE;
        case EFFECT_FLAG_HW_ACC_TUNNEL:
            return Flags::HardwareAccelerator::TUNNEL;
        case 0:
            return Flags::HardwareAccelerator::NONE;
    }
    return unexpected(BAD_VALUE);
}

ConversionResult<Flags> legacy2aidl_uint32_Flags(uint32_t legacy) {
    Flags aidl;

    aidl.type = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_Type(legacy));
    aidl.insert = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_Insert(legacy));
    aidl.volume = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_Volume(legacy));
    aidl.hwAcceleratorMode = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_HardwareAccelerator(legacy));
    aidl.offloadIndication = (legacy & EFFECT_FLAG_OFFLOAD_SUPPORTED);
    aidl.deviceIndication = (legacy & EFFECT_FLAG_DEVICE_IND);
    aidl.audioModeIndication = (legacy & EFFECT_FLAG_AUDIO_MODE_IND);
    aidl.audioSourceIndication = (legacy & EFFECT_FLAG_AUDIO_SOURCE_IND);
    aidl.noProcessing = (legacy & EFFECT_FLAG_NO_PROCESS);
    return aidl;
}

ConversionResult<effect_descriptor_t>
aidl2legacy_Descriptor_effect_descriptor(const Descriptor& aidl) {
    effect_descriptor_t legacy;
@@ -231,6 +231,7 @@ legacy2aidl_effect_descriptor_Descriptor(const effect_descriptor_t& legacy) {
    return aidl;
}

// buffer_provider_t is not supported thus skipped
ConversionResult<buffer_config_t> aidl2legacy_AudioConfigBase_buffer_config_t(
        const media::audio::common::AudioConfigBase& aidl, bool isInput) {
    buffer_config_t legacy;
@@ -245,6 +246,7 @@ ConversionResult<buffer_config_t> aidl2legacy_AudioConfigBase_buffer_config_t(
    legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormatDescription_audio_format_t(aidl.format));
    legacy.mask |= EFFECT_CONFIG_FORMAT;

    // TODO: add accessMode and mask
    return legacy;
}

@@ -263,37 +265,100 @@ legacy2aidl_buffer_config_t_AudioConfigBase(const buffer_config_t& legacy, bool
        aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormatDescription(
                static_cast<audio_format_t>(legacy.format)));
    }

    // TODO: add accessMode and mask
    return aidl;
}

ConversionResult<uint32_t> aidl2legacy_Parameter_uint32_echoDelay(const Parameter& aidl) {
    const auto& aec = VALUE_OR_RETURN(getParameterSpecificAec(aidl));
    const auto& echoDelay = VALUE_OR_RETURN(UNION_GET(aec, echoDelayUs));
    return VALUE_OR_RETURN(convertIntegral<uint32_t>(echoDelay));
ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_echoDelay(const Parameter& aidl) {
    int echoDelay = VALUE_OR_RETURN(GET_PARAMETER_SPECIFIC_FIELD(
            aidl, AcousticEchoCanceler, acousticEchoCanceler, echoDelayUs, int));
    return VALUE_OR_RETURN(convertReinterpret<uint32_t>(echoDelay));
}

ConversionResult<Parameter> legacy2aidl_uint32_echoDelay_Parameter(const uint32_t& legacy) {
ConversionResult<Parameter> legacy2aidl_uint32_echoDelay_Parameter_aec(uint32_t legacy) {
    int delay = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy));
    AcousticEchoCanceler aec = AcousticEchoCanceler::make<AcousticEchoCanceler::echoDelayUs>(delay);
    Parameter::Specific specific =
            Parameter::Specific::make<Parameter::Specific::acousticEchoCanceler>(aec);

    return Parameter::make<Parameter::specific>(specific);
    return MAKE_SPECIFIC_PARAMETER(AcousticEchoCanceler, acousticEchoCanceler, echoDelayUs, delay);
}

ConversionResult<uint32_t> aidl2legacy_Parameter_uint32_mobileMode(const Parameter& aidl) {
    const auto& aec = VALUE_OR_RETURN(getParameterSpecificAec(aidl));
    const auto& mobileMode = VALUE_OR_RETURN(UNION_GET(aec, mobileMode));
ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_mobileMode(const Parameter& aidl) {
    bool mobileMode = VALUE_OR_RETURN(GET_PARAMETER_SPECIFIC_FIELD(
            aidl, AcousticEchoCanceler, acousticEchoCanceler, mobileMode, bool));
    return VALUE_OR_RETURN(convertIntegral<uint32_t>(mobileMode));
}

ConversionResult<Parameter> legacy2aidl_uint32_mobileMode_Parameter(const uint32_t& legacy) {
ConversionResult<Parameter> legacy2aidl_uint32_mobileMode_Parameter_aec(uint32_t legacy) {
    bool mode = VALUE_OR_RETURN(convertIntegral<bool>(legacy));
    AcousticEchoCanceler aec = AcousticEchoCanceler::make<AcousticEchoCanceler::mobileMode>(mode);
    Parameter::Specific specific =
            Parameter::Specific::make<Parameter::Specific::acousticEchoCanceler>(aec);
    return MAKE_SPECIFIC_PARAMETER(AcousticEchoCanceler, acousticEchoCanceler, mobileMode, mode);
}

ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_fixedDigitalGain(
        const Parameter& aidl) {
    int gain = VALUE_OR_RETURN(GET_PARAMETER_SPECIFIC_FIELD(
            aidl, AutomaticGainControl, automaticGainControl, fixedDigitalGainMb, int));
    return VALUE_OR_RETURN(convertReinterpret<uint32_t>(gain));
}

ConversionResult<Parameter> legacy2aidl_uint32_fixedDigitalGain_Parameter_agc(uint32_t legacy) {
    int gain = VALUE_OR_RETURN(convertReinterpret<int>(legacy));
    return MAKE_SPECIFIC_PARAMETER(AutomaticGainControl, automaticGainControl, fixedDigitalGainMb,
                                   gain);
}

    return Parameter::make<Parameter::specific>(specific);
ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_levelEstimator(
        const Parameter& aidl) {
    const auto& le = VALUE_OR_RETURN(
            GET_PARAMETER_SPECIFIC_FIELD(aidl, AutomaticGainControl, automaticGainControl,
                                         levelEstimator, AutomaticGainControl::LevelEstimator));
    return static_cast<uint32_t>(le);
}

ConversionResult<Parameter> legacy2aidl_uint32_levelEstimator_Parameter_agc(uint32_t legacy) {
    if (legacy > (uint32_t) AutomaticGainControl::LevelEstimator::PEAK) {
        return unexpected(BAD_VALUE);
    }
    AutomaticGainControl::LevelEstimator le =
            static_cast<AutomaticGainControl::LevelEstimator>(legacy);
    return MAKE_SPECIFIC_PARAMETER(AutomaticGainControl, automaticGainControl, levelEstimator, le);
}

ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_saturationMargin(
        const Parameter& aidl) {
    int saturationMargin = VALUE_OR_RETURN(GET_PARAMETER_SPECIFIC_FIELD(
            aidl, AutomaticGainControl, automaticGainControl, saturationMarginMb, int));
    return VALUE_OR_RETURN(convertIntegral<uint32_t>(saturationMargin));
}

ConversionResult<Parameter> legacy2aidl_uint32_saturationMargin_Parameter_agc(uint32_t legacy) {
    int saturationMargin = VALUE_OR_RETURN(convertIntegral<int>(legacy));
    return MAKE_SPECIFIC_PARAMETER(AutomaticGainControl, automaticGainControl, saturationMarginMb,
                                   saturationMargin);
}

ConversionResult<uint16_t> aidl2legacy_Parameter_BassBoost_uint16_strengthPm(
        const Parameter& aidl) {
    int strength = VALUE_OR_RETURN(
            GET_PARAMETER_SPECIFIC_FIELD(aidl, BassBoost, bassBoost, strengthPm, int));
    return VALUE_OR_RETURN(convertIntegral<uint16_t>(strength));
}

ConversionResult<Parameter> legacy2aidl_uint16_strengthPm_Parameter_BassBoost(uint16_t legacy) {
    int strength = VALUE_OR_RETURN(convertIntegral<int>(legacy));
    return MAKE_SPECIFIC_PARAMETER(BassBoost, bassBoost, strengthPm, strength);
}

ConversionResult<int16_t> aidl2legacy_Parameter_Downmix_int16_type(const Parameter& aidl) {
    Downmix::Type aidlType = VALUE_OR_RETURN(
            GET_PARAMETER_SPECIFIC_FIELD(aidl, Downmix, downmix, type, Downmix::Type));
    return VALUE_OR_RETURN(convertIntegral<int16_t>(static_cast<uint32_t>(aidlType)));
}

ConversionResult<Parameter> legacy2aidl_int16_type_Parameter_Downmix(int16_t legacy) {
    if (legacy > (uint32_t) Downmix::Type::FOLD) {
        return unexpected(BAD_VALUE);
    }
    Downmix::Type aidlType = static_cast<Downmix::Type>(legacy);
    return MAKE_SPECIFIC_PARAMETER(Downmix, downmix, type, aidlType);
}

}  // namespace android
+54 −6
Original line number Diff line number Diff line
@@ -32,8 +32,32 @@
namespace aidl {
namespace android {

ConversionResult<::aidl::android::hardware::audio::effect::AcousticEchoCanceler>
getParameterSpecificAec(const ::aidl::android::hardware::audio::effect::Parameter& aidl);
template <typename P, typename T, typename P::Specific::Tag tag>
ConversionResult<T> getParameterSpecific(const P& u) {
    const auto& spec = VALUE_OR_RETURN(UNION_GET(u, specific));
    return unionGetField<typename P::Specific, tag>(spec);
}

template <typename P, typename T, typename P::Specific::Tag tag, typename T::Tag field, typename F>
ConversionResult<F> getParameterSpecificField(const P& u) {
    const auto& spec =
            VALUE_OR_RETURN((getParameterSpecific<std::decay_t<decltype(u)>, T, tag>(u)));
    return VALUE_OR_RETURN((unionGetField<T, field>(spec)));
}

#define GET_PARAMETER_SPECIFIC_FIELD(u, specific, tag, field, fieldType)                        \
    getParameterSpecificField<std::decay_t<decltype(u)>, specific,                              \
                              aidl::android::hardware::audio::effect::Parameter::Specific::tag, \
                              specific::field, fieldType>(u)

#define MAKE_SPECIFIC_PARAMETER(spec, tag, field, value)                                    \
    UNION_MAKE(aidl::android::hardware::audio::effect::Parameter, specific,                 \
               UNION_MAKE(aidl::android::hardware::audio::effect::Parameter::Specific, tag, \
                          UNION_MAKE(spec, field, value)))

#define MAKE_SPECIFIC_PARAMETER_ID(spec, tag, field)                       \
    UNION_MAKE(aidl::android::hardware::audio::effect::Parameter::Id, tag, \
               UNION_MAKE(spec::Id, commonTag, spec::field))

ConversionResult<uint32_t> aidl2legacy_Flags_Type_uint32(
        ::aidl::android::hardware::audio::effect::Flags::Type type);
@@ -67,16 +91,40 @@ ConversionResult<buffer_config_t> aidl2legacy_AudioConfigBase_buffer_config_t(
ConversionResult<media::audio::common::AudioConfigBase> legacy2aidl_buffer_config_t_AudioConfigBase(
        const buffer_config_t& legacy, bool isInput);

ConversionResult<uint32_t> aidl2legacy_Parameter_uint32_echoDelay(
ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_echoDelay(
        const ::aidl::android::hardware::audio::effect::Parameter& aidl);
ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
legacy2aidl_uint32_echoDelay_Parameter_aec(uint32_t legacy);

ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_mobileMode(
        const ::aidl::android::hardware::audio::effect::Parameter& aidl);
ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
legacy2aidl_uint32_mobileMode_Parameter_aec(uint32_t legacy);

ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_fixedDigitalGain(
        const ::aidl::android::hardware::audio::effect::Parameter& aidl);
ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
legacy2aidl_uint32_echoDelay_Parameter(const uint32_t& legacy);
legacy2aidl_uint32_fixedDigitalGain_Parameter_agc(uint32_t legacy);

ConversionResult<uint32_t> aidl2legacy_Parameter_uint32_mobileMode(
ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_levelEstimator(
        const ::aidl::android::hardware::audio::effect::Parameter& aidl);
ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
legacy2aidl_uint32_mobileMode_Parameter(const uint32_t& legacy);
legacy2aidl_uint32_levelEstimator_Parameter_agc(uint32_t legacy);

ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_saturationMargin(
        const ::aidl::android::hardware::audio::effect::Parameter& aidl);
ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
legacy2aidl_uint32_saturationMargin_Parameter_agc(uint32_t legacy);

ConversionResult<uint16_t> aidl2legacy_Parameter_BassBoost_uint16_strengthPm(
        const ::aidl::android::hardware::audio::effect::Parameter& aidl);
ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
legacy2aidl_uint16_strengthPm_Parameter_BassBoost(uint16_t legacy);

ConversionResult<int16_t> aidl2legacy_Parameter_Downmix_int16_type(
        const ::aidl::android::hardware::audio::effect::Parameter& aidl);
ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
legacy2aidl_int16_type_Parameter_Downmix(int16_t legacy);

}  // namespace android
}  // namespace aidl
+2 −0
Original line number Diff line number Diff line
@@ -278,6 +278,8 @@ ConversionResult<UnionFieldType<T, tag>> unionGetField(const T& u) {
#define UNION_SET(u, field, value) \
    (u).set<std::decay_t<decltype(u)>::Tag::field>(value)

#define UNION_MAKE(u, field, value) u::make<u::Tag::field>(value)

namespace aidl_utils {

/**
+300 −78

File changed.

Preview size limit exceeded, changes collapsed.

+32 −30
Original line number Diff line number Diff line
@@ -25,28 +25,17 @@

#include <media/AidlConversionNdk.h>
#include <system/audio_effect.h>
#include <system/audio_effects/effect_aec.h>
#include <system/audio_effects/effect_downmix.h>
#include <system/audio_effects/effect_dynamicsprocessing.h>
#include <system/audio_effects/effect_hapticgenerator.h>
#include <system/audio_effects/effect_ns.h>
#include <system/audio_effects/effect_visualizer.h>
#include <system/audio_effects/audio_effects_utils.h>

namespace android {
namespace effect {

static const size_t kEffectParamSize = sizeof(effect_param_t);
static const size_t kEffectConfigSize = sizeof(effect_config_t);

class EffectConversionHelperAidl {
  protected:
    EffectConversionHelperAidl(
            std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect,
            int32_t sessionId, int32_t ioId, ::aidl::android::media::audio::common::AudioUuid uuid)
        : mSessionId(sessionId),
          mIoId(ioId),
          mTypeUuid(std::move(uuid)),
          mEffect(std::move(effect)) {}
            int32_t sessionId, int32_t ioId,
            const ::aidl::android::hardware::audio::effect::Descriptor& desc);

    status_t handleCommand(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize,
                           void* pReplyData);
@@ -54,9 +43,25 @@ class EffectConversionHelperAidl {
  private:
    const int32_t mSessionId;
    const int32_t mIoId;
    const ::aidl::android::hardware::audio::effect::Descriptor mDesc;
    ::aidl::android::media::audio::common::AudioUuid mTypeUuid;
    const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect;
    ::aidl::android::hardware::audio::effect::IEffect::OpenEffectReturn mOpenReturn;
    ::aidl::android::hardware::audio::effect::Parameter::Common mCommon;

    const aidl::android::media::audio::common::AudioFormatDescription kDefaultFormatDescription = {
            .type = aidl::android::media::audio::common::AudioFormatType::PCM,
            .pcm = aidl::android::media::audio::common::PcmType::FLOAT_32_BIT};

    static constexpr int kDefaultframeCount = 0x100;

    using AudioChannelLayout = aidl::android::media::audio::common::AudioChannelLayout;
    const aidl::android::media::audio::common::AudioConfig kDefaultAudioConfig = {
            .base = {.sampleRate = 44100,
                     .channelMask = AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
                             AudioChannelLayout::LAYOUT_STEREO),
                     .format = kDefaultFormatDescription},
            .frameCount = kDefaultframeCount};
    // command handler map
    typedef status_t (EffectConversionHelperAidl::*CommandHandler)(uint32_t /* cmdSize */,
                                                                   const void* /* pCmdData */,
@@ -65,23 +70,14 @@ class EffectConversionHelperAidl {
    static const std::map<uint32_t /* effect_command_e */, CommandHandler> mCommandHandlerMap;

    // parameter set/get handler map
    typedef status_t (EffectConversionHelperAidl::*SetParameter)(const effect_param_t& param);
    typedef status_t (EffectConversionHelperAidl::*GetParameter)(effect_param_t& param);
    typedef status_t (EffectConversionHelperAidl::*SetParameter)(
            android::effect::utils::EffectParamReader& param);
    typedef status_t (EffectConversionHelperAidl::*GetParameter)(
            android::effect::utils::EffectParamWriter& param);
    static const std::map<::aidl::android::media::audio::common::AudioUuid /* TypeUUID */,
                          std::pair<SetParameter, GetParameter>>
            mParameterHandlerMap;

    // align to 32 bit boundary
    static constexpr size_t padding(size_t size) {
        return ((size - 1) / sizeof(int) + 1) * sizeof(int);
    }
    static constexpr bool validatePVsize(const effect_param_t& param, size_t p, size_t v) {
        return padding(param.psize) == p && param.vsize == v;
    }
    static constexpr bool validateCommandSize(const effect_param_t& param, size_t size) {
        return padding(param.psize) + param.vsize + kEffectParamSize <= size;
    }

    status_t handleInit(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize,
                        void* pReplyData);
    status_t handleSetParameter(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize,
@@ -107,9 +103,15 @@ class EffectConversionHelperAidl {
    status_t handleFirstPriority(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize,
                                 void* pReplyData);

    // AEC parameter handler
    status_t setAecParameter(const effect_param_t& param);
    status_t getAecParameter(effect_param_t& param);
    // set/get parameter handler
    status_t setAecParameter(android::effect::utils::EffectParamReader& param);
    status_t getAecParameter(android::effect::utils::EffectParamWriter& param);
    status_t setAgcParameter(android::effect::utils::EffectParamReader& param);
    status_t getAgcParameter(android::effect::utils::EffectParamWriter& param);
    status_t setBassBoostParameter(android::effect::utils::EffectParamReader& param);
    status_t getBassBoostParameter(android::effect::utils::EffectParamWriter& param);
    status_t setDownmixParameter(android::effect::utils::EffectParamReader& param);
    status_t getDownmixParameter(android::effect::utils::EffectParamWriter& param);
};

}  // namespace effect
Loading