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

Commit 7453ec9e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Only set initial volume to 0 for the effect that does volume control."...

Merge "Only set initial volume to 0 for the effect that does volume control." into udc-dev-plus-aosp
parents 4b3e41b1 75935aa9
Loading
Loading
Loading
Loading
+34 −23
Original line number Diff line number Diff line
@@ -996,13 +996,6 @@ status_t EffectModule::configure()
                    &size,
                    &cmdStatus);
        }

        if (isVolumeControl()) {
            // Force initializing the volume as 0 for volume control effect for safer ramping
            uint32_t left = 0;
            uint32_t right = 0;
            setVolumeInternal(&left, &right, true /*controller*/);
        }
    }

    // mConfig.outputCfg.buffer.frameCount cannot be zero.
@@ -2127,7 +2120,7 @@ sp<IAfEffectChain> IAfEffectChain::create(
EffectChain::EffectChain(const sp<IAfThreadBase>& thread,
                                       audio_session_t sessionId)
    : mSessionId(sessionId), mActiveTrackCnt(0), mTrackCnt(0), mTailBufferCount(0),
      mVolumeCtrlIdx(-1), mLeftVolume(UINT_MAX), mRightVolume(UINT_MAX),
      mLeftVolume(UINT_MAX), mRightVolume(UINT_MAX),
      mNewLeftVolume(UINT_MAX), mNewRightVolume(UINT_MAX),
      mEffectCallback(new EffectCallback(wp<EffectChain>(this), thread))
{
@@ -2365,6 +2358,15 @@ status_t EffectChain::addEffect_ll(const sp<IAfEffectModule>& effect)
    return NO_ERROR;
}

std::optional<size_t> EffectChain::findVolumeControl_l(size_t from, size_t to) const {
    for (size_t i = std::min(to, mEffects.size()); i > from; i--) {
        if (mEffects[i - 1]->isVolumeControlEnabled()) {
            return i - 1;
        }
    }
    return std::nullopt;
}

ssize_t EffectChain::getInsertIndex(const effect_descriptor_t& desc) {
    // Insert effects are inserted at the end of mEffects vector as they are processed
    //  after track and auxiliary effects.
@@ -2534,29 +2536,38 @@ bool EffectChain::setVolume_l(uint32_t *left, uint32_t *right, bool force)
{
    uint32_t newLeft = *left;
    uint32_t newRight = *right;
    bool hasControl = false;
    int ctrlIdx = -1;
    size_t size = mEffects.size();
    const size_t size = mEffects.size();

    // first update volume controller
    for (size_t i = size; i > 0; i--) {
        if (mEffects[i - 1]->isVolumeControlEnabled()) {
            ctrlIdx = i - 1;
            hasControl = true;
            break;
        }
    }
    const auto volumeControlIndex = findVolumeControl_l(0, size);
    const int ctrlIdx = volumeControlIndex.value_or(-1);
    const sp<IAfEffectModule> volumeControlEffect =
            volumeControlIndex.has_value() ? mEffects[ctrlIdx] : nullptr;
    const sp<IAfEffectModule> cachedVolumeControlEffect = mVolumeControlEffect.promote();

    if (!force && ctrlIdx == mVolumeCtrlIdx &&
    if (!force && volumeControlEffect == cachedVolumeControlEffect &&
            *left == mLeftVolume && *right == mRightVolume) {
        if (hasControl) {
        if (volumeControlIndex.has_value()) {
            *left = mNewLeftVolume;
            *right = mNewRightVolume;
        }
        return hasControl;
        return volumeControlIndex.has_value();
    }

    mVolumeCtrlIdx = ctrlIdx;
    if (volumeControlEffect != cachedVolumeControlEffect) {
        // The volume control effect is a new one. Set the old one as full volume. Set the new onw
        // as zero for safe ramping.
        if (cachedVolumeControlEffect != nullptr) {
            uint32_t leftMax = 1 << 24;
            uint32_t rightMax = 1 << 24;
            cachedVolumeControlEffect->setVolume(&leftMax, &rightMax, true /*controller*/);
        }
        if (volumeControlEffect != nullptr) {
            uint32_t leftZero = 0;
            uint32_t rightZero = 0;
            volumeControlEffect->setVolume(&leftZero, &rightZero, true /*controller*/);
        }
    }
    mLeftVolume = newLeft;
    mRightVolume = newRight;

@@ -2593,7 +2604,7 @@ bool EffectChain::setVolume_l(uint32_t *left, uint32_t *right, bool force)

    setVolumeForOutput_l(*left, *right);

    return hasControl;
    return volumeControlIndex.has_value();
}

// resetVolume_l() must be called with IAfThreadBase::mutex() or EffectChain::mLock held
+4 −1
Original line number Diff line number Diff line
@@ -622,6 +622,8 @@ private:

    ssize_t getInsertIndex(const effect_descriptor_t& desc);

    std::optional<size_t> findVolumeControl_l(size_t from, size_t to) const;

    mutable  Mutex mLock;        // mutex protecting effect list
             Vector<sp<IAfEffectModule>> mEffects; // list of effect modules
             audio_session_t mSessionId; // audio session ID
@@ -634,7 +636,6 @@ private:

             int32_t mTailBufferCount;   // current effect tail buffer count
             int32_t mMaxTailBuffers;    // maximum effect tail buffers
             int mVolumeCtrlIdx;         // index of insert effect having control over volume
             uint32_t mLeftVolume;       // previous volume on left channel
             uint32_t mRightVolume;      // previous volume on right channel
             uint32_t mNewLeftVolume;       // new volume on left channel
@@ -647,6 +648,8 @@ private:
             KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects;

             const sp<EffectCallback> mEffectCallback;

             wp<IAfEffectModule> mVolumeControlEffect;
};

class DeviceEffectProxy : public IAfDeviceEffectProxy, public EffectBase {