AudioSystem: more locking work on audio device callback
commit 24a9fb0d left some locking issues with management of device
callbacks in AudioSystem, AudioTrack and AudioRecord.
This change makes that the AudioSystem mutex is not held when
callbacks are called into AudioTrack and AudioRecord removing cross
deadlock risks and allowing AudioRecord and AudioTrack to hold their
mutexes while installing and handling the callbacks
Test: CTS RoutingTest, AudioTrackTest, AudioRecordTest
Change-Id: I5d17e77ca26220092deb0bd6e5a33dc32348d460
diff --git a/media/libaudioclient/AudioRecord.cpp b/media/libaudioclient/AudioRecord.cpp
index 8afb1cc..baa1469 100644
--- a/media/libaudioclient/AudioRecord.cpp
+++ b/media/libaudioclient/AudioRecord.cpp
@@ -1361,14 +1361,12 @@
ALOGW("%s(%d): removing NULL callback!", __func__, mPortId);
return BAD_VALUE;
}
- {
- AutoMutex lock(mLock);
- if (mDeviceCallback.unsafe_get() != callback.get()) {
- ALOGW("%s(%d): removing different callback!", __func__, mPortId);
- return INVALID_OPERATION;
- }
- mDeviceCallback.clear();
+ AutoMutex lock(mLock);
+ if (mDeviceCallback.unsafe_get() != callback.get()) {
+ ALOGW("%s(%d): removing different callback!", __func__, mPortId);
+ return INVALID_OPERATION;
}
+ mDeviceCallback.clear();
if (mInput != AUDIO_IO_HANDLE_NONE) {
AudioSystem::removeAudioDeviceCallback(this, mInput);
}