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