From ce2b95ae200332495b348be07f77fe60b6c23dcc Mon Sep 17 00:00:00 2001 From: Jay Shrauner Date: Wed, 26 Feb 2014 10:08:37 -0800 Subject: Fix AudioEngine to allow re-initialization - DO NOT MERGE Add AudioEngine::CompareAndSetEngine and change VariableSpeed::initializeEngine to use this method so it only initializes a new engine once rather than asserting on subsequent calls. Change AudioEngine::DeleteEngine so it ignores repeated calls instead of asserting. Add VariableSpeed::isReadyToPlay so callers can detect when the audio library has been properly initialized. Bug:11511992 Change-Id: I4517cb2ab4c186da43dffc7dbc2a9ad49000059f (cherry picked from commit 8502b724a9fdc104e7b4a3aba1641e101b4c7be9) --- variablespeed/jni/variablespeed.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'variablespeed/jni/variablespeed.cc') diff --git a/variablespeed/jni/variablespeed.cc b/variablespeed/jni/variablespeed.cc index 73ac609..4bdbbcc 100644 --- a/variablespeed/jni/variablespeed.cc +++ b/variablespeed/jni/variablespeed.cc @@ -129,14 +129,21 @@ void AudioEngine::SetEngine(AudioEngine* engine) { audioEngine_ = engine; } +bool AudioEngine::CompareAndSetEngine(AudioEngine* expect, AudioEngine* update) { + android::Mutex::Autolock autoLock(publishEngineLock_); + if (audioEngine_ == expect) { + DeleteEngine(); + audioEngine_ = update; + return true; + } + return false; +} + void AudioEngine::DeleteEngine() { - if (audioEngine_ == NULL) { - LOGE("you haven't initialized the audio engine"); - CHECK(false); - return; + if (audioEngine_ != NULL) { + delete audioEngine_; + audioEngine_ = NULL; } - delete audioEngine_; - audioEngine_ = NULL; } // **************************************************************************** -- cgit v1.2.3