blob: ccb7426510a27b85e6338bd1e713fa104903b78f [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>
Harald Alvestrandc24a2182022-02-23 13:44:59 +000020#include <type_traits>
Zhi Huange818b6e2018-02-22 15:26:27 -080021#include <utility>
22#include <vector>
23
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000024#include "absl/types/optional.h"
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000025#include "api/async_dns_resolver.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080026#include "api/candidate.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "api/crypto/crypto_options.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080028#include "api/ice_transport_factory.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000029#include "api/ice_transport_interface.h"
30#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "api/peer_connection_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000032#include "api/rtc_error.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020033#include "api/rtc_event_log/rtc_event_log.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000034#include "api/scoped_refptr.h"
Harald Alvestrandde22ab22021-06-17 10:45:33 +000035#include "api/sequence_checker.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000036#include "api/transport/data_channel_transport_interface.h"
37#include "api/transport/sctp_transport_factory_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080038#include "media/sctp/sctp_transport_internal.h"
39#include "p2p/base/dtls_transport.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080040#include "p2p/base/dtls_transport_factory.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000041#include "p2p/base/dtls_transport_internal.h"
42#include "p2p/base/ice_transport_internal.h"
Steve Anton10542f22019-01-11 09:11:00 -080043#include "p2p/base/p2p_transport_channel.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000044#include "p2p/base/packet_transport_internal.h"
45#include "p2p/base/port.h"
46#include "p2p/base/port_allocator.h"
47#include "p2p/base/transport_description.h"
48#include "p2p/base/transport_info.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;
Ali Tofigh62238092022-01-25 13:27:19 +0100138 std::function<void(rtc::SSLHandshakeError)> on_dtls_handshake_error_;
Jonas Orelanded99dae2022-03-09 09:28:10 +0100139
140 // Field trials.
Jonas Orelande62c2f22022-03-29 11:04:48 +0200141 const webrtc::FieldTrialsView* field_trials;
Zhi Huange818b6e2018-02-22 15:26:27 -0800142 };
143
Artem Titov880fa812021-07-30 22:30:23 +0200144 // The ICE related events are fired on the `network_thread`.
145 // All the transport related methods are called on the `network_thread`
Tommic3257d02021-02-10 17:40:08 +0000146 // and destruction of the JsepTransportController must occur on the
Artem Titov880fa812021-07-30 22:30:23 +0200147 // `network_thread`.
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +0000148 JsepTransportController(
149 rtc::Thread* network_thread,
150 cricket::PortAllocator* port_allocator,
151 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory,
152 Config config);
Zhi Huange818b6e2018-02-22 15:26:27 -0800153 virtual ~JsepTransportController();
154
Byoungchan Leec065e732022-01-18 09:35:48 +0900155 JsepTransportController(const JsepTransportController&) = delete;
156 JsepTransportController& operator=(const JsepTransportController&) = delete;
157
Zhi Huange818b6e2018-02-22 15:26:27 -0800158 // The main method to be called; applies a description at the transport
159 // level, creating/destroying transport objects as needed and updating their
160 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
161 // yet? May make sense to in the future.
162 RTCError SetLocalDescription(SdpType type,
163 const cricket::SessionDescription* description);
164
165 RTCError SetRemoteDescription(SdpType type,
166 const cricket::SessionDescription* description);
167
Artem Titov880fa812021-07-30 22:30:23 +0200168 // Get transports to be used for the provided `mid`. If bundling is enabled,
Zhi Huange818b6e2018-02-22 15:26:27 -0800169 // calling GetRtpTransport for multiple MIDs may yield the same object.
Harald Alvestrand8f429922022-05-04 10:32:30 +0000170 RtpTransportInternal* GetRtpTransport(absl::string_view mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100171 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
172 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800173 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100174 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100175 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100176 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700177 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
178 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800179
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700180 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700181 const std::string& mid) const;
182
Zhi Huange818b6e2018-02-22 15:26:27 -0800183 /*********************
184 * ICE-related methods
185 ********************/
186 // This method is public to allow PeerConnection to update it from
187 // SetConfiguration.
188 void SetIceConfig(const cricket::IceConfig& config);
189 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
190 // set, offers should generate new ufrags/passwords until an ICE restart
191 // occurs.
192 void SetNeedsIceRestartFlag();
193 // Returns true if the ICE restart flag above was set, and no ICE restart has
194 // occurred yet for this transport (by applying a local description with
195 // changed ufrag/password). If the transport has been deleted as a result of
196 // bundling, returns false.
197 bool NeedsIceRestart(const std::string& mid) const;
198 // Start gathering candidates for any new transports, or transports doing an
199 // ICE restart.
200 void MaybeStartGathering();
201 RTCError AddRemoteCandidates(
202 const std::string& mid,
203 const std::vector<cricket::Candidate>& candidates);
204 RTCError RemoveRemoteCandidates(
205 const std::vector<cricket::Candidate>& candidates);
206
207 /**********************
208 * DTLS-related methods
209 *********************/
210 // Specifies the identity to use in this session.
211 // Can only be called once.
212 bool SetLocalCertificate(
213 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
214 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
215 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800216 // Caller owns returned certificate chain. This method mainly exists for
217 // stats reporting.
218 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800219 const std::string& mid) const;
220 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200221 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800222
223 // TODO(deadbeef): GetStats isn't const because all the way down to
224 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
225 // const. Fix this.
226 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800227
Zhi Huange830e682018-03-30 10:48:35 -0700228 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700229
Zhi Huangb57e1692018-06-12 11:41:11 -0700230 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
231
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700232 RTCError RollbackTransports();
Eldar Rello5ab79e62019-10-09 18:29:44 +0300233
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800234 // F: void(const std::string&, const std::vector<cricket::Candidate>&)
235 template <typename F>
236 void SubscribeIceCandidateGathered(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000237 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800238 signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
239 }
240
241 // F: void(cricket::IceConnectionState)
242 template <typename F>
243 void SubscribeIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000244 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800245 signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
246 }
247
248 // F: void(PeerConnectionInterface::PeerConnectionState)
249 template <typename F>
250 void SubscribeConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000251 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800252 signal_connection_state_.AddReceiver(std::forward<F>(callback));
253 }
254
255 // F: void(PeerConnectionInterface::IceConnectionState)
256 template <typename F>
257 void SubscribeStandardizedIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000258 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800259 signal_standardized_ice_connection_state_.AddReceiver(
260 std::forward<F>(callback));
261 }
262
263 // F: void(cricket::IceGatheringState)
264 template <typename F>
265 void SubscribeIceGatheringState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000266 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800267 signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
268 }
269
270 // F: void(const cricket::IceCandidateErrorEvent&)
271 template <typename F>
272 void SubscribeIceCandidateError(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000273 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800274 signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
275 }
276
277 // F: void(const std::vector<cricket::Candidate>&)
278 template <typename F>
279 void SubscribeIceCandidatesRemoved(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000280 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800281 signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
282 }
283
284 // F: void(const cricket::CandidatePairChangeEvent&)
285 template <typename F>
286 void SubscribeIceCandidatePairChanged(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000287 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800288 signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
289 }
290
291 private:
Tommic3257d02021-02-10 17:40:08 +0000292 // All of these callbacks are fired on the network thread.
Zhi Huange818b6e2018-02-22 15:26:27 -0800293
294 // If any transport failed => failed,
295 // Else if all completed => completed,
296 // Else if all connected => connected,
297 // Else => connecting
Tommic3257d02021-02-10 17:40:08 +0000298 CallbackList<cricket::IceConnectionState> signal_ice_connection_state_
299 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800300
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800301 CallbackList<PeerConnectionInterface::PeerConnectionState>
Tommic3257d02021-02-10 17:40:08 +0000302 signal_connection_state_ RTC_GUARDED_BY(network_thread_);
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 14:33:45 -0700303
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800304 CallbackList<PeerConnectionInterface::IceConnectionState>
Tommic3257d02021-02-10 17:40:08 +0000305 signal_standardized_ice_connection_state_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200306
Zhi Huange818b6e2018-02-22 15:26:27 -0800307 // If all transports done gathering => complete,
308 // Else if any are gathering => gathering,
309 // Else => new
Tommic3257d02021-02-10 17:40:08 +0000310 CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_
311 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800312
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800313 // [mid, candidates]
314 CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08 +0000315 signal_ice_candidates_gathered_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800316
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800317 CallbackList<const cricket::IceCandidateErrorEvent&>
Tommic3257d02021-02-10 17:40:08 +0000318 signal_ice_candidate_error_ RTC_GUARDED_BY(network_thread_);
Eldar Relloda13ea22019-06-01 12:23:43 +0300319
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800320 CallbackList<const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08 +0000321 signal_ice_candidates_removed_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800322
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800323 CallbackList<const cricket::CandidatePairChangeEvent&>
Tommic3257d02021-02-10 17:40:08 +0000324 signal_ice_candidate_pair_changed_ RTC_GUARDED_BY(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700325
Zhi Huange818b6e2018-02-22 15:26:27 -0800326 RTCError ApplyDescription_n(bool local,
327 SdpType type,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100328 const cricket::SessionDescription* description)
329 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 21:04:26 +0200330 RTCError ValidateAndMaybeUpdateBundleGroups(
Zhi Huangd2248f82018-04-10 14:41:03 -0700331 bool local,
332 SdpType type,
333 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700334 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800335
Harald Alvestrand11b92cf2021-06-17 14:03:09 +0000336 void HandleRejectedContent(const cricket::ContentInfo& content_info)
Niels Möller5cf0ef02021-01-18 14:00:36 +0100337 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 21:04:26 +0200338 bool HandleBundledContent(const cricket::ContentInfo& content_info,
339 const cricket::ContentGroup& bundle_group)
Niels Möller5cf0ef02021-01-18 14:00:36 +0100340 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800341
342 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200343 const cricket::ContentInfo& content_info,
344 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700345 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 10:10:17 +0200346 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800347
Henrik Boströmf8187e02021-04-26 21:04:26 +0200348 std::map<const cricket::ContentGroup*, std::vector<int>>
349 MergeEncryptedHeaderExtensionIdsForBundles(
Zhi Huange818b6e2018-02-22 15:26:27 -0800350 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800351 std::vector<int> GetEncryptedHeaderExtensionIds(
352 const cricket::ContentInfo& content_info);
353
Zhi Huange830e682018-03-30 10:48:35 -0700354 int GetRtpAbsSendTimeHeaderExtensionId(
355 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800356
Zhi Huange830e682018-03-30 10:48:35 -0700357 // This method takes the BUNDLE group into account. If the JsepTransport is
358 // destroyed because of BUNDLE, it would return the transport which other
359 // transports are bundled on (In current implementation, it is the first
360 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700361 const cricket::JsepTransport* GetJsepTransportForMid(
Tomas Gunnarsson92eebef2021-02-10 13:05:44 +0100362 const std::string& mid) const RTC_RUN_ON(network_thread_);
363 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid)
364 RTC_RUN_ON(network_thread_);
Harald Alvestrand8f429922022-05-04 10:32:30 +0000365 const cricket::JsepTransport* GetJsepTransportForMid(
366 absl::string_view mid) const RTC_RUN_ON(network_thread_);
367 cricket::JsepTransport* GetJsepTransportForMid(absl::string_view mid)
368 RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 10:48:35 -0700369
370 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
371 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700372 const cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 10:22:50 +0100373 const std::string& transport_name) const RTC_RUN_ON(network_thread_);
Zhi Huang365381f2018-04-13 16:44:34 -0700374 cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 10:22:50 +0100375 const std::string& transport_name) RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 10:48:35 -0700376
Anton Sukhanov7940da02018-10-10 10:34:49 -0700377 // Creates jsep transport. Noop if transport is already created.
Artem Titov880fa812021-07-30 22:30:23 +0200378 // Transport is created either during SetLocalDescription (`local` == true) or
379 // during SetRemoteDescription (`local` == false). Passing `local` helps to
Anton Sukhanov7940da02018-10-10 10:34:49 -0700380 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800381 RTCError MaybeCreateJsepTransport(
382 bool local,
383 const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100384 const cricket::SessionDescription& description)
385 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800386
Niels Möller5cf0ef02021-01-18 14:00:36 +0100387 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800388
Niels Möller5cf0ef02021-01-18 14:00:36 +0100389 void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800390
391 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700392 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800393 const cricket::TransportInfo& transport_info,
394 SdpType type,
395 bool local);
396
397 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700398 const cricket::ContentInfo& content_info,
Niels Möller2a707032020-06-16 16:39:13 +0200399 cricket::IceTransportInternal* ice);
Qingsi Wang25ec8882019-11-15 12:33:05 -0800400 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
401 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800402 bool rtcp);
403
404 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
405 const std::string& transport_name,
406 rtc::PacketTransportInternal* rtp_packet_transport,
407 rtc::PacketTransportInternal* rtcp_packet_transport);
408 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
409 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700410 cricket::DtlsTransportInternal* rtp_dtls_transport,
411 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800412 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
413 const std::string& transport_name,
414 cricket::DtlsTransportInternal* rtp_dtls_transport,
415 cricket::DtlsTransportInternal* rtcp_dtls_transport);
416
417 // Collect all the DtlsTransports, including RTP and RTCP, from the
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700418 // JsepTransports, including those not mapped to a MID because they are being
419 // kept alive in case of rollback.
Zhi Huange818b6e2018-02-22 15:26:27 -0800420 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700421 // Same as the above, but doesn't include rollback transports.
422 // JsepTransportController can iterate all the DtlsTransports and update the
423 // aggregate states.
424 std::vector<cricket::DtlsTransportInternal*> GetActiveDtlsTransports();
Zhi Huange818b6e2018-02-22 15:26:27 -0800425
426 // Handlers for signals from Transport.
Niels Möller5cf0ef02021-01-18 14:00:36 +0100427 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport)
428 RTC_RUN_ON(network_thread_);
429 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport)
430 RTC_RUN_ON(network_thread_);
431 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport)
432 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800433 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100434 const cricket::Candidate& candidate)
435 RTC_RUN_ON(network_thread_);
436 void OnTransportCandidateError_n(cricket::IceTransportInternal* transport,
437 const cricket::IceCandidateErrorEvent& event)
438 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800439 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100440 const cricket::Candidates& candidates)
441 RTC_RUN_ON(network_thread_);
442 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport)
443 RTC_RUN_ON(network_thread_);
444 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport)
445 RTC_RUN_ON(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700446 void OnTransportCandidatePairChanged_n(
Niels Möller5cf0ef02021-01-18 14:00:36 +0100447 const cricket::CandidatePairChangeEvent& event)
448 RTC_RUN_ON(network_thread_);
449 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800450
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200451 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100452 int64_t packet_time_us)
453 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200454
Zhi Huange818b6e2018-02-22 15:26:27 -0800455 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
456
Harald Alvestrand9dea3932021-06-10 06:03:06 +0000457 bool OnTransportChanged(const std::string& mid,
458 cricket::JsepTransport* transport);
459
Zhi Huange818b6e2018-02-22 15:26:27 -0800460 rtc::Thread* const network_thread_ = nullptr;
461 cricket::PortAllocator* const port_allocator_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +0000462 AsyncDnsResolverFactoryInterface* const async_dns_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800463
Harald Alvestrand9dea3932021-06-10 06:03:06 +0000464 JsepTransportCollection transports_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200465 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000466 // standardized_ice_connection_state_ is intended to replace
467 // ice_connection_state, see bugs.webrtc.org/9308
468 cricket::IceConnectionState ice_connection_state_ =
469 cricket::kIceConnectionConnecting;
470 PeerConnectionInterface::IceConnectionState
471 standardized_ice_connection_state_ =
472 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200473 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
474 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800475 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
476
Harald Alvestrand133c0522021-01-29 14:27:12 +0000477 const Config config_;
478 bool active_reset_srtp_params_ RTC_GUARDED_BY(network_thread_);
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800479
Zhi Huange818b6e2018-02-22 15:26:27 -0800480 const cricket::SessionDescription* local_desc_ = nullptr;
481 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200482 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800483
Zhi Huange818b6e2018-02-22 15:26:27 -0800484 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_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800488
Harald Alvestrand9f9bf382021-06-08 04:12:37 +0000489 BundleManager bundles_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800490};
491
492} // namespace webrtc
493
Steve Anton10542f22019-01-11 09:11:00 -0800494#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_