From 0ede8924b98c2967be2795e8d4f9837d8d3f094c Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Fri, 9 May 2014 18:04:42 -0700 Subject: audiopolicy: refactor audio command threads - Use strong pointers for command data to avoid transfering ownership of the object to receiver thread. This avoids waiting for the command acknowlegement to proceed with next command on server side. - Use a separate mutex for each command condition. - Factor in duplicated code to send commands. Change-Id: Ib0526e7c4fa64a71ad4015f477c6361727c6f40a --- services/audiopolicy/AudioPolicyService.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'services/audiopolicy/AudioPolicyService.h') diff --git a/services/audiopolicy/AudioPolicyService.h b/services/audiopolicy/AudioPolicyService.h index 28e3a4b..26037e4 100644 --- a/services/audiopolicy/AudioPolicyService.h +++ b/services/audiopolicy/AudioPolicyService.h @@ -194,30 +194,31 @@ private: audio_stream_type_t stream, int session); void releaseOutputCommand(audio_io_handle_t output); - - void insertCommand_l(AudioCommand *command, int delayMs = 0); + status_t sendCommand(sp& command, int delayMs = 0); + void insertCommand_l(sp& command, int delayMs = 0); private: class AudioCommandData; // descriptor for requested tone playback event - class AudioCommand { + class AudioCommand: public RefBase { public: AudioCommand() - : mCommand(-1) {} + : mCommand(-1), mStatus(NO_ERROR), mWaitStatus(false) {} void dump(char* buffer, size_t size); int mCommand; // START_TONE, STOP_TONE ... nsecs_t mTime; // time stamp + Mutex mLock; // mutex associated to mCond Condition mCond; // condition for status return status_t mStatus; // command status bool mWaitStatus; // true if caller is waiting for status - AudioCommandData *mParam; // command specific parameter data + sp mParam; // command specific parameter data }; - class AudioCommandData { + class AudioCommandData: public RefBase { public: virtual ~AudioCommandData() {} protected: @@ -262,9 +263,9 @@ private: Mutex mLock; Condition mWaitWorkCV; - Vector mAudioCommands; // list of pending commands + Vector < sp > mAudioCommands; // list of pending commands ToneGenerator *mpToneGenerator; // the tone generator - AudioCommand mLastCommand; // last processed command (used by dump) + sp mLastCommand; // last processed command (used by dump) String8 mName; // string used by wake lock fo delayed commands wp mService; }; -- cgit v1.1