| 6 | namespace tgcalls { |
| 7 |
| 8 | AndroidContext::AndroidContext(JNIEnv *env, jobject peerInstance, jobject groupInstance, bool screencast) { |
| 9 | VideoCapturerDeviceClass = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/messenger/voip/VideoCapturerDevice")); |
| 10 | jmethodID initMethodId = env->GetMethodID(VideoCapturerDeviceClass, "<init>", "(Z)V"); |
| 11 | javaCapturer = env->NewGlobalRef(env->NewObject(VideoCapturerDeviceClass, initMethodId, screencast)); |
| 12 | if (peerInstance) { |
| 13 | javaPeerInstance = env->NewGlobalRef(peerInstance); |
| 14 | } |
| 15 | if (groupInstance) { |
| 16 | javaGroupInstance = env->NewGlobalRef(groupInstance); |
| 17 | } |
| 18 | } |
| 19 |
| 20 | AndroidContext::~AndroidContext() { |
| 21 | JNIEnv *env = webrtc::AttachCurrentThreadIfNeeded(); |
| 22 |
| 23 | jmethodID onDestroyMethodId = env->GetMethodID(VideoCapturerDeviceClass, "onDestroy", "()V"); |
| 24 | env->CallVoidMethod(javaCapturer, onDestroyMethodId); |
| 25 | env->DeleteGlobalRef(javaCapturer); |
| 26 | javaCapturer = nullptr; |
| 27 |
| 28 | env->DeleteGlobalRef(VideoCapturerDeviceClass); |
| 29 |
| 30 | if (javaPeerInstance) { |
| 31 | env->DeleteGlobalRef(javaPeerInstance); |
| 32 | } |
| 33 | if (javaGroupInstance) { |
| 34 | env->DeleteGlobalRef(javaGroupInstance); |
| 35 | } |
| 36 | } |
| 37 |
| 38 | void AndroidContext::setJavaPeerInstance(JNIEnv *env, jobject instance) { |
| 39 | javaPeerInstance = env->NewGlobalRef(instance); |
| 40 | } |
| 41 |
| 42 | void AndroidContext::setJavaGroupInstance(JNIEnv *env, jobject instance) { |
| 43 | javaGroupInstance = env->NewGlobalRef(instance); |
| 44 | } |
| 45 |
| 46 | jobject AndroidContext::getJavaPeerInstance() { |
| 47 | return javaPeerInstance; |
| 48 | } |
| 49 |
| 50 | jobject AndroidContext::getJavaGroupInstance() { |
| 51 | return javaGroupInstance; |
| 52 | } |
| 53 |
| 54 | jobject AndroidContext::getJavaCapturer() { |
| 55 | return javaCapturer; |
| 56 | } |
| 57 |
| 58 | jclass AndroidContext::getJavaCapturerClass() { |
| 59 | return VideoCapturerDeviceClass; |
| 60 | } |
| 61 |
| 62 | } // namespace tgcalls |
| 63 |