blob: 7ad72c4eb45db4de3606450bf3c12483ebfbb81d [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
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700121 /** Triggered when some ICE candidates have been removed. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100122 @CalledByNative("Observer") void onIceCandidatesRemoved(IceCandidate[] candidates);
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700123
Alex Drake43faee02019-08-12 16:27:34 -0700124 /** Triggered when the ICE candidate pair is changed. */
125 @CalledByNative("Observer")
126 default void onSelectedCandidatePairChanged(CandidatePairChangeEvent event) {}
127
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128 /** Triggered when media is received on a new stream from remote peer. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100129 @CalledByNative("Observer") void onAddStream(MediaStream stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130
131 /** Triggered when a remote peer close a stream. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100132 @CalledByNative("Observer") void onRemoveStream(MediaStream stream);
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000133
134 /** Triggered when a remote peer opens a DataChannel. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100135 @CalledByNative("Observer") void onDataChannel(DataChannel dataChannel);
fischman@webrtc.orgd7568a02014-01-13 22:04:12 +0000136
137 /** Triggered when renegotiation is necessary. */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100138 @CalledByNative("Observer") void onRenegotiationNeeded();
zhihuangdcccda72016-12-21 14:08:03 -0800139
140 /**
141 * Triggered when a new track is signaled by the remote peer, as a result of
142 * setRemoteDescription.
143 */
Jesús Leganés-Combarro 'pirannaffbfba92021-05-25 10:35:10 +0200144 @CalledByNative("Observer")
145 default void onAddTrack(RtpReceiver receiver, MediaStream[] mediaStreams){};
146
147 /**
148 * Triggered when a previously added remote track is removed by the remote
149 * peer, as a result of setRemoteDescription.
150 */
151 @CalledByNative("Observer") default void onRemoveTrack(RtpReceiver receiver){};
Seth Hampson31dbc242018-05-07 09:28:19 -0700152
153 /**
154 * Triggered when the signaling from SetRemoteDescription indicates that a transceiver
155 * will be receiving media from a remote endpoint. This is only called if UNIFIED_PLAN
156 * semantics are specified. The transceiver will be disposed automatically.
157 */
158 @CalledByNative("Observer") default void onTrack(RtpTransceiver transceiver){};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 }
160
161 /** Java version of PeerConnectionInterface.IceServer. */
162 public static class IceServer {
Emad Omaradab1d2d2017-06-16 15:43:11 -0700163 // List of URIs associated with this server. Valid formats are described
164 // in RFC7064 and RFC7065, and more may be added in the future. The "host"
165 // part of the URI may contain either an IP address or a hostname.
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700166 @Deprecated public final String uri;
167 public final List<String> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 public final String username;
169 public final String password;
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000170 public final TlsCertPolicy tlsCertPolicy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171
Artem Titovd7ac5812021-07-27 12:23:39 +0200172 // If the URIs in `urls` only contain IP addresses, this field can be used
Emad Omaradab1d2d2017-06-16 15:43:11 -0700173 // to indicate the hostname, which may be necessary for TLS (using the SNI
Artem Titovd7ac5812021-07-27 12:23:39 +0200174 // extension). If `urls` itself contains the hostname, this isn't
Emad Omaradab1d2d2017-06-16 15:43:11 -0700175 // necessary.
176 public final String hostname;
177
Diogo Real1dca9d52017-08-29 12:18:32 -0700178 // List of protocols to be used in the TLS ALPN extension.
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000179 public final List<String> tlsAlpnProtocols;
Diogo Real1dca9d52017-08-29 12:18:32 -0700180
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700181 // List of elliptic curves to be used in the TLS elliptic curves extension.
182 // Only curve names supported by OpenSSL should be used (eg. "P-256","X25519").
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000183 public final List<String> tlsEllipticCurves;
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700184
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 /** Convenience constructor for STUN servers. */
Diogo Real05ea2b32017-08-31 00:12:58 -0700186 @Deprecated
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 public IceServer(String uri) {
188 this(uri, "", "");
189 }
190
Diogo Real05ea2b32017-08-31 00:12:58 -0700191 @Deprecated
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 public IceServer(String uri, String username, String password) {
hnsl04833622017-01-09 08:35:45 -0800193 this(uri, username, password, TlsCertPolicy.TLS_CERT_POLICY_SECURE);
194 }
195
Diogo Real05ea2b32017-08-31 00:12:58 -0700196 @Deprecated
hnsl04833622017-01-09 08:35:45 -0800197 public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy) {
Emad Omaradab1d2d2017-06-16 15:43:11 -0700198 this(uri, username, password, tlsCertPolicy, "");
199 }
200
Diogo Real05ea2b32017-08-31 00:12:58 -0700201 @Deprecated
Emad Omaradab1d2d2017-06-16 15:43:11 -0700202 public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy,
203 String hostname) {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700204 this(uri, Collections.singletonList(uri), username, password, tlsCertPolicy, hostname, null,
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000205 null);
Diogo Real1dca9d52017-08-29 12:18:32 -0700206 }
207
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700208 private IceServer(String uri, List<String> urls, String username, String password,
209 TlsCertPolicy tlsCertPolicy, String hostname, List<String> tlsAlpnProtocols,
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000210 List<String> tlsEllipticCurves) {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700211 if (uri == null || urls == null || urls.isEmpty()) {
212 throw new IllegalArgumentException("uri == null || urls == null || urls.isEmpty()");
213 }
214 for (String it : urls) {
215 if (it == null) {
216 throw new IllegalArgumentException("urls element is null: " + urls);
217 }
218 }
219 if (username == null) {
220 throw new IllegalArgumentException("username == null");
221 }
222 if (password == null) {
223 throw new IllegalArgumentException("password == null");
224 }
225 if (hostname == null) {
226 throw new IllegalArgumentException("hostname == null");
227 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 this.uri = uri;
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700229 this.urls = urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 this.username = username;
231 this.password = password;
hnsl04833622017-01-09 08:35:45 -0800232 this.tlsCertPolicy = tlsCertPolicy;
Emad Omaradab1d2d2017-06-16 15:43:11 -0700233 this.hostname = hostname;
Diogo Real1dca9d52017-08-29 12:18:32 -0700234 this.tlsAlpnProtocols = tlsAlpnProtocols;
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700235 this.tlsEllipticCurves = tlsEllipticCurves;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 }
237
Sami Kalliomäkibde473e2017-10-30 13:34:41 +0100238 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 public String toString() {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700240 return urls + " [" + username + ":" + password + "] [" + tlsCertPolicy + "] [" + hostname
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000241 + "] [" + tlsAlpnProtocols + "] [" + tlsEllipticCurves + "]";
Diogo Real1dca9d52017-08-29 12:18:32 -0700242 }
243
Qingsi Wanga0d45802019-01-15 13:33:11 -0800244 @Override
245 public boolean equals(@Nullable Object obj) {
246 if (obj == null) {
247 return false;
248 }
249 if (obj == this) {
250 return true;
251 }
252 if (!(obj instanceof IceServer)) {
253 return false;
254 }
255 IceServer other = (IceServer) obj;
256 return (uri.equals(other.uri) && urls.equals(other.urls) && username.equals(other.username)
257 && password.equals(other.password) && tlsCertPolicy.equals(other.tlsCertPolicy)
258 && hostname.equals(other.hostname) && tlsAlpnProtocols.equals(other.tlsAlpnProtocols)
259 && tlsEllipticCurves.equals(other.tlsEllipticCurves));
260 }
261
262 @Override
263 public int hashCode() {
264 Object[] values = {uri, urls, username, password, tlsCertPolicy, hostname, tlsAlpnProtocols,
265 tlsEllipticCurves};
266 return Arrays.hashCode(values);
267 }
268
Diogo Real1dca9d52017-08-29 12:18:32 -0700269 public static Builder builder(String uri) {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700270 return new Builder(Collections.singletonList(uri));
271 }
272
273 public static Builder builder(List<String> urls) {
274 return new Builder(urls);
Diogo Real1dca9d52017-08-29 12:18:32 -0700275 }
276
277 public static class Builder {
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100278 @Nullable private final List<String> urls;
Diogo Real1dca9d52017-08-29 12:18:32 -0700279 private String username = "";
280 private String password = "";
281 private TlsCertPolicy tlsCertPolicy = TlsCertPolicy.TLS_CERT_POLICY_SECURE;
282 private String hostname = "";
283 private List<String> tlsAlpnProtocols;
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700284 private List<String> tlsEllipticCurves;
Diogo Real1dca9d52017-08-29 12:18:32 -0700285
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700286 private Builder(List<String> urls) {
287 if (urls == null || urls.isEmpty()) {
288 throw new IllegalArgumentException("urls == null || urls.isEmpty(): " + urls);
289 }
290 this.urls = urls;
Diogo Real1dca9d52017-08-29 12:18:32 -0700291 }
292
293 public Builder setUsername(String username) {
294 this.username = username;
295 return this;
296 }
297
298 public Builder setPassword(String password) {
299 this.password = password;
300 return this;
301 }
302
303 public Builder setTlsCertPolicy(TlsCertPolicy tlsCertPolicy) {
304 this.tlsCertPolicy = tlsCertPolicy;
305 return this;
306 }
307
308 public Builder setHostname(String hostname) {
309 this.hostname = hostname;
310 return this;
311 }
312
313 public Builder setTlsAlpnProtocols(List<String> tlsAlpnProtocols) {
314 this.tlsAlpnProtocols = tlsAlpnProtocols;
315 return this;
316 }
317
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700318 public Builder setTlsEllipticCurves(List<String> tlsEllipticCurves) {
319 this.tlsEllipticCurves = tlsEllipticCurves;
320 return this;
321 }
322
Diogo Real1dca9d52017-08-29 12:18:32 -0700323 public IceServer createIceServer() {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700324 return new IceServer(urls.get(0), urls, username, password, tlsCertPolicy, hostname,
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000325 tlsAlpnProtocols, tlsEllipticCurves);
Diogo Real1dca9d52017-08-29 12:18:32 -0700326 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100328
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100329 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100330 @CalledByNative("IceServer")
331 List<String> getUrls() {
332 return urls;
333 }
334
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100335 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100336 @CalledByNative("IceServer")
337 String getUsername() {
338 return username;
339 }
340
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100341 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100342 @CalledByNative("IceServer")
343 String getPassword() {
344 return password;
345 }
346
347 @CalledByNative("IceServer")
348 TlsCertPolicy getTlsCertPolicy() {
349 return tlsCertPolicy;
350 }
351
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100352 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100353 @CalledByNative("IceServer")
354 String getHostname() {
355 return hostname;
356 }
357
358 @CalledByNative("IceServer")
359 List<String> getTlsAlpnProtocols() {
360 return tlsAlpnProtocols;
361 }
362
363 @CalledByNative("IceServer")
364 List<String> getTlsEllipticCurves() {
365 return tlsEllipticCurves;
366 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 }
368
Jiayang Liucac1b382015-04-30 12:35:24 -0700369 /** Java version of PeerConnectionInterface.IceTransportsType */
sakalb6760f92016-09-29 04:12:44 -0700370 public enum IceTransportsType { NONE, RELAY, NOHOST, ALL }
Jiayang Liucac1b382015-04-30 12:35:24 -0700371
372 /** Java version of PeerConnectionInterface.BundlePolicy */
sakalb6760f92016-09-29 04:12:44 -0700373 public enum BundlePolicy { BALANCED, MAXBUNDLE, MAXCOMPAT }
Jiayang Liucac1b382015-04-30 12:35:24 -0700374
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700375 /** Java version of PeerConnectionInterface.RtcpMuxPolicy */
sakalb6760f92016-09-29 04:12:44 -0700376 public enum RtcpMuxPolicy { NEGOTIATE, REQUIRE }
glaznev97579a42015-09-01 11:31:27 -0700377
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700378 /** Java version of PeerConnectionInterface.TcpCandidatePolicy */
sakalb6760f92016-09-29 04:12:44 -0700379 public enum TcpCandidatePolicy { ENABLED, DISABLED }
Jiayang Liucac1b382015-04-30 12:35:24 -0700380
honghaiz60347052016-05-31 18:29:12 -0700381 /** Java version of PeerConnectionInterface.CandidateNetworkPolicy */
sakalb6760f92016-09-29 04:12:44 -0700382 public enum CandidateNetworkPolicy { ALL, LOW_COST }
honghaiz60347052016-05-31 18:29:12 -0700383
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800384 // Keep in sync with webrtc/rtc_base/network_constants.h.
385 public enum AdapterType {
Alex Drake68c2a562019-08-13 15:56:07 -0700386 UNKNOWN(0),
387 ETHERNET(1 << 0),
388 WIFI(1 << 1),
389 CELLULAR(1 << 2),
390 VPN(1 << 3),
391 LOOPBACK(1 << 4),
Jonas Oreland0cc37302020-04-02 18:26:26 +0200392 ADAPTER_TYPE_ANY(1 << 5),
393 CELLULAR_2G(1 << 6),
394 CELLULAR_3G(1 << 7),
395 CELLULAR_4G(1 << 8),
396 CELLULAR_5G(1 << 9);
Alex Drake68c2a562019-08-13 15:56:07 -0700397
398 public final Integer bitMask;
399 private AdapterType(Integer bitMask) {
400 this.bitMask = bitMask;
401 }
402 private static final Map<Integer, AdapterType> BY_BITMASK = new HashMap<>();
403 static {
404 for (AdapterType t : values()) {
405 BY_BITMASK.put(t.bitMask, t);
406 }
407 }
408
Yves Gerey29e07e52019-11-19 12:13:25 +0100409 @Nullable
Alex Drake68c2a562019-08-13 15:56:07 -0700410 @CalledByNative("AdapterType")
411 static AdapterType fromNativeIndex(int nativeIndex) {
412 return BY_BITMASK.get(nativeIndex);
413 }
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800414 }
415
glaznev97579a42015-09-01 11:31:27 -0700416 /** Java version of rtc::KeyType */
sakalb6760f92016-09-29 04:12:44 -0700417 public enum KeyType { RSA, ECDSA }
glaznev97579a42015-09-01 11:31:27 -0700418
honghaiz1f429e32015-09-28 07:57:34 -0700419 /** Java version of PeerConnectionInterface.ContinualGatheringPolicy */
sakalb6760f92016-09-29 04:12:44 -0700420 public enum ContinualGatheringPolicy { GATHER_ONCE, GATHER_CONTINUALLY }
honghaiz1f429e32015-09-28 07:57:34 -0700421
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700422 /** Java version of webrtc::PortPrunePolicy */
423 public enum PortPrunePolicy {
424 NO_PRUNE, // Do not prune turn port.
425 PRUNE_BASED_ON_PRIORITY, // Prune turn port based the priority on the same network
426 KEEP_FIRST_READY // Keep the first ready port and prune the rest on the same network.
427 }
428
Seth Hampsonc384e142018-03-06 15:47:10 -0800429 /**
430 * Java version of webrtc::SdpSemantics.
431 *
432 * Configure the SDP semantics used by this PeerConnection. Note that the
433 * WebRTC 1.0 specification requires UNIFIED_PLAN semantics. The
434 * RtpTransceiver API is only available with UNIFIED_PLAN semantics.
435 *
436 * <p>PLAN_B will cause PeerConnection to create offers and answers with at
437 * most one audio and one video m= section with multiple RtpSenders and
438 * RtpReceivers specified as multiple a=ssrc lines within the section. This
439 * will also cause PeerConnection to ignore all but the first m= section of
440 * the same media type.
441 *
442 * <p>UNIFIED_PLAN will cause PeerConnection to create offers and answers with
443 * multiple m= sections where each m= section maps to one RtpSender and one
444 * RtpReceiver (an RtpTransceiver), either both audio or both video. This
445 * will also cause PeerConnection to ignore all but the first a=ssrc lines
446 * that form a Plan B stream.
447 *
448 * <p>For users who wish to send multiple audio/video streams and need to stay
449 * interoperable with legacy WebRTC implementations, specify PLAN_B.
450 *
451 * <p>For users who wish to send multiple audio/video streams and/or wish to
452 * use the new RtpTransceiver API, specify UNIFIED_PLAN.
453 */
454 public enum SdpSemantics { PLAN_B, UNIFIED_PLAN }
455
Jiayang Liucac1b382015-04-30 12:35:24 -0700456 /** Java version of PeerConnectionInterface.RTCConfiguration */
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800457 // TODO(qingsi): Resolve the naming inconsistency of fields with/without units.
Jiayang Liucac1b382015-04-30 12:35:24 -0700458 public static class RTCConfiguration {
459 public IceTransportsType iceTransportsType;
460 public List<IceServer> iceServers;
461 public BundlePolicy bundlePolicy;
Michael Iedema02137862018-10-09 15:30:01 +0200462 @Nullable public RtcCertificatePem certificate;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700463 public RtcpMuxPolicy rtcpMuxPolicy;
Jiayang Liucac1b382015-04-30 12:35:24 -0700464 public TcpCandidatePolicy tcpCandidatePolicy;
honghaiz60347052016-05-31 18:29:12 -0700465 public CandidateNetworkPolicy candidateNetworkPolicy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200466 public int audioJitterBufferMaxPackets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200467 public boolean audioJitterBufferFastAccelerate;
honghaiz4edc39c2015-09-01 09:53:56 -0700468 public int iceConnectionReceivingTimeout;
Honghai Zhang381b4212015-12-04 12:24:03 -0800469 public int iceBackupCandidatePairPingInterval;
glaznev97579a42015-09-01 11:31:27 -0700470 public KeyType keyType;
honghaiz1f429e32015-09-28 07:57:34 -0700471 public ContinualGatheringPolicy continualGatheringPolicy;
deadbeefbe0c96f2016-05-18 16:20:14 -0700472 public int iceCandidatePoolSize;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700473 @Deprecated // by the turnPortPrunePolicy. See bugs.webrtc.org/11026
Honghai Zhangd78ecf72016-07-01 14:40:40 -0700474 public boolean pruneTurnPorts;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700475 public PortPrunePolicy turnPortPrunePolicy;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700476 public boolean presumeWritableWhenFullyRelayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700477 public boolean surfaceIceCandidatesOnIceTransportTypeChanged;
Qingsi Wange6826d22018-03-08 14:55:14 -0800478 // The following fields define intervals in milliseconds at which ICE
479 // connectivity checks are sent.
480 //
481 // We consider ICE is "strongly connected" for an agent when there is at
482 // least one candidate pair that currently succeeds in connectivity check
483 // from its direction i.e. sending a ping and receives a ping response, AND
484 // all candidate pairs have sent a minimum number of pings for connectivity
485 // (this number is implementation-specific). Otherwise, ICE is considered in
486 // "weak connectivity".
487 //
488 // Note that the above notion of strong and weak connectivity is not defined
489 // in RFC 5245, and they apply to our current ICE implementation only.
490 //
491 // 1) iceCheckIntervalStrongConnectivityMs defines the interval applied to
492 // ALL candidate pairs when ICE is strongly connected,
493 // 2) iceCheckIntervalWeakConnectivityMs defines the counterpart for ALL
494 // pairs when ICE is weakly connected, and
495 // 3) iceCheckMinInterval defines the minimal interval (equivalently the
496 // maximum rate) that overrides the above two intervals when either of them
497 // is less.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100498 @Nullable public Integer iceCheckIntervalStrongConnectivityMs;
499 @Nullable public Integer iceCheckIntervalWeakConnectivityMs;
500 @Nullable public Integer iceCheckMinInterval;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700501 // The time period in milliseconds for which a candidate pair must wait for response to
502 // connectivitiy checks before it becomes unwritable.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100503 @Nullable public Integer iceUnwritableTimeMs;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700504 // The minimum number of connectivity checks that a candidate pair must sent without receiving
505 // response before it becomes unwritable.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100506 @Nullable public Integer iceUnwritableMinChecks;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800507 // The interval in milliseconds at which STUN candidates will resend STUN binding requests
508 // to keep NAT bindings open.
509 // The default value in the implementation is used if this field is null.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100510 @Nullable public Integer stunCandidateKeepaliveIntervalMs;
Derek Bailey6c127a12021-04-15 12:42:41 -0700511 // The interval in milliseconds of pings sent when the connection is stable and writable.
512 // The default value in the implementation is used if this field is null.
513 @Nullable public Integer stableWritableConnectionPingIntervalMs;
zhihuangb09b3f92017-03-07 14:40:51 -0800514 public boolean disableIPv6OnWifi;
deadbeef28e29192017-07-27 09:14:38 -0700515 // By default, PeerConnection will use a limited number of IPv6 network
516 // interfaces, in order to avoid too many ICE candidate pairs being created
517 // and delaying ICE completion.
518 //
519 // Can be set to Integer.MAX_VALUE to effectively disable the limit.
520 public int maxIPv6Networks;
Jiayang Liucac1b382015-04-30 12:35:24 -0700521
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100522 // These values will be overridden by MediaStream constraints if deprecated constraints-based
523 // create peerconnection interface is used.
524 public boolean disableIpv6;
525 public boolean enableDscp;
526 public boolean enableCpuOveruseDetection;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100527 public boolean suspendBelowMinBitrate;
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100528 @Nullable public Integer screencastMinBitrate;
529 @Nullable public Boolean combinedAudioVideoBwe;
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800530 // Use "Unknown" to represent no preference of adapter types, not the
531 // preference of adapters of unknown types.
532 public AdapterType networkPreference;
Seth Hampsonc384e142018-03-06 15:47:10 -0800533 public SdpSemantics sdpSemantics;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100534
Jonas Orelandbdcee282017-10-10 14:01:40 +0200535 // This is an optional wrapper for the C++ webrtc::TurnCustomizer.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100536 @Nullable public TurnCustomizer turnCustomizer;
Jonas Orelandbdcee282017-10-10 14:01:40 +0200537
Zhi Huangb57e1692018-06-12 11:41:11 -0700538 // Actively reset the SRTP parameters whenever the DTLS transports underneath are reset for
539 // every offer/answer negotiation.This is only intended to be a workaround for crbug.com/835958
540 public boolean activeResetSrtpParams;
541
philipel16cec3b2019-10-25 12:23:02 +0200542 // Whether this client is allowed to switch encoding codec mid-stream. This is a workaround for
543 // a WebRTC bug where the receiver could get confussed if a codec switch happened mid-call.
544 // Null indicates no change to currently configured value.
545 @Nullable public Boolean allowCodecSwitching;
546
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700547 /**
548 * Defines advanced optional cryptographic settings related to SRTP and
549 * frame encryption for native WebRTC. Setting this will overwrite any
550 * options set through the PeerConnectionFactory (which is deprecated).
551 */
552 @Nullable public CryptoOptions cryptoOptions;
553
Jonas Oreland228900f2019-08-28 09:08:58 +0200554 /**
555 * An optional string that if set will be attached to the
556 * TURN_ALLOCATE_REQUEST which can be used to correlate client
557 * logs with backend logs
558 */
559 @Nullable public String turnLoggingId;
560
Yura Yaroshevich90fab632021-03-22 17:10:33 +0300561 /**
562 * Allow implicit rollback of local description when remote description
563 * conflicts with local description.
564 * See: https://w3c.github.io/webrtc-pc/#dom-peerconnection-setremotedescription
565 */
566 public boolean enableImplicitRollback;
567
568 /**
569 * Control if "a=extmap-allow-mixed" is included in the offer.
570 * See: https://www.chromestatus.com/feature/6269234631933952
571 */
572 public boolean offerExtmapAllowMixed;
573
deadbeef28e29192017-07-27 09:14:38 -0700574 // TODO(deadbeef): Instead of duplicating the defaults here, we should do
575 // something to pick up the defaults from C++. The Objective-C equivalent
576 // of RTCConfiguration does that.
Jiayang Liucac1b382015-04-30 12:35:24 -0700577 public RTCConfiguration(List<IceServer> iceServers) {
578 iceTransportsType = IceTransportsType.ALL;
579 bundlePolicy = BundlePolicy.BALANCED;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800580 rtcpMuxPolicy = RtcpMuxPolicy.REQUIRE;
Jiayang Liucac1b382015-04-30 12:35:24 -0700581 tcpCandidatePolicy = TcpCandidatePolicy.ENABLED;
Sami Kalliomäki9828beb2017-10-26 16:21:22 +0200582 candidateNetworkPolicy = CandidateNetworkPolicy.ALL;
Jiayang Liucac1b382015-04-30 12:35:24 -0700583 this.iceServers = iceServers;
Henrik Lundin64dad832015-05-11 12:44:23 +0200584 audioJitterBufferMaxPackets = 50;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200585 audioJitterBufferFastAccelerate = false;
honghaiz4edc39c2015-09-01 09:53:56 -0700586 iceConnectionReceivingTimeout = -1;
Honghai Zhang381b4212015-12-04 12:24:03 -0800587 iceBackupCandidatePairPingInterval = -1;
glaznev97579a42015-09-01 11:31:27 -0700588 keyType = KeyType.ECDSA;
honghaiz1f429e32015-09-28 07:57:34 -0700589 continualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE;
deadbeefbe0c96f2016-05-18 16:20:14 -0700590 iceCandidatePoolSize = 0;
Honghai Zhangd78ecf72016-07-01 14:40:40 -0700591 pruneTurnPorts = false;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700592 turnPortPrunePolicy = PortPrunePolicy.NO_PRUNE;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700593 presumeWritableWhenFullyRelayed = false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700594 surfaceIceCandidatesOnIceTransportTypeChanged = false;
Qingsi Wange6826d22018-03-08 14:55:14 -0800595 iceCheckIntervalStrongConnectivityMs = null;
596 iceCheckIntervalWeakConnectivityMs = null;
skvlad51072462017-02-02 11:50:14 -0800597 iceCheckMinInterval = null;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700598 iceUnwritableTimeMs = null;
599 iceUnwritableMinChecks = null;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800600 stunCandidateKeepaliveIntervalMs = null;
Derek Bailey6c127a12021-04-15 12:42:41 -0700601 stableWritableConnectionPingIntervalMs = null;
zhihuangb09b3f92017-03-07 14:40:51 -0800602 disableIPv6OnWifi = false;
deadbeef28e29192017-07-27 09:14:38 -0700603 maxIPv6Networks = 5;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100604 disableIpv6 = false;
605 enableDscp = false;
606 enableCpuOveruseDetection = true;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100607 suspendBelowMinBitrate = false;
608 screencastMinBitrate = null;
609 combinedAudioVideoBwe = null;
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800610 networkPreference = AdapterType.UNKNOWN;
Seth Hampsonc384e142018-03-06 15:47:10 -0800611 sdpSemantics = SdpSemantics.PLAN_B;
Zhi Huangb57e1692018-06-12 11:41:11 -0700612 activeResetSrtpParams = false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700613 cryptoOptions = null;
Jonas Oreland228900f2019-08-28 09:08:58 +0200614 turnLoggingId = null;
philipel16cec3b2019-10-25 12:23:02 +0200615 allowCodecSwitching = null;
Yura Yaroshevich90fab632021-03-22 17:10:33 +0300616 enableImplicitRollback = false;
617 offerExtmapAllowMixed = true;
Jiayang Liucac1b382015-04-30 12:35:24 -0700618 }
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100619
620 @CalledByNative("RTCConfiguration")
621 IceTransportsType getIceTransportsType() {
622 return iceTransportsType;
623 }
624
625 @CalledByNative("RTCConfiguration")
626 List<IceServer> getIceServers() {
627 return iceServers;
628 }
629
630 @CalledByNative("RTCConfiguration")
631 BundlePolicy getBundlePolicy() {
632 return bundlePolicy;
633 }
634
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700635 @CalledByNative("RTCConfiguration")
636 PortPrunePolicy getTurnPortPrunePolicy() {
637 return turnPortPrunePolicy;
638 }
639
Michael Iedema02137862018-10-09 15:30:01 +0200640 @Nullable
641 @CalledByNative("RTCConfiguration")
642 RtcCertificatePem getCertificate() {
643 return certificate;
644 }
645
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100646 @CalledByNative("RTCConfiguration")
647 RtcpMuxPolicy getRtcpMuxPolicy() {
648 return rtcpMuxPolicy;
649 }
650
651 @CalledByNative("RTCConfiguration")
652 TcpCandidatePolicy getTcpCandidatePolicy() {
653 return tcpCandidatePolicy;
654 }
655
656 @CalledByNative("RTCConfiguration")
657 CandidateNetworkPolicy getCandidateNetworkPolicy() {
658 return candidateNetworkPolicy;
659 }
660
661 @CalledByNative("RTCConfiguration")
662 int getAudioJitterBufferMaxPackets() {
663 return audioJitterBufferMaxPackets;
664 }
665
666 @CalledByNative("RTCConfiguration")
667 boolean getAudioJitterBufferFastAccelerate() {
668 return audioJitterBufferFastAccelerate;
669 }
670
671 @CalledByNative("RTCConfiguration")
672 int getIceConnectionReceivingTimeout() {
673 return iceConnectionReceivingTimeout;
674 }
675
676 @CalledByNative("RTCConfiguration")
677 int getIceBackupCandidatePairPingInterval() {
678 return iceBackupCandidatePairPingInterval;
679 }
680
681 @CalledByNative("RTCConfiguration")
682 KeyType getKeyType() {
683 return keyType;
684 }
685
686 @CalledByNative("RTCConfiguration")
687 ContinualGatheringPolicy getContinualGatheringPolicy() {
688 return continualGatheringPolicy;
689 }
690
691 @CalledByNative("RTCConfiguration")
692 int getIceCandidatePoolSize() {
693 return iceCandidatePoolSize;
694 }
695
696 @CalledByNative("RTCConfiguration")
697 boolean getPruneTurnPorts() {
698 return pruneTurnPorts;
699 }
700
701 @CalledByNative("RTCConfiguration")
702 boolean getPresumeWritableWhenFullyRelayed() {
703 return presumeWritableWhenFullyRelayed;
704 }
705
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700706 @CalledByNative("RTCConfiguration")
707 boolean getSurfaceIceCandidatesOnIceTransportTypeChanged() {
708 return surfaceIceCandidatesOnIceTransportTypeChanged;
709 }
710
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100711 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100712 @CalledByNative("RTCConfiguration")
Qingsi Wange6826d22018-03-08 14:55:14 -0800713 Integer getIceCheckIntervalStrongConnectivity() {
714 return iceCheckIntervalStrongConnectivityMs;
715 }
716
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100717 @Nullable
Qingsi Wange6826d22018-03-08 14:55:14 -0800718 @CalledByNative("RTCConfiguration")
719 Integer getIceCheckIntervalWeakConnectivity() {
720 return iceCheckIntervalWeakConnectivityMs;
721 }
722
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100723 @Nullable
Qingsi Wange6826d22018-03-08 14:55:14 -0800724 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100725 Integer getIceCheckMinInterval() {
726 return iceCheckMinInterval;
727 }
728
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100729 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100730 @CalledByNative("RTCConfiguration")
Qingsi Wang22e623a2018-03-13 10:53:57 -0700731 Integer getIceUnwritableTimeout() {
732 return iceUnwritableTimeMs;
733 }
734
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100735 @Nullable
Qingsi Wang22e623a2018-03-13 10:53:57 -0700736 @CalledByNative("RTCConfiguration")
737 Integer getIceUnwritableMinChecks() {
738 return iceUnwritableMinChecks;
739 }
740
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100741 @Nullable
Qingsi Wang22e623a2018-03-13 10:53:57 -0700742 @CalledByNative("RTCConfiguration")
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800743 Integer getStunCandidateKeepaliveInterval() {
744 return stunCandidateKeepaliveIntervalMs;
745 }
746
Derek Bailey6c127a12021-04-15 12:42:41 -0700747 @Nullable
748 @CalledByNative("RTCConfiguration")
749 Integer getStableWritableConnectionPingIntervalMs() {
750 return stableWritableConnectionPingIntervalMs;
751 }
752
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800753 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100754 boolean getDisableIPv6OnWifi() {
755 return disableIPv6OnWifi;
756 }
757
758 @CalledByNative("RTCConfiguration")
759 int getMaxIPv6Networks() {
760 return maxIPv6Networks;
761 }
762
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100763 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100764 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100765 TurnCustomizer getTurnCustomizer() {
766 return turnCustomizer;
767 }
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100768
769 @CalledByNative("RTCConfiguration")
770 boolean getDisableIpv6() {
771 return disableIpv6;
772 }
773
774 @CalledByNative("RTCConfiguration")
775 boolean getEnableDscp() {
776 return enableDscp;
777 }
778
779 @CalledByNative("RTCConfiguration")
780 boolean getEnableCpuOveruseDetection() {
781 return enableCpuOveruseDetection;
782 }
783
784 @CalledByNative("RTCConfiguration")
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100785 boolean getSuspendBelowMinBitrate() {
786 return suspendBelowMinBitrate;
787 }
788
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100789 @Nullable
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100790 @CalledByNative("RTCConfiguration")
791 Integer getScreencastMinBitrate() {
792 return screencastMinBitrate;
793 }
794
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100795 @Nullable
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100796 @CalledByNative("RTCConfiguration")
797 Boolean getCombinedAudioVideoBwe() {
798 return combinedAudioVideoBwe;
799 }
800
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800801 @CalledByNative("RTCConfiguration")
802 AdapterType getNetworkPreference() {
803 return networkPreference;
804 }
Seth Hampsonc384e142018-03-06 15:47:10 -0800805
806 @CalledByNative("RTCConfiguration")
807 SdpSemantics getSdpSemantics() {
808 return sdpSemantics;
809 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700810
811 @CalledByNative("RTCConfiguration")
812 boolean getActiveResetSrtpParams() {
813 return activeResetSrtpParams;
814 }
Piotr (Peter) Slatala09beff22018-10-17 07:22:40 -0700815
philipel16cec3b2019-10-25 12:23:02 +0200816 @Nullable
817 @CalledByNative("RTCConfiguration")
818 Boolean getAllowCodecSwitching() {
819 return allowCodecSwitching;
820 }
821
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700822 @Nullable
823 @CalledByNative("RTCConfiguration")
824 CryptoOptions getCryptoOptions() {
825 return cryptoOptions;
826 }
Jonas Oreland228900f2019-08-28 09:08:58 +0200827
828 @Nullable
829 @CalledByNative("RTCConfiguration")
830 String getTurnLoggingId() {
831 return turnLoggingId;
832 }
Yura Yaroshevich90fab632021-03-22 17:10:33 +0300833
834 @CalledByNative("RTCConfiguration")
835 boolean getEnableImplicitRollback() {
836 return enableImplicitRollback;
837 }
838
839 @CalledByNative("RTCConfiguration")
840 boolean getOfferExtmapAllowMixed() {
841 return offerExtmapAllowMixed;
842 }
Jiayang Liucac1b382015-04-30 12:35:24 -0700843 };
844
Magnus Jedvert6062f372017-11-16 16:53:12 +0100845 private final List<MediaStream> localStreams = new ArrayList<>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 private final long nativePeerConnection;
Magnus Jedvert6062f372017-11-16 16:53:12 +0100847 private List<RtpSender> senders = new ArrayList<>();
848 private List<RtpReceiver> receivers = new ArrayList<>();
Seth Hampsonc384e142018-03-06 15:47:10 -0800849 private List<RtpTransceiver> transceivers = new ArrayList<>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850
Sami Kalliomäki1ece1ed2017-12-20 11:59:22 +0100851 /**
852 * Wraps a PeerConnection created by the factory. Can be used by clients that want to implement
853 * their PeerConnection creation in JNI.
854 */
855 public PeerConnection(NativePeerConnectionFactory factory) {
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100856 this(factory.createNativePeerConnection());
Sami Kalliomäki1ece1ed2017-12-20 11:59:22 +0100857 }
858
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100859 PeerConnection(long nativePeerConnection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 this.nativePeerConnection = nativePeerConnection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 }
862
863 // JsepInterface.
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100864 public SessionDescription getLocalDescription() {
865 return nativeGetLocalDescription();
866 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100868 public SessionDescription getRemoteDescription() {
869 return nativeGetRemoteDescription();
870 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871
Michael Iedema02137862018-10-09 15:30:01 +0200872 public RtcCertificatePem getCertificate() {
873 return nativeGetCertificate();
874 }
875
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100876 public DataChannel createDataChannel(String label, DataChannel.Init init) {
877 return nativeCreateDataChannel(label, init);
878 }
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000879
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100880 public void createOffer(SdpObserver observer, MediaConstraints constraints) {
881 nativeCreateOffer(observer, constraints);
882 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100884 public void createAnswer(SdpObserver observer, MediaConstraints constraints) {
885 nativeCreateAnswer(observer, constraints);
886 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887
Yura Yaroshevich4e9e7232021-03-22 11:45:43 +0300888 public void setLocalDescription(SdpObserver observer) {
889 nativeSetLocalDescriptionAutomatically(observer);
890 }
891
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100892 public void setLocalDescription(SdpObserver observer, SessionDescription sdp) {
893 nativeSetLocalDescription(observer, sdp);
894 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100896 public void setRemoteDescription(SdpObserver observer, SessionDescription sdp) {
897 nativeSetRemoteDescription(observer, sdp);
898 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899
Seth Hampsonc384e142018-03-06 15:47:10 -0800900 /**
Yura Yaroshevichd8d9ac32021-03-22 12:46:47 +0300901 * Tells the PeerConnection that ICE should be restarted.
902 */
903 public void restartIce() {
904 nativeRestartIce();
905 }
906
907 /**
Seth Hampsonc384e142018-03-06 15:47:10 -0800908 * Enables/disables playout of received audio streams. Enabled by default.
909 *
910 * Note that even if playout is enabled, streams will only be played out if
911 * the appropriate SDP is also applied. The main purpose of this API is to
912 * be able to control the exact time when audio playout starts.
913 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100914 public void setAudioPlayout(boolean playout) {
915 nativeSetAudioPlayout(playout);
916 }
henrika5f6bf242017-11-01 11:06:56 +0100917
Seth Hampsonc384e142018-03-06 15:47:10 -0800918 /**
919 * Enables/disables recording of transmitted audio streams. Enabled by default.
920 *
921 * Note that even if recording is enabled, streams will only be recorded if
922 * the appropriate SDP is also applied. The main purpose of this API is to
923 * be able to control the exact time when audio recording starts.
924 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100925 public void setAudioRecording(boolean recording) {
926 nativeSetAudioRecording(recording);
927 }
henrika5f6bf242017-11-01 11:06:56 +0100928
deadbeef5d0b6d82017-01-09 16:05:28 -0800929 public boolean setConfiguration(RTCConfiguration config) {
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100930 return nativeSetConfiguration(config);
deadbeef5d0b6d82017-01-09 16:05:28 -0800931 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932
933 public boolean addIceCandidate(IceCandidate candidate) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100934 return nativeAddIceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 }
936
Yura Yaroshevich1cdeb0a2021-04-08 16:56:56 +0300937 public void addIceCandidate(IceCandidate candidate, AddIceObserver observer) {
938 nativeAddIceCandidateWithObserver(
939 candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp, observer);
940 }
941
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700942 public boolean removeIceCandidates(final IceCandidate[] candidates) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100943 return nativeRemoveIceCandidates(candidates);
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700944 }
945
Seth Hampsonc384e142018-03-06 15:47:10 -0800946 /**
947 * Adds a new MediaStream to be sent on this peer connection.
948 * Note: This method is not supported with SdpSemantics.UNIFIED_PLAN. Please
949 * use addTrack instead.
950 */
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000951 public boolean addStream(MediaStream stream) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +0200952 boolean ret = nativeAddLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 if (!ret) {
954 return false;
955 }
956 localStreams.add(stream);
957 return true;
958 }
959
Seth Hampsonc384e142018-03-06 15:47:10 -0800960 /**
961 * Removes the given media stream from this peer connection.
962 * This method is not supported with SdpSemantics.UNIFIED_PLAN. Please use
963 * removeTrack instead.
964 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 public void removeStream(MediaStream stream) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +0200966 nativeRemoveLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 localStreams.remove(stream);
968 }
969
deadbeef7a246882017-08-09 08:40:10 -0700970 /**
971 * Creates an RtpSender without a track.
Seth Hampsonc384e142018-03-06 15:47:10 -0800972 *
973 * <p>This method allows an application to cause the PeerConnection to negotiate
deadbeef7a246882017-08-09 08:40:10 -0700974 * sending/receiving a specific media type, but without having a track to
975 * send yet.
Seth Hampsonc384e142018-03-06 15:47:10 -0800976 *
977 * <p>When the application does want to begin sending a track, it can call
deadbeef7a246882017-08-09 08:40:10 -0700978 * RtpSender.setTrack, which doesn't require any additional SDP negotiation.
Seth Hampsonc384e142018-03-06 15:47:10 -0800979 *
980 * <p>Example use:
deadbeef7a246882017-08-09 08:40:10 -0700981 * <pre>
982 * {@code
983 * audioSender = pc.createSender("audio", "stream1");
984 * videoSender = pc.createSender("video", "stream1");
985 * // Do normal SDP offer/answer, which will kick off ICE/DTLS and negotiate
986 * // media parameters....
987 * // Later, when the endpoint is ready to actually begin sending:
988 * audioSender.setTrack(audioTrack, false);
989 * videoSender.setTrack(videoTrack, false);
990 * }
991 * </pre>
Seth Hampsonc384e142018-03-06 15:47:10 -0800992 * <p>Note: This corresponds most closely to "addTransceiver" in the official
deadbeef7a246882017-08-09 08:40:10 -0700993 * WebRTC API, in that it creates a sender without a track. It was
994 * implemented before addTransceiver because it provides useful
995 * functionality, and properly implementing transceivers would have required
996 * a great deal more work.
997 *
Seth Hampsonc384e142018-03-06 15:47:10 -0800998 * <p>Note: This is only available with SdpSemantics.PLAN_B specified. Please use
999 * addTransceiver instead.
1000 *
deadbeef7a246882017-08-09 08:40:10 -07001001 * @param kind Corresponds to MediaStreamTrack kinds (must be "audio" or
1002 * "video").
1003 * @param stream_id The ID of the MediaStream that this sender's track will
1004 * be associated with when SDP is applied to the remote
1005 * PeerConnection. If createSender is used to create an
1006 * audio and video sender that should be synchronized, they
1007 * should use the same stream ID.
1008 * @return A new RtpSender object if successful, or null otherwise.
1009 */
deadbeefbd7d8f72015-12-18 16:58:44 -08001010 public RtpSender createSender(String kind, String stream_id) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001011 RtpSender newSender = nativeCreateSender(kind, stream_id);
1012 if (newSender != null) {
1013 senders.add(newSender);
deadbeefee524f72015-12-02 11:27:40 -08001014 }
Seth Hampsonc384e142018-03-06 15:47:10 -08001015 return newSender;
deadbeefee524f72015-12-02 11:27:40 -08001016 }
1017
Seth Hampsonc384e142018-03-06 15:47:10 -08001018 /**
1019 * Gets all RtpSenders associated with this peer connection.
1020 * Note that calling getSenders will dispose of the senders previously
1021 * returned.
1022 */
deadbeef4139c0f2015-10-06 12:29:25 -07001023 public List<RtpSender> getSenders() {
1024 for (RtpSender sender : senders) {
1025 sender.dispose();
1026 }
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001027 senders = nativeGetSenders();
deadbeef4139c0f2015-10-06 12:29:25 -07001028 return Collections.unmodifiableList(senders);
1029 }
1030
Seth Hampsonc384e142018-03-06 15:47:10 -08001031 /**
1032 * Gets all RtpReceivers associated with this peer connection.
1033 * Note that calling getReceivers will dispose of the receivers previously
1034 * returned.
1035 */
deadbeef4139c0f2015-10-06 12:29:25 -07001036 public List<RtpReceiver> getReceivers() {
1037 for (RtpReceiver receiver : receivers) {
1038 receiver.dispose();
1039 }
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001040 receivers = nativeGetReceivers();
deadbeef4139c0f2015-10-06 12:29:25 -07001041 return Collections.unmodifiableList(receivers);
1042 }
1043
Seth Hampsonc384e142018-03-06 15:47:10 -08001044 /**
1045 * Gets all RtpTransceivers associated with this peer connection.
1046 * Note that calling getTransceivers will dispose of the transceivers previously
1047 * returned.
1048 * Note: This is only available with SdpSemantics.UNIFIED_PLAN specified.
1049 */
1050 public List<RtpTransceiver> getTransceivers() {
1051 for (RtpTransceiver transceiver : transceivers) {
1052 transceiver.dispose();
1053 }
1054 transceivers = nativeGetTransceivers();
1055 return Collections.unmodifiableList(transceivers);
1056 }
1057
1058 /**
1059 * Adds a new media stream track to be sent on this peer connection, and returns
1060 * the newly created RtpSender. If streamIds are specified, the RtpSender will
1061 * be associated with the streams specified in the streamIds list.
1062 *
1063 * @throws IllegalStateException if an error accors in C++ addTrack.
1064 * An error can occur if:
1065 * - A sender already exists for the track.
1066 * - The peer connection is closed.
1067 */
1068 public RtpSender addTrack(MediaStreamTrack track) {
1069 return addTrack(track, Collections.emptyList());
1070 }
1071
1072 public RtpSender addTrack(MediaStreamTrack track, List<String> streamIds) {
1073 if (track == null || streamIds == null) {
1074 throw new NullPointerException("No MediaStreamTrack specified in addTrack.");
1075 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001076 RtpSender newSender = nativeAddTrack(track.getNativeMediaStreamTrack(), streamIds);
Seth Hampsonc384e142018-03-06 15:47:10 -08001077 if (newSender == null) {
1078 throw new IllegalStateException("C++ addTrack failed.");
1079 }
1080 senders.add(newSender);
1081 return newSender;
1082 }
1083
1084 /**
1085 * Stops sending media from sender. The sender will still appear in getSenders. Future
1086 * calls to createOffer will mark the m section for the corresponding transceiver as
1087 * receive only or inactive, as defined in JSEP. Returns true on success.
1088 */
1089 public boolean removeTrack(RtpSender sender) {
1090 if (sender == null) {
1091 throw new NullPointerException("No RtpSender specified for removeTrack.");
1092 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001093 return nativeRemoveTrack(sender.getNativeRtpSender());
Seth Hampsonc384e142018-03-06 15:47:10 -08001094 }
1095
1096 /**
1097 * Creates a new RtpTransceiver and adds it to the set of transceivers. Adding a
1098 * transceiver will cause future calls to CreateOffer to add a media description
1099 * for the corresponding transceiver.
1100 *
Artem Titovd7ac5812021-07-27 12:23:39 +02001101 * <p>The initial value of `mid` in the returned transceiver is null. Setting a
Seth Hampsonc384e142018-03-06 15:47:10 -08001102 * new session description may change it to a non-null value.
1103 *
1104 * <p>https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
1105 *
1106 * <p>If a MediaStreamTrack is specified then a transceiver will be added with a
1107 * sender set to transmit the given track. The kind
1108 * of the transceiver (and sender/receiver) will be derived from the kind of
1109 * the track.
1110 *
1111 * <p>If MediaType is specified then a transceiver will be added based upon that type.
1112 * This can be either MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO.
1113 *
1114 * <p>Optionally, an RtpTransceiverInit structure can be specified to configure
1115 * the transceiver from construction. If not specified, the transceiver will
1116 * default to having a direction of kSendRecv and not be part of any streams.
1117 *
1118 * <p>Note: These methods are only available with SdpSemantics.UNIFIED_PLAN specified.
1119 * @throws IllegalStateException if an error accors in C++ addTransceiver
1120 */
1121 public RtpTransceiver addTransceiver(MediaStreamTrack track) {
1122 return addTransceiver(track, new RtpTransceiver.RtpTransceiverInit());
1123 }
1124
1125 public RtpTransceiver addTransceiver(
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001126 MediaStreamTrack track, @Nullable RtpTransceiver.RtpTransceiverInit init) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001127 if (track == null) {
1128 throw new NullPointerException("No MediaStreamTrack specified for addTransceiver.");
1129 }
1130 if (init == null) {
1131 init = new RtpTransceiver.RtpTransceiverInit();
1132 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001133 RtpTransceiver newTransceiver =
1134 nativeAddTransceiverWithTrack(track.getNativeMediaStreamTrack(), init);
Seth Hampsonc384e142018-03-06 15:47:10 -08001135 if (newTransceiver == null) {
1136 throw new IllegalStateException("C++ addTransceiver failed.");
1137 }
1138 transceivers.add(newTransceiver);
1139 return newTransceiver;
1140 }
1141
1142 public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType) {
1143 return addTransceiver(mediaType, new RtpTransceiver.RtpTransceiverInit());
1144 }
1145
1146 public RtpTransceiver addTransceiver(
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001147 MediaStreamTrack.MediaType mediaType, @Nullable RtpTransceiver.RtpTransceiverInit init) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001148 if (mediaType == null) {
1149 throw new NullPointerException("No MediaType specified for addTransceiver.");
1150 }
1151 if (init == null) {
1152 init = new RtpTransceiver.RtpTransceiverInit();
1153 }
1154 RtpTransceiver newTransceiver = nativeAddTransceiverOfType(mediaType, init);
1155 if (newTransceiver == null) {
1156 throw new IllegalStateException("C++ addTransceiver failed.");
1157 }
1158 transceivers.add(newTransceiver);
1159 return newTransceiver;
1160 }
1161
deadbeef82215872017-04-18 10:27:51 -07001162 // Older, non-standard implementation of getStats.
1163 @Deprecated
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001164 public boolean getStats(StatsObserver observer, @Nullable MediaStreamTrack track) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001165 return nativeOldGetStats(observer, (track == null) ? 0 : track.getNativeMediaStreamTrack());
deadbeef82215872017-04-18 10:27:51 -07001166 }
1167
Seth Hampsonc384e142018-03-06 15:47:10 -08001168 /**
1169 * Gets stats using the new stats collection API, see webrtc/api/stats/. These
1170 * will replace old stats collection API when the new API has matured enough.
1171 */
deadbeef82215872017-04-18 10:27:51 -07001172 public void getStats(RTCStatsCollectorCallback callback) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001173 nativeNewGetStats(callback);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 }
1175
Seth Hampsonc384e142018-03-06 15:47:10 -08001176 /**
1177 * Limits the bandwidth allocated for all RTP streams sent by this
1178 * PeerConnection. Pass null to leave a value unchanged.
1179 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001180 public boolean setBitrate(Integer min, Integer current, Integer max) {
1181 return nativeSetBitrate(min, current, max);
1182 }
zsteind89b0bc2017-08-03 11:11:40 -07001183
Seth Hampsonc384e142018-03-06 15:47:10 -08001184 /**
1185 * Starts recording an RTC event log.
1186 *
1187 * Ownership of the file is transfered to the native code. If an RTC event
1188 * log is already being recorded, it will be stopped and a new one will start
1189 * using the provided file. Logging will continue until the stopRtcEventLog
1190 * function is called. The max_size_bytes argument is ignored, it is added
1191 * for future use.
1192 */
ivoc0c6f0f62016-07-06 04:34:23 -07001193 public boolean startRtcEventLog(int file_descriptor, int max_size_bytes) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001194 return nativeStartRtcEventLog(file_descriptor, max_size_bytes);
ivoc14d5dbe2016-07-04 07:06:55 -07001195 }
1196
Seth Hampsonc384e142018-03-06 15:47:10 -08001197 /**
1198 * Stops recording an RTC event log. If no RTC event log is currently being
1199 * recorded, this call will have no effect.
1200 */
ivoc14d5dbe2016-07-04 07:06:55 -07001201 public void stopRtcEventLog() {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001202 nativeStopRtcEventLog();
ivoc14d5dbe2016-07-04 07:06:55 -07001203 }
1204
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 // TODO(fischman): add support for DTMF-related methods once that API
1206 // stabilizes.
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001207 public SignalingState signalingState() {
1208 return nativeSignalingState();
1209 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001210
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001211 public IceConnectionState iceConnectionState() {
1212 return nativeIceConnectionState();
1213 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214
Jonas Olssonf01d8c82018-11-08 15:19:04 +01001215 public PeerConnectionState connectionState() {
1216 return nativeConnectionState();
1217 }
1218
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001219 public IceGatheringState iceGatheringState() {
1220 return nativeIceGatheringState();
1221 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001223 public void close() {
1224 nativeClose();
1225 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226
deadbeef43697f62017-09-12 10:52:14 -07001227 /**
1228 * Free native resources associated with this PeerConnection instance.
Seth Hampsonc384e142018-03-06 15:47:10 -08001229 *
deadbeef43697f62017-09-12 10:52:14 -07001230 * This method removes a reference count from the C++ PeerConnection object,
1231 * which should result in it being destroyed. It also calls equivalent
1232 * "dispose" methods on the Java objects attached to this PeerConnection
1233 * (streams, senders, receivers), such that their associated C++ objects
1234 * will also be destroyed.
Seth Hampsonc384e142018-03-06 15:47:10 -08001235 *
1236 * <p>Note that this method cannot be safely called from an observer callback
deadbeef43697f62017-09-12 10:52:14 -07001237 * (PeerConnection.Observer, DataChannel.Observer, etc.). If you want to, for
1238 * example, destroy the PeerConnection after an "ICE failed" callback, you
1239 * must do this asynchronously (in other words, unwind the stack first). See
1240 * <a href="https://bugs.chromium.org/p/webrtc/issues/detail?id=3721">bug
1241 * 3721</a> for more details.
1242 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 public void dispose() {
1244 close();
1245 for (MediaStream stream : localStreams) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001246 nativeRemoveLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247 stream.dispose();
1248 }
1249 localStreams.clear();
deadbeef4139c0f2015-10-06 12:29:25 -07001250 for (RtpSender sender : senders) {
1251 sender.dispose();
1252 }
1253 senders.clear();
1254 for (RtpReceiver receiver : receivers) {
1255 receiver.dispose();
1256 }
Seth Hampsonc384e142018-03-06 15:47:10 -08001257 for (RtpTransceiver transceiver : transceivers) {
1258 transceiver.dispose();
1259 }
1260 transceivers.clear();
deadbeef4139c0f2015-10-06 12:29:25 -07001261 receivers.clear();
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001262 nativeFreeOwnedPeerConnection(nativePeerConnection);
1263 }
1264
1265 /** Returns a pointer to the native webrtc::PeerConnectionInterface. */
1266 public long getNativePeerConnection() {
1267 return nativeGetNativePeerConnection();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268 }
1269
Magnus Jedvert9060eb12017-12-12 12:52:54 +01001270 @CalledByNative
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001271 long getNativeOwnedPeerConnection() {
Magnus Jedvert9060eb12017-12-12 12:52:54 +01001272 return nativePeerConnection;
1273 }
1274
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001275 public static long createNativePeerConnectionObserver(Observer observer) {
1276 return nativeCreatePeerConnectionObserver(observer);
1277 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001279 private native long nativeGetNativePeerConnection();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001280 private native SessionDescription nativeGetLocalDescription();
1281 private native SessionDescription nativeGetRemoteDescription();
Michael Iedema02137862018-10-09 15:30:01 +02001282 private native RtcCertificatePem nativeGetCertificate();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001283 private native DataChannel nativeCreateDataChannel(String label, DataChannel.Init init);
1284 private native void nativeCreateOffer(SdpObserver observer, MediaConstraints constraints);
1285 private native void nativeCreateAnswer(SdpObserver observer, MediaConstraints constraints);
Yura Yaroshevich4e9e7232021-03-22 11:45:43 +03001286 private native void nativeSetLocalDescriptionAutomatically(SdpObserver observer);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001287 private native void nativeSetLocalDescription(SdpObserver observer, SessionDescription sdp);
1288 private native void nativeSetRemoteDescription(SdpObserver observer, SessionDescription sdp);
Yura Yaroshevichd8d9ac32021-03-22 12:46:47 +03001289 private native void nativeRestartIce();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001290 private native void nativeSetAudioPlayout(boolean playout);
1291 private native void nativeSetAudioRecording(boolean recording);
1292 private native boolean nativeSetBitrate(Integer min, Integer current, Integer max);
1293 private native SignalingState nativeSignalingState();
1294 private native IceConnectionState nativeIceConnectionState();
Jonas Olssonf01d8c82018-11-08 15:19:04 +01001295 private native PeerConnectionState nativeConnectionState();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001296 private native IceGatheringState nativeIceGatheringState();
1297 private native void nativeClose();
1298 private static native long nativeCreatePeerConnectionObserver(Observer observer);
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001299 private static native void nativeFreeOwnedPeerConnection(long ownedPeerConnection);
1300 private native boolean nativeSetConfiguration(RTCConfiguration config);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001301 private native boolean nativeAddIceCandidate(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 String sdpMid, int sdpMLineIndex, String iceCandidateSdp);
Yura Yaroshevich1cdeb0a2021-04-08 16:56:56 +03001303 private native void nativeAddIceCandidateWithObserver(
1304 String sdpMid, int sdpMLineIndex, String iceCandidateSdp, AddIceObserver observer);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001305 private native boolean nativeRemoveIceCandidates(final IceCandidate[] candidates);
1306 private native boolean nativeAddLocalStream(long stream);
1307 private native void nativeRemoveLocalStream(long stream);
1308 private native boolean nativeOldGetStats(StatsObserver observer, long nativeTrack);
1309 private native void nativeNewGetStats(RTCStatsCollectorCallback callback);
1310 private native RtpSender nativeCreateSender(String kind, String stream_id);
1311 private native List<RtpSender> nativeGetSenders();
1312 private native List<RtpReceiver> nativeGetReceivers();
Seth Hampsonc384e142018-03-06 15:47:10 -08001313 private native List<RtpTransceiver> nativeGetTransceivers();
1314 private native RtpSender nativeAddTrack(long track, List<String> streamIds);
1315 private native boolean nativeRemoveTrack(long sender);
1316 private native RtpTransceiver nativeAddTransceiverWithTrack(
1317 long track, RtpTransceiver.RtpTransceiverInit init);
1318 private native RtpTransceiver nativeAddTransceiverOfType(
1319 MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001320 private native boolean nativeStartRtcEventLog(int file_descriptor, int max_size_bytes);
1321 private native void nativeStopRtcEventLog();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322}