aaudio: set to SHARED when EXCLUSIVE fails
SHARED streams and endpoints were being created with sharing mode
set to EXCLUSIVE. This was confusing the close() code and caused a hang.
Now we create a modified Request object with the sharing mode set
correctly.
Bug: 112709847
Test: Hack AAudioServiceEndpointMMAP so isBufferShareable is false.
Test: 'adb shell write_sine_callback -pl -x -s2' should not hang.
Change-Id: I7a5c8260beaffdd706f34d35ef00a61b072adb1d
diff --git a/services/oboeservice/AAudioService.cpp b/services/oboeservice/AAudioService.cpp
index 94440b1..53ee145 100644
--- a/services/oboeservice/AAudioService.cpp
+++ b/services/oboeservice/AAudioService.cpp
@@ -118,11 +118,16 @@
}
}
- // if SHARED requested or if EXCLUSIVE failed
- if (sharingMode == AAUDIO_SHARING_MODE_SHARED
- || (serviceStream.get() == nullptr && !sharingModeMatchRequired)) {
+ // If SHARED requested or if EXCLUSIVE failed.
+ if (sharingMode == AAUDIO_SHARING_MODE_SHARED) {
serviceStream = new AAudioServiceStreamShared(*this);
result = serviceStream->open(request);
+ } else if (serviceStream.get() == nullptr && !sharingModeMatchRequired) {
+ aaudio::AAudioStreamRequest modifiedRequest = request;
+ // Overwrite the original EXCLUSIVE mode with SHARED.
+ modifiedRequest.getConfiguration().setSharingMode(AAUDIO_SHARING_MODE_SHARED);
+ serviceStream = new AAudioServiceStreamShared(*this);
+ result = serviceStream->open(modifiedRequest);
}
if (result != AAUDIO_OK) {