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