@@ -96,7 +96,6 @@ namespace jni
96
96
JavaFactories::add<webrtc::DataBuffer>(std::make_unique<DataBufferFactory>(env, PKG" RTCDataChannelBuffer" ));
97
97
98
98
initializeClassLoader (env, PKG_INTERNAL" NativeClassLoader" );
99
- initializeDeviceManagers ();
100
99
}
101
100
102
101
void WebRTCContext::initializeClassLoader (JNIEnv* env, const char * loaderName)
@@ -126,26 +125,48 @@ namespace jni
126
125
127
126
avdev::AudioDeviceManager * WebRTCContext::getAudioDeviceManager ()
128
127
{
128
+ std::unique_lock<std::mutex> mlock (aMutex);
129
+
130
+ if (audioDevManager == nullptr ) {
131
+ initializeAudioManager ();
132
+ }
133
+
129
134
return audioDevManager.get ();
130
135
}
131
136
132
137
avdev::VideoDeviceManager * WebRTCContext::getVideoDeviceManager ()
133
138
{
139
+ std::unique_lock<std::mutex> mlock (vMutex);
140
+
141
+ if (videoDevManager == nullptr ) {
142
+ initializeVideoManager ();
143
+ }
144
+
134
145
return videoDevManager.get ();
135
146
}
136
147
137
- void WebRTCContext::initializeDeviceManagers ()
148
+ void WebRTCContext::initializeAudioManager ()
138
149
{
139
150
#ifdef _WIN32
140
151
audioDevManager = std::make_unique<avdev::WindowsAudioDeviceManager>();
141
- videoDevManager = std::make_unique<avdev::WindowsVideoDeviceManager>();
142
152
#endif
143
153
#ifdef __linux__
144
154
audioDevManager = std::make_unique<avdev::PulseAudioDeviceManager>();
145
- videoDevManager = std::make_unique<avdev::V4l2VideoDeviceManager>();
146
155
#endif
147
156
#ifdef __APPLE__
148
157
audioDevManager = std::make_unique<avdev::CoreAudioDeviceManager>();
158
+ #endif
159
+ }
160
+
161
+ void WebRTCContext::initializeVideoManager ()
162
+ {
163
+ #ifdef _WIN32
164
+ videoDevManager = std::make_unique<avdev::WindowsVideoDeviceManager>();
165
+ #endif
166
+ #ifdef __linux__
167
+ videoDevManager = std::make_unique<avdev::V4l2VideoDeviceManager>();
168
+ #endif
169
+ #ifdef __APPLE__
149
170
videoDevManager = std::make_unique<avdev::AVFVideoDeviceManager>();
150
171
#endif
151
172
}
0 commit comments