aaudio: use strong pointer to protect callback
Hold a strong pointer to the AudioStream so it cannot get deleted while
the MMAP callback is running.
Also fixes disconnect for shared streams, which was broken
by a previous attempt to fix b/166877425
Bug: 166877425
Bug: 170551030
Test: see bug for details
Test: atest AAudioTestCases
Test: OboeTester V1.5.30 or later, "TEST DISCONNECT"
Change-Id: I236e2d68632070d253d14ddf7b9d7076e068830a
Merged-In: I236e2d68632070d253d14ddf7b9d7076e068830a
(cherry picked from commit e358ec63eedd7a6289984b1f2468c5c16c2ff6c8)
diff --git a/services/oboeservice/AAudioServiceEndpointCapture.cpp b/services/oboeservice/AAudioServiceEndpointCapture.cpp
index 220584c..3ba3c28 100644
--- a/services/oboeservice/AAudioServiceEndpointCapture.cpp
+++ b/services/oboeservice/AAudioServiceEndpointCapture.cpp
@@ -69,7 +69,9 @@
// Read audio data from stream using a blocking read.
result = getStreamInternal()->read(mDistributionBuffer, getFramesPerBurst(), timeoutNanos);
if (result == AAUDIO_ERROR_DISCONNECTED) {
- ALOGV("%s() read() returned AAUDIO_ERROR_DISCONNECTED, break", __func__);
+ ALOGD("%s() read() returned AAUDIO_ERROR_DISCONNECTED", __func__);
+ // We do not need the returned vector.
+ (void) AAudioServiceEndpointShared::disconnectRegisteredStreams();
break;
} else if (result != getFramesPerBurst()) {
ALOGW("callbackLoop() read %d / %d",