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

Commit 323b15a7 authored by Shunkai Yao's avatar Shunkai Yao Committed by Android Build Coastguard Worker
Browse files

Reset effect chain volume whenever the volume controller effect stopped

so the correct volume can be apply to the new volume controller

Bug: 347866898
Flag: EXEMPT bugfix
Test: repro steps in b/34786689
Test: atest CtsMediaAudioTestCases
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f62fbceee74181ff59727d1bc708bcf41cb95667)
Merged-In: I38187906f74c7cabc564d1aa01426257a0d90ba6
Change-Id: I38187906f74c7cabc564d1aa01426257a0d90ba6
parent 9f949976
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -617,10 +617,11 @@ EffectModule::~EffectModule()

}

// return true if any effect started or stopped
bool EffectModule::updateState_l() {
    audio_utils::lock_guard _l(mutex());

    bool started = false;
    bool startedOrStopped = false;
    switch (mState) {
    case RESTART:
        reset_l();
@@ -635,7 +636,7 @@ bool EffectModule::updateState_l() {
        }
        if (start_ll() == NO_ERROR) {
            mState = ACTIVE;
            started = true;
            startedOrStopped = true;
        } else {
            mState = IDLE;
        }
@@ -655,6 +656,7 @@ bool EffectModule::updateState_l() {
        // turn off sequence.
        if (--mDisableWaitCnt == 0) {
            reset_l();
            startedOrStopped = true;
            mState = IDLE;
        }
        break;
@@ -669,7 +671,7 @@ bool EffectModule::updateState_l() {
        break;
    }

    return started;
    return startedOrStopped;
}

void EffectModule::process()
@@ -2310,6 +2312,9 @@ void EffectChain::process_l() {
    }
    bool doResetVolume = false;
    for (size_t i = 0; i < size; i++) {
        // reset volume when any effect just started or stopped.
        // resetVolume_l will check if the volume controller effect in the chain needs update and
        // apply the correct volume
        doResetVolume = mEffects[i]->updateState_l() || doResetVolume;
    }
    if (doResetVolume) {
@@ -2663,6 +2668,9 @@ bool EffectChain::setVolume_l(uint32_t* left, uint32_t* right, bool force) {
                                       true /* effect chain volume controller */);
        mNewLeftVolume = newLeft;
        mNewRightVolume = newRight;
        ALOGD("%s sessionId %d volume controller effect %s set (%d, %d), ret (%d, %d)", __func__,
              mSessionId, mEffects[ctrlIdx]->desc().name, mLeftVolume, mRightVolume, newLeft,
              newRight);
    }
    // then indicate volume to all other effects in chain.
    // Pass altered volume to effects before volume controller
+4 −2
Original line number Diff line number Diff line
@@ -189,11 +189,13 @@ public:
    virtual status_t sendMetadata_ll(const std::vector<playback_track_metadata_v7_t>& metadata)
            REQUIRES(audio_utils::ThreadBase_Mutex,
                     audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex = 0;
    // return true if there was a state change from STARTING to ACTIVE, or STOPPED to IDLE, effect
    // chain will do a volume reset in these two cases
    virtual bool updateState_l()
            REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex = 0;

private:
    virtual void process() = 0;
    virtual bool updateState_l()
            REQUIRES(audio_utils::EffectChain_Mutex) EXCLUDES_EffectBase_Mutex = 0;
    virtual void reset_l() REQUIRES(audio_utils::EffectChain_Mutex) = 0;
    virtual status_t configure_l() REQUIRES(audio_utils::EffectChain_Mutex) = 0;
    virtual status_t init_l()