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