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

Commit 8448a797 authored by Eric Laurent's avatar Eric Laurent
Browse files

Fix issue 2929440

Fixed regression introduced by change a54d7d3d in audioflinger mixer thread:
When the output stream is suspended, the sleep time between two writes must match the actual duration
of one output stream buffer otherwise the playback rate is not respected.

Change-Id: Ic5bebe890290d1f44aeff9dd3c142d18e26fff2a
parent f6354aca
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -1601,7 +1601,7 @@ bool AudioFlinger::MixerThread::threadLoop()
        }

        if (mSuspended) {
            sleepTime = idleSleepTime;
            sleepTime = suspendSleepTimeUs();
        }
        // sleepTime == 0 means we must write to audio hardware
        if (sleepTime == 0) {
@@ -2021,6 +2021,11 @@ uint32_t AudioFlinger::MixerThread::idleSleepTimeUs()
    return (uint32_t)(((mFrameCount * 1000) / mSampleRate) * 1000) / 2;
}

uint32_t AudioFlinger::MixerThread::suspendSleepTimeUs()
{
    return (uint32_t)(((mFrameCount * 1000) / mSampleRate) * 1000);
}

// ----------------------------------------------------------------------------
AudioFlinger::DirectOutputThread::DirectOutputThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device)
    :   PlaybackThread(audioFlinger, output, id, device)
@@ -2365,7 +2370,7 @@ bool AudioFlinger::DirectOutputThread::threadLoop()
        }

        if (mSuspended) {
            sleepTime = idleSleepTime;
            sleepTime = suspendSleepTimeUs();
        }
        // sleepTime == 0 means we must write to audio hardware
        if (sleepTime == 0) {
@@ -2486,6 +2491,18 @@ uint32_t AudioFlinger::DirectOutputThread::idleSleepTimeUs()
    return time;
}

uint32_t AudioFlinger::DirectOutputThread::suspendSleepTimeUs()
{
    uint32_t time;
    if (AudioSystem::isLinearPCM(mFormat)) {
        time = (uint32_t)(((mFrameCount * 1000) / mSampleRate) * 1000);
    } else {
        time = 10000;
    }
    return time;
}


// ----------------------------------------------------------------------------

AudioFlinger::DuplicatingThread::DuplicatingThread(const sp<AudioFlinger>& audioFlinger, AudioFlinger::MixerThread* mainThread, int id)
@@ -2612,7 +2629,7 @@ bool AudioFlinger::DuplicatingThread::threadLoop()
        }

        if (mSuspended) {
            sleepTime = idleSleepTime;
            sleepTime = suspendSleepTimeUs();
        }
        // sleepTime == 0 means we must write to audio hardware
        if (sleepTime == 0) {
+3 −0
Original line number Diff line number Diff line
@@ -664,6 +664,7 @@ private:
        virtual void            deleteTrackName_l(int name) = 0;
        virtual uint32_t        activeSleepTimeUs() = 0;
        virtual uint32_t        idleSleepTimeUs() = 0;
        virtual uint32_t        suspendSleepTimeUs() = 0;

    private:

@@ -724,6 +725,7 @@ private:
        virtual     void        deleteTrackName_l(int name);
        virtual     uint32_t    activeSleepTimeUs();
        virtual     uint32_t    idleSleepTimeUs();
        virtual     uint32_t    suspendSleepTimeUs();

        AudioMixer*                     mAudioMixer;
    };
@@ -744,6 +746,7 @@ private:
        virtual     void        deleteTrackName_l(int name);
        virtual     uint32_t    activeSleepTimeUs();
        virtual     uint32_t    idleSleepTimeUs();
        virtual     uint32_t    suspendSleepTimeUs();

    private:
        void applyVolume(uint16_t leftVol, uint16_t rightVol, bool ramp);