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