Skip to content

Commit 0609231

Browse files
author
Eric Laurent
committed
AudioFlinger: refine mixer sleep time logic
When an AudioTrack is in underrun state, the AudioFlinger mixer will sleep for a short period of time to give the app a chance to fill the AudioTrack buffer. If the AudioTrack is still not ready during next mixing round, the mixer will proceed with other tracks. If an application keeps a steady underrun condition, the AudioFlinger mixer will alternate between ready and not ready states. In the longer term this will cause the audio HAL to underrun. There is a mechanism to reduce the sleep period if the mixer is not ready several times in a row but this mechanism is defeated by the alternating ready/not ready conditions. The fix consists in only increasing sleep time if the mixer is ready for at least two consecutive times. Issue 5904527. Change-Id: Id0139bca9be8c4e425ec6d428515c4d8f718e8c9
1 parent 0b08965 commit 0609231

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

services/audioflinger/AudioFlinger.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,11 +1973,14 @@ bool AudioFlinger::MixerThread::threadLoop()
19731973
if (LIKELY(mixerStatus == MIXER_TRACKS_READY)) {
19741974
// mix buffers...
19751975
mAudioMixer->process();
1976-
sleepTime = 0;
1977-
// increase sleep time progressively when application underrun condition clears
1978-
if (sleepTimeShift > 0) {
1976+
// increase sleep time progressively when application underrun condition clears.
1977+
// Only increase sleep time if the mixer is ready for two consecutive times to avoid
1978+
// that a steady state of alternating ready/not ready conditions keeps the sleep time
1979+
// such that we would underrun the audio HAL.
1980+
if ((sleepTime == 0) && (sleepTimeShift > 0)) {
19791981
sleepTimeShift--;
19801982
}
1983+
sleepTime = 0;
19811984
standbyTime = systemTime() + kStandbyTimeInNsecs;
19821985
//TODO: delay standby when effects have a tail
19831986
} else {

0 commit comments

Comments
 (0)