1818#include " api/DataBufferFactory.h"
1919#include " api/RTCStats.h"
2020#include " Exception.h"
21+ #include " JavaClassLoader.h"
2122#include " JavaError.h"
2223#include " JavaEnums.h"
2324#include " JavaFactories.h"
@@ -55,8 +56,6 @@ namespace jni
5556
5657 void WebRTCContext::initialize (JNIEnv * env)
5758 {
58- JavaContext::initialize (env);
59-
6059 if (!rtc::InitializeSSL ()) {
6160 throw Exception (" Initialize SSL failed" );
6261 }
@@ -96,7 +95,23 @@ namespace jni
9695 JavaFactories::add<webrtc::RtpTransceiverInterface>(env, PKG" RTCRtpTransceiver" );
9796 JavaFactories::add<webrtc::DataBuffer>(std::make_unique<DataBufferFactory>(env, PKG" RTCDataChannelBuffer" ));
9897
99- initDeviceManagers ();
98+ initializeClassLoader (env, PKG_INTERNAL" NativeClassLoader" );
99+ initializeDeviceManagers ();
100+ }
101+
102+ void WebRTCContext::initializeClassLoader (JNIEnv* env, const char * loaderName)
103+ {
104+ auto javaClass = JavaLocalRef<jclass>(env, FindClass (env, loaderName));
105+
106+ if (ExceptionCheck (env)) {
107+ return ;
108+ }
109+
110+ auto javaGet = GetStaticMethod (env, javaClass, " getClassLoader" , " ()Ljava/lang/ClassLoader;" );
111+
112+ auto loaderRef = jni::JavaGlobalRef<jobject>(env, env->CallStaticObjectMethod (javaClass, javaGet));
113+
114+ InitClassLoader (env, loaderRef);
100115 }
101116
102117 void WebRTCContext::destroy (JNIEnv * env)
@@ -107,8 +122,6 @@ namespace jni
107122
108123 audioDevManager = nullptr ;
109124 videoDevManager = nullptr ;
110-
111- JavaContext::destroy (env);
112125 }
113126
114127 avdev::AudioDeviceManager * WebRTCContext::getAudioDeviceManager ()
@@ -121,7 +134,7 @@ namespace jni
121134 return videoDevManager.get ();
122135 }
123136
124- void WebRTCContext::initDeviceManagers ()
137+ void WebRTCContext::initializeDeviceManagers ()
125138 {
126139#ifdef _WIN32
127140 audioDevManager = std::make_unique<avdev::WindowsAudioDeviceManager>();
0 commit comments