Loading services/audioflinger/Effects.cpp +34 −23 Original line number Diff line number Diff line Loading @@ -997,13 +997,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. Loading Loading @@ -2129,7 +2122,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)) { Loading Loading @@ -2367,6 +2360,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. Loading Loading @@ -2536,29 +2538,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; Loading Loading @@ -2595,7 +2606,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 Loading services/audioflinger/Effects.h +4 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -647,6 +648,8 @@ private: KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects; const sp<EffectCallback> mEffectCallback; wp<IAfEffectModule> mVolumeControlEffect; }; class DeviceEffectProxy : public IAfDeviceEffectProxy, public EffectBase { Loading Loading
services/audioflinger/Effects.cpp +34 −23 Original line number Diff line number Diff line Loading @@ -997,13 +997,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. Loading Loading @@ -2129,7 +2122,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)) { Loading Loading @@ -2367,6 +2360,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. Loading Loading @@ -2536,29 +2538,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; Loading Loading @@ -2595,7 +2606,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 Loading
services/audioflinger/Effects.h +4 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -647,6 +648,8 @@ private: KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects; const sp<EffectCallback> mEffectCallback; wp<IAfEffectModule> mVolumeControlEffect; }; class DeviceEffectProxy : public IAfDeviceEffectProxy, public EffectBase { Loading