aaudio: lower latency using MMAP capture
MMAP can be enabled by setting system properties.
Bug: 38267780
Test: input_monitor.cpp
Change-Id: I5e86fd1d9baef4fe59837ccbca7971acbb54d8b5
Signed-off-by: Phil Burk <philburk@google.com>
diff --git a/services/oboeservice/AAudioEndpointManager.cpp b/services/oboeservice/AAudioEndpointManager.cpp
index 65b17bc..2cb0cba 100644
--- a/services/oboeservice/AAudioEndpointManager.cpp
+++ b/services/oboeservice/AAudioEndpointManager.cpp
@@ -21,10 +21,8 @@
#include <assert.h>
#include <map>
#include <mutex>
-#include <utils/Singleton.h>
#include "AAudioEndpointManager.h"
-#include "AAudioServiceEndpoint.h"
using namespace android;
using namespace aaudio;
@@ -55,32 +53,36 @@
assert(false); // There are only two possible directions.
break;
}
-
- // If we can't find an existing one then open one.
ALOGD("AAudioEndpointManager::openEndpoint(), found %p", endpoint);
+
+ // If we can't find an existing one then open a new one.
if (endpoint == nullptr) {
- endpoint = new AAudioServiceEndpoint(audioService);
- if (endpoint->open(deviceId, direction) != AAUDIO_OK) {
- ALOGE("AAudioEndpointManager::findEndpoint(), open failed");
- delete endpoint;
- endpoint = nullptr;
- } else {
- switch(direction) {
- case AAUDIO_DIRECTION_INPUT:
- mInputs[deviceId] = endpoint;
- break;
- case AAUDIO_DIRECTION_OUTPUT:
- mOutputs[deviceId] = endpoint;
- break;
+ if (direction == AAUDIO_DIRECTION_INPUT) {
+ AAudioServiceEndpointCapture *capture = new AAudioServiceEndpointCapture(audioService);
+ if (capture->open(deviceId) != AAUDIO_OK) {
+ ALOGE("AAudioEndpointManager::openEndpoint(), open failed");
+ delete capture;
+ } else {
+ mInputs[deviceId] = capture;
+ endpoint = capture;
+ }
+ } else if (direction == AAUDIO_DIRECTION_OUTPUT) {
+ AAudioServiceEndpointPlay *player = new AAudioServiceEndpointPlay(audioService);
+ if (player->open(deviceId) != AAUDIO_OK) {
+ ALOGE("AAudioEndpointManager::openEndpoint(), open failed");
+ delete player;
+ } else {
+ mOutputs[deviceId] = player;
+ endpoint = player;
}
}
+
}
if (endpoint != nullptr) {
// Increment the reference count under this lock.
endpoint->setReferenceCount(endpoint->getReferenceCount() + 1);
}
-
return endpoint;
}
@@ -105,6 +107,7 @@
mOutputs.erase(deviceId);
break;
}
+
serviceEndpoint->close();
delete serviceEndpoint;
}