OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 #include <jni.h> | 55 #include <jni.h> |
56 #undef JNIEXPORT | 56 #undef JNIEXPORT |
57 #define JNIEXPORT __attribute__((visibility("default"))) | 57 #define JNIEXPORT __attribute__((visibility("default"))) |
58 | 58 |
59 #include <limits> | 59 #include <limits> |
60 | 60 |
61 #include "talk/app/webrtc/java/jni/classreferenceholder.h" | 61 #include "talk/app/webrtc/java/jni/classreferenceholder.h" |
62 #include "talk/app/webrtc/java/jni/jni_helpers.h" | 62 #include "talk/app/webrtc/java/jni/jni_helpers.h" |
63 #include "talk/app/webrtc/java/jni/native_handle_impl.h" | 63 #include "talk/app/webrtc/java/jni/native_handle_impl.h" |
| 64 #include "talk/app/webrtc/dtlsidentitystore.h" |
64 #include "talk/app/webrtc/mediaconstraintsinterface.h" | 65 #include "talk/app/webrtc/mediaconstraintsinterface.h" |
65 #include "talk/app/webrtc/peerconnectioninterface.h" | 66 #include "talk/app/webrtc/peerconnectioninterface.h" |
66 #include "talk/app/webrtc/videosourceinterface.h" | 67 #include "talk/app/webrtc/videosourceinterface.h" |
67 #include "talk/media/base/videocapturer.h" | 68 #include "talk/media/base/videocapturer.h" |
68 #include "talk/media/base/videorenderer.h" | 69 #include "talk/media/base/videorenderer.h" |
69 #include "talk/media/devices/videorendererfactory.h" | 70 #include "talk/media/devices/videorendererfactory.h" |
70 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" | 71 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" |
71 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" | 72 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" |
72 #include "webrtc/base/bind.h" | 73 #include "webrtc/base/bind.h" |
73 #include "webrtc/base/checks.h" | 74 #include "webrtc/base/checks.h" |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 if (enum_name == "ENABLED") | 1267 if (enum_name == "ENABLED") |
1267 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; | 1268 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; |
1268 | 1269 |
1269 if (enum_name == "DISABLED") | 1270 if (enum_name == "DISABLED") |
1270 return PeerConnectionInterface::kTcpCandidatePolicyDisabled; | 1271 return PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
1271 | 1272 |
1272 CHECK(false) << "Unexpected TcpCandidatePolicy enum_name " << enum_name; | 1273 CHECK(false) << "Unexpected TcpCandidatePolicy enum_name " << enum_name; |
1273 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; | 1274 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; |
1274 } | 1275 } |
1275 | 1276 |
| 1277 static rtc::KeyType JavaKeyTypeToNativeType(JNIEnv* jni, jobject j_key_type) { |
| 1278 std::string enum_name = GetJavaEnumName( |
| 1279 jni, "org/webrtc/PeerConnection$KeyType", j_key_type); |
| 1280 |
| 1281 if (enum_name == "RSA") |
| 1282 return rtc::KT_RSA; |
| 1283 if (enum_name == "ECDSA") |
| 1284 return rtc::KT_ECDSA; |
| 1285 |
| 1286 CHECK(false) << "Unexpected KeyType enum_name " << enum_name; |
| 1287 return rtc::KT_ECDSA; |
| 1288 } |
| 1289 |
1276 static void JavaIceServersToJsepIceServers( | 1290 static void JavaIceServersToJsepIceServers( |
1277 JNIEnv* jni, jobject j_ice_servers, | 1291 JNIEnv* jni, jobject j_ice_servers, |
1278 PeerConnectionInterface::IceServers* ice_servers) { | 1292 PeerConnectionInterface::IceServers* ice_servers) { |
1279 jclass list_class = GetObjectClass(jni, j_ice_servers); | 1293 jclass list_class = GetObjectClass(jni, j_ice_servers); |
1280 jmethodID iterator_id = GetMethodID( | 1294 jmethodID iterator_id = GetMethodID( |
1281 jni, list_class, "iterator", "()Ljava/util/Iterator;"); | 1295 jni, list_class, "iterator", "()Ljava/util/Iterator;"); |
1282 jobject iterator = jni->CallObjectMethod(j_ice_servers, iterator_id); | 1296 jobject iterator = jni->CallObjectMethod(j_ice_servers, iterator_id); |
1283 CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; | 1297 CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; |
1284 jmethodID iterator_has_next = GetMethodID( | 1298 jmethodID iterator_has_next = GetMethodID( |
1285 jni, GetObjectClass(jni, iterator), "hasNext", "()Z"); | 1299 jni, GetObjectClass(jni, iterator), "hasNext", "()Z"); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 jobject j_rtcp_mux_policy = GetObjectField( | 1352 jobject j_rtcp_mux_policy = GetObjectField( |
1339 jni, j_rtc_config, j_rtcp_mux_policy_id); | 1353 jni, j_rtc_config, j_rtcp_mux_policy_id); |
1340 | 1354 |
1341 jfieldID j_tcp_candidate_policy_id = GetFieldID( | 1355 jfieldID j_tcp_candidate_policy_id = GetFieldID( |
1342 jni, j_rtc_config_class, "tcpCandidatePolicy", | 1356 jni, j_rtc_config_class, "tcpCandidatePolicy", |
1343 "Lorg/webrtc/PeerConnection$TcpCandidatePolicy;"); | 1357 "Lorg/webrtc/PeerConnection$TcpCandidatePolicy;"); |
1344 jobject j_tcp_candidate_policy = GetObjectField( | 1358 jobject j_tcp_candidate_policy = GetObjectField( |
1345 jni, j_rtc_config, j_tcp_candidate_policy_id); | 1359 jni, j_rtc_config, j_tcp_candidate_policy_id); |
1346 | 1360 |
1347 jfieldID j_ice_servers_id = GetFieldID( | 1361 jfieldID j_ice_servers_id = GetFieldID( |
1348 jni, j_rtc_config_class, "iceServers", | 1362 jni, j_rtc_config_class, "iceServers", "Ljava/util/List;"); |
1349 "Ljava/util/List;"); | |
1350 jobject j_ice_servers = GetObjectField(jni, j_rtc_config, j_ice_servers_id); | 1363 jobject j_ice_servers = GetObjectField(jni, j_rtc_config, j_ice_servers_id); |
1351 | 1364 |
1352 jfieldID j_audio_jitter_buffer_max_packets_id = | 1365 jfieldID j_audio_jitter_buffer_max_packets_id = |
1353 GetFieldID(jni, j_rtc_config_class, "audioJitterBufferMaxPackets", "I"); | 1366 GetFieldID(jni, j_rtc_config_class, "audioJitterBufferMaxPackets", "I"); |
1354 jfieldID j_audio_jitter_buffer_fast_accelerate_id = GetFieldID( | 1367 jfieldID j_audio_jitter_buffer_fast_accelerate_id = GetFieldID( |
1355 jni, j_rtc_config_class, "audioJitterBufferFastAccelerate", "Z"); | 1368 jni, j_rtc_config_class, "audioJitterBufferFastAccelerate", "Z"); |
1356 | 1369 |
1357 jfieldID j_ice_connection_receiving_timeout_id = | 1370 jfieldID j_ice_connection_receiving_timeout_id = |
1358 GetFieldID(jni, j_rtc_config_class, "iceConnectionReceivingTimeout", "I"); | 1371 GetFieldID(jni, j_rtc_config_class, "iceConnectionReceivingTimeout", "I"); |
1359 | 1372 |
| 1373 jfieldID j_key_type_id = GetFieldID(jni, j_rtc_config_class, "keyType", |
| 1374 "Lorg/webrtc/PeerConnection$KeyType;"); |
| 1375 jobject j_key_type = GetObjectField(jni, j_rtc_config, j_key_type_id); |
| 1376 |
1360 PeerConnectionInterface::RTCConfiguration rtc_config; | 1377 PeerConnectionInterface::RTCConfiguration rtc_config; |
1361 rtc_config.type = | 1378 rtc_config.type = |
1362 JavaIceTransportsTypeToNativeType(jni, j_ice_transports_type); | 1379 JavaIceTransportsTypeToNativeType(jni, j_ice_transports_type); |
1363 rtc_config.bundle_policy = JavaBundlePolicyToNativeType(jni, j_bundle_policy); | 1380 rtc_config.bundle_policy = JavaBundlePolicyToNativeType(jni, j_bundle_policy); |
1364 rtc_config.rtcp_mux_policy = | 1381 rtc_config.rtcp_mux_policy = |
1365 JavaRtcpMuxPolicyToNativeType(jni, j_rtcp_mux_policy); | 1382 JavaRtcpMuxPolicyToNativeType(jni, j_rtcp_mux_policy); |
1366 rtc_config.tcp_candidate_policy = | 1383 rtc_config.tcp_candidate_policy = |
1367 JavaTcpCandidatePolicyToNativeType(jni, j_tcp_candidate_policy); | 1384 JavaTcpCandidatePolicyToNativeType(jni, j_tcp_candidate_policy); |
1368 JavaIceServersToJsepIceServers(jni, j_ice_servers, &rtc_config.servers); | 1385 JavaIceServersToJsepIceServers(jni, j_ice_servers, &rtc_config.servers); |
1369 rtc_config.audio_jitter_buffer_max_packets = | 1386 rtc_config.audio_jitter_buffer_max_packets = |
1370 GetIntField(jni, j_rtc_config, j_audio_jitter_buffer_max_packets_id); | 1387 GetIntField(jni, j_rtc_config, j_audio_jitter_buffer_max_packets_id); |
1371 rtc_config.audio_jitter_buffer_fast_accelerate = GetBooleanField( | 1388 rtc_config.audio_jitter_buffer_fast_accelerate = GetBooleanField( |
1372 jni, j_rtc_config, j_audio_jitter_buffer_fast_accelerate_id); | 1389 jni, j_rtc_config, j_audio_jitter_buffer_fast_accelerate_id); |
1373 rtc_config.ice_connection_receiving_timeout = | 1390 rtc_config.ice_connection_receiving_timeout = |
1374 GetIntField(jni, j_rtc_config, j_ice_connection_receiving_timeout_id); | 1391 GetIntField(jni, j_rtc_config, j_ice_connection_receiving_timeout_id); |
1375 | 1392 |
| 1393 // Create ECDSA certificate. |
| 1394 if (JavaKeyTypeToNativeType(jni, j_key_type) == rtc::KT_ECDSA) { |
| 1395 scoped_ptr<rtc::SSLIdentity> ssl_identity( |
| 1396 rtc::SSLIdentity::Generate(webrtc::kIdentityName, rtc::KT_ECDSA)); |
| 1397 if (ssl_identity.get()) { |
| 1398 rtc_config.certificates.push_back( |
| 1399 rtc::RTCCertificate::Create(ssl_identity.Pass())); |
| 1400 LOG(LS_INFO) << "ECDSA certificate created."; |
| 1401 } else { |
| 1402 // Failing to create certificate should not abort peer connection |
| 1403 // creation. Instead default encryption (currently RSA) will be used. |
| 1404 LOG(LS_WARNING) << |
| 1405 "Failed to generate SSLIdentity. Default encryption will be used."; |
| 1406 } |
| 1407 } |
| 1408 |
1376 PCOJava* observer = reinterpret_cast<PCOJava*>(observer_p); | 1409 PCOJava* observer = reinterpret_cast<PCOJava*>(observer_p); |
1377 observer->SetConstraints(new ConstraintsWrapper(jni, j_constraints)); | 1410 observer->SetConstraints(new ConstraintsWrapper(jni, j_constraints)); |
1378 rtc::scoped_refptr<PeerConnectionInterface> pc(f->CreatePeerConnection( | 1411 rtc::scoped_refptr<PeerConnectionInterface> pc(f->CreatePeerConnection( |
1379 rtc_config, observer->constraints(), NULL, NULL, observer)); | 1412 rtc_config, observer->constraints(), NULL, NULL, observer)); |
1380 return (jlong)pc.release(); | 1413 return (jlong)pc.release(); |
1381 } | 1414 } |
1382 | 1415 |
1383 static rtc::scoped_refptr<PeerConnectionInterface> ExtractNativePC( | 1416 static rtc::scoped_refptr<PeerConnectionInterface> ExtractNativePC( |
1384 JNIEnv* jni, jobject j_pc) { | 1417 JNIEnv* jni, jobject j_pc) { |
1385 jfieldID native_pc_id = GetFieldID(jni, | 1418 jfieldID native_pc_id = GetFieldID(jni, |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 } | 1735 } |
1703 | 1736 |
1704 JOW(void, VideoTrack_nativeRemoveRenderer)( | 1737 JOW(void, VideoTrack_nativeRemoveRenderer)( |
1705 JNIEnv* jni, jclass, | 1738 JNIEnv* jni, jclass, |
1706 jlong j_video_track_pointer, jlong j_renderer_pointer) { | 1739 jlong j_video_track_pointer, jlong j_renderer_pointer) { |
1707 reinterpret_cast<VideoTrackInterface*>(j_video_track_pointer)->RemoveRenderer( | 1740 reinterpret_cast<VideoTrackInterface*>(j_video_track_pointer)->RemoveRenderer( |
1708 reinterpret_cast<VideoRendererInterface*>(j_renderer_pointer)); | 1741 reinterpret_cast<VideoRendererInterface*>(j_renderer_pointer)); |
1709 } | 1742 } |
1710 | 1743 |
1711 } // namespace webrtc_jni | 1744 } // namespace webrtc_jni |
OLD | NEW |