blob: 3dab284a76c8f9542cb083d8eaa69a69a97c01ec [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
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000014#include <stdint.h>
15
16#include <functional>
Zhi Huange818b6e2018-02-22 15:26:27 -080017#include <map>
18#include <memory>
19#include <string>
20#include <utility>
21#include <vector>
22
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000023#include "absl/types/optional.h"
24#include "api/async_resolver_factory.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080025#include "api/candidate.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/crypto/crypto_options.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080027#include "api/ice_transport_factory.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000028#include "api/ice_transport_interface.h"
29#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "api/peer_connection_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000031#include "api/rtc_error.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020032#include "api/rtc_event_log/rtc_event_log.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000033#include "api/scoped_refptr.h"
34#include "api/transport/data_channel_transport_interface.h"
35#include "api/transport/sctp_transport_factory_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "media/sctp/sctp_transport_internal.h"
37#include "p2p/base/dtls_transport.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080038#include "p2p/base/dtls_transport_factory.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000039#include "p2p/base/dtls_transport_internal.h"
40#include "p2p/base/ice_transport_internal.h"
Steve Anton10542f22019-01-11 09:11:00 -080041#include "p2p/base/p2p_transport_channel.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000042#include "p2p/base/packet_transport_internal.h"
43#include "p2p/base/port.h"
44#include "p2p/base/port_allocator.h"
45#include "p2p/base/transport_description.h"
46#include "p2p/base/transport_info.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080047#include "pc/channel.h"
Steve Anton10542f22019-01-11 09:11:00 -080048#include "pc/dtls_srtp_transport.h"
49#include "pc/dtls_transport.h"
50#include "pc/jsep_transport.h"
51#include "pc/rtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000052#include "pc/rtp_transport_internal.h"
53#include "pc/sctp_transport.h"
54#include "pc/session_description.h"
Steve Anton10542f22019-01-11 09:11:00 -080055#include "pc/srtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000056#include "pc/transport_stats.h"
Steve Anton10542f22019-01-11 09:11:00 -080057#include "rtc_base/async_invoker.h"
Mirko Bonadei3d259352020-10-23 12:04:40 +020058#include "rtc_base/callback_list.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000059#include "rtc_base/constructor_magic.h"
60#include "rtc_base/copy_on_write_buffer.h"
61#include "rtc_base/helpers.h"
62#include "rtc_base/ref_counted_object.h"
63#include "rtc_base/rtc_certificate.h"
64#include "rtc_base/ssl_certificate.h"
65#include "rtc_base/ssl_stream_adapter.h"
Artem Titove41c4332018-07-25 15:04:28 +020066#include "rtc_base/third_party/sigslot/sigslot.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000067#include "rtc_base/thread.h"
68#include "rtc_base/thread_annotations.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080069
70namespace rtc {
71class Thread;
72class PacketTransportInternal;
73} // namespace rtc
74
75namespace webrtc {
76
Steve Antond25828a2018-08-31 13:06:05 -070077class JsepTransportController : public sigslot::has_slots<> {
Zhi Huange818b6e2018-02-22 15:26:27 -080078 public:
Zhi Huang365381f2018-04-13 16:44:34 -070079 // Used when the RtpTransport/DtlsTransport of the m= section is changed
80 // because the section is rejected or BUNDLE is enabled.
81 class Observer {
82 public:
83 virtual ~Observer() {}
84
85 // Returns true if media associated with |mid| was successfully set up to be
86 // demultiplexed on |rtp_transport|. Could return false if two bundled m=
87 // sections use the same SSRC, for example.
Bjorn A Mellemb689af42019-08-21 10:44:59 -070088 //
89 // If a data channel transport must be negotiated, |data_channel_transport|
90 // and |negotiation_state| indicate negotiation status. If
91 // |data_channel_transport| is null, the data channel transport should not
92 // be used. Otherwise, the value is a pointer to the transport to be used
93 // for data channels on |mid|, if any.
94 //
95 // The observer should not send data on |data_channel_transport| until
96 // |negotiation_state| is provisional or final. It should not delete
97 // |data_channel_transport| or any fallback transport until
98 // |negotiation_state| is final.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -070099 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 16:44:34 -0700100 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700101 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +0100102 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700103 DataChannelTransportInterface* data_channel_transport) = 0;
Zhi Huang365381f2018-04-13 16:44:34 -0700104 };
105
Zhi Huange818b6e2018-02-22 15:26:27 -0800106 struct Config {
107 // If |redetermine_role_on_ice_restart| is true, ICE role is redetermined
108 // upon setting a local transport description that indicates an ICE
109 // restart.
110 bool redetermine_role_on_ice_restart = true;
111 rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
112 // |crypto_options| is used to determine if created DTLS transports
113 // negotiate GCM crypto suites or not.
Benjamin Wrighta54daf12018-10-11 15:33:17 -0700114 webrtc::CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 15:26:27 -0800115 PeerConnectionInterface::BundlePolicy bundle_policy =
116 PeerConnectionInterface::kBundlePolicyBalanced;
117 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy =
118 PeerConnectionInterface::kRtcpMuxPolicyRequire;
119 bool disable_encryption = false;
120 bool enable_external_auth = false;
121 // Used to inject the ICE/DTLS transports created externally.
Qingsi Wang25ec8882019-11-15 12:33:05 -0800122 webrtc::IceTransportFactory* ice_transport_factory = nullptr;
123 cricket::DtlsTransportFactory* dtls_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 16:44:34 -0700124 Observer* transport_observer = nullptr;
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200125 // Must be provided and valid for the lifetime of the
126 // JsepTransportController instance.
127 std::function<void(const rtc::CopyOnWriteBuffer& packet,
128 int64_t packet_time_us)>
129 rtcp_handler;
Harald Alvestrand133c0522021-01-29 14:27:12 +0000130 // Initial value for whether DtlsTransport reset causes a reset
131 // of SRTP parameters.
Zhi Huangb57e1692018-06-12 11:41:11 -0700132 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-11 20:15:46 -0700133 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700134
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700135 // Factory for SCTP transports.
Per Kjellander2bca0082020-08-28 09:15:15 +0200136 SctpTransportFactoryInterface* sctp_factory = nullptr;
Lahiru Ginnaliya Gamathige70f9e242021-01-27 23:32:46 -0800137 std::function<void(const rtc::SSLHandshakeError)> on_dtls_handshake_error_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800138 };
139
140 // The ICE related events are signaled on the |signaling_thread|.
141 // All the transport related methods are called on the |network_thread|.
142 JsepTransportController(rtc::Thread* signaling_thread,
143 rtc::Thread* network_thread,
144 cricket::PortAllocator* port_allocator,
Zach Steine20867f2018-08-02 13:20:15 -0700145 AsyncResolverFactory* async_resolver_factory,
Zhi Huange818b6e2018-02-22 15:26:27 -0800146 Config config);
147 virtual ~JsepTransportController();
148
149 // The main method to be called; applies a description at the transport
150 // level, creating/destroying transport objects as needed and updating their
151 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
152 // yet? May make sense to in the future.
153 RTCError SetLocalDescription(SdpType type,
154 const cricket::SessionDescription* description);
155
156 RTCError SetRemoteDescription(SdpType type,
157 const cricket::SessionDescription* description);
158
159 // Get transports to be used for the provided |mid|. If bundling is enabled,
160 // calling GetRtpTransport for multiple MIDs may yield the same object.
161 RtpTransportInternal* GetRtpTransport(const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100162 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
163 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800164 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100165 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100166 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100167 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700168 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
169 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800170
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700171 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700172 const std::string& mid) const;
173
Zhi Huange818b6e2018-02-22 15:26:27 -0800174 /*********************
175 * ICE-related methods
176 ********************/
177 // This method is public to allow PeerConnection to update it from
178 // SetConfiguration.
179 void SetIceConfig(const cricket::IceConfig& config);
180 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
181 // set, offers should generate new ufrags/passwords until an ICE restart
182 // occurs.
183 void SetNeedsIceRestartFlag();
184 // Returns true if the ICE restart flag above was set, and no ICE restart has
185 // occurred yet for this transport (by applying a local description with
186 // changed ufrag/password). If the transport has been deleted as a result of
187 // bundling, returns false.
188 bool NeedsIceRestart(const std::string& mid) const;
189 // Start gathering candidates for any new transports, or transports doing an
190 // ICE restart.
191 void MaybeStartGathering();
192 RTCError AddRemoteCandidates(
193 const std::string& mid,
194 const std::vector<cricket::Candidate>& candidates);
195 RTCError RemoveRemoteCandidates(
196 const std::vector<cricket::Candidate>& candidates);
197
198 /**********************
199 * DTLS-related methods
200 *********************/
201 // Specifies the identity to use in this session.
202 // Can only be called once.
203 bool SetLocalCertificate(
204 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
205 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
206 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800207 // Caller owns returned certificate chain. This method mainly exists for
208 // stats reporting.
209 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800210 const std::string& mid) const;
211 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200212 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800213
214 // TODO(deadbeef): GetStats isn't const because all the way down to
215 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
216 // const. Fix this.
217 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800218
Zhi Huange830e682018-03-30 10:48:35 -0700219 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700220
Zhi Huangb57e1692018-06-12 11:41:11 -0700221 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
222
Eldar Rellod85ea752020-02-19 20:41:07 +0200223 // For now the rollback only removes mid to transport mappings
Eldar Rello353a7182019-11-25 18:49:44 +0200224 // and deletes unused transports, but doesn't consider anything more complex.
Eldar Rellod85ea752020-02-19 20:41:07 +0200225 void RollbackTransports();
Eldar Rello5ab79e62019-10-09 18:29:44 +0300226
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800227 // F: void(const std::string&, const std::vector<cricket::Candidate>&)
228 template <typename F>
229 void SubscribeIceCandidateGathered(F&& callback) {
230 signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
231 }
232
233 // F: void(cricket::IceConnectionState)
234 template <typename F>
235 void SubscribeIceConnectionState(F&& callback) {
236 signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
237 }
238
239 // F: void(PeerConnectionInterface::PeerConnectionState)
240 template <typename F>
241 void SubscribeConnectionState(F&& callback) {
242 signal_connection_state_.AddReceiver(std::forward<F>(callback));
243 }
244
245 // F: void(PeerConnectionInterface::IceConnectionState)
246 template <typename F>
247 void SubscribeStandardizedIceConnectionState(F&& callback) {
248 signal_standardized_ice_connection_state_.AddReceiver(
249 std::forward<F>(callback));
250 }
251
252 // F: void(cricket::IceGatheringState)
253 template <typename F>
254 void SubscribeIceGatheringState(F&& callback) {
255 signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
256 }
257
258 // F: void(const cricket::IceCandidateErrorEvent&)
259 template <typename F>
260 void SubscribeIceCandidateError(F&& callback) {
261 signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
262 }
263
264 // F: void(const std::vector<cricket::Candidate>&)
265 template <typename F>
266 void SubscribeIceCandidatesRemoved(F&& callback) {
267 signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
268 }
269
270 // F: void(const cricket::CandidatePairChangeEvent&)
271 template <typename F>
272 void SubscribeIceCandidatePairChanged(F&& callback) {
273 signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
274 }
275
276 private:
277 // All of these callbacks are fired on the signaling thread.
Zhi Huange818b6e2018-02-22 15:26:27 -0800278
279 // If any transport failed => failed,
280 // Else if all completed => completed,
281 // Else if all connected => connected,
282 // Else => connecting
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800283 CallbackList<cricket::IceConnectionState> signal_ice_connection_state_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800284
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800285 CallbackList<PeerConnectionInterface::PeerConnectionState>
286 signal_connection_state_;
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 14:33:45 -0700287
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800288 CallbackList<PeerConnectionInterface::IceConnectionState>
289 signal_standardized_ice_connection_state_;
Jonas Olsson635474e2018-10-18 15:58:17 +0200290
Zhi Huange818b6e2018-02-22 15:26:27 -0800291 // If all transports done gathering => complete,
292 // Else if any are gathering => gathering,
293 // Else => new
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800294 CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800295
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800296 // [mid, candidates]
297 CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
298 signal_ice_candidates_gathered_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800299
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800300 CallbackList<const cricket::IceCandidateErrorEvent&>
301 signal_ice_candidate_error_;
Eldar Relloda13ea22019-06-01 12:23:43 +0300302
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800303 CallbackList<const std::vector<cricket::Candidate>&>
304 signal_ice_candidates_removed_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800305
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800306 CallbackList<const cricket::CandidatePairChangeEvent&>
307 signal_ice_candidate_pair_changed_;
Alex Drake00c7ecf2019-08-06 10:54:47 -0700308
Zhi Huange818b6e2018-02-22 15:26:27 -0800309 RTCError ApplyDescription_n(bool local,
310 SdpType type,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100311 const cricket::SessionDescription* description)
312 RTC_RUN_ON(network_thread_);
Zhi Huangd2248f82018-04-10 14:41:03 -0700313 RTCError ValidateAndMaybeUpdateBundleGroup(
314 bool local,
315 SdpType type,
316 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700317 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800318
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700319 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100320 const cricket::SessionDescription* description)
321 RTC_RUN_ON(network_thread_);
322 bool HandleBundledContent(const cricket::ContentInfo& content_info)
323 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800324
Zhi Huang365381f2018-04-13 16:44:34 -0700325 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700326 cricket::JsepTransport* jsep_transport);
327 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700328
Zhi Huange818b6e2018-02-22 15:26:27 -0800329 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200330 const cricket::ContentInfo& content_info,
331 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700332 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 10:10:17 +0200333 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800334
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200335 absl::optional<std::string> bundled_mid() const {
336 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700337 if (bundle_group_ && bundle_group_->FirstContentName()) {
338 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800339 }
340 return bundled_mid;
341 }
342
343 bool IsBundled(const std::string& mid) const {
344 return bundle_group_ && bundle_group_->HasContentName(mid);
345 }
346
347 bool ShouldUpdateBundleGroup(SdpType type,
348 const cricket::SessionDescription* description);
349
350 std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle(
351 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800352 std::vector<int> GetEncryptedHeaderExtensionIds(
353 const cricket::ContentInfo& content_info);
354
Zhi Huange830e682018-03-30 10:48:35 -0700355 int GetRtpAbsSendTimeHeaderExtensionId(
356 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800357
Zhi Huange830e682018-03-30 10:48:35 -0700358 // This method takes the BUNDLE group into account. If the JsepTransport is
359 // destroyed because of BUNDLE, it would return the transport which other
360 // transports are bundled on (In current implementation, it is the first
361 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700362 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700363 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700364 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700365
366 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
367 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700368 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700369 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700370 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700371 const std::string& transport_name);
372
Anton Sukhanov7940da02018-10-10 10:34:49 -0700373 // Creates jsep transport. Noop if transport is already created.
374 // Transport is created either during SetLocalDescription (|local| == true) or
375 // during SetRemoteDescription (|local| == false). Passing |local| helps to
376 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800377 RTCError MaybeCreateJsepTransport(
378 bool local,
379 const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100380 const cricket::SessionDescription& description)
381 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800382
Niels Möller5cf0ef02021-01-18 14:00:36 +0100383 void MaybeDestroyJsepTransport(const std::string& mid)
384 RTC_RUN_ON(network_thread_);
385 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800386
Niels Möller5cf0ef02021-01-18 14:00:36 +0100387 void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800388
389 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700390 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800391 const cricket::TransportInfo& transport_info,
392 SdpType type,
393 bool local);
394
395 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700396 const cricket::ContentInfo& content_info,
Niels Möller2a707032020-06-16 16:39:13 +0200397 cricket::IceTransportInternal* ice);
Qingsi Wang25ec8882019-11-15 12:33:05 -0800398 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
399 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800400 bool rtcp);
401
402 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
403 const std::string& transport_name,
404 rtc::PacketTransportInternal* rtp_packet_transport,
405 rtc::PacketTransportInternal* rtcp_packet_transport);
406 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
407 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700408 cricket::DtlsTransportInternal* rtp_dtls_transport,
409 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800410 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
411 const std::string& transport_name,
412 cricket::DtlsTransportInternal* rtp_dtls_transport,
413 cricket::DtlsTransportInternal* rtcp_dtls_transport);
414
415 // Collect all the DtlsTransports, including RTP and RTCP, from the
416 // JsepTransports. JsepTransportController can iterate all the DtlsTransports
417 // and update the aggregate states.
418 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
419
420 // Handlers for signals from Transport.
Niels Möller5cf0ef02021-01-18 14:00:36 +0100421 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport)
422 RTC_RUN_ON(network_thread_);
423 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport)
424 RTC_RUN_ON(network_thread_);
425 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport)
426 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800427 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100428 const cricket::Candidate& candidate)
429 RTC_RUN_ON(network_thread_);
430 void OnTransportCandidateError_n(cricket::IceTransportInternal* transport,
431 const cricket::IceCandidateErrorEvent& event)
432 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800433 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100434 const cricket::Candidates& candidates)
435 RTC_RUN_ON(network_thread_);
436 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport)
437 RTC_RUN_ON(network_thread_);
438 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport)
439 RTC_RUN_ON(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700440 void OnTransportCandidatePairChanged_n(
Niels Möller5cf0ef02021-01-18 14:00:36 +0100441 const cricket::CandidatePairChangeEvent& event)
442 RTC_RUN_ON(network_thread_);
443 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800444
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200445 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100446 int64_t packet_time_us)
447 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200448
Zhi Huange818b6e2018-02-22 15:26:27 -0800449 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
450
451 rtc::Thread* const signaling_thread_ = nullptr;
452 rtc::Thread* const network_thread_ = nullptr;
453 cricket::PortAllocator* const port_allocator_ = nullptr;
Zach Steine20867f2018-08-02 13:20:15 -0700454 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800455
Zhi Huang365381f2018-04-13 16:44:34 -0700456 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700457 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700458 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700459 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
460 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Eldar Rellod85ea752020-02-19 20:41:07 +0200461 // Keep track of mids that have been mapped to transports. Used for rollback.
462 std::vector<std::string> pending_mids_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200463 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000464 // standardized_ice_connection_state_ is intended to replace
465 // ice_connection_state, see bugs.webrtc.org/9308
466 cricket::IceConnectionState ice_connection_state_ =
467 cricket::kIceConnectionConnecting;
468 PeerConnectionInterface::IceConnectionState
469 standardized_ice_connection_state_ =
470 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200471 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
472 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800473 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
474
Harald Alvestrand133c0522021-01-29 14:27:12 +0000475 const Config config_;
476 bool active_reset_srtp_params_ RTC_GUARDED_BY(network_thread_);
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800477
Zhi Huange818b6e2018-02-22 15:26:27 -0800478 const cricket::SessionDescription* local_desc_ = nullptr;
479 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200480 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800481
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200482 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800483
484 cricket::IceConfig ice_config_;
485 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
486 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
487 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
488 rtc::AsyncInvoker invoker_;
489
Zhi Huange818b6e2018-02-22 15:26:27 -0800490 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
491};
492
493} // namespace webrtc
494
Steve Anton10542f22019-01-11 09:11:00 -0800495#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_