Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_JSEP_TRANSPORT_CONTROLLER_H_ |
| 12 | #define PC_JSEP_TRANSPORT_CONTROLLER_H_ |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 13 | |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <string> |
| 17 | #include <utility> |
| 18 | #include <vector> |
| 19 | |
| 20 | #include "api/candidate.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 21 | #include "api/crypto/crypto_options.h" |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 22 | #include "api/ice_transport_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "api/peer_connection_interface.h" |
Danil Chapovalov | 83bbe91 | 2019-08-07 12:24:53 +0200 | [diff] [blame] | 24 | #include "api/rtc_event_log/rtc_event_log.h" |
Niels Möller | 65f17ca | 2019-09-12 13:59:36 +0200 | [diff] [blame] | 25 | #include "api/transport/media/media_transport_config.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "media/sctp/sctp_transport_internal.h" |
| 27 | #include "p2p/base/dtls_transport.h" |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 28 | #include "p2p/base/dtls_transport_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 29 | #include "p2p/base/p2p_transport_channel.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 30 | #include "pc/channel.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "pc/dtls_srtp_transport.h" |
| 32 | #include "pc/dtls_transport.h" |
| 33 | #include "pc/jsep_transport.h" |
| 34 | #include "pc/rtp_transport.h" |
| 35 | #include "pc/srtp_transport.h" |
| 36 | #include "rtc_base/async_invoker.h" |
| 37 | #include "rtc_base/constructor_magic.h" |
| 38 | #include "rtc_base/ref_counted_object.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame] | 39 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 40 | |
| 41 | namespace rtc { |
| 42 | class Thread; |
| 43 | class PacketTransportInternal; |
| 44 | } // namespace rtc |
| 45 | |
| 46 | namespace webrtc { |
| 47 | |
Steve Anton | d25828a | 2018-08-31 13:06:05 -0700 | [diff] [blame] | 48 | class JsepTransportController : public sigslot::has_slots<> { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 49 | public: |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 50 | // Used when the RtpTransport/DtlsTransport of the m= section is changed |
| 51 | // because the section is rejected or BUNDLE is enabled. |
| 52 | class Observer { |
| 53 | public: |
| 54 | virtual ~Observer() {} |
| 55 | |
| 56 | // Returns true if media associated with |mid| was successfully set up to be |
| 57 | // demultiplexed on |rtp_transport|. Could return false if two bundled m= |
| 58 | // sections use the same SSRC, for example. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 59 | // |
| 60 | // If a data channel transport must be negotiated, |data_channel_transport| |
| 61 | // and |negotiation_state| indicate negotiation status. If |
| 62 | // |data_channel_transport| is null, the data channel transport should not |
| 63 | // be used. Otherwise, the value is a pointer to the transport to be used |
| 64 | // for data channels on |mid|, if any. |
| 65 | // |
| 66 | // The observer should not send data on |data_channel_transport| until |
| 67 | // |negotiation_state| is provisional or final. It should not delete |
| 68 | // |data_channel_transport| or any fallback transport until |
| 69 | // |negotiation_state| is final. |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 70 | virtual bool OnTransportChanged( |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 71 | const std::string& mid, |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 72 | RtpTransportInternal* rtp_transport, |
Harald Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 73 | rtc::scoped_refptr<DtlsTransport> dtls_transport, |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 74 | DataChannelTransportInterface* data_channel_transport) = 0; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 77 | struct Config { |
| 78 | // If |redetermine_role_on_ice_restart| is true, ICE role is redetermined |
| 79 | // upon setting a local transport description that indicates an ICE |
| 80 | // restart. |
| 81 | bool redetermine_role_on_ice_restart = true; |
| 82 | rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 83 | // |crypto_options| is used to determine if created DTLS transports |
| 84 | // negotiate GCM crypto suites or not. |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 85 | webrtc::CryptoOptions crypto_options; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 86 | PeerConnectionInterface::BundlePolicy bundle_policy = |
| 87 | PeerConnectionInterface::kBundlePolicyBalanced; |
| 88 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy = |
| 89 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 90 | bool disable_encryption = false; |
| 91 | bool enable_external_auth = false; |
| 92 | // Used to inject the ICE/DTLS transports created externally. |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 93 | webrtc::IceTransportFactory* ice_transport_factory = nullptr; |
| 94 | cricket::DtlsTransportFactory* dtls_transport_factory = nullptr; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 95 | Observer* transport_observer = nullptr; |
Sebastian Jansson | 1b83a9e | 2019-09-18 18:22:12 +0200 | [diff] [blame] | 96 | // Must be provided and valid for the lifetime of the |
| 97 | // JsepTransportController instance. |
| 98 | std::function<void(const rtc::CopyOnWriteBuffer& packet, |
| 99 | int64_t packet_time_us)> |
| 100 | rtcp_handler; |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 101 | bool active_reset_srtp_params = false; |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 102 | RtcEventLog* event_log = nullptr; |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 103 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 104 | // Factory for SCTP transports. |
| 105 | cricket::SctpTransportInternalFactory* sctp_factory = nullptr; |
| 106 | |
Niels Möller | abea6e5 | 2019-03-08 14:49:32 +0100 | [diff] [blame] | 107 | // Whether an RtpMediaTransport should be created as default, when no |
| 108 | // MediaTransportFactory is provided. |
| 109 | bool use_rtp_media_transport = false; |
| 110 | |
Anton Sukhanov | 316f3ac | 2019-05-23 15:50:38 -0700 | [diff] [blame] | 111 | // Use encrypted datagram transport to send packets. |
| 112 | bool use_datagram_transport = false; |
| 113 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 114 | // Use datagram transport's implementation of data channels instead of SCTP. |
| 115 | bool use_datagram_transport_for_data_channels = false; |
| 116 | |
Bjorn A Mellem | 7da4e56 | 2019-09-26 11:02:11 -0700 | [diff] [blame] | 117 | // Whether |use_datagram_transport_for_data_channels| applies to outgoing |
| 118 | // calls. If true, |use_datagram_transport_for_data_channels| applies only |
| 119 | // to incoming calls. |
| 120 | bool use_datagram_transport_for_data_channels_receive_only = false; |
| 121 | |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 122 | // Optional media transport factory (experimental). If provided it will be |
Bjorn A Mellem | 7a9a092 | 2019-11-26 09:19:40 -0800 | [diff] [blame] | 123 | // used to create datagram_transport (as long as either |
| 124 | // |use_datagram_transport| or |
| 125 | // |use_datagram_transport_for_data_channels| is set to true). However, |
| 126 | // whether it will be used to send / receive audio and video frames instead |
| 127 | // of RTP is determined by |use_datagram_transport|. Note that currently |
| 128 | // datagram_transport co-exists with RTP / RTCP transports and may use the |
| 129 | // same underlying ICE transport. |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 130 | MediaTransportFactory* media_transport_factory = nullptr; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | // The ICE related events are signaled on the |signaling_thread|. |
| 134 | // All the transport related methods are called on the |network_thread|. |
| 135 | JsepTransportController(rtc::Thread* signaling_thread, |
| 136 | rtc::Thread* network_thread, |
| 137 | cricket::PortAllocator* port_allocator, |
Zach Stein | e20867f | 2018-08-02 13:20:15 -0700 | [diff] [blame] | 138 | AsyncResolverFactory* async_resolver_factory, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 139 | Config config); |
| 140 | virtual ~JsepTransportController(); |
| 141 | |
| 142 | // The main method to be called; applies a description at the transport |
| 143 | // level, creating/destroying transport objects as needed and updating their |
| 144 | // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not |
| 145 | // yet? May make sense to in the future. |
| 146 | RTCError SetLocalDescription(SdpType type, |
| 147 | const cricket::SessionDescription* description); |
| 148 | |
| 149 | RTCError SetRemoteDescription(SdpType type, |
| 150 | const cricket::SessionDescription* description); |
| 151 | |
| 152 | // Get transports to be used for the provided |mid|. If bundling is enabled, |
| 153 | // calling GetRtpTransport for multiple MIDs may yield the same object. |
| 154 | RtpTransportInternal* GetRtpTransport(const std::string& mid) const; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 155 | cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid); |
| 156 | const cricket::DtlsTransportInternal* GetRtcpDtlsTransport( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 157 | const std::string& mid) const; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 158 | // Gets the externally sharable version of the DtlsTransport. |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 159 | rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid( |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 160 | const std::string& mid); |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 161 | rtc::scoped_refptr<SctpTransport> GetSctpTransport( |
| 162 | const std::string& mid) const; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 163 | |
Anton Sukhanov | 316f3ac | 2019-05-23 15:50:38 -0700 | [diff] [blame] | 164 | MediaTransportConfig GetMediaTransportConfig(const std::string& mid) const; |
| 165 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 166 | DataChannelTransportInterface* GetDataChannelTransport( |
Anton Sukhanov | 316f3ac | 2019-05-23 15:50:38 -0700 | [diff] [blame] | 167 | const std::string& mid) const; |
| 168 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 169 | /********************* |
| 170 | * ICE-related methods |
| 171 | ********************/ |
| 172 | // This method is public to allow PeerConnection to update it from |
| 173 | // SetConfiguration. |
| 174 | void SetIceConfig(const cricket::IceConfig& config); |
| 175 | // Set the "needs-ice-restart" flag as described in JSEP. After the flag is |
| 176 | // set, offers should generate new ufrags/passwords until an ICE restart |
| 177 | // occurs. |
| 178 | void SetNeedsIceRestartFlag(); |
| 179 | // Returns true if the ICE restart flag above was set, and no ICE restart has |
| 180 | // occurred yet for this transport (by applying a local description with |
| 181 | // changed ufrag/password). If the transport has been deleted as a result of |
| 182 | // bundling, returns false. |
| 183 | bool NeedsIceRestart(const std::string& mid) const; |
| 184 | // Start gathering candidates for any new transports, or transports doing an |
| 185 | // ICE restart. |
| 186 | void MaybeStartGathering(); |
| 187 | RTCError AddRemoteCandidates( |
| 188 | const std::string& mid, |
| 189 | const std::vector<cricket::Candidate>& candidates); |
| 190 | RTCError RemoveRemoteCandidates( |
| 191 | const std::vector<cricket::Candidate>& candidates); |
| 192 | |
| 193 | /********************** |
| 194 | * DTLS-related methods |
| 195 | *********************/ |
| 196 | // Specifies the identity to use in this session. |
| 197 | // Can only be called once. |
| 198 | bool SetLocalCertificate( |
| 199 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
| 200 | rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate( |
| 201 | const std::string& mid) const; |
Taylor Brandstetter | c392866 | 2018-02-23 13:04:51 -0800 | [diff] [blame] | 202 | // Caller owns returned certificate chain. This method mainly exists for |
| 203 | // stats reporting. |
| 204 | std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 205 | const std::string& mid) const; |
| 206 | // Get negotiated role, if one has been negotiated. |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 207 | absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 208 | |
| 209 | // TODO(deadbeef): GetStats isn't const because all the way down to |
| 210 | // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not |
| 211 | // const. Fix this. |
| 212 | bool GetStats(const std::string& mid, cricket::TransportStats* stats); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 213 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 214 | bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; } |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 215 | |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 216 | void SetActiveResetSrtpParams(bool active_reset_srtp_params); |
| 217 | |
Piotr (Peter) Slatala | 97fc11f | 2018-10-18 12:57:59 -0700 | [diff] [blame] | 218 | // Allows to overwrite the settings from config. You may set or reset the |
Piotr (Peter) Slatala | 55b91b9 | 2019-01-25 13:31:15 -0800 | [diff] [blame] | 219 | // media transport configuration on the jsep transport controller, as long as |
| 220 | // you did not call 'GetMediaTransport' or 'MaybeCreateJsepTransport'. Once |
| 221 | // Jsep transport is created, you can't change this setting. |
Bjorn A Mellem | 7da4e56 | 2019-09-26 11:02:11 -0700 | [diff] [blame] | 222 | void SetMediaTransportSettings( |
Bjorn A Mellem | 7da4e56 | 2019-09-26 11:02:11 -0700 | [diff] [blame] | 223 | bool use_datagram_transport, |
| 224 | bool use_datagram_transport_for_data_channels, |
| 225 | bool use_datagram_transport_for_data_channels_receive_only); |
Piotr (Peter) Slatala | 97fc11f | 2018-10-18 12:57:59 -0700 | [diff] [blame] | 226 | |
Eldar Rello | d85ea75 | 2020-02-19 20:41:07 +0200 | [diff] [blame] | 227 | // For now the rollback only removes mid to transport mappings |
Eldar Rello | 353a718 | 2019-11-25 18:49:44 +0200 | [diff] [blame] | 228 | // and deletes unused transports, but doesn't consider anything more complex. |
Eldar Rello | d85ea75 | 2020-02-19 20:41:07 +0200 | [diff] [blame] | 229 | void RollbackTransports(); |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 230 | |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 231 | // Gets the transport parameters for the transport identified by |mid|. |
| 232 | // If |mid| is bundled, returns the parameters for the bundled transport. |
| 233 | // If the transport for |mid| has not been created yet, it may be allocated in |
| 234 | // order to generate transport parameters. |
| 235 | absl::optional<cricket::OpaqueTransportParameters> GetTransportParameters( |
| 236 | const std::string& mid); |
| 237 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 238 | // All of these signals are fired on the signaling thread. |
| 239 | |
| 240 | // If any transport failed => failed, |
| 241 | // Else if all completed => completed, |
| 242 | // Else if all connected => connected, |
| 243 | // Else => connecting |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 244 | sigslot::signal1<cricket::IceConnectionState> SignalIceConnectionState; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 245 | |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 246 | sigslot::signal1<PeerConnectionInterface::PeerConnectionState> |
| 247 | SignalConnectionState; |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 248 | sigslot::signal1<PeerConnectionInterface::IceConnectionState> |
| 249 | SignalStandardizedIceConnectionState; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 250 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 251 | // If all transports done gathering => complete, |
| 252 | // Else if any are gathering => gathering, |
| 253 | // Else => new |
| 254 | sigslot::signal1<cricket::IceGatheringState> SignalIceGatheringState; |
| 255 | |
| 256 | // (mid, candidates) |
| 257 | sigslot::signal2<const std::string&, const std::vector<cricket::Candidate>&> |
| 258 | SignalIceCandidatesGathered; |
| 259 | |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 260 | sigslot::signal1<const cricket::IceCandidateErrorEvent&> |
| 261 | SignalIceCandidateError; |
| 262 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 263 | sigslot::signal1<const std::vector<cricket::Candidate>&> |
| 264 | SignalIceCandidatesRemoved; |
| 265 | |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 266 | sigslot::signal1<const cricket::CandidatePairChangeEvent&> |
| 267 | SignalIceCandidatePairChanged; |
| 268 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 269 | sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError; |
| 270 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 271 | private: |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 272 | RTCError ApplyDescription_n(bool local, |
| 273 | SdpType type, |
| 274 | const cricket::SessionDescription* description); |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 275 | RTCError ValidateAndMaybeUpdateBundleGroup( |
| 276 | bool local, |
| 277 | SdpType type, |
| 278 | const cricket::SessionDescription* description); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 279 | RTCError ValidateContent(const cricket::ContentInfo& content_info); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 280 | |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 281 | void HandleRejectedContent(const cricket::ContentInfo& content_info, |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 282 | const cricket::SessionDescription* description); |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 283 | bool HandleBundledContent(const cricket::ContentInfo& content_info); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 284 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 285 | bool SetTransportForMid(const std::string& mid, |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 286 | cricket::JsepTransport* jsep_transport); |
| 287 | void RemoveTransportForMid(const std::string& mid); |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 288 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 289 | cricket::JsepTransportDescription CreateJsepTransportDescription( |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 290 | const cricket::ContentInfo& content_info, |
| 291 | const cricket::TransportInfo& transport_info, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 292 | const std::vector<int>& encrypted_extension_ids, |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 293 | int rtp_abs_sendtime_extn_id, |
| 294 | absl::optional<std::string> media_alt_protocol, |
| 295 | absl::optional<std::string> data_alt_protocol); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 296 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 297 | absl::optional<std::string> bundled_mid() const { |
| 298 | absl::optional<std::string> bundled_mid; |
Taylor Brandstetter | 0ab5651 | 2018-04-12 10:30:48 -0700 | [diff] [blame] | 299 | if (bundle_group_ && bundle_group_->FirstContentName()) { |
| 300 | bundled_mid = *(bundle_group_->FirstContentName()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 301 | } |
| 302 | return bundled_mid; |
| 303 | } |
| 304 | |
| 305 | bool IsBundled(const std::string& mid) const { |
| 306 | return bundle_group_ && bundle_group_->HasContentName(mid); |
| 307 | } |
| 308 | |
| 309 | bool ShouldUpdateBundleGroup(SdpType type, |
| 310 | const cricket::SessionDescription* description); |
| 311 | |
| 312 | std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle( |
| 313 | const cricket::SessionDescription* description); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 314 | std::vector<int> GetEncryptedHeaderExtensionIds( |
| 315 | const cricket::ContentInfo& content_info); |
| 316 | |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 317 | // Extracts the alt-protocol settings that apply to the bundle group. |
| 318 | RTCError GetAltProtocolsForBundle( |
| 319 | const cricket::SessionDescription* description, |
| 320 | absl::optional<std::string>* media_alt_protocol, |
| 321 | absl::optional<std::string>* data_alt_protocol); |
| 322 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 323 | int GetRtpAbsSendTimeHeaderExtensionId( |
| 324 | const cricket::ContentInfo& content_info); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 325 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 326 | // This method takes the BUNDLE group into account. If the JsepTransport is |
| 327 | // destroyed because of BUNDLE, it would return the transport which other |
| 328 | // transports are bundled on (In current implementation, it is the first |
| 329 | // content in the BUNDLE group). |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 330 | const cricket::JsepTransport* GetJsepTransportForMid( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 331 | const std::string& mid) const; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 332 | cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 333 | |
| 334 | // Get the JsepTransport without considering the BUNDLE group. Return nullptr |
| 335 | // if the JsepTransport is destroyed. |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 336 | const cricket::JsepTransport* GetJsepTransportByName( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 337 | const std::string& transport_name) const; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 338 | cricket::JsepTransport* GetJsepTransportByName( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 339 | const std::string& transport_name); |
| 340 | |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 341 | // Creates jsep transport. Noop if transport is already created. |
| 342 | // Transport is created either during SetLocalDescription (|local| == true) or |
| 343 | // during SetRemoteDescription (|local| == false). Passing |local| helps to |
| 344 | // differentiate initiator (caller) from answerer (callee). |
Piotr (Peter) Slatala | 105ded3 | 2019-02-27 14:26:15 -0800 | [diff] [blame] | 345 | RTCError MaybeCreateJsepTransport( |
| 346 | bool local, |
| 347 | const cricket::ContentInfo& content_info, |
| 348 | const cricket::SessionDescription& description); |
Piotr (Peter) Slatala | 47dfdca | 2018-11-16 14:13:58 -0800 | [diff] [blame] | 349 | |
Anton Sukhanov | 316f3ac | 2019-05-23 15:50:38 -0700 | [diff] [blame] | 350 | // Creates datagram transport if config wants to use it, and a=x-mt line is |
| 351 | // present for the current media transport. Returned |
| 352 | // DatagramTransportInterface is not connected, and must be connected to ICE. |
| 353 | // You must call |GenerateOrGetLastMediaTransportOffer| on the caller before |
| 354 | // calling MaybeCreateDatagramTransport. |
| 355 | std::unique_ptr<webrtc::DatagramTransportInterface> |
| 356 | MaybeCreateDatagramTransport(const cricket::ContentInfo& content_info, |
| 357 | const cricket::SessionDescription& description, |
| 358 | bool local); |
| 359 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 360 | void MaybeDestroyJsepTransport(const std::string& mid); |
| 361 | void DestroyAllJsepTransports_n(); |
| 362 | |
| 363 | void SetIceRole_n(cricket::IceRole ice_role); |
| 364 | |
| 365 | cricket::IceRole DetermineIceRole( |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 366 | cricket::JsepTransport* jsep_transport, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 367 | const cricket::TransportInfo& transport_info, |
| 368 | SdpType type, |
| 369 | bool local); |
| 370 | |
| 371 | std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport( |
Anton Sukhanov | ac6c096 | 2019-07-10 15:44:56 -0700 | [diff] [blame] | 372 | const cricket::ContentInfo& content_info, |
Bjorn A Mellem | 0c1c1b4 | 2019-05-29 17:34:13 -0700 | [diff] [blame] | 373 | cricket::IceTransportInternal* ice, |
Anton Sukhanov | 292ce4e | 2019-06-03 13:00:24 -0700 | [diff] [blame] | 374 | DatagramTransportInterface* datagram_transport); |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 375 | rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport( |
| 376 | const std::string& transport_name, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 377 | bool rtcp); |
| 378 | |
| 379 | std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport( |
| 380 | const std::string& transport_name, |
| 381 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 382 | rtc::PacketTransportInternal* rtcp_packet_transport); |
| 383 | std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport( |
| 384 | const std::string& transport_name, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 385 | cricket::DtlsTransportInternal* rtp_dtls_transport, |
| 386 | cricket::DtlsTransportInternal* rtcp_dtls_transport); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 387 | std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport( |
| 388 | const std::string& transport_name, |
| 389 | cricket::DtlsTransportInternal* rtp_dtls_transport, |
| 390 | cricket::DtlsTransportInternal* rtcp_dtls_transport); |
| 391 | |
| 392 | // Collect all the DtlsTransports, including RTP and RTCP, from the |
| 393 | // JsepTransports. JsepTransportController can iterate all the DtlsTransports |
| 394 | // and update the aggregate states. |
| 395 | std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports(); |
| 396 | |
| 397 | // Handlers for signals from Transport. |
| 398 | void OnTransportWritableState_n(rtc::PacketTransportInternal* transport); |
| 399 | void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport); |
| 400 | void OnTransportGatheringState_n(cricket::IceTransportInternal* transport); |
| 401 | void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport, |
| 402 | const cricket::Candidate& candidate); |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 403 | void OnTransportCandidateError_n( |
| 404 | cricket::IceTransportInternal* transport, |
| 405 | const cricket::IceCandidateErrorEvent& event); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 406 | void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport, |
| 407 | const cricket::Candidates& candidates); |
| 408 | void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport); |
| 409 | void OnTransportStateChanged_n(cricket::IceTransportInternal* transport); |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 410 | void OnTransportCandidatePairChanged_n( |
| 411 | const cricket::CandidatePairChangeEvent& event); |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 412 | void OnDataChannelTransportNegotiated_n( |
| 413 | cricket::JsepTransport* transport, |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 414 | DataChannelTransportInterface* data_channel_transport); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 415 | |
| 416 | void UpdateAggregateStates_n(); |
| 417 | |
Sebastian Jansson | 1b83a9e | 2019-09-18 18:22:12 +0200 | [diff] [blame] | 418 | void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet, |
| 419 | int64_t packet_time_us); |
| 420 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 421 | void OnDtlsHandshakeError(rtc::SSLHandshakeError error); |
| 422 | |
| 423 | rtc::Thread* const signaling_thread_ = nullptr; |
| 424 | rtc::Thread* const network_thread_ = nullptr; |
| 425 | cricket::PortAllocator* const port_allocator_ = nullptr; |
Zach Stein | e20867f | 2018-08-02 13:20:15 -0700 | [diff] [blame] | 426 | AsyncResolverFactory* const async_resolver_factory_ = nullptr; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 427 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 428 | std::map<std::string, std::unique_ptr<cricket::JsepTransport>> |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 429 | jsep_transports_by_name_; |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 430 | // This keeps track of the mapping between media section |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 431 | // (BaseChannel/SctpTransport) and the JsepTransport underneath. |
| 432 | std::map<std::string, cricket::JsepTransport*> mid_to_transport_; |
Eldar Rello | d85ea75 | 2020-02-19 20:41:07 +0200 | [diff] [blame] | 433 | // Keep track of mids that have been mapped to transports. Used for rollback. |
| 434 | std::vector<std::string> pending_mids_ RTC_GUARDED_BY(network_thread_); |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 435 | // Aggregate states for Transports. |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 436 | // standardized_ice_connection_state_ is intended to replace |
| 437 | // ice_connection_state, see bugs.webrtc.org/9308 |
| 438 | cricket::IceConnectionState ice_connection_state_ = |
| 439 | cricket::kIceConnectionConnecting; |
| 440 | PeerConnectionInterface::IceConnectionState |
| 441 | standardized_ice_connection_state_ = |
| 442 | PeerConnectionInterface::kIceConnectionNew; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 443 | PeerConnectionInterface::PeerConnectionState combined_connection_state_ = |
| 444 | PeerConnectionInterface::PeerConnectionState::kNew; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 445 | cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew; |
| 446 | |
| 447 | Config config_; |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 448 | |
Anton Sukhanov | 316f3ac | 2019-05-23 15:50:38 -0700 | [diff] [blame] | 449 | // Early on in the call we don't know if datagram transport is going to be |
| 450 | // used, but we need to get the server-supported parameters to add to an SDP. |
| 451 | // This server datagram transport will be promoted to the used datagram |
| 452 | // transport after the local description is set, and the ownership will be |
| 453 | // transferred to the actual JsepTransport. This "offer" datagram transport is |
| 454 | // not created if it's done on the party that provides answer. This offer |
| 455 | // datagram transport is only created once at the beginning of the connection, |
| 456 | // and never again. |
| 457 | std::unique_ptr<DatagramTransportInterface> offer_datagram_transport_ = |
| 458 | nullptr; |
| 459 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 460 | const cricket::SessionDescription* local_desc_ = nullptr; |
| 461 | const cricket::SessionDescription* remote_desc_ = nullptr; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 462 | absl::optional<bool> initial_offerer_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 463 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 464 | absl::optional<cricket::ContentGroup> bundle_group_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 465 | |
| 466 | cricket::IceConfig ice_config_; |
| 467 | cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING; |
| 468 | uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); |
| 469 | rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| 470 | rtc::AsyncInvoker invoker_; |
| 471 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 472 | RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController); |
| 473 | }; |
| 474 | |
| 475 | } // namespace webrtc |
| 476 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 477 | #endif // PC_JSEP_TRANSPORT_CONTROLLER_H_ |