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