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 --- include/media/AudioSystem.h | 55 +++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) (limited to 'include/media/AudioSystem.h') diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h index a454481..8d3396d 100644 --- a/include/media/AudioSystem.h +++ b/include/media/AudioSystem.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -155,33 +156,6 @@ public: // or no HW sync source is used. static audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId); - // types of io configuration change events received with ioConfigChanged() - enum io_config_event { - OUTPUT_OPENED, - OUTPUT_CLOSED, - OUTPUT_CONFIG_CHANGED, - INPUT_OPENED, - INPUT_CLOSED, - INPUT_CONFIG_CHANGED, - STREAM_CONFIG_CHANGED, - NUM_CONFIG_EVENTS - }; - - // audio output descriptor used to cache output configurations in client process to avoid - // frequent calls through IAudioFlinger - class OutputDescriptor { - public: - OutputDescriptor() - : samplingRate(0), format(AUDIO_FORMAT_DEFAULT), channelMask(0), frameCount(0), latency(0) - {} - - uint32_t samplingRate; - audio_format_t format; - audio_channel_mask_t channelMask; - size_t frameCount; - uint32_t latency; - }; - // Events used to synchronize actions between audio sessions. // For instance SYNC_EVENT_PRESENTATION_COMPLETE can be used to delay recording start until // playback is complete on another audio session. @@ -362,9 +336,16 @@ private: class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient { public: - AudioFlingerClient() { + AudioFlingerClient() : + mInBuffSize(0), mInSamplingRate(0), + mInFormat(AUDIO_FORMAT_DEFAULT), mInChannelMask(AUDIO_CHANNEL_NONE) { } + void clearIoCache(); + status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, + audio_channel_mask_t channelMask, size_t* buffSize); + sp getIoDescriptor(audio_io_handle_t ioHandle); + // DeathRecipient virtual void binderDied(const wp& who); @@ -372,7 +353,17 @@ private: // indicate a change in the configuration of an output or input: keeps the cached // values for output/input parameters up-to-date in client process - virtual void ioConfigChanged(int event, audio_io_handle_t ioHandle, const void *param2); + virtual void ioConfigChanged(audio_io_config_event event, + const sp& ioDesc); + private: + Mutex mLock; + DefaultKeyedVector > mIoDescriptors; + + // cached values for recording getInputBufferSize() queries + size_t mInBuffSize; // zero indicates cache is invalid + uint32_t mInSamplingRate; + audio_format_t mInFormat; + audio_channel_mask_t mInChannelMask; }; class AudioPolicyServiceClient: public IBinder::DeathRecipient, @@ -404,8 +395,6 @@ private: friend class AudioPolicyServiceClient; static Mutex gLock; // protects gAudioFlinger and gAudioErrorCallback, - static Mutex gLockCache; // protects gOutputs, gPrevInSamplingRate, gPrevInFormat, - // gPrevInChannelMask and gInBuffSize static Mutex gLockAPS; // protects gAudioPolicyService and gAudioPolicyServiceClient static sp gAudioFlinger; static audio_error_callback gAudioErrorCallback; @@ -417,10 +406,6 @@ private: static audio_channel_mask_t gPrevInChannelMask; static sp gAudioPolicyService; - - // list of output descriptors containing cached parameters - // (sampling rate, framecount, channel count...) - static DefaultKeyedVector gOutputs; }; }; // namespace android -- cgit v1.1