blob: e675d13c75e827b05d5fa91fca571bfb7dc1be24 [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
Artem Titarenko69540f42018-12-10 12:30:46 +010013import android.support.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 */
Magnus Jedvertba700f62017-12-04 13:43:27 +0100144 @CalledByNative("Observer") void onAddTrack(RtpReceiver receiver, MediaStream[] mediaStreams);
Seth Hampson31dbc242018-05-07 09:28:19 -0700145
146 /**
147 * Triggered when the signaling from SetRemoteDescription indicates that a transceiver
148 * will be receiving media from a remote endpoint. This is only called if UNIFIED_PLAN
149 * semantics are specified. The transceiver will be disposed automatically.
150 */
151 @CalledByNative("Observer") default void onTrack(RtpTransceiver transceiver){};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 }
153
154 /** Java version of PeerConnectionInterface.IceServer. */
155 public static class IceServer {
Emad Omaradab1d2d2017-06-16 15:43:11 -0700156 // List of URIs associated with this server. Valid formats are described
157 // in RFC7064 and RFC7065, and more may be added in the future. The "host"
158 // part of the URI may contain either an IP address or a hostname.
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700159 @Deprecated public final String uri;
160 public final List<String> urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 public final String username;
162 public final String password;
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000163 public final TlsCertPolicy tlsCertPolicy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164
Emad Omaradab1d2d2017-06-16 15:43:11 -0700165 // If the URIs in |urls| only contain IP addresses, this field can be used
166 // to indicate the hostname, which may be necessary for TLS (using the SNI
167 // extension). If |urls| itself contains the hostname, this isn't
168 // necessary.
169 public final String hostname;
170
Diogo Real1dca9d52017-08-29 12:18:32 -0700171 // List of protocols to be used in the TLS ALPN extension.
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000172 public final List<String> tlsAlpnProtocols;
Diogo Real1dca9d52017-08-29 12:18:32 -0700173
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700174 // List of elliptic curves to be used in the TLS elliptic curves extension.
175 // Only curve names supported by OpenSSL should be used (eg. "P-256","X25519").
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000176 public final List<String> tlsEllipticCurves;
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700177
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 /** Convenience constructor for STUN servers. */
Diogo Real05ea2b32017-08-31 00:12:58 -0700179 @Deprecated
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 public IceServer(String uri) {
181 this(uri, "", "");
182 }
183
Diogo Real05ea2b32017-08-31 00:12:58 -0700184 @Deprecated
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 public IceServer(String uri, String username, String password) {
hnsl04833622017-01-09 08:35:45 -0800186 this(uri, username, password, TlsCertPolicy.TLS_CERT_POLICY_SECURE);
187 }
188
Diogo Real05ea2b32017-08-31 00:12:58 -0700189 @Deprecated
hnsl04833622017-01-09 08:35:45 -0800190 public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy) {
Emad Omaradab1d2d2017-06-16 15:43:11 -0700191 this(uri, username, password, tlsCertPolicy, "");
192 }
193
Diogo Real05ea2b32017-08-31 00:12:58 -0700194 @Deprecated
Emad Omaradab1d2d2017-06-16 15:43:11 -0700195 public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy,
196 String hostname) {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700197 this(uri, Collections.singletonList(uri), username, password, tlsCertPolicy, hostname, null,
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000198 null);
Diogo Real1dca9d52017-08-29 12:18:32 -0700199 }
200
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700201 private IceServer(String uri, List<String> urls, String username, String password,
202 TlsCertPolicy tlsCertPolicy, String hostname, List<String> tlsAlpnProtocols,
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000203 List<String> tlsEllipticCurves) {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700204 if (uri == null || urls == null || urls.isEmpty()) {
205 throw new IllegalArgumentException("uri == null || urls == null || urls.isEmpty()");
206 }
207 for (String it : urls) {
208 if (it == null) {
209 throw new IllegalArgumentException("urls element is null: " + urls);
210 }
211 }
212 if (username == null) {
213 throw new IllegalArgumentException("username == null");
214 }
215 if (password == null) {
216 throw new IllegalArgumentException("password == null");
217 }
218 if (hostname == null) {
219 throw new IllegalArgumentException("hostname == null");
220 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 this.uri = uri;
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700222 this.urls = urls;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 this.username = username;
224 this.password = password;
hnsl04833622017-01-09 08:35:45 -0800225 this.tlsCertPolicy = tlsCertPolicy;
Emad Omaradab1d2d2017-06-16 15:43:11 -0700226 this.hostname = hostname;
Diogo Real1dca9d52017-08-29 12:18:32 -0700227 this.tlsAlpnProtocols = tlsAlpnProtocols;
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700228 this.tlsEllipticCurves = tlsEllipticCurves;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 }
230
Sami Kalliomäkibde473e2017-10-30 13:34:41 +0100231 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 public String toString() {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700233 return urls + " [" + username + ":" + password + "] [" + tlsCertPolicy + "] [" + hostname
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000234 + "] [" + tlsAlpnProtocols + "] [" + tlsEllipticCurves + "]";
Diogo Real1dca9d52017-08-29 12:18:32 -0700235 }
236
Qingsi Wanga0d45802019-01-15 13:33:11 -0800237 @Override
238 public boolean equals(@Nullable Object obj) {
239 if (obj == null) {
240 return false;
241 }
242 if (obj == this) {
243 return true;
244 }
245 if (!(obj instanceof IceServer)) {
246 return false;
247 }
248 IceServer other = (IceServer) obj;
249 return (uri.equals(other.uri) && urls.equals(other.urls) && username.equals(other.username)
250 && password.equals(other.password) && tlsCertPolicy.equals(other.tlsCertPolicy)
251 && hostname.equals(other.hostname) && tlsAlpnProtocols.equals(other.tlsAlpnProtocols)
252 && tlsEllipticCurves.equals(other.tlsEllipticCurves));
253 }
254
255 @Override
256 public int hashCode() {
257 Object[] values = {uri, urls, username, password, tlsCertPolicy, hostname, tlsAlpnProtocols,
258 tlsEllipticCurves};
259 return Arrays.hashCode(values);
260 }
261
Diogo Real1dca9d52017-08-29 12:18:32 -0700262 public static Builder builder(String uri) {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700263 return new Builder(Collections.singletonList(uri));
264 }
265
266 public static Builder builder(List<String> urls) {
267 return new Builder(urls);
Diogo Real1dca9d52017-08-29 12:18:32 -0700268 }
269
270 public static class Builder {
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100271 @Nullable private final List<String> urls;
Diogo Real1dca9d52017-08-29 12:18:32 -0700272 private String username = "";
273 private String password = "";
274 private TlsCertPolicy tlsCertPolicy = TlsCertPolicy.TLS_CERT_POLICY_SECURE;
275 private String hostname = "";
276 private List<String> tlsAlpnProtocols;
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700277 private List<String> tlsEllipticCurves;
Diogo Real1dca9d52017-08-29 12:18:32 -0700278
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700279 private Builder(List<String> urls) {
280 if (urls == null || urls.isEmpty()) {
281 throw new IllegalArgumentException("urls == null || urls.isEmpty(): " + urls);
282 }
283 this.urls = urls;
Diogo Real1dca9d52017-08-29 12:18:32 -0700284 }
285
286 public Builder setUsername(String username) {
287 this.username = username;
288 return this;
289 }
290
291 public Builder setPassword(String password) {
292 this.password = password;
293 return this;
294 }
295
296 public Builder setTlsCertPolicy(TlsCertPolicy tlsCertPolicy) {
297 this.tlsCertPolicy = tlsCertPolicy;
298 return this;
299 }
300
301 public Builder setHostname(String hostname) {
302 this.hostname = hostname;
303 return this;
304 }
305
306 public Builder setTlsAlpnProtocols(List<String> tlsAlpnProtocols) {
307 this.tlsAlpnProtocols = tlsAlpnProtocols;
308 return this;
309 }
310
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700311 public Builder setTlsEllipticCurves(List<String> tlsEllipticCurves) {
312 this.tlsEllipticCurves = tlsEllipticCurves;
313 return this;
314 }
315
Diogo Real1dca9d52017-08-29 12:18:32 -0700316 public IceServer createIceServer() {
korniltsev.anatoly0ea03102017-09-11 06:41:38 -0700317 return new IceServer(urls.get(0), urls, username, password, tlsCertPolicy, hostname,
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000318 tlsAlpnProtocols, tlsEllipticCurves);
Diogo Real1dca9d52017-08-29 12:18:32 -0700319 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 }
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100321
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100322 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100323 @CalledByNative("IceServer")
324 List<String> getUrls() {
325 return urls;
326 }
327
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100328 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100329 @CalledByNative("IceServer")
330 String getUsername() {
331 return username;
332 }
333
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100334 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100335 @CalledByNative("IceServer")
336 String getPassword() {
337 return password;
338 }
339
340 @CalledByNative("IceServer")
341 TlsCertPolicy getTlsCertPolicy() {
342 return tlsCertPolicy;
343 }
344
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100345 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100346 @CalledByNative("IceServer")
347 String getHostname() {
348 return hostname;
349 }
350
351 @CalledByNative("IceServer")
352 List<String> getTlsAlpnProtocols() {
353 return tlsAlpnProtocols;
354 }
355
356 @CalledByNative("IceServer")
357 List<String> getTlsEllipticCurves() {
358 return tlsEllipticCurves;
359 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 }
361
Jiayang Liucac1b382015-04-30 12:35:24 -0700362 /** Java version of PeerConnectionInterface.IceTransportsType */
sakalb6760f92016-09-29 04:12:44 -0700363 public enum IceTransportsType { NONE, RELAY, NOHOST, ALL }
Jiayang Liucac1b382015-04-30 12:35:24 -0700364
365 /** Java version of PeerConnectionInterface.BundlePolicy */
sakalb6760f92016-09-29 04:12:44 -0700366 public enum BundlePolicy { BALANCED, MAXBUNDLE, MAXCOMPAT }
Jiayang Liucac1b382015-04-30 12:35:24 -0700367
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700368 /** Java version of PeerConnectionInterface.RtcpMuxPolicy */
sakalb6760f92016-09-29 04:12:44 -0700369 public enum RtcpMuxPolicy { NEGOTIATE, REQUIRE }
glaznev97579a42015-09-01 11:31:27 -0700370
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700371 /** Java version of PeerConnectionInterface.TcpCandidatePolicy */
sakalb6760f92016-09-29 04:12:44 -0700372 public enum TcpCandidatePolicy { ENABLED, DISABLED }
Jiayang Liucac1b382015-04-30 12:35:24 -0700373
honghaiz60347052016-05-31 18:29:12 -0700374 /** Java version of PeerConnectionInterface.CandidateNetworkPolicy */
sakalb6760f92016-09-29 04:12:44 -0700375 public enum CandidateNetworkPolicy { ALL, LOW_COST }
honghaiz60347052016-05-31 18:29:12 -0700376
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800377 // Keep in sync with webrtc/rtc_base/network_constants.h.
378 public enum AdapterType {
Alex Drake68c2a562019-08-13 15:56:07 -0700379 UNKNOWN(0),
380 ETHERNET(1 << 0),
381 WIFI(1 << 1),
382 CELLULAR(1 << 2),
383 VPN(1 << 3),
384 LOOPBACK(1 << 4),
385 ADAPTER_TYPE_ANY(1 << 5);
386
387 public final Integer bitMask;
388 private AdapterType(Integer bitMask) {
389 this.bitMask = bitMask;
390 }
391 private static final Map<Integer, AdapterType> BY_BITMASK = new HashMap<>();
392 static {
393 for (AdapterType t : values()) {
394 BY_BITMASK.put(t.bitMask, t);
395 }
396 }
397
398 @CalledByNative("AdapterType")
399 static AdapterType fromNativeIndex(int nativeIndex) {
400 return BY_BITMASK.get(nativeIndex);
401 }
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800402 }
403
glaznev97579a42015-09-01 11:31:27 -0700404 /** Java version of rtc::KeyType */
sakalb6760f92016-09-29 04:12:44 -0700405 public enum KeyType { RSA, ECDSA }
glaznev97579a42015-09-01 11:31:27 -0700406
honghaiz1f429e32015-09-28 07:57:34 -0700407 /** Java version of PeerConnectionInterface.ContinualGatheringPolicy */
sakalb6760f92016-09-29 04:12:44 -0700408 public enum ContinualGatheringPolicy { GATHER_ONCE, GATHER_CONTINUALLY }
honghaiz1f429e32015-09-28 07:57:34 -0700409
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700410 /** Java version of webrtc::PortPrunePolicy */
411 public enum PortPrunePolicy {
412 NO_PRUNE, // Do not prune turn port.
413 PRUNE_BASED_ON_PRIORITY, // Prune turn port based the priority on the same network
414 KEEP_FIRST_READY // Keep the first ready port and prune the rest on the same network.
415 }
416
Steve Antond960a0c2017-07-17 12:33:07 -0700417 /** Java version of rtc::IntervalRange */
418 public static class IntervalRange {
419 private final int min;
420 private final int max;
421
422 public IntervalRange(int min, int max) {
423 this.min = min;
424 this.max = max;
425 }
426
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100427 @CalledByNative("IntervalRange")
Steve Antond960a0c2017-07-17 12:33:07 -0700428 public int getMin() {
429 return min;
430 }
431
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100432 @CalledByNative("IntervalRange")
Steve Antond960a0c2017-07-17 12:33:07 -0700433 public int getMax() {
434 return max;
435 }
436 }
437
Seth Hampsonc384e142018-03-06 15:47:10 -0800438 /**
439 * Java version of webrtc::SdpSemantics.
440 *
441 * Configure the SDP semantics used by this PeerConnection. Note that the
442 * WebRTC 1.0 specification requires UNIFIED_PLAN semantics. The
443 * RtpTransceiver API is only available with UNIFIED_PLAN semantics.
444 *
445 * <p>PLAN_B will cause PeerConnection to create offers and answers with at
446 * most one audio and one video m= section with multiple RtpSenders and
447 * RtpReceivers specified as multiple a=ssrc lines within the section. This
448 * will also cause PeerConnection to ignore all but the first m= section of
449 * the same media type.
450 *
451 * <p>UNIFIED_PLAN will cause PeerConnection to create offers and answers with
452 * multiple m= sections where each m= section maps to one RtpSender and one
453 * RtpReceiver (an RtpTransceiver), either both audio or both video. This
454 * will also cause PeerConnection to ignore all but the first a=ssrc lines
455 * that form a Plan B stream.
456 *
457 * <p>For users who wish to send multiple audio/video streams and need to stay
458 * interoperable with legacy WebRTC implementations, specify PLAN_B.
459 *
460 * <p>For users who wish to send multiple audio/video streams and/or wish to
461 * use the new RtpTransceiver API, specify UNIFIED_PLAN.
462 */
463 public enum SdpSemantics { PLAN_B, UNIFIED_PLAN }
464
Jiayang Liucac1b382015-04-30 12:35:24 -0700465 /** Java version of PeerConnectionInterface.RTCConfiguration */
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800466 // TODO(qingsi): Resolve the naming inconsistency of fields with/without units.
Jiayang Liucac1b382015-04-30 12:35:24 -0700467 public static class RTCConfiguration {
468 public IceTransportsType iceTransportsType;
469 public List<IceServer> iceServers;
470 public BundlePolicy bundlePolicy;
Michael Iedema02137862018-10-09 15:30:01 +0200471 @Nullable public RtcCertificatePem certificate;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700472 public RtcpMuxPolicy rtcpMuxPolicy;
Jiayang Liucac1b382015-04-30 12:35:24 -0700473 public TcpCandidatePolicy tcpCandidatePolicy;
honghaiz60347052016-05-31 18:29:12 -0700474 public CandidateNetworkPolicy candidateNetworkPolicy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200475 public int audioJitterBufferMaxPackets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200476 public boolean audioJitterBufferFastAccelerate;
honghaiz4edc39c2015-09-01 09:53:56 -0700477 public int iceConnectionReceivingTimeout;
Honghai Zhang381b4212015-12-04 12:24:03 -0800478 public int iceBackupCandidatePairPingInterval;
glaznev97579a42015-09-01 11:31:27 -0700479 public KeyType keyType;
honghaiz1f429e32015-09-28 07:57:34 -0700480 public ContinualGatheringPolicy continualGatheringPolicy;
deadbeefbe0c96f2016-05-18 16:20:14 -0700481 public int iceCandidatePoolSize;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700482 @Deprecated // by the turnPortPrunePolicy. See bugs.webrtc.org/11026
Honghai Zhangd78ecf72016-07-01 14:40:40 -0700483 public boolean pruneTurnPorts;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700484 public PortPrunePolicy turnPortPrunePolicy;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700485 public boolean presumeWritableWhenFullyRelayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700486 public boolean surfaceIceCandidatesOnIceTransportTypeChanged;
Qingsi Wange6826d22018-03-08 14:55:14 -0800487 // The following fields define intervals in milliseconds at which ICE
488 // connectivity checks are sent.
489 //
490 // We consider ICE is "strongly connected" for an agent when there is at
491 // least one candidate pair that currently succeeds in connectivity check
492 // from its direction i.e. sending a ping and receives a ping response, AND
493 // all candidate pairs have sent a minimum number of pings for connectivity
494 // (this number is implementation-specific). Otherwise, ICE is considered in
495 // "weak connectivity".
496 //
497 // Note that the above notion of strong and weak connectivity is not defined
498 // in RFC 5245, and they apply to our current ICE implementation only.
499 //
500 // 1) iceCheckIntervalStrongConnectivityMs defines the interval applied to
501 // ALL candidate pairs when ICE is strongly connected,
502 // 2) iceCheckIntervalWeakConnectivityMs defines the counterpart for ALL
503 // pairs when ICE is weakly connected, and
504 // 3) iceCheckMinInterval defines the minimal interval (equivalently the
505 // maximum rate) that overrides the above two intervals when either of them
506 // is less.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100507 @Nullable public Integer iceCheckIntervalStrongConnectivityMs;
508 @Nullable public Integer iceCheckIntervalWeakConnectivityMs;
509 @Nullable public Integer iceCheckMinInterval;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700510 // The time period in milliseconds for which a candidate pair must wait for response to
511 // connectivitiy checks before it becomes unwritable.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100512 @Nullable public Integer iceUnwritableTimeMs;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700513 // The minimum number of connectivity checks that a candidate pair must sent without receiving
514 // response before it becomes unwritable.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100515 @Nullable public Integer iceUnwritableMinChecks;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800516 // The interval in milliseconds at which STUN candidates will resend STUN binding requests
517 // to keep NAT bindings open.
518 // The default value in the implementation is used if this field is null.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100519 @Nullable public Integer stunCandidateKeepaliveIntervalMs;
zhihuangb09b3f92017-03-07 14:40:51 -0800520 public boolean disableIPv6OnWifi;
deadbeef28e29192017-07-27 09:14:38 -0700521 // By default, PeerConnection will use a limited number of IPv6 network
522 // interfaces, in order to avoid too many ICE candidate pairs being created
523 // and delaying ICE completion.
524 //
525 // Can be set to Integer.MAX_VALUE to effectively disable the limit.
526 public int maxIPv6Networks;
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100527 @Nullable public IntervalRange iceRegatherIntervalRange;
Jiayang Liucac1b382015-04-30 12:35:24 -0700528
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100529 // These values will be overridden by MediaStream constraints if deprecated constraints-based
530 // create peerconnection interface is used.
531 public boolean disableIpv6;
532 public boolean enableDscp;
533 public boolean enableCpuOveruseDetection;
534 public boolean enableRtpDataChannel;
535 public boolean suspendBelowMinBitrate;
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100536 @Nullable public Integer screencastMinBitrate;
537 @Nullable public Boolean combinedAudioVideoBwe;
538 @Nullable public Boolean enableDtlsSrtp;
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800539 // Use "Unknown" to represent no preference of adapter types, not the
540 // preference of adapters of unknown types.
541 public AdapterType networkPreference;
Seth Hampsonc384e142018-03-06 15:47:10 -0800542 public SdpSemantics sdpSemantics;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100543
Jonas Orelandbdcee282017-10-10 14:01:40 +0200544 // This is an optional wrapper for the C++ webrtc::TurnCustomizer.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100545 @Nullable public TurnCustomizer turnCustomizer;
Jonas Orelandbdcee282017-10-10 14:01:40 +0200546
Zhi Huangb57e1692018-06-12 11:41:11 -0700547 // Actively reset the SRTP parameters whenever the DTLS transports underneath are reset for
548 // every offer/answer negotiation.This is only intended to be a workaround for crbug.com/835958
549 public boolean activeResetSrtpParams;
550
philipel16cec3b2019-10-25 12:23:02 +0200551 // Whether this client is allowed to switch encoding codec mid-stream. This is a workaround for
552 // a WebRTC bug where the receiver could get confussed if a codec switch happened mid-call.
553 // Null indicates no change to currently configured value.
554 @Nullable public Boolean allowCodecSwitching;
555
Piotr (Peter) Slatala09beff22018-10-17 07:22:40 -0700556 /*
557 * Experimental flag that enables a use of media transport. If this is true, the media transport
558 * factory MUST be provided to the PeerConnectionFactory.
559 */
560 public boolean useMediaTransport;
561
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700562 /*
563 * Experimental flag that enables a use of media transport for data channels. If this is true,
564 * the media transport factory MUST be provided to the PeerConnectionFactory.
565 */
566 public boolean useMediaTransportForDataChannels;
567
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700568 /**
569 * Defines advanced optional cryptographic settings related to SRTP and
570 * frame encryption for native WebRTC. Setting this will overwrite any
571 * options set through the PeerConnectionFactory (which is deprecated).
572 */
573 @Nullable public CryptoOptions cryptoOptions;
574
Jonas Oreland228900f2019-08-28 09:08:58 +0200575 /**
576 * An optional string that if set will be attached to the
577 * TURN_ALLOCATE_REQUEST which can be used to correlate client
578 * logs with backend logs
579 */
580 @Nullable public String turnLoggingId;
581
deadbeef28e29192017-07-27 09:14:38 -0700582 // TODO(deadbeef): Instead of duplicating the defaults here, we should do
583 // something to pick up the defaults from C++. The Objective-C equivalent
584 // of RTCConfiguration does that.
Jiayang Liucac1b382015-04-30 12:35:24 -0700585 public RTCConfiguration(List<IceServer> iceServers) {
586 iceTransportsType = IceTransportsType.ALL;
587 bundlePolicy = BundlePolicy.BALANCED;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800588 rtcpMuxPolicy = RtcpMuxPolicy.REQUIRE;
Jiayang Liucac1b382015-04-30 12:35:24 -0700589 tcpCandidatePolicy = TcpCandidatePolicy.ENABLED;
Sami Kalliomäki9828beb2017-10-26 16:21:22 +0200590 candidateNetworkPolicy = CandidateNetworkPolicy.ALL;
Jiayang Liucac1b382015-04-30 12:35:24 -0700591 this.iceServers = iceServers;
Henrik Lundin64dad832015-05-11 12:44:23 +0200592 audioJitterBufferMaxPackets = 50;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200593 audioJitterBufferFastAccelerate = false;
honghaiz4edc39c2015-09-01 09:53:56 -0700594 iceConnectionReceivingTimeout = -1;
Honghai Zhang381b4212015-12-04 12:24:03 -0800595 iceBackupCandidatePairPingInterval = -1;
glaznev97579a42015-09-01 11:31:27 -0700596 keyType = KeyType.ECDSA;
honghaiz1f429e32015-09-28 07:57:34 -0700597 continualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE;
deadbeefbe0c96f2016-05-18 16:20:14 -0700598 iceCandidatePoolSize = 0;
Honghai Zhangd78ecf72016-07-01 14:40:40 -0700599 pruneTurnPorts = false;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700600 turnPortPrunePolicy = PortPrunePolicy.NO_PRUNE;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700601 presumeWritableWhenFullyRelayed = false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700602 surfaceIceCandidatesOnIceTransportTypeChanged = false;
Qingsi Wange6826d22018-03-08 14:55:14 -0800603 iceCheckIntervalStrongConnectivityMs = null;
604 iceCheckIntervalWeakConnectivityMs = null;
skvlad51072462017-02-02 11:50:14 -0800605 iceCheckMinInterval = null;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700606 iceUnwritableTimeMs = null;
607 iceUnwritableMinChecks = null;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800608 stunCandidateKeepaliveIntervalMs = null;
zhihuangb09b3f92017-03-07 14:40:51 -0800609 disableIPv6OnWifi = false;
deadbeef28e29192017-07-27 09:14:38 -0700610 maxIPv6Networks = 5;
Steve Antond960a0c2017-07-17 12:33:07 -0700611 iceRegatherIntervalRange = null;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100612 disableIpv6 = false;
613 enableDscp = false;
614 enableCpuOveruseDetection = true;
615 enableRtpDataChannel = false;
616 suspendBelowMinBitrate = false;
617 screencastMinBitrate = null;
618 combinedAudioVideoBwe = null;
619 enableDtlsSrtp = null;
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800620 networkPreference = AdapterType.UNKNOWN;
Seth Hampsonc384e142018-03-06 15:47:10 -0800621 sdpSemantics = SdpSemantics.PLAN_B;
Zhi Huangb57e1692018-06-12 11:41:11 -0700622 activeResetSrtpParams = false;
Piotr (Peter) Slatala09beff22018-10-17 07:22:40 -0700623 useMediaTransport = false;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700624 useMediaTransportForDataChannels = false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700625 cryptoOptions = null;
Jonas Oreland228900f2019-08-28 09:08:58 +0200626 turnLoggingId = null;
philipel16cec3b2019-10-25 12:23:02 +0200627 allowCodecSwitching = null;
Jiayang Liucac1b382015-04-30 12:35:24 -0700628 }
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100629
630 @CalledByNative("RTCConfiguration")
631 IceTransportsType getIceTransportsType() {
632 return iceTransportsType;
633 }
634
635 @CalledByNative("RTCConfiguration")
636 List<IceServer> getIceServers() {
637 return iceServers;
638 }
639
640 @CalledByNative("RTCConfiguration")
641 BundlePolicy getBundlePolicy() {
642 return bundlePolicy;
643 }
644
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700645 @CalledByNative("RTCConfiguration")
646 PortPrunePolicy getTurnPortPrunePolicy() {
647 return turnPortPrunePolicy;
648 }
649
Michael Iedema02137862018-10-09 15:30:01 +0200650 @Nullable
651 @CalledByNative("RTCConfiguration")
652 RtcCertificatePem getCertificate() {
653 return certificate;
654 }
655
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100656 @CalledByNative("RTCConfiguration")
657 RtcpMuxPolicy getRtcpMuxPolicy() {
658 return rtcpMuxPolicy;
659 }
660
661 @CalledByNative("RTCConfiguration")
662 TcpCandidatePolicy getTcpCandidatePolicy() {
663 return tcpCandidatePolicy;
664 }
665
666 @CalledByNative("RTCConfiguration")
667 CandidateNetworkPolicy getCandidateNetworkPolicy() {
668 return candidateNetworkPolicy;
669 }
670
671 @CalledByNative("RTCConfiguration")
672 int getAudioJitterBufferMaxPackets() {
673 return audioJitterBufferMaxPackets;
674 }
675
676 @CalledByNative("RTCConfiguration")
677 boolean getAudioJitterBufferFastAccelerate() {
678 return audioJitterBufferFastAccelerate;
679 }
680
681 @CalledByNative("RTCConfiguration")
682 int getIceConnectionReceivingTimeout() {
683 return iceConnectionReceivingTimeout;
684 }
685
686 @CalledByNative("RTCConfiguration")
687 int getIceBackupCandidatePairPingInterval() {
688 return iceBackupCandidatePairPingInterval;
689 }
690
691 @CalledByNative("RTCConfiguration")
692 KeyType getKeyType() {
693 return keyType;
694 }
695
696 @CalledByNative("RTCConfiguration")
697 ContinualGatheringPolicy getContinualGatheringPolicy() {
698 return continualGatheringPolicy;
699 }
700
701 @CalledByNative("RTCConfiguration")
702 int getIceCandidatePoolSize() {
703 return iceCandidatePoolSize;
704 }
705
706 @CalledByNative("RTCConfiguration")
707 boolean getPruneTurnPorts() {
708 return pruneTurnPorts;
709 }
710
711 @CalledByNative("RTCConfiguration")
712 boolean getPresumeWritableWhenFullyRelayed() {
713 return presumeWritableWhenFullyRelayed;
714 }
715
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700716 @CalledByNative("RTCConfiguration")
717 boolean getSurfaceIceCandidatesOnIceTransportTypeChanged() {
718 return surfaceIceCandidatesOnIceTransportTypeChanged;
719 }
720
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100721 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100722 @CalledByNative("RTCConfiguration")
Qingsi Wange6826d22018-03-08 14:55:14 -0800723 Integer getIceCheckIntervalStrongConnectivity() {
724 return iceCheckIntervalStrongConnectivityMs;
725 }
726
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100727 @Nullable
Qingsi Wange6826d22018-03-08 14:55:14 -0800728 @CalledByNative("RTCConfiguration")
729 Integer getIceCheckIntervalWeakConnectivity() {
730 return iceCheckIntervalWeakConnectivityMs;
731 }
732
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100733 @Nullable
Qingsi Wange6826d22018-03-08 14:55:14 -0800734 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100735 Integer getIceCheckMinInterval() {
736 return iceCheckMinInterval;
737 }
738
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100739 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100740 @CalledByNative("RTCConfiguration")
Qingsi Wang22e623a2018-03-13 10:53:57 -0700741 Integer getIceUnwritableTimeout() {
742 return iceUnwritableTimeMs;
743 }
744
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100745 @Nullable
Qingsi Wang22e623a2018-03-13 10:53:57 -0700746 @CalledByNative("RTCConfiguration")
747 Integer getIceUnwritableMinChecks() {
748 return iceUnwritableMinChecks;
749 }
750
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100751 @Nullable
Qingsi Wang22e623a2018-03-13 10:53:57 -0700752 @CalledByNative("RTCConfiguration")
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800753 Integer getStunCandidateKeepaliveInterval() {
754 return stunCandidateKeepaliveIntervalMs;
755 }
756
757 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100758 boolean getDisableIPv6OnWifi() {
759 return disableIPv6OnWifi;
760 }
761
762 @CalledByNative("RTCConfiguration")
763 int getMaxIPv6Networks() {
764 return maxIPv6Networks;
765 }
766
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100767 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100768 @CalledByNative("RTCConfiguration")
769 IntervalRange getIceRegatherIntervalRange() {
770 return iceRegatherIntervalRange;
771 }
772
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100773 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100774 @CalledByNative("RTCConfiguration")
775 TurnCustomizer getTurnCustomizer() {
776 return turnCustomizer;
777 }
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100778
779 @CalledByNative("RTCConfiguration")
780 boolean getDisableIpv6() {
781 return disableIpv6;
782 }
783
784 @CalledByNative("RTCConfiguration")
785 boolean getEnableDscp() {
786 return enableDscp;
787 }
788
789 @CalledByNative("RTCConfiguration")
790 boolean getEnableCpuOveruseDetection() {
791 return enableCpuOveruseDetection;
792 }
793
794 @CalledByNative("RTCConfiguration")
795 boolean getEnableRtpDataChannel() {
796 return enableRtpDataChannel;
797 }
798
799 @CalledByNative("RTCConfiguration")
800 boolean getSuspendBelowMinBitrate() {
801 return suspendBelowMinBitrate;
802 }
803
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100804 @Nullable
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100805 @CalledByNative("RTCConfiguration")
806 Integer getScreencastMinBitrate() {
807 return screencastMinBitrate;
808 }
809
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100810 @Nullable
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100811 @CalledByNative("RTCConfiguration")
812 Boolean getCombinedAudioVideoBwe() {
813 return combinedAudioVideoBwe;
814 }
815
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100816 @Nullable
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100817 @CalledByNative("RTCConfiguration")
818 Boolean getEnableDtlsSrtp() {
819 return enableDtlsSrtp;
820 }
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800821
822 @CalledByNative("RTCConfiguration")
823 AdapterType getNetworkPreference() {
824 return networkPreference;
825 }
Seth Hampsonc384e142018-03-06 15:47:10 -0800826
827 @CalledByNative("RTCConfiguration")
828 SdpSemantics getSdpSemantics() {
829 return sdpSemantics;
830 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700831
832 @CalledByNative("RTCConfiguration")
833 boolean getActiveResetSrtpParams() {
834 return activeResetSrtpParams;
835 }
Piotr (Peter) Slatala09beff22018-10-17 07:22:40 -0700836
philipel16cec3b2019-10-25 12:23:02 +0200837 @Nullable
838 @CalledByNative("RTCConfiguration")
839 Boolean getAllowCodecSwitching() {
840 return allowCodecSwitching;
841 }
842
Piotr (Peter) Slatala09beff22018-10-17 07:22:40 -0700843 @CalledByNative("RTCConfiguration")
844 boolean getUseMediaTransport() {
845 return useMediaTransport;
846 }
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700847
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700848 @CalledByNative("RTCConfiguration")
849 boolean getUseMediaTransportForDataChannels() {
850 return useMediaTransportForDataChannels;
851 }
852
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700853 @Nullable
854 @CalledByNative("RTCConfiguration")
855 CryptoOptions getCryptoOptions() {
856 return cryptoOptions;
857 }
Jonas Oreland228900f2019-08-28 09:08:58 +0200858
859 @Nullable
860 @CalledByNative("RTCConfiguration")
861 String getTurnLoggingId() {
862 return turnLoggingId;
863 }
Jiayang Liucac1b382015-04-30 12:35:24 -0700864 };
865
Magnus Jedvert6062f372017-11-16 16:53:12 +0100866 private final List<MediaStream> localStreams = new ArrayList<>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 private final long nativePeerConnection;
Magnus Jedvert6062f372017-11-16 16:53:12 +0100868 private List<RtpSender> senders = new ArrayList<>();
869 private List<RtpReceiver> receivers = new ArrayList<>();
Seth Hampsonc384e142018-03-06 15:47:10 -0800870 private List<RtpTransceiver> transceivers = new ArrayList<>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871
Sami Kalliomäki1ece1ed2017-12-20 11:59:22 +0100872 /**
873 * Wraps a PeerConnection created by the factory. Can be used by clients that want to implement
874 * their PeerConnection creation in JNI.
875 */
876 public PeerConnection(NativePeerConnectionFactory factory) {
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100877 this(factory.createNativePeerConnection());
Sami Kalliomäki1ece1ed2017-12-20 11:59:22 +0100878 }
879
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100880 PeerConnection(long nativePeerConnection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 this.nativePeerConnection = nativePeerConnection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 }
883
884 // JsepInterface.
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100885 public SessionDescription getLocalDescription() {
886 return nativeGetLocalDescription();
887 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100889 public SessionDescription getRemoteDescription() {
890 return nativeGetRemoteDescription();
891 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892
Michael Iedema02137862018-10-09 15:30:01 +0200893 public RtcCertificatePem getCertificate() {
894 return nativeGetCertificate();
895 }
896
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100897 public DataChannel createDataChannel(String label, DataChannel.Init init) {
898 return nativeCreateDataChannel(label, init);
899 }
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000900
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100901 public void createOffer(SdpObserver observer, MediaConstraints constraints) {
902 nativeCreateOffer(observer, constraints);
903 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100905 public void createAnswer(SdpObserver observer, MediaConstraints constraints) {
906 nativeCreateAnswer(observer, constraints);
907 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100909 public void setLocalDescription(SdpObserver observer, SessionDescription sdp) {
910 nativeSetLocalDescription(observer, sdp);
911 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100913 public void setRemoteDescription(SdpObserver observer, SessionDescription sdp) {
914 nativeSetRemoteDescription(observer, sdp);
915 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916
Seth Hampsonc384e142018-03-06 15:47:10 -0800917 /**
918 * Enables/disables playout of received audio streams. Enabled by default.
919 *
920 * Note that even if playout is enabled, streams will only be played out if
921 * the appropriate SDP is also applied. The main purpose of this API is to
922 * be able to control the exact time when audio playout starts.
923 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100924 public void setAudioPlayout(boolean playout) {
925 nativeSetAudioPlayout(playout);
926 }
henrika5f6bf242017-11-01 11:06:56 +0100927
Seth Hampsonc384e142018-03-06 15:47:10 -0800928 /**
929 * Enables/disables recording of transmitted audio streams. Enabled by default.
930 *
931 * Note that even if recording is enabled, streams will only be recorded if
932 * the appropriate SDP is also applied. The main purpose of this API is to
933 * be able to control the exact time when audio recording starts.
934 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100935 public void setAudioRecording(boolean recording) {
936 nativeSetAudioRecording(recording);
937 }
henrika5f6bf242017-11-01 11:06:56 +0100938
deadbeef5d0b6d82017-01-09 16:05:28 -0800939 public boolean setConfiguration(RTCConfiguration config) {
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100940 return nativeSetConfiguration(config);
deadbeef5d0b6d82017-01-09 16:05:28 -0800941 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942
943 public boolean addIceCandidate(IceCandidate candidate) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100944 return nativeAddIceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 }
946
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700947 public boolean removeIceCandidates(final IceCandidate[] candidates) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100948 return nativeRemoveIceCandidates(candidates);
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700949 }
950
Seth Hampsonc384e142018-03-06 15:47:10 -0800951 /**
952 * Adds a new MediaStream to be sent on this peer connection.
953 * Note: This method is not supported with SdpSemantics.UNIFIED_PLAN. Please
954 * use addTrack instead.
955 */
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000956 public boolean addStream(MediaStream stream) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +0200957 boolean ret = nativeAddLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 if (!ret) {
959 return false;
960 }
961 localStreams.add(stream);
962 return true;
963 }
964
Seth Hampsonc384e142018-03-06 15:47:10 -0800965 /**
966 * Removes the given media stream from this peer connection.
967 * This method is not supported with SdpSemantics.UNIFIED_PLAN. Please use
968 * removeTrack instead.
969 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 public void removeStream(MediaStream stream) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +0200971 nativeRemoveLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 localStreams.remove(stream);
973 }
974
deadbeef7a246882017-08-09 08:40:10 -0700975 /**
976 * Creates an RtpSender without a track.
Seth Hampsonc384e142018-03-06 15:47:10 -0800977 *
978 * <p>This method allows an application to cause the PeerConnection to negotiate
deadbeef7a246882017-08-09 08:40:10 -0700979 * sending/receiving a specific media type, but without having a track to
980 * send yet.
Seth Hampsonc384e142018-03-06 15:47:10 -0800981 *
982 * <p>When the application does want to begin sending a track, it can call
deadbeef7a246882017-08-09 08:40:10 -0700983 * RtpSender.setTrack, which doesn't require any additional SDP negotiation.
Seth Hampsonc384e142018-03-06 15:47:10 -0800984 *
985 * <p>Example use:
deadbeef7a246882017-08-09 08:40:10 -0700986 * <pre>
987 * {@code
988 * audioSender = pc.createSender("audio", "stream1");
989 * videoSender = pc.createSender("video", "stream1");
990 * // Do normal SDP offer/answer, which will kick off ICE/DTLS and negotiate
991 * // media parameters....
992 * // Later, when the endpoint is ready to actually begin sending:
993 * audioSender.setTrack(audioTrack, false);
994 * videoSender.setTrack(videoTrack, false);
995 * }
996 * </pre>
Seth Hampsonc384e142018-03-06 15:47:10 -0800997 * <p>Note: This corresponds most closely to "addTransceiver" in the official
deadbeef7a246882017-08-09 08:40:10 -0700998 * WebRTC API, in that it creates a sender without a track. It was
999 * implemented before addTransceiver because it provides useful
1000 * functionality, and properly implementing transceivers would have required
1001 * a great deal more work.
1002 *
Seth Hampsonc384e142018-03-06 15:47:10 -08001003 * <p>Note: This is only available with SdpSemantics.PLAN_B specified. Please use
1004 * addTransceiver instead.
1005 *
deadbeef7a246882017-08-09 08:40:10 -07001006 * @param kind Corresponds to MediaStreamTrack kinds (must be "audio" or
1007 * "video").
1008 * @param stream_id The ID of the MediaStream that this sender's track will
1009 * be associated with when SDP is applied to the remote
1010 * PeerConnection. If createSender is used to create an
1011 * audio and video sender that should be synchronized, they
1012 * should use the same stream ID.
1013 * @return A new RtpSender object if successful, or null otherwise.
1014 */
deadbeefbd7d8f72015-12-18 16:58:44 -08001015 public RtpSender createSender(String kind, String stream_id) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001016 RtpSender newSender = nativeCreateSender(kind, stream_id);
1017 if (newSender != null) {
1018 senders.add(newSender);
deadbeefee524f72015-12-02 11:27:40 -08001019 }
Seth Hampsonc384e142018-03-06 15:47:10 -08001020 return newSender;
deadbeefee524f72015-12-02 11:27:40 -08001021 }
1022
Seth Hampsonc384e142018-03-06 15:47:10 -08001023 /**
1024 * Gets all RtpSenders associated with this peer connection.
1025 * Note that calling getSenders will dispose of the senders previously
1026 * returned.
1027 */
deadbeef4139c0f2015-10-06 12:29:25 -07001028 public List<RtpSender> getSenders() {
1029 for (RtpSender sender : senders) {
1030 sender.dispose();
1031 }
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001032 senders = nativeGetSenders();
deadbeef4139c0f2015-10-06 12:29:25 -07001033 return Collections.unmodifiableList(senders);
1034 }
1035
Seth Hampsonc384e142018-03-06 15:47:10 -08001036 /**
1037 * Gets all RtpReceivers associated with this peer connection.
1038 * Note that calling getReceivers will dispose of the receivers previously
1039 * returned.
1040 */
deadbeef4139c0f2015-10-06 12:29:25 -07001041 public List<RtpReceiver> getReceivers() {
1042 for (RtpReceiver receiver : receivers) {
1043 receiver.dispose();
1044 }
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001045 receivers = nativeGetReceivers();
deadbeef4139c0f2015-10-06 12:29:25 -07001046 return Collections.unmodifiableList(receivers);
1047 }
1048
Seth Hampsonc384e142018-03-06 15:47:10 -08001049 /**
1050 * Gets all RtpTransceivers associated with this peer connection.
1051 * Note that calling getTransceivers will dispose of the transceivers previously
1052 * returned.
1053 * Note: This is only available with SdpSemantics.UNIFIED_PLAN specified.
1054 */
1055 public List<RtpTransceiver> getTransceivers() {
1056 for (RtpTransceiver transceiver : transceivers) {
1057 transceiver.dispose();
1058 }
1059 transceivers = nativeGetTransceivers();
1060 return Collections.unmodifiableList(transceivers);
1061 }
1062
1063 /**
1064 * Adds a new media stream track to be sent on this peer connection, and returns
1065 * the newly created RtpSender. If streamIds are specified, the RtpSender will
1066 * be associated with the streams specified in the streamIds list.
1067 *
1068 * @throws IllegalStateException if an error accors in C++ addTrack.
1069 * An error can occur if:
1070 * - A sender already exists for the track.
1071 * - The peer connection is closed.
1072 */
1073 public RtpSender addTrack(MediaStreamTrack track) {
1074 return addTrack(track, Collections.emptyList());
1075 }
1076
1077 public RtpSender addTrack(MediaStreamTrack track, List<String> streamIds) {
1078 if (track == null || streamIds == null) {
1079 throw new NullPointerException("No MediaStreamTrack specified in addTrack.");
1080 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001081 RtpSender newSender = nativeAddTrack(track.getNativeMediaStreamTrack(), streamIds);
Seth Hampsonc384e142018-03-06 15:47:10 -08001082 if (newSender == null) {
1083 throw new IllegalStateException("C++ addTrack failed.");
1084 }
1085 senders.add(newSender);
1086 return newSender;
1087 }
1088
1089 /**
1090 * Stops sending media from sender. The sender will still appear in getSenders. Future
1091 * calls to createOffer will mark the m section for the corresponding transceiver as
1092 * receive only or inactive, as defined in JSEP. Returns true on success.
1093 */
1094 public boolean removeTrack(RtpSender sender) {
1095 if (sender == null) {
1096 throw new NullPointerException("No RtpSender specified for removeTrack.");
1097 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001098 return nativeRemoveTrack(sender.getNativeRtpSender());
Seth Hampsonc384e142018-03-06 15:47:10 -08001099 }
1100
1101 /**
1102 * Creates a new RtpTransceiver and adds it to the set of transceivers. Adding a
1103 * transceiver will cause future calls to CreateOffer to add a media description
1104 * for the corresponding transceiver.
1105 *
1106 * <p>The initial value of |mid| in the returned transceiver is null. Setting a
1107 * new session description may change it to a non-null value.
1108 *
1109 * <p>https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
1110 *
1111 * <p>If a MediaStreamTrack is specified then a transceiver will be added with a
1112 * sender set to transmit the given track. The kind
1113 * of the transceiver (and sender/receiver) will be derived from the kind of
1114 * the track.
1115 *
1116 * <p>If MediaType is specified then a transceiver will be added based upon that type.
1117 * This can be either MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO.
1118 *
1119 * <p>Optionally, an RtpTransceiverInit structure can be specified to configure
1120 * the transceiver from construction. If not specified, the transceiver will
1121 * default to having a direction of kSendRecv and not be part of any streams.
1122 *
1123 * <p>Note: These methods are only available with SdpSemantics.UNIFIED_PLAN specified.
1124 * @throws IllegalStateException if an error accors in C++ addTransceiver
1125 */
1126 public RtpTransceiver addTransceiver(MediaStreamTrack track) {
1127 return addTransceiver(track, new RtpTransceiver.RtpTransceiverInit());
1128 }
1129
1130 public RtpTransceiver addTransceiver(
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001131 MediaStreamTrack track, @Nullable RtpTransceiver.RtpTransceiverInit init) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001132 if (track == null) {
1133 throw new NullPointerException("No MediaStreamTrack specified for addTransceiver.");
1134 }
1135 if (init == null) {
1136 init = new RtpTransceiver.RtpTransceiverInit();
1137 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001138 RtpTransceiver newTransceiver =
1139 nativeAddTransceiverWithTrack(track.getNativeMediaStreamTrack(), init);
Seth Hampsonc384e142018-03-06 15:47:10 -08001140 if (newTransceiver == null) {
1141 throw new IllegalStateException("C++ addTransceiver failed.");
1142 }
1143 transceivers.add(newTransceiver);
1144 return newTransceiver;
1145 }
1146
1147 public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType) {
1148 return addTransceiver(mediaType, new RtpTransceiver.RtpTransceiverInit());
1149 }
1150
1151 public RtpTransceiver addTransceiver(
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001152 MediaStreamTrack.MediaType mediaType, @Nullable RtpTransceiver.RtpTransceiverInit init) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001153 if (mediaType == null) {
1154 throw new NullPointerException("No MediaType specified for addTransceiver.");
1155 }
1156 if (init == null) {
1157 init = new RtpTransceiver.RtpTransceiverInit();
1158 }
1159 RtpTransceiver newTransceiver = nativeAddTransceiverOfType(mediaType, init);
1160 if (newTransceiver == null) {
1161 throw new IllegalStateException("C++ addTransceiver failed.");
1162 }
1163 transceivers.add(newTransceiver);
1164 return newTransceiver;
1165 }
1166
deadbeef82215872017-04-18 10:27:51 -07001167 // Older, non-standard implementation of getStats.
1168 @Deprecated
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001169 public boolean getStats(StatsObserver observer, @Nullable MediaStreamTrack track) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001170 return nativeOldGetStats(observer, (track == null) ? 0 : track.getNativeMediaStreamTrack());
deadbeef82215872017-04-18 10:27:51 -07001171 }
1172
Seth Hampsonc384e142018-03-06 15:47:10 -08001173 /**
1174 * Gets stats using the new stats collection API, see webrtc/api/stats/. These
1175 * will replace old stats collection API when the new API has matured enough.
1176 */
deadbeef82215872017-04-18 10:27:51 -07001177 public void getStats(RTCStatsCollectorCallback callback) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001178 nativeNewGetStats(callback);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001179 }
1180
Seth Hampsonc384e142018-03-06 15:47:10 -08001181 /**
1182 * Limits the bandwidth allocated for all RTP streams sent by this
1183 * PeerConnection. Pass null to leave a value unchanged.
1184 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001185 public boolean setBitrate(Integer min, Integer current, Integer max) {
1186 return nativeSetBitrate(min, current, max);
1187 }
zsteind89b0bc2017-08-03 11:11:40 -07001188
Seth Hampsonc384e142018-03-06 15:47:10 -08001189 /**
1190 * Starts recording an RTC event log.
1191 *
1192 * Ownership of the file is transfered to the native code. If an RTC event
1193 * log is already being recorded, it will be stopped and a new one will start
1194 * using the provided file. Logging will continue until the stopRtcEventLog
1195 * function is called. The max_size_bytes argument is ignored, it is added
1196 * for future use.
1197 */
ivoc0c6f0f62016-07-06 04:34:23 -07001198 public boolean startRtcEventLog(int file_descriptor, int max_size_bytes) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001199 return nativeStartRtcEventLog(file_descriptor, max_size_bytes);
ivoc14d5dbe2016-07-04 07:06:55 -07001200 }
1201
Seth Hampsonc384e142018-03-06 15:47:10 -08001202 /**
1203 * Stops recording an RTC event log. If no RTC event log is currently being
1204 * recorded, this call will have no effect.
1205 */
ivoc14d5dbe2016-07-04 07:06:55 -07001206 public void stopRtcEventLog() {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001207 nativeStopRtcEventLog();
ivoc14d5dbe2016-07-04 07:06:55 -07001208 }
1209
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001210 // TODO(fischman): add support for DTMF-related methods once that API
1211 // stabilizes.
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001212 public SignalingState signalingState() {
1213 return nativeSignalingState();
1214 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001215
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001216 public IceConnectionState iceConnectionState() {
1217 return nativeIceConnectionState();
1218 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219
Jonas Olssonf01d8c82018-11-08 15:19:04 +01001220 public PeerConnectionState connectionState() {
1221 return nativeConnectionState();
1222 }
1223
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001224 public IceGatheringState iceGatheringState() {
1225 return nativeIceGatheringState();
1226 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001228 public void close() {
1229 nativeClose();
1230 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231
deadbeef43697f62017-09-12 10:52:14 -07001232 /**
1233 * Free native resources associated with this PeerConnection instance.
Seth Hampsonc384e142018-03-06 15:47:10 -08001234 *
deadbeef43697f62017-09-12 10:52:14 -07001235 * This method removes a reference count from the C++ PeerConnection object,
1236 * which should result in it being destroyed. It also calls equivalent
1237 * "dispose" methods on the Java objects attached to this PeerConnection
1238 * (streams, senders, receivers), such that their associated C++ objects
1239 * will also be destroyed.
Seth Hampsonc384e142018-03-06 15:47:10 -08001240 *
1241 * <p>Note that this method cannot be safely called from an observer callback
deadbeef43697f62017-09-12 10:52:14 -07001242 * (PeerConnection.Observer, DataChannel.Observer, etc.). If you want to, for
1243 * example, destroy the PeerConnection after an "ICE failed" callback, you
1244 * must do this asynchronously (in other words, unwind the stack first). See
1245 * <a href="https://bugs.chromium.org/p/webrtc/issues/detail?id=3721">bug
1246 * 3721</a> for more details.
1247 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 public void dispose() {
1249 close();
1250 for (MediaStream stream : localStreams) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001251 nativeRemoveLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 stream.dispose();
1253 }
1254 localStreams.clear();
deadbeef4139c0f2015-10-06 12:29:25 -07001255 for (RtpSender sender : senders) {
1256 sender.dispose();
1257 }
1258 senders.clear();
1259 for (RtpReceiver receiver : receivers) {
1260 receiver.dispose();
1261 }
Seth Hampsonc384e142018-03-06 15:47:10 -08001262 for (RtpTransceiver transceiver : transceivers) {
1263 transceiver.dispose();
1264 }
1265 transceivers.clear();
deadbeef4139c0f2015-10-06 12:29:25 -07001266 receivers.clear();
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001267 nativeFreeOwnedPeerConnection(nativePeerConnection);
1268 }
1269
1270 /** Returns a pointer to the native webrtc::PeerConnectionInterface. */
1271 public long getNativePeerConnection() {
1272 return nativeGetNativePeerConnection();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 }
1274
Magnus Jedvert9060eb12017-12-12 12:52:54 +01001275 @CalledByNative
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001276 long getNativeOwnedPeerConnection() {
Magnus Jedvert9060eb12017-12-12 12:52:54 +01001277 return nativePeerConnection;
1278 }
1279
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001280 public static long createNativePeerConnectionObserver(Observer observer) {
1281 return nativeCreatePeerConnectionObserver(observer);
1282 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001284 private native long nativeGetNativePeerConnection();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001285 private native SessionDescription nativeGetLocalDescription();
1286 private native SessionDescription nativeGetRemoteDescription();
Michael Iedema02137862018-10-09 15:30:01 +02001287 private native RtcCertificatePem nativeGetCertificate();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001288 private native DataChannel nativeCreateDataChannel(String label, DataChannel.Init init);
1289 private native void nativeCreateOffer(SdpObserver observer, MediaConstraints constraints);
1290 private native void nativeCreateAnswer(SdpObserver observer, MediaConstraints constraints);
1291 private native void nativeSetLocalDescription(SdpObserver observer, SessionDescription sdp);
1292 private native void nativeSetRemoteDescription(SdpObserver observer, SessionDescription sdp);
1293 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);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001306 private native boolean nativeRemoveIceCandidates(final IceCandidate[] candidates);
1307 private native boolean nativeAddLocalStream(long stream);
1308 private native void nativeRemoveLocalStream(long stream);
1309 private native boolean nativeOldGetStats(StatsObserver observer, long nativeTrack);
1310 private native void nativeNewGetStats(RTCStatsCollectorCallback callback);
1311 private native RtpSender nativeCreateSender(String kind, String stream_id);
1312 private native List<RtpSender> nativeGetSenders();
1313 private native List<RtpReceiver> nativeGetReceivers();
Seth Hampsonc384e142018-03-06 15:47:10 -08001314 private native List<RtpTransceiver> nativeGetTransceivers();
1315 private native RtpSender nativeAddTrack(long track, List<String> streamIds);
1316 private native boolean nativeRemoveTrack(long sender);
1317 private native RtpTransceiver nativeAddTransceiverWithTrack(
1318 long track, RtpTransceiver.RtpTransceiverInit init);
1319 private native RtpTransceiver nativeAddTransceiverOfType(
1320 MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001321 private native boolean nativeStartRtcEventLog(int file_descriptor, int max_size_bytes);
1322 private native void nativeStopRtcEventLog();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323}