blob: c966e744c683c955424d5744d5b84a3717d2542b [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
14#include <map>
15#include <memory>
16#include <string>
17#include <utility>
18#include <vector>
19
20#include "api/candidate.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/crypto/crypto_options.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080022#include "api/ice_transport_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/peer_connection_interface.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020024#include "api/rtc_event_log/rtc_event_log.h"
Niels Möller65f17ca2019-09-12 13:59:36 +020025#include "api/transport/media/media_transport_config.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "media/sctp/sctp_transport_internal.h"
27#include "p2p/base/dtls_transport.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080028#include "p2p/base/dtls_transport_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "p2p/base/p2p_transport_channel.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080030#include "pc/channel.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "pc/dtls_srtp_transport.h"
32#include "pc/dtls_transport.h"
33#include "pc/jsep_transport.h"
34#include "pc/rtp_transport.h"
35#include "pc/srtp_transport.h"
36#include "rtc_base/async_invoker.h"
37#include "rtc_base/constructor_magic.h"
38#include "rtc_base/ref_counted_object.h"
Artem Titove41c4332018-07-25 15:04:28 +020039#include "rtc_base/third_party/sigslot/sigslot.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080040
41namespace rtc {
42class Thread;
43class PacketTransportInternal;
44} // namespace rtc
45
46namespace webrtc {
47
Steve Antond25828a2018-08-31 13:06:05 -070048class JsepTransportController : public sigslot::has_slots<> {
Zhi Huange818b6e2018-02-22 15:26:27 -080049 public:
Zhi Huang365381f2018-04-13 16:44:34 -070050 // Used when the RtpTransport/DtlsTransport of the m= section is changed
51 // because the section is rejected or BUNDLE is enabled.
52 class Observer {
53 public:
54 virtual ~Observer() {}
55
56 // Returns true if media associated with |mid| was successfully set up to be
57 // demultiplexed on |rtp_transport|. Could return false if two bundled m=
58 // sections use the same SSRC, for example.
Bjorn A Mellemb689af42019-08-21 10:44:59 -070059 //
60 // If a data channel transport must be negotiated, |data_channel_transport|
61 // and |negotiation_state| indicate negotiation status. If
62 // |data_channel_transport| is null, the data channel transport should not
63 // be used. Otherwise, the value is a pointer to the transport to be used
64 // for data channels on |mid|, if any.
65 //
66 // The observer should not send data on |data_channel_transport| until
67 // |negotiation_state| is provisional or final. It should not delete
68 // |data_channel_transport| or any fallback transport until
69 // |negotiation_state| is final.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -070070 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 16:44:34 -070071 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -070072 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +010073 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -070074 DataChannelTransportInterface* data_channel_transport) = 0;
Zhi Huang365381f2018-04-13 16:44:34 -070075 };
76
Zhi Huange818b6e2018-02-22 15:26:27 -080077 struct Config {
78 // If |redetermine_role_on_ice_restart| is true, ICE role is redetermined
79 // upon setting a local transport description that indicates an ICE
80 // restart.
81 bool redetermine_role_on_ice_restart = true;
82 rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
83 // |crypto_options| is used to determine if created DTLS transports
84 // negotiate GCM crypto suites or not.
Benjamin Wrighta54daf12018-10-11 15:33:17 -070085 webrtc::CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 15:26:27 -080086 PeerConnectionInterface::BundlePolicy bundle_policy =
87 PeerConnectionInterface::kBundlePolicyBalanced;
88 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy =
89 PeerConnectionInterface::kRtcpMuxPolicyRequire;
90 bool disable_encryption = false;
91 bool enable_external_auth = false;
92 // Used to inject the ICE/DTLS transports created externally.
Qingsi Wang25ec8882019-11-15 12:33:05 -080093 webrtc::IceTransportFactory* ice_transport_factory = nullptr;
94 cricket::DtlsTransportFactory* dtls_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 16:44:34 -070095 Observer* transport_observer = nullptr;
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +020096 // Must be provided and valid for the lifetime of the
97 // JsepTransportController instance.
98 std::function<void(const rtc::CopyOnWriteBuffer& packet,
99 int64_t packet_time_us)>
100 rtcp_handler;
Zhi Huangb57e1692018-06-12 11:41:11 -0700101 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-11 20:15:46 -0700102 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700103
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700104 // Factory for SCTP transports.
105 cricket::SctpTransportInternalFactory* sctp_factory = nullptr;
106
Niels Möllerabea6e52019-03-08 14:49:32 +0100107 // Whether an RtpMediaTransport should be created as default, when no
108 // MediaTransportFactory is provided.
109 bool use_rtp_media_transport = false;
110
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700111 // Use encrypted datagram transport to send packets.
112 bool use_datagram_transport = false;
113
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700114 // Use datagram transport's implementation of data channels instead of SCTP.
115 bool use_datagram_transport_for_data_channels = false;
116
Bjorn A Mellem7da4e562019-09-26 11:02:11 -0700117 // Whether |use_datagram_transport_for_data_channels| applies to outgoing
118 // calls. If true, |use_datagram_transport_for_data_channels| applies only
119 // to incoming calls.
120 bool use_datagram_transport_for_data_channels_receive_only = false;
121
Anton Sukhanov7940da02018-10-10 10:34:49 -0700122 // Optional media transport factory (experimental). If provided it will be
Bjorn A Mellem7a9a0922019-11-26 09:19:40 -0800123 // used to create datagram_transport (as long as either
124 // |use_datagram_transport| or
125 // |use_datagram_transport_for_data_channels| is set to true). However,
126 // whether it will be used to send / receive audio and video frames instead
127 // of RTP is determined by |use_datagram_transport|. Note that currently
128 // datagram_transport co-exists with RTP / RTCP transports and may use the
129 // same underlying ICE transport.
Anton Sukhanov7940da02018-10-10 10:34:49 -0700130 MediaTransportFactory* media_transport_factory = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800131 };
132
133 // The ICE related events are signaled on the |signaling_thread|.
134 // All the transport related methods are called on the |network_thread|.
135 JsepTransportController(rtc::Thread* signaling_thread,
136 rtc::Thread* network_thread,
137 cricket::PortAllocator* port_allocator,
Zach Steine20867f2018-08-02 13:20:15 -0700138 AsyncResolverFactory* async_resolver_factory,
Zhi Huange818b6e2018-02-22 15:26:27 -0800139 Config config);
140 virtual ~JsepTransportController();
141
142 // The main method to be called; applies a description at the transport
143 // level, creating/destroying transport objects as needed and updating their
144 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
145 // yet? May make sense to in the future.
146 RTCError SetLocalDescription(SdpType type,
147 const cricket::SessionDescription* description);
148
149 RTCError SetRemoteDescription(SdpType type,
150 const cricket::SessionDescription* description);
151
152 // Get transports to be used for the provided |mid|. If bundling is enabled,
153 // calling GetRtpTransport for multiple MIDs may yield the same object.
154 RtpTransportInternal* GetRtpTransport(const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100155 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
156 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800157 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100158 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100159 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100160 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700161 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
162 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800163
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700164 MediaTransportConfig GetMediaTransportConfig(const std::string& mid) const;
165
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700166 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700167 const std::string& mid) const;
168
Zhi Huange818b6e2018-02-22 15:26:27 -0800169 /*********************
170 * ICE-related methods
171 ********************/
172 // This method is public to allow PeerConnection to update it from
173 // SetConfiguration.
174 void SetIceConfig(const cricket::IceConfig& config);
175 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
176 // set, offers should generate new ufrags/passwords until an ICE restart
177 // occurs.
178 void SetNeedsIceRestartFlag();
179 // Returns true if the ICE restart flag above was set, and no ICE restart has
180 // occurred yet for this transport (by applying a local description with
181 // changed ufrag/password). If the transport has been deleted as a result of
182 // bundling, returns false.
183 bool NeedsIceRestart(const std::string& mid) const;
184 // Start gathering candidates for any new transports, or transports doing an
185 // ICE restart.
186 void MaybeStartGathering();
187 RTCError AddRemoteCandidates(
188 const std::string& mid,
189 const std::vector<cricket::Candidate>& candidates);
190 RTCError RemoveRemoteCandidates(
191 const std::vector<cricket::Candidate>& candidates);
192
193 /**********************
194 * DTLS-related methods
195 *********************/
196 // Specifies the identity to use in this session.
197 // Can only be called once.
198 bool SetLocalCertificate(
199 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
200 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
201 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800202 // Caller owns returned certificate chain. This method mainly exists for
203 // stats reporting.
204 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800205 const std::string& mid) const;
206 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200207 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800208
209 // TODO(deadbeef): GetStats isn't const because all the way down to
210 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
211 // const. Fix this.
212 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800213
Zhi Huange830e682018-03-30 10:48:35 -0700214 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700215
Zhi Huangb57e1692018-06-12 11:41:11 -0700216 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
217
Piotr (Peter) Slatala97fc11f2018-10-18 12:57:59 -0700218 // Allows to overwrite the settings from config. You may set or reset the
Piotr (Peter) Slatala55b91b92019-01-25 13:31:15 -0800219 // media transport configuration on the jsep transport controller, as long as
220 // you did not call 'GetMediaTransport' or 'MaybeCreateJsepTransport'. Once
221 // Jsep transport is created, you can't change this setting.
Bjorn A Mellem7da4e562019-09-26 11:02:11 -0700222 void SetMediaTransportSettings(
Bjorn A Mellem7da4e562019-09-26 11:02:11 -0700223 bool use_datagram_transport,
224 bool use_datagram_transport_for_data_channels,
225 bool use_datagram_transport_for_data_channels_receive_only);
Piotr (Peter) Slatala97fc11f2018-10-18 12:57:59 -0700226
Eldar Rellod85ea752020-02-19 20:41:07 +0200227 // For now the rollback only removes mid to transport mappings
Eldar Rello353a7182019-11-25 18:49:44 +0200228 // and deletes unused transports, but doesn't consider anything more complex.
Eldar Rellod85ea752020-02-19 20:41:07 +0200229 void RollbackTransports();
Eldar Rello5ab79e62019-10-09 18:29:44 +0300230
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -0700231 // Gets the transport parameters for the transport identified by |mid|.
232 // If |mid| is bundled, returns the parameters for the bundled transport.
233 // If the transport for |mid| has not been created yet, it may be allocated in
234 // order to generate transport parameters.
235 absl::optional<cricket::OpaqueTransportParameters> GetTransportParameters(
236 const std::string& mid);
237
Zhi Huange818b6e2018-02-22 15:26:27 -0800238 // All of these signals are fired on the signaling thread.
239
240 // If any transport failed => failed,
241 // Else if all completed => completed,
242 // Else if all connected => connected,
243 // Else => connecting
Alex Loiko9289eda2018-11-23 16:18:59 +0000244 sigslot::signal1<cricket::IceConnectionState> SignalIceConnectionState;
Zhi Huange818b6e2018-02-22 15:26:27 -0800245
Jonas Olsson635474e2018-10-18 15:58:17 +0200246 sigslot::signal1<PeerConnectionInterface::PeerConnectionState>
247 SignalConnectionState;
Alex Loiko9289eda2018-11-23 16:18:59 +0000248 sigslot::signal1<PeerConnectionInterface::IceConnectionState>
249 SignalStandardizedIceConnectionState;
Jonas Olsson635474e2018-10-18 15:58:17 +0200250
Zhi Huange818b6e2018-02-22 15:26:27 -0800251 // If all transports done gathering => complete,
252 // Else if any are gathering => gathering,
253 // Else => new
254 sigslot::signal1<cricket::IceGatheringState> SignalIceGatheringState;
255
256 // (mid, candidates)
257 sigslot::signal2<const std::string&, const std::vector<cricket::Candidate>&>
258 SignalIceCandidatesGathered;
259
Eldar Relloda13ea22019-06-01 12:23:43 +0300260 sigslot::signal1<const cricket::IceCandidateErrorEvent&>
261 SignalIceCandidateError;
262
Zhi Huange818b6e2018-02-22 15:26:27 -0800263 sigslot::signal1<const std::vector<cricket::Candidate>&>
264 SignalIceCandidatesRemoved;
265
Alex Drake00c7ecf2019-08-06 10:54:47 -0700266 sigslot::signal1<const cricket::CandidatePairChangeEvent&>
267 SignalIceCandidatePairChanged;
268
Zhi Huange818b6e2018-02-22 15:26:27 -0800269 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
270
Zhi Huange818b6e2018-02-22 15:26:27 -0800271 private:
Zhi Huange818b6e2018-02-22 15:26:27 -0800272 RTCError ApplyDescription_n(bool local,
273 SdpType type,
274 const cricket::SessionDescription* description);
Zhi Huangd2248f82018-04-10 14:41:03 -0700275 RTCError ValidateAndMaybeUpdateBundleGroup(
276 bool local,
277 SdpType type,
278 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700279 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800280
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700281 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Zhi Huangd2248f82018-04-10 14:41:03 -0700282 const cricket::SessionDescription* description);
Zhi Huang365381f2018-04-13 16:44:34 -0700283 bool HandleBundledContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800284
Zhi Huang365381f2018-04-13 16:44:34 -0700285 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700286 cricket::JsepTransport* jsep_transport);
287 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700288
Zhi Huange818b6e2018-02-22 15:26:27 -0800289 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200290 const cricket::ContentInfo& content_info,
291 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700292 const std::vector<int>& encrypted_extension_ids,
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700293 int rtp_abs_sendtime_extn_id,
294 absl::optional<std::string> media_alt_protocol,
295 absl::optional<std::string> data_alt_protocol);
Zhi Huange818b6e2018-02-22 15:26:27 -0800296
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200297 absl::optional<std::string> bundled_mid() const {
298 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700299 if (bundle_group_ && bundle_group_->FirstContentName()) {
300 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800301 }
302 return bundled_mid;
303 }
304
305 bool IsBundled(const std::string& mid) const {
306 return bundle_group_ && bundle_group_->HasContentName(mid);
307 }
308
309 bool ShouldUpdateBundleGroup(SdpType type,
310 const cricket::SessionDescription* description);
311
312 std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle(
313 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800314 std::vector<int> GetEncryptedHeaderExtensionIds(
315 const cricket::ContentInfo& content_info);
316
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700317 // Extracts the alt-protocol settings that apply to the bundle group.
318 RTCError GetAltProtocolsForBundle(
319 const cricket::SessionDescription* description,
320 absl::optional<std::string>* media_alt_protocol,
321 absl::optional<std::string>* data_alt_protocol);
322
Zhi Huange830e682018-03-30 10:48:35 -0700323 int GetRtpAbsSendTimeHeaderExtensionId(
324 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800325
Zhi Huange830e682018-03-30 10:48:35 -0700326 // This method takes the BUNDLE group into account. If the JsepTransport is
327 // destroyed because of BUNDLE, it would return the transport which other
328 // transports are bundled on (In current implementation, it is the first
329 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700330 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700331 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700332 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700333
334 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
335 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700336 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700337 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700338 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700339 const std::string& transport_name);
340
Anton Sukhanov7940da02018-10-10 10:34:49 -0700341 // Creates jsep transport. Noop if transport is already created.
342 // Transport is created either during SetLocalDescription (|local| == true) or
343 // during SetRemoteDescription (|local| == false). Passing |local| helps to
344 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800345 RTCError MaybeCreateJsepTransport(
346 bool local,
347 const cricket::ContentInfo& content_info,
348 const cricket::SessionDescription& description);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800349
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700350 // Creates datagram transport if config wants to use it, and a=x-mt line is
351 // present for the current media transport. Returned
352 // DatagramTransportInterface is not connected, and must be connected to ICE.
353 // You must call |GenerateOrGetLastMediaTransportOffer| on the caller before
354 // calling MaybeCreateDatagramTransport.
355 std::unique_ptr<webrtc::DatagramTransportInterface>
356 MaybeCreateDatagramTransport(const cricket::ContentInfo& content_info,
357 const cricket::SessionDescription& description,
358 bool local);
359
Zhi Huange818b6e2018-02-22 15:26:27 -0800360 void MaybeDestroyJsepTransport(const std::string& mid);
361 void DestroyAllJsepTransports_n();
362
363 void SetIceRole_n(cricket::IceRole ice_role);
364
365 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700366 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800367 const cricket::TransportInfo& transport_info,
368 SdpType type,
369 bool local);
370
371 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700372 const cricket::ContentInfo& content_info,
Bjorn A Mellem0c1c1b42019-05-29 17:34:13 -0700373 cricket::IceTransportInternal* ice,
Anton Sukhanov292ce4e2019-06-03 13:00:24 -0700374 DatagramTransportInterface* datagram_transport);
Qingsi Wang25ec8882019-11-15 12:33:05 -0800375 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
376 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800377 bool rtcp);
378
379 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
380 const std::string& transport_name,
381 rtc::PacketTransportInternal* rtp_packet_transport,
382 rtc::PacketTransportInternal* rtcp_packet_transport);
383 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
384 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700385 cricket::DtlsTransportInternal* rtp_dtls_transport,
386 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800387 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
388 const std::string& transport_name,
389 cricket::DtlsTransportInternal* rtp_dtls_transport,
390 cricket::DtlsTransportInternal* rtcp_dtls_transport);
391
392 // Collect all the DtlsTransports, including RTP and RTCP, from the
393 // JsepTransports. JsepTransportController can iterate all the DtlsTransports
394 // and update the aggregate states.
395 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
396
397 // Handlers for signals from Transport.
398 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport);
399 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport);
400 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport);
401 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
402 const cricket::Candidate& candidate);
Eldar Relloda13ea22019-06-01 12:23:43 +0300403 void OnTransportCandidateError_n(
404 cricket::IceTransportInternal* transport,
405 const cricket::IceCandidateErrorEvent& event);
Zhi Huange818b6e2018-02-22 15:26:27 -0800406 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
407 const cricket::Candidates& candidates);
408 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport);
409 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700410 void OnTransportCandidatePairChanged_n(
411 const cricket::CandidatePairChangeEvent& event);
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700412 void OnDataChannelTransportNegotiated_n(
413 cricket::JsepTransport* transport,
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700414 DataChannelTransportInterface* data_channel_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800415
416 void UpdateAggregateStates_n();
417
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200418 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
419 int64_t packet_time_us);
420
Zhi Huange818b6e2018-02-22 15:26:27 -0800421 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
422
423 rtc::Thread* const signaling_thread_ = nullptr;
424 rtc::Thread* const network_thread_ = nullptr;
425 cricket::PortAllocator* const port_allocator_ = nullptr;
Zach Steine20867f2018-08-02 13:20:15 -0700426 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800427
Zhi Huang365381f2018-04-13 16:44:34 -0700428 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700429 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700430 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700431 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
432 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Eldar Rellod85ea752020-02-19 20:41:07 +0200433 // Keep track of mids that have been mapped to transports. Used for rollback.
434 std::vector<std::string> pending_mids_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200435 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000436 // standardized_ice_connection_state_ is intended to replace
437 // ice_connection_state, see bugs.webrtc.org/9308
438 cricket::IceConnectionState ice_connection_state_ =
439 cricket::kIceConnectionConnecting;
440 PeerConnectionInterface::IceConnectionState
441 standardized_ice_connection_state_ =
442 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200443 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
444 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800445 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
446
447 Config config_;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800448
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700449 // Early on in the call we don't know if datagram transport is going to be
450 // used, but we need to get the server-supported parameters to add to an SDP.
451 // This server datagram transport will be promoted to the used datagram
452 // transport after the local description is set, and the ownership will be
453 // transferred to the actual JsepTransport. This "offer" datagram transport is
454 // not created if it's done on the party that provides answer. This offer
455 // datagram transport is only created once at the beginning of the connection,
456 // and never again.
457 std::unique_ptr<DatagramTransportInterface> offer_datagram_transport_ =
458 nullptr;
459
Zhi Huange818b6e2018-02-22 15:26:27 -0800460 const cricket::SessionDescription* local_desc_ = nullptr;
461 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200462 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800463
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200464 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800465
466 cricket::IceConfig ice_config_;
467 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
468 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
469 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
470 rtc::AsyncInvoker invoker_;
471
Zhi Huange818b6e2018-02-22 15:26:27 -0800472 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
473};
474
475} // namespace webrtc
476
Steve Anton10542f22019-01-11 09:11:00 -0800477#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_