Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Side by Side Diff: webrtc/sdk/android/src/jni/pc/peerconnectionfactory_jni.cc

Issue 3009613002: Android: Replace webrtc_jni namespace with nested jni namespace (Closed)
Patch Set: Rebase Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 14 matching lines...) Expand all
25 #include "webrtc/sdk/android/src/jni/pc/ownedfactoryandthreads.h" 25 #include "webrtc/sdk/android/src/jni/pc/ownedfactoryandthreads.h"
26 #include "webrtc/sdk/android/src/jni/pc/peerconnectionobserver_jni.h" 26 #include "webrtc/sdk/android/src/jni/pc/peerconnectionobserver_jni.h"
27 #include "webrtc/sdk/android/src/jni/pc/video_jni.h" 27 #include "webrtc/sdk/android/src/jni/pc/video_jni.h"
28 #include "webrtc/system_wrappers/include/field_trial.h" 28 #include "webrtc/system_wrappers/include/field_trial.h"
29 // Adding 'nogncheck' to disable the gn include headers check. 29 // Adding 'nogncheck' to disable the gn include headers check.
30 // We don't want to depend on 'system_wrappers:field_trial_default' because 30 // We don't want to depend on 'system_wrappers:field_trial_default' because
31 // clients should be able to provide their own implementation. 31 // clients should be able to provide their own implementation.
32 #include "webrtc/system_wrappers/include/field_trial_default.h" // nogncheck 32 #include "webrtc/system_wrappers/include/field_trial_default.h" // nogncheck
33 #include "webrtc/system_wrappers/include/trace.h" 33 #include "webrtc/system_wrappers/include/trace.h"
34 34
35 namespace webrtc_jni { 35 namespace webrtc {
36 namespace jni {
36 37
37 // Note: Some of the video-specific PeerConnectionFactory methods are 38 // Note: Some of the video-specific PeerConnectionFactory methods are
38 // implemented in "video_jni.cc". This is done so that if an application 39 // implemented in "video_jni.cc". This is done so that if an application
39 // doesn't need video support, it can just link with "null_video_jni.cc" 40 // doesn't need video support, it can just link with "null_video_jni.cc"
40 // instead of "video_jni.cc", which doesn't bring in the video-specific 41 // instead of "video_jni.cc", which doesn't bring in the video-specific
41 // dependencies. 42 // dependencies.
42 43
43 // Field trials initialization string 44 // Field trials initialization string
44 static char* field_trials_init_string = nullptr; 45 static char* field_trials_init_string = nullptr;
45 46
(...skipping 10 matching lines...) Expand all
56 } 57 }
57 58
58 JNI_FUNCTION_DECLARATION(void, 59 JNI_FUNCTION_DECLARATION(void,
59 PeerConnectionFactory_nativeInitializeAndroidGlobals, 60 PeerConnectionFactory_nativeInitializeAndroidGlobals,
60 JNIEnv* jni, 61 JNIEnv* jni,
61 jclass, 62 jclass,
62 jobject context, 63 jobject context,
63 jboolean video_hw_acceleration) { 64 jboolean video_hw_acceleration) {
64 video_hw_acceleration_enabled = video_hw_acceleration; 65 video_hw_acceleration_enabled = video_hw_acceleration;
65 if (!factory_static_initialized) { 66 if (!factory_static_initialized) {
66 webrtc::JVM::Initialize(GetJVM()); 67 JVM::Initialize(GetJVM());
67 factory_static_initialized = true; 68 factory_static_initialized = true;
68 } 69 }
69 } 70 }
70 71
71 JNI_FUNCTION_DECLARATION(void, 72 JNI_FUNCTION_DECLARATION(void,
72 PeerConnectionFactory_initializeFieldTrials, 73 PeerConnectionFactory_initializeFieldTrials,
73 JNIEnv* jni, 74 JNIEnv* jni,
74 jclass, 75 jclass,
75 jstring j_trials_init_string) { 76 jstring j_trials_init_string) {
76 field_trials_init_string = NULL; 77 field_trials_init_string = NULL;
77 if (j_trials_init_string != NULL) { 78 if (j_trials_init_string != NULL) {
78 const char* init_string = 79 const char* init_string =
79 jni->GetStringUTFChars(j_trials_init_string, NULL); 80 jni->GetStringUTFChars(j_trials_init_string, NULL);
80 int init_string_length = jni->GetStringUTFLength(j_trials_init_string); 81 int init_string_length = jni->GetStringUTFLength(j_trials_init_string);
81 field_trials_init_string = new char[init_string_length + 1]; 82 field_trials_init_string = new char[init_string_length + 1];
82 rtc::strcpyn(field_trials_init_string, init_string_length + 1, init_string); 83 rtc::strcpyn(field_trials_init_string, init_string_length + 1, init_string);
83 jni->ReleaseStringUTFChars(j_trials_init_string, init_string); 84 jni->ReleaseStringUTFChars(j_trials_init_string, init_string);
84 LOG(LS_INFO) << "initializeFieldTrials: " << field_trials_init_string; 85 LOG(LS_INFO) << "initializeFieldTrials: " << field_trials_init_string;
85 } 86 }
86 webrtc::field_trial::InitFieldTrialsFromString(field_trials_init_string); 87 field_trial::InitFieldTrialsFromString(field_trials_init_string);
87 } 88 }
88 89
89 JNI_FUNCTION_DECLARATION(void, 90 JNI_FUNCTION_DECLARATION(void,
90 PeerConnectionFactory_initializeInternalTracer, 91 PeerConnectionFactory_initializeInternalTracer,
91 JNIEnv* jni, 92 JNIEnv* jni,
92 jclass) { 93 jclass) {
93 rtc::tracing::SetupInternalTracer(); 94 rtc::tracing::SetupInternalTracer();
94 } 95 }
95 96
96 JNI_FUNCTION_DECLARATION(jstring, 97 JNI_FUNCTION_DECLARATION(jstring,
97 PeerConnectionFactory_nativeFieldTrialsFindFullName, 98 PeerConnectionFactory_nativeFieldTrialsFindFullName,
98 JNIEnv* jni, 99 JNIEnv* jni,
99 jclass, 100 jclass,
100 jstring j_name) { 101 jstring j_name) {
101 return JavaStringFromStdString( 102 return JavaStringFromStdString(
102 jni, webrtc::field_trial::FindFullName(JavaToStdString(jni, j_name))); 103 jni, field_trial::FindFullName(JavaToStdString(jni, j_name)));
103 } 104 }
104 105
105 JNI_FUNCTION_DECLARATION(jboolean, 106 JNI_FUNCTION_DECLARATION(jboolean,
106 PeerConnectionFactory_startInternalTracingCapture, 107 PeerConnectionFactory_startInternalTracingCapture,
107 JNIEnv* jni, 108 JNIEnv* jni,
108 jclass, 109 jclass,
109 jstring j_event_tracing_filename) { 110 jstring j_event_tracing_filename) {
110 if (!j_event_tracing_filename) 111 if (!j_event_tracing_filename)
111 return false; 112 return false;
112 113
(...skipping 26 matching lines...) Expand all
139 jclass, 140 jclass,
140 jobject joptions, 141 jobject joptions,
141 jobject jencoder_factory, 142 jobject jencoder_factory,
142 jobject jdecoder_factory) { 143 jobject jdecoder_factory) {
143 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but 144 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but
144 // ThreadManager only WrapCurrentThread()s the thread where it is first 145 // ThreadManager only WrapCurrentThread()s the thread where it is first
145 // created. Since the semantics around when auto-wrapping happens in 146 // created. Since the semantics around when auto-wrapping happens in
146 // webrtc/rtc_base/ are convoluted, we simply wrap here to avoid having to 147 // webrtc/rtc_base/ are convoluted, we simply wrap here to avoid having to
147 // think about ramifications of auto-wrapping there. 148 // think about ramifications of auto-wrapping there.
148 rtc::ThreadManager::Instance()->WrapCurrentThread(); 149 rtc::ThreadManager::Instance()->WrapCurrentThread();
149 webrtc::Trace::CreateTrace(); 150 Trace::CreateTrace();
150 151
151 std::unique_ptr<rtc::Thread> network_thread = 152 std::unique_ptr<rtc::Thread> network_thread =
152 rtc::Thread::CreateWithSocketServer(); 153 rtc::Thread::CreateWithSocketServer();
153 network_thread->SetName("network_thread", nullptr); 154 network_thread->SetName("network_thread", nullptr);
154 RTC_CHECK(network_thread->Start()) << "Failed to start thread"; 155 RTC_CHECK(network_thread->Start()) << "Failed to start thread";
155 156
156 std::unique_ptr<rtc::Thread> worker_thread = rtc::Thread::Create(); 157 std::unique_ptr<rtc::Thread> worker_thread = rtc::Thread::Create();
157 worker_thread->SetName("worker_thread", nullptr); 158 worker_thread->SetName("worker_thread", nullptr);
158 RTC_CHECK(worker_thread->Start()) << "Failed to start thread"; 159 RTC_CHECK(worker_thread->Start()) << "Failed to start thread";
159 160
160 std::unique_ptr<rtc::Thread> signaling_thread = rtc::Thread::Create(); 161 std::unique_ptr<rtc::Thread> signaling_thread = rtc::Thread::Create();
161 signaling_thread->SetName("signaling_thread", NULL); 162 signaling_thread->SetName("signaling_thread", NULL);
162 RTC_CHECK(signaling_thread->Start()) << "Failed to start thread"; 163 RTC_CHECK(signaling_thread->Start()) << "Failed to start thread";
163 164
164 cricket::WebRtcVideoEncoderFactory* video_encoder_factory = nullptr; 165 cricket::WebRtcVideoEncoderFactory* video_encoder_factory = nullptr;
165 cricket::WebRtcVideoDecoderFactory* video_decoder_factory = nullptr; 166 cricket::WebRtcVideoDecoderFactory* video_decoder_factory = nullptr;
166 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; 167 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
167 auto audio_encoder_factory = CreateAudioEncoderFactory(); 168 auto audio_encoder_factory = CreateAudioEncoderFactory();
168 auto audio_decoder_factory = CreateAudioDecoderFactory(); 169 auto audio_decoder_factory = CreateAudioDecoderFactory();
169 170
170 webrtc::PeerConnectionFactoryInterface::Options options; 171 PeerConnectionFactoryInterface::Options options;
171 bool has_options = joptions != NULL; 172 bool has_options = joptions != NULL;
172 if (has_options) { 173 if (has_options) {
173 options = JavaToNativePeerConnectionFactoryOptions(jni, joptions); 174 options = JavaToNativePeerConnectionFactoryOptions(jni, joptions);
174 } 175 }
175 176
176 if (video_hw_acceleration_enabled) { 177 if (video_hw_acceleration_enabled) {
177 video_encoder_factory = CreateVideoEncoderFactory(jni, jencoder_factory); 178 video_encoder_factory = CreateVideoEncoderFactory(jni, jencoder_factory);
178 video_decoder_factory = CreateVideoDecoderFactory(jni, jdecoder_factory); 179 video_decoder_factory = CreateVideoDecoderFactory(jni, jdecoder_factory);
179 } 180 }
180 // Do not create network_monitor_factory only if the options are 181 // Do not create network_monitor_factory only if the options are
181 // provided and disable_network_monitor therein is set to true. 182 // provided and disable_network_monitor therein is set to true.
182 if (!(has_options && options.disable_network_monitor)) { 183 if (!(has_options && options.disable_network_monitor)) {
183 network_monitor_factory = new AndroidNetworkMonitorFactory(); 184 network_monitor_factory = new AndroidNetworkMonitorFactory();
184 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); 185 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory);
185 } 186 }
186 187
187 webrtc::AudioDeviceModule* adm = nullptr; 188 AudioDeviceModule* adm = nullptr;
188 rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer = nullptr; 189 rtc::scoped_refptr<AudioMixer> audio_mixer = nullptr;
189 std::unique_ptr<webrtc::CallFactoryInterface> call_factory( 190 std::unique_ptr<CallFactoryInterface> call_factory(CreateCallFactory());
190 CreateCallFactory()); 191 std::unique_ptr<RtcEventLogFactoryInterface> rtc_event_log_factory(
191 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> rtc_event_log_factory(
192 CreateRtcEventLogFactory()); 192 CreateRtcEventLogFactory());
193 std::unique_ptr<cricket::MediaEngineInterface> media_engine(CreateMediaEngine( 193 std::unique_ptr<cricket::MediaEngineInterface> media_engine(CreateMediaEngine(
194 adm, audio_encoder_factory, audio_decoder_factory, video_encoder_factory, 194 adm, audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
195 video_decoder_factory, audio_mixer)); 195 video_decoder_factory, audio_mixer));
196 196
197 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 197 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
198 CreateModularPeerConnectionFactory( 198 CreateModularPeerConnectionFactory(
199 network_thread.get(), worker_thread.get(), signaling_thread.get(), 199 network_thread.get(), worker_thread.get(), signaling_thread.get(),
200 adm, audio_encoder_factory, audio_decoder_factory, 200 adm, audio_encoder_factory, audio_decoder_factory,
201 video_encoder_factory, video_decoder_factory, audio_mixer, 201 video_encoder_factory, video_decoder_factory, audio_mixer,
202 std::move(media_engine), std::move(call_factory), 202 std::move(media_engine), std::move(call_factory),
203 std::move(rtc_event_log_factory))); 203 std::move(rtc_event_log_factory)));
204 RTC_CHECK(factory) << "Failed to create the peer connection factory; " 204 RTC_CHECK(factory) << "Failed to create the peer connection factory; "
205 << "WebRTC/libjingle init likely failed on this device"; 205 << "WebRTC/libjingle init likely failed on this device";
206 // TODO(honghaiz): Maybe put the options as the argument of 206 // TODO(honghaiz): Maybe put the options as the argument of
207 // CreatePeerConnectionFactory. 207 // CreatePeerConnectionFactory.
208 if (has_options) { 208 if (has_options) {
209 factory->SetOptions(options); 209 factory->SetOptions(options);
210 } 210 }
211 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( 211 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
212 std::move(network_thread), std::move(worker_thread), 212 std::move(network_thread), std::move(worker_thread),
213 std::move(signaling_thread), video_encoder_factory, video_decoder_factory, 213 std::move(signaling_thread), video_encoder_factory, video_decoder_factory,
214 network_monitor_factory, factory.release()); 214 network_monitor_factory, factory.release());
215 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); 215 owned_factory->InvokeJavaCallbacksOnFactoryThreads();
216 return jlongFromPointer(owned_factory); 216 return jlongFromPointer(owned_factory);
217 } 217 }
218 218
219 JNI_FUNCTION_DECLARATION(void, 219 JNI_FUNCTION_DECLARATION(void,
220 PeerConnectionFactory_nativeFreeFactory, 220 PeerConnectionFactory_nativeFreeFactory,
221 JNIEnv*, 221 JNIEnv*,
222 jclass, 222 jclass,
223 jlong j_p) { 223 jlong j_p) {
224 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); 224 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p);
225 if (field_trials_init_string) { 225 if (field_trials_init_string) {
226 webrtc::field_trial::InitFieldTrialsFromString(NULL); 226 field_trial::InitFieldTrialsFromString(NULL);
227 delete field_trials_init_string; 227 delete field_trials_init_string;
228 field_trials_init_string = NULL; 228 field_trials_init_string = NULL;
229 } 229 }
230 webrtc::Trace::ReturnTrace(); 230 Trace::ReturnTrace();
231 } 231 }
232 232
233 JNI_FUNCTION_DECLARATION(void, 233 JNI_FUNCTION_DECLARATION(void,
234 PeerConnectionFactory_nativeThreadsCallbacks, 234 PeerConnectionFactory_nativeThreadsCallbacks,
235 JNIEnv*, 235 JNIEnv*,
236 jclass, 236 jclass,
237 jlong j_p) { 237 jlong j_p) {
238 OwnedFactoryAndThreads* factory = 238 OwnedFactoryAndThreads* factory =
239 reinterpret_cast<OwnedFactoryAndThreads*>(j_p); 239 reinterpret_cast<OwnedFactoryAndThreads*>(j_p);
240 factory->InvokeJavaCallbacksOnFactoryThreads(); 240 factory->InvokeJavaCallbacksOnFactoryThreads();
241 } 241 }
242 242
243 JNI_FUNCTION_DECLARATION(jlong, 243 JNI_FUNCTION_DECLARATION(jlong,
244 PeerConnectionFactory_nativeCreateLocalMediaStream, 244 PeerConnectionFactory_nativeCreateLocalMediaStream,
245 JNIEnv* jni, 245 JNIEnv* jni,
246 jclass, 246 jclass,
247 jlong native_factory, 247 jlong native_factory,
248 jstring label) { 248 jstring label) {
249 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 249 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
250 factoryFromJava(native_factory)); 250 factoryFromJava(native_factory));
251 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( 251 rtc::scoped_refptr<MediaStreamInterface> stream(
252 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); 252 factory->CreateLocalMediaStream(JavaToStdString(jni, label)));
253 return (jlong)stream.release(); 253 return (jlong)stream.release();
254 } 254 }
255 255
256 JNI_FUNCTION_DECLARATION(jlong, 256 JNI_FUNCTION_DECLARATION(jlong,
257 PeerConnectionFactory_nativeCreateAudioSource, 257 PeerConnectionFactory_nativeCreateAudioSource,
258 JNIEnv* jni, 258 JNIEnv* jni,
259 jclass, 259 jclass,
260 jlong native_factory, 260 jlong native_factory,
261 jobject j_constraints) { 261 jobject j_constraints) {
262 std::unique_ptr<MediaConstraintsJni> constraints( 262 std::unique_ptr<MediaConstraintsJni> constraints(
263 new MediaConstraintsJni(jni, j_constraints)); 263 new MediaConstraintsJni(jni, j_constraints));
264 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 264 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
265 factoryFromJava(native_factory)); 265 factoryFromJava(native_factory));
266 cricket::AudioOptions options; 266 cricket::AudioOptions options;
267 CopyConstraintsIntoAudioOptions(constraints.get(), &options); 267 CopyConstraintsIntoAudioOptions(constraints.get(), &options);
268 rtc::scoped_refptr<webrtc::AudioSourceInterface> source( 268 rtc::scoped_refptr<AudioSourceInterface> source(
269 factory->CreateAudioSource(options)); 269 factory->CreateAudioSource(options));
270 return (jlong)source.release(); 270 return (jlong)source.release();
271 } 271 }
272 272
273 JNI_FUNCTION_DECLARATION(jlong, 273 JNI_FUNCTION_DECLARATION(jlong,
274 PeerConnectionFactory_nativeCreateAudioTrack, 274 PeerConnectionFactory_nativeCreateAudioTrack,
275 JNIEnv* jni, 275 JNIEnv* jni,
276 jclass, 276 jclass,
277 jlong native_factory, 277 jlong native_factory,
278 jstring id, 278 jstring id,
279 jlong native_source) { 279 jlong native_source) {
280 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 280 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
281 factoryFromJava(native_factory)); 281 factoryFromJava(native_factory));
282 rtc::scoped_refptr<webrtc::AudioTrackInterface> track( 282 rtc::scoped_refptr<AudioTrackInterface> track(factory->CreateAudioTrack(
283 factory->CreateAudioTrack( 283 JavaToStdString(jni, id),
284 JavaToStdString(jni, id), 284 reinterpret_cast<AudioSourceInterface*>(native_source)));
285 reinterpret_cast<webrtc::AudioSourceInterface*>(native_source)));
286 return (jlong)track.release(); 285 return (jlong)track.release();
287 } 286 }
288 287
289 JNI_FUNCTION_DECLARATION(jboolean, 288 JNI_FUNCTION_DECLARATION(jboolean,
290 PeerConnectionFactory_nativeStartAecDump, 289 PeerConnectionFactory_nativeStartAecDump,
291 JNIEnv* jni, 290 JNIEnv* jni,
292 jclass, 291 jclass,
293 jlong native_factory, 292 jlong native_factory,
294 jint file, 293 jint file,
295 jint filesize_limit_bytes) { 294 jint filesize_limit_bytes) {
296 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 295 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
297 factoryFromJava(native_factory)); 296 factoryFromJava(native_factory));
298 return factory->StartAecDump(file, filesize_limit_bytes); 297 return factory->StartAecDump(file, filesize_limit_bytes);
299 } 298 }
300 299
301 JNI_FUNCTION_DECLARATION(void, 300 JNI_FUNCTION_DECLARATION(void,
302 PeerConnectionFactory_nativeStopAecDump, 301 PeerConnectionFactory_nativeStopAecDump,
303 JNIEnv* jni, 302 JNIEnv* jni,
304 jclass, 303 jclass,
305 jlong native_factory) { 304 jlong native_factory) {
306 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 305 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
307 factoryFromJava(native_factory)); 306 factoryFromJava(native_factory));
308 factory->StopAecDump(); 307 factory->StopAecDump();
309 } 308 }
310 309
311 JNI_FUNCTION_DECLARATION(void, 310 JNI_FUNCTION_DECLARATION(void,
312 PeerConnectionFactory_nativeSetOptions, 311 PeerConnectionFactory_nativeSetOptions,
313 JNIEnv* jni, 312 JNIEnv* jni,
314 jclass, 313 jclass,
315 jlong native_factory, 314 jlong native_factory,
316 jobject options) { 315 jobject options) {
317 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 316 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
318 factoryFromJava(native_factory)); 317 factoryFromJava(native_factory));
319 webrtc::PeerConnectionFactoryInterface::Options options_to_set = 318 PeerConnectionFactoryInterface::Options options_to_set =
320 JavaToNativePeerConnectionFactoryOptions(jni, options); 319 JavaToNativePeerConnectionFactoryOptions(jni, options);
321 factory->SetOptions(options_to_set); 320 factory->SetOptions(options_to_set);
322 321
323 if (options_to_set.disable_network_monitor) { 322 if (options_to_set.disable_network_monitor) {
324 OwnedFactoryAndThreads* owner = 323 OwnedFactoryAndThreads* owner =
325 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); 324 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory);
326 if (owner->network_monitor_factory()) { 325 if (owner->network_monitor_factory()) {
327 rtc::NetworkMonitorFactory::ReleaseFactory( 326 rtc::NetworkMonitorFactory::ReleaseFactory(
328 owner->network_monitor_factory()); 327 owner->network_monitor_factory());
329 owner->clear_network_monitor_factory(); 328 owner->clear_network_monitor_factory();
330 } 329 }
331 } 330 }
332 } 331 }
333 332
334 JNI_FUNCTION_DECLARATION(jlong, 333 JNI_FUNCTION_DECLARATION(jlong,
335 PeerConnectionFactory_nativeCreatePeerConnection, 334 PeerConnectionFactory_nativeCreatePeerConnection,
336 JNIEnv* jni, 335 JNIEnv* jni,
337 jclass, 336 jclass,
338 jlong factory, 337 jlong factory,
339 jobject j_rtc_config, 338 jobject j_rtc_config,
340 jobject j_constraints, 339 jobject j_constraints,
341 jlong observer_p) { 340 jlong observer_p) {
342 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> f( 341 rtc::scoped_refptr<PeerConnectionFactoryInterface> f(
343 reinterpret_cast<webrtc::PeerConnectionFactoryInterface*>( 342 reinterpret_cast<PeerConnectionFactoryInterface*>(
344 factoryFromJava(factory))); 343 factoryFromJava(factory)));
345 344
346 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config( 345 PeerConnectionInterface::RTCConfiguration rtc_config(
347 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive); 346 PeerConnectionInterface::RTCConfigurationType::kAggressive);
348 JavaToNativeRTCConfiguration(jni, j_rtc_config, &rtc_config); 347 JavaToNativeRTCConfiguration(jni, j_rtc_config, &rtc_config);
349 348
350 jclass j_rtc_config_class = GetObjectClass(jni, j_rtc_config); 349 jclass j_rtc_config_class = GetObjectClass(jni, j_rtc_config);
351 jfieldID j_key_type_id = GetFieldID(jni, j_rtc_config_class, "keyType", 350 jfieldID j_key_type_id = GetFieldID(jni, j_rtc_config_class, "keyType",
352 "Lorg/webrtc/PeerConnection$KeyType;"); 351 "Lorg/webrtc/PeerConnection$KeyType;");
353 jobject j_key_type = GetObjectField(jni, j_rtc_config, j_key_type_id); 352 jobject j_key_type = GetObjectField(jni, j_rtc_config, j_key_type_id);
354 353
355 // Generate non-default certificate. 354 // Generate non-default certificate.
356 rtc::KeyType key_type = JavaToNativeKeyType(jni, j_key_type); 355 rtc::KeyType key_type = JavaToNativeKeyType(jni, j_key_type);
357 if (key_type != rtc::KT_DEFAULT) { 356 if (key_type != rtc::KT_DEFAULT) {
358 rtc::scoped_refptr<rtc::RTCCertificate> certificate = 357 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
359 rtc::RTCCertificateGenerator::GenerateCertificate( 358 rtc::RTCCertificateGenerator::GenerateCertificate(
360 rtc::KeyParams(key_type), rtc::Optional<uint64_t>()); 359 rtc::KeyParams(key_type), rtc::Optional<uint64_t>());
361 if (!certificate) { 360 if (!certificate) {
362 LOG(LS_ERROR) << "Failed to generate certificate. KeyType: " << key_type; 361 LOG(LS_ERROR) << "Failed to generate certificate. KeyType: " << key_type;
363 return 0; 362 return 0;
364 } 363 }
365 rtc_config.certificates.push_back(certificate); 364 rtc_config.certificates.push_back(certificate);
366 } 365 }
367 366
368 PeerConnectionObserverJni* observer = 367 PeerConnectionObserverJni* observer =
369 reinterpret_cast<PeerConnectionObserverJni*>(observer_p); 368 reinterpret_cast<PeerConnectionObserverJni*>(observer_p);
370 observer->SetConstraints(new MediaConstraintsJni(jni, j_constraints)); 369 observer->SetConstraints(new MediaConstraintsJni(jni, j_constraints));
371 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config); 370 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config);
372 rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc( 371 rtc::scoped_refptr<PeerConnectionInterface> pc(
373 f->CreatePeerConnection(rtc_config, nullptr, nullptr, observer)); 372 f->CreatePeerConnection(rtc_config, nullptr, nullptr, observer));
374 return (jlong)pc.release(); 373 return (jlong)pc.release();
375 } 374 }
376 375
377 } // namespace webrtc_jni 376 } // namespace jni
377 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/pc/peerconnection_jni.cc ('k') | webrtc/sdk/android/src/jni/pc/peerconnectionobserver_jni.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698