blob: 82d2a70c08734beba8d24d08dc0696ae8dd11abe [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;
Niels Möller2579f0c2019-08-19 09:58:17 +0200214 RTCError SetConfiguration(
215 const PeerConnectionInterface::RTCConfiguration& configuration) override;
deadbeefa67696b2015-09-29 11:56:26 -0700216 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700217 bool RemoveIceCandidates(
218 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219
Niels Möller0c4f7be2018-05-07 14:01:37 +0200220 RTCError SetBitrate(const BitrateSettings& bitrate) override;
zstein4b979802017-06-02 14:37:37 -0700221
henrika5f6bf242017-11-01 11:06:56 +0100222 void SetAudioPlayout(bool playout) override;
223 void SetAudioRecording(bool recording) override;
224
Harald Alvestrandad88c882018-11-28 16:47:46 +0100225 rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid(
226 const std::string& mid) override;
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100227 rtc::scoped_refptr<DtlsTransport> LookupDtlsTransportByMidInternal(
228 const std::string& mid);
Harald Alvestrandad88c882018-11-28 16:47:46 +0100229
Harald Alvestrandc85328f2019-02-28 07:51:00 +0100230 rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const override;
231
Bjorn Tereliusde939432017-11-20 17:38:14 +0100232 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,
233 int64_t output_period_ms) override;
Niels Möllerf00ca1a2019-05-10 11:33:12 +0200234 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override;
ivoc14d5dbe2016-07-04 07:06:55 -0700235 void StopRtcEventLog() override;
236
deadbeefa67696b2015-09-29 11:56:26 -0700237 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238
Steve Anton2d8609c2018-01-23 16:38:46 -0800239 // PeerConnectionInternal implementation.
Karl Wiberg4ae63472019-02-22 00:57:06 +0100240 rtc::Thread* network_thread() const final {
Steve Anton2d8609c2018-01-23 16:38:46 -0800241 return factory_->network_thread();
242 }
Karl Wiberg4ae63472019-02-22 00:57:06 +0100243 rtc::Thread* worker_thread() const final { return factory_->worker_thread(); }
244 rtc::Thread* signaling_thread() const final {
Steve Anton2d8609c2018-01-23 16:38:46 -0800245 return factory_->signaling_thread();
perkjd61bf802016-03-24 03:16:19 -0700246 }
deadbeefab9b2d12015-10-14 11:33:11 -0700247
Karl Wiberga58e1692019-03-26 13:33:43 +0100248 std::string session_id() const override {
249 RTC_DCHECK_RUN_ON(signaling_thread());
250 return session_id_;
251 }
Steve Anton75737c02017-11-06 10:37:17 -0800252
Steve Anton2d8609c2018-01-23 16:38:46 -0800253 bool initial_offerer() const override {
Karl Wiberg2cc368f2019-04-02 11:31:56 +0200254 RTC_DCHECK_RUN_ON(signaling_thread());
Zhi Huange830e682018-03-30 10:48:35 -0700255 return transport_controller_ && transport_controller_->initial_offerer();
Steve Anton2d8609c2018-01-23 16:38:46 -0800256 }
Steve Anton75737c02017-11-06 10:37:17 -0800257
Steve Anton2d8609c2018-01-23 16:38:46 -0800258 std::vector<
259 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 10:07:54 -0800260 GetTransceiversInternal() const override {
Karl Wiberga58e1692019-03-26 13:33:43 +0100261 RTC_DCHECK_RUN_ON(signaling_thread());
Steve Anton2d8609c2018-01-23 16:38:46 -0800262 return transceivers_;
263 }
264
Steve Anton2d8609c2018-01-23 16:38:46 -0800265 sigslot::signal1<DataChannel*>& SignalDataChannelCreated() override {
266 return SignalDataChannelCreated_;
267 }
268
269 cricket::RtpDataChannel* rtp_data_channel() const override {
Steve Anton75737c02017-11-06 10:37:17 -0800270 return rtp_data_channel_;
Steve Anton978b8762017-09-29 12:15:02 -0700271 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800272
Steve Antonbe5e2082018-01-24 15:29:17 -0800273 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels()
Steve Anton2d8609c2018-01-23 16:38:46 -0800274 const override {
Karl Wiberg85a4a932019-03-22 15:29:58 +0100275 RTC_DCHECK_RUN_ON(signaling_thread());
Steve Anton2d8609c2018-01-23 16:38:46 -0800276 return sctp_data_channels_;
277 }
278
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200279 absl::optional<std::string> sctp_content_name() const override {
Karl Wiberg2cc368f2019-04-02 11:31:56 +0200280 RTC_DCHECK_RUN_ON(signaling_thread());
Zhi Huange830e682018-03-30 10:48:35 -0700281 return sctp_mid_;
Steve Anton75737c02017-11-06 10:37:17 -0800282 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800283
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200284 absl::optional<std::string> sctp_transport_name() const override;
Steve Anton75737c02017-11-06 10:37:17 -0800285
Qingsi Wang72a43a12018-02-20 16:03:18 -0800286 cricket::CandidateStatsList GetPooledCandidateStats() const override;
Steve Anton5dfde182018-02-06 10:34:40 -0800287 std::map<std::string, std::string> GetTransportNamesByMid() const override;
288 std::map<std::string, cricket::TransportStats> GetTransportStatsByNames(
289 const std::set<std::string>& transport_names) override;
Steve Anton2d8609c2018-01-23 16:38:46 -0800290 Call::Stats GetCallStats() override;
Steve Anton75737c02017-11-06 10:37:17 -0800291
Steve Anton2d8609c2018-01-23 16:38:46 -0800292 bool GetLocalCertificate(
293 const std::string& transport_name,
294 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800295 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-23 16:38:46 -0800296 const std::string& transport_name) override;
297 bool IceRestartPending(const std::string& content_name) const override;
298 bool NeedsIceRestart(const std::string& content_name) const override;
299 bool GetSslRole(const std::string& content_name, rtc::SSLRole* role) override;
Steve Anton7464fca2018-01-19 11:10:37 -0800300
Harald Alvestrand19793842018-06-25 12:03:50 +0200301 void ReturnHistogramVeryQuicklyForTesting() {
Karl Wibergf73f7d62019-04-08 15:36:53 +0200302 RTC_DCHECK_RUN_ON(signaling_thread());
Harald Alvestrand19793842018-06-25 12:03:50 +0200303 return_histogram_very_quickly_ = true;
304 }
Harald Alvestrand7a1c7f72018-08-01 10:50:16 +0200305 void RequestUsagePatternReportForTesting();
Harald Alvestrand19793842018-06-25 12:03:50 +0200306
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700308 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309
310 private:
Henrik Boström31638672017-11-23 17:48:32 +0100311 class SetRemoteDescriptionObserverAdapter;
312 friend class SetRemoteDescriptionObserverAdapter;
Henrik Boström79b69802019-07-18 11:16:56 +0200313 // Represents the [[LocalIceCredentialsToReplace]] internal slot in the spec.
314 // It makes the next CreateOffer() produce new ICE credentials even if
315 // RTCOfferAnswerOptions::ice_restart is false.
316 // https://w3c.github.io/webrtc-pc/#dfn-localufragstoreplace
317 // TODO(hbos): When JsepTransportController/JsepTransport supports rollback,
318 // move this type of logic to JsepTransportController/JsepTransport.
319 class LocalIceCredentialsToReplace;
Henrik Boström31638672017-11-23 17:48:32 +0100320
Steve Anton4171afb2017-11-20 10:20:22 -0800321 struct RtpSenderInfo {
322 RtpSenderInfo() : first_ssrc(0) {}
Seth Hampson845e8782018-03-02 11:34:10 -0800323 RtpSenderInfo(const std::string& stream_id,
Steve Anton4171afb2017-11-20 10:20:22 -0800324 const std::string sender_id,
325 uint32_t ssrc)
Seth Hampson845e8782018-03-02 11:34:10 -0800326 : stream_id(stream_id), sender_id(sender_id), first_ssrc(ssrc) {}
Steve Anton4171afb2017-11-20 10:20:22 -0800327 bool operator==(const RtpSenderInfo& other) {
Seth Hampson845e8782018-03-02 11:34:10 -0800328 return this->stream_id == other.stream_id &&
Steve Anton4171afb2017-11-20 10:20:22 -0800329 this->sender_id == other.sender_id &&
330 this->first_ssrc == other.first_ssrc;
deadbeefbda7e0b2015-12-08 17:13:40 -0800331 }
Seth Hampson845e8782018-03-02 11:34:10 -0800332 std::string stream_id;
Steve Anton4171afb2017-11-20 10:20:22 -0800333 std::string sender_id;
334 // An RtpSender can have many SSRCs. The first one is used as a sort of ID
335 // for communicating with the lower layers.
336 uint32_t first_ssrc;
deadbeefab9b2d12015-10-14 11:33:11 -0700337 };
deadbeefab9b2d12015-10-14 11:33:11 -0700338
Bjorn A Mellem5985a042019-06-28 14:19:38 -0700339 // Field-trial based configuration for datagram transport.
340 struct DatagramTransportConfig {
341 explicit DatagramTransportConfig(const std::string& field_trial)
342 : enabled("enabled", true), default_value("default_value", false) {
343 ParseFieldTrial({&enabled, &default_value}, field_trial);
344 }
345
346 // Whether datagram transport support is enabled at all. Defaults to true,
347 // allowing datagram transport to be used if (a) the application provides a
348 // factory for it and (b) the configuration specifies its use. This flag
349 // provides a kill-switch to force-disable datagram transport across all
350 // applications, without code changes.
351 FieldTrialFlag enabled;
352
353 // Whether the datagram transport is enabled or disabled by default.
354 // Defaults to false, meaning that applications must configure use of
355 // datagram transport through RTCConfiguration. If set to true,
356 // applications will use the datagram transport by default (but may still
357 // explicitly configure themselves not to use it through RTCConfiguration).
358 FieldTrialFlag default_value;
359 };
360
Steve Antonad182762018-09-05 20:22:40 +0000361 // Implements MessageHandler.
362 void OnMessage(rtc::Message* msg) override;
363
Steve Antonafb0bb72018-02-20 11:35:37 -0800364 // Plan B helpers for getting the voice/video media channels for the single
365 // audio/video transceiver, if it exists.
Karl Wiberg5966c502019-02-21 23:55:09 +0100366 cricket::VoiceMediaChannel* voice_media_channel() const
367 RTC_RUN_ON(signaling_thread());
368 cricket::VideoMediaChannel* video_media_channel() const
369 RTC_RUN_ON(signaling_thread());
Steve Anton60776752018-01-10 11:51:34 -0800370
Steve Anton4171afb2017-11-20 10:20:22 -0800371 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100372 GetSendersInternal() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800373 std::vector<
374 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100375 GetReceiversInternal() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800376
377 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100378 GetAudioTransceiver() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800379 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100380 GetVideoTransceiver() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800381
Steve Antonafb0bb72018-02-20 11:35:37 -0800382 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100383 GetFirstAudioTransceiver() const RTC_RUN_ON(signaling_thread());
Steve Antonafb0bb72018-02-20 11:35:37 -0800384
deadbeefab9b2d12015-10-14 11:33:11 -0700385 void CreateAudioReceiver(MediaStreamInterface* stream,
Karl Wiberg744310f2019-02-14 10:18:56 +0100386 const RtpSenderInfo& remote_sender_info)
387 RTC_RUN_ON(signaling_thread());
perkjf0dcfe22016-03-10 18:32:00 +0100388
deadbeefab9b2d12015-10-14 11:33:11 -0700389 void CreateVideoReceiver(MediaStreamInterface* stream,
Karl Wiberg744310f2019-02-14 10:18:56 +0100390 const RtpSenderInfo& remote_sender_info)
391 RTC_RUN_ON(signaling_thread());
Henrik Boström933d8b02017-10-10 10:05:16 -0700392 rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver(
Karl Wiberg5966c502019-02-21 23:55:09 +0100393 const RtpSenderInfo& remote_sender_info) RTC_RUN_ON(signaling_thread());
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700394
395 // May be called either by AddStream/RemoveStream, or when a track is
396 // added/removed from a stream previously added via AddStream.
Karl Wiberg5966c502019-02-21 23:55:09 +0100397 void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream)
398 RTC_RUN_ON(signaling_thread());
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700399 void RemoveAudioTrack(AudioTrackInterface* track,
Karl Wiberg5966c502019-02-21 23:55:09 +0100400 MediaStreamInterface* stream)
401 RTC_RUN_ON(signaling_thread());
402 void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream)
403 RTC_RUN_ON(signaling_thread());
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700404 void RemoveVideoTrack(VideoTrackInterface* track,
Karl Wiberg5966c502019-02-21 23:55:09 +0100405 MediaStreamInterface* stream)
406 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407
Steve Antonf9381f02017-12-14 10:23:57 -0800408 // AddTrack implementation when Unified Plan is specified.
409 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackUnifiedPlan(
410 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Karl Wiberga58e1692019-03-26 13:33:43 +0100411 const std::vector<std::string>& stream_ids)
412 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800413 // AddTrack implementation when Plan B is specified.
414 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackPlanB(
415 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Karl Wiberg5966c502019-02-21 23:55:09 +0100416 const std::vector<std::string>& stream_ids)
417 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800418
419 // Returns the first RtpTransceiver suitable for a newly added track, if such
420 // transceiver is available.
421 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
422 FindFirstTransceiverForAddedTrack(
Karl Wiberga58e1692019-03-26 13:33:43 +0100423 rtc::scoped_refptr<MediaStreamTrackInterface> track)
424 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800425
Steve Antonf9381f02017-12-14 10:23:57 -0800426 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100427 FindTransceiverBySender(rtc::scoped_refptr<RtpSenderInterface> sender)
428 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800429
Steve Anton22da89f2018-01-25 13:58:07 -0800430 // Internal implementation for AddTransceiver family of methods. If
431 // |fire_callback| is set, fires OnRenegotiationNeeded callback if successful.
Steve Anton9158ef62017-11-27 13:01:52 -0800432 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
433 cricket::MediaType media_type,
434 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Steve Anton22da89f2018-01-25 13:58:07 -0800435 const RtpTransceiverInit& init,
Karl Wiberg744310f2019-02-14 10:18:56 +0100436 bool fire_callback = true) RTC_RUN_ON(signaling_thread());
Steve Anton9158ef62017-11-27 13:01:52 -0800437
Steve Anton02ee47c2018-01-10 16:26:06 -0800438 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
439 CreateSender(cricket::MediaType media_type,
Steve Anton111fdfd2018-06-25 13:03:36 -0700440 const std::string& id,
Steve Anton02ee47c2018-01-10 16:26:06 -0800441 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Florent Castelli892acf02018-10-01 22:47:20 +0200442 const std::vector<std::string>& stream_ids,
443 const std::vector<RtpEncodingParameters>& send_encodings);
Steve Anton02ee47c2018-01-10 16:26:06 -0800444
445 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
446 CreateReceiver(cricket::MediaType media_type, const std::string& receiver_id);
447
Steve Antonf9381f02017-12-14 10:23:57 -0800448 // Create a new RtpTransceiver of the given type and add it to the list of
449 // transceivers.
450 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Steve Anton02ee47c2018-01-10 16:26:06 -0800451 CreateAndAddTransceiver(
452 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender,
453 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100454 receiver) RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800455
Karl Wiberg744310f2019-02-14 10:18:56 +0100456 void SetIceConnectionState(IceConnectionState new_state)
457 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 15:58:17 +0200458 void SetStandardizedIceConnectionState(
Karl Wiberg744310f2019-02-14 10:18:56 +0100459 PeerConnectionInterface::IceConnectionState new_state)
460 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 15:58:17 +0200461 void SetConnectionState(
Karl Wiberg744310f2019-02-14 10:18:56 +0100462 PeerConnectionInterface::PeerConnectionState new_state)
463 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 15:58:17 +0200464
Eldar Relloda13ea22019-06-01 12:23:43 +0300465 // Called any time the IceGatheringState changes.
Karl Wiberg744310f2019-02-14 10:18:56 +0100466 void OnIceGatheringChange(IceGatheringState new_state)
467 RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 10:21:57 -0800468 // New ICE candidate has been gathered.
Karl Wiberg744310f2019-02-14 10:18:56 +0100469 void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate)
470 RTC_RUN_ON(signaling_thread());
Eldar Relloda13ea22019-06-01 12:23:43 +0300471 // Gathering of an ICE candidate failed.
472 void OnIceCandidateError(const std::string& host_candidate,
473 const std::string& url,
474 int error_code,
475 const std::string& error_text)
476 RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 10:21:57 -0800477 // Some local ICE candidates have been removed.
Karl Wiberg744310f2019-02-14 10:18:56 +0100478 void OnIceCandidatesRemoved(const std::vector<cricket::Candidate>& candidates)
479 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480
Alex Drake00c7ecf2019-08-06 10:54:47 -0700481 void OnSelectedCandidatePairChanged(
482 const cricket::CandidatePairChangeEvent& event)
483 RTC_RUN_ON(signaling_thread());
484
Steve Antonba818672017-11-06 10:21:57 -0800485 // Update the state, signaling if necessary.
Karl Wiberg744310f2019-02-14 10:18:56 +0100486 void ChangeSignalingState(SignalingState signaling_state)
487 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488
deadbeefeb459812015-12-15 19:24:43 -0800489 // Signals from MediaStreamObserver.
490 void OnAudioTrackAdded(AudioTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100491 MediaStreamInterface* stream)
492 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800493 void OnAudioTrackRemoved(AudioTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100494 MediaStreamInterface* stream)
495 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800496 void OnVideoTrackAdded(VideoTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100497 MediaStreamInterface* stream)
498 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800499 void OnVideoTrackRemoved(VideoTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100500 MediaStreamInterface* stream)
501 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800502
Henrik Boström31638672017-11-23 17:48:32 +0100503 void PostSetSessionDescriptionSuccess(
504 SetSessionDescriptionObserver* observer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
Steve Antonad182762018-09-05 20:22:40 +0000506 RTCError&& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700507 void PostCreateSessionDescriptionFailure(
508 CreateSessionDescriptionObserver* observer,
Harald Alvestrand5081c0c2018-03-09 15:18:03 +0100509 RTCError error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510
Steve Anton8a006912017-12-04 15:25:56 -0800511 // Synchronous implementations of SetLocalDescription/SetRemoteDescription
512 // that return an RTCError instead of invoking a callback.
513 RTCError ApplyLocalDescription(
514 std::unique_ptr<SessionDescriptionInterface> desc);
515 RTCError ApplyRemoteDescription(
516 std::unique_ptr<SessionDescriptionInterface> desc);
517
Steve Antondcc3c022017-12-22 16:02:54 -0800518 // Updates the local RtpTransceivers according to the JSEP rules. Called as
519 // part of setting the local/remote description.
520 RTCError UpdateTransceiversAndDataChannels(
521 cricket::ContentSource source,
Seth Hampsonae8a90a2018-02-13 15:33:48 -0800522 const SessionDescriptionInterface& new_session,
523 const SessionDescriptionInterface* old_local_description,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100524 const SessionDescriptionInterface* old_remote_description)
525 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800526
527 // Either creates or destroys the transceiver's BaseChannel according to the
528 // given media section.
529 RTCError UpdateTransceiverChannel(
530 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
531 transceiver,
532 const cricket::ContentInfo& content,
Karl Wiberg5966c502019-02-21 23:55:09 +0100533 const cricket::ContentGroup* bundle_group) RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800534
Steve Antonfa2260d2017-12-28 16:38:23 -0800535 // Either creates or destroys the local data channel according to the given
536 // media section.
537 RTCError UpdateDataChannel(cricket::ContentSource source,
538 const cricket::ContentInfo& content,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100539 const cricket::ContentGroup* bundle_group)
540 RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800541
Steve Antondcc3c022017-12-22 16:02:54 -0800542 // Associate the given transceiver according to the JSEP rules.
543 RTCErrorOr<
544 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
545 AssociateTransceiver(cricket::ContentSource source,
Seth Hampsonae8a90a2018-02-13 15:33:48 -0800546 SdpType type,
Steve Antondcc3c022017-12-22 16:02:54 -0800547 size_t mline_index,
548 const cricket::ContentInfo& content,
Seth Hampsonae8a90a2018-02-13 15:33:48 -0800549 const cricket::ContentInfo* old_local_content,
Karl Wiberg5966c502019-02-21 23:55:09 +0100550 const cricket::ContentInfo* old_remote_content)
551 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800552
553 // Returns the RtpTransceiver, if found, that is associated to the given MID.
554 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100555 GetAssociatedTransceiver(const std::string& mid) const
556 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800557
558 // Returns the RtpTransceiver, if found, that was assigned to the given mline
559 // index in CreateOffer.
560 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100561 GetTransceiverByMLineIndex(size_t mline_index) const
562 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800563
564 // Returns an RtpTransciever, if available, that can be used to receive the
565 // given media type according to JSEP rules.
566 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100567 FindAvailableTransceiverToReceive(cricket::MediaType media_type) const
568 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800569
Steve Antoned10bd92017-12-05 10:52:59 -0800570 // Returns the media section in the given session description that is
571 // associated with the RtpTransceiver. Returns null if none found or this
572 // RtpTransceiver is not associated. Logic varies depending on the
573 // SdpSemantics specified in the configuration.
574 const cricket::ContentInfo* FindMediaSectionForTransceiver(
575 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
576 transceiver,
Karl Wiberg5966c502019-02-21 23:55:09 +0100577 const SessionDescriptionInterface* sdesc) const
578 RTC_RUN_ON(signaling_thread());
Steve Antoned10bd92017-12-05 10:52:59 -0800579
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100580 // Runs the algorithm **set the associated remote streams** specified in
581 // https://w3c.github.io/webrtc-pc/#set-associated-remote-streams.
582 void SetAssociatedRemoteStreams(
583 rtc::scoped_refptr<RtpReceiverInternal> receiver,
584 const std::vector<std::string>& stream_ids,
585 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* added_streams,
Karl Wiberg1e1e1022019-03-22 14:27:22 +0100586 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams)
587 RTC_RUN_ON(signaling_thread());
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100588
Steve Anton0f5400a2018-07-17 14:25:36 -0700589 // Runs the algorithm **process the removal of a remote track** specified in
590 // the WebRTC specification.
591 // This method will update the following lists:
592 // |remove_list| is the list of transceivers for which the receiving track is
593 // being removed.
594 // |removed_streams| is the list of streams which no longer have a receiving
595 // track so should be removed.
596 // https://w3c.github.io/webrtc-pc/#process-remote-track-removal
597 void ProcessRemovalOfRemoteTrack(
598 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
599 transceiver,
600 std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>* remove_list,
Karl Wiberg1e1e1022019-03-22 14:27:22 +0100601 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams)
602 RTC_RUN_ON(signaling_thread());
Steve Anton0f5400a2018-07-17 14:25:36 -0700603
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100604 void RemoveRemoteStreamsIfEmpty(
605 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&
606 remote_streams,
Karl Wiberg1e1e1022019-03-22 14:27:22 +0100607 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams)
608 RTC_RUN_ON(signaling_thread());
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100609
Steve Anton52d86772018-02-20 15:48:12 -0800610 void OnNegotiationNeeded();
611
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 bool IsClosed() const {
Karl Wiberg8d2e2282019-02-17 13:00:07 +0100613 RTC_DCHECK_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 return signaling_state_ == PeerConnectionInterface::kClosed;
615 }
616
deadbeefab9b2d12015-10-14 11:33:11 -0700617 // Returns a MediaSessionOptions struct with options decided by |options|,
618 // the local MediaStreams and DataChannels.
Steve Antondcc3c022017-12-22 16:02:54 -0800619 void GetOptionsForOffer(const PeerConnectionInterface::RTCOfferAnswerOptions&
620 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100621 cricket::MediaSessionOptions* session_options)
622 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800623 void GetOptionsForPlanBOffer(
624 const PeerConnectionInterface::RTCOfferAnswerOptions&
625 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100626 cricket::MediaSessionOptions* session_options)
627 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800628 void GetOptionsForUnifiedPlanOffer(
629 const PeerConnectionInterface::RTCOfferAnswerOptions&
630 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100631 cricket::MediaSessionOptions* session_options)
632 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700633
Karl Wiberg5966c502019-02-21 23:55:09 +0100634 RTCError HandleLegacyOfferOptions(const RTCOfferAnswerOptions& options)
635 RTC_RUN_ON(signaling_thread());
Steve Anton22da89f2018-01-25 13:58:07 -0800636 void RemoveRecvDirectionFromReceivingTransceiversOfType(
Karl Wiberga58e1692019-03-26 13:33:43 +0100637 cricket::MediaType media_type) RTC_RUN_ON(signaling_thread());
Steve Anton22da89f2018-01-25 13:58:07 -0800638 void AddUpToOneReceivingTransceiverOfType(cricket::MediaType media_type);
639 std::vector<
640 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100641 GetReceivingTransceiversOfType(cricket::MediaType media_type)
642 RTC_RUN_ON(signaling_thread());
Steve Anton22da89f2018-01-25 13:58:07 -0800643
deadbeefab9b2d12015-10-14 11:33:11 -0700644 // Returns a MediaSessionOptions struct with options decided by
645 // |constraints|, the local MediaStreams and DataChannels.
Steve Antondcc3c022017-12-22 16:02:54 -0800646 void GetOptionsForAnswer(const RTCOfferAnswerOptions& offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100647 cricket::MediaSessionOptions* session_options)
648 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800649 void GetOptionsForPlanBAnswer(
650 const PeerConnectionInterface::RTCOfferAnswerOptions&
651 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100652 cricket::MediaSessionOptions* session_options)
653 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800654 void GetOptionsForUnifiedPlanAnswer(
655 const PeerConnectionInterface::RTCOfferAnswerOptions&
656 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100657 cricket::MediaSessionOptions* session_options)
658 RTC_RUN_ON(signaling_thread());
htaa2a49d92016-03-04 02:51:39 -0800659
zhihuang1c378ed2017-08-17 14:10:50 -0700660 // Generates MediaDescriptionOptions for the |session_opts| based on existing
661 // local description or remote description.
662 void GenerateMediaDescriptionOptions(
663 const SessionDescriptionInterface* session_desc,
Steve Anton1d03a752017-11-27 14:30:09 -0800664 RtpTransceiverDirection audio_direction,
665 RtpTransceiverDirection video_direction,
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200666 absl::optional<size_t>* audio_index,
667 absl::optional<size_t>* video_index,
668 absl::optional<size_t>* data_index,
Karl Wiberg85a4a932019-03-22 15:29:58 +0100669 cricket::MediaSessionOptions* session_options)
670 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700671
Steve Antonfa2260d2017-12-28 16:38:23 -0800672 // Generates the active MediaDescriptionOptions for the local data channel
673 // given the specified MID.
674 cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForActiveData(
Karl Wiberg85a4a932019-03-22 15:29:58 +0100675 const std::string& mid) const RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800676
677 // Generates the rejected MediaDescriptionOptions for the local data channel
678 // given the specified MID.
679 cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForRejectedData(
Karl Wiberg85a4a932019-03-22 15:29:58 +0100680 const std::string& mid) const RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800681
682 // Returns the MID for the data section associated with either the
683 // RtpDataChannel or SCTP data channel, if it has been set. If no data
684 // channels are configured this will return nullopt.
Karl Wiberg2cc368f2019-04-02 11:31:56 +0200685 absl::optional<std::string> GetDataMid() const RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800686
Steve Anton4171afb2017-11-20 10:20:22 -0800687 // Remove all local and remote senders of type |media_type|.
deadbeeffaac4972015-11-12 15:33:07 -0800688 // Called when a media type is rejected (m-line set to port 0).
Karl Wiberg744310f2019-02-14 10:18:56 +0100689 void RemoveSenders(cricket::MediaType media_type)
690 RTC_RUN_ON(signaling_thread());
deadbeeffaac4972015-11-12 15:33:07 -0800691
deadbeefbda7e0b2015-12-08 17:13:40 -0800692 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
693 // and existing MediaStreamTracks are removed if there is no corresponding
694 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
695 // is created if it doesn't exist; if false, it's removed if it exists.
696 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700697 // If a new MediaStream is created it is added to |new_streams|.
Steve Anton4171afb2017-11-20 10:20:22 -0800698 void UpdateRemoteSendersList(
deadbeefab9b2d12015-10-14 11:33:11 -0700699 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800700 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700701 cricket::MediaType media_type,
Karl Wiberg744310f2019-02-14 10:18:56 +0100702 StreamCollection* new_streams) RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700703
Steve Anton4171afb2017-11-20 10:20:22 -0800704 // Triggered when a remote sender has been seen for the first time in a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700705 // session description. It creates a remote MediaStreamTrackInterface
706 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800707 void OnRemoteSenderAdded(const RtpSenderInfo& sender_info,
Karl Wiberg744310f2019-02-14 10:18:56 +0100708 cricket::MediaType media_type)
709 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700710
Steve Anton4171afb2017-11-20 10:20:22 -0800711 // Triggered when a remote sender has been removed from a remote session
712 // description. It removes the remote sender with id |sender_id| from a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700713 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800714 void OnRemoteSenderRemoved(const RtpSenderInfo& sender_info,
Karl Wiberg744310f2019-02-14 10:18:56 +0100715 cricket::MediaType media_type)
716 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700717
718 // Finds remote MediaStreams without any tracks and removes them from
719 // |remote_streams_| and notifies the observer that the MediaStreams no longer
720 // exist.
Karl Wiberg744310f2019-02-14 10:18:56 +0100721 void UpdateEndedRemoteMediaStreams() RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700722
deadbeefab9b2d12015-10-14 11:33:11 -0700723 // Loops through the vector of |streams| and finds added and removed
724 // StreamParams since last time this method was called.
Steve Anton4171afb2017-11-20 10:20:22 -0800725 // For each new or removed StreamParam, OnLocalSenderSeen or
726 // OnLocalSenderRemoved is invoked.
727 void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams,
Karl Wiberg5966c502019-02-21 23:55:09 +0100728 cricket::MediaType media_type)
729 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700730
Steve Anton4171afb2017-11-20 10:20:22 -0800731 // Triggered when a local sender has been seen for the first time in a local
deadbeefab9b2d12015-10-14 11:33:11 -0700732 // session description.
733 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
734 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
735 // in a MediaStream in |local_streams_|
Steve Anton4171afb2017-11-20 10:20:22 -0800736 void OnLocalSenderAdded(const RtpSenderInfo& sender_info,
Karl Wiberg5966c502019-02-21 23:55:09 +0100737 cricket::MediaType media_type)
738 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700739
Steve Anton4171afb2017-11-20 10:20:22 -0800740 // Triggered when a local sender has been removed from a local session
deadbeefab9b2d12015-10-14 11:33:11 -0700741 // description.
742 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
743 // has been removed from the local SessionDescription and the stream can be
744 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
Steve Anton4171afb2017-11-20 10:20:22 -0800745 void OnLocalSenderRemoved(const RtpSenderInfo& sender_info,
Karl Wiberga58e1692019-03-26 13:33:43 +0100746 cricket::MediaType media_type)
747 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700748
Karl Wiberg85a4a932019-03-22 15:29:58 +0100749 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams)
750 RTC_RUN_ON(signaling_thread());
Karl Wiberg106d92d2019-02-14 10:17:47 +0100751 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams)
752 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700753 void UpdateClosingRtpDataChannels(
754 const std::vector<std::string>& active_channels,
Karl Wiberg85a4a932019-03-22 15:29:58 +0100755 bool is_local_update) RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700756 void CreateRemoteRtpDataChannel(const std::string& label,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100757 uint32_t remote_ssrc)
758 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700759
760 // Creates channel and adds it to the collection of DataChannels that will
761 // be offered in a SessionDescription.
762 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
763 const std::string& label,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100764 const InternalDataChannelInit* config) RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700765
766 // Checks if any data channel has been added.
Karl Wiberg85a4a932019-03-22 15:29:58 +0100767 bool HasDataChannels() const RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700768
Karl Wiberg85a4a932019-03-22 15:29:58 +0100769 void AllocateSctpSids(rtc::SSLRole role) RTC_RUN_ON(signaling_thread());
770 void OnSctpDataChannelClosed(DataChannel* channel)
771 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700772
Karl Wiberg85a4a932019-03-22 15:29:58 +0100773 void OnDataChannelDestroyed() RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 10:21:57 -0800774 // Called when a valid data channel OPEN message is received.
deadbeefab9b2d12015-10-14 11:33:11 -0700775 void OnDataChannelOpenMessage(const std::string& label,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100776 const InternalDataChannelInit& config)
777 RTC_RUN_ON(signaling_thread());
778
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800779 // Parses and handles open messages. Returns true if the message is an open
780 // message, false otherwise.
781 bool HandleOpenMessage_s(const cricket::ReceiveDataParams& params,
782 const rtc::CopyOnWriteBuffer& buffer)
783 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700784
Steve Anton4171afb2017-11-20 10:20:22 -0800785 // Returns true if the PeerConnection is configured to use Unified Plan
786 // semantics for creating offers/answers and setting local/remote
787 // descriptions. If this is true the RtpTransceiver API will also be available
788 // to the user. If this is false, Plan B semantics are assumed.
Steve Anton79e79602017-11-20 10:25:56 -0800789 // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once
790 // sufficient time has passed.
Karl Wiberg5966c502019-02-21 23:55:09 +0100791 bool IsUnifiedPlan() const RTC_RUN_ON(signaling_thread()) {
Steve Anton79e79602017-11-20 10:25:56 -0800792 return configuration_.sdp_semantics == SdpSemantics::kUnifiedPlan;
793 }
Steve Anton4171afb2017-11-20 10:20:22 -0800794
Steve Anton06817cd2018-12-18 15:55:30 -0800795 // The offer/answer machinery assumes the media section MID is present and
796 // unique. To support legacy end points that do not supply a=mid lines, this
797 // method will modify the session description to add MIDs generated according
798 // to the SDP semantics.
Karl Wiberg5966c502019-02-21 23:55:09 +0100799 void FillInMissingRemoteMids(cricket::SessionDescription* remote_description)
800 RTC_RUN_ON(signaling_thread());
Steve Anton06817cd2018-12-18 15:55:30 -0800801
Steve Anton4171afb2017-11-20 10:20:22 -0800802 // Is there an RtpSender of the given type?
Karl Wiberg5966c502019-02-21 23:55:09 +0100803 bool HasRtpSender(cricket::MediaType type) const
804 RTC_RUN_ON(signaling_thread());
deadbeeffac06552015-11-25 11:26:01 -0800805
Steve Anton4171afb2017-11-20 10:20:22 -0800806 // Return the RtpSender with the given track attached.
807 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100808 FindSenderForTrack(MediaStreamTrackInterface* track) const
809 RTC_RUN_ON(signaling_thread());
deadbeef70ab1a12015-09-28 16:53:55 -0700810
Steve Anton4171afb2017-11-20 10:20:22 -0800811 // Return the RtpSender with the given id, or null if none exists.
812 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100813 FindSenderById(const std::string& sender_id) const
814 RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800815
816 // Return the RtpReceiver with the given id, or null if none exists.
817 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100818 FindReceiverById(const std::string& receiver_id) const
819 RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800820
821 std::vector<RtpSenderInfo>* GetRemoteSenderInfos(
822 cricket::MediaType media_type);
823 std::vector<RtpSenderInfo>* GetLocalSenderInfos(
824 cricket::MediaType media_type);
825 const RtpSenderInfo* FindSenderInfo(const std::vector<RtpSenderInfo>& infos,
Emircan Uysalerbc609ea2018-03-27 21:57:18 +0000826 const std::string& stream_id,
Steve Anton4171afb2017-11-20 10:20:22 -0800827 const std::string sender_id) const;
deadbeefab9b2d12015-10-14 11:33:11 -0700828
829 // Returns the specified SCTP DataChannel in sctp_data_channels_,
830 // or nullptr if not found.
Karl Wiberg85a4a932019-03-22 15:29:58 +0100831 DataChannel* FindDataChannelBySid(int sid) const
832 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700833
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700834 // Called when first configuring the port allocator.
Karl Wibergfb3be392019-03-22 14:13:22 +0100835 struct InitializePortAllocatorResult {
836 bool enable_ipv6;
837 };
838 InitializePortAllocatorResult InitializePortAllocator_n(
Harald Alvestrandb2a74782018-06-28 13:54:07 +0200839 const cricket::ServerAddresses& stun_servers,
840 const std::vector<cricket::RelayServerConfig>& turn_servers,
841 const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 12:28:30 -0800842 // Called when SetConfiguration is called to apply the supported subset
843 // of the configuration on the network thread.
844 bool ReconfigurePortAllocator_n(
845 const cricket::ServerAddresses& stun_servers,
846 const std::vector<cricket::RelayServerConfig>& turn_servers,
847 IceTransportsType type,
848 int candidate_pool_size,
Jonas Orelandbdcee282017-10-10 14:01:40 +0200849 bool prune_turn_ports,
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800850 webrtc::TurnCustomizer* turn_customizer,
Karl Wiberg739506e2019-04-03 11:37:28 +0200851 absl::optional<int> stun_candidate_keepalive_interval,
852 bool have_local_description);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700853
Elad Alon99c3fe52017-10-13 16:29:40 +0200854 // Starts output of an RTC event log to the given output object.
ivoc14d5dbe2016-07-04 07:06:55 -0700855 // This function should only be called from the worker thread.
Bjorn Tereliusde939432017-11-20 17:38:14 +0100856 bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output,
857 int64_t output_period_ms);
Elad Alon99c3fe52017-10-13 16:29:40 +0200858
Elad Alonacb24172017-10-06 14:32:13 +0200859 // Stops recording an RTC event log.
ivoc14d5dbe2016-07-04 07:06:55 -0700860 // This function should only be called from the worker thread.
861 void StopRtcEventLog_w();
862
Steve Anton038834f2017-07-14 15:59:59 -0700863 // Ensures the configuration doesn't have any parameters with invalid values,
864 // or values that conflict with other parameters.
865 //
866 // Returns RTCError::OK() if there are no issues.
867 RTCError ValidateConfiguration(const RTCConfiguration& config) const;
868
Steve Antonba818672017-11-06 10:21:57 -0800869 cricket::ChannelManager* channel_manager() const;
Steve Antonba818672017-11-06 10:21:57 -0800870
Steve Antonf8470812017-12-04 10:46:21 -0800871 enum class SessionError {
872 kNone, // No error.
873 kContent, // Error in BaseChannel SetLocalContent/SetRemoteContent.
874 kTransport, // Error from the underlying transport.
875 };
876
Steve Anton75737c02017-11-06 10:37:17 -0800877 // Returns the last error in the session. See the enum above for details.
Karl Wiberga58e1692019-03-26 13:33:43 +0100878 SessionError session_error() const RTC_RUN_ON(signaling_thread()) {
879 return session_error_;
880 }
Steve Antonf8470812017-12-04 10:46:21 -0800881 const std::string& session_error_desc() const { return session_error_desc_; }
Steve Anton75737c02017-11-06 10:37:17 -0800882
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800883 cricket::ChannelInterface* GetChannel(const std::string& content_name);
Steve Anton75737c02017-11-06 10:37:17 -0800884
885 // Get current SSL role used by SCTP's underlying transport.
886 bool GetSctpSslRole(rtc::SSLRole* role);
887
Steve Anton75737c02017-11-06 10:37:17 -0800888 cricket::IceConfig ParseIceConfig(
889 const PeerConnectionInterface::RTCConfiguration& config) const;
890
Steve Anton75737c02017-11-06 10:37:17 -0800891 // Implements DataChannelProviderInterface.
892 bool SendData(const cricket::SendDataParams& params,
893 const rtc::CopyOnWriteBuffer& payload,
894 cricket::SendDataResult* result) override;
895 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override;
896 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override;
897 void AddSctpDataStream(int sid) override;
898 void RemoveSctpDataStream(int sid) override;
899 bool ReadyToSendData() const override;
900
901 cricket::DataChannelType data_channel_type() const;
902
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800903 // Implements DataChannelSink.
904 void OnDataReceived(int channel_id,
905 DataMessageType type,
906 const rtc::CopyOnWriteBuffer& buffer) override;
907 void OnChannelClosing(int channel_id) override;
908 void OnChannelClosed(int channel_id) override;
909
Steve Anton75737c02017-11-06 10:37:17 -0800910 // Called when an RTCCertificate is generated or retrieved by
911 // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription.
912 void OnCertificateReady(
913 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
914 void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp);
915
Steve Anton75737c02017-11-06 10:37:17 -0800916 // Non-const versions of local_description()/remote_description(), for use
917 // internally.
Karl Wiberg739506e2019-04-03 11:37:28 +0200918 SessionDescriptionInterface* mutable_local_description()
919 RTC_RUN_ON(signaling_thread()) {
Steve Anton75737c02017-11-06 10:37:17 -0800920 return pending_local_description_ ? pending_local_description_.get()
921 : current_local_description_.get();
922 }
Karl Wiberg739506e2019-04-03 11:37:28 +0200923 SessionDescriptionInterface* mutable_remote_description()
924 RTC_RUN_ON(signaling_thread()) {
Steve Anton75737c02017-11-06 10:37:17 -0800925 return pending_remote_description_ ? pending_remote_description_.get()
926 : current_remote_description_.get();
927 }
928
929 // Updates the error state, signaling if necessary.
Steve Antonf8470812017-12-04 10:46:21 -0800930 void SetSessionError(SessionError error, const std::string& error_desc);
Steve Anton75737c02017-11-06 10:37:17 -0800931
Zhi Huange830e682018-03-30 10:48:35 -0700932 RTCError UpdateSessionState(SdpType type,
933 cricket::ContentSource source,
934 const cricket::SessionDescription* description);
Steve Anton75737c02017-11-06 10:37:17 -0800935 // Push the media parts of the local or remote session description
936 // down to all of the channels.
Karl Wiberg5966c502019-02-21 23:55:09 +0100937 RTCError PushdownMediaDescription(SdpType type, cricket::ContentSource source)
938 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800939
Steve Anton8a006912017-12-04 15:25:56 -0800940 RTCError PushdownTransportDescription(cricket::ContentSource source,
Steve Anton3828c062017-12-06 10:34:51 -0800941 SdpType type);
Steve Anton75737c02017-11-06 10:37:17 -0800942
943 // Returns true and the TransportInfo of the given |content_name|
944 // from |description|. Returns false if it's not available.
945 static bool GetTransportDescription(
946 const cricket::SessionDescription* description,
947 const std::string& content_name,
948 cricket::TransportDescription* info);
949
Steve Anton75737c02017-11-06 10:37:17 -0800950 // Enables media channels to allow sending of media.
Steve Antoned10bd92017-12-05 10:52:59 -0800951 // This enables media to flow on all configured audio/video channels and the
952 // RtpDataChannel.
Karl Wiberga58e1692019-03-26 13:33:43 +0100953 void EnableSending() RTC_RUN_ON(signaling_thread());
Steve Anton3fe1b152017-12-12 10:20:08 -0800954
Steve Anton8af21862017-12-15 11:20:13 -0800955 // Destroys all BaseChannels and destroys the SCTP data channel, if present.
Karl Wiberg85a4a932019-03-22 15:29:58 +0100956 void DestroyAllChannels() RTC_RUN_ON(signaling_thread());
Steve Anton3fe1b152017-12-12 10:20:08 -0800957
Steve Anton75737c02017-11-06 10:37:17 -0800958 // Returns the media index for a local ice candidate given the content name.
959 // Returns false if the local session description does not have a media
960 // content called |content_name|.
961 bool GetLocalCandidateMediaIndex(const std::string& content_name,
Karl Wiberg739506e2019-04-03 11:37:28 +0200962 int* sdp_mline_index)
963 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800964 // Uses all remote candidates in |remote_desc| in this session.
965 bool UseCandidatesInSessionDescription(
Karl Wiberg744310f2019-02-14 10:18:56 +0100966 const SessionDescriptionInterface* remote_desc)
967 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800968 // Uses |candidate| in this session.
Karl Wiberg744310f2019-02-14 10:18:56 +0100969 bool UseCandidate(const IceCandidateInterface* candidate)
970 RTC_RUN_ON(signaling_thread());
Guido Urdaneta41633172019-05-23 20:12:29 +0200971 RTCErrorOr<const cricket::ContentInfo*> FindContentInfo(
972 const SessionDescriptionInterface* description,
973 const IceCandidateInterface* candidate) RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800974 // Deletes the corresponding channel of contents that don't exist in |desc|.
975 // |desc| can be null. This means that all channels are deleted.
Karl Wiberg5966c502019-02-21 23:55:09 +0100976 void RemoveUnusedChannels(const cricket::SessionDescription* desc)
977 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800978
979 // Allocates media channels based on the |desc|. If |desc| doesn't have
980 // the BUNDLE option, this method will disable BUNDLE in PortAllocator.
981 // This method will also delete any existing media channels before creating.
Karl Wiberg5966c502019-02-21 23:55:09 +0100982 RTCError CreateChannels(const cricket::SessionDescription& desc)
983 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800984
985 // If the BUNDLE policy is max-bundle, then we know for sure that all
986 // transports will be bundled from the start. This method returns the BUNDLE
987 // group if that's the case, or null if BUNDLE will be negotiated later. An
988 // error is returned if max-bundle is specified but the session description
989 // does not have a BUNDLE group.
990 RTCErrorOr<const cricket::ContentGroup*> GetEarlyBundleGroup(
Karl Wiberg5966c502019-02-21 23:55:09 +0100991 const cricket::SessionDescription& desc) const
992 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800993
994 // Helper methods to create media channels.
Karl Wiberg5966c502019-02-21 23:55:09 +0100995 cricket::VoiceChannel* CreateVoiceChannel(const std::string& mid)
996 RTC_RUN_ON(signaling_thread());
997 cricket::VideoChannel* CreateVideoChannel(const std::string& mid)
998 RTC_RUN_ON(signaling_thread());
999 bool CreateDataChannel(const std::string& mid) RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001000
Zhi Huange830e682018-03-30 10:48:35 -07001001 bool CreateSctpTransport_n(const std::string& mid);
Steve Anton75737c02017-11-06 10:37:17 -08001002 // For bundling.
Steve Anton75737c02017-11-06 10:37:17 -08001003 void DestroySctpTransport_n();
1004 // SctpTransport signal handlers. Needed to marshal signals from the network
1005 // to signaling thread.
1006 void OnSctpTransportReadyToSendData_n();
1007 // This may be called with "false" if the direction of the m= section causes
1008 // us to tear down the SCTP connection.
1009 void OnSctpTransportReadyToSendData_s(bool ready);
1010 void OnSctpTransportDataReceived_n(const cricket::ReceiveDataParams& params,
1011 const rtc::CopyOnWriteBuffer& payload);
1012 // Beyond just firing the signal to the signaling thread, listens to SCTP
1013 // CONTROL messages on unused SIDs and processes them as OPEN messages.
1014 void OnSctpTransportDataReceived_s(const cricket::ReceiveDataParams& params,
1015 const rtc::CopyOnWriteBuffer& payload);
Taylor Brandstettercdd05f02018-05-31 13:23:32 -07001016 void OnSctpClosingProcedureStartedRemotely_n(int sid);
1017 void OnSctpClosingProcedureComplete_n(int sid);
Steve Anton75737c02017-11-06 10:37:17 -08001018
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001019 bool SetupMediaTransportForDataChannels_n(const std::string& mid)
1020 RTC_RUN_ON(network_thread());
1021 void OnMediaTransportStateChanged_n() RTC_RUN_ON(network_thread());
1022 void TeardownMediaTransportForDataChannels_n() RTC_RUN_ON(network_thread());
1023
Steve Anton75737c02017-11-06 10:37:17 -08001024 bool ValidateBundleSettings(const cricket::SessionDescription* desc);
1025 bool HasRtcpMuxEnabled(const cricket::ContentInfo* content);
1026 // Below methods are helper methods which verifies SDP.
Steve Anton8a006912017-12-04 15:25:56 -08001027 RTCError ValidateSessionDescription(const SessionDescriptionInterface* sdesc,
Karl Wiberg5966c502019-02-21 23:55:09 +01001028 cricket::ContentSource source)
1029 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001030
Steve Anton3828c062017-12-06 10:34:51 -08001031 // Check if a call to SetLocalDescription is acceptable with a session
1032 // description of the given type.
1033 bool ExpectSetLocalDescription(SdpType type);
1034 // Check if a call to SetRemoteDescription is acceptable with a session
1035 // description of the given type.
1036 bool ExpectSetRemoteDescription(SdpType type);
Steve Anton75737c02017-11-06 10:37:17 -08001037 // Verifies a=setup attribute as per RFC 5763.
1038 bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc,
Steve Anton3828c062017-12-06 10:34:51 -08001039 SdpType type);
Steve Anton75737c02017-11-06 10:37:17 -08001040
1041 // Returns true if we are ready to push down the remote candidate.
1042 // |remote_desc| is the new remote description, or NULL if the current remote
1043 // description should be used. Output |valid| is true if the candidate media
1044 // index is valid.
1045 bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate,
1046 const SessionDescriptionInterface* remote_desc,
Karl Wiberga58e1692019-03-26 13:33:43 +01001047 bool* valid) RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001048
1049 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
1050 // this session.
Karl Wiberg739506e2019-04-03 11:37:28 +02001051 bool SrtpRequired() const RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001052
Zhi Huange830e682018-03-30 10:48:35 -07001053 // JsepTransportController signal handlers.
Karl Wiberg744310f2019-02-14 10:18:56 +01001054 void OnTransportControllerConnectionState(cricket::IceConnectionState state)
1055 RTC_RUN_ON(signaling_thread());
1056 void OnTransportControllerGatheringState(cricket::IceGatheringState state)
1057 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001058 void OnTransportControllerCandidatesGathered(
1059 const std::string& transport_name,
Karl Wiberg744310f2019-02-14 10:18:56 +01001060 const std::vector<cricket::Candidate>& candidates)
1061 RTC_RUN_ON(signaling_thread());
Eldar Relloda13ea22019-06-01 12:23:43 +03001062 void OnTransportControllerCandidateError(
1063 const cricket::IceCandidateErrorEvent& event)
1064 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001065 void OnTransportControllerCandidatesRemoved(
Karl Wiberg744310f2019-02-14 10:18:56 +01001066 const std::vector<cricket::Candidate>& candidates)
1067 RTC_RUN_ON(signaling_thread());
Alex Drake00c7ecf2019-08-06 10:54:47 -07001068 void OnTransportControllerCandidateChanged(
1069 const cricket::CandidatePairChangeEvent& event)
1070 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001071 void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error);
1072
Steve Antonf8470812017-12-04 10:46:21 -08001073 const char* SessionErrorToString(SessionError error) const;
Karl Wiberga58e1692019-03-26 13:33:43 +01001074 std::string GetSessionErrorMsg() RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001075
Steve Anton8e20f172018-03-06 10:55:04 -08001076 // Report the UMA metric SdpFormatReceived for the given remote offer.
1077 void ReportSdpFormatReceived(const SessionDescriptionInterface& remote_offer);
1078
Steve Anton0ffaaa22018-02-23 10:31:30 -08001079 // Report inferred negotiated SDP semantics from a local/remote answer to the
1080 // UMA observer.
1081 void ReportNegotiatedSdpSemantics(const SessionDescriptionInterface& answer);
1082
Steve Anton75737c02017-11-06 10:37:17 -08001083 // Invoked when TransportController connection completion is signaled.
1084 // Reports stats for all transports in use.
Karl Wiberga58e1692019-03-26 13:33:43 +01001085 void ReportTransportStats() RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001086
1087 // Gather the usage of IPv4/IPv6 as best connection.
1088 void ReportBestConnectionState(const cricket::TransportStats& stats);
1089
Steve Antonc7b964c2018-02-01 14:39:45 -08001090 void ReportNegotiatedCiphers(const cricket::TransportStats& stats,
Karl Wiberg739506e2019-04-03 11:37:28 +02001091 const std::set<cricket::MediaType>& media_types)
1092 RTC_RUN_ON(signaling_thread());
Qingsi Wang1ba5dec2019-08-19 11:57:17 -07001093 void ReportIceCandidateCollected(const cricket::Candidate& candidate)
1094 RTC_RUN_ON(signaling_thread());
1095 void ReportRemoteIceCandidateAdded(const cricket::Candidate& candidate)
1096 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001097
Harald Alvestrand8ebba742018-05-31 14:00:34 +02001098 void NoteUsageEvent(UsageEvent event);
Karl Wiberg744310f2019-02-14 10:18:56 +01001099 void ReportUsagePattern() const RTC_RUN_ON(signaling_thread());
Harald Alvestrand8ebba742018-05-31 14:00:34 +02001100
Steve Anton75737c02017-11-06 10:37:17 -08001101 void OnSentPacket_w(const rtc::SentPacket& sent_packet);
1102
Karl Wiberga58e1692019-03-26 13:33:43 +01001103 const std::string GetTransportName(const std::string& content_name)
1104 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001105
Steve Anton6fec8802017-12-04 10:37:29 -08001106 // Destroys and clears the BaseChannel associated with the given transceiver,
1107 // if such channel is set.
1108 void DestroyTransceiverChannel(
1109 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
1110 transceiver);
1111
1112 // Destroys the RTP data channel and/or the SCTP data channel and clears it.
Karl Wiberg85a4a932019-03-22 15:29:58 +01001113 void DestroyDataChannel() RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001114
Amit Hilbuchdd9390c2018-11-13 16:26:05 -08001115 // Destroys the given ChannelInterface.
1116 // The channel cannot be accessed after this method is called.
1117 void DestroyChannelInterface(cricket::ChannelInterface* channel);
Steve Anton6fec8802017-12-04 10:37:29 -08001118
Zhi Huang365381f2018-04-13 16:44:34 -07001119 // JsepTransportController::Observer override.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -07001120 //
1121 // Called by |transport_controller_| when processing transport information
1122 // from a session description, and the mapping from m= sections to transports
1123 // changed (as a result of BUNDLE negotiation, or m= sections being
1124 // rejected).
Piotr (Peter) Slatalacc8e8bb2018-11-15 08:26:19 -08001125 bool OnTransportChanged(const std::string& mid,
1126 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +01001127 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Karl Wibergac025892019-03-26 13:08:37 +01001128 MediaTransportInterface* media_transport) override;
Zhi Huange830e682018-03-30 10:48:35 -07001129
Guido Urdaneta1ff16c82019-05-20 19:31:53 +02001130 // RtpSenderBase::SetStreamsObserver override.
1131 void OnSetStreams() override;
1132
Harald Alvestrand7a1c7f72018-08-01 10:50:16 +02001133 // Returns the observer. Will crash on CHECK if the observer is removed.
Karl Wiberg744310f2019-02-14 10:18:56 +01001134 PeerConnectionObserver* Observer() const RTC_RUN_ON(signaling_thread());
Harald Alvestrand7a1c7f72018-08-01 10:50:16 +02001135
Benjamin Wright8c27cca2018-10-25 10:16:44 -07001136 // Returns the CryptoOptions for this PeerConnection. This will always
1137 // return the RTCConfiguration.crypto_options if set and will only default
1138 // back to the PeerConnectionFactory settings if nothing was set.
Karl Wiberg5966c502019-02-21 23:55:09 +01001139 CryptoOptions GetCryptoOptions() RTC_RUN_ON(signaling_thread());
Benjamin Wright8c27cca2018-10-25 10:16:44 -07001140
Anton Sukhanov98a462c2018-10-17 13:15:42 -07001141 // Returns rtp transport, result can not be nullptr.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001142 RtpTransportInternal* GetRtpTransport(const std::string& mid)
1143 RTC_RUN_ON(signaling_thread()) {
Anton Sukhanov98a462c2018-10-17 13:15:42 -07001144 auto rtp_transport = transport_controller_->GetRtpTransport(mid);
1145 RTC_DCHECK(rtp_transport);
1146 return rtp_transport;
1147 }
1148
Guido Urdaneta70c2db12019-04-16 12:24:14 +02001149 void UpdateNegotiationNeeded();
1150 bool CheckIfNegotiationIsNeeded();
1151
Karl Wiberg106d92d2019-02-14 10:17:47 +01001152 sigslot::signal1<DataChannel*> SignalDataChannelCreated_
1153 RTC_GUARDED_BY(signaling_thread());
Steve Anton2d8609c2018-01-23 16:38:46 -08001154
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 // Storing the factory as a scoped reference pointer ensures that the memory
1156 // in the PeerConnectionFactoryImpl remains available as long as the
1157 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
1158 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -07001159 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001160 // will refer to the same reference count.
Karl Wiberg744310f2019-02-14 10:18:56 +01001161 const rtc::scoped_refptr<PeerConnectionFactory> factory_;
1162 PeerConnectionObserver* observer_ RTC_GUARDED_BY(signaling_thread()) =
1163 nullptr;
terelius33860252017-05-12 23:37:18 -07001164
1165 // The EventLog needs to outlive |call_| (and any other object that uses it).
Karl Wibergb03ab712019-02-14 11:59:57 +01001166 std::unique_ptr<RtcEventLog> event_log_ RTC_GUARDED_BY(worker_thread());
1167
1168 // Points to the same thing as `event_log_`. Since it's const, we may read the
1169 // pointer (but not touch the object) from any thread.
1170 RtcEventLog* const event_log_ptr_ RTC_PT_GUARDED_BY(worker_thread());
terelius33860252017-05-12 23:37:18 -07001171
Karl Wiberg8d2e2282019-02-17 13:00:07 +01001172 SignalingState signaling_state_ RTC_GUARDED_BY(signaling_thread()) = kStable;
1173 IceConnectionState ice_connection_state_ RTC_GUARDED_BY(signaling_thread()) =
1174 kIceConnectionNew;
1175 PeerConnectionInterface::IceConnectionState standardized_ice_connection_state_
1176 RTC_GUARDED_BY(signaling_thread()) = kIceConnectionNew;
1177 PeerConnectionInterface::PeerConnectionState connection_state_
1178 RTC_GUARDED_BY(signaling_thread()) = PeerConnectionState::kNew;
Jonas Olsson635474e2018-10-18 15:58:17 +02001179
Karl Wiberg8d2e2282019-02-17 13:00:07 +01001180 IceGatheringState ice_gathering_state_ RTC_GUARDED_BY(signaling_thread()) =
1181 kIceGatheringNew;
Karl Wiberg5966c502019-02-21 23:55:09 +01001182 PeerConnectionInterface::RTCConfiguration configuration_
1183 RTC_GUARDED_BY(signaling_thread());
1184
Bjorn A Mellem5985a042019-06-28 14:19:38 -07001185 // Field-trial based configuration for datagram transport.
1186 const DatagramTransportConfig datagram_transport_config_;
1187
1188 // Final, resolved value for whether datagram transport is in use.
1189 bool use_datagram_transport_ RTC_GUARDED_BY(signaling_thread()) = false;
1190
Karl Wiberg5966c502019-02-21 23:55:09 +01001191 // Cache configuration_.use_media_transport so that we can access it from
1192 // other threads.
1193 // TODO(bugs.webrtc.org/9987): Caching just this bool and allowing the data
1194 // it's derived from to change is not necessarily sound. Stop doing it.
1195 rtc::RaceChecker use_media_transport_race_checker_;
1196 bool use_media_transport_ RTC_GUARDED_BY(use_media_transport_race_checker_) =
1197 configuration_.use_media_transport;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198
Zach Steine20867f2018-08-02 13:20:15 -07001199 // TODO(zstein): |async_resolver_factory_| can currently be nullptr if it
1200 // is not injected. It should be required once chromium supplies it.
Karl Wibergfb3be392019-03-22 14:13:22 +01001201 std::unique_ptr<AsyncResolverFactory> async_resolver_factory_
1202 RTC_GUARDED_BY(signaling_thread());
1203 std::unique_ptr<cricket::PortAllocator>
1204 port_allocator_; // TODO(bugs.webrtc.org/9987): Accessed on both
1205 // signaling and network thread.
1206 std::unique_ptr<rtc::SSLCertificateVerifier>
1207 tls_cert_verifier_; // TODO(bugs.webrtc.org/9987): Accessed on both
1208 // signaling and network thread.
deadbeefab9b2d12015-10-14 11:33:11 -07001209
zhihuang8f65cdf2016-05-06 18:40:30 -07001210 // One PeerConnection has only one RTCP CNAME.
1211 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
Karl Wibergfb3be392019-03-22 14:13:22 +01001212 const std::string rtcp_cname_;
zhihuang8f65cdf2016-05-06 18:40:30 -07001213
deadbeefab9b2d12015-10-14 11:33:11 -07001214 // Streams added via AddStream.
Karl Wiberg1e1e1022019-03-22 14:27:22 +01001215 const rtc::scoped_refptr<StreamCollection> local_streams_
1216 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001217 // Streams created as a result of SetRemoteDescription.
Karl Wiberg1e1e1022019-03-22 14:27:22 +01001218 const rtc::scoped_refptr<StreamCollection> remote_streams_
1219 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001220
Karl Wiberg1e1e1022019-03-22 14:27:22 +01001221 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_
1222 RTC_GUARDED_BY(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -08001223
Steve Anton4171afb2017-11-20 10:20:22 -08001224 // These lists store sender info seen in local/remote descriptions.
Karl Wibergc70999e2019-03-22 15:14:27 +01001225 std::vector<RtpSenderInfo> remote_audio_sender_infos_
1226 RTC_GUARDED_BY(signaling_thread());
1227 std::vector<RtpSenderInfo> remote_video_sender_infos_
1228 RTC_GUARDED_BY(signaling_thread());
1229 std::vector<RtpSenderInfo> local_audio_sender_infos_
1230 RTC_GUARDED_BY(signaling_thread());
1231 std::vector<RtpSenderInfo> local_video_sender_infos_
1232 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001233
Karl Wiberg85a4a932019-03-22 15:29:58 +01001234 SctpSidAllocator sid_allocator_ RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001235 // label -> DataChannel
Karl Wiberg85a4a932019-03-22 15:29:58 +01001236 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_
1237 RTC_GUARDED_BY(signaling_thread());
1238 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_
1239 RTC_GUARDED_BY(signaling_thread());
1240 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_
1241 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001242
Karl Wiberg85a4a932019-03-22 15:29:58 +01001243 bool remote_peer_supports_msid_ RTC_GUARDED_BY(signaling_thread()) = false;
deadbeef70ab1a12015-09-28 16:53:55 -07001244
Karl Wibergac025892019-03-26 13:08:37 +01001245 // The unique_ptr belongs to the worker thread, but the Call object manages
1246 // its own thread safety.
Karl Wiberg6cab5c82019-03-26 09:57:01 +01001247 std::unique_ptr<Call> call_ RTC_GUARDED_BY(worker_thread());
1248
1249 // Points to the same thing as `call_`. Since it's const, we may read the
Karl Wibergac025892019-03-26 13:08:37 +01001250 // pointer from any thread.
1251 Call* const call_ptr_;
Karl Wiberg6cab5c82019-03-26 09:57:01 +01001252
1253 std::unique_ptr<StatsCollector> stats_
1254 RTC_GUARDED_BY(signaling_thread()); // A pointer is passed to senders_
1255 rtc::scoped_refptr<RTCStatsCollector> stats_collector_
1256 RTC_GUARDED_BY(signaling_thread());
terelius33860252017-05-12 23:37:18 -07001257
deadbeefa601f5c2016-06-06 14:27:39 -07001258 std::vector<
Steve Anton4171afb2017-11-20 10:20:22 -08001259 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001260 transceivers_; // TODO(bugs.webrtc.org/9987): Accessed on both signaling
1261 // and network thread.
1262
Henrik Boström5b147782018-12-04 11:25:05 +01001263 // In Unified Plan, if we encounter remote SDP that does not contain an a=msid
1264 // line we create and use a stream with a random ID for our receivers. This is
1265 // to support legacy endpoints that do not support the a=msid attribute (as
1266 // opposed to streamless tracks with "a=msid:-").
Karl Wiberga58e1692019-03-26 13:33:43 +01001267 rtc::scoped_refptr<MediaStreamInterface> missing_msid_default_stream_
1268 RTC_GUARDED_BY(signaling_thread());
Amit Hilbuchae3df542019-01-07 12:13:08 -08001269 // MIDs will be generated using this generator which will keep track of
1270 // all the MIDs that have been seen over the life of the PeerConnection.
Karl Wiberga58e1692019-03-26 13:33:43 +01001271 rtc::UniqueStringGenerator mid_generator_ RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001272
Karl Wiberga58e1692019-03-26 13:33:43 +01001273 SessionError session_error_ RTC_GUARDED_BY(signaling_thread()) =
1274 SessionError::kNone;
1275 std::string session_error_desc_ RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001276
Karl Wiberga58e1692019-03-26 13:33:43 +01001277 std::string session_id_ RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001278
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001279 std::unique_ptr<JsepTransportController>
1280 transport_controller_; // TODO(bugs.webrtc.org/9987): Accessed on both
1281 // signaling and network thread.
1282 std::unique_ptr<cricket::SctpTransportInternalFactory>
1283 sctp_factory_; // TODO(bugs.webrtc.org/9987): Accessed on both
1284 // signaling and network thread.
Steve Anton75737c02017-11-06 10:37:17 -08001285 // |rtp_data_channel_| is used if in RTP data channel mode, |sctp_transport_|
1286 // when using SCTP.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001287 cricket::RtpDataChannel* rtp_data_channel_ =
1288 nullptr; // TODO(bugs.webrtc.org/9987): Accessed on both
1289 // signaling and some other thread.
Steve Anton75737c02017-11-06 10:37:17 -08001290
Harald Alvestrandc85328f2019-02-28 07:51:00 +01001291 cricket::SctpTransportInternal* cricket_sctp_transport() {
1292 return sctp_transport_->internal();
1293 }
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001294 rtc::scoped_refptr<SctpTransport>
1295 sctp_transport_; // TODO(bugs.webrtc.org/9987): Accessed on both
1296 // signaling and network thread.
1297
Zhi Huange830e682018-03-30 10:48:35 -07001298 // |sctp_mid_| is the content name (MID) in SDP.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001299 absl::optional<std::string>
1300 sctp_mid_; // TODO(bugs.webrtc.org/9987): Accessed on both signaling
1301 // and network thread.
1302
Steve Anton75737c02017-11-06 10:37:17 -08001303 // Value cached on signaling thread. Only updated when SctpReadyToSendData
1304 // fires on the signaling thread.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001305 bool sctp_ready_to_send_data_ RTC_GUARDED_BY(signaling_thread()) = false;
1306
Steve Anton75737c02017-11-06 10:37:17 -08001307 // Same as signals provided by SctpTransport, but these are guaranteed to
1308 // fire on the signaling thread, whereas SctpTransport fires on the networking
1309 // thread.
1310 // |sctp_invoker_| is used so that any signals queued on the signaling thread
1311 // from the network thread are immediately discarded if the SctpTransport is
1312 // destroyed (due to m= section being rejected).
1313 // TODO(deadbeef): Use a proxy object to ensure that method calls/signals
1314 // are marshalled to the right thread. Could almost use proxy.h for this,
1315 // but it doesn't have a mechanism for marshalling sigslot::signals
Karl Wiberg7a651c6e2019-04-02 13:00:46 +02001316 std::unique_ptr<rtc::AsyncInvoker> sctp_invoker_
1317 RTC_GUARDED_BY(network_thread());
1318 sigslot::signal1<bool> SignalSctpReadyToSendData
1319 RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001320 sigslot::signal2<const cricket::ReceiveDataParams&,
1321 const rtc::CopyOnWriteBuffer&>
Karl Wiberg7a651c6e2019-04-02 13:00:46 +02001322 SignalSctpDataReceived RTC_GUARDED_BY(signaling_thread());
1323 sigslot::signal1<int> SignalSctpClosingProcedureStartedRemotely
1324 RTC_GUARDED_BY(signaling_thread());
1325 sigslot::signal1<int> SignalSctpClosingProcedureComplete
1326 RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001327
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001328 // Whether this peer is the caller. Set when the local description is applied.
1329 absl::optional<bool> is_caller_ RTC_GUARDED_BY(signaling_thread());
1330
1331 // Content name (MID) for media transport data channels in SDP.
Karl Wibergd9bf7202019-04-02 19:36:24 +02001332 absl::optional<std::string>
1333 media_transport_data_mid_; // TODO(bugs.webrtc.org/9987): Accessed on
1334 // both signaling and network thread.
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001335
1336 // Media transport used for data channels. Thread-safe.
Karl Wibergd9bf7202019-04-02 19:36:24 +02001337 MediaTransportInterface* media_transport_ =
1338 nullptr; // TODO(bugs.webrtc.org/9987): Object is thread safe, but
1339 // pointer accessed on both signaling and network thread.
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001340
1341 // Cached value of whether the media transport is ready to send.
1342 bool media_transport_ready_to_send_data_ RTC_GUARDED_BY(signaling_thread()) =
1343 false;
1344
1345 // Used to invoke media transport signals on the signaling thread.
Karl Wiberg739506e2019-04-03 11:37:28 +02001346 std::unique_ptr<rtc::AsyncInvoker> media_transport_invoker_
1347 RTC_GUARDED_BY(network_thread());
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001348
1349 // Identical to the signals for SCTP, but from media transport:
1350 sigslot::signal1<bool> SignalMediaTransportWritable_s
1351 RTC_GUARDED_BY(signaling_thread());
1352 sigslot::signal2<const cricket::ReceiveDataParams&,
1353 const rtc::CopyOnWriteBuffer&>
1354 SignalMediaTransportReceivedData_s RTC_GUARDED_BY(signaling_thread());
1355 sigslot::signal1<int> SignalMediaTransportChannelClosing_s
1356 RTC_GUARDED_BY(signaling_thread());
1357 sigslot::signal1<int> SignalMediaTransportChannelClosed_s
1358 RTC_GUARDED_BY(signaling_thread());
1359
Karl Wiberg739506e2019-04-03 11:37:28 +02001360 std::unique_ptr<SessionDescriptionInterface> current_local_description_
1361 RTC_GUARDED_BY(signaling_thread());
1362 std::unique_ptr<SessionDescriptionInterface> pending_local_description_
1363 RTC_GUARDED_BY(signaling_thread());
1364 std::unique_ptr<SessionDescriptionInterface> current_remote_description_
1365 RTC_GUARDED_BY(signaling_thread());
1366 std::unique_ptr<SessionDescriptionInterface> pending_remote_description_
1367 RTC_GUARDED_BY(signaling_thread());
1368 bool dtls_enabled_ RTC_GUARDED_BY(signaling_thread()) = false;
Steve Anton75737c02017-11-06 10:37:17 -08001369 // Specifies which kind of data channel is allowed. This is controlled
1370 // by the chrome command-line flag and constraints:
1371 // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled,
1372 // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is
1373 // not set or false, SCTP is allowed (DCT_SCTP);
1374 // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP);
1375 // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE).
Karl Wibergf73f7d62019-04-08 15:36:53 +02001376 cricket::DataChannelType data_channel_type_ =
1377 cricket::DCT_NONE; // TODO(bugs.webrtc.org/9987): Accessed on both
1378 // signaling and network thread.
Steve Anton75737c02017-11-06 10:37:17 -08001379
Karl Wibergf73f7d62019-04-08 15:36:53 +02001380 // List of content names for which the remote side triggered an ICE restart.
1381 std::set<std::string> pending_ice_restarts_
1382 RTC_GUARDED_BY(signaling_thread());
1383
1384 std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_
1385 RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001386
1387 // Member variables for caching global options.
Karl Wibergf73f7d62019-04-08 15:36:53 +02001388 cricket::AudioOptions audio_options_ RTC_GUARDED_BY(signaling_thread());
1389 cricket::VideoOptions video_options_ RTC_GUARDED_BY(signaling_thread());
Harald Alvestrand8ebba742018-05-31 14:00:34 +02001390
Karl Wibergf73f7d62019-04-08 15:36:53 +02001391 int usage_event_accumulator_ RTC_GUARDED_BY(signaling_thread()) = 0;
1392 bool return_histogram_very_quickly_ RTC_GUARDED_BY(signaling_thread()) =
1393 false;
Amit Hilbuchbcd39d42019-01-25 17:13:56 -08001394
1395 // This object should be used to generate any SSRC that is not explicitly
1396 // specified by the user (or by the remote party).
1397 // The generator is not used directly, instead it is passed on to the
1398 // channel manager and the session description factory.
Karl Wibergf73f7d62019-04-08 15:36:53 +02001399 rtc::UniqueRandomIdGenerator ssrc_generator_
1400 RTC_GUARDED_BY(signaling_thread());
Jonas Orelanda3aa9bd2019-04-17 07:38:40 +02001401
1402 // A video bitrate allocator factory.
1403 // This can injected using the PeerConnectionDependencies,
1404 // or else the CreateBuiltinVideoBitrateAllocatorFactory() will be called.
1405 // Note that one can still choose to override this in a MediaEngine
1406 // if one wants too.
1407 std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
1408 video_bitrate_allocator_factory_;
1409
Henrik Boström79b69802019-07-18 11:16:56 +02001410 std::unique_ptr<LocalIceCredentialsToReplace>
1411 local_ice_credentials_to_replace_ RTC_GUARDED_BY(signaling_thread());
Guido Urdaneta70c2db12019-04-16 12:24:14 +02001412 bool is_negotiation_needed_ RTC_GUARDED_BY(signaling_thread()) = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413};
1414
1415} // namespace webrtc
1416
Steve Anton10542f22019-01-11 09:11:00 -08001417#endif // PC_PEER_CONNECTION_H_