xref: /aosp_15_r20/external/webrtc/api/peer_connection_interface.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2012 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker // This file contains the PeerConnection interface as defined in
12*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-pc/#peer-to-peer-connections
13*d9f75844SAndroid Build Coastguard Worker //
14*d9f75844SAndroid Build Coastguard Worker // The PeerConnectionFactory class provides factory methods to create
15*d9f75844SAndroid Build Coastguard Worker // PeerConnection, MediaStream and MediaStreamTrack objects.
16*d9f75844SAndroid Build Coastguard Worker //
17*d9f75844SAndroid Build Coastguard Worker // The following steps are needed to setup a typical call using WebRTC:
18*d9f75844SAndroid Build Coastguard Worker //
19*d9f75844SAndroid Build Coastguard Worker // 1. Create a PeerConnectionFactoryInterface. Check constructors for more
20*d9f75844SAndroid Build Coastguard Worker // information about input parameters.
21*d9f75844SAndroid Build Coastguard Worker //
22*d9f75844SAndroid Build Coastguard Worker // 2. Create a PeerConnection object. Provide a configuration struct which
23*d9f75844SAndroid Build Coastguard Worker // points to STUN and/or TURN servers used to generate ICE candidates, and
24*d9f75844SAndroid Build Coastguard Worker // provide an object that implements the PeerConnectionObserver interface,
25*d9f75844SAndroid Build Coastguard Worker // which is used to receive callbacks from the PeerConnection.
26*d9f75844SAndroid Build Coastguard Worker //
27*d9f75844SAndroid Build Coastguard Worker // 3. Create local MediaStreamTracks using the PeerConnectionFactory and add
28*d9f75844SAndroid Build Coastguard Worker // them to PeerConnection by calling AddTrack (or legacy method, AddStream).
29*d9f75844SAndroid Build Coastguard Worker //
30*d9f75844SAndroid Build Coastguard Worker // 4. Create an offer, call SetLocalDescription with it, serialize it, and send
31*d9f75844SAndroid Build Coastguard Worker // it to the remote peer
32*d9f75844SAndroid Build Coastguard Worker //
33*d9f75844SAndroid Build Coastguard Worker // 5. Once an ICE candidate has been gathered, the PeerConnection will call the
34*d9f75844SAndroid Build Coastguard Worker // observer function OnIceCandidate. The candidates must also be serialized and
35*d9f75844SAndroid Build Coastguard Worker // sent to the remote peer.
36*d9f75844SAndroid Build Coastguard Worker //
37*d9f75844SAndroid Build Coastguard Worker // 6. Once an answer is received from the remote peer, call
38*d9f75844SAndroid Build Coastguard Worker // SetRemoteDescription with the remote answer.
39*d9f75844SAndroid Build Coastguard Worker //
40*d9f75844SAndroid Build Coastguard Worker // 7. Once a remote candidate is received from the remote peer, provide it to
41*d9f75844SAndroid Build Coastguard Worker // the PeerConnection by calling AddIceCandidate.
42*d9f75844SAndroid Build Coastguard Worker //
43*d9f75844SAndroid Build Coastguard Worker // The receiver of a call (assuming the application is "call"-based) can decide
44*d9f75844SAndroid Build Coastguard Worker // to accept or reject the call; this decision will be taken by the application,
45*d9f75844SAndroid Build Coastguard Worker // not the PeerConnection.
46*d9f75844SAndroid Build Coastguard Worker //
47*d9f75844SAndroid Build Coastguard Worker // If the application decides to accept the call, it should:
48*d9f75844SAndroid Build Coastguard Worker //
49*d9f75844SAndroid Build Coastguard Worker // 1. Create PeerConnectionFactoryInterface if it doesn't exist.
50*d9f75844SAndroid Build Coastguard Worker //
51*d9f75844SAndroid Build Coastguard Worker // 2. Create a new PeerConnection.
52*d9f75844SAndroid Build Coastguard Worker //
53*d9f75844SAndroid Build Coastguard Worker // 3. Provide the remote offer to the new PeerConnection object by calling
54*d9f75844SAndroid Build Coastguard Worker // SetRemoteDescription.
55*d9f75844SAndroid Build Coastguard Worker //
56*d9f75844SAndroid Build Coastguard Worker // 4. Generate an answer to the remote offer by calling CreateAnswer and send it
57*d9f75844SAndroid Build Coastguard Worker // back to the remote peer.
58*d9f75844SAndroid Build Coastguard Worker //
59*d9f75844SAndroid Build Coastguard Worker // 5. Provide the local answer to the new PeerConnection by calling
60*d9f75844SAndroid Build Coastguard Worker // SetLocalDescription with the answer.
61*d9f75844SAndroid Build Coastguard Worker //
62*d9f75844SAndroid Build Coastguard Worker // 6. Provide the remote ICE candidates by calling AddIceCandidate.
63*d9f75844SAndroid Build Coastguard Worker //
64*d9f75844SAndroid Build Coastguard Worker // 7. Once a candidate has been gathered, the PeerConnection will call the
65*d9f75844SAndroid Build Coastguard Worker // observer function OnIceCandidate. Send these candidates to the remote peer.
66*d9f75844SAndroid Build Coastguard Worker 
67*d9f75844SAndroid Build Coastguard Worker #ifndef API_PEER_CONNECTION_INTERFACE_H_
68*d9f75844SAndroid Build Coastguard Worker #define API_PEER_CONNECTION_INTERFACE_H_
69*d9f75844SAndroid Build Coastguard Worker 
70*d9f75844SAndroid Build Coastguard Worker #include <stdint.h>
71*d9f75844SAndroid Build Coastguard Worker #include <stdio.h>
72*d9f75844SAndroid Build Coastguard Worker 
73*d9f75844SAndroid Build Coastguard Worker #include <functional>
74*d9f75844SAndroid Build Coastguard Worker #include <memory>
75*d9f75844SAndroid Build Coastguard Worker #include <string>
76*d9f75844SAndroid Build Coastguard Worker #include <vector>
77*d9f75844SAndroid Build Coastguard Worker 
78*d9f75844SAndroid Build Coastguard Worker #include "absl/base/attributes.h"
79*d9f75844SAndroid Build Coastguard Worker #include "absl/strings/string_view.h"
80*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h"
81*d9f75844SAndroid Build Coastguard Worker #include "api/adaptation/resource.h"
82*d9f75844SAndroid Build Coastguard Worker #include "api/async_dns_resolver.h"
83*d9f75844SAndroid Build Coastguard Worker #include "api/async_resolver_factory.h"
84*d9f75844SAndroid Build Coastguard Worker #include "api/audio/audio_mixer.h"
85*d9f75844SAndroid Build Coastguard Worker #include "api/audio_codecs/audio_decoder_factory.h"
86*d9f75844SAndroid Build Coastguard Worker #include "api/audio_codecs/audio_encoder_factory.h"
87*d9f75844SAndroid Build Coastguard Worker #include "api/audio_options.h"
88*d9f75844SAndroid Build Coastguard Worker #include "api/call/call_factory_interface.h"
89*d9f75844SAndroid Build Coastguard Worker #include "api/candidate.h"
90*d9f75844SAndroid Build Coastguard Worker #include "api/crypto/crypto_options.h"
91*d9f75844SAndroid Build Coastguard Worker #include "api/data_channel_interface.h"
92*d9f75844SAndroid Build Coastguard Worker #include "api/dtls_transport_interface.h"
93*d9f75844SAndroid Build Coastguard Worker #include "api/fec_controller.h"
94*d9f75844SAndroid Build Coastguard Worker #include "api/field_trials_view.h"
95*d9f75844SAndroid Build Coastguard Worker #include "api/ice_transport_interface.h"
96*d9f75844SAndroid Build Coastguard Worker #include "api/jsep.h"
97*d9f75844SAndroid Build Coastguard Worker #include "api/legacy_stats_types.h"
98*d9f75844SAndroid Build Coastguard Worker #include "api/media_stream_interface.h"
99*d9f75844SAndroid Build Coastguard Worker #include "api/media_types.h"
100*d9f75844SAndroid Build Coastguard Worker #include "api/metronome/metronome.h"
101*d9f75844SAndroid Build Coastguard Worker #include "api/neteq/neteq_factory.h"
102*d9f75844SAndroid Build Coastguard Worker #include "api/network_state_predictor.h"
103*d9f75844SAndroid Build Coastguard Worker #include "api/packet_socket_factory.h"
104*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_error.h"
105*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
106*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_event_log_output.h"
107*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_parameters.h"
108*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_receiver_interface.h"
109*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_sender_interface.h"
110*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_transceiver_interface.h"
111*d9f75844SAndroid Build Coastguard Worker #include "api/scoped_refptr.h"
112*d9f75844SAndroid Build Coastguard Worker #include "api/sctp_transport_interface.h"
113*d9f75844SAndroid Build Coastguard Worker #include "api/set_local_description_observer_interface.h"
114*d9f75844SAndroid Build Coastguard Worker #include "api/set_remote_description_observer_interface.h"
115*d9f75844SAndroid Build Coastguard Worker #include "api/stats/rtc_stats_collector_callback.h"
116*d9f75844SAndroid Build Coastguard Worker #include "api/task_queue/task_queue_factory.h"
117*d9f75844SAndroid Build Coastguard Worker #include "api/transport/bitrate_settings.h"
118*d9f75844SAndroid Build Coastguard Worker #include "api/transport/enums.h"
119*d9f75844SAndroid Build Coastguard Worker #include "api/transport/network_control.h"
120*d9f75844SAndroid Build Coastguard Worker #include "api/transport/sctp_transport_factory_interface.h"
121*d9f75844SAndroid Build Coastguard Worker #include "api/turn_customizer.h"
122*d9f75844SAndroid Build Coastguard Worker #include "api/video/video_bitrate_allocator_factory.h"
123*d9f75844SAndroid Build Coastguard Worker #include "call/rtp_transport_controller_send_factory_interface.h"
124*d9f75844SAndroid Build Coastguard Worker #include "media/base/media_config.h"
125*d9f75844SAndroid Build Coastguard Worker #include "media/base/media_engine.h"
126*d9f75844SAndroid Build Coastguard Worker // TODO(bugs.webrtc.org/7447): We plan to provide a way to let applications
127*d9f75844SAndroid Build Coastguard Worker // inject a PacketSocketFactory and/or NetworkManager, and not expose
128*d9f75844SAndroid Build Coastguard Worker // PortAllocator in the PeerConnection api.
129*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/port_allocator.h"
130*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/network.h"
131*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/network_constants.h"
132*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/network_monitor_factory.h"
133*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/ref_count.h"
134*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/rtc_certificate.h"
135*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/rtc_certificate_generator.h"
136*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/socket_address.h"
137*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/ssl_certificate.h"
138*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/ssl_stream_adapter.h"
139*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/system/rtc_export.h"
140*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread.h"
141*d9f75844SAndroid Build Coastguard Worker 
142*d9f75844SAndroid Build Coastguard Worker namespace rtc {
143*d9f75844SAndroid Build Coastguard Worker class Thread;
144*d9f75844SAndroid Build Coastguard Worker }  // namespace rtc
145*d9f75844SAndroid Build Coastguard Worker 
146*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
147*d9f75844SAndroid Build Coastguard Worker 
148*d9f75844SAndroid Build Coastguard Worker // MediaStream container interface.
149*d9f75844SAndroid Build Coastguard Worker class StreamCollectionInterface : public rtc::RefCountInterface {
150*d9f75844SAndroid Build Coastguard Worker  public:
151*d9f75844SAndroid Build Coastguard Worker   // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
152*d9f75844SAndroid Build Coastguard Worker   virtual size_t count() = 0;
153*d9f75844SAndroid Build Coastguard Worker   virtual MediaStreamInterface* at(size_t index) = 0;
154*d9f75844SAndroid Build Coastguard Worker   virtual MediaStreamInterface* find(const std::string& label) = 0;
155*d9f75844SAndroid Build Coastguard Worker   virtual MediaStreamTrackInterface* FindAudioTrack(const std::string& id) = 0;
156*d9f75844SAndroid Build Coastguard Worker   virtual MediaStreamTrackInterface* FindVideoTrack(const std::string& id) = 0;
157*d9f75844SAndroid Build Coastguard Worker 
158*d9f75844SAndroid Build Coastguard Worker  protected:
159*d9f75844SAndroid Build Coastguard Worker   // Dtor protected as objects shouldn't be deleted via this interface.
160*d9f75844SAndroid Build Coastguard Worker   ~StreamCollectionInterface() override = default;
161*d9f75844SAndroid Build Coastguard Worker };
162*d9f75844SAndroid Build Coastguard Worker 
163*d9f75844SAndroid Build Coastguard Worker class StatsObserver : public rtc::RefCountInterface {
164*d9f75844SAndroid Build Coastguard Worker  public:
165*d9f75844SAndroid Build Coastguard Worker   virtual void OnComplete(const StatsReports& reports) = 0;
166*d9f75844SAndroid Build Coastguard Worker 
167*d9f75844SAndroid Build Coastguard Worker  protected:
168*d9f75844SAndroid Build Coastguard Worker   ~StatsObserver() override = default;
169*d9f75844SAndroid Build Coastguard Worker };
170*d9f75844SAndroid Build Coastguard Worker 
171*d9f75844SAndroid Build Coastguard Worker enum class SdpSemantics {
172*d9f75844SAndroid Build Coastguard Worker   // TODO(https://crbug.com/webrtc/13528): Remove support for kPlanB.
173*d9f75844SAndroid Build Coastguard Worker   kPlanB_DEPRECATED,
174*d9f75844SAndroid Build Coastguard Worker   kPlanB [[deprecated]] = kPlanB_DEPRECATED,
175*d9f75844SAndroid Build Coastguard Worker   kUnifiedPlan,
176*d9f75844SAndroid Build Coastguard Worker };
177*d9f75844SAndroid Build Coastguard Worker 
178*d9f75844SAndroid Build Coastguard Worker class RTC_EXPORT PeerConnectionInterface : public rtc::RefCountInterface {
179*d9f75844SAndroid Build Coastguard Worker  public:
180*d9f75844SAndroid Build Coastguard Worker   // See https://w3c.github.io/webrtc-pc/#dom-rtcsignalingstate
181*d9f75844SAndroid Build Coastguard Worker   enum SignalingState {
182*d9f75844SAndroid Build Coastguard Worker     kStable,
183*d9f75844SAndroid Build Coastguard Worker     kHaveLocalOffer,
184*d9f75844SAndroid Build Coastguard Worker     kHaveLocalPrAnswer,
185*d9f75844SAndroid Build Coastguard Worker     kHaveRemoteOffer,
186*d9f75844SAndroid Build Coastguard Worker     kHaveRemotePrAnswer,
187*d9f75844SAndroid Build Coastguard Worker     kClosed,
188*d9f75844SAndroid Build Coastguard Worker   };
189*d9f75844SAndroid Build Coastguard Worker   static constexpr absl::string_view AsString(SignalingState);
190*d9f75844SAndroid Build Coastguard Worker 
191*d9f75844SAndroid Build Coastguard Worker   // See https://w3c.github.io/webrtc-pc/#dom-rtcicegatheringstate
192*d9f75844SAndroid Build Coastguard Worker   enum IceGatheringState {
193*d9f75844SAndroid Build Coastguard Worker     kIceGatheringNew,
194*d9f75844SAndroid Build Coastguard Worker     kIceGatheringGathering,
195*d9f75844SAndroid Build Coastguard Worker     kIceGatheringComplete
196*d9f75844SAndroid Build Coastguard Worker   };
197*d9f75844SAndroid Build Coastguard Worker   static constexpr absl::string_view AsString(IceGatheringState state);
198*d9f75844SAndroid Build Coastguard Worker 
199*d9f75844SAndroid Build Coastguard Worker   // See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnectionstate
200*d9f75844SAndroid Build Coastguard Worker   enum class PeerConnectionState {
201*d9f75844SAndroid Build Coastguard Worker     kNew,
202*d9f75844SAndroid Build Coastguard Worker     kConnecting,
203*d9f75844SAndroid Build Coastguard Worker     kConnected,
204*d9f75844SAndroid Build Coastguard Worker     kDisconnected,
205*d9f75844SAndroid Build Coastguard Worker     kFailed,
206*d9f75844SAndroid Build Coastguard Worker     kClosed,
207*d9f75844SAndroid Build Coastguard Worker   };
208*d9f75844SAndroid Build Coastguard Worker   static constexpr absl::string_view AsString(PeerConnectionState state);
209*d9f75844SAndroid Build Coastguard Worker 
210*d9f75844SAndroid Build Coastguard Worker   // See https://w3c.github.io/webrtc-pc/#dom-rtciceconnectionstate
211*d9f75844SAndroid Build Coastguard Worker   enum IceConnectionState {
212*d9f75844SAndroid Build Coastguard Worker     kIceConnectionNew,
213*d9f75844SAndroid Build Coastguard Worker     kIceConnectionChecking,
214*d9f75844SAndroid Build Coastguard Worker     kIceConnectionConnected,
215*d9f75844SAndroid Build Coastguard Worker     kIceConnectionCompleted,
216*d9f75844SAndroid Build Coastguard Worker     kIceConnectionFailed,
217*d9f75844SAndroid Build Coastguard Worker     kIceConnectionDisconnected,
218*d9f75844SAndroid Build Coastguard Worker     kIceConnectionClosed,
219*d9f75844SAndroid Build Coastguard Worker     kIceConnectionMax,
220*d9f75844SAndroid Build Coastguard Worker   };
221*d9f75844SAndroid Build Coastguard Worker   static constexpr absl::string_view AsString(IceConnectionState state);
222*d9f75844SAndroid Build Coastguard Worker 
223*d9f75844SAndroid Build Coastguard Worker   // TLS certificate policy.
224*d9f75844SAndroid Build Coastguard Worker   enum TlsCertPolicy {
225*d9f75844SAndroid Build Coastguard Worker     // For TLS based protocols, ensure the connection is secure by not
226*d9f75844SAndroid Build Coastguard Worker     // circumventing certificate validation.
227*d9f75844SAndroid Build Coastguard Worker     kTlsCertPolicySecure,
228*d9f75844SAndroid Build Coastguard Worker     // For TLS based protocols, disregard security completely by skipping
229*d9f75844SAndroid Build Coastguard Worker     // certificate validation. This is insecure and should never be used unless
230*d9f75844SAndroid Build Coastguard Worker     // security is irrelevant in that particular context.
231*d9f75844SAndroid Build Coastguard Worker     kTlsCertPolicyInsecureNoCheck,
232*d9f75844SAndroid Build Coastguard Worker   };
233*d9f75844SAndroid Build Coastguard Worker 
234*d9f75844SAndroid Build Coastguard Worker   struct RTC_EXPORT IceServer {
235*d9f75844SAndroid Build Coastguard Worker     IceServer();
236*d9f75844SAndroid Build Coastguard Worker     IceServer(const IceServer&);
237*d9f75844SAndroid Build Coastguard Worker     ~IceServer();
238*d9f75844SAndroid Build Coastguard Worker 
239*d9f75844SAndroid Build Coastguard Worker     // TODO(jbauch): Remove uri when all code using it has switched to urls.
240*d9f75844SAndroid Build Coastguard Worker     // List of URIs associated with this server. Valid formats are described
241*d9f75844SAndroid Build Coastguard Worker     // in RFC7064 and RFC7065, and more may be added in the future. The "host"
242*d9f75844SAndroid Build Coastguard Worker     // part of the URI may contain either an IP address or a hostname.
243*d9f75844SAndroid Build Coastguard Worker     std::string uri;
244*d9f75844SAndroid Build Coastguard Worker     std::vector<std::string> urls;
245*d9f75844SAndroid Build Coastguard Worker     std::string username;
246*d9f75844SAndroid Build Coastguard Worker     std::string password;
247*d9f75844SAndroid Build Coastguard Worker     TlsCertPolicy tls_cert_policy = kTlsCertPolicySecure;
248*d9f75844SAndroid Build Coastguard Worker     // If the URIs in `urls` only contain IP addresses, this field can be used
249*d9f75844SAndroid Build Coastguard Worker     // to indicate the hostname, which may be necessary for TLS (using the SNI
250*d9f75844SAndroid Build Coastguard Worker     // extension). If `urls` itself contains the hostname, this isn't
251*d9f75844SAndroid Build Coastguard Worker     // necessary.
252*d9f75844SAndroid Build Coastguard Worker     std::string hostname;
253*d9f75844SAndroid Build Coastguard Worker     // List of protocols to be used in the TLS ALPN extension.
254*d9f75844SAndroid Build Coastguard Worker     std::vector<std::string> tls_alpn_protocols;
255*d9f75844SAndroid Build Coastguard Worker     // List of elliptic curves to be used in the TLS elliptic curves extension.
256*d9f75844SAndroid Build Coastguard Worker     std::vector<std::string> tls_elliptic_curves;
257*d9f75844SAndroid Build Coastguard Worker 
258*d9f75844SAndroid Build Coastguard Worker     bool operator==(const IceServer& o) const {
259*d9f75844SAndroid Build Coastguard Worker       return uri == o.uri && urls == o.urls && username == o.username &&
260*d9f75844SAndroid Build Coastguard Worker              password == o.password && tls_cert_policy == o.tls_cert_policy &&
261*d9f75844SAndroid Build Coastguard Worker              hostname == o.hostname &&
262*d9f75844SAndroid Build Coastguard Worker              tls_alpn_protocols == o.tls_alpn_protocols &&
263*d9f75844SAndroid Build Coastguard Worker              tls_elliptic_curves == o.tls_elliptic_curves;
264*d9f75844SAndroid Build Coastguard Worker     }
265*d9f75844SAndroid Build Coastguard Worker     bool operator!=(const IceServer& o) const { return !(*this == o); }
266*d9f75844SAndroid Build Coastguard Worker   };
267*d9f75844SAndroid Build Coastguard Worker   typedef std::vector<IceServer> IceServers;
268*d9f75844SAndroid Build Coastguard Worker 
269*d9f75844SAndroid Build Coastguard Worker   enum IceTransportsType {
270*d9f75844SAndroid Build Coastguard Worker     // TODO(pthatcher): Rename these kTransporTypeXXX, but update
271*d9f75844SAndroid Build Coastguard Worker     // Chromium at the same time.
272*d9f75844SAndroid Build Coastguard Worker     kNone,
273*d9f75844SAndroid Build Coastguard Worker     kRelay,
274*d9f75844SAndroid Build Coastguard Worker     kNoHost,
275*d9f75844SAndroid Build Coastguard Worker     kAll
276*d9f75844SAndroid Build Coastguard Worker   };
277*d9f75844SAndroid Build Coastguard Worker 
278*d9f75844SAndroid Build Coastguard Worker   // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24#section-4.1.1
279*d9f75844SAndroid Build Coastguard Worker   enum BundlePolicy {
280*d9f75844SAndroid Build Coastguard Worker     kBundlePolicyBalanced,
281*d9f75844SAndroid Build Coastguard Worker     kBundlePolicyMaxBundle,
282*d9f75844SAndroid Build Coastguard Worker     kBundlePolicyMaxCompat
283*d9f75844SAndroid Build Coastguard Worker   };
284*d9f75844SAndroid Build Coastguard Worker 
285*d9f75844SAndroid Build Coastguard Worker   // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24#section-4.1.1
286*d9f75844SAndroid Build Coastguard Worker   enum RtcpMuxPolicy {
287*d9f75844SAndroid Build Coastguard Worker     kRtcpMuxPolicyNegotiate,
288*d9f75844SAndroid Build Coastguard Worker     kRtcpMuxPolicyRequire,
289*d9f75844SAndroid Build Coastguard Worker   };
290*d9f75844SAndroid Build Coastguard Worker 
291*d9f75844SAndroid Build Coastguard Worker   enum TcpCandidatePolicy {
292*d9f75844SAndroid Build Coastguard Worker     kTcpCandidatePolicyEnabled,
293*d9f75844SAndroid Build Coastguard Worker     kTcpCandidatePolicyDisabled
294*d9f75844SAndroid Build Coastguard Worker   };
295*d9f75844SAndroid Build Coastguard Worker 
296*d9f75844SAndroid Build Coastguard Worker   enum CandidateNetworkPolicy {
297*d9f75844SAndroid Build Coastguard Worker     kCandidateNetworkPolicyAll,
298*d9f75844SAndroid Build Coastguard Worker     kCandidateNetworkPolicyLowCost
299*d9f75844SAndroid Build Coastguard Worker   };
300*d9f75844SAndroid Build Coastguard Worker 
301*d9f75844SAndroid Build Coastguard Worker   enum ContinualGatheringPolicy { GATHER_ONCE, GATHER_CONTINUALLY };
302*d9f75844SAndroid Build Coastguard Worker 
303*d9f75844SAndroid Build Coastguard Worker   struct PortAllocatorConfig {
304*d9f75844SAndroid Build Coastguard Worker     // For min_port and max_port, 0 means not specified.
305*d9f75844SAndroid Build Coastguard Worker     int min_port = 0;
306*d9f75844SAndroid Build Coastguard Worker     int max_port = 0;
307*d9f75844SAndroid Build Coastguard Worker     uint32_t flags = 0;  // Same as kDefaultPortAllocatorFlags.
308*d9f75844SAndroid Build Coastguard Worker   };
309*d9f75844SAndroid Build Coastguard Worker 
310*d9f75844SAndroid Build Coastguard Worker   enum class RTCConfigurationType {
311*d9f75844SAndroid Build Coastguard Worker     // A configuration that is safer to use, despite not having the best
312*d9f75844SAndroid Build Coastguard Worker     // performance. Currently this is the default configuration.
313*d9f75844SAndroid Build Coastguard Worker     kSafe,
314*d9f75844SAndroid Build Coastguard Worker     // An aggressive configuration that has better performance, although it
315*d9f75844SAndroid Build Coastguard Worker     // may be riskier and may need extra support in the application.
316*d9f75844SAndroid Build Coastguard Worker     kAggressive
317*d9f75844SAndroid Build Coastguard Worker   };
318*d9f75844SAndroid Build Coastguard Worker 
319*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): Change into class with private data and public getters.
320*d9f75844SAndroid Build Coastguard Worker   // TODO(nisse): In particular, accessing fields directly from an
321*d9f75844SAndroid Build Coastguard Worker   // application is brittle, since the organization mirrors the
322*d9f75844SAndroid Build Coastguard Worker   // organization of the implementation, which isn't stable. So we
323*d9f75844SAndroid Build Coastguard Worker   // need getters and setters at least for fields which applications
324*d9f75844SAndroid Build Coastguard Worker   // are interested in.
325*d9f75844SAndroid Build Coastguard Worker   struct RTC_EXPORT RTCConfiguration {
326*d9f75844SAndroid Build Coastguard Worker     // This struct is subject to reorganization, both for naming
327*d9f75844SAndroid Build Coastguard Worker     // consistency, and to group settings to match where they are used
328*d9f75844SAndroid Build Coastguard Worker     // in the implementation. To do that, we need getter and setter
329*d9f75844SAndroid Build Coastguard Worker     // methods for all settings which are of interest to applications,
330*d9f75844SAndroid Build Coastguard Worker     // Chrome in particular.
331*d9f75844SAndroid Build Coastguard Worker 
332*d9f75844SAndroid Build Coastguard Worker     RTCConfiguration();
333*d9f75844SAndroid Build Coastguard Worker     RTCConfiguration(const RTCConfiguration&);
334*d9f75844SAndroid Build Coastguard Worker     explicit RTCConfiguration(RTCConfigurationType type);
335*d9f75844SAndroid Build Coastguard Worker     ~RTCConfiguration();
336*d9f75844SAndroid Build Coastguard Worker 
337*d9f75844SAndroid Build Coastguard Worker     bool operator==(const RTCConfiguration& o) const;
338*d9f75844SAndroid Build Coastguard Worker     bool operator!=(const RTCConfiguration& o) const;
339*d9f75844SAndroid Build Coastguard Worker 
dscpRTCConfiguration340*d9f75844SAndroid Build Coastguard Worker     bool dscp() const { return media_config.enable_dscp; }
set_dscpRTCConfiguration341*d9f75844SAndroid Build Coastguard Worker     void set_dscp(bool enable) { media_config.enable_dscp = enable; }
342*d9f75844SAndroid Build Coastguard Worker 
cpu_adaptationRTCConfiguration343*d9f75844SAndroid Build Coastguard Worker     bool cpu_adaptation() const {
344*d9f75844SAndroid Build Coastguard Worker       return media_config.video.enable_cpu_adaptation;
345*d9f75844SAndroid Build Coastguard Worker     }
set_cpu_adaptationRTCConfiguration346*d9f75844SAndroid Build Coastguard Worker     void set_cpu_adaptation(bool enable) {
347*d9f75844SAndroid Build Coastguard Worker       media_config.video.enable_cpu_adaptation = enable;
348*d9f75844SAndroid Build Coastguard Worker     }
349*d9f75844SAndroid Build Coastguard Worker 
suspend_below_min_bitrateRTCConfiguration350*d9f75844SAndroid Build Coastguard Worker     bool suspend_below_min_bitrate() const {
351*d9f75844SAndroid Build Coastguard Worker       return media_config.video.suspend_below_min_bitrate;
352*d9f75844SAndroid Build Coastguard Worker     }
set_suspend_below_min_bitrateRTCConfiguration353*d9f75844SAndroid Build Coastguard Worker     void set_suspend_below_min_bitrate(bool enable) {
354*d9f75844SAndroid Build Coastguard Worker       media_config.video.suspend_below_min_bitrate = enable;
355*d9f75844SAndroid Build Coastguard Worker     }
356*d9f75844SAndroid Build Coastguard Worker 
prerenderer_smoothingRTCConfiguration357*d9f75844SAndroid Build Coastguard Worker     bool prerenderer_smoothing() const {
358*d9f75844SAndroid Build Coastguard Worker       return media_config.video.enable_prerenderer_smoothing;
359*d9f75844SAndroid Build Coastguard Worker     }
set_prerenderer_smoothingRTCConfiguration360*d9f75844SAndroid Build Coastguard Worker     void set_prerenderer_smoothing(bool enable) {
361*d9f75844SAndroid Build Coastguard Worker       media_config.video.enable_prerenderer_smoothing = enable;
362*d9f75844SAndroid Build Coastguard Worker     }
363*d9f75844SAndroid Build Coastguard Worker 
experiment_cpu_load_estimatorRTCConfiguration364*d9f75844SAndroid Build Coastguard Worker     bool experiment_cpu_load_estimator() const {
365*d9f75844SAndroid Build Coastguard Worker       return media_config.video.experiment_cpu_load_estimator;
366*d9f75844SAndroid Build Coastguard Worker     }
set_experiment_cpu_load_estimatorRTCConfiguration367*d9f75844SAndroid Build Coastguard Worker     void set_experiment_cpu_load_estimator(bool enable) {
368*d9f75844SAndroid Build Coastguard Worker       media_config.video.experiment_cpu_load_estimator = enable;
369*d9f75844SAndroid Build Coastguard Worker     }
370*d9f75844SAndroid Build Coastguard Worker 
audio_rtcp_report_interval_msRTCConfiguration371*d9f75844SAndroid Build Coastguard Worker     int audio_rtcp_report_interval_ms() const {
372*d9f75844SAndroid Build Coastguard Worker       return media_config.audio.rtcp_report_interval_ms;
373*d9f75844SAndroid Build Coastguard Worker     }
set_audio_rtcp_report_interval_msRTCConfiguration374*d9f75844SAndroid Build Coastguard Worker     void set_audio_rtcp_report_interval_ms(int audio_rtcp_report_interval_ms) {
375*d9f75844SAndroid Build Coastguard Worker       media_config.audio.rtcp_report_interval_ms =
376*d9f75844SAndroid Build Coastguard Worker           audio_rtcp_report_interval_ms;
377*d9f75844SAndroid Build Coastguard Worker     }
378*d9f75844SAndroid Build Coastguard Worker 
video_rtcp_report_interval_msRTCConfiguration379*d9f75844SAndroid Build Coastguard Worker     int video_rtcp_report_interval_ms() const {
380*d9f75844SAndroid Build Coastguard Worker       return media_config.video.rtcp_report_interval_ms;
381*d9f75844SAndroid Build Coastguard Worker     }
set_video_rtcp_report_interval_msRTCConfiguration382*d9f75844SAndroid Build Coastguard Worker     void set_video_rtcp_report_interval_ms(int video_rtcp_report_interval_ms) {
383*d9f75844SAndroid Build Coastguard Worker       media_config.video.rtcp_report_interval_ms =
384*d9f75844SAndroid Build Coastguard Worker           video_rtcp_report_interval_ms;
385*d9f75844SAndroid Build Coastguard Worker     }
386*d9f75844SAndroid Build Coastguard Worker 
387*d9f75844SAndroid Build Coastguard Worker     // Settings for the port allcoator. Applied only if the port allocator is
388*d9f75844SAndroid Build Coastguard Worker     // created by PeerConnectionFactory, not if it is injected with
389*d9f75844SAndroid Build Coastguard Worker     // PeerConnectionDependencies
min_portRTCConfiguration390*d9f75844SAndroid Build Coastguard Worker     int min_port() const { return port_allocator_config.min_port; }
set_min_portRTCConfiguration391*d9f75844SAndroid Build Coastguard Worker     void set_min_port(int port) { port_allocator_config.min_port = port; }
max_portRTCConfiguration392*d9f75844SAndroid Build Coastguard Worker     int max_port() const { return port_allocator_config.max_port; }
set_max_portRTCConfiguration393*d9f75844SAndroid Build Coastguard Worker     void set_max_port(int port) { port_allocator_config.max_port = port; }
port_allocator_flagsRTCConfiguration394*d9f75844SAndroid Build Coastguard Worker     uint32_t port_allocator_flags() { return port_allocator_config.flags; }
set_port_allocator_flagsRTCConfiguration395*d9f75844SAndroid Build Coastguard Worker     void set_port_allocator_flags(uint32_t flags) {
396*d9f75844SAndroid Build Coastguard Worker       port_allocator_config.flags = flags;
397*d9f75844SAndroid Build Coastguard Worker     }
398*d9f75844SAndroid Build Coastguard Worker 
399*d9f75844SAndroid Build Coastguard Worker     static const int kUndefined = -1;
400*d9f75844SAndroid Build Coastguard Worker     // Default maximum number of packets in the audio jitter buffer.
401*d9f75844SAndroid Build Coastguard Worker     static const int kAudioJitterBufferMaxPackets = 200;
402*d9f75844SAndroid Build Coastguard Worker     // ICE connection receiving timeout for aggressive configuration.
403*d9f75844SAndroid Build Coastguard Worker     static const int kAggressiveIceConnectionReceivingTimeout = 1000;
404*d9f75844SAndroid Build Coastguard Worker 
405*d9f75844SAndroid Build Coastguard Worker     ////////////////////////////////////////////////////////////////////////
406*d9f75844SAndroid Build Coastguard Worker     // The below few fields mirror the standard RTCConfiguration dictionary:
407*d9f75844SAndroid Build Coastguard Worker     // https://w3c.github.io/webrtc-pc/#rtcconfiguration-dictionary
408*d9f75844SAndroid Build Coastguard Worker     ////////////////////////////////////////////////////////////////////////
409*d9f75844SAndroid Build Coastguard Worker 
410*d9f75844SAndroid Build Coastguard Worker     // TODO(pthatcher): Rename this ice_servers, but update Chromium
411*d9f75844SAndroid Build Coastguard Worker     // at the same time.
412*d9f75844SAndroid Build Coastguard Worker     IceServers servers;
413*d9f75844SAndroid Build Coastguard Worker     // TODO(pthatcher): Rename this ice_transport_type, but update
414*d9f75844SAndroid Build Coastguard Worker     // Chromium at the same time.
415*d9f75844SAndroid Build Coastguard Worker     IceTransportsType type = kAll;
416*d9f75844SAndroid Build Coastguard Worker     BundlePolicy bundle_policy = kBundlePolicyBalanced;
417*d9f75844SAndroid Build Coastguard Worker     RtcpMuxPolicy rtcp_mux_policy = kRtcpMuxPolicyRequire;
418*d9f75844SAndroid Build Coastguard Worker     std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
419*d9f75844SAndroid Build Coastguard Worker     int ice_candidate_pool_size = 0;
420*d9f75844SAndroid Build Coastguard Worker 
421*d9f75844SAndroid Build Coastguard Worker     //////////////////////////////////////////////////////////////////////////
422*d9f75844SAndroid Build Coastguard Worker     // The below fields correspond to constraints from the deprecated
423*d9f75844SAndroid Build Coastguard Worker     // constraints interface for constructing a PeerConnection.
424*d9f75844SAndroid Build Coastguard Worker     //
425*d9f75844SAndroid Build Coastguard Worker     // absl::optional fields can be "missing", in which case the implementation
426*d9f75844SAndroid Build Coastguard Worker     // default will be used.
427*d9f75844SAndroid Build Coastguard Worker     //////////////////////////////////////////////////////////////////////////
428*d9f75844SAndroid Build Coastguard Worker 
429*d9f75844SAndroid Build Coastguard Worker     // If set to true, don't gather IPv6 ICE candidates on Wi-Fi.
430*d9f75844SAndroid Build Coastguard Worker     // Only intended to be used on specific devices. Certain phones disable IPv6
431*d9f75844SAndroid Build Coastguard Worker     // when the screen is turned off and it would be better to just disable the
432*d9f75844SAndroid Build Coastguard Worker     // IPv6 ICE candidates on Wi-Fi in those cases.
433*d9f75844SAndroid Build Coastguard Worker     bool disable_ipv6_on_wifi = false;
434*d9f75844SAndroid Build Coastguard Worker 
435*d9f75844SAndroid Build Coastguard Worker     // By default, the PeerConnection will use a limited number of IPv6 network
436*d9f75844SAndroid Build Coastguard Worker     // interfaces, in order to avoid too many ICE candidate pairs being created
437*d9f75844SAndroid Build Coastguard Worker     // and delaying ICE completion.
438*d9f75844SAndroid Build Coastguard Worker     //
439*d9f75844SAndroid Build Coastguard Worker     // Can be set to INT_MAX to effectively disable the limit.
440*d9f75844SAndroid Build Coastguard Worker     int max_ipv6_networks = cricket::kDefaultMaxIPv6Networks;
441*d9f75844SAndroid Build Coastguard Worker 
442*d9f75844SAndroid Build Coastguard Worker     // Exclude link-local network interfaces
443*d9f75844SAndroid Build Coastguard Worker     // from consideration for gathering ICE candidates.
444*d9f75844SAndroid Build Coastguard Worker     bool disable_link_local_networks = false;
445*d9f75844SAndroid Build Coastguard Worker 
446*d9f75844SAndroid Build Coastguard Worker     // Minimum bitrate at which screencast video tracks will be encoded at.
447*d9f75844SAndroid Build Coastguard Worker     // This means adding padding bits up to this bitrate, which can help
448*d9f75844SAndroid Build Coastguard Worker     // when switching from a static scene to one with motion.
449*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> screencast_min_bitrate;
450*d9f75844SAndroid Build Coastguard Worker 
451*d9f75844SAndroid Build Coastguard Worker     // Use new combined audio/video bandwidth estimation?
452*d9f75844SAndroid Build Coastguard Worker     absl::optional<bool> combined_audio_video_bwe;
453*d9f75844SAndroid Build Coastguard Worker 
454*d9f75844SAndroid Build Coastguard Worker #if defined(WEBRTC_FUCHSIA)
455*d9f75844SAndroid Build Coastguard Worker     // TODO(bugs.webrtc.org/11066): Remove entirely once Fuchsia does not use.
456*d9f75844SAndroid Build Coastguard Worker     // TODO(bugs.webrtc.org/9891) - Move to crypto_options
457*d9f75844SAndroid Build Coastguard Worker     // Can be used to disable DTLS-SRTP. This should never be done, but can be
458*d9f75844SAndroid Build Coastguard Worker     // useful for testing purposes, for example in setting up a loopback call
459*d9f75844SAndroid Build Coastguard Worker     // with a single PeerConnection.
460*d9f75844SAndroid Build Coastguard Worker     absl::optional<bool> enable_dtls_srtp;
461*d9f75844SAndroid Build Coastguard Worker #endif
462*d9f75844SAndroid Build Coastguard Worker 
463*d9f75844SAndroid Build Coastguard Worker     /////////////////////////////////////////////////
464*d9f75844SAndroid Build Coastguard Worker     // The below fields are not part of the standard.
465*d9f75844SAndroid Build Coastguard Worker     /////////////////////////////////////////////////
466*d9f75844SAndroid Build Coastguard Worker 
467*d9f75844SAndroid Build Coastguard Worker     // Can be used to disable TCP candidate generation.
468*d9f75844SAndroid Build Coastguard Worker     TcpCandidatePolicy tcp_candidate_policy = kTcpCandidatePolicyEnabled;
469*d9f75844SAndroid Build Coastguard Worker 
470*d9f75844SAndroid Build Coastguard Worker     // Can be used to avoid gathering candidates for a "higher cost" network,
471*d9f75844SAndroid Build Coastguard Worker     // if a lower cost one exists. For example, if both Wi-Fi and cellular
472*d9f75844SAndroid Build Coastguard Worker     // interfaces are available, this could be used to avoid using the cellular
473*d9f75844SAndroid Build Coastguard Worker     // interface.
474*d9f75844SAndroid Build Coastguard Worker     CandidateNetworkPolicy candidate_network_policy =
475*d9f75844SAndroid Build Coastguard Worker         kCandidateNetworkPolicyAll;
476*d9f75844SAndroid Build Coastguard Worker 
477*d9f75844SAndroid Build Coastguard Worker     // The maximum number of packets that can be stored in the NetEq audio
478*d9f75844SAndroid Build Coastguard Worker     // jitter buffer. Can be reduced to lower tolerated audio latency.
479*d9f75844SAndroid Build Coastguard Worker     int audio_jitter_buffer_max_packets = kAudioJitterBufferMaxPackets;
480*d9f75844SAndroid Build Coastguard Worker 
481*d9f75844SAndroid Build Coastguard Worker     // Whether to use the NetEq "fast mode" which will accelerate audio quicker
482*d9f75844SAndroid Build Coastguard Worker     // if it falls behind.
483*d9f75844SAndroid Build Coastguard Worker     bool audio_jitter_buffer_fast_accelerate = false;
484*d9f75844SAndroid Build Coastguard Worker 
485*d9f75844SAndroid Build Coastguard Worker     // The minimum delay in milliseconds for the audio jitter buffer.
486*d9f75844SAndroid Build Coastguard Worker     int audio_jitter_buffer_min_delay_ms = 0;
487*d9f75844SAndroid Build Coastguard Worker 
488*d9f75844SAndroid Build Coastguard Worker     // Timeout in milliseconds before an ICE candidate pair is considered to be
489*d9f75844SAndroid Build Coastguard Worker     // "not receiving", after which a lower priority candidate pair may be
490*d9f75844SAndroid Build Coastguard Worker     // selected.
491*d9f75844SAndroid Build Coastguard Worker     int ice_connection_receiving_timeout = kUndefined;
492*d9f75844SAndroid Build Coastguard Worker 
493*d9f75844SAndroid Build Coastguard Worker     // Interval in milliseconds at which an ICE "backup" candidate pair will be
494*d9f75844SAndroid Build Coastguard Worker     // pinged. This is a candidate pair which is not actively in use, but may
495*d9f75844SAndroid Build Coastguard Worker     // be switched to if the active candidate pair becomes unusable.
496*d9f75844SAndroid Build Coastguard Worker     //
497*d9f75844SAndroid Build Coastguard Worker     // This is relevant mainly to Wi-Fi/cell handoff; the application may not
498*d9f75844SAndroid Build Coastguard Worker     // want this backup cellular candidate pair pinged frequently, since it
499*d9f75844SAndroid Build Coastguard Worker     // consumes data/battery.
500*d9f75844SAndroid Build Coastguard Worker     int ice_backup_candidate_pair_ping_interval = kUndefined;
501*d9f75844SAndroid Build Coastguard Worker 
502*d9f75844SAndroid Build Coastguard Worker     // Can be used to enable continual gathering, which means new candidates
503*d9f75844SAndroid Build Coastguard Worker     // will be gathered as network interfaces change. Note that if continual
504*d9f75844SAndroid Build Coastguard Worker     // gathering is used, the candidate removal API should also be used, to
505*d9f75844SAndroid Build Coastguard Worker     // avoid an ever-growing list of candidates.
506*d9f75844SAndroid Build Coastguard Worker     ContinualGatheringPolicy continual_gathering_policy = GATHER_ONCE;
507*d9f75844SAndroid Build Coastguard Worker 
508*d9f75844SAndroid Build Coastguard Worker     // If set to true, candidate pairs will be pinged in order of most likely
509*d9f75844SAndroid Build Coastguard Worker     // to work (which means using a TURN server, generally), rather than in
510*d9f75844SAndroid Build Coastguard Worker     // standard priority order.
511*d9f75844SAndroid Build Coastguard Worker     bool prioritize_most_likely_ice_candidate_pairs = false;
512*d9f75844SAndroid Build Coastguard Worker 
513*d9f75844SAndroid Build Coastguard Worker     // Implementation defined settings. A public member only for the benefit of
514*d9f75844SAndroid Build Coastguard Worker     // the implementation. Applications must not access it directly, and should
515*d9f75844SAndroid Build Coastguard Worker     // instead use provided accessor methods, e.g., set_cpu_adaptation.
516*d9f75844SAndroid Build Coastguard Worker     struct cricket::MediaConfig media_config;
517*d9f75844SAndroid Build Coastguard Worker 
518*d9f75844SAndroid Build Coastguard Worker     // If set to true, only one preferred TURN allocation will be used per
519*d9f75844SAndroid Build Coastguard Worker     // network interface. UDP is preferred over TCP and IPv6 over IPv4. This
520*d9f75844SAndroid Build Coastguard Worker     // can be used to cut down on the number of candidate pairings.
521*d9f75844SAndroid Build Coastguard Worker     // Deprecated. TODO(webrtc:11026) Remove this flag once the downstream
522*d9f75844SAndroid Build Coastguard Worker     // dependency is removed.
523*d9f75844SAndroid Build Coastguard Worker     bool prune_turn_ports = false;
524*d9f75844SAndroid Build Coastguard Worker 
525*d9f75844SAndroid Build Coastguard Worker     // The policy used to prune turn port.
526*d9f75844SAndroid Build Coastguard Worker     PortPrunePolicy turn_port_prune_policy = NO_PRUNE;
527*d9f75844SAndroid Build Coastguard Worker 
GetTurnPortPrunePolicyRTCConfiguration528*d9f75844SAndroid Build Coastguard Worker     PortPrunePolicy GetTurnPortPrunePolicy() const {
529*d9f75844SAndroid Build Coastguard Worker       return prune_turn_ports ? PRUNE_BASED_ON_PRIORITY
530*d9f75844SAndroid Build Coastguard Worker                               : turn_port_prune_policy;
531*d9f75844SAndroid Build Coastguard Worker     }
532*d9f75844SAndroid Build Coastguard Worker 
533*d9f75844SAndroid Build Coastguard Worker     // If set to true, this means the ICE transport should presume TURN-to-TURN
534*d9f75844SAndroid Build Coastguard Worker     // candidate pairs will succeed, even before a binding response is received.
535*d9f75844SAndroid Build Coastguard Worker     // This can be used to optimize the initial connection time, since the DTLS
536*d9f75844SAndroid Build Coastguard Worker     // handshake can begin immediately.
537*d9f75844SAndroid Build Coastguard Worker     bool presume_writable_when_fully_relayed = false;
538*d9f75844SAndroid Build Coastguard Worker 
539*d9f75844SAndroid Build Coastguard Worker     // If true, "renomination" will be added to the ice options in the transport
540*d9f75844SAndroid Build Coastguard Worker     // description.
541*d9f75844SAndroid Build Coastguard Worker     // See: https://tools.ietf.org/html/draft-thatcher-ice-renomination-00
542*d9f75844SAndroid Build Coastguard Worker     bool enable_ice_renomination = false;
543*d9f75844SAndroid Build Coastguard Worker 
544*d9f75844SAndroid Build Coastguard Worker     // If true, the ICE role is re-determined when the PeerConnection sets a
545*d9f75844SAndroid Build Coastguard Worker     // local transport description that indicates an ICE restart.
546*d9f75844SAndroid Build Coastguard Worker     //
547*d9f75844SAndroid Build Coastguard Worker     // This is standard RFC5245 ICE behavior, but causes unnecessary role
548*d9f75844SAndroid Build Coastguard Worker     // thrashing, so an application may wish to avoid it. This role
549*d9f75844SAndroid Build Coastguard Worker     // re-determining was removed in ICEbis (ICE v2).
550*d9f75844SAndroid Build Coastguard Worker     bool redetermine_role_on_ice_restart = true;
551*d9f75844SAndroid Build Coastguard Worker 
552*d9f75844SAndroid Build Coastguard Worker     // This flag is only effective when `continual_gathering_policy` is
553*d9f75844SAndroid Build Coastguard Worker     // GATHER_CONTINUALLY.
554*d9f75844SAndroid Build Coastguard Worker     //
555*d9f75844SAndroid Build Coastguard Worker     // If true, after the ICE transport type is changed such that new types of
556*d9f75844SAndroid Build Coastguard Worker     // ICE candidates are allowed by the new transport type, e.g. from
557*d9f75844SAndroid Build Coastguard Worker     // IceTransportsType::kRelay to IceTransportsType::kAll, candidates that
558*d9f75844SAndroid Build Coastguard Worker     // have been gathered by the ICE transport but not matching the previous
559*d9f75844SAndroid Build Coastguard Worker     // transport type and as a result not observed by PeerConnectionObserver,
560*d9f75844SAndroid Build Coastguard Worker     // will be surfaced to the observer.
561*d9f75844SAndroid Build Coastguard Worker     bool surface_ice_candidates_on_ice_transport_type_changed = false;
562*d9f75844SAndroid Build Coastguard Worker 
563*d9f75844SAndroid Build Coastguard Worker     // The following fields define intervals in milliseconds at which ICE
564*d9f75844SAndroid Build Coastguard Worker     // connectivity checks are sent.
565*d9f75844SAndroid Build Coastguard Worker     //
566*d9f75844SAndroid Build Coastguard Worker     // We consider ICE is "strongly connected" for an agent when there is at
567*d9f75844SAndroid Build Coastguard Worker     // least one candidate pair that currently succeeds in connectivity check
568*d9f75844SAndroid Build Coastguard Worker     // from its direction i.e. sending a STUN ping and receives a STUN ping
569*d9f75844SAndroid Build Coastguard Worker     // response, AND all candidate pairs have sent a minimum number of pings for
570*d9f75844SAndroid Build Coastguard Worker     // connectivity (this number is implementation-specific). Otherwise, ICE is
571*d9f75844SAndroid Build Coastguard Worker     // considered in "weak connectivity".
572*d9f75844SAndroid Build Coastguard Worker     //
573*d9f75844SAndroid Build Coastguard Worker     // Note that the above notion of strong and weak connectivity is not defined
574*d9f75844SAndroid Build Coastguard Worker     // in RFC 5245, and they apply to our current ICE implementation only.
575*d9f75844SAndroid Build Coastguard Worker     //
576*d9f75844SAndroid Build Coastguard Worker     // 1) ice_check_interval_strong_connectivity defines the interval applied to
577*d9f75844SAndroid Build Coastguard Worker     // ALL candidate pairs when ICE is strongly connected, and it overrides the
578*d9f75844SAndroid Build Coastguard Worker     // default value of this interval in the ICE implementation;
579*d9f75844SAndroid Build Coastguard Worker     // 2) ice_check_interval_weak_connectivity defines the counterpart for ALL
580*d9f75844SAndroid Build Coastguard Worker     // pairs when ICE is weakly connected, and it overrides the default value of
581*d9f75844SAndroid Build Coastguard Worker     // this interval in the ICE implementation;
582*d9f75844SAndroid Build Coastguard Worker     // 3) ice_check_min_interval defines the minimal interval (equivalently the
583*d9f75844SAndroid Build Coastguard Worker     // maximum rate) that overrides the above two intervals when either of them
584*d9f75844SAndroid Build Coastguard Worker     // is less.
585*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> ice_check_interval_strong_connectivity;
586*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> ice_check_interval_weak_connectivity;
587*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> ice_check_min_interval;
588*d9f75844SAndroid Build Coastguard Worker 
589*d9f75844SAndroid Build Coastguard Worker     // The min time period for which a candidate pair must wait for response to
590*d9f75844SAndroid Build Coastguard Worker     // connectivity checks before it becomes unwritable. This parameter
591*d9f75844SAndroid Build Coastguard Worker     // overrides the default value in the ICE implementation if set.
592*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> ice_unwritable_timeout;
593*d9f75844SAndroid Build Coastguard Worker 
594*d9f75844SAndroid Build Coastguard Worker     // The min number of connectivity checks that a candidate pair must sent
595*d9f75844SAndroid Build Coastguard Worker     // without receiving response before it becomes unwritable. This parameter
596*d9f75844SAndroid Build Coastguard Worker     // overrides the default value in the ICE implementation if set.
597*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> ice_unwritable_min_checks;
598*d9f75844SAndroid Build Coastguard Worker 
599*d9f75844SAndroid Build Coastguard Worker     // The min time period for which a candidate pair must wait for response to
600*d9f75844SAndroid Build Coastguard Worker     // connectivity checks it becomes inactive. This parameter overrides the
601*d9f75844SAndroid Build Coastguard Worker     // default value in the ICE implementation if set.
602*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> ice_inactive_timeout;
603*d9f75844SAndroid Build Coastguard Worker 
604*d9f75844SAndroid Build Coastguard Worker     // The interval in milliseconds at which STUN candidates will resend STUN
605*d9f75844SAndroid Build Coastguard Worker     // binding requests to keep NAT bindings open.
606*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> stun_candidate_keepalive_interval;
607*d9f75844SAndroid Build Coastguard Worker 
608*d9f75844SAndroid Build Coastguard Worker     // Optional TurnCustomizer.
609*d9f75844SAndroid Build Coastguard Worker     // With this class one can modify outgoing TURN messages.
610*d9f75844SAndroid Build Coastguard Worker     // The object passed in must remain valid until PeerConnection::Close() is
611*d9f75844SAndroid Build Coastguard Worker     // called.
612*d9f75844SAndroid Build Coastguard Worker     webrtc::TurnCustomizer* turn_customizer = nullptr;
613*d9f75844SAndroid Build Coastguard Worker 
614*d9f75844SAndroid Build Coastguard Worker     // Preferred network interface.
615*d9f75844SAndroid Build Coastguard Worker     // A candidate pair on a preferred network has a higher precedence in ICE
616*d9f75844SAndroid Build Coastguard Worker     // than one on an un-preferred network, regardless of priority or network
617*d9f75844SAndroid Build Coastguard Worker     // cost.
618*d9f75844SAndroid Build Coastguard Worker     absl::optional<rtc::AdapterType> network_preference;
619*d9f75844SAndroid Build Coastguard Worker 
620*d9f75844SAndroid Build Coastguard Worker     // Configure the SDP semantics used by this PeerConnection. By default, this
621*d9f75844SAndroid Build Coastguard Worker     // is Unified Plan which is compliant to the WebRTC 1.0 specification. It is
622*d9f75844SAndroid Build Coastguard Worker     // possible to overrwite this to the deprecated Plan B SDP format, but note
623*d9f75844SAndroid Build Coastguard Worker     // that kPlanB will be deleted at some future date, see
624*d9f75844SAndroid Build Coastguard Worker     // https://crbug.com/webrtc/13528.
625*d9f75844SAndroid Build Coastguard Worker     //
626*d9f75844SAndroid Build Coastguard Worker     // kUnifiedPlan will cause the PeerConnection to create offers and answers
627*d9f75844SAndroid Build Coastguard Worker     // with multiple m= sections where each m= section maps to one RtpSender and
628*d9f75844SAndroid Build Coastguard Worker     // one RtpReceiver (an RtpTransceiver), either both audio or both video.
629*d9f75844SAndroid Build Coastguard Worker     // This will also cause the PeerConnection to ignore all but the first
630*d9f75844SAndroid Build Coastguard Worker     // a=ssrc lines that form a Plan B streams (if the PeerConnection is given
631*d9f75844SAndroid Build Coastguard Worker     // Plan B SDP to process).
632*d9f75844SAndroid Build Coastguard Worker     //
633*d9f75844SAndroid Build Coastguard Worker     // kPlanB will cause the PeerConnection to create offers and answers with at
634*d9f75844SAndroid Build Coastguard Worker     // most one audio and one video m= section with multiple RtpSenders and
635*d9f75844SAndroid Build Coastguard Worker     // RtpReceivers specified as multiple a=ssrc lines within the section. This
636*d9f75844SAndroid Build Coastguard Worker     // will also cause PeerConnection to ignore all but the first m= section of
637*d9f75844SAndroid Build Coastguard Worker     // the same media type (if the PeerConnection is given Unified Plan SDP to
638*d9f75844SAndroid Build Coastguard Worker     // process).
639*d9f75844SAndroid Build Coastguard Worker     SdpSemantics sdp_semantics = SdpSemantics::kUnifiedPlan;
640*d9f75844SAndroid Build Coastguard Worker 
641*d9f75844SAndroid Build Coastguard Worker     // TODO(bugs.webrtc.org/9891) - Move to crypto_options or remove.
642*d9f75844SAndroid Build Coastguard Worker     // Actively reset the SRTP parameters whenever the DTLS transports
643*d9f75844SAndroid Build Coastguard Worker     // underneath are reset for every offer/answer negotiation.
644*d9f75844SAndroid Build Coastguard Worker     // This is only intended to be a workaround for crbug.com/835958
645*d9f75844SAndroid Build Coastguard Worker     // WARNING: This would cause RTP/RTCP packets decryption failure if not used
646*d9f75844SAndroid Build Coastguard Worker     // correctly. This flag will be deprecated soon. Do not rely on it.
647*d9f75844SAndroid Build Coastguard Worker     bool active_reset_srtp_params = false;
648*d9f75844SAndroid Build Coastguard Worker 
649*d9f75844SAndroid Build Coastguard Worker     // Defines advanced optional cryptographic settings related to SRTP and
650*d9f75844SAndroid Build Coastguard Worker     // frame encryption for native WebRTC. Setting this will overwrite any
651*d9f75844SAndroid Build Coastguard Worker     // settings set in PeerConnectionFactory (which is deprecated).
652*d9f75844SAndroid Build Coastguard Worker     absl::optional<CryptoOptions> crypto_options;
653*d9f75844SAndroid Build Coastguard Worker 
654*d9f75844SAndroid Build Coastguard Worker     // Configure if we should include the SDP attribute extmap-allow-mixed in
655*d9f75844SAndroid Build Coastguard Worker     // our offer on session level.
656*d9f75844SAndroid Build Coastguard Worker     bool offer_extmap_allow_mixed = true;
657*d9f75844SAndroid Build Coastguard Worker 
658*d9f75844SAndroid Build Coastguard Worker     // TURN logging identifier.
659*d9f75844SAndroid Build Coastguard Worker     // This identifier is added to a TURN allocation
660*d9f75844SAndroid Build Coastguard Worker     // and it intended to be used to be able to match client side
661*d9f75844SAndroid Build Coastguard Worker     // logs with TURN server logs. It will not be added if it's an empty string.
662*d9f75844SAndroid Build Coastguard Worker     std::string turn_logging_id;
663*d9f75844SAndroid Build Coastguard Worker 
664*d9f75844SAndroid Build Coastguard Worker     // Added to be able to control rollout of this feature.
665*d9f75844SAndroid Build Coastguard Worker     bool enable_implicit_rollback = false;
666*d9f75844SAndroid Build Coastguard Worker 
667*d9f75844SAndroid Build Coastguard Worker     // Whether network condition based codec switching is allowed.
668*d9f75844SAndroid Build Coastguard Worker     absl::optional<bool> allow_codec_switching;
669*d9f75844SAndroid Build Coastguard Worker 
670*d9f75844SAndroid Build Coastguard Worker     // The delay before doing a usage histogram report for long-lived
671*d9f75844SAndroid Build Coastguard Worker     // PeerConnections. Used for testing only.
672*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> report_usage_pattern_delay_ms;
673*d9f75844SAndroid Build Coastguard Worker 
674*d9f75844SAndroid Build Coastguard Worker     // The ping interval (ms) when the connection is stable and writable. This
675*d9f75844SAndroid Build Coastguard Worker     // parameter overrides the default value in the ICE implementation if set.
676*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> stable_writable_connection_ping_interval_ms;
677*d9f75844SAndroid Build Coastguard Worker 
678*d9f75844SAndroid Build Coastguard Worker     // Whether this PeerConnection will avoid VPNs (kAvoidVpn), prefer VPNs
679*d9f75844SAndroid Build Coastguard Worker     // (kPreferVpn), only work over VPN (kOnlyUseVpn) or only work over non-VPN
680*d9f75844SAndroid Build Coastguard Worker     // (kNeverUseVpn) interfaces. This controls which local interfaces the
681*d9f75844SAndroid Build Coastguard Worker     // PeerConnection will prefer to connect over. Since VPN detection is not
682*d9f75844SAndroid Build Coastguard Worker     // perfect, adherence to this preference cannot be guaranteed.
683*d9f75844SAndroid Build Coastguard Worker     VpnPreference vpn_preference = VpnPreference::kDefault;
684*d9f75844SAndroid Build Coastguard Worker 
685*d9f75844SAndroid Build Coastguard Worker     // List of address/length subnets that should be treated like
686*d9f75844SAndroid Build Coastguard Worker     // VPN (in case webrtc fails to auto detect them).
687*d9f75844SAndroid Build Coastguard Worker     std::vector<rtc::NetworkMask> vpn_list;
688*d9f75844SAndroid Build Coastguard Worker 
689*d9f75844SAndroid Build Coastguard Worker     PortAllocatorConfig port_allocator_config;
690*d9f75844SAndroid Build Coastguard Worker 
691*d9f75844SAndroid Build Coastguard Worker     // The burst interval of the pacer, see TaskQueuePacedSender constructor.
692*d9f75844SAndroid Build Coastguard Worker     absl::optional<TimeDelta> pacer_burst_interval;
693*d9f75844SAndroid Build Coastguard Worker 
694*d9f75844SAndroid Build Coastguard Worker     //
695*d9f75844SAndroid Build Coastguard Worker     // Don't forget to update operator== if adding something.
696*d9f75844SAndroid Build Coastguard Worker     //
697*d9f75844SAndroid Build Coastguard Worker   };
698*d9f75844SAndroid Build Coastguard Worker 
699*d9f75844SAndroid Build Coastguard Worker   // See: https://www.w3.org/TR/webrtc/#idl-def-rtcofferansweroptions
700*d9f75844SAndroid Build Coastguard Worker   struct RTCOfferAnswerOptions {
701*d9f75844SAndroid Build Coastguard Worker     static const int kUndefined = -1;
702*d9f75844SAndroid Build Coastguard Worker     static const int kMaxOfferToReceiveMedia = 1;
703*d9f75844SAndroid Build Coastguard Worker 
704*d9f75844SAndroid Build Coastguard Worker     // The default value for constraint offerToReceiveX:true.
705*d9f75844SAndroid Build Coastguard Worker     static const int kOfferToReceiveMediaTrue = 1;
706*d9f75844SAndroid Build Coastguard Worker 
707*d9f75844SAndroid Build Coastguard Worker     // These options are left as backwards compatibility for clients who need
708*d9f75844SAndroid Build Coastguard Worker     // "Plan B" semantics. Clients who have switched to "Unified Plan" semantics
709*d9f75844SAndroid Build Coastguard Worker     // should use the RtpTransceiver API (AddTransceiver) instead.
710*d9f75844SAndroid Build Coastguard Worker     //
711*d9f75844SAndroid Build Coastguard Worker     // offer_to_receive_X set to 1 will cause a media description to be
712*d9f75844SAndroid Build Coastguard Worker     // generated in the offer, even if no tracks of that type have been added.
713*d9f75844SAndroid Build Coastguard Worker     // Values greater than 1 are treated the same.
714*d9f75844SAndroid Build Coastguard Worker     //
715*d9f75844SAndroid Build Coastguard Worker     // If set to 0, the generated directional attribute will not include the
716*d9f75844SAndroid Build Coastguard Worker     // "recv" direction (meaning it will be "sendonly" or "inactive".
717*d9f75844SAndroid Build Coastguard Worker     int offer_to_receive_video = kUndefined;
718*d9f75844SAndroid Build Coastguard Worker     int offer_to_receive_audio = kUndefined;
719*d9f75844SAndroid Build Coastguard Worker 
720*d9f75844SAndroid Build Coastguard Worker     bool voice_activity_detection = true;
721*d9f75844SAndroid Build Coastguard Worker     bool ice_restart = false;
722*d9f75844SAndroid Build Coastguard Worker 
723*d9f75844SAndroid Build Coastguard Worker     // If true, will offer to BUNDLE audio/video/data together. Not to be
724*d9f75844SAndroid Build Coastguard Worker     // confused with RTCP mux (multiplexing RTP and RTCP together).
725*d9f75844SAndroid Build Coastguard Worker     bool use_rtp_mux = true;
726*d9f75844SAndroid Build Coastguard Worker 
727*d9f75844SAndroid Build Coastguard Worker     // If true, "a=packetization:<payload_type> raw" attribute will be offered
728*d9f75844SAndroid Build Coastguard Worker     // in the SDP for all video payload and accepted in the answer if offered.
729*d9f75844SAndroid Build Coastguard Worker     bool raw_packetization_for_video = false;
730*d9f75844SAndroid Build Coastguard Worker 
731*d9f75844SAndroid Build Coastguard Worker     // This will apply to all video tracks with a Plan B SDP offer/answer.
732*d9f75844SAndroid Build Coastguard Worker     int num_simulcast_layers = 1;
733*d9f75844SAndroid Build Coastguard Worker 
734*d9f75844SAndroid Build Coastguard Worker     // If true: Use SDP format from draft-ietf-mmusic-scdp-sdp-03
735*d9f75844SAndroid Build Coastguard Worker     // If false: Use SDP format from draft-ietf-mmusic-sdp-sdp-26 or later
736*d9f75844SAndroid Build Coastguard Worker     bool use_obsolete_sctp_sdp = false;
737*d9f75844SAndroid Build Coastguard Worker 
738*d9f75844SAndroid Build Coastguard Worker     RTCOfferAnswerOptions() = default;
739*d9f75844SAndroid Build Coastguard Worker 
RTCOfferAnswerOptionsRTCOfferAnswerOptions740*d9f75844SAndroid Build Coastguard Worker     RTCOfferAnswerOptions(int offer_to_receive_video,
741*d9f75844SAndroid Build Coastguard Worker                           int offer_to_receive_audio,
742*d9f75844SAndroid Build Coastguard Worker                           bool voice_activity_detection,
743*d9f75844SAndroid Build Coastguard Worker                           bool ice_restart,
744*d9f75844SAndroid Build Coastguard Worker                           bool use_rtp_mux)
745*d9f75844SAndroid Build Coastguard Worker         : offer_to_receive_video(offer_to_receive_video),
746*d9f75844SAndroid Build Coastguard Worker           offer_to_receive_audio(offer_to_receive_audio),
747*d9f75844SAndroid Build Coastguard Worker           voice_activity_detection(voice_activity_detection),
748*d9f75844SAndroid Build Coastguard Worker           ice_restart(ice_restart),
749*d9f75844SAndroid Build Coastguard Worker           use_rtp_mux(use_rtp_mux) {}
750*d9f75844SAndroid Build Coastguard Worker   };
751*d9f75844SAndroid Build Coastguard Worker 
752*d9f75844SAndroid Build Coastguard Worker   // Used by GetStats to decide which stats to include in the stats reports.
753*d9f75844SAndroid Build Coastguard Worker   // `kStatsOutputLevelStandard` includes the standard stats for Javascript API;
754*d9f75844SAndroid Build Coastguard Worker   // `kStatsOutputLevelDebug` includes both the standard stats and additional
755*d9f75844SAndroid Build Coastguard Worker   // stats for debugging purposes.
756*d9f75844SAndroid Build Coastguard Worker   enum StatsOutputLevel {
757*d9f75844SAndroid Build Coastguard Worker     kStatsOutputLevelStandard,
758*d9f75844SAndroid Build Coastguard Worker     kStatsOutputLevelDebug,
759*d9f75844SAndroid Build Coastguard Worker   };
760*d9f75844SAndroid Build Coastguard Worker 
761*d9f75844SAndroid Build Coastguard Worker   // Accessor methods to active local streams.
762*d9f75844SAndroid Build Coastguard Worker   // This method is not supported with kUnifiedPlan semantics. Please use
763*d9f75844SAndroid Build Coastguard Worker   // GetSenders() instead.
764*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<StreamCollectionInterface> local_streams() = 0;
765*d9f75844SAndroid Build Coastguard Worker 
766*d9f75844SAndroid Build Coastguard Worker   // Accessor methods to remote streams.
767*d9f75844SAndroid Build Coastguard Worker   // This method is not supported with kUnifiedPlan semantics. Please use
768*d9f75844SAndroid Build Coastguard Worker   // GetReceivers() instead.
769*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<StreamCollectionInterface> remote_streams() = 0;
770*d9f75844SAndroid Build Coastguard Worker 
771*d9f75844SAndroid Build Coastguard Worker   // Add a new MediaStream to be sent on this PeerConnection.
772*d9f75844SAndroid Build Coastguard Worker   // Note that a SessionDescription negotiation is needed before the
773*d9f75844SAndroid Build Coastguard Worker   // remote peer can receive the stream.
774*d9f75844SAndroid Build Coastguard Worker   //
775*d9f75844SAndroid Build Coastguard Worker   // This has been removed from the standard in favor of a track-based API. So,
776*d9f75844SAndroid Build Coastguard Worker   // this is equivalent to simply calling AddTrack for each track within the
777*d9f75844SAndroid Build Coastguard Worker   // stream, with the one difference that if "stream->AddTrack(...)" is called
778*d9f75844SAndroid Build Coastguard Worker   // later, the PeerConnection will automatically pick up the new track. Though
779*d9f75844SAndroid Build Coastguard Worker   // this functionality will be deprecated in the future.
780*d9f75844SAndroid Build Coastguard Worker   //
781*d9f75844SAndroid Build Coastguard Worker   // This method is not supported with kUnifiedPlan semantics. Please use
782*d9f75844SAndroid Build Coastguard Worker   // AddTrack instead.
783*d9f75844SAndroid Build Coastguard Worker   virtual bool AddStream(MediaStreamInterface* stream) = 0;
784*d9f75844SAndroid Build Coastguard Worker 
785*d9f75844SAndroid Build Coastguard Worker   // Remove a MediaStream from this PeerConnection.
786*d9f75844SAndroid Build Coastguard Worker   // Note that a SessionDescription negotiation is needed before the
787*d9f75844SAndroid Build Coastguard Worker   // remote peer is notified.
788*d9f75844SAndroid Build Coastguard Worker   //
789*d9f75844SAndroid Build Coastguard Worker   // This method is not supported with kUnifiedPlan semantics. Please use
790*d9f75844SAndroid Build Coastguard Worker   // RemoveTrack instead.
791*d9f75844SAndroid Build Coastguard Worker   virtual void RemoveStream(MediaStreamInterface* stream) = 0;
792*d9f75844SAndroid Build Coastguard Worker 
793*d9f75844SAndroid Build Coastguard Worker   // Add a new MediaStreamTrack to be sent on this PeerConnection, and return
794*d9f75844SAndroid Build Coastguard Worker   // the newly created RtpSender. The RtpSender will be associated with the
795*d9f75844SAndroid Build Coastguard Worker   // streams specified in the `stream_ids` list.
796*d9f75844SAndroid Build Coastguard Worker   //
797*d9f75844SAndroid Build Coastguard Worker   // Errors:
798*d9f75844SAndroid Build Coastguard Worker   // - INVALID_PARAMETER: `track` is null, has a kind other than audio or video,
799*d9f75844SAndroid Build Coastguard Worker   //       or a sender already exists for the track.
800*d9f75844SAndroid Build Coastguard Worker   // - INVALID_STATE: The PeerConnection is closed.
801*d9f75844SAndroid Build Coastguard Worker   virtual RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
802*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<MediaStreamTrackInterface> track,
803*d9f75844SAndroid Build Coastguard Worker       const std::vector<std::string>& stream_ids) = 0;
804*d9f75844SAndroid Build Coastguard Worker 
805*d9f75844SAndroid Build Coastguard Worker   // Add a new MediaStreamTrack as above, but with an additional parameter,
806*d9f75844SAndroid Build Coastguard Worker   // `init_send_encodings` : initial RtpEncodingParameters for RtpSender,
807*d9f75844SAndroid Build Coastguard Worker   // similar to init_send_encodings in RtpTransceiverInit.
808*d9f75844SAndroid Build Coastguard Worker   // Note that a new transceiver will always be created.
809*d9f75844SAndroid Build Coastguard Worker   //
810*d9f75844SAndroid Build Coastguard Worker   virtual RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
811*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<MediaStreamTrackInterface> track,
812*d9f75844SAndroid Build Coastguard Worker       const std::vector<std::string>& stream_ids,
813*d9f75844SAndroid Build Coastguard Worker       const std::vector<RtpEncodingParameters>& init_send_encodings) = 0;
814*d9f75844SAndroid Build Coastguard Worker 
815*d9f75844SAndroid Build Coastguard Worker   // Removes the connection between a MediaStreamTrack and the PeerConnection.
816*d9f75844SAndroid Build Coastguard Worker   // Stops sending on the RtpSender and marks the
817*d9f75844SAndroid Build Coastguard Worker   // corresponding RtpTransceiver direction as no longer sending.
818*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack
819*d9f75844SAndroid Build Coastguard Worker   //
820*d9f75844SAndroid Build Coastguard Worker   // Errors:
821*d9f75844SAndroid Build Coastguard Worker   // - INVALID_PARAMETER: `sender` is null or (Plan B only) the sender is not
822*d9f75844SAndroid Build Coastguard Worker   //       associated with this PeerConnection.
823*d9f75844SAndroid Build Coastguard Worker   // - INVALID_STATE: PeerConnection is closed.
824*d9f75844SAndroid Build Coastguard Worker   //
825*d9f75844SAndroid Build Coastguard Worker   // Plan B semantics: Removes the RtpSender from this PeerConnection.
826*d9f75844SAndroid Build Coastguard Worker   //
827*d9f75844SAndroid Build Coastguard Worker   // TODO(bugs.webrtc.org/9534): Rename to RemoveTrack once the other signature
828*d9f75844SAndroid Build Coastguard Worker   // is removed; remove default implementation once upstream is updated.
RemoveTrackOrError(rtc::scoped_refptr<RtpSenderInterface> sender)829*d9f75844SAndroid Build Coastguard Worker   virtual RTCError RemoveTrackOrError(
830*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<RtpSenderInterface> sender) {
831*d9f75844SAndroid Build Coastguard Worker     RTC_CHECK_NOTREACHED();
832*d9f75844SAndroid Build Coastguard Worker     return RTCError();
833*d9f75844SAndroid Build Coastguard Worker   }
834*d9f75844SAndroid Build Coastguard Worker 
835*d9f75844SAndroid Build Coastguard Worker   // AddTransceiver creates a new RtpTransceiver and adds it to the set of
836*d9f75844SAndroid Build Coastguard Worker   // transceivers. Adding a transceiver will cause future calls to CreateOffer
837*d9f75844SAndroid Build Coastguard Worker   // to add a media description for the corresponding transceiver.
838*d9f75844SAndroid Build Coastguard Worker   //
839*d9f75844SAndroid Build Coastguard Worker   // The initial value of `mid` in the returned transceiver is null. Setting a
840*d9f75844SAndroid Build Coastguard Worker   // new session description may change it to a non-null value.
841*d9f75844SAndroid Build Coastguard Worker   //
842*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
843*d9f75844SAndroid Build Coastguard Worker   //
844*d9f75844SAndroid Build Coastguard Worker   // Optionally, an RtpTransceiverInit structure can be specified to configure
845*d9f75844SAndroid Build Coastguard Worker   // the transceiver from construction. If not specified, the transceiver will
846*d9f75844SAndroid Build Coastguard Worker   // default to having a direction of kSendRecv and not be part of any streams.
847*d9f75844SAndroid Build Coastguard Worker   //
848*d9f75844SAndroid Build Coastguard Worker   // These methods are only available when Unified Plan is enabled (see
849*d9f75844SAndroid Build Coastguard Worker   // RTCConfiguration).
850*d9f75844SAndroid Build Coastguard Worker   //
851*d9f75844SAndroid Build Coastguard Worker   // Common errors:
852*d9f75844SAndroid Build Coastguard Worker   // - INTERNAL_ERROR: The configuration does not have Unified Plan enabled.
853*d9f75844SAndroid Build Coastguard Worker 
854*d9f75844SAndroid Build Coastguard Worker   // Adds a transceiver with a sender set to transmit the given track. The kind
855*d9f75844SAndroid Build Coastguard Worker   // of the transceiver (and sender/receiver) will be derived from the kind of
856*d9f75844SAndroid Build Coastguard Worker   // the track.
857*d9f75844SAndroid Build Coastguard Worker   // Errors:
858*d9f75844SAndroid Build Coastguard Worker   // - INVALID_PARAMETER: `track` is null.
859*d9f75844SAndroid Build Coastguard Worker   virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
860*d9f75844SAndroid Build Coastguard Worker   AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track) = 0;
861*d9f75844SAndroid Build Coastguard Worker   virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
862*d9f75844SAndroid Build Coastguard Worker   AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track,
863*d9f75844SAndroid Build Coastguard Worker                  const RtpTransceiverInit& init) = 0;
864*d9f75844SAndroid Build Coastguard Worker 
865*d9f75844SAndroid Build Coastguard Worker   // Adds a transceiver with the given kind. Can either be MEDIA_TYPE_AUDIO or
866*d9f75844SAndroid Build Coastguard Worker   // MEDIA_TYPE_VIDEO.
867*d9f75844SAndroid Build Coastguard Worker   // Errors:
868*d9f75844SAndroid Build Coastguard Worker   // - INVALID_PARAMETER: `media_type` is not MEDIA_TYPE_AUDIO or
869*d9f75844SAndroid Build Coastguard Worker   //                      MEDIA_TYPE_VIDEO.
870*d9f75844SAndroid Build Coastguard Worker   virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
871*d9f75844SAndroid Build Coastguard Worker   AddTransceiver(cricket::MediaType media_type) = 0;
872*d9f75844SAndroid Build Coastguard Worker   virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
873*d9f75844SAndroid Build Coastguard Worker   AddTransceiver(cricket::MediaType media_type,
874*d9f75844SAndroid Build Coastguard Worker                  const RtpTransceiverInit& init) = 0;
875*d9f75844SAndroid Build Coastguard Worker 
876*d9f75844SAndroid Build Coastguard Worker   // Creates a sender without a track. Can be used for "early media"/"warmup"
877*d9f75844SAndroid Build Coastguard Worker   // use cases, where the application may want to negotiate video attributes
878*d9f75844SAndroid Build Coastguard Worker   // before a track is available to send.
879*d9f75844SAndroid Build Coastguard Worker   //
880*d9f75844SAndroid Build Coastguard Worker   // The standard way to do this would be through "addTransceiver", but we
881*d9f75844SAndroid Build Coastguard Worker   // don't support that API yet.
882*d9f75844SAndroid Build Coastguard Worker   //
883*d9f75844SAndroid Build Coastguard Worker   // `kind` must be "audio" or "video".
884*d9f75844SAndroid Build Coastguard Worker   //
885*d9f75844SAndroid Build Coastguard Worker   // `stream_id` is used to populate the msid attribute; if empty, one will
886*d9f75844SAndroid Build Coastguard Worker   // be generated automatically.
887*d9f75844SAndroid Build Coastguard Worker   //
888*d9f75844SAndroid Build Coastguard Worker   // This method is not supported with kUnifiedPlan semantics. Please use
889*d9f75844SAndroid Build Coastguard Worker   // AddTransceiver instead.
890*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
891*d9f75844SAndroid Build Coastguard Worker       const std::string& kind,
892*d9f75844SAndroid Build Coastguard Worker       const std::string& stream_id) = 0;
893*d9f75844SAndroid Build Coastguard Worker 
894*d9f75844SAndroid Build Coastguard Worker   // If Plan B semantics are specified, gets all RtpSenders, created either
895*d9f75844SAndroid Build Coastguard Worker   // through AddStream, AddTrack, or CreateSender. All senders of a specific
896*d9f75844SAndroid Build Coastguard Worker   // media type share the same media description.
897*d9f75844SAndroid Build Coastguard Worker   //
898*d9f75844SAndroid Build Coastguard Worker   // If Unified Plan semantics are specified, gets the RtpSender for each
899*d9f75844SAndroid Build Coastguard Worker   // RtpTransceiver.
900*d9f75844SAndroid Build Coastguard Worker   virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
901*d9f75844SAndroid Build Coastguard Worker       const = 0;
902*d9f75844SAndroid Build Coastguard Worker 
903*d9f75844SAndroid Build Coastguard Worker   // If Plan B semantics are specified, gets all RtpReceivers created when a
904*d9f75844SAndroid Build Coastguard Worker   // remote description is applied. All receivers of a specific media type share
905*d9f75844SAndroid Build Coastguard Worker   // the same media description. It is also possible to have a media description
906*d9f75844SAndroid Build Coastguard Worker   // with no associated RtpReceivers, if the directional attribute does not
907*d9f75844SAndroid Build Coastguard Worker   // indicate that the remote peer is sending any media.
908*d9f75844SAndroid Build Coastguard Worker   //
909*d9f75844SAndroid Build Coastguard Worker   // If Unified Plan semantics are specified, gets the RtpReceiver for each
910*d9f75844SAndroid Build Coastguard Worker   // RtpTransceiver.
911*d9f75844SAndroid Build Coastguard Worker   virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
912*d9f75844SAndroid Build Coastguard Worker       const = 0;
913*d9f75844SAndroid Build Coastguard Worker 
914*d9f75844SAndroid Build Coastguard Worker   // Get all RtpTransceivers, created either through AddTransceiver, AddTrack or
915*d9f75844SAndroid Build Coastguard Worker   // by a remote description applied with SetRemoteDescription.
916*d9f75844SAndroid Build Coastguard Worker   //
917*d9f75844SAndroid Build Coastguard Worker   // Note: This method is only available when Unified Plan is enabled (see
918*d9f75844SAndroid Build Coastguard Worker   // RTCConfiguration).
919*d9f75844SAndroid Build Coastguard Worker   virtual std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>
920*d9f75844SAndroid Build Coastguard Worker   GetTransceivers() const = 0;
921*d9f75844SAndroid Build Coastguard Worker 
922*d9f75844SAndroid Build Coastguard Worker   // The legacy non-compliant GetStats() API. This correspond to the
923*d9f75844SAndroid Build Coastguard Worker   // callback-based version of getStats() in JavaScript. The returned metrics
924*d9f75844SAndroid Build Coastguard Worker   // are UNDOCUMENTED and many of them rely on implementation-specific details.
925*d9f75844SAndroid Build Coastguard Worker   // The goal is to DELETE THIS VERSION but we can't today because it is heavily
926*d9f75844SAndroid Build Coastguard Worker   // relied upon by third parties. See https://crbug.com/822696.
927*d9f75844SAndroid Build Coastguard Worker   //
928*d9f75844SAndroid Build Coastguard Worker   // This version is wired up into Chrome. Any stats implemented are
929*d9f75844SAndroid Build Coastguard Worker   // automatically exposed to the Web Platform. This has BYPASSED the Chrome
930*d9f75844SAndroid Build Coastguard Worker   // release processes for years and lead to cross-browser incompatibility
931*d9f75844SAndroid Build Coastguard Worker   // issues and web application reliance on Chrome-only behavior.
932*d9f75844SAndroid Build Coastguard Worker   //
933*d9f75844SAndroid Build Coastguard Worker   // This API is in "maintenance mode", serious regressions should be fixed but
934*d9f75844SAndroid Build Coastguard Worker   // adding new stats is highly discouraged.
935*d9f75844SAndroid Build Coastguard Worker   //
936*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): Deprecate and remove this when third parties have migrated to
937*d9f75844SAndroid Build Coastguard Worker   // the spec-compliant GetStats() API. https://crbug.com/822696
938*d9f75844SAndroid Build Coastguard Worker   virtual bool GetStats(StatsObserver* observer,
939*d9f75844SAndroid Build Coastguard Worker                         MediaStreamTrackInterface* track,  // Optional
940*d9f75844SAndroid Build Coastguard Worker                         StatsOutputLevel level) = 0;
941*d9f75844SAndroid Build Coastguard Worker   // The spec-compliant GetStats() API. This correspond to the promise-based
942*d9f75844SAndroid Build Coastguard Worker   // version of getStats() in JavaScript. Implementation status is described in
943*d9f75844SAndroid Build Coastguard Worker   // api/stats/rtcstats_objects.h. For more details on stats, see spec:
944*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-getstats
945*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): Takes shared ownership, use rtc::scoped_refptr<> instead. This
946*d9f75844SAndroid Build Coastguard Worker   // requires stop overriding the current version in third party or making third
947*d9f75844SAndroid Build Coastguard Worker   // party calls explicit to avoid ambiguity during switch. Make the future
948*d9f75844SAndroid Build Coastguard Worker   // version abstract as soon as third party projects implement it.
949*d9f75844SAndroid Build Coastguard Worker   virtual void GetStats(RTCStatsCollectorCallback* callback) = 0;
950*d9f75844SAndroid Build Coastguard Worker   // Spec-compliant getStats() performing the stats selection algorithm with the
951*d9f75844SAndroid Build Coastguard Worker   // sender. https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender-getstats
952*d9f75844SAndroid Build Coastguard Worker   virtual void GetStats(
953*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<RtpSenderInterface> selector,
954*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<RTCStatsCollectorCallback> callback) = 0;
955*d9f75844SAndroid Build Coastguard Worker   // Spec-compliant getStats() performing the stats selection algorithm with the
956*d9f75844SAndroid Build Coastguard Worker   // receiver. https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver-getstats
957*d9f75844SAndroid Build Coastguard Worker   virtual void GetStats(
958*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<RtpReceiverInterface> selector,
959*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<RTCStatsCollectorCallback> callback) = 0;
960*d9f75844SAndroid Build Coastguard Worker   // Clear cached stats in the RTCStatsCollector.
ClearStatsCache()961*d9f75844SAndroid Build Coastguard Worker   virtual void ClearStatsCache() {}
962*d9f75844SAndroid Build Coastguard Worker 
963*d9f75844SAndroid Build Coastguard Worker   // Create a data channel with the provided config, or default config if none
964*d9f75844SAndroid Build Coastguard Worker   // is provided. Note that an offer/answer negotiation is still necessary
965*d9f75844SAndroid Build Coastguard Worker   // before the data channel can be used.
966*d9f75844SAndroid Build Coastguard Worker   //
967*d9f75844SAndroid Build Coastguard Worker   // Also, calling CreateDataChannel is the only way to get a data "m=" section
968*d9f75844SAndroid Build Coastguard Worker   // in SDP, so it should be done before CreateOffer is called, if the
969*d9f75844SAndroid Build Coastguard Worker   // application plans to use data channels.
970*d9f75844SAndroid Build Coastguard Worker   virtual RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>>
CreateDataChannelOrError(const std::string & label,const DataChannelInit * config)971*d9f75844SAndroid Build Coastguard Worker   CreateDataChannelOrError(const std::string& label,
972*d9f75844SAndroid Build Coastguard Worker                            const DataChannelInit* config) {
973*d9f75844SAndroid Build Coastguard Worker     return RTCError(RTCErrorType::INTERNAL_ERROR, "dummy function called");
974*d9f75844SAndroid Build Coastguard Worker   }
975*d9f75844SAndroid Build Coastguard Worker   // TODO(crbug.com/788659): Remove "virtual" below and default implementation
976*d9f75844SAndroid Build Coastguard Worker   // above once mock in Chrome is fixed.
977*d9f75844SAndroid Build Coastguard Worker   ABSL_DEPRECATED("Use CreateDataChannelOrError")
CreateDataChannel(const std::string & label,const DataChannelInit * config)978*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
979*d9f75844SAndroid Build Coastguard Worker       const std::string& label,
980*d9f75844SAndroid Build Coastguard Worker       const DataChannelInit* config) {
981*d9f75844SAndroid Build Coastguard Worker     auto result = CreateDataChannelOrError(label, config);
982*d9f75844SAndroid Build Coastguard Worker     if (!result.ok()) {
983*d9f75844SAndroid Build Coastguard Worker       return nullptr;
984*d9f75844SAndroid Build Coastguard Worker     } else {
985*d9f75844SAndroid Build Coastguard Worker       return result.MoveValue();
986*d9f75844SAndroid Build Coastguard Worker     }
987*d9f75844SAndroid Build Coastguard Worker   }
988*d9f75844SAndroid Build Coastguard Worker 
989*d9f75844SAndroid Build Coastguard Worker   // NOTE: For the following 6 methods, it's only safe to dereference the
990*d9f75844SAndroid Build Coastguard Worker   // SessionDescriptionInterface on signaling_thread() (for example, calling
991*d9f75844SAndroid Build Coastguard Worker   // ToString).
992*d9f75844SAndroid Build Coastguard Worker 
993*d9f75844SAndroid Build Coastguard Worker   // Returns the more recently applied description; "pending" if it exists, and
994*d9f75844SAndroid Build Coastguard Worker   // otherwise "current". See below.
995*d9f75844SAndroid Build Coastguard Worker   virtual const SessionDescriptionInterface* local_description() const = 0;
996*d9f75844SAndroid Build Coastguard Worker   virtual const SessionDescriptionInterface* remote_description() const = 0;
997*d9f75844SAndroid Build Coastguard Worker 
998*d9f75844SAndroid Build Coastguard Worker   // A "current" description the one currently negotiated from a complete
999*d9f75844SAndroid Build Coastguard Worker   // offer/answer exchange.
1000*d9f75844SAndroid Build Coastguard Worker   virtual const SessionDescriptionInterface* current_local_description()
1001*d9f75844SAndroid Build Coastguard Worker       const = 0;
1002*d9f75844SAndroid Build Coastguard Worker   virtual const SessionDescriptionInterface* current_remote_description()
1003*d9f75844SAndroid Build Coastguard Worker       const = 0;
1004*d9f75844SAndroid Build Coastguard Worker 
1005*d9f75844SAndroid Build Coastguard Worker   // A "pending" description is one that's part of an incomplete offer/answer
1006*d9f75844SAndroid Build Coastguard Worker   // exchange (thus, either an offer or a pranswer). Once the offer/answer
1007*d9f75844SAndroid Build Coastguard Worker   // exchange is finished, the "pending" description will become "current".
1008*d9f75844SAndroid Build Coastguard Worker   virtual const SessionDescriptionInterface* pending_local_description()
1009*d9f75844SAndroid Build Coastguard Worker       const = 0;
1010*d9f75844SAndroid Build Coastguard Worker   virtual const SessionDescriptionInterface* pending_remote_description()
1011*d9f75844SAndroid Build Coastguard Worker       const = 0;
1012*d9f75844SAndroid Build Coastguard Worker 
1013*d9f75844SAndroid Build Coastguard Worker   // Tells the PeerConnection that ICE should be restarted. This triggers a need
1014*d9f75844SAndroid Build Coastguard Worker   // for negotiation and subsequent CreateOffer() calls will act as if
1015*d9f75844SAndroid Build Coastguard Worker   // RTCOfferAnswerOptions::ice_restart is true.
1016*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-restartice
1017*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): Remove default implementation when downstream projects
1018*d9f75844SAndroid Build Coastguard Worker   // implement this.
1019*d9f75844SAndroid Build Coastguard Worker   virtual void RestartIce() = 0;
1020*d9f75844SAndroid Build Coastguard Worker 
1021*d9f75844SAndroid Build Coastguard Worker   // Create a new offer.
1022*d9f75844SAndroid Build Coastguard Worker   // The CreateSessionDescriptionObserver callback will be called when done.
1023*d9f75844SAndroid Build Coastguard Worker   virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
1024*d9f75844SAndroid Build Coastguard Worker                            const RTCOfferAnswerOptions& options) = 0;
1025*d9f75844SAndroid Build Coastguard Worker 
1026*d9f75844SAndroid Build Coastguard Worker   // Create an answer to an offer.
1027*d9f75844SAndroid Build Coastguard Worker   // The CreateSessionDescriptionObserver callback will be called when done.
1028*d9f75844SAndroid Build Coastguard Worker   virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
1029*d9f75844SAndroid Build Coastguard Worker                             const RTCOfferAnswerOptions& options) = 0;
1030*d9f75844SAndroid Build Coastguard Worker 
1031*d9f75844SAndroid Build Coastguard Worker   // Sets the local session description.
1032*d9f75844SAndroid Build Coastguard Worker   //
1033*d9f75844SAndroid Build Coastguard Worker   // According to spec, the local session description MUST be the same as was
1034*d9f75844SAndroid Build Coastguard Worker   // returned by CreateOffer() or CreateAnswer() or else the operation should
1035*d9f75844SAndroid Build Coastguard Worker   // fail. Our implementation however allows some amount of "SDP munging", but
1036*d9f75844SAndroid Build Coastguard Worker   // please note that this is HIGHLY DISCOURAGED. If you do not intent to munge
1037*d9f75844SAndroid Build Coastguard Worker   // SDP, the method below that doesn't take `desc` as an argument will create
1038*d9f75844SAndroid Build Coastguard Worker   // the offer or answer for you.
1039*d9f75844SAndroid Build Coastguard Worker   //
1040*d9f75844SAndroid Build Coastguard Worker   // The observer is invoked as soon as the operation completes, which could be
1041*d9f75844SAndroid Build Coastguard Worker   // before or after the SetLocalDescription() method has exited.
SetLocalDescription(std::unique_ptr<SessionDescriptionInterface> desc,rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer)1042*d9f75844SAndroid Build Coastguard Worker   virtual void SetLocalDescription(
1043*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<SessionDescriptionInterface> desc,
1044*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer) {}
1045*d9f75844SAndroid Build Coastguard Worker   // Creates an offer or answer (depending on current signaling state) and sets
1046*d9f75844SAndroid Build Coastguard Worker   // it as the local session description.
1047*d9f75844SAndroid Build Coastguard Worker   //
1048*d9f75844SAndroid Build Coastguard Worker   // The observer is invoked as soon as the operation completes, which could be
1049*d9f75844SAndroid Build Coastguard Worker   // before or after the SetLocalDescription() method has exited.
SetLocalDescription(rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer)1050*d9f75844SAndroid Build Coastguard Worker   virtual void SetLocalDescription(
1051*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer) {}
1052*d9f75844SAndroid Build Coastguard Worker   // Like SetLocalDescription() above, but the observer is invoked with a delay
1053*d9f75844SAndroid Build Coastguard Worker   // after the operation completes. This helps avoid recursive calls by the
1054*d9f75844SAndroid Build Coastguard Worker   // observer but also makes it possible for states to change in-between the
1055*d9f75844SAndroid Build Coastguard Worker   // operation completing and the observer getting called. This makes them racy
1056*d9f75844SAndroid Build Coastguard Worker   // for synchronizing peer connection states to the application.
1057*d9f75844SAndroid Build Coastguard Worker   // TODO(https://crbug.com/webrtc/11798): Delete these methods in favor of the
1058*d9f75844SAndroid Build Coastguard Worker   // ones taking SetLocalDescriptionObserverInterface as argument.
1059*d9f75844SAndroid Build Coastguard Worker   virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
1060*d9f75844SAndroid Build Coastguard Worker                                    SessionDescriptionInterface* desc) = 0;
SetLocalDescription(SetSessionDescriptionObserver * observer)1061*d9f75844SAndroid Build Coastguard Worker   virtual void SetLocalDescription(SetSessionDescriptionObserver* observer) {}
1062*d9f75844SAndroid Build Coastguard Worker 
1063*d9f75844SAndroid Build Coastguard Worker   // Sets the remote session description.
1064*d9f75844SAndroid Build Coastguard Worker   //
1065*d9f75844SAndroid Build Coastguard Worker   // (Unlike "SDP munging" before SetLocalDescription(), modifying a remote
1066*d9f75844SAndroid Build Coastguard Worker   // offer or answer is allowed by the spec.)
1067*d9f75844SAndroid Build Coastguard Worker   //
1068*d9f75844SAndroid Build Coastguard Worker   // The observer is invoked as soon as the operation completes, which could be
1069*d9f75844SAndroid Build Coastguard Worker   // before or after the SetRemoteDescription() method has exited.
1070*d9f75844SAndroid Build Coastguard Worker   virtual void SetRemoteDescription(
1071*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<SessionDescriptionInterface> desc,
1072*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) = 0;
1073*d9f75844SAndroid Build Coastguard Worker   // Like SetRemoteDescription() above, but the observer is invoked with a delay
1074*d9f75844SAndroid Build Coastguard Worker   // after the operation completes. This helps avoid recursive calls by the
1075*d9f75844SAndroid Build Coastguard Worker   // observer but also makes it possible for states to change in-between the
1076*d9f75844SAndroid Build Coastguard Worker   // operation completing and the observer getting called. This makes them racy
1077*d9f75844SAndroid Build Coastguard Worker   // for synchronizing peer connection states to the application.
1078*d9f75844SAndroid Build Coastguard Worker   // TODO(https://crbug.com/webrtc/11798): Delete this method in favor of the
1079*d9f75844SAndroid Build Coastguard Worker   // ones taking SetRemoteDescriptionObserverInterface as argument.
SetRemoteDescription(SetSessionDescriptionObserver * observer,SessionDescriptionInterface * desc)1080*d9f75844SAndroid Build Coastguard Worker   virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
1081*d9f75844SAndroid Build Coastguard Worker                                     SessionDescriptionInterface* desc) {}
1082*d9f75844SAndroid Build Coastguard Worker 
1083*d9f75844SAndroid Build Coastguard Worker   // According to spec, we must only fire "negotiationneeded" if the Operations
1084*d9f75844SAndroid Build Coastguard Worker   // Chain is empty. This method takes care of validating an event previously
1085*d9f75844SAndroid Build Coastguard Worker   // generated with PeerConnectionObserver::OnNegotiationNeededEvent() to make
1086*d9f75844SAndroid Build Coastguard Worker   // sure that even if there was a delay (e.g. due to a PostTask) between the
1087*d9f75844SAndroid Build Coastguard Worker   // event being generated and the time of firing, the Operations Chain is empty
1088*d9f75844SAndroid Build Coastguard Worker   // and the event is still valid to be fired.
ShouldFireNegotiationNeededEvent(uint32_t event_id)1089*d9f75844SAndroid Build Coastguard Worker   virtual bool ShouldFireNegotiationNeededEvent(uint32_t event_id) {
1090*d9f75844SAndroid Build Coastguard Worker     return true;
1091*d9f75844SAndroid Build Coastguard Worker   }
1092*d9f75844SAndroid Build Coastguard Worker 
1093*d9f75844SAndroid Build Coastguard Worker   virtual PeerConnectionInterface::RTCConfiguration GetConfiguration() = 0;
1094*d9f75844SAndroid Build Coastguard Worker 
1095*d9f75844SAndroid Build Coastguard Worker   // Sets the PeerConnection's global configuration to `config`.
1096*d9f75844SAndroid Build Coastguard Worker   //
1097*d9f75844SAndroid Build Coastguard Worker   // The members of `config` that may be changed are `type`, `servers`,
1098*d9f75844SAndroid Build Coastguard Worker   // `ice_candidate_pool_size` and `prune_turn_ports` (though the candidate
1099*d9f75844SAndroid Build Coastguard Worker   // pool size can't be changed after the first call to SetLocalDescription).
1100*d9f75844SAndroid Build Coastguard Worker   // Note that this means the BUNDLE and RTCP-multiplexing policies cannot be
1101*d9f75844SAndroid Build Coastguard Worker   // changed with this method.
1102*d9f75844SAndroid Build Coastguard Worker   //
1103*d9f75844SAndroid Build Coastguard Worker   // Any changes to STUN/TURN servers or ICE candidate policy will affect the
1104*d9f75844SAndroid Build Coastguard Worker   // next gathering phase, and cause the next call to createOffer to generate
1105*d9f75844SAndroid Build Coastguard Worker   // new ICE credentials, as described in JSEP. This also occurs when
1106*d9f75844SAndroid Build Coastguard Worker   // `prune_turn_ports` changes, for the same reasoning.
1107*d9f75844SAndroid Build Coastguard Worker   //
1108*d9f75844SAndroid Build Coastguard Worker   // If an error occurs, returns false and populates `error` if non-null:
1109*d9f75844SAndroid Build Coastguard Worker   // - INVALID_MODIFICATION if `config` contains a modified parameter other
1110*d9f75844SAndroid Build Coastguard Worker   //   than one of the parameters listed above.
1111*d9f75844SAndroid Build Coastguard Worker   // - INVALID_RANGE if `ice_candidate_pool_size` is out of range.
1112*d9f75844SAndroid Build Coastguard Worker   // - SYNTAX_ERROR if parsing an ICE server URL failed.
1113*d9f75844SAndroid Build Coastguard Worker   // - INVALID_PARAMETER if a TURN server is missing `username` or `password`.
1114*d9f75844SAndroid Build Coastguard Worker   // - INTERNAL_ERROR if an unexpected error occurred.
1115*d9f75844SAndroid Build Coastguard Worker   virtual RTCError SetConfiguration(
1116*d9f75844SAndroid Build Coastguard Worker       const PeerConnectionInterface::RTCConfiguration& config) = 0;
1117*d9f75844SAndroid Build Coastguard Worker 
1118*d9f75844SAndroid Build Coastguard Worker   // Provides a remote candidate to the ICE Agent.
1119*d9f75844SAndroid Build Coastguard Worker   // A copy of the `candidate` will be created and added to the remote
1120*d9f75844SAndroid Build Coastguard Worker   // description. So the caller of this method still has the ownership of the
1121*d9f75844SAndroid Build Coastguard Worker   // `candidate`.
1122*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): The spec mandates chaining this operation onto the operations
1123*d9f75844SAndroid Build Coastguard Worker   // chain; deprecate and remove this version in favor of the callback-based
1124*d9f75844SAndroid Build Coastguard Worker   // signature.
1125*d9f75844SAndroid Build Coastguard Worker   virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
1126*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): Remove default implementation once implemented by downstream
1127*d9f75844SAndroid Build Coastguard Worker   // projects.
AddIceCandidate(std::unique_ptr<IceCandidateInterface> candidate,std::function<void (RTCError)> callback)1128*d9f75844SAndroid Build Coastguard Worker   virtual void AddIceCandidate(std::unique_ptr<IceCandidateInterface> candidate,
1129*d9f75844SAndroid Build Coastguard Worker                                std::function<void(RTCError)> callback) {}
1130*d9f75844SAndroid Build Coastguard Worker 
1131*d9f75844SAndroid Build Coastguard Worker   // Removes a group of remote candidates from the ICE agent. Needed mainly for
1132*d9f75844SAndroid Build Coastguard Worker   // continual gathering, to avoid an ever-growing list of candidates as
1133*d9f75844SAndroid Build Coastguard Worker   // networks come and go. Note that the candidates' transport_name must be set
1134*d9f75844SAndroid Build Coastguard Worker   // to the MID of the m= section that generated the candidate.
1135*d9f75844SAndroid Build Coastguard Worker   // TODO(bugs.webrtc.org/8395): Use IceCandidateInterface instead of
1136*d9f75844SAndroid Build Coastguard Worker   // cricket::Candidate, which would avoid the transport_name oddity.
1137*d9f75844SAndroid Build Coastguard Worker   virtual bool RemoveIceCandidates(
1138*d9f75844SAndroid Build Coastguard Worker       const std::vector<cricket::Candidate>& candidates) = 0;
1139*d9f75844SAndroid Build Coastguard Worker 
1140*d9f75844SAndroid Build Coastguard Worker   // SetBitrate limits the bandwidth allocated for all RTP streams sent by
1141*d9f75844SAndroid Build Coastguard Worker   // this PeerConnection. Other limitations might affect these limits and
1142*d9f75844SAndroid Build Coastguard Worker   // are respected (for example "b=AS" in SDP).
1143*d9f75844SAndroid Build Coastguard Worker   //
1144*d9f75844SAndroid Build Coastguard Worker   // Setting `current_bitrate_bps` will reset the current bitrate estimate
1145*d9f75844SAndroid Build Coastguard Worker   // to the provided value.
1146*d9f75844SAndroid Build Coastguard Worker   virtual RTCError SetBitrate(const BitrateSettings& bitrate) = 0;
1147*d9f75844SAndroid Build Coastguard Worker 
1148*d9f75844SAndroid Build Coastguard Worker   // Enable/disable playout of received audio streams. Enabled by default. Note
1149*d9f75844SAndroid Build Coastguard Worker   // that even if playout is enabled, streams will only be played out if the
1150*d9f75844SAndroid Build Coastguard Worker   // appropriate SDP is also applied. Setting `playout` to false will stop
1151*d9f75844SAndroid Build Coastguard Worker   // playout of the underlying audio device but starts a task which will poll
1152*d9f75844SAndroid Build Coastguard Worker   // for audio data every 10ms to ensure that audio processing happens and the
1153*d9f75844SAndroid Build Coastguard Worker   // audio statistics are updated.
SetAudioPlayout(bool playout)1154*d9f75844SAndroid Build Coastguard Worker   virtual void SetAudioPlayout(bool playout) {}
1155*d9f75844SAndroid Build Coastguard Worker 
1156*d9f75844SAndroid Build Coastguard Worker   // Enable/disable recording of transmitted audio streams. Enabled by default.
1157*d9f75844SAndroid Build Coastguard Worker   // Note that even if recording is enabled, streams will only be recorded if
1158*d9f75844SAndroid Build Coastguard Worker   // the appropriate SDP is also applied.
SetAudioRecording(bool recording)1159*d9f75844SAndroid Build Coastguard Worker   virtual void SetAudioRecording(bool recording) {}
1160*d9f75844SAndroid Build Coastguard Worker 
1161*d9f75844SAndroid Build Coastguard Worker   // Looks up the DtlsTransport associated with a MID value.
1162*d9f75844SAndroid Build Coastguard Worker   // In the Javascript API, DtlsTransport is a property of a sender, but
1163*d9f75844SAndroid Build Coastguard Worker   // because the PeerConnection owns the DtlsTransport in this implementation,
1164*d9f75844SAndroid Build Coastguard Worker   // it is better to look them up on the PeerConnection.
1165*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid(
1166*d9f75844SAndroid Build Coastguard Worker       const std::string& mid) = 0;
1167*d9f75844SAndroid Build Coastguard Worker 
1168*d9f75844SAndroid Build Coastguard Worker   // Returns the SCTP transport, if any.
1169*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport()
1170*d9f75844SAndroid Build Coastguard Worker       const = 0;
1171*d9f75844SAndroid Build Coastguard Worker 
1172*d9f75844SAndroid Build Coastguard Worker   // Returns the current SignalingState.
1173*d9f75844SAndroid Build Coastguard Worker   virtual SignalingState signaling_state() = 0;
1174*d9f75844SAndroid Build Coastguard Worker 
1175*d9f75844SAndroid Build Coastguard Worker   // Returns an aggregate state of all ICE *and* DTLS transports.
1176*d9f75844SAndroid Build Coastguard Worker   // This is left in place to avoid breaking native clients who expect our old,
1177*d9f75844SAndroid Build Coastguard Worker   // nonstandard behavior.
1178*d9f75844SAndroid Build Coastguard Worker   // TODO(jonasolsson): deprecate and remove this.
1179*d9f75844SAndroid Build Coastguard Worker   virtual IceConnectionState ice_connection_state() = 0;
1180*d9f75844SAndroid Build Coastguard Worker 
1181*d9f75844SAndroid Build Coastguard Worker   // Returns an aggregated state of all ICE transports.
1182*d9f75844SAndroid Build Coastguard Worker   virtual IceConnectionState standardized_ice_connection_state() = 0;
1183*d9f75844SAndroid Build Coastguard Worker 
1184*d9f75844SAndroid Build Coastguard Worker   // Returns an aggregated state of all ICE and DTLS transports.
1185*d9f75844SAndroid Build Coastguard Worker   virtual PeerConnectionState peer_connection_state() = 0;
1186*d9f75844SAndroid Build Coastguard Worker 
1187*d9f75844SAndroid Build Coastguard Worker   virtual IceGatheringState ice_gathering_state() = 0;
1188*d9f75844SAndroid Build Coastguard Worker 
1189*d9f75844SAndroid Build Coastguard Worker   // Returns the current state of canTrickleIceCandidates per
1190*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#attributes-1
can_trickle_ice_candidates()1191*d9f75844SAndroid Build Coastguard Worker   virtual absl::optional<bool> can_trickle_ice_candidates() {
1192*d9f75844SAndroid Build Coastguard Worker     // TODO(crbug.com/708484): Remove default implementation.
1193*d9f75844SAndroid Build Coastguard Worker     return absl::nullopt;
1194*d9f75844SAndroid Build Coastguard Worker   }
1195*d9f75844SAndroid Build Coastguard Worker 
1196*d9f75844SAndroid Build Coastguard Worker   // When a resource is overused, the PeerConnection will try to reduce the load
1197*d9f75844SAndroid Build Coastguard Worker   // on the sysem, for example by reducing the resolution or frame rate of
1198*d9f75844SAndroid Build Coastguard Worker   // encoded streams. The Resource API allows injecting platform-specific usage
1199*d9f75844SAndroid Build Coastguard Worker   // measurements. The conditions to trigger kOveruse or kUnderuse are up to the
1200*d9f75844SAndroid Build Coastguard Worker   // implementation.
1201*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): Make pure virtual when implemented by downstream projects.
AddAdaptationResource(rtc::scoped_refptr<Resource> resource)1202*d9f75844SAndroid Build Coastguard Worker   virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) {}
1203*d9f75844SAndroid Build Coastguard Worker 
1204*d9f75844SAndroid Build Coastguard Worker   // Start RtcEventLog using an existing output-sink. Takes ownership of
1205*d9f75844SAndroid Build Coastguard Worker   // `output` and passes it on to Call, which will take the ownership. If the
1206*d9f75844SAndroid Build Coastguard Worker   // operation fails the output will be closed and deallocated. The event log
1207*d9f75844SAndroid Build Coastguard Worker   // will send serialized events to the output object every `output_period_ms`.
1208*d9f75844SAndroid Build Coastguard Worker   // Applications using the event log should generally make their own trade-off
1209*d9f75844SAndroid Build Coastguard Worker   // regarding the output period. A long period is generally more efficient,
1210*d9f75844SAndroid Build Coastguard Worker   // with potential drawbacks being more bursty thread usage, and more events
1211*d9f75844SAndroid Build Coastguard Worker   // lost in case the application crashes. If the `output_period_ms` argument is
1212*d9f75844SAndroid Build Coastguard Worker   // omitted, webrtc selects a default deemed to be workable in most cases.
1213*d9f75844SAndroid Build Coastguard Worker   virtual bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,
1214*d9f75844SAndroid Build Coastguard Worker                                 int64_t output_period_ms) = 0;
1215*d9f75844SAndroid Build Coastguard Worker   virtual bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) = 0;
1216*d9f75844SAndroid Build Coastguard Worker 
1217*d9f75844SAndroid Build Coastguard Worker   // Stops logging the RtcEventLog.
1218*d9f75844SAndroid Build Coastguard Worker   virtual void StopRtcEventLog() = 0;
1219*d9f75844SAndroid Build Coastguard Worker 
1220*d9f75844SAndroid Build Coastguard Worker   // Terminates all media, closes the transports, and in general releases any
1221*d9f75844SAndroid Build Coastguard Worker   // resources used by the PeerConnection. This is an irreversible operation.
1222*d9f75844SAndroid Build Coastguard Worker   //
1223*d9f75844SAndroid Build Coastguard Worker   // Note that after this method completes, the PeerConnection will no longer
1224*d9f75844SAndroid Build Coastguard Worker   // use the PeerConnectionObserver interface passed in on construction, and
1225*d9f75844SAndroid Build Coastguard Worker   // thus the observer object can be safely destroyed.
1226*d9f75844SAndroid Build Coastguard Worker   virtual void Close() = 0;
1227*d9f75844SAndroid Build Coastguard Worker 
1228*d9f75844SAndroid Build Coastguard Worker   // The thread on which all PeerConnectionObserver callbacks will be invoked,
1229*d9f75844SAndroid Build Coastguard Worker   // as well as callbacks for other classes such as DataChannelObserver.
1230*d9f75844SAndroid Build Coastguard Worker   //
1231*d9f75844SAndroid Build Coastguard Worker   // Also the only thread on which it's safe to use SessionDescriptionInterface
1232*d9f75844SAndroid Build Coastguard Worker   // pointers.
1233*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Make pure virtual when all subclasses implement it.
signaling_thread()1234*d9f75844SAndroid Build Coastguard Worker   virtual rtc::Thread* signaling_thread() const { return nullptr; }
1235*d9f75844SAndroid Build Coastguard Worker 
1236*d9f75844SAndroid Build Coastguard Worker  protected:
1237*d9f75844SAndroid Build Coastguard Worker   // Dtor protected as objects shouldn't be deleted via this interface.
1238*d9f75844SAndroid Build Coastguard Worker   ~PeerConnectionInterface() override = default;
1239*d9f75844SAndroid Build Coastguard Worker };
1240*d9f75844SAndroid Build Coastguard Worker 
1241*d9f75844SAndroid Build Coastguard Worker // PeerConnection callback interface, used for RTCPeerConnection events.
1242*d9f75844SAndroid Build Coastguard Worker // Application should implement these methods.
1243*d9f75844SAndroid Build Coastguard Worker class PeerConnectionObserver {
1244*d9f75844SAndroid Build Coastguard Worker  public:
1245*d9f75844SAndroid Build Coastguard Worker   virtual ~PeerConnectionObserver() = default;
1246*d9f75844SAndroid Build Coastguard Worker 
1247*d9f75844SAndroid Build Coastguard Worker   // Triggered when the SignalingState changed.
1248*d9f75844SAndroid Build Coastguard Worker   virtual void OnSignalingChange(
1249*d9f75844SAndroid Build Coastguard Worker       PeerConnectionInterface::SignalingState new_state) = 0;
1250*d9f75844SAndroid Build Coastguard Worker 
1251*d9f75844SAndroid Build Coastguard Worker   // Triggered when media is received on a new stream from remote peer.
OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream)1252*d9f75844SAndroid Build Coastguard Worker   virtual void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) {}
1253*d9f75844SAndroid Build Coastguard Worker 
1254*d9f75844SAndroid Build Coastguard Worker   // Triggered when a remote peer closes a stream.
OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream)1255*d9f75844SAndroid Build Coastguard Worker   virtual void OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream) {
1256*d9f75844SAndroid Build Coastguard Worker   }
1257*d9f75844SAndroid Build Coastguard Worker 
1258*d9f75844SAndroid Build Coastguard Worker   // Triggered when a remote peer opens a data channel.
1259*d9f75844SAndroid Build Coastguard Worker   virtual void OnDataChannel(
1260*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<DataChannelInterface> data_channel) = 0;
1261*d9f75844SAndroid Build Coastguard Worker 
1262*d9f75844SAndroid Build Coastguard Worker   // Triggered when renegotiation is needed. For example, an ICE restart
1263*d9f75844SAndroid Build Coastguard Worker   // has begun.
1264*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): Delete in favor of OnNegotiationNeededEvent() when downstream
1265*d9f75844SAndroid Build Coastguard Worker   // projects have migrated.
OnRenegotiationNeeded()1266*d9f75844SAndroid Build Coastguard Worker   virtual void OnRenegotiationNeeded() {}
1267*d9f75844SAndroid Build Coastguard Worker   // Used to fire spec-compliant onnegotiationneeded events, which should only
1268*d9f75844SAndroid Build Coastguard Worker   // fire when the Operations Chain is empty. The observer is responsible for
1269*d9f75844SAndroid Build Coastguard Worker   // queuing a task (e.g. Chromium: jump to main thread) to maybe fire the
1270*d9f75844SAndroid Build Coastguard Worker   // event. The event identified using `event_id` must only fire if
1271*d9f75844SAndroid Build Coastguard Worker   // PeerConnection::ShouldFireNegotiationNeededEvent() returns true since it is
1272*d9f75844SAndroid Build Coastguard Worker   // possible for the event to become invalidated by operations subsequently
1273*d9f75844SAndroid Build Coastguard Worker   // chained.
OnNegotiationNeededEvent(uint32_t event_id)1274*d9f75844SAndroid Build Coastguard Worker   virtual void OnNegotiationNeededEvent(uint32_t event_id) {}
1275*d9f75844SAndroid Build Coastguard Worker 
1276*d9f75844SAndroid Build Coastguard Worker   // Called any time the legacy IceConnectionState changes.
1277*d9f75844SAndroid Build Coastguard Worker   //
1278*d9f75844SAndroid Build Coastguard Worker   // Note that our ICE states lag behind the standard slightly. The most
1279*d9f75844SAndroid Build Coastguard Worker   // notable differences include the fact that "failed" occurs after 15
1280*d9f75844SAndroid Build Coastguard Worker   // seconds, not 30, and this actually represents a combination ICE + DTLS
1281*d9f75844SAndroid Build Coastguard Worker   // state, so it may be "failed" if DTLS fails while ICE succeeds.
1282*d9f75844SAndroid Build Coastguard Worker   //
1283*d9f75844SAndroid Build Coastguard Worker   // TODO(jonasolsson): deprecate and remove this.
OnIceConnectionChange(PeerConnectionInterface::IceConnectionState new_state)1284*d9f75844SAndroid Build Coastguard Worker   virtual void OnIceConnectionChange(
1285*d9f75844SAndroid Build Coastguard Worker       PeerConnectionInterface::IceConnectionState new_state) {}
1286*d9f75844SAndroid Build Coastguard Worker 
1287*d9f75844SAndroid Build Coastguard Worker   // Called any time the standards-compliant IceConnectionState changes.
OnStandardizedIceConnectionChange(PeerConnectionInterface::IceConnectionState new_state)1288*d9f75844SAndroid Build Coastguard Worker   virtual void OnStandardizedIceConnectionChange(
1289*d9f75844SAndroid Build Coastguard Worker       PeerConnectionInterface::IceConnectionState new_state) {}
1290*d9f75844SAndroid Build Coastguard Worker 
1291*d9f75844SAndroid Build Coastguard Worker   // Called any time the PeerConnectionState changes.
OnConnectionChange(PeerConnectionInterface::PeerConnectionState new_state)1292*d9f75844SAndroid Build Coastguard Worker   virtual void OnConnectionChange(
1293*d9f75844SAndroid Build Coastguard Worker       PeerConnectionInterface::PeerConnectionState new_state) {}
1294*d9f75844SAndroid Build Coastguard Worker 
1295*d9f75844SAndroid Build Coastguard Worker   // Called any time the IceGatheringState changes.
1296*d9f75844SAndroid Build Coastguard Worker   virtual void OnIceGatheringChange(
1297*d9f75844SAndroid Build Coastguard Worker       PeerConnectionInterface::IceGatheringState new_state) = 0;
1298*d9f75844SAndroid Build Coastguard Worker 
1299*d9f75844SAndroid Build Coastguard Worker   // A new ICE candidate has been gathered.
1300*d9f75844SAndroid Build Coastguard Worker   virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
1301*d9f75844SAndroid Build Coastguard Worker 
1302*d9f75844SAndroid Build Coastguard Worker   // Gathering of an ICE candidate failed.
1303*d9f75844SAndroid Build Coastguard Worker   // See https://w3c.github.io/webrtc-pc/#event-icecandidateerror
OnIceCandidateError(const std::string & address,int port,const std::string & url,int error_code,const std::string & error_text)1304*d9f75844SAndroid Build Coastguard Worker   virtual void OnIceCandidateError(const std::string& address,
1305*d9f75844SAndroid Build Coastguard Worker                                    int port,
1306*d9f75844SAndroid Build Coastguard Worker                                    const std::string& url,
1307*d9f75844SAndroid Build Coastguard Worker                                    int error_code,
1308*d9f75844SAndroid Build Coastguard Worker                                    const std::string& error_text) {}
1309*d9f75844SAndroid Build Coastguard Worker 
1310*d9f75844SAndroid Build Coastguard Worker   // Ice candidates have been removed.
1311*d9f75844SAndroid Build Coastguard Worker   // TODO(honghaiz): Make this a pure virtual method when all its subclasses
1312*d9f75844SAndroid Build Coastguard Worker   // implement it.
OnIceCandidatesRemoved(const std::vector<cricket::Candidate> & candidates)1313*d9f75844SAndroid Build Coastguard Worker   virtual void OnIceCandidatesRemoved(
1314*d9f75844SAndroid Build Coastguard Worker       const std::vector<cricket::Candidate>& candidates) {}
1315*d9f75844SAndroid Build Coastguard Worker 
1316*d9f75844SAndroid Build Coastguard Worker   // Called when the ICE connection receiving status changes.
OnIceConnectionReceivingChange(bool receiving)1317*d9f75844SAndroid Build Coastguard Worker   virtual void OnIceConnectionReceivingChange(bool receiving) {}
1318*d9f75844SAndroid Build Coastguard Worker 
1319*d9f75844SAndroid Build Coastguard Worker   // Called when the selected candidate pair for the ICE connection changes.
OnIceSelectedCandidatePairChanged(const cricket::CandidatePairChangeEvent & event)1320*d9f75844SAndroid Build Coastguard Worker   virtual void OnIceSelectedCandidatePairChanged(
1321*d9f75844SAndroid Build Coastguard Worker       const cricket::CandidatePairChangeEvent& event) {}
1322*d9f75844SAndroid Build Coastguard Worker 
1323*d9f75844SAndroid Build Coastguard Worker   // This is called when a receiver and its track are created.
1324*d9f75844SAndroid Build Coastguard Worker   // TODO(zhihuang): Make this pure virtual when all subclasses implement it.
1325*d9f75844SAndroid Build Coastguard Worker   // Note: This is called with both Plan B and Unified Plan semantics. Unified
1326*d9f75844SAndroid Build Coastguard Worker   // Plan users should prefer OnTrack, OnAddTrack is only called as backwards
1327*d9f75844SAndroid Build Coastguard Worker   // compatibility (and is called in the exact same situations as OnTrack).
OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver,const std::vector<rtc::scoped_refptr<MediaStreamInterface>> & streams)1328*d9f75844SAndroid Build Coastguard Worker   virtual void OnAddTrack(
1329*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<RtpReceiverInterface> receiver,
1330*d9f75844SAndroid Build Coastguard Worker       const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {}
1331*d9f75844SAndroid Build Coastguard Worker 
1332*d9f75844SAndroid Build Coastguard Worker   // This is called when signaling indicates a transceiver will be receiving
1333*d9f75844SAndroid Build Coastguard Worker   // media from the remote endpoint. This is fired during a call to
1334*d9f75844SAndroid Build Coastguard Worker   // SetRemoteDescription. The receiving track can be accessed by:
1335*d9f75844SAndroid Build Coastguard Worker   // `transceiver->receiver()->track()` and its associated streams by
1336*d9f75844SAndroid Build Coastguard Worker   // `transceiver->receiver()->streams()`.
1337*d9f75844SAndroid Build Coastguard Worker   // Note: This will only be called if Unified Plan semantics are specified.
1338*d9f75844SAndroid Build Coastguard Worker   // This behavior is specified in section 2.2.8.2.5 of the "Set the
1339*d9f75844SAndroid Build Coastguard Worker   // RTCSessionDescription" algorithm:
1340*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#set-description
OnTrack(rtc::scoped_refptr<RtpTransceiverInterface> transceiver)1341*d9f75844SAndroid Build Coastguard Worker   virtual void OnTrack(
1342*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<RtpTransceiverInterface> transceiver) {}
1343*d9f75844SAndroid Build Coastguard Worker 
1344*d9f75844SAndroid Build Coastguard Worker   // Called when signaling indicates that media will no longer be received on a
1345*d9f75844SAndroid Build Coastguard Worker   // track.
1346*d9f75844SAndroid Build Coastguard Worker   // With Plan B semantics, the given receiver will have been removed from the
1347*d9f75844SAndroid Build Coastguard Worker   // PeerConnection and the track muted.
1348*d9f75844SAndroid Build Coastguard Worker   // With Unified Plan semantics, the receiver will remain but the transceiver
1349*d9f75844SAndroid Build Coastguard Worker   // will have changed direction to either sendonly or inactive.
1350*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#process-remote-track-removal
1351*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos,deadbeef): Make pure virtual when all subclasses implement it.
OnRemoveTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver)1352*d9f75844SAndroid Build Coastguard Worker   virtual void OnRemoveTrack(
1353*d9f75844SAndroid Build Coastguard Worker       rtc::scoped_refptr<RtpReceiverInterface> receiver) {}
1354*d9f75844SAndroid Build Coastguard Worker 
1355*d9f75844SAndroid Build Coastguard Worker   // Called when an interesting usage is detected by WebRTC.
1356*d9f75844SAndroid Build Coastguard Worker   // An appropriate action is to add information about the context of the
1357*d9f75844SAndroid Build Coastguard Worker   // PeerConnection and write the event to some kind of "interesting events"
1358*d9f75844SAndroid Build Coastguard Worker   // log function.
1359*d9f75844SAndroid Build Coastguard Worker   // The heuristics for defining what constitutes "interesting" are
1360*d9f75844SAndroid Build Coastguard Worker   // implementation-defined.
OnInterestingUsage(int usage_pattern)1361*d9f75844SAndroid Build Coastguard Worker   virtual void OnInterestingUsage(int usage_pattern) {}
1362*d9f75844SAndroid Build Coastguard Worker };
1363*d9f75844SAndroid Build Coastguard Worker 
1364*d9f75844SAndroid Build Coastguard Worker // PeerConnectionDependencies holds all of PeerConnections dependencies.
1365*d9f75844SAndroid Build Coastguard Worker // A dependency is distinct from a configuration as it defines significant
1366*d9f75844SAndroid Build Coastguard Worker // executable code that can be provided by a user of the API.
1367*d9f75844SAndroid Build Coastguard Worker //
1368*d9f75844SAndroid Build Coastguard Worker // All new dependencies should be added as a unique_ptr to allow the
1369*d9f75844SAndroid Build Coastguard Worker // PeerConnection object to be the definitive owner of the dependencies
1370*d9f75844SAndroid Build Coastguard Worker // lifetime making injection safer.
1371*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT PeerConnectionDependencies final {
1372*d9f75844SAndroid Build Coastguard Worker   explicit PeerConnectionDependencies(PeerConnectionObserver* observer_in);
1373*d9f75844SAndroid Build Coastguard Worker   // This object is not copyable or assignable.
1374*d9f75844SAndroid Build Coastguard Worker   PeerConnectionDependencies(const PeerConnectionDependencies&) = delete;
1375*d9f75844SAndroid Build Coastguard Worker   PeerConnectionDependencies& operator=(const PeerConnectionDependencies&) =
1376*d9f75844SAndroid Build Coastguard Worker       delete;
1377*d9f75844SAndroid Build Coastguard Worker   // This object is only moveable.
1378*d9f75844SAndroid Build Coastguard Worker   PeerConnectionDependencies(PeerConnectionDependencies&&);
1379*d9f75844SAndroid Build Coastguard Worker   PeerConnectionDependencies& operator=(PeerConnectionDependencies&&) = default;
1380*d9f75844SAndroid Build Coastguard Worker   ~PeerConnectionDependencies();
1381*d9f75844SAndroid Build Coastguard Worker   // Mandatory dependencies
1382*d9f75844SAndroid Build Coastguard Worker   PeerConnectionObserver* observer = nullptr;
1383*d9f75844SAndroid Build Coastguard Worker   // Optional dependencies
1384*d9f75844SAndroid Build Coastguard Worker   // TODO(bugs.webrtc.org/7447): remove port allocator once downstream is
1385*d9f75844SAndroid Build Coastguard Worker   // updated. The recommended way to inject networking components is to pass a
1386*d9f75844SAndroid Build Coastguard Worker   // PacketSocketFactory when creating the PeerConnectionFactory.
1387*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<cricket::PortAllocator> allocator;
1388*d9f75844SAndroid Build Coastguard Worker   // Factory for creating resolvers that look up hostnames in DNS
1389*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<webrtc::AsyncDnsResolverFactoryInterface>
1390*d9f75844SAndroid Build Coastguard Worker       async_dns_resolver_factory;
1391*d9f75844SAndroid Build Coastguard Worker   // Deprecated - use async_dns_resolver_factory
1392*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory;
1393*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<webrtc::IceTransportFactory> ice_transport_factory;
1394*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
1395*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier;
1396*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
1397*d9f75844SAndroid Build Coastguard Worker       video_bitrate_allocator_factory;
1398*d9f75844SAndroid Build Coastguard Worker   // Optional field trials to use.
1399*d9f75844SAndroid Build Coastguard Worker   // Overrides those from PeerConnectionFactoryDependencies.
1400*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<FieldTrialsView> trials;
1401*d9f75844SAndroid Build Coastguard Worker };
1402*d9f75844SAndroid Build Coastguard Worker 
1403*d9f75844SAndroid Build Coastguard Worker // PeerConnectionFactoryDependencies holds all of the PeerConnectionFactory
1404*d9f75844SAndroid Build Coastguard Worker // dependencies. All new dependencies should be added here instead of
1405*d9f75844SAndroid Build Coastguard Worker // overloading the function. This simplifies dependency injection and makes it
1406*d9f75844SAndroid Build Coastguard Worker // clear which are mandatory and optional. If possible please allow the peer
1407*d9f75844SAndroid Build Coastguard Worker // connection factory to take ownership of the dependency by adding a unique_ptr
1408*d9f75844SAndroid Build Coastguard Worker // to this structure.
1409*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT PeerConnectionFactoryDependencies final {
1410*d9f75844SAndroid Build Coastguard Worker   PeerConnectionFactoryDependencies();
1411*d9f75844SAndroid Build Coastguard Worker   // This object is not copyable or assignable.
1412*d9f75844SAndroid Build Coastguard Worker   PeerConnectionFactoryDependencies(const PeerConnectionFactoryDependencies&) =
1413*d9f75844SAndroid Build Coastguard Worker       delete;
1414*d9f75844SAndroid Build Coastguard Worker   PeerConnectionFactoryDependencies& operator=(
1415*d9f75844SAndroid Build Coastguard Worker       const PeerConnectionFactoryDependencies&) = delete;
1416*d9f75844SAndroid Build Coastguard Worker   // This object is only moveable.
1417*d9f75844SAndroid Build Coastguard Worker   PeerConnectionFactoryDependencies(PeerConnectionFactoryDependencies&&);
1418*d9f75844SAndroid Build Coastguard Worker   PeerConnectionFactoryDependencies& operator=(
1419*d9f75844SAndroid Build Coastguard Worker       PeerConnectionFactoryDependencies&&) = default;
1420*d9f75844SAndroid Build Coastguard Worker   ~PeerConnectionFactoryDependencies();
1421*d9f75844SAndroid Build Coastguard Worker 
1422*d9f75844SAndroid Build Coastguard Worker   // Optional dependencies
1423*d9f75844SAndroid Build Coastguard Worker   rtc::Thread* network_thread = nullptr;
1424*d9f75844SAndroid Build Coastguard Worker   rtc::Thread* worker_thread = nullptr;
1425*d9f75844SAndroid Build Coastguard Worker   rtc::Thread* signaling_thread = nullptr;
1426*d9f75844SAndroid Build Coastguard Worker   rtc::SocketFactory* socket_factory = nullptr;
1427*d9f75844SAndroid Build Coastguard Worker   // The `packet_socket_factory` will only be used if CreatePeerConnection is
1428*d9f75844SAndroid Build Coastguard Worker   // called without a `port_allocator`.
1429*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory;
1430*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<TaskQueueFactory> task_queue_factory;
1431*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<cricket::MediaEngineInterface> media_engine;
1432*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<CallFactoryInterface> call_factory;
1433*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory;
1434*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory;
1435*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<NetworkStatePredictorFactoryInterface>
1436*d9f75844SAndroid Build Coastguard Worker       network_state_predictor_factory;
1437*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<NetworkControllerFactoryInterface> network_controller_factory;
1438*d9f75844SAndroid Build Coastguard Worker   // The `network_manager` will only be used if CreatePeerConnection is called
1439*d9f75844SAndroid Build Coastguard Worker   // without a `port_allocator`, causing the default allocator and network
1440*d9f75844SAndroid Build Coastguard Worker   // manager to be used.
1441*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<rtc::NetworkManager> network_manager;
1442*d9f75844SAndroid Build Coastguard Worker   // The `network_monitor_factory` will only be used if CreatePeerConnection is
1443*d9f75844SAndroid Build Coastguard Worker   // called without a `port_allocator`, and the above `network_manager' is null.
1444*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<rtc::NetworkMonitorFactory> network_monitor_factory;
1445*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<NetEqFactory> neteq_factory;
1446*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<SctpTransportFactoryInterface> sctp_factory;
1447*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<FieldTrialsView> trials;
1448*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<RtpTransportControllerSendFactoryInterface>
1449*d9f75844SAndroid Build Coastguard Worker       transport_controller_send_factory;
1450*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<Metronome> metronome;
1451*d9f75844SAndroid Build Coastguard Worker };
1452*d9f75844SAndroid Build Coastguard Worker 
1453*d9f75844SAndroid Build Coastguard Worker // PeerConnectionFactoryInterface is the factory interface used for creating
1454*d9f75844SAndroid Build Coastguard Worker // PeerConnection, MediaStream and MediaStreamTrack objects.
1455*d9f75844SAndroid Build Coastguard Worker //
1456*d9f75844SAndroid Build Coastguard Worker // The simplest method for obtaiing one, CreatePeerConnectionFactory will
1457*d9f75844SAndroid Build Coastguard Worker // create the required libjingle threads, socket and network manager factory
1458*d9f75844SAndroid Build Coastguard Worker // classes for networking if none are provided, though it requires that the
1459*d9f75844SAndroid Build Coastguard Worker // application runs a message loop on the thread that called the method (see
1460*d9f75844SAndroid Build Coastguard Worker // explanation below)
1461*d9f75844SAndroid Build Coastguard Worker //
1462*d9f75844SAndroid Build Coastguard Worker // If an application decides to provide its own threads and/or implementation
1463*d9f75844SAndroid Build Coastguard Worker // of networking classes, it should use the alternate
1464*d9f75844SAndroid Build Coastguard Worker // CreatePeerConnectionFactory method which accepts threads as input, and use
1465*d9f75844SAndroid Build Coastguard Worker // the CreatePeerConnection version that takes a PortAllocator as an argument.
1466*d9f75844SAndroid Build Coastguard Worker class RTC_EXPORT PeerConnectionFactoryInterface
1467*d9f75844SAndroid Build Coastguard Worker     : public rtc::RefCountInterface {
1468*d9f75844SAndroid Build Coastguard Worker  public:
1469*d9f75844SAndroid Build Coastguard Worker   class Options {
1470*d9f75844SAndroid Build Coastguard Worker    public:
Options()1471*d9f75844SAndroid Build Coastguard Worker     Options() {}
1472*d9f75844SAndroid Build Coastguard Worker 
1473*d9f75844SAndroid Build Coastguard Worker     // If set to true, created PeerConnections won't enforce any SRTP
1474*d9f75844SAndroid Build Coastguard Worker     // requirement, allowing unsecured media. Should only be used for
1475*d9f75844SAndroid Build Coastguard Worker     // testing/debugging.
1476*d9f75844SAndroid Build Coastguard Worker     bool disable_encryption = false;
1477*d9f75844SAndroid Build Coastguard Worker 
1478*d9f75844SAndroid Build Coastguard Worker     // If set to true, any platform-supported network monitoring capability
1479*d9f75844SAndroid Build Coastguard Worker     // won't be used, and instead networks will only be updated via polling.
1480*d9f75844SAndroid Build Coastguard Worker     //
1481*d9f75844SAndroid Build Coastguard Worker     // This only has an effect if a PeerConnection is created with the default
1482*d9f75844SAndroid Build Coastguard Worker     // PortAllocator implementation.
1483*d9f75844SAndroid Build Coastguard Worker     bool disable_network_monitor = false;
1484*d9f75844SAndroid Build Coastguard Worker 
1485*d9f75844SAndroid Build Coastguard Worker     // Sets the network types to ignore. For instance, calling this with
1486*d9f75844SAndroid Build Coastguard Worker     // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
1487*d9f75844SAndroid Build Coastguard Worker     // loopback interfaces.
1488*d9f75844SAndroid Build Coastguard Worker     int network_ignore_mask = rtc::kDefaultNetworkIgnoreMask;
1489*d9f75844SAndroid Build Coastguard Worker 
1490*d9f75844SAndroid Build Coastguard Worker     // Sets the maximum supported protocol version. The highest version
1491*d9f75844SAndroid Build Coastguard Worker     // supported by both ends will be used for the connection, i.e. if one
1492*d9f75844SAndroid Build Coastguard Worker     // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
1493*d9f75844SAndroid Build Coastguard Worker     rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1494*d9f75844SAndroid Build Coastguard Worker 
1495*d9f75844SAndroid Build Coastguard Worker     // Sets crypto related options, e.g. enabled cipher suites.
1496*d9f75844SAndroid Build Coastguard Worker     CryptoOptions crypto_options = CryptoOptions::NoGcm();
1497*d9f75844SAndroid Build Coastguard Worker   };
1498*d9f75844SAndroid Build Coastguard Worker 
1499*d9f75844SAndroid Build Coastguard Worker   // Set the options to be used for subsequently created PeerConnections.
1500*d9f75844SAndroid Build Coastguard Worker   virtual void SetOptions(const Options& options) = 0;
1501*d9f75844SAndroid Build Coastguard Worker 
1502*d9f75844SAndroid Build Coastguard Worker   // The preferred way to create a new peer connection. Simply provide the
1503*d9f75844SAndroid Build Coastguard Worker   // configuration and a PeerConnectionDependencies structure.
1504*d9f75844SAndroid Build Coastguard Worker   // TODO(benwright): Make pure virtual once downstream mock PC factory classes
1505*d9f75844SAndroid Build Coastguard Worker   // are updated.
1506*d9f75844SAndroid Build Coastguard Worker   virtual RTCErrorOr<rtc::scoped_refptr<PeerConnectionInterface>>
1507*d9f75844SAndroid Build Coastguard Worker   CreatePeerConnectionOrError(
1508*d9f75844SAndroid Build Coastguard Worker       const PeerConnectionInterface::RTCConfiguration& configuration,
1509*d9f75844SAndroid Build Coastguard Worker       PeerConnectionDependencies dependencies);
1510*d9f75844SAndroid Build Coastguard Worker   // Deprecated creator - does not return an error code on error.
1511*d9f75844SAndroid Build Coastguard Worker   // TODO(bugs.webrtc.org:12238): Deprecate and remove.
1512*d9f75844SAndroid Build Coastguard Worker   ABSL_DEPRECATED("Use CreatePeerConnectionOrError")
1513*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
1514*d9f75844SAndroid Build Coastguard Worker       const PeerConnectionInterface::RTCConfiguration& configuration,
1515*d9f75844SAndroid Build Coastguard Worker       PeerConnectionDependencies dependencies);
1516*d9f75844SAndroid Build Coastguard Worker 
1517*d9f75844SAndroid Build Coastguard Worker   // Deprecated; `allocator` and `cert_generator` may be null, in which case
1518*d9f75844SAndroid Build Coastguard Worker   // default implementations will be used.
1519*d9f75844SAndroid Build Coastguard Worker   //
1520*d9f75844SAndroid Build Coastguard Worker   // `observer` must not be null.
1521*d9f75844SAndroid Build Coastguard Worker   //
1522*d9f75844SAndroid Build Coastguard Worker   // Note that this method does not take ownership of `observer`; it's the
1523*d9f75844SAndroid Build Coastguard Worker   // responsibility of the caller to delete it. It can be safely deleted after
1524*d9f75844SAndroid Build Coastguard Worker   // Close has been called on the returned PeerConnection, which ensures no
1525*d9f75844SAndroid Build Coastguard Worker   // more observer callbacks will be invoked.
1526*d9f75844SAndroid Build Coastguard Worker   ABSL_DEPRECATED("Use CreatePeerConnectionOrError")
1527*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
1528*d9f75844SAndroid Build Coastguard Worker       const PeerConnectionInterface::RTCConfiguration& configuration,
1529*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<cricket::PortAllocator> allocator,
1530*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
1531*d9f75844SAndroid Build Coastguard Worker       PeerConnectionObserver* observer);
1532*d9f75844SAndroid Build Coastguard Worker 
1533*d9f75844SAndroid Build Coastguard Worker   // Returns the capabilities of an RTP sender of type `kind`.
1534*d9f75844SAndroid Build Coastguard Worker   // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure.
1535*d9f75844SAndroid Build Coastguard Worker   // TODO(orphis): Make pure virtual when all subclasses implement it.
1536*d9f75844SAndroid Build Coastguard Worker   virtual RtpCapabilities GetRtpSenderCapabilities(
1537*d9f75844SAndroid Build Coastguard Worker       cricket::MediaType kind) const;
1538*d9f75844SAndroid Build Coastguard Worker 
1539*d9f75844SAndroid Build Coastguard Worker   // Returns the capabilities of an RTP receiver of type `kind`.
1540*d9f75844SAndroid Build Coastguard Worker   // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure.
1541*d9f75844SAndroid Build Coastguard Worker   // TODO(orphis): Make pure virtual when all subclasses implement it.
1542*d9f75844SAndroid Build Coastguard Worker   virtual RtpCapabilities GetRtpReceiverCapabilities(
1543*d9f75844SAndroid Build Coastguard Worker       cricket::MediaType kind) const;
1544*d9f75844SAndroid Build Coastguard Worker 
1545*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream(
1546*d9f75844SAndroid Build Coastguard Worker       const std::string& stream_id) = 0;
1547*d9f75844SAndroid Build Coastguard Worker 
1548*d9f75844SAndroid Build Coastguard Worker   // Creates an AudioSourceInterface.
1549*d9f75844SAndroid Build Coastguard Worker   // `options` decides audio processing settings.
1550*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
1551*d9f75844SAndroid Build Coastguard Worker       const cricket::AudioOptions& options) = 0;
1552*d9f75844SAndroid Build Coastguard Worker 
1553*d9f75844SAndroid Build Coastguard Worker   // Creates a new local VideoTrack. The same `source` can be used in several
1554*d9f75844SAndroid Build Coastguard Worker   // tracks.
1555*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
1556*d9f75844SAndroid Build Coastguard Worker       const std::string& label,
1557*d9f75844SAndroid Build Coastguard Worker       VideoTrackSourceInterface* source) = 0;
1558*d9f75844SAndroid Build Coastguard Worker 
1559*d9f75844SAndroid Build Coastguard Worker   // Creates an new AudioTrack. At the moment `source` can be null.
1560*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
1561*d9f75844SAndroid Build Coastguard Worker       const std::string& label,
1562*d9f75844SAndroid Build Coastguard Worker       AudioSourceInterface* source) = 0;
1563*d9f75844SAndroid Build Coastguard Worker 
1564*d9f75844SAndroid Build Coastguard Worker   // Starts AEC dump using existing file. Takes ownership of `file` and passes
1565*d9f75844SAndroid Build Coastguard Worker   // it on to VoiceEngine (via other objects) immediately, which will take
1566*d9f75844SAndroid Build Coastguard Worker   // the ownerhip. If the operation fails, the file will be closed.
1567*d9f75844SAndroid Build Coastguard Worker   // A maximum file size in bytes can be specified. When the file size limit is
1568*d9f75844SAndroid Build Coastguard Worker   // reached, logging is stopped automatically. If max_size_bytes is set to a
1569*d9f75844SAndroid Build Coastguard Worker   // value <= 0, no limit will be used, and logging will continue until the
1570*d9f75844SAndroid Build Coastguard Worker   // StopAecDump function is called.
1571*d9f75844SAndroid Build Coastguard Worker   // TODO(webrtc:6463): Delete default implementation when downstream mocks
1572*d9f75844SAndroid Build Coastguard Worker   // classes are updated.
StartAecDump(FILE * file,int64_t max_size_bytes)1573*d9f75844SAndroid Build Coastguard Worker   virtual bool StartAecDump(FILE* file, int64_t max_size_bytes) {
1574*d9f75844SAndroid Build Coastguard Worker     return false;
1575*d9f75844SAndroid Build Coastguard Worker   }
1576*d9f75844SAndroid Build Coastguard Worker 
1577*d9f75844SAndroid Build Coastguard Worker   // Stops logging the AEC dump.
1578*d9f75844SAndroid Build Coastguard Worker   virtual void StopAecDump() = 0;
1579*d9f75844SAndroid Build Coastguard Worker 
1580*d9f75844SAndroid Build Coastguard Worker  protected:
1581*d9f75844SAndroid Build Coastguard Worker   // Dtor and ctor protected as objects shouldn't be created or deleted via
1582*d9f75844SAndroid Build Coastguard Worker   // this interface.
PeerConnectionFactoryInterface()1583*d9f75844SAndroid Build Coastguard Worker   PeerConnectionFactoryInterface() {}
1584*d9f75844SAndroid Build Coastguard Worker   ~PeerConnectionFactoryInterface() override = default;
1585*d9f75844SAndroid Build Coastguard Worker };
1586*d9f75844SAndroid Build Coastguard Worker 
1587*d9f75844SAndroid Build Coastguard Worker // CreateModularPeerConnectionFactory is implemented in the "peerconnection"
1588*d9f75844SAndroid Build Coastguard Worker // build target, which doesn't pull in the implementations of every module
1589*d9f75844SAndroid Build Coastguard Worker // webrtc may use.
1590*d9f75844SAndroid Build Coastguard Worker //
1591*d9f75844SAndroid Build Coastguard Worker // If an application knows it will only require certain modules, it can reduce
1592*d9f75844SAndroid Build Coastguard Worker // webrtc's impact on its binary size by depending only on the "peerconnection"
1593*d9f75844SAndroid Build Coastguard Worker // target and the modules the application requires, using
1594*d9f75844SAndroid Build Coastguard Worker // CreateModularPeerConnectionFactory. For example, if an application
1595*d9f75844SAndroid Build Coastguard Worker // only uses WebRTC for audio, it can pass in null pointers for the
1596*d9f75844SAndroid Build Coastguard Worker // video-specific interfaces, and omit the corresponding modules from its
1597*d9f75844SAndroid Build Coastguard Worker // build.
1598*d9f75844SAndroid Build Coastguard Worker //
1599*d9f75844SAndroid Build Coastguard Worker // If `network_thread` or `worker_thread` are null, the PeerConnectionFactory
1600*d9f75844SAndroid Build Coastguard Worker // will create the necessary thread internally. If `signaling_thread` is null,
1601*d9f75844SAndroid Build Coastguard Worker // the PeerConnectionFactory will use the thread on which this method is called
1602*d9f75844SAndroid Build Coastguard Worker // as the signaling thread, wrapping it in an rtc::Thread object if needed.
1603*d9f75844SAndroid Build Coastguard Worker RTC_EXPORT rtc::scoped_refptr<PeerConnectionFactoryInterface>
1604*d9f75844SAndroid Build Coastguard Worker CreateModularPeerConnectionFactory(
1605*d9f75844SAndroid Build Coastguard Worker     PeerConnectionFactoryDependencies dependencies);
1606*d9f75844SAndroid Build Coastguard Worker 
1607*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-pc/#dom-rtcsignalingstate
AsString(SignalingState state)1608*d9f75844SAndroid Build Coastguard Worker inline constexpr absl::string_view PeerConnectionInterface::AsString(
1609*d9f75844SAndroid Build Coastguard Worker     SignalingState state) {
1610*d9f75844SAndroid Build Coastguard Worker   switch (state) {
1611*d9f75844SAndroid Build Coastguard Worker     case SignalingState::kStable:
1612*d9f75844SAndroid Build Coastguard Worker       return "stable";
1613*d9f75844SAndroid Build Coastguard Worker     case SignalingState::kHaveLocalOffer:
1614*d9f75844SAndroid Build Coastguard Worker       return "have-local-offer";
1615*d9f75844SAndroid Build Coastguard Worker     case SignalingState::kHaveLocalPrAnswer:
1616*d9f75844SAndroid Build Coastguard Worker       return "have-local-pranswer";
1617*d9f75844SAndroid Build Coastguard Worker     case SignalingState::kHaveRemoteOffer:
1618*d9f75844SAndroid Build Coastguard Worker       return "have-remote-offer";
1619*d9f75844SAndroid Build Coastguard Worker     case SignalingState::kHaveRemotePrAnswer:
1620*d9f75844SAndroid Build Coastguard Worker       return "have-remote-pranswer";
1621*d9f75844SAndroid Build Coastguard Worker     case SignalingState::kClosed:
1622*d9f75844SAndroid Build Coastguard Worker       return "closed";
1623*d9f75844SAndroid Build Coastguard Worker   }
1624*d9f75844SAndroid Build Coastguard Worker   // This cannot happen.
1625*d9f75844SAndroid Build Coastguard Worker   // Not using "RTC_CHECK_NOTREACHED()" because AsString() is constexpr.
1626*d9f75844SAndroid Build Coastguard Worker   return "";
1627*d9f75844SAndroid Build Coastguard Worker }
1628*d9f75844SAndroid Build Coastguard Worker 
1629*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-pc/#dom-rtcicegatheringstate
AsString(IceGatheringState state)1630*d9f75844SAndroid Build Coastguard Worker inline constexpr absl::string_view PeerConnectionInterface::AsString(
1631*d9f75844SAndroid Build Coastguard Worker     IceGatheringState state) {
1632*d9f75844SAndroid Build Coastguard Worker   switch (state) {
1633*d9f75844SAndroid Build Coastguard Worker     case IceGatheringState::kIceGatheringNew:
1634*d9f75844SAndroid Build Coastguard Worker       return "new";
1635*d9f75844SAndroid Build Coastguard Worker     case IceGatheringState::kIceGatheringGathering:
1636*d9f75844SAndroid Build Coastguard Worker       return "gathering";
1637*d9f75844SAndroid Build Coastguard Worker     case IceGatheringState::kIceGatheringComplete:
1638*d9f75844SAndroid Build Coastguard Worker       return "complete";
1639*d9f75844SAndroid Build Coastguard Worker   }
1640*d9f75844SAndroid Build Coastguard Worker   // This cannot happen.
1641*d9f75844SAndroid Build Coastguard Worker   // Not using "RTC_CHECK_NOTREACHED()" because AsString() is constexpr.
1642*d9f75844SAndroid Build Coastguard Worker   return "";
1643*d9f75844SAndroid Build Coastguard Worker }
1644*d9f75844SAndroid Build Coastguard Worker 
1645*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-pc/#dom-rtciceconnectionstate
AsString(PeerConnectionState state)1646*d9f75844SAndroid Build Coastguard Worker inline constexpr absl::string_view PeerConnectionInterface::AsString(
1647*d9f75844SAndroid Build Coastguard Worker     PeerConnectionState state) {
1648*d9f75844SAndroid Build Coastguard Worker   switch (state) {
1649*d9f75844SAndroid Build Coastguard Worker     case PeerConnectionState::kNew:
1650*d9f75844SAndroid Build Coastguard Worker       return "new";
1651*d9f75844SAndroid Build Coastguard Worker     case PeerConnectionState::kConnecting:
1652*d9f75844SAndroid Build Coastguard Worker       return "connecting";
1653*d9f75844SAndroid Build Coastguard Worker     case PeerConnectionState::kConnected:
1654*d9f75844SAndroid Build Coastguard Worker       return "connected";
1655*d9f75844SAndroid Build Coastguard Worker     case PeerConnectionState::kDisconnected:
1656*d9f75844SAndroid Build Coastguard Worker       return "disconnected";
1657*d9f75844SAndroid Build Coastguard Worker     case PeerConnectionState::kFailed:
1658*d9f75844SAndroid Build Coastguard Worker       return "failed";
1659*d9f75844SAndroid Build Coastguard Worker     case PeerConnectionState::kClosed:
1660*d9f75844SAndroid Build Coastguard Worker       return "closed";
1661*d9f75844SAndroid Build Coastguard Worker   }
1662*d9f75844SAndroid Build Coastguard Worker   // This cannot happen.
1663*d9f75844SAndroid Build Coastguard Worker   // Not using "RTC_CHECK_NOTREACHED()" because AsString() is constexpr.
1664*d9f75844SAndroid Build Coastguard Worker   return "";
1665*d9f75844SAndroid Build Coastguard Worker }
1666*d9f75844SAndroid Build Coastguard Worker 
AsString(IceConnectionState state)1667*d9f75844SAndroid Build Coastguard Worker inline constexpr absl::string_view PeerConnectionInterface::AsString(
1668*d9f75844SAndroid Build Coastguard Worker     IceConnectionState state) {
1669*d9f75844SAndroid Build Coastguard Worker   switch (state) {
1670*d9f75844SAndroid Build Coastguard Worker     case kIceConnectionNew:
1671*d9f75844SAndroid Build Coastguard Worker       return "new";
1672*d9f75844SAndroid Build Coastguard Worker     case kIceConnectionChecking:
1673*d9f75844SAndroid Build Coastguard Worker       return "checking";
1674*d9f75844SAndroid Build Coastguard Worker     case kIceConnectionConnected:
1675*d9f75844SAndroid Build Coastguard Worker       return "connected";
1676*d9f75844SAndroid Build Coastguard Worker     case kIceConnectionCompleted:
1677*d9f75844SAndroid Build Coastguard Worker       return "completed";
1678*d9f75844SAndroid Build Coastguard Worker     case kIceConnectionFailed:
1679*d9f75844SAndroid Build Coastguard Worker       return "failed";
1680*d9f75844SAndroid Build Coastguard Worker     case kIceConnectionDisconnected:
1681*d9f75844SAndroid Build Coastguard Worker       return "disconnected";
1682*d9f75844SAndroid Build Coastguard Worker     case kIceConnectionClosed:
1683*d9f75844SAndroid Build Coastguard Worker       return "closed";
1684*d9f75844SAndroid Build Coastguard Worker     case kIceConnectionMax:
1685*d9f75844SAndroid Build Coastguard Worker       // This cannot happen.
1686*d9f75844SAndroid Build Coastguard Worker       // Not using "RTC_CHECK_NOTREACHED()" because AsString() is constexpr.
1687*d9f75844SAndroid Build Coastguard Worker       return "";
1688*d9f75844SAndroid Build Coastguard Worker   }
1689*d9f75844SAndroid Build Coastguard Worker   // This cannot happen.
1690*d9f75844SAndroid Build Coastguard Worker   // Not using "RTC_CHECK_NOTREACHED()" because AsString() is constexpr.
1691*d9f75844SAndroid Build Coastguard Worker   return "";
1692*d9f75844SAndroid Build Coastguard Worker }
1693*d9f75844SAndroid Build Coastguard Worker 
1694*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
1695*d9f75844SAndroid Build Coastguard Worker 
1696*d9f75844SAndroid Build Coastguard Worker #endif  // API_PEER_CONNECTION_INTERFACE_H_
1697