Android: Fixes crash when exiting WebRTCDemo.
BUG=2738 R=fischman@webrtc.org, niklas.enbom@webrtc.org Review URL: https://webrtc-codereview.appspot.com/6179004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5365 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
7cc64b3747
commit
573a1b45b5
@ -30,6 +30,12 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
|
|||||||
}
|
}
|
||||||
return InputType::SetAndroidAudioDeviceObjects(javaVM, env, context);
|
return InputType::SetAndroidAudioDeviceObjects(javaVM, env, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ClearAndroidAudioDeviceObjects() {
|
||||||
|
OutputType::ClearAndroidAudioDeviceObjects();
|
||||||
|
InputType::ClearAndroidAudioDeviceObjects();
|
||||||
|
}
|
||||||
|
|
||||||
explicit AudioDeviceTemplate(const int32_t id)
|
explicit AudioDeviceTemplate(const int32_t id)
|
||||||
: output_(id),
|
: output_(id),
|
||||||
input_(id, &output_) {
|
input_(id, &output_) {
|
||||||
|
@ -37,9 +37,8 @@ jclass AudioRecordJni::globalScClass = NULL;
|
|||||||
|
|
||||||
int32_t AudioRecordJni::SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
int32_t AudioRecordJni::SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
||||||
void* context) {
|
void* context) {
|
||||||
|
assert(env);
|
||||||
globalJvm = reinterpret_cast<JavaVM*>(javaVM);
|
globalJvm = reinterpret_cast<JavaVM*>(javaVM);
|
||||||
|
|
||||||
if (env) {
|
|
||||||
globalJNIEnv = reinterpret_cast<JNIEnv*>(env);
|
globalJNIEnv = reinterpret_cast<JNIEnv*>(env);
|
||||||
// Get java class type (note path to class packet).
|
// Get java class type (note path to class packet).
|
||||||
jclass javaScClassLocal = globalJNIEnv->FindClass(
|
jclass javaScClassLocal = globalJNIEnv->FindClass(
|
||||||
@ -70,27 +69,28 @@ int32_t AudioRecordJni::SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
|||||||
|
|
||||||
// Delete local class ref, we only use the global ref
|
// Delete local class ref, we only use the global ref
|
||||||
globalJNIEnv->DeleteLocalRef(javaScClassLocal);
|
globalJNIEnv->DeleteLocalRef(javaScClassLocal);
|
||||||
}
|
|
||||||
else { // User is resetting the env variable
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioRecordJni::ClearAndroidAudioDeviceObjects() {
|
||||||
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, -1,
|
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, -1,
|
||||||
"%s: env is NULL, assuming deinit", __FUNCTION__);
|
"%s: env is NULL, assuming deinit", __FUNCTION__);
|
||||||
|
|
||||||
|
globalJvm = NULL;;
|
||||||
if (!globalJNIEnv) {
|
if (!globalJNIEnv) {
|
||||||
WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, -1,
|
WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, -1,
|
||||||
"%s: saved env already NULL", __FUNCTION__);
|
"%s: saved env already NULL", __FUNCTION__);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
globalJNIEnv->DeleteGlobalRef(globalScClass);
|
|
||||||
globalScClass = reinterpret_cast<jclass>(NULL);
|
|
||||||
|
|
||||||
globalJNIEnv->DeleteGlobalRef(globalContext);
|
globalJNIEnv->DeleteGlobalRef(globalContext);
|
||||||
globalContext = reinterpret_cast<jobject>(NULL);
|
globalContext = reinterpret_cast<jobject>(NULL);
|
||||||
|
|
||||||
globalJNIEnv = reinterpret_cast<JNIEnv*>(NULL);
|
globalJNIEnv->DeleteGlobalRef(globalScClass);
|
||||||
}
|
globalScClass = reinterpret_cast<jclass>(NULL);
|
||||||
|
|
||||||
return 0;
|
globalJNIEnv = reinterpret_cast<JNIEnv*>(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioRecordJni::AudioRecordJni(
|
AudioRecordJni::AudioRecordJni(
|
||||||
|
@ -31,6 +31,7 @@ class AudioRecordJni {
|
|||||||
public:
|
public:
|
||||||
static int32_t SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
static int32_t SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
||||||
void* context);
|
void* context);
|
||||||
|
static void ClearAndroidAudioDeviceObjects();
|
||||||
|
|
||||||
AudioRecordJni(const int32_t id, PlayoutDelayProvider* delay_provider);
|
AudioRecordJni(const int32_t id, PlayoutDelayProvider* delay_provider);
|
||||||
~AudioRecordJni();
|
~AudioRecordJni();
|
||||||
|
@ -36,9 +36,8 @@ jclass AudioTrackJni::globalScClass = NULL;
|
|||||||
|
|
||||||
int32_t AudioTrackJni::SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
int32_t AudioTrackJni::SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
||||||
void* context) {
|
void* context) {
|
||||||
|
assert(env);
|
||||||
globalJvm = reinterpret_cast<JavaVM*>(javaVM);
|
globalJvm = reinterpret_cast<JavaVM*>(javaVM);
|
||||||
|
|
||||||
if (env) {
|
|
||||||
globalJNIEnv = reinterpret_cast<JNIEnv*>(env);
|
globalJNIEnv = reinterpret_cast<JNIEnv*>(env);
|
||||||
// Get java class type (note path to class packet).
|
// Get java class type (note path to class packet).
|
||||||
jclass javaScClassLocal = globalJNIEnv->FindClass(
|
jclass javaScClassLocal = globalJNIEnv->FindClass(
|
||||||
@ -69,27 +68,27 @@ int32_t AudioTrackJni::SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
|||||||
|
|
||||||
// Delete local class ref, we only use the global ref
|
// Delete local class ref, we only use the global ref
|
||||||
globalJNIEnv->DeleteLocalRef(javaScClassLocal);
|
globalJNIEnv->DeleteLocalRef(javaScClassLocal);
|
||||||
}
|
return 0;
|
||||||
else { // User is resetting the env variable
|
}
|
||||||
|
|
||||||
|
void AudioTrackJni::ClearAndroidAudioDeviceObjects() {
|
||||||
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, -1,
|
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, -1,
|
||||||
"%s: env is NULL, assuming deinit", __FUNCTION__);
|
"%s: env is NULL, assuming deinit", __FUNCTION__);
|
||||||
|
|
||||||
|
globalJvm = NULL;
|
||||||
if (!globalJNIEnv) {
|
if (!globalJNIEnv) {
|
||||||
WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, -1,
|
WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, -1,
|
||||||
"%s: saved env already NULL", __FUNCTION__);
|
"%s: saved env already NULL", __FUNCTION__);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
globalJNIEnv->DeleteGlobalRef(globalScClass);
|
|
||||||
globalScClass = reinterpret_cast<jclass>(NULL);
|
|
||||||
|
|
||||||
globalJNIEnv->DeleteGlobalRef(globalContext);
|
globalJNIEnv->DeleteGlobalRef(globalContext);
|
||||||
globalContext = reinterpret_cast<jobject>(NULL);
|
globalContext = reinterpret_cast<jobject>(NULL);
|
||||||
|
|
||||||
globalJNIEnv = reinterpret_cast<JNIEnv*>(NULL);
|
globalJNIEnv->DeleteGlobalRef(globalScClass);
|
||||||
}
|
globalScClass = reinterpret_cast<jclass>(NULL);
|
||||||
|
|
||||||
return 0;
|
globalJNIEnv = reinterpret_cast<JNIEnv*>(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioTrackJni::AudioTrackJni(const int32_t id)
|
AudioTrackJni::AudioTrackJni(const int32_t id)
|
||||||
|
@ -30,7 +30,7 @@ class AudioTrackJni : public PlayoutDelayProvider {
|
|||||||
public:
|
public:
|
||||||
static int32_t SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
static int32_t SetAndroidAudioDeviceObjects(void* javaVM, void* env,
|
||||||
void* context);
|
void* context);
|
||||||
|
static void ClearAndroidAudioDeviceObjects();
|
||||||
explicit AudioTrackJni(const int32_t id);
|
explicit AudioTrackJni(const int32_t id);
|
||||||
virtual ~AudioTrackJni();
|
virtual ~AudioTrackJni();
|
||||||
|
|
||||||
|
@ -75,6 +75,9 @@ int32_t OpenSlesInput::SetAndroidAudioDeviceObjects(void* javaVM,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenSlesInput::ClearAndroidAudioDeviceObjects() {
|
||||||
|
}
|
||||||
|
|
||||||
int32_t OpenSlesInput::Init() {
|
int32_t OpenSlesInput::Init() {
|
||||||
assert(!initialized_);
|
assert(!initialized_);
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ class OpenSlesInput {
|
|||||||
static int32_t SetAndroidAudioDeviceObjects(void* javaVM,
|
static int32_t SetAndroidAudioDeviceObjects(void* javaVM,
|
||||||
void* env,
|
void* env,
|
||||||
void* context);
|
void* context);
|
||||||
|
static void ClearAndroidAudioDeviceObjects();
|
||||||
|
|
||||||
// Main initializaton and termination
|
// Main initializaton and termination
|
||||||
int32_t Init();
|
int32_t Init();
|
||||||
|
@ -76,6 +76,10 @@ int32_t OpenSlesOutput::SetAndroidAudioDeviceObjects(void* javaVM,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenSlesOutput::ClearAndroidAudioDeviceObjects() {
|
||||||
|
AudioManagerJni::ClearAndroidAudioDeviceObjects();
|
||||||
|
}
|
||||||
|
|
||||||
int32_t OpenSlesOutput::Init() {
|
int32_t OpenSlesOutput::Init() {
|
||||||
assert(!initialized_);
|
assert(!initialized_);
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ class OpenSlesOutput : public PlayoutDelayProvider {
|
|||||||
static int32_t SetAndroidAudioDeviceObjects(void* javaVM,
|
static int32_t SetAndroidAudioDeviceObjects(void* javaVM,
|
||||||
void* env,
|
void* env,
|
||||||
void* context);
|
void* context);
|
||||||
|
static void ClearAndroidAudioDeviceObjects();
|
||||||
|
|
||||||
// Main initializaton and termination
|
// Main initializaton and termination
|
||||||
int32_t Init();
|
int32_t Init();
|
||||||
|
@ -149,12 +149,18 @@ int VoiceEngine::SetAndroidObjects(void* javaVM, void* env, void* context)
|
|||||||
{
|
{
|
||||||
#ifdef WEBRTC_ANDROID
|
#ifdef WEBRTC_ANDROID
|
||||||
#ifdef WEBRTC_ANDROID_OPENSLES
|
#ifdef WEBRTC_ANDROID_OPENSLES
|
||||||
return AudioDeviceTemplate<OpenSlesInput, OpenSlesOutput>::
|
typedef AudioDeviceTemplate<OpenSlesInput, OpenSlesOutput>
|
||||||
SetAndroidAudioDeviceObjects(javaVM, env, context);
|
AudioDeviceInstance;
|
||||||
#else
|
#else
|
||||||
return AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>::
|
typedef AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>
|
||||||
SetAndroidAudioDeviceObjects(javaVM, env, context);
|
AudioDeviceInstance;
|
||||||
#endif
|
#endif
|
||||||
|
if (javaVM && env && context) {
|
||||||
|
AudioDeviceInstance::SetAndroidAudioDeviceObjects(javaVM, env, context);
|
||||||
|
} else {
|
||||||
|
AudioDeviceInstance::ClearAndroidAudioDeviceObjects();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user