Add an indicator for stream is closed.
When the stream is closed, the HAL may not reply to any command via FMQ.
In that case, the framework should not send command if the stream is
closed.
Bug: 444055834
Test: crash OboeTester, check dumpsys audioflinger, aaudio
Flag: EXEMPT BUGFIX
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:9acf0c9e072038be1429c94109fa9a549012360f
Merged-In: I01250febf52b038b633e70a6afc0607cd329f61c
Change-Id: I01250febf52b038b633e70a6afc0607cd329f61c
diff --git a/media/libaudiohal/impl/StreamHalAidl.cpp b/media/libaudiohal/impl/StreamHalAidl.cpp
index 66d8543..d11b880 100644
--- a/media/libaudiohal/impl/StreamHalAidl.cpp
+++ b/media/libaudiohal/impl/StreamHalAidl.cpp
@@ -185,6 +185,8 @@
if (auto handler = mStreamCloseHandler.promote(); handler != nullptr) {
handler->streamClosed(sp<StreamHalInterface>::fromExisting(this));
}
+ std::lock_guard l(mLock);
+ mIsClosed = true;
}
AUGMENT_LOG_IF(E, !status.isOk(), "status %s", status.getDescription().c_str());
return statusTFromBinderStatus(status);
@@ -874,6 +876,10 @@
const ::aidl::android::hardware::audio::core::StreamDescriptor::Command& command,
::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply,
bool safeFromNonWorkerThread, StatePositions* statePositions) {
+ {
+ std::lock_guard l(mLock);
+ if (mIsClosed) return DEAD_OBJECT;
+ }
// Add timeCheck only for start command (pause, flush checked at caller).
std::unique_ptr<mediautils::TimeCheck> timeCheck;
diff --git a/media/libaudiohal/impl/StreamHalAidl.h b/media/libaudiohal/impl/StreamHalAidl.h
index f515f5a..244f053 100644
--- a/media/libaudiohal/impl/StreamHalAidl.h
+++ b/media/libaudiohal/impl/StreamHalAidl.h
@@ -326,7 +326,7 @@
const ::aidl::android::hardware::audio::core::StreamDescriptor::Command& command,
::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply = nullptr,
bool safeFromNonWorkerThread = false,
- StatePositions* statePositions = nullptr);
+ StatePositions* statePositions = nullptr) EXCLUDES(mLock);
status_t updateCountersIfNeeded(
::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply = nullptr,
StatePositions* statePositions = nullptr);
@@ -350,6 +350,7 @@
// Cached values of observable positions when the stream last entered certain state.
// Updated for output streams only.
StatePositions mStatePositions GUARDED_BY(mLock) = {};
+ bool mIsClosed GUARDED_BY(mLock) = false;
// mStreamPowerLog is used for audio signal power logging.
StreamPowerLog mStreamPowerLog;
std::atomic<pid_t> mWorkerTid = -1;