From 73e26b661af50be2c0a4ff6c9ac85f7347a8b235 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Mon, 27 Apr 2015 16:55:58 -0700 Subject: AudioSystem: refactor audio config cache and callbacks Clean up implementation of audio configuration cache and callback events from AudioFlinger: - Define class AudioIoDescriptor for audio input and output configurations outside of AudioSystem class. - Do not use void * but an AudioIoDescriptor as argument to audio config callbacks from AudioFlinger. - Remove unused configuration events. - Move AudioSystem audio input and output cache from static singletons to members of AudioFlingerClient subclass. Change-Id: I67c196c32c09ce2756af0755ee1fe631040c3270 --- services/audioflinger/AudioFlinger.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'services/audioflinger/AudioFlinger.cpp') diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 0530aae..3e4b1fc 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1268,11 +1268,11 @@ void AudioFlinger::registerClient(const sp& client) // 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(AudioSystem::OUTPUT_OPENED); + mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AUDIO_OUTPUT_OPENED); } for (size_t i = 0; i < mRecordThreads.size(); i++) { - mRecordThreads.valueAt(i)->sendIoConfigEvent(AudioSystem::INPUT_OPENED); + mRecordThreads.valueAt(i)->sendIoConfigEvent(AUDIO_INPUT_OPENED); } } } @@ -1306,14 +1306,13 @@ void AudioFlinger::removeNotificationClient(pid_t pid) } } -void AudioFlinger::audioConfigChanged(int event, audio_io_handle_t ioHandle, const void *param2) +void AudioFlinger::ioConfigChanged(audio_io_config_event event, + const sp& ioDesc) { Mutex::Autolock _l(mClientLock); size_t size = mNotificationClients.size(); for (size_t i = 0; i < size; i++) { - mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, - ioHandle, - param2); + mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, ioDesc); } } @@ -1831,7 +1830,7 @@ status_t AudioFlinger::openOutput(audio_module_handle_t module, *latencyMs = thread->latency(); // notify client processes of the new output creation - thread->audioConfigChanged(AudioSystem::OUTPUT_OPENED); + thread->ioConfigChanged(AUDIO_OUTPUT_OPENED); // the first primary output opened designates the primary hw device if ((mPrimaryHardwareDev == NULL) && (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) { @@ -1869,7 +1868,7 @@ audio_io_handle_t AudioFlinger::openDuplicateOutput(audio_io_handle_t output1, thread->addOutputTrack(thread2); mPlaybackThreads.add(id, thread); // notify client processes of the new output creation - thread->audioConfigChanged(AudioSystem::OUTPUT_OPENED); + thread->ioConfigChanged(AUDIO_OUTPUT_OPENED); return id; } @@ -1919,7 +1918,9 @@ status_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output) } } } - audioConfigChanged(AudioSystem::OUTPUT_CLOSED, output, NULL); + const sp ioDesc = new AudioIoDescriptor(); + ioDesc->mIoHandle = output; + ioConfigChanged(AUDIO_OUTPUT_CLOSED, ioDesc); } thread->exit(); // The thread entity (active unit of execution) is no longer running here, @@ -1997,7 +1998,7 @@ status_t AudioFlinger::openInput(audio_module_handle_t module, if (thread != 0) { // notify client processes of the new input creation - thread->audioConfigChanged(AudioSystem::INPUT_OPENED); + thread->ioConfigChanged(AUDIO_INPUT_OPENED); return NO_ERROR; } return NO_INIT; @@ -2180,7 +2181,9 @@ status_t AudioFlinger::closeInput_nonvirtual(audio_io_handle_t input) putOrphanEffectChain_l(chain); } } - audioConfigChanged(AudioSystem::INPUT_CLOSED, input, NULL); + const sp ioDesc = new AudioIoDescriptor(); + ioDesc->mIoHandle = input; + ioConfigChanged(AUDIO_INPUT_CLOSED, ioDesc); mRecordThreads.removeItem(input); } // FIXME: calling thread->exit() without mLock held should not be needed anymore now that -- cgit v1.1