henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 11 | package org.webrtc; |
| 12 | |
Artem Titarenko | 69540f4 | 2018-12-10 12:30:46 +0100 | [diff] [blame] | 13 | import android.support.annotation.Nullable; |
Magnus Jedvert | 6062f37 | 2017-11-16 16:53:12 +0100 | [diff] [blame] | 14 | import java.util.ArrayList; |
Qingsi Wang | a0d4580 | 2019-01-15 13:33:11 -0800 | [diff] [blame] | 15 | import java.util.Arrays; |
Sami Kalliomäki | 3e189a6 | 2017-11-24 11:13:39 +0100 | [diff] [blame] | 16 | import java.util.Collections; |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 17 | import java.util.HashMap; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | import java.util.List; |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 19 | import java.util.Map; |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 20 | import org.webrtc.CandidatePairChangeEvent; |
Patrik Höglund | bd6ffaf | 2018-11-16 14:55:16 +0100 | [diff] [blame] | 21 | import org.webrtc.DataChannel; |
| 22 | import org.webrtc.MediaStreamTrack; |
| 23 | import org.webrtc.RtpTransceiver; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Java-land version of the PeerConnection APIs; wraps the C++ API |
| 27 | * http://www.webrtc.org/reference/native-apis, which in turn is inspired by the |
| 28 | * JS APIs: http://dev.w3.org/2011/webrtc/editor/webrtc.html and |
| 29 | * http://www.w3.org/TR/mediacapture-streams/ |
| 30 | */ |
| 31 | public class PeerConnection { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | /** Tracks PeerConnectionInterface::IceGatheringState */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 33 | public enum IceGatheringState { |
| 34 | NEW, |
| 35 | GATHERING, |
| 36 | COMPLETE; |
| 37 | |
| 38 | @CalledByNative("IceGatheringState") |
| 39 | static IceGatheringState fromNativeIndex(int nativeIndex) { |
| 40 | return values()[nativeIndex]; |
| 41 | } |
| 42 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | |
| 44 | /** Tracks PeerConnectionInterface::IceConnectionState */ |
| 45 | public enum IceConnectionState { |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 46 | NEW, |
| 47 | CHECKING, |
| 48 | CONNECTED, |
| 49 | COMPLETED, |
| 50 | FAILED, |
| 51 | DISCONNECTED, |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 52 | CLOSED; |
| 53 | |
| 54 | @CalledByNative("IceConnectionState") |
| 55 | static IceConnectionState fromNativeIndex(int nativeIndex) { |
| 56 | return values()[nativeIndex]; |
| 57 | } |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 58 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | |
Jonas Olsson | f01d8c8 | 2018-11-08 15:19:04 +0100 | [diff] [blame] | 60 | /** Tracks PeerConnectionInterface::PeerConnectionState */ |
| 61 | public enum PeerConnectionState { |
| 62 | NEW, |
| 63 | CONNECTING, |
| 64 | CONNECTED, |
| 65 | DISCONNECTED, |
| 66 | FAILED, |
| 67 | CLOSED; |
| 68 | |
| 69 | @CalledByNative("PeerConnectionState") |
| 70 | static PeerConnectionState fromNativeIndex(int nativeIndex) { |
| 71 | return values()[nativeIndex]; |
| 72 | } |
| 73 | } |
| 74 | |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 75 | /** Tracks PeerConnectionInterface::TlsCertPolicy */ |
| 76 | public enum TlsCertPolicy { |
| 77 | TLS_CERT_POLICY_SECURE, |
| 78 | TLS_CERT_POLICY_INSECURE_NO_CHECK, |
| 79 | } |
| 80 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | /** Tracks PeerConnectionInterface::SignalingState */ |
| 82 | public enum SignalingState { |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 83 | STABLE, |
| 84 | HAVE_LOCAL_OFFER, |
| 85 | HAVE_LOCAL_PRANSWER, |
| 86 | HAVE_REMOTE_OFFER, |
| 87 | HAVE_REMOTE_PRANSWER, |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 88 | CLOSED; |
| 89 | |
| 90 | @CalledByNative("SignalingState") |
| 91 | static SignalingState fromNativeIndex(int nativeIndex) { |
| 92 | return values()[nativeIndex]; |
| 93 | } |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 94 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | |
| 96 | /** Java version of PeerConnectionObserver. */ |
| 97 | public static interface Observer { |
| 98 | /** Triggered when the SignalingState changes. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 99 | @CalledByNative("Observer") void onSignalingChange(SignalingState newState); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | |
| 101 | /** Triggered when the IceConnectionState changes. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 102 | @CalledByNative("Observer") void onIceConnectionChange(IceConnectionState newState); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | |
Qingsi Wang | 36e3147 | 2019-05-29 11:37:26 -0700 | [diff] [blame] | 104 | /* Triggered when the standard-compliant state transition of IceConnectionState happens. */ |
| 105 | @CalledByNative("Observer") |
| 106 | default void onStandardizedIceConnectionChange(IceConnectionState newState) {} |
| 107 | |
Jonas Olsson | f01d8c8 | 2018-11-08 15:19:04 +0100 | [diff] [blame] | 108 | /** Triggered when the PeerConnectionState changes. */ |
| 109 | @CalledByNative("Observer") |
| 110 | default void onConnectionChange(PeerConnectionState newState) {} |
| 111 | |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 112 | /** Triggered when the ICE connection receiving status changes. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 113 | @CalledByNative("Observer") void onIceConnectionReceivingChange(boolean receiving); |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 114 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 115 | /** Triggered when the IceGatheringState changes. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 116 | @CalledByNative("Observer") void onIceGatheringChange(IceGatheringState newState); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | |
| 118 | /** Triggered when a new ICE candidate has been found. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 119 | @CalledByNative("Observer") void onIceCandidate(IceCandidate candidate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 121 | /** Triggered when some ICE candidates have been removed. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 122 | @CalledByNative("Observer") void onIceCandidatesRemoved(IceCandidate[] candidates); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 123 | |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 124 | /** Triggered when the ICE candidate pair is changed. */ |
| 125 | @CalledByNative("Observer") |
| 126 | default void onSelectedCandidatePairChanged(CandidatePairChangeEvent event) {} |
| 127 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | /** Triggered when media is received on a new stream from remote peer. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 129 | @CalledByNative("Observer") void onAddStream(MediaStream stream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | |
| 131 | /** Triggered when a remote peer close a stream. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 132 | @CalledByNative("Observer") void onRemoveStream(MediaStream stream); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 133 | |
| 134 | /** Triggered when a remote peer opens a DataChannel. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 135 | @CalledByNative("Observer") void onDataChannel(DataChannel dataChannel); |
fischman@webrtc.org | d7568a0 | 2014-01-13 22:04:12 +0000 | [diff] [blame] | 136 | |
| 137 | /** Triggered when renegotiation is necessary. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 138 | @CalledByNative("Observer") void onRenegotiationNeeded(); |
zhihuang | dcccda7 | 2016-12-21 14:08:03 -0800 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Triggered when a new track is signaled by the remote peer, as a result of |
| 142 | * setRemoteDescription. |
| 143 | */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 144 | @CalledByNative("Observer") void onAddTrack(RtpReceiver receiver, MediaStream[] mediaStreams); |
Seth Hampson | 31dbc24 | 2018-05-07 09:28:19 -0700 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * Triggered when the signaling from SetRemoteDescription indicates that a transceiver |
| 148 | * will be receiving media from a remote endpoint. This is only called if UNIFIED_PLAN |
| 149 | * semantics are specified. The transceiver will be disposed automatically. |
| 150 | */ |
| 151 | @CalledByNative("Observer") default void onTrack(RtpTransceiver transceiver){}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** Java version of PeerConnectionInterface.IceServer. */ |
| 155 | public static class IceServer { |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 156 | // List of URIs associated with this server. Valid formats are described |
| 157 | // in RFC7064 and RFC7065, and more may be added in the future. The "host" |
| 158 | // part of the URI may contain either an IP address or a hostname. |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 159 | @Deprecated public final String uri; |
| 160 | public final List<String> urls; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | public final String username; |
| 162 | public final String password; |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 163 | public final TlsCertPolicy tlsCertPolicy; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 165 | // If the URIs in |urls| only contain IP addresses, this field can be used |
| 166 | // to indicate the hostname, which may be necessary for TLS (using the SNI |
| 167 | // extension). If |urls| itself contains the hostname, this isn't |
| 168 | // necessary. |
| 169 | public final String hostname; |
| 170 | |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 171 | // List of protocols to be used in the TLS ALPN extension. |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 172 | public final List<String> tlsAlpnProtocols; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 173 | |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 174 | // List of elliptic curves to be used in the TLS elliptic curves extension. |
| 175 | // Only curve names supported by OpenSSL should be used (eg. "P-256","X25519"). |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 176 | public final List<String> tlsEllipticCurves; |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 177 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 178 | /** Convenience constructor for STUN servers. */ |
Diogo Real | 05ea2b3 | 2017-08-31 00:12:58 -0700 | [diff] [blame] | 179 | @Deprecated |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | public IceServer(String uri) { |
| 181 | this(uri, "", ""); |
| 182 | } |
| 183 | |
Diogo Real | 05ea2b3 | 2017-08-31 00:12:58 -0700 | [diff] [blame] | 184 | @Deprecated |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | public IceServer(String uri, String username, String password) { |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 186 | this(uri, username, password, TlsCertPolicy.TLS_CERT_POLICY_SECURE); |
| 187 | } |
| 188 | |
Diogo Real | 05ea2b3 | 2017-08-31 00:12:58 -0700 | [diff] [blame] | 189 | @Deprecated |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 190 | public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy) { |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 191 | this(uri, username, password, tlsCertPolicy, ""); |
| 192 | } |
| 193 | |
Diogo Real | 05ea2b3 | 2017-08-31 00:12:58 -0700 | [diff] [blame] | 194 | @Deprecated |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 195 | public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy, |
| 196 | String hostname) { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 197 | this(uri, Collections.singletonList(uri), username, password, tlsCertPolicy, hostname, null, |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 198 | null); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 199 | } |
| 200 | |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 201 | private IceServer(String uri, List<String> urls, String username, String password, |
| 202 | TlsCertPolicy tlsCertPolicy, String hostname, List<String> tlsAlpnProtocols, |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 203 | List<String> tlsEllipticCurves) { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 204 | if (uri == null || urls == null || urls.isEmpty()) { |
| 205 | throw new IllegalArgumentException("uri == null || urls == null || urls.isEmpty()"); |
| 206 | } |
| 207 | for (String it : urls) { |
| 208 | if (it == null) { |
| 209 | throw new IllegalArgumentException("urls element is null: " + urls); |
| 210 | } |
| 211 | } |
| 212 | if (username == null) { |
| 213 | throw new IllegalArgumentException("username == null"); |
| 214 | } |
| 215 | if (password == null) { |
| 216 | throw new IllegalArgumentException("password == null"); |
| 217 | } |
| 218 | if (hostname == null) { |
| 219 | throw new IllegalArgumentException("hostname == null"); |
| 220 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | this.uri = uri; |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 222 | this.urls = urls; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 223 | this.username = username; |
| 224 | this.password = password; |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 225 | this.tlsCertPolicy = tlsCertPolicy; |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 226 | this.hostname = hostname; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 227 | this.tlsAlpnProtocols = tlsAlpnProtocols; |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 228 | this.tlsEllipticCurves = tlsEllipticCurves; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Sami Kalliomäki | bde473e | 2017-10-30 13:34:41 +0100 | [diff] [blame] | 231 | @Override |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | public String toString() { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 233 | return urls + " [" + username + ":" + password + "] [" + tlsCertPolicy + "] [" + hostname |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 234 | + "] [" + tlsAlpnProtocols + "] [" + tlsEllipticCurves + "]"; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Qingsi Wang | a0d4580 | 2019-01-15 13:33:11 -0800 | [diff] [blame] | 237 | @Override |
| 238 | public boolean equals(@Nullable Object obj) { |
| 239 | if (obj == null) { |
| 240 | return false; |
| 241 | } |
| 242 | if (obj == this) { |
| 243 | return true; |
| 244 | } |
| 245 | if (!(obj instanceof IceServer)) { |
| 246 | return false; |
| 247 | } |
| 248 | IceServer other = (IceServer) obj; |
| 249 | return (uri.equals(other.uri) && urls.equals(other.urls) && username.equals(other.username) |
| 250 | && password.equals(other.password) && tlsCertPolicy.equals(other.tlsCertPolicy) |
| 251 | && hostname.equals(other.hostname) && tlsAlpnProtocols.equals(other.tlsAlpnProtocols) |
| 252 | && tlsEllipticCurves.equals(other.tlsEllipticCurves)); |
| 253 | } |
| 254 | |
| 255 | @Override |
| 256 | public int hashCode() { |
| 257 | Object[] values = {uri, urls, username, password, tlsCertPolicy, hostname, tlsAlpnProtocols, |
| 258 | tlsEllipticCurves}; |
| 259 | return Arrays.hashCode(values); |
| 260 | } |
| 261 | |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 262 | public static Builder builder(String uri) { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 263 | return new Builder(Collections.singletonList(uri)); |
| 264 | } |
| 265 | |
| 266 | public static Builder builder(List<String> urls) { |
| 267 | return new Builder(urls); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | public static class Builder { |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 271 | @Nullable private final List<String> urls; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 272 | private String username = ""; |
| 273 | private String password = ""; |
| 274 | private TlsCertPolicy tlsCertPolicy = TlsCertPolicy.TLS_CERT_POLICY_SECURE; |
| 275 | private String hostname = ""; |
| 276 | private List<String> tlsAlpnProtocols; |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 277 | private List<String> tlsEllipticCurves; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 278 | |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 279 | private Builder(List<String> urls) { |
| 280 | if (urls == null || urls.isEmpty()) { |
| 281 | throw new IllegalArgumentException("urls == null || urls.isEmpty(): " + urls); |
| 282 | } |
| 283 | this.urls = urls; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | public Builder setUsername(String username) { |
| 287 | this.username = username; |
| 288 | return this; |
| 289 | } |
| 290 | |
| 291 | public Builder setPassword(String password) { |
| 292 | this.password = password; |
| 293 | return this; |
| 294 | } |
| 295 | |
| 296 | public Builder setTlsCertPolicy(TlsCertPolicy tlsCertPolicy) { |
| 297 | this.tlsCertPolicy = tlsCertPolicy; |
| 298 | return this; |
| 299 | } |
| 300 | |
| 301 | public Builder setHostname(String hostname) { |
| 302 | this.hostname = hostname; |
| 303 | return this; |
| 304 | } |
| 305 | |
| 306 | public Builder setTlsAlpnProtocols(List<String> tlsAlpnProtocols) { |
| 307 | this.tlsAlpnProtocols = tlsAlpnProtocols; |
| 308 | return this; |
| 309 | } |
| 310 | |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 311 | public Builder setTlsEllipticCurves(List<String> tlsEllipticCurves) { |
| 312 | this.tlsEllipticCurves = tlsEllipticCurves; |
| 313 | return this; |
| 314 | } |
| 315 | |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 316 | public IceServer createIceServer() { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 317 | return new IceServer(urls.get(0), urls, username, password, tlsCertPolicy, hostname, |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 318 | tlsAlpnProtocols, tlsEllipticCurves); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 319 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 320 | } |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 321 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 322 | @Nullable |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 323 | @CalledByNative("IceServer") |
| 324 | List<String> getUrls() { |
| 325 | return urls; |
| 326 | } |
| 327 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 328 | @Nullable |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 329 | @CalledByNative("IceServer") |
| 330 | String getUsername() { |
| 331 | return username; |
| 332 | } |
| 333 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 334 | @Nullable |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 335 | @CalledByNative("IceServer") |
| 336 | String getPassword() { |
| 337 | return password; |
| 338 | } |
| 339 | |
| 340 | @CalledByNative("IceServer") |
| 341 | TlsCertPolicy getTlsCertPolicy() { |
| 342 | return tlsCertPolicy; |
| 343 | } |
| 344 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 345 | @Nullable |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 346 | @CalledByNative("IceServer") |
| 347 | String getHostname() { |
| 348 | return hostname; |
| 349 | } |
| 350 | |
| 351 | @CalledByNative("IceServer") |
| 352 | List<String> getTlsAlpnProtocols() { |
| 353 | return tlsAlpnProtocols; |
| 354 | } |
| 355 | |
| 356 | @CalledByNative("IceServer") |
| 357 | List<String> getTlsEllipticCurves() { |
| 358 | return tlsEllipticCurves; |
| 359 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 362 | /** Java version of PeerConnectionInterface.IceTransportsType */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 363 | public enum IceTransportsType { NONE, RELAY, NOHOST, ALL } |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 364 | |
| 365 | /** Java version of PeerConnectionInterface.BundlePolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 366 | public enum BundlePolicy { BALANCED, MAXBUNDLE, MAXCOMPAT } |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 367 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 368 | /** Java version of PeerConnectionInterface.RtcpMuxPolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 369 | public enum RtcpMuxPolicy { NEGOTIATE, REQUIRE } |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 370 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 371 | /** Java version of PeerConnectionInterface.TcpCandidatePolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 372 | public enum TcpCandidatePolicy { ENABLED, DISABLED } |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 373 | |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 374 | /** Java version of PeerConnectionInterface.CandidateNetworkPolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 375 | public enum CandidateNetworkPolicy { ALL, LOW_COST } |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 376 | |
Qingsi Wang | 9a5c6f8 | 2018-02-01 10:38:40 -0800 | [diff] [blame] | 377 | // Keep in sync with webrtc/rtc_base/network_constants.h. |
| 378 | public enum AdapterType { |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 379 | UNKNOWN(0), |
| 380 | ETHERNET(1 << 0), |
| 381 | WIFI(1 << 1), |
| 382 | CELLULAR(1 << 2), |
| 383 | VPN(1 << 3), |
| 384 | LOOPBACK(1 << 4), |
| 385 | ADAPTER_TYPE_ANY(1 << 5); |
| 386 | |
| 387 | public final Integer bitMask; |
| 388 | private AdapterType(Integer bitMask) { |
| 389 | this.bitMask = bitMask; |
| 390 | } |
| 391 | private static final Map<Integer, AdapterType> BY_BITMASK = new HashMap<>(); |
| 392 | static { |
| 393 | for (AdapterType t : values()) { |
| 394 | BY_BITMASK.put(t.bitMask, t); |
| 395 | } |
| 396 | } |
| 397 | |
Yves Gerey | 29e07e5 | 2019-11-19 12:13:25 +0100 | [diff] [blame^] | 398 | @Nullable |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 399 | @CalledByNative("AdapterType") |
| 400 | static AdapterType fromNativeIndex(int nativeIndex) { |
| 401 | return BY_BITMASK.get(nativeIndex); |
| 402 | } |
Qingsi Wang | 9a5c6f8 | 2018-02-01 10:38:40 -0800 | [diff] [blame] | 403 | } |
| 404 | |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 405 | /** Java version of rtc::KeyType */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 406 | public enum KeyType { RSA, ECDSA } |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 407 | |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 408 | /** Java version of PeerConnectionInterface.ContinualGatheringPolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 409 | public enum ContinualGatheringPolicy { GATHER_ONCE, GATHER_CONTINUALLY } |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 410 | |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 411 | /** Java version of webrtc::PortPrunePolicy */ |
| 412 | public enum PortPrunePolicy { |
| 413 | NO_PRUNE, // Do not prune turn port. |
| 414 | PRUNE_BASED_ON_PRIORITY, // Prune turn port based the priority on the same network |
| 415 | KEEP_FIRST_READY // Keep the first ready port and prune the rest on the same network. |
| 416 | } |
| 417 | |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 418 | /** Java version of rtc::IntervalRange */ |
| 419 | public static class IntervalRange { |
| 420 | private final int min; |
| 421 | private final int max; |
| 422 | |
| 423 | public IntervalRange(int min, int max) { |
| 424 | this.min = min; |
| 425 | this.max = max; |
| 426 | } |
| 427 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 428 | @CalledByNative("IntervalRange") |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 429 | public int getMin() { |
| 430 | return min; |
| 431 | } |
| 432 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 433 | @CalledByNative("IntervalRange") |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 434 | public int getMax() { |
| 435 | return max; |
| 436 | } |
| 437 | } |
| 438 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 439 | /** |
| 440 | * Java version of webrtc::SdpSemantics. |
| 441 | * |
| 442 | * Configure the SDP semantics used by this PeerConnection. Note that the |
| 443 | * WebRTC 1.0 specification requires UNIFIED_PLAN semantics. The |
| 444 | * RtpTransceiver API is only available with UNIFIED_PLAN semantics. |
| 445 | * |
| 446 | * <p>PLAN_B will cause PeerConnection to create offers and answers with at |
| 447 | * most one audio and one video m= section with multiple RtpSenders and |
| 448 | * RtpReceivers specified as multiple a=ssrc lines within the section. This |
| 449 | * will also cause PeerConnection to ignore all but the first m= section of |
| 450 | * the same media type. |
| 451 | * |
| 452 | * <p>UNIFIED_PLAN will cause PeerConnection to create offers and answers with |
| 453 | * multiple m= sections where each m= section maps to one RtpSender and one |
| 454 | * RtpReceiver (an RtpTransceiver), either both audio or both video. This |
| 455 | * will also cause PeerConnection to ignore all but the first a=ssrc lines |
| 456 | * that form a Plan B stream. |
| 457 | * |
| 458 | * <p>For users who wish to send multiple audio/video streams and need to stay |
| 459 | * interoperable with legacy WebRTC implementations, specify PLAN_B. |
| 460 | * |
| 461 | * <p>For users who wish to send multiple audio/video streams and/or wish to |
| 462 | * use the new RtpTransceiver API, specify UNIFIED_PLAN. |
| 463 | */ |
| 464 | public enum SdpSemantics { PLAN_B, UNIFIED_PLAN } |
| 465 | |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 466 | /** Java version of PeerConnectionInterface.RTCConfiguration */ |
Qingsi Wang | db53f8e | 2018-02-20 14:45:49 -0800 | [diff] [blame] | 467 | // TODO(qingsi): Resolve the naming inconsistency of fields with/without units. |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 468 | public static class RTCConfiguration { |
| 469 | public IceTransportsType iceTransportsType; |
| 470 | public List<IceServer> iceServers; |
| 471 | public BundlePolicy bundlePolicy; |
Michael Iedema | 0213786 | 2018-10-09 15:30:01 +0200 | [diff] [blame] | 472 | @Nullable public RtcCertificatePem certificate; |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 473 | public RtcpMuxPolicy rtcpMuxPolicy; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 474 | public TcpCandidatePolicy tcpCandidatePolicy; |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 475 | public CandidateNetworkPolicy candidateNetworkPolicy; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 476 | public int audioJitterBufferMaxPackets; |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 477 | public boolean audioJitterBufferFastAccelerate; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 478 | public int iceConnectionReceivingTimeout; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 479 | public int iceBackupCandidatePairPingInterval; |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 480 | public KeyType keyType; |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 481 | public ContinualGatheringPolicy continualGatheringPolicy; |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 482 | public int iceCandidatePoolSize; |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 483 | @Deprecated // by the turnPortPrunePolicy. See bugs.webrtc.org/11026 |
Honghai Zhang | d78ecf7 | 2016-07-01 14:40:40 -0700 | [diff] [blame] | 484 | public boolean pruneTurnPorts; |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 485 | public PortPrunePolicy turnPortPrunePolicy; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 486 | public boolean presumeWritableWhenFullyRelayed; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 487 | public boolean surfaceIceCandidatesOnIceTransportTypeChanged; |
Qingsi Wang | e6826d2 | 2018-03-08 14:55:14 -0800 | [diff] [blame] | 488 | // The following fields define intervals in milliseconds at which ICE |
| 489 | // connectivity checks are sent. |
| 490 | // |
| 491 | // We consider ICE is "strongly connected" for an agent when there is at |
| 492 | // least one candidate pair that currently succeeds in connectivity check |
| 493 | // from its direction i.e. sending a ping and receives a ping response, AND |
| 494 | // all candidate pairs have sent a minimum number of pings for connectivity |
| 495 | // (this number is implementation-specific). Otherwise, ICE is considered in |
| 496 | // "weak connectivity". |
| 497 | // |
| 498 | // Note that the above notion of strong and weak connectivity is not defined |
| 499 | // in RFC 5245, and they apply to our current ICE implementation only. |
| 500 | // |
| 501 | // 1) iceCheckIntervalStrongConnectivityMs defines the interval applied to |
| 502 | // ALL candidate pairs when ICE is strongly connected, |
| 503 | // 2) iceCheckIntervalWeakConnectivityMs defines the counterpart for ALL |
| 504 | // pairs when ICE is weakly connected, and |
| 505 | // 3) iceCheckMinInterval defines the minimal interval (equivalently the |
| 506 | // maximum rate) that overrides the above two intervals when either of them |
| 507 | // is less. |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 508 | @Nullable public Integer iceCheckIntervalStrongConnectivityMs; |
| 509 | @Nullable public Integer iceCheckIntervalWeakConnectivityMs; |
| 510 | @Nullable public Integer iceCheckMinInterval; |
Qingsi Wang | 22e623a | 2018-03-13 10:53:57 -0700 | [diff] [blame] | 511 | // The time period in milliseconds for which a candidate pair must wait for response to |
| 512 | // connectivitiy checks before it becomes unwritable. |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 513 | @Nullable public Integer iceUnwritableTimeMs; |
Qingsi Wang | 22e623a | 2018-03-13 10:53:57 -0700 | [diff] [blame] | 514 | // The minimum number of connectivity checks that a candidate pair must sent without receiving |
| 515 | // response before it becomes unwritable. |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 516 | @Nullable public Integer iceUnwritableMinChecks; |
Qingsi Wang | db53f8e | 2018-02-20 14:45:49 -0800 | [diff] [blame] | 517 | // The interval in milliseconds at which STUN candidates will resend STUN binding requests |
| 518 | // to keep NAT bindings open. |
| 519 | // The default value in the implementation is used if this field is null. |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 520 | @Nullable public Integer stunCandidateKeepaliveIntervalMs; |
zhihuang | b09b3f9 | 2017-03-07 14:40:51 -0800 | [diff] [blame] | 521 | public boolean disableIPv6OnWifi; |
deadbeef | 28e2919 | 2017-07-27 09:14:38 -0700 | [diff] [blame] | 522 | // By default, PeerConnection will use a limited number of IPv6 network |
| 523 | // interfaces, in order to avoid too many ICE candidate pairs being created |
| 524 | // and delaying ICE completion. |
| 525 | // |
| 526 | // Can be set to Integer.MAX_VALUE to effectively disable the limit. |
| 527 | public int maxIPv6Networks; |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 528 | @Nullable public IntervalRange iceRegatherIntervalRange; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 529 | |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 530 | // These values will be overridden by MediaStream constraints if deprecated constraints-based |
| 531 | // create peerconnection interface is used. |
| 532 | public boolean disableIpv6; |
| 533 | public boolean enableDscp; |
| 534 | public boolean enableCpuOveruseDetection; |
| 535 | public boolean enableRtpDataChannel; |
| 536 | public boolean suspendBelowMinBitrate; |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 537 | @Nullable public Integer screencastMinBitrate; |
| 538 | @Nullable public Boolean combinedAudioVideoBwe; |
| 539 | @Nullable public Boolean enableDtlsSrtp; |
Qingsi Wang | 9a5c6f8 | 2018-02-01 10:38:40 -0800 | [diff] [blame] | 540 | // Use "Unknown" to represent no preference of adapter types, not the |
| 541 | // preference of adapters of unknown types. |
| 542 | public AdapterType networkPreference; |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 543 | public SdpSemantics sdpSemantics; |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 544 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 545 | // This is an optional wrapper for the C++ webrtc::TurnCustomizer. |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 546 | @Nullable public TurnCustomizer turnCustomizer; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 547 | |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 548 | // Actively reset the SRTP parameters whenever the DTLS transports underneath are reset for |
| 549 | // every offer/answer negotiation.This is only intended to be a workaround for crbug.com/835958 |
| 550 | public boolean activeResetSrtpParams; |
| 551 | |
philipel | 16cec3b | 2019-10-25 12:23:02 +0200 | [diff] [blame] | 552 | // Whether this client is allowed to switch encoding codec mid-stream. This is a workaround for |
| 553 | // a WebRTC bug where the receiver could get confussed if a codec switch happened mid-call. |
| 554 | // Null indicates no change to currently configured value. |
| 555 | @Nullable public Boolean allowCodecSwitching; |
| 556 | |
Piotr (Peter) Slatala | 09beff2 | 2018-10-17 07:22:40 -0700 | [diff] [blame] | 557 | /* |
| 558 | * Experimental flag that enables a use of media transport. If this is true, the media transport |
| 559 | * factory MUST be provided to the PeerConnectionFactory. |
| 560 | */ |
| 561 | public boolean useMediaTransport; |
| 562 | |
Bjorn Mellem | a9bbd86 | 2018-11-02 09:07:48 -0700 | [diff] [blame] | 563 | /* |
| 564 | * Experimental flag that enables a use of media transport for data channels. If this is true, |
| 565 | * the media transport factory MUST be provided to the PeerConnectionFactory. |
| 566 | */ |
| 567 | public boolean useMediaTransportForDataChannels; |
| 568 | |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 569 | /** |
| 570 | * Defines advanced optional cryptographic settings related to SRTP and |
| 571 | * frame encryption for native WebRTC. Setting this will overwrite any |
| 572 | * options set through the PeerConnectionFactory (which is deprecated). |
| 573 | */ |
| 574 | @Nullable public CryptoOptions cryptoOptions; |
| 575 | |
Jonas Oreland | 228900f | 2019-08-28 09:08:58 +0200 | [diff] [blame] | 576 | /** |
| 577 | * An optional string that if set will be attached to the |
| 578 | * TURN_ALLOCATE_REQUEST which can be used to correlate client |
| 579 | * logs with backend logs |
| 580 | */ |
| 581 | @Nullable public String turnLoggingId; |
| 582 | |
deadbeef | 28e2919 | 2017-07-27 09:14:38 -0700 | [diff] [blame] | 583 | // TODO(deadbeef): Instead of duplicating the defaults here, we should do |
| 584 | // something to pick up the defaults from C++. The Objective-C equivalent |
| 585 | // of RTCConfiguration does that. |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 586 | public RTCConfiguration(List<IceServer> iceServers) { |
| 587 | iceTransportsType = IceTransportsType.ALL; |
| 588 | bundlePolicy = BundlePolicy.BALANCED; |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 589 | rtcpMuxPolicy = RtcpMuxPolicy.REQUIRE; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 590 | tcpCandidatePolicy = TcpCandidatePolicy.ENABLED; |
Sami Kalliomäki | 9828beb | 2017-10-26 16:21:22 +0200 | [diff] [blame] | 591 | candidateNetworkPolicy = CandidateNetworkPolicy.ALL; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 592 | this.iceServers = iceServers; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 593 | audioJitterBufferMaxPackets = 50; |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 594 | audioJitterBufferFastAccelerate = false; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 595 | iceConnectionReceivingTimeout = -1; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 596 | iceBackupCandidatePairPingInterval = -1; |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 597 | keyType = KeyType.ECDSA; |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 598 | continualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE; |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 599 | iceCandidatePoolSize = 0; |
Honghai Zhang | d78ecf7 | 2016-07-01 14:40:40 -0700 | [diff] [blame] | 600 | pruneTurnPorts = false; |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 601 | turnPortPrunePolicy = PortPrunePolicy.NO_PRUNE; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 602 | presumeWritableWhenFullyRelayed = false; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 603 | surfaceIceCandidatesOnIceTransportTypeChanged = false; |
Qingsi Wang | e6826d2 | 2018-03-08 14:55:14 -0800 | [diff] [blame] | 604 | iceCheckIntervalStrongConnectivityMs = null; |
| 605 | iceCheckIntervalWeakConnectivityMs = null; |
skvlad | 5107246 | 2017-02-02 11:50:14 -0800 | [diff] [blame] | 606 | iceCheckMinInterval = null; |
Qingsi Wang | 22e623a | 2018-03-13 10:53:57 -0700 | [diff] [blame] | 607 | iceUnwritableTimeMs = null; |
| 608 | iceUnwritableMinChecks = null; |
Qingsi Wang | db53f8e | 2018-02-20 14:45:49 -0800 | [diff] [blame] | 609 | stunCandidateKeepaliveIntervalMs = null; |
zhihuang | b09b3f9 | 2017-03-07 14:40:51 -0800 | [diff] [blame] | 610 | disableIPv6OnWifi = false; |
deadbeef | 28e2919 | 2017-07-27 09:14:38 -0700 | [diff] [blame] | 611 | maxIPv6Networks = 5; |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 612 | iceRegatherIntervalRange = null; |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 613 | disableIpv6 = false; |
| 614 | enableDscp = false; |
| 615 | enableCpuOveruseDetection = true; |
| 616 | enableRtpDataChannel = false; |
| 617 | suspendBelowMinBitrate = false; |
| 618 | screencastMinBitrate = null; |
| 619 | combinedAudioVideoBwe = null; |
| 620 | enableDtlsSrtp = null; |
Qingsi Wang | 9a5c6f8 | 2018-02-01 10:38:40 -0800 | [diff] [blame] | 621 | networkPreference = AdapterType.UNKNOWN; |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 622 | sdpSemantics = SdpSemantics.PLAN_B; |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 623 | activeResetSrtpParams = false; |
Piotr (Peter) Slatala | 09beff2 | 2018-10-17 07:22:40 -0700 | [diff] [blame] | 624 | useMediaTransport = false; |
Bjorn Mellem | a9bbd86 | 2018-11-02 09:07:48 -0700 | [diff] [blame] | 625 | useMediaTransportForDataChannels = false; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 626 | cryptoOptions = null; |
Jonas Oreland | 228900f | 2019-08-28 09:08:58 +0200 | [diff] [blame] | 627 | turnLoggingId = null; |
philipel | 16cec3b | 2019-10-25 12:23:02 +0200 | [diff] [blame] | 628 | allowCodecSwitching = null; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 629 | } |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 630 | |
| 631 | @CalledByNative("RTCConfiguration") |
| 632 | IceTransportsType getIceTransportsType() { |
| 633 | return iceTransportsType; |
| 634 | } |
| 635 | |
| 636 | @CalledByNative("RTCConfiguration") |
| 637 | List<IceServer> getIceServers() { |
| 638 | return iceServers; |
| 639 | } |
| 640 | |
| 641 | @CalledByNative("RTCConfiguration") |
| 642 | BundlePolicy getBundlePolicy() { |
| 643 | return bundlePolicy; |
| 644 | } |
| 645 | |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 646 | @CalledByNative("RTCConfiguration") |
| 647 | PortPrunePolicy getTurnPortPrunePolicy() { |
| 648 | return turnPortPrunePolicy; |
| 649 | } |
| 650 | |
Michael Iedema | 0213786 | 2018-10-09 15:30:01 +0200 | [diff] [blame] | 651 | @Nullable |
| 652 | @CalledByNative("RTCConfiguration") |
| 653 | RtcCertificatePem getCertificate() { |
| 654 | return certificate; |
| 655 | } |
| 656 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 657 | @CalledByNative("RTCConfiguration") |
| 658 | RtcpMuxPolicy getRtcpMuxPolicy() { |
| 659 | return rtcpMuxPolicy; |
| 660 | } |
| 661 | |
| 662 | @CalledByNative("RTCConfiguration") |
| 663 | TcpCandidatePolicy getTcpCandidatePolicy() { |
| 664 | return tcpCandidatePolicy; |
| 665 | } |
| 666 | |
| 667 | @CalledByNative("RTCConfiguration") |
| 668 | CandidateNetworkPolicy getCandidateNetworkPolicy() { |
| 669 | return candidateNetworkPolicy; |
| 670 | } |
| 671 | |
| 672 | @CalledByNative("RTCConfiguration") |
| 673 | int getAudioJitterBufferMaxPackets() { |
| 674 | return audioJitterBufferMaxPackets; |
| 675 | } |
| 676 | |
| 677 | @CalledByNative("RTCConfiguration") |
| 678 | boolean getAudioJitterBufferFastAccelerate() { |
| 679 | return audioJitterBufferFastAccelerate; |
| 680 | } |
| 681 | |
| 682 | @CalledByNative("RTCConfiguration") |
| 683 | int getIceConnectionReceivingTimeout() { |
| 684 | return iceConnectionReceivingTimeout; |
| 685 | } |
| 686 | |
| 687 | @CalledByNative("RTCConfiguration") |
| 688 | int getIceBackupCandidatePairPingInterval() { |
| 689 | return iceBackupCandidatePairPingInterval; |
| 690 | } |
| 691 | |
| 692 | @CalledByNative("RTCConfiguration") |
| 693 | KeyType getKeyType() { |
| 694 | return keyType; |
| 695 | } |
| 696 | |
| 697 | @CalledByNative("RTCConfiguration") |
| 698 | ContinualGatheringPolicy getContinualGatheringPolicy() { |
| 699 | return continualGatheringPolicy; |
| 700 | } |
| 701 | |
| 702 | @CalledByNative("RTCConfiguration") |
| 703 | int getIceCandidatePoolSize() { |
| 704 | return iceCandidatePoolSize; |
| 705 | } |
| 706 | |
| 707 | @CalledByNative("RTCConfiguration") |
| 708 | boolean getPruneTurnPorts() { |
| 709 | return pruneTurnPorts; |
| 710 | } |
| 711 | |
| 712 | @CalledByNative("RTCConfiguration") |
| 713 | boolean getPresumeWritableWhenFullyRelayed() { |
| 714 | return presumeWritableWhenFullyRelayed; |
| 715 | } |
| 716 | |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 717 | @CalledByNative("RTCConfiguration") |
| 718 | boolean getSurfaceIceCandidatesOnIceTransportTypeChanged() { |
| 719 | return surfaceIceCandidatesOnIceTransportTypeChanged; |
| 720 | } |
| 721 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 722 | @Nullable |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 723 | @CalledByNative("RTCConfiguration") |
Qingsi Wang | e6826d2 | 2018-03-08 14:55:14 -0800 | [diff] [blame] | 724 | Integer getIceCheckIntervalStrongConnectivity() { |
| 725 | return iceCheckIntervalStrongConnectivityMs; |
| 726 | } |
| 727 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 728 | @Nullable |
Qingsi Wang | e6826d2 | 2018-03-08 14:55:14 -0800 | [diff] [blame] | 729 | @CalledByNative("RTCConfiguration") |
| 730 | Integer getIceCheckIntervalWeakConnectivity() { |
| 731 | return iceCheckIntervalWeakConnectivityMs; |
| 732 | } |
| 733 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 734 | @Nullable |
Qingsi Wang | e6826d2 | 2018-03-08 14:55:14 -0800 | [diff] [blame] | 735 | @CalledByNative("RTCConfiguration") |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 736 | Integer getIceCheckMinInterval() { |
| 737 | return iceCheckMinInterval; |
| 738 | } |
| 739 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 740 | @Nullable |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 741 | @CalledByNative("RTCConfiguration") |
Qingsi Wang | 22e623a | 2018-03-13 10:53:57 -0700 | [diff] [blame] | 742 | Integer getIceUnwritableTimeout() { |
| 743 | return iceUnwritableTimeMs; |
| 744 | } |
| 745 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 746 | @Nullable |
Qingsi Wang | 22e623a | 2018-03-13 10:53:57 -0700 | [diff] [blame] | 747 | @CalledByNative("RTCConfiguration") |
| 748 | Integer getIceUnwritableMinChecks() { |
| 749 | return iceUnwritableMinChecks; |
| 750 | } |
| 751 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 752 | @Nullable |
Qingsi Wang | 22e623a | 2018-03-13 10:53:57 -0700 | [diff] [blame] | 753 | @CalledByNative("RTCConfiguration") |
Qingsi Wang | db53f8e | 2018-02-20 14:45:49 -0800 | [diff] [blame] | 754 | Integer getStunCandidateKeepaliveInterval() { |
| 755 | return stunCandidateKeepaliveIntervalMs; |
| 756 | } |
| 757 | |
| 758 | @CalledByNative("RTCConfiguration") |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 759 | boolean getDisableIPv6OnWifi() { |
| 760 | return disableIPv6OnWifi; |
| 761 | } |
| 762 | |
| 763 | @CalledByNative("RTCConfiguration") |
| 764 | int getMaxIPv6Networks() { |
| 765 | return maxIPv6Networks; |
| 766 | } |
| 767 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 768 | @Nullable |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 769 | @CalledByNative("RTCConfiguration") |
| 770 | IntervalRange getIceRegatherIntervalRange() { |
| 771 | return iceRegatherIntervalRange; |
| 772 | } |
| 773 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 774 | @Nullable |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 775 | @CalledByNative("RTCConfiguration") |
| 776 | TurnCustomizer getTurnCustomizer() { |
| 777 | return turnCustomizer; |
| 778 | } |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 779 | |
| 780 | @CalledByNative("RTCConfiguration") |
| 781 | boolean getDisableIpv6() { |
| 782 | return disableIpv6; |
| 783 | } |
| 784 | |
| 785 | @CalledByNative("RTCConfiguration") |
| 786 | boolean getEnableDscp() { |
| 787 | return enableDscp; |
| 788 | } |
| 789 | |
| 790 | @CalledByNative("RTCConfiguration") |
| 791 | boolean getEnableCpuOveruseDetection() { |
| 792 | return enableCpuOveruseDetection; |
| 793 | } |
| 794 | |
| 795 | @CalledByNative("RTCConfiguration") |
| 796 | boolean getEnableRtpDataChannel() { |
| 797 | return enableRtpDataChannel; |
| 798 | } |
| 799 | |
| 800 | @CalledByNative("RTCConfiguration") |
| 801 | boolean getSuspendBelowMinBitrate() { |
| 802 | return suspendBelowMinBitrate; |
| 803 | } |
| 804 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 805 | @Nullable |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 806 | @CalledByNative("RTCConfiguration") |
| 807 | Integer getScreencastMinBitrate() { |
| 808 | return screencastMinBitrate; |
| 809 | } |
| 810 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 811 | @Nullable |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 812 | @CalledByNative("RTCConfiguration") |
| 813 | Boolean getCombinedAudioVideoBwe() { |
| 814 | return combinedAudioVideoBwe; |
| 815 | } |
| 816 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 817 | @Nullable |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 818 | @CalledByNative("RTCConfiguration") |
| 819 | Boolean getEnableDtlsSrtp() { |
| 820 | return enableDtlsSrtp; |
| 821 | } |
Qingsi Wang | 9a5c6f8 | 2018-02-01 10:38:40 -0800 | [diff] [blame] | 822 | |
| 823 | @CalledByNative("RTCConfiguration") |
| 824 | AdapterType getNetworkPreference() { |
| 825 | return networkPreference; |
| 826 | } |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 827 | |
| 828 | @CalledByNative("RTCConfiguration") |
| 829 | SdpSemantics getSdpSemantics() { |
| 830 | return sdpSemantics; |
| 831 | } |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 832 | |
| 833 | @CalledByNative("RTCConfiguration") |
| 834 | boolean getActiveResetSrtpParams() { |
| 835 | return activeResetSrtpParams; |
| 836 | } |
Piotr (Peter) Slatala | 09beff2 | 2018-10-17 07:22:40 -0700 | [diff] [blame] | 837 | |
philipel | 16cec3b | 2019-10-25 12:23:02 +0200 | [diff] [blame] | 838 | @Nullable |
| 839 | @CalledByNative("RTCConfiguration") |
| 840 | Boolean getAllowCodecSwitching() { |
| 841 | return allowCodecSwitching; |
| 842 | } |
| 843 | |
Piotr (Peter) Slatala | 09beff2 | 2018-10-17 07:22:40 -0700 | [diff] [blame] | 844 | @CalledByNative("RTCConfiguration") |
| 845 | boolean getUseMediaTransport() { |
| 846 | return useMediaTransport; |
| 847 | } |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 848 | |
Bjorn Mellem | a9bbd86 | 2018-11-02 09:07:48 -0700 | [diff] [blame] | 849 | @CalledByNative("RTCConfiguration") |
| 850 | boolean getUseMediaTransportForDataChannels() { |
| 851 | return useMediaTransportForDataChannels; |
| 852 | } |
| 853 | |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 854 | @Nullable |
| 855 | @CalledByNative("RTCConfiguration") |
| 856 | CryptoOptions getCryptoOptions() { |
| 857 | return cryptoOptions; |
| 858 | } |
Jonas Oreland | 228900f | 2019-08-28 09:08:58 +0200 | [diff] [blame] | 859 | |
| 860 | @Nullable |
| 861 | @CalledByNative("RTCConfiguration") |
| 862 | String getTurnLoggingId() { |
| 863 | return turnLoggingId; |
| 864 | } |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 865 | }; |
| 866 | |
Magnus Jedvert | 6062f37 | 2017-11-16 16:53:12 +0100 | [diff] [blame] | 867 | private final List<MediaStream> localStreams = new ArrayList<>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 868 | private final long nativePeerConnection; |
Magnus Jedvert | 6062f37 | 2017-11-16 16:53:12 +0100 | [diff] [blame] | 869 | private List<RtpSender> senders = new ArrayList<>(); |
| 870 | private List<RtpReceiver> receivers = new ArrayList<>(); |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 871 | private List<RtpTransceiver> transceivers = new ArrayList<>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 872 | |
Sami Kalliomäki | 1ece1ed | 2017-12-20 11:59:22 +0100 | [diff] [blame] | 873 | /** |
| 874 | * Wraps a PeerConnection created by the factory. Can be used by clients that want to implement |
| 875 | * their PeerConnection creation in JNI. |
| 876 | */ |
| 877 | public PeerConnection(NativePeerConnectionFactory factory) { |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 878 | this(factory.createNativePeerConnection()); |
Sami Kalliomäki | 1ece1ed | 2017-12-20 11:59:22 +0100 | [diff] [blame] | 879 | } |
| 880 | |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 881 | PeerConnection(long nativePeerConnection) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | this.nativePeerConnection = nativePeerConnection; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | // JsepInterface. |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 886 | public SessionDescription getLocalDescription() { |
| 887 | return nativeGetLocalDescription(); |
| 888 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 889 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 890 | public SessionDescription getRemoteDescription() { |
| 891 | return nativeGetRemoteDescription(); |
| 892 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 893 | |
Michael Iedema | 0213786 | 2018-10-09 15:30:01 +0200 | [diff] [blame] | 894 | public RtcCertificatePem getCertificate() { |
| 895 | return nativeGetCertificate(); |
| 896 | } |
| 897 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 898 | public DataChannel createDataChannel(String label, DataChannel.Init init) { |
| 899 | return nativeCreateDataChannel(label, init); |
| 900 | } |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 901 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 902 | public void createOffer(SdpObserver observer, MediaConstraints constraints) { |
| 903 | nativeCreateOffer(observer, constraints); |
| 904 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 905 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 906 | public void createAnswer(SdpObserver observer, MediaConstraints constraints) { |
| 907 | nativeCreateAnswer(observer, constraints); |
| 908 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 909 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 910 | public void setLocalDescription(SdpObserver observer, SessionDescription sdp) { |
| 911 | nativeSetLocalDescription(observer, sdp); |
| 912 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 913 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 914 | public void setRemoteDescription(SdpObserver observer, SessionDescription sdp) { |
| 915 | nativeSetRemoteDescription(observer, sdp); |
| 916 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 917 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 918 | /** |
| 919 | * Enables/disables playout of received audio streams. Enabled by default. |
| 920 | * |
| 921 | * Note that even if playout is enabled, streams will only be played out if |
| 922 | * the appropriate SDP is also applied. The main purpose of this API is to |
| 923 | * be able to control the exact time when audio playout starts. |
| 924 | */ |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 925 | public void setAudioPlayout(boolean playout) { |
| 926 | nativeSetAudioPlayout(playout); |
| 927 | } |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 928 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 929 | /** |
| 930 | * Enables/disables recording of transmitted audio streams. Enabled by default. |
| 931 | * |
| 932 | * Note that even if recording is enabled, streams will only be recorded if |
| 933 | * the appropriate SDP is also applied. The main purpose of this API is to |
| 934 | * be able to control the exact time when audio recording starts. |
| 935 | */ |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 936 | public void setAudioRecording(boolean recording) { |
| 937 | nativeSetAudioRecording(recording); |
| 938 | } |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 939 | |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 940 | public boolean setConfiguration(RTCConfiguration config) { |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 941 | return nativeSetConfiguration(config); |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 942 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 943 | |
| 944 | public boolean addIceCandidate(IceCandidate candidate) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 945 | return nativeAddIceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 946 | } |
| 947 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 948 | public boolean removeIceCandidates(final IceCandidate[] candidates) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 949 | return nativeRemoveIceCandidates(candidates); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 952 | /** |
| 953 | * Adds a new MediaStream to be sent on this peer connection. |
| 954 | * Note: This method is not supported with SdpSemantics.UNIFIED_PLAN. Please |
| 955 | * use addTrack instead. |
| 956 | */ |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 957 | public boolean addStream(MediaStream stream) { |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 958 | boolean ret = nativeAddLocalStream(stream.getNativeMediaStream()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 959 | if (!ret) { |
| 960 | return false; |
| 961 | } |
| 962 | localStreams.add(stream); |
| 963 | return true; |
| 964 | } |
| 965 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 966 | /** |
| 967 | * Removes the given media stream from this peer connection. |
| 968 | * This method is not supported with SdpSemantics.UNIFIED_PLAN. Please use |
| 969 | * removeTrack instead. |
| 970 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 971 | public void removeStream(MediaStream stream) { |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 972 | nativeRemoveLocalStream(stream.getNativeMediaStream()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 973 | localStreams.remove(stream); |
| 974 | } |
| 975 | |
deadbeef | 7a24688 | 2017-08-09 08:40:10 -0700 | [diff] [blame] | 976 | /** |
| 977 | * Creates an RtpSender without a track. |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 978 | * |
| 979 | * <p>This method allows an application to cause the PeerConnection to negotiate |
deadbeef | 7a24688 | 2017-08-09 08:40:10 -0700 | [diff] [blame] | 980 | * sending/receiving a specific media type, but without having a track to |
| 981 | * send yet. |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 982 | * |
| 983 | * <p>When the application does want to begin sending a track, it can call |
deadbeef | 7a24688 | 2017-08-09 08:40:10 -0700 | [diff] [blame] | 984 | * RtpSender.setTrack, which doesn't require any additional SDP negotiation. |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 985 | * |
| 986 | * <p>Example use: |
deadbeef | 7a24688 | 2017-08-09 08:40:10 -0700 | [diff] [blame] | 987 | * <pre> |
| 988 | * {@code |
| 989 | * audioSender = pc.createSender("audio", "stream1"); |
| 990 | * videoSender = pc.createSender("video", "stream1"); |
| 991 | * // Do normal SDP offer/answer, which will kick off ICE/DTLS and negotiate |
| 992 | * // media parameters.... |
| 993 | * // Later, when the endpoint is ready to actually begin sending: |
| 994 | * audioSender.setTrack(audioTrack, false); |
| 995 | * videoSender.setTrack(videoTrack, false); |
| 996 | * } |
| 997 | * </pre> |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 998 | * <p>Note: This corresponds most closely to "addTransceiver" in the official |
deadbeef | 7a24688 | 2017-08-09 08:40:10 -0700 | [diff] [blame] | 999 | * WebRTC API, in that it creates a sender without a track. It was |
| 1000 | * implemented before addTransceiver because it provides useful |
| 1001 | * functionality, and properly implementing transceivers would have required |
| 1002 | * a great deal more work. |
| 1003 | * |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1004 | * <p>Note: This is only available with SdpSemantics.PLAN_B specified. Please use |
| 1005 | * addTransceiver instead. |
| 1006 | * |
deadbeef | 7a24688 | 2017-08-09 08:40:10 -0700 | [diff] [blame] | 1007 | * @param kind Corresponds to MediaStreamTrack kinds (must be "audio" or |
| 1008 | * "video"). |
| 1009 | * @param stream_id The ID of the MediaStream that this sender's track will |
| 1010 | * be associated with when SDP is applied to the remote |
| 1011 | * PeerConnection. If createSender is used to create an |
| 1012 | * audio and video sender that should be synchronized, they |
| 1013 | * should use the same stream ID. |
| 1014 | * @return A new RtpSender object if successful, or null otherwise. |
| 1015 | */ |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1016 | public RtpSender createSender(String kind, String stream_id) { |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1017 | RtpSender newSender = nativeCreateSender(kind, stream_id); |
| 1018 | if (newSender != null) { |
| 1019 | senders.add(newSender); |
deadbeef | ee524f7 | 2015-12-02 11:27:40 -0800 | [diff] [blame] | 1020 | } |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1021 | return newSender; |
deadbeef | ee524f7 | 2015-12-02 11:27:40 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1024 | /** |
| 1025 | * Gets all RtpSenders associated with this peer connection. |
| 1026 | * Note that calling getSenders will dispose of the senders previously |
| 1027 | * returned. |
| 1028 | */ |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 1029 | public List<RtpSender> getSenders() { |
| 1030 | for (RtpSender sender : senders) { |
| 1031 | sender.dispose(); |
| 1032 | } |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1033 | senders = nativeGetSenders(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 1034 | return Collections.unmodifiableList(senders); |
| 1035 | } |
| 1036 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1037 | /** |
| 1038 | * Gets all RtpReceivers associated with this peer connection. |
| 1039 | * Note that calling getReceivers will dispose of the receivers previously |
| 1040 | * returned. |
| 1041 | */ |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 1042 | public List<RtpReceiver> getReceivers() { |
| 1043 | for (RtpReceiver receiver : receivers) { |
| 1044 | receiver.dispose(); |
| 1045 | } |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1046 | receivers = nativeGetReceivers(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 1047 | return Collections.unmodifiableList(receivers); |
| 1048 | } |
| 1049 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1050 | /** |
| 1051 | * Gets all RtpTransceivers associated with this peer connection. |
| 1052 | * Note that calling getTransceivers will dispose of the transceivers previously |
| 1053 | * returned. |
| 1054 | * Note: This is only available with SdpSemantics.UNIFIED_PLAN specified. |
| 1055 | */ |
| 1056 | public List<RtpTransceiver> getTransceivers() { |
| 1057 | for (RtpTransceiver transceiver : transceivers) { |
| 1058 | transceiver.dispose(); |
| 1059 | } |
| 1060 | transceivers = nativeGetTransceivers(); |
| 1061 | return Collections.unmodifiableList(transceivers); |
| 1062 | } |
| 1063 | |
| 1064 | /** |
| 1065 | * Adds a new media stream track to be sent on this peer connection, and returns |
| 1066 | * the newly created RtpSender. If streamIds are specified, the RtpSender will |
| 1067 | * be associated with the streams specified in the streamIds list. |
| 1068 | * |
| 1069 | * @throws IllegalStateException if an error accors in C++ addTrack. |
| 1070 | * An error can occur if: |
| 1071 | * - A sender already exists for the track. |
| 1072 | * - The peer connection is closed. |
| 1073 | */ |
| 1074 | public RtpSender addTrack(MediaStreamTrack track) { |
| 1075 | return addTrack(track, Collections.emptyList()); |
| 1076 | } |
| 1077 | |
| 1078 | public RtpSender addTrack(MediaStreamTrack track, List<String> streamIds) { |
| 1079 | if (track == null || streamIds == null) { |
| 1080 | throw new NullPointerException("No MediaStreamTrack specified in addTrack."); |
| 1081 | } |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 1082 | RtpSender newSender = nativeAddTrack(track.getNativeMediaStreamTrack(), streamIds); |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1083 | if (newSender == null) { |
| 1084 | throw new IllegalStateException("C++ addTrack failed."); |
| 1085 | } |
| 1086 | senders.add(newSender); |
| 1087 | return newSender; |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * Stops sending media from sender. The sender will still appear in getSenders. Future |
| 1092 | * calls to createOffer will mark the m section for the corresponding transceiver as |
| 1093 | * receive only or inactive, as defined in JSEP. Returns true on success. |
| 1094 | */ |
| 1095 | public boolean removeTrack(RtpSender sender) { |
| 1096 | if (sender == null) { |
| 1097 | throw new NullPointerException("No RtpSender specified for removeTrack."); |
| 1098 | } |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 1099 | return nativeRemoveTrack(sender.getNativeRtpSender()); |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | /** |
| 1103 | * Creates a new RtpTransceiver and adds it to the set of transceivers. Adding a |
| 1104 | * transceiver will cause future calls to CreateOffer to add a media description |
| 1105 | * for the corresponding transceiver. |
| 1106 | * |
| 1107 | * <p>The initial value of |mid| in the returned transceiver is null. Setting a |
| 1108 | * new session description may change it to a non-null value. |
| 1109 | * |
| 1110 | * <p>https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver |
| 1111 | * |
| 1112 | * <p>If a MediaStreamTrack is specified then a transceiver will be added with a |
| 1113 | * sender set to transmit the given track. The kind |
| 1114 | * of the transceiver (and sender/receiver) will be derived from the kind of |
| 1115 | * the track. |
| 1116 | * |
| 1117 | * <p>If MediaType is specified then a transceiver will be added based upon that type. |
| 1118 | * This can be either MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO. |
| 1119 | * |
| 1120 | * <p>Optionally, an RtpTransceiverInit structure can be specified to configure |
| 1121 | * the transceiver from construction. If not specified, the transceiver will |
| 1122 | * default to having a direction of kSendRecv and not be part of any streams. |
| 1123 | * |
| 1124 | * <p>Note: These methods are only available with SdpSemantics.UNIFIED_PLAN specified. |
| 1125 | * @throws IllegalStateException if an error accors in C++ addTransceiver |
| 1126 | */ |
| 1127 | public RtpTransceiver addTransceiver(MediaStreamTrack track) { |
| 1128 | return addTransceiver(track, new RtpTransceiver.RtpTransceiverInit()); |
| 1129 | } |
| 1130 | |
| 1131 | public RtpTransceiver addTransceiver( |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 1132 | MediaStreamTrack track, @Nullable RtpTransceiver.RtpTransceiverInit init) { |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1133 | if (track == null) { |
| 1134 | throw new NullPointerException("No MediaStreamTrack specified for addTransceiver."); |
| 1135 | } |
| 1136 | if (init == null) { |
| 1137 | init = new RtpTransceiver.RtpTransceiverInit(); |
| 1138 | } |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 1139 | RtpTransceiver newTransceiver = |
| 1140 | nativeAddTransceiverWithTrack(track.getNativeMediaStreamTrack(), init); |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1141 | if (newTransceiver == null) { |
| 1142 | throw new IllegalStateException("C++ addTransceiver failed."); |
| 1143 | } |
| 1144 | transceivers.add(newTransceiver); |
| 1145 | return newTransceiver; |
| 1146 | } |
| 1147 | |
| 1148 | public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType) { |
| 1149 | return addTransceiver(mediaType, new RtpTransceiver.RtpTransceiverInit()); |
| 1150 | } |
| 1151 | |
| 1152 | public RtpTransceiver addTransceiver( |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 1153 | MediaStreamTrack.MediaType mediaType, @Nullable RtpTransceiver.RtpTransceiverInit init) { |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1154 | if (mediaType == null) { |
| 1155 | throw new NullPointerException("No MediaType specified for addTransceiver."); |
| 1156 | } |
| 1157 | if (init == null) { |
| 1158 | init = new RtpTransceiver.RtpTransceiverInit(); |
| 1159 | } |
| 1160 | RtpTransceiver newTransceiver = nativeAddTransceiverOfType(mediaType, init); |
| 1161 | if (newTransceiver == null) { |
| 1162 | throw new IllegalStateException("C++ addTransceiver failed."); |
| 1163 | } |
| 1164 | transceivers.add(newTransceiver); |
| 1165 | return newTransceiver; |
| 1166 | } |
| 1167 | |
deadbeef | 8221587 | 2017-04-18 10:27:51 -0700 | [diff] [blame] | 1168 | // Older, non-standard implementation of getStats. |
| 1169 | @Deprecated |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 1170 | public boolean getStats(StatsObserver observer, @Nullable MediaStreamTrack track) { |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 1171 | return nativeOldGetStats(observer, (track == null) ? 0 : track.getNativeMediaStreamTrack()); |
deadbeef | 8221587 | 2017-04-18 10:27:51 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1174 | /** |
| 1175 | * Gets stats using the new stats collection API, see webrtc/api/stats/. These |
| 1176 | * will replace old stats collection API when the new API has matured enough. |
| 1177 | */ |
deadbeef | 8221587 | 2017-04-18 10:27:51 -0700 | [diff] [blame] | 1178 | public void getStats(RTCStatsCollectorCallback callback) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1179 | nativeNewGetStats(callback); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1182 | /** |
| 1183 | * Limits the bandwidth allocated for all RTP streams sent by this |
| 1184 | * PeerConnection. Pass null to leave a value unchanged. |
| 1185 | */ |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1186 | public boolean setBitrate(Integer min, Integer current, Integer max) { |
| 1187 | return nativeSetBitrate(min, current, max); |
| 1188 | } |
zstein | d89b0bc | 2017-08-03 11:11:40 -0700 | [diff] [blame] | 1189 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1190 | /** |
| 1191 | * Starts recording an RTC event log. |
| 1192 | * |
| 1193 | * Ownership of the file is transfered to the native code. If an RTC event |
| 1194 | * log is already being recorded, it will be stopped and a new one will start |
| 1195 | * using the provided file. Logging will continue until the stopRtcEventLog |
| 1196 | * function is called. The max_size_bytes argument is ignored, it is added |
| 1197 | * for future use. |
| 1198 | */ |
ivoc | 0c6f0f6 | 2016-07-06 04:34:23 -0700 | [diff] [blame] | 1199 | public boolean startRtcEventLog(int file_descriptor, int max_size_bytes) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1200 | return nativeStartRtcEventLog(file_descriptor, max_size_bytes); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1203 | /** |
| 1204 | * Stops recording an RTC event log. If no RTC event log is currently being |
| 1205 | * recorded, this call will have no effect. |
| 1206 | */ |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 1207 | public void stopRtcEventLog() { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1208 | nativeStopRtcEventLog(); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1211 | // TODO(fischman): add support for DTMF-related methods once that API |
| 1212 | // stabilizes. |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1213 | public SignalingState signalingState() { |
| 1214 | return nativeSignalingState(); |
| 1215 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1216 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1217 | public IceConnectionState iceConnectionState() { |
| 1218 | return nativeIceConnectionState(); |
| 1219 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1220 | |
Jonas Olsson | f01d8c8 | 2018-11-08 15:19:04 +0100 | [diff] [blame] | 1221 | public PeerConnectionState connectionState() { |
| 1222 | return nativeConnectionState(); |
| 1223 | } |
| 1224 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1225 | public IceGatheringState iceGatheringState() { |
| 1226 | return nativeIceGatheringState(); |
| 1227 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1228 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1229 | public void close() { |
| 1230 | nativeClose(); |
| 1231 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1232 | |
deadbeef | 43697f6 | 2017-09-12 10:52:14 -0700 | [diff] [blame] | 1233 | /** |
| 1234 | * Free native resources associated with this PeerConnection instance. |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1235 | * |
deadbeef | 43697f6 | 2017-09-12 10:52:14 -0700 | [diff] [blame] | 1236 | * This method removes a reference count from the C++ PeerConnection object, |
| 1237 | * which should result in it being destroyed. It also calls equivalent |
| 1238 | * "dispose" methods on the Java objects attached to this PeerConnection |
| 1239 | * (streams, senders, receivers), such that their associated C++ objects |
| 1240 | * will also be destroyed. |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1241 | * |
| 1242 | * <p>Note that this method cannot be safely called from an observer callback |
deadbeef | 43697f6 | 2017-09-12 10:52:14 -0700 | [diff] [blame] | 1243 | * (PeerConnection.Observer, DataChannel.Observer, etc.). If you want to, for |
| 1244 | * example, destroy the PeerConnection after an "ICE failed" callback, you |
| 1245 | * must do this asynchronously (in other words, unwind the stack first). See |
| 1246 | * <a href="https://bugs.chromium.org/p/webrtc/issues/detail?id=3721">bug |
| 1247 | * 3721</a> for more details. |
| 1248 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1249 | public void dispose() { |
| 1250 | close(); |
| 1251 | for (MediaStream stream : localStreams) { |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 1252 | nativeRemoveLocalStream(stream.getNativeMediaStream()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1253 | stream.dispose(); |
| 1254 | } |
| 1255 | localStreams.clear(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 1256 | for (RtpSender sender : senders) { |
| 1257 | sender.dispose(); |
| 1258 | } |
| 1259 | senders.clear(); |
| 1260 | for (RtpReceiver receiver : receivers) { |
| 1261 | receiver.dispose(); |
| 1262 | } |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1263 | for (RtpTransceiver transceiver : transceivers) { |
| 1264 | transceiver.dispose(); |
| 1265 | } |
| 1266 | transceivers.clear(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 1267 | receivers.clear(); |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 1268 | nativeFreeOwnedPeerConnection(nativePeerConnection); |
| 1269 | } |
| 1270 | |
| 1271 | /** Returns a pointer to the native webrtc::PeerConnectionInterface. */ |
| 1272 | public long getNativePeerConnection() { |
| 1273 | return nativeGetNativePeerConnection(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 1276 | @CalledByNative |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 1277 | long getNativeOwnedPeerConnection() { |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 1278 | return nativePeerConnection; |
| 1279 | } |
| 1280 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1281 | public static long createNativePeerConnectionObserver(Observer observer) { |
| 1282 | return nativeCreatePeerConnectionObserver(observer); |
| 1283 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1284 | |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 1285 | private native long nativeGetNativePeerConnection(); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1286 | private native SessionDescription nativeGetLocalDescription(); |
| 1287 | private native SessionDescription nativeGetRemoteDescription(); |
Michael Iedema | 0213786 | 2018-10-09 15:30:01 +0200 | [diff] [blame] | 1288 | private native RtcCertificatePem nativeGetCertificate(); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1289 | private native DataChannel nativeCreateDataChannel(String label, DataChannel.Init init); |
| 1290 | private native void nativeCreateOffer(SdpObserver observer, MediaConstraints constraints); |
| 1291 | private native void nativeCreateAnswer(SdpObserver observer, MediaConstraints constraints); |
| 1292 | private native void nativeSetLocalDescription(SdpObserver observer, SessionDescription sdp); |
| 1293 | private native void nativeSetRemoteDescription(SdpObserver observer, SessionDescription sdp); |
| 1294 | private native void nativeSetAudioPlayout(boolean playout); |
| 1295 | private native void nativeSetAudioRecording(boolean recording); |
| 1296 | private native boolean nativeSetBitrate(Integer min, Integer current, Integer max); |
| 1297 | private native SignalingState nativeSignalingState(); |
| 1298 | private native IceConnectionState nativeIceConnectionState(); |
Jonas Olsson | f01d8c8 | 2018-11-08 15:19:04 +0100 | [diff] [blame] | 1299 | private native PeerConnectionState nativeConnectionState(); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1300 | private native IceGatheringState nativeIceGatheringState(); |
| 1301 | private native void nativeClose(); |
| 1302 | private static native long nativeCreatePeerConnectionObserver(Observer observer); |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 1303 | private static native void nativeFreeOwnedPeerConnection(long ownedPeerConnection); |
| 1304 | private native boolean nativeSetConfiguration(RTCConfiguration config); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1305 | private native boolean nativeAddIceCandidate( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1306 | String sdpMid, int sdpMLineIndex, String iceCandidateSdp); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1307 | private native boolean nativeRemoveIceCandidates(final IceCandidate[] candidates); |
| 1308 | private native boolean nativeAddLocalStream(long stream); |
| 1309 | private native void nativeRemoveLocalStream(long stream); |
| 1310 | private native boolean nativeOldGetStats(StatsObserver observer, long nativeTrack); |
| 1311 | private native void nativeNewGetStats(RTCStatsCollectorCallback callback); |
| 1312 | private native RtpSender nativeCreateSender(String kind, String stream_id); |
| 1313 | private native List<RtpSender> nativeGetSenders(); |
| 1314 | private native List<RtpReceiver> nativeGetReceivers(); |
Seth Hampson | c384e14 | 2018-03-06 15:47:10 -0800 | [diff] [blame] | 1315 | private native List<RtpTransceiver> nativeGetTransceivers(); |
| 1316 | private native RtpSender nativeAddTrack(long track, List<String> streamIds); |
| 1317 | private native boolean nativeRemoveTrack(long sender); |
| 1318 | private native RtpTransceiver nativeAddTransceiverWithTrack( |
| 1319 | long track, RtpTransceiver.RtpTransceiverInit init); |
| 1320 | private native RtpTransceiver nativeAddTransceiverOfType( |
| 1321 | MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 1322 | private native boolean nativeStartRtcEventLog(int file_descriptor, int max_size_bytes); |
| 1323 | private native void nativeStopRtcEventLog(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1324 | } |