blob: aaaab4881e713eb74d9e40ecf8b9e6ef7007788f [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"
Anton Sukhanov316f3ac2019-05-23 15:50:38 -070022#include "api/media_transport_config.h"
Anton Sukhanov7940da02018-10-10 10:34:49 -070023#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/peer_connection_interface.h"
Qingsi Wang7685e862018-06-11 20:15:46 -070025#include "logging/rtc_event_log/rtc_event_log.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "media/sctp/sctp_transport_internal.h"
27#include "p2p/base/dtls_transport.h"
28#include "p2p/base/p2p_transport_channel.h"
29#include "p2p/base/transport_factory_interface.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.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -070059 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 16:44:34 -070060 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -070061 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +010062 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Piotr (Peter) Slatalacc8e8bb2018-11-15 08:26:19 -080063 MediaTransportInterface* media_transport) = 0;
Zhi Huang365381f2018-04-13 16:44:34 -070064 };
65
Zhi Huange818b6e2018-02-22 15:26:27 -080066 struct Config {
67 // If |redetermine_role_on_ice_restart| is true, ICE role is redetermined
68 // upon setting a local transport description that indicates an ICE
69 // restart.
70 bool redetermine_role_on_ice_restart = true;
71 rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
72 // |crypto_options| is used to determine if created DTLS transports
73 // negotiate GCM crypto suites or not.
Benjamin Wrighta54daf12018-10-11 15:33:17 -070074 webrtc::CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 15:26:27 -080075 PeerConnectionInterface::BundlePolicy bundle_policy =
76 PeerConnectionInterface::kBundlePolicyBalanced;
77 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy =
78 PeerConnectionInterface::kRtcpMuxPolicyRequire;
79 bool disable_encryption = false;
80 bool enable_external_auth = false;
81 // Used to inject the ICE/DTLS transports created externally.
82 cricket::TransportFactoryInterface* external_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 16:44:34 -070083 Observer* transport_observer = nullptr;
Zhi Huangb57e1692018-06-12 11:41:11 -070084 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-11 20:15:46 -070085 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 10:34:49 -070086
Piotr (Peter) Slatala55b91b92019-01-25 13:31:15 -080087 // Whether media transport is used for media.
88 bool use_media_transport_for_media = false;
89
90 // Whether media transport is used for data channels.
91 bool use_media_transport_for_data_channels = false;
92
Niels Möllerabea6e52019-03-08 14:49:32 +010093 // Whether an RtpMediaTransport should be created as default, when no
94 // MediaTransportFactory is provided.
95 bool use_rtp_media_transport = false;
96
Anton Sukhanov316f3ac2019-05-23 15:50:38 -070097 // Use encrypted datagram transport to send packets.
98 bool use_datagram_transport = false;
99
Anton Sukhanov7940da02018-10-10 10:34:49 -0700100 // Optional media transport factory (experimental). If provided it will be
Piotr (Peter) Slatala55b91b92019-01-25 13:31:15 -0800101 // used to create media_transport (as long as either
102 // |use_media_transport_for_media| or
103 // |use_media_transport_for_data_channels| is set to true). However, whether
104 // it will be used to send / receive audio and video frames instead of RTP
105 // is determined by |use_media_transport_for_media|. Note that currently
106 // media_transport co-exists with RTP / RTCP transports and may use the same
Anton Sukhanov7940da02018-10-10 10:34:49 -0700107 // underlying ICE transport.
108 MediaTransportFactory* media_transport_factory = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800109 };
110
111 // The ICE related events are signaled on the |signaling_thread|.
112 // All the transport related methods are called on the |network_thread|.
113 JsepTransportController(rtc::Thread* signaling_thread,
114 rtc::Thread* network_thread,
115 cricket::PortAllocator* port_allocator,
Zach Steine20867f2018-08-02 13:20:15 -0700116 AsyncResolverFactory* async_resolver_factory,
Zhi Huange818b6e2018-02-22 15:26:27 -0800117 Config config);
118 virtual ~JsepTransportController();
119
120 // The main method to be called; applies a description at the transport
121 // level, creating/destroying transport objects as needed and updating their
122 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
123 // yet? May make sense to in the future.
124 RTCError SetLocalDescription(SdpType type,
125 const cricket::SessionDescription* description);
126
127 RTCError SetRemoteDescription(SdpType type,
128 const cricket::SessionDescription* description);
129
130 // Get transports to be used for the provided |mid|. If bundling is enabled,
131 // calling GetRtpTransport for multiple MIDs may yield the same object.
132 RtpTransportInternal* GetRtpTransport(const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100133 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
134 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800135 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100136 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100137 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100138 const std::string& mid);
Zhi Huange818b6e2018-02-22 15:26:27 -0800139
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700140 MediaTransportConfig GetMediaTransportConfig(const std::string& mid) const;
141
142 MediaTransportInterface* GetMediaTransportForDataChannel(
143 const std::string& mid) const;
144
145 // TODO(sukhanov): Deprecate, return only config.
146 MediaTransportInterface* GetMediaTransport(const std::string& mid) const {
147 return GetMediaTransportConfig(mid).media_transport;
148 }
149
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800150 MediaTransportState GetMediaTransportState(const std::string& mid) const;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700151
Zhi Huange818b6e2018-02-22 15:26:27 -0800152 /*********************
153 * ICE-related methods
154 ********************/
155 // This method is public to allow PeerConnection to update it from
156 // SetConfiguration.
157 void SetIceConfig(const cricket::IceConfig& config);
158 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
159 // set, offers should generate new ufrags/passwords until an ICE restart
160 // occurs.
161 void SetNeedsIceRestartFlag();
162 // Returns true if the ICE restart flag above was set, and no ICE restart has
163 // occurred yet for this transport (by applying a local description with
164 // changed ufrag/password). If the transport has been deleted as a result of
165 // bundling, returns false.
166 bool NeedsIceRestart(const std::string& mid) const;
167 // Start gathering candidates for any new transports, or transports doing an
168 // ICE restart.
169 void MaybeStartGathering();
170 RTCError AddRemoteCandidates(
171 const std::string& mid,
172 const std::vector<cricket::Candidate>& candidates);
173 RTCError RemoveRemoteCandidates(
174 const std::vector<cricket::Candidate>& candidates);
175
176 /**********************
177 * DTLS-related methods
178 *********************/
179 // Specifies the identity to use in this session.
180 // Can only be called once.
181 bool SetLocalCertificate(
182 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
183 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
184 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800185 // Caller owns returned certificate chain. This method mainly exists for
186 // stats reporting.
187 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800188 const std::string& mid) const;
189 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200190 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800191
192 // TODO(deadbeef): GetStats isn't const because all the way down to
193 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
194 // const. Fix this.
195 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800196
Zhi Huange830e682018-03-30 10:48:35 -0700197 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700198
Zhi Huangb57e1692018-06-12 11:41:11 -0700199 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
200
Piotr (Peter) Slatala97fc11f2018-10-18 12:57:59 -0700201 // Allows to overwrite the settings from config. You may set or reset the
Piotr (Peter) Slatala55b91b92019-01-25 13:31:15 -0800202 // media transport configuration on the jsep transport controller, as long as
203 // you did not call 'GetMediaTransport' or 'MaybeCreateJsepTransport'. Once
204 // Jsep transport is created, you can't change this setting.
205 void SetMediaTransportSettings(bool use_media_transport_for_media,
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700206 bool use_media_transport_for_data_channels,
207 bool use_datagram_transport);
Piotr (Peter) Slatala97fc11f2018-10-18 12:57:59 -0700208
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800209 // If media transport is present enabled and supported,
210 // when this method is called, it creates a media transport and generates its
211 // offer. The new offer is then returned, and the created media transport will
212 // subsequently be used.
213 absl::optional<cricket::SessionDescription::MediaTransportSetting>
214 GenerateOrGetLastMediaTransportOffer();
215
Zhi Huange818b6e2018-02-22 15:26:27 -0800216 // All of these signals are fired on the signaling thread.
217
218 // If any transport failed => failed,
219 // Else if all completed => completed,
220 // Else if all connected => connected,
221 // Else => connecting
Alex Loiko9289eda2018-11-23 16:18:59 +0000222 sigslot::signal1<cricket::IceConnectionState> SignalIceConnectionState;
Zhi Huange818b6e2018-02-22 15:26:27 -0800223
Jonas Olsson635474e2018-10-18 15:58:17 +0200224 sigslot::signal1<PeerConnectionInterface::PeerConnectionState>
225 SignalConnectionState;
Alex Loiko9289eda2018-11-23 16:18:59 +0000226 sigslot::signal1<PeerConnectionInterface::IceConnectionState>
227 SignalStandardizedIceConnectionState;
Jonas Olsson635474e2018-10-18 15:58:17 +0200228
Zhi Huange818b6e2018-02-22 15:26:27 -0800229 // If all transports done gathering => complete,
230 // Else if any are gathering => gathering,
231 // Else => new
232 sigslot::signal1<cricket::IceGatheringState> SignalIceGatheringState;
233
234 // (mid, candidates)
235 sigslot::signal2<const std::string&, const std::vector<cricket::Candidate>&>
236 SignalIceCandidatesGathered;
237
238 sigslot::signal1<const std::vector<cricket::Candidate>&>
239 SignalIceCandidatesRemoved;
240
241 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
242
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800243 sigslot::signal<> SignalMediaTransportStateChanged;
244
Zhi Huange818b6e2018-02-22 15:26:27 -0800245 private:
Zhi Huange818b6e2018-02-22 15:26:27 -0800246 RTCError ApplyDescription_n(bool local,
247 SdpType type,
248 const cricket::SessionDescription* description);
Zhi Huangd2248f82018-04-10 14:41:03 -0700249 RTCError ValidateAndMaybeUpdateBundleGroup(
250 bool local,
251 SdpType type,
252 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700253 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800254
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700255 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Zhi Huangd2248f82018-04-10 14:41:03 -0700256 const cricket::SessionDescription* description);
Zhi Huang365381f2018-04-13 16:44:34 -0700257 bool HandleBundledContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800258
Zhi Huang365381f2018-04-13 16:44:34 -0700259 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700260 cricket::JsepTransport* jsep_transport);
261 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700262
Zhi Huange818b6e2018-02-22 15:26:27 -0800263 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200264 const cricket::ContentInfo& content_info,
265 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700266 const std::vector<int>& encrypted_extension_ids,
267 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800268
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200269 absl::optional<std::string> bundled_mid() const {
270 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700271 if (bundle_group_ && bundle_group_->FirstContentName()) {
272 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800273 }
274 return bundled_mid;
275 }
276
277 bool IsBundled(const std::string& mid) const {
278 return bundle_group_ && bundle_group_->HasContentName(mid);
279 }
280
281 bool ShouldUpdateBundleGroup(SdpType type,
282 const cricket::SessionDescription* description);
283
284 std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle(
285 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800286 std::vector<int> GetEncryptedHeaderExtensionIds(
287 const cricket::ContentInfo& content_info);
288
Zhi Huange830e682018-03-30 10:48:35 -0700289 int GetRtpAbsSendTimeHeaderExtensionId(
290 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800291
Zhi Huange830e682018-03-30 10:48:35 -0700292 // This method takes the BUNDLE group into account. If the JsepTransport is
293 // destroyed because of BUNDLE, it would return the transport which other
294 // transports are bundled on (In current implementation, it is the first
295 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700296 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700297 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700298 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700299
300 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
301 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700302 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700303 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700304 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700305 const std::string& transport_name);
306
Anton Sukhanov7940da02018-10-10 10:34:49 -0700307 // Creates jsep transport. Noop if transport is already created.
308 // Transport is created either during SetLocalDescription (|local| == true) or
309 // during SetRemoteDescription (|local| == false). Passing |local| helps to
310 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800311 RTCError MaybeCreateJsepTransport(
312 bool local,
313 const cricket::ContentInfo& content_info,
314 const cricket::SessionDescription& description);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800315
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800316 // Creates media transport if config wants to use it, and a=x-mt line is
317 // present for the current media transport. Returned MediaTransportInterface
318 // is not connected, and must be connected to ICE. You must call
319 // |GenerateOrGetLastMediaTransportOffer| on the caller before calling
320 // MaybeCreateMediaTransport.
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800321 std::unique_ptr<webrtc::MediaTransportInterface> MaybeCreateMediaTransport(
322 const cricket::ContentInfo& content_info,
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800323 const cricket::SessionDescription& description,
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800324 bool local);
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700325
326 // Creates datagram transport if config wants to use it, and a=x-mt line is
327 // present for the current media transport. Returned
328 // DatagramTransportInterface is not connected, and must be connected to ICE.
329 // You must call |GenerateOrGetLastMediaTransportOffer| on the caller before
330 // calling MaybeCreateDatagramTransport.
331 std::unique_ptr<webrtc::DatagramTransportInterface>
332 MaybeCreateDatagramTransport(const cricket::ContentInfo& content_info,
333 const cricket::SessionDescription& description,
334 bool local);
335
Zhi Huange818b6e2018-02-22 15:26:27 -0800336 void MaybeDestroyJsepTransport(const std::string& mid);
337 void DestroyAllJsepTransports_n();
338
339 void SetIceRole_n(cricket::IceRole ice_role);
340
341 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700342 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800343 const cricket::TransportInfo& transport_info,
344 SdpType type,
345 bool local);
346
347 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Bjorn A Mellem0c1c1b42019-05-29 17:34:13 -0700348 cricket::IceTransportInternal* ice,
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700349 std::unique_ptr<DatagramTransportInterface> datagram_transport);
Piotr (Peter) Slatala2b5baee2019-01-16 08:25:21 -0800350 std::unique_ptr<cricket::IceTransportInternal> CreateIceTransport(
351 const std::string transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800352 bool rtcp);
353
354 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
355 const std::string& transport_name,
356 rtc::PacketTransportInternal* rtp_packet_transport,
357 rtc::PacketTransportInternal* rtcp_packet_transport);
358 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
359 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700360 cricket::DtlsTransportInternal* rtp_dtls_transport,
361 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800362 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
363 const std::string& transport_name,
364 cricket::DtlsTransportInternal* rtp_dtls_transport,
365 cricket::DtlsTransportInternal* rtcp_dtls_transport);
366
367 // Collect all the DtlsTransports, including RTP and RTCP, from the
368 // JsepTransports. JsepTransportController can iterate all the DtlsTransports
369 // and update the aggregate states.
370 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
371
372 // Handlers for signals from Transport.
373 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport);
374 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport);
375 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport);
376 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
377 const cricket::Candidate& candidate);
Zhi Huange818b6e2018-02-22 15:26:27 -0800378 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
379 const cricket::Candidates& candidates);
380 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport);
381 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport);
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800382 void OnMediaTransportStateChanged_n();
Zhi Huange818b6e2018-02-22 15:26:27 -0800383
384 void UpdateAggregateStates_n();
385
386 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
387
388 rtc::Thread* const signaling_thread_ = nullptr;
389 rtc::Thread* const network_thread_ = nullptr;
390 cricket::PortAllocator* const port_allocator_ = nullptr;
Zach Steine20867f2018-08-02 13:20:15 -0700391 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800392
Zhi Huang365381f2018-04-13 16:44:34 -0700393 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700394 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700395 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700396 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
397 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800398
Jonas Olsson635474e2018-10-18 15:58:17 +0200399 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000400 // standardized_ice_connection_state_ is intended to replace
401 // ice_connection_state, see bugs.webrtc.org/9308
402 cricket::IceConnectionState ice_connection_state_ =
403 cricket::kIceConnectionConnecting;
404 PeerConnectionInterface::IceConnectionState
405 standardized_ice_connection_state_ =
406 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200407 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
408 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800409 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
410
411 Config config_;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800412
413 // Early on in the call we don't know if media transport is going to be used,
414 // but we need to get the server-supported parameters to add to an SDP.
415 // This server media transport will be promoted to the used media transport
416 // after the local description is set, and the ownership will be transferred
417 // to the actual JsepTransport.
418 // This "offer" media transport is not created if it's done on the party that
419 // provides answer. This offer media transport is only created once at the
420 // beginning of the connection, and never again.
421 std::unique_ptr<MediaTransportInterface> offer_media_transport_ = nullptr;
422
423 // Contains the offer of the |offer_media_transport_|, in case if it needs to
424 // be repeated.
425 absl::optional<cricket::SessionDescription::MediaTransportSetting>
426 media_transport_offer_settings_;
427
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700428 // Early on in the call we don't know if datagram transport is going to be
429 // used, but we need to get the server-supported parameters to add to an SDP.
430 // This server datagram transport will be promoted to the used datagram
431 // transport after the local description is set, and the ownership will be
432 // transferred to the actual JsepTransport. This "offer" datagram transport is
433 // not created if it's done on the party that provides answer. This offer
434 // datagram transport is only created once at the beginning of the connection,
435 // and never again.
436 std::unique_ptr<DatagramTransportInterface> offer_datagram_transport_ =
437 nullptr;
438
439 // Contains the offer of the |offer_datagram_transport_|, in case if it needs
440 // to be repeated.
441 absl::optional<cricket::SessionDescription::MediaTransportSetting>
442 datagram_transport_offer_settings_;
443
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800444 // When the new offer is regenerated (due to upgrade), we don't want to
445 // re-create media transport. New streams might be created; but media
446 // transport stays the same. This flag prevents re-creation of the transport
447 // on the offerer.
448 // The first media transport is created in jsep transport controller as the
449 // |offer_media_transport_|, and then the ownership is moved to the
450 // appropriate JsepTransport, at which point |offer_media_transport_| is
451 // zeroed out. On the callee (answerer), the first media transport is not even
452 // assigned to |offer_media_transport_|. Both offerer and answerer can
453 // recreate the Offer (e.g. after adding streams in Plan B), and so we want to
454 // prevent recreation of the media transport when that happens.
455 bool media_transport_created_once_ = false;
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700456 bool datagram_transport_created_once_ = false;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800457
Zhi Huange818b6e2018-02-22 15:26:27 -0800458 const cricket::SessionDescription* local_desc_ = nullptr;
459 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200460 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800461
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200462 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800463
464 cricket::IceConfig ice_config_;
465 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
466 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
467 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
468 rtc::AsyncInvoker invoker_;
469
Zhi Huange818b6e2018-02-22 15:26:27 -0800470 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
471};
472
473} // namespace webrtc
474
Steve Anton10542f22019-01-11 09:11:00 -0800475#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_