blob: 2919c711ad134257a370fc56247509a8a603f9ec [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
Bjorn A Mellemc85ebbe2019-06-07 10:28:06 -0700216 // Gets the transport parameters for the transport identified by |mid|.
217 // If |mid| is bundled, returns the parameters for the bundled transport.
218 // If the transport for |mid| has not been created yet, it may be allocated in
219 // order to generate transport parameters.
220 absl::optional<cricket::OpaqueTransportParameters> GetTransportParameters(
221 const std::string& mid);
222
Zhi Huange818b6e2018-02-22 15:26:27 -0800223 // All of these signals are fired on the signaling thread.
224
225 // If any transport failed => failed,
226 // Else if all completed => completed,
227 // Else if all connected => connected,
228 // Else => connecting
Alex Loiko9289eda2018-11-23 16:18:59 +0000229 sigslot::signal1<cricket::IceConnectionState> SignalIceConnectionState;
Zhi Huange818b6e2018-02-22 15:26:27 -0800230
Jonas Olsson635474e2018-10-18 15:58:17 +0200231 sigslot::signal1<PeerConnectionInterface::PeerConnectionState>
232 SignalConnectionState;
Alex Loiko9289eda2018-11-23 16:18:59 +0000233 sigslot::signal1<PeerConnectionInterface::IceConnectionState>
234 SignalStandardizedIceConnectionState;
Jonas Olsson635474e2018-10-18 15:58:17 +0200235
Zhi Huange818b6e2018-02-22 15:26:27 -0800236 // If all transports done gathering => complete,
237 // Else if any are gathering => gathering,
238 // Else => new
239 sigslot::signal1<cricket::IceGatheringState> SignalIceGatheringState;
240
241 // (mid, candidates)
242 sigslot::signal2<const std::string&, const std::vector<cricket::Candidate>&>
243 SignalIceCandidatesGathered;
244
Eldar Relloda13ea22019-06-01 12:23:43 +0300245 sigslot::signal1<const cricket::IceCandidateErrorEvent&>
246 SignalIceCandidateError;
247
Zhi Huange818b6e2018-02-22 15:26:27 -0800248 sigslot::signal1<const std::vector<cricket::Candidate>&>
249 SignalIceCandidatesRemoved;
250
Alex Drake00c7ecf2019-08-06 10:54:47 -0700251 sigslot::signal1<const cricket::CandidatePairChangeEvent&>
252 SignalIceCandidatePairChanged;
253
Zhi Huange818b6e2018-02-22 15:26:27 -0800254 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
255
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800256 sigslot::signal<> SignalMediaTransportStateChanged;
257
Zhi Huange818b6e2018-02-22 15:26:27 -0800258 private:
Zhi Huange818b6e2018-02-22 15:26:27 -0800259 RTCError ApplyDescription_n(bool local,
260 SdpType type,
261 const cricket::SessionDescription* description);
Zhi Huangd2248f82018-04-10 14:41:03 -0700262 RTCError ValidateAndMaybeUpdateBundleGroup(
263 bool local,
264 SdpType type,
265 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700266 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800267
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700268 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Zhi Huangd2248f82018-04-10 14:41:03 -0700269 const cricket::SessionDescription* description);
Zhi Huang365381f2018-04-13 16:44:34 -0700270 bool HandleBundledContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800271
Zhi Huang365381f2018-04-13 16:44:34 -0700272 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700273 cricket::JsepTransport* jsep_transport);
274 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700275
Zhi Huange818b6e2018-02-22 15:26:27 -0800276 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200277 const cricket::ContentInfo& content_info,
278 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700279 const std::vector<int>& encrypted_extension_ids,
280 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800281
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200282 absl::optional<std::string> bundled_mid() const {
283 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700284 if (bundle_group_ && bundle_group_->FirstContentName()) {
285 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800286 }
287 return bundled_mid;
288 }
289
290 bool IsBundled(const std::string& mid) const {
291 return bundle_group_ && bundle_group_->HasContentName(mid);
292 }
293
294 bool ShouldUpdateBundleGroup(SdpType type,
295 const cricket::SessionDescription* description);
296
297 std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle(
298 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800299 std::vector<int> GetEncryptedHeaderExtensionIds(
300 const cricket::ContentInfo& content_info);
301
Zhi Huange830e682018-03-30 10:48:35 -0700302 int GetRtpAbsSendTimeHeaderExtensionId(
303 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800304
Zhi Huange830e682018-03-30 10:48:35 -0700305 // This method takes the BUNDLE group into account. If the JsepTransport is
306 // destroyed because of BUNDLE, it would return the transport which other
307 // transports are bundled on (In current implementation, it is the first
308 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700309 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700310 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700311 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700312
313 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
314 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700315 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700316 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700317 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700318 const std::string& transport_name);
319
Anton Sukhanov7940da02018-10-10 10:34:49 -0700320 // Creates jsep transport. Noop if transport is already created.
321 // Transport is created either during SetLocalDescription (|local| == true) or
322 // during SetRemoteDescription (|local| == false). Passing |local| helps to
323 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800324 RTCError MaybeCreateJsepTransport(
325 bool local,
326 const cricket::ContentInfo& content_info,
327 const cricket::SessionDescription& description);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800328
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800329 // Creates media transport if config wants to use it, and a=x-mt line is
330 // present for the current media transport. Returned MediaTransportInterface
331 // is not connected, and must be connected to ICE. You must call
332 // |GenerateOrGetLastMediaTransportOffer| on the caller before calling
333 // MaybeCreateMediaTransport.
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800334 std::unique_ptr<webrtc::MediaTransportInterface> MaybeCreateMediaTransport(
335 const cricket::ContentInfo& content_info,
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800336 const cricket::SessionDescription& description,
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800337 bool local);
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700338
339 // Creates datagram transport if config wants to use it, and a=x-mt line is
340 // present for the current media transport. Returned
341 // DatagramTransportInterface is not connected, and must be connected to ICE.
342 // You must call |GenerateOrGetLastMediaTransportOffer| on the caller before
343 // calling MaybeCreateDatagramTransport.
344 std::unique_ptr<webrtc::DatagramTransportInterface>
345 MaybeCreateDatagramTransport(const cricket::ContentInfo& content_info,
346 const cricket::SessionDescription& description,
347 bool local);
348
Zhi Huange818b6e2018-02-22 15:26:27 -0800349 void MaybeDestroyJsepTransport(const std::string& mid);
350 void DestroyAllJsepTransports_n();
351
352 void SetIceRole_n(cricket::IceRole ice_role);
353
354 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700355 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800356 const cricket::TransportInfo& transport_info,
357 SdpType type,
358 bool local);
359
360 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700361 const cricket::ContentInfo& content_info,
Bjorn A Mellem0c1c1b42019-05-29 17:34:13 -0700362 cricket::IceTransportInternal* ice,
Anton Sukhanov292ce4e2019-06-03 13:00:24 -0700363 DatagramTransportInterface* datagram_transport);
Piotr (Peter) Slatala2b5baee2019-01-16 08:25:21 -0800364 std::unique_ptr<cricket::IceTransportInternal> CreateIceTransport(
365 const std::string transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800366 bool rtcp);
367
368 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
369 const std::string& transport_name,
370 rtc::PacketTransportInternal* rtp_packet_transport,
371 rtc::PacketTransportInternal* rtcp_packet_transport);
372 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
373 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700374 cricket::DtlsTransportInternal* rtp_dtls_transport,
375 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800376 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
377 const std::string& transport_name,
378 cricket::DtlsTransportInternal* rtp_dtls_transport,
379 cricket::DtlsTransportInternal* rtcp_dtls_transport);
380
381 // Collect all the DtlsTransports, including RTP and RTCP, from the
382 // JsepTransports. JsepTransportController can iterate all the DtlsTransports
383 // and update the aggregate states.
384 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
385
386 // Handlers for signals from Transport.
387 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport);
388 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport);
389 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport);
390 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
391 const cricket::Candidate& candidate);
Eldar Relloda13ea22019-06-01 12:23:43 +0300392 void OnTransportCandidateError_n(
393 cricket::IceTransportInternal* transport,
394 const cricket::IceCandidateErrorEvent& event);
Zhi Huange818b6e2018-02-22 15:26:27 -0800395 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
396 const cricket::Candidates& candidates);
397 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport);
398 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport);
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800399 void OnMediaTransportStateChanged_n();
Alex Drake00c7ecf2019-08-06 10:54:47 -0700400 void OnTransportCandidatePairChanged_n(
401 const cricket::CandidatePairChangeEvent& event);
Zhi Huange818b6e2018-02-22 15:26:27 -0800402
403 void UpdateAggregateStates_n();
404
405 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
406
407 rtc::Thread* const signaling_thread_ = nullptr;
408 rtc::Thread* const network_thread_ = nullptr;
409 cricket::PortAllocator* const port_allocator_ = nullptr;
Zach Steine20867f2018-08-02 13:20:15 -0700410 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800411
Zhi Huang365381f2018-04-13 16:44:34 -0700412 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700413 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700414 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700415 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
416 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800417
Jonas Olsson635474e2018-10-18 15:58:17 +0200418 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000419 // standardized_ice_connection_state_ is intended to replace
420 // ice_connection_state, see bugs.webrtc.org/9308
421 cricket::IceConnectionState ice_connection_state_ =
422 cricket::kIceConnectionConnecting;
423 PeerConnectionInterface::IceConnectionState
424 standardized_ice_connection_state_ =
425 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200426 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
427 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800428 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
429
430 Config config_;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800431
432 // Early on in the call we don't know if media transport is going to be used,
433 // but we need to get the server-supported parameters to add to an SDP.
434 // This server media transport will be promoted to the used media transport
435 // after the local description is set, and the ownership will be transferred
436 // to the actual JsepTransport.
437 // This "offer" media transport is not created if it's done on the party that
438 // provides answer. This offer media transport is only created once at the
439 // beginning of the connection, and never again.
440 std::unique_ptr<MediaTransportInterface> offer_media_transport_ = nullptr;
441
442 // Contains the offer of the |offer_media_transport_|, in case if it needs to
443 // be repeated.
444 absl::optional<cricket::SessionDescription::MediaTransportSetting>
445 media_transport_offer_settings_;
446
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700447 // Early on in the call we don't know if datagram transport is going to be
448 // used, but we need to get the server-supported parameters to add to an SDP.
449 // This server datagram transport will be promoted to the used datagram
450 // transport after the local description is set, and the ownership will be
451 // transferred to the actual JsepTransport. This "offer" datagram transport is
452 // not created if it's done on the party that provides answer. This offer
453 // datagram transport is only created once at the beginning of the connection,
454 // and never again.
455 std::unique_ptr<DatagramTransportInterface> offer_datagram_transport_ =
456 nullptr;
457
458 // Contains the offer of the |offer_datagram_transport_|, in case if it needs
459 // to be repeated.
460 absl::optional<cricket::SessionDescription::MediaTransportSetting>
461 datagram_transport_offer_settings_;
462
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800463 // When the new offer is regenerated (due to upgrade), we don't want to
464 // re-create media transport. New streams might be created; but media
465 // transport stays the same. This flag prevents re-creation of the transport
466 // on the offerer.
467 // The first media transport is created in jsep transport controller as the
468 // |offer_media_transport_|, and then the ownership is moved to the
469 // appropriate JsepTransport, at which point |offer_media_transport_| is
470 // zeroed out. On the callee (answerer), the first media transport is not even
471 // assigned to |offer_media_transport_|. Both offerer and answerer can
472 // recreate the Offer (e.g. after adding streams in Plan B), and so we want to
473 // prevent recreation of the media transport when that happens.
474 bool media_transport_created_once_ = false;
475
Zhi Huange818b6e2018-02-22 15:26:27 -0800476 const cricket::SessionDescription* local_desc_ = nullptr;
477 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200478 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800479
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200480 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800481
482 cricket::IceConfig ice_config_;
483 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
484 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
485 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
486 rtc::AsyncInvoker invoker_;
487
Zhi Huange818b6e2018-02-22 15:26:27 -0800488 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
489};
490
491} // namespace webrtc
492
Steve Anton10542f22019-01-11 09:11:00 -0800493#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_