diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2009-07-21 14:12:47 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2009-07-21 14:22:25 -0700 |
commit | cee3bd4d68bf40d36fee3f0f5ce03f9edae87b51 (patch) | |
tree | f60abaf471d16280fbb5b23231c9d9ec3df46c1b /packages/TtsService | |
parent | db7db69a2162439bf722d0f1f65429ca3ca19dcd (diff) | |
download | frameworks_base-cee3bd4d68bf40d36fee3f0f5ce03f9edae87b51.zip frameworks_base-cee3bd4d68bf40d36fee3f0f5ce03f9edae87b51.tar.gz frameworks_base-cee3bd4d68bf40d36fee3f0f5ce03f9edae87b51.tar.bz2 |
Reset the speech synth singleton to null when the service is destroyed
so it can be recreated when the service is initialized.
In the interface with the native synthesizer library, close the lib
in the finalizer, delete the global ref to the SynthProxy java object.
Diffstat (limited to 'packages/TtsService')
-rw-r--r-- | packages/TtsService/jni/android_tts_SynthProxy.cpp | 64 | ||||
-rwxr-xr-x | packages/TtsService/src/android/tts/TtsService.java | 1 |
2 files changed, 37 insertions, 28 deletions
diff --git a/packages/TtsService/jni/android_tts_SynthProxy.cpp b/packages/TtsService/jni/android_tts_SynthProxy.cpp index 82067be..8c83fad 100644 --- a/packages/TtsService/jni/android_tts_SynthProxy.cpp +++ b/packages/TtsService/jni/android_tts_SynthProxy.cpp @@ -65,9 +65,9 @@ static Mutex engineMutex; // ---------------------------------------------------------------------------- class SynthProxyJniStorage { public : - //jclass tts_class; jobject tts_ref; TtsEngine* mNativeSynthInterface; + void* mEngineLibHandle; AudioTrack* mAudioOut; AudioSystem::stream_type mStreamType; uint32_t mSampleRate; @@ -77,9 +77,9 @@ class SynthProxyJniStorage { size_t mBufferSize; SynthProxyJniStorage() { - //tts_class = NULL; tts_ref = NULL; mNativeSynthInterface = NULL; + mEngineLibHandle = NULL; mAudioOut = NULL; mStreamType = DEFAULT_TTS_STREAM_TYPE; mSampleRate = DEFAULT_TTS_RATE; @@ -91,11 +91,17 @@ class SynthProxyJniStorage { } ~SynthProxyJniStorage() { + //LOGV("entering ~SynthProxyJniStorage()"); killAudio(); if (mNativeSynthInterface) { mNativeSynthInterface->shutdown(); mNativeSynthInterface = NULL; } + if (mEngineLibHandle) { + //LOGE("~SynthProxyJniStorage(): before close library"); + int res = dlclose(mEngineLibHandle); + LOGE_IF( res != 0, "~SynthProxyJniStorage(): dlclose returned %d", res); + } delete mBuffer; } @@ -138,13 +144,13 @@ class SynthProxyJniStorage { 0, 0, 0, 0); // not using an AudioTrack callback if (mAudioOut->initCheck() != NO_ERROR) { - LOGI("AudioTrack error"); + LOGE("createAudioOut(): AudioTrack error"); delete mAudioOut; mAudioOut = NULL; } else { //LOGI("AudioTrack OK"); mAudioOut->start(); - LOGI("AudioTrack started"); + LOGV("AudioTrack started"); } } }; @@ -259,16 +265,18 @@ android_tts_SynthProxy_native_setup(JNIEnv *env, jobject thiz, void *engine_lib_handle = dlopen(nativeSoLibNativeString, RTLD_NOW | RTLD_LOCAL); - if (engine_lib_handle==NULL) { - LOGI("engine_lib_handle==NULL"); + if (engine_lib_handle == NULL) { + LOGE("android_tts_SynthProxy_native_setup(): engine_lib_handle == NULL"); // TODO report error so the TTS can't be used } else { TtsEngine *(*get_TtsEngine)() = reinterpret_cast<TtsEngine* (*)()>(dlsym(engine_lib_handle, "getTtsEngine")); pJniStorage->mNativeSynthInterface = (*get_TtsEngine)(); + pJniStorage->mEngineLibHandle = engine_lib_handle; if (pJniStorage->mNativeSynthInterface) { + Mutex::Autolock l(engineMutex); pJniStorage->mNativeSynthInterface->init(ttsSynthDoneCB); } } @@ -287,11 +295,29 @@ android_tts_SynthProxy_native_setup(JNIEnv *env, jobject thiz, static void android_tts_SynthProxy_native_finalize(JNIEnv *env, jobject thiz, jint jniData) { - if (jniData) { - SynthProxyJniStorage* pSynthData = (SynthProxyJniStorage*)jniData; - env->DeleteGlobalRef(pSynthData->tts_ref); - delete pSynthData; + //LOGV("entering android_tts_SynthProxy_finalize()"); + if (jniData == 0) { + //LOGE("android_tts_SynthProxy_native_finalize(): invalid JNI data"); + return; } + + Mutex::Autolock l(engineMutex); + + SynthProxyJniStorage* pSynthData = (SynthProxyJniStorage*)jniData; + env->DeleteGlobalRef(pSynthData->tts_ref); + delete pSynthData; + + env->SetIntField(thiz, javaTTSFields.synthProxyFieldJniData, 0); +} + + +static void +android_tts_SynthProxy_shutdown(JNIEnv *env, jobject thiz, jint jniData) +{ + //LOGV("entering android_tts_SynthProxy_shutdown()"); + + // do everything a call to finalize would + android_tts_SynthProxy_native_finalize(env, thiz, jniData); } @@ -604,24 +630,6 @@ android_tts_SynthProxy_stop(JNIEnv *env, jobject thiz, jint jniData) } -static void -android_tts_SynthProxy_shutdown(JNIEnv *env, jobject thiz, jint jniData) -{ - if (jniData == 0) { - LOGE("android_tts_SynthProxy_shutdown(): invalid JNI data"); - return; - } - - Mutex::Autolock l(engineMutex); - - SynthProxyJniStorage* pSynthData = (SynthProxyJniStorage*)jniData; - if (pSynthData->mNativeSynthInterface) { - pSynthData->mNativeSynthInterface->shutdown(); - pSynthData->mNativeSynthInterface = NULL; - } -} - - static jobjectArray android_tts_SynthProxy_getLanguage(JNIEnv *env, jobject thiz, jint jniData) { diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java index cfefcb7..e52ba80 100755 --- a/packages/TtsService/src/android/tts/TtsService.java +++ b/packages/TtsService/src/android/tts/TtsService.java @@ -174,6 +174,7 @@ public class TtsService extends Service implements OnCompletionListener { cleanUpPlayer(); sNativeSynth.shutdown(); + sNativeSynth = null; // Unregister all callbacks. mCallbacks.kill(); |