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