blob: 4e0656680668736d71d525741b272069229372ff [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"
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000024#include "api/async_dns_resolver.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"
Harald Alvestrandde22ab22021-06-17 10:45:33 +000034#include "api/sequence_checker.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000035#include "api/transport/data_channel_transport_interface.h"
36#include "api/transport/sctp_transport_factory_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080037#include "media/sctp/sctp_transport_internal.h"
38#include "p2p/base/dtls_transport.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080039#include "p2p/base/dtls_transport_factory.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000040#include "p2p/base/dtls_transport_internal.h"
41#include "p2p/base/ice_transport_internal.h"
Steve Anton10542f22019-01-11 09:11:00 -080042#include "p2p/base/p2p_transport_channel.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000043#include "p2p/base/packet_transport_internal.h"
44#include "p2p/base/port.h"
45#include "p2p/base/port_allocator.h"
46#include "p2p/base/transport_description.h"
47#include "p2p/base/transport_info.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080048#include "pc/channel.h"
Steve Anton10542f22019-01-11 09:11:00 -080049#include "pc/dtls_srtp_transport.h"
50#include "pc/dtls_transport.h"
51#include "pc/jsep_transport.h"
Harald Alvestrand9dea3932021-06-10 06:03:06 +000052#include "pc/jsep_transport_collection.h"
Steve Anton10542f22019-01-11 09:11:00 -080053#include "pc/rtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000054#include "pc/rtp_transport_internal.h"
55#include "pc/sctp_transport.h"
56#include "pc/session_description.h"
Steve Anton10542f22019-01-11 09:11:00 -080057#include "pc/srtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000058#include "pc/transport_stats.h"
Mirko Bonadei3d259352020-10-23 12:04:40 +020059#include "rtc_base/callback_list.h"
Harald Alvestrandde22ab22021-06-17 10:45:33 +000060#include "rtc_base/checks.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000061#include "rtc_base/copy_on_write_buffer.h"
62#include "rtc_base/helpers.h"
63#include "rtc_base/ref_counted_object.h"
64#include "rtc_base/rtc_certificate.h"
65#include "rtc_base/ssl_certificate.h"
66#include "rtc_base/ssl_stream_adapter.h"
Artem Titove41c4332018-07-25 15:04:28 +020067#include "rtc_base/third_party/sigslot/sigslot.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000068#include "rtc_base/thread.h"
69#include "rtc_base/thread_annotations.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080070
71namespace rtc {
72class Thread;
73class PacketTransportInternal;
74} // namespace rtc
75
76namespace webrtc {
77
Steve Antond25828a2018-08-31 13:06:05 -070078class JsepTransportController : public sigslot::has_slots<> {
Zhi Huange818b6e2018-02-22 15:26:27 -080079 public:
Zhi Huang365381f2018-04-13 16:44:34 -070080 // Used when the RtpTransport/DtlsTransport of the m= section is changed
81 // because the section is rejected or BUNDLE is enabled.
82 class Observer {
83 public:
84 virtual ~Observer() {}
85
Artem Titov880fa812021-07-30 22:30:23 +020086 // Returns true if media associated with `mid` was successfully set up to be
87 // demultiplexed on `rtp_transport`. Could return false if two bundled m=
Zhi Huang365381f2018-04-13 16:44:34 -070088 // sections use the same SSRC, for example.
Bjorn A Mellemb689af42019-08-21 10:44:59 -070089 //
Artem Titov880fa812021-07-30 22:30:23 +020090 // If a data channel transport must be negotiated, `data_channel_transport`
91 // and `negotiation_state` indicate negotiation status. If
92 // `data_channel_transport` is null, the data channel transport should not
Bjorn A Mellemb689af42019-08-21 10:44:59 -070093 // be used. Otherwise, the value is a pointer to the transport to be used
Artem Titov880fa812021-07-30 22:30:23 +020094 // for data channels on `mid`, if any.
Bjorn A Mellemb689af42019-08-21 10:44:59 -070095 //
Artem Titov880fa812021-07-30 22:30:23 +020096 // The observer should not send data on `data_channel_transport` until
97 // `negotiation_state` is provisional or final. It should not delete
98 // `data_channel_transport` or any fallback transport until
99 // `negotiation_state` is final.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700100 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 16:44:34 -0700101 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700102 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +0100103 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700104 DataChannelTransportInterface* data_channel_transport) = 0;
Zhi Huang365381f2018-04-13 16:44:34 -0700105 };
106
Zhi Huange818b6e2018-02-22 15:26:27 -0800107 struct Config {
Artem Titov880fa812021-07-30 22:30:23 +0200108 // If `redetermine_role_on_ice_restart` is true, ICE role is redetermined
Zhi Huange818b6e2018-02-22 15:26:27 -0800109 // upon setting a local transport description that indicates an ICE
110 // restart.
111 bool redetermine_role_on_ice_restart = true;
112 rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
Artem Titov880fa812021-07-30 22:30:23 +0200113 // `crypto_options` is used to determine if created DTLS transports
Zhi Huange818b6e2018-02-22 15:26:27 -0800114 // negotiate GCM crypto suites or not.
Benjamin Wrighta54daf12018-10-11 15:33:17 -0700115 webrtc::CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 15:26:27 -0800116 PeerConnectionInterface::BundlePolicy bundle_policy =
117 PeerConnectionInterface::kBundlePolicyBalanced;
118 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy =
119 PeerConnectionInterface::kRtcpMuxPolicyRequire;
120 bool disable_encryption = false;
121 bool enable_external_auth = false;
122 // Used to inject the ICE/DTLS transports created externally.
Qingsi Wang25ec8882019-11-15 12:33:05 -0800123 webrtc::IceTransportFactory* ice_transport_factory = nullptr;
124 cricket::DtlsTransportFactory* dtls_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 16:44:34 -0700125 Observer* transport_observer = nullptr;
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200126 // Must be provided and valid for the lifetime of the
127 // JsepTransportController instance.
128 std::function<void(const rtc::CopyOnWriteBuffer& packet,
129 int64_t packet_time_us)>
130 rtcp_handler;
Harald Alvestrand133c0522021-01-29 14:27:12 +0000131 // Initial value for whether DtlsTransport reset causes a reset
132 // of SRTP parameters.
Zhi Huangb57e1692018-06-12 11:41:11 -0700133 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-11 20:15:46 -0700134 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700135
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700136 // Factory for SCTP transports.
Per Kjellander2bca0082020-08-28 09:15:15 +0200137 SctpTransportFactoryInterface* sctp_factory = nullptr;
Lahiru Ginnaliya Gamathige70f9e242021-01-27 23:32:46 -0800138 std::function<void(const rtc::SSLHandshakeError)> on_dtls_handshake_error_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800139 };
140
Artem Titov880fa812021-07-30 22:30:23 +0200141 // The ICE related events are fired on the `network_thread`.
142 // All the transport related methods are called on the `network_thread`
Tommic3257d02021-02-10 17:40:08 +0000143 // and destruction of the JsepTransportController must occur on the
Artem Titov880fa812021-07-30 22:30:23 +0200144 // `network_thread`.
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +0000145 JsepTransportController(
146 rtc::Thread* network_thread,
147 cricket::PortAllocator* port_allocator,
148 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory,
149 Config config);
Zhi Huange818b6e2018-02-22 15:26:27 -0800150 virtual ~JsepTransportController();
151
Byoungchan Leec065e732022-01-18 09:35:48 +0900152 JsepTransportController(const JsepTransportController&) = delete;
153 JsepTransportController& operator=(const JsepTransportController&) = delete;
154
Zhi Huange818b6e2018-02-22 15:26:27 -0800155 // The main method to be called; applies a description at the transport
156 // level, creating/destroying transport objects as needed and updating their
157 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
158 // yet? May make sense to in the future.
159 RTCError SetLocalDescription(SdpType type,
160 const cricket::SessionDescription* description);
161
162 RTCError SetRemoteDescription(SdpType type,
163 const cricket::SessionDescription* description);
164
Artem Titov880fa812021-07-30 22:30:23 +0200165 // Get transports to be used for the provided `mid`. If bundling is enabled,
Zhi Huange818b6e2018-02-22 15:26:27 -0800166 // calling GetRtpTransport for multiple MIDs may yield the same object.
167 RtpTransportInternal* GetRtpTransport(const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100168 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
169 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800170 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100171 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100172 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100173 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700174 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
175 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800176
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700177 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700178 const std::string& mid) const;
179
Zhi Huange818b6e2018-02-22 15:26:27 -0800180 /*********************
181 * ICE-related methods
182 ********************/
183 // This method is public to allow PeerConnection to update it from
184 // SetConfiguration.
185 void SetIceConfig(const cricket::IceConfig& config);
186 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
187 // set, offers should generate new ufrags/passwords until an ICE restart
188 // occurs.
189 void SetNeedsIceRestartFlag();
190 // Returns true if the ICE restart flag above was set, and no ICE restart has
191 // occurred yet for this transport (by applying a local description with
192 // changed ufrag/password). If the transport has been deleted as a result of
193 // bundling, returns false.
194 bool NeedsIceRestart(const std::string& mid) const;
195 // Start gathering candidates for any new transports, or transports doing an
196 // ICE restart.
197 void MaybeStartGathering();
198 RTCError AddRemoteCandidates(
199 const std::string& mid,
200 const std::vector<cricket::Candidate>& candidates);
201 RTCError RemoveRemoteCandidates(
202 const std::vector<cricket::Candidate>& candidates);
203
204 /**********************
205 * DTLS-related methods
206 *********************/
207 // Specifies the identity to use in this session.
208 // Can only be called once.
209 bool SetLocalCertificate(
210 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
211 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
212 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800213 // Caller owns returned certificate chain. This method mainly exists for
214 // stats reporting.
215 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800216 const std::string& mid) const;
217 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200218 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800219
220 // TODO(deadbeef): GetStats isn't const because all the way down to
221 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
222 // const. Fix this.
223 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800224
Zhi Huange830e682018-03-30 10:48:35 -0700225 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700226
Zhi Huangb57e1692018-06-12 11:41:11 -0700227 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
228
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700229 RTCError RollbackTransports();
Eldar Rello5ab79e62019-10-09 18:29:44 +0300230
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800231 // F: void(const std::string&, const std::vector<cricket::Candidate>&)
232 template <typename F>
233 void SubscribeIceCandidateGathered(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000234 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800235 signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
236 }
237
238 // F: void(cricket::IceConnectionState)
239 template <typename F>
240 void SubscribeIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000241 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800242 signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
243 }
244
245 // F: void(PeerConnectionInterface::PeerConnectionState)
246 template <typename F>
247 void SubscribeConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000248 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800249 signal_connection_state_.AddReceiver(std::forward<F>(callback));
250 }
251
252 // F: void(PeerConnectionInterface::IceConnectionState)
253 template <typename F>
254 void SubscribeStandardizedIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000255 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800256 signal_standardized_ice_connection_state_.AddReceiver(
257 std::forward<F>(callback));
258 }
259
260 // F: void(cricket::IceGatheringState)
261 template <typename F>
262 void SubscribeIceGatheringState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000263 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800264 signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
265 }
266
267 // F: void(const cricket::IceCandidateErrorEvent&)
268 template <typename F>
269 void SubscribeIceCandidateError(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000270 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800271 signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
272 }
273
274 // F: void(const std::vector<cricket::Candidate>&)
275 template <typename F>
276 void SubscribeIceCandidatesRemoved(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000277 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800278 signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
279 }
280
281 // F: void(const cricket::CandidatePairChangeEvent&)
282 template <typename F>
283 void SubscribeIceCandidatePairChanged(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000284 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800285 signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
286 }
287
288 private:
Tommic3257d02021-02-10 17:40:08 +0000289 // All of these callbacks are fired on the network thread.
Zhi Huange818b6e2018-02-22 15:26:27 -0800290
291 // If any transport failed => failed,
292 // Else if all completed => completed,
293 // Else if all connected => connected,
294 // Else => connecting
Tommic3257d02021-02-10 17:40:08 +0000295 CallbackList<cricket::IceConnectionState> signal_ice_connection_state_
296 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800297
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800298 CallbackList<PeerConnectionInterface::PeerConnectionState>
Tommic3257d02021-02-10 17:40:08 +0000299 signal_connection_state_ RTC_GUARDED_BY(network_thread_);
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 14:33:45 -0700300
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800301 CallbackList<PeerConnectionInterface::IceConnectionState>
Tommic3257d02021-02-10 17:40:08 +0000302 signal_standardized_ice_connection_state_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200303
Zhi Huange818b6e2018-02-22 15:26:27 -0800304 // If all transports done gathering => complete,
305 // Else if any are gathering => gathering,
306 // Else => new
Tommic3257d02021-02-10 17:40:08 +0000307 CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_
308 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800309
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800310 // [mid, candidates]
311 CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08 +0000312 signal_ice_candidates_gathered_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800313
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800314 CallbackList<const cricket::IceCandidateErrorEvent&>
Tommic3257d02021-02-10 17:40:08 +0000315 signal_ice_candidate_error_ RTC_GUARDED_BY(network_thread_);
Eldar Relloda13ea22019-06-01 12:23:43 +0300316
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800317 CallbackList<const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08 +0000318 signal_ice_candidates_removed_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800319
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800320 CallbackList<const cricket::CandidatePairChangeEvent&>
Tommic3257d02021-02-10 17:40:08 +0000321 signal_ice_candidate_pair_changed_ RTC_GUARDED_BY(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700322
Zhi Huange818b6e2018-02-22 15:26:27 -0800323 RTCError ApplyDescription_n(bool local,
324 SdpType type,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100325 const cricket::SessionDescription* description)
326 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 21:04:26 +0200327 RTCError ValidateAndMaybeUpdateBundleGroups(
Zhi Huangd2248f82018-04-10 14:41:03 -0700328 bool local,
329 SdpType type,
330 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700331 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800332
Harald Alvestrand11b92cf2021-06-17 14:03:09 +0000333 void HandleRejectedContent(const cricket::ContentInfo& content_info)
Niels Möller5cf0ef02021-01-18 14:00:36 +0100334 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 21:04:26 +0200335 bool HandleBundledContent(const cricket::ContentInfo& content_info,
336 const cricket::ContentGroup& bundle_group)
Niels Möller5cf0ef02021-01-18 14:00:36 +0100337 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800338
339 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200340 const cricket::ContentInfo& content_info,
341 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700342 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 10:10:17 +0200343 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800344
Henrik Boströmf8187e02021-04-26 21:04:26 +0200345 std::map<const cricket::ContentGroup*, std::vector<int>>
346 MergeEncryptedHeaderExtensionIdsForBundles(
Zhi Huange818b6e2018-02-22 15:26:27 -0800347 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800348 std::vector<int> GetEncryptedHeaderExtensionIds(
349 const cricket::ContentInfo& content_info);
350
Zhi Huange830e682018-03-30 10:48:35 -0700351 int GetRtpAbsSendTimeHeaderExtensionId(
352 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800353
Zhi Huange830e682018-03-30 10:48:35 -0700354 // This method takes the BUNDLE group into account. If the JsepTransport is
355 // destroyed because of BUNDLE, it would return the transport which other
356 // transports are bundled on (In current implementation, it is the first
357 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700358 const cricket::JsepTransport* GetJsepTransportForMid(
Tomas Gunnarsson92eebef2021-02-10 13:05:44 +0100359 const std::string& mid) const RTC_RUN_ON(network_thread_);
360 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid)
361 RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 10:48:35 -0700362
363 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
364 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700365 const cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 10:22:50 +0100366 const std::string& transport_name) const RTC_RUN_ON(network_thread_);
Zhi Huang365381f2018-04-13 16:44:34 -0700367 cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 10:22:50 +0100368 const std::string& transport_name) RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 10:48:35 -0700369
Anton Sukhanov7940da02018-10-10 10:34:49 -0700370 // Creates jsep transport. Noop if transport is already created.
Artem Titov880fa812021-07-30 22:30:23 +0200371 // Transport is created either during SetLocalDescription (`local` == true) or
372 // during SetRemoteDescription (`local` == false). Passing `local` helps to
Anton Sukhanov7940da02018-10-10 10:34:49 -0700373 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800374 RTCError MaybeCreateJsepTransport(
375 bool local,
376 const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100377 const cricket::SessionDescription& description)
378 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800379
Niels Möller5cf0ef02021-01-18 14:00:36 +0100380 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800381
Niels Möller5cf0ef02021-01-18 14:00:36 +0100382 void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800383
384 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700385 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800386 const cricket::TransportInfo& transport_info,
387 SdpType type,
388 bool local);
389
390 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700391 const cricket::ContentInfo& content_info,
Niels Möller2a707032020-06-16 16:39:13 +0200392 cricket::IceTransportInternal* ice);
Qingsi Wang25ec8882019-11-15 12:33:05 -0800393 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
394 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800395 bool rtcp);
396
397 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
398 const std::string& transport_name,
399 rtc::PacketTransportInternal* rtp_packet_transport,
400 rtc::PacketTransportInternal* rtcp_packet_transport);
401 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
402 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700403 cricket::DtlsTransportInternal* rtp_dtls_transport,
404 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800405 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
406 const std::string& transport_name,
407 cricket::DtlsTransportInternal* rtp_dtls_transport,
408 cricket::DtlsTransportInternal* rtcp_dtls_transport);
409
410 // Collect all the DtlsTransports, including RTP and RTCP, from the
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700411 // JsepTransports, including those not mapped to a MID because they are being
412 // kept alive in case of rollback.
Zhi Huange818b6e2018-02-22 15:26:27 -0800413 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700414 // Same as the above, but doesn't include rollback transports.
415 // JsepTransportController can iterate all the DtlsTransports and update the
416 // aggregate states.
417 std::vector<cricket::DtlsTransportInternal*> GetActiveDtlsTransports();
Zhi Huange818b6e2018-02-22 15:26:27 -0800418
419 // Handlers for signals from Transport.
Niels Möller5cf0ef02021-01-18 14:00:36 +0100420 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport)
421 RTC_RUN_ON(network_thread_);
422 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport)
423 RTC_RUN_ON(network_thread_);
424 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport)
425 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800426 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100427 const cricket::Candidate& candidate)
428 RTC_RUN_ON(network_thread_);
429 void OnTransportCandidateError_n(cricket::IceTransportInternal* transport,
430 const cricket::IceCandidateErrorEvent& event)
431 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800432 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100433 const cricket::Candidates& candidates)
434 RTC_RUN_ON(network_thread_);
435 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport)
436 RTC_RUN_ON(network_thread_);
437 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport)
438 RTC_RUN_ON(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700439 void OnTransportCandidatePairChanged_n(
Niels Möller5cf0ef02021-01-18 14:00:36 +0100440 const cricket::CandidatePairChangeEvent& event)
441 RTC_RUN_ON(network_thread_);
442 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800443
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200444 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100445 int64_t packet_time_us)
446 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200447
Zhi Huange818b6e2018-02-22 15:26:27 -0800448 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
449
Harald Alvestrand9dea3932021-06-10 06:03:06 +0000450 bool OnTransportChanged(const std::string& mid,
451 cricket::JsepTransport* transport);
452
Zhi Huange818b6e2018-02-22 15:26:27 -0800453 rtc::Thread* const network_thread_ = nullptr;
454 cricket::PortAllocator* const port_allocator_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +0000455 AsyncDnsResolverFactoryInterface* const async_dns_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800456
Harald Alvestrand9dea3932021-06-10 06:03:06 +0000457 JsepTransportCollection transports_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200458 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000459 // standardized_ice_connection_state_ is intended to replace
460 // ice_connection_state, see bugs.webrtc.org/9308
461 cricket::IceConnectionState ice_connection_state_ =
462 cricket::kIceConnectionConnecting;
463 PeerConnectionInterface::IceConnectionState
464 standardized_ice_connection_state_ =
465 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200466 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
467 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800468 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
469
Harald Alvestrand133c0522021-01-29 14:27:12 +0000470 const Config config_;
471 bool active_reset_srtp_params_ RTC_GUARDED_BY(network_thread_);
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800472
Zhi Huange818b6e2018-02-22 15:26:27 -0800473 const cricket::SessionDescription* local_desc_ = nullptr;
474 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200475 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800476
Zhi Huange818b6e2018-02-22 15:26:27 -0800477 cricket::IceConfig ice_config_;
478 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
479 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
480 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800481
Harald Alvestrand9f9bf382021-06-08 04:12:37 +0000482 BundleManager bundles_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800483};
484
485} // namespace webrtc
486
Steve Anton10542f22019-01-11 09:11:00 -0800487#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_