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

Commit 2e10aa85 authored by François Gaffie's avatar François Gaffie Committed by Andy Hung
Browse files

AudioFlinger: device effect not added to HAL



Regression introduced by checking on assigned io rather
than boolean addedToHAL. Device effects may not be assigned to
an io, hence they are never added to HAL.
This CL fixes by adding relying on an virtual API rather then in io.
Implementations will be specific to device / session effects.

Bug; 329395147
Test: manual
Flag: EXEMPT bugfix
Change-Id: I711f288b11fc303b3c428c64c4a8a687afde5872
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 59332a5c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ public:
    }

    audio_io_handle_t io() const final { return AUDIO_IO_HANDLE_NONE; }
    bool shouldDispatchAddRemoveToHal(bool isAdded __unused) const final { return true; }
    bool isOutput() const final { return false; }
    bool isOffload() const final { return false; }
    bool isOffloadOrDirect() const final { return false; }
+16 −6
Original line number Diff line number Diff line
@@ -1040,12 +1040,11 @@ void EffectModule::addEffectToHal_l()
{
    if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC ||
         (mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_POST_PROC) {
        if (mCurrentHalStream == getCallback()->io()) {
        if (!getCallback()->shouldDispatchAddRemoveToHal(/* isAdded= */ true)) {
            return;
        }

        (void)getCallback()->addEffectToHal(mEffectInterface);
        mCurrentHalStream = getCallback()->io();
    }
}

@@ -1142,11 +1141,10 @@ status_t EffectModule::removeEffectFromHal_l()
{
    if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC ||
             (mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_POST_PROC) {
        if (mCurrentHalStream != getCallback()->io()) {
            return (mCurrentHalStream == AUDIO_IO_HANDLE_NONE) ? NO_ERROR : INVALID_OPERATION;
        if (!getCallback()->shouldDispatchAddRemoveToHal(/* isAdded= */ false)) {
            return (getCallback()->io() == AUDIO_IO_HANDLE_NONE) ? NO_ERROR : INVALID_OPERATION;
        }
        getCallback()->removeEffectFromHal(mEffectInterface);
        mCurrentHalStream = AUDIO_IO_HANDLE_NONE;
    }
    return NO_ERROR;
}
@@ -3122,12 +3120,16 @@ status_t EffectChain::EffectCallback::addEffectToHal(
        return result;
    }
    result = st->addEffect(effect);
    if (result == OK) {
        mCurrentHalStream = t->id();
    }
    ALOGE_IF(result != OK, "Error when adding effect: %d", result);
    return result;
}

status_t EffectChain::EffectCallback::removeEffectFromHal(
        const sp<EffectHalInterface>& effect) {
    mCurrentHalStream = AUDIO_IO_HANDLE_NONE;
    status_t result = NO_INIT;
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
@@ -3142,6 +3144,11 @@ status_t EffectChain::EffectCallback::removeEffectFromHal(
    return result;
}

bool EffectChain::EffectCallback::shouldDispatchAddRemoveToHal(bool isAdded) const {
    const bool currentHalStreamMatchesThreadId = (io() == mCurrentHalStream);
    return isAdded != currentHalStreamMatchesThreadId;
}

audio_io_handle_t EffectChain::EffectCallback::io() const {
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
@@ -3734,11 +3741,14 @@ status_t DeviceEffectProxy::ProxyCallback::addEffectToHal(
    if (proxy == nullptr) {
        return NO_INIT;
    }
    return proxy->addEffectToHal(effect);
    status_t ret = proxy->addEffectToHal(effect);
    mAddedToHal = (ret == OK);
    return ret;
}

status_t DeviceEffectProxy::ProxyCallback::removeEffectFromHal(
        const sp<EffectHalInterface>& effect) {
    mAddedToHal = false;
    sp<DeviceEffectProxy> proxy = mProxy.promote();
    if (proxy == nullptr) {
        return NO_INIT;
+7 −2
Original line number Diff line number Diff line
@@ -279,8 +279,6 @@ private:
                                    // sending disable command.
    uint32_t mDisableWaitCnt;       // current process() calls count during disable period.
    bool     mOffloaded;            // effect is currently offloaded to the audio DSP
    // effect has been added to this HAL input stream
    audio_io_handle_t mCurrentHalStream = AUDIO_IO_HANDLE_NONE;
    bool     mIsOutput;             // direction of the AF thread

    bool    mSupportsFloat;         // effect supports float processing
@@ -596,6 +594,7 @@ public:
        status_t allocateHalBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) override;
        bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect) override;

        bool shouldDispatchAddRemoveToHal(bool isAdded) const override;
        audio_io_handle_t io() const override;
        bool isOutput() const override;
        bool isOffload() const override;
@@ -653,6 +652,8 @@ public:
        mediautils::atomic_wp<IAfThreadBase> mThread;
        sp<IAfThreadCallback> mAfThreadCallback;
        IAfThreadBase::type_t mThreadType = IAfThreadBase::MIXER;
        // effect has been added to this HAL input stream
        audio_io_handle_t mCurrentHalStream = AUDIO_IO_HANDLE_NONE;
    };

    DISALLOW_COPY_AND_ASSIGN(EffectChain);
@@ -784,6 +785,9 @@ private:
        }

        audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; }
        bool shouldDispatchAddRemoveToHal(bool isAdded) const override {
            return isAdded != mAddedToHal;
        }
        bool isOutput() const override;
        bool isOffload() const override { return false; }
        bool isOffloadOrDirect() const override { return false; }
@@ -824,6 +828,7 @@ private:
    private:
        const wp<DeviceEffectProxy> mProxy;
        const sp<DeviceEffectManagerCallback> mManagerCallback;
        bool mAddedToHal = false;
    };

    status_t checkPort(const IAfPatchPanel::Patch& patch,
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ class EffectCallbackInterface : public RefBase {
public:
    // Trivial methods usually implemented with help from ThreadBase
    virtual audio_io_handle_t io() const = 0;
    virtual bool shouldDispatchAddRemoveToHal(bool isAdded) const = 0;
    virtual bool isOutput() const = 0;
    virtual bool isOffload() const = 0;
    virtual bool isOffloadOrDirect() const = 0;