aaudio: stop calling virtual methods from destructor
Was calling close(), which is abstract and virtual.
This may have been related to some audioserver crashes.
Also cleaned up some strong pointer handling.
Bug: 63390734
Bug: 63353455
Test: run CTS nativemedia/aaudio many times
Change-Id: Ib95aed60a64771b64395c67f0921c67146f9d10f
diff --git a/services/oboeservice/AAudioServiceStreamShared.cpp b/services/oboeservice/AAudioServiceStreamShared.cpp
index 1978ddd..9cc5cbc 100644
--- a/services/oboeservice/AAudioServiceStreamShared.cpp
+++ b/services/oboeservice/AAudioServiceStreamShared.cpp
@@ -44,10 +44,6 @@
{
}
-AAudioServiceStreamShared::~AAudioServiceStreamShared() {
- close();
-}
-
int32_t AAudioServiceStreamShared::calculateBufferCapacity(int32_t requestedCapacityFrames,
int32_t framesPerBurst) {
@@ -260,21 +256,27 @@
}
aaudio_result_t AAudioServiceStreamShared::close() {
- pause();
- // TODO wait for pause() to synchronize
- AAudioServiceEndpoint *endpoint = mServiceEndpoint;
- if (endpoint != nullptr) {
- sp<AAudioServiceStreamShared> keep(this);
- endpoint->unregisterStream(keep);
-
- AAudioEndpointManager &mEndpointManager = AAudioEndpointManager::getInstance();
- mEndpointManager.closeEndpoint(endpoint);
- mServiceEndpoint = nullptr;
+ if (mState == AAUDIO_STREAM_STATE_CLOSED) {
+ return AAUDIO_OK;
}
+
+ AAudioServiceEndpoint *endpoint = mServiceEndpoint;
+ if (endpoint == nullptr) {
+ return AAUDIO_ERROR_INVALID_STATE;
+ }
+ endpoint->stopStream(this);
+
+ endpoint->unregisterStream(this);
+
+ AAudioEndpointManager &mEndpointManager = AAudioEndpointManager::getInstance();
+ mEndpointManager.closeEndpoint(endpoint);
+ mServiceEndpoint = nullptr;
+
if (mAudioDataQueue != nullptr) {
delete mAudioDataQueue;
mAudioDataQueue = nullptr;
}
+
return AAudioServiceStreamBase::close();
}