mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 918372 - Allocate a single GlobalRef for the Android Context. r=blassey
This commit is contained in:
parent
958950efd6
commit
4b6f20b8c6
@ -94,15 +94,10 @@ MediaEngineWebRTC::EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSourc
|
||||
// get the JVM
|
||||
JavaVM *jvm = mozilla::AndroidBridge::Bridge()->GetVM();
|
||||
|
||||
JNIEnv *env;
|
||||
jint res = jvm->AttachCurrentThread(&env, NULL);
|
||||
|
||||
if (webrtc::VideoEngine::SetAndroidObjects(jvm, (void*)context) != 0) {
|
||||
LOG(("VieCapture:SetAndroidObjects Failed"));
|
||||
return;
|
||||
}
|
||||
|
||||
env->DeleteGlobalRef(context);
|
||||
#endif
|
||||
|
||||
if (!mVideoEngine) {
|
||||
|
@ -145,19 +145,10 @@ MediaConduitErrorCode WebrtcAudioConduit::Init(WebrtcAudioConduit *other)
|
||||
// get the JVM
|
||||
JavaVM *jvm = jsjni_GetVM();
|
||||
|
||||
JNIEnv* env;
|
||||
if (jvm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) {
|
||||
CSFLogError(logTag, "%s: could not get Java environment", __FUNCTION__);
|
||||
return kMediaConduitSessionNotInited;
|
||||
}
|
||||
jvm->AttachCurrentThread(&env, NULL);
|
||||
|
||||
if (webrtc::VoiceEngine::SetAndroidObjects(jvm, (void*)context) != 0) {
|
||||
CSFLogError(logTag, "%s Unable to set Android objects", __FUNCTION__);
|
||||
return kMediaConduitSessionNotInited;
|
||||
}
|
||||
|
||||
env->DeleteGlobalRef(context);
|
||||
#endif
|
||||
|
||||
//Per WebRTC APIs below function calls return NULL on failure
|
||||
|
@ -113,19 +113,10 @@ MediaConduitErrorCode WebrtcVideoConduit::Init()
|
||||
// get the JVM
|
||||
JavaVM *jvm = jsjni_GetVM();
|
||||
|
||||
JNIEnv* env;
|
||||
if (jvm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) {
|
||||
CSFLogError(logTag, "%s: could not get Java environment", __FUNCTION__);
|
||||
return kMediaConduitSessionNotInited;
|
||||
}
|
||||
jvm->AttachCurrentThread(&env, nullptr);
|
||||
|
||||
if (webrtc::VideoEngine::SetAndroidObjects(jvm, (void*)context) != 0) {
|
||||
CSFLogError(logTag, "%s: could not set Android objects", __FUNCTION__);
|
||||
return kMediaConduitSessionNotInited;
|
||||
}
|
||||
|
||||
env->DeleteGlobalRef(context);
|
||||
#endif
|
||||
|
||||
if( !(mVideoEngine = webrtc::VideoEngine::Create()) )
|
||||
|
@ -49,6 +49,7 @@ NS_IMPL_ISUPPORTS0(nsFilePickerCallback)
|
||||
|
||||
StaticRefPtr<AndroidBridge> AndroidBridge::sBridge;
|
||||
static unsigned sJavaEnvThreadIndex = 0;
|
||||
static jobject sGlobalContext = nullptr;
|
||||
static void JavaThreadDetachFunc(void *arg);
|
||||
|
||||
// This is a dummy class that can be used in the template for android::sp
|
||||
@ -1434,18 +1435,40 @@ AndroidBridge::LockWindow(void *window, unsigned char **bits, int *width, int *h
|
||||
|
||||
jobject
|
||||
AndroidBridge::GetGlobalContextRef() {
|
||||
if (sGlobalContext == nullptr) {
|
||||
JNIEnv *env = GetJNIForThread();
|
||||
if (!env)
|
||||
return 0;
|
||||
|
||||
AutoLocalJNIFrame jniFrame(env, 2);
|
||||
AutoLocalJNIFrame jniFrame(env, 4);
|
||||
|
||||
jobject context = GetContext();
|
||||
if (!context) {
|
||||
ALOG_BRIDGE("%s: Could not GetContext()", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
jclass contextClass = env->FindClass("android/content/Context");
|
||||
if (!contextClass) {
|
||||
ALOG_BRIDGE("%s: Could not find Context class.", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
jmethodID mid = env->GetMethodID(contextClass, "getApplicationContext",
|
||||
"()Landroid/content/Context;");
|
||||
if (!mid) {
|
||||
ALOG_BRIDGE("%s: Could not find getApplicationContext.", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
jobject appContext = env->CallObjectMethod(context, mid);
|
||||
if (!appContext) {
|
||||
ALOG_BRIDGE("%s: getApplicationContext failed.", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
jobject globalRef = env->NewGlobalRef(context);
|
||||
MOZ_ASSERT(globalRef);
|
||||
sGlobalContext = env->NewGlobalRef(appContext);
|
||||
MOZ_ASSERT(sGlobalContext);
|
||||
}
|
||||
|
||||
return globalRef;
|
||||
return sGlobalContext;
|
||||
}
|
||||
|
||||
bool
|
||||
|
Loading…
Reference in New Issue
Block a user