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