From 7c1ec5f038e63a5eb8b04434577c25bc23f5f410 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 9 Jul 2015 14:52:47 -0700 Subject: audio: several fixes in audio routing callbacks - audio policy: Force device change to ensure new audio patch creation upon first track activity on a given output. Fix function device_distinguishes_on_address() which could mistake some output device with remote submix input device. - audio flinger: Reduce number of binder calls upon new client registration by only sending ioConfigChanged() callbacks to newly registered client. Fix first patch after output thread creation not triggering an ioConfigChanged() callback. -audio system: Force client registration upon routing callback installation to force new ioConfigChanged() callback from audio flinger. Bug: 22381136. Change-Id: Ieb0d9f92f563a40552eb31bc0499c8ac65f78ce4 --- services/audioflinger/AudioFlinger.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'services/audioflinger/AudioFlinger.cpp') diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 52fce34..8f1e050 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1252,11 +1252,9 @@ void AudioFlinger::registerClient(const sp& client) if (client == 0) { return; } - bool clientAdded = false; + pid_t pid = IPCThreadState::self()->getCallingPid(); { Mutex::Autolock _cl(mClientLock); - - pid_t pid = IPCThreadState::self()->getCallingPid(); if (mNotificationClients.indexOfKey(pid) < 0) { sp notificationClient = new NotificationClient(this, client, @@ -1267,22 +1265,19 @@ void AudioFlinger::registerClient(const sp& client) sp binder = IInterface::asBinder(client); binder->linkToDeath(notificationClient); - clientAdded = true; } } // mClientLock should not be held here because ThreadBase::sendIoConfigEvent() will lock the // ThreadBase mutex and the locking order is ThreadBase::mLock then AudioFlinger::mClientLock. - if (clientAdded) { - // the config change is always sent from playback or record threads to avoid deadlock - // with AudioSystem::gLock - for (size_t i = 0; i < mPlaybackThreads.size(); i++) { - mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AUDIO_OUTPUT_OPENED); - } + // the config change is always sent from playback or record threads to avoid deadlock + // with AudioSystem::gLock + for (size_t i = 0; i < mPlaybackThreads.size(); i++) { + mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AUDIO_OUTPUT_OPENED, pid); + } - for (size_t i = 0; i < mRecordThreads.size(); i++) { - mRecordThreads.valueAt(i)->sendIoConfigEvent(AUDIO_INPUT_OPENED); - } + for (size_t i = 0; i < mRecordThreads.size(); i++) { + mRecordThreads.valueAt(i)->sendIoConfigEvent(AUDIO_INPUT_OPENED, pid); } } @@ -1316,12 +1311,15 @@ void AudioFlinger::removeNotificationClient(pid_t pid) } void AudioFlinger::ioConfigChanged(audio_io_config_event event, - const sp& ioDesc) + const sp& ioDesc, + pid_t pid) { Mutex::Autolock _l(mClientLock); size_t size = mNotificationClients.size(); for (size_t i = 0; i < size; i++) { - mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, ioDesc); + if ((pid == 0) || (mNotificationClients.keyAt(i) == pid)) { + mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, ioDesc); + } } } -- cgit v1.1