blob: 2f9d8a0a935fa96c722675697a147faec6ffd4f4 [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;
Lahiru Ginnaliya Gamathige70f9e242021-01-27 23:32:46 -0800106 std::function<void(const rtc::SSLHandshakeError)> on_dtls_handshake_error_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800107 };
108
109 // The ICE related events are signaled on the |signaling_thread|.
110 // All the transport related methods are called on the |network_thread|.
111 JsepTransportController(rtc::Thread* signaling_thread,
112 rtc::Thread* network_thread,
113 cricket::PortAllocator* port_allocator,
Zach Steine20867f2018-08-02 13:20:15 -0700114 AsyncResolverFactory* async_resolver_factory,
Zhi Huange818b6e2018-02-22 15:26:27 -0800115 Config config);
116 virtual ~JsepTransportController();
117
118 // The main method to be called; applies a description at the transport
119 // level, creating/destroying transport objects as needed and updating their
120 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
121 // yet? May make sense to in the future.
122 RTCError SetLocalDescription(SdpType type,
123 const cricket::SessionDescription* description);
124
125 RTCError SetRemoteDescription(SdpType type,
126 const cricket::SessionDescription* description);
127
128 // Get transports to be used for the provided |mid|. If bundling is enabled,
129 // calling GetRtpTransport for multiple MIDs may yield the same object.
130 RtpTransportInternal* GetRtpTransport(const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100131 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
132 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800133 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100134 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100135 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100136 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700137 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
138 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800139
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700140 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700141 const std::string& mid) const;
142
Zhi Huange818b6e2018-02-22 15:26:27 -0800143 /*********************
144 * ICE-related methods
145 ********************/
146 // This method is public to allow PeerConnection to update it from
147 // SetConfiguration.
148 void SetIceConfig(const cricket::IceConfig& config);
149 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
150 // set, offers should generate new ufrags/passwords until an ICE restart
151 // occurs.
152 void SetNeedsIceRestartFlag();
153 // Returns true if the ICE restart flag above was set, and no ICE restart has
154 // occurred yet for this transport (by applying a local description with
155 // changed ufrag/password). If the transport has been deleted as a result of
156 // bundling, returns false.
157 bool NeedsIceRestart(const std::string& mid) const;
158 // Start gathering candidates for any new transports, or transports doing an
159 // ICE restart.
160 void MaybeStartGathering();
161 RTCError AddRemoteCandidates(
162 const std::string& mid,
163 const std::vector<cricket::Candidate>& candidates);
164 RTCError RemoveRemoteCandidates(
165 const std::vector<cricket::Candidate>& candidates);
166
167 /**********************
168 * DTLS-related methods
169 *********************/
170 // Specifies the identity to use in this session.
171 // Can only be called once.
172 bool SetLocalCertificate(
173 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
174 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
175 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800176 // Caller owns returned certificate chain. This method mainly exists for
177 // stats reporting.
178 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800179 const std::string& mid) const;
180 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200181 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800182
183 // TODO(deadbeef): GetStats isn't const because all the way down to
184 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
185 // const. Fix this.
186 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800187
Zhi Huange830e682018-03-30 10:48:35 -0700188 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700189
Zhi Huangb57e1692018-06-12 11:41:11 -0700190 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
191
Eldar Rellod85ea752020-02-19 20:41:07 +0200192 // For now the rollback only removes mid to transport mappings
Eldar Rello353a7182019-11-25 18:49:44 +0200193 // and deletes unused transports, but doesn't consider anything more complex.
Eldar Rellod85ea752020-02-19 20:41:07 +0200194 void RollbackTransports();
Eldar Rello5ab79e62019-10-09 18:29:44 +0300195
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800196 // F: void(const std::string&, const std::vector<cricket::Candidate>&)
197 template <typename F>
198 void SubscribeIceCandidateGathered(F&& callback) {
199 signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
200 }
201
202 // F: void(cricket::IceConnectionState)
203 template <typename F>
204 void SubscribeIceConnectionState(F&& callback) {
205 signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
206 }
207
208 // F: void(PeerConnectionInterface::PeerConnectionState)
209 template <typename F>
210 void SubscribeConnectionState(F&& callback) {
211 signal_connection_state_.AddReceiver(std::forward<F>(callback));
212 }
213
214 // F: void(PeerConnectionInterface::IceConnectionState)
215 template <typename F>
216 void SubscribeStandardizedIceConnectionState(F&& callback) {
217 signal_standardized_ice_connection_state_.AddReceiver(
218 std::forward<F>(callback));
219 }
220
221 // F: void(cricket::IceGatheringState)
222 template <typename F>
223 void SubscribeIceGatheringState(F&& callback) {
224 signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
225 }
226
227 // F: void(const cricket::IceCandidateErrorEvent&)
228 template <typename F>
229 void SubscribeIceCandidateError(F&& callback) {
230 signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
231 }
232
233 // F: void(const std::vector<cricket::Candidate>&)
234 template <typename F>
235 void SubscribeIceCandidatesRemoved(F&& callback) {
236 signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
237 }
238
239 // F: void(const cricket::CandidatePairChangeEvent&)
240 template <typename F>
241 void SubscribeIceCandidatePairChanged(F&& callback) {
242 signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
243 }
244
245 private:
246 // All of these callbacks are fired on the signaling thread.
Zhi Huange818b6e2018-02-22 15:26:27 -0800247
248 // If any transport failed => failed,
249 // Else if all completed => completed,
250 // Else if all connected => connected,
251 // Else => connecting
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800252 CallbackList<cricket::IceConnectionState> signal_ice_connection_state_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800253
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800254 CallbackList<PeerConnectionInterface::PeerConnectionState>
255 signal_connection_state_;
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 14:33:45 -0700256
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800257 CallbackList<PeerConnectionInterface::IceConnectionState>
258 signal_standardized_ice_connection_state_;
Jonas Olsson635474e2018-10-18 15:58:17 +0200259
Zhi Huange818b6e2018-02-22 15:26:27 -0800260 // If all transports done gathering => complete,
261 // Else if any are gathering => gathering,
262 // Else => new
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800263 CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800264
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800265 // [mid, candidates]
266 CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
267 signal_ice_candidates_gathered_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800268
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800269 CallbackList<const cricket::IceCandidateErrorEvent&>
270 signal_ice_candidate_error_;
Eldar Relloda13ea22019-06-01 12:23:43 +0300271
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800272 CallbackList<const std::vector<cricket::Candidate>&>
273 signal_ice_candidates_removed_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800274
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800275 CallbackList<const cricket::CandidatePairChangeEvent&>
276 signal_ice_candidate_pair_changed_;
Alex Drake00c7ecf2019-08-06 10:54:47 -0700277
Zhi Huange818b6e2018-02-22 15:26:27 -0800278 RTCError ApplyDescription_n(bool local,
279 SdpType type,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100280 const cricket::SessionDescription* description)
281 RTC_RUN_ON(network_thread_);
Zhi Huangd2248f82018-04-10 14:41:03 -0700282 RTCError ValidateAndMaybeUpdateBundleGroup(
283 bool local,
284 SdpType type,
285 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700286 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800287
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700288 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100289 const cricket::SessionDescription* description)
290 RTC_RUN_ON(network_thread_);
291 bool HandleBundledContent(const cricket::ContentInfo& content_info)
292 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800293
Zhi Huang365381f2018-04-13 16:44:34 -0700294 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700295 cricket::JsepTransport* jsep_transport);
296 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700297
Zhi Huange818b6e2018-02-22 15:26:27 -0800298 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200299 const cricket::ContentInfo& content_info,
300 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700301 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 10:10:17 +0200302 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800303
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200304 absl::optional<std::string> bundled_mid() const {
305 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700306 if (bundle_group_ && bundle_group_->FirstContentName()) {
307 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800308 }
309 return bundled_mid;
310 }
311
312 bool IsBundled(const std::string& mid) const {
313 return bundle_group_ && bundle_group_->HasContentName(mid);
314 }
315
316 bool ShouldUpdateBundleGroup(SdpType type,
317 const cricket::SessionDescription* description);
318
319 std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle(
320 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800321 std::vector<int> GetEncryptedHeaderExtensionIds(
322 const cricket::ContentInfo& content_info);
323
Zhi Huange830e682018-03-30 10:48:35 -0700324 int GetRtpAbsSendTimeHeaderExtensionId(
325 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800326
Zhi Huange830e682018-03-30 10:48:35 -0700327 // This method takes the BUNDLE group into account. If the JsepTransport is
328 // destroyed because of BUNDLE, it would return the transport which other
329 // transports are bundled on (In current implementation, it is the first
330 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700331 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700332 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700333 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700334
335 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
336 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700337 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700338 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700339 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700340 const std::string& transport_name);
341
Anton Sukhanov7940da02018-10-10 10:34:49 -0700342 // Creates jsep transport. Noop if transport is already created.
343 // Transport is created either during SetLocalDescription (|local| == true) or
344 // during SetRemoteDescription (|local| == false). Passing |local| helps to
345 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800346 RTCError MaybeCreateJsepTransport(
347 bool local,
348 const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100349 const cricket::SessionDescription& description)
350 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800351
Niels Möller5cf0ef02021-01-18 14:00:36 +0100352 void MaybeDestroyJsepTransport(const std::string& mid)
353 RTC_RUN_ON(network_thread_);
354 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800355
Niels Möller5cf0ef02021-01-18 14:00:36 +0100356 void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800357
358 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700359 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800360 const cricket::TransportInfo& transport_info,
361 SdpType type,
362 bool local);
363
364 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700365 const cricket::ContentInfo& content_info,
Niels Möller2a707032020-06-16 16:39:13 +0200366 cricket::IceTransportInternal* ice);
Qingsi Wang25ec8882019-11-15 12:33:05 -0800367 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
368 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800369 bool rtcp);
370
371 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
372 const std::string& transport_name,
373 rtc::PacketTransportInternal* rtp_packet_transport,
374 rtc::PacketTransportInternal* rtcp_packet_transport);
375 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
376 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700377 cricket::DtlsTransportInternal* rtp_dtls_transport,
378 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800379 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
380 const std::string& transport_name,
381 cricket::DtlsTransportInternal* rtp_dtls_transport,
382 cricket::DtlsTransportInternal* rtcp_dtls_transport);
383
384 // Collect all the DtlsTransports, including RTP and RTCP, from the
385 // JsepTransports. JsepTransportController can iterate all the DtlsTransports
386 // and update the aggregate states.
387 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
388
389 // Handlers for signals from Transport.
Niels Möller5cf0ef02021-01-18 14:00:36 +0100390 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport)
391 RTC_RUN_ON(network_thread_);
392 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport)
393 RTC_RUN_ON(network_thread_);
394 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport)
395 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800396 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100397 const cricket::Candidate& candidate)
398 RTC_RUN_ON(network_thread_);
399 void OnTransportCandidateError_n(cricket::IceTransportInternal* transport,
400 const cricket::IceCandidateErrorEvent& event)
401 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800402 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100403 const cricket::Candidates& candidates)
404 RTC_RUN_ON(network_thread_);
405 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport)
406 RTC_RUN_ON(network_thread_);
407 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport)
408 RTC_RUN_ON(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700409 void OnTransportCandidatePairChanged_n(
Niels Möller5cf0ef02021-01-18 14:00:36 +0100410 const cricket::CandidatePairChangeEvent& event)
411 RTC_RUN_ON(network_thread_);
412 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800413
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200414 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100415 int64_t packet_time_us)
416 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200417
Zhi Huange818b6e2018-02-22 15:26:27 -0800418 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
419
420 rtc::Thread* const signaling_thread_ = nullptr;
421 rtc::Thread* const network_thread_ = nullptr;
422 cricket::PortAllocator* const port_allocator_ = nullptr;
Zach Steine20867f2018-08-02 13:20:15 -0700423 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800424
Zhi Huang365381f2018-04-13 16:44:34 -0700425 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700426 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700427 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700428 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
429 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Eldar Rellod85ea752020-02-19 20:41:07 +0200430 // Keep track of mids that have been mapped to transports. Used for rollback.
431 std::vector<std::string> pending_mids_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200432 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000433 // standardized_ice_connection_state_ is intended to replace
434 // ice_connection_state, see bugs.webrtc.org/9308
435 cricket::IceConnectionState ice_connection_state_ =
436 cricket::kIceConnectionConnecting;
437 PeerConnectionInterface::IceConnectionState
438 standardized_ice_connection_state_ =
439 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200440 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
441 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800442 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
443
444 Config config_;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800445
Zhi Huange818b6e2018-02-22 15:26:27 -0800446 const cricket::SessionDescription* local_desc_ = nullptr;
447 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200448 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800449
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200450 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800451
452 cricket::IceConfig ice_config_;
453 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
454 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
455 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
456 rtc::AsyncInvoker invoker_;
457
Zhi Huange818b6e2018-02-22 15:26:27 -0800458 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
459};
460
461} // namespace webrtc
462
Steve Anton10542f22019-01-11 09:11:00 -0800463#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_