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

Commit d505c647 authored by Zhou Song's avatar Zhou Song Committed by Andy Hung
Browse files

Effects: set hw volume if effect chain doesn't have volume control

If effect chain has non-offloaded effect, and is enabled for direct
output, when there's no volume control for all the effect modules
within this chain, volume should still be set to HAL.

Test: Play Music, Videos with effects
Bug: 149899134
CRs-Fixed: 2625597
Change-Id: I77bd0d456d5fa4e88afb283002a5eb1e2b704ca8
parent 831ed185
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -1395,7 +1395,11 @@ status_t AudioFlinger::EffectModule::setVolume(uint32_t *left, uint32_t *right,

void AudioFlinger::EffectChain::setVolumeForOutput_l(uint32_t left, uint32_t right)
{
    if (mEffectCallback->isOffloadOrDirect() && !isNonOffloadableEnabled_l()) {
    // for offload or direct thread, if the effect chain has non-offloadable
    // effect and any effect module within the chain has volume control, then
    // volume control is delegated to effect, otherwise, set volume to hal.
    if (mEffectCallback->isOffloadOrDirect() &&
        !(isNonOffloadableEnabled_l() && hasVolumeControlEnabled_l())) {
        float vol_l = (float)left / (1 << 24);
        float vol_r = (float)right / (1 << 24);
        mEffectCallback->setVolumeForOutput(vol_l, vol_r);
@@ -2296,6 +2300,13 @@ void AudioFlinger::EffectChain::setAudioSource_l(audio_source_t source)
    }
}

bool AudioFlinger::EffectChain::hasVolumeControlEnabled_l() const {
    for (const auto &effect : mEffects) {
        if (effect->isVolumeControlEnabled()) return true;
    }
    return false;
}

// setVolume_l() must be called with ThreadBase::mLock or EffectChain::mLock held
bool AudioFlinger::EffectChain::setVolume_l(uint32_t *left, uint32_t *right, bool force)
{
+3 −0
Original line number Diff line number Diff line
@@ -596,6 +596,9 @@ private:

    void setThread(const sp<ThreadBase>& thread);

    // true if any effect module within the chain has volume control
    bool hasVolumeControlEnabled_l() const;

    void setVolumeForOutput_l(uint32_t left, uint32_t right);

    mutable  Mutex mLock;        // mutex protecting effect list