AAudioService: integrated with audioserver
Call the MmapStreamInterface from AudioFlinger instead of the FakeHAL.
Fix sending timestamps from the thread.
Add shared mode in service.
Bug: 35260844
Bug: 33398120
Test: CTS test_aaudio.cpp
Change-Id: I44c7e4ecae4ce205611b6b73a72e0ae8a5b243e5
Signed-off-by: Phil Burk <philburk@google.com>
(cherry picked from commit 7f6b40d78b1976c78d1300e8a51fda36eeb50c5d)
diff --git a/services/oboeservice/AAudioThread.cpp b/services/oboeservice/AAudioThread.cpp
index f5e5784..b1b563d 100644
--- a/services/oboeservice/AAudioThread.cpp
+++ b/services/oboeservice/AAudioThread.cpp
@@ -21,14 +21,17 @@
#include <pthread.h>
#include <aaudio/AAudioDefinitions.h>
+#include <utility/AAudioUtilities.h>
#include "AAudioThread.h"
using namespace aaudio;
-AAudioThread::AAudioThread() {
- // mThread is a pthread_t of unknown size so we need memset.
+AAudioThread::AAudioThread()
+ : mRunnable(nullptr)
+ , mHasThread(false) {
+ // mThread is a pthread_t of unknown size so we need memset().
memset(&mThread, 0, sizeof(mThread));
}
@@ -50,14 +53,16 @@
aaudio_result_t AAudioThread::start(Runnable *runnable) {
if (mHasThread) {
+ ALOGE("AAudioThread::start() - mHasThread.load() already true");
return AAUDIO_ERROR_INVALID_STATE;
}
- mRunnable = runnable; // TODO use atomic?
+ // mRunnable will be read by the new thread when it starts.
+ // pthread_create() forces a memory synchronization so mRunnable does not need to be atomic.
+ mRunnable = runnable;
int err = pthread_create(&mThread, nullptr, AAudioThread_internalThreadProc, this);
if (err != 0) {
- ALOGE("AAudioThread::pthread_create() returned %d", err);
- // TODO convert errno to aaudio_result_t
- return AAUDIO_ERROR_INTERNAL;
+ ALOGE("AAudioThread::start() - pthread_create() returned %d %s", err, strerror(err));
+ return AAudioConvert_androidToAAudioResult(-err);
} else {
mHasThread = true;
return AAUDIO_OK;
@@ -70,7 +75,11 @@
}
int err = pthread_join(mThread, nullptr);
mHasThread = false;
- // TODO convert errno to aaudio_result_t
- return err ? AAUDIO_ERROR_INTERNAL : AAUDIO_OK;
+ if (err != 0) {
+ ALOGE("AAudioThread::stop() - pthread_join() returned %d %s", err, strerror(err));
+ return AAudioConvert_androidToAAudioResult(-err);
+ } else {
+ return AAUDIO_OK;
+ }
}