blob: 44d5981684f5760faee763b05e449628656b59ff [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"
Zhi Huange818b6e2018-02-22 15:26:27 -080049#include "pc/channel.h"
Steve Anton10542f22019-01-11 09:11:00 -080050#include "pc/dtls_srtp_transport.h"
51#include "pc/dtls_transport.h"
52#include "pc/jsep_transport.h"
Harald Alvestrand9dea3932021-06-10 06:03:06 +000053#include "pc/jsep_transport_collection.h"
Steve Anton10542f22019-01-11 09:11:00 -080054#include "pc/rtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000055#include "pc/rtp_transport_internal.h"
56#include "pc/sctp_transport.h"
57#include "pc/session_description.h"
Steve Anton10542f22019-01-11 09:11:00 -080058#include "pc/srtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000059#include "pc/transport_stats.h"
Mirko Bonadei3d259352020-10-23 12:04:40 +020060#include "rtc_base/callback_list.h"
Harald Alvestrandde22ab22021-06-17 10:45:33 +000061#include "rtc_base/checks.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000062#include "rtc_base/copy_on_write_buffer.h"
63#include "rtc_base/helpers.h"
64#include "rtc_base/ref_counted_object.h"
65#include "rtc_base/rtc_certificate.h"
66#include "rtc_base/ssl_certificate.h"
67#include "rtc_base/ssl_stream_adapter.h"
Artem Titove41c4332018-07-25 15:04:28 +020068#include "rtc_base/third_party/sigslot/sigslot.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000069#include "rtc_base/thread.h"
70#include "rtc_base/thread_annotations.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080071
72namespace rtc {
73class Thread;
74class PacketTransportInternal;
75} // namespace rtc
76
77namespace webrtc {
78
Steve Antond25828a2018-08-31 13:06:05 -070079class JsepTransportController : public sigslot::has_slots<> {
Zhi Huange818b6e2018-02-22 15:26:27 -080080 public:
Zhi Huang365381f2018-04-13 16:44:34 -070081 // Used when the RtpTransport/DtlsTransport of the m= section is changed
82 // because the section is rejected or BUNDLE is enabled.
83 class Observer {
84 public:
85 virtual ~Observer() {}
86
Artem Titov880fa812021-07-30 22:30:23 +020087 // Returns true if media associated with `mid` was successfully set up to be
88 // demultiplexed on `rtp_transport`. Could return false if two bundled m=
Zhi Huang365381f2018-04-13 16:44:34 -070089 // sections use the same SSRC, for example.
Bjorn A Mellemb689af42019-08-21 10:44:59 -070090 //
Artem Titov880fa812021-07-30 22:30:23 +020091 // If a data channel transport must be negotiated, `data_channel_transport`
92 // and `negotiation_state` indicate negotiation status. If
93 // `data_channel_transport` is null, the data channel transport should not
Bjorn A Mellemb689af42019-08-21 10:44:59 -070094 // be used. Otherwise, the value is a pointer to the transport to be used
Artem Titov880fa812021-07-30 22:30:23 +020095 // for data channels on `mid`, if any.
Bjorn A Mellemb689af42019-08-21 10:44:59 -070096 //
Artem Titov880fa812021-07-30 22:30:23 +020097 // The observer should not send data on `data_channel_transport` until
98 // `negotiation_state` is provisional or final. It should not delete
99 // `data_channel_transport` or any fallback transport until
100 // `negotiation_state` is final.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700101 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 16:44:34 -0700102 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700103 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +0100104 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700105 DataChannelTransportInterface* data_channel_transport) = 0;
Zhi Huang365381f2018-04-13 16:44:34 -0700106 };
107
Zhi Huange818b6e2018-02-22 15:26:27 -0800108 struct Config {
Artem Titov880fa812021-07-30 22:30:23 +0200109 // If `redetermine_role_on_ice_restart` is true, ICE role is redetermined
Zhi Huange818b6e2018-02-22 15:26:27 -0800110 // upon setting a local transport description that indicates an ICE
111 // restart.
112 bool redetermine_role_on_ice_restart = true;
113 rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
Artem Titov880fa812021-07-30 22:30:23 +0200114 // `crypto_options` is used to determine if created DTLS transports
Zhi Huange818b6e2018-02-22 15:26:27 -0800115 // negotiate GCM crypto suites or not.
Benjamin Wrighta54daf12018-10-11 15:33:17 -0700116 webrtc::CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 15:26:27 -0800117 PeerConnectionInterface::BundlePolicy bundle_policy =
118 PeerConnectionInterface::kBundlePolicyBalanced;
119 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy =
120 PeerConnectionInterface::kRtcpMuxPolicyRequire;
121 bool disable_encryption = false;
122 bool enable_external_auth = false;
123 // Used to inject the ICE/DTLS transports created externally.
Qingsi Wang25ec8882019-11-15 12:33:05 -0800124 webrtc::IceTransportFactory* ice_transport_factory = nullptr;
125 cricket::DtlsTransportFactory* dtls_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 16:44:34 -0700126 Observer* transport_observer = nullptr;
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200127 // Must be provided and valid for the lifetime of the
128 // JsepTransportController instance.
129 std::function<void(const rtc::CopyOnWriteBuffer& packet,
130 int64_t packet_time_us)>
131 rtcp_handler;
Harald Alvestrand133c0522021-01-29 14:27:12 +0000132 // Initial value for whether DtlsTransport reset causes a reset
133 // of SRTP parameters.
Zhi Huangb57e1692018-06-12 11:41:11 -0700134 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-11 20:15:46 -0700135 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700136
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700137 // Factory for SCTP transports.
Per Kjellander2bca0082020-08-28 09:15:15 +0200138 SctpTransportFactoryInterface* sctp_factory = nullptr;
Ali Tofigh62238092022-01-25 13:27:19 +0100139 std::function<void(rtc::SSLHandshakeError)> on_dtls_handshake_error_;
Jonas Orelanded99dae2022-03-09 09:28:10 +0100140
141 // Field trials.
142 const webrtc::WebRtcKeyValueConfig* field_trials;
Zhi Huange818b6e2018-02-22 15:26:27 -0800143 };
144
Artem Titov880fa812021-07-30 22:30:23 +0200145 // The ICE related events are fired on the `network_thread`.
146 // All the transport related methods are called on the `network_thread`
Tommic3257d02021-02-10 17:40:08 +0000147 // and destruction of the JsepTransportController must occur on the
Artem Titov880fa812021-07-30 22:30:23 +0200148 // `network_thread`.
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +0000149 JsepTransportController(
150 rtc::Thread* network_thread,
151 cricket::PortAllocator* port_allocator,
152 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory,
153 Config config);
Zhi Huange818b6e2018-02-22 15:26:27 -0800154 virtual ~JsepTransportController();
155
Byoungchan Leec065e732022-01-18 09:35:48 +0900156 JsepTransportController(const JsepTransportController&) = delete;
157 JsepTransportController& operator=(const JsepTransportController&) = delete;
158
Zhi Huange818b6e2018-02-22 15:26:27 -0800159 // The main method to be called; applies a description at the transport
160 // level, creating/destroying transport objects as needed and updating their
161 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
162 // yet? May make sense to in the future.
163 RTCError SetLocalDescription(SdpType type,
164 const cricket::SessionDescription* description);
165
166 RTCError SetRemoteDescription(SdpType type,
167 const cricket::SessionDescription* description);
168
Artem Titov880fa812021-07-30 22:30:23 +0200169 // Get transports to be used for the provided `mid`. If bundling is enabled,
Zhi Huange818b6e2018-02-22 15:26:27 -0800170 // calling GetRtpTransport for multiple MIDs may yield the same object.
171 RtpTransportInternal* GetRtpTransport(const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100172 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
173 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800174 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100175 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100176 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100177 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700178 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
179 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800180
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700181 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700182 const std::string& mid) const;
183
Zhi Huange818b6e2018-02-22 15:26:27 -0800184 /*********************
185 * ICE-related methods
186 ********************/
187 // This method is public to allow PeerConnection to update it from
188 // SetConfiguration.
189 void SetIceConfig(const cricket::IceConfig& config);
190 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
191 // set, offers should generate new ufrags/passwords until an ICE restart
192 // occurs.
193 void SetNeedsIceRestartFlag();
194 // Returns true if the ICE restart flag above was set, and no ICE restart has
195 // occurred yet for this transport (by applying a local description with
196 // changed ufrag/password). If the transport has been deleted as a result of
197 // bundling, returns false.
198 bool NeedsIceRestart(const std::string& mid) const;
199 // Start gathering candidates for any new transports, or transports doing an
200 // ICE restart.
201 void MaybeStartGathering();
202 RTCError AddRemoteCandidates(
203 const std::string& mid,
204 const std::vector<cricket::Candidate>& candidates);
205 RTCError RemoveRemoteCandidates(
206 const std::vector<cricket::Candidate>& candidates);
207
208 /**********************
209 * DTLS-related methods
210 *********************/
211 // Specifies the identity to use in this session.
212 // Can only be called once.
213 bool SetLocalCertificate(
214 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
215 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
216 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800217 // Caller owns returned certificate chain. This method mainly exists for
218 // stats reporting.
219 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800220 const std::string& mid) const;
221 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200222 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800223
224 // TODO(deadbeef): GetStats isn't const because all the way down to
225 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
226 // const. Fix this.
227 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800228
Zhi Huange830e682018-03-30 10:48:35 -0700229 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700230
Zhi Huangb57e1692018-06-12 11:41:11 -0700231 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
232
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700233 RTCError RollbackTransports();
Eldar Rello5ab79e62019-10-09 18:29:44 +0300234
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800235 // F: void(const std::string&, const std::vector<cricket::Candidate>&)
236 template <typename F>
237 void SubscribeIceCandidateGathered(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000238 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800239 signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
240 }
241
242 // F: void(cricket::IceConnectionState)
243 template <typename F>
244 void SubscribeIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000245 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800246 signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
247 }
248
249 // F: void(PeerConnectionInterface::PeerConnectionState)
250 template <typename F>
251 void SubscribeConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000252 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800253 signal_connection_state_.AddReceiver(std::forward<F>(callback));
254 }
255
256 // F: void(PeerConnectionInterface::IceConnectionState)
257 template <typename F>
258 void SubscribeStandardizedIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000259 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800260 signal_standardized_ice_connection_state_.AddReceiver(
261 std::forward<F>(callback));
262 }
263
264 // F: void(cricket::IceGatheringState)
265 template <typename F>
266 void SubscribeIceGatheringState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000267 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800268 signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
269 }
270
271 // F: void(const cricket::IceCandidateErrorEvent&)
272 template <typename F>
273 void SubscribeIceCandidateError(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000274 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800275 signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
276 }
277
278 // F: void(const std::vector<cricket::Candidate>&)
279 template <typename F>
280 void SubscribeIceCandidatesRemoved(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000281 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800282 signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
283 }
284
285 // F: void(const cricket::CandidatePairChangeEvent&)
286 template <typename F>
287 void SubscribeIceCandidatePairChanged(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000288 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800289 signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
290 }
291
292 private:
Tommic3257d02021-02-10 17:40:08 +0000293 // All of these callbacks are fired on the network thread.
Zhi Huange818b6e2018-02-22 15:26:27 -0800294
295 // If any transport failed => failed,
296 // Else if all completed => completed,
297 // Else if all connected => connected,
298 // Else => connecting
Tommic3257d02021-02-10 17:40:08 +0000299 CallbackList<cricket::IceConnectionState> signal_ice_connection_state_
300 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800301
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800302 CallbackList<PeerConnectionInterface::PeerConnectionState>
Tommic3257d02021-02-10 17:40:08 +0000303 signal_connection_state_ RTC_GUARDED_BY(network_thread_);
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 14:33:45 -0700304
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800305 CallbackList<PeerConnectionInterface::IceConnectionState>
Tommic3257d02021-02-10 17:40:08 +0000306 signal_standardized_ice_connection_state_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200307
Zhi Huange818b6e2018-02-22 15:26:27 -0800308 // If all transports done gathering => complete,
309 // Else if any are gathering => gathering,
310 // Else => new
Tommic3257d02021-02-10 17:40:08 +0000311 CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_
312 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800313
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800314 // [mid, candidates]
315 CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08 +0000316 signal_ice_candidates_gathered_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800317
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800318 CallbackList<const cricket::IceCandidateErrorEvent&>
Tommic3257d02021-02-10 17:40:08 +0000319 signal_ice_candidate_error_ RTC_GUARDED_BY(network_thread_);
Eldar Relloda13ea22019-06-01 12:23:43 +0300320
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800321 CallbackList<const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08 +0000322 signal_ice_candidates_removed_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800323
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800324 CallbackList<const cricket::CandidatePairChangeEvent&>
Tommic3257d02021-02-10 17:40:08 +0000325 signal_ice_candidate_pair_changed_ RTC_GUARDED_BY(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700326
Zhi Huange818b6e2018-02-22 15:26:27 -0800327 RTCError ApplyDescription_n(bool local,
328 SdpType type,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100329 const cricket::SessionDescription* description)
330 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 21:04:26 +0200331 RTCError ValidateAndMaybeUpdateBundleGroups(
Zhi Huangd2248f82018-04-10 14:41:03 -0700332 bool local,
333 SdpType type,
334 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700335 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800336
Harald Alvestrand11b92cf2021-06-17 14:03:09 +0000337 void HandleRejectedContent(const cricket::ContentInfo& content_info)
Niels Möller5cf0ef02021-01-18 14:00:36 +0100338 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 21:04:26 +0200339 bool HandleBundledContent(const cricket::ContentInfo& content_info,
340 const cricket::ContentGroup& bundle_group)
Niels Möller5cf0ef02021-01-18 14:00:36 +0100341 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800342
343 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200344 const cricket::ContentInfo& content_info,
345 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700346 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 10:10:17 +0200347 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800348
Henrik Boströmf8187e02021-04-26 21:04:26 +0200349 std::map<const cricket::ContentGroup*, std::vector<int>>
350 MergeEncryptedHeaderExtensionIdsForBundles(
Zhi Huange818b6e2018-02-22 15:26:27 -0800351 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(
Tomas Gunnarsson92eebef2021-02-10 13:05:44 +0100363 const std::string& mid) const RTC_RUN_ON(network_thread_);
364 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid)
365 RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 10:48:35 -0700366
367 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
368 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700369 const cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 10:22:50 +0100370 const std::string& transport_name) const RTC_RUN_ON(network_thread_);
Zhi Huang365381f2018-04-13 16:44:34 -0700371 cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 10:22:50 +0100372 const std::string& transport_name) RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 10:48:35 -0700373
Anton Sukhanov7940da02018-10-10 10:34:49 -0700374 // Creates jsep transport. Noop if transport is already created.
Artem Titov880fa812021-07-30 22:30:23 +0200375 // Transport is created either during SetLocalDescription (`local` == true) or
376 // during SetRemoteDescription (`local` == false). Passing `local` helps to
Anton Sukhanov7940da02018-10-10 10:34:49 -0700377 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800378 RTCError MaybeCreateJsepTransport(
379 bool local,
380 const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100381 const cricket::SessionDescription& description)
382 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800383
Niels Möller5cf0ef02021-01-18 14:00:36 +0100384 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800385
Niels Möller5cf0ef02021-01-18 14:00:36 +0100386 void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800387
388 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700389 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800390 const cricket::TransportInfo& transport_info,
391 SdpType type,
392 bool local);
393
394 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700395 const cricket::ContentInfo& content_info,
Niels Möller2a707032020-06-16 16:39:13 +0200396 cricket::IceTransportInternal* ice);
Qingsi Wang25ec8882019-11-15 12:33:05 -0800397 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
398 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800399 bool rtcp);
400
401 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
402 const std::string& transport_name,
403 rtc::PacketTransportInternal* rtp_packet_transport,
404 rtc::PacketTransportInternal* rtcp_packet_transport);
405 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
406 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700407 cricket::DtlsTransportInternal* rtp_dtls_transport,
408 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800409 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
410 const std::string& transport_name,
411 cricket::DtlsTransportInternal* rtp_dtls_transport,
412 cricket::DtlsTransportInternal* rtcp_dtls_transport);
413
414 // Collect all the DtlsTransports, including RTP and RTCP, from the
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700415 // JsepTransports, including those not mapped to a MID because they are being
416 // kept alive in case of rollback.
Zhi Huange818b6e2018-02-22 15:26:27 -0800417 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700418 // Same as the above, but doesn't include rollback transports.
419 // JsepTransportController can iterate all the DtlsTransports and update the
420 // aggregate states.
421 std::vector<cricket::DtlsTransportInternal*> GetActiveDtlsTransports();
Zhi Huange818b6e2018-02-22 15:26:27 -0800422
423 // Handlers for signals from Transport.
Niels Möller5cf0ef02021-01-18 14:00:36 +0100424 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport)
425 RTC_RUN_ON(network_thread_);
426 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport)
427 RTC_RUN_ON(network_thread_);
428 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport)
429 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800430 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100431 const cricket::Candidate& candidate)
432 RTC_RUN_ON(network_thread_);
433 void OnTransportCandidateError_n(cricket::IceTransportInternal* transport,
434 const cricket::IceCandidateErrorEvent& event)
435 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800436 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100437 const cricket::Candidates& candidates)
438 RTC_RUN_ON(network_thread_);
439 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport)
440 RTC_RUN_ON(network_thread_);
441 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport)
442 RTC_RUN_ON(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700443 void OnTransportCandidatePairChanged_n(
Niels Möller5cf0ef02021-01-18 14:00:36 +0100444 const cricket::CandidatePairChangeEvent& event)
445 RTC_RUN_ON(network_thread_);
446 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800447
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200448 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100449 int64_t packet_time_us)
450 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200451
Zhi Huange818b6e2018-02-22 15:26:27 -0800452 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
453
Harald Alvestrand9dea3932021-06-10 06:03:06 +0000454 bool OnTransportChanged(const std::string& mid,
455 cricket::JsepTransport* transport);
456
Zhi Huange818b6e2018-02-22 15:26:27 -0800457 rtc::Thread* const network_thread_ = nullptr;
458 cricket::PortAllocator* const port_allocator_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +0000459 AsyncDnsResolverFactoryInterface* const async_dns_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800460
Harald Alvestrand9dea3932021-06-10 06:03:06 +0000461 JsepTransportCollection transports_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200462 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000463 // standardized_ice_connection_state_ is intended to replace
464 // ice_connection_state, see bugs.webrtc.org/9308
465 cricket::IceConnectionState ice_connection_state_ =
466 cricket::kIceConnectionConnecting;
467 PeerConnectionInterface::IceConnectionState
468 standardized_ice_connection_state_ =
469 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200470 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
471 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800472 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
473
Harald Alvestrand133c0522021-01-29 14:27:12 +0000474 const Config config_;
475 bool active_reset_srtp_params_ RTC_GUARDED_BY(network_thread_);
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800476
Zhi Huange818b6e2018-02-22 15:26:27 -0800477 const cricket::SessionDescription* local_desc_ = nullptr;
478 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200479 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800480
Zhi Huange818b6e2018-02-22 15:26:27 -0800481 cricket::IceConfig ice_config_;
482 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
483 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
484 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800485
Harald Alvestrand9f9bf382021-06-08 04:12:37 +0000486 BundleManager bundles_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800487};
488
489} // namespace webrtc
490
Steve Anton10542f22019-01-11 09:11:00 -0800491#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_