From 296fb13dd9b5e90d6a05cce897c3b1e7914a478a Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Fri, 1 May 2015 11:38:42 -0700 Subject: Implement audio device callback Add class AudioSystem::AudioDeviceCallback notifying AudioSystem clients upon device selection change on a given input or output thread. Maintain a list of installed callback per I/O handle in AudioSystem and call registered callbacks when an OPEN of CONFIG_CHANGED event is received on IAudioFlingerClient::ioConfigChanged(). Add methods to AudioTrack and AudioRecord to add and remove device change callbacks. Add methods to AudioTrack and AudioRecord to query currently selected device. ioConfigChanged() events now convey the audio patch describing the input or output thread routing. Fix AudioRecord failure to start when invalidation is handled by start(). Change-Id: I9e938adf025fa712337c63b1e02a8c18f2a20d39 --- services/audioflinger/Threads.cpp | 8 ++++++++ services/audioflinger/Threads.h | 1 + 2 files changed, 9 insertions(+) (limited to 'services/audioflinger') diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp index 8b8dd78..2c4d801 100644 --- a/services/audioflinger/Threads.cpp +++ b/services/audioflinger/Threads.cpp @@ -500,6 +500,7 @@ AudioFlinger::ThreadBase::ThreadBase(const sp& audioFlinger, audio // mName will be set by concrete (non-virtual) subclass mDeathRecipient(new PMDeathRecipient(this)) { + memset(&mPatch, 0, sizeof(struct audio_patch)); } AudioFlinger::ThreadBase::~ThreadBase() @@ -1930,6 +1931,7 @@ void AudioFlinger::PlaybackThread::ioConfigChanged(audio_io_config_event event) switch (event) { case AUDIO_OUTPUT_OPENED: case AUDIO_OUTPUT_CONFIG_CHANGED: + desc->mPatch = mPatch; desc->mChannelMask = mChannelMask; desc->mSamplingRate = mSampleRate; desc->mFormat = mFormat; @@ -3002,6 +3004,7 @@ status_t AudioFlinger::PlaybackThread::createAudioPatch_l(const struct audio_pat mEffectChains[i]->setDevice_l(type); } mOutDevice = type; + mPatch = *patch; if (mOutput->audioHwDev->version() >= AUDIO_DEVICE_API_VERSION_3_0) { audio_hw_device_t *hwDevice = mOutput->audioHwDev->hwDevice(); @@ -3028,6 +3031,7 @@ status_t AudioFlinger::PlaybackThread::createAudioPatch_l(const struct audio_pat param.toString().string()); *handle = AUDIO_PATCH_HANDLE_NONE; } + sendIoConfigEvent_l(AUDIO_OUTPUT_CONFIG_CHANGED); return status; } @@ -6727,6 +6731,7 @@ void AudioFlinger::RecordThread::ioConfigChanged(audio_io_config_event event) { switch (event) { case AUDIO_INPUT_OPENED: case AUDIO_INPUT_CONFIG_CHANGED: + desc->mPatch = mPatch; desc->mChannelMask = mChannelMask; desc->mSamplingRate = mSampleRate; desc->mFormat = mFormat; @@ -6884,6 +6889,7 @@ status_t AudioFlinger::RecordThread::createAudioPatch_l(const struct audio_patch // store new device and send to effects mInDevice = patch->sources[0].ext.device.type; + mPatch = *patch; for (size_t i = 0; i < mEffectChains.size(); i++) { mEffectChains[i]->setDevice_l(mInDevice); } @@ -6936,6 +6942,8 @@ status_t AudioFlinger::RecordThread::createAudioPatch_l(const struct audio_patch *handle = AUDIO_PATCH_HANDLE_NONE; } + sendIoConfigEvent_l(AUDIO_INPUT_CONFIG_CHANGED); + return status; } diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h index 8167bd1..0a5597f 100644 --- a/services/audioflinger/Threads.h +++ b/services/audioflinger/Threads.h @@ -426,6 +426,7 @@ protected: bool mStandby; // Whether thread is currently in standby. audio_devices_t mOutDevice; // output device audio_devices_t mInDevice; // input device + struct audio_patch mPatch; audio_source_t mAudioSource; const audio_io_handle_t mId; -- cgit v1.1