Thanks to visit codestin.com
Credit goes to webrtc.googlesource.com

blob: 72fc7aa59abb567320fdcfc37ae52062f655c864 [file] [log] [blame]
Zhi Huange818b6e2018-02-22 23:26:271/*
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 17:11:0011#ifndef PC_JSEP_TRANSPORT_CONTROLLER_H_
12#define PC_JSEP_TRANSPORT_CONTROLLER_H_
Zhi Huange818b6e2018-02-22 23:26:2713
Harald Alvestrand5761e7b2021-01-29 14:45:0814#include <stdint.h>
15
16#include <functional>
Zhi Huange818b6e2018-02-22 23:26:2717#include <map>
18#include <memory>
Florent Castelli8037fc62024-08-29 13:00:4019#include <optional>
Zhi Huange818b6e2018-02-22 23:26:2720#include <string>
21#include <utility>
22#include <vector>
23
Per Ke1e94ad2023-03-30 14:53:5924#include "absl/functional/any_invocable.h"
Harald Alvestrandc17ca012024-09-03 11:20:3625#include "absl/strings/string_view.h"
Harald Alvestrand0ccfbd22021-04-08 07:25:0426#include "api/async_dns_resolver.h"
Zhi Huange818b6e2018-02-22 23:26:2727#include "api/candidate.h"
Steve Anton10542f22019-01-11 17:11:0028#include "api/crypto/crypto_options.h"
Victor Boiviecd54fd82024-02-28 11:16:1529#include "api/environment/environment.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0830#include "api/ice_transport_interface.h"
31#include "api/jsep.h"
Giovanni Ortuño Urquidie2cfc362025-06-13 21:23:3632#include "api/local_network_access_permission.h"
Steve Anton10542f22019-01-11 17:11:0033#include "api/peer_connection_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0834#include "api/rtc_error.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0835#include "api/scoped_refptr.h"
Harald Alvestrandde22ab22021-06-17 10:45:3336#include "api/sequence_checker.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0837#include "api/transport/data_channel_transport_interface.h"
Per K12103ce2025-11-12 16:04:4938#include "api/transport/ecn_marking.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0839#include "api/transport/sctp_transport_factory_interface.h"
Per K12103ce2025-11-12 16:04:4940#include "api/units/timestamp.h"
Harald Alvestrandc17ca012024-09-03 11:20:3641#include "call/payload_type.h"
42#include "call/payload_type_picker.h"
43#include "media/base/codec.h"
44#include "modules/rtp_rtcp/source/rtp_packet_received.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0845#include "p2p/base/ice_transport_internal.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0846#include "p2p/base/packet_transport_internal.h"
47#include "p2p/base/port.h"
48#include "p2p/base/port_allocator.h"
49#include "p2p/base/transport_description.h"
50#include "p2p/base/transport_info.h"
Philipp Hancke740d7262024-12-09 05:26:3451#include "p2p/dtls/dtls_transport_factory.h"
52#include "p2p/dtls/dtls_transport_internal.h"
Steve Anton10542f22019-01-11 17:11:0053#include "pc/dtls_srtp_transport.h"
54#include "pc/dtls_transport.h"
55#include "pc/jsep_transport.h"
Harald Alvestrand9dea3932021-06-10 06:03:0656#include "pc/jsep_transport_collection.h"
Steve Anton10542f22019-01-11 17:11:0057#include "pc/rtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0858#include "pc/rtp_transport_internal.h"
59#include "pc/sctp_transport.h"
60#include "pc/session_description.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0861#include "pc/transport_stats.h"
Mirko Bonadei3d259352020-10-23 10:04:4062#include "rtc_base/callback_list.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0863#include "rtc_base/copy_on_write_buffer.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0864#include "rtc_base/rtc_certificate.h"
65#include "rtc_base/ssl_certificate.h"
66#include "rtc_base/ssl_stream_adapter.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0867#include "rtc_base/thread.h"
68#include "rtc_base/thread_annotations.h"
Zhi Huange818b6e2018-02-22 23:26:2769
Zhi Huange818b6e2018-02-22 23:26:2770namespace webrtc {
71
Harald Alvestrand660b3fa92025-10-16 10:12:2572class JsepTransportController : public PayloadTypeSuggester {
Zhi Huange818b6e2018-02-22 23:26:2773 public:
Zhi Huang365381f2018-04-13 23:44:3474 // Used when the RtpTransport/DtlsTransport of the m= section is changed
75 // because the section is rejected or BUNDLE is enabled.
76 class Observer {
77 public:
78 virtual ~Observer() {}
79
Artem Titov880fa812021-07-30 20:30:2380 // Returns true if media associated with `mid` was successfully set up to be
81 // demultiplexed on `rtp_transport`. Could return false if two bundled m=
Zhi Huang365381f2018-04-13 23:44:3482 // sections use the same SSRC, for example.
Bjorn A Mellemb689af42019-08-21 17:44:5983 //
Artem Titov880fa812021-07-30 20:30:2384 // If a data channel transport must be negotiated, `data_channel_transport`
85 // and `negotiation_state` indicate negotiation status. If
86 // `data_channel_transport` is null, the data channel transport should not
Bjorn A Mellemb689af42019-08-21 17:44:5987 // be used. Otherwise, the value is a pointer to the transport to be used
Artem Titov880fa812021-07-30 20:30:2388 // for data channels on `mid`, if any.
Bjorn A Mellemb689af42019-08-21 17:44:5989 //
Artem Titov880fa812021-07-30 20:30:2390 // The observer should not send data on `data_channel_transport` until
91 // `negotiation_state` is provisional or final. It should not delete
92 // `data_channel_transport` or any fallback transport until
93 // `negotiation_state` is final.
Taylor Brandstettercbaa2542018-04-16 23:42:1494 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 23:44:3495 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 23:42:1496 RtpTransportInternal* rtp_transport,
Evan Shrubsolee6a1f702025-04-15 14:55:4297 scoped_refptr<DtlsTransport> dtls_transport,
Bjorn A Mellembc3eebc2019-09-23 21:53:5498 DataChannelTransportInterface* data_channel_transport) = 0;
Zhi Huang365381f2018-04-13 23:44:3499 };
100
Zhi Huange818b6e2018-02-22 23:26:27101 struct Config {
Artem Titov880fa812021-07-30 20:30:23102 // If `redetermine_role_on_ice_restart` is true, ICE role is redetermined
Zhi Huange818b6e2018-02-22 23:26:27103 // upon setting a local transport description that indicates an ICE
104 // restart.
105 bool redetermine_role_on_ice_restart = true;
Evan Shrubsoleeb835d02025-03-12 09:41:06106 SSLProtocolVersion ssl_max_version = SSL_PROTOCOL_DTLS_12;
Artem Titov880fa812021-07-30 20:30:23107 // `crypto_options` is used to determine if created DTLS transports
Zhi Huange818b6e2018-02-22 23:26:27108 // negotiate GCM crypto suites or not.
Harald Alvestranda6544372023-11-13 09:33:56109 CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 23:26:27110 PeerConnectionInterface::BundlePolicy bundle_policy =
111 PeerConnectionInterface::kBundlePolicyBalanced;
112 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy =
113 PeerConnectionInterface::kRtcpMuxPolicyRequire;
114 bool disable_encryption = false;
115 bool enable_external_auth = false;
116 // Used to inject the ICE/DTLS transports created externally.
Harald Alvestranda6544372023-11-13 09:33:56117 IceTransportFactory* ice_transport_factory = nullptr;
Evan Shrubsole945e5172025-04-08 14:11:45118 DtlsTransportFactory* dtls_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 23:44:34119 Observer* transport_observer = nullptr;
Sebastian Jansson1b83a9e2019-09-18 16:22:12120 // Must be provided and valid for the lifetime of the
121 // JsepTransportController instance.
Per K12103ce2025-11-12 16:04:49122 absl::AnyInvocable<void(const CopyOnWriteBuffer& packet,
Per Ke1e94ad2023-03-30 14:53:59123 int64_t packet_time_us) const>
Sebastian Jansson1b83a9e2019-09-18 16:22:12124 rtcp_handler;
Per Ke1e94ad2023-03-30 14:53:59125 absl::AnyInvocable<void(const RtpPacketReceived& parsed_packet) const>
126 un_demuxable_packet_handler;
Harald Alvestrand133c0522021-01-29 14:27:12127 // Initial value for whether DtlsTransport reset causes a reset
128 // of SRTP parameters.
Zhi Huangb57e1692018-06-12 18:41:11129 bool active_reset_srtp_params = false;
Anton Sukhanov7940da02018-10-10 17:34:49130
Bjorn A Mellembc3eebc2019-09-23 21:53:54131 // Factory for SCTP transports.
Per Kjellander2bca0082020-08-28 07:15:15132 SctpTransportFactoryInterface* sctp_factory = nullptr;
Per K12103ce2025-11-12 16:04:49133 std::function<void(SSLHandshakeError)> on_dtls_handshake_error_;
Zhi Huange818b6e2018-02-22 23:26:27134 };
135
Artem Titov880fa812021-07-30 20:30:23136 // The ICE related events are fired on the `network_thread`.
137 // All the transport related methods are called on the `network_thread`
Tommic3257d02021-02-10 17:40:08138 // and destruction of the JsepTransportController must occur on the
Artem Titov880fa812021-07-30 20:30:23139 // `network_thread`.
Harald Alvestrand0ccfbd22021-04-08 07:25:04140 JsepTransportController(
Victor Boiviecd54fd82024-02-28 11:16:15141 const Environment& env,
Evan Shrubsole6a9a1ae2025-03-21 12:54:15142 Thread* network_thread,
Evan Shrubsole080cdac2025-03-20 09:34:48143 PortAllocator* port_allocator,
Harald Alvestrand0ccfbd22021-04-08 07:25:04144 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory,
Giovanni Ortuño Urquidie2cfc362025-06-13 21:23:36145 LocalNetworkAccessPermissionFactoryInterface* lna_permission_factory,
Harald Alvestrand53086522024-08-25 16:43:08146 PayloadTypePicker& payload_type_picker,
Harald Alvestrand0ccfbd22021-04-08 07:25:04147 Config config);
Zhi Huange818b6e2018-02-22 23:26:27148 virtual ~JsepTransportController();
149
Byoungchan Leec065e732022-01-18 00:35:48150 JsepTransportController(const JsepTransportController&) = delete;
151 JsepTransportController& operator=(const JsepTransportController&) = delete;
152
Zhi Huange818b6e2018-02-22 23:26:27153 // The main method to be called; applies a description at the transport
154 // level, creating/destroying transport objects as needed and updating their
155 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
156 // yet? May make sense to in the future.
Tommic5605202024-01-11 21:15:27157 //
158 // `local_desc` must always be valid. If a remote description has previously
159 // been set via a call to `SetRemoteDescription()` then `remote_desc` should
160 // point to that description object in order to keep the current local and
161 // remote session descriptions in sync.
Zhi Huange818b6e2018-02-22 23:26:27162 RTCError SetLocalDescription(SdpType type,
Evan Shrubsole080cdac2025-03-20 09:34:48163 const SessionDescription* local_desc,
164 const SessionDescription* remote_desc);
Zhi Huange818b6e2018-02-22 23:26:27165
Tommic5605202024-01-11 21:15:27166 // Call to apply a remote description (See `SetLocalDescription()` for local).
167 //
168 // `remote_desc` must always be valid. If a local description has previously
169 // been set via a call to `SetLocalDescription()` then `local_desc` should
170 // point to that description object in order to keep the current local and
171 // remote session descriptions in sync.
Zhi Huange818b6e2018-02-22 23:26:27172 RTCError SetRemoteDescription(SdpType type,
Evan Shrubsole080cdac2025-03-20 09:34:48173 const SessionDescription* local_desc,
174 const SessionDescription* remote_desc);
Zhi Huange818b6e2018-02-22 23:26:27175
Artem Titov880fa812021-07-30 20:30:23176 // Get transports to be used for the provided `mid`. If bundling is enabled,
Zhi Huange818b6e2018-02-22 23:26:27177 // calling GetRtpTransport for multiple MIDs may yield the same object.
Harald Alvestrand8f429922022-05-04 10:32:30178 RtpTransportInternal* GetRtpTransport(absl::string_view mid) const;
Evan Shrubsole945e5172025-04-08 14:11:45179 DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
180 const DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 23:26:27181 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 15:47:46182 // Gets the externally sharable version of the DtlsTransport.
Evan Shrubsolee6a1f702025-04-15 14:55:42183 scoped_refptr<DtlsTransport> LookupDtlsTransportByMid(const std::string& mid);
184 scoped_refptr<SctpTransport> GetSctpTransport(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 23:26:27185
Bjorn A Mellemb689af42019-08-21 17:44:59186 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 22:50:38187 const std::string& mid) const;
188
Zhi Huange818b6e2018-02-22 23:26:27189 /*********************
190 * ICE-related methods
191 ********************/
192 // This method is public to allow PeerConnection to update it from
193 // SetConfiguration.
Evan Shrubsole080cdac2025-03-20 09:34:48194 void SetIceConfig(const IceConfig& config);
Zhi Huange818b6e2018-02-22 23:26:27195 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
196 // set, offers should generate new ufrags/passwords until an ICE restart
197 // occurs.
198 void SetNeedsIceRestartFlag();
199 // Returns true if the ICE restart flag above was set, and no ICE restart has
200 // occurred yet for this transport (by applying a local description with
201 // changed ufrag/password). If the transport has been deleted as a result of
202 // bundling, returns false.
203 bool NeedsIceRestart(const std::string& mid) const;
204 // Start gathering candidates for any new transports, or transports doing an
205 // ICE restart.
206 void MaybeStartGathering();
Evan Shrubsole080cdac2025-03-20 09:34:48207 RTCError AddRemoteCandidates(const std::string& mid,
208 const std::vector<Candidate>& candidates);
Tommi4fad2612025-07-06 10:01:57209 bool RemoveRemoteCandidate(const IceCandidate* candidate);
Zhi Huange818b6e2018-02-22 23:26:27210
211 /**********************
212 * DTLS-related methods
213 *********************/
214 // Specifies the identity to use in this session.
215 // Can only be called once.
Evan Shrubsolee6a1f702025-04-15 14:55:42216 bool SetLocalCertificate(const scoped_refptr<RTCCertificate>& certificate);
217 scoped_refptr<RTCCertificate> GetLocalCertificate(
Zhi Huange818b6e2018-02-22 23:26:27218 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 21:04:51219 // Caller owns returned certificate chain. This method mainly exists for
220 // stats reporting.
Evan Shrubsoledaf96cf2025-03-31 12:34:02221 std::unique_ptr<SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 23:26:27222 const std::string& mid) const;
223 // Get negotiated role, if one has been negotiated.
Evan Shrubsoleeb835d02025-03-12 09:41:06224 std::optional<SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 23:26:27225
Harald Alvestrand84ce5452024-08-26 16:02:11226 // Suggest a payload type for a given codec on a given media section.
227 // Media section is indicated by MID.
228 // The function will either return a PT already in use on the connection
229 // or a newly suggested one.
230 RTCErrorOr<PayloadType> SuggestPayloadType(const std::string& mid,
Evan Shrubsole0b212e32025-04-07 13:43:01231 Codec codec) override;
Harald Alvestranddc56a362024-09-07 20:38:29232 RTCError AddLocalMapping(const std::string& mid,
233 PayloadType payload_type,
Evan Shrubsole0b212e32025-04-07 13:43:01234 const Codec& codec) override;
Harald Alvestrand81fb1de2025-03-31 09:38:11235 const PayloadTypePicker& PayloadTypePickerForTesting() const {
236 return payload_type_picker_;
237 }
Harald Alvestrand84ce5452024-08-26 16:02:11238
Evan Shrubsole3c825f12025-04-04 14:07:27239 bool GetStats(const std::string& mid, TransportStats* stats) const;
Zhi Huange818b6e2018-02-22 23:26:27240
Zhi Huange830e682018-03-30 17:48:35241 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 23:44:34242
Zhi Huangb57e1692018-06-12 18:41:11243 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
244
Taylor Brandstetter8591eff2021-08-11 21:56:38245 RTCError RollbackTransports();
Eldar Rello5ab79e62019-10-09 15:29:44246
Evan Shrubsolee6a1f702025-04-15 14:55:42247 // F: void(const std::string&, const std::vector<webrtc::Candidate>&)
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22248 template <typename F>
249 void SubscribeIceCandidateGathered(F&& callback) {
Tommic3257d02021-02-10 17:40:08250 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22251 signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
252 }
253
Evan Shrubsolee6a1f702025-04-15 14:55:42254 // F: void(webrtc::IceConnectionState)
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22255 template <typename F>
256 void SubscribeIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08257 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22258 signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
259 }
260
261 // F: void(PeerConnectionInterface::PeerConnectionState)
262 template <typename F>
263 void SubscribeConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08264 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22265 signal_connection_state_.AddReceiver(std::forward<F>(callback));
266 }
267
268 // F: void(PeerConnectionInterface::IceConnectionState)
269 template <typename F>
270 void SubscribeStandardizedIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08271 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22272 signal_standardized_ice_connection_state_.AddReceiver(
273 std::forward<F>(callback));
274 }
275
Evan Shrubsolee6a1f702025-04-15 14:55:42276 // F: void(webrtc::IceGatheringState)
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22277 template <typename F>
278 void SubscribeIceGatheringState(F&& callback) {
Tommic3257d02021-02-10 17:40:08279 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22280 signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
281 }
282
Evan Shrubsolee6a1f702025-04-15 14:55:42283 // F: void(const webrtc::IceCandidateErrorEvent&)
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22284 template <typename F>
285 void SubscribeIceCandidateError(F&& callback) {
Tommic3257d02021-02-10 17:40:08286 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22287 signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
288 }
289
Evan Shrubsolee6a1f702025-04-15 14:55:42290 // F: void(const std::vector<webrtc::Candidate>&)
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22291 template <typename F>
292 void SubscribeIceCandidatesRemoved(F&& callback) {
Tommic3257d02021-02-10 17:40:08293 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22294 signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
295 }
296
Evan Shrubsolee6a1f702025-04-15 14:55:42297 // F: void(const webrtc::CandidatePairChangeEvent&)
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22298 template <typename F>
299 void SubscribeIceCandidatePairChanged(F&& callback) {
Tommic3257d02021-02-10 17:40:08300 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22301 signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
302 }
303
304 private:
Tommic3257d02021-02-10 17:40:08305 // All of these callbacks are fired on the network thread.
Zhi Huange818b6e2018-02-22 23:26:27306
307 // If any transport failed => failed,
308 // Else if all completed => completed,
309 // Else if all connected => connected,
310 // Else => connecting
Evan Shrubsolee6a1f702025-04-15 14:55:42311 CallbackList<IceConnectionState> signal_ice_connection_state_
Tommic3257d02021-02-10 17:40:08312 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27313
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22314 CallbackList<PeerConnectionInterface::PeerConnectionState>
Tommic3257d02021-02-10 17:40:08315 signal_connection_state_ RTC_GUARDED_BY(network_thread_);
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 21:33:45316
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22317 CallbackList<PeerConnectionInterface::IceConnectionState>
Tommic3257d02021-02-10 17:40:08318 signal_standardized_ice_connection_state_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 13:58:17319
Zhi Huange818b6e2018-02-22 23:26:27320 // If all transports done gathering => complete,
321 // Else if any are gathering => gathering,
322 // Else => new
Evan Shrubsole080cdac2025-03-20 09:34:48323 CallbackList<IceGatheringState> signal_ice_gathering_state_
Tommic3257d02021-02-10 17:40:08324 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27325
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22326 // [mid, candidates]
Evan Shrubsole080cdac2025-03-20 09:34:48327 CallbackList<const std::string&, const std::vector<Candidate>&>
Tommic3257d02021-02-10 17:40:08328 signal_ice_candidates_gathered_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27329
Evan Shrubsole945e5172025-04-08 14:11:45330 CallbackList<const IceCandidateErrorEvent&> signal_ice_candidate_error_
331 RTC_GUARDED_BY(network_thread_);
Eldar Relloda13ea22019-06-01 09:23:43332
Tommiefc58a52025-07-23 09:04:38333 CallbackList<IceTransportInternal*, const std::vector<Candidate>&>
334 signal_ice_candidates_removed_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27335
Evan Shrubsole945e5172025-04-08 14:11:45336 CallbackList<const CandidatePairChangeEvent&>
Tommic3257d02021-02-10 17:40:08337 signal_ice_candidate_pair_changed_ RTC_GUARDED_BY(network_thread_);
Alex Drake00c7ecf2019-08-06 17:54:47338
Tommic5605202024-01-11 21:15:27339 // Called from SetLocalDescription and SetRemoteDescription.
340 // When `local` is true, local_desc must be valid. Similarly when
341 // `local` is false, remote_desc must be valid. The description counterpart
342 // to the one that's being applied, may be nullptr but when it's supplied
343 // the counterpart description's content groups will be kept up to date for
344 // `type == SdpType::kAnswer`.
Zhi Huange818b6e2018-02-22 23:26:27345 RTCError ApplyDescription_n(bool local,
346 SdpType type,
Evan Shrubsole080cdac2025-03-20 09:34:48347 const SessionDescription* local_desc,
348 const SessionDescription* remote_desc)
Niels Möller5cf0ef02021-01-18 13:00:36349 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 19:04:26350 RTCError ValidateAndMaybeUpdateBundleGroups(
Zhi Huangd2248f82018-04-10 21:41:03351 bool local,
352 SdpType type,
Evan Shrubsole080cdac2025-03-20 09:34:48353 const SessionDescription* local_desc,
354 const SessionDescription* remote_desc) RTC_RUN_ON(network_thread_);
355 RTCError ValidateContent(const ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 23:26:27356
Evan Shrubsole080cdac2025-03-20 09:34:48357 void HandleRejectedContent(const ContentInfo& content_info)
Niels Möller5cf0ef02021-01-18 13:00:36358 RTC_RUN_ON(network_thread_);
Evan Shrubsole080cdac2025-03-20 09:34:48359 bool HandleBundledContent(const ContentInfo& content_info,
360 const ContentGroup& bundle_group)
Niels Möller5cf0ef02021-01-18 13:00:36361 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27362
Evan Shrubsole3c825f12025-04-04 14:07:27363 JsepTransportDescription CreateJsepTransportDescription(
Evan Shrubsole080cdac2025-03-20 09:34:48364 const ContentInfo& content_info,
Evan Shrubsole945e5172025-04-08 14:11:45365 const TransportInfo& transport_info,
Zhi Huange830e682018-03-30 17:48:35366 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 08:10:17367 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 23:26:27368
Evan Shrubsole080cdac2025-03-20 09:34:48369 std::map<const ContentGroup*, std::vector<int>>
Henrik Boströmf8187e02021-04-26 19:04:26370 MergeEncryptedHeaderExtensionIdsForBundles(
Evan Shrubsole080cdac2025-03-20 09:34:48371 const SessionDescription* description);
Zhi Huange818b6e2018-02-22 23:26:27372 std::vector<int> GetEncryptedHeaderExtensionIds(
Evan Shrubsole080cdac2025-03-20 09:34:48373 const ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 23:26:27374
Evan Shrubsole080cdac2025-03-20 09:34:48375 int GetRtpAbsSendTimeHeaderExtensionId(const ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 23:26:27376
Zhi Huange830e682018-03-30 17:48:35377 // This method takes the BUNDLE group into account. If the JsepTransport is
378 // destroyed because of BUNDLE, it would return the transport which other
379 // transports are bundled on (In current implementation, it is the first
380 // content in the BUNDLE group).
Evan Shrubsole3c825f12025-04-04 14:07:27381 const JsepTransport* GetJsepTransportForMid(const std::string& mid) const
Tomas Gunnarsson92eebef2021-02-10 12:05:44382 RTC_RUN_ON(network_thread_);
Evan Shrubsole3c825f12025-04-04 14:07:27383 JsepTransport* GetJsepTransportForMid(const std::string& mid)
384 RTC_RUN_ON(network_thread_);
385 const JsepTransport* GetJsepTransportForMid(absl::string_view mid) const
386 RTC_RUN_ON(network_thread_);
387 JsepTransport* GetJsepTransportForMid(absl::string_view mid)
Harald Alvestrand8f429922022-05-04 10:32:30388 RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 17:48:35389
390 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
391 // if the JsepTransport is destroyed.
Evan Shrubsole3c825f12025-04-04 14:07:27392 const JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 09:22:50393 const std::string& transport_name) const RTC_RUN_ON(network_thread_);
Evan Shrubsole3c825f12025-04-04 14:07:27394 JsepTransport* GetJsepTransportByName(const std::string& transport_name)
395 RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 17:48:35396
Anton Sukhanov7940da02018-10-10 17:34:49397 // Creates jsep transport. Noop if transport is already created.
Artem Titov880fa812021-07-30 20:30:23398 // Transport is created either during SetLocalDescription (`local` == true) or
399 // during SetRemoteDescription (`local` == false). Passing `local` helps to
Anton Sukhanov7940da02018-10-10 17:34:49400 // differentiate initiator (caller) from answerer (callee).
Evan Shrubsole080cdac2025-03-20 09:34:48401 RTCError MaybeCreateJsepTransport(bool local,
402 const ContentInfo& content_info,
403 const SessionDescription& description)
Niels Möller5cf0ef02021-01-18 13:00:36404 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 22:13:58405
Niels Möller5cf0ef02021-01-18 13:00:36406 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27407
Evan Shrubsole945e5172025-04-08 14:11:45408 void SetIceRole_n(IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27409
Evan Shrubsole945e5172025-04-08 14:11:45410 IceRole DetermineIceRole(JsepTransport* jsep_transport,
411 const TransportInfo& transport_info,
412 SdpType type,
413 bool local);
Zhi Huange818b6e2018-02-22 23:26:27414
Evan Shrubsole945e5172025-04-08 14:11:45415 std::unique_ptr<DtlsTransportInternal> CreateDtlsTransport(
Evan Shrubsole080cdac2025-03-20 09:34:48416 const ContentInfo& content_info,
417 IceTransportInternal* ice);
Evan Shrubsolee6a1f702025-04-15 14:55:42418 scoped_refptr<IceTransportInterface> CreateIceTransport(
Qingsi Wang25ec8882019-11-15 20:33:05419 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 23:26:27420 bool rtcp);
421
Harald Alvestranda6544372023-11-13 09:33:56422 std::unique_ptr<RtpTransport> CreateUnencryptedRtpTransport(
Zhi Huange818b6e2018-02-22 23:26:27423 const std::string& transport_name,
Evan Shrubsole8f7678f2025-04-01 14:23:55424 PacketTransportInternal* rtp_packet_transport,
425 PacketTransportInternal* rtcp_packet_transport);
Harald Alvestranda6544372023-11-13 09:33:56426 std::unique_ptr<DtlsSrtpTransport> CreateDtlsSrtpTransport(
Zhi Huange818b6e2018-02-22 23:26:27427 const std::string& transport_name,
Evan Shrubsole945e5172025-04-08 14:11:45428 DtlsTransportInternal* rtp_dtls_transport,
429 DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 23:26:27430
431 // Collect all the DtlsTransports, including RTP and RTCP, from the
Taylor Brandstetter8591eff2021-08-11 21:56:38432 // JsepTransports, including those not mapped to a MID because they are being
433 // kept alive in case of rollback.
Evan Shrubsole945e5172025-04-08 14:11:45434 std::vector<DtlsTransportInternal*> GetDtlsTransports();
Taylor Brandstetter8591eff2021-08-11 21:56:38435 // Same as the above, but doesn't include rollback transports.
436 // JsepTransportController can iterate all the DtlsTransports and update the
437 // aggregate states.
Evan Shrubsole945e5172025-04-08 14:11:45438 std::vector<DtlsTransportInternal*> GetActiveDtlsTransports();
Zhi Huange818b6e2018-02-22 23:26:27439
440 // Handlers for signals from Transport.
Evan Shrubsole8f7678f2025-04-01 14:23:55441 void OnTransportWritableState_n(PacketTransportInternal* transport)
Niels Möller5cf0ef02021-01-18 13:00:36442 RTC_RUN_ON(network_thread_);
Evan Shrubsole8f7678f2025-04-01 14:23:55443 void OnTransportReceivingState_n(PacketTransportInternal* transport)
Niels Möller5cf0ef02021-01-18 13:00:36444 RTC_RUN_ON(network_thread_);
Evan Shrubsole080cdac2025-03-20 09:34:48445 void OnTransportGatheringState_n(IceTransportInternal* transport)
Niels Möller5cf0ef02021-01-18 13:00:36446 RTC_RUN_ON(network_thread_);
Evan Shrubsole080cdac2025-03-20 09:34:48447 void OnTransportCandidateGathered_n(IceTransportInternal* transport,
448 const Candidate& candidate)
Niels Möller5cf0ef02021-01-18 13:00:36449 RTC_RUN_ON(network_thread_);
Evan Shrubsole080cdac2025-03-20 09:34:48450 void OnTransportCandidateError_n(IceTransportInternal* transport,
Evan Shrubsole945e5172025-04-08 14:11:45451 const IceCandidateErrorEvent& event)
Niels Möller5cf0ef02021-01-18 13:00:36452 RTC_RUN_ON(network_thread_);
Evan Shrubsole080cdac2025-03-20 09:34:48453 void OnTransportCandidatesRemoved_n(IceTransportInternal* transport,
Evan Shrubsolee6a1f702025-04-15 14:55:42454 const Candidates& candidates)
Niels Möller5cf0ef02021-01-18 13:00:36455 RTC_RUN_ON(network_thread_);
Evan Shrubsole080cdac2025-03-20 09:34:48456 void OnTransportRoleConflict_n(IceTransportInternal* transport)
Niels Möller5cf0ef02021-01-18 13:00:36457 RTC_RUN_ON(network_thread_);
Evan Shrubsole080cdac2025-03-20 09:34:48458 void OnTransportStateChanged_n(IceTransportInternal* transport)
Niels Möller5cf0ef02021-01-18 13:00:36459 RTC_RUN_ON(network_thread_);
Evan Shrubsole945e5172025-04-08 14:11:45460 void OnTransportCandidatePairChanged_n(const CandidatePairChangeEvent& event)
Niels Möller5cf0ef02021-01-18 13:00:36461 RTC_RUN_ON(network_thread_);
462 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27463
Per K12103ce2025-11-12 16:04:49464 void OnRtcpPacketReceived_n(CopyOnWriteBuffer packet,
465 std::optional<Timestamp> arrival_time,
466 EcnMarking ecn) RTC_RUN_ON(network_thread_);
Harald Alvestranda6544372023-11-13 09:33:56467 void OnUnDemuxableRtpPacketReceived_n(const RtpPacketReceived& packet)
Per Ke1e94ad2023-03-30 14:53:59468 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 16:22:12469
Evan Shrubsoleeb835d02025-03-12 09:41:06470 void OnDtlsHandshakeError(SSLHandshakeError error);
Zhi Huange818b6e2018-02-22 23:26:27471
Evan Shrubsole3c825f12025-04-04 14:07:27472 bool OnTransportChanged(const std::string& mid, JsepTransport* transport);
Harald Alvestrand9dea3932021-06-10 06:03:06473
Victor Boiviecd54fd82024-02-28 11:16:15474 const Environment env_;
Evan Shrubsole6a9a1ae2025-03-21 12:54:15475 Thread* const network_thread_ = nullptr;
Evan Shrubsole080cdac2025-03-20 09:34:48476 PortAllocator* const port_allocator_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04477 AsyncDnsResolverFactoryInterface* const async_dns_resolver_factory_ = nullptr;
Giovanni Ortuño Urquidie2cfc362025-06-13 21:23:36478 LocalNetworkAccessPermissionFactoryInterface* const lna_permission_factory_ =
479 nullptr;
Zhi Huange818b6e2018-02-22 23:26:27480
Harald Alvestrand9dea3932021-06-10 06:03:06481 JsepTransportCollection transports_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 13:58:17482 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59483 // standardized_ice_connection_state_ is intended to replace
484 // ice_connection_state, see bugs.webrtc.org/9308
Evan Shrubsolee6a1f702025-04-15 14:55:42485 IceConnectionState ice_connection_state_ = kIceConnectionConnecting;
Alex Loiko9289eda2018-11-23 16:18:59486 PeerConnectionInterface::IceConnectionState
487 standardized_ice_connection_state_ =
488 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 13:58:17489 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
490 PeerConnectionInterface::PeerConnectionState::kNew;
Evan Shrubsole080cdac2025-03-20 09:34:48491 IceGatheringState ice_gathering_state_ = kIceGatheringNew;
Zhi Huange818b6e2018-02-22 23:26:27492
Harald Alvestrand133c0522021-01-29 14:27:12493 const Config config_;
494 bool active_reset_srtp_params_ RTC_GUARDED_BY(network_thread_);
Piotr (Peter) Slatalab1ae10b2019-03-01 19:14:05495
Florent Castelli8037fc62024-08-29 13:00:40496 std::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 23:26:27497
Evan Shrubsole080cdac2025-03-20 09:34:48498 IceConfig ice_config_;
Evan Shrubsole945e5172025-04-08 14:11:45499 IceRole ice_role_ = ICEROLE_CONTROLLING;
Evan Shrubsolee6a1f702025-04-15 14:55:42500 scoped_refptr<RTCCertificate> certificate_;
Zhi Huange818b6e2018-02-22 23:26:27501
Harald Alvestrand9f9bf382021-06-08 04:12:37502 BundleManager bundles_;
Harald Alvestrand53086522024-08-25 16:43:08503 // Reference to the SdpOfferAnswerHandler's payload type picker.
504 PayloadTypePicker& payload_type_picker_;
Zhi Huange818b6e2018-02-22 23:26:27505};
506
507} // namespace webrtc
508
Steve Anton10542f22019-01-11 17:11:00509#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_