addIceCandidate with callback into Android's SDK.
Bug: webrtc:12609 Change-Id: I059a246f5ade201b6a8decac264a8dd79fef3f9a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212740 Commit-Queue: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Xavier Lepaul <xalep@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33681}
This commit is contained in:
committed by
Commit Bot
parent
f075917cb0
commit
1cdeb0a56e
@ -36,6 +36,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.appspot.apprtc.AppRTCClient.SignalingParameters;
|
import org.appspot.apprtc.AppRTCClient.SignalingParameters;
|
||||||
import org.appspot.apprtc.RecordedAudioToFileController;
|
import org.appspot.apprtc.RecordedAudioToFileController;
|
||||||
|
import org.webrtc.AddIceObserver;
|
||||||
import org.webrtc.AudioSource;
|
import org.webrtc.AudioSource;
|
||||||
import org.webrtc.AudioTrack;
|
import org.webrtc.AudioTrack;
|
||||||
import org.webrtc.CameraVideoCapturer;
|
import org.webrtc.CameraVideoCapturer;
|
||||||
@ -824,7 +825,16 @@ public class PeerConnectionClient {
|
|||||||
if (queuedRemoteCandidates != null) {
|
if (queuedRemoteCandidates != null) {
|
||||||
queuedRemoteCandidates.add(candidate);
|
queuedRemoteCandidates.add(candidate);
|
||||||
} else {
|
} else {
|
||||||
peerConnection.addIceCandidate(candidate);
|
peerConnection.addIceCandidate(candidate, new AddIceObserver() {
|
||||||
|
@Override
|
||||||
|
public void onAddSuccess() {
|
||||||
|
Log.d(TAG, "Candidate " + candidate + " successfully added.");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onAddFailure(String error) {
|
||||||
|
Log.d(TAG, "Candidate " + candidate + " addition failed: " + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1146,7 +1156,16 @@ public class PeerConnectionClient {
|
|||||||
if (queuedRemoteCandidates != null) {
|
if (queuedRemoteCandidates != null) {
|
||||||
Log.d(TAG, "Add " + queuedRemoteCandidates.size() + " remote candidates");
|
Log.d(TAG, "Add " + queuedRemoteCandidates.size() + " remote candidates");
|
||||||
for (IceCandidate candidate : queuedRemoteCandidates) {
|
for (IceCandidate candidate : queuedRemoteCandidates) {
|
||||||
peerConnection.addIceCandidate(candidate);
|
peerConnection.addIceCandidate(candidate, new AddIceObserver() {
|
||||||
|
@Override
|
||||||
|
public void onAddSuccess() {
|
||||||
|
Log.d(TAG, "Candidate " + candidate + " successfully added.");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onAddFailure(String error) {
|
||||||
|
Log.d(TAG, "Candidate " + candidate + " addition failed: " + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
queuedRemoteCandidates = null;
|
queuedRemoteCandidates = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -262,6 +262,7 @@ if (is_android) {
|
|||||||
rtc_android_library("peerconnection_java") {
|
rtc_android_library("peerconnection_java") {
|
||||||
visibility = [ "*" ]
|
visibility = [ "*" ]
|
||||||
sources = [
|
sources = [
|
||||||
|
"api/org/webrtc/AddIceObserver.java",
|
||||||
"api/org/webrtc/AudioProcessingFactory.java",
|
"api/org/webrtc/AudioProcessingFactory.java",
|
||||||
"api/org/webrtc/AudioSource.java",
|
"api/org/webrtc/AudioSource.java",
|
||||||
"api/org/webrtc/AudioTrack.java",
|
"api/org/webrtc/AudioTrack.java",
|
||||||
@ -692,6 +693,8 @@ if (current_os == "linux" || is_android) {
|
|||||||
visibility = [ "*" ]
|
visibility = [ "*" ]
|
||||||
|
|
||||||
sources = [
|
sources = [
|
||||||
|
"src/jni/pc/add_ice_candidate_observer.cc",
|
||||||
|
"src/jni/pc/add_ice_candidate_observer.h",
|
||||||
"src/jni/pc/android_network_monitor.h",
|
"src/jni/pc/android_network_monitor.h",
|
||||||
"src/jni/pc/audio_track.cc",
|
"src/jni/pc/audio_track.cc",
|
||||||
"src/jni/pc/call_session_file_rotating_log_sink.cc",
|
"src/jni/pc/call_session_file_rotating_log_sink.cc",
|
||||||
@ -1264,6 +1267,7 @@ if (current_os == "linux" || is_android) {
|
|||||||
|
|
||||||
generate_jni("generated_peerconnection_jni") {
|
generate_jni("generated_peerconnection_jni") {
|
||||||
sources = [
|
sources = [
|
||||||
|
"api/org/webrtc/AddIceObserver.java",
|
||||||
"api/org/webrtc/AudioTrack.java",
|
"api/org/webrtc/AudioTrack.java",
|
||||||
"api/org/webrtc/CallSessionFileRotatingLogSink.java",
|
"api/org/webrtc/CallSessionFileRotatingLogSink.java",
|
||||||
"api/org/webrtc/CandidatePairChangeEvent.java",
|
"api/org/webrtc/CandidatePairChangeEvent.java",
|
||||||
|
|||||||
20
sdk/android/api/org/webrtc/AddIceObserver.java
Normal file
20
sdk/android/api/org/webrtc/AddIceObserver.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.webrtc;
|
||||||
|
|
||||||
|
/** Interface to handle completion of addIceCandidate */
|
||||||
|
public interface AddIceObserver {
|
||||||
|
/** Called when ICE candidate added successfully.*/
|
||||||
|
@CalledByNative public void onAddSuccess();
|
||||||
|
|
||||||
|
/** Called when ICE candidate addition failed.*/
|
||||||
|
@CalledByNative public void onAddFailure(String error);
|
||||||
|
}
|
||||||
@ -932,6 +932,11 @@ public class PeerConnection {
|
|||||||
return nativeAddIceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp);
|
return nativeAddIceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addIceCandidate(IceCandidate candidate, AddIceObserver observer) {
|
||||||
|
nativeAddIceCandidateWithObserver(
|
||||||
|
candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp, observer);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean removeIceCandidates(final IceCandidate[] candidates) {
|
public boolean removeIceCandidates(final IceCandidate[] candidates) {
|
||||||
return nativeRemoveIceCandidates(candidates);
|
return nativeRemoveIceCandidates(candidates);
|
||||||
}
|
}
|
||||||
@ -1293,6 +1298,8 @@ public class PeerConnection {
|
|||||||
private native boolean nativeSetConfiguration(RTCConfiguration config);
|
private native boolean nativeSetConfiguration(RTCConfiguration config);
|
||||||
private native boolean nativeAddIceCandidate(
|
private native boolean nativeAddIceCandidate(
|
||||||
String sdpMid, int sdpMLineIndex, String iceCandidateSdp);
|
String sdpMid, int sdpMLineIndex, String iceCandidateSdp);
|
||||||
|
private native void nativeAddIceCandidateWithObserver(
|
||||||
|
String sdpMid, int sdpMLineIndex, String iceCandidateSdp, AddIceObserver observer);
|
||||||
private native boolean nativeRemoveIceCandidates(final IceCandidate[] candidates);
|
private native boolean nativeRemoveIceCandidates(final IceCandidate[] candidates);
|
||||||
private native boolean nativeAddLocalStream(long stream);
|
private native boolean nativeAddLocalStream(long stream);
|
||||||
private native void nativeRemoveLocalStream(long stream);
|
private native void nativeRemoveLocalStream(long stream);
|
||||||
|
|||||||
39
sdk/android/src/jni/pc/add_ice_candidate_observer.cc
Normal file
39
sdk/android/src/jni/pc/add_ice_candidate_observer.cc
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sdk/android/src/jni/pc/add_ice_candidate_observer.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "sdk/android/generated_peerconnection_jni/AddIceObserver_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
#include "sdk/media_constraints.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace jni {
|
||||||
|
|
||||||
|
AddIceCandidateObserverJni::AddIceCandidateObserverJni(
|
||||||
|
JNIEnv* env,
|
||||||
|
const JavaRef<jobject>& j_observer)
|
||||||
|
: j_observer_global_(env, j_observer) {}
|
||||||
|
|
||||||
|
void AddIceCandidateObserverJni::OnComplete(webrtc::RTCError error) {
|
||||||
|
JNIEnv* env = AttachCurrentThreadIfNeeded();
|
||||||
|
if (error.ok()) {
|
||||||
|
Java_AddIceObserver_onAddSuccess(env, j_observer_global_);
|
||||||
|
} else {
|
||||||
|
Java_AddIceObserver_onAddFailure(env, j_observer_global_,
|
||||||
|
NativeToJavaString(env, error.message()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace jni
|
||||||
|
} // namespace webrtc
|
||||||
37
sdk/android/src/jni/pc/add_ice_candidate_observer.h
Normal file
37
sdk/android/src/jni/pc/add_ice_candidate_observer.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SDK_ANDROID_SRC_JNI_PC_ADD_ICE_CANDIDATE_OBSERVER_H_
|
||||||
|
#define SDK_ANDROID_SRC_JNI_PC_ADD_ICE_CANDIDATE_OBSERVER_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "api/peer_connection_interface.h"
|
||||||
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace jni {
|
||||||
|
|
||||||
|
class AddIceCandidateObserverJni final : public rtc::RefCountedBase {
|
||||||
|
public:
|
||||||
|
AddIceCandidateObserverJni(JNIEnv* env, const JavaRef<jobject>& j_observer);
|
||||||
|
~AddIceCandidateObserverJni() override = default;
|
||||||
|
|
||||||
|
void OnComplete(RTCError error);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const ScopedJavaGlobalRef<jobject> j_observer_global_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace jni
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_SRC_JNI_PC_ADD_ICE_CANDIDATE_OBSERVER_H_
|
||||||
@ -44,6 +44,7 @@
|
|||||||
#include "sdk/android/generated_peerconnection_jni/PeerConnection_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/PeerConnection_jni.h"
|
||||||
#include "sdk/android/native_api/jni/java_types.h"
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
#include "sdk/android/src/jni/pc/add_ice_candidate_observer.h"
|
||||||
#include "sdk/android/src/jni/pc/crypto_options.h"
|
#include "sdk/android/src/jni/pc/crypto_options.h"
|
||||||
#include "sdk/android/src/jni/pc/data_channel.h"
|
#include "sdk/android/src/jni/pc/data_channel.h"
|
||||||
#include "sdk/android/src/jni/pc/ice_candidate.h"
|
#include "sdk/android/src/jni/pc/ice_candidate.h"
|
||||||
@ -651,6 +652,25 @@ static jboolean JNI_PeerConnection_AddIceCandidate(
|
|||||||
return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get());
|
return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void JNI_PeerConnection_AddIceCandidateWithObserver(
|
||||||
|
JNIEnv* jni,
|
||||||
|
const JavaParamRef<jobject>& j_pc,
|
||||||
|
const JavaParamRef<jstring>& j_sdp_mid,
|
||||||
|
jint j_sdp_mline_index,
|
||||||
|
const JavaParamRef<jstring>& j_candidate_sdp,
|
||||||
|
const JavaParamRef<jobject>& j_observer) {
|
||||||
|
std::string sdp_mid = JavaToNativeString(jni, j_sdp_mid);
|
||||||
|
std::string sdp = JavaToNativeString(jni, j_candidate_sdp);
|
||||||
|
std::unique_ptr<IceCandidateInterface> candidate(
|
||||||
|
CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, nullptr));
|
||||||
|
|
||||||
|
rtc::scoped_refptr<AddIceCandidateObserverJni> observer(
|
||||||
|
new AddIceCandidateObserverJni(jni, j_observer));
|
||||||
|
ExtractNativePC(jni, j_pc)->AddIceCandidate(
|
||||||
|
std::move(candidate),
|
||||||
|
[observer](RTCError error) { observer->OnComplete(error); });
|
||||||
|
}
|
||||||
|
|
||||||
static jboolean JNI_PeerConnection_RemoveIceCandidates(
|
static jboolean JNI_PeerConnection_RemoveIceCandidates(
|
||||||
JNIEnv* jni,
|
JNIEnv* jni,
|
||||||
const JavaParamRef<jobject>& j_pc,
|
const JavaParamRef<jobject>& j_pc,
|
||||||
|
|||||||
Reference in New Issue
Block a user