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

Side by Side Diff: webrtc/api/java/jni/peerconnection_jni.cc

Issue 1648813004: Remove candidates when doing continual gathering (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address Alex's comments Created 4 years, 9 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 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
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"
59 #include "webrtc/base/bind.h" 60 #include "webrtc/base/bind.h"
60 #include "webrtc/base/checks.h" 61 #include "webrtc/base/checks.h"
61 #include "webrtc/base/event_tracer.h" 62 #include "webrtc/base/event_tracer.h"
62 #include "webrtc/base/logging.h" 63 #include "webrtc/base/logging.h"
63 #include "webrtc/base/logsinks.h" 64 #include "webrtc/base/logsinks.h"
64 #include "webrtc/base/messagequeue.h" 65 #include "webrtc/base/messagequeue.h"
65 #include "webrtc/base/networkmonitor.h" 66 #include "webrtc/base/networkmonitor.h"
66 #include "webrtc/base/ssladapter.h" 67 #include "webrtc/base/ssladapter.h"
67 #include "webrtc/base/stringutils.h" 68 #include "webrtc/base/stringutils.h"
68 #include "webrtc/media/base/videocapturer.h" 69 #include "webrtc/media/base/videocapturer.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 189
189 void OnIceCandidate(const IceCandidateInterface* candidate) override { 190 void OnIceCandidate(const IceCandidateInterface* candidate) override {
190 ScopedLocalRefFrame local_ref_frame(jni()); 191 ScopedLocalRefFrame local_ref_frame(jni());
191 std::string sdp; 192 std::string sdp;
192 RTC_CHECK(candidate->ToString(&sdp)) << "got so far: " << sdp; 193 RTC_CHECK(candidate->ToString(&sdp)) << "got so far: " << sdp;
193 jclass candidate_class = FindClass(jni(), "org/webrtc/IceCandidate"); 194 jclass candidate_class = FindClass(jni(), "org/webrtc/IceCandidate");
194 jmethodID ctor = GetMethodID(jni(), candidate_class, 195 jmethodID ctor = GetMethodID(jni(), candidate_class,
195 "<init>", "(Ljava/lang/String;ILjava/lang/String;)V"); 196 "<init>", "(Ljava/lang/String;ILjava/lang/String;)V");
196 jstring j_mid = JavaStringFromStdString(jni(), candidate->sdp_mid()); 197 jstring j_mid = JavaStringFromStdString(jni(), candidate->sdp_mid());
197 jstring j_sdp = JavaStringFromStdString(jni(), sdp); 198 jstring j_sdp = JavaStringFromStdString(jni(), sdp);
198 jobject j_candidate = jni()->NewObject( 199 jobject j_candidate = jni()->NewObject(candidate_class, ctor, j_mid,
199 candidate_class, ctor, j_mid, candidate->sdp_mline_index(), j_sdp); 200 candidate->sdp_mline_index(), j_sdp);
200 CHECK_EXCEPTION(jni()) << "error during NewObject"; 201 CHECK_EXCEPTION(jni()) << "error during NewObject";
201 jmethodID m = GetMethodID(jni(), *j_observer_class_, 202 jmethodID m = GetMethodID(jni(), *j_observer_class_,
202 "onIceCandidate", "(Lorg/webrtc/IceCandidate;)V"); 203 "onIceCandidate", "(Lorg/webrtc/IceCandidate;)V");
203 jni()->CallVoidMethod(*j_observer_global_, m, j_candidate); 204 jni()->CallVoidMethod(*j_observer_global_, m, j_candidate);
204 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; 205 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
205 } 206 }
206 207
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
207 void OnSignalingChange( 219 void OnSignalingChange(
208 PeerConnectionInterface::SignalingState new_state) override { 220 PeerConnectionInterface::SignalingState new_state) override {
209 ScopedLocalRefFrame local_ref_frame(jni()); 221 ScopedLocalRefFrame local_ref_frame(jni());
210 jmethodID m = GetMethodID( 222 jmethodID m = GetMethodID(
211 jni(), *j_observer_class_, "onSignalingChange", 223 jni(), *j_observer_class_, "onSignalingChange",
212 "(Lorg/webrtc/PeerConnection$SignalingState;)V"); 224 "(Lorg/webrtc/PeerConnection$SignalingState;)V");
213 jobject new_state_enum = 225 jobject new_state_enum =
214 JavaEnumFromIndex(jni(), "PeerConnection$SignalingState", new_state); 226 JavaEnumFromIndex(jni(), "PeerConnection$SignalingState", new_state);
215 jni()->CallVoidMethod(*j_observer_global_, m, new_state_enum); 227 jni()->CallVoidMethod(*j_observer_global_, m, new_state_enum);
216 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; 228 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 376
365 void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it) { 377 void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it) {
366 jobject j_stream = it->second; 378 jobject j_stream = it->second;
367 remote_streams_.erase(it); 379 remote_streams_.erase(it);
368 jni()->CallVoidMethod( 380 jni()->CallVoidMethod(
369 j_stream, GetMethodID(jni(), *j_media_stream_class_, "dispose", "()V")); 381 j_stream, GetMethodID(jni(), *j_media_stream_class_, "dispose", "()V"));
370 CHECK_EXCEPTION(jni()) << "error during MediaStream.dispose()"; 382 CHECK_EXCEPTION(jni()) << "error during MediaStream.dispose()";
371 DeleteGlobalRef(jni(), j_stream); 383 DeleteGlobalRef(jni(), j_stream);
372 } 384 }
373 385
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
374 JNIEnv* jni() { 416 JNIEnv* jni() {
375 return AttachCurrentThreadIfNeeded(); 417 return AttachCurrentThreadIfNeeded();
376 } 418 }
377 419
378 const ScopedGlobalRef<jobject> j_observer_global_; 420 const ScopedGlobalRef<jobject> j_observer_global_;
379 const ScopedGlobalRef<jclass> j_observer_class_; 421 const ScopedGlobalRef<jclass> j_observer_class_;
380 const ScopedGlobalRef<jclass> j_media_stream_class_; 422 const ScopedGlobalRef<jclass> j_media_stream_class_;
381 const jmethodID j_media_stream_ctor_; 423 const jmethodID j_media_stream_ctor_;
382 const ScopedGlobalRef<jclass> j_audio_track_class_; 424 const ScopedGlobalRef<jclass> j_audio_track_class_;
383 const jmethodID j_audio_track_ctor_; 425 const jmethodID j_audio_track_ctor_;
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 JOW(jboolean, PeerConnection_nativeAddIceCandidate)( 1758 JOW(jboolean, PeerConnection_nativeAddIceCandidate)(
1717 JNIEnv* jni, jobject j_pc, jstring j_sdp_mid, 1759 JNIEnv* jni, jobject j_pc, jstring j_sdp_mid,
1718 jint j_sdp_mline_index, jstring j_candidate_sdp) { 1760 jint j_sdp_mline_index, jstring j_candidate_sdp) {
1719 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid); 1761 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid);
1720 std::string sdp = JavaToStdString(jni, j_candidate_sdp); 1762 std::string sdp = JavaToStdString(jni, j_candidate_sdp);
1721 scoped_ptr<IceCandidateInterface> candidate( 1763 scoped_ptr<IceCandidateInterface> candidate(
1722 webrtc::CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, NULL)); 1764 webrtc::CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, NULL));
1723 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get()); 1765 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get());
1724 } 1766 }
1725 1767
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
1726 JOW(jboolean, PeerConnection_nativeAddLocalStream)( 1797 JOW(jboolean, PeerConnection_nativeAddLocalStream)(
1727 JNIEnv* jni, jobject j_pc, jlong native_stream) { 1798 JNIEnv* jni, jobject j_pc, jlong native_stream) {
1728 return ExtractNativePC(jni, j_pc)->AddStream( 1799 return ExtractNativePC(jni, j_pc)->AddStream(
1729 reinterpret_cast<MediaStreamInterface*>(native_stream)); 1800 reinterpret_cast<MediaStreamInterface*>(native_stream));
1730 } 1801 }
1731 1802
1732 JOW(void, PeerConnection_nativeRemoveLocalStream)( 1803 JOW(void, PeerConnection_nativeRemoveLocalStream)(
1733 JNIEnv* jni, jobject j_pc, jlong native_stream) { 1804 JNIEnv* jni, jobject j_pc, jlong native_stream) {
1734 ExtractNativePC(jni, j_pc)->RemoveStream( 1805 ExtractNativePC(jni, j_pc)->RemoveStream(
1735 reinterpret_cast<MediaStreamInterface*>(native_stream)); 1806 reinterpret_cast<MediaStreamInterface*>(native_stream));
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 return JavaStringFromStdString( 2109 return JavaStringFromStdString(
2039 jni, 2110 jni,
2040 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); 2111 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id());
2041 } 2112 }
2042 2113
2043 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { 2114 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) {
2044 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); 2115 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release();
2045 } 2116 }
2046 2117
2047 } // namespace webrtc_jni 2118 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/api/androidtests/src/org/webrtc/PeerConnectionTest.java ('k') | webrtc/api/java/src/org/webrtc/PeerConnection.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698