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