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

Commit 87a63c5b authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge changes from topic "locking_reordering_for_device_effects" into main

* changes:
  AudioFlinger: update primaryPlaybackThread_l() getter
  AudioFlinger: device effect not added to HAL
parents a1ce8ab9 328a0a5e
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -3812,7 +3812,11 @@ audio_unique_id_t AudioFlinger::nextUniqueId(audio_unique_id_use_t use)

IAfPlaybackThread* AudioFlinger::primaryPlaybackThread_l() const
{
    audio_utils::lock_guard lock(hardwareMutex());
    // The atomic ptr mPrimaryHardwareDev requires both the
    // AudioFlinger and the Hardware mutex for modification.
    // As we hold the AudioFlinger mutex, we access it
    // safely without the Hardware mutex, to avoid mutex order
    // inversion with Thread methods and the ThreadBase mutex.
    if (mPrimaryHardwareDev == nullptr) {
        return nullptr;
    }
+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;