audio flinger: pause direct output when underrunning
If a direct output supports pause, pause the stream
instead of placing it into standby when the audio track
underruns. This will avoid resetting the presented frame count
and preserve A/V sync.
Bug: 21437855.
Change-Id: I598346edb62a1864126acdb1d9a937c82eac2191
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 594ed05..d9b4249 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -4443,7 +4443,7 @@
track->mRetryCount = kMaxTrackRetriesDirect;
mActiveTrack = t;
mixerStatus = MIXER_TRACKS_READY;
- if (usesHwAvSync() && mHwPaused) {
+ if (mHwPaused) {
doHwResume = true;
mHwPaused = false;
}
@@ -4495,7 +4495,7 @@
android_atomic_or(CBLK_DISABLED, &cblk->mFlags);
} else if (last) {
mixerStatus = MIXER_TRACKS_ENABLED;
- if (usesHwAvSync() && !mHwPaused && !mStandby) {
+ if (mHwSupportsPause && !mHwPaused && !mStandby) {
doHwPause = true;
mHwPaused = true;
}
@@ -4609,7 +4609,7 @@
mTracks[mTracks.size() - 1]->mState == TrackBase::IDLE;
}
- return !mStandby && !(trackPaused || (usesHwAvSync() && mHwPaused && !trackStopped));
+ return !mStandby && !(trackPaused || (mHwPaused && !trackStopped));
}
// getTrackName_l() must be called with ThreadBase::mLock held
@@ -4715,10 +4715,10 @@
// no delay on outputs with HW A/V sync
if (usesHwAvSync()) {
standbyDelay = 0;
- } else if (audio_is_linear_pcm(mFormat)) {
- standbyDelay = microseconds(activeSleepTime*2);
- } else {
+ } else if ((mType == OFFLOAD) && !audio_is_linear_pcm(mFormat)) {
standbyDelay = kOffloadStandbyDelayNs;
+ } else {
+ standbyDelay = microseconds(activeSleepTime*2);
}
}
@@ -4898,7 +4898,7 @@
if (track->isPausing()) {
track->setPaused();
if (last) {
- if (!mHwPaused) {
+ if (mHwSupportsPause && !mHwPaused) {
doHwPause = true;
mHwPaused = true;
}