blob: ced780433ab7234503e58f54edf43cd1d899add0 [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;
Harald Alvestrand133c0522021-01-29 14:27:12 +0000101 // Initial value for whether DtlsTransport reset causes a reset
102 // of SRTP parameters.
Zhi Huangb57e1692018-06-12 11:41:11 -0700103 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-11 20:15:46 -0700104 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700105
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700106 // Factory for SCTP transports.
Per Kjellander2bca0082020-08-28 09:15:15 +0200107 SctpTransportFactoryInterface* sctp_factory = nullptr;
Lahiru Ginnaliya Gamathige70f9e242021-01-27 23:32:46 -0800108 std::function<void(const rtc::SSLHandshakeError)> on_dtls_handshake_error_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800109 };
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 Steine20867f2018-08-02 13:20:15 -0700116 AsyncResolverFactory* async_resolver_factory,
Zhi Huange818b6e2018-02-22 15:26:27 -0800117 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 Alvestrandad88c882018-11-28 16:47:46 +0100133 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
134 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800135 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100136 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100137 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100138 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700139 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
140 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800141
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700142 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700143 const std::string& mid) const;
144
Zhi Huange818b6e2018-02-22 15:26:27 -0800145 /*********************
146 * ICE-related methods
147 ********************/
148 // This method is public to allow PeerConnection to update it from
149 // SetConfiguration.
150 void SetIceConfig(const cricket::IceConfig& config);
151 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
152 // set, offers should generate new ufrags/passwords until an ICE restart
153 // occurs.
154 void SetNeedsIceRestartFlag();
155 // Returns true if the ICE restart flag above was set, and no ICE restart has
156 // occurred yet for this transport (by applying a local description with
157 // changed ufrag/password). If the transport has been deleted as a result of
158 // bundling, returns false.
159 bool NeedsIceRestart(const std::string& mid) const;
160 // Start gathering candidates for any new transports, or transports doing an
161 // ICE restart.
162 void MaybeStartGathering();
163 RTCError AddRemoteCandidates(
164 const std::string& mid,
165 const std::vector<cricket::Candidate>& candidates);
166 RTCError RemoveRemoteCandidates(
167 const std::vector<cricket::Candidate>& candidates);
168
169 /**********************
170 * DTLS-related methods
171 *********************/
172 // Specifies the identity to use in this session.
173 // Can only be called once.
174 bool SetLocalCertificate(
175 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
176 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
177 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800178 // Caller owns returned certificate chain. This method mainly exists for
179 // stats reporting.
180 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800181 const std::string& mid) const;
182 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200183 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800184
185 // TODO(deadbeef): GetStats isn't const because all the way down to
186 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
187 // const. Fix this.
188 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800189
Zhi Huange830e682018-03-30 10:48:35 -0700190 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700191
Zhi Huangb57e1692018-06-12 11:41:11 -0700192 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
193
Eldar Rellod85ea752020-02-19 20:41:07 +0200194 // For now the rollback only removes mid to transport mappings
Eldar Rello353a7182019-11-25 18:49:44 +0200195 // and deletes unused transports, but doesn't consider anything more complex.
Eldar Rellod85ea752020-02-19 20:41:07 +0200196 void RollbackTransports();
Eldar Rello5ab79e62019-10-09 18:29:44 +0300197
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800198 // F: void(const std::string&, const std::vector<cricket::Candidate>&)
199 template <typename F>
200 void SubscribeIceCandidateGathered(F&& callback) {
201 signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
202 }
203
204 // F: void(cricket::IceConnectionState)
205 template <typename F>
206 void SubscribeIceConnectionState(F&& callback) {
207 signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
208 }
209
210 // F: void(PeerConnectionInterface::PeerConnectionState)
211 template <typename F>
212 void SubscribeConnectionState(F&& callback) {
213 signal_connection_state_.AddReceiver(std::forward<F>(callback));
214 }
215
216 // F: void(PeerConnectionInterface::IceConnectionState)
217 template <typename F>
218 void SubscribeStandardizedIceConnectionState(F&& callback) {
219 signal_standardized_ice_connection_state_.AddReceiver(
220 std::forward<F>(callback));
221 }
222
223 // F: void(cricket::IceGatheringState)
224 template <typename F>
225 void SubscribeIceGatheringState(F&& callback) {
226 signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
227 }
228
229 // F: void(const cricket::IceCandidateErrorEvent&)
230 template <typename F>
231 void SubscribeIceCandidateError(F&& callback) {
232 signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
233 }
234
235 // F: void(const std::vector<cricket::Candidate>&)
236 template <typename F>
237 void SubscribeIceCandidatesRemoved(F&& callback) {
238 signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
239 }
240
241 // F: void(const cricket::CandidatePairChangeEvent&)
242 template <typename F>
243 void SubscribeIceCandidatePairChanged(F&& callback) {
244 signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
245 }
246
247 private:
248 // All of these callbacks are fired on the signaling thread.
Zhi Huange818b6e2018-02-22 15:26:27 -0800249
250 // If any transport failed => failed,
251 // Else if all completed => completed,
252 // Else if all connected => connected,
253 // Else => connecting
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800254 CallbackList<cricket::IceConnectionState> signal_ice_connection_state_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800255
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800256 CallbackList<PeerConnectionInterface::PeerConnectionState>
257 signal_connection_state_;
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 14:33:45 -0700258
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800259 CallbackList<PeerConnectionInterface::IceConnectionState>
260 signal_standardized_ice_connection_state_;
Jonas Olsson635474e2018-10-18 15:58:17 +0200261
Zhi Huange818b6e2018-02-22 15:26:27 -0800262 // If all transports done gathering => complete,
263 // Else if any are gathering => gathering,
264 // Else => new
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800265 CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800266
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800267 // [mid, candidates]
268 CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
269 signal_ice_candidates_gathered_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800270
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800271 CallbackList<const cricket::IceCandidateErrorEvent&>
272 signal_ice_candidate_error_;
Eldar Relloda13ea22019-06-01 12:23:43 +0300273
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800274 CallbackList<const std::vector<cricket::Candidate>&>
275 signal_ice_candidates_removed_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800276
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800277 CallbackList<const cricket::CandidatePairChangeEvent&>
278 signal_ice_candidate_pair_changed_;
Alex Drake00c7ecf2019-08-06 10:54:47 -0700279
Zhi Huange818b6e2018-02-22 15:26:27 -0800280 RTCError ApplyDescription_n(bool local,
281 SdpType type,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100282 const cricket::SessionDescription* description)
283 RTC_RUN_ON(network_thread_);
Zhi Huangd2248f82018-04-10 14:41:03 -0700284 RTCError ValidateAndMaybeUpdateBundleGroup(
285 bool local,
286 SdpType type,
287 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700288 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800289
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700290 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100291 const cricket::SessionDescription* description)
292 RTC_RUN_ON(network_thread_);
293 bool HandleBundledContent(const cricket::ContentInfo& content_info)
294 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800295
Zhi Huang365381f2018-04-13 16:44:34 -0700296 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700297 cricket::JsepTransport* jsep_transport);
298 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700299
Zhi Huange818b6e2018-02-22 15:26:27 -0800300 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200301 const cricket::ContentInfo& content_info,
302 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700303 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 10:10:17 +0200304 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800305
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200306 absl::optional<std::string> bundled_mid() const {
307 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700308 if (bundle_group_ && bundle_group_->FirstContentName()) {
309 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800310 }
311 return bundled_mid;
312 }
313
314 bool IsBundled(const std::string& mid) const {
315 return bundle_group_ && bundle_group_->HasContentName(mid);
316 }
317
318 bool ShouldUpdateBundleGroup(SdpType type,
319 const cricket::SessionDescription* description);
320
321 std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle(
322 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800323 std::vector<int> GetEncryptedHeaderExtensionIds(
324 const cricket::ContentInfo& content_info);
325
Zhi Huange830e682018-03-30 10:48:35 -0700326 int GetRtpAbsSendTimeHeaderExtensionId(
327 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800328
Zhi Huange830e682018-03-30 10:48:35 -0700329 // This method takes the BUNDLE group into account. If the JsepTransport is
330 // destroyed because of BUNDLE, it would return the transport which other
331 // transports are bundled on (In current implementation, it is the first
332 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700333 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700334 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700335 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700336
337 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
338 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700339 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700340 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700341 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700342 const std::string& transport_name);
343
Anton Sukhanov7940da02018-10-10 10:34:49 -0700344 // Creates jsep transport. Noop if transport is already created.
345 // Transport is created either during SetLocalDescription (|local| == true) or
346 // during SetRemoteDescription (|local| == false). Passing |local| helps to
347 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800348 RTCError MaybeCreateJsepTransport(
349 bool local,
350 const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100351 const cricket::SessionDescription& description)
352 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800353
Niels Möller5cf0ef02021-01-18 14:00:36 +0100354 void MaybeDestroyJsepTransport(const std::string& mid)
355 RTC_RUN_ON(network_thread_);
356 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800357
Niels Möller5cf0ef02021-01-18 14:00:36 +0100358 void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800359
360 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700361 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800362 const cricket::TransportInfo& transport_info,
363 SdpType type,
364 bool local);
365
366 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700367 const cricket::ContentInfo& content_info,
Niels Möller2a707032020-06-16 16:39:13 +0200368 cricket::IceTransportInternal* ice);
Qingsi Wang25ec8882019-11-15 12:33:05 -0800369 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
370 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800371 bool rtcp);
372
373 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
374 const std::string& transport_name,
375 rtc::PacketTransportInternal* rtp_packet_transport,
376 rtc::PacketTransportInternal* rtcp_packet_transport);
377 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
378 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700379 cricket::DtlsTransportInternal* rtp_dtls_transport,
380 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800381 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
382 const std::string& transport_name,
383 cricket::DtlsTransportInternal* rtp_dtls_transport,
384 cricket::DtlsTransportInternal* rtcp_dtls_transport);
385
386 // Collect all the DtlsTransports, including RTP and RTCP, from the
387 // JsepTransports. JsepTransportController can iterate all the DtlsTransports
388 // and update the aggregate states.
389 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
390
391 // Handlers for signals from Transport.
Niels Möller5cf0ef02021-01-18 14:00:36 +0100392 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport)
393 RTC_RUN_ON(network_thread_);
394 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport)
395 RTC_RUN_ON(network_thread_);
396 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport)
397 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800398 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100399 const cricket::Candidate& candidate)
400 RTC_RUN_ON(network_thread_);
401 void OnTransportCandidateError_n(cricket::IceTransportInternal* transport,
402 const cricket::IceCandidateErrorEvent& event)
403 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800404 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100405 const cricket::Candidates& candidates)
406 RTC_RUN_ON(network_thread_);
407 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport)
408 RTC_RUN_ON(network_thread_);
409 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport)
410 RTC_RUN_ON(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700411 void OnTransportCandidatePairChanged_n(
Niels Möller5cf0ef02021-01-18 14:00:36 +0100412 const cricket::CandidatePairChangeEvent& event)
413 RTC_RUN_ON(network_thread_);
414 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800415
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200416 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100417 int64_t packet_time_us)
418 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200419
Zhi Huange818b6e2018-02-22 15:26:27 -0800420 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
421
422 rtc::Thread* const signaling_thread_ = nullptr;
423 rtc::Thread* const network_thread_ = nullptr;
424 cricket::PortAllocator* const port_allocator_ = nullptr;
Zach Steine20867f2018-08-02 13:20:15 -0700425 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800426
Zhi Huang365381f2018-04-13 16:44:34 -0700427 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700428 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700429 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700430 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
431 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Eldar Rellod85ea752020-02-19 20:41:07 +0200432 // Keep track of mids that have been mapped to transports. Used for rollback.
433 std::vector<std::string> pending_mids_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200434 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000435 // standardized_ice_connection_state_ is intended to replace
436 // ice_connection_state, see bugs.webrtc.org/9308
437 cricket::IceConnectionState ice_connection_state_ =
438 cricket::kIceConnectionConnecting;
439 PeerConnectionInterface::IceConnectionState
440 standardized_ice_connection_state_ =
441 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200442 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
443 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800444 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
445
Harald Alvestrand133c0522021-01-29 14:27:12 +0000446 const Config config_;
447 bool active_reset_srtp_params_ RTC_GUARDED_BY(network_thread_);
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800448
Zhi Huange818b6e2018-02-22 15:26:27 -0800449 const cricket::SessionDescription* local_desc_ = nullptr;
450 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200451 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800452
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200453 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800454
455 cricket::IceConfig ice_config_;
456 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
457 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
458 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
459 rtc::AsyncInvoker invoker_;
460
Zhi Huange818b6e2018-02-22 15:26:27 -0800461 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
462};
463
464} // namespace webrtc
465
Steve Anton10542f22019-01-11 09:11:00 -0800466#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_