Merge "audioflinger: fix offload underrun sleep logic" into nyc-dev
am: eebc3ad
* commit 'eebc3ad457d5b9a1acc0fe0393b770004016a014':
audioflinger: fix offload underrun sleep logic
Change-Id: I85a5ec92178cf7edbbcea47459833af95e338b3f
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index b82682d..87374bc 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -3162,20 +3162,23 @@
if ((mType == OFFLOAD) && !audio_has_proportional_frames(mFormat)) {
Mutex::Autolock _l(mLock);
if (!mSignalPending && !exitPending()) {
- // Do not sleep more than one buffer duration since last write and not
- // less than kDirectMinSleepTimeUs
+ // If more than one buffer has been written to the audio HAL since exiting
+ // standby or last flush, do not sleep more than one buffer duration
+ // since last write and not less than kDirectMinSleepTimeUs.
// Wake up if a command is received
- nsecs_t now = systemTime();
- uint32_t deltaUs = (uint32_t)((now - mLastWriteTime) / 1000);
uint32_t timeoutUs = mSleepTimeUs;
- if (timeoutUs + deltaUs > mBufferDurationUs) {
- if (mBufferDurationUs > deltaUs) {
- timeoutUs = mBufferDurationUs - deltaUs;
- if (timeoutUs < kDirectMinSleepTimeUs) {
+ if (mBytesWritten >= (int64_t) mBufferSize) {
+ nsecs_t now = systemTime();
+ uint32_t deltaUs = (uint32_t)((now - mLastWriteTime) / 1000);
+ if (timeoutUs + deltaUs > mBufferDurationUs) {
+ if (mBufferDurationUs > deltaUs) {
+ timeoutUs = mBufferDurationUs - deltaUs;
+ if (timeoutUs < kDirectMinSleepTimeUs) {
+ timeoutUs = kDirectMinSleepTimeUs;
+ }
+ } else {
timeoutUs = kDirectMinSleepTimeUs;
}
- } else {
- timeoutUs = kDirectMinSleepTimeUs;
}
}
mWaitWorkCV.waitRelative(mLock, microseconds((nsecs_t)timeoutUs));
@@ -5418,6 +5421,8 @@
mBytesRemaining = 0;
mPausedWriteLength = 0;
mPausedBytesRemaining = 0;
+ // reset bytes written count to reflect that DSP buffers are empty after flush.
+ mBytesWritten = 0;
if (mUseAsyncWrite) {
// discard any pending drain or write ack by incrementing sequence