blob: fcae15373feb8110533e9b14ce39f1a9938471b5 [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
Eldar Relloda13ea22019-06-01 12:23:43 +0300238 sigslot::signal1<const cricket::IceCandidateErrorEvent&>
239 SignalIceCandidateError;
240
Zhi Huange818b6e2018-02-22 15:26:27 -0800241 sigslot::signal1<const std::vector<cricket::Candidate>&>
242 SignalIceCandidatesRemoved;
243
244 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
245
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800246 sigslot::signal<> SignalMediaTransportStateChanged;
247
Zhi Huange818b6e2018-02-22 15:26:27 -0800248 private:
Zhi Huange818b6e2018-02-22 15:26:27 -0800249 RTCError ApplyDescription_n(bool local,
250 SdpType type,
251 const cricket::SessionDescription* description);
Zhi Huangd2248f82018-04-10 14:41:03 -0700252 RTCError ValidateAndMaybeUpdateBundleGroup(
253 bool local,
254 SdpType type,
255 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700256 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800257
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700258 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Zhi Huangd2248f82018-04-10 14:41:03 -0700259 const cricket::SessionDescription* description);
Zhi Huang365381f2018-04-13 16:44:34 -0700260 bool HandleBundledContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800261
Zhi Huang365381f2018-04-13 16:44:34 -0700262 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700263 cricket::JsepTransport* jsep_transport);
264 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700265
Zhi Huange818b6e2018-02-22 15:26:27 -0800266 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200267 const cricket::ContentInfo& content_info,
268 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700269 const std::vector<int>& encrypted_extension_ids,
270 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800271
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200272 absl::optional<std::string> bundled_mid() const {
273 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700274 if (bundle_group_ && bundle_group_->FirstContentName()) {
275 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800276 }
277 return bundled_mid;
278 }
279
280 bool IsBundled(const std::string& mid) const {
281 return bundle_group_ && bundle_group_->HasContentName(mid);
282 }
283
284 bool ShouldUpdateBundleGroup(SdpType type,
285 const cricket::SessionDescription* description);
286
287 std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle(
288 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800289 std::vector<int> GetEncryptedHeaderExtensionIds(
290 const cricket::ContentInfo& content_info);
291
Zhi Huange830e682018-03-30 10:48:35 -0700292 int GetRtpAbsSendTimeHeaderExtensionId(
293 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800294
Zhi Huange830e682018-03-30 10:48:35 -0700295 // This method takes the BUNDLE group into account. If the JsepTransport is
296 // destroyed because of BUNDLE, it would return the transport which other
297 // transports are bundled on (In current implementation, it is the first
298 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700299 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700300 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700301 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700302
303 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
304 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700305 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700306 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700307 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700308 const std::string& transport_name);
309
Anton Sukhanov7940da02018-10-10 10:34:49 -0700310 // Creates jsep transport. Noop if transport is already created.
311 // Transport is created either during SetLocalDescription (|local| == true) or
312 // during SetRemoteDescription (|local| == false). Passing |local| helps to
313 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800314 RTCError MaybeCreateJsepTransport(
315 bool local,
316 const cricket::ContentInfo& content_info,
317 const cricket::SessionDescription& description);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800318
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800319 // Creates media transport if config wants to use it, and a=x-mt line is
320 // present for the current media transport. Returned MediaTransportInterface
321 // is not connected, and must be connected to ICE. You must call
322 // |GenerateOrGetLastMediaTransportOffer| on the caller before calling
323 // MaybeCreateMediaTransport.
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800324 std::unique_ptr<webrtc::MediaTransportInterface> MaybeCreateMediaTransport(
325 const cricket::ContentInfo& content_info,
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800326 const cricket::SessionDescription& description,
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800327 bool local);
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700328
329 // Creates datagram transport if config wants to use it, and a=x-mt line is
330 // present for the current media transport. Returned
331 // DatagramTransportInterface is not connected, and must be connected to ICE.
332 // You must call |GenerateOrGetLastMediaTransportOffer| on the caller before
333 // calling MaybeCreateDatagramTransport.
334 std::unique_ptr<webrtc::DatagramTransportInterface>
335 MaybeCreateDatagramTransport(const cricket::ContentInfo& content_info,
336 const cricket::SessionDescription& description,
337 bool local);
338
Zhi Huange818b6e2018-02-22 15:26:27 -0800339 void MaybeDestroyJsepTransport(const std::string& mid);
340 void DestroyAllJsepTransports_n();
341
342 void SetIceRole_n(cricket::IceRole ice_role);
343
344 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700345 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800346 const cricket::TransportInfo& transport_info,
347 SdpType type,
348 bool local);
349
350 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Bjorn A Mellem0c1c1b42019-05-29 17:34:13 -0700351 cricket::IceTransportInternal* ice,
Anton Sukhanov292ce4e2019-06-03 13:00:24 -0700352 DatagramTransportInterface* datagram_transport);
Piotr (Peter) Slatala2b5baee2019-01-16 08:25:21 -0800353 std::unique_ptr<cricket::IceTransportInternal> CreateIceTransport(
354 const std::string transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800355 bool rtcp);
356
357 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
358 const std::string& transport_name,
359 rtc::PacketTransportInternal* rtp_packet_transport,
360 rtc::PacketTransportInternal* rtcp_packet_transport);
361 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
362 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700363 cricket::DtlsTransportInternal* rtp_dtls_transport,
364 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800365 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
366 const std::string& transport_name,
367 cricket::DtlsTransportInternal* rtp_dtls_transport,
368 cricket::DtlsTransportInternal* rtcp_dtls_transport);
369
370 // Collect all the DtlsTransports, including RTP and RTCP, from the
371 // JsepTransports. JsepTransportController can iterate all the DtlsTransports
372 // and update the aggregate states.
373 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
374
375 // Handlers for signals from Transport.
376 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport);
377 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport);
378 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport);
379 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
380 const cricket::Candidate& candidate);
Eldar Relloda13ea22019-06-01 12:23:43 +0300381 void OnTransportCandidateError_n(
382 cricket::IceTransportInternal* transport,
383 const cricket::IceCandidateErrorEvent& event);
Zhi Huange818b6e2018-02-22 15:26:27 -0800384 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
385 const cricket::Candidates& candidates);
386 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport);
387 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport);
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800388 void OnMediaTransportStateChanged_n();
Zhi Huange818b6e2018-02-22 15:26:27 -0800389
390 void UpdateAggregateStates_n();
391
392 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
393
394 rtc::Thread* const signaling_thread_ = nullptr;
395 rtc::Thread* const network_thread_ = nullptr;
396 cricket::PortAllocator* const port_allocator_ = nullptr;
Zach Steine20867f2018-08-02 13:20:15 -0700397 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800398
Zhi Huang365381f2018-04-13 16:44:34 -0700399 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700400 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700401 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700402 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
403 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800404
Jonas Olsson635474e2018-10-18 15:58:17 +0200405 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000406 // standardized_ice_connection_state_ is intended to replace
407 // ice_connection_state, see bugs.webrtc.org/9308
408 cricket::IceConnectionState ice_connection_state_ =
409 cricket::kIceConnectionConnecting;
410 PeerConnectionInterface::IceConnectionState
411 standardized_ice_connection_state_ =
412 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200413 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
414 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800415 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
416
417 Config config_;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800418
419 // Early on in the call we don't know if media transport is going to be used,
420 // but we need to get the server-supported parameters to add to an SDP.
421 // This server media transport will be promoted to the used media transport
422 // after the local description is set, and the ownership will be transferred
423 // to the actual JsepTransport.
424 // This "offer" media transport is not created if it's done on the party that
425 // provides answer. This offer media transport is only created once at the
426 // beginning of the connection, and never again.
427 std::unique_ptr<MediaTransportInterface> offer_media_transport_ = nullptr;
428
429 // Contains the offer of the |offer_media_transport_|, in case if it needs to
430 // be repeated.
431 absl::optional<cricket::SessionDescription::MediaTransportSetting>
432 media_transport_offer_settings_;
433
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700434 // Early on in the call we don't know if datagram transport is going to be
435 // used, but we need to get the server-supported parameters to add to an SDP.
436 // This server datagram transport will be promoted to the used datagram
437 // transport after the local description is set, and the ownership will be
438 // transferred to the actual JsepTransport. This "offer" datagram transport is
439 // not created if it's done on the party that provides answer. This offer
440 // datagram transport is only created once at the beginning of the connection,
441 // and never again.
442 std::unique_ptr<DatagramTransportInterface> offer_datagram_transport_ =
443 nullptr;
444
445 // Contains the offer of the |offer_datagram_transport_|, in case if it needs
446 // to be repeated.
447 absl::optional<cricket::SessionDescription::MediaTransportSetting>
448 datagram_transport_offer_settings_;
449
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800450 // When the new offer is regenerated (due to upgrade), we don't want to
451 // re-create media transport. New streams might be created; but media
452 // transport stays the same. This flag prevents re-creation of the transport
453 // on the offerer.
454 // The first media transport is created in jsep transport controller as the
455 // |offer_media_transport_|, and then the ownership is moved to the
456 // appropriate JsepTransport, at which point |offer_media_transport_| is
457 // zeroed out. On the callee (answerer), the first media transport is not even
458 // assigned to |offer_media_transport_|. Both offerer and answerer can
459 // recreate the Offer (e.g. after adding streams in Plan B), and so we want to
460 // prevent recreation of the media transport when that happens.
461 bool media_transport_created_once_ = false;
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700462 bool datagram_transport_created_once_ = false;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800463
Zhi Huange818b6e2018-02-22 15:26:27 -0800464 const cricket::SessionDescription* local_desc_ = nullptr;
465 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200466 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800467
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200468 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800469
470 cricket::IceConfig ice_config_;
471 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
472 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
473 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
474 rtc::AsyncInvoker invoker_;
475
Zhi Huange818b6e2018-02-22 15:26:27 -0800476 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
477};
478
479} // namespace webrtc
480
Steve Anton10542f22019-01-11 09:11:00 -0800481#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_