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 | */ |
| 23 | public class PeerConnection { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 24 | /** Tracks PeerConnectionInterface::IceGatheringState */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 25 | public enum IceGatheringState { |
| 26 | NEW, |
| 27 | GATHERING, |
| 28 | COMPLETE; |
| 29 | |
| 30 | @CalledByNative("IceGatheringState") |
| 31 | static IceGatheringState fromNativeIndex(int nativeIndex) { |
| 32 | return values()[nativeIndex]; |
| 33 | } |
| 34 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | |
| 36 | /** Tracks PeerConnectionInterface::IceConnectionState */ |
| 37 | public enum IceConnectionState { |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 38 | NEW, |
| 39 | CHECKING, |
| 40 | CONNECTED, |
| 41 | COMPLETED, |
| 42 | FAILED, |
| 43 | DISCONNECTED, |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 44 | CLOSED; |
| 45 | |
| 46 | @CalledByNative("IceConnectionState") |
| 47 | static IceConnectionState fromNativeIndex(int nativeIndex) { |
| 48 | return values()[nativeIndex]; |
| 49 | } |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 50 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 52 | /** Tracks PeerConnectionInterface::TlsCertPolicy */ |
| 53 | public enum TlsCertPolicy { |
| 54 | TLS_CERT_POLICY_SECURE, |
| 55 | TLS_CERT_POLICY_INSECURE_NO_CHECK, |
| 56 | } |
| 57 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | /** Tracks PeerConnectionInterface::SignalingState */ |
| 59 | public enum SignalingState { |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 60 | STABLE, |
| 61 | HAVE_LOCAL_OFFER, |
| 62 | HAVE_LOCAL_PRANSWER, |
| 63 | HAVE_REMOTE_OFFER, |
| 64 | HAVE_REMOTE_PRANSWER, |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 65 | CLOSED; |
| 66 | |
| 67 | @CalledByNative("SignalingState") |
| 68 | static SignalingState fromNativeIndex(int nativeIndex) { |
| 69 | return values()[nativeIndex]; |
| 70 | } |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 71 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | |
| 73 | /** Java version of PeerConnectionObserver. */ |
| 74 | public static interface Observer { |
| 75 | /** Triggered when the SignalingState changes. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 76 | @CalledByNative("Observer") void onSignalingChange(SignalingState newState); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 77 | |
| 78 | /** Triggered when the IceConnectionState changes. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 79 | @CalledByNative("Observer") void onIceConnectionChange(IceConnectionState newState); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 81 | /** Triggered when the ICE connection receiving status changes. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 82 | @CalledByNative("Observer") void onIceConnectionReceivingChange(boolean receiving); |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 83 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | /** Triggered when the IceGatheringState changes. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 85 | @CalledByNative("Observer") void onIceGatheringChange(IceGatheringState newState); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | |
| 87 | /** Triggered when a new ICE candidate has been found. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 88 | @CalledByNative("Observer") void onIceCandidate(IceCandidate candidate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 90 | /** Triggered when some ICE candidates have been removed. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 91 | @CalledByNative("Observer") void onIceCandidatesRemoved(IceCandidate[] candidates); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 92 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | /** Triggered when media is received on a new stream from remote peer. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 94 | @CalledByNative("Observer") void onAddStream(MediaStream stream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | |
| 96 | /** Triggered when a remote peer close a stream. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 97 | @CalledByNative("Observer") void onRemoveStream(MediaStream stream); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 98 | |
| 99 | /** Triggered when a remote peer opens a DataChannel. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 100 | @CalledByNative("Observer") void onDataChannel(DataChannel dataChannel); |
fischman@webrtc.org | d7568a0 | 2014-01-13 22:04:12 +0000 | [diff] [blame] | 101 | |
| 102 | /** Triggered when renegotiation is necessary. */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 103 | @CalledByNative("Observer") void onRenegotiationNeeded(); |
zhihuang | dcccda7 | 2016-12-21 14:08:03 -0800 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Triggered when a new track is signaled by the remote peer, as a result of |
| 107 | * setRemoteDescription. |
| 108 | */ |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 109 | @CalledByNative("Observer") void onAddTrack(RtpReceiver receiver, MediaStream[] mediaStreams); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** Java version of PeerConnectionInterface.IceServer. */ |
| 113 | public static class IceServer { |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 114 | // List of URIs associated with this server. Valid formats are described |
| 115 | // in RFC7064 and RFC7065, and more may be added in the future. The "host" |
| 116 | // 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] | 117 | @Deprecated public final String uri; |
| 118 | public final List<String> urls; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | public final String username; |
| 120 | public final String password; |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 121 | public final TlsCertPolicy tlsCertPolicy; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 123 | // If the URIs in |urls| only contain IP addresses, this field can be used |
| 124 | // to indicate the hostname, which may be necessary for TLS (using the SNI |
| 125 | // extension). If |urls| itself contains the hostname, this isn't |
| 126 | // necessary. |
| 127 | public final String hostname; |
| 128 | |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 129 | // List of protocols to be used in the TLS ALPN extension. |
| 130 | public final List<String> tlsAlpnProtocols; |
| 131 | |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 132 | // List of elliptic curves to be used in the TLS elliptic curves extension. |
| 133 | // Only curve names supported by OpenSSL should be used (eg. "P-256","X25519"). |
| 134 | public final List<String> tlsEllipticCurves; |
| 135 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 136 | /** Convenience constructor for STUN servers. */ |
Diogo Real | 05ea2b3 | 2017-08-31 00:12:58 -0700 | [diff] [blame] | 137 | @Deprecated |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | public IceServer(String uri) { |
| 139 | this(uri, "", ""); |
| 140 | } |
| 141 | |
Diogo Real | 05ea2b3 | 2017-08-31 00:12:58 -0700 | [diff] [blame] | 142 | @Deprecated |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | public IceServer(String uri, String username, String password) { |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 144 | this(uri, username, password, TlsCertPolicy.TLS_CERT_POLICY_SECURE); |
| 145 | } |
| 146 | |
Diogo Real | 05ea2b3 | 2017-08-31 00:12:58 -0700 | [diff] [blame] | 147 | @Deprecated |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 148 | public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy) { |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 149 | this(uri, username, password, tlsCertPolicy, ""); |
| 150 | } |
| 151 | |
Diogo Real | 05ea2b3 | 2017-08-31 00:12:58 -0700 | [diff] [blame] | 152 | @Deprecated |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 153 | public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy, |
| 154 | String hostname) { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 155 | this(uri, Collections.singletonList(uri), username, password, tlsCertPolicy, hostname, null, |
| 156 | null); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 157 | } |
| 158 | |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 159 | private IceServer(String uri, List<String> urls, String username, String password, |
| 160 | TlsCertPolicy tlsCertPolicy, String hostname, List<String> tlsAlpnProtocols, |
| 161 | List<String> tlsEllipticCurves) { |
| 162 | if (uri == null || urls == null || urls.isEmpty()) { |
| 163 | throw new IllegalArgumentException("uri == null || urls == null || urls.isEmpty()"); |
| 164 | } |
| 165 | for (String it : urls) { |
| 166 | if (it == null) { |
| 167 | throw new IllegalArgumentException("urls element is null: " + urls); |
| 168 | } |
| 169 | } |
| 170 | if (username == null) { |
| 171 | throw new IllegalArgumentException("username == null"); |
| 172 | } |
| 173 | if (password == null) { |
| 174 | throw new IllegalArgumentException("password == null"); |
| 175 | } |
| 176 | if (hostname == null) { |
| 177 | throw new IllegalArgumentException("hostname == null"); |
| 178 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 179 | this.uri = uri; |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 180 | this.urls = urls; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 181 | this.username = username; |
| 182 | this.password = password; |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 183 | this.tlsCertPolicy = tlsCertPolicy; |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 184 | this.hostname = hostname; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 185 | this.tlsAlpnProtocols = tlsAlpnProtocols; |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 186 | this.tlsEllipticCurves = tlsEllipticCurves; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Sami Kalliomäki | bde473e | 2017-10-30 13:34:41 +0100 | [diff] [blame] | 189 | @Override |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 190 | public String toString() { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 191 | return urls + " [" + username + ":" + password + "] [" + tlsCertPolicy + "] [" + hostname |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 192 | + "] [" + tlsAlpnProtocols + "] [" + tlsEllipticCurves + "]"; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | public static Builder builder(String uri) { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 196 | return new Builder(Collections.singletonList(uri)); |
| 197 | } |
| 198 | |
| 199 | public static Builder builder(List<String> urls) { |
| 200 | return new Builder(urls); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | public static class Builder { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 204 | private final List<String> urls; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 205 | private String username = ""; |
| 206 | private String password = ""; |
| 207 | private TlsCertPolicy tlsCertPolicy = TlsCertPolicy.TLS_CERT_POLICY_SECURE; |
| 208 | private String hostname = ""; |
| 209 | private List<String> tlsAlpnProtocols; |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 210 | private List<String> tlsEllipticCurves; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 211 | |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 212 | private Builder(List<String> urls) { |
| 213 | if (urls == null || urls.isEmpty()) { |
| 214 | throw new IllegalArgumentException("urls == null || urls.isEmpty(): " + urls); |
| 215 | } |
| 216 | this.urls = urls; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | public Builder setUsername(String username) { |
| 220 | this.username = username; |
| 221 | return this; |
| 222 | } |
| 223 | |
| 224 | public Builder setPassword(String password) { |
| 225 | this.password = password; |
| 226 | return this; |
| 227 | } |
| 228 | |
| 229 | public Builder setTlsCertPolicy(TlsCertPolicy tlsCertPolicy) { |
| 230 | this.tlsCertPolicy = tlsCertPolicy; |
| 231 | return this; |
| 232 | } |
| 233 | |
| 234 | public Builder setHostname(String hostname) { |
| 235 | this.hostname = hostname; |
| 236 | return this; |
| 237 | } |
| 238 | |
| 239 | public Builder setTlsAlpnProtocols(List<String> tlsAlpnProtocols) { |
| 240 | this.tlsAlpnProtocols = tlsAlpnProtocols; |
| 241 | return this; |
| 242 | } |
| 243 | |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 244 | public Builder setTlsEllipticCurves(List<String> tlsEllipticCurves) { |
| 245 | this.tlsEllipticCurves = tlsEllipticCurves; |
| 246 | return this; |
| 247 | } |
| 248 | |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 249 | public IceServer createIceServer() { |
korniltsev.anatoly | 0ea0310 | 2017-09-11 06:41:38 -0700 | [diff] [blame] | 250 | return new IceServer(urls.get(0), urls, username, password, tlsCertPolicy, hostname, |
| 251 | tlsAlpnProtocols, tlsEllipticCurves); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 252 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | } |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 254 | |
| 255 | @CalledByNative("IceServer") |
| 256 | List<String> getUrls() { |
| 257 | return urls; |
| 258 | } |
| 259 | |
| 260 | @CalledByNative("IceServer") |
| 261 | String getUsername() { |
| 262 | return username; |
| 263 | } |
| 264 | |
| 265 | @CalledByNative("IceServer") |
| 266 | String getPassword() { |
| 267 | return password; |
| 268 | } |
| 269 | |
| 270 | @CalledByNative("IceServer") |
| 271 | TlsCertPolicy getTlsCertPolicy() { |
| 272 | return tlsCertPolicy; |
| 273 | } |
| 274 | |
| 275 | @CalledByNative("IceServer") |
| 276 | String getHostname() { |
| 277 | return hostname; |
| 278 | } |
| 279 | |
| 280 | @CalledByNative("IceServer") |
| 281 | List<String> getTlsAlpnProtocols() { |
| 282 | return tlsAlpnProtocols; |
| 283 | } |
| 284 | |
| 285 | @CalledByNative("IceServer") |
| 286 | List<String> getTlsEllipticCurves() { |
| 287 | return tlsEllipticCurves; |
| 288 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 291 | /** Java version of PeerConnectionInterface.IceTransportsType */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 292 | public enum IceTransportsType { NONE, RELAY, NOHOST, ALL } |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 293 | |
| 294 | /** Java version of PeerConnectionInterface.BundlePolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 295 | public enum BundlePolicy { BALANCED, MAXBUNDLE, MAXCOMPAT } |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 296 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 297 | /** Java version of PeerConnectionInterface.RtcpMuxPolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 298 | public enum RtcpMuxPolicy { NEGOTIATE, REQUIRE } |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 299 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 300 | /** Java version of PeerConnectionInterface.TcpCandidatePolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 301 | public enum TcpCandidatePolicy { ENABLED, DISABLED } |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 302 | |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 303 | /** Java version of PeerConnectionInterface.CandidateNetworkPolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 304 | public enum CandidateNetworkPolicy { ALL, LOW_COST } |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 305 | |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 306 | /** Java version of rtc::KeyType */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 307 | public enum KeyType { RSA, ECDSA } |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 308 | |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 309 | /** Java version of PeerConnectionInterface.ContinualGatheringPolicy */ |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 310 | public enum ContinualGatheringPolicy { GATHER_ONCE, GATHER_CONTINUALLY } |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 311 | |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 312 | /** Java version of rtc::IntervalRange */ |
| 313 | public static class IntervalRange { |
| 314 | private final int min; |
| 315 | private final int max; |
| 316 | |
| 317 | public IntervalRange(int min, int max) { |
| 318 | this.min = min; |
| 319 | this.max = max; |
| 320 | } |
| 321 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 322 | @CalledByNative("IntervalRange") |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 323 | public int getMin() { |
| 324 | return min; |
| 325 | } |
| 326 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 327 | @CalledByNative("IntervalRange") |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 328 | public int getMax() { |
| 329 | return max; |
| 330 | } |
| 331 | } |
| 332 | |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 333 | /** Java version of PeerConnectionInterface.RTCConfiguration */ |
| 334 | public static class RTCConfiguration { |
| 335 | public IceTransportsType iceTransportsType; |
| 336 | public List<IceServer> iceServers; |
| 337 | public BundlePolicy bundlePolicy; |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 338 | public RtcpMuxPolicy rtcpMuxPolicy; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 339 | public TcpCandidatePolicy tcpCandidatePolicy; |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 340 | public CandidateNetworkPolicy candidateNetworkPolicy; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 341 | public int audioJitterBufferMaxPackets; |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 342 | public boolean audioJitterBufferFastAccelerate; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 343 | public int iceConnectionReceivingTimeout; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 344 | public int iceBackupCandidatePairPingInterval; |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 345 | public KeyType keyType; |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 346 | public ContinualGatheringPolicy continualGatheringPolicy; |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 347 | public int iceCandidatePoolSize; |
Honghai Zhang | d78ecf7 | 2016-07-01 14:40:40 -0700 | [diff] [blame] | 348 | public boolean pruneTurnPorts; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 349 | public boolean presumeWritableWhenFullyRelayed; |
skvlad | 5107246 | 2017-02-02 11:50:14 -0800 | [diff] [blame] | 350 | public Integer iceCheckMinInterval; |
zhihuang | b09b3f9 | 2017-03-07 14:40:51 -0800 | [diff] [blame] | 351 | public boolean disableIPv6OnWifi; |
deadbeef | 28e2919 | 2017-07-27 09:14:38 -0700 | [diff] [blame] | 352 | // By default, PeerConnection will use a limited number of IPv6 network |
| 353 | // interfaces, in order to avoid too many ICE candidate pairs being created |
| 354 | // and delaying ICE completion. |
| 355 | // |
| 356 | // Can be set to Integer.MAX_VALUE to effectively disable the limit. |
| 357 | public int maxIPv6Networks; |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 358 | public IntervalRange iceRegatherIntervalRange; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 359 | |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 360 | // These values will be overridden by MediaStream constraints if deprecated constraints-based |
| 361 | // create peerconnection interface is used. |
| 362 | public boolean disableIpv6; |
| 363 | public boolean enableDscp; |
| 364 | public boolean enableCpuOveruseDetection; |
| 365 | public boolean enableRtpDataChannel; |
| 366 | public boolean suspendBelowMinBitrate; |
| 367 | public Integer screencastMinBitrate; |
| 368 | public Boolean combinedAudioVideoBwe; |
| 369 | public Boolean enableDtlsSrtp; |
| 370 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 371 | // This is an optional wrapper for the C++ webrtc::TurnCustomizer. |
| 372 | public TurnCustomizer turnCustomizer; |
| 373 | |
deadbeef | 28e2919 | 2017-07-27 09:14:38 -0700 | [diff] [blame] | 374 | // TODO(deadbeef): Instead of duplicating the defaults here, we should do |
| 375 | // something to pick up the defaults from C++. The Objective-C equivalent |
| 376 | // of RTCConfiguration does that. |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 377 | public RTCConfiguration(List<IceServer> iceServers) { |
| 378 | iceTransportsType = IceTransportsType.ALL; |
| 379 | bundlePolicy = BundlePolicy.BALANCED; |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 380 | rtcpMuxPolicy = RtcpMuxPolicy.REQUIRE; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 381 | tcpCandidatePolicy = TcpCandidatePolicy.ENABLED; |
Sami Kalliomäki | 9828beb | 2017-10-26 16:21:22 +0200 | [diff] [blame] | 382 | candidateNetworkPolicy = CandidateNetworkPolicy.ALL; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 383 | this.iceServers = iceServers; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 384 | audioJitterBufferMaxPackets = 50; |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 385 | audioJitterBufferFastAccelerate = false; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 386 | iceConnectionReceivingTimeout = -1; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 387 | iceBackupCandidatePairPingInterval = -1; |
glaznev | 97579a4 | 2015-09-01 11:31:27 -0700 | [diff] [blame] | 388 | keyType = KeyType.ECDSA; |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 389 | continualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE; |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 390 | iceCandidatePoolSize = 0; |
Honghai Zhang | d78ecf7 | 2016-07-01 14:40:40 -0700 | [diff] [blame] | 391 | pruneTurnPorts = false; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 392 | presumeWritableWhenFullyRelayed = false; |
skvlad | 5107246 | 2017-02-02 11:50:14 -0800 | [diff] [blame] | 393 | iceCheckMinInterval = null; |
zhihuang | b09b3f9 | 2017-03-07 14:40:51 -0800 | [diff] [blame] | 394 | disableIPv6OnWifi = false; |
deadbeef | 28e2919 | 2017-07-27 09:14:38 -0700 | [diff] [blame] | 395 | maxIPv6Networks = 5; |
Steve Anton | d960a0c | 2017-07-17 12:33:07 -0700 | [diff] [blame] | 396 | iceRegatherIntervalRange = null; |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 397 | disableIpv6 = false; |
| 398 | enableDscp = false; |
| 399 | enableCpuOveruseDetection = true; |
| 400 | enableRtpDataChannel = false; |
| 401 | suspendBelowMinBitrate = false; |
| 402 | screencastMinBitrate = null; |
| 403 | combinedAudioVideoBwe = null; |
| 404 | enableDtlsSrtp = null; |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 405 | } |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 406 | |
| 407 | @CalledByNative("RTCConfiguration") |
| 408 | IceTransportsType getIceTransportsType() { |
| 409 | return iceTransportsType; |
| 410 | } |
| 411 | |
| 412 | @CalledByNative("RTCConfiguration") |
| 413 | List<IceServer> getIceServers() { |
| 414 | return iceServers; |
| 415 | } |
| 416 | |
| 417 | @CalledByNative("RTCConfiguration") |
| 418 | BundlePolicy getBundlePolicy() { |
| 419 | return bundlePolicy; |
| 420 | } |
| 421 | |
| 422 | @CalledByNative("RTCConfiguration") |
| 423 | RtcpMuxPolicy getRtcpMuxPolicy() { |
| 424 | return rtcpMuxPolicy; |
| 425 | } |
| 426 | |
| 427 | @CalledByNative("RTCConfiguration") |
| 428 | TcpCandidatePolicy getTcpCandidatePolicy() { |
| 429 | return tcpCandidatePolicy; |
| 430 | } |
| 431 | |
| 432 | @CalledByNative("RTCConfiguration") |
| 433 | CandidateNetworkPolicy getCandidateNetworkPolicy() { |
| 434 | return candidateNetworkPolicy; |
| 435 | } |
| 436 | |
| 437 | @CalledByNative("RTCConfiguration") |
| 438 | int getAudioJitterBufferMaxPackets() { |
| 439 | return audioJitterBufferMaxPackets; |
| 440 | } |
| 441 | |
| 442 | @CalledByNative("RTCConfiguration") |
| 443 | boolean getAudioJitterBufferFastAccelerate() { |
| 444 | return audioJitterBufferFastAccelerate; |
| 445 | } |
| 446 | |
| 447 | @CalledByNative("RTCConfiguration") |
| 448 | int getIceConnectionReceivingTimeout() { |
| 449 | return iceConnectionReceivingTimeout; |
| 450 | } |
| 451 | |
| 452 | @CalledByNative("RTCConfiguration") |
| 453 | int getIceBackupCandidatePairPingInterval() { |
| 454 | return iceBackupCandidatePairPingInterval; |
| 455 | } |
| 456 | |
| 457 | @CalledByNative("RTCConfiguration") |
| 458 | KeyType getKeyType() { |
| 459 | return keyType; |
| 460 | } |
| 461 | |
| 462 | @CalledByNative("RTCConfiguration") |
| 463 | ContinualGatheringPolicy getContinualGatheringPolicy() { |
| 464 | return continualGatheringPolicy; |
| 465 | } |
| 466 | |
| 467 | @CalledByNative("RTCConfiguration") |
| 468 | int getIceCandidatePoolSize() { |
| 469 | return iceCandidatePoolSize; |
| 470 | } |
| 471 | |
| 472 | @CalledByNative("RTCConfiguration") |
| 473 | boolean getPruneTurnPorts() { |
| 474 | return pruneTurnPorts; |
| 475 | } |
| 476 | |
| 477 | @CalledByNative("RTCConfiguration") |
| 478 | boolean getPresumeWritableWhenFullyRelayed() { |
| 479 | return presumeWritableWhenFullyRelayed; |
| 480 | } |
| 481 | |
| 482 | @CalledByNative("RTCConfiguration") |
| 483 | Integer getIceCheckMinInterval() { |
| 484 | return iceCheckMinInterval; |
| 485 | } |
| 486 | |
| 487 | @CalledByNative("RTCConfiguration") |
| 488 | boolean getDisableIPv6OnWifi() { |
| 489 | return disableIPv6OnWifi; |
| 490 | } |
| 491 | |
| 492 | @CalledByNative("RTCConfiguration") |
| 493 | int getMaxIPv6Networks() { |
| 494 | return maxIPv6Networks; |
| 495 | } |
| 496 | |
| 497 | @CalledByNative("RTCConfiguration") |
| 498 | IntervalRange getIceRegatherIntervalRange() { |
| 499 | return iceRegatherIntervalRange; |
| 500 | } |
| 501 | |
| 502 | @CalledByNative("RTCConfiguration") |
| 503 | TurnCustomizer getTurnCustomizer() { |
| 504 | return turnCustomizer; |
| 505 | } |
Sami Kalliomäki | e8b26cd | 2017-12-19 12:51:53 +0100 | [diff] [blame] | 506 | |
| 507 | @CalledByNative("RTCConfiguration") |
| 508 | boolean getDisableIpv6() { |
| 509 | return disableIpv6; |
| 510 | } |
| 511 | |
| 512 | @CalledByNative("RTCConfiguration") |
| 513 | boolean getEnableDscp() { |
| 514 | return enableDscp; |
| 515 | } |
| 516 | |
| 517 | @CalledByNative("RTCConfiguration") |
| 518 | boolean getEnableCpuOveruseDetection() { |
| 519 | return enableCpuOveruseDetection; |
| 520 | } |
| 521 | |
| 522 | @CalledByNative("RTCConfiguration") |
| 523 | boolean getEnableRtpDataChannel() { |
| 524 | return enableRtpDataChannel; |
| 525 | } |
| 526 | |
| 527 | @CalledByNative("RTCConfiguration") |
| 528 | boolean getSuspendBelowMinBitrate() { |
| 529 | return suspendBelowMinBitrate; |
| 530 | } |
| 531 | |
| 532 | @CalledByNative("RTCConfiguration") |
| 533 | Integer getScreencastMinBitrate() { |
| 534 | return screencastMinBitrate; |
| 535 | } |
| 536 | |
| 537 | @CalledByNative("RTCConfiguration") |
| 538 | Boolean getCombinedAudioVideoBwe() { |
| 539 | return combinedAudioVideoBwe; |
| 540 | } |
| 541 | |
| 542 | @CalledByNative("RTCConfiguration") |
| 543 | Boolean getEnableDtlsSrtp() { |
| 544 | return enableDtlsSrtp; |
| 545 | } |
Jiayang Liu | cac1b38 | 2015-04-30 12:35:24 -0700 | [diff] [blame] | 546 | }; |
| 547 | |
Magnus Jedvert | 6062f37 | 2017-11-16 16:53:12 +0100 | [diff] [blame] | 548 | private final List<MediaStream> localStreams = new ArrayList<>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 549 | private final long nativePeerConnection; |
| 550 | private final long nativeObserver; |
Magnus Jedvert | 6062f37 | 2017-11-16 16:53:12 +0100 | [diff] [blame] | 551 | private List<RtpSender> senders = new ArrayList<>(); |
| 552 | private List<RtpReceiver> receivers = new ArrayList<>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 553 | |
| 554 | PeerConnection(long nativePeerConnection, long nativeObserver) { |
| 555 | this.nativePeerConnection = nativePeerConnection; |
| 556 | this.nativeObserver = nativeObserver; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | // JsepInterface. |
| 560 | public native SessionDescription getLocalDescription(); |
| 561 | |
| 562 | public native SessionDescription getRemoteDescription(); |
| 563 | |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 564 | public native DataChannel createDataChannel(String label, DataChannel.Init init); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 565 | |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 566 | public native void createOffer(SdpObserver observer, MediaConstraints constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 567 | |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 568 | public native void createAnswer(SdpObserver observer, MediaConstraints constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 569 | |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 570 | public native void setLocalDescription(SdpObserver observer, SessionDescription sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 571 | |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 572 | public native void setRemoteDescription(SdpObserver observer, SessionDescription sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 573 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 574 | // True if remote audio should be played out. Defaults to true. |
| 575 | // Note that even if playout is enabled, streams will only be played out if |
| 576 | // the appropriate SDP is also applied. The main purpose of this API is to |
| 577 | // be able to control the exact time when audio playout starts. |
| 578 | public native void setAudioPlayout(boolean playout); |
| 579 | |
| 580 | // True if local audio shall be recorded. Defaults to true. |
| 581 | // Note that even if recording is enabled, streams will only be recorded if |
| 582 | // the appropriate SDP is also applied. The main purpose of this API is to |
| 583 | // be able to control the exact time when audio recording starts. |
| 584 | public native void setAudioRecording(boolean recording); |
| 585 | |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 586 | public boolean setConfiguration(RTCConfiguration config) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 587 | return setNativeConfiguration(config, nativeObserver); |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 588 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 589 | |
| 590 | public boolean addIceCandidate(IceCandidate candidate) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 591 | return addNativeIceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 594 | public boolean removeIceCandidates(final IceCandidate[] candidates) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 595 | return removeNativeIceCandidates(candidates); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 596 | } |
| 597 | |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 598 | public boolean addStream(MediaStream stream) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 599 | boolean ret = addNativeLocalStream(stream.nativeStream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 600 | if (!ret) { |
| 601 | return false; |
| 602 | } |
| 603 | localStreams.add(stream); |
| 604 | return true; |
| 605 | } |
| 606 | |
| 607 | public void removeStream(MediaStream stream) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 608 | removeNativeLocalStream(stream.nativeStream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 609 | localStreams.remove(stream); |
| 610 | } |
| 611 | |
deadbeef | 7a24688 | 2017-08-09 08:40:10 -0700 | [diff] [blame] | 612 | /** |
| 613 | * Creates an RtpSender without a track. |
| 614 | * <p> |
| 615 | * This method allows an application to cause the PeerConnection to negotiate |
| 616 | * sending/receiving a specific media type, but without having a track to |
| 617 | * send yet. |
| 618 | * <p> |
| 619 | * When the application does want to begin sending a track, it can call |
| 620 | * RtpSender.setTrack, which doesn't require any additional SDP negotiation. |
| 621 | * <p> |
| 622 | * Example use: |
| 623 | * <pre> |
| 624 | * {@code |
| 625 | * audioSender = pc.createSender("audio", "stream1"); |
| 626 | * videoSender = pc.createSender("video", "stream1"); |
| 627 | * // Do normal SDP offer/answer, which will kick off ICE/DTLS and negotiate |
| 628 | * // media parameters.... |
| 629 | * // Later, when the endpoint is ready to actually begin sending: |
| 630 | * audioSender.setTrack(audioTrack, false); |
| 631 | * videoSender.setTrack(videoTrack, false); |
| 632 | * } |
| 633 | * </pre> |
| 634 | * Note: This corresponds most closely to "addTransceiver" in the official |
| 635 | * WebRTC API, in that it creates a sender without a track. It was |
| 636 | * implemented before addTransceiver because it provides useful |
| 637 | * functionality, and properly implementing transceivers would have required |
| 638 | * a great deal more work. |
| 639 | * |
| 640 | * @param kind Corresponds to MediaStreamTrack kinds (must be "audio" or |
| 641 | * "video"). |
| 642 | * @param stream_id The ID of the MediaStream that this sender's track will |
| 643 | * be associated with when SDP is applied to the remote |
| 644 | * PeerConnection. If createSender is used to create an |
| 645 | * audio and video sender that should be synchronized, they |
| 646 | * should use the same stream ID. |
| 647 | * @return A new RtpSender object if successful, or null otherwise. |
| 648 | */ |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 649 | public RtpSender createSender(String kind, String stream_id) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 650 | RtpSender new_sender = createNativeSender(kind, stream_id); |
deadbeef | ee524f7 | 2015-12-02 11:27:40 -0800 | [diff] [blame] | 651 | if (new_sender != null) { |
| 652 | senders.add(new_sender); |
| 653 | } |
| 654 | return new_sender; |
| 655 | } |
| 656 | |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 657 | // Note that calling getSenders will dispose of the senders previously |
| 658 | // returned (and same goes for getReceivers). |
| 659 | public List<RtpSender> getSenders() { |
| 660 | for (RtpSender sender : senders) { |
| 661 | sender.dispose(); |
| 662 | } |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 663 | senders = getNativeSenders(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 664 | return Collections.unmodifiableList(senders); |
| 665 | } |
| 666 | |
| 667 | public List<RtpReceiver> getReceivers() { |
| 668 | for (RtpReceiver receiver : receivers) { |
| 669 | receiver.dispose(); |
| 670 | } |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 671 | receivers = getNativeReceivers(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 672 | return Collections.unmodifiableList(receivers); |
| 673 | } |
| 674 | |
deadbeef | 8221587 | 2017-04-18 10:27:51 -0700 | [diff] [blame] | 675 | // Older, non-standard implementation of getStats. |
| 676 | @Deprecated |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 677 | public boolean getStats(StatsObserver observer, MediaStreamTrack track) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 678 | return oldGetNativeStats(observer, (track == null) ? 0 : track.nativeTrack); |
deadbeef | 8221587 | 2017-04-18 10:27:51 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | // Gets stats using the new stats collection API, see webrtc/api/stats/. These |
| 682 | // will replace old stats collection API when the new API has matured enough. |
| 683 | public void getStats(RTCStatsCollectorCallback callback) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 684 | newGetNativeStats(callback); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 685 | } |
| 686 | |
zstein | d89b0bc | 2017-08-03 11:11:40 -0700 | [diff] [blame] | 687 | // Limits the bandwidth allocated for all RTP streams sent by this |
| 688 | // PeerConnection. Pass null to leave a value unchanged. |
| 689 | public native boolean setBitrate(Integer min, Integer current, Integer max); |
| 690 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 691 | // Starts recording an RTC event log. Ownership of the file is transfered to |
| 692 | // the native code. If an RTC event log is already being recorded, it will be |
| 693 | // stopped and a new one will start using the provided file. Logging will |
| 694 | // continue until the stopRtcEventLog function is called. The max_size_bytes |
| 695 | // argument is ignored, it is added for future use. |
ivoc | 0c6f0f6 | 2016-07-06 04:34:23 -0700 | [diff] [blame] | 696 | public boolean startRtcEventLog(int file_descriptor, int max_size_bytes) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 697 | return startNativeRtcEventLog(file_descriptor, max_size_bytes); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | // Stops recording an RTC event log. If no RTC event log is currently being |
| 701 | // recorded, this call will have no effect. |
| 702 | public void stopRtcEventLog() { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 703 | stopNativeRtcEventLog(); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 704 | } |
| 705 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 706 | // TODO(fischman): add support for DTMF-related methods once that API |
| 707 | // stabilizes. |
| 708 | public native SignalingState signalingState(); |
| 709 | |
| 710 | public native IceConnectionState iceConnectionState(); |
| 711 | |
| 712 | public native IceGatheringState iceGatheringState(); |
| 713 | |
| 714 | public native void close(); |
| 715 | |
deadbeef | 43697f6 | 2017-09-12 10:52:14 -0700 | [diff] [blame] | 716 | /** |
| 717 | * Free native resources associated with this PeerConnection instance. |
| 718 | * <p> |
| 719 | * This method removes a reference count from the C++ PeerConnection object, |
| 720 | * which should result in it being destroyed. It also calls equivalent |
| 721 | * "dispose" methods on the Java objects attached to this PeerConnection |
| 722 | * (streams, senders, receivers), such that their associated C++ objects |
| 723 | * will also be destroyed. |
| 724 | * <p> |
| 725 | * Note that this method cannot be safely called from an observer callback |
| 726 | * (PeerConnection.Observer, DataChannel.Observer, etc.). If you want to, for |
| 727 | * example, destroy the PeerConnection after an "ICE failed" callback, you |
| 728 | * must do this asynchronously (in other words, unwind the stack first). See |
| 729 | * <a href="https://bugs.chromium.org/p/webrtc/issues/detail?id=3721">bug |
| 730 | * 3721</a> for more details. |
| 731 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 732 | public void dispose() { |
| 733 | close(); |
| 734 | for (MediaStream stream : localStreams) { |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 735 | removeNativeLocalStream(stream.nativeStream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 736 | stream.dispose(); |
| 737 | } |
| 738 | localStreams.clear(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 739 | for (RtpSender sender : senders) { |
| 740 | sender.dispose(); |
| 741 | } |
| 742 | senders.clear(); |
| 743 | for (RtpReceiver receiver : receivers) { |
| 744 | receiver.dispose(); |
| 745 | } |
| 746 | receivers.clear(); |
magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [diff] [blame] | 747 | JniCommon.nativeReleaseRef(nativePeerConnection); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 748 | freeObserver(nativeObserver); |
| 749 | } |
| 750 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 751 | @CalledByNative |
| 752 | long getNativePeerConnection() { |
| 753 | return nativePeerConnection; |
| 754 | } |
| 755 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 756 | private static native void freeObserver(long nativeObserver); |
| 757 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 758 | private native boolean setNativeConfiguration(RTCConfiguration config, long nativeObserver); |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 759 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 760 | private native boolean addNativeIceCandidate( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 761 | String sdpMid, int sdpMLineIndex, String iceCandidateSdp); |
| 762 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 763 | private native boolean removeNativeIceCandidates(final IceCandidate[] candidates); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 764 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 765 | private native boolean addNativeLocalStream(long nativeStream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 766 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 767 | private native void removeNativeLocalStream(long nativeStream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 768 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 769 | private native boolean oldGetNativeStats(StatsObserver observer, long nativeTrack); |
deadbeef | 8221587 | 2017-04-18 10:27:51 -0700 | [diff] [blame] | 770 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 771 | private native void newGetNativeStats(RTCStatsCollectorCallback callback); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 772 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 773 | private native RtpSender createNativeSender(String kind, String stream_id); |
deadbeef | ee524f7 | 2015-12-02 11:27:40 -0800 | [diff] [blame] | 774 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 775 | private native List<RtpSender> getNativeSenders(); |
deadbeef | 4139c0f | 2015-10-06 12:29:25 -0700 | [diff] [blame] | 776 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 777 | private native List<RtpReceiver> getNativeReceivers(); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 778 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 779 | private native boolean startNativeRtcEventLog(int file_descriptor, int max_size_bytes); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 780 | |
Magnus Jedvert | ba700f6 | 2017-12-04 13:43:27 +0100 | [diff] [blame] | 781 | private native void stopNativeRtcEventLog(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 782 | } |