Clean up variable after it gets deleted

BUG=None
TEST=trybots
Review URL: https://webrtc-codereview.appspot.com/939038

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3313 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
leozwang@webrtc.org 2012-12-19 05:36:36 +00:00
parent e239bf0940
commit 515ef2428c
2 changed files with 12 additions and 11 deletions

@ -28,7 +28,8 @@
namespace webrtc namespace webrtc
{ {
// TODO(leozwang): Refactor jni and the following global variables, a
// good example is jni_helper in Chromium.
JavaVM* AudioDeviceAndroidJni::globalJvm = NULL; JavaVM* AudioDeviceAndroidJni::globalJvm = NULL;
JNIEnv* AudioDeviceAndroidJni::globalJNIEnv = NULL; JNIEnv* AudioDeviceAndroidJni::globalJNIEnv = NULL;
jobject AudioDeviceAndroidJni::globalContext = NULL; jobject AudioDeviceAndroidJni::globalContext = NULL;
@ -94,6 +95,11 @@ WebRtc_Word32 AudioDeviceAndroidJni::SetAndroidAudioDeviceObjects(
} }
globalJNIEnv->DeleteGlobalRef(globalScClass); globalJNIEnv->DeleteGlobalRef(globalScClass);
globalScClass = reinterpret_cast<jclass>(NULL);
globalJNIEnv->DeleteGlobalRef(globalContext);
globalContext = reinterpret_cast<jobject>(NULL);
globalJNIEnv = reinterpret_cast<JNIEnv*>(NULL); globalJNIEnv = reinterpret_cast<JNIEnv*>(NULL);
} }
@ -139,7 +145,7 @@ AudioDeviceAndroidJni::AudioDeviceAndroidJni(const WebRtc_Word32 id) :
_maxSpeakerVolume(0), _maxSpeakerVolume(0),
_loudSpeakerOn(false), _loudSpeakerOn(false),
_recAudioSource(1), // 1 is AudioSource.MIC which is our default _recAudioSource(1), // 1 is AudioSource.MIC which is our default
_javaVM(NULL), _javaContext(NULL), _jniEnvPlay(NULL), _javaVM(NULL), _jniEnvPlay(NULL),
_jniEnvRec(NULL), _javaScClass(0), _javaScObj(0), _jniEnvRec(NULL), _javaScClass(0), _javaScObj(0),
_javaPlayBuffer(0), _javaRecBuffer(0), _javaDirectPlayBuffer(NULL), _javaPlayBuffer(0), _javaRecBuffer(0), _javaDirectPlayBuffer(NULL),
_javaDirectRecBuffer(NULL), _javaMidPlayAudio(0), _javaDirectRecBuffer(NULL), _javaMidPlayAudio(0),
@ -424,9 +430,6 @@ WebRtc_Word32 AudioDeviceAndroidJni::Terminate()
_javaDirectPlayBuffer = NULL; _javaDirectPlayBuffer = NULL;
_javaDirectRecBuffer = NULL; _javaDirectRecBuffer = NULL;
env->DeleteGlobalRef(_javaContext);
_javaContext = NULL;
// Delete the references to the java buffers, this allows the // Delete the references to the java buffers, this allows the
// garbage collector to delete them // garbage collector to delete them
env->DeleteGlobalRef(_javaPlayBuffer); env->DeleteGlobalRef(_javaPlayBuffer);
@ -596,7 +599,7 @@ WebRtc_Word32 AudioDeviceAndroidJni::SetSpeakerVolume(WebRtc_UWord32 volume)
" Speaker not initialized"); " Speaker not initialized");
return -1; return -1;
} }
if (!_javaContext) if (!globalContext)
{ {
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
" Context is not set"); " Context is not set");
@ -661,7 +664,7 @@ WebRtc_Word32 AudioDeviceAndroidJni::SpeakerVolume(WebRtc_UWord32& volume) const
" Speaker not initialized"); " Speaker not initialized");
return -1; return -1;
} }
if (!_javaContext) if (!globalContext)
{ {
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
" Context is not set"); " Context is not set");
@ -2081,7 +2084,7 @@ WebRtc_Word32 AudioDeviceAndroidJni::SetPlayoutSampleRate(
WebRtc_Word32 AudioDeviceAndroidJni::SetLoudspeakerStatus(bool enable) WebRtc_Word32 AudioDeviceAndroidJni::SetLoudspeakerStatus(bool enable)
{ {
if (!_javaContext) if (!globalContext)
{ {
WEBRTC_TRACE(kTraceError, kTraceUtility, -1, WEBRTC_TRACE(kTraceError, kTraceUtility, -1,
" Context is not set"); " Context is not set");
@ -2165,7 +2168,6 @@ WebRtc_Word32 AudioDeviceAndroidJni::InitJavaResources()
{ {
// todo: Check if we already have created the java object // todo: Check if we already have created the java object
_javaVM = globalJvm; _javaVM = globalJvm;
_javaContext = globalContext;
_javaScClass = globalScClass; _javaScClass = globalScClass;
// use the jvm that has been set // use the jvm that has been set
@ -2238,7 +2240,7 @@ WebRtc_Word32 AudioDeviceAndroidJni::InitJavaResources()
// AUDIO MANAGEMENT // AUDIO MANAGEMENT
// This is not mandatory functionality // This is not mandatory functionality
if (_javaContext) { if (globalContext) {
jfieldID context_id = env->GetFieldID(globalScClass, jfieldID context_id = env->GetFieldID(globalScClass,
"_context", "_context",
"Landroid/content/Context;"); "Landroid/content/Context;");

@ -242,7 +242,6 @@ class AudioDeviceAndroidJni : public AudioDeviceGeneric {
// JNI and Java // JNI and Java
JavaVM* _javaVM; // denotes a Java VM JavaVM* _javaVM; // denotes a Java VM
jobject _javaContext; // the application context
JNIEnv* _jniEnvPlay; // The JNI env for playout thread JNIEnv* _jniEnvPlay; // The JNI env for playout thread
JNIEnv* _jniEnvRec; // The JNI env for recording thread JNIEnv* _jniEnvRec; // The JNI env for recording thread