aaudio: add AAudioStream_release()
Split close into close and release phases.
Release() will release hardware and service resources.
Close() will delete the stream object.
This allows us to defer the deletion and avoid race conditions.
The CLOSING state is used to indicate that a stream has been released.
Added some test cases to test_various.cpp.
A lone call to close() will automatically call release() so we should
have good code coverage for testing.
Bug: 136288001
Test: adb shell test_various
Test: atest CtsNativeMediaAAudioTestCases
Change-Id: Ia648838f30c521ba101f55259dbcd4594c1263cd
diff --git a/services/oboeservice/AAudioServiceStreamBase.cpp b/services/oboeservice/AAudioServiceStreamBase.cpp
index 880a3d7..39e90b1 100644
--- a/services/oboeservice/AAudioServiceStreamBase.cpp
+++ b/services/oboeservice/AAudioServiceStreamBase.cpp
@@ -56,7 +56,8 @@
LOG_ALWAYS_FATAL_IF(!(getState() == AAUDIO_STREAM_STATE_CLOSED
|| getState() == AAUDIO_STREAM_STATE_UNINITIALIZED
|| getState() == AAUDIO_STREAM_STATE_DISCONNECTED),
- "service stream still open, state = %d", getState());
+ "service stream %p still open, state = %d",
+ this, getState());
}
std::string AAudioServiceStreamBase::dumpHeader() {
@@ -126,13 +127,13 @@
}
aaudio_result_t AAudioServiceStreamBase::close() {
- aaudio_result_t result = AAUDIO_OK;
if (getState() == AAUDIO_STREAM_STATE_CLOSED) {
return AAUDIO_OK;
}
stop();
+ aaudio_result_t result = AAUDIO_OK;
sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote();
if (endpoint == nullptr) {
result = AAUDIO_ERROR_INVALID_STATE;