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" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "media/sctp/sctp_transport_internal.h" |
| 26 | #include "p2p/base/dtls_transport.h" |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 27 | #include "p2p/base/dtls_transport_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "p2p/base/p2p_transport_channel.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 29 | #include "pc/channel.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 30 | #include "pc/dtls_srtp_transport.h" |
| 31 | #include "pc/dtls_transport.h" |
| 32 | #include "pc/jsep_transport.h" |
| 33 | #include "pc/rtp_transport.h" |
| 34 | #include "pc/srtp_transport.h" |
| 35 | #include "rtc_base/async_invoker.h" |
| 36 | #include "rtc_base/constructor_magic.h" |
| 37 | #include "rtc_base/ref_counted_object.h" |
Mirko Bonadei | 3d25935 | 2020-10-23 12:04:40 +0200 | [diff] [blame] | 38 | #include "rtc_base/callback_list.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; |
Harald Alvestrand | 133c052 | 2021-01-29 14:27:12 +0000 | [diff] [blame^] | 101 | // Initial value for whether DtlsTransport reset causes a reset |
| 102 | // of SRTP parameters. |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 103 | bool active_reset_srtp_params = false; |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 104 | RtcEventLog* event_log = nullptr; |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 105 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 106 | // Factory for SCTP transports. |
Per Kjellander | 2bca008 | 2020-08-28 09:15:15 +0200 | [diff] [blame] | 107 | SctpTransportFactoryInterface* sctp_factory = nullptr; |
Lahiru Ginnaliya Gamathige | 70f9e24 | 2021-01-27 23:32:46 -0800 | [diff] [blame] | 108 | std::function<void(const rtc::SSLHandshakeError)> on_dtls_handshake_error_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | // The ICE related events are signaled on the |signaling_thread|. |
| 112 | // All the transport related methods are called on the |network_thread|. |
| 113 | JsepTransportController(rtc::Thread* signaling_thread, |
| 114 | rtc::Thread* network_thread, |
| 115 | cricket::PortAllocator* port_allocator, |
Zach Stein | e20867f | 2018-08-02 13:20:15 -0700 | [diff] [blame] | 116 | AsyncResolverFactory* async_resolver_factory, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 117 | Config config); |
| 118 | virtual ~JsepTransportController(); |
| 119 | |
| 120 | // The main method to be called; applies a description at the transport |
| 121 | // level, creating/destroying transport objects as needed and updating their |
| 122 | // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not |
| 123 | // yet? May make sense to in the future. |
| 124 | RTCError SetLocalDescription(SdpType type, |
| 125 | const cricket::SessionDescription* description); |
| 126 | |
| 127 | RTCError SetRemoteDescription(SdpType type, |
| 128 | const cricket::SessionDescription* description); |
| 129 | |
| 130 | // Get transports to be used for the provided |mid|. If bundling is enabled, |
| 131 | // calling GetRtpTransport for multiple MIDs may yield the same object. |
| 132 | RtpTransportInternal* GetRtpTransport(const std::string& mid) const; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 133 | cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid); |
| 134 | const cricket::DtlsTransportInternal* GetRtcpDtlsTransport( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 135 | const std::string& mid) const; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 136 | // Gets the externally sharable version of the DtlsTransport. |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 137 | rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid( |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 138 | const std::string& mid); |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 139 | rtc::scoped_refptr<SctpTransport> GetSctpTransport( |
| 140 | const std::string& mid) const; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 141 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 142 | DataChannelTransportInterface* GetDataChannelTransport( |
Anton Sukhanov | 316f3ac | 2019-05-23 15:50:38 -0700 | [diff] [blame] | 143 | const std::string& mid) const; |
| 144 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 145 | /********************* |
| 146 | * ICE-related methods |
| 147 | ********************/ |
| 148 | // This method is public to allow PeerConnection to update it from |
| 149 | // SetConfiguration. |
| 150 | void SetIceConfig(const cricket::IceConfig& config); |
| 151 | // Set the "needs-ice-restart" flag as described in JSEP. After the flag is |
| 152 | // set, offers should generate new ufrags/passwords until an ICE restart |
| 153 | // occurs. |
| 154 | void SetNeedsIceRestartFlag(); |
| 155 | // Returns true if the ICE restart flag above was set, and no ICE restart has |
| 156 | // occurred yet for this transport (by applying a local description with |
| 157 | // changed ufrag/password). If the transport has been deleted as a result of |
| 158 | // bundling, returns false. |
| 159 | bool NeedsIceRestart(const std::string& mid) const; |
| 160 | // Start gathering candidates for any new transports, or transports doing an |
| 161 | // ICE restart. |
| 162 | void MaybeStartGathering(); |
| 163 | RTCError AddRemoteCandidates( |
| 164 | const std::string& mid, |
| 165 | const std::vector<cricket::Candidate>& candidates); |
| 166 | RTCError RemoveRemoteCandidates( |
| 167 | const std::vector<cricket::Candidate>& candidates); |
| 168 | |
| 169 | /********************** |
| 170 | * DTLS-related methods |
| 171 | *********************/ |
| 172 | // Specifies the identity to use in this session. |
| 173 | // Can only be called once. |
| 174 | bool SetLocalCertificate( |
| 175 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
| 176 | rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate( |
| 177 | const std::string& mid) const; |
Taylor Brandstetter | c392866 | 2018-02-23 13:04:51 -0800 | [diff] [blame] | 178 | // Caller owns returned certificate chain. This method mainly exists for |
| 179 | // stats reporting. |
| 180 | std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 181 | const std::string& mid) const; |
| 182 | // Get negotiated role, if one has been negotiated. |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 183 | absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 184 | |
| 185 | // TODO(deadbeef): GetStats isn't const because all the way down to |
| 186 | // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not |
| 187 | // const. Fix this. |
| 188 | bool GetStats(const std::string& mid, cricket::TransportStats* stats); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 189 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 190 | bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; } |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 191 | |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 192 | void SetActiveResetSrtpParams(bool active_reset_srtp_params); |
| 193 | |
Eldar Rello | d85ea75 | 2020-02-19 20:41:07 +0200 | [diff] [blame] | 194 | // For now the rollback only removes mid to transport mappings |
Eldar Rello | 353a718 | 2019-11-25 18:49:44 +0200 | [diff] [blame] | 195 | // and deletes unused transports, but doesn't consider anything more complex. |
Eldar Rello | d85ea75 | 2020-02-19 20:41:07 +0200 | [diff] [blame] | 196 | void RollbackTransports(); |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 197 | |
Lahiru Ginnaliya Gamathige | 5eb527c | 2021-01-18 23:32:22 -0800 | [diff] [blame] | 198 | // F: void(const std::string&, const std::vector<cricket::Candidate>&) |
| 199 | template <typename F> |
| 200 | void SubscribeIceCandidateGathered(F&& callback) { |
| 201 | signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback)); |
| 202 | } |
| 203 | |
| 204 | // F: void(cricket::IceConnectionState) |
| 205 | template <typename F> |
| 206 | void SubscribeIceConnectionState(F&& callback) { |
| 207 | signal_ice_connection_state_.AddReceiver(std::forward<F>(callback)); |
| 208 | } |
| 209 | |
| 210 | // F: void(PeerConnectionInterface::PeerConnectionState) |
| 211 | template <typename F> |
| 212 | void SubscribeConnectionState(F&& callback) { |
| 213 | signal_connection_state_.AddReceiver(std::forward<F>(callback)); |
| 214 | } |
| 215 | |
| 216 | // F: void(PeerConnectionInterface::IceConnectionState) |
| 217 | template <typename F> |
| 218 | void SubscribeStandardizedIceConnectionState(F&& callback) { |
| 219 | signal_standardized_ice_connection_state_.AddReceiver( |
| 220 | std::forward<F>(callback)); |
| 221 | } |
| 222 | |
| 223 | // F: void(cricket::IceGatheringState) |
| 224 | template <typename F> |
| 225 | void SubscribeIceGatheringState(F&& callback) { |
| 226 | signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback)); |
| 227 | } |
| 228 | |
| 229 | // F: void(const cricket::IceCandidateErrorEvent&) |
| 230 | template <typename F> |
| 231 | void SubscribeIceCandidateError(F&& callback) { |
| 232 | signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback)); |
| 233 | } |
| 234 | |
| 235 | // F: void(const std::vector<cricket::Candidate>&) |
| 236 | template <typename F> |
| 237 | void SubscribeIceCandidatesRemoved(F&& callback) { |
| 238 | signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback)); |
| 239 | } |
| 240 | |
| 241 | // F: void(const cricket::CandidatePairChangeEvent&) |
| 242 | template <typename F> |
| 243 | void SubscribeIceCandidatePairChanged(F&& callback) { |
| 244 | signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback)); |
| 245 | } |
| 246 | |
| 247 | private: |
| 248 | // All of these callbacks are fired on the signaling thread. |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 249 | |
| 250 | // If any transport failed => failed, |
| 251 | // Else if all completed => completed, |
| 252 | // Else if all connected => connected, |
| 253 | // Else => connecting |
Lahiru Ginnaliya Gamathige | 5eb527c | 2021-01-18 23:32:22 -0800 | [diff] [blame] | 254 | CallbackList<cricket::IceConnectionState> signal_ice_connection_state_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 255 | |
Lahiru Ginnaliya Gamathige | 5eb527c | 2021-01-18 23:32:22 -0800 | [diff] [blame] | 256 | CallbackList<PeerConnectionInterface::PeerConnectionState> |
| 257 | signal_connection_state_; |
Lahiru Ginnaliya Gamathige | e99c68d | 2020-09-30 14:33:45 -0700 | [diff] [blame] | 258 | |
Lahiru Ginnaliya Gamathige | 5eb527c | 2021-01-18 23:32:22 -0800 | [diff] [blame] | 259 | CallbackList<PeerConnectionInterface::IceConnectionState> |
| 260 | signal_standardized_ice_connection_state_; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 261 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 262 | // If all transports done gathering => complete, |
| 263 | // Else if any are gathering => gathering, |
| 264 | // Else => new |
Lahiru Ginnaliya Gamathige | 5eb527c | 2021-01-18 23:32:22 -0800 | [diff] [blame] | 265 | CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 266 | |
Lahiru Ginnaliya Gamathige | 5eb527c | 2021-01-18 23:32:22 -0800 | [diff] [blame] | 267 | // [mid, candidates] |
| 268 | CallbackList<const std::string&, const std::vector<cricket::Candidate>&> |
| 269 | signal_ice_candidates_gathered_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 270 | |
Lahiru Ginnaliya Gamathige | 5eb527c | 2021-01-18 23:32:22 -0800 | [diff] [blame] | 271 | CallbackList<const cricket::IceCandidateErrorEvent&> |
| 272 | signal_ice_candidate_error_; |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 273 | |
Lahiru Ginnaliya Gamathige | 5eb527c | 2021-01-18 23:32:22 -0800 | [diff] [blame] | 274 | CallbackList<const std::vector<cricket::Candidate>&> |
| 275 | signal_ice_candidates_removed_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 276 | |
Lahiru Ginnaliya Gamathige | 5eb527c | 2021-01-18 23:32:22 -0800 | [diff] [blame] | 277 | CallbackList<const cricket::CandidatePairChangeEvent&> |
| 278 | signal_ice_candidate_pair_changed_; |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 279 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 280 | RTCError ApplyDescription_n(bool local, |
| 281 | SdpType type, |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 282 | const cricket::SessionDescription* description) |
| 283 | RTC_RUN_ON(network_thread_); |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 284 | RTCError ValidateAndMaybeUpdateBundleGroup( |
| 285 | bool local, |
| 286 | SdpType type, |
| 287 | const cricket::SessionDescription* description); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 288 | RTCError ValidateContent(const cricket::ContentInfo& content_info); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 289 | |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 290 | void HandleRejectedContent(const cricket::ContentInfo& content_info, |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 291 | const cricket::SessionDescription* description) |
| 292 | RTC_RUN_ON(network_thread_); |
| 293 | bool HandleBundledContent(const cricket::ContentInfo& content_info) |
| 294 | RTC_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 295 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 296 | bool SetTransportForMid(const std::string& mid, |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 297 | cricket::JsepTransport* jsep_transport); |
| 298 | void RemoveTransportForMid(const std::string& mid); |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 299 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 300 | cricket::JsepTransportDescription CreateJsepTransportDescription( |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 301 | const cricket::ContentInfo& content_info, |
| 302 | const cricket::TransportInfo& transport_info, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 303 | const std::vector<int>& encrypted_extension_ids, |
Niels Möller | dc80aaf | 2020-06-18 10:10:17 +0200 | [diff] [blame] | 304 | int rtp_abs_sendtime_extn_id); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 305 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 306 | absl::optional<std::string> bundled_mid() const { |
| 307 | absl::optional<std::string> bundled_mid; |
Taylor Brandstetter | 0ab5651 | 2018-04-12 10:30:48 -0700 | [diff] [blame] | 308 | if (bundle_group_ && bundle_group_->FirstContentName()) { |
| 309 | bundled_mid = *(bundle_group_->FirstContentName()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 310 | } |
| 311 | return bundled_mid; |
| 312 | } |
| 313 | |
| 314 | bool IsBundled(const std::string& mid) const { |
| 315 | return bundle_group_ && bundle_group_->HasContentName(mid); |
| 316 | } |
| 317 | |
| 318 | bool ShouldUpdateBundleGroup(SdpType type, |
| 319 | const cricket::SessionDescription* description); |
| 320 | |
| 321 | std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle( |
| 322 | const cricket::SessionDescription* description); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 323 | std::vector<int> GetEncryptedHeaderExtensionIds( |
| 324 | const cricket::ContentInfo& content_info); |
| 325 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 326 | int GetRtpAbsSendTimeHeaderExtensionId( |
| 327 | const cricket::ContentInfo& content_info); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 328 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 329 | // This method takes the BUNDLE group into account. If the JsepTransport is |
| 330 | // destroyed because of BUNDLE, it would return the transport which other |
| 331 | // transports are bundled on (In current implementation, it is the first |
| 332 | // content in the BUNDLE group). |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 333 | const cricket::JsepTransport* GetJsepTransportForMid( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 334 | const std::string& mid) const; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 335 | cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 336 | |
| 337 | // Get the JsepTransport without considering the BUNDLE group. Return nullptr |
| 338 | // if the JsepTransport is destroyed. |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 339 | const cricket::JsepTransport* GetJsepTransportByName( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 340 | const std::string& transport_name) const; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 341 | cricket::JsepTransport* GetJsepTransportByName( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 342 | const std::string& transport_name); |
| 343 | |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 344 | // Creates jsep transport. Noop if transport is already created. |
| 345 | // Transport is created either during SetLocalDescription (|local| == true) or |
| 346 | // during SetRemoteDescription (|local| == false). Passing |local| helps to |
| 347 | // differentiate initiator (caller) from answerer (callee). |
Piotr (Peter) Slatala | 105ded3 | 2019-02-27 14:26:15 -0800 | [diff] [blame] | 348 | RTCError MaybeCreateJsepTransport( |
| 349 | bool local, |
| 350 | const cricket::ContentInfo& content_info, |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 351 | const cricket::SessionDescription& description) |
| 352 | RTC_RUN_ON(network_thread_); |
Piotr (Peter) Slatala | 47dfdca | 2018-11-16 14:13:58 -0800 | [diff] [blame] | 353 | |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 354 | void MaybeDestroyJsepTransport(const std::string& mid) |
| 355 | RTC_RUN_ON(network_thread_); |
| 356 | void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 357 | |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 358 | void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 359 | |
| 360 | cricket::IceRole DetermineIceRole( |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 361 | cricket::JsepTransport* jsep_transport, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 362 | const cricket::TransportInfo& transport_info, |
| 363 | SdpType type, |
| 364 | bool local); |
| 365 | |
| 366 | std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport( |
Anton Sukhanov | ac6c096 | 2019-07-10 15:44:56 -0700 | [diff] [blame] | 367 | const cricket::ContentInfo& content_info, |
Niels Möller | 2a70703 | 2020-06-16 16:39:13 +0200 | [diff] [blame] | 368 | cricket::IceTransportInternal* ice); |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 369 | rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport( |
| 370 | const std::string& transport_name, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 371 | bool rtcp); |
| 372 | |
| 373 | std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport( |
| 374 | const std::string& transport_name, |
| 375 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 376 | rtc::PacketTransportInternal* rtcp_packet_transport); |
| 377 | std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport( |
| 378 | const std::string& transport_name, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 379 | cricket::DtlsTransportInternal* rtp_dtls_transport, |
| 380 | cricket::DtlsTransportInternal* rtcp_dtls_transport); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 381 | std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport( |
| 382 | const std::string& transport_name, |
| 383 | cricket::DtlsTransportInternal* rtp_dtls_transport, |
| 384 | cricket::DtlsTransportInternal* rtcp_dtls_transport); |
| 385 | |
| 386 | // Collect all the DtlsTransports, including RTP and RTCP, from the |
| 387 | // JsepTransports. JsepTransportController can iterate all the DtlsTransports |
| 388 | // and update the aggregate states. |
| 389 | std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports(); |
| 390 | |
| 391 | // Handlers for signals from Transport. |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 392 | void OnTransportWritableState_n(rtc::PacketTransportInternal* transport) |
| 393 | RTC_RUN_ON(network_thread_); |
| 394 | void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport) |
| 395 | RTC_RUN_ON(network_thread_); |
| 396 | void OnTransportGatheringState_n(cricket::IceTransportInternal* transport) |
| 397 | RTC_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 398 | void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport, |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 399 | const cricket::Candidate& candidate) |
| 400 | RTC_RUN_ON(network_thread_); |
| 401 | void OnTransportCandidateError_n(cricket::IceTransportInternal* transport, |
| 402 | const cricket::IceCandidateErrorEvent& event) |
| 403 | RTC_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 404 | void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport, |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 405 | const cricket::Candidates& candidates) |
| 406 | RTC_RUN_ON(network_thread_); |
| 407 | void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport) |
| 408 | RTC_RUN_ON(network_thread_); |
| 409 | void OnTransportStateChanged_n(cricket::IceTransportInternal* transport) |
| 410 | RTC_RUN_ON(network_thread_); |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 411 | void OnTransportCandidatePairChanged_n( |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 412 | const cricket::CandidatePairChangeEvent& event) |
| 413 | RTC_RUN_ON(network_thread_); |
| 414 | void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 415 | |
Sebastian Jansson | 1b83a9e | 2019-09-18 18:22:12 +0200 | [diff] [blame] | 416 | void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet, |
Niels Möller | 5cf0ef0 | 2021-01-18 14:00:36 +0100 | [diff] [blame] | 417 | int64_t packet_time_us) |
| 418 | RTC_RUN_ON(network_thread_); |
Sebastian Jansson | 1b83a9e | 2019-09-18 18:22:12 +0200 | [diff] [blame] | 419 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 420 | void OnDtlsHandshakeError(rtc::SSLHandshakeError error); |
| 421 | |
| 422 | rtc::Thread* const signaling_thread_ = nullptr; |
| 423 | rtc::Thread* const network_thread_ = nullptr; |
| 424 | cricket::PortAllocator* const port_allocator_ = nullptr; |
Zach Stein | e20867f | 2018-08-02 13:20:15 -0700 | [diff] [blame] | 425 | AsyncResolverFactory* const async_resolver_factory_ = nullptr; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 426 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 427 | std::map<std::string, std::unique_ptr<cricket::JsepTransport>> |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 428 | jsep_transports_by_name_; |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 429 | // This keeps track of the mapping between media section |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 430 | // (BaseChannel/SctpTransport) and the JsepTransport underneath. |
| 431 | std::map<std::string, cricket::JsepTransport*> mid_to_transport_; |
Eldar Rello | d85ea75 | 2020-02-19 20:41:07 +0200 | [diff] [blame] | 432 | // Keep track of mids that have been mapped to transports. Used for rollback. |
| 433 | std::vector<std::string> pending_mids_ RTC_GUARDED_BY(network_thread_); |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 434 | // Aggregate states for Transports. |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 435 | // standardized_ice_connection_state_ is intended to replace |
| 436 | // ice_connection_state, see bugs.webrtc.org/9308 |
| 437 | cricket::IceConnectionState ice_connection_state_ = |
| 438 | cricket::kIceConnectionConnecting; |
| 439 | PeerConnectionInterface::IceConnectionState |
| 440 | standardized_ice_connection_state_ = |
| 441 | PeerConnectionInterface::kIceConnectionNew; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 442 | PeerConnectionInterface::PeerConnectionState combined_connection_state_ = |
| 443 | PeerConnectionInterface::PeerConnectionState::kNew; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 444 | cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew; |
| 445 | |
Harald Alvestrand | 133c052 | 2021-01-29 14:27:12 +0000 | [diff] [blame^] | 446 | const Config config_; |
| 447 | bool active_reset_srtp_params_ RTC_GUARDED_BY(network_thread_); |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 448 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 449 | const cricket::SessionDescription* local_desc_ = nullptr; |
| 450 | const cricket::SessionDescription* remote_desc_ = nullptr; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 451 | absl::optional<bool> initial_offerer_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 452 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 453 | absl::optional<cricket::ContentGroup> bundle_group_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 454 | |
| 455 | cricket::IceConfig ice_config_; |
| 456 | cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING; |
| 457 | uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); |
| 458 | rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| 459 | rtc::AsyncInvoker invoker_; |
| 460 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 461 | RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController); |
| 462 | }; |
| 463 | |
| 464 | } // namespace webrtc |
| 465 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 466 | #endif // PC_JSEP_TRANSPORT_CONTROLLER_H_ |