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 | |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 344 | /** Java version of PeerConnectionInterface.RTCConfiguration */ |
| 345 | public static class RTCConfiguration { |
| 346 | public IceTransportsType iceTransportsType; |
| 347 | public List<IceServer> iceServers; |
| 348 | public BundlePolicy bundlePolicy; |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 349 | public RtcpMuxPolicy rtcpMuxPolicy; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 350 | public TcpCandidatePolicy tcpCandidatePolicy; |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 351 | public CandidateNetworkPolicy candidateNetworkPolicy; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 352 | public int audioJitterBufferMaxPackets; |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 353 | public boolean audioJitterBufferFastAccelerate; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 354 | public int iceConnectionReceivingTimeout; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 355 | public int iceBackupCandidatePairPingInterval; |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 356 | public KeyType keyType; |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 357 | public ContinualGatheringPolicy continualGatheringPolicy; |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 358 | public int iceCandidatePoolSize; |
Honghai Zhang | d78ecf7 | 2016-07-01 14:40:40 -0700 | [diff] [blame] | 359 | public boolean pruneTurnPorts; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 360 | public boolean presumeWritableWhenFullyRelayed; |
skvlad | 5107246 | 2017-02-02 11:50:14 -0800 | [diff] [blame] | 361 | public Integer iceCheckMinInterval; |
zhihuang | b09b3f9 | 2017-03-07 14:40:51 -0800 | [diff] [blame] | 362 | public boolean disableIPv6OnWifi; |
deadbeef | 28e2919 | 2017-07-27 09:14:38 -0700 | [diff] [blame] | 363 | // By default, PeerConnection will use a limited number of IPv6 network |
| 364 | // interfaces, in order to avoid too many ICE candidate pairs being created |
| 365 | // and delaying ICE completion. |
| 366 | // |
| 367 | // Can be set to Integer.MAX_VALUE to effectively disable the limit. |
| 368 | public int maxIPv6Networks; |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 369 | public IntervalRange iceRegatherIntervalRange; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 370 | |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 371 | // These values will be overridden by MediaStream constraints if deprecated constraints-based |
| 372 | // create peerconnection interface is used. |
| 373 | public boolean disableIpv6; |
| 374 | public boolean enableDscp; |
| 375 | public boolean enableCpuOveruseDetection; |
| 376 | public boolean enableRtpDataChannel; |
| 377 | public boolean suspendBelowMinBitrate; |
| 378 | public Integer screencastMinBitrate; |
| 379 | public Boolean combinedAudioVideoBwe; |
| 380 | public Boolean enableDtlsSrtp; |
Qingsi Wang | 9a5c6f8 | 2018-02-01 10:38:40 -0800 | [diff] [blame^] | 381 | // Use "Unknown" to represent no preference of adapter types, not the |
| 382 | // preference of adapters of unknown types. |
| 383 | public AdapterType networkPreference; |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 384 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 385 | // This is an optional wrapper for the C++ webrtc::TurnCustomizer. |
| 386 | public TurnCustomizer turnCustomizer; |
| 387 | |
deadbeef | 28e2919 | 2017-07-27 09:14:38 -0700 | [diff] [blame] | 388 | // TODO(deadbeef): Instead of duplicating the defaults here, we should do |
| 389 | // something to pick up the defaults from C++. The Objective-C equivalent |
| 390 | // of RTCConfiguration does that. |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 391 | public RTCConfiguration(List<IceServer> iceServers) { |
| 392 | iceTransportsType = IceTransportsType.ALL; |
| 393 | bundlePolicy = BundlePolicy.BALANCED; |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 394 | rtcpMuxPolicy = RtcpMuxPolicy.REQUIRE; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 395 | tcpCandidatePolicy = TcpCandidatePolicy.ENABLED; |
Sami Kalliomäki | 9828beb | 2017-10-26 16:21:22 +0200 | [diff] [blame] | 396 | candidateNetworkPolicy = CandidateNetworkPolicy.ALL; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 397 | this.iceServers = iceServers; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 398 | audioJitterBufferMaxPackets = 50; |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 399 | audioJitterBufferFastAccelerate = false; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 400 | iceConnectionReceivingTimeout = -1; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 401 | iceBackupCandidatePairPingInterval = -1; |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 402 | keyType = KeyType.ECDSA; |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 403 | continualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE; |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 404 | iceCandidatePoolSize = 0; |
Honghai Zhang | d78ecf7 | 2016-07-01 14:40:40 -0700 | [diff] [blame] | 405 | pruneTurnPorts = false; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 406 | presumeWritableWhenFullyRelayed = false; |
skvlad | 5107246 | 2017-02-02 11:50:14 -0800 | [diff] [blame] | 407 | iceCheckMinInterval = null; |
zhihuang | b09b3f9 | 2017-03-07 14:40:51 -0800 | [diff] [blame] | 408 | disableIPv6OnWifi = false; |
deadbeef | 28e2919 | 2017-07-27 09:14:38 -0700 | [diff] [blame] | 409 | maxIPv6Networks = 5; |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 410 | iceRegatherIntervalRange = null; |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 411 | disableIpv6 = false; |
| 412 | enableDscp = false; |
| 413 | enableCpuOveruseDetection = true; |
| 414 | enableRtpDataChannel = false; |
| 415 | suspendBelowMinBitrate = false; |
| 416 | screencastMinBitrate = null; |
| 417 | combinedAudioVideoBwe = null; |
| 418 | enableDtlsSrtp = null; |
Qingsi Wang | 9a5c6f8 | 2018-02-01 10:38:40 -0800 | [diff] [blame^] | 419 | networkPreference = AdapterType.UNKNOWN; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 420 | } |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 421 | |
| 422 | @CalledByNative("RTCConfiguration") |
| 423 | IceTransportsType getIceTransportsType() { |
| 424 | return iceTransportsType; |
| 425 | } |
| 426 | |
| 427 | @CalledByNative("RTCConfiguration") |
| 428 | List<IceServer> getIceServers() { |
| 429 | return iceServers; |
| 430 | } |
| 431 | |
| 432 | @CalledByNative("RTCConfiguration") |
| 433 | BundlePolicy getBundlePolicy() { |
| 434 | return bundlePolicy; |
| 435 | } |
| 436 | |
| 437 | @CalledByNative("RTCConfiguration") |
| 438 | RtcpMuxPolicy getRtcpMuxPolicy() { |
| 439 | return rtcpMuxPolicy; |
| 440 | } |
| 441 | |
| 442 | @CalledByNative("RTCConfiguration") |
| 443 | TcpCandidatePolicy getTcpCandidatePolicy() { |
| 444 | return tcpCandidatePolicy; |
| 445 | } |
| 446 | |
| 447 | @CalledByNative("RTCConfiguration") |
| 448 | CandidateNetworkPolicy getCandidateNetworkPolicy() { |
| 449 | return candidateNetworkPolicy; |
| 450 | } |
| 451 | |
| 452 | @CalledByNative("RTCConfiguration") |
| 453 | int getAudioJitterBufferMaxPackets() { |
| 454 | return audioJitterBufferMaxPackets; |
| 455 | } |
| 456 | |
| 457 | @CalledByNative("RTCConfiguration") |
| 458 | boolean getAudioJitterBufferFastAccelerate() { |
| 459 | return audioJitterBufferFastAccelerate; |
| 460 | } |
| 461 | |
| 462 | @CalledByNative("RTCConfiguration") |
| 463 | int getIceConnectionReceivingTimeout() { |
| 464 | return iceConnectionReceivingTimeout; |
| 465 | } |
| 466 | |
| 467 | @CalledByNative("RTCConfiguration") |
| 468 | int getIceBackupCandidatePairPingInterval() { |
| 469 | return iceBackupCandidatePairPingInterval; |
| 470 | } |
| 471 | |
| 472 | @CalledByNative("RTCConfiguration") |
| 473 | KeyType getKeyType() { |
| 474 | return keyType; |
| 475 | } |
| 476 | |
| 477 | @CalledByNative("RTCConfiguration") |
| 478 | ContinualGatheringPolicy getContinualGatheringPolicy() { |
| 479 | return continualGatheringPolicy; |
| 480 | } |
| 481 | |
| 482 | @CalledByNative("RTCConfiguration") |
| 483 | int getIceCandidatePoolSize() { |
| 484 | return iceCandidatePoolSize; |
| 485 | } |
| 486 | |
| 487 | @CalledByNative("RTCConfiguration") |
| 488 | boolean getPruneTurnPorts() { |
| 489 | return pruneTurnPorts; |
| 490 | } |
| 491 | |
| 492 | @CalledByNative("RTCConfiguration") |
| 493 | boolean getPresumeWritableWhenFullyRelayed() { |
| 494 | return presumeWritableWhenFullyRelayed; |
| 495 | } |
| 496 | |
| 497 | @CalledByNative("RTCConfiguration") |
| 498 | Integer getIceCheckMinInterval() { |
| 499 | return iceCheckMinInterval; |
| 500 | } |
| 501 | |
| 502 | @CalledByNative("RTCConfiguration") |
| 503 | boolean getDisableIPv6OnWifi() { |
| 504 | return disableIPv6OnWifi; |
| 505 | } |
| 506 | |
| 507 | @CalledByNative("RTCConfiguration") |
| 508 | int getMaxIPv6Networks() { |
| 509 | return maxIPv6Networks; |
| 510 | } |
| 511 | |
| 512 | @CalledByNative("RTCConfiguration") |
| 513 | IntervalRange getIceRegatherIntervalRange() { |
| 514 | return iceRegatherIntervalRange; |
| 515 | } |
| 516 | |
| 517 | @CalledByNative("RTCConfiguration") |
| 518 | TurnCustomizer getTurnCustomizer() { |
| 519 | return turnCustomizer; |
| 520 | } |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 521 | |
| 522 | @CalledByNative("RTCConfiguration") |
| 523 | boolean getDisableIpv6() { |
| 524 | return disableIpv6; |
| 525 | } |
| 526 | |
| 527 | @CalledByNative("RTCConfiguration") |
| 528 | boolean getEnableDscp() { |
| 529 | return enableDscp; |
| 530 | } |
| 531 | |
| 532 | @CalledByNative("RTCConfiguration") |
| 533 | boolean getEnableCpuOveruseDetection() { |
| 534 | return enableCpuOveruseDetection; |
| 535 | } |
| 536 | |
| 537 | @CalledByNative("RTCConfiguration") |
| 538 | boolean getEnableRtpDataChannel() { |
| 539 | return enableRtpDataChannel; |
| 540 | } |
| 541 | |
| 542 | @CalledByNative("RTCConfiguration") |
| 543 | boolean getSuspendBelowMinBitrate() { |
| 544 | return suspendBelowMinBitrate; |
| 545 | } |
| 546 | |
| 547 | @CalledByNative("RTCConfiguration") |
| 548 | Integer getScreencastMinBitrate() { |
| 549 | return screencastMinBitrate; |
| 550 | } |
| 551 | |
| 552 | @CalledByNative("RTCConfiguration") |
| 553 | Boolean getCombinedAudioVideoBwe() { |
| 554 | return combinedAudioVideoBwe; |
| 555 | } |
| 556 | |
| 557 | @CalledByNative("RTCConfiguration") |
| 558 | Boolean getEnableDtlsSrtp() { |
| 559 | return enableDtlsSrtp; |
| 560 | } |
Qingsi Wang | 9a5c6f8 | 2018-02-01 10:38:40 -0800 | [diff] [blame^] | 561 | |
| 562 | @CalledByNative("RTCConfiguration") |
| 563 | AdapterType getNetworkPreference() { |
| 564 | return networkPreference; |
| 565 | } |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 566 | }; |
| 567 | |
Magnus Jedvert | 6062f37 | 2017-11-16 16:53:12 +0100 | [diff] [blame] | 568 | private final List<MediaStream> localStreams = new ArrayList<>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 569 | private final long nativePeerConnection; |
Magnus Jedvert | 6062f37 | 2017-11-16 16:53:12 +0100 | [diff] [blame] | 570 | private List<RtpSender> senders = new ArrayList<>(); |
| 571 | private List<RtpReceiver> receivers = new ArrayList<>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 572 | |
Sami Kalliomäki | 1ece1ed | 2017-12-20 11:59:22 +0100 | [diff] [blame] | 573 | /** |
| 574 | * Wraps a PeerConnection created by the factory. Can be used by clients that want to implement |
| 575 | * their PeerConnection creation in JNI. |
| 576 | */ |
| 577 | public PeerConnection(NativePeerConnectionFactory factory) { |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 578 | this(factory.createNativePeerConnection()); |
Sami Kalliomäki | 1ece1ed | 2017-12-20 11:59:22 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 581 | PeerConnection(long nativePeerConnection) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 582 | this.nativePeerConnection = nativePeerConnection; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | // JsepInterface. |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 586 | public SessionDescription getLocalDescription() { |
| 587 | return nativeGetLocalDescription(); |
| 588 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 589 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 590 | public SessionDescription getRemoteDescription() { |
| 591 | return nativeGetRemoteDescription(); |
| 592 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 593 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 594 | public DataChannel createDataChannel(String label, DataChannel.Init init) { |
| 595 | return nativeCreateDataChannel(label, init); |
| 596 | } |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 597 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 598 | public void createOffer(SdpObserver observer, MediaConstraints constraints) { |
| 599 | nativeCreateOffer(observer, constraints); |
| 600 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 601 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 602 | public void createAnswer(SdpObserver observer, MediaConstraints constraints) { |
| 603 | nativeCreateAnswer(observer, constraints); |
| 604 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 605 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 606 | public void setLocalDescription(SdpObserver observer, SessionDescription sdp) { |
| 607 | nativeSetLocalDescription(observer, sdp); |
| 608 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 609 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 610 | public void setRemoteDescription(SdpObserver observer, SessionDescription sdp) { |
| 611 | nativeSetRemoteDescription(observer, sdp); |
| 612 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 613 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 614 | // True if remote audio should be played out. Defaults to true. |
| 615 | // Note that even if playout is enabled, streams will only be played out if |
| 616 | // the appropriate SDP is also applied. The main purpose of this API is to |
| 617 | // be able to control the exact time when audio playout starts. |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 618 | public void setAudioPlayout(boolean playout) { |
| 619 | nativeSetAudioPlayout(playout); |
| 620 | } |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 621 | |
| 622 | // True if local audio shall be recorded. Defaults to true. |
| 623 | // Note that even if recording is enabled, streams will only be recorded if |
| 624 | // the appropriate SDP is also applied. The main purpose of this API is to |
| 625 | // be able to control the exact time when audio recording starts. |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 626 | public void setAudioRecording(boolean recording) { |
| 627 | nativeSetAudioRecording(recording); |
| 628 | } |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 629 | |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 630 | public boolean setConfiguration(RTCConfiguration config) { |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 631 | return nativeSetConfiguration(config); |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 632 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 633 | |
| 634 | public boolean addIceCandidate(IceCandidate candidate) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 635 | return nativeAddIceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 638 | public boolean removeIceCandidates(final IceCandidate[] candidates) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 639 | return nativeRemoveIceCandidates(candidates); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 640 | } |
| 641 | |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 642 | public boolean addStream(MediaStream stream) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 643 | boolean ret = nativeAddLocalStream(stream.nativeStream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 644 | if (!ret) { |
| 645 | return false; |
| 646 | } |
| 647 | localStreams.add(stream); |
| 648 | return true; |
| 649 | } |
| 650 | |
| 651 | public void removeStream(MediaStream stream) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 652 | nativeRemoveLocalStream(stream.nativeStream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 653 | localStreams.remove(stream); |
| 654 | } |
| 655 | |
deadbeef | 7a24688 | 2017-08-09 08:40:10 -0700 | [diff] [blame] | 656 | /** |
| 657 | * Creates an RtpSender without a track. |
| 658 | * <p> |
| 659 | * This method allows an application to cause the PeerConnection to negotiate |
| 660 | * sending/receiving a specific media type, but without having a track to |
| 661 | * send yet. |
| 662 | * <p> |
| 663 | * When the application does want to begin sending a track, it can call |
| 664 | * RtpSender.setTrack, which doesn't require any additional SDP negotiation. |
| 665 | * <p> |
| 666 | * Example use: |
| 667 | * <pre> |
| 668 | * {@code |
| 669 | * audioSender = pc.createSender("audio", "stream1"); |
| 670 | * videoSender = pc.createSender("video", "stream1"); |
| 671 | * // Do normal SDP offer/answer, which will kick off ICE/DTLS and negotiate |
| 672 | * // media parameters.... |
| 673 | * // Later, when the endpoint is ready to actually begin sending: |
| 674 | * audioSender.setTrack(audioTrack, false); |
| 675 | * videoSender.setTrack(videoTrack, false); |
| 676 | * } |
| 677 | * </pre> |
| 678 | * Note: This corresponds most closely to "addTransceiver" in the official |
| 679 | * WebRTC API, in that it creates a sender without a track. It was |
| 680 | * implemented before addTransceiver because it provides useful |
| 681 | * functionality, and properly implementing transceivers would have required |
| 682 | * a great deal more work. |
| 683 | * |
| 684 | * @param kind Corresponds to MediaStreamTrack kinds (must be "audio" or |
| 685 | * "video"). |
| 686 | * @param stream_id The ID of the MediaStream that this sender's track will |
| 687 | * be associated with when SDP is applied to the remote |
| 688 | * PeerConnection. If createSender is used to create an |
| 689 | * audio and video sender that should be synchronized, they |
| 690 | * should use the same stream ID. |
| 691 | * @return A new RtpSender object if successful, or null otherwise. |
| 692 | */ |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 693 | public RtpSender createSender(String kind, String stream_id) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 694 | RtpSender new_sender = nativeCreateSender(kind, stream_id); |
deadbeef | ee524f7 | 2015-12-02 11:27:40 -0800 | [diff] [blame] | 695 | if (new_sender != null) { |
| 696 | senders.add(new_sender); |
| 697 | } |
| 698 | return new_sender; |
| 699 | } |
| 700 | |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 701 | // Note that calling getSenders will dispose of the senders previously |
| 702 | // returned (and same goes for getReceivers). |
| 703 | public List<RtpSender> getSenders() { |
| 704 | for (RtpSender sender : senders) { |
| 705 | sender.dispose(); |
| 706 | } |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 707 | senders = nativeGetSenders(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 708 | return Collections.unmodifiableList(senders); |
| 709 | } |
| 710 | |
| 711 | public List<RtpReceiver> getReceivers() { |
| 712 | for (RtpReceiver receiver : receivers) { |
| 713 | receiver.dispose(); |
| 714 | } |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 715 | receivers = nativeGetReceivers(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 716 | return Collections.unmodifiableList(receivers); |
| 717 | } |
| 718 | |
deadbeef | 8221587 | 2017-04-18 10:27:51 -0700 | [diff] [blame] | 719 | // Older, non-standard implementation of getStats. |
| 720 | @Deprecated |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 721 | public boolean getStats(StatsObserver observer, MediaStreamTrack track) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 722 | return nativeOldGetStats(observer, (track == null) ? 0 : track.nativeTrack); |
deadbeef | 8221587 | 2017-04-18 10:27:51 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | // Gets stats using the new stats collection API, see webrtc/api/stats/. These |
| 726 | // will replace old stats collection API when the new API has matured enough. |
| 727 | public void getStats(RTCStatsCollectorCallback callback) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 728 | nativeNewGetStats(callback); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 729 | } |
| 730 | |
zstein | d89b0bc | 2017-08-03 11:11:40 -0700 | [diff] [blame] | 731 | // Limits the bandwidth allocated for all RTP streams sent by this |
| 732 | // PeerConnection. Pass null to leave a value unchanged. |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 733 | public boolean setBitrate(Integer min, Integer current, Integer max) { |
| 734 | return nativeSetBitrate(min, current, max); |
| 735 | } |
zstein | d89b0bc | 2017-08-03 11:11:40 -0700 | [diff] [blame] | 736 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 737 | // Starts recording an RTC event log. Ownership of the file is transfered to |
| 738 | // the native code. If an RTC event log is already being recorded, it will be |
| 739 | // stopped and a new one will start using the provided file. Logging will |
| 740 | // continue until the stopRtcEventLog function is called. The max_size_bytes |
| 741 | // argument is ignored, it is added for future use. |
ivoc | 0c6f0f6 | 2016-07-06 04:34:23 -0700 | [diff] [blame] | 742 | public boolean startRtcEventLog(int file_descriptor, int max_size_bytes) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 743 | return nativeStartRtcEventLog(file_descriptor, max_size_bytes); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | // Stops recording an RTC event log. If no RTC event log is currently being |
| 747 | // recorded, this call will have no effect. |
| 748 | public void stopRtcEventLog() { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 749 | nativeStopRtcEventLog(); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 750 | } |
| 751 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 752 | // TODO(fischman): add support for DTMF-related methods once that API |
| 753 | // stabilizes. |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 754 | public SignalingState signalingState() { |
| 755 | return nativeSignalingState(); |
| 756 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 757 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 758 | public IceConnectionState iceConnectionState() { |
| 759 | return nativeIceConnectionState(); |
| 760 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 761 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 762 | public IceGatheringState iceGatheringState() { |
| 763 | return nativeIceGatheringState(); |
| 764 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 765 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 766 | public void close() { |
| 767 | nativeClose(); |
| 768 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 769 | |
deadbeef | 43697f6 | 2017-09-12 10:52:14 -0700 | [diff] [blame] | 770 | /** |
| 771 | * Free native resources associated with this PeerConnection instance. |
| 772 | * <p> |
| 773 | * This method removes a reference count from the C++ PeerConnection object, |
| 774 | * which should result in it being destroyed. It also calls equivalent |
| 775 | * "dispose" methods on the Java objects attached to this PeerConnection |
| 776 | * (streams, senders, receivers), such that their associated C++ objects |
| 777 | * will also be destroyed. |
| 778 | * <p> |
| 779 | * Note that this method cannot be safely called from an observer callback |
| 780 | * (PeerConnection.Observer, DataChannel.Observer, etc.). If you want to, for |
| 781 | * example, destroy the PeerConnection after an "ICE failed" callback, you |
| 782 | * must do this asynchronously (in other words, unwind the stack first). See |
| 783 | * <a href="https://bugs.chromium.org/p/webrtc/issues/detail?id=3721">bug |
| 784 | * 3721</a> for more details. |
| 785 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 786 | public void dispose() { |
| 787 | close(); |
| 788 | for (MediaStream stream : localStreams) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 789 | nativeRemoveLocalStream(stream.nativeStream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 790 | stream.dispose(); |
| 791 | } |
| 792 | localStreams.clear(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 793 | for (RtpSender sender : senders) { |
| 794 | sender.dispose(); |
| 795 | } |
| 796 | senders.clear(); |
| 797 | for (RtpReceiver receiver : receivers) { |
| 798 | receiver.dispose(); |
| 799 | } |
| 800 | receivers.clear(); |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 801 | nativeFreeOwnedPeerConnection(nativePeerConnection); |
| 802 | } |
| 803 | |
| 804 | /** Returns a pointer to the native webrtc::PeerConnectionInterface. */ |
| 805 | public long getNativePeerConnection() { |
| 806 | return nativeGetNativePeerConnection(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 809 | @CalledByNative |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 810 | long getNativeOwnedPeerConnection() { |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 811 | return nativePeerConnection; |
| 812 | } |
| 813 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 814 | public static long createNativePeerConnectionObserver(Observer observer) { |
| 815 | return nativeCreatePeerConnectionObserver(observer); |
| 816 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 817 | |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 818 | private native long nativeGetNativePeerConnection(); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 819 | private native SessionDescription nativeGetLocalDescription(); |
| 820 | private native SessionDescription nativeGetRemoteDescription(); |
| 821 | private native DataChannel nativeCreateDataChannel(String label, DataChannel.Init init); |
| 822 | private native void nativeCreateOffer(SdpObserver observer, MediaConstraints constraints); |
| 823 | private native void nativeCreateAnswer(SdpObserver observer, MediaConstraints constraints); |
| 824 | private native void nativeSetLocalDescription(SdpObserver observer, SessionDescription sdp); |
| 825 | private native void nativeSetRemoteDescription(SdpObserver observer, SessionDescription sdp); |
| 826 | private native void nativeSetAudioPlayout(boolean playout); |
| 827 | private native void nativeSetAudioRecording(boolean recording); |
| 828 | private native boolean nativeSetBitrate(Integer min, Integer current, Integer max); |
| 829 | private native SignalingState nativeSignalingState(); |
| 830 | private native IceConnectionState nativeIceConnectionState(); |
| 831 | private native IceGatheringState nativeIceGatheringState(); |
| 832 | private native void nativeClose(); |
| 833 | private static native long nativeCreatePeerConnectionObserver(Observer observer); |
Sami Kalliomäki | ce5c19a | 2018-01-15 09:28:34 +0100 | [diff] [blame] | 834 | private static native void nativeFreeOwnedPeerConnection(long ownedPeerConnection); |
| 835 | private native boolean nativeSetConfiguration(RTCConfiguration config); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 836 | private native boolean nativeAddIceCandidate( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 837 | String sdpMid, int sdpMLineIndex, String iceCandidateSdp); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 838 | private native boolean nativeRemoveIceCandidates(final IceCandidate[] candidates); |
| 839 | private native boolean nativeAddLocalStream(long stream); |
| 840 | private native void nativeRemoveLocalStream(long stream); |
| 841 | private native boolean nativeOldGetStats(StatsObserver observer, long nativeTrack); |
| 842 | private native void nativeNewGetStats(RTCStatsCollectorCallback callback); |
| 843 | private native RtpSender nativeCreateSender(String kind, String stream_id); |
| 844 | private native List<RtpSender> nativeGetSenders(); |
| 845 | private native List<RtpReceiver> nativeGetReceivers(); |
| 846 | private native boolean nativeStartRtcEventLog(int file_descriptor, int max_size_bytes); |
| 847 | private native void nativeStopRtcEventLog(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 848 | } |