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