Loading media/libaaudio/src/utility/HandleTracker.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -113,7 +113,8 @@ std::string HandleTracker::dump() const { result << "HandleTracker may be deadlocked\n"; } result << "Handles:\n"; result << "HandleTracker:\n"; result << " HandleHeaders:\n"; // atLineStart() can be changed to support an arbitrary line breaking algorithm; // it should return true when a new line starts. // For simplicity, we will use a constant 16 items per line. Loading services/oboeservice/AAudioClientTracker.cpp +57 −4 Original line number Diff line number Diff line Loading @@ -39,6 +39,28 @@ AAudioClientTracker::AAudioClientTracker() : Singleton<AAudioClientTracker>() { } std::string AAudioClientTracker::dump() const { std::stringstream result; const bool isLocked = AAudio_tryUntilTrue( [this]()->bool { return mLock.try_lock(); } /* f */, 50 /* times */, 20 /* sleepMs */); if (!isLocked) { result << "AAudioClientTracker may be deadlocked\n"; } result << "AAudioClientTracker:\n"; for (const auto& it : mNotificationClients) { result << it.second->dump(); } if (isLocked) { mLock.unlock(); } return result.str(); } // Create a tracker for the client. aaudio_result_t AAudioClientTracker::registerClient(pid_t pid, const sp<IAAudioClient>& client) { Loading Loading @@ -81,12 +103,12 @@ int32_t AAudioClientTracker::getStreamCount(pid_t pid) { aaudio_result_t AAudioClientTracker::registerClientStream(pid_t pid, sp<AAudioServiceStreamBase> serviceStream) { aaudio_result_t result = AAUDIO_OK; ALOGV("AAudioClientTracker::registerClientStream(%d, %p)\n", pid, serviceStream.get()); ALOGD("AAudioClientTracker::registerClientStream(%d, %p)\n", pid, serviceStream.get()); std::lock_guard<std::mutex> lock(mLock); sp<NotificationClient> notificationClient = mNotificationClients[pid]; if (notificationClient == 0) { // This will get called the first time the audio server registers an internal stream. ALOGV("AAudioClientTracker::registerClientStream(%d,) unrecognized pid\n", pid); ALOGD("AAudioClientTracker::registerClientStream(%d,) unrecognized pid\n", pid); notificationClient = new NotificationClient(pid); mNotificationClients[pid] = notificationClient; } Loading @@ -98,11 +120,16 @@ AAudioClientTracker::registerClientStream(pid_t pid, sp<AAudioServiceStreamBase> aaudio_result_t AAudioClientTracker::unregisterClientStream(pid_t pid, sp<AAudioServiceStreamBase> serviceStream) { ALOGV("AAudioClientTracker::unregisterClientStream(%d, %p)\n", pid, serviceStream.get()); ALOGD("AAudioClientTracker::unregisterClientStream(%d, %p)\n", pid, serviceStream.get()); std::lock_guard<std::mutex> lock(mLock); auto it = mNotificationClients.find(pid); if (it != mNotificationClients.end()) { ALOGD("AAudioClientTracker::unregisterClientStream(%d, %p) found NotificationClient\n", pid, serviceStream.get()); it->second->unregisterClientStream(serviceStream); } else { ALOGE("AAudioClientTracker::unregisterClientStream(%d, %p) missing NotificationClient\n", pid, serviceStream.get()); } return AAUDIO_OK; } Loading Loading @@ -131,7 +158,11 @@ aaudio_result_t AAudioClientTracker::NotificationClient::registerClientStream( aaudio_result_t AAudioClientTracker::NotificationClient::unregisterClientStream( sp<AAudioServiceStreamBase> serviceStream) { std::lock_guard<std::mutex> lock(mLock); ALOGD("AAudioClientTracker::NotificationClient() before erase() count = %d\n", (int)mStreams.size()); mStreams.erase(serviceStream); ALOGD("AAudioClientTracker::NotificationClient() after erase() count = %d\n", (int)mStreams.size()); return AAUDIO_OK; } Loading @@ -141,7 +172,7 @@ void AAudioClientTracker::NotificationClient::binderDied(const wp<IBinder>& who if (aaudioService != nullptr) { // Copy the current list of streams to another vector because closing them below // will cause unregisterClientStream() calls back to this object. std::set<android::sp<AAudioServiceStreamBase>> streamsToClose; std::set<sp<AAudioServiceStreamBase>> streamsToClose; { std::lock_guard<std::mutex> lock(mLock); Loading @@ -162,3 +193,25 @@ void AAudioClientTracker::NotificationClient::binderDied(const wp<IBinder>& who sp<NotificationClient> keep(this); AAudioClientTracker::getInstance().unregisterClient(mProcessId); } std::string AAudioClientTracker::NotificationClient::dump() const { std::stringstream result; const bool isLocked = AAudio_tryUntilTrue( [this]()->bool { return mLock.try_lock(); } /* f */, 50 /* times */, 20 /* sleepMs */); if (!isLocked) { result << "AAudioClientTracker::NotificationClient may be deadlocked\n"; } result << " client: pid = " << mProcessId << " has " << mStreams.size() << " streams\n"; for (auto serviceStream : mStreams) { result << " stream: 0x" << std::hex << serviceStream->getHandle() << std::dec << "\n"; } if (isLocked) { mLock.unlock(); } return result.str(); } services/oboeservice/AAudioClientTracker.h +16 −2 Original line number Diff line number Diff line Loading @@ -34,6 +34,18 @@ public: AAudioClientTracker(); ~AAudioClientTracker() = default; /** * Returns information about the state of the this class. * * Will attempt to get the object lock, but will proceed * even if it cannot. * * Each line of information ends with a newline. * * @return a string with useful information */ std::string dump() const; aaudio_result_t registerClient(pid_t pid, const android::sp<android::IAAudioClient>& client); void unregisterClient(pid_t pid); Loading Loading @@ -66,6 +78,8 @@ private: int32_t getStreamCount(); std::string dump() const; aaudio_result_t registerClientStream(android::sp<AAudioServiceStreamBase> serviceStream); aaudio_result_t unregisterClientStream(android::sp<AAudioServiceStreamBase> serviceStream); Loading @@ -74,12 +88,12 @@ private: virtual void binderDied(const android::wp<IBinder>& who); protected: std::mutex mLock; mutable std::mutex mLock; const pid_t mProcessId; std::set<android::sp<AAudioServiceStreamBase>> mStreams; }; std::mutex mLock; mutable std::mutex mLock; std::map<pid_t, android::sp<NotificationClient>> mNotificationClients; android::AAudioService *mAAudioService = nullptr; }; Loading services/oboeservice/AAudioEndpointManager.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -48,16 +48,17 @@ std::string AAudioEndpointManager::dump() const { result << "EndpointManager may be deadlocked\n"; } result << "AAudioEndpointManager:" << "\n"; size_t inputs = mInputs.size(); result << "Inputs: " << inputs << "\n"; result << "Input Endpoints: " << inputs << "\n"; for (const auto &input : mInputs) { result << " Input(" << input << ")\n"; result << " Input: " << input->dump() << "\n"; } size_t outputs = mOutputs.size(); result << "Outputs: " << outputs << "\n"; result << "Output Endpoints: " << outputs << "\n"; for (const auto &output : mOutputs) { result << " Output(" << output << ")\n"; result << " Output: " << output->dump() << "\n"; } if (isLocked) { Loading services/oboeservice/AAudioEndpointManager.h +2 −2 Original line number Diff line number Diff line Loading @@ -34,14 +34,14 @@ public: ~AAudioEndpointManager() = default; /** * Returns EndpointManager information. * Returns information about the state of the this class. * * Will attempt to get the object lock, but will proceed * even if it cannot. * * Each line of information ends with a newline. * * @return a string representing the EndpointManager info * @return a string with useful information */ std::string dump() const; Loading Loading
media/libaaudio/src/utility/HandleTracker.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -113,7 +113,8 @@ std::string HandleTracker::dump() const { result << "HandleTracker may be deadlocked\n"; } result << "Handles:\n"; result << "HandleTracker:\n"; result << " HandleHeaders:\n"; // atLineStart() can be changed to support an arbitrary line breaking algorithm; // it should return true when a new line starts. // For simplicity, we will use a constant 16 items per line. Loading
services/oboeservice/AAudioClientTracker.cpp +57 −4 Original line number Diff line number Diff line Loading @@ -39,6 +39,28 @@ AAudioClientTracker::AAudioClientTracker() : Singleton<AAudioClientTracker>() { } std::string AAudioClientTracker::dump() const { std::stringstream result; const bool isLocked = AAudio_tryUntilTrue( [this]()->bool { return mLock.try_lock(); } /* f */, 50 /* times */, 20 /* sleepMs */); if (!isLocked) { result << "AAudioClientTracker may be deadlocked\n"; } result << "AAudioClientTracker:\n"; for (const auto& it : mNotificationClients) { result << it.second->dump(); } if (isLocked) { mLock.unlock(); } return result.str(); } // Create a tracker for the client. aaudio_result_t AAudioClientTracker::registerClient(pid_t pid, const sp<IAAudioClient>& client) { Loading Loading @@ -81,12 +103,12 @@ int32_t AAudioClientTracker::getStreamCount(pid_t pid) { aaudio_result_t AAudioClientTracker::registerClientStream(pid_t pid, sp<AAudioServiceStreamBase> serviceStream) { aaudio_result_t result = AAUDIO_OK; ALOGV("AAudioClientTracker::registerClientStream(%d, %p)\n", pid, serviceStream.get()); ALOGD("AAudioClientTracker::registerClientStream(%d, %p)\n", pid, serviceStream.get()); std::lock_guard<std::mutex> lock(mLock); sp<NotificationClient> notificationClient = mNotificationClients[pid]; if (notificationClient == 0) { // This will get called the first time the audio server registers an internal stream. ALOGV("AAudioClientTracker::registerClientStream(%d,) unrecognized pid\n", pid); ALOGD("AAudioClientTracker::registerClientStream(%d,) unrecognized pid\n", pid); notificationClient = new NotificationClient(pid); mNotificationClients[pid] = notificationClient; } Loading @@ -98,11 +120,16 @@ AAudioClientTracker::registerClientStream(pid_t pid, sp<AAudioServiceStreamBase> aaudio_result_t AAudioClientTracker::unregisterClientStream(pid_t pid, sp<AAudioServiceStreamBase> serviceStream) { ALOGV("AAudioClientTracker::unregisterClientStream(%d, %p)\n", pid, serviceStream.get()); ALOGD("AAudioClientTracker::unregisterClientStream(%d, %p)\n", pid, serviceStream.get()); std::lock_guard<std::mutex> lock(mLock); auto it = mNotificationClients.find(pid); if (it != mNotificationClients.end()) { ALOGD("AAudioClientTracker::unregisterClientStream(%d, %p) found NotificationClient\n", pid, serviceStream.get()); it->second->unregisterClientStream(serviceStream); } else { ALOGE("AAudioClientTracker::unregisterClientStream(%d, %p) missing NotificationClient\n", pid, serviceStream.get()); } return AAUDIO_OK; } Loading Loading @@ -131,7 +158,11 @@ aaudio_result_t AAudioClientTracker::NotificationClient::registerClientStream( aaudio_result_t AAudioClientTracker::NotificationClient::unregisterClientStream( sp<AAudioServiceStreamBase> serviceStream) { std::lock_guard<std::mutex> lock(mLock); ALOGD("AAudioClientTracker::NotificationClient() before erase() count = %d\n", (int)mStreams.size()); mStreams.erase(serviceStream); ALOGD("AAudioClientTracker::NotificationClient() after erase() count = %d\n", (int)mStreams.size()); return AAUDIO_OK; } Loading @@ -141,7 +172,7 @@ void AAudioClientTracker::NotificationClient::binderDied(const wp<IBinder>& who if (aaudioService != nullptr) { // Copy the current list of streams to another vector because closing them below // will cause unregisterClientStream() calls back to this object. std::set<android::sp<AAudioServiceStreamBase>> streamsToClose; std::set<sp<AAudioServiceStreamBase>> streamsToClose; { std::lock_guard<std::mutex> lock(mLock); Loading @@ -162,3 +193,25 @@ void AAudioClientTracker::NotificationClient::binderDied(const wp<IBinder>& who sp<NotificationClient> keep(this); AAudioClientTracker::getInstance().unregisterClient(mProcessId); } std::string AAudioClientTracker::NotificationClient::dump() const { std::stringstream result; const bool isLocked = AAudio_tryUntilTrue( [this]()->bool { return mLock.try_lock(); } /* f */, 50 /* times */, 20 /* sleepMs */); if (!isLocked) { result << "AAudioClientTracker::NotificationClient may be deadlocked\n"; } result << " client: pid = " << mProcessId << " has " << mStreams.size() << " streams\n"; for (auto serviceStream : mStreams) { result << " stream: 0x" << std::hex << serviceStream->getHandle() << std::dec << "\n"; } if (isLocked) { mLock.unlock(); } return result.str(); }
services/oboeservice/AAudioClientTracker.h +16 −2 Original line number Diff line number Diff line Loading @@ -34,6 +34,18 @@ public: AAudioClientTracker(); ~AAudioClientTracker() = default; /** * Returns information about the state of the this class. * * Will attempt to get the object lock, but will proceed * even if it cannot. * * Each line of information ends with a newline. * * @return a string with useful information */ std::string dump() const; aaudio_result_t registerClient(pid_t pid, const android::sp<android::IAAudioClient>& client); void unregisterClient(pid_t pid); Loading Loading @@ -66,6 +78,8 @@ private: int32_t getStreamCount(); std::string dump() const; aaudio_result_t registerClientStream(android::sp<AAudioServiceStreamBase> serviceStream); aaudio_result_t unregisterClientStream(android::sp<AAudioServiceStreamBase> serviceStream); Loading @@ -74,12 +88,12 @@ private: virtual void binderDied(const android::wp<IBinder>& who); protected: std::mutex mLock; mutable std::mutex mLock; const pid_t mProcessId; std::set<android::sp<AAudioServiceStreamBase>> mStreams; }; std::mutex mLock; mutable std::mutex mLock; std::map<pid_t, android::sp<NotificationClient>> mNotificationClients; android::AAudioService *mAAudioService = nullptr; }; Loading
services/oboeservice/AAudioEndpointManager.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -48,16 +48,17 @@ std::string AAudioEndpointManager::dump() const { result << "EndpointManager may be deadlocked\n"; } result << "AAudioEndpointManager:" << "\n"; size_t inputs = mInputs.size(); result << "Inputs: " << inputs << "\n"; result << "Input Endpoints: " << inputs << "\n"; for (const auto &input : mInputs) { result << " Input(" << input << ")\n"; result << " Input: " << input->dump() << "\n"; } size_t outputs = mOutputs.size(); result << "Outputs: " << outputs << "\n"; result << "Output Endpoints: " << outputs << "\n"; for (const auto &output : mOutputs) { result << " Output(" << output << ")\n"; result << " Output: " << output->dump() << "\n"; } if (isLocked) { Loading
services/oboeservice/AAudioEndpointManager.h +2 −2 Original line number Diff line number Diff line Loading @@ -34,14 +34,14 @@ public: ~AAudioEndpointManager() = default; /** * Returns EndpointManager information. * Returns information about the state of the this class. * * Will attempt to get the object lock, but will proceed * even if it cannot. * * Each line of information ends with a newline. * * @return a string representing the EndpointManager info * @return a string with useful information */ std::string dump() const; Loading