OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "webrtc/api/java/jni/androidnetworkmonitor_jni.h" | 49 #include "webrtc/api/java/jni/androidnetworkmonitor_jni.h" |
50 #include "webrtc/api/java/jni/androidvideocapturer_jni.h" | 50 #include "webrtc/api/java/jni/androidvideocapturer_jni.h" |
51 #include "webrtc/api/java/jni/classreferenceholder.h" | 51 #include "webrtc/api/java/jni/classreferenceholder.h" |
52 #include "webrtc/api/java/jni/jni_helpers.h" | 52 #include "webrtc/api/java/jni/jni_helpers.h" |
53 #include "webrtc/api/java/jni/native_handle_impl.h" | 53 #include "webrtc/api/java/jni/native_handle_impl.h" |
54 #include "webrtc/api/mediaconstraintsinterface.h" | 54 #include "webrtc/api/mediaconstraintsinterface.h" |
55 #include "webrtc/api/peerconnectioninterface.h" | 55 #include "webrtc/api/peerconnectioninterface.h" |
56 #include "webrtc/api/rtpreceiverinterface.h" | 56 #include "webrtc/api/rtpreceiverinterface.h" |
57 #include "webrtc/api/rtpsenderinterface.h" | 57 #include "webrtc/api/rtpsenderinterface.h" |
58 #include "webrtc/api/videosourceinterface.h" | 58 #include "webrtc/api/videosourceinterface.h" |
59 #include "webrtc/api/webrtcsdp.h" | |
60 #include "webrtc/base/bind.h" | 59 #include "webrtc/base/bind.h" |
61 #include "webrtc/base/checks.h" | 60 #include "webrtc/base/checks.h" |
62 #include "webrtc/base/event_tracer.h" | 61 #include "webrtc/base/event_tracer.h" |
63 #include "webrtc/base/logging.h" | 62 #include "webrtc/base/logging.h" |
64 #include "webrtc/base/logsinks.h" | 63 #include "webrtc/base/logsinks.h" |
65 #include "webrtc/base/messagequeue.h" | 64 #include "webrtc/base/messagequeue.h" |
66 #include "webrtc/base/networkmonitor.h" | 65 #include "webrtc/base/networkmonitor.h" |
67 #include "webrtc/base/ssladapter.h" | 66 #include "webrtc/base/ssladapter.h" |
68 #include "webrtc/base/stringutils.h" | 67 #include "webrtc/base/stringutils.h" |
69 #include "webrtc/media/base/videocapturer.h" | 68 #include "webrtc/media/base/videocapturer.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 188 |
190 void OnIceCandidate(const IceCandidateInterface* candidate) override { | 189 void OnIceCandidate(const IceCandidateInterface* candidate) override { |
191 ScopedLocalRefFrame local_ref_frame(jni()); | 190 ScopedLocalRefFrame local_ref_frame(jni()); |
192 std::string sdp; | 191 std::string sdp; |
193 RTC_CHECK(candidate->ToString(&sdp)) << "got so far: " << sdp; | 192 RTC_CHECK(candidate->ToString(&sdp)) << "got so far: " << sdp; |
194 jclass candidate_class = FindClass(jni(), "org/webrtc/IceCandidate"); | 193 jclass candidate_class = FindClass(jni(), "org/webrtc/IceCandidate"); |
195 jmethodID ctor = GetMethodID(jni(), candidate_class, | 194 jmethodID ctor = GetMethodID(jni(), candidate_class, |
196 "<init>", "(Ljava/lang/String;ILjava/lang/String;)V"); | 195 "<init>", "(Ljava/lang/String;ILjava/lang/String;)V"); |
197 jstring j_mid = JavaStringFromStdString(jni(), candidate->sdp_mid()); | 196 jstring j_mid = JavaStringFromStdString(jni(), candidate->sdp_mid()); |
198 jstring j_sdp = JavaStringFromStdString(jni(), sdp); | 197 jstring j_sdp = JavaStringFromStdString(jni(), sdp); |
199 jobject j_candidate = jni()->NewObject(candidate_class, ctor, j_mid, | 198 jobject j_candidate = jni()->NewObject( |
200 candidate->sdp_mline_index(), j_sdp); | 199 candidate_class, ctor, j_mid, candidate->sdp_mline_index(), j_sdp); |
201 CHECK_EXCEPTION(jni()) << "error during NewObject"; | 200 CHECK_EXCEPTION(jni()) << "error during NewObject"; |
202 jmethodID m = GetMethodID(jni(), *j_observer_class_, | 201 jmethodID m = GetMethodID(jni(), *j_observer_class_, |
203 "onIceCandidate", "(Lorg/webrtc/IceCandidate;)V"); | 202 "onIceCandidate", "(Lorg/webrtc/IceCandidate;)V"); |
204 jni()->CallVoidMethod(*j_observer_global_, m, j_candidate); | 203 jni()->CallVoidMethod(*j_observer_global_, m, j_candidate); |
205 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 204 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
206 } | 205 } |
207 | 206 |
208 void OnIceCandidatesRemoved( | |
209 const std::vector<cricket::Candidate>& candidates) { | |
210 ScopedLocalRefFrame local_ref_frame(jni()); | |
211 jobjectArray candidates_array = ToJavaCandidateArray(jni(), candidates); | |
212 jmethodID m = | |
213 GetMethodID(jni(), *j_observer_class_, "onIceCandidatesRemoved", | |
214 "([Lorg/webrtc/IceCandidate;)V"); | |
215 jni()->CallVoidMethod(*j_observer_global_, m, candidates_array); | |
216 CHECK_EXCEPTION(jni()) << "Error during CallVoidMethod"; | |
217 } | |
218 | |
219 void OnSignalingChange( | 207 void OnSignalingChange( |
220 PeerConnectionInterface::SignalingState new_state) override { | 208 PeerConnectionInterface::SignalingState new_state) override { |
221 ScopedLocalRefFrame local_ref_frame(jni()); | 209 ScopedLocalRefFrame local_ref_frame(jni()); |
222 jmethodID m = GetMethodID( | 210 jmethodID m = GetMethodID( |
223 jni(), *j_observer_class_, "onSignalingChange", | 211 jni(), *j_observer_class_, "onSignalingChange", |
224 "(Lorg/webrtc/PeerConnection$SignalingState;)V"); | 212 "(Lorg/webrtc/PeerConnection$SignalingState;)V"); |
225 jobject new_state_enum = | 213 jobject new_state_enum = |
226 JavaEnumFromIndex(jni(), "PeerConnection$SignalingState", new_state); | 214 JavaEnumFromIndex(jni(), "PeerConnection$SignalingState", new_state); |
227 jni()->CallVoidMethod(*j_observer_global_, m, new_state_enum); | 215 jni()->CallVoidMethod(*j_observer_global_, m, new_state_enum); |
228 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 216 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 364 |
377 void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it) { | 365 void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it) { |
378 jobject j_stream = it->second; | 366 jobject j_stream = it->second; |
379 remote_streams_.erase(it); | 367 remote_streams_.erase(it); |
380 jni()->CallVoidMethod( | 368 jni()->CallVoidMethod( |
381 j_stream, GetMethodID(jni(), *j_media_stream_class_, "dispose", "()V")); | 369 j_stream, GetMethodID(jni(), *j_media_stream_class_, "dispose", "()V")); |
382 CHECK_EXCEPTION(jni()) << "error during MediaStream.dispose()"; | 370 CHECK_EXCEPTION(jni()) << "error during MediaStream.dispose()"; |
383 DeleteGlobalRef(jni(), j_stream); | 371 DeleteGlobalRef(jni(), j_stream); |
384 } | 372 } |
385 | 373 |
386 jobject ToJavaCandidate(JNIEnv* jni, | |
387 jclass* candidate_class, | |
388 const cricket::Candidate& candidate) { | |
389 std::string sdp = webrtc::SdpSerializeCandidate(candidate); | |
390 RTC_CHECK(!sdp.empty()) << "got an empty ICE candidate"; | |
391 jmethodID ctor = GetMethodID(jni, *candidate_class, "<init>", | |
392 "(Ljava/lang/String;ILjava/lang/String;)V"); | |
393 jstring j_mid = JavaStringFromStdString(jni, candidate.transport_name()); | |
394 jstring j_sdp = JavaStringFromStdString(jni, sdp); | |
395 // sdp_mline_index is not used, pass an invalid value -1. | |
396 jobject j_candidate = | |
397 jni->NewObject(*candidate_class, ctor, j_mid, -1, j_sdp); | |
398 CHECK_EXCEPTION(jni) << "error during Java Candidate NewObject"; | |
399 return j_candidate; | |
400 } | |
401 | |
402 jobjectArray ToJavaCandidateArray( | |
403 JNIEnv* jni, | |
404 const std::vector<cricket::Candidate>& candidates) { | |
405 jclass candidate_class = FindClass(jni, "org/webrtc/IceCandidate"); | |
406 jobjectArray java_candidates = | |
407 jni->NewObjectArray(candidates.size(), candidate_class, NULL); | |
408 int i = 0; | |
409 for (const cricket::Candidate& candidate : candidates) { | |
410 jobject j_candidate = ToJavaCandidate(jni, &candidate_class, candidate); | |
411 jni->SetObjectArrayElement(java_candidates, i++, j_candidate); | |
412 } | |
413 return java_candidates; | |
414 } | |
415 | |
416 JNIEnv* jni() { | 374 JNIEnv* jni() { |
417 return AttachCurrentThreadIfNeeded(); | 375 return AttachCurrentThreadIfNeeded(); |
418 } | 376 } |
419 | 377 |
420 const ScopedGlobalRef<jobject> j_observer_global_; | 378 const ScopedGlobalRef<jobject> j_observer_global_; |
421 const ScopedGlobalRef<jclass> j_observer_class_; | 379 const ScopedGlobalRef<jclass> j_observer_class_; |
422 const ScopedGlobalRef<jclass> j_media_stream_class_; | 380 const ScopedGlobalRef<jclass> j_media_stream_class_; |
423 const jmethodID j_media_stream_ctor_; | 381 const jmethodID j_media_stream_ctor_; |
424 const ScopedGlobalRef<jclass> j_audio_track_class_; | 382 const ScopedGlobalRef<jclass> j_audio_track_class_; |
425 const jmethodID j_audio_track_ctor_; | 383 const jmethodID j_audio_track_ctor_; |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 JOW(jboolean, PeerConnection_nativeAddIceCandidate)( | 1716 JOW(jboolean, PeerConnection_nativeAddIceCandidate)( |
1759 JNIEnv* jni, jobject j_pc, jstring j_sdp_mid, | 1717 JNIEnv* jni, jobject j_pc, jstring j_sdp_mid, |
1760 jint j_sdp_mline_index, jstring j_candidate_sdp) { | 1718 jint j_sdp_mline_index, jstring j_candidate_sdp) { |
1761 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid); | 1719 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid); |
1762 std::string sdp = JavaToStdString(jni, j_candidate_sdp); | 1720 std::string sdp = JavaToStdString(jni, j_candidate_sdp); |
1763 scoped_ptr<IceCandidateInterface> candidate( | 1721 scoped_ptr<IceCandidateInterface> candidate( |
1764 webrtc::CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, NULL)); | 1722 webrtc::CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, NULL)); |
1765 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get()); | 1723 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get()); |
1766 } | 1724 } |
1767 | 1725 |
1768 static cricket::Candidate GetCandidateFromJava(JNIEnv* jni, | |
1769 jobject j_candidate) { | |
1770 jclass j_candidate_class = GetObjectClass(jni, j_candidate); | |
1771 jfieldID j_sdp_mid_id = | |
1772 GetFieldID(jni, j_candidate_class, "sdpMid", "Ljava/lang/String;"); | |
1773 std::string sdp_mid = | |
1774 JavaToStdString(jni, GetStringField(jni, j_candidate, j_sdp_mid_id)); | |
1775 jfieldID j_sdp_id = | |
1776 GetFieldID(jni, j_candidate_class, "sdp", "Ljava/lang/String;"); | |
1777 std::string sdp = | |
1778 JavaToStdString(jni, GetStringField(jni, j_candidate, j_sdp_id)); | |
1779 cricket::Candidate candidate; | |
1780 if (!webrtc::SdpDeserializeCandidate(sdp_mid, sdp, &candidate, NULL)) { | |
1781 LOG(LS_ERROR) << "SdpDescrializeCandidate failed with sdp " << sdp; | |
1782 } | |
1783 return candidate; | |
1784 } | |
1785 | |
1786 JOW(jboolean, PeerConnection_nativeRemoveIceCandidates) | |
1787 (JNIEnv* jni, jobject j_pc, jobjectArray j_candidates) { | |
1788 std::vector<cricket::Candidate> candidates; | |
1789 size_t num_candidates = jni->GetArrayLength(j_candidates); | |
1790 for (size_t i = 0; i < num_candidates; ++i) { | |
1791 jobject j_candidate = jni->GetObjectArrayElement(j_candidates, i); | |
1792 candidates.push_back(GetCandidateFromJava(jni, j_candidate)); | |
1793 } | |
1794 return ExtractNativePC(jni, j_pc)->RemoveIceCandidates(candidates); | |
1795 } | |
1796 | |
1797 JOW(jboolean, PeerConnection_nativeAddLocalStream)( | 1726 JOW(jboolean, PeerConnection_nativeAddLocalStream)( |
1798 JNIEnv* jni, jobject j_pc, jlong native_stream) { | 1727 JNIEnv* jni, jobject j_pc, jlong native_stream) { |
1799 return ExtractNativePC(jni, j_pc)->AddStream( | 1728 return ExtractNativePC(jni, j_pc)->AddStream( |
1800 reinterpret_cast<MediaStreamInterface*>(native_stream)); | 1729 reinterpret_cast<MediaStreamInterface*>(native_stream)); |
1801 } | 1730 } |
1802 | 1731 |
1803 JOW(void, PeerConnection_nativeRemoveLocalStream)( | 1732 JOW(void, PeerConnection_nativeRemoveLocalStream)( |
1804 JNIEnv* jni, jobject j_pc, jlong native_stream) { | 1733 JNIEnv* jni, jobject j_pc, jlong native_stream) { |
1805 ExtractNativePC(jni, j_pc)->RemoveStream( | 1734 ExtractNativePC(jni, j_pc)->RemoveStream( |
1806 reinterpret_cast<MediaStreamInterface*>(native_stream)); | 1735 reinterpret_cast<MediaStreamInterface*>(native_stream)); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2109 return JavaStringFromStdString( | 2038 return JavaStringFromStdString( |
2110 jni, | 2039 jni, |
2111 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); | 2040 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); |
2112 } | 2041 } |
2113 | 2042 |
2114 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { | 2043 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { |
2115 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); | 2044 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); |
2116 } | 2045 } |
2117 | 2046 |
2118 } // namespace webrtc_jni | 2047 } // namespace webrtc_jni |
OLD | NEW |