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