blob: 7317573f035d3b93462b1fc6b86de686d8d73f3e [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
Steve Antond960a0c2017-07-17 12:33:07 -0700410 /** Java version of rtc::IntervalRange */
411 public static class IntervalRange {
412 private final int min;
413 private final int max;
414
415 public IntervalRange(int min, int max) {
416 this.min = min;
417 this.max = max;
418 }
419
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100420 @CalledByNative("IntervalRange")
Steve Antond960a0c2017-07-17 12:33:07 -0700421 public int getMin() {
422 return min;
423 }
424
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100425 @CalledByNative("IntervalRange")
Steve Antond960a0c2017-07-17 12:33:07 -0700426 public int getMax() {
427 return max;
428 }
429 }
430
Seth Hampsonc384e142018-03-06 15:47:10 -0800431 /**
432 * Java version of webrtc::SdpSemantics.
433 *
434 * Configure the SDP semantics used by this PeerConnection. Note that the
435 * WebRTC 1.0 specification requires UNIFIED_PLAN semantics. The
436 * RtpTransceiver API is only available with UNIFIED_PLAN semantics.
437 *
438 * <p>PLAN_B will cause PeerConnection to create offers and answers with at
439 * most one audio and one video m= section with multiple RtpSenders and
440 * RtpReceivers specified as multiple a=ssrc lines within the section. This
441 * will also cause PeerConnection to ignore all but the first m= section of
442 * the same media type.
443 *
444 * <p>UNIFIED_PLAN will cause PeerConnection to create offers and answers with
445 * multiple m= sections where each m= section maps to one RtpSender and one
446 * RtpReceiver (an RtpTransceiver), either both audio or both video. This
447 * will also cause PeerConnection to ignore all but the first a=ssrc lines
448 * that form a Plan B stream.
449 *
450 * <p>For users who wish to send multiple audio/video streams and need to stay
451 * interoperable with legacy WebRTC implementations, specify PLAN_B.
452 *
453 * <p>For users who wish to send multiple audio/video streams and/or wish to
454 * use the new RtpTransceiver API, specify UNIFIED_PLAN.
455 */
456 public enum SdpSemantics { PLAN_B, UNIFIED_PLAN }
457
Jiayang Liucac1b382015-04-30 12:35:24 -0700458 /** Java version of PeerConnectionInterface.RTCConfiguration */
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800459 // TODO(qingsi): Resolve the naming inconsistency of fields with/without units.
Jiayang Liucac1b382015-04-30 12:35:24 -0700460 public static class RTCConfiguration {
461 public IceTransportsType iceTransportsType;
462 public List<IceServer> iceServers;
463 public BundlePolicy bundlePolicy;
Michael Iedema02137862018-10-09 15:30:01 +0200464 @Nullable public RtcCertificatePem certificate;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700465 public RtcpMuxPolicy rtcpMuxPolicy;
Jiayang Liucac1b382015-04-30 12:35:24 -0700466 public TcpCandidatePolicy tcpCandidatePolicy;
honghaiz60347052016-05-31 18:29:12 -0700467 public CandidateNetworkPolicy candidateNetworkPolicy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200468 public int audioJitterBufferMaxPackets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200469 public boolean audioJitterBufferFastAccelerate;
honghaiz4edc39c2015-09-01 09:53:56 -0700470 public int iceConnectionReceivingTimeout;
Honghai Zhang381b4212015-12-04 12:24:03 -0800471 public int iceBackupCandidatePairPingInterval;
glaznev97579a42015-09-01 11:31:27 -0700472 public KeyType keyType;
honghaiz1f429e32015-09-28 07:57:34 -0700473 public ContinualGatheringPolicy continualGatheringPolicy;
deadbeefbe0c96f2016-05-18 16:20:14 -0700474 public int iceCandidatePoolSize;
Honghai Zhangd78ecf72016-07-01 14:40:40 -0700475 public boolean pruneTurnPorts;
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;
zhihuangb09b3f92017-03-07 14:40:51 -0800511 public boolean disableIPv6OnWifi;
deadbeef28e29192017-07-27 09:14:38 -0700512 // By default, PeerConnection will use a limited number of IPv6 network
513 // interfaces, in order to avoid too many ICE candidate pairs being created
514 // and delaying ICE completion.
515 //
516 // Can be set to Integer.MAX_VALUE to effectively disable the limit.
517 public int maxIPv6Networks;
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100518 @Nullable public IntervalRange iceRegatherIntervalRange;
Jiayang Liucac1b382015-04-30 12:35:24 -0700519
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100520 // These values will be overridden by MediaStream constraints if deprecated constraints-based
521 // create peerconnection interface is used.
522 public boolean disableIpv6;
523 public boolean enableDscp;
524 public boolean enableCpuOveruseDetection;
525 public boolean enableRtpDataChannel;
526 public boolean suspendBelowMinBitrate;
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100527 @Nullable public Integer screencastMinBitrate;
528 @Nullable public Boolean combinedAudioVideoBwe;
529 @Nullable public Boolean enableDtlsSrtp;
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
Piotr (Peter) Slatala09beff22018-10-17 07:22:40 -0700542 /*
543 * Experimental flag that enables a use of media transport. If this is true, the media transport
544 * factory MUST be provided to the PeerConnectionFactory.
545 */
546 public boolean useMediaTransport;
547
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700548 /*
549 * Experimental flag that enables a use of media transport for data channels. If this is true,
550 * the media transport factory MUST be provided to the PeerConnectionFactory.
551 */
552 public boolean useMediaTransportForDataChannels;
553
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700554 /**
555 * Defines advanced optional cryptographic settings related to SRTP and
556 * frame encryption for native WebRTC. Setting this will overwrite any
557 * options set through the PeerConnectionFactory (which is deprecated).
558 */
559 @Nullable public CryptoOptions cryptoOptions;
560
Jonas Oreland228900f2019-08-28 09:08:58 +0200561 /**
562 * An optional string that if set will be attached to the
563 * TURN_ALLOCATE_REQUEST which can be used to correlate client
564 * logs with backend logs
565 */
566 @Nullable public String turnLoggingId;
567
deadbeef28e29192017-07-27 09:14:38 -0700568 // TODO(deadbeef): Instead of duplicating the defaults here, we should do
569 // something to pick up the defaults from C++. The Objective-C equivalent
570 // of RTCConfiguration does that.
Jiayang Liucac1b382015-04-30 12:35:24 -0700571 public RTCConfiguration(List<IceServer> iceServers) {
572 iceTransportsType = IceTransportsType.ALL;
573 bundlePolicy = BundlePolicy.BALANCED;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800574 rtcpMuxPolicy = RtcpMuxPolicy.REQUIRE;
Jiayang Liucac1b382015-04-30 12:35:24 -0700575 tcpCandidatePolicy = TcpCandidatePolicy.ENABLED;
Sami Kalliomäki9828beb2017-10-26 16:21:22 +0200576 candidateNetworkPolicy = CandidateNetworkPolicy.ALL;
Jiayang Liucac1b382015-04-30 12:35:24 -0700577 this.iceServers = iceServers;
Henrik Lundin64dad832015-05-11 12:44:23 +0200578 audioJitterBufferMaxPackets = 50;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200579 audioJitterBufferFastAccelerate = false;
honghaiz4edc39c2015-09-01 09:53:56 -0700580 iceConnectionReceivingTimeout = -1;
Honghai Zhang381b4212015-12-04 12:24:03 -0800581 iceBackupCandidatePairPingInterval = -1;
glaznev97579a42015-09-01 11:31:27 -0700582 keyType = KeyType.ECDSA;
honghaiz1f429e32015-09-28 07:57:34 -0700583 continualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE;
deadbeefbe0c96f2016-05-18 16:20:14 -0700584 iceCandidatePoolSize = 0;
Honghai Zhangd78ecf72016-07-01 14:40:40 -0700585 pruneTurnPorts = false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700586 presumeWritableWhenFullyRelayed = false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700587 surfaceIceCandidatesOnIceTransportTypeChanged = false;
Qingsi Wange6826d22018-03-08 14:55:14 -0800588 iceCheckIntervalStrongConnectivityMs = null;
589 iceCheckIntervalWeakConnectivityMs = null;
skvlad51072462017-02-02 11:50:14 -0800590 iceCheckMinInterval = null;
Qingsi Wang22e623a2018-03-13 10:53:57 -0700591 iceUnwritableTimeMs = null;
592 iceUnwritableMinChecks = null;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800593 stunCandidateKeepaliveIntervalMs = null;
zhihuangb09b3f92017-03-07 14:40:51 -0800594 disableIPv6OnWifi = false;
deadbeef28e29192017-07-27 09:14:38 -0700595 maxIPv6Networks = 5;
Steve Antond960a0c2017-07-17 12:33:07 -0700596 iceRegatherIntervalRange = null;
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100597 disableIpv6 = false;
598 enableDscp = false;
599 enableCpuOveruseDetection = true;
600 enableRtpDataChannel = false;
601 suspendBelowMinBitrate = false;
602 screencastMinBitrate = null;
603 combinedAudioVideoBwe = null;
604 enableDtlsSrtp = null;
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800605 networkPreference = AdapterType.UNKNOWN;
Seth Hampsonc384e142018-03-06 15:47:10 -0800606 sdpSemantics = SdpSemantics.PLAN_B;
Zhi Huangb57e1692018-06-12 11:41:11 -0700607 activeResetSrtpParams = false;
Piotr (Peter) Slatala09beff22018-10-17 07:22:40 -0700608 useMediaTransport = false;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700609 useMediaTransportForDataChannels = false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700610 cryptoOptions = null;
Jonas Oreland228900f2019-08-28 09:08:58 +0200611 turnLoggingId = null;
Jiayang Liucac1b382015-04-30 12:35:24 -0700612 }
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100613
614 @CalledByNative("RTCConfiguration")
615 IceTransportsType getIceTransportsType() {
616 return iceTransportsType;
617 }
618
619 @CalledByNative("RTCConfiguration")
620 List<IceServer> getIceServers() {
621 return iceServers;
622 }
623
624 @CalledByNative("RTCConfiguration")
625 BundlePolicy getBundlePolicy() {
626 return bundlePolicy;
627 }
628
Michael Iedema02137862018-10-09 15:30:01 +0200629 @Nullable
630 @CalledByNative("RTCConfiguration")
631 RtcCertificatePem getCertificate() {
632 return certificate;
633 }
634
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100635 @CalledByNative("RTCConfiguration")
636 RtcpMuxPolicy getRtcpMuxPolicy() {
637 return rtcpMuxPolicy;
638 }
639
640 @CalledByNative("RTCConfiguration")
641 TcpCandidatePolicy getTcpCandidatePolicy() {
642 return tcpCandidatePolicy;
643 }
644
645 @CalledByNative("RTCConfiguration")
646 CandidateNetworkPolicy getCandidateNetworkPolicy() {
647 return candidateNetworkPolicy;
648 }
649
650 @CalledByNative("RTCConfiguration")
651 int getAudioJitterBufferMaxPackets() {
652 return audioJitterBufferMaxPackets;
653 }
654
655 @CalledByNative("RTCConfiguration")
656 boolean getAudioJitterBufferFastAccelerate() {
657 return audioJitterBufferFastAccelerate;
658 }
659
660 @CalledByNative("RTCConfiguration")
661 int getIceConnectionReceivingTimeout() {
662 return iceConnectionReceivingTimeout;
663 }
664
665 @CalledByNative("RTCConfiguration")
666 int getIceBackupCandidatePairPingInterval() {
667 return iceBackupCandidatePairPingInterval;
668 }
669
670 @CalledByNative("RTCConfiguration")
671 KeyType getKeyType() {
672 return keyType;
673 }
674
675 @CalledByNative("RTCConfiguration")
676 ContinualGatheringPolicy getContinualGatheringPolicy() {
677 return continualGatheringPolicy;
678 }
679
680 @CalledByNative("RTCConfiguration")
681 int getIceCandidatePoolSize() {
682 return iceCandidatePoolSize;
683 }
684
685 @CalledByNative("RTCConfiguration")
686 boolean getPruneTurnPorts() {
687 return pruneTurnPorts;
688 }
689
690 @CalledByNative("RTCConfiguration")
691 boolean getPresumeWritableWhenFullyRelayed() {
692 return presumeWritableWhenFullyRelayed;
693 }
694
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700695 @CalledByNative("RTCConfiguration")
696 boolean getSurfaceIceCandidatesOnIceTransportTypeChanged() {
697 return surfaceIceCandidatesOnIceTransportTypeChanged;
698 }
699
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100700 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100701 @CalledByNative("RTCConfiguration")
Qingsi Wange6826d22018-03-08 14:55:14 -0800702 Integer getIceCheckIntervalStrongConnectivity() {
703 return iceCheckIntervalStrongConnectivityMs;
704 }
705
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100706 @Nullable
Qingsi Wange6826d22018-03-08 14:55:14 -0800707 @CalledByNative("RTCConfiguration")
708 Integer getIceCheckIntervalWeakConnectivity() {
709 return iceCheckIntervalWeakConnectivityMs;
710 }
711
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100712 @Nullable
Qingsi Wange6826d22018-03-08 14:55:14 -0800713 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100714 Integer getIceCheckMinInterval() {
715 return iceCheckMinInterval;
716 }
717
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100718 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100719 @CalledByNative("RTCConfiguration")
Qingsi Wang22e623a2018-03-13 10:53:57 -0700720 Integer getIceUnwritableTimeout() {
721 return iceUnwritableTimeMs;
722 }
723
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100724 @Nullable
Qingsi Wang22e623a2018-03-13 10:53:57 -0700725 @CalledByNative("RTCConfiguration")
726 Integer getIceUnwritableMinChecks() {
727 return iceUnwritableMinChecks;
728 }
729
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100730 @Nullable
Qingsi Wang22e623a2018-03-13 10:53:57 -0700731 @CalledByNative("RTCConfiguration")
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800732 Integer getStunCandidateKeepaliveInterval() {
733 return stunCandidateKeepaliveIntervalMs;
734 }
735
736 @CalledByNative("RTCConfiguration")
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100737 boolean getDisableIPv6OnWifi() {
738 return disableIPv6OnWifi;
739 }
740
741 @CalledByNative("RTCConfiguration")
742 int getMaxIPv6Networks() {
743 return maxIPv6Networks;
744 }
745
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100746 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100747 @CalledByNative("RTCConfiguration")
748 IntervalRange getIceRegatherIntervalRange() {
749 return iceRegatherIntervalRange;
750 }
751
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100752 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100753 @CalledByNative("RTCConfiguration")
754 TurnCustomizer getTurnCustomizer() {
755 return turnCustomizer;
756 }
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100757
758 @CalledByNative("RTCConfiguration")
759 boolean getDisableIpv6() {
760 return disableIpv6;
761 }
762
763 @CalledByNative("RTCConfiguration")
764 boolean getEnableDscp() {
765 return enableDscp;
766 }
767
768 @CalledByNative("RTCConfiguration")
769 boolean getEnableCpuOveruseDetection() {
770 return enableCpuOveruseDetection;
771 }
772
773 @CalledByNative("RTCConfiguration")
774 boolean getEnableRtpDataChannel() {
775 return enableRtpDataChannel;
776 }
777
778 @CalledByNative("RTCConfiguration")
779 boolean getSuspendBelowMinBitrate() {
780 return suspendBelowMinBitrate;
781 }
782
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100783 @Nullable
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100784 @CalledByNative("RTCConfiguration")
785 Integer getScreencastMinBitrate() {
786 return screencastMinBitrate;
787 }
788
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100789 @Nullable
Sami Kalliomäkie8b26cd2017-12-19 12:51:53 +0100790 @CalledByNative("RTCConfiguration")
791 Boolean getCombinedAudioVideoBwe() {
792 return combinedAudioVideoBwe;
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 getEnableDtlsSrtp() {
798 return enableDtlsSrtp;
799 }
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800800
801 @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
816 @CalledByNative("RTCConfiguration")
817 boolean getUseMediaTransport() {
818 return useMediaTransport;
819 }
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700820
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700821 @CalledByNative("RTCConfiguration")
822 boolean getUseMediaTransportForDataChannels() {
823 return useMediaTransportForDataChannels;
824 }
825
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700826 @Nullable
827 @CalledByNative("RTCConfiguration")
828 CryptoOptions getCryptoOptions() {
829 return cryptoOptions;
830 }
Jonas Oreland228900f2019-08-28 09:08:58 +0200831
832 @Nullable
833 @CalledByNative("RTCConfiguration")
834 String getTurnLoggingId() {
835 return turnLoggingId;
836 }
Jiayang Liucac1b382015-04-30 12:35:24 -0700837 };
838
Magnus Jedvert6062f372017-11-16 16:53:12 +0100839 private final List<MediaStream> localStreams = new ArrayList<>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 private final long nativePeerConnection;
Magnus Jedvert6062f372017-11-16 16:53:12 +0100841 private List<RtpSender> senders = new ArrayList<>();
842 private List<RtpReceiver> receivers = new ArrayList<>();
Seth Hampsonc384e142018-03-06 15:47:10 -0800843 private List<RtpTransceiver> transceivers = new ArrayList<>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844
Sami Kalliomäki1ece1ed2017-12-20 11:59:22 +0100845 /**
846 * Wraps a PeerConnection created by the factory. Can be used by clients that want to implement
847 * their PeerConnection creation in JNI.
848 */
849 public PeerConnection(NativePeerConnectionFactory factory) {
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100850 this(factory.createNativePeerConnection());
Sami Kalliomäki1ece1ed2017-12-20 11:59:22 +0100851 }
852
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100853 PeerConnection(long nativePeerConnection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 this.nativePeerConnection = nativePeerConnection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 }
856
857 // JsepInterface.
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100858 public SessionDescription getLocalDescription() {
859 return nativeGetLocalDescription();
860 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100862 public SessionDescription getRemoteDescription() {
863 return nativeGetRemoteDescription();
864 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865
Michael Iedema02137862018-10-09 15:30:01 +0200866 public RtcCertificatePem getCertificate() {
867 return nativeGetCertificate();
868 }
869
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100870 public DataChannel createDataChannel(String label, DataChannel.Init init) {
871 return nativeCreateDataChannel(label, init);
872 }
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000873
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100874 public void createOffer(SdpObserver observer, MediaConstraints constraints) {
875 nativeCreateOffer(observer, constraints);
876 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100878 public void createAnswer(SdpObserver observer, MediaConstraints constraints) {
879 nativeCreateAnswer(observer, constraints);
880 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100882 public void setLocalDescription(SdpObserver observer, SessionDescription sdp) {
883 nativeSetLocalDescription(observer, sdp);
884 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100886 public void setRemoteDescription(SdpObserver observer, SessionDescription sdp) {
887 nativeSetRemoteDescription(observer, sdp);
888 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889
Seth Hampsonc384e142018-03-06 15:47:10 -0800890 /**
891 * Enables/disables playout of received audio streams. Enabled by default.
892 *
893 * Note that even if playout is enabled, streams will only be played out if
894 * the appropriate SDP is also applied. The main purpose of this API is to
895 * be able to control the exact time when audio playout starts.
896 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100897 public void setAudioPlayout(boolean playout) {
898 nativeSetAudioPlayout(playout);
899 }
henrika5f6bf242017-11-01 11:06:56 +0100900
Seth Hampsonc384e142018-03-06 15:47:10 -0800901 /**
902 * Enables/disables recording of transmitted audio streams. Enabled by default.
903 *
904 * Note that even if recording is enabled, streams will only be recorded if
905 * the appropriate SDP is also applied. The main purpose of this API is to
906 * be able to control the exact time when audio recording starts.
907 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100908 public void setAudioRecording(boolean recording) {
909 nativeSetAudioRecording(recording);
910 }
henrika5f6bf242017-11-01 11:06:56 +0100911
deadbeef5d0b6d82017-01-09 16:05:28 -0800912 public boolean setConfiguration(RTCConfiguration config) {
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +0100913 return nativeSetConfiguration(config);
deadbeef5d0b6d82017-01-09 16:05:28 -0800914 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915
916 public boolean addIceCandidate(IceCandidate candidate) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100917 return nativeAddIceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 }
919
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700920 public boolean removeIceCandidates(final IceCandidate[] candidates) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +0100921 return nativeRemoveIceCandidates(candidates);
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700922 }
923
Seth Hampsonc384e142018-03-06 15:47:10 -0800924 /**
925 * Adds a new MediaStream to be sent on this peer connection.
926 * Note: This method is not supported with SdpSemantics.UNIFIED_PLAN. Please
927 * use addTrack instead.
928 */
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000929 public boolean addStream(MediaStream stream) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +0200930 boolean ret = nativeAddLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 if (!ret) {
932 return false;
933 }
934 localStreams.add(stream);
935 return true;
936 }
937
Seth Hampsonc384e142018-03-06 15:47:10 -0800938 /**
939 * Removes the given media stream from this peer connection.
940 * This method is not supported with SdpSemantics.UNIFIED_PLAN. Please use
941 * removeTrack instead.
942 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 public void removeStream(MediaStream stream) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +0200944 nativeRemoveLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 localStreams.remove(stream);
946 }
947
deadbeef7a246882017-08-09 08:40:10 -0700948 /**
949 * Creates an RtpSender without a track.
Seth Hampsonc384e142018-03-06 15:47:10 -0800950 *
951 * <p>This method allows an application to cause the PeerConnection to negotiate
deadbeef7a246882017-08-09 08:40:10 -0700952 * sending/receiving a specific media type, but without having a track to
953 * send yet.
Seth Hampsonc384e142018-03-06 15:47:10 -0800954 *
955 * <p>When the application does want to begin sending a track, it can call
deadbeef7a246882017-08-09 08:40:10 -0700956 * RtpSender.setTrack, which doesn't require any additional SDP negotiation.
Seth Hampsonc384e142018-03-06 15:47:10 -0800957 *
958 * <p>Example use:
deadbeef7a246882017-08-09 08:40:10 -0700959 * <pre>
960 * {@code
961 * audioSender = pc.createSender("audio", "stream1");
962 * videoSender = pc.createSender("video", "stream1");
963 * // Do normal SDP offer/answer, which will kick off ICE/DTLS and negotiate
964 * // media parameters....
965 * // Later, when the endpoint is ready to actually begin sending:
966 * audioSender.setTrack(audioTrack, false);
967 * videoSender.setTrack(videoTrack, false);
968 * }
969 * </pre>
Seth Hampsonc384e142018-03-06 15:47:10 -0800970 * <p>Note: This corresponds most closely to "addTransceiver" in the official
deadbeef7a246882017-08-09 08:40:10 -0700971 * WebRTC API, in that it creates a sender without a track. It was
972 * implemented before addTransceiver because it provides useful
973 * functionality, and properly implementing transceivers would have required
974 * a great deal more work.
975 *
Seth Hampsonc384e142018-03-06 15:47:10 -0800976 * <p>Note: This is only available with SdpSemantics.PLAN_B specified. Please use
977 * addTransceiver instead.
978 *
deadbeef7a246882017-08-09 08:40:10 -0700979 * @param kind Corresponds to MediaStreamTrack kinds (must be "audio" or
980 * "video").
981 * @param stream_id The ID of the MediaStream that this sender's track will
982 * be associated with when SDP is applied to the remote
983 * PeerConnection. If createSender is used to create an
984 * audio and video sender that should be synchronized, they
985 * should use the same stream ID.
986 * @return A new RtpSender object if successful, or null otherwise.
987 */
deadbeefbd7d8f72015-12-18 16:58:44 -0800988 public RtpSender createSender(String kind, String stream_id) {
Seth Hampsonc384e142018-03-06 15:47:10 -0800989 RtpSender newSender = nativeCreateSender(kind, stream_id);
990 if (newSender != null) {
991 senders.add(newSender);
deadbeefee524f72015-12-02 11:27:40 -0800992 }
Seth Hampsonc384e142018-03-06 15:47:10 -0800993 return newSender;
deadbeefee524f72015-12-02 11:27:40 -0800994 }
995
Seth Hampsonc384e142018-03-06 15:47:10 -0800996 /**
997 * Gets all RtpSenders associated with this peer connection.
998 * Note that calling getSenders will dispose of the senders previously
999 * returned.
1000 */
deadbeef4139c0f2015-10-06 12:29:25 -07001001 public List<RtpSender> getSenders() {
1002 for (RtpSender sender : senders) {
1003 sender.dispose();
1004 }
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001005 senders = nativeGetSenders();
deadbeef4139c0f2015-10-06 12:29:25 -07001006 return Collections.unmodifiableList(senders);
1007 }
1008
Seth Hampsonc384e142018-03-06 15:47:10 -08001009 /**
1010 * Gets all RtpReceivers associated with this peer connection.
1011 * Note that calling getReceivers will dispose of the receivers previously
1012 * returned.
1013 */
deadbeef4139c0f2015-10-06 12:29:25 -07001014 public List<RtpReceiver> getReceivers() {
1015 for (RtpReceiver receiver : receivers) {
1016 receiver.dispose();
1017 }
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001018 receivers = nativeGetReceivers();
deadbeef4139c0f2015-10-06 12:29:25 -07001019 return Collections.unmodifiableList(receivers);
1020 }
1021
Seth Hampsonc384e142018-03-06 15:47:10 -08001022 /**
1023 * Gets all RtpTransceivers associated with this peer connection.
1024 * Note that calling getTransceivers will dispose of the transceivers previously
1025 * returned.
1026 * Note: This is only available with SdpSemantics.UNIFIED_PLAN specified.
1027 */
1028 public List<RtpTransceiver> getTransceivers() {
1029 for (RtpTransceiver transceiver : transceivers) {
1030 transceiver.dispose();
1031 }
1032 transceivers = nativeGetTransceivers();
1033 return Collections.unmodifiableList(transceivers);
1034 }
1035
1036 /**
1037 * Adds a new media stream track to be sent on this peer connection, and returns
1038 * the newly created RtpSender. If streamIds are specified, the RtpSender will
1039 * be associated with the streams specified in the streamIds list.
1040 *
1041 * @throws IllegalStateException if an error accors in C++ addTrack.
1042 * An error can occur if:
1043 * - A sender already exists for the track.
1044 * - The peer connection is closed.
1045 */
1046 public RtpSender addTrack(MediaStreamTrack track) {
1047 return addTrack(track, Collections.emptyList());
1048 }
1049
1050 public RtpSender addTrack(MediaStreamTrack track, List<String> streamIds) {
1051 if (track == null || streamIds == null) {
1052 throw new NullPointerException("No MediaStreamTrack specified in addTrack.");
1053 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001054 RtpSender newSender = nativeAddTrack(track.getNativeMediaStreamTrack(), streamIds);
Seth Hampsonc384e142018-03-06 15:47:10 -08001055 if (newSender == null) {
1056 throw new IllegalStateException("C++ addTrack failed.");
1057 }
1058 senders.add(newSender);
1059 return newSender;
1060 }
1061
1062 /**
1063 * Stops sending media from sender. The sender will still appear in getSenders. Future
1064 * calls to createOffer will mark the m section for the corresponding transceiver as
1065 * receive only or inactive, as defined in JSEP. Returns true on success.
1066 */
1067 public boolean removeTrack(RtpSender sender) {
1068 if (sender == null) {
1069 throw new NullPointerException("No RtpSender specified for removeTrack.");
1070 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001071 return nativeRemoveTrack(sender.getNativeRtpSender());
Seth Hampsonc384e142018-03-06 15:47:10 -08001072 }
1073
1074 /**
1075 * Creates a new RtpTransceiver and adds it to the set of transceivers. Adding a
1076 * transceiver will cause future calls to CreateOffer to add a media description
1077 * for the corresponding transceiver.
1078 *
1079 * <p>The initial value of |mid| in the returned transceiver is null. Setting a
1080 * new session description may change it to a non-null value.
1081 *
1082 * <p>https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
1083 *
1084 * <p>If a MediaStreamTrack is specified then a transceiver will be added with a
1085 * sender set to transmit the given track. The kind
1086 * of the transceiver (and sender/receiver) will be derived from the kind of
1087 * the track.
1088 *
1089 * <p>If MediaType is specified then a transceiver will be added based upon that type.
1090 * This can be either MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO.
1091 *
1092 * <p>Optionally, an RtpTransceiverInit structure can be specified to configure
1093 * the transceiver from construction. If not specified, the transceiver will
1094 * default to having a direction of kSendRecv and not be part of any streams.
1095 *
1096 * <p>Note: These methods are only available with SdpSemantics.UNIFIED_PLAN specified.
1097 * @throws IllegalStateException if an error accors in C++ addTransceiver
1098 */
1099 public RtpTransceiver addTransceiver(MediaStreamTrack track) {
1100 return addTransceiver(track, new RtpTransceiver.RtpTransceiverInit());
1101 }
1102
1103 public RtpTransceiver addTransceiver(
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001104 MediaStreamTrack track, @Nullable RtpTransceiver.RtpTransceiverInit init) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001105 if (track == null) {
1106 throw new NullPointerException("No MediaStreamTrack specified for addTransceiver.");
1107 }
1108 if (init == null) {
1109 init = new RtpTransceiver.RtpTransceiverInit();
1110 }
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001111 RtpTransceiver newTransceiver =
1112 nativeAddTransceiverWithTrack(track.getNativeMediaStreamTrack(), init);
Seth Hampsonc384e142018-03-06 15:47:10 -08001113 if (newTransceiver == null) {
1114 throw new IllegalStateException("C++ addTransceiver failed.");
1115 }
1116 transceivers.add(newTransceiver);
1117 return newTransceiver;
1118 }
1119
1120 public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType) {
1121 return addTransceiver(mediaType, new RtpTransceiver.RtpTransceiverInit());
1122 }
1123
1124 public RtpTransceiver addTransceiver(
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001125 MediaStreamTrack.MediaType mediaType, @Nullable RtpTransceiver.RtpTransceiverInit init) {
Seth Hampsonc384e142018-03-06 15:47:10 -08001126 if (mediaType == null) {
1127 throw new NullPointerException("No MediaType specified for addTransceiver.");
1128 }
1129 if (init == null) {
1130 init = new RtpTransceiver.RtpTransceiverInit();
1131 }
1132 RtpTransceiver newTransceiver = nativeAddTransceiverOfType(mediaType, init);
1133 if (newTransceiver == null) {
1134 throw new IllegalStateException("C++ addTransceiver failed.");
1135 }
1136 transceivers.add(newTransceiver);
1137 return newTransceiver;
1138 }
1139
deadbeef82215872017-04-18 10:27:51 -07001140 // Older, non-standard implementation of getStats.
1141 @Deprecated
Sami Kalliomäkie7592d82018-03-22 13:32:44 +01001142 public boolean getStats(StatsObserver observer, @Nullable MediaStreamTrack track) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001143 return nativeOldGetStats(observer, (track == null) ? 0 : track.getNativeMediaStreamTrack());
deadbeef82215872017-04-18 10:27:51 -07001144 }
1145
Seth Hampsonc384e142018-03-06 15:47:10 -08001146 /**
1147 * Gets stats using the new stats collection API, see webrtc/api/stats/. These
1148 * will replace old stats collection API when the new API has matured enough.
1149 */
deadbeef82215872017-04-18 10:27:51 -07001150 public void getStats(RTCStatsCollectorCallback callback) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001151 nativeNewGetStats(callback);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001152 }
1153
Seth Hampsonc384e142018-03-06 15:47:10 -08001154 /**
1155 * Limits the bandwidth allocated for all RTP streams sent by this
1156 * PeerConnection. Pass null to leave a value unchanged.
1157 */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001158 public boolean setBitrate(Integer min, Integer current, Integer max) {
1159 return nativeSetBitrate(min, current, max);
1160 }
zsteind89b0bc2017-08-03 11:11:40 -07001161
Seth Hampsonc384e142018-03-06 15:47:10 -08001162 /**
1163 * Starts recording an RTC event log.
1164 *
1165 * Ownership of the file is transfered to the native code. If an RTC event
1166 * log is already being recorded, it will be stopped and a new one will start
1167 * using the provided file. Logging will continue until the stopRtcEventLog
1168 * function is called. The max_size_bytes argument is ignored, it is added
1169 * for future use.
1170 */
ivoc0c6f0f62016-07-06 04:34:23 -07001171 public boolean startRtcEventLog(int file_descriptor, int max_size_bytes) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001172 return nativeStartRtcEventLog(file_descriptor, max_size_bytes);
ivoc14d5dbe2016-07-04 07:06:55 -07001173 }
1174
Seth Hampsonc384e142018-03-06 15:47:10 -08001175 /**
1176 * Stops recording an RTC event log. If no RTC event log is currently being
1177 * recorded, this call will have no effect.
1178 */
ivoc14d5dbe2016-07-04 07:06:55 -07001179 public void stopRtcEventLog() {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001180 nativeStopRtcEventLog();
ivoc14d5dbe2016-07-04 07:06:55 -07001181 }
1182
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183 // TODO(fischman): add support for DTMF-related methods once that API
1184 // stabilizes.
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001185 public SignalingState signalingState() {
1186 return nativeSignalingState();
1187 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001188
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001189 public IceConnectionState iceConnectionState() {
1190 return nativeIceConnectionState();
1191 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001192
Jonas Olssonf01d8c82018-11-08 15:19:04 +01001193 public PeerConnectionState connectionState() {
1194 return nativeConnectionState();
1195 }
1196
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001197 public IceGatheringState iceGatheringState() {
1198 return nativeIceGatheringState();
1199 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001201 public void close() {
1202 nativeClose();
1203 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001204
deadbeef43697f62017-09-12 10:52:14 -07001205 /**
1206 * Free native resources associated with this PeerConnection instance.
Seth Hampsonc384e142018-03-06 15:47:10 -08001207 *
deadbeef43697f62017-09-12 10:52:14 -07001208 * This method removes a reference count from the C++ PeerConnection object,
1209 * which should result in it being destroyed. It also calls equivalent
1210 * "dispose" methods on the Java objects attached to this PeerConnection
1211 * (streams, senders, receivers), such that their associated C++ objects
1212 * will also be destroyed.
Seth Hampsonc384e142018-03-06 15:47:10 -08001213 *
1214 * <p>Note that this method cannot be safely called from an observer callback
deadbeef43697f62017-09-12 10:52:14 -07001215 * (PeerConnection.Observer, DataChannel.Observer, etc.). If you want to, for
1216 * example, destroy the PeerConnection after an "ICE failed" callback, you
1217 * must do this asynchronously (in other words, unwind the stack first). See
1218 * <a href="https://bugs.chromium.org/p/webrtc/issues/detail?id=3721">bug
1219 * 3721</a> for more details.
1220 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 public void dispose() {
1222 close();
1223 for (MediaStream stream : localStreams) {
Sami Kalliomäkiee05e902018-09-28 14:38:21 +02001224 nativeRemoveLocalStream(stream.getNativeMediaStream());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 stream.dispose();
1226 }
1227 localStreams.clear();
deadbeef4139c0f2015-10-06 12:29:25 -07001228 for (RtpSender sender : senders) {
1229 sender.dispose();
1230 }
1231 senders.clear();
1232 for (RtpReceiver receiver : receivers) {
1233 receiver.dispose();
1234 }
Seth Hampsonc384e142018-03-06 15:47:10 -08001235 for (RtpTransceiver transceiver : transceivers) {
1236 transceiver.dispose();
1237 }
1238 transceivers.clear();
deadbeef4139c0f2015-10-06 12:29:25 -07001239 receivers.clear();
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001240 nativeFreeOwnedPeerConnection(nativePeerConnection);
1241 }
1242
1243 /** Returns a pointer to the native webrtc::PeerConnectionInterface. */
1244 public long getNativePeerConnection() {
1245 return nativeGetNativePeerConnection();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246 }
1247
Magnus Jedvert9060eb12017-12-12 12:52:54 +01001248 @CalledByNative
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001249 long getNativeOwnedPeerConnection() {
Magnus Jedvert9060eb12017-12-12 12:52:54 +01001250 return nativePeerConnection;
1251 }
1252
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001253 public static long createNativePeerConnectionObserver(Observer observer) {
1254 return nativeCreatePeerConnectionObserver(observer);
1255 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001257 private native long nativeGetNativePeerConnection();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001258 private native SessionDescription nativeGetLocalDescription();
1259 private native SessionDescription nativeGetRemoteDescription();
Michael Iedema02137862018-10-09 15:30:01 +02001260 private native RtcCertificatePem nativeGetCertificate();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001261 private native DataChannel nativeCreateDataChannel(String label, DataChannel.Init init);
1262 private native void nativeCreateOffer(SdpObserver observer, MediaConstraints constraints);
1263 private native void nativeCreateAnswer(SdpObserver observer, MediaConstraints constraints);
1264 private native void nativeSetLocalDescription(SdpObserver observer, SessionDescription sdp);
1265 private native void nativeSetRemoteDescription(SdpObserver observer, SessionDescription sdp);
1266 private native void nativeSetAudioPlayout(boolean playout);
1267 private native void nativeSetAudioRecording(boolean recording);
1268 private native boolean nativeSetBitrate(Integer min, Integer current, Integer max);
1269 private native SignalingState nativeSignalingState();
1270 private native IceConnectionState nativeIceConnectionState();
Jonas Olssonf01d8c82018-11-08 15:19:04 +01001271 private native PeerConnectionState nativeConnectionState();
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001272 private native IceGatheringState nativeIceGatheringState();
1273 private native void nativeClose();
1274 private static native long nativeCreatePeerConnectionObserver(Observer observer);
Sami Kalliomäkice5c19a2018-01-15 09:28:34 +01001275 private static native void nativeFreeOwnedPeerConnection(long ownedPeerConnection);
1276 private native boolean nativeSetConfiguration(RTCConfiguration config);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001277 private native boolean nativeAddIceCandidate(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 String sdpMid, int sdpMLineIndex, String iceCandidateSdp);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001279 private native boolean nativeRemoveIceCandidates(final IceCandidate[] candidates);
1280 private native boolean nativeAddLocalStream(long stream);
1281 private native void nativeRemoveLocalStream(long stream);
1282 private native boolean nativeOldGetStats(StatsObserver observer, long nativeTrack);
1283 private native void nativeNewGetStats(RTCStatsCollectorCallback callback);
1284 private native RtpSender nativeCreateSender(String kind, String stream_id);
1285 private native List<RtpSender> nativeGetSenders();
1286 private native List<RtpReceiver> nativeGetReceivers();
Seth Hampsonc384e142018-03-06 15:47:10 -08001287 private native List<RtpTransceiver> nativeGetTransceivers();
1288 private native RtpSender nativeAddTrack(long track, List<String> streamIds);
1289 private native boolean nativeRemoveTrack(long sender);
1290 private native RtpTransceiver nativeAddTransceiverWithTrack(
1291 long track, RtpTransceiver.RtpTransceiverInit init);
1292 private native RtpTransceiver nativeAddTransceiverOfType(
1293 MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +01001294 private native boolean nativeStartRtcEventLog(int file_descriptor, int max_size_bytes);
1295 private native void nativeStopRtcEventLog();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296}