From a6e58fe31667fab8ccfd01912a5e76e5c6f6d71f Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Mon, 14 Sep 2009 01:38:42 -0700 Subject: [PATCH] Fix issue 2115450: a2dp thread is started, even though we are only connected to headset and not playing music. This is due to a regression introduced by change 24114: when no audio tracks are ready for mixing, 0s are written to audio hardware. However this should only happen if tracks have already been mixed since the audio flinger thread woke up. Also do not write 0s to audio hardware in direct output threads when audio format is not linear PCM. --- libs/audioflinger/AudioFlinger.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp index 790a6558a..d9be007ba 100644 --- a/libs/audioflinger/AudioFlinger.cpp +++ b/libs/audioflinger/AudioFlinger.cpp @@ -1239,7 +1239,7 @@ bool AudioFlinger::MixerThread::threadLoop() // active tracks were late. Sleep a little bit to give // them another chance. If we're too late, write 0s to audio // hardware to avoid underrun. - if (sleepTime < kMaxBufferRecoveryInUsecs) { + if (mBytesWritten == 0 || sleepTime < kMaxBufferRecoveryInUsecs) { usleep(kBufferRecoveryInUsecs); } else { memset (curBuf, 0, mixBufferSize); @@ -1741,7 +1741,8 @@ bool AudioFlinger::DirectOutputThread::threadLoop() standbyTime = systemTime() + kStandbyTimeInNsecs; } else { sleepTime += kBufferRecoveryInUsecs; - if (sleepTime < kMaxBufferRecoveryInUsecs) { + if (mBytesWritten == 0 || !AudioSystem::isLinearPCM(mFormat) || + sleepTime < kMaxBufferRecoveryInUsecs) { usleep(kBufferRecoveryInUsecs); } else { memset (mMixBuffer, 0, mFrameCount * mFrameSize);