blob: 537b2b1d86bc17ad071ac31531724161f6140a56 [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
Anton Sukhanov7940da02018-10-10 10:34:49 -070092 // Optional media transport factory (experimental). If provided it will be
Piotr (Peter) Slatala55b91b92019-01-25 13:31:15 -080093 // used to create media_transport (as long as either
94 // |use_media_transport_for_media| or
95 // |use_media_transport_for_data_channels| is set to true). However, whether
96 // it will be used to send / receive audio and video frames instead of RTP
97 // is determined by |use_media_transport_for_media|. Note that currently
98 // media_transport co-exists with RTP / RTCP transports and may use the same
Anton Sukhanov7940da02018-10-10 10:34:49 -070099 // underlying ICE transport.
100 MediaTransportFactory* media_transport_factory = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800101 };
102
103 // The ICE related events are signaled on the |signaling_thread|.
104 // All the transport related methods are called on the |network_thread|.
105 JsepTransportController(rtc::Thread* signaling_thread,
106 rtc::Thread* network_thread,
107 cricket::PortAllocator* port_allocator,
Zach Steine20867f2018-08-02 13:20:15 -0700108 AsyncResolverFactory* async_resolver_factory,
Zhi Huange818b6e2018-02-22 15:26:27 -0800109 Config config);
110 virtual ~JsepTransportController();
111
112 // The main method to be called; applies a description at the transport
113 // level, creating/destroying transport objects as needed and updating their
114 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
115 // yet? May make sense to in the future.
116 RTCError SetLocalDescription(SdpType type,
117 const cricket::SessionDescription* description);
118
119 RTCError SetRemoteDescription(SdpType type,
120 const cricket::SessionDescription* description);
121
122 // Get transports to be used for the provided |mid|. If bundling is enabled,
123 // calling GetRtpTransport for multiple MIDs may yield the same object.
124 RtpTransportInternal* GetRtpTransport(const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100125 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
126 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800127 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100128 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100129 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100130 const std::string& mid);
Zhi Huange818b6e2018-02-22 15:26:27 -0800131
Anton Sukhanov7940da02018-10-10 10:34:49 -0700132 MediaTransportInterface* GetMediaTransport(const std::string& mid) const;
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800133 MediaTransportState GetMediaTransportState(const std::string& mid) const;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700134
Zhi Huange818b6e2018-02-22 15:26:27 -0800135 /*********************
136 * ICE-related methods
137 ********************/
138 // This method is public to allow PeerConnection to update it from
139 // SetConfiguration.
140 void SetIceConfig(const cricket::IceConfig& config);
141 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
142 // set, offers should generate new ufrags/passwords until an ICE restart
143 // occurs.
144 void SetNeedsIceRestartFlag();
145 // Returns true if the ICE restart flag above was set, and no ICE restart has
146 // occurred yet for this transport (by applying a local description with
147 // changed ufrag/password). If the transport has been deleted as a result of
148 // bundling, returns false.
149 bool NeedsIceRestart(const std::string& mid) const;
150 // Start gathering candidates for any new transports, or transports doing an
151 // ICE restart.
152 void MaybeStartGathering();
153 RTCError AddRemoteCandidates(
154 const std::string& mid,
155 const std::vector<cricket::Candidate>& candidates);
156 RTCError RemoveRemoteCandidates(
157 const std::vector<cricket::Candidate>& candidates);
158
159 /**********************
160 * DTLS-related methods
161 *********************/
162 // Specifies the identity to use in this session.
163 // Can only be called once.
164 bool SetLocalCertificate(
165 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
166 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
167 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800168 // Caller owns returned certificate chain. This method mainly exists for
169 // stats reporting.
170 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800171 const std::string& mid) const;
172 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200173 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800174
175 // TODO(deadbeef): GetStats isn't const because all the way down to
176 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
177 // const. Fix this.
178 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800179
Zhi Huange830e682018-03-30 10:48:35 -0700180 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700181
Zhi Huangb57e1692018-06-12 11:41:11 -0700182 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
183
Piotr (Peter) Slatala97fc11f2018-10-18 12:57:59 -0700184 // Allows to overwrite the settings from config. You may set or reset the
Piotr (Peter) Slatala55b91b92019-01-25 13:31:15 -0800185 // media transport configuration on the jsep transport controller, as long as
186 // you did not call 'GetMediaTransport' or 'MaybeCreateJsepTransport'. Once
187 // Jsep transport is created, you can't change this setting.
188 void SetMediaTransportSettings(bool use_media_transport_for_media,
189 bool use_media_transport_for_data_channels);
Piotr (Peter) Slatala97fc11f2018-10-18 12:57:59 -0700190
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800191 // If media transport is present enabled and supported,
192 // when this method is called, it creates a media transport and generates its
193 // offer. The new offer is then returned, and the created media transport will
194 // subsequently be used.
195 absl::optional<cricket::SessionDescription::MediaTransportSetting>
196 GenerateOrGetLastMediaTransportOffer();
197
Zhi Huange818b6e2018-02-22 15:26:27 -0800198 // All of these signals are fired on the signaling thread.
199
200 // If any transport failed => failed,
201 // Else if all completed => completed,
202 // Else if all connected => connected,
203 // Else => connecting
Alex Loiko9289eda2018-11-23 16:18:59 +0000204 sigslot::signal1<cricket::IceConnectionState> SignalIceConnectionState;
Zhi Huange818b6e2018-02-22 15:26:27 -0800205
Jonas Olsson635474e2018-10-18 15:58:17 +0200206 sigslot::signal1<PeerConnectionInterface::PeerConnectionState>
207 SignalConnectionState;
Alex Loiko9289eda2018-11-23 16:18:59 +0000208 sigslot::signal1<PeerConnectionInterface::IceConnectionState>
209 SignalStandardizedIceConnectionState;
Jonas Olsson635474e2018-10-18 15:58:17 +0200210
Zhi Huange818b6e2018-02-22 15:26:27 -0800211 // If all transports done gathering => complete,
212 // Else if any are gathering => gathering,
213 // Else => new
214 sigslot::signal1<cricket::IceGatheringState> SignalIceGatheringState;
215
216 // (mid, candidates)
217 sigslot::signal2<const std::string&, const std::vector<cricket::Candidate>&>
218 SignalIceCandidatesGathered;
219
220 sigslot::signal1<const std::vector<cricket::Candidate>&>
221 SignalIceCandidatesRemoved;
222
223 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
224
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800225 sigslot::signal<> SignalMediaTransportStateChanged;
226
Zhi Huange818b6e2018-02-22 15:26:27 -0800227 private:
Zhi Huange818b6e2018-02-22 15:26:27 -0800228 RTCError ApplyDescription_n(bool local,
229 SdpType type,
230 const cricket::SessionDescription* description);
Zhi Huangd2248f82018-04-10 14:41:03 -0700231 RTCError ValidateAndMaybeUpdateBundleGroup(
232 bool local,
233 SdpType type,
234 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700235 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800236
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700237 void HandleRejectedContent(const cricket::ContentInfo& content_info,
Zhi Huangd2248f82018-04-10 14:41:03 -0700238 const cricket::SessionDescription* description);
Zhi Huang365381f2018-04-13 16:44:34 -0700239 bool HandleBundledContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800240
Zhi Huang365381f2018-04-13 16:44:34 -0700241 bool SetTransportForMid(const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700242 cricket::JsepTransport* jsep_transport);
243 void RemoveTransportForMid(const std::string& mid);
Zhi Huangd2248f82018-04-10 14:41:03 -0700244
Zhi Huange818b6e2018-02-22 15:26:27 -0800245 cricket::JsepTransportDescription CreateJsepTransportDescription(
246 cricket::ContentInfo content_info,
247 cricket::TransportInfo transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700248 const std::vector<int>& encrypted_extension_ids,
249 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800250
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200251 absl::optional<std::string> bundled_mid() const {
252 absl::optional<std::string> bundled_mid;
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700253 if (bundle_group_ && bundle_group_->FirstContentName()) {
254 bundled_mid = *(bundle_group_->FirstContentName());
Zhi Huange818b6e2018-02-22 15:26:27 -0800255 }
256 return bundled_mid;
257 }
258
259 bool IsBundled(const std::string& mid) const {
260 return bundle_group_ && bundle_group_->HasContentName(mid);
261 }
262
263 bool ShouldUpdateBundleGroup(SdpType type,
264 const cricket::SessionDescription* description);
265
266 std::vector<int> MergeEncryptedHeaderExtensionIdsForBundle(
267 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800268 std::vector<int> GetEncryptedHeaderExtensionIds(
269 const cricket::ContentInfo& content_info);
270
Zhi Huange830e682018-03-30 10:48:35 -0700271 int GetRtpAbsSendTimeHeaderExtensionId(
272 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800273
Zhi Huange830e682018-03-30 10:48:35 -0700274 // This method takes the BUNDLE group into account. If the JsepTransport is
275 // destroyed because of BUNDLE, it would return the transport which other
276 // transports are bundled on (In current implementation, it is the first
277 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700278 const cricket::JsepTransport* GetJsepTransportForMid(
Zhi Huange830e682018-03-30 10:48:35 -0700279 const std::string& mid) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700280 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid);
Zhi Huange830e682018-03-30 10:48:35 -0700281
282 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
283 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700284 const cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700285 const std::string& transport_name) const;
Zhi Huang365381f2018-04-13 16:44:34 -0700286 cricket::JsepTransport* GetJsepTransportByName(
Zhi Huange830e682018-03-30 10:48:35 -0700287 const std::string& transport_name);
288
Anton Sukhanov7940da02018-10-10 10:34:49 -0700289 // Creates jsep transport. Noop if transport is already created.
290 // Transport is created either during SetLocalDescription (|local| == true) or
291 // during SetRemoteDescription (|local| == false). Passing |local| helps to
292 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800293 RTCError MaybeCreateJsepTransport(
294 bool local,
295 const cricket::ContentInfo& content_info,
296 const cricket::SessionDescription& description);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800297
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800298 // Creates media transport if config wants to use it, and a=x-mt line is
299 // present for the current media transport. Returned MediaTransportInterface
300 // is not connected, and must be connected to ICE. You must call
301 // |GenerateOrGetLastMediaTransportOffer| on the caller before calling
302 // MaybeCreateMediaTransport.
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800303 std::unique_ptr<webrtc::MediaTransportInterface> MaybeCreateMediaTransport(
304 const cricket::ContentInfo& content_info,
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800305 const cricket::SessionDescription& description,
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800306 bool local);
Zhi Huange818b6e2018-02-22 15:26:27 -0800307 void MaybeDestroyJsepTransport(const std::string& mid);
308 void DestroyAllJsepTransports_n();
309
310 void SetIceRole_n(cricket::IceRole ice_role);
311
312 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700313 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800314 const cricket::TransportInfo& transport_info,
315 SdpType type,
316 bool local);
317
318 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Piotr (Peter) Slatala2b5baee2019-01-16 08:25:21 -0800319 std::unique_ptr<cricket::IceTransportInternal> ice);
320 std::unique_ptr<cricket::IceTransportInternal> CreateIceTransport(
321 const std::string transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800322 bool rtcp);
323
324 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
325 const std::string& transport_name,
326 rtc::PacketTransportInternal* rtp_packet_transport,
327 rtc::PacketTransportInternal* rtcp_packet_transport);
328 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
329 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700330 cricket::DtlsTransportInternal* rtp_dtls_transport,
331 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800332 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
333 const std::string& transport_name,
334 cricket::DtlsTransportInternal* rtp_dtls_transport,
335 cricket::DtlsTransportInternal* rtcp_dtls_transport);
336
337 // Collect all the DtlsTransports, including RTP and RTCP, from the
338 // JsepTransports. JsepTransportController can iterate all the DtlsTransports
339 // and update the aggregate states.
340 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
341
342 // Handlers for signals from Transport.
343 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport);
344 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport);
345 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport);
346 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
347 const cricket::Candidate& candidate);
Zhi Huange818b6e2018-02-22 15:26:27 -0800348 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
349 const cricket::Candidates& candidates);
350 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport);
351 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport);
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800352 void OnMediaTransportStateChanged_n();
Zhi Huange818b6e2018-02-22 15:26:27 -0800353
354 void UpdateAggregateStates_n();
355
356 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
357
358 rtc::Thread* const signaling_thread_ = nullptr;
359 rtc::Thread* const network_thread_ = nullptr;
360 cricket::PortAllocator* const port_allocator_ = nullptr;
Zach Steine20867f2018-08-02 13:20:15 -0700361 AsyncResolverFactory* const async_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800362
Zhi Huang365381f2018-04-13 16:44:34 -0700363 std::map<std::string, std::unique_ptr<cricket::JsepTransport>>
Zhi Huange830e682018-03-30 10:48:35 -0700364 jsep_transports_by_name_;
Zhi Huangd2248f82018-04-10 14:41:03 -0700365 // This keeps track of the mapping between media section
Zhi Huang365381f2018-04-13 16:44:34 -0700366 // (BaseChannel/SctpTransport) and the JsepTransport underneath.
367 std::map<std::string, cricket::JsepTransport*> mid_to_transport_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800368
Jonas Olsson635474e2018-10-18 15:58:17 +0200369 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000370 // standardized_ice_connection_state_ is intended to replace
371 // ice_connection_state, see bugs.webrtc.org/9308
372 cricket::IceConnectionState ice_connection_state_ =
373 cricket::kIceConnectionConnecting;
374 PeerConnectionInterface::IceConnectionState
375 standardized_ice_connection_state_ =
376 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200377 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
378 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800379 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
380
381 Config config_;
Piotr (Peter) Slatala63a176b2019-01-25 08:25:33 -0800382 // Determines if Config::media_transport_factory should be used
383 // to create a media transport. (when falling back to RTP this may be false).
384 // This is a prerequisite, but is not sufficient to create media transport
385 // (the factory needs to be provided in the config, and config must allow for
386 // media transport).
387 bool is_media_transport_factory_enabled_ = true;
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800388
389 // Early on in the call we don't know if media transport is going to be used,
390 // but we need to get the server-supported parameters to add to an SDP.
391 // This server media transport will be promoted to the used media transport
392 // after the local description is set, and the ownership will be transferred
393 // to the actual JsepTransport.
394 // This "offer" media transport is not created if it's done on the party that
395 // provides answer. This offer media transport is only created once at the
396 // beginning of the connection, and never again.
397 std::unique_ptr<MediaTransportInterface> offer_media_transport_ = nullptr;
398
399 // Contains the offer of the |offer_media_transport_|, in case if it needs to
400 // be repeated.
401 absl::optional<cricket::SessionDescription::MediaTransportSetting>
402 media_transport_offer_settings_;
403
404 // When the new offer is regenerated (due to upgrade), we don't want to
405 // re-create media transport. New streams might be created; but media
406 // transport stays the same. This flag prevents re-creation of the transport
407 // on the offerer.
408 // The first media transport is created in jsep transport controller as the
409 // |offer_media_transport_|, and then the ownership is moved to the
410 // appropriate JsepTransport, at which point |offer_media_transport_| is
411 // zeroed out. On the callee (answerer), the first media transport is not even
412 // assigned to |offer_media_transport_|. Both offerer and answerer can
413 // recreate the Offer (e.g. after adding streams in Plan B), and so we want to
414 // prevent recreation of the media transport when that happens.
415 bool media_transport_created_once_ = false;
416
Zhi Huange818b6e2018-02-22 15:26:27 -0800417 const cricket::SessionDescription* local_desc_ = nullptr;
418 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200419 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800420
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200421 absl::optional<cricket::ContentGroup> bundle_group_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800422
423 cricket::IceConfig ice_config_;
424 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
425 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
426 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
427 rtc::AsyncInvoker invoker_;
428
Zhi Huange818b6e2018-02-22 15:26:27 -0800429 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
430};
431
432} // namespace webrtc
433
Steve Anton10542f22019-01-11 09:11:00 -0800434#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_