aaudio: limit number of streams per process
Testing the new max streams restriction revealed the bug
involving the second shared stream.
Bug: 62951298
Bug: 63171495
Test: test_n_streams.cpp can open MAX_STREAMS_PER_PROCESS MMAP streams
Change-Id: Ibea7d9c4716326a37c669954b52f397ed2968caa
diff --git a/services/oboeservice/AAudioClientTracker.cpp b/services/oboeservice/AAudioClientTracker.cpp
index da7b80f..c0dfc54 100644
--- a/services/oboeservice/AAudioClientTracker.cpp
+++ b/services/oboeservice/AAudioClientTracker.cpp
@@ -68,6 +68,16 @@
mNotificationClients.erase(pid);
}
+int32_t AAudioClientTracker::getStreamCount(pid_t pid) {
+ std::lock_guard<std::mutex> lock(mLock);
+ auto it = mNotificationClients.find(pid);
+ if (it != mNotificationClients.end()) {
+ return it->second->getStreamCount();
+ } else {
+ return 0; // no existing client
+ }
+}
+
aaudio_result_t
AAudioClientTracker::registerClientStream(pid_t pid, sp<AAudioServiceStreamBase> serviceStream) {
aaudio_result_t result = AAUDIO_OK;
@@ -90,8 +100,7 @@
sp<AAudioServiceStreamBase> serviceStream) {
ALOGV("AAudioClientTracker::unregisterClientStream(%d, %p)\n", pid, serviceStream.get());
std::lock_guard<std::mutex> lock(mLock);
- std::map<pid_t, android::sp<NotificationClient>>::iterator it;
- it = mNotificationClients.find(pid);
+ auto it = mNotificationClients.find(pid);
if (it != mNotificationClients.end()) {
it->second->unregisterClientStream(serviceStream);
}
@@ -107,6 +116,11 @@
//ALOGD("AAudioClientTracker::~NotificationClient() destroyed %p\n", this);
}
+int32_t AAudioClientTracker::NotificationClient::getStreamCount() {
+ std::lock_guard<std::mutex> lock(mLock);
+ return mStreams.size();
+}
+
aaudio_result_t AAudioClientTracker::NotificationClient::registerClientStream(
sp<AAudioServiceStreamBase> serviceStream) {
std::lock_guard<std::mutex> lock(mLock);