blob: af86b01984199942329be23a0a1e319c5115a6de [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_PEER_CONNECTION_H_
12#define PC_PEER_CONNECTION_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
perkjd61bf802016-03-24 03:16:19 -070014#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070015#include <memory>
Steve Anton75737c02017-11-06 10:37:17 -080016#include <set>
17#include <string>
Henrik Boström79b69802019-07-18 11:16:56 +020018#include <utility>
perkjd61bf802016-03-24 03:16:19 -070019#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -070021#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "api/peer_connection_interface.h"
23#include "api/turn_customizer.h"
24#include "pc/ice_server_parsing.h"
25#include "pc/jsep_transport_controller.h"
26#include "pc/peer_connection_factory.h"
27#include "pc/peer_connection_internal.h"
28#include "pc/rtc_stats_collector.h"
Guido Urdaneta1ff16c82019-05-20 19:31:53 +020029#include "pc/rtp_sender.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "pc/rtp_transceiver.h"
Harald Alvestrandc85328f2019-02-28 07:51:00 +010031#include "pc/sctp_transport.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "pc/stats_collector.h"
33#include "pc/stream_collection.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "pc/webrtc_session_description_factory.h"
Jonas Olsson0182a032019-07-09 12:31:20 +020035#include "rtc_base/experiments/field_trial_parser.h"
Karl Wiberg5966c502019-02-21 23:55:09 +010036#include "rtc_base/race_checker.h"
Amit Hilbuchdbb49df2019-01-23 14:54:24 -080037#include "rtc_base/unique_id_generator.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038
39namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040
deadbeefeb459812015-12-15 19:24:43 -080041class MediaStreamObserver;
perkjf0dcfe22016-03-10 18:32:00 +010042class VideoRtpReceiver;
skvlad11a9cbf2016-10-07 11:53:05 -070043class RtcEventLog;
deadbeefab9b2d12015-10-14 11:33:11 -070044
Steve Anton75737c02017-11-06 10:37:17 -080045// PeerConnection is the implementation of the PeerConnection object as defined
46// by the PeerConnectionInterface API surface.
47// The class currently is solely responsible for the following:
48// - Managing the session state machine (signaling state).
49// - Creating and initializing lower-level objects, like PortAllocator and
50// BaseChannels.
51// - Owning and managing the life cycle of the RtpSender/RtpReceiver and track
52// objects.
53// - Tracking the current and pending local/remote session descriptions.
54// The class currently is jointly responsible for the following:
55// - Parsing and interpreting SDP.
56// - Generating offers and answers based on the current state.
57// - The ICE state machine.
58// - Generating stats.
Steve Anton2d8609c2018-01-23 16:38:46 -080059class PeerConnection : public PeerConnectionInternal,
Steve Anton75737c02017-11-06 10:37:17 -080060 public DataChannelProviderInterface,
Bjorn Mellem175aa2e2018-11-08 11:23:22 -080061 public DataChannelSink,
Zhi Huang365381f2018-04-13 16:44:34 -070062 public JsepTransportController::Observer,
Guido Urdaneta1ff16c82019-05-20 19:31:53 +020063 public RtpSenderBase::SetStreamsObserver,
Steve Antonad182762018-09-05 20:22:40 +000064 public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065 public sigslot::has_slots<> {
66 public:
Qingsi Wang1ba5dec2019-08-19 11:57:17 -070067 // A bit in the usage pattern is registered when its defining event occurs at
68 // least once.
Harald Alvestrand8ebba742018-05-31 14:00:34 +020069 enum class UsageEvent : int {
70 TURN_SERVER_ADDED = 0x01,
71 STUN_SERVER_ADDED = 0x02,
72 DATA_ADDED = 0x04,
73 AUDIO_ADDED = 0x08,
74 VIDEO_ADDED = 0x10,
Qingsi Wang1ba5dec2019-08-19 11:57:17 -070075 // |SetLocalDescription| returns successfully.
76 SET_LOCAL_DESCRIPTION_SUCCEEDED = 0x20,
77 // |SetRemoteDescription| returns successfully.
78 SET_REMOTE_DESCRIPTION_SUCCEEDED = 0x40,
79 // A local candidate (with type host, server-reflexive, or relay) is
80 // collected.
Harald Alvestrand8ebba742018-05-31 14:00:34 +020081 CANDIDATE_COLLECTED = 0x80,
Qingsi Wang1ba5dec2019-08-19 11:57:17 -070082 // A remote candidate is successfully added via |AddIceCandidate|.
83 ADD_ICE_CANDIDATE_SUCCEEDED = 0x100,
Harald Alvestrand8ebba742018-05-31 14:00:34 +020084 ICE_STATE_CONNECTED = 0x200,
Qingsi Wang7fc821d2018-07-12 12:54:53 -070085 CLOSE_CALLED = 0x400,
Qingsi Wang1ba5dec2019-08-19 11:57:17 -070086 // A local candidate with private IP is collected.
Harald Alvestrand056d8112018-07-16 19:18:58 +020087 PRIVATE_CANDIDATE_COLLECTED = 0x800,
Qingsi Wang1ba5dec2019-08-19 11:57:17 -070088 // A remote candidate with private IP is added, either via AddiceCandidate
89 // or from the remote description.
Jeroen de Borstaf242c82019-04-24 13:13:48 -070090 REMOTE_PRIVATE_CANDIDATE_ADDED = 0x1000,
Qingsi Wang1ba5dec2019-08-19 11:57:17 -070091 // A local mDNS candidate is collected.
Jeroen de Borstaf242c82019-04-24 13:13:48 -070092 MDNS_CANDIDATE_COLLECTED = 0x2000,
Qingsi Wang1ba5dec2019-08-19 11:57:17 -070093 // A remote mDNS candidate is added, either via AddIceCandidate or from the
94 // remote description.
Jeroen de Borstaf242c82019-04-24 13:13:48 -070095 REMOTE_MDNS_CANDIDATE_ADDED = 0x4000,
Qingsi Wang1ba5dec2019-08-19 11:57:17 -070096 // A local candidate with IPv6 address is collected.
97 IPV6_CANDIDATE_COLLECTED = 0x8000,
98 // A remote candidate with IPv6 address is added, either via AddIceCandidate
99 // or from the remote description.
100 REMOTE_IPV6_CANDIDATE_ADDED = 0x10000,
101 // A remote candidate (with type host, server-reflexive, or relay) is
102 // successfully added, either via AddIceCandidate or from the remote
103 // description.
104 REMOTE_CANDIDATE_ADDED = 0x20000,
105 MAX_VALUE = 0x40000,
Harald Alvestrand8ebba742018-05-31 14:00:34 +0200106 };
107
zhihuang38ede132017-06-15 12:52:32 -0700108 explicit PeerConnection(PeerConnectionFactory* factory,
109 std::unique_ptr<RtcEventLog> event_log,
110 std::unique_ptr<Call> call);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111
deadbeef653b8e02015-11-11 12:55:10 -0800112 bool Initialize(
113 const PeerConnectionInterface::RTCConfiguration& configuration,
Benjamin Wrightcab58882018-05-02 15:12:47 -0700114 PeerConnectionDependencies dependencies);
deadbeef653b8e02015-11-11 12:55:10 -0800115
deadbeefa67696b2015-09-29 11:56:26 -0700116 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
117 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
118 bool AddStream(MediaStreamInterface* local_stream) override;
119 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120
Steve Anton2d6c76a2018-01-05 17:10:52 -0800121 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
Steve Antonf9381f02017-12-14 10:23:57 -0800122 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Seth Hampson845e8782018-03-02 11:34:10 -0800123 const std::vector<std::string>& stream_ids) override;
deadbeefe1f9d832016-01-14 15:35:42 -0800124 bool RemoveTrack(RtpSenderInterface* sender) override;
Steve Anton24db5732018-07-23 10:27:33 -0700125 RTCError RemoveTrackNew(
126 rtc::scoped_refptr<RtpSenderInterface> sender) override;
deadbeefe1f9d832016-01-14 15:35:42 -0800127
Steve Anton9158ef62017-11-27 13:01:52 -0800128 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
129 rtc::scoped_refptr<MediaStreamTrackInterface> track) override;
130 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
131 rtc::scoped_refptr<MediaStreamTrackInterface> track,
132 const RtpTransceiverInit& init) override;
133 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
134 cricket::MediaType media_type) override;
135 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
136 cricket::MediaType media_type,
137 const RtpTransceiverInit& init) override;
138
Steve Anton8c0f7a72017-10-03 10:03:10 -0700139 // Gets the DTLS SSL certificate associated with the audio transport on the
140 // remote side. This will become populated once the DTLS connection with the
141 // peer has been completed, as indicated by the ICE connection state
142 // transitioning to kIceConnectionCompleted.
143 // Note that this will be removed once we implement RTCDtlsTransport which
144 // has standardized method for getting this information.
145 // See https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface
146 std::unique_ptr<rtc::SSLCertificate> GetRemoteAudioSSLCertificate();
147
Zhi Huang70b820f2018-01-27 14:16:15 -0800148 // Version of the above method that returns the full certificate chain.
149 std::unique_ptr<rtc::SSLCertChain> GetRemoteAudioSSLCertChain();
150
deadbeeffac06552015-11-25 11:26:01 -0800151 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800152 const std::string& kind,
153 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -0800154
deadbeef70ab1a12015-09-28 16:53:55 -0700155 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
156 const override;
157 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
158 const override;
Steve Anton9158ef62017-11-27 13:01:52 -0800159 std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers()
160 const override;
deadbeef70ab1a12015-09-28 16:53:55 -0700161
deadbeefa67696b2015-09-29 11:56:26 -0700162 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700164 const DataChannelInit* config) override;
Henrik Boström1df1bf82018-03-20 13:24:20 +0100165 // WARNING: LEGACY. See peerconnectioninterface.h
deadbeefa67696b2015-09-29 11:56:26 -0700166 bool GetStats(StatsObserver* observer,
167 webrtc::MediaStreamTrackInterface* track,
168 StatsOutputLevel level) override;
Henrik Boström1df1bf82018-03-20 13:24:20 +0100169 // Spec-complaint GetStats(). See peerconnectioninterface.h
hbos74e1a4f2016-09-15 23:33:01 -0700170 void GetStats(RTCStatsCollectorCallback* callback) override;
Henrik Boström1df1bf82018-03-20 13:24:20 +0100171 void GetStats(
172 rtc::scoped_refptr<RtpSenderInterface> selector,
173 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override;
174 void GetStats(
175 rtc::scoped_refptr<RtpReceiverInterface> selector,
176 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override;
Harald Alvestrand89061872018-01-02 14:08:34 +0100177 void ClearStatsCache() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178
deadbeefa67696b2015-09-29 11:56:26 -0700179 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180
deadbeefa67696b2015-09-29 11:56:26 -0700181 IceConnectionState ice_connection_state() override;
Jonas Olsson12046902018-12-06 11:25:14 +0100182 IceConnectionState standardized_ice_connection_state() override;
Jonas Olsson635474e2018-10-18 15:58:17 +0200183 PeerConnectionState peer_connection_state() override;
deadbeefa67696b2015-09-29 11:56:26 -0700184 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185
deadbeefa67696b2015-09-29 11:56:26 -0700186 const SessionDescriptionInterface* local_description() const override;
187 const SessionDescriptionInterface* remote_description() const override;
deadbeeffe4a8a42016-12-20 17:56:17 -0800188 const SessionDescriptionInterface* current_local_description() const override;
189 const SessionDescriptionInterface* current_remote_description()
190 const override;
191 const SessionDescriptionInterface* pending_local_description() const override;
192 const SessionDescriptionInterface* pending_remote_description()
193 const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194
Henrik Boström79b69802019-07-18 11:16:56 +0200195 void RestartIce() override;
196
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197 // JSEP01
deadbeefa67696b2015-09-29 11:56:26 -0700198 void CreateOffer(CreateSessionDescriptionObserver* observer,
199 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800200 void CreateAnswer(CreateSessionDescriptionObserver* observer,
201 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700202 void SetLocalDescription(SetSessionDescriptionObserver* observer,
203 SessionDescriptionInterface* desc) override;
Henrik Boströma4ecf552017-11-23 14:17:07 +0000204 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
205 SessionDescriptionInterface* desc) override;
Henrik Boström31638672017-11-23 17:48:32 +0100206 void SetRemoteDescription(
207 std::unique_ptr<SessionDescriptionInterface> desc,
208 rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer)
209 override;
deadbeef46c73892016-11-16 19:42:04 -0800210 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
deadbeefa67696b2015-09-29 11:56:26 -0700211 bool SetConfiguration(
deadbeef293e9262017-01-11 12:28:30 -0800212 const PeerConnectionInterface::RTCConfiguration& configuration,
213 RTCError* error) override;
214 bool SetConfiguration(
215 const PeerConnectionInterface::RTCConfiguration& configuration) override {
216 return SetConfiguration(configuration, nullptr);
217 }
deadbeefa67696b2015-09-29 11:56:26 -0700218 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700219 bool RemoveIceCandidates(
220 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221
Niels Möller0c4f7be2018-05-07 14:01:37 +0200222 RTCError SetBitrate(const BitrateSettings& bitrate) override;
zstein4b979802017-06-02 14:37:37 -0700223
henrika5f6bf242017-11-01 11:06:56 +0100224 void SetAudioPlayout(bool playout) override;
225 void SetAudioRecording(bool recording) override;
226
Harald Alvestrandad88c882018-11-28 16:47:46 +0100227 rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid(
228 const std::string& mid) override;
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100229 rtc::scoped_refptr<DtlsTransport> LookupDtlsTransportByMidInternal(
230 const std::string& mid);
Harald Alvestrandad88c882018-11-28 16:47:46 +0100231
Harald Alvestrandc85328f2019-02-28 07:51:00 +0100232 rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const override;
233
Bjorn Tereliusde939432017-11-20 17:38:14 +0100234 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,
235 int64_t output_period_ms) override;
Niels Möllerf00ca1a2019-05-10 11:33:12 +0200236 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override;
ivoc14d5dbe2016-07-04 07:06:55 -0700237 void StopRtcEventLog() override;
238
deadbeefa67696b2015-09-29 11:56:26 -0700239 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240
Steve Anton2d8609c2018-01-23 16:38:46 -0800241 // PeerConnectionInternal implementation.
Karl Wiberg4ae63472019-02-22 00:57:06 +0100242 rtc::Thread* network_thread() const final {
Steve Anton2d8609c2018-01-23 16:38:46 -0800243 return factory_->network_thread();
244 }
Karl Wiberg4ae63472019-02-22 00:57:06 +0100245 rtc::Thread* worker_thread() const final { return factory_->worker_thread(); }
246 rtc::Thread* signaling_thread() const final {
Steve Anton2d8609c2018-01-23 16:38:46 -0800247 return factory_->signaling_thread();
perkjd61bf802016-03-24 03:16:19 -0700248 }
deadbeefab9b2d12015-10-14 11:33:11 -0700249
Karl Wiberga58e1692019-03-26 13:33:43 +0100250 std::string session_id() const override {
251 RTC_DCHECK_RUN_ON(signaling_thread());
252 return session_id_;
253 }
Steve Anton75737c02017-11-06 10:37:17 -0800254
Steve Anton2d8609c2018-01-23 16:38:46 -0800255 bool initial_offerer() const override {
Karl Wiberg2cc368f2019-04-02 11:31:56 +0200256 RTC_DCHECK_RUN_ON(signaling_thread());
Zhi Huange830e682018-03-30 10:48:35 -0700257 return transport_controller_ && transport_controller_->initial_offerer();
Steve Anton2d8609c2018-01-23 16:38:46 -0800258 }
Steve Anton75737c02017-11-06 10:37:17 -0800259
Steve Anton2d8609c2018-01-23 16:38:46 -0800260 std::vector<
261 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 10:07:54 -0800262 GetTransceiversInternal() const override {
Karl Wiberga58e1692019-03-26 13:33:43 +0100263 RTC_DCHECK_RUN_ON(signaling_thread());
Steve Anton2d8609c2018-01-23 16:38:46 -0800264 return transceivers_;
265 }
266
Steve Anton2d8609c2018-01-23 16:38:46 -0800267 sigslot::signal1<DataChannel*>& SignalDataChannelCreated() override {
268 return SignalDataChannelCreated_;
269 }
270
271 cricket::RtpDataChannel* rtp_data_channel() const override {
Steve Anton75737c02017-11-06 10:37:17 -0800272 return rtp_data_channel_;
Steve Anton978b8762017-09-29 12:15:02 -0700273 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800274
Steve Antonbe5e2082018-01-24 15:29:17 -0800275 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels()
Steve Anton2d8609c2018-01-23 16:38:46 -0800276 const override {
Karl Wiberg85a4a932019-03-22 15:29:58 +0100277 RTC_DCHECK_RUN_ON(signaling_thread());
Steve Anton2d8609c2018-01-23 16:38:46 -0800278 return sctp_data_channels_;
279 }
280
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200281 absl::optional<std::string> sctp_content_name() const override {
Karl Wiberg2cc368f2019-04-02 11:31:56 +0200282 RTC_DCHECK_RUN_ON(signaling_thread());
Zhi Huange830e682018-03-30 10:48:35 -0700283 return sctp_mid_;
Steve Anton75737c02017-11-06 10:37:17 -0800284 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800285
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200286 absl::optional<std::string> sctp_transport_name() const override;
Steve Anton75737c02017-11-06 10:37:17 -0800287
Qingsi Wang72a43a12018-02-20 16:03:18 -0800288 cricket::CandidateStatsList GetPooledCandidateStats() const override;
Steve Anton5dfde182018-02-06 10:34:40 -0800289 std::map<std::string, std::string> GetTransportNamesByMid() const override;
290 std::map<std::string, cricket::TransportStats> GetTransportStatsByNames(
291 const std::set<std::string>& transport_names) override;
Steve Anton2d8609c2018-01-23 16:38:46 -0800292 Call::Stats GetCallStats() override;
Steve Anton75737c02017-11-06 10:37:17 -0800293
Steve Anton2d8609c2018-01-23 16:38:46 -0800294 bool GetLocalCertificate(
295 const std::string& transport_name,
296 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800297 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-23 16:38:46 -0800298 const std::string& transport_name) override;
299 bool IceRestartPending(const std::string& content_name) const override;
300 bool NeedsIceRestart(const std::string& content_name) const override;
301 bool GetSslRole(const std::string& content_name, rtc::SSLRole* role) override;
Steve Anton7464fca2018-01-19 11:10:37 -0800302
Harald Alvestrand19793842018-06-25 12:03:50 +0200303 void ReturnHistogramVeryQuicklyForTesting() {
Karl Wibergf73f7d62019-04-08 15:36:53 +0200304 RTC_DCHECK_RUN_ON(signaling_thread());
Harald Alvestrand19793842018-06-25 12:03:50 +0200305 return_histogram_very_quickly_ = true;
306 }
Harald Alvestrand7a1c7f72018-08-01 10:50:16 +0200307 void RequestUsagePatternReportForTesting();
Harald Alvestrand19793842018-06-25 12:03:50 +0200308
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700310 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311
312 private:
Henrik Boström31638672017-11-23 17:48:32 +0100313 class SetRemoteDescriptionObserverAdapter;
314 friend class SetRemoteDescriptionObserverAdapter;
Henrik Boström79b69802019-07-18 11:16:56 +0200315 // Represents the [[LocalIceCredentialsToReplace]] internal slot in the spec.
316 // It makes the next CreateOffer() produce new ICE credentials even if
317 // RTCOfferAnswerOptions::ice_restart is false.
318 // https://w3c.github.io/webrtc-pc/#dfn-localufragstoreplace
319 // TODO(hbos): When JsepTransportController/JsepTransport supports rollback,
320 // move this type of logic to JsepTransportController/JsepTransport.
321 class LocalIceCredentialsToReplace;
Henrik Boström31638672017-11-23 17:48:32 +0100322
Steve Anton4171afb2017-11-20 10:20:22 -0800323 struct RtpSenderInfo {
324 RtpSenderInfo() : first_ssrc(0) {}
Seth Hampson845e8782018-03-02 11:34:10 -0800325 RtpSenderInfo(const std::string& stream_id,
Steve Anton4171afb2017-11-20 10:20:22 -0800326 const std::string sender_id,
327 uint32_t ssrc)
Seth Hampson845e8782018-03-02 11:34:10 -0800328 : stream_id(stream_id), sender_id(sender_id), first_ssrc(ssrc) {}
Steve Anton4171afb2017-11-20 10:20:22 -0800329 bool operator==(const RtpSenderInfo& other) {
Seth Hampson845e8782018-03-02 11:34:10 -0800330 return this->stream_id == other.stream_id &&
Steve Anton4171afb2017-11-20 10:20:22 -0800331 this->sender_id == other.sender_id &&
332 this->first_ssrc == other.first_ssrc;
deadbeefbda7e0b2015-12-08 17:13:40 -0800333 }
Seth Hampson845e8782018-03-02 11:34:10 -0800334 std::string stream_id;
Steve Anton4171afb2017-11-20 10:20:22 -0800335 std::string sender_id;
336 // An RtpSender can have many SSRCs. The first one is used as a sort of ID
337 // for communicating with the lower layers.
338 uint32_t first_ssrc;
deadbeefab9b2d12015-10-14 11:33:11 -0700339 };
deadbeefab9b2d12015-10-14 11:33:11 -0700340
Bjorn A Mellem5985a042019-06-28 14:19:38 -0700341 // Field-trial based configuration for datagram transport.
342 struct DatagramTransportConfig {
343 explicit DatagramTransportConfig(const std::string& field_trial)
344 : enabled("enabled", true), default_value("default_value", false) {
345 ParseFieldTrial({&enabled, &default_value}, field_trial);
346 }
347
348 // Whether datagram transport support is enabled at all. Defaults to true,
349 // allowing datagram transport to be used if (a) the application provides a
350 // factory for it and (b) the configuration specifies its use. This flag
351 // provides a kill-switch to force-disable datagram transport across all
352 // applications, without code changes.
353 FieldTrialFlag enabled;
354
355 // Whether the datagram transport is enabled or disabled by default.
356 // Defaults to false, meaning that applications must configure use of
357 // datagram transport through RTCConfiguration. If set to true,
358 // applications will use the datagram transport by default (but may still
359 // explicitly configure themselves not to use it through RTCConfiguration).
360 FieldTrialFlag default_value;
361 };
362
Steve Antonad182762018-09-05 20:22:40 +0000363 // Implements MessageHandler.
364 void OnMessage(rtc::Message* msg) override;
365
Steve Antonafb0bb72018-02-20 11:35:37 -0800366 // Plan B helpers for getting the voice/video media channels for the single
367 // audio/video transceiver, if it exists.
Karl Wiberg5966c502019-02-21 23:55:09 +0100368 cricket::VoiceMediaChannel* voice_media_channel() const
369 RTC_RUN_ON(signaling_thread());
370 cricket::VideoMediaChannel* video_media_channel() const
371 RTC_RUN_ON(signaling_thread());
Steve Anton60776752018-01-10 11:51:34 -0800372
Steve Anton4171afb2017-11-20 10:20:22 -0800373 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100374 GetSendersInternal() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800375 std::vector<
376 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100377 GetReceiversInternal() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800378
379 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100380 GetAudioTransceiver() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800381 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100382 GetVideoTransceiver() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800383
Steve Antonafb0bb72018-02-20 11:35:37 -0800384 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100385 GetFirstAudioTransceiver() const RTC_RUN_ON(signaling_thread());
Steve Antonafb0bb72018-02-20 11:35:37 -0800386
deadbeefab9b2d12015-10-14 11:33:11 -0700387 void CreateAudioReceiver(MediaStreamInterface* stream,
Karl Wiberg744310f2019-02-14 10:18:56 +0100388 const RtpSenderInfo& remote_sender_info)
389 RTC_RUN_ON(signaling_thread());
perkjf0dcfe22016-03-10 18:32:00 +0100390
deadbeefab9b2d12015-10-14 11:33:11 -0700391 void CreateVideoReceiver(MediaStreamInterface* stream,
Karl Wiberg744310f2019-02-14 10:18:56 +0100392 const RtpSenderInfo& remote_sender_info)
393 RTC_RUN_ON(signaling_thread());
Henrik Boström933d8b02017-10-10 10:05:16 -0700394 rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver(
Karl Wiberg5966c502019-02-21 23:55:09 +0100395 const RtpSenderInfo& remote_sender_info) RTC_RUN_ON(signaling_thread());
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700396
397 // May be called either by AddStream/RemoveStream, or when a track is
398 // added/removed from a stream previously added via AddStream.
Karl Wiberg5966c502019-02-21 23:55:09 +0100399 void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream)
400 RTC_RUN_ON(signaling_thread());
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700401 void RemoveAudioTrack(AudioTrackInterface* track,
Karl Wiberg5966c502019-02-21 23:55:09 +0100402 MediaStreamInterface* stream)
403 RTC_RUN_ON(signaling_thread());
404 void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream)
405 RTC_RUN_ON(signaling_thread());
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700406 void RemoveVideoTrack(VideoTrackInterface* track,
Karl Wiberg5966c502019-02-21 23:55:09 +0100407 MediaStreamInterface* stream)
408 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409
Steve Antonf9381f02017-12-14 10:23:57 -0800410 // AddTrack implementation when Unified Plan is specified.
411 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackUnifiedPlan(
412 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Karl Wiberga58e1692019-03-26 13:33:43 +0100413 const std::vector<std::string>& stream_ids)
414 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800415 // AddTrack implementation when Plan B is specified.
416 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackPlanB(
417 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Karl Wiberg5966c502019-02-21 23:55:09 +0100418 const std::vector<std::string>& stream_ids)
419 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800420
421 // Returns the first RtpTransceiver suitable for a newly added track, if such
422 // transceiver is available.
423 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
424 FindFirstTransceiverForAddedTrack(
Karl Wiberga58e1692019-03-26 13:33:43 +0100425 rtc::scoped_refptr<MediaStreamTrackInterface> track)
426 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800427
Steve Antonf9381f02017-12-14 10:23:57 -0800428 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100429 FindTransceiverBySender(rtc::scoped_refptr<RtpSenderInterface> sender)
430 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800431
Steve Anton22da89f2018-01-25 13:58:07 -0800432 // Internal implementation for AddTransceiver family of methods. If
433 // |fire_callback| is set, fires OnRenegotiationNeeded callback if successful.
Steve Anton9158ef62017-11-27 13:01:52 -0800434 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
435 cricket::MediaType media_type,
436 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Steve Anton22da89f2018-01-25 13:58:07 -0800437 const RtpTransceiverInit& init,
Karl Wiberg744310f2019-02-14 10:18:56 +0100438 bool fire_callback = true) RTC_RUN_ON(signaling_thread());
Steve Anton9158ef62017-11-27 13:01:52 -0800439
Steve Anton02ee47c2018-01-10 16:26:06 -0800440 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
441 CreateSender(cricket::MediaType media_type,
Steve Anton111fdfd2018-06-25 13:03:36 -0700442 const std::string& id,
Steve Anton02ee47c2018-01-10 16:26:06 -0800443 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Florent Castelli892acf02018-10-01 22:47:20 +0200444 const std::vector<std::string>& stream_ids,
445 const std::vector<RtpEncodingParameters>& send_encodings);
Steve Anton02ee47c2018-01-10 16:26:06 -0800446
447 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
448 CreateReceiver(cricket::MediaType media_type, const std::string& receiver_id);
449
Steve Antonf9381f02017-12-14 10:23:57 -0800450 // Create a new RtpTransceiver of the given type and add it to the list of
451 // transceivers.
452 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Steve Anton02ee47c2018-01-10 16:26:06 -0800453 CreateAndAddTransceiver(
454 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender,
455 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100456 receiver) RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800457
Karl Wiberg744310f2019-02-14 10:18:56 +0100458 void SetIceConnectionState(IceConnectionState new_state)
459 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 15:58:17 +0200460 void SetStandardizedIceConnectionState(
Karl Wiberg744310f2019-02-14 10:18:56 +0100461 PeerConnectionInterface::IceConnectionState new_state)
462 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 15:58:17 +0200463 void SetConnectionState(
Karl Wiberg744310f2019-02-14 10:18:56 +0100464 PeerConnectionInterface::PeerConnectionState new_state)
465 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 15:58:17 +0200466
Eldar Relloda13ea22019-06-01 12:23:43 +0300467 // Called any time the IceGatheringState changes.
Karl Wiberg744310f2019-02-14 10:18:56 +0100468 void OnIceGatheringChange(IceGatheringState new_state)
469 RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 10:21:57 -0800470 // New ICE candidate has been gathered.
Karl Wiberg744310f2019-02-14 10:18:56 +0100471 void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate)
472 RTC_RUN_ON(signaling_thread());
Eldar Relloda13ea22019-06-01 12:23:43 +0300473 // Gathering of an ICE candidate failed.
474 void OnIceCandidateError(const std::string& host_candidate,
475 const std::string& url,
476 int error_code,
477 const std::string& error_text)
478 RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 10:21:57 -0800479 // Some local ICE candidates have been removed.
Karl Wiberg744310f2019-02-14 10:18:56 +0100480 void OnIceCandidatesRemoved(const std::vector<cricket::Candidate>& candidates)
481 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482
Alex Drake00c7ecf2019-08-06 10:54:47 -0700483 void OnSelectedCandidatePairChanged(
484 const cricket::CandidatePairChangeEvent& event)
485 RTC_RUN_ON(signaling_thread());
486
Steve Antonba818672017-11-06 10:21:57 -0800487 // Update the state, signaling if necessary.
Karl Wiberg744310f2019-02-14 10:18:56 +0100488 void ChangeSignalingState(SignalingState signaling_state)
489 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490
deadbeefeb459812015-12-15 19:24:43 -0800491 // Signals from MediaStreamObserver.
492 void OnAudioTrackAdded(AudioTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100493 MediaStreamInterface* stream)
494 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800495 void OnAudioTrackRemoved(AudioTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100496 MediaStreamInterface* stream)
497 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800498 void OnVideoTrackAdded(VideoTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100499 MediaStreamInterface* stream)
500 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800501 void OnVideoTrackRemoved(VideoTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100502 MediaStreamInterface* stream)
503 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800504
Henrik Boström31638672017-11-23 17:48:32 +0100505 void PostSetSessionDescriptionSuccess(
506 SetSessionDescriptionObserver* observer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000507 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
Steve Antonad182762018-09-05 20:22:40 +0000508 RTCError&& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700509 void PostCreateSessionDescriptionFailure(
510 CreateSessionDescriptionObserver* observer,
Harald Alvestrand5081c0c2018-03-09 15:18:03 +0100511 RTCError error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512
Steve Anton8a006912017-12-04 15:25:56 -0800513 // Synchronous implementations of SetLocalDescription/SetRemoteDescription
514 // that return an RTCError instead of invoking a callback.
515 RTCError ApplyLocalDescription(
516 std::unique_ptr<SessionDescriptionInterface> desc);
517 RTCError ApplyRemoteDescription(
518 std::unique_ptr<SessionDescriptionInterface> desc);
519
Steve Antondcc3c022017-12-22 16:02:54 -0800520 // Updates the local RtpTransceivers according to the JSEP rules. Called as
521 // part of setting the local/remote description.
522 RTCError UpdateTransceiversAndDataChannels(
523 cricket::ContentSource source,
Seth Hampsonae8a90a2018-02-13 15:33:48 -0800524 const SessionDescriptionInterface& new_session,
525 const SessionDescriptionInterface* old_local_description,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100526 const SessionDescriptionInterface* old_remote_description)
527 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800528
529 // Either creates or destroys the transceiver's BaseChannel according to the
530 // given media section.
531 RTCError UpdateTransceiverChannel(
532 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
533 transceiver,
534 const cricket::ContentInfo& content,
Karl Wiberg5966c502019-02-21 23:55:09 +0100535 const cricket::ContentGroup* bundle_group) RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800536
Steve Antonfa2260d2017-12-28 16:38:23 -0800537 // Either creates or destroys the local data channel according to the given
538 // media section.
539 RTCError UpdateDataChannel(cricket::ContentSource source,
540 const cricket::ContentInfo& content,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100541 const cricket::ContentGroup* bundle_group)
542 RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800543
Steve Antondcc3c022017-12-22 16:02:54 -0800544 // Associate the given transceiver according to the JSEP rules.
545 RTCErrorOr<
546 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
547 AssociateTransceiver(cricket::ContentSource source,
Seth Hampsonae8a90a2018-02-13 15:33:48 -0800548 SdpType type,
Steve Antondcc3c022017-12-22 16:02:54 -0800549 size_t mline_index,
550 const cricket::ContentInfo& content,
Seth Hampsonae8a90a2018-02-13 15:33:48 -0800551 const cricket::ContentInfo* old_local_content,
Karl Wiberg5966c502019-02-21 23:55:09 +0100552 const cricket::ContentInfo* old_remote_content)
553 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800554
555 // Returns the RtpTransceiver, if found, that is associated to the given MID.
556 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100557 GetAssociatedTransceiver(const std::string& mid) const
558 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800559
560 // Returns the RtpTransceiver, if found, that was assigned to the given mline
561 // index in CreateOffer.
562 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100563 GetTransceiverByMLineIndex(size_t mline_index) const
564 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800565
566 // Returns an RtpTransciever, if available, that can be used to receive the
567 // given media type according to JSEP rules.
568 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100569 FindAvailableTransceiverToReceive(cricket::MediaType media_type) const
570 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800571
Steve Antoned10bd92017-12-05 10:52:59 -0800572 // Returns the media section in the given session description that is
573 // associated with the RtpTransceiver. Returns null if none found or this
574 // RtpTransceiver is not associated. Logic varies depending on the
575 // SdpSemantics specified in the configuration.
576 const cricket::ContentInfo* FindMediaSectionForTransceiver(
577 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
578 transceiver,
Karl Wiberg5966c502019-02-21 23:55:09 +0100579 const SessionDescriptionInterface* sdesc) const
580 RTC_RUN_ON(signaling_thread());
Steve Antoned10bd92017-12-05 10:52:59 -0800581
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100582 // Runs the algorithm **set the associated remote streams** specified in
583 // https://w3c.github.io/webrtc-pc/#set-associated-remote-streams.
584 void SetAssociatedRemoteStreams(
585 rtc::scoped_refptr<RtpReceiverInternal> receiver,
586 const std::vector<std::string>& stream_ids,
587 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* added_streams,
Karl Wiberg1e1e1022019-03-22 14:27:22 +0100588 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams)
589 RTC_RUN_ON(signaling_thread());
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100590
Steve Anton0f5400a2018-07-17 14:25:36 -0700591 // Runs the algorithm **process the removal of a remote track** specified in
592 // the WebRTC specification.
593 // This method will update the following lists:
594 // |remove_list| is the list of transceivers for which the receiving track is
595 // being removed.
596 // |removed_streams| is the list of streams which no longer have a receiving
597 // track so should be removed.
598 // https://w3c.github.io/webrtc-pc/#process-remote-track-removal
599 void ProcessRemovalOfRemoteTrack(
600 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
601 transceiver,
602 std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>* remove_list,
Karl Wiberg1e1e1022019-03-22 14:27:22 +0100603 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams)
604 RTC_RUN_ON(signaling_thread());
Steve Anton0f5400a2018-07-17 14:25:36 -0700605
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100606 void RemoveRemoteStreamsIfEmpty(
607 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&
608 remote_streams,
Karl Wiberg1e1e1022019-03-22 14:27:22 +0100609 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams)
610 RTC_RUN_ON(signaling_thread());
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100611
Steve Anton52d86772018-02-20 15:48:12 -0800612 void OnNegotiationNeeded();
613
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 bool IsClosed() const {
Karl Wiberg8d2e2282019-02-17 13:00:07 +0100615 RTC_DCHECK_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 return signaling_state_ == PeerConnectionInterface::kClosed;
617 }
618
deadbeefab9b2d12015-10-14 11:33:11 -0700619 // Returns a MediaSessionOptions struct with options decided by |options|,
620 // the local MediaStreams and DataChannels.
Steve Antondcc3c022017-12-22 16:02:54 -0800621 void GetOptionsForOffer(const PeerConnectionInterface::RTCOfferAnswerOptions&
622 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100623 cricket::MediaSessionOptions* session_options)
624 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800625 void GetOptionsForPlanBOffer(
626 const PeerConnectionInterface::RTCOfferAnswerOptions&
627 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100628 cricket::MediaSessionOptions* session_options)
629 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800630 void GetOptionsForUnifiedPlanOffer(
631 const PeerConnectionInterface::RTCOfferAnswerOptions&
632 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100633 cricket::MediaSessionOptions* session_options)
634 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700635
Karl Wiberg5966c502019-02-21 23:55:09 +0100636 RTCError HandleLegacyOfferOptions(const RTCOfferAnswerOptions& options)
637 RTC_RUN_ON(signaling_thread());
Steve Anton22da89f2018-01-25 13:58:07 -0800638 void RemoveRecvDirectionFromReceivingTransceiversOfType(
Karl Wiberga58e1692019-03-26 13:33:43 +0100639 cricket::MediaType media_type) RTC_RUN_ON(signaling_thread());
Steve Anton22da89f2018-01-25 13:58:07 -0800640 void AddUpToOneReceivingTransceiverOfType(cricket::MediaType media_type);
641 std::vector<
642 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100643 GetReceivingTransceiversOfType(cricket::MediaType media_type)
644 RTC_RUN_ON(signaling_thread());
Steve Anton22da89f2018-01-25 13:58:07 -0800645
deadbeefab9b2d12015-10-14 11:33:11 -0700646 // Returns a MediaSessionOptions struct with options decided by
647 // |constraints|, the local MediaStreams and DataChannels.
Steve Antondcc3c022017-12-22 16:02:54 -0800648 void GetOptionsForAnswer(const RTCOfferAnswerOptions& offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100649 cricket::MediaSessionOptions* session_options)
650 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800651 void GetOptionsForPlanBAnswer(
652 const PeerConnectionInterface::RTCOfferAnswerOptions&
653 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100654 cricket::MediaSessionOptions* session_options)
655 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800656 void GetOptionsForUnifiedPlanAnswer(
657 const PeerConnectionInterface::RTCOfferAnswerOptions&
658 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100659 cricket::MediaSessionOptions* session_options)
660 RTC_RUN_ON(signaling_thread());
htaa2a49d92016-03-04 02:51:39 -0800661
zhihuang1c378ed2017-08-17 14:10:50 -0700662 // Generates MediaDescriptionOptions for the |session_opts| based on existing
663 // local description or remote description.
664 void GenerateMediaDescriptionOptions(
665 const SessionDescriptionInterface* session_desc,
Steve Anton1d03a752017-11-27 14:30:09 -0800666 RtpTransceiverDirection audio_direction,
667 RtpTransceiverDirection video_direction,
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200668 absl::optional<size_t>* audio_index,
669 absl::optional<size_t>* video_index,
670 absl::optional<size_t>* data_index,
Karl Wiberg85a4a932019-03-22 15:29:58 +0100671 cricket::MediaSessionOptions* session_options)
672 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700673
Steve Antonfa2260d2017-12-28 16:38:23 -0800674 // Generates the active MediaDescriptionOptions for the local data channel
675 // given the specified MID.
676 cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForActiveData(
Karl Wiberg85a4a932019-03-22 15:29:58 +0100677 const std::string& mid) const RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800678
679 // Generates the rejected MediaDescriptionOptions for the local data channel
680 // given the specified MID.
681 cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForRejectedData(
Karl Wiberg85a4a932019-03-22 15:29:58 +0100682 const std::string& mid) const RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800683
684 // Returns the MID for the data section associated with either the
685 // RtpDataChannel or SCTP data channel, if it has been set. If no data
686 // channels are configured this will return nullopt.
Karl Wiberg2cc368f2019-04-02 11:31:56 +0200687 absl::optional<std::string> GetDataMid() const RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800688
Steve Anton4171afb2017-11-20 10:20:22 -0800689 // Remove all local and remote senders of type |media_type|.
deadbeeffaac4972015-11-12 15:33:07 -0800690 // Called when a media type is rejected (m-line set to port 0).
Karl Wiberg744310f2019-02-14 10:18:56 +0100691 void RemoveSenders(cricket::MediaType media_type)
692 RTC_RUN_ON(signaling_thread());
deadbeeffaac4972015-11-12 15:33:07 -0800693
deadbeefbda7e0b2015-12-08 17:13:40 -0800694 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
695 // and existing MediaStreamTracks are removed if there is no corresponding
696 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
697 // is created if it doesn't exist; if false, it's removed if it exists.
698 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700699 // If a new MediaStream is created it is added to |new_streams|.
Steve Anton4171afb2017-11-20 10:20:22 -0800700 void UpdateRemoteSendersList(
deadbeefab9b2d12015-10-14 11:33:11 -0700701 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800702 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700703 cricket::MediaType media_type,
Karl Wiberg744310f2019-02-14 10:18:56 +0100704 StreamCollection* new_streams) RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700705
Steve Anton4171afb2017-11-20 10:20:22 -0800706 // Triggered when a remote sender has been seen for the first time in a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700707 // session description. It creates a remote MediaStreamTrackInterface
708 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800709 void OnRemoteSenderAdded(const RtpSenderInfo& sender_info,
Karl Wiberg744310f2019-02-14 10:18:56 +0100710 cricket::MediaType media_type)
711 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700712
Steve Anton4171afb2017-11-20 10:20:22 -0800713 // Triggered when a remote sender has been removed from a remote session
714 // description. It removes the remote sender with id |sender_id| from a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700715 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800716 void OnRemoteSenderRemoved(const RtpSenderInfo& sender_info,
Karl Wiberg744310f2019-02-14 10:18:56 +0100717 cricket::MediaType media_type)
718 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700719
720 // Finds remote MediaStreams without any tracks and removes them from
721 // |remote_streams_| and notifies the observer that the MediaStreams no longer
722 // exist.
Karl Wiberg744310f2019-02-14 10:18:56 +0100723 void UpdateEndedRemoteMediaStreams() RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700724
deadbeefab9b2d12015-10-14 11:33:11 -0700725 // Loops through the vector of |streams| and finds added and removed
726 // StreamParams since last time this method was called.
Steve Anton4171afb2017-11-20 10:20:22 -0800727 // For each new or removed StreamParam, OnLocalSenderSeen or
728 // OnLocalSenderRemoved is invoked.
729 void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams,
Karl Wiberg5966c502019-02-21 23:55:09 +0100730 cricket::MediaType media_type)
731 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700732
Steve Anton4171afb2017-11-20 10:20:22 -0800733 // Triggered when a local sender has been seen for the first time in a local
deadbeefab9b2d12015-10-14 11:33:11 -0700734 // session description.
735 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
736 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
737 // in a MediaStream in |local_streams_|
Steve Anton4171afb2017-11-20 10:20:22 -0800738 void OnLocalSenderAdded(const RtpSenderInfo& sender_info,
Karl Wiberg5966c502019-02-21 23:55:09 +0100739 cricket::MediaType media_type)
740 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700741
Steve Anton4171afb2017-11-20 10:20:22 -0800742 // Triggered when a local sender has been removed from a local session
deadbeefab9b2d12015-10-14 11:33:11 -0700743 // description.
744 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
745 // has been removed from the local SessionDescription and the stream can be
746 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
Steve Anton4171afb2017-11-20 10:20:22 -0800747 void OnLocalSenderRemoved(const RtpSenderInfo& sender_info,
Karl Wiberga58e1692019-03-26 13:33:43 +0100748 cricket::MediaType media_type)
749 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700750
Karl Wiberg85a4a932019-03-22 15:29:58 +0100751 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams)
752 RTC_RUN_ON(signaling_thread());
Karl Wiberg106d92d2019-02-14 10:17:47 +0100753 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams)
754 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700755 void UpdateClosingRtpDataChannels(
756 const std::vector<std::string>& active_channels,
Karl Wiberg85a4a932019-03-22 15:29:58 +0100757 bool is_local_update) RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700758 void CreateRemoteRtpDataChannel(const std::string& label,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100759 uint32_t remote_ssrc)
760 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700761
762 // Creates channel and adds it to the collection of DataChannels that will
763 // be offered in a SessionDescription.
764 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
765 const std::string& label,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100766 const InternalDataChannelInit* config) RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700767
768 // Checks if any data channel has been added.
Karl Wiberg85a4a932019-03-22 15:29:58 +0100769 bool HasDataChannels() const RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700770
Karl Wiberg85a4a932019-03-22 15:29:58 +0100771 void AllocateSctpSids(rtc::SSLRole role) RTC_RUN_ON(signaling_thread());
772 void OnSctpDataChannelClosed(DataChannel* channel)
773 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700774
Karl Wiberg85a4a932019-03-22 15:29:58 +0100775 void OnDataChannelDestroyed() RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 10:21:57 -0800776 // Called when a valid data channel OPEN message is received.
deadbeefab9b2d12015-10-14 11:33:11 -0700777 void OnDataChannelOpenMessage(const std::string& label,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100778 const InternalDataChannelInit& config)
779 RTC_RUN_ON(signaling_thread());
780
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800781 // Parses and handles open messages. Returns true if the message is an open
782 // message, false otherwise.
783 bool HandleOpenMessage_s(const cricket::ReceiveDataParams& params,
784 const rtc::CopyOnWriteBuffer& buffer)
785 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700786
Steve Anton4171afb2017-11-20 10:20:22 -0800787 // Returns true if the PeerConnection is configured to use Unified Plan
788 // semantics for creating offers/answers and setting local/remote
789 // descriptions. If this is true the RtpTransceiver API will also be available
790 // to the user. If this is false, Plan B semantics are assumed.
Steve Anton79e79602017-11-20 10:25:56 -0800791 // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once
792 // sufficient time has passed.
Karl Wiberg5966c502019-02-21 23:55:09 +0100793 bool IsUnifiedPlan() const RTC_RUN_ON(signaling_thread()) {
Steve Anton79e79602017-11-20 10:25:56 -0800794 return configuration_.sdp_semantics == SdpSemantics::kUnifiedPlan;
795 }
Steve Anton4171afb2017-11-20 10:20:22 -0800796
Steve Anton06817cd2018-12-18 15:55:30 -0800797 // The offer/answer machinery assumes the media section MID is present and
798 // unique. To support legacy end points that do not supply a=mid lines, this
799 // method will modify the session description to add MIDs generated according
800 // to the SDP semantics.
Karl Wiberg5966c502019-02-21 23:55:09 +0100801 void FillInMissingRemoteMids(cricket::SessionDescription* remote_description)
802 RTC_RUN_ON(signaling_thread());
Steve Anton06817cd2018-12-18 15:55:30 -0800803
Steve Anton4171afb2017-11-20 10:20:22 -0800804 // Is there an RtpSender of the given type?
Karl Wiberg5966c502019-02-21 23:55:09 +0100805 bool HasRtpSender(cricket::MediaType type) const
806 RTC_RUN_ON(signaling_thread());
deadbeeffac06552015-11-25 11:26:01 -0800807
Steve Anton4171afb2017-11-20 10:20:22 -0800808 // Return the RtpSender with the given track attached.
809 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100810 FindSenderForTrack(MediaStreamTrackInterface* track) const
811 RTC_RUN_ON(signaling_thread());
deadbeef70ab1a12015-09-28 16:53:55 -0700812
Steve Anton4171afb2017-11-20 10:20:22 -0800813 // Return the RtpSender with the given id, or null if none exists.
814 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100815 FindSenderById(const std::string& sender_id) const
816 RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800817
818 // Return the RtpReceiver with the given id, or null if none exists.
819 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100820 FindReceiverById(const std::string& receiver_id) const
821 RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800822
823 std::vector<RtpSenderInfo>* GetRemoteSenderInfos(
824 cricket::MediaType media_type);
825 std::vector<RtpSenderInfo>* GetLocalSenderInfos(
826 cricket::MediaType media_type);
827 const RtpSenderInfo* FindSenderInfo(const std::vector<RtpSenderInfo>& infos,
Emircan Uysalerbc609ea2018-03-27 21:57:18 +0000828 const std::string& stream_id,
Steve Anton4171afb2017-11-20 10:20:22 -0800829 const std::string sender_id) const;
deadbeefab9b2d12015-10-14 11:33:11 -0700830
831 // Returns the specified SCTP DataChannel in sctp_data_channels_,
832 // or nullptr if not found.
Karl Wiberg85a4a932019-03-22 15:29:58 +0100833 DataChannel* FindDataChannelBySid(int sid) const
834 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700835
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700836 // Called when first configuring the port allocator.
Karl Wibergfb3be392019-03-22 14:13:22 +0100837 struct InitializePortAllocatorResult {
838 bool enable_ipv6;
839 };
840 InitializePortAllocatorResult InitializePortAllocator_n(
Harald Alvestrandb2a74782018-06-28 13:54:07 +0200841 const cricket::ServerAddresses& stun_servers,
842 const std::vector<cricket::RelayServerConfig>& turn_servers,
843 const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 12:28:30 -0800844 // Called when SetConfiguration is called to apply the supported subset
845 // of the configuration on the network thread.
846 bool ReconfigurePortAllocator_n(
847 const cricket::ServerAddresses& stun_servers,
848 const std::vector<cricket::RelayServerConfig>& turn_servers,
849 IceTransportsType type,
850 int candidate_pool_size,
Jonas Orelandbdcee282017-10-10 14:01:40 +0200851 bool prune_turn_ports,
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800852 webrtc::TurnCustomizer* turn_customizer,
Karl Wiberg739506e2019-04-03 11:37:28 +0200853 absl::optional<int> stun_candidate_keepalive_interval,
854 bool have_local_description);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700855
Elad Alon99c3fe52017-10-13 16:29:40 +0200856 // Starts output of an RTC event log to the given output object.
ivoc14d5dbe2016-07-04 07:06:55 -0700857 // This function should only be called from the worker thread.
Bjorn Tereliusde939432017-11-20 17:38:14 +0100858 bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output,
859 int64_t output_period_ms);
Elad Alon99c3fe52017-10-13 16:29:40 +0200860
Elad Alonacb24172017-10-06 14:32:13 +0200861 // Stops recording an RTC event log.
ivoc14d5dbe2016-07-04 07:06:55 -0700862 // This function should only be called from the worker thread.
863 void StopRtcEventLog_w();
864
Steve Anton038834f2017-07-14 15:59:59 -0700865 // Ensures the configuration doesn't have any parameters with invalid values,
866 // or values that conflict with other parameters.
867 //
868 // Returns RTCError::OK() if there are no issues.
869 RTCError ValidateConfiguration(const RTCConfiguration& config) const;
870
Steve Antonba818672017-11-06 10:21:57 -0800871 cricket::ChannelManager* channel_manager() const;
Steve Antonba818672017-11-06 10:21:57 -0800872
Steve Antonf8470812017-12-04 10:46:21 -0800873 enum class SessionError {
874 kNone, // No error.
875 kContent, // Error in BaseChannel SetLocalContent/SetRemoteContent.
876 kTransport, // Error from the underlying transport.
877 };
878
Steve Anton75737c02017-11-06 10:37:17 -0800879 // Returns the last error in the session. See the enum above for details.
Karl Wiberga58e1692019-03-26 13:33:43 +0100880 SessionError session_error() const RTC_RUN_ON(signaling_thread()) {
881 return session_error_;
882 }
Steve Antonf8470812017-12-04 10:46:21 -0800883 const std::string& session_error_desc() const { return session_error_desc_; }
Steve Anton75737c02017-11-06 10:37:17 -0800884
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800885 cricket::ChannelInterface* GetChannel(const std::string& content_name);
Steve Anton75737c02017-11-06 10:37:17 -0800886
887 // Get current SSL role used by SCTP's underlying transport.
888 bool GetSctpSslRole(rtc::SSLRole* role);
889
Steve Anton75737c02017-11-06 10:37:17 -0800890 cricket::IceConfig ParseIceConfig(
891 const PeerConnectionInterface::RTCConfiguration& config) const;
892
Steve Anton75737c02017-11-06 10:37:17 -0800893 // Implements DataChannelProviderInterface.
894 bool SendData(const cricket::SendDataParams& params,
895 const rtc::CopyOnWriteBuffer& payload,
896 cricket::SendDataResult* result) override;
897 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override;
898 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override;
899 void AddSctpDataStream(int sid) override;
900 void RemoveSctpDataStream(int sid) override;
901 bool ReadyToSendData() const override;
902
903 cricket::DataChannelType data_channel_type() const;
904
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800905 // Implements DataChannelSink.
906 void OnDataReceived(int channel_id,
907 DataMessageType type,
908 const rtc::CopyOnWriteBuffer& buffer) override;
909 void OnChannelClosing(int channel_id) override;
910 void OnChannelClosed(int channel_id) override;
911
Steve Anton75737c02017-11-06 10:37:17 -0800912 // Called when an RTCCertificate is generated or retrieved by
913 // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription.
914 void OnCertificateReady(
915 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
916 void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp);
917
Steve Anton75737c02017-11-06 10:37:17 -0800918 // Non-const versions of local_description()/remote_description(), for use
919 // internally.
Karl Wiberg739506e2019-04-03 11:37:28 +0200920 SessionDescriptionInterface* mutable_local_description()
921 RTC_RUN_ON(signaling_thread()) {
Steve Anton75737c02017-11-06 10:37:17 -0800922 return pending_local_description_ ? pending_local_description_.get()
923 : current_local_description_.get();
924 }
Karl Wiberg739506e2019-04-03 11:37:28 +0200925 SessionDescriptionInterface* mutable_remote_description()
926 RTC_RUN_ON(signaling_thread()) {
Steve Anton75737c02017-11-06 10:37:17 -0800927 return pending_remote_description_ ? pending_remote_description_.get()
928 : current_remote_description_.get();
929 }
930
931 // Updates the error state, signaling if necessary.
Steve Antonf8470812017-12-04 10:46:21 -0800932 void SetSessionError(SessionError error, const std::string& error_desc);
Steve Anton75737c02017-11-06 10:37:17 -0800933
Zhi Huange830e682018-03-30 10:48:35 -0700934 RTCError UpdateSessionState(SdpType type,
935 cricket::ContentSource source,
936 const cricket::SessionDescription* description);
Steve Anton75737c02017-11-06 10:37:17 -0800937 // Push the media parts of the local or remote session description
938 // down to all of the channels.
Karl Wiberg5966c502019-02-21 23:55:09 +0100939 RTCError PushdownMediaDescription(SdpType type, cricket::ContentSource source)
940 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800941
Steve Anton8a006912017-12-04 15:25:56 -0800942 RTCError PushdownTransportDescription(cricket::ContentSource source,
Steve Anton3828c062017-12-06 10:34:51 -0800943 SdpType type);
Steve Anton75737c02017-11-06 10:37:17 -0800944
945 // Returns true and the TransportInfo of the given |content_name|
946 // from |description|. Returns false if it's not available.
947 static bool GetTransportDescription(
948 const cricket::SessionDescription* description,
949 const std::string& content_name,
950 cricket::TransportDescription* info);
951
Steve Anton75737c02017-11-06 10:37:17 -0800952 // Enables media channels to allow sending of media.
Steve Antoned10bd92017-12-05 10:52:59 -0800953 // This enables media to flow on all configured audio/video channels and the
954 // RtpDataChannel.
Karl Wiberga58e1692019-03-26 13:33:43 +0100955 void EnableSending() RTC_RUN_ON(signaling_thread());
Steve Anton3fe1b152017-12-12 10:20:08 -0800956
Steve Anton8af21862017-12-15 11:20:13 -0800957 // Destroys all BaseChannels and destroys the SCTP data channel, if present.
Karl Wiberg85a4a932019-03-22 15:29:58 +0100958 void DestroyAllChannels() RTC_RUN_ON(signaling_thread());
Steve Anton3fe1b152017-12-12 10:20:08 -0800959
Steve Anton75737c02017-11-06 10:37:17 -0800960 // Returns the media index for a local ice candidate given the content name.
961 // Returns false if the local session description does not have a media
962 // content called |content_name|.
963 bool GetLocalCandidateMediaIndex(const std::string& content_name,
Karl Wiberg739506e2019-04-03 11:37:28 +0200964 int* sdp_mline_index)
965 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800966 // Uses all remote candidates in |remote_desc| in this session.
967 bool UseCandidatesInSessionDescription(
Karl Wiberg744310f2019-02-14 10:18:56 +0100968 const SessionDescriptionInterface* remote_desc)
969 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800970 // Uses |candidate| in this session.
Karl Wiberg744310f2019-02-14 10:18:56 +0100971 bool UseCandidate(const IceCandidateInterface* candidate)
972 RTC_RUN_ON(signaling_thread());
Guido Urdaneta41633172019-05-23 20:12:29 +0200973 RTCErrorOr<const cricket::ContentInfo*> FindContentInfo(
974 const SessionDescriptionInterface* description,
975 const IceCandidateInterface* candidate) RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800976 // Deletes the corresponding channel of contents that don't exist in |desc|.
977 // |desc| can be null. This means that all channels are deleted.
Karl Wiberg5966c502019-02-21 23:55:09 +0100978 void RemoveUnusedChannels(const cricket::SessionDescription* desc)
979 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800980
981 // Allocates media channels based on the |desc|. If |desc| doesn't have
982 // the BUNDLE option, this method will disable BUNDLE in PortAllocator.
983 // This method will also delete any existing media channels before creating.
Karl Wiberg5966c502019-02-21 23:55:09 +0100984 RTCError CreateChannels(const cricket::SessionDescription& desc)
985 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800986
987 // If the BUNDLE policy is max-bundle, then we know for sure that all
988 // transports will be bundled from the start. This method returns the BUNDLE
989 // group if that's the case, or null if BUNDLE will be negotiated later. An
990 // error is returned if max-bundle is specified but the session description
991 // does not have a BUNDLE group.
992 RTCErrorOr<const cricket::ContentGroup*> GetEarlyBundleGroup(
Karl Wiberg5966c502019-02-21 23:55:09 +0100993 const cricket::SessionDescription& desc) const
994 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800995
996 // Helper methods to create media channels.
Karl Wiberg5966c502019-02-21 23:55:09 +0100997 cricket::VoiceChannel* CreateVoiceChannel(const std::string& mid)
998 RTC_RUN_ON(signaling_thread());
999 cricket::VideoChannel* CreateVideoChannel(const std::string& mid)
1000 RTC_RUN_ON(signaling_thread());
1001 bool CreateDataChannel(const std::string& mid) RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001002
Zhi Huange830e682018-03-30 10:48:35 -07001003 bool CreateSctpTransport_n(const std::string& mid);
Steve Anton75737c02017-11-06 10:37:17 -08001004 // For bundling.
Steve Anton75737c02017-11-06 10:37:17 -08001005 void DestroySctpTransport_n();
1006 // SctpTransport signal handlers. Needed to marshal signals from the network
1007 // to signaling thread.
1008 void OnSctpTransportReadyToSendData_n();
1009 // This may be called with "false" if the direction of the m= section causes
1010 // us to tear down the SCTP connection.
1011 void OnSctpTransportReadyToSendData_s(bool ready);
1012 void OnSctpTransportDataReceived_n(const cricket::ReceiveDataParams& params,
1013 const rtc::CopyOnWriteBuffer& payload);
1014 // Beyond just firing the signal to the signaling thread, listens to SCTP
1015 // CONTROL messages on unused SIDs and processes them as OPEN messages.
1016 void OnSctpTransportDataReceived_s(const cricket::ReceiveDataParams& params,
1017 const rtc::CopyOnWriteBuffer& payload);
Taylor Brandstettercdd05f02018-05-31 13:23:32 -07001018 void OnSctpClosingProcedureStartedRemotely_n(int sid);
1019 void OnSctpClosingProcedureComplete_n(int sid);
Steve Anton75737c02017-11-06 10:37:17 -08001020
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001021 bool SetupMediaTransportForDataChannels_n(const std::string& mid)
1022 RTC_RUN_ON(network_thread());
1023 void OnMediaTransportStateChanged_n() RTC_RUN_ON(network_thread());
1024 void TeardownMediaTransportForDataChannels_n() RTC_RUN_ON(network_thread());
1025
Steve Anton75737c02017-11-06 10:37:17 -08001026 bool ValidateBundleSettings(const cricket::SessionDescription* desc);
1027 bool HasRtcpMuxEnabled(const cricket::ContentInfo* content);
1028 // Below methods are helper methods which verifies SDP.
Steve Anton8a006912017-12-04 15:25:56 -08001029 RTCError ValidateSessionDescription(const SessionDescriptionInterface* sdesc,
Karl Wiberg5966c502019-02-21 23:55:09 +01001030 cricket::ContentSource source)
1031 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001032
Steve Anton3828c062017-12-06 10:34:51 -08001033 // Check if a call to SetLocalDescription is acceptable with a session
1034 // description of the given type.
1035 bool ExpectSetLocalDescription(SdpType type);
1036 // Check if a call to SetRemoteDescription is acceptable with a session
1037 // description of the given type.
1038 bool ExpectSetRemoteDescription(SdpType type);
Steve Anton75737c02017-11-06 10:37:17 -08001039 // Verifies a=setup attribute as per RFC 5763.
1040 bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc,
Steve Anton3828c062017-12-06 10:34:51 -08001041 SdpType type);
Steve Anton75737c02017-11-06 10:37:17 -08001042
1043 // Returns true if we are ready to push down the remote candidate.
1044 // |remote_desc| is the new remote description, or NULL if the current remote
1045 // description should be used. Output |valid| is true if the candidate media
1046 // index is valid.
1047 bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate,
1048 const SessionDescriptionInterface* remote_desc,
Karl Wiberga58e1692019-03-26 13:33:43 +01001049 bool* valid) RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001050
1051 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
1052 // this session.
Karl Wiberg739506e2019-04-03 11:37:28 +02001053 bool SrtpRequired() const RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001054
Zhi Huange830e682018-03-30 10:48:35 -07001055 // JsepTransportController signal handlers.
Karl Wiberg744310f2019-02-14 10:18:56 +01001056 void OnTransportControllerConnectionState(cricket::IceConnectionState state)
1057 RTC_RUN_ON(signaling_thread());
1058 void OnTransportControllerGatheringState(cricket::IceGatheringState state)
1059 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001060 void OnTransportControllerCandidatesGathered(
1061 const std::string& transport_name,
Karl Wiberg744310f2019-02-14 10:18:56 +01001062 const std::vector<cricket::Candidate>& candidates)
1063 RTC_RUN_ON(signaling_thread());
Eldar Relloda13ea22019-06-01 12:23:43 +03001064 void OnTransportControllerCandidateError(
1065 const cricket::IceCandidateErrorEvent& event)
1066 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001067 void OnTransportControllerCandidatesRemoved(
Karl Wiberg744310f2019-02-14 10:18:56 +01001068 const std::vector<cricket::Candidate>& candidates)
1069 RTC_RUN_ON(signaling_thread());
Alex Drake00c7ecf2019-08-06 10:54:47 -07001070 void OnTransportControllerCandidateChanged(
1071 const cricket::CandidatePairChangeEvent& event)
1072 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001073 void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error);
1074
Steve Antonf8470812017-12-04 10:46:21 -08001075 const char* SessionErrorToString(SessionError error) const;
Karl Wiberga58e1692019-03-26 13:33:43 +01001076 std::string GetSessionErrorMsg() RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001077
Steve Anton8e20f172018-03-06 10:55:04 -08001078 // Report the UMA metric SdpFormatReceived for the given remote offer.
1079 void ReportSdpFormatReceived(const SessionDescriptionInterface& remote_offer);
1080
Steve Anton0ffaaa22018-02-23 10:31:30 -08001081 // Report inferred negotiated SDP semantics from a local/remote answer to the
1082 // UMA observer.
1083 void ReportNegotiatedSdpSemantics(const SessionDescriptionInterface& answer);
1084
Steve Anton75737c02017-11-06 10:37:17 -08001085 // Invoked when TransportController connection completion is signaled.
1086 // Reports stats for all transports in use.
Karl Wiberga58e1692019-03-26 13:33:43 +01001087 void ReportTransportStats() RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001088
1089 // Gather the usage of IPv4/IPv6 as best connection.
1090 void ReportBestConnectionState(const cricket::TransportStats& stats);
1091
Steve Antonc7b964c2018-02-01 14:39:45 -08001092 void ReportNegotiatedCiphers(const cricket::TransportStats& stats,
Karl Wiberg739506e2019-04-03 11:37:28 +02001093 const std::set<cricket::MediaType>& media_types)
1094 RTC_RUN_ON(signaling_thread());
Qingsi Wang1ba5dec2019-08-19 11:57:17 -07001095 void ReportIceCandidateCollected(const cricket::Candidate& candidate)
1096 RTC_RUN_ON(signaling_thread());
1097 void ReportRemoteIceCandidateAdded(const cricket::Candidate& candidate)
1098 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001099
Harald Alvestrand8ebba742018-05-31 14:00:34 +02001100 void NoteUsageEvent(UsageEvent event);
Karl Wiberg744310f2019-02-14 10:18:56 +01001101 void ReportUsagePattern() const RTC_RUN_ON(signaling_thread());
Harald Alvestrand8ebba742018-05-31 14:00:34 +02001102
Steve Anton75737c02017-11-06 10:37:17 -08001103 void OnSentPacket_w(const rtc::SentPacket& sent_packet);
1104
Karl Wiberga58e1692019-03-26 13:33:43 +01001105 const std::string GetTransportName(const std::string& content_name)
1106 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001107
Steve Anton6fec8802017-12-04 10:37:29 -08001108 // Destroys and clears the BaseChannel associated with the given transceiver,
1109 // if such channel is set.
1110 void DestroyTransceiverChannel(
1111 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
1112 transceiver);
1113
1114 // Destroys the RTP data channel and/or the SCTP data channel and clears it.
Karl Wiberg85a4a932019-03-22 15:29:58 +01001115 void DestroyDataChannel() RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001116
Amit Hilbuchdd9390c2018-11-13 16:26:05 -08001117 // Destroys the given ChannelInterface.
1118 // The channel cannot be accessed after this method is called.
1119 void DestroyChannelInterface(cricket::ChannelInterface* channel);
Steve Anton6fec8802017-12-04 10:37:29 -08001120
Zhi Huang365381f2018-04-13 16:44:34 -07001121 // JsepTransportController::Observer override.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -07001122 //
1123 // Called by |transport_controller_| when processing transport information
1124 // from a session description, and the mapping from m= sections to transports
1125 // changed (as a result of BUNDLE negotiation, or m= sections being
1126 // rejected).
Piotr (Peter) Slatalacc8e8bb2018-11-15 08:26:19 -08001127 bool OnTransportChanged(const std::string& mid,
1128 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +01001129 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Karl Wibergac025892019-03-26 13:08:37 +01001130 MediaTransportInterface* media_transport) override;
Zhi Huange830e682018-03-30 10:48:35 -07001131
Guido Urdaneta1ff16c82019-05-20 19:31:53 +02001132 // RtpSenderBase::SetStreamsObserver override.
1133 void OnSetStreams() override;
1134
Harald Alvestrand7a1c7f72018-08-01 10:50:16 +02001135 // Returns the observer. Will crash on CHECK if the observer is removed.
Karl Wiberg744310f2019-02-14 10:18:56 +01001136 PeerConnectionObserver* Observer() const RTC_RUN_ON(signaling_thread());
Harald Alvestrand7a1c7f72018-08-01 10:50:16 +02001137
Benjamin Wright8c27cca2018-10-25 10:16:44 -07001138 // Returns the CryptoOptions for this PeerConnection. This will always
1139 // return the RTCConfiguration.crypto_options if set and will only default
1140 // back to the PeerConnectionFactory settings if nothing was set.
Karl Wiberg5966c502019-02-21 23:55:09 +01001141 CryptoOptions GetCryptoOptions() RTC_RUN_ON(signaling_thread());
Benjamin Wright8c27cca2018-10-25 10:16:44 -07001142
Anton Sukhanov98a462c2018-10-17 13:15:42 -07001143 // Returns rtp transport, result can not be nullptr.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001144 RtpTransportInternal* GetRtpTransport(const std::string& mid)
1145 RTC_RUN_ON(signaling_thread()) {
Anton Sukhanov98a462c2018-10-17 13:15:42 -07001146 auto rtp_transport = transport_controller_->GetRtpTransport(mid);
1147 RTC_DCHECK(rtp_transport);
1148 return rtp_transport;
1149 }
1150
Guido Urdaneta70c2db12019-04-16 12:24:14 +02001151 void UpdateNegotiationNeeded();
1152 bool CheckIfNegotiationIsNeeded();
1153
Karl Wiberg106d92d2019-02-14 10:17:47 +01001154 sigslot::signal1<DataChannel*> SignalDataChannelCreated_
1155 RTC_GUARDED_BY(signaling_thread());
Steve Anton2d8609c2018-01-23 16:38:46 -08001156
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157 // Storing the factory as a scoped reference pointer ensures that the memory
1158 // in the PeerConnectionFactoryImpl remains available as long as the
1159 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
1160 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -07001161 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001162 // will refer to the same reference count.
Karl Wiberg744310f2019-02-14 10:18:56 +01001163 const rtc::scoped_refptr<PeerConnectionFactory> factory_;
1164 PeerConnectionObserver* observer_ RTC_GUARDED_BY(signaling_thread()) =
1165 nullptr;
terelius33860252017-05-12 23:37:18 -07001166
1167 // The EventLog needs to outlive |call_| (and any other object that uses it).
Karl Wibergb03ab712019-02-14 11:59:57 +01001168 std::unique_ptr<RtcEventLog> event_log_ RTC_GUARDED_BY(worker_thread());
1169
1170 // Points to the same thing as `event_log_`. Since it's const, we may read the
1171 // pointer (but not touch the object) from any thread.
1172 RtcEventLog* const event_log_ptr_ RTC_PT_GUARDED_BY(worker_thread());
terelius33860252017-05-12 23:37:18 -07001173
Karl Wiberg8d2e2282019-02-17 13:00:07 +01001174 SignalingState signaling_state_ RTC_GUARDED_BY(signaling_thread()) = kStable;
1175 IceConnectionState ice_connection_state_ RTC_GUARDED_BY(signaling_thread()) =
1176 kIceConnectionNew;
1177 PeerConnectionInterface::IceConnectionState standardized_ice_connection_state_
1178 RTC_GUARDED_BY(signaling_thread()) = kIceConnectionNew;
1179 PeerConnectionInterface::PeerConnectionState connection_state_
1180 RTC_GUARDED_BY(signaling_thread()) = PeerConnectionState::kNew;
Jonas Olsson635474e2018-10-18 15:58:17 +02001181
Karl Wiberg8d2e2282019-02-17 13:00:07 +01001182 IceGatheringState ice_gathering_state_ RTC_GUARDED_BY(signaling_thread()) =
1183 kIceGatheringNew;
Karl Wiberg5966c502019-02-21 23:55:09 +01001184 PeerConnectionInterface::RTCConfiguration configuration_
1185 RTC_GUARDED_BY(signaling_thread());
1186
Bjorn A Mellem5985a042019-06-28 14:19:38 -07001187 // Field-trial based configuration for datagram transport.
1188 const DatagramTransportConfig datagram_transport_config_;
1189
1190 // Final, resolved value for whether datagram transport is in use.
1191 bool use_datagram_transport_ RTC_GUARDED_BY(signaling_thread()) = false;
1192
Karl Wiberg5966c502019-02-21 23:55:09 +01001193 // Cache configuration_.use_media_transport so that we can access it from
1194 // other threads.
1195 // TODO(bugs.webrtc.org/9987): Caching just this bool and allowing the data
1196 // it's derived from to change is not necessarily sound. Stop doing it.
1197 rtc::RaceChecker use_media_transport_race_checker_;
1198 bool use_media_transport_ RTC_GUARDED_BY(use_media_transport_race_checker_) =
1199 configuration_.use_media_transport;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200
Zach Steine20867f2018-08-02 13:20:15 -07001201 // TODO(zstein): |async_resolver_factory_| can currently be nullptr if it
1202 // is not injected. It should be required once chromium supplies it.
Karl Wibergfb3be392019-03-22 14:13:22 +01001203 std::unique_ptr<AsyncResolverFactory> async_resolver_factory_
1204 RTC_GUARDED_BY(signaling_thread());
1205 std::unique_ptr<cricket::PortAllocator>
1206 port_allocator_; // TODO(bugs.webrtc.org/9987): Accessed on both
1207 // signaling and network thread.
1208 std::unique_ptr<rtc::SSLCertificateVerifier>
1209 tls_cert_verifier_; // TODO(bugs.webrtc.org/9987): Accessed on both
1210 // signaling and network thread.
deadbeefab9b2d12015-10-14 11:33:11 -07001211
zhihuang8f65cdf2016-05-06 18:40:30 -07001212 // One PeerConnection has only one RTCP CNAME.
1213 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
Karl Wibergfb3be392019-03-22 14:13:22 +01001214 const std::string rtcp_cname_;
zhihuang8f65cdf2016-05-06 18:40:30 -07001215
deadbeefab9b2d12015-10-14 11:33:11 -07001216 // Streams added via AddStream.
Karl Wiberg1e1e1022019-03-22 14:27:22 +01001217 const rtc::scoped_refptr<StreamCollection> local_streams_
1218 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001219 // Streams created as a result of SetRemoteDescription.
Karl Wiberg1e1e1022019-03-22 14:27:22 +01001220 const rtc::scoped_refptr<StreamCollection> remote_streams_
1221 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001222
Karl Wiberg1e1e1022019-03-22 14:27:22 +01001223 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_
1224 RTC_GUARDED_BY(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -08001225
Steve Anton4171afb2017-11-20 10:20:22 -08001226 // These lists store sender info seen in local/remote descriptions.
Karl Wibergc70999e2019-03-22 15:14:27 +01001227 std::vector<RtpSenderInfo> remote_audio_sender_infos_
1228 RTC_GUARDED_BY(signaling_thread());
1229 std::vector<RtpSenderInfo> remote_video_sender_infos_
1230 RTC_GUARDED_BY(signaling_thread());
1231 std::vector<RtpSenderInfo> local_audio_sender_infos_
1232 RTC_GUARDED_BY(signaling_thread());
1233 std::vector<RtpSenderInfo> local_video_sender_infos_
1234 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001235
Karl Wiberg85a4a932019-03-22 15:29:58 +01001236 SctpSidAllocator sid_allocator_ RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001237 // label -> DataChannel
Karl Wiberg85a4a932019-03-22 15:29:58 +01001238 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_
1239 RTC_GUARDED_BY(signaling_thread());
1240 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_
1241 RTC_GUARDED_BY(signaling_thread());
1242 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_
1243 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001244
Karl Wiberg85a4a932019-03-22 15:29:58 +01001245 bool remote_peer_supports_msid_ RTC_GUARDED_BY(signaling_thread()) = false;
deadbeef70ab1a12015-09-28 16:53:55 -07001246
Karl Wibergac025892019-03-26 13:08:37 +01001247 // The unique_ptr belongs to the worker thread, but the Call object manages
1248 // its own thread safety.
Karl Wiberg6cab5c82019-03-26 09:57:01 +01001249 std::unique_ptr<Call> call_ RTC_GUARDED_BY(worker_thread());
1250
1251 // Points to the same thing as `call_`. Since it's const, we may read the
Karl Wibergac025892019-03-26 13:08:37 +01001252 // pointer from any thread.
1253 Call* const call_ptr_;
Karl Wiberg6cab5c82019-03-26 09:57:01 +01001254
1255 std::unique_ptr<StatsCollector> stats_
1256 RTC_GUARDED_BY(signaling_thread()); // A pointer is passed to senders_
1257 rtc::scoped_refptr<RTCStatsCollector> stats_collector_
1258 RTC_GUARDED_BY(signaling_thread());
terelius33860252017-05-12 23:37:18 -07001259
deadbeefa601f5c2016-06-06 14:27:39 -07001260 std::vector<
Steve Anton4171afb2017-11-20 10:20:22 -08001261 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001262 transceivers_; // TODO(bugs.webrtc.org/9987): Accessed on both signaling
1263 // and network thread.
1264
Henrik Boström5b147782018-12-04 11:25:05 +01001265 // In Unified Plan, if we encounter remote SDP that does not contain an a=msid
1266 // line we create and use a stream with a random ID for our receivers. This is
1267 // to support legacy endpoints that do not support the a=msid attribute (as
1268 // opposed to streamless tracks with "a=msid:-").
Karl Wiberga58e1692019-03-26 13:33:43 +01001269 rtc::scoped_refptr<MediaStreamInterface> missing_msid_default_stream_
1270 RTC_GUARDED_BY(signaling_thread());
Amit Hilbuchae3df542019-01-07 12:13:08 -08001271 // MIDs will be generated using this generator which will keep track of
1272 // all the MIDs that have been seen over the life of the PeerConnection.
Karl Wiberga58e1692019-03-26 13:33:43 +01001273 rtc::UniqueStringGenerator mid_generator_ RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001274
Karl Wiberga58e1692019-03-26 13:33:43 +01001275 SessionError session_error_ RTC_GUARDED_BY(signaling_thread()) =
1276 SessionError::kNone;
1277 std::string session_error_desc_ RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001278
Karl Wiberga58e1692019-03-26 13:33:43 +01001279 std::string session_id_ RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001280
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001281 std::unique_ptr<JsepTransportController>
1282 transport_controller_; // TODO(bugs.webrtc.org/9987): Accessed on both
1283 // signaling and network thread.
1284 std::unique_ptr<cricket::SctpTransportInternalFactory>
1285 sctp_factory_; // TODO(bugs.webrtc.org/9987): Accessed on both
1286 // signaling and network thread.
Steve Anton75737c02017-11-06 10:37:17 -08001287 // |rtp_data_channel_| is used if in RTP data channel mode, |sctp_transport_|
1288 // when using SCTP.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001289 cricket::RtpDataChannel* rtp_data_channel_ =
1290 nullptr; // TODO(bugs.webrtc.org/9987): Accessed on both
1291 // signaling and some other thread.
Steve Anton75737c02017-11-06 10:37:17 -08001292
Harald Alvestrandc85328f2019-02-28 07:51:00 +01001293 cricket::SctpTransportInternal* cricket_sctp_transport() {
1294 return sctp_transport_->internal();
1295 }
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001296 rtc::scoped_refptr<SctpTransport>
1297 sctp_transport_; // TODO(bugs.webrtc.org/9987): Accessed on both
1298 // signaling and network thread.
1299
Zhi Huange830e682018-03-30 10:48:35 -07001300 // |sctp_mid_| is the content name (MID) in SDP.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001301 absl::optional<std::string>
1302 sctp_mid_; // TODO(bugs.webrtc.org/9987): Accessed on both signaling
1303 // and network thread.
1304
Steve Anton75737c02017-11-06 10:37:17 -08001305 // Value cached on signaling thread. Only updated when SctpReadyToSendData
1306 // fires on the signaling thread.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001307 bool sctp_ready_to_send_data_ RTC_GUARDED_BY(signaling_thread()) = false;
1308
Steve Anton75737c02017-11-06 10:37:17 -08001309 // Same as signals provided by SctpTransport, but these are guaranteed to
1310 // fire on the signaling thread, whereas SctpTransport fires on the networking
1311 // thread.
1312 // |sctp_invoker_| is used so that any signals queued on the signaling thread
1313 // from the network thread are immediately discarded if the SctpTransport is
1314 // destroyed (due to m= section being rejected).
1315 // TODO(deadbeef): Use a proxy object to ensure that method calls/signals
1316 // are marshalled to the right thread. Could almost use proxy.h for this,
1317 // but it doesn't have a mechanism for marshalling sigslot::signals
Karl Wiberg7a651c6e2019-04-02 13:00:46 +02001318 std::unique_ptr<rtc::AsyncInvoker> sctp_invoker_
1319 RTC_GUARDED_BY(network_thread());
1320 sigslot::signal1<bool> SignalSctpReadyToSendData
1321 RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001322 sigslot::signal2<const cricket::ReceiveDataParams&,
1323 const rtc::CopyOnWriteBuffer&>
Karl Wiberg7a651c6e2019-04-02 13:00:46 +02001324 SignalSctpDataReceived RTC_GUARDED_BY(signaling_thread());
1325 sigslot::signal1<int> SignalSctpClosingProcedureStartedRemotely
1326 RTC_GUARDED_BY(signaling_thread());
1327 sigslot::signal1<int> SignalSctpClosingProcedureComplete
1328 RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001329
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001330 // Whether this peer is the caller. Set when the local description is applied.
1331 absl::optional<bool> is_caller_ RTC_GUARDED_BY(signaling_thread());
1332
1333 // Content name (MID) for media transport data channels in SDP.
Karl Wibergd9bf7202019-04-02 19:36:24 +02001334 absl::optional<std::string>
1335 media_transport_data_mid_; // TODO(bugs.webrtc.org/9987): Accessed on
1336 // both signaling and network thread.
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001337
1338 // Media transport used for data channels. Thread-safe.
Karl Wibergd9bf7202019-04-02 19:36:24 +02001339 MediaTransportInterface* media_transport_ =
1340 nullptr; // TODO(bugs.webrtc.org/9987): Object is thread safe, but
1341 // pointer accessed on both signaling and network thread.
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001342
1343 // Cached value of whether the media transport is ready to send.
1344 bool media_transport_ready_to_send_data_ RTC_GUARDED_BY(signaling_thread()) =
1345 false;
1346
1347 // Used to invoke media transport signals on the signaling thread.
Karl Wiberg739506e2019-04-03 11:37:28 +02001348 std::unique_ptr<rtc::AsyncInvoker> media_transport_invoker_
1349 RTC_GUARDED_BY(network_thread());
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001350
1351 // Identical to the signals for SCTP, but from media transport:
1352 sigslot::signal1<bool> SignalMediaTransportWritable_s
1353 RTC_GUARDED_BY(signaling_thread());
1354 sigslot::signal2<const cricket::ReceiveDataParams&,
1355 const rtc::CopyOnWriteBuffer&>
1356 SignalMediaTransportReceivedData_s RTC_GUARDED_BY(signaling_thread());
1357 sigslot::signal1<int> SignalMediaTransportChannelClosing_s
1358 RTC_GUARDED_BY(signaling_thread());
1359 sigslot::signal1<int> SignalMediaTransportChannelClosed_s
1360 RTC_GUARDED_BY(signaling_thread());
1361
Karl Wiberg739506e2019-04-03 11:37:28 +02001362 std::unique_ptr<SessionDescriptionInterface> current_local_description_
1363 RTC_GUARDED_BY(signaling_thread());
1364 std::unique_ptr<SessionDescriptionInterface> pending_local_description_
1365 RTC_GUARDED_BY(signaling_thread());
1366 std::unique_ptr<SessionDescriptionInterface> current_remote_description_
1367 RTC_GUARDED_BY(signaling_thread());
1368 std::unique_ptr<SessionDescriptionInterface> pending_remote_description_
1369 RTC_GUARDED_BY(signaling_thread());
1370 bool dtls_enabled_ RTC_GUARDED_BY(signaling_thread()) = false;
Steve Anton75737c02017-11-06 10:37:17 -08001371 // Specifies which kind of data channel is allowed. This is controlled
1372 // by the chrome command-line flag and constraints:
1373 // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled,
1374 // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is
1375 // not set or false, SCTP is allowed (DCT_SCTP);
1376 // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP);
1377 // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE).
Karl Wibergf73f7d62019-04-08 15:36:53 +02001378 cricket::DataChannelType data_channel_type_ =
1379 cricket::DCT_NONE; // TODO(bugs.webrtc.org/9987): Accessed on both
1380 // signaling and network thread.
Steve Anton75737c02017-11-06 10:37:17 -08001381
Karl Wibergf73f7d62019-04-08 15:36:53 +02001382 // List of content names for which the remote side triggered an ICE restart.
1383 std::set<std::string> pending_ice_restarts_
1384 RTC_GUARDED_BY(signaling_thread());
1385
1386 std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_
1387 RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001388
1389 // Member variables for caching global options.
Karl Wibergf73f7d62019-04-08 15:36:53 +02001390 cricket::AudioOptions audio_options_ RTC_GUARDED_BY(signaling_thread());
1391 cricket::VideoOptions video_options_ RTC_GUARDED_BY(signaling_thread());
Harald Alvestrand8ebba742018-05-31 14:00:34 +02001392
Karl Wibergf73f7d62019-04-08 15:36:53 +02001393 int usage_event_accumulator_ RTC_GUARDED_BY(signaling_thread()) = 0;
1394 bool return_histogram_very_quickly_ RTC_GUARDED_BY(signaling_thread()) =
1395 false;
Amit Hilbuchbcd39d42019-01-25 17:13:56 -08001396
1397 // This object should be used to generate any SSRC that is not explicitly
1398 // specified by the user (or by the remote party).
1399 // The generator is not used directly, instead it is passed on to the
1400 // channel manager and the session description factory.
Karl Wibergf73f7d62019-04-08 15:36:53 +02001401 rtc::UniqueRandomIdGenerator ssrc_generator_
1402 RTC_GUARDED_BY(signaling_thread());
Jonas Orelanda3aa9bd2019-04-17 07:38:40 +02001403
1404 // A video bitrate allocator factory.
1405 // This can injected using the PeerConnectionDependencies,
1406 // or else the CreateBuiltinVideoBitrateAllocatorFactory() will be called.
1407 // Note that one can still choose to override this in a MediaEngine
1408 // if one wants too.
1409 std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
1410 video_bitrate_allocator_factory_;
1411
Henrik Boström79b69802019-07-18 11:16:56 +02001412 std::unique_ptr<LocalIceCredentialsToReplace>
1413 local_ice_credentials_to_replace_ RTC_GUARDED_BY(signaling_thread());
Guido Urdaneta70c2db12019-04-16 12:24:14 +02001414 bool is_negotiation_needed_ RTC_GUARDED_BY(signaling_thread()) = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415};
1416
1417} // namespace webrtc
1418
Steve Anton10542f22019-01-11 09:11:00 -08001419#endif // PC_PEER_CONNECTION_H_