2020-12-24 05:36:01 +00:00
|
|
|
#include <tgnet/FileLog.h>
|
2020-08-14 16:58:22 +00:00
|
|
|
#include "AndroidContext.h"
|
|
|
|
|
|
|
|
#include "sdk/android/native_api/jni/jvm.h"
|
|
|
|
|
|
|
|
namespace tgcalls {
|
|
|
|
|
2020-12-24 05:36:01 +00:00
|
|
|
AndroidContext::AndroidContext(JNIEnv *env, jobject instance) {
|
2020-08-14 16:58:22 +00:00
|
|
|
VideoCameraCapturerClass = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/messenger/voip/VideoCameraCapturer"));
|
|
|
|
jmethodID initMethodId = env->GetMethodID(VideoCameraCapturerClass, "<init>", "()V");
|
|
|
|
javaCapturer = env->NewGlobalRef(env->NewObject(VideoCameraCapturerClass, initMethodId));
|
2020-12-24 05:36:01 +00:00
|
|
|
javaInstance = env->NewGlobalRef(instance);
|
2020-08-14 16:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AndroidContext::~AndroidContext() {
|
|
|
|
JNIEnv *env = webrtc::AttachCurrentThreadIfNeeded();
|
|
|
|
|
|
|
|
jmethodID onDestroyMethodId = env->GetMethodID(VideoCameraCapturerClass, "onDestroy", "()V");
|
|
|
|
env->CallVoidMethod(javaCapturer, onDestroyMethodId);
|
|
|
|
env->DeleteGlobalRef(javaCapturer);
|
|
|
|
javaCapturer = nullptr;
|
|
|
|
|
|
|
|
env->DeleteGlobalRef(VideoCameraCapturerClass);
|
2020-12-24 05:36:01 +00:00
|
|
|
|
|
|
|
if (javaInstance) {
|
|
|
|
env->DeleteGlobalRef(javaInstance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidContext::setJavaInstance(JNIEnv *env, jobject instance) {
|
|
|
|
javaInstance = env->NewGlobalRef(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject AndroidContext::getJavaInstance() {
|
|
|
|
return javaInstance;
|
2020-08-14 16:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
jobject AndroidContext::getJavaCapturer() {
|
|
|
|
return javaCapturer;
|
|
|
|
}
|
|
|
|
|
|
|
|
jclass AndroidContext::getJavaCapturerClass() {
|
|
|
|
return VideoCameraCapturerClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace tgcalls
|