blob: f123997ae17221e3dced947a8cff8b77a17be947 [file] [log] [blame]
Zhi Huange818b6e2018-02-22 15:26:27 -08001/*
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 Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_JSEP_TRANSPORT_CONTROLLER_H_
12#define PC_JSEP_TRANSPORT_CONTROLLER_H_
Zhi Huange818b6e2018-02-22 15:26:27 -080013
14#include <map>
15#include <memory>
16#include <string>
17#include <utility>
18#include <vector>
19
20#include "api/candidate.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/crypto/crypto_options.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080022#include "api/ice_transport_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/peer_connection_interface.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020024#include "api/rtc_event_log/rtc_event_log.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "media/sctp/sctp_transport_internal.h"
26#include "p2p/base/dtls_transport.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080027#include "p2p/base/dtls_transport_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "p2p/base/p2p_transport_channel.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080029#include "pc/channel.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#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 Bonadei3d259352020-10-23 12:04:40 +020038#include "rtc_base/callback_list.h"
Artem Titove41c4332018-07-25 15:04:28 +020039#include "rtc_base/third_party/sigslot/sigslot.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080040
41namespace rtc {
42class Thread;
43class PacketTransportInternal;
44} // namespace rtc
45
46namespace webrtc {
47
Steve Antond25828a2018-08-31 13:06:05 -070048class JsepTransportController : public sigslot::has_slots<> {
Zhi Huange818b6e2018-02-22 15:26:27 -080049 public:
Zhi Huang365381f2018-04-13 16:44:34 -070050 // 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 Mellemb689af42019-08-21 10:44:59 -070059 //
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 Brandstettercbaa2542018-04-16 16:42:14 -070070 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 16:44:34 -070071 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -070072 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +010073 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -070074 DataChannelTransportInterface* data_channel_transport) = 0;
Zhi Huang365381f2018-04-13 16:44:34 -070075 };
76
Zhi Huange818b6e2018-02-22 15:26:27 -080077 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 Wrighta54daf12018-10-11 15:33:17 -070085 webrtc::CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 15:26:27 -080086 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 Wang25ec8882019-11-15 12:33:05 -080093 webrtc::IceTransportFactory* ice_transport_factory = nullptr;
94 cricket::DtlsTransportFactory* dtls_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 16:44:34 -070095 Observer* transport_observer = nullptr;
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +020096 // 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 Huangb57e1692018-06-12 11:41:11 -0700101 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-11 20:15:46 -0700102 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700103
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700104 // Factory for SCTP transports.
Per Kjellander2bca0082020-08-28 09:15:15 +0200105 SctpTransportFactoryInterface* sctp_factory = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800106 };
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 Steine20867f2018-08-02 13:20:15 -0700113 AsyncResolverFactory* async_resolver_factory,
Zhi Huange818b6e2018-02-22 15:26:27 -0800114 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 Alvestrandad88c882018-11-28 16:47:46 +0100130 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
131 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800132 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100133 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100134 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100135 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700136 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
137 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800138
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700139 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700140 const std::string& mid) const;
141
Zhi Huange818b6e2018-02-22 15:26:27 -0800142 /*********************
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 Brandstetterc3928662018-02-23 13:04:51 -0800175 // Caller owns returned certificate chain. This method mainly exists for
176 // stats reporting.
177 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800178 const std::string& mid) const;
179 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200180 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800181
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 Huange818b6e2018-02-22 15:26:27 -0800186
Zhi Huange830e682018-03-30 10:48:35 -0700187 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700188
Zhi Huangb57e1692018-06-12 11:41:11 -0700189 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
190
Eldar Rellod85ea752020-02-19 20:41:07 +0200191 // For now the rollback only removes mid to transport mappings
Eldar Rello353a7182019-11-25 18:49:44 +0200192 // and deletes unused transports, but doesn't consider anything more complex.
Eldar Rellod85ea752020-02-19 20:41:07 +0200193 void RollbackTransports();
Eldar Rello5ab79e62019-10-09 18:29:44 +0300194
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800195 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 Huange818b6e2018-02-22 15:26:27 -0800248
249 // If any transport failed => failed,
250 // Else if all completed => completed,
251 // Else if all connected => connected,
252 // Else => connecting
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800253 CallbackList<cricket::IceConnectionState> signal_ice_connection_state_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800254
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800255 CallbackList<PeerConnectionInterface::PeerConnectionState>
256 signal_connection_state_;
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 14:33:45 -0700257
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800258 CallbackList<PeerConnectionInterface::IceConnectionState>
259 signal_standardized_ice_connection_state_;
Jonas Olsson635474e2018-10-18 15:58:17 +0200260
Zhi Huange818b6e2018-02-22 15:26:27 -0800261 // If all transports done gathering => complete,
262 // Else if any are gathering => gathering,
263 // Else => new
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800264 CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800265
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800266 // [mid, candidates]
267 CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
268 signal_ice_candidates_gathered_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800269
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800270 CallbackList<const cricket::IceCandidateErrorEvent&>
271 signal_ice_candidate_error_;
Eldar Relloda13ea22019-06-01 12:23:43 +0300272
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800273 CallbackList<const std::vector<cricket::Candidate>&>
274 signal_ice_candidates_removed_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800275
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800276 CallbackList<const cricket::CandidatePairChangeEvent&>
277 signal_ice_candidate_pair_changed_;
Alex Drake00c7ecf2019-08-06 10:54:47 -0700278
Zhi Huange818b6e2018-02-22 15:26:27 -0800279 RTCError ApplyDescription_n(bool local,
280 SdpType type,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100281 const cricket::SessionDescription* description)
282 RTC_RUN_ON(network_thread_);
Zhi Huangd2248f82018-04-10 14:41:03 -0700283 RTCError ValidateAndMaybeUpdateBundleGroup(
284 bool local,
285 SdpType type,
286 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700287 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800288
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700289 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100290 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 Huange818b6e2018-02-22 15:26:27 -0800294
Zhi Huang365381f2018-04-13 16:44:34 -0700295 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700296 cricket::JsepTransport* jsep_transport);
297 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700298
Zhi Huange818b6e2018-02-22 15:26:27 -0800299 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200300 const cricket::ContentInfo& content_info,
301 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700302 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 10:10:17 +0200303 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800304
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200305 absl::optional<std::string> bundled_mid() const {
306 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700307 if (bundle_group_ && bundle_group_->FirstContentName()) {
308 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800309 }
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 Huange818b6e2018-02-22 15:26:27 -0800322 std::vector<int> GetEncryptedHeaderExtensionIds(
323 const cricket::ContentInfo& content_info);
324
Zhi Huange830e682018-03-30 10:48:35 -0700325 int GetRtpAbsSendTimeHeaderExtensionId(
326 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800327
Zhi Huange830e682018-03-30 10:48:35 -0700328 // 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 Huang365381f2018-04-13 16:44:34 -0700332 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700333 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700334 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700335
336 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
337 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700338 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700339 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700340 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700341 const std::string& transport_name);
342
Anton Sukhanov7940da02018-10-10 10:34:49 -0700343 // 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) Slatala105ded32019-02-27 14:26:15 -0800347 RTCError MaybeCreateJsepTransport(
348 bool local,
349 const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100350 const cricket::SessionDescription& description)
351 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800352
Niels Möller5cf0ef02021-01-18 14:00:36 +0100353 void MaybeDestroyJsepTransport(const std::string& mid)
354 RTC_RUN_ON(network_thread_);
355 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800356
Niels Möller5cf0ef02021-01-18 14:00:36 +0100357 void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800358
359 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700360 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800361 const cricket::TransportInfo& transport_info,
362 SdpType type,
363 bool local);
364
365 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700366 const cricket::ContentInfo& content_info,
Niels Möller2a707032020-06-16 16:39:13 +0200367 cricket::IceTransportInternal* ice);
Qingsi Wang25ec8882019-11-15 12:33:05 -0800368 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
369 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800370 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 Huange830e682018-03-30 10:48:35 -0700378 cricket::DtlsTransportInternal* rtp_dtls_transport,
379 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800380 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öller5cf0ef02021-01-18 14:00:36 +0100391 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 Huange818b6e2018-02-22 15:26:27 -0800397 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100398 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 Huange818b6e2018-02-22 15:26:27 -0800403 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100404 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 Drake00c7ecf2019-08-06 10:54:47 -0700410 void OnTransportCandidatePairChanged_n(
Niels Möller5cf0ef02021-01-18 14:00:36 +0100411 const cricket::CandidatePairChangeEvent& event)
412 RTC_RUN_ON(network_thread_);
413 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800414
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200415 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100416 int64_t packet_time_us)
417 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200418
Zhi Huange818b6e2018-02-22 15:26:27 -0800419 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 Steine20867f2018-08-02 13:20:15 -0700424 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800425
Zhi Huang365381f2018-04-13 16:44:34 -0700426 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700427 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700428 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700429 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
430 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Eldar Rellod85ea752020-02-19 20:41:07 +0200431 // 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 Olsson635474e2018-10-18 15:58:17 +0200433 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000434 // 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 Olsson635474e2018-10-18 15:58:17 +0200441 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
442 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800443 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
444
445 Config config_;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800446
Zhi Huange818b6e2018-02-22 15:26:27 -0800447 const cricket::SessionDescription* local_desc_ = nullptr;
448 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200449 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800450
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200451 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800452
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 Huange818b6e2018-02-22 15:26:27 -0800459 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
460};
461
462} // namespace webrtc
463
Steve Anton10542f22019-01-11 09:11:00 -0800464#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_