Nagram/TMessagesProj/jni/voip/tgcalls/platform/android/AndroidContext.cpp

47 lines
1.4 KiB
C++
Raw Normal View History

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 {
2021-06-25 00:43:10 +00:00
AndroidContext::AndroidContext(JNIEnv *env, jobject instance, bool screencast) {
VideoCapturerDeviceClass = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/messenger/voip/VideoCapturerDevice"));
jmethodID initMethodId = env->GetMethodID(VideoCapturerDeviceClass, "<init>", "(Z)V");
javaCapturer = env->NewGlobalRef(env->NewObject(VideoCapturerDeviceClass, initMethodId, screencast));
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();
2021-06-25 00:43:10 +00:00
jmethodID onDestroyMethodId = env->GetMethodID(VideoCapturerDeviceClass, "onDestroy", "()V");
2020-08-14 16:58:22 +00:00
env->CallVoidMethod(javaCapturer, onDestroyMethodId);
env->DeleteGlobalRef(javaCapturer);
javaCapturer = nullptr;
2021-06-25 00:43:10 +00:00
env->DeleteGlobalRef(VideoCapturerDeviceClass);
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() {
2021-06-25 00:43:10 +00:00
return VideoCapturerDeviceClass;
2020-08-14 16:58:22 +00:00
}
} // namespace tgcalls