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" |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 22 | #include "api/media_transport_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "api/peer_connection_interface.h" |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 24 | #include "logging/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" |
| 27 | #include "p2p/base/p2p_transport_channel.h" |
| 28 | #include "p2p/base/transport_factory_interface.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" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame] | 38 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 39 | |
| 40 | namespace rtc { |
| 41 | class Thread; |
| 42 | class PacketTransportInternal; |
| 43 | } // namespace rtc |
| 44 | |
| 45 | namespace webrtc { |
| 46 | |
Steve Anton | d25828a | 2018-08-31 13:06:05 -0700 | [diff] [blame] | 47 | class JsepTransportController : public sigslot::has_slots<> { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 48 | public: |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 49 | // Used when the RtpTransport/DtlsTransport of the m= section is changed |
| 50 | // because the section is rejected or BUNDLE is enabled. |
| 51 | class Observer { |
| 52 | public: |
| 53 | virtual ~Observer() {} |
| 54 | |
| 55 | // Returns true if media associated with |mid| was successfully set up to be |
| 56 | // demultiplexed on |rtp_transport|. Could return false if two bundled m= |
| 57 | // sections use the same SSRC, for example. |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 58 | virtual bool OnTransportChanged( |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 59 | const std::string& mid, |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 60 | RtpTransportInternal* rtp_transport, |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 08:26:19 -0800 | [diff] [blame] | 61 | cricket::DtlsTransportInternal* dtls_transport, |
| 62 | MediaTransportInterface* media_transport) = 0; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 65 | struct Config { |
| 66 | // If |redetermine_role_on_ice_restart| is true, ICE role is redetermined |
| 67 | // upon setting a local transport description that indicates an ICE |
| 68 | // restart. |
| 69 | bool redetermine_role_on_ice_restart = true; |
| 70 | rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 71 | // |crypto_options| is used to determine if created DTLS transports |
| 72 | // negotiate GCM crypto suites or not. |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 73 | webrtc::CryptoOptions crypto_options; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 74 | PeerConnectionInterface::BundlePolicy bundle_policy = |
| 75 | PeerConnectionInterface::kBundlePolicyBalanced; |
| 76 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy = |
| 77 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 78 | bool disable_encryption = false; |
| 79 | bool enable_external_auth = false; |
| 80 | // Used to inject the ICE/DTLS transports created externally. |
| 81 | cricket::TransportFactoryInterface* external_transport_factory = nullptr; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 82 | Observer* transport_observer = nullptr; |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 83 | bool active_reset_srtp_params = false; |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 84 | RtcEventLog* event_log = nullptr; |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 85 | |
| 86 | // Optional media transport factory (experimental). If provided it will be |
| 87 | // used to create media_transport and will be used to send / receive |
| 88 | // audio and video frames instead of RTP. Note that currently |
| 89 | // media_transport co-exists with RTP / RTCP transports and uses the same |
| 90 | // underlying ICE transport. |
| 91 | MediaTransportFactory* media_transport_factory = nullptr; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | // The ICE related events are signaled on the |signaling_thread|. |
| 95 | // All the transport related methods are called on the |network_thread|. |
| 96 | JsepTransportController(rtc::Thread* signaling_thread, |
| 97 | rtc::Thread* network_thread, |
| 98 | cricket::PortAllocator* port_allocator, |
Zach Stein | e20867f | 2018-08-02 13:20:15 -0700 | [diff] [blame] | 99 | AsyncResolverFactory* async_resolver_factory, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 100 | Config config); |
| 101 | virtual ~JsepTransportController(); |
| 102 | |
| 103 | // The main method to be called; applies a description at the transport |
| 104 | // level, creating/destroying transport objects as needed and updating their |
| 105 | // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not |
| 106 | // yet? May make sense to in the future. |
| 107 | RTCError SetLocalDescription(SdpType type, |
| 108 | const cricket::SessionDescription* description); |
| 109 | |
| 110 | RTCError SetRemoteDescription(SdpType type, |
| 111 | const cricket::SessionDescription* description); |
| 112 | |
| 113 | // Get transports to be used for the provided |mid|. If bundling is enabled, |
| 114 | // calling GetRtpTransport for multiple MIDs may yield the same object. |
| 115 | RtpTransportInternal* GetRtpTransport(const std::string& mid) const; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 116 | cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid); |
| 117 | const cricket::DtlsTransportInternal* GetRtcpDtlsTransport( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 118 | const std::string& mid) const; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 119 | // Gets the externally sharable version of the DtlsTransport. |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame^] | 120 | rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid( |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 121 | const std::string& mid); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 122 | |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 123 | MediaTransportInterface* GetMediaTransport(const std::string& mid) const; |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 124 | MediaTransportState GetMediaTransportState(const std::string& mid) const; |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 125 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 126 | /********************* |
| 127 | * ICE-related methods |
| 128 | ********************/ |
| 129 | // This method is public to allow PeerConnection to update it from |
| 130 | // SetConfiguration. |
| 131 | void SetIceConfig(const cricket::IceConfig& config); |
| 132 | // Set the "needs-ice-restart" flag as described in JSEP. After the flag is |
| 133 | // set, offers should generate new ufrags/passwords until an ICE restart |
| 134 | // occurs. |
| 135 | void SetNeedsIceRestartFlag(); |
| 136 | // Returns true if the ICE restart flag above was set, and no ICE restart has |
| 137 | // occurred yet for this transport (by applying a local description with |
| 138 | // changed ufrag/password). If the transport has been deleted as a result of |
| 139 | // bundling, returns false. |
| 140 | bool NeedsIceRestart(const std::string& mid) const; |
| 141 | // Start gathering candidates for any new transports, or transports doing an |
| 142 | // ICE restart. |
| 143 | void MaybeStartGathering(); |
| 144 | RTCError AddRemoteCandidates( |
| 145 | const std::string& mid, |
| 146 | const std::vector<cricket::Candidate>& candidates); |
| 147 | RTCError RemoveRemoteCandidates( |
| 148 | const std::vector<cricket::Candidate>& candidates); |
| 149 | |
| 150 | /********************** |
| 151 | * DTLS-related methods |
| 152 | *********************/ |
| 153 | // Specifies the identity to use in this session. |
| 154 | // Can only be called once. |
| 155 | bool SetLocalCertificate( |
| 156 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
| 157 | rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate( |
| 158 | const std::string& mid) const; |
Taylor Brandstetter | c392866 | 2018-02-23 13:04:51 -0800 | [diff] [blame] | 159 | // Caller owns returned certificate chain. This method mainly exists for |
| 160 | // stats reporting. |
| 161 | std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 162 | const std::string& mid) const; |
| 163 | // Get negotiated role, if one has been negotiated. |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 164 | absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 165 | |
| 166 | // TODO(deadbeef): GetStats isn't const because all the way down to |
| 167 | // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not |
| 168 | // const. Fix this. |
| 169 | bool GetStats(const std::string& mid, cricket::TransportStats* stats); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 170 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 171 | bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; } |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 172 | |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 173 | void SetActiveResetSrtpParams(bool active_reset_srtp_params); |
| 174 | |
Piotr (Peter) Slatala | 97fc11f | 2018-10-18 12:57:59 -0700 | [diff] [blame] | 175 | // Allows to overwrite the settings from config. You may set or reset the |
| 176 | // media transport factory on the jsep transport controller, as long as you |
| 177 | // did not call 'GetMediaTransport' or 'MaybeCreateJsepTransport'. Once Jsep |
| 178 | // transport is created, you can't change this setting. |
| 179 | void SetMediaTransportFactory(MediaTransportFactory* media_transport_factory); |
| 180 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 181 | // All of these signals are fired on the signaling thread. |
| 182 | |
| 183 | // If any transport failed => failed, |
| 184 | // Else if all completed => completed, |
| 185 | // Else if all connected => connected, |
| 186 | // Else => connecting |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 187 | sigslot::signal1<cricket::IceConnectionState> SignalIceConnectionState; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 188 | |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 189 | sigslot::signal1<PeerConnectionInterface::PeerConnectionState> |
| 190 | SignalConnectionState; |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 191 | sigslot::signal1<PeerConnectionInterface::IceConnectionState> |
| 192 | SignalStandardizedIceConnectionState; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 193 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 194 | // If all transports done gathering => complete, |
| 195 | // Else if any are gathering => gathering, |
| 196 | // Else => new |
| 197 | sigslot::signal1<cricket::IceGatheringState> SignalIceGatheringState; |
| 198 | |
| 199 | // (mid, candidates) |
| 200 | sigslot::signal2<const std::string&, const std::vector<cricket::Candidate>&> |
| 201 | SignalIceCandidatesGathered; |
| 202 | |
| 203 | sigslot::signal1<const std::vector<cricket::Candidate>&> |
| 204 | SignalIceCandidatesRemoved; |
| 205 | |
| 206 | sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError; |
| 207 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 208 | sigslot::signal<> SignalMediaTransportStateChanged; |
| 209 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 210 | private: |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 211 | RTCError ApplyDescription_n(bool local, |
| 212 | SdpType type, |
| 213 | const cricket::SessionDescription* description); |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 214 | RTCError ValidateAndMaybeUpdateBundleGroup( |
| 215 | bool local, |
| 216 | SdpType type, |
| 217 | const cricket::SessionDescription* description); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 218 | RTCError ValidateContent(const cricket::ContentInfo& content_info); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 219 | |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 220 | void HandleRejectedContent(const cricket::ContentInfo& content_info, |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 221 | const cricket::SessionDescription* description); |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 222 | bool HandleBundledContent(const cricket::ContentInfo& content_info); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 223 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 224 | bool SetTransportForMid(const std::string& mid, |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 225 | cricket::JsepTransport* jsep_transport); |
| 226 | void RemoveTransportForMid(const std::string& mid); |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 227 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 228 | cricket::JsepTransportDescription CreateJsepTransportDescription( |
| 229 | cricket::ContentInfo content_info, |
| 230 | cricket::TransportInfo transport_info, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 231 | const std::vector<int>& encrypted_extension_ids, |
| 232 | int rtp_abs_sendtime_extn_id); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 233 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 234 | absl::optional<std::string> bundled_mid() const { |
| 235 | absl::optional<std::string> bundled_mid; |
Taylor Brandstetter | 0ab5651 | 2018-04-12 10:30:48 -0700 | [diff] [blame] | 236 | if (bundle_group_ && bundle_group_->FirstContentName()) { |
| 237 | bundled_mid = *(bundle_group_->FirstContentName()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 238 | } |
| 239 | return bundled_mid; |
| 240 | } |
| 241 | |
| 242 | bool IsBundled(const std::string& mid) const { |
| 243 | return bundle_group_ && bundle_group_->HasContentName(mid); |
| 244 | } |
| 245 | |
| 246 | bool ShouldUpdateBundleGroup(SdpType type, |
| 247 | const cricket::SessionDescription* description); |
| 248 | |
| 249 | std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle( |
| 250 | const cricket::SessionDescription* description); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 251 | std::vector<int> GetEncryptedHeaderExtensionIds( |
| 252 | const cricket::ContentInfo& content_info); |
| 253 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 254 | int GetRtpAbsSendTimeHeaderExtensionId( |
| 255 | const cricket::ContentInfo& content_info); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 256 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 257 | // This method takes the BUNDLE group into account. If the JsepTransport is |
| 258 | // destroyed because of BUNDLE, it would return the transport which other |
| 259 | // transports are bundled on (In current implementation, it is the first |
| 260 | // content in the BUNDLE group). |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 261 | const cricket::JsepTransport* GetJsepTransportForMid( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 262 | const std::string& mid) const; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 263 | cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 264 | |
| 265 | // Get the JsepTransport without considering the BUNDLE group. Return nullptr |
| 266 | // if the JsepTransport is destroyed. |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 267 | const cricket::JsepTransport* GetJsepTransportByName( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 268 | const std::string& transport_name) const; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 269 | cricket::JsepTransport* GetJsepTransportByName( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 270 | const std::string& transport_name); |
| 271 | |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 272 | // Creates jsep transport. Noop if transport is already created. |
| 273 | // Transport is created either during SetLocalDescription (|local| == true) or |
| 274 | // during SetRemoteDescription (|local| == false). Passing |local| helps to |
| 275 | // differentiate initiator (caller) from answerer (callee). |
| 276 | RTCError MaybeCreateJsepTransport(bool local, |
| 277 | const cricket::ContentInfo& content_info); |
Piotr (Peter) Slatala | 47dfdca | 2018-11-16 14:13:58 -0800 | [diff] [blame] | 278 | |
| 279 | // Creates media transport if config wants to use it, and pre-shared key is |
| 280 | // provided in content info. It modifies the config to disable media transport |
| 281 | // if pre-shared key is not provided. |
| 282 | std::unique_ptr<webrtc::MediaTransportInterface> MaybeCreateMediaTransport( |
| 283 | const cricket::ContentInfo& content_info, |
| 284 | bool local, |
| 285 | cricket::IceTransportInternal* ice_transport); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 286 | void MaybeDestroyJsepTransport(const std::string& mid); |
| 287 | void DestroyAllJsepTransports_n(); |
| 288 | |
| 289 | void SetIceRole_n(cricket::IceRole ice_role); |
| 290 | |
| 291 | cricket::IceRole DetermineIceRole( |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 292 | cricket::JsepTransport* jsep_transport, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 293 | const cricket::TransportInfo& transport_info, |
| 294 | SdpType type, |
| 295 | bool local); |
| 296 | |
| 297 | std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport( |
Piotr (Peter) Slatala | 2b5baee | 2019-01-16 08:25:21 -0800 | [diff] [blame] | 298 | std::unique_ptr<cricket::IceTransportInternal> ice); |
| 299 | std::unique_ptr<cricket::IceTransportInternal> CreateIceTransport( |
| 300 | const std::string transport_name, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 301 | bool rtcp); |
| 302 | |
| 303 | std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport( |
| 304 | const std::string& transport_name, |
| 305 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 306 | rtc::PacketTransportInternal* rtcp_packet_transport); |
| 307 | std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport( |
| 308 | const std::string& transport_name, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 309 | cricket::DtlsTransportInternal* rtp_dtls_transport, |
| 310 | cricket::DtlsTransportInternal* rtcp_dtls_transport); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 311 | std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport( |
| 312 | const std::string& transport_name, |
| 313 | cricket::DtlsTransportInternal* rtp_dtls_transport, |
| 314 | cricket::DtlsTransportInternal* rtcp_dtls_transport); |
| 315 | |
| 316 | // Collect all the DtlsTransports, including RTP and RTCP, from the |
| 317 | // JsepTransports. JsepTransportController can iterate all the DtlsTransports |
| 318 | // and update the aggregate states. |
| 319 | std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports(); |
| 320 | |
| 321 | // Handlers for signals from Transport. |
| 322 | void OnTransportWritableState_n(rtc::PacketTransportInternal* transport); |
| 323 | void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport); |
| 324 | void OnTransportGatheringState_n(cricket::IceTransportInternal* transport); |
| 325 | void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport, |
| 326 | const cricket::Candidate& candidate); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 327 | void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport, |
| 328 | const cricket::Candidates& candidates); |
| 329 | void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport); |
| 330 | void OnTransportStateChanged_n(cricket::IceTransportInternal* transport); |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 331 | void OnMediaTransportStateChanged_n(); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 332 | |
| 333 | void UpdateAggregateStates_n(); |
| 334 | |
| 335 | void OnDtlsHandshakeError(rtc::SSLHandshakeError error); |
| 336 | |
| 337 | rtc::Thread* const signaling_thread_ = nullptr; |
| 338 | rtc::Thread* const network_thread_ = nullptr; |
| 339 | cricket::PortAllocator* const port_allocator_ = nullptr; |
Zach Stein | e20867f | 2018-08-02 13:20:15 -0700 | [diff] [blame] | 340 | AsyncResolverFactory* const async_resolver_factory_ = nullptr; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 341 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 342 | std::map<std::string, std::unique_ptr<cricket::JsepTransport>> |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 343 | jsep_transports_by_name_; |
Zhi Huang | d2248f8 | 2018-04-10 14:41:03 -0700 | [diff] [blame] | 344 | // This keeps track of the mapping between media section |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 345 | // (BaseChannel/SctpTransport) and the JsepTransport underneath. |
| 346 | std::map<std::string, cricket::JsepTransport*> mid_to_transport_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 347 | |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 348 | // Aggregate states for Transports. |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 349 | // standardized_ice_connection_state_ is intended to replace |
| 350 | // ice_connection_state, see bugs.webrtc.org/9308 |
| 351 | cricket::IceConnectionState ice_connection_state_ = |
| 352 | cricket::kIceConnectionConnecting; |
| 353 | PeerConnectionInterface::IceConnectionState |
| 354 | standardized_ice_connection_state_ = |
| 355 | PeerConnectionInterface::kIceConnectionNew; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 356 | PeerConnectionInterface::PeerConnectionState combined_connection_state_ = |
| 357 | PeerConnectionInterface::PeerConnectionState::kNew; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 358 | cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew; |
| 359 | |
| 360 | Config config_; |
| 361 | const cricket::SessionDescription* local_desc_ = nullptr; |
| 362 | const cricket::SessionDescription* remote_desc_ = nullptr; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 363 | absl::optional<bool> initial_offerer_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 364 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 365 | absl::optional<cricket::ContentGroup> bundle_group_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 366 | |
| 367 | cricket::IceConfig ice_config_; |
| 368 | cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING; |
| 369 | uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); |
| 370 | rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| 371 | rtc::AsyncInvoker invoker_; |
| 372 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 373 | RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController); |
| 374 | }; |
| 375 | |
| 376 | } // namespace webrtc |
| 377 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 378 | #endif // PC_JSEP_TRANSPORT_CONTROLLER_H_ |