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

Commit 8781102d authored by Shunkai Yao's avatar Shunkai Yao
Browse files

Effect AIDL: Refactor effect capability with Range implementation

Bug: 258124419
Test: atest --test-mapping hardware/interfaces/audio/aidl/vts:presubmit
Change-Id: Ie76270e91471a30f7dda1883c510cd318745855f
parent 376dbd96
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ ndk::ScopedAStatus EffectImpl::close() {
ndk::ScopedAStatus EffectImpl::setParameter(const Parameter& param) {
    LOG(DEBUG) << __func__ << " with: " << param.toString();

    auto tag = param.getTag();
    const auto tag = param.getTag();
    switch (tag) {
        case Parameter::common:
        case Parameter::deviceDescription:
+12 −9
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ using aidl::android::hardware::audio::effect::AcousticEchoCancelerSw;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::kAcousticEchoCancelerSwImplUUID;
using aidl::android::hardware::audio::effect::Range;
using aidl::android::media::audio::common::AudioUuid;

extern "C" binder_exception_t createEffect(const AudioUuid* in_impl_uuid,
@@ -60,8 +61,14 @@ extern "C" binder_exception_t queryEffect(const AudioUuid* in_impl_uuid, Descrip
namespace aidl::android::hardware::audio::effect {

const std::string AcousticEchoCancelerSw::kEffectName = "AcousticEchoCancelerSw";
const AcousticEchoCanceler::Capability AcousticEchoCancelerSw::kCapability = {
        .maxEchoDelayUs = 500, .supportMobileMode = false};

const std::vector<Range::AcousticEchoCancelerRange> AcousticEchoCancelerSw::kRanges = {
        MAKE_RANGE(AcousticEchoCanceler, echoDelayUs, 0, 500),
        /* mobile mode not supported, and not settable */
        MAKE_RANGE(AcousticEchoCanceler, mobileMode, false, false)};

const Capability AcousticEchoCancelerSw::kCapability = {.range = AcousticEchoCancelerSw::kRanges};

const Descriptor AcousticEchoCancelerSw::kDescriptor = {
        .common = {.id = {.type = kAcousticEchoCancelerTypeUUID,
                          .uuid = kAcousticEchoCancelerSwImplUUID,
@@ -71,8 +78,7 @@ const Descriptor AcousticEchoCancelerSw::kDescriptor = {
                             .volume = Flags::Volume::CTRL},
                   .name = AcousticEchoCancelerSw::kEffectName,
                   .implementor = "The Android Open Source Project"},
        .capability = Capability::make<Capability::acousticEchoCanceler>(
                AcousticEchoCancelerSw::kCapability)};
        .capability = AcousticEchoCancelerSw::kCapability};

ndk::ScopedAStatus AcousticEchoCancelerSw::getDescriptor(Descriptor* _aidl_return) {
    LOG(DEBUG) << __func__ << kDescriptor.toString();
@@ -87,8 +93,9 @@ ndk::ScopedAStatus AcousticEchoCancelerSw::setParameterSpecific(
    RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");

    auto& param = specific.get<Parameter::Specific::acousticEchoCanceler>();
    auto tag = param.getTag();
    RETURN_IF(!inRange(param, kRanges), EX_ILLEGAL_ARGUMENT, "outOfRange");

    auto tag = param.getTag();
    switch (tag) {
        case AcousticEchoCanceler::echoDelayUs: {
            RETURN_IF(mContext->setEchoDelay(param.get<AcousticEchoCanceler::echoDelayUs>()) !=
@@ -182,10 +189,6 @@ IEffect::Status AcousticEchoCancelerSw::effectProcessImpl(float* in, float* out,
}

RetCode AcousticEchoCancelerSwContext::setEchoDelay(int echoDelayUs) {
    if (echoDelayUs < 0 || echoDelayUs > AcousticEchoCancelerSw::kCapability.maxEchoDelayUs) {
        LOG(DEBUG) << __func__ << " illegal delay " << echoDelayUs;
        return RetCode::ERROR_ILLEGAL_PARAMETER;
    }
    mEchoDelayUs = echoDelayUs;
    return RetCode::SUCCESS;
}
+3 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <aidl/android/hardware/audio/effect/BnEffect.h>
#include <aidl/android/hardware/audio/effect/Range.h>
#include <fmq/AidlMessageQueue.h>
#include <cstdlib>
#include <memory>
@@ -43,8 +44,7 @@ class AcousticEchoCancelerSwContext final : public EffectContext {
class AcousticEchoCancelerSw final : public EffectImpl {
  public:
    static const std::string kEffectName;
    static const bool kStrengthSupported;
    static const AcousticEchoCanceler::Capability kCapability;
    static const Capability kCapability;
    static const Descriptor kDescriptor;
    AcousticEchoCancelerSw() { LOG(DEBUG) << __func__; }
    ~AcousticEchoCancelerSw() {
@@ -65,6 +65,7 @@ class AcousticEchoCancelerSw final : public EffectImpl {
    IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;

  private:
    static const std::vector<Range::AcousticEchoCancelerRange> kRanges;
    std::shared_ptr<AcousticEchoCancelerSwContext> mContext;
    ndk::ScopedAStatus getParameterAcousticEchoCanceler(const AcousticEchoCanceler::Tag& tag,
                                                        Parameter::Specific* specific);
+9 −13
Original line number Diff line number Diff line
@@ -60,8 +60,13 @@ extern "C" binder_exception_t queryEffect(const AudioUuid* in_impl_uuid, Descrip
namespace aidl::android::hardware::audio::effect {

const std::string AutomaticGainControlSw::kEffectName = "AutomaticGainControlSw";
const AutomaticGainControl::Capability AutomaticGainControlSw::kCapability = {
        .maxFixedDigitalGainMb = 50000, .maxSaturationMarginMb = 10000};

const std::vector<Range::AutomaticGainControlRange> AutomaticGainControlSw::kRanges = {
        MAKE_RANGE(AutomaticGainControl, fixedDigitalGainMb, 0, 50000),
        MAKE_RANGE(AutomaticGainControl, saturationMarginMb, 0, 10000)};

const Capability AutomaticGainControlSw::kCapability = {.range = AutomaticGainControlSw::kRanges};

const Descriptor AutomaticGainControlSw::kDescriptor = {
        .common = {.id = {.type = kAutomaticGainControlTypeUUID,
                          .uuid = kAutomaticGainControlSwImplUUID,
@@ -71,8 +76,7 @@ const Descriptor AutomaticGainControlSw::kDescriptor = {
                             .volume = Flags::Volume::CTRL},
                   .name = AutomaticGainControlSw::kEffectName,
                   .implementor = "The Android Open Source Project"},
        .capability = Capability::make<Capability::automaticGainControl>(
                AutomaticGainControlSw::kCapability)};
        .capability = AutomaticGainControlSw::kCapability};

ndk::ScopedAStatus AutomaticGainControlSw::getDescriptor(Descriptor* _aidl_return) {
    LOG(DEBUG) << __func__ << kDescriptor.toString();
@@ -87,8 +91,8 @@ ndk::ScopedAStatus AutomaticGainControlSw::setParameterSpecific(
    RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");

    auto& param = specific.get<Parameter::Specific::automaticGainControl>();
    RETURN_IF(!inRange(param, kRanges), EX_ILLEGAL_ARGUMENT, "outOfRange");
    auto tag = param.getTag();

    switch (tag) {
        case AutomaticGainControl::fixedDigitalGainMb: {
            RETURN_IF(mContext->setDigitalGain(
@@ -196,10 +200,6 @@ IEffect::Status AutomaticGainControlSw::effectProcessImpl(float* in, float* out,
}

RetCode AutomaticGainControlSwContext::setDigitalGain(int gain) {
    if (gain < 0 || gain > AutomaticGainControlSw::kCapability.maxFixedDigitalGainMb) {
        LOG(DEBUG) << __func__ << " illegal digital gain " << gain;
        return RetCode::ERROR_ILLEGAL_PARAMETER;
    }
    mDigitalGain = gain;
    return RetCode::SUCCESS;
}
@@ -219,10 +219,6 @@ AutomaticGainControl::LevelEstimator AutomaticGainControlSwContext::getLevelEsti
}

RetCode AutomaticGainControlSwContext::setSaturationMargin(int margin) {
    if (margin < 0 || margin > AutomaticGainControlSw::kCapability.maxSaturationMarginMb) {
        LOG(DEBUG) << __func__ << " illegal saturationMargin " << margin;
        return RetCode::ERROR_ILLEGAL_PARAMETER;
    }
    mSaturationMargin = margin;
    return RetCode::SUCCESS;
}
+2 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ class AutomaticGainControlSw final : public EffectImpl {
  public:
    static const std::string kEffectName;
    static const bool kStrengthSupported;
    static const AutomaticGainControl::Capability kCapability;
    static const Capability kCapability;
    static const Descriptor kDescriptor;
    AutomaticGainControlSw() { LOG(DEBUG) << __func__; }
    ~AutomaticGainControlSw() {
@@ -72,6 +72,7 @@ class AutomaticGainControlSw final : public EffectImpl {
    IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;

  private:
    static const std::vector<Range::AutomaticGainControlRange> kRanges;
    std::shared_ptr<AutomaticGainControlSwContext> mContext;
    ndk::ScopedAStatus getParameterAutomaticGainControl(const AutomaticGainControl::Tag& tag,
                                                        Parameter::Specific* specific);
Loading