Loading services/audioflinger/Effects.cpp +21 −12 Original line number Diff line number Diff line Loading @@ -1358,15 +1358,16 @@ void EffectModule::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) { } } status_t EffectModule::setVolume(uint32_t* left, uint32_t* right, bool controller, bool force) { status_t EffectModule::setVolume_l(uint32_t* left, uint32_t* right, bool controller, bool force) { AutoLockReentrant _l(mutex(), mSetVolumeReentrantTid); if (mStatus != NO_ERROR) { return mStatus; } status_t status = NO_ERROR; // Send volume indication if EFFECT_FLAG_VOLUME_IND is set and read back altered volume // if controller flag is set (Note that controller == TRUE => EFFECT_FLAG_VOLUME_CTRL set) if ((isProcessEnabled() || force) && // if controller flag is set (Note that controller == TRUE => the volume controller effect in // the effect chain) if (((isOffloadedOrDirect_l() ? isEnabled() : isProcessEnabled()) || force) && ((mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL || (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_IND || (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_MONITOR)) { Loading @@ -1377,7 +1378,8 @@ status_t EffectModule::setVolume(uint32_t* left, uint32_t* right, bool controlle status_t EffectModule::setVolumeInternal( uint32_t *left, uint32_t *right, bool controller) { if (mVolume.has_value() && *left == mVolume.value()[0] && *right == mVolume.value()[1]) { if (mVolume.has_value() && *left == mVolume.value()[0] && *right == mVolume.value()[1] && !controller) { LOG_ALWAYS_FATAL_IF( !mReturnedVolume.has_value(), "The cached returned volume must not be null when the cached volume has value"); Loading @@ -1387,14 +1389,14 @@ status_t EffectModule::setVolumeInternal( } LOG_ALWAYS_FATAL_IF(mEffectInterface == nullptr, "%s", mEffectInterfaceDebug.c_str()); uint32_t volume[2] = {*left, *right}; uint32_t *pVolume = controller ? volume : nullptr; uint32_t* pVolume = isVolumeControl() ? volume : nullptr; uint32_t size = sizeof(volume); status_t status = mEffectInterface->command(EFFECT_CMD_SET_VOLUME, size, volume, &size, pVolume); if (controller && status == NO_ERROR && size == sizeof(volume)) { if (pVolume && status == NO_ERROR && size == sizeof(volume)) { mVolume = {*left, *right}; // Cache the value that has been set *left = volume[0]; *right = volume[1]; Loading Loading @@ -2425,7 +2427,7 @@ status_t EffectChain::addEffect_l(const sp<IAfEffectModule>& effect) // volume will be set from setVolume_l. uint32_t left = 0; uint32_t right = 0; effect->setVolume(&left, &right, true /*controller*/, true /*force*/); effect->setVolume_l(&left, &right, true /*controller*/, true /*force*/); } } Loading Loading @@ -2623,6 +2625,7 @@ bool EffectChain::setVolume_l(uint32_t* left, uint32_t* right, bool force) { // first update volume controller const auto volumeControlIndex = findVolumeControl_l(0, size); // index of the effect chain volume controller const int ctrlIdx = volumeControlIndex.value_or(-1); const sp<IAfEffectModule> volumeControlEffect = volumeControlIndex.has_value() ? mEffects[ctrlIdx] : nullptr; Loading @@ -2639,12 +2642,15 @@ bool EffectChain::setVolume_l(uint32_t* left, uint32_t* right, bool force) { mVolumeControlEffect = volumeControlEffect; for (int i = 0; i < ctrlIdx; ++i) { // For all volume control effects before the effect that controls volume, set the volume // For all effects before the effect that controls volume, they are not controlling the // effect chain volume, if these effects has the volume control capability, set the volume // to maximum to avoid double attenuation. if (mEffects[i]->isVolumeControl()) { uint32_t leftMax = 1 << 24; uint32_t rightMax = 1 << 24; mEffects[i]->setVolume(&leftMax, &rightMax, true /*controller*/, true /*force*/); mEffects[i]->setVolume_l(&leftMax, &rightMax, false /* not an effect chain volume controller */, true /* force */); } } Loading @@ -2653,7 +2659,8 @@ bool EffectChain::setVolume_l(uint32_t* left, uint32_t* right, bool force) { // second get volume update from volume controller if (ctrlIdx >= 0) { mEffects[ctrlIdx]->setVolume(&newLeft, &newRight, true); mEffects[ctrlIdx]->setVolume_l(&newLeft, &newRight, true /* effect chain volume controller */); mNewLeftVolume = newLeft; mNewRightVolume = newRight; } Loading @@ -2674,9 +2681,11 @@ bool EffectChain::setVolume_l(uint32_t* left, uint32_t* right, bool force) { } // Pass requested volume directly if this is volume monitor module if (mEffects[i]->isVolumeMonitor()) { mEffects[i]->setVolume(left, right, false); mEffects[i]->setVolume_l(left, right, false /* not an effect chain volume controller */); } else { mEffects[i]->setVolume(&lVol, &rVol, false); mEffects[i]->setVolume_l(&lVol, &rVol, false /* not an effect chain volume controller */); } } *left = newLeft; Loading services/audioflinger/Effects.h +4 −3 Original line number Diff line number Diff line Loading @@ -217,7 +217,8 @@ public: } status_t setDevices(const AudioDeviceTypeAddrVector& devices) final EXCLUDES_EffectBase_Mutex; status_t setInputDevice(const AudioDeviceTypeAddr& device) final EXCLUDES_EffectBase_Mutex; status_t setVolume(uint32_t *left, uint32_t *right, bool controller, bool force) final; status_t setVolume_l(uint32_t* left, uint32_t* right, bool controller, bool force) final REQUIRES(audio_utils::EffectChain_Mutex); status_t setMode(audio_mode_t mode) final EXCLUDES_EffectBase_Mutex; status_t setAudioSource(audio_source_t source) final EXCLUDES_EffectBase_Mutex; status_t start_l() final REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex; Loading Loading @@ -265,8 +266,8 @@ private: ? EFFECT_BUFFER_ACCESS_WRITE : EFFECT_BUFFER_ACCESS_ACCUMULATE; } status_t setVolumeInternal(uint32_t *left, uint32_t *right, bool controller); status_t setVolumeInternal(uint32_t* left, uint32_t* right, bool controller /* the volume controller effect of the chain */); effect_config_t mConfig; // input and output audio configuration sp<EffectHalInterface> mEffectInterface; // Effect module HAL Loading services/audioflinger/IAfEffect.h +3 −2 Original line number Diff line number Diff line Loading @@ -163,8 +163,9 @@ public: virtual int16_t *inBuffer() const = 0; virtual status_t setDevices(const AudioDeviceTypeAddrVector &devices) = 0; virtual status_t setInputDevice(const AudioDeviceTypeAddr &device) = 0; virtual status_t setVolume(uint32_t *left, uint32_t *right, bool controller, bool force = false) = 0; virtual status_t setVolume_l(uint32_t* left, uint32_t* right, bool controller /* effect controlling chain volume */, bool force = false) REQUIRES(audio_utils::EffectChain_Mutex) = 0; virtual status_t setOffloaded_l(bool offloaded, audio_io_handle_t io) = 0; virtual bool isOffloaded_l() const = 0; Loading Loading
services/audioflinger/Effects.cpp +21 −12 Original line number Diff line number Diff line Loading @@ -1358,15 +1358,16 @@ void EffectModule::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) { } } status_t EffectModule::setVolume(uint32_t* left, uint32_t* right, bool controller, bool force) { status_t EffectModule::setVolume_l(uint32_t* left, uint32_t* right, bool controller, bool force) { AutoLockReentrant _l(mutex(), mSetVolumeReentrantTid); if (mStatus != NO_ERROR) { return mStatus; } status_t status = NO_ERROR; // Send volume indication if EFFECT_FLAG_VOLUME_IND is set and read back altered volume // if controller flag is set (Note that controller == TRUE => EFFECT_FLAG_VOLUME_CTRL set) if ((isProcessEnabled() || force) && // if controller flag is set (Note that controller == TRUE => the volume controller effect in // the effect chain) if (((isOffloadedOrDirect_l() ? isEnabled() : isProcessEnabled()) || force) && ((mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL || (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_IND || (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_MONITOR)) { Loading @@ -1377,7 +1378,8 @@ status_t EffectModule::setVolume(uint32_t* left, uint32_t* right, bool controlle status_t EffectModule::setVolumeInternal( uint32_t *left, uint32_t *right, bool controller) { if (mVolume.has_value() && *left == mVolume.value()[0] && *right == mVolume.value()[1]) { if (mVolume.has_value() && *left == mVolume.value()[0] && *right == mVolume.value()[1] && !controller) { LOG_ALWAYS_FATAL_IF( !mReturnedVolume.has_value(), "The cached returned volume must not be null when the cached volume has value"); Loading @@ -1387,14 +1389,14 @@ status_t EffectModule::setVolumeInternal( } LOG_ALWAYS_FATAL_IF(mEffectInterface == nullptr, "%s", mEffectInterfaceDebug.c_str()); uint32_t volume[2] = {*left, *right}; uint32_t *pVolume = controller ? volume : nullptr; uint32_t* pVolume = isVolumeControl() ? volume : nullptr; uint32_t size = sizeof(volume); status_t status = mEffectInterface->command(EFFECT_CMD_SET_VOLUME, size, volume, &size, pVolume); if (controller && status == NO_ERROR && size == sizeof(volume)) { if (pVolume && status == NO_ERROR && size == sizeof(volume)) { mVolume = {*left, *right}; // Cache the value that has been set *left = volume[0]; *right = volume[1]; Loading Loading @@ -2425,7 +2427,7 @@ status_t EffectChain::addEffect_l(const sp<IAfEffectModule>& effect) // volume will be set from setVolume_l. uint32_t left = 0; uint32_t right = 0; effect->setVolume(&left, &right, true /*controller*/, true /*force*/); effect->setVolume_l(&left, &right, true /*controller*/, true /*force*/); } } Loading Loading @@ -2623,6 +2625,7 @@ bool EffectChain::setVolume_l(uint32_t* left, uint32_t* right, bool force) { // first update volume controller const auto volumeControlIndex = findVolumeControl_l(0, size); // index of the effect chain volume controller const int ctrlIdx = volumeControlIndex.value_or(-1); const sp<IAfEffectModule> volumeControlEffect = volumeControlIndex.has_value() ? mEffects[ctrlIdx] : nullptr; Loading @@ -2639,12 +2642,15 @@ bool EffectChain::setVolume_l(uint32_t* left, uint32_t* right, bool force) { mVolumeControlEffect = volumeControlEffect; for (int i = 0; i < ctrlIdx; ++i) { // For all volume control effects before the effect that controls volume, set the volume // For all effects before the effect that controls volume, they are not controlling the // effect chain volume, if these effects has the volume control capability, set the volume // to maximum to avoid double attenuation. if (mEffects[i]->isVolumeControl()) { uint32_t leftMax = 1 << 24; uint32_t rightMax = 1 << 24; mEffects[i]->setVolume(&leftMax, &rightMax, true /*controller*/, true /*force*/); mEffects[i]->setVolume_l(&leftMax, &rightMax, false /* not an effect chain volume controller */, true /* force */); } } Loading @@ -2653,7 +2659,8 @@ bool EffectChain::setVolume_l(uint32_t* left, uint32_t* right, bool force) { // second get volume update from volume controller if (ctrlIdx >= 0) { mEffects[ctrlIdx]->setVolume(&newLeft, &newRight, true); mEffects[ctrlIdx]->setVolume_l(&newLeft, &newRight, true /* effect chain volume controller */); mNewLeftVolume = newLeft; mNewRightVolume = newRight; } Loading @@ -2674,9 +2681,11 @@ bool EffectChain::setVolume_l(uint32_t* left, uint32_t* right, bool force) { } // Pass requested volume directly if this is volume monitor module if (mEffects[i]->isVolumeMonitor()) { mEffects[i]->setVolume(left, right, false); mEffects[i]->setVolume_l(left, right, false /* not an effect chain volume controller */); } else { mEffects[i]->setVolume(&lVol, &rVol, false); mEffects[i]->setVolume_l(&lVol, &rVol, false /* not an effect chain volume controller */); } } *left = newLeft; Loading
services/audioflinger/Effects.h +4 −3 Original line number Diff line number Diff line Loading @@ -217,7 +217,8 @@ public: } status_t setDevices(const AudioDeviceTypeAddrVector& devices) final EXCLUDES_EffectBase_Mutex; status_t setInputDevice(const AudioDeviceTypeAddr& device) final EXCLUDES_EffectBase_Mutex; status_t setVolume(uint32_t *left, uint32_t *right, bool controller, bool force) final; status_t setVolume_l(uint32_t* left, uint32_t* right, bool controller, bool force) final REQUIRES(audio_utils::EffectChain_Mutex); status_t setMode(audio_mode_t mode) final EXCLUDES_EffectBase_Mutex; status_t setAudioSource(audio_source_t source) final EXCLUDES_EffectBase_Mutex; status_t start_l() final REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex; Loading Loading @@ -265,8 +266,8 @@ private: ? EFFECT_BUFFER_ACCESS_WRITE : EFFECT_BUFFER_ACCESS_ACCUMULATE; } status_t setVolumeInternal(uint32_t *left, uint32_t *right, bool controller); status_t setVolumeInternal(uint32_t* left, uint32_t* right, bool controller /* the volume controller effect of the chain */); effect_config_t mConfig; // input and output audio configuration sp<EffectHalInterface> mEffectInterface; // Effect module HAL Loading
services/audioflinger/IAfEffect.h +3 −2 Original line number Diff line number Diff line Loading @@ -163,8 +163,9 @@ public: virtual int16_t *inBuffer() const = 0; virtual status_t setDevices(const AudioDeviceTypeAddrVector &devices) = 0; virtual status_t setInputDevice(const AudioDeviceTypeAddr &device) = 0; virtual status_t setVolume(uint32_t *left, uint32_t *right, bool controller, bool force = false) = 0; virtual status_t setVolume_l(uint32_t* left, uint32_t* right, bool controller /* effect controlling chain volume */, bool force = false) REQUIRES(audio_utils::EffectChain_Mutex) = 0; virtual status_t setOffloaded_l(bool offloaded, audio_io_handle_t io) = 0; virtual bool isOffloaded_l() const = 0; Loading