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