Skip to content

Commit 4433169

Browse files
author
Eric Laurent
committed
audioflinger: fix audio skipping over A2DP
The maximum sleep time allowed in the mixer thread when audio tracks are enabled but not ready for mixing is derived from the latency reported by the output stream. This does not work for A2DP where the latency also reflects encoding, decoding and transfer time. Modified activeSleepTimeUs() to take A2DP case into account. Issue 5682206. Change-Id: I3784ac01fb6f836b5a6ce6f764fb15347586de35
1 parent e35581a commit 4433169

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

services/audioflinger/AudioFlinger.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,18 @@ audio_stream_t* AudioFlinger::PlaybackThread::stream()
18161816
return &mOutput->stream->common;
18171817
}
18181818

1819+
uint32_t AudioFlinger::PlaybackThread::activeSleepTimeUs()
1820+
{
1821+
// A2DP output latency is not due only to buffering capacity. It also reflects encoding,
1822+
// decoding and transfer time. So sleeping for half of the latency would likely cause
1823+
// underruns
1824+
if (audio_is_a2dp_device((audio_devices_t)mDevice)) {
1825+
return (uint32_t)((uint32_t)((mFrameCount * 1000) / mSampleRate) * 1000);
1826+
} else {
1827+
return (uint32_t)(mOutput->stream->get_latency(mOutput->stream) * 1000) / 2;
1828+
}
1829+
}
1830+
18191831
// ----------------------------------------------------------------------------
18201832

18211833
AudioFlinger::MixerThread::MixerThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device)
@@ -2422,11 +2434,6 @@ status_t AudioFlinger::MixerThread::dumpInternals(int fd, const Vector<String16>
24222434
return NO_ERROR;
24232435
}
24242436

2425-
uint32_t AudioFlinger::MixerThread::activeSleepTimeUs()
2426-
{
2427-
return (uint32_t)(mOutput->stream->get_latency(mOutput->stream) * 1000) / 2;
2428-
}
2429-
24302437
uint32_t AudioFlinger::MixerThread::idleSleepTimeUs()
24312438
{
24322439
return (uint32_t)(((mFrameCount * 1000) / mSampleRate) * 1000) / 2;
@@ -2893,7 +2900,7 @@ uint32_t AudioFlinger::DirectOutputThread::activeSleepTimeUs()
28932900
{
28942901
uint32_t time;
28952902
if (audio_is_linear_pcm(mFormat)) {
2896-
time = (uint32_t)(mOutput->stream->get_latency(mOutput->stream) * 1000) / 2;
2903+
time = PlaybackThread::activeSleepTimeUs();
28972904
} else {
28982905
time = 10000;
28992906
}

services/audioflinger/AudioFlinger.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ class AudioFlinger :
776776

777777
virtual int getTrackName_l() = 0;
778778
virtual void deleteTrackName_l(int name) = 0;
779-
virtual uint32_t activeSleepTimeUs() = 0;
779+
virtual uint32_t activeSleepTimeUs();
780780
virtual uint32_t idleSleepTimeUs() = 0;
781781
virtual uint32_t suspendSleepTimeUs() = 0;
782782

@@ -833,7 +833,6 @@ class AudioFlinger :
833833
Vector< sp<Track> > *tracksToRemove);
834834
virtual int getTrackName_l();
835835
virtual void deleteTrackName_l(int name);
836-
virtual uint32_t activeSleepTimeUs();
837836
virtual uint32_t idleSleepTimeUs();
838837
virtual uint32_t suspendSleepTimeUs();
839838

0 commit comments

Comments
 (0)