Do not send command when aaudio command thread is not running.
If there is error when opening aaudio MMAP stream, the aaudio command
thread may not be started. In that case, if there is any command sending
to the command queue, it will always be blocked until timeout.
In this CL, sending command when the command thread is not running will
directly return AAUDIO_ERROR_INVALID_STATE.
Bug: 209520562
Test: atest AAudioTests
Test: repo steps from the bug
Change-Id: I01c076c120be9a68b984d0c365a61e77821ef117
diff --git a/services/oboeservice/AAudioCommandQueue.h b/services/oboeservice/AAudioCommandQueue.h
index 5f25507..64442a3 100644
--- a/services/oboeservice/AAudioCommandQueue.h
+++ b/services/oboeservice/AAudioCommandQueue.h
@@ -78,6 +78,12 @@
std::shared_ptr<AAudioCommand> waitForCommand(int64_t timeoutNanos = -1);
/**
+ * Start waiting for commands. Commands can only be pushed into the command queue after it
+ * starts waiting.
+ */
+ void startWaiting();
+
+ /**
* Force stop waiting for next command
*/
void stopWaiting();
@@ -87,7 +93,7 @@
std::condition_variable mWaitWorkCond;
std::queue<std::shared_ptr<AAudioCommand>> mCommands GUARDED_BY(mLock);
- bool mRunning GUARDED_BY(mLock) = true;
+ bool mRunning GUARDED_BY(mLock) = false;
};
} // namespace aaudio
\ No newline at end of file