blob: fff08d18897455c48e40f133b78a11f1ec6693db [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 Sukhanov7940da02018-10-10 10:34:49 -070022#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/peer_connection_interface.h"
Qingsi Wang7685e862018-06-11 20:15:46 -070024#include "logging/rtc_event_log/rtc_event_log.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "media/sctp/sctp_transport_internal.h"
26#include "p2p/base/dtls_transport.h"
27#include "p2p/base/p2p_transport_channel.h"
28#include "p2p/base/transport_factory_interface.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080029#include "pc/channel.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "pc/dtls_srtp_transport.h"
31#include "pc/dtls_transport.h"
32#include "pc/jsep_transport.h"
33#include "pc/rtp_transport.h"
34#include "pc/srtp_transport.h"
35#include "rtc_base/async_invoker.h"
36#include "rtc_base/constructor_magic.h"
37#include "rtc_base/ref_counted_object.h"
Artem Titove41c4332018-07-25 15:04:28 +020038#include "rtc_base/third_party/sigslot/sigslot.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080039
40namespace rtc {
41class Thread;
42class PacketTransportInternal;
43} // namespace rtc
44
45namespace webrtc {
46
Steve Antond25828a2018-08-31 13:06:05 -070047class JsepTransportController : public sigslot::has_slots<> {
Zhi Huange818b6e2018-02-22 15:26:27 -080048 public:
Zhi Huang365381f2018-04-13 16:44:34 -070049 // Used when the RtpTransport/DtlsTransport of the m= section is changed
50 // because the section is rejected or BUNDLE is enabled.
51 class Observer {
52 public:
53 virtual ~Observer() {}
54
55 // Returns true if media associated with |mid| was successfully set up to be
56 // demultiplexed on |rtp_transport|. Could return false if two bundled m=
57 // sections use the same SSRC, for example.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -070058 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 16:44:34 -070059 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -070060 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +010061 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Piotr (Peter) Slatalacc8e8bb2018-11-15 08:26:19 -080062 MediaTransportInterface* media_transport) = 0;
Zhi Huang365381f2018-04-13 16:44:34 -070063 };
64
Zhi Huange818b6e2018-02-22 15:26:27 -080065 struct Config {
66 // If |redetermine_role_on_ice_restart| is true, ICE role is redetermined
67 // upon setting a local transport description that indicates an ICE
68 // restart.
69 bool redetermine_role_on_ice_restart = true;
70 rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
71 // |crypto_options| is used to determine if created DTLS transports
72 // negotiate GCM crypto suites or not.
Benjamin Wrighta54daf12018-10-11 15:33:17 -070073 webrtc::CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 15:26:27 -080074 PeerConnectionInterface::BundlePolicy bundle_policy =
75 PeerConnectionInterface::kBundlePolicyBalanced;
76 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy =
77 PeerConnectionInterface::kRtcpMuxPolicyRequire;
78 bool disable_encryption = false;
79 bool enable_external_auth = false;
80 // Used to inject the ICE/DTLS transports created externally.
81 cricket::TransportFactoryInterface* external_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 16:44:34 -070082 Observer* transport_observer = nullptr;
Zhi Huangb57e1692018-06-12 11:41:11 -070083 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-11 20:15:46 -070084 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 10:34:49 -070085
Piotr (Peter) Slatala55b91b92019-01-25 13:31:15 -080086 // Whether media transport is used for media.
87 bool use_media_transport_for_media = false;
88
89 // Whether media transport is used for data channels.
90 bool use_media_transport_for_data_channels = false;
91
Niels Möllerabea6e52019-03-08 14:49:32 +010092 // Whether an RtpMediaTransport should be created as default, when no
93 // MediaTransportFactory is provided.
94 bool use_rtp_media_transport = false;
95
Anton Sukhanov7940da02018-10-10 10:34:49 -070096 // Optional media transport factory (experimental). If provided it will be
Piotr (Peter) Slatala55b91b92019-01-25 13:31:15 -080097 // used to create media_transport (as long as either
98 // |use_media_transport_for_media| or
99 // |use_media_transport_for_data_channels| is set to true). However, whether
100 // it will be used to send / receive audio and video frames instead of RTP
101 // is determined by |use_media_transport_for_media|. Note that currently
102 // media_transport co-exists with RTP / RTCP transports and may use the same
Anton Sukhanov7940da02018-10-10 10:34:49 -0700103 // underlying ICE transport.
104 MediaTransportFactory* media_transport_factory = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800105 };
106
107 // The ICE related events are signaled on the |signaling_thread|.
108 // All the transport related methods are called on the |network_thread|.
109 JsepTransportController(rtc::Thread* signaling_thread,
110 rtc::Thread* network_thread,
111 cricket::PortAllocator* port_allocator,
Zach Steine20867f2018-08-02 13:20:15 -0700112 AsyncResolverFactory* async_resolver_factory,
Zhi Huange818b6e2018-02-22 15:26:27 -0800113 Config config);
114 virtual ~JsepTransportController();
115
116 // The main method to be called; applies a description at the transport
117 // level, creating/destroying transport objects as needed and updating their
118 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
119 // yet? May make sense to in the future.
120 RTCError SetLocalDescription(SdpType type,
121 const cricket::SessionDescription* description);
122
123 RTCError SetRemoteDescription(SdpType type,
124 const cricket::SessionDescription* description);
125
126 // Get transports to be used for the provided |mid|. If bundling is enabled,
127 // calling GetRtpTransport for multiple MIDs may yield the same object.
128 RtpTransportInternal* GetRtpTransport(const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100129 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
130 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800131 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100132 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100133 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100134 const std::string& mid);
Zhi Huange818b6e2018-02-22 15:26:27 -0800135
Anton Sukhanov7940da02018-10-10 10:34:49 -0700136 MediaTransportInterface* GetMediaTransport(const std::string& mid) const;
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800137 MediaTransportState GetMediaTransportState(const std::string& mid) const;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700138
Zhi Huange818b6e2018-02-22 15:26:27 -0800139 /*********************
140 * ICE-related methods
141 ********************/
142 // This method is public to allow PeerConnection to update it from
143 // SetConfiguration.
144 void SetIceConfig(const cricket::IceConfig& config);
145 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
146 // set, offers should generate new ufrags/passwords until an ICE restart
147 // occurs.
148 void SetNeedsIceRestartFlag();
149 // Returns true if the ICE restart flag above was set, and no ICE restart has
150 // occurred yet for this transport (by applying a local description with
151 // changed ufrag/password). If the transport has been deleted as a result of
152 // bundling, returns false.
153 bool NeedsIceRestart(const std::string& mid) const;
154 // Start gathering candidates for any new transports, or transports doing an
155 // ICE restart.
156 void MaybeStartGathering();
157 RTCError AddRemoteCandidates(
158 const std::string& mid,
159 const std::vector<cricket::Candidate>& candidates);
160 RTCError RemoveRemoteCandidates(
161 const std::vector<cricket::Candidate>& candidates);
162
163 /**********************
164 * DTLS-related methods
165 *********************/
166 // Specifies the identity to use in this session.
167 // Can only be called once.
168 bool SetLocalCertificate(
169 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
170 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
171 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800172 // Caller owns returned certificate chain. This method mainly exists for
173 // stats reporting.
174 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800175 const std::string& mid) const;
176 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200177 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800178
179 // TODO(deadbeef): GetStats isn't const because all the way down to
180 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
181 // const. Fix this.
182 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800183
Zhi Huange830e682018-03-30 10:48:35 -0700184 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700185
Zhi Huangb57e1692018-06-12 11:41:11 -0700186 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
187
Piotr (Peter) Slatala97fc11f2018-10-18 12:57:59 -0700188 // Allows to overwrite the settings from config. You may set or reset the
Piotr (Peter) Slatala55b91b92019-01-25 13:31:15 -0800189 // media transport configuration on the jsep transport controller, as long as
190 // you did not call 'GetMediaTransport' or 'MaybeCreateJsepTransport'. Once
191 // Jsep transport is created, you can't change this setting.
192 void SetMediaTransportSettings(bool use_media_transport_for_media,
193 bool use_media_transport_for_data_channels);
Piotr (Peter) Slatala97fc11f2018-10-18 12:57:59 -0700194
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800195 // If media transport is present enabled and supported,
196 // when this method is called, it creates a media transport and generates its
197 // offer. The new offer is then returned, and the created media transport will
198 // subsequently be used.
199 absl::optional<cricket::SessionDescription::MediaTransportSetting>
200 GenerateOrGetLastMediaTransportOffer();
201
Zhi Huange818b6e2018-02-22 15:26:27 -0800202 // All of these signals are fired on the signaling thread.
203
204 // If any transport failed => failed,
205 // Else if all completed => completed,
206 // Else if all connected => connected,
207 // Else => connecting
Alex Loiko9289eda2018-11-23 16:18:59 +0000208 sigslot::signal1<cricket::IceConnectionState> SignalIceConnectionState;
Zhi Huange818b6e2018-02-22 15:26:27 -0800209
Jonas Olsson635474e2018-10-18 15:58:17 +0200210 sigslot::signal1<PeerConnectionInterface::PeerConnectionState>
211 SignalConnectionState;
Alex Loiko9289eda2018-11-23 16:18:59 +0000212 sigslot::signal1<PeerConnectionInterface::IceConnectionState>
213 SignalStandardizedIceConnectionState;
Jonas Olsson635474e2018-10-18 15:58:17 +0200214
Zhi Huange818b6e2018-02-22 15:26:27 -0800215 // If all transports done gathering => complete,
216 // Else if any are gathering => gathering,
217 // Else => new
218 sigslot::signal1<cricket::IceGatheringState> SignalIceGatheringState;
219
220 // (mid, candidates)
221 sigslot::signal2<const std::string&, const std::vector<cricket::Candidate>&>
222 SignalIceCandidatesGathered;
223
224 sigslot::signal1<const std::vector<cricket::Candidate>&>
225 SignalIceCandidatesRemoved;
226
227 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
228
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800229 sigslot::signal<> SignalMediaTransportStateChanged;
230
Zhi Huange818b6e2018-02-22 15:26:27 -0800231 private:
Zhi Huange818b6e2018-02-22 15:26:27 -0800232 RTCError ApplyDescription_n(bool local,
233 SdpType type,
234 const cricket::SessionDescription* description);
Zhi Huangd2248f82018-04-10 14:41:03 -0700235 RTCError ValidateAndMaybeUpdateBundleGroup(
236 bool local,
237 SdpType type,
238 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700239 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800240
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700241 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Zhi Huangd2248f82018-04-10 14:41:03 -0700242 const cricket::SessionDescription* description);
Zhi Huang365381f2018-04-13 16:44:34 -0700243 bool HandleBundledContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800244
Zhi Huang365381f2018-04-13 16:44:34 -0700245 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700246 cricket::JsepTransport* jsep_transport);
247 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700248
Zhi Huange818b6e2018-02-22 15:26:27 -0800249 cricket::JsepTransportDescription CreateJsepTransportDescription(
250 cricket::ContentInfo content_info,
251 cricket::TransportInfo transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700252 const std::vector<int>& encrypted_extension_ids,
253 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800254
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200255 absl::optional<std::string> bundled_mid() const {
256 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700257 if (bundle_group_ && bundle_group_->FirstContentName()) {
258 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800259 }
260 return bundled_mid;
261 }
262
263 bool IsBundled(const std::string& mid) const {
264 return bundle_group_ && bundle_group_->HasContentName(mid);
265 }
266
267 bool ShouldUpdateBundleGroup(SdpType type,
268 const cricket::SessionDescription* description);
269
270 std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle(
271 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800272 std::vector<int> GetEncryptedHeaderExtensionIds(
273 const cricket::ContentInfo& content_info);
274
Zhi Huange830e682018-03-30 10:48:35 -0700275 int GetRtpAbsSendTimeHeaderExtensionId(
276 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800277
Zhi Huange830e682018-03-30 10:48:35 -0700278 // This method takes the BUNDLE group into account. If the JsepTransport is
279 // destroyed because of BUNDLE, it would return the transport which other
280 // transports are bundled on (In current implementation, it is the first
281 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700282 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700283 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700284 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700285
286 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
287 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700288 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700289 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700290 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700291 const std::string& transport_name);
292
Anton Sukhanov7940da02018-10-10 10:34:49 -0700293 // Creates jsep transport. Noop if transport is already created.
294 // Transport is created either during SetLocalDescription (|local| == true) or
295 // during SetRemoteDescription (|local| == false). Passing |local| helps to
296 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800297 RTCError MaybeCreateJsepTransport(
298 bool local,
299 const cricket::ContentInfo& content_info,
300 const cricket::SessionDescription& description);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800301
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800302 // Creates media transport if config wants to use it, and a=x-mt line is
303 // present for the current media transport. Returned MediaTransportInterface
304 // is not connected, and must be connected to ICE. You must call
305 // |GenerateOrGetLastMediaTransportOffer| on the caller before calling
306 // MaybeCreateMediaTransport.
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800307 std::unique_ptr<webrtc::MediaTransportInterface> MaybeCreateMediaTransport(
308 const cricket::ContentInfo& content_info,
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800309 const cricket::SessionDescription& description,
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800310 bool local);
Zhi Huange818b6e2018-02-22 15:26:27 -0800311 void MaybeDestroyJsepTransport(const std::string& mid);
312 void DestroyAllJsepTransports_n();
313
314 void SetIceRole_n(cricket::IceRole ice_role);
315
316 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700317 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800318 const cricket::TransportInfo& transport_info,
319 SdpType type,
320 bool local);
321
322 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Piotr (Peter) Slatala2b5baee2019-01-16 08:25:21 -0800323 std::unique_ptr<cricket::IceTransportInternal> ice);
324 std::unique_ptr<cricket::IceTransportInternal> CreateIceTransport(
325 const std::string transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800326 bool rtcp);
327
328 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
329 const std::string& transport_name,
330 rtc::PacketTransportInternal* rtp_packet_transport,
331 rtc::PacketTransportInternal* rtcp_packet_transport);
332 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
333 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700334 cricket::DtlsTransportInternal* rtp_dtls_transport,
335 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800336 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
337 const std::string& transport_name,
338 cricket::DtlsTransportInternal* rtp_dtls_transport,
339 cricket::DtlsTransportInternal* rtcp_dtls_transport);
340
341 // Collect all the DtlsTransports, including RTP and RTCP, from the
342 // JsepTransports. JsepTransportController can iterate all the DtlsTransports
343 // and update the aggregate states.
344 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
345
346 // Handlers for signals from Transport.
347 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport);
348 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport);
349 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport);
350 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
351 const cricket::Candidate& candidate);
Zhi Huange818b6e2018-02-22 15:26:27 -0800352 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
353 const cricket::Candidates& candidates);
354 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport);
355 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport);
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800356 void OnMediaTransportStateChanged_n();
Zhi Huange818b6e2018-02-22 15:26:27 -0800357
358 void UpdateAggregateStates_n();
359
360 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
361
362 rtc::Thread* const signaling_thread_ = nullptr;
363 rtc::Thread* const network_thread_ = nullptr;
364 cricket::PortAllocator* const port_allocator_ = nullptr;
Zach Steine20867f2018-08-02 13:20:15 -0700365 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800366
Zhi Huang365381f2018-04-13 16:44:34 -0700367 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700368 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700369 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700370 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
371 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800372
Jonas Olsson635474e2018-10-18 15:58:17 +0200373 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000374 // standardized_ice_connection_state_ is intended to replace
375 // ice_connection_state, see bugs.webrtc.org/9308
376 cricket::IceConnectionState ice_connection_state_ =
377 cricket::kIceConnectionConnecting;
378 PeerConnectionInterface::IceConnectionState
379 standardized_ice_connection_state_ =
380 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200381 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
382 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800383 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
384
385 Config config_;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800386
387 // Early on in the call we don't know if media transport is going to be used,
388 // but we need to get the server-supported parameters to add to an SDP.
389 // This server media transport will be promoted to the used media transport
390 // after the local description is set, and the ownership will be transferred
391 // to the actual JsepTransport.
392 // This "offer" media transport is not created if it's done on the party that
393 // provides answer. This offer media transport is only created once at the
394 // beginning of the connection, and never again.
395 std::unique_ptr<MediaTransportInterface> offer_media_transport_ = nullptr;
396
397 // Contains the offer of the |offer_media_transport_|, in case if it needs to
398 // be repeated.
399 absl::optional<cricket::SessionDescription::MediaTransportSetting>
400 media_transport_offer_settings_;
401
402 // When the new offer is regenerated (due to upgrade), we don't want to
403 // re-create media transport. New streams might be created; but media
404 // transport stays the same. This flag prevents re-creation of the transport
405 // on the offerer.
406 // The first media transport is created in jsep transport controller as the
407 // |offer_media_transport_|, and then the ownership is moved to the
408 // appropriate JsepTransport, at which point |offer_media_transport_| is
409 // zeroed out. On the callee (answerer), the first media transport is not even
410 // assigned to |offer_media_transport_|. Both offerer and answerer can
411 // recreate the Offer (e.g. after adding streams in Plan B), and so we want to
412 // prevent recreation of the media transport when that happens.
413 bool media_transport_created_once_ = false;
414
Zhi Huange818b6e2018-02-22 15:26:27 -0800415 const cricket::SessionDescription* local_desc_ = nullptr;
416 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200417 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800418
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200419 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800420
421 cricket::IceConfig ice_config_;
422 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
423 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
424 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
425 rtc::AsyncInvoker invoker_;
426
Zhi Huange818b6e2018-02-22 15:26:27 -0800427 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
428};
429
430} // namespace webrtc
431
Steve Anton10542f22019-01-11 09:11:00 -0800432#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_