aaudio: fix small underflow when a stream is stopped
Also remove inconsequential volume parameter.
Bug: 67910437
Test: test_aaudio_monkey.cpp and write_sine_callback.cpp
Change-Id: I6d11f3bfced3d579440f99c02d01a7d68af5c1e0
diff --git a/services/oboeservice/AAudioServiceEndpointPlay.cpp b/services/oboeservice/AAudioServiceEndpointPlay.cpp
index 9b1833a..472a336 100644
--- a/services/oboeservice/AAudioServiceEndpointPlay.cpp
+++ b/services/oboeservice/AAudioServiceEndpointPlay.cpp
@@ -82,9 +82,13 @@
std::lock_guard <std::mutex> lock(mLockStreams);
for (const auto clientStream : mRegisteredStreams) {
int64_t clientFramesRead = 0;
+ bool allowUnderflow = true;
- if (!clientStream->isRunning()) {
- continue;
+ aaudio_stream_state_t state = clientStream->getState();
+ if (state == AAUDIO_STREAM_STATE_STOPPING) {
+ allowUnderflow = false; // just read what is already in the FIFO
+ } else if (state != AAUDIO_STREAM_STATE_STARTED) {
+ continue; // this stream is not running so skip it.
}
sp<AAudioServiceStreamShared> streamShared =
@@ -104,8 +108,7 @@
int64_t positionOffset = mmapFramesWritten - clientFramesRead;
streamShared->setTimestampPositionOffset(positionOffset);
- float volume = 1.0; // to match legacy volume
- bool underflowed = mMixer.mix(index, fifo, volume);
+ bool underflowed = mMixer.mix(index, fifo, allowUnderflow);
if (underflowed) {
streamShared->incrementXRunCount();
}