blob: 468413ba2faad55aacf3d5deed51251e4ba4cbdc [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
henrike@webrtc.org28e20752013-07-10 00:45:36 +000011package org.webrtc;
12
Byoungchan Lee02334e02021-08-14 11:41:59 +090013import androidx.annotation.Nullable;
Magnus Jedvert6062f372017-11-16 16:53:12 +010014import java.util.ArrayList;
Qingsi Wanga0d45802019-01-15 13:33:11 -080015import java.util.Arrays;
Sami Kalliomäki3e189a62017-11-24 11:13:39 +010016import java.util.Collections;
Alex Drake68c2a562019-08-13 15:56:07 -070017import java.util.HashMap;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018import java.util.List;
Alex Drake68c2a562019-08-13 15:56:07 -070019import java.util.Map;
Alex Drake43faee02019-08-12 16:27:34 -070020import org.webrtc.CandidatePairChangeEvent;
Patrik Höglundbd6ffaf2018-11-16 14:55:16 +010021import org.webrtc.DataChannel;
22import org.webrtc.MediaStreamTrack;
23import org.webrtc.RtpTransceiver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024
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 */
31public class PeerConnection {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032 /** Tracks PeerConnectionInterface::IceGatheringState */
Magnus Jedvertba700f62017-12-04 13:43:27 +010033 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.org28e20752013-07-10 00:45:36 +000043
44 /** Tracks PeerConnectionInterface::IceConnectionState */
45 public enum IceConnectionState {
sakalb6760f92016-09-29 04:12:44 -070046 NEW,
47 CHECKING,
48 CONNECTED,
49 COMPLETED,
50 FAILED,
51 DISCONNECTED,
Magnus Jedvertba700f62017-12-04 13:43:27 +010052 CLOSED;
53
54 @CalledByNative("IceConnectionState")
55 static IceConnectionState fromNativeIndex(int nativeIndex) {
56 return values()[nativeIndex];
57 }
sakalb6760f92016-09-29 04:12:44 -070058 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059
Jonas Olssonf01d8c82018-11-08 15:19:04 +010060 /** 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
hnsl04833622017-01-09 08:35:45 -080075 /** Tracks PeerConnectionInterface::TlsCertPolicy */
76 public enum TlsCertPolicy {
77 TLS_CERT_POLICY_SECURE,
78 TLS_CERT_POLICY_INSECURE_NO_CHECK,
79 }
80
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081 /** Tracks PeerConnectionInterface::SignalingState */
82 public enum SignalingState {
sakalb6760f92016-09-29 04:12:44 -070083 STABLE,
84 HAVE_LOCAL_OFFER,
85 HAVE_LOCAL_PRANSWER,
86 HAVE_REMOTE_OFFER,
87 HAVE_REMOTE_PRANSWER,
Magnus Jedvertba700f62017-12-04 13:43:27 +010088 CLOSED;
89
90 @CalledByNative("SignalingState")
91 static SignalingState fromNativeIndex(int nativeIndex) {
92 return values()[nativeIndex];
93 }
sakalb6760f92016-09-29 04:12:44 -070094 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095
96 /** Java version of PeerConnectionObserver. */
97 public static interface Observer {
98 /** Triggered when the SignalingState changes. */
Magnus Jedvertba700f62017-12-04 13:43:27 +010099 @CalledByNative("Observer") void onSignalingChange(SignalingState newState);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101 /** Triggered when the IceConnectionState changes. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100102 @CalledByNative("Observer") void onIceConnectionChange(IceConnectionState newState);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
Qingsi Wang36e31472019-05-29 11:37:26 -0700104 /* Triggered when the standard-compliant state transition of IceConnectionState happens. */
105 @CalledByNative("Observer")
106 default void onStandardizedIceConnectionChange(IceConnectionState newState) {}
107
Jonas Olssonf01d8c82018-11-08 15:19:04 +0100108 /** Triggered when the PeerConnectionState changes. */
109 @CalledByNative("Observer")
110 default void onConnectionChange(PeerConnectionState newState) {}
111
Peter Thatcher54360512015-07-08 11:08:35 -0700112 /** Triggered when the ICE connection receiving status changes. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100113 @CalledByNative("Observer") void onIceConnectionReceivingChange(boolean receiving);
Peter Thatcher54360512015-07-08 11:08:35 -0700114
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 /** Triggered when the IceGatheringState changes. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100116 @CalledByNative("Observer") void onIceGatheringChange(IceGatheringState newState);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117
118 /** Triggered when a new ICE candidate has been found. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100119 @CalledByNative("Observer") void onIceCandidate(IceCandidate candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120
Jaehyun Kod2110982021-11-30 19:01:43 +0900121 /** Triggered when gathering of an ICE candidate failed. */
122 default @CalledByNative("Observer") void onIceCandidateError(IceCandidateErrorEvent event) {}
123
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700124 /** Triggered when some ICE candidates have been removed. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100125 @CalledByNative("Observer") void onIceCandidatesRemoved(IceCandidate[] candidates);
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700126
Alex Drake43faee02019-08-12 16:27:34 -0700127 /** Triggered when the ICE candidate pair is changed. */
128 @CalledByNative("Observer")
129 default void onSelectedCandidatePairChanged(CandidatePairChangeEvent event) {}
130
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 /** Triggered when media is received on a new stream from remote peer. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100132 @CalledByNative("Observer") void onAddStream(MediaStream stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133
134 /** Triggered when a remote peer close a stream. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100135 @CalledByNative("Observer") void onRemoveStream(MediaStream stream);
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000136
137 /** Triggered when a remote peer opens a DataChannel. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100138 @CalledByNative("Observer") void onDataChannel(DataChannel dataChannel);
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000139
140 /** Triggered when renegotiation is necessary. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100141 @CalledByNative("Observer") void onRenegotiationNeeded();
zhihuangdcccda72016-12-21 14:08:03 -0800142
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 'pirannaffbfba92021-05-25 10:35:10 +0200147 @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 Hampson31dbc242018-05-07 09:28:19 -0700155
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.org28e20752013-07-10 00:45:36 +0000162 }
163
164 /** Java version of PeerConnectionInterface.IceServer. */
165 public static class IceServer {
Emad Omaradab1d2d2017-06-16 15:43:11 -0700166 // 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.anatoly0ea03102017-09-11 06:41:38 -0700169 @Deprecated public final String uri;
170 public final List<String> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 public final String username;
172 public final String password;
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000173 public final TlsCertPolicy tlsCertPolicy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174
Artem Titovd7ac5812021-07-27 12:23:39 +0200175 // If the URIs in `urls` only contain IP addresses, this field can be used
Emad Omaradab1d2d2017-06-16 15:43:11 -0700176 // to indicate the hostname, which may be necessary for TLS (using the SNI
Artem Titovd7ac5812021-07-27 12:23:39 +0200177 // extension). If `urls` itself contains the hostname, this isn't
Emad Omaradab1d2d2017-06-16 15:43:11 -0700178 // necessary.
179 public final String hostname;
180
Diogo Real1dca9d52017-08-29 12:18:32 -0700181 // List of protocols to be used in the TLS ALPN extension.
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000182 public final List<String> tlsAlpnProtocols;
Diogo Real1dca9d52017-08-29 12:18:32 -0700183
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700184 // 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 Silkin9c147dd2018-09-12 10:45:38 +0000186 public final List<String> tlsEllipticCurves;
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700187
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 /** Convenience constructor for STUN servers. */
Diogo Real05ea2b32017-08-31 00:12:58 -0700189 @Deprecated
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 public IceServer(String uri) {
191 this(uri, "", "");
192 }
193
Diogo Real05ea2b32017-08-31 00:12:58 -0700194 @Deprecated
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 public IceServer(String uri, String username, String password) {
hnsl04833622017-01-09 08:35:45 -0800196 this(uri, username, password, TlsCertPolicy.TLS_CERT_POLICY_SECURE);
197 }
198
Diogo Real05ea2b32017-08-31 00:12:58 -0700199 @Deprecated
hnsl04833622017-01-09 08:35:45 -0800200 public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy) {
Emad Omaradab1d2d2017-06-16 15:43:11 -0700201 this(uri, username, password, tlsCertPolicy, "");
202 }
203
Diogo Real05ea2b32017-08-31 00:12:58 -0700204 @Deprecated
Emad Omaradab1d2d2017-06-16 15:43:11 -0700205 public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy,
206 String hostname) {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700207 this(uri, Collections.singletonList(uri), username, password, tlsCertPolicy, hostname, null,
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000208 null);
Diogo Real1dca9d52017-08-29 12:18:32 -0700209 }
210
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700211 private IceServer(String uri, List<String> urls, String username, String password,
212 TlsCertPolicy tlsCertPolicy, String hostname, List<String> tlsAlpnProtocols,
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000213 List<String> tlsEllipticCurves) {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700214 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.org28e20752013-07-10 00:45:36 +0000231 this.uri = uri;
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700232 this.urls = urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 this.username = username;
234 this.password = password;
hnsl04833622017-01-09 08:35:45 -0800235 this.tlsCertPolicy = tlsCertPolicy;
Emad Omaradab1d2d2017-06-16 15:43:11 -0700236 this.hostname = hostname;
Diogo Real1dca9d52017-08-29 12:18:32 -0700237 this.tlsAlpnProtocols = tlsAlpnProtocols;
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700238 this.tlsEllipticCurves = tlsEllipticCurves;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 }
240
Sami Kalliomäkibde473e2017-10-30 13:34:41 +0100241 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 public String toString() {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700243 return urls + " [" + username + ":" + password + "] [" + tlsCertPolicy + "] [" + hostname
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000244 + "] [" + tlsAlpnProtocols + "] [" + tlsEllipticCurves + "]";
Diogo Real1dca9d52017-08-29 12:18:32 -0700245 }
246
Qingsi Wanga0d45802019-01-15 13:33:11 -0800247 @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 Real1dca9d52017-08-29 12:18:32 -0700272 public static Builder builder(String uri) {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700273 return new Builder(Collections.singletonList(uri));
274 }
275
276 public static Builder builder(List<String> urls) {
277 return new Builder(urls);
Diogo Real1dca9d52017-08-29 12:18:32 -0700278 }
279
280 public static class Builder {
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100281 @Nullable private final List<String> urls;
Diogo Real1dca9d52017-08-29 12:18:32 -0700282 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 Real7bd1f1b2017-09-08 12:50:41 -0700287 private List<String> tlsEllipticCurves;
Diogo Real1dca9d52017-08-29 12:18:32 -0700288
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700289 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 Real1dca9d52017-08-29 12:18:32 -0700294 }
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 Real7bd1f1b2017-09-08 12:50:41 -0700321 public Builder setTlsEllipticCurves(List<String> tlsEllipticCurves) {
322 this.tlsEllipticCurves = tlsEllipticCurves;
323 return this;
324 }
325
Diogo Real1dca9d52017-08-29 12:18:32 -0700326 public IceServer createIceServer() {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700327 return new IceServer(urls.get(0), urls, username, password, tlsCertPolicy, hostname,
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000328 tlsAlpnProtocols, tlsEllipticCurves);
Diogo Real1dca9d52017-08-29 12:18:32 -0700329 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100331
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100332 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100333 @CalledByNative("IceServer")
334 List<String> getUrls() {
335 return urls;
336 }
337
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100338 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100339 @CalledByNative("IceServer")
340 String getUsername() {
341 return username;
342 }
343
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100344 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100345 @CalledByNative("IceServer")
346 String getPassword() {
347 return password;
348 }
349
350 @CalledByNative("IceServer")
351 TlsCertPolicy getTlsCertPolicy() {
352 return tlsCertPolicy;
353 }
354
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100355 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100356 @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.org28e20752013-07-10 00:45:36 +0000370 }
371
Jiayang Liucac1b382015-04-30 12:35:24 -0700372 /** Java version of PeerConnectionInterface.IceTransportsType */
sakalb6760f92016-09-29 04:12:44 -0700373 public enum IceTransportsType { NONE, RELAY, NOHOST, ALL }
Jiayang Liucac1b382015-04-30 12:35:24 -0700374
375 /** Java version of PeerConnectionInterface.BundlePolicy */
sakalb6760f92016-09-29 04:12:44 -0700376 public enum BundlePolicy { BALANCED, MAXBUNDLE, MAXCOMPAT }
Jiayang Liucac1b382015-04-30 12:35:24 -0700377
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700378 /** Java version of PeerConnectionInterface.RtcpMuxPolicy */
sakalb6760f92016-09-29 04:12:44 -0700379 public enum RtcpMuxPolicy { NEGOTIATE, REQUIRE }
glaznev97579a42015-09-01 11:31:27 -0700380
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700381 /** Java version of PeerConnectionInterface.TcpCandidatePolicy */
sakalb6760f92016-09-29 04:12:44 -0700382 public enum TcpCandidatePolicy { ENABLED, DISABLED }
Jiayang Liucac1b382015-04-30 12:35:24 -0700383
honghaiz60347052016-05-31 18:29:12 -0700384 /** Java version of PeerConnectionInterface.CandidateNetworkPolicy */
sakalb6760f92016-09-29 04:12:44 -0700385 public enum CandidateNetworkPolicy { ALL, LOW_COST }
honghaiz60347052016-05-31 18:29:12 -0700386
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800387 // Keep in sync with webrtc/rtc_base/network_constants.h.
388 public enum AdapterType {
Alex Drake68c2a562019-08-13 15:56:07 -0700389 UNKNOWN(0),
390 ETHERNET(1 << 0),
391 WIFI(1 << 1),
392 CELLULAR(1 << 2),
393 VPN(1 << 3),
394 LOOPBACK(1 << 4),
Jonas Oreland0cc37302020-04-02 18:26:26 +0200395 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 Drake68c2a562019-08-13 15:56:07 -0700400
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 Gerey29e07e52019-11-19 12:13:25 +0100412 @Nullable
Alex Drake68c2a562019-08-13 15:56:07 -0700413 @CalledByNative("AdapterType")
414 static AdapterType fromNativeIndex(int nativeIndex) {
415 return BY_BITMASK.get(nativeIndex);
416 }
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800417 }
418
glaznev97579a42015-09-01 11:31:27 -0700419 /** Java version of rtc::KeyType */
sakalb6760f92016-09-29 04:12:44 -0700420 public enum KeyType { RSA, ECDSA }
glaznev97579a42015-09-01 11:31:27 -0700421
honghaiz1f429e32015-09-28 07:57:34 -0700422 /** Java version of PeerConnectionInterface.ContinualGatheringPolicy */
sakalb6760f92016-09-29 04:12:44 -0700423 public enum ContinualGatheringPolicy { GATHER_ONCE, GATHER_CONTINUALLY }
honghaiz1f429e32015-09-28 07:57:34 -0700424
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700425 /** 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 Hampsonc384e142018-03-06 15:47:10 -0800432 /**
433 * Java version of webrtc::SdpSemantics.
434 *
435 * Configure the SDP semantics used by this PeerConnection. Note that the
436 * WebRTC 1.0 specification requires UNIFIED_PLAN semantics. The
437 * RtpTransceiver API is only available with UNIFIED_PLAN semantics.
438 *
439 * <p>PLAN_B will cause PeerConnection to create offers and answers with at
440 * most one audio and one video m= section with multiple RtpSenders and
441 * RtpReceivers specified as multiple a=ssrc lines within the section. This
442 * will also cause PeerConnection to ignore all but the first m= section of
443 * the same media type.
444 *
445 * <p>UNIFIED_PLAN will cause PeerConnection to create offers and answers with
446 * multiple m= sections where each m= section maps to one RtpSender and one
447 * RtpReceiver (an RtpTransceiver), either both audio or both video. This
448 * will also cause PeerConnection to ignore all but the first a=ssrc lines
449 * that form a Plan B stream.
450 *
451 * <p>For users who wish to send multiple audio/video streams and need to stay
452 * interoperable with legacy WebRTC implementations, specify PLAN_B.
453 *
454 * <p>For users who wish to send multiple audio/video streams and/or wish to
455 * use the new RtpTransceiver API, specify UNIFIED_PLAN.
456 */
457 public enum SdpSemantics { PLAN_B, UNIFIED_PLAN }
458
Jiayang Liucac1b382015-04-30 12:35:24 -0700459 /** Java version of PeerConnectionInterface.RTCConfiguration */
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800460 // TODO(qingsi): Resolve the naming inconsistency of fields with/without units.
Jiayang Liucac1b382015-04-30 12:35:24 -0700461 public static class RTCConfiguration {
462 public IceTransportsType iceTransportsType;
463 public List<IceServer> iceServers;
464 public BundlePolicy bundlePolicy;
Michael Iedema02137862018-10-09 15:30:01 +0200465 @Nullable public RtcCertificatePem certificate;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700466 public RtcpMuxPolicy rtcpMuxPolicy;
Jiayang Liucac1b382015-04-30 12:35:24 -0700467 public TcpCandidatePolicy tcpCandidatePolicy;
honghaiz60347052016-05-31 18:29:12 -0700468 public CandidateNetworkPolicy candidateNetworkPolicy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200469 public int audioJitterBufferMaxPackets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200470 public boolean audioJitterBufferFastAccelerate;
honghaiz4edc39c2015-09-01 09:53:56 -0700471 public int iceConnectionReceivingTimeout;
Honghai Zhang381b4212015-12-04 12:24:03 -0800472 public int iceBackupCandidatePairPingInterval;
glaznev97579a42015-09-01 11:31:27 -0700473 public KeyType keyType;
honghaiz1f429e32015-09-28 07:57:34 -0700474 public ContinualGatheringPolicy continualGatheringPolicy;
deadbeefbe0c96f2016-05-18 16:20:14 -0700475 public int iceCandidatePoolSize;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700476 @Deprecated // by the turnPortPrunePolicy. See bugs.webrtc.org/11026
Honghai Zhangd78ecf72016-07-01 14:40:40 -0700477 public boolean pruneTurnPorts;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700478 public PortPrunePolicy turnPortPrunePolicy;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700479 public boolean presumeWritableWhenFullyRelayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700480 public boolean surfaceIceCandidatesOnIceTransportTypeChanged;
Qingsi Wange6826d22018-03-08 14:55:14 -0800481 // The following fields define intervals in milliseconds at which ICE
482 // connectivity checks are sent.
483 //
484 // We consider ICE is "strongly connected" for an agent when there is at
485 // least one candidate pair that currently succeeds in connectivity check
486 // from its direction i.e. sending a ping and receives a ping response, AND
487 // all candidate pairs have sent a minimum number of pings for connectivity
488 // (this number is implementation-specific). Otherwise, ICE is considered in
489 // "weak connectivity".
490 //
491 // Note that the above notion of strong and weak connectivity is not defined
492 // in RFC 5245, and they apply to our current ICE implementation only.
493 //
494 // 1) iceCheckIntervalStrongConnectivityMs defines the interval applied to
495 // ALL candidate pairs when ICE is strongly connected,
496 // 2) iceCheckIntervalWeakConnectivityMs defines the counterpart for ALL
497 // pairs when ICE is weakly connected, and
498 // 3) iceCheckMinInterval defines the minimal interval (equivalently the
499 // maximum rate) that overrides the above two intervals when either of them
500 // is less.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100501 @Nullable public Integer iceCheckIntervalStrongConnectivityMs;
502 @Nullable public Integer iceCheckIntervalWeakConnectivityMs;
503 @Nullable public Integer iceCheckMinInterval;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700504 // The time period in milliseconds for which a candidate pair must wait for response to
505 // connectivitiy checks before it becomes unwritable.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100506 @Nullable public Integer iceUnwritableTimeMs;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700507 // The minimum number of connectivity checks that a candidate pair must sent without receiving
508 // response before it becomes unwritable.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100509 @Nullable public Integer iceUnwritableMinChecks;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800510 // The interval in milliseconds at which STUN candidates will resend STUN binding requests
511 // to keep NAT bindings open.
512 // The default value in the implementation is used if this field is null.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100513 @Nullable public Integer stunCandidateKeepaliveIntervalMs;
Derek Bailey6c127a12021-04-15 12:42:41 -0700514 // The interval in milliseconds of pings sent when the connection is stable and writable.
515 // The default value in the implementation is used if this field is null.
516 @Nullable public Integer stableWritableConnectionPingIntervalMs;
zhihuangb09b3f92017-03-07 14:40:51 -0800517 public boolean disableIPv6OnWifi;
deadbeef28e29192017-07-27 09:14:38 -0700518 // By default, PeerConnection will use a limited number of IPv6 network
519 // interfaces, in order to avoid too many ICE candidate pairs being created
520 // and delaying ICE completion.
521 //
522 // Can be set to Integer.MAX_VALUE to effectively disable the limit.
523 public int maxIPv6Networks;
Jiayang Liucac1b382015-04-30 12:35:24 -0700524
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100525 // These values will be overridden by MediaStream constraints if deprecated constraints-based
526 // create peerconnection interface is used.
527 public boolean disableIpv6;
528 public boolean enableDscp;
529 public boolean enableCpuOveruseDetection;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100530 public boolean suspendBelowMinBitrate;
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100531 @Nullable public Integer screencastMinBitrate;
532 @Nullable public Boolean combinedAudioVideoBwe;
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800533 // Use "Unknown" to represent no preference of adapter types, not the
534 // preference of adapters of unknown types.
535 public AdapterType networkPreference;
Seth Hampsonc384e142018-03-06 15:47:10 -0800536 public SdpSemantics sdpSemantics;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100537
Jonas Orelandbdcee282017-10-10 14:01:40 +0200538 // This is an optional wrapper for the C++ webrtc::TurnCustomizer.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100539 @Nullable public TurnCustomizer turnCustomizer;
Jonas Orelandbdcee282017-10-10 14:01:40 +0200540
Zhi Huangb57e1692018-06-12 11:41:11 -0700541 // Actively reset the SRTP parameters whenever the DTLS transports underneath are reset for
542 // every offer/answer negotiation.This is only intended to be a workaround for crbug.com/835958
543 public boolean activeResetSrtpParams;
544
philipel16cec3b2019-10-25 12:23:02 +0200545 // Whether this client is allowed to switch encoding codec mid-stream. This is a workaround for
546 // a WebRTC bug where the receiver could get confussed if a codec switch happened mid-call.
547 // Null indicates no change to currently configured value.
548 @Nullable public Boolean allowCodecSwitching;
549
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700550 /**
551 * Defines advanced optional cryptographic settings related to SRTP and
552 * frame encryption for native WebRTC. Setting this will overwrite any
553 * options set through the PeerConnectionFactory (which is deprecated).
554 */
555 @Nullable public CryptoOptions cryptoOptions;
556
Jonas Oreland228900f2019-08-28 09:08:58 +0200557 /**
558 * An optional string that if set will be attached to the
559 * TURN_ALLOCATE_REQUEST which can be used to correlate client
560 * logs with backend logs
561 */
562 @Nullable public String turnLoggingId;
563
Yura Yaroshevich90fab632021-03-22 17:10:33 +0300564 /**
565 * Allow implicit rollback of local description when remote description
566 * conflicts with local description.
567 * See: https://w3c.github.io/webrtc-pc/#dom-peerconnection-setremotedescription
568 */
569 public boolean enableImplicitRollback;
570
571 /**
572 * Control if "a=extmap-allow-mixed" is included in the offer.
573 * See: https://www.chromestatus.com/feature/6269234631933952
574 */
575 public boolean offerExtmapAllowMixed;
576
deadbeef28e29192017-07-27 09:14:38 -0700577 // TODO(deadbeef): Instead of duplicating the defaults here, we should do
578 // something to pick up the defaults from C++. The Objective-C equivalent
579 // of RTCConfiguration does that.
Jiayang Liucac1b382015-04-30 12:35:24 -0700580 public RTCConfiguration(List<IceServer> iceServers) {
581 iceTransportsType = IceTransportsType.ALL;
582 bundlePolicy = BundlePolicy.BALANCED;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800583 rtcpMuxPolicy = RtcpMuxPolicy.REQUIRE;
Jiayang Liucac1b382015-04-30 12:35:24 -0700584 tcpCandidatePolicy = TcpCandidatePolicy.ENABLED;
Sami Kalliomäki9828beb2017-10-26 16:21:22 +0200585 candidateNetworkPolicy = CandidateNetworkPolicy.ALL;
Jiayang Liucac1b382015-04-30 12:35:24 -0700586 this.iceServers = iceServers;
Henrik Lundin64dad832015-05-11 12:44:23 +0200587 audioJitterBufferMaxPackets = 50;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200588 audioJitterBufferFastAccelerate = false;
honghaiz4edc39c2015-09-01 09:53:56 -0700589 iceConnectionReceivingTimeout = -1;
Honghai Zhang381b4212015-12-04 12:24:03 -0800590 iceBackupCandidatePairPingInterval = -1;
glaznev97579a42015-09-01 11:31:27 -0700591 keyType = KeyType.ECDSA;
honghaiz1f429e32015-09-28 07:57:34 -0700592 continualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE;
deadbeefbe0c96f2016-05-18 16:20:14 -0700593 iceCandidatePoolSize = 0;
Honghai Zhangd78ecf72016-07-01 14:40:40 -0700594 pruneTurnPorts = false;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700595 turnPortPrunePolicy = PortPrunePolicy.NO_PRUNE;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700596 presumeWritableWhenFullyRelayed = false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700597 surfaceIceCandidatesOnIceTransportTypeChanged = false;
Qingsi Wange6826d22018-03-08 14:55:14 -0800598 iceCheckIntervalStrongConnectivityMs = null;
599 iceCheckIntervalWeakConnectivityMs = null;
skvlad51072462017-02-02 11:50:14 -0800600 iceCheckMinInterval = null;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700601 iceUnwritableTimeMs = null;
602 iceUnwritableMinChecks = null;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800603 stunCandidateKeepaliveIntervalMs = null;
Derek Bailey6c127a12021-04-15 12:42:41 -0700604 stableWritableConnectionPingIntervalMs = null;
zhihuangb09b3f92017-03-07 14:40:51 -0800605 disableIPv6OnWifi = false;
deadbeef28e29192017-07-27 09:14:38 -0700606 maxIPv6Networks = 5;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100607 disableIpv6 = false;
608 enableDscp = false;
609 enableCpuOveruseDetection = true;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100610 suspendBelowMinBitrate = false;
611 screencastMinBitrate = null;
612 combinedAudioVideoBwe = null;
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800613 networkPreference = AdapterType.UNKNOWN;
Seth Hampsonc384e142018-03-06 15:47:10 -0800614 sdpSemantics = SdpSemantics.PLAN_B;
Zhi Huangb57e1692018-06-12 11:41:11 -0700615 activeResetSrtpParams = false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700616 cryptoOptions = null;
Jonas Oreland228900f2019-08-28 09:08:58 +0200617 turnLoggingId = null;
philipel16cec3b2019-10-25 12:23:02 +0200618 allowCodecSwitching = null;
Yura Yaroshevich90fab632021-03-22 17:10:33 +0300619 enableImplicitRollback = false;
620 offerExtmapAllowMixed = true;
Jiayang Liucac1b382015-04-30 12:35:24 -0700621 }
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100622
623 @CalledByNative("RTCConfiguration")
624 IceTransportsType getIceTransportsType() {
625 return iceTransportsType;
626 }
627
628 @CalledByNative("RTCConfiguration")
629 List<IceServer> getIceServers() {
630 return iceServers;
631 }
632
633 @CalledByNative("RTCConfiguration")
634 BundlePolicy getBundlePolicy() {
635 return bundlePolicy;
636 }
637
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700638 @CalledByNative("RTCConfiguration")
639 PortPrunePolicy getTurnPortPrunePolicy() {
640 return turnPortPrunePolicy;
641 }
642
Michael Iedema02137862018-10-09 15:30:01 +0200643 @Nullable
644 @CalledByNative("RTCConfiguration")
645 RtcCertificatePem getCertificate() {
646 return certificate;
647 }
648
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100649 @CalledByNative("RTCConfiguration")
650 RtcpMuxPolicy getRtcpMuxPolicy() {
651 return rtcpMuxPolicy;
652 }
653
654 @CalledByNative("RTCConfiguration")
655 TcpCandidatePolicy getTcpCandidatePolicy() {
656 return tcpCandidatePolicy;
657 }
658
659 @CalledByNative("RTCConfiguration")
660 CandidateNetworkPolicy getCandidateNetworkPolicy() {
661 return candidateNetworkPolicy;
662 }
663
664 @CalledByNative("RTCConfiguration")
665 int getAudioJitterBufferMaxPackets() {
666 return audioJitterBufferMaxPackets;
667 }
668
669 @CalledByNative("RTCConfiguration")
670 boolean getAudioJitterBufferFastAccelerate() {
671 return audioJitterBufferFastAccelerate;
672 }
673
674 @CalledByNative("RTCConfiguration")
675 int getIceConnectionReceivingTimeout() {
676 return iceConnectionReceivingTimeout;
677 }
678
679 @CalledByNative("RTCConfiguration")
680 int getIceBackupCandidatePairPingInterval() {
681 return iceBackupCandidatePairPingInterval;
682 }
683
684 @CalledByNative("RTCConfiguration")
685 KeyType getKeyType() {
686 return keyType;
687 }
688
689 @CalledByNative("RTCConfiguration")
690 ContinualGatheringPolicy getContinualGatheringPolicy() {
691 return continualGatheringPolicy;
692 }
693
694 @CalledByNative("RTCConfiguration")
695 int getIceCandidatePoolSize() {
696 return iceCandidatePoolSize;
697 }
698
699 @CalledByNative("RTCConfiguration")
700 boolean getPruneTurnPorts() {
701 return pruneTurnPorts;
702 }
703
704 @CalledByNative("RTCConfiguration")
705 boolean getPresumeWritableWhenFullyRelayed() {
706 return presumeWritableWhenFullyRelayed;
707 }
708
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700709 @CalledByNative("RTCConfiguration")
710 boolean getSurfaceIceCandidatesOnIceTransportTypeChanged() {
711 return surfaceIceCandidatesOnIceTransportTypeChanged;
712 }
713
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100714 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100715 @CalledByNative("RTCConfiguration")
Qingsi Wange6826d22018-03-08 14:55:14 -0800716 Integer getIceCheckIntervalStrongConnectivity() {
717 return iceCheckIntervalStrongConnectivityMs;
718 }
719
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100720 @Nullable
Qingsi Wange6826d22018-03-08 14:55:14 -0800721 @CalledByNative("RTCConfiguration")
722 Integer getIceCheckIntervalWeakConnectivity() {
723 return iceCheckIntervalWeakConnectivityMs;
724 }
725
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100726 @Nullable
Qingsi Wange6826d22018-03-08 14:55:14 -0800727 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100728 Integer getIceCheckMinInterval() {
729 return iceCheckMinInterval;
730 }
731
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100732 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100733 @CalledByNative("RTCConfiguration")
Qingsi Wang22e623a2018-03-13 10:53:57 -0700734 Integer getIceUnwritableTimeout() {
735 return iceUnwritableTimeMs;
736 }
737
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100738 @Nullable
Qingsi Wang22e623a2018-03-13 10:53:57 -0700739 @CalledByNative("RTCConfiguration")
740 Integer getIceUnwritableMinChecks() {
741 return iceUnwritableMinChecks;
742 }
743
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100744 @Nullable
Qingsi Wang22e623a2018-03-13 10:53:57 -0700745 @CalledByNative("RTCConfiguration")
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800746 Integer getStunCandidateKeepaliveInterval() {
747 return stunCandidateKeepaliveIntervalMs;
748 }
749
Derek Bailey6c127a12021-04-15 12:42:41 -0700750 @Nullable
751 @CalledByNative("RTCConfiguration")
752 Integer getStableWritableConnectionPingIntervalMs() {
753 return stableWritableConnectionPingIntervalMs;
754 }
755
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800756 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100757 boolean getDisableIPv6OnWifi() {
758 return disableIPv6OnWifi;
759 }
760
761 @CalledByNative("RTCConfiguration")
762 int getMaxIPv6Networks() {
763 return maxIPv6Networks;
764 }
765
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100766 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100767 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100768 TurnCustomizer getTurnCustomizer() {
769 return turnCustomizer;
770 }
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100771
772 @CalledByNative("RTCConfiguration")
773 boolean getDisableIpv6() {
774 return disableIpv6;
775 }
776
777 @CalledByNative("RTCConfiguration")
778 boolean getEnableDscp() {
779 return enableDscp;
780 }
781
782 @CalledByNative("RTCConfiguration")
783 boolean getEnableCpuOveruseDetection() {
784 return enableCpuOveruseDetection;
785 }
786
787 @CalledByNative("RTCConfiguration")
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100788 boolean getSuspendBelowMinBitrate() {
789 return suspendBelowMinBitrate;
790 }
791
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100792 @Nullable
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100793 @CalledByNative("RTCConfiguration")
794 Integer getScreencastMinBitrate() {
795 return screencastMinBitrate;
796 }
797
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100798 @Nullable
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100799 @CalledByNative("RTCConfiguration")
800 Boolean getCombinedAudioVideoBwe() {
801 return combinedAudioVideoBwe;
802 }
803
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800804 @CalledByNative("RTCConfiguration")
805 AdapterType getNetworkPreference() {
806 return networkPreference;
807 }
Seth Hampsonc384e142018-03-06 15:47:10 -0800808
809 @CalledByNative("RTCConfiguration")
810 SdpSemantics getSdpSemantics() {
811 return sdpSemantics;
812 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700813
814 @CalledByNative("RTCConfiguration")
815 boolean getActiveResetSrtpParams() {
816 return activeResetSrtpParams;
817 }
Piotr (Peter) Slatala09beff22018-10-17 07:22:40 -0700818
philipel16cec3b2019-10-25 12:23:02 +0200819 @Nullable
820 @CalledByNative("RTCConfiguration")
821 Boolean getAllowCodecSwitching() {
822 return allowCodecSwitching;
823 }
824
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700825 @Nullable
826 @CalledByNative("RTCConfiguration")
827 CryptoOptions getCryptoOptions() {
828 return cryptoOptions;
829 }
Jonas Oreland228900f2019-08-28 09:08:58 +0200830
831 @Nullable
832 @CalledByNative("RTCConfiguration")
833 String getTurnLoggingId() {
834 return turnLoggingId;
835 }
Yura Yaroshevich90fab632021-03-22 17:10:33 +0300836
837 @CalledByNative("RTCConfiguration")
838 boolean getEnableImplicitRollback() {
839 return enableImplicitRollback;
840 }
841
842 @CalledByNative("RTCConfiguration")
843 boolean getOfferExtmapAllowMixed() {
844 return offerExtmapAllowMixed;
845 }
Jiayang Liucac1b382015-04-30 12:35:24 -0700846 };
847
Magnus Jedvert6062f372017-11-16 16:53:12 +0100848 private final List<MediaStream> localStreams = new ArrayList<>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 private final long nativePeerConnection;
Magnus Jedvert6062f372017-11-16 16:53:12 +0100850 private List<RtpSender> senders = new ArrayList<>();
851 private List<RtpReceiver> receivers = new ArrayList<>();
Seth Hampsonc384e142018-03-06 15:47:10 -0800852 private List<RtpTransceiver> transceivers = new ArrayList<>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853
Sami Kalliomäki1ece1ed2017-12-20 11:59:22 +0100854 /**
855 * Wraps a PeerConnection created by the factory. Can be used by clients that want to implement
856 * their PeerConnection creation in JNI.
857 */
858 public PeerConnection(NativePeerConnectionFactory factory) {
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100859 this(factory.createNativePeerConnection());
Sami Kalliomäki1ece1ed2017-12-20 11:59:22 +0100860 }
861
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100862 PeerConnection(long nativePeerConnection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 this.nativePeerConnection = nativePeerConnection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 }
865
866 // JsepInterface.
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100867 public SessionDescription getLocalDescription() {
868 return nativeGetLocalDescription();
869 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100871 public SessionDescription getRemoteDescription() {
872 return nativeGetRemoteDescription();
873 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874
Michael Iedema02137862018-10-09 15:30:01 +0200875 public RtcCertificatePem getCertificate() {
876 return nativeGetCertificate();
877 }
878
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100879 public DataChannel createDataChannel(String label, DataChannel.Init init) {
880 return nativeCreateDataChannel(label, init);
881 }
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000882
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100883 public void createOffer(SdpObserver observer, MediaConstraints constraints) {
884 nativeCreateOffer(observer, constraints);
885 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100887 public void createAnswer(SdpObserver observer, MediaConstraints constraints) {
888 nativeCreateAnswer(observer, constraints);
889 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890
Yura Yaroshevich4e9e7232021-03-22 11:45:43 +0300891 public void setLocalDescription(SdpObserver observer) {
892 nativeSetLocalDescriptionAutomatically(observer);
893 }
894
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100895 public void setLocalDescription(SdpObserver observer, SessionDescription sdp) {
896 nativeSetLocalDescription(observer, sdp);
897 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100899 public void setRemoteDescription(SdpObserver observer, SessionDescription sdp) {
900 nativeSetRemoteDescription(observer, sdp);
901 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902
Seth Hampsonc384e142018-03-06 15:47:10 -0800903 /**
Yura Yaroshevichd8d9ac32021-03-22 12:46:47 +0300904 * Tells the PeerConnection that ICE should be restarted.
905 */
906 public void restartIce() {
907 nativeRestartIce();
908 }
909
910 /**
Seth Hampsonc384e142018-03-06 15:47:10 -0800911 * Enables/disables playout of received audio streams. Enabled by default.
912 *
913 * Note that even if playout is enabled, streams will only be played out if
914 * the appropriate SDP is also applied. The main purpose of this API is to
915 * be able to control the exact time when audio playout starts.
916 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100917 public void setAudioPlayout(boolean playout) {
918 nativeSetAudioPlayout(playout);
919 }
henrika5f6bf242017-11-01 11:06:56 +0100920
Seth Hampsonc384e142018-03-06 15:47:10 -0800921 /**
922 * Enables/disables recording of transmitted audio streams. Enabled by default.
923 *
924 * Note that even if recording is enabled, streams will only be recorded if
925 * the appropriate SDP is also applied. The main purpose of this API is to
926 * be able to control the exact time when audio recording starts.
927 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100928 public void setAudioRecording(boolean recording) {
929 nativeSetAudioRecording(recording);
930 }
henrika5f6bf242017-11-01 11:06:56 +0100931
deadbeef5d0b6d82017-01-09 16:05:28 -0800932 public boolean setConfiguration(RTCConfiguration config) {
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100933 return nativeSetConfiguration(config);
deadbeef5d0b6d82017-01-09 16:05:28 -0800934 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935
936 public boolean addIceCandidate(IceCandidate candidate) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100937 return nativeAddIceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 }
939
Yura Yaroshevich1cdeb0a2021-04-08 16:56:56 +0300940 public void addIceCandidate(IceCandidate candidate, AddIceObserver observer) {
941 nativeAddIceCandidateWithObserver(
942 candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp, observer);
943 }
944
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700945 public boolean removeIceCandidates(final IceCandidate[] candidates) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100946 return nativeRemoveIceCandidates(candidates);
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700947 }
948
Seth Hampsonc384e142018-03-06 15:47:10 -0800949 /**
950 * Adds a new MediaStream to be sent on this peer connection.
951 * Note: This method is not supported with SdpSemantics.UNIFIED_PLAN. Please
952 * use addTrack instead.
953 */
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000954 public boolean addStream(MediaStream stream) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +0200955 boolean ret = nativeAddLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 if (!ret) {
957 return false;
958 }
959 localStreams.add(stream);
960 return true;
961 }
962
Seth Hampsonc384e142018-03-06 15:47:10 -0800963 /**
964 * Removes the given media stream from this peer connection.
965 * This method is not supported with SdpSemantics.UNIFIED_PLAN. Please use
966 * removeTrack instead.
967 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 public void removeStream(MediaStream stream) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +0200969 nativeRemoveLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 localStreams.remove(stream);
971 }
972
deadbeef7a246882017-08-09 08:40:10 -0700973 /**
974 * Creates an RtpSender without a track.
Seth Hampsonc384e142018-03-06 15:47:10 -0800975 *
976 * <p>This method allows an application to cause the PeerConnection to negotiate
deadbeef7a246882017-08-09 08:40:10 -0700977 * sending/receiving a specific media type, but without having a track to
978 * send yet.
Seth Hampsonc384e142018-03-06 15:47:10 -0800979 *
980 * <p>When the application does want to begin sending a track, it can call
deadbeef7a246882017-08-09 08:40:10 -0700981 * RtpSender.setTrack, which doesn't require any additional SDP negotiation.
Seth Hampsonc384e142018-03-06 15:47:10 -0800982 *
983 * <p>Example use:
deadbeef7a246882017-08-09 08:40:10 -0700984 * <pre>
985 * {@code
986 * audioSender = pc.createSender("audio", "stream1");
987 * videoSender = pc.createSender("video", "stream1");
988 * // Do normal SDP offer/answer, which will kick off ICE/DTLS and negotiate
989 * // media parameters....
990 * // Later, when the endpoint is ready to actually begin sending:
991 * audioSender.setTrack(audioTrack, false);
992 * videoSender.setTrack(videoTrack, false);
993 * }
994 * </pre>
Seth Hampsonc384e142018-03-06 15:47:10 -0800995 * <p>Note: This corresponds most closely to "addTransceiver" in the official
deadbeef7a246882017-08-09 08:40:10 -0700996 * WebRTC API, in that it creates a sender without a track. It was
997 * implemented before addTransceiver because it provides useful
998 * functionality, and properly implementing transceivers would have required
999 * a great deal more work.
1000 *
Seth Hampsonc384e142018-03-06 15:47:10 -08001001 * <p>Note: This is only available with SdpSemantics.PLAN_B specified. Please use
1002 * addTransceiver instead.
1003 *
deadbeef7a246882017-08-09 08:40:10 -07001004 * @param kind Corresponds to MediaStreamTrack kinds (must be "audio" or
1005 * "video").
1006 * @param stream_id The ID of the MediaStream that this sender's track will
1007 * be associated with when SDP is applied to the remote
1008 * PeerConnection. If createSender is used to create an
1009 * audio and video sender that should be synchronized, they
1010 * should use the same stream ID.
1011 * @return A new RtpSender object if successful, or null otherwise.
1012 */
deadbeefbd7d8f72015-12-18 16:58:44 -08001013 public RtpSender createSender(String kind, String stream_id) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001014 RtpSender newSender = nativeCreateSender(kind, stream_id);
1015 if (newSender != null) {
1016 senders.add(newSender);
deadbeefee524f72015-12-02 11:27:40 -08001017 }
Seth Hampsonc384e142018-03-06 15:47:10 -08001018 return newSender;
deadbeefee524f72015-12-02 11:27:40 -08001019 }
1020
Seth Hampsonc384e142018-03-06 15:47:10 -08001021 /**
1022 * Gets all RtpSenders associated with this peer connection.
1023 * Note that calling getSenders will dispose of the senders previously
1024 * returned.
1025 */
deadbeef4139c0f2015-10-06 12:29:25 -07001026 public List<RtpSender> getSenders() {
1027 for (RtpSender sender : senders) {
1028 sender.dispose();
1029 }
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001030 senders = nativeGetSenders();
deadbeef4139c0f2015-10-06 12:29:25 -07001031 return Collections.unmodifiableList(senders);
1032 }
1033
Seth Hampsonc384e142018-03-06 15:47:10 -08001034 /**
1035 * Gets all RtpReceivers associated with this peer connection.
1036 * Note that calling getReceivers will dispose of the receivers previously
1037 * returned.
1038 */
deadbeef4139c0f2015-10-06 12:29:25 -07001039 public List<RtpReceiver> getReceivers() {
1040 for (RtpReceiver receiver : receivers) {
1041 receiver.dispose();
1042 }
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001043 receivers = nativeGetReceivers();
deadbeef4139c0f2015-10-06 12:29:25 -07001044 return Collections.unmodifiableList(receivers);
1045 }
1046
Seth Hampsonc384e142018-03-06 15:47:10 -08001047 /**
1048 * Gets all RtpTransceivers associated with this peer connection.
1049 * Note that calling getTransceivers will dispose of the transceivers previously
1050 * returned.
1051 * Note: This is only available with SdpSemantics.UNIFIED_PLAN specified.
1052 */
1053 public List<RtpTransceiver> getTransceivers() {
1054 for (RtpTransceiver transceiver : transceivers) {
1055 transceiver.dispose();
1056 }
1057 transceivers = nativeGetTransceivers();
1058 return Collections.unmodifiableList(transceivers);
1059 }
1060
1061 /**
1062 * Adds a new media stream track to be sent on this peer connection, and returns
1063 * the newly created RtpSender. If streamIds are specified, the RtpSender will
1064 * be associated with the streams specified in the streamIds list.
1065 *
1066 * @throws IllegalStateException if an error accors in C++ addTrack.
1067 * An error can occur if:
1068 * - A sender already exists for the track.
1069 * - The peer connection is closed.
1070 */
1071 public RtpSender addTrack(MediaStreamTrack track) {
1072 return addTrack(track, Collections.emptyList());
1073 }
1074
1075 public RtpSender addTrack(MediaStreamTrack track, List<String> streamIds) {
1076 if (track == null || streamIds == null) {
1077 throw new NullPointerException("No MediaStreamTrack specified in addTrack.");
1078 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001079 RtpSender newSender = nativeAddTrack(track.getNativeMediaStreamTrack(), streamIds);
Seth Hampsonc384e142018-03-06 15:47:10 -08001080 if (newSender == null) {
1081 throw new IllegalStateException("C++ addTrack failed.");
1082 }
1083 senders.add(newSender);
1084 return newSender;
1085 }
1086
1087 /**
1088 * Stops sending media from sender. The sender will still appear in getSenders. Future
1089 * calls to createOffer will mark the m section for the corresponding transceiver as
1090 * receive only or inactive, as defined in JSEP. Returns true on success.
1091 */
1092 public boolean removeTrack(RtpSender sender) {
1093 if (sender == null) {
1094 throw new NullPointerException("No RtpSender specified for removeTrack.");
1095 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001096 return nativeRemoveTrack(sender.getNativeRtpSender());
Seth Hampsonc384e142018-03-06 15:47:10 -08001097 }
1098
1099 /**
1100 * Creates a new RtpTransceiver and adds it to the set of transceivers. Adding a
1101 * transceiver will cause future calls to CreateOffer to add a media description
1102 * for the corresponding transceiver.
1103 *
Artem Titovd7ac5812021-07-27 12:23:39 +02001104 * <p>The initial value of `mid` in the returned transceiver is null. Setting a
Seth Hampsonc384e142018-03-06 15:47:10 -08001105 * new session description may change it to a non-null value.
1106 *
1107 * <p>https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
1108 *
1109 * <p>If a MediaStreamTrack is specified then a transceiver will be added with a
1110 * sender set to transmit the given track. The kind
1111 * of the transceiver (and sender/receiver) will be derived from the kind of
1112 * the track.
1113 *
1114 * <p>If MediaType is specified then a transceiver will be added based upon that type.
1115 * This can be either MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO.
1116 *
1117 * <p>Optionally, an RtpTransceiverInit structure can be specified to configure
1118 * the transceiver from construction. If not specified, the transceiver will
1119 * default to having a direction of kSendRecv and not be part of any streams.
1120 *
1121 * <p>Note: These methods are only available with SdpSemantics.UNIFIED_PLAN specified.
1122 * @throws IllegalStateException if an error accors in C++ addTransceiver
1123 */
1124 public RtpTransceiver addTransceiver(MediaStreamTrack track) {
1125 return addTransceiver(track, new RtpTransceiver.RtpTransceiverInit());
1126 }
1127
1128 public RtpTransceiver addTransceiver(
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001129 MediaStreamTrack track, @Nullable RtpTransceiver.RtpTransceiverInit init) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001130 if (track == null) {
1131 throw new NullPointerException("No MediaStreamTrack specified for addTransceiver.");
1132 }
1133 if (init == null) {
1134 init = new RtpTransceiver.RtpTransceiverInit();
1135 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001136 RtpTransceiver newTransceiver =
1137 nativeAddTransceiverWithTrack(track.getNativeMediaStreamTrack(), init);
Seth Hampsonc384e142018-03-06 15:47:10 -08001138 if (newTransceiver == null) {
1139 throw new IllegalStateException("C++ addTransceiver failed.");
1140 }
1141 transceivers.add(newTransceiver);
1142 return newTransceiver;
1143 }
1144
1145 public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType) {
1146 return addTransceiver(mediaType, new RtpTransceiver.RtpTransceiverInit());
1147 }
1148
1149 public RtpTransceiver addTransceiver(
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001150 MediaStreamTrack.MediaType mediaType, @Nullable RtpTransceiver.RtpTransceiverInit init) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001151 if (mediaType == null) {
1152 throw new NullPointerException("No MediaType specified for addTransceiver.");
1153 }
1154 if (init == null) {
1155 init = new RtpTransceiver.RtpTransceiverInit();
1156 }
1157 RtpTransceiver newTransceiver = nativeAddTransceiverOfType(mediaType, init);
1158 if (newTransceiver == null) {
1159 throw new IllegalStateException("C++ addTransceiver failed.");
1160 }
1161 transceivers.add(newTransceiver);
1162 return newTransceiver;
1163 }
1164
deadbeef82215872017-04-18 10:27:51 -07001165 // Older, non-standard implementation of getStats.
1166 @Deprecated
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001167 public boolean getStats(StatsObserver observer, @Nullable MediaStreamTrack track) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001168 return nativeOldGetStats(observer, (track == null) ? 0 : track.getNativeMediaStreamTrack());
deadbeef82215872017-04-18 10:27:51 -07001169 }
1170
Seth Hampsonc384e142018-03-06 15:47:10 -08001171 /**
1172 * Gets stats using the new stats collection API, see webrtc/api/stats/. These
1173 * will replace old stats collection API when the new API has matured enough.
1174 */
deadbeef82215872017-04-18 10:27:51 -07001175 public void getStats(RTCStatsCollectorCallback callback) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001176 nativeNewGetStats(callback);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177 }
1178
Seth Hampsonc384e142018-03-06 15:47:10 -08001179 /**
1180 * Limits the bandwidth allocated for all RTP streams sent by this
1181 * PeerConnection. Pass null to leave a value unchanged.
1182 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001183 public boolean setBitrate(Integer min, Integer current, Integer max) {
1184 return nativeSetBitrate(min, current, max);
1185 }
zsteind89b0bc2017-08-03 11:11:40 -07001186
Seth Hampsonc384e142018-03-06 15:47:10 -08001187 /**
1188 * Starts recording an RTC event log.
1189 *
1190 * Ownership of the file is transfered to the native code. If an RTC event
1191 * log is already being recorded, it will be stopped and a new one will start
1192 * using the provided file. Logging will continue until the stopRtcEventLog
1193 * function is called. The max_size_bytes argument is ignored, it is added
1194 * for future use.
1195 */
ivoc0c6f0f62016-07-06 04:34:23 -07001196 public boolean startRtcEventLog(int file_descriptor, int max_size_bytes) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001197 return nativeStartRtcEventLog(file_descriptor, max_size_bytes);
ivoc14d5dbe2016-07-04 07:06:55 -07001198 }
1199
Seth Hampsonc384e142018-03-06 15:47:10 -08001200 /**
1201 * Stops recording an RTC event log. If no RTC event log is currently being
1202 * recorded, this call will have no effect.
1203 */
ivoc14d5dbe2016-07-04 07:06:55 -07001204 public void stopRtcEventLog() {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001205 nativeStopRtcEventLog();
ivoc14d5dbe2016-07-04 07:06:55 -07001206 }
1207
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001208 // TODO(fischman): add support for DTMF-related methods once that API
1209 // stabilizes.
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001210 public SignalingState signalingState() {
1211 return nativeSignalingState();
1212 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001214 public IceConnectionState iceConnectionState() {
1215 return nativeIceConnectionState();
1216 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217
Jonas Olssonf01d8c82018-11-08 15:19:04 +01001218 public PeerConnectionState connectionState() {
1219 return nativeConnectionState();
1220 }
1221
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001222 public IceGatheringState iceGatheringState() {
1223 return nativeIceGatheringState();
1224 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001226 public void close() {
1227 nativeClose();
1228 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001229
deadbeef43697f62017-09-12 10:52:14 -07001230 /**
1231 * Free native resources associated with this PeerConnection instance.
Seth Hampsonc384e142018-03-06 15:47:10 -08001232 *
deadbeef43697f62017-09-12 10:52:14 -07001233 * This method removes a reference count from the C++ PeerConnection object,
1234 * which should result in it being destroyed. It also calls equivalent
1235 * "dispose" methods on the Java objects attached to this PeerConnection
1236 * (streams, senders, receivers), such that their associated C++ objects
1237 * will also be destroyed.
Seth Hampsonc384e142018-03-06 15:47:10 -08001238 *
1239 * <p>Note that this method cannot be safely called from an observer callback
deadbeef43697f62017-09-12 10:52:14 -07001240 * (PeerConnection.Observer, DataChannel.Observer, etc.). If you want to, for
1241 * example, destroy the PeerConnection after an "ICE failed" callback, you
1242 * must do this asynchronously (in other words, unwind the stack first). See
1243 * <a href="https://bugs.chromium.org/p/webrtc/issues/detail?id=3721">bug
1244 * 3721</a> for more details.
1245 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246 public void dispose() {
1247 close();
1248 for (MediaStream stream : localStreams) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001249 nativeRemoveLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 stream.dispose();
1251 }
1252 localStreams.clear();
deadbeef4139c0f2015-10-06 12:29:25 -07001253 for (RtpSender sender : senders) {
1254 sender.dispose();
1255 }
1256 senders.clear();
1257 for (RtpReceiver receiver : receivers) {
1258 receiver.dispose();
1259 }
Seth Hampsonc384e142018-03-06 15:47:10 -08001260 for (RtpTransceiver transceiver : transceivers) {
1261 transceiver.dispose();
1262 }
1263 transceivers.clear();
deadbeef4139c0f2015-10-06 12:29:25 -07001264 receivers.clear();
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001265 nativeFreeOwnedPeerConnection(nativePeerConnection);
1266 }
1267
1268 /** Returns a pointer to the native webrtc::PeerConnectionInterface. */
1269 public long getNativePeerConnection() {
1270 return nativeGetNativePeerConnection();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 }
1272
Magnus Jedvert9060eb12017-12-12 12:52:54 +01001273 @CalledByNative
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001274 long getNativeOwnedPeerConnection() {
Magnus Jedvert9060eb12017-12-12 12:52:54 +01001275 return nativePeerConnection;
1276 }
1277
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001278 public static long createNativePeerConnectionObserver(Observer observer) {
1279 return nativeCreatePeerConnectionObserver(observer);
1280 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001282 private native long nativeGetNativePeerConnection();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001283 private native SessionDescription nativeGetLocalDescription();
1284 private native SessionDescription nativeGetRemoteDescription();
Michael Iedema02137862018-10-09 15:30:01 +02001285 private native RtcCertificatePem nativeGetCertificate();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001286 private native DataChannel nativeCreateDataChannel(String label, DataChannel.Init init);
1287 private native void nativeCreateOffer(SdpObserver observer, MediaConstraints constraints);
1288 private native void nativeCreateAnswer(SdpObserver observer, MediaConstraints constraints);
Yura Yaroshevich4e9e7232021-03-22 11:45:43 +03001289 private native void nativeSetLocalDescriptionAutomatically(SdpObserver observer);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001290 private native void nativeSetLocalDescription(SdpObserver observer, SessionDescription sdp);
1291 private native void nativeSetRemoteDescription(SdpObserver observer, SessionDescription sdp);
Yura Yaroshevichd8d9ac32021-03-22 12:46:47 +03001292 private native void nativeRestartIce();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001293 private native void nativeSetAudioPlayout(boolean playout);
1294 private native void nativeSetAudioRecording(boolean recording);
1295 private native boolean nativeSetBitrate(Integer min, Integer current, Integer max);
1296 private native SignalingState nativeSignalingState();
1297 private native IceConnectionState nativeIceConnectionState();
Jonas Olssonf01d8c82018-11-08 15:19:04 +01001298 private native PeerConnectionState nativeConnectionState();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001299 private native IceGatheringState nativeIceGatheringState();
1300 private native void nativeClose();
1301 private static native long nativeCreatePeerConnectionObserver(Observer observer);
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001302 private static native void nativeFreeOwnedPeerConnection(long ownedPeerConnection);
1303 private native boolean nativeSetConfiguration(RTCConfiguration config);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001304 private native boolean nativeAddIceCandidate(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 String sdpMid, int sdpMLineIndex, String iceCandidateSdp);
Yura Yaroshevich1cdeb0a2021-04-08 16:56:56 +03001306 private native void nativeAddIceCandidateWithObserver(
1307 String sdpMid, int sdpMLineIndex, String iceCandidateSdp, AddIceObserver observer);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001308 private native boolean nativeRemoveIceCandidates(final IceCandidate[] candidates);
1309 private native boolean nativeAddLocalStream(long stream);
1310 private native void nativeRemoveLocalStream(long stream);
1311 private native boolean nativeOldGetStats(StatsObserver observer, long nativeTrack);
1312 private native void nativeNewGetStats(RTCStatsCollectorCallback callback);
1313 private native RtpSender nativeCreateSender(String kind, String stream_id);
1314 private native List<RtpSender> nativeGetSenders();
1315 private native List<RtpReceiver> nativeGetReceivers();
Seth Hampsonc384e142018-03-06 15:47:10 -08001316 private native List<RtpTransceiver> nativeGetTransceivers();
1317 private native RtpSender nativeAddTrack(long track, List<String> streamIds);
1318 private native boolean nativeRemoveTrack(long sender);
1319 private native RtpTransceiver nativeAddTransceiverWithTrack(
1320 long track, RtpTransceiver.RtpTransceiverInit init);
1321 private native RtpTransceiver nativeAddTransceiverOfType(
1322 MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001323 private native boolean nativeStartRtcEventLog(int file_descriptor, int max_size_bytes);
1324 private native void nativeStopRtcEventLog();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325}