Release all connected streams when routing device is changed.
When there is a routing change, the existing mmap endpoint is
invalidated and can no longer be used. In that case, release all
registered streams and set the endpoint as disconnected so that it won't
be reused by another new request. That also releases the resources from
the service side so that it won't be harmful if the clients don't close
the stream when receiving disconnect event.
Bug: 299360979
Test: atest AAudioTests
Test: test_idle_disconnected_shared_stream
Change-Id: I4d7c68d5c0d15b75cc2f07471f50bfedb6292da9
diff --git a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
index 3badb0b..d98cf56 100644
--- a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
@@ -353,8 +353,10 @@
result = write(mCallbackBuffer.get(), mCallbackFrames, timeoutNanos);
if ((result != mCallbackFrames)) {
if (result >= 0) {
- // Only wrote some of the frames requested. Must have timed out.
- result = AAUDIO_ERROR_TIMEOUT;
+ // Only wrote some of the frames requested. The stream can be disconnected
+ // or timed out.
+ processCommands();
+ result = isDisconnected() ? AAUDIO_ERROR_DISCONNECTED : AAUDIO_ERROR_TIMEOUT;
}
maybeCallErrorCallback(result);
break;