Loading media/libaaudio/tests/Android.mk +10 −0 Original line number Diff line number Diff line Loading @@ -69,3 +69,13 @@ LOCAL_SRC_FILES:= test_recovery.cpp LOCAL_SHARED_LIBRARIES := libaaudio libbinder libcutils libutils LOCAL_MODULE := test_aaudio_recovery include $(BUILD_NATIVE_TEST) include $(CLEAR_VARS) LOCAL_C_INCLUDES := \ $(call include-path-for, audio-utils) \ frameworks/av/media/libaaudio/include \ frameworks/av/media/libaaudio/src LOCAL_SRC_FILES:= test_n_streams.cpp LOCAL_SHARED_LIBRARIES := libaaudio libbinder libcutils libutils LOCAL_MODULE := test_n_streams include $(BUILD_NATIVE_TEST) media/libaaudio/tests/test_n_streams.cpp 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Try to create as many streams as possible and report the maximum. #include <stdio.h> #include <stdlib.h> #include <aaudio/AAudio.h> #include <aaudio/AAudioTesting.h> //#define MMAP_POLICY AAUDIO_UNSPECIFIED //#define MMAP_POLICY AAUDIO_POLICY_NEVER #define MMAP_POLICY AAUDIO_POLICY_AUTO //#define MMAP_POLICY AAUDIO_POLICY_ALWAYS #define MAX_STREAMS 100 int main(int argc, char **argv) { (void)argc; // unused (void)argv; // unused aaudio_result_t result = AAUDIO_OK; AAudioStreamBuilder *aaudioBuilder = nullptr; AAudioStream *aaudioStream[MAX_STREAMS]; int32_t numStreams = 0; // Make printf print immediately so that debug info is not stuck // in a buffer if we hang or crash. setvbuf(stdout, NULL, _IONBF, (size_t) 0); printf("Try to open a maximum of %d streams.\n", MAX_STREAMS); AAudio_setMMapPolicy(MMAP_POLICY); printf("requested MMapPolicy = %d\n", AAudio_getMMapPolicy()); result = AAudio_createStreamBuilder(&aaudioBuilder); if (result != AAUDIO_OK) { return 1; } for (int i = 0; i < MAX_STREAMS; i++) { // Create an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream[i]); if (result != AAUDIO_OK) { printf("ERROR could not open AAudio stream, %d %s\n", result, AAudio_convertResultToText(result)); break; } else { printf("AAudio stream[%2d] opened successfully. MMAP = %s\n", i, AAudioStream_isMMapUsed(aaudioStream[i]) ? "YES" : "NO"); numStreams++; } } printf("Created %d streams!\n", numStreams); // Close all the streams. for (int i = 0; i < numStreams; i++) { result = AAudioStream_close(aaudioStream[i]); if (result != AAUDIO_OK) { printf("ERROR could not close AAudio stream, %d %s\n", result, AAudio_convertResultToText(result)); break; } else { printf("AAudio stream[%2d] closed successfully.\n", i); } } AAudioStreamBuilder_delete(aaudioBuilder); finish: return (result != AAUDIO_OK) ? EXIT_FAILURE : EXIT_SUCCESS; } services/oboeservice/AAudioClientTracker.cpp +16 −2 Original line number Diff line number Diff line Loading @@ -68,6 +68,16 @@ void AAudioClientTracker::unregisterClient(pid_t pid) { 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; Loading @@ -90,8 +100,7 @@ AAudioClientTracker::unregisterClientStream(pid_t pid, 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); } Loading @@ -107,6 +116,11 @@ AAudioClientTracker::NotificationClient::~NotificationClient() { //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); Loading services/oboeservice/AAudioClientTracker.h +8 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ public: void unregisterClient(pid_t pid); int32_t getStreamCount(pid_t pid); aaudio_result_t registerClientStream(pid_t pid, android::sp<AAudioServiceStreamBase> serviceStream); Loading @@ -53,11 +55,17 @@ public: } private: /** * One per process. */ class NotificationClient : public IBinder::DeathRecipient { public: NotificationClient(pid_t pid); virtual ~NotificationClient(); int32_t getStreamCount(); aaudio_result_t registerClientStream(android::sp<AAudioServiceStreamBase> serviceStream); aaudio_result_t unregisterClientStream(android::sp<AAudioServiceStreamBase> serviceStream); Loading services/oboeservice/AAudioEndpointManager.cpp +17 −17 Original line number Diff line number Diff line Loading @@ -115,7 +115,6 @@ AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioS default: break; } } if (endpoint != nullptr) { aaudio_result_t result = endpoint->open(configuration); Loading @@ -135,6 +134,7 @@ AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioS break; } } } ALOGD("AAudioEndpointManager::openEndpoint(), created %p for device = %d, dir = %d", endpoint, configuration.getDeviceId(), (int)direction); } Loading Loading
media/libaaudio/tests/Android.mk +10 −0 Original line number Diff line number Diff line Loading @@ -69,3 +69,13 @@ LOCAL_SRC_FILES:= test_recovery.cpp LOCAL_SHARED_LIBRARIES := libaaudio libbinder libcutils libutils LOCAL_MODULE := test_aaudio_recovery include $(BUILD_NATIVE_TEST) include $(CLEAR_VARS) LOCAL_C_INCLUDES := \ $(call include-path-for, audio-utils) \ frameworks/av/media/libaaudio/include \ frameworks/av/media/libaaudio/src LOCAL_SRC_FILES:= test_n_streams.cpp LOCAL_SHARED_LIBRARIES := libaaudio libbinder libcutils libutils LOCAL_MODULE := test_n_streams include $(BUILD_NATIVE_TEST)
media/libaaudio/tests/test_n_streams.cpp 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Try to create as many streams as possible and report the maximum. #include <stdio.h> #include <stdlib.h> #include <aaudio/AAudio.h> #include <aaudio/AAudioTesting.h> //#define MMAP_POLICY AAUDIO_UNSPECIFIED //#define MMAP_POLICY AAUDIO_POLICY_NEVER #define MMAP_POLICY AAUDIO_POLICY_AUTO //#define MMAP_POLICY AAUDIO_POLICY_ALWAYS #define MAX_STREAMS 100 int main(int argc, char **argv) { (void)argc; // unused (void)argv; // unused aaudio_result_t result = AAUDIO_OK; AAudioStreamBuilder *aaudioBuilder = nullptr; AAudioStream *aaudioStream[MAX_STREAMS]; int32_t numStreams = 0; // Make printf print immediately so that debug info is not stuck // in a buffer if we hang or crash. setvbuf(stdout, NULL, _IONBF, (size_t) 0); printf("Try to open a maximum of %d streams.\n", MAX_STREAMS); AAudio_setMMapPolicy(MMAP_POLICY); printf("requested MMapPolicy = %d\n", AAudio_getMMapPolicy()); result = AAudio_createStreamBuilder(&aaudioBuilder); if (result != AAUDIO_OK) { return 1; } for (int i = 0; i < MAX_STREAMS; i++) { // Create an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream[i]); if (result != AAUDIO_OK) { printf("ERROR could not open AAudio stream, %d %s\n", result, AAudio_convertResultToText(result)); break; } else { printf("AAudio stream[%2d] opened successfully. MMAP = %s\n", i, AAudioStream_isMMapUsed(aaudioStream[i]) ? "YES" : "NO"); numStreams++; } } printf("Created %d streams!\n", numStreams); // Close all the streams. for (int i = 0; i < numStreams; i++) { result = AAudioStream_close(aaudioStream[i]); if (result != AAUDIO_OK) { printf("ERROR could not close AAudio stream, %d %s\n", result, AAudio_convertResultToText(result)); break; } else { printf("AAudio stream[%2d] closed successfully.\n", i); } } AAudioStreamBuilder_delete(aaudioBuilder); finish: return (result != AAUDIO_OK) ? EXIT_FAILURE : EXIT_SUCCESS; }
services/oboeservice/AAudioClientTracker.cpp +16 −2 Original line number Diff line number Diff line Loading @@ -68,6 +68,16 @@ void AAudioClientTracker::unregisterClient(pid_t pid) { 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; Loading @@ -90,8 +100,7 @@ AAudioClientTracker::unregisterClientStream(pid_t pid, 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); } Loading @@ -107,6 +116,11 @@ AAudioClientTracker::NotificationClient::~NotificationClient() { //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); Loading
services/oboeservice/AAudioClientTracker.h +8 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ public: void unregisterClient(pid_t pid); int32_t getStreamCount(pid_t pid); aaudio_result_t registerClientStream(pid_t pid, android::sp<AAudioServiceStreamBase> serviceStream); Loading @@ -53,11 +55,17 @@ public: } private: /** * One per process. */ class NotificationClient : public IBinder::DeathRecipient { public: NotificationClient(pid_t pid); virtual ~NotificationClient(); int32_t getStreamCount(); aaudio_result_t registerClientStream(android::sp<AAudioServiceStreamBase> serviceStream); aaudio_result_t unregisterClientStream(android::sp<AAudioServiceStreamBase> serviceStream); Loading
services/oboeservice/AAudioEndpointManager.cpp +17 −17 Original line number Diff line number Diff line Loading @@ -115,7 +115,6 @@ AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioS default: break; } } if (endpoint != nullptr) { aaudio_result_t result = endpoint->open(configuration); Loading @@ -135,6 +134,7 @@ AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioS break; } } } ALOGD("AAudioEndpointManager::openEndpoint(), created %p for device = %d, dir = %d", endpoint, configuration.getDeviceId(), (int)direction); } Loading