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

Commit f80f58fb authored by Shunkai Yao's avatar Shunkai Yao
Browse files

Revert "AudioFlinger: device effect not added to HAL"

Revert submission 28043980-locking_reordering_for_device_effects

Reason for revert: b/350617044

Reverted changes: /q/submissionid:28043980-locking_reordering_for_device_effects

Change-Id: I7dee3f24c0074d9c7fba57e60f643f35a006cfa0
parent 76fad50e
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -108,7 +108,6 @@ 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; }
+6 −16
Original line number Diff line number Diff line
@@ -1042,11 +1042,12 @@ 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 (!getCallback()->shouldDispatchAddRemoveToHal(/* isAdded= */ true)) {
        if (mCurrentHalStream == getCallback()->io()) {
            return;
        }

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

@@ -1143,10 +1144,11 @@ 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 (!getCallback()->shouldDispatchAddRemoveToHal(/* isAdded= */ false)) {
            return (getCallback()->io() == AUDIO_IO_HANDLE_NONE) ? NO_ERROR : INVALID_OPERATION;
        if (mCurrentHalStream != getCallback()->io()) {
            return (mCurrentHalStream == AUDIO_IO_HANDLE_NONE) ? NO_ERROR : INVALID_OPERATION;
        }
        getCallback()->removeEffectFromHal(mEffectInterface);
        mCurrentHalStream = AUDIO_IO_HANDLE_NONE;
    }
    return NO_ERROR;
}
@@ -3128,16 +3130,12 @@ 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) {
@@ -3152,11 +3150,6 @@ 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) {
@@ -3749,14 +3742,11 @@ status_t DeviceEffectProxy::ProxyCallback::addEffectToHal(
    if (proxy == nullptr) {
        return NO_INIT;
    }
    status_t ret = proxy->addEffectToHal(effect);
    mAddedToHal = (ret == OK);
    return ret;
    return proxy->addEffectToHal(effect);
}

status_t DeviceEffectProxy::ProxyCallback::removeEffectFromHal(
        const sp<EffectHalInterface>& effect) {
    mAddedToHal = false;
    sp<DeviceEffectProxy> proxy = mProxy.promote();
    if (proxy == nullptr) {
        return NO_INIT;
+2 −7
Original line number Diff line number Diff line
@@ -279,6 +279,8 @@ 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
@@ -594,7 +596,6 @@ 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;
@@ -652,8 +653,6 @@ 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);
@@ -785,9 +784,6 @@ 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; }
@@ -828,7 +824,6 @@ private:
    private:
        const wp<DeviceEffectProxy> mProxy;
        const sp<DeviceEffectManagerCallback> mManagerCallback;
        bool mAddedToHal = false;
    };

    status_t checkPort(const IAfPatchPanel::Patch& patch,
+0 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ 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;