From d2d089fc86c62843992e7d5b371ee9227189a1e6 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Wed, 5 Nov 2014 11:48:12 -0800 Subject: Improve AudioTrack recovery from mediaserver death 1. Fix race condition in handling of binder death notifications. AudioSystem has a mixture of APIs for both ordinary app clients, and the AudioFlinger and AudioPolicy services within mediaserver. Due to this mix of uses, it is possible for there to be "surprising" sequences of calls on the call stack. Previously, we used a single mutex for all global variables, but this caused a deadlock. To avoid the deadlock, we unlocked the mutex during the critical sequence of calls. But this was a a crucial place where it should have stayed locked; see Change-Id I315c1c5066f62b05e1c13b04fae1272b5fbce977 Now we use separate mutexes for the AudioFlinger, AudioPolicy, and audio port related global variables. This allows us to correctly hold each mutex throughout the atomic region, even when AudioFlinger calls AudioPolicy via AudioSystem, or vice-versa. 2. AudioSystem::clearAudioConfigCache now clears the IAudioFlinger reference. 3. Make AudioSystem::get_audio_policy_service more like get_audio_flinger. Bug: 18242291 Change-Id: I9761443d8337df5bf66d4ca2316a9fd0bd11be94 --- include/media/AudioSystem.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include/media/AudioSystem.h') diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h index f8c0198..341f9ab 100644 --- a/include/media/AudioSystem.h +++ b/include/media/AudioSystem.h @@ -377,7 +377,10 @@ private: friend class AudioFlingerClient; friend class AudioPolicyServiceClient; - static Mutex gLock; + static Mutex gLock; // protects all members except gAudioPolicyService, + // gAudioPolicyServiceClient, and gAudioPortCallback + static Mutex gLockAPS; // protects gAudioPolicyService and gAudioPolicyServiceClient + static Mutex gLockAPC; // protects gAudioPortCallback static sp gAudioFlinger; static audio_error_callback gAudioErrorCallback; -- cgit v1.1