blob: 4e84b977d4ee276e278198e32027e0bb8cfcc596 [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:
Harald Alvestrand8ebba742018-05-31 14:00:34 +020067 enum class UsageEvent : int {
68 TURN_SERVER_ADDED = 0x01,
69 STUN_SERVER_ADDED = 0x02,
70 DATA_ADDED = 0x04,
71 AUDIO_ADDED = 0x08,
72 VIDEO_ADDED = 0x10,
73 SET_LOCAL_DESCRIPTION_CALLED = 0x20,
74 SET_REMOTE_DESCRIPTION_CALLED = 0x40,
75 CANDIDATE_COLLECTED = 0x80,
76 REMOTE_CANDIDATE_ADDED = 0x100,
77 ICE_STATE_CONNECTED = 0x200,
Qingsi Wang7fc821d2018-07-12 12:54:53 -070078 CLOSE_CALLED = 0x400,
Harald Alvestrand056d8112018-07-16 19:18:58 +020079 PRIVATE_CANDIDATE_COLLECTED = 0x800,
Jeroen de Borstaf242c82019-04-24 13:13:48 -070080 REMOTE_PRIVATE_CANDIDATE_ADDED = 0x1000,
81 MDNS_CANDIDATE_COLLECTED = 0x2000,
82 REMOTE_MDNS_CANDIDATE_ADDED = 0x4000,
83 MAX_VALUE = 0x8000,
Harald Alvestrand8ebba742018-05-31 14:00:34 +020084 };
85
zhihuang38ede132017-06-15 12:52:32 -070086 explicit PeerConnection(PeerConnectionFactory* factory,
87 std::unique_ptr<RtcEventLog> event_log,
88 std::unique_ptr<Call> call);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
deadbeef653b8e02015-11-11 12:55:10 -080090 bool Initialize(
91 const PeerConnectionInterface::RTCConfiguration& configuration,
Benjamin Wrightcab58882018-05-02 15:12:47 -070092 PeerConnectionDependencies dependencies);
deadbeef653b8e02015-11-11 12:55:10 -080093
deadbeefa67696b2015-09-29 11:56:26 -070094 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
95 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
96 bool AddStream(MediaStreamInterface* local_stream) override;
97 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098
Steve Anton2d6c76a2018-01-05 17:10:52 -080099 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
Steve Antonf9381f02017-12-14 10:23:57 -0800100 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Seth Hampson845e8782018-03-02 11:34:10 -0800101 const std::vector<std::string>& stream_ids) override;
deadbeefe1f9d832016-01-14 15:35:42 -0800102 bool RemoveTrack(RtpSenderInterface* sender) override;
Steve Anton24db5732018-07-23 10:27:33 -0700103 RTCError RemoveTrackNew(
104 rtc::scoped_refptr<RtpSenderInterface> sender) override;
deadbeefe1f9d832016-01-14 15:35:42 -0800105
Steve Anton9158ef62017-11-27 13:01:52 -0800106 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
107 rtc::scoped_refptr<MediaStreamTrackInterface> track) override;
108 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
109 rtc::scoped_refptr<MediaStreamTrackInterface> track,
110 const RtpTransceiverInit& init) override;
111 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
112 cricket::MediaType media_type) override;
113 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
114 cricket::MediaType media_type,
115 const RtpTransceiverInit& init) override;
116
Steve Anton8c0f7a72017-10-03 10:03:10 -0700117 // Gets the DTLS SSL certificate associated with the audio transport on the
118 // remote side. This will become populated once the DTLS connection with the
119 // peer has been completed, as indicated by the ICE connection state
120 // transitioning to kIceConnectionCompleted.
121 // Note that this will be removed once we implement RTCDtlsTransport which
122 // has standardized method for getting this information.
123 // See https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface
124 std::unique_ptr<rtc::SSLCertificate> GetRemoteAudioSSLCertificate();
125
Zhi Huang70b820f2018-01-27 14:16:15 -0800126 // Version of the above method that returns the full certificate chain.
127 std::unique_ptr<rtc::SSLCertChain> GetRemoteAudioSSLCertChain();
128
deadbeeffac06552015-11-25 11:26:01 -0800129 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800130 const std::string& kind,
131 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -0800132
deadbeef70ab1a12015-09-28 16:53:55 -0700133 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
134 const override;
135 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
136 const override;
Steve Anton9158ef62017-11-27 13:01:52 -0800137 std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers()
138 const override;
deadbeef70ab1a12015-09-28 16:53:55 -0700139
deadbeefa67696b2015-09-29 11:56:26 -0700140 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700142 const DataChannelInit* config) override;
Henrik Boström1df1bf82018-03-20 13:24:20 +0100143 // WARNING: LEGACY. See peerconnectioninterface.h
deadbeefa67696b2015-09-29 11:56:26 -0700144 bool GetStats(StatsObserver* observer,
145 webrtc::MediaStreamTrackInterface* track,
146 StatsOutputLevel level) override;
Henrik Boström1df1bf82018-03-20 13:24:20 +0100147 // Spec-complaint GetStats(). See peerconnectioninterface.h
hbos74e1a4f2016-09-15 23:33:01 -0700148 void GetStats(RTCStatsCollectorCallback* callback) override;
Henrik Boström1df1bf82018-03-20 13:24:20 +0100149 void GetStats(
150 rtc::scoped_refptr<RtpSenderInterface> selector,
151 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override;
152 void GetStats(
153 rtc::scoped_refptr<RtpReceiverInterface> selector,
154 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override;
Harald Alvestrand89061872018-01-02 14:08:34 +0100155 void ClearStatsCache() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156
deadbeefa67696b2015-09-29 11:56:26 -0700157 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158
deadbeefa67696b2015-09-29 11:56:26 -0700159 IceConnectionState ice_connection_state() override;
Jonas Olsson12046902018-12-06 11:25:14 +0100160 IceConnectionState standardized_ice_connection_state() override;
Jonas Olsson635474e2018-10-18 15:58:17 +0200161 PeerConnectionState peer_connection_state() override;
deadbeefa67696b2015-09-29 11:56:26 -0700162 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163
deadbeefa67696b2015-09-29 11:56:26 -0700164 const SessionDescriptionInterface* local_description() const override;
165 const SessionDescriptionInterface* remote_description() const override;
deadbeeffe4a8a42016-12-20 17:56:17 -0800166 const SessionDescriptionInterface* current_local_description() const override;
167 const SessionDescriptionInterface* current_remote_description()
168 const override;
169 const SessionDescriptionInterface* pending_local_description() const override;
170 const SessionDescriptionInterface* pending_remote_description()
171 const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172
Henrik Boström79b69802019-07-18 11:16:56 +0200173 void RestartIce() override;
174
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 // JSEP01
deadbeefa67696b2015-09-29 11:56:26 -0700176 void CreateOffer(CreateSessionDescriptionObserver* observer,
177 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800178 void CreateAnswer(CreateSessionDescriptionObserver* observer,
179 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700180 void SetLocalDescription(SetSessionDescriptionObserver* observer,
181 SessionDescriptionInterface* desc) override;
Henrik Boströma4ecf552017-11-23 14:17:07 +0000182 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
183 SessionDescriptionInterface* desc) override;
Henrik Boström31638672017-11-23 17:48:32 +0100184 void SetRemoteDescription(
185 std::unique_ptr<SessionDescriptionInterface> desc,
186 rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer)
187 override;
deadbeef46c73892016-11-16 19:42:04 -0800188 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
deadbeefa67696b2015-09-29 11:56:26 -0700189 bool SetConfiguration(
deadbeef293e9262017-01-11 12:28:30 -0800190 const PeerConnectionInterface::RTCConfiguration& configuration,
191 RTCError* error) override;
192 bool SetConfiguration(
193 const PeerConnectionInterface::RTCConfiguration& configuration) override {
194 return SetConfiguration(configuration, nullptr);
195 }
deadbeefa67696b2015-09-29 11:56:26 -0700196 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700197 bool RemoveIceCandidates(
198 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199
Niels Möller0c4f7be2018-05-07 14:01:37 +0200200 RTCError SetBitrate(const BitrateSettings& bitrate) override;
zstein4b979802017-06-02 14:37:37 -0700201
henrika5f6bf242017-11-01 11:06:56 +0100202 void SetAudioPlayout(bool playout) override;
203 void SetAudioRecording(bool recording) override;
204
Harald Alvestrandad88c882018-11-28 16:47:46 +0100205 rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid(
206 const std::string& mid) override;
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100207 rtc::scoped_refptr<DtlsTransport> LookupDtlsTransportByMidInternal(
208 const std::string& mid);
Harald Alvestrandad88c882018-11-28 16:47:46 +0100209
Harald Alvestrandc85328f2019-02-28 07:51:00 +0100210 rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const override;
211
Bjorn Tereliusde939432017-11-20 17:38:14 +0100212 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,
213 int64_t output_period_ms) override;
Niels Möllerf00ca1a2019-05-10 11:33:12 +0200214 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override;
ivoc14d5dbe2016-07-04 07:06:55 -0700215 void StopRtcEventLog() override;
216
deadbeefa67696b2015-09-29 11:56:26 -0700217 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218
Steve Anton2d8609c2018-01-23 16:38:46 -0800219 // PeerConnectionInternal implementation.
Karl Wiberg4ae63472019-02-22 00:57:06 +0100220 rtc::Thread* network_thread() const final {
Steve Anton2d8609c2018-01-23 16:38:46 -0800221 return factory_->network_thread();
222 }
Karl Wiberg4ae63472019-02-22 00:57:06 +0100223 rtc::Thread* worker_thread() const final { return factory_->worker_thread(); }
224 rtc::Thread* signaling_thread() const final {
Steve Anton2d8609c2018-01-23 16:38:46 -0800225 return factory_->signaling_thread();
perkjd61bf802016-03-24 03:16:19 -0700226 }
deadbeefab9b2d12015-10-14 11:33:11 -0700227
Karl Wiberga58e1692019-03-26 13:33:43 +0100228 std::string session_id() const override {
229 RTC_DCHECK_RUN_ON(signaling_thread());
230 return session_id_;
231 }
Steve Anton75737c02017-11-06 10:37:17 -0800232
Steve Anton2d8609c2018-01-23 16:38:46 -0800233 bool initial_offerer() const override {
Karl Wiberg2cc368f2019-04-02 11:31:56 +0200234 RTC_DCHECK_RUN_ON(signaling_thread());
Zhi Huange830e682018-03-30 10:48:35 -0700235 return transport_controller_ && transport_controller_->initial_offerer();
Steve Anton2d8609c2018-01-23 16:38:46 -0800236 }
Steve Anton75737c02017-11-06 10:37:17 -0800237
Steve Anton2d8609c2018-01-23 16:38:46 -0800238 std::vector<
239 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 10:07:54 -0800240 GetTransceiversInternal() const override {
Karl Wiberga58e1692019-03-26 13:33:43 +0100241 RTC_DCHECK_RUN_ON(signaling_thread());
Steve Anton2d8609c2018-01-23 16:38:46 -0800242 return transceivers_;
243 }
244
Steve Anton2d8609c2018-01-23 16:38:46 -0800245 sigslot::signal1<DataChannel*>& SignalDataChannelCreated() override {
246 return SignalDataChannelCreated_;
247 }
248
249 cricket::RtpDataChannel* rtp_data_channel() const override {
Steve Anton75737c02017-11-06 10:37:17 -0800250 return rtp_data_channel_;
Steve Anton978b8762017-09-29 12:15:02 -0700251 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800252
Steve Antonbe5e2082018-01-24 15:29:17 -0800253 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels()
Steve Anton2d8609c2018-01-23 16:38:46 -0800254 const override {
Karl Wiberg85a4a932019-03-22 15:29:58 +0100255 RTC_DCHECK_RUN_ON(signaling_thread());
Steve Anton2d8609c2018-01-23 16:38:46 -0800256 return sctp_data_channels_;
257 }
258
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200259 absl::optional<std::string> sctp_content_name() const override {
Karl Wiberg2cc368f2019-04-02 11:31:56 +0200260 RTC_DCHECK_RUN_ON(signaling_thread());
Zhi Huange830e682018-03-30 10:48:35 -0700261 return sctp_mid_;
Steve Anton75737c02017-11-06 10:37:17 -0800262 }
Steve Anton2d8609c2018-01-23 16:38:46 -0800263
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200264 absl::optional<std::string> sctp_transport_name() const override;
Steve Anton75737c02017-11-06 10:37:17 -0800265
Qingsi Wang72a43a12018-02-20 16:03:18 -0800266 cricket::CandidateStatsList GetPooledCandidateStats() const override;
Steve Anton5dfde182018-02-06 10:34:40 -0800267 std::map<std::string, std::string> GetTransportNamesByMid() const override;
268 std::map<std::string, cricket::TransportStats> GetTransportStatsByNames(
269 const std::set<std::string>& transport_names) override;
Steve Anton2d8609c2018-01-23 16:38:46 -0800270 Call::Stats GetCallStats() override;
Steve Anton75737c02017-11-06 10:37:17 -0800271
Steve Anton2d8609c2018-01-23 16:38:46 -0800272 bool GetLocalCertificate(
273 const std::string& transport_name,
274 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800275 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-23 16:38:46 -0800276 const std::string& transport_name) override;
277 bool IceRestartPending(const std::string& content_name) const override;
278 bool NeedsIceRestart(const std::string& content_name) const override;
279 bool GetSslRole(const std::string& content_name, rtc::SSLRole* role) override;
Steve Anton7464fca2018-01-19 11:10:37 -0800280
Harald Alvestrand19793842018-06-25 12:03:50 +0200281 void ReturnHistogramVeryQuicklyForTesting() {
Karl Wibergf73f7d62019-04-08 15:36:53 +0200282 RTC_DCHECK_RUN_ON(signaling_thread());
Harald Alvestrand19793842018-06-25 12:03:50 +0200283 return_histogram_very_quickly_ = true;
284 }
Harald Alvestrand7a1c7f72018-08-01 10:50:16 +0200285 void RequestUsagePatternReportForTesting();
Harald Alvestrand19793842018-06-25 12:03:50 +0200286
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700288 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289
290 private:
Henrik Boström31638672017-11-23 17:48:32 +0100291 class SetRemoteDescriptionObserverAdapter;
292 friend class SetRemoteDescriptionObserverAdapter;
Henrik Boström79b69802019-07-18 11:16:56 +0200293 // Represents the [[LocalIceCredentialsToReplace]] internal slot in the spec.
294 // It makes the next CreateOffer() produce new ICE credentials even if
295 // RTCOfferAnswerOptions::ice_restart is false.
296 // https://w3c.github.io/webrtc-pc/#dfn-localufragstoreplace
297 // TODO(hbos): When JsepTransportController/JsepTransport supports rollback,
298 // move this type of logic to JsepTransportController/JsepTransport.
299 class LocalIceCredentialsToReplace;
Henrik Boström31638672017-11-23 17:48:32 +0100300
Steve Anton4171afb2017-11-20 10:20:22 -0800301 struct RtpSenderInfo {
302 RtpSenderInfo() : first_ssrc(0) {}
Seth Hampson845e8782018-03-02 11:34:10 -0800303 RtpSenderInfo(const std::string& stream_id,
Steve Anton4171afb2017-11-20 10:20:22 -0800304 const std::string sender_id,
305 uint32_t ssrc)
Seth Hampson845e8782018-03-02 11:34:10 -0800306 : stream_id(stream_id), sender_id(sender_id), first_ssrc(ssrc) {}
Steve Anton4171afb2017-11-20 10:20:22 -0800307 bool operator==(const RtpSenderInfo& other) {
Seth Hampson845e8782018-03-02 11:34:10 -0800308 return this->stream_id == other.stream_id &&
Steve Anton4171afb2017-11-20 10:20:22 -0800309 this->sender_id == other.sender_id &&
310 this->first_ssrc == other.first_ssrc;
deadbeefbda7e0b2015-12-08 17:13:40 -0800311 }
Seth Hampson845e8782018-03-02 11:34:10 -0800312 std::string stream_id;
Steve Anton4171afb2017-11-20 10:20:22 -0800313 std::string sender_id;
314 // An RtpSender can have many SSRCs. The first one is used as a sort of ID
315 // for communicating with the lower layers.
316 uint32_t first_ssrc;
deadbeefab9b2d12015-10-14 11:33:11 -0700317 };
deadbeefab9b2d12015-10-14 11:33:11 -0700318
Bjorn A Mellem5985a042019-06-28 14:19:38 -0700319 // Field-trial based configuration for datagram transport.
320 struct DatagramTransportConfig {
321 explicit DatagramTransportConfig(const std::string& field_trial)
322 : enabled("enabled", true), default_value("default_value", false) {
323 ParseFieldTrial({&enabled, &default_value}, field_trial);
324 }
325
326 // Whether datagram transport support is enabled at all. Defaults to true,
327 // allowing datagram transport to be used if (a) the application provides a
328 // factory for it and (b) the configuration specifies its use. This flag
329 // provides a kill-switch to force-disable datagram transport across all
330 // applications, without code changes.
331 FieldTrialFlag enabled;
332
333 // Whether the datagram transport is enabled or disabled by default.
334 // Defaults to false, meaning that applications must configure use of
335 // datagram transport through RTCConfiguration. If set to true,
336 // applications will use the datagram transport by default (but may still
337 // explicitly configure themselves not to use it through RTCConfiguration).
338 FieldTrialFlag default_value;
339 };
340
Steve Antonad182762018-09-05 20:22:40 +0000341 // Implements MessageHandler.
342 void OnMessage(rtc::Message* msg) override;
343
Steve Antonafb0bb72018-02-20 11:35:37 -0800344 // Plan B helpers for getting the voice/video media channels for the single
345 // audio/video transceiver, if it exists.
Karl Wiberg5966c502019-02-21 23:55:09 +0100346 cricket::VoiceMediaChannel* voice_media_channel() const
347 RTC_RUN_ON(signaling_thread());
348 cricket::VideoMediaChannel* video_media_channel() const
349 RTC_RUN_ON(signaling_thread());
Steve Anton60776752018-01-10 11:51:34 -0800350
Steve Anton4171afb2017-11-20 10:20:22 -0800351 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100352 GetSendersInternal() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800353 std::vector<
354 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100355 GetReceiversInternal() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800356
357 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100358 GetAudioTransceiver() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800359 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100360 GetVideoTransceiver() const RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800361
Steve Antonafb0bb72018-02-20 11:35:37 -0800362 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100363 GetFirstAudioTransceiver() const RTC_RUN_ON(signaling_thread());
Steve Antonafb0bb72018-02-20 11:35:37 -0800364
deadbeefab9b2d12015-10-14 11:33:11 -0700365 void CreateAudioReceiver(MediaStreamInterface* stream,
Karl Wiberg744310f2019-02-14 10:18:56 +0100366 const RtpSenderInfo& remote_sender_info)
367 RTC_RUN_ON(signaling_thread());
perkjf0dcfe22016-03-10 18:32:00 +0100368
deadbeefab9b2d12015-10-14 11:33:11 -0700369 void CreateVideoReceiver(MediaStreamInterface* stream,
Karl Wiberg744310f2019-02-14 10:18:56 +0100370 const RtpSenderInfo& remote_sender_info)
371 RTC_RUN_ON(signaling_thread());
Henrik Boström933d8b02017-10-10 10:05:16 -0700372 rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver(
Karl Wiberg5966c502019-02-21 23:55:09 +0100373 const RtpSenderInfo& remote_sender_info) RTC_RUN_ON(signaling_thread());
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700374
375 // May be called either by AddStream/RemoveStream, or when a track is
376 // added/removed from a stream previously added via AddStream.
Karl Wiberg5966c502019-02-21 23:55:09 +0100377 void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream)
378 RTC_RUN_ON(signaling_thread());
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700379 void RemoveAudioTrack(AudioTrackInterface* track,
Karl Wiberg5966c502019-02-21 23:55:09 +0100380 MediaStreamInterface* stream)
381 RTC_RUN_ON(signaling_thread());
382 void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream)
383 RTC_RUN_ON(signaling_thread());
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700384 void RemoveVideoTrack(VideoTrackInterface* track,
Karl Wiberg5966c502019-02-21 23:55:09 +0100385 MediaStreamInterface* stream)
386 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387
Steve Antonf9381f02017-12-14 10:23:57 -0800388 // AddTrack implementation when Unified Plan is specified.
389 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackUnifiedPlan(
390 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Karl Wiberga58e1692019-03-26 13:33:43 +0100391 const std::vector<std::string>& stream_ids)
392 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800393 // AddTrack implementation when Plan B is specified.
394 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackPlanB(
395 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Karl Wiberg5966c502019-02-21 23:55:09 +0100396 const std::vector<std::string>& stream_ids)
397 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800398
399 // Returns the first RtpTransceiver suitable for a newly added track, if such
400 // transceiver is available.
401 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
402 FindFirstTransceiverForAddedTrack(
Karl Wiberga58e1692019-03-26 13:33:43 +0100403 rtc::scoped_refptr<MediaStreamTrackInterface> track)
404 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800405
Steve Antonf9381f02017-12-14 10:23:57 -0800406 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100407 FindTransceiverBySender(rtc::scoped_refptr<RtpSenderInterface> sender)
408 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800409
Steve Anton22da89f2018-01-25 13:58:07 -0800410 // Internal implementation for AddTransceiver family of methods. If
411 // |fire_callback| is set, fires OnRenegotiationNeeded callback if successful.
Steve Anton9158ef62017-11-27 13:01:52 -0800412 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
413 cricket::MediaType media_type,
414 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Steve Anton22da89f2018-01-25 13:58:07 -0800415 const RtpTransceiverInit& init,
Karl Wiberg744310f2019-02-14 10:18:56 +0100416 bool fire_callback = true) RTC_RUN_ON(signaling_thread());
Steve Anton9158ef62017-11-27 13:01:52 -0800417
Steve Anton02ee47c2018-01-10 16:26:06 -0800418 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
419 CreateSender(cricket::MediaType media_type,
Steve Anton111fdfd2018-06-25 13:03:36 -0700420 const std::string& id,
Steve Anton02ee47c2018-01-10 16:26:06 -0800421 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Florent Castelli892acf02018-10-01 22:47:20 +0200422 const std::vector<std::string>& stream_ids,
423 const std::vector<RtpEncodingParameters>& send_encodings);
Steve Anton02ee47c2018-01-10 16:26:06 -0800424
425 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
426 CreateReceiver(cricket::MediaType media_type, const std::string& receiver_id);
427
Steve Antonf9381f02017-12-14 10:23:57 -0800428 // Create a new RtpTransceiver of the given type and add it to the list of
429 // transceivers.
430 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Steve Anton02ee47c2018-01-10 16:26:06 -0800431 CreateAndAddTransceiver(
432 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender,
433 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100434 receiver) RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 10:23:57 -0800435
Karl Wiberg744310f2019-02-14 10:18:56 +0100436 void SetIceConnectionState(IceConnectionState new_state)
437 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 15:58:17 +0200438 void SetStandardizedIceConnectionState(
Karl Wiberg744310f2019-02-14 10:18:56 +0100439 PeerConnectionInterface::IceConnectionState new_state)
440 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 15:58:17 +0200441 void SetConnectionState(
Karl Wiberg744310f2019-02-14 10:18:56 +0100442 PeerConnectionInterface::PeerConnectionState new_state)
443 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 15:58:17 +0200444
Eldar Relloda13ea22019-06-01 12:23:43 +0300445 // Called any time the IceGatheringState changes.
Karl Wiberg744310f2019-02-14 10:18:56 +0100446 void OnIceGatheringChange(IceGatheringState new_state)
447 RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 10:21:57 -0800448 // New ICE candidate has been gathered.
Karl Wiberg744310f2019-02-14 10:18:56 +0100449 void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate)
450 RTC_RUN_ON(signaling_thread());
Eldar Relloda13ea22019-06-01 12:23:43 +0300451 // Gathering of an ICE candidate failed.
452 void OnIceCandidateError(const std::string& host_candidate,
453 const std::string& url,
454 int error_code,
455 const std::string& error_text)
456 RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 10:21:57 -0800457 // Some local ICE candidates have been removed.
Karl Wiberg744310f2019-02-14 10:18:56 +0100458 void OnIceCandidatesRemoved(const std::vector<cricket::Candidate>& candidates)
459 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460
Steve Antonba818672017-11-06 10:21:57 -0800461 // Update the state, signaling if necessary.
Karl Wiberg744310f2019-02-14 10:18:56 +0100462 void ChangeSignalingState(SignalingState signaling_state)
463 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464
deadbeefeb459812015-12-15 19:24:43 -0800465 // Signals from MediaStreamObserver.
466 void OnAudioTrackAdded(AudioTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100467 MediaStreamInterface* stream)
468 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800469 void OnAudioTrackRemoved(AudioTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100470 MediaStreamInterface* stream)
471 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800472 void OnVideoTrackAdded(VideoTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100473 MediaStreamInterface* stream)
474 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800475 void OnVideoTrackRemoved(VideoTrackInterface* track,
Karl Wiberg744310f2019-02-14 10:18:56 +0100476 MediaStreamInterface* stream)
477 RTC_RUN_ON(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -0800478
Henrik Boström31638672017-11-23 17:48:32 +0100479 void PostSetSessionDescriptionSuccess(
480 SetSessionDescriptionObserver* observer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
Steve Antonad182762018-09-05 20:22:40 +0000482 RTCError&& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700483 void PostCreateSessionDescriptionFailure(
484 CreateSessionDescriptionObserver* observer,
Harald Alvestrand5081c0c2018-03-09 15:18:03 +0100485 RTCError error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486
Steve Anton8a006912017-12-04 15:25:56 -0800487 // Synchronous implementations of SetLocalDescription/SetRemoteDescription
488 // that return an RTCError instead of invoking a callback.
489 RTCError ApplyLocalDescription(
490 std::unique_ptr<SessionDescriptionInterface> desc);
491 RTCError ApplyRemoteDescription(
492 std::unique_ptr<SessionDescriptionInterface> desc);
493
Steve Antondcc3c022017-12-22 16:02:54 -0800494 // Updates the local RtpTransceivers according to the JSEP rules. Called as
495 // part of setting the local/remote description.
496 RTCError UpdateTransceiversAndDataChannels(
497 cricket::ContentSource source,
Seth Hampsonae8a90a2018-02-13 15:33:48 -0800498 const SessionDescriptionInterface& new_session,
499 const SessionDescriptionInterface* old_local_description,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100500 const SessionDescriptionInterface* old_remote_description)
501 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800502
503 // Either creates or destroys the transceiver's BaseChannel according to the
504 // given media section.
505 RTCError UpdateTransceiverChannel(
506 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
507 transceiver,
508 const cricket::ContentInfo& content,
Karl Wiberg5966c502019-02-21 23:55:09 +0100509 const cricket::ContentGroup* bundle_group) RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800510
Steve Antonfa2260d2017-12-28 16:38:23 -0800511 // Either creates or destroys the local data channel according to the given
512 // media section.
513 RTCError UpdateDataChannel(cricket::ContentSource source,
514 const cricket::ContentInfo& content,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100515 const cricket::ContentGroup* bundle_group)
516 RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800517
Steve Antondcc3c022017-12-22 16:02:54 -0800518 // Associate the given transceiver according to the JSEP rules.
519 RTCErrorOr<
520 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
521 AssociateTransceiver(cricket::ContentSource source,
Seth Hampsonae8a90a2018-02-13 15:33:48 -0800522 SdpType type,
Steve Antondcc3c022017-12-22 16:02:54 -0800523 size_t mline_index,
524 const cricket::ContentInfo& content,
Seth Hampsonae8a90a2018-02-13 15:33:48 -0800525 const cricket::ContentInfo* old_local_content,
Karl Wiberg5966c502019-02-21 23:55:09 +0100526 const cricket::ContentInfo* old_remote_content)
527 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800528
529 // Returns the RtpTransceiver, if found, that is associated to the given MID.
530 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100531 GetAssociatedTransceiver(const std::string& mid) const
532 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800533
534 // Returns the RtpTransceiver, if found, that was assigned to the given mline
535 // index in CreateOffer.
536 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100537 GetTransceiverByMLineIndex(size_t mline_index) const
538 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800539
540 // Returns an RtpTransciever, if available, that can be used to receive the
541 // given media type according to JSEP rules.
542 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberg5966c502019-02-21 23:55:09 +0100543 FindAvailableTransceiverToReceive(cricket::MediaType media_type) const
544 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800545
Steve Antoned10bd92017-12-05 10:52:59 -0800546 // Returns the media section in the given session description that is
547 // associated with the RtpTransceiver. Returns null if none found or this
548 // RtpTransceiver is not associated. Logic varies depending on the
549 // SdpSemantics specified in the configuration.
550 const cricket::ContentInfo* FindMediaSectionForTransceiver(
551 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
552 transceiver,
Karl Wiberg5966c502019-02-21 23:55:09 +0100553 const SessionDescriptionInterface* sdesc) const
554 RTC_RUN_ON(signaling_thread());
Steve Antoned10bd92017-12-05 10:52:59 -0800555
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100556 // Runs the algorithm **set the associated remote streams** specified in
557 // https://w3c.github.io/webrtc-pc/#set-associated-remote-streams.
558 void SetAssociatedRemoteStreams(
559 rtc::scoped_refptr<RtpReceiverInternal> receiver,
560 const std::vector<std::string>& stream_ids,
561 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* added_streams,
Karl Wiberg1e1e1022019-03-22 14:27:22 +0100562 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams)
563 RTC_RUN_ON(signaling_thread());
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100564
Steve Anton0f5400a2018-07-17 14:25:36 -0700565 // Runs the algorithm **process the removal of a remote track** specified in
566 // the WebRTC specification.
567 // This method will update the following lists:
568 // |remove_list| is the list of transceivers for which the receiving track is
569 // being removed.
570 // |removed_streams| is the list of streams which no longer have a receiving
571 // track so should be removed.
572 // https://w3c.github.io/webrtc-pc/#process-remote-track-removal
573 void ProcessRemovalOfRemoteTrack(
574 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
575 transceiver,
576 std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>* remove_list,
Karl Wiberg1e1e1022019-03-22 14:27:22 +0100577 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams)
578 RTC_RUN_ON(signaling_thread());
Steve Anton0f5400a2018-07-17 14:25:36 -0700579
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100580 void RemoveRemoteStreamsIfEmpty(
581 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&
582 remote_streams,
Karl Wiberg1e1e1022019-03-22 14:27:22 +0100583 std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams)
584 RTC_RUN_ON(signaling_thread());
Henrik Boströmafa07dd2018-12-20 11:06:02 +0100585
Steve Anton52d86772018-02-20 15:48:12 -0800586 void OnNegotiationNeeded();
587
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588 bool IsClosed() const {
Karl Wiberg8d2e2282019-02-17 13:00:07 +0100589 RTC_DCHECK_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 return signaling_state_ == PeerConnectionInterface::kClosed;
591 }
592
deadbeefab9b2d12015-10-14 11:33:11 -0700593 // Returns a MediaSessionOptions struct with options decided by |options|,
594 // the local MediaStreams and DataChannels.
Steve Antondcc3c022017-12-22 16:02:54 -0800595 void GetOptionsForOffer(const PeerConnectionInterface::RTCOfferAnswerOptions&
596 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100597 cricket::MediaSessionOptions* session_options)
598 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800599 void GetOptionsForPlanBOffer(
600 const PeerConnectionInterface::RTCOfferAnswerOptions&
601 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100602 cricket::MediaSessionOptions* session_options)
603 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800604 void GetOptionsForUnifiedPlanOffer(
605 const PeerConnectionInterface::RTCOfferAnswerOptions&
606 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100607 cricket::MediaSessionOptions* session_options)
608 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700609
Karl Wiberg5966c502019-02-21 23:55:09 +0100610 RTCError HandleLegacyOfferOptions(const RTCOfferAnswerOptions& options)
611 RTC_RUN_ON(signaling_thread());
Steve Anton22da89f2018-01-25 13:58:07 -0800612 void RemoveRecvDirectionFromReceivingTransceiversOfType(
Karl Wiberga58e1692019-03-26 13:33:43 +0100613 cricket::MediaType media_type) RTC_RUN_ON(signaling_thread());
Steve Anton22da89f2018-01-25 13:58:07 -0800614 void AddUpToOneReceivingTransceiverOfType(cricket::MediaType media_type);
615 std::vector<
616 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100617 GetReceivingTransceiversOfType(cricket::MediaType media_type)
618 RTC_RUN_ON(signaling_thread());
Steve Anton22da89f2018-01-25 13:58:07 -0800619
deadbeefab9b2d12015-10-14 11:33:11 -0700620 // Returns a MediaSessionOptions struct with options decided by
621 // |constraints|, the local MediaStreams and DataChannels.
Steve Antondcc3c022017-12-22 16:02:54 -0800622 void GetOptionsForAnswer(const RTCOfferAnswerOptions& offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100623 cricket::MediaSessionOptions* session_options)
624 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800625 void GetOptionsForPlanBAnswer(
626 const PeerConnectionInterface::RTCOfferAnswerOptions&
627 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100628 cricket::MediaSessionOptions* session_options)
629 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800630 void GetOptionsForUnifiedPlanAnswer(
631 const PeerConnectionInterface::RTCOfferAnswerOptions&
632 offer_answer_options,
Karl Wiberg5966c502019-02-21 23:55:09 +0100633 cricket::MediaSessionOptions* session_options)
634 RTC_RUN_ON(signaling_thread());
htaa2a49d92016-03-04 02:51:39 -0800635
zhihuang1c378ed2017-08-17 14:10:50 -0700636 // Generates MediaDescriptionOptions for the |session_opts| based on existing
637 // local description or remote description.
638 void GenerateMediaDescriptionOptions(
639 const SessionDescriptionInterface* session_desc,
Steve Anton1d03a752017-11-27 14:30:09 -0800640 RtpTransceiverDirection audio_direction,
641 RtpTransceiverDirection video_direction,
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200642 absl::optional<size_t>* audio_index,
643 absl::optional<size_t>* video_index,
644 absl::optional<size_t>* data_index,
Karl Wiberg85a4a932019-03-22 15:29:58 +0100645 cricket::MediaSessionOptions* session_options)
646 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700647
Steve Antonfa2260d2017-12-28 16:38:23 -0800648 // Generates the active MediaDescriptionOptions for the local data channel
649 // given the specified MID.
650 cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForActiveData(
Karl Wiberg85a4a932019-03-22 15:29:58 +0100651 const std::string& mid) const RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800652
653 // Generates the rejected MediaDescriptionOptions for the local data channel
654 // given the specified MID.
655 cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForRejectedData(
Karl Wiberg85a4a932019-03-22 15:29:58 +0100656 const std::string& mid) const RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800657
658 // Returns the MID for the data section associated with either the
659 // RtpDataChannel or SCTP data channel, if it has been set. If no data
660 // channels are configured this will return nullopt.
Karl Wiberg2cc368f2019-04-02 11:31:56 +0200661 absl::optional<std::string> GetDataMid() const RTC_RUN_ON(signaling_thread());
Steve Antonfa2260d2017-12-28 16:38:23 -0800662
Steve Anton4171afb2017-11-20 10:20:22 -0800663 // Remove all local and remote senders of type |media_type|.
deadbeeffaac4972015-11-12 15:33:07 -0800664 // Called when a media type is rejected (m-line set to port 0).
Karl Wiberg744310f2019-02-14 10:18:56 +0100665 void RemoveSenders(cricket::MediaType media_type)
666 RTC_RUN_ON(signaling_thread());
deadbeeffaac4972015-11-12 15:33:07 -0800667
deadbeefbda7e0b2015-12-08 17:13:40 -0800668 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
669 // and existing MediaStreamTracks are removed if there is no corresponding
670 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
671 // is created if it doesn't exist; if false, it's removed if it exists.
672 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700673 // If a new MediaStream is created it is added to |new_streams|.
Steve Anton4171afb2017-11-20 10:20:22 -0800674 void UpdateRemoteSendersList(
deadbeefab9b2d12015-10-14 11:33:11 -0700675 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800676 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700677 cricket::MediaType media_type,
Karl Wiberg744310f2019-02-14 10:18:56 +0100678 StreamCollection* new_streams) RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700679
Steve Anton4171afb2017-11-20 10:20:22 -0800680 // Triggered when a remote sender has been seen for the first time in a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700681 // session description. It creates a remote MediaStreamTrackInterface
682 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800683 void OnRemoteSenderAdded(const RtpSenderInfo& sender_info,
Karl Wiberg744310f2019-02-14 10:18:56 +0100684 cricket::MediaType media_type)
685 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700686
Steve Anton4171afb2017-11-20 10:20:22 -0800687 // Triggered when a remote sender has been removed from a remote session
688 // description. It removes the remote sender with id |sender_id| from a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700689 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800690 void OnRemoteSenderRemoved(const RtpSenderInfo& sender_info,
Karl Wiberg744310f2019-02-14 10:18:56 +0100691 cricket::MediaType media_type)
692 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700693
694 // Finds remote MediaStreams without any tracks and removes them from
695 // |remote_streams_| and notifies the observer that the MediaStreams no longer
696 // exist.
Karl Wiberg744310f2019-02-14 10:18:56 +0100697 void UpdateEndedRemoteMediaStreams() RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700698
deadbeefab9b2d12015-10-14 11:33:11 -0700699 // Loops through the vector of |streams| and finds added and removed
700 // StreamParams since last time this method was called.
Steve Anton4171afb2017-11-20 10:20:22 -0800701 // For each new or removed StreamParam, OnLocalSenderSeen or
702 // OnLocalSenderRemoved is invoked.
703 void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams,
Karl Wiberg5966c502019-02-21 23:55:09 +0100704 cricket::MediaType media_type)
705 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700706
Steve Anton4171afb2017-11-20 10:20:22 -0800707 // Triggered when a local sender has been seen for the first time in a local
deadbeefab9b2d12015-10-14 11:33:11 -0700708 // session description.
709 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
710 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
711 // in a MediaStream in |local_streams_|
Steve Anton4171afb2017-11-20 10:20:22 -0800712 void OnLocalSenderAdded(const RtpSenderInfo& sender_info,
Karl Wiberg5966c502019-02-21 23:55:09 +0100713 cricket::MediaType media_type)
714 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700715
Steve Anton4171afb2017-11-20 10:20:22 -0800716 // Triggered when a local sender has been removed from a local session
deadbeefab9b2d12015-10-14 11:33:11 -0700717 // description.
718 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
719 // has been removed from the local SessionDescription and the stream can be
720 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
Steve Anton4171afb2017-11-20 10:20:22 -0800721 void OnLocalSenderRemoved(const RtpSenderInfo& sender_info,
Karl Wiberga58e1692019-03-26 13:33:43 +0100722 cricket::MediaType media_type)
723 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700724
Karl Wiberg85a4a932019-03-22 15:29:58 +0100725 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams)
726 RTC_RUN_ON(signaling_thread());
Karl Wiberg106d92d2019-02-14 10:17:47 +0100727 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams)
728 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700729 void UpdateClosingRtpDataChannels(
730 const std::vector<std::string>& active_channels,
Karl Wiberg85a4a932019-03-22 15:29:58 +0100731 bool is_local_update) RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700732 void CreateRemoteRtpDataChannel(const std::string& label,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100733 uint32_t remote_ssrc)
734 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700735
736 // Creates channel and adds it to the collection of DataChannels that will
737 // be offered in a SessionDescription.
738 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
739 const std::string& label,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100740 const InternalDataChannelInit* config) RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700741
742 // Checks if any data channel has been added.
Karl Wiberg85a4a932019-03-22 15:29:58 +0100743 bool HasDataChannels() const RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700744
Karl Wiberg85a4a932019-03-22 15:29:58 +0100745 void AllocateSctpSids(rtc::SSLRole role) RTC_RUN_ON(signaling_thread());
746 void OnSctpDataChannelClosed(DataChannel* channel)
747 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700748
Karl Wiberg85a4a932019-03-22 15:29:58 +0100749 void OnDataChannelDestroyed() RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 10:21:57 -0800750 // Called when a valid data channel OPEN message is received.
deadbeefab9b2d12015-10-14 11:33:11 -0700751 void OnDataChannelOpenMessage(const std::string& label,
Karl Wiberg106d92d2019-02-14 10:17:47 +0100752 const InternalDataChannelInit& config)
753 RTC_RUN_ON(signaling_thread());
754
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800755 // Parses and handles open messages. Returns true if the message is an open
756 // message, false otherwise.
757 bool HandleOpenMessage_s(const cricket::ReceiveDataParams& params,
758 const rtc::CopyOnWriteBuffer& buffer)
759 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700760
Steve Anton4171afb2017-11-20 10:20:22 -0800761 // Returns true if the PeerConnection is configured to use Unified Plan
762 // semantics for creating offers/answers and setting local/remote
763 // descriptions. If this is true the RtpTransceiver API will also be available
764 // to the user. If this is false, Plan B semantics are assumed.
Steve Anton79e79602017-11-20 10:25:56 -0800765 // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once
766 // sufficient time has passed.
Karl Wiberg5966c502019-02-21 23:55:09 +0100767 bool IsUnifiedPlan() const RTC_RUN_ON(signaling_thread()) {
Steve Anton79e79602017-11-20 10:25:56 -0800768 return configuration_.sdp_semantics == SdpSemantics::kUnifiedPlan;
769 }
Steve Anton4171afb2017-11-20 10:20:22 -0800770
Steve Anton06817cd2018-12-18 15:55:30 -0800771 // The offer/answer machinery assumes the media section MID is present and
772 // unique. To support legacy end points that do not supply a=mid lines, this
773 // method will modify the session description to add MIDs generated according
774 // to the SDP semantics.
Karl Wiberg5966c502019-02-21 23:55:09 +0100775 void FillInMissingRemoteMids(cricket::SessionDescription* remote_description)
776 RTC_RUN_ON(signaling_thread());
Steve Anton06817cd2018-12-18 15:55:30 -0800777
Steve Anton4171afb2017-11-20 10:20:22 -0800778 // Is there an RtpSender of the given type?
Karl Wiberg5966c502019-02-21 23:55:09 +0100779 bool HasRtpSender(cricket::MediaType type) const
780 RTC_RUN_ON(signaling_thread());
deadbeeffac06552015-11-25 11:26:01 -0800781
Steve Anton4171afb2017-11-20 10:20:22 -0800782 // Return the RtpSender with the given track attached.
783 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100784 FindSenderForTrack(MediaStreamTrackInterface* track) const
785 RTC_RUN_ON(signaling_thread());
deadbeef70ab1a12015-09-28 16:53:55 -0700786
Steve Anton4171afb2017-11-20 10:20:22 -0800787 // Return the RtpSender with the given id, or null if none exists.
788 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100789 FindSenderById(const std::string& sender_id) const
790 RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800791
792 // Return the RtpReceiver with the given id, or null if none exists.
793 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
Karl Wiberga58e1692019-03-26 13:33:43 +0100794 FindReceiverById(const std::string& receiver_id) const
795 RTC_RUN_ON(signaling_thread());
Steve Anton4171afb2017-11-20 10:20:22 -0800796
797 std::vector<RtpSenderInfo>* GetRemoteSenderInfos(
798 cricket::MediaType media_type);
799 std::vector<RtpSenderInfo>* GetLocalSenderInfos(
800 cricket::MediaType media_type);
801 const RtpSenderInfo* FindSenderInfo(const std::vector<RtpSenderInfo>& infos,
Emircan Uysalerbc609ea2018-03-27 21:57:18 +0000802 const std::string& stream_id,
Steve Anton4171afb2017-11-20 10:20:22 -0800803 const std::string sender_id) const;
deadbeefab9b2d12015-10-14 11:33:11 -0700804
805 // Returns the specified SCTP DataChannel in sctp_data_channels_,
806 // or nullptr if not found.
Karl Wiberg85a4a932019-03-22 15:29:58 +0100807 DataChannel* FindDataChannelBySid(int sid) const
808 RTC_RUN_ON(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -0700809
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700810 // Called when first configuring the port allocator.
Karl Wibergfb3be392019-03-22 14:13:22 +0100811 struct InitializePortAllocatorResult {
812 bool enable_ipv6;
813 };
814 InitializePortAllocatorResult InitializePortAllocator_n(
Harald Alvestrandb2a74782018-06-28 13:54:07 +0200815 const cricket::ServerAddresses& stun_servers,
816 const std::vector<cricket::RelayServerConfig>& turn_servers,
817 const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 12:28:30 -0800818 // Called when SetConfiguration is called to apply the supported subset
819 // of the configuration on the network thread.
820 bool ReconfigurePortAllocator_n(
821 const cricket::ServerAddresses& stun_servers,
822 const std::vector<cricket::RelayServerConfig>& turn_servers,
823 IceTransportsType type,
824 int candidate_pool_size,
Jonas Orelandbdcee282017-10-10 14:01:40 +0200825 bool prune_turn_ports,
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800826 webrtc::TurnCustomizer* turn_customizer,
Karl Wiberg739506e2019-04-03 11:37:28 +0200827 absl::optional<int> stun_candidate_keepalive_interval,
828 bool have_local_description);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700829
Elad Alon99c3fe52017-10-13 16:29:40 +0200830 // Starts output of an RTC event log to the given output object.
ivoc14d5dbe2016-07-04 07:06:55 -0700831 // This function should only be called from the worker thread.
Bjorn Tereliusde939432017-11-20 17:38:14 +0100832 bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output,
833 int64_t output_period_ms);
Elad Alon99c3fe52017-10-13 16:29:40 +0200834
Elad Alonacb24172017-10-06 14:32:13 +0200835 // Stops recording an RTC event log.
ivoc14d5dbe2016-07-04 07:06:55 -0700836 // This function should only be called from the worker thread.
837 void StopRtcEventLog_w();
838
Steve Anton038834f2017-07-14 15:59:59 -0700839 // Ensures the configuration doesn't have any parameters with invalid values,
840 // or values that conflict with other parameters.
841 //
842 // Returns RTCError::OK() if there are no issues.
843 RTCError ValidateConfiguration(const RTCConfiguration& config) const;
844
Steve Antonba818672017-11-06 10:21:57 -0800845 cricket::ChannelManager* channel_manager() const;
Steve Antonba818672017-11-06 10:21:57 -0800846
Steve Antonf8470812017-12-04 10:46:21 -0800847 enum class SessionError {
848 kNone, // No error.
849 kContent, // Error in BaseChannel SetLocalContent/SetRemoteContent.
850 kTransport, // Error from the underlying transport.
851 };
852
Steve Anton75737c02017-11-06 10:37:17 -0800853 // Returns the last error in the session. See the enum above for details.
Karl Wiberga58e1692019-03-26 13:33:43 +0100854 SessionError session_error() const RTC_RUN_ON(signaling_thread()) {
855 return session_error_;
856 }
Steve Antonf8470812017-12-04 10:46:21 -0800857 const std::string& session_error_desc() const { return session_error_desc_; }
Steve Anton75737c02017-11-06 10:37:17 -0800858
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800859 cricket::ChannelInterface* GetChannel(const std::string& content_name);
Steve Anton75737c02017-11-06 10:37:17 -0800860
861 // Get current SSL role used by SCTP's underlying transport.
862 bool GetSctpSslRole(rtc::SSLRole* role);
863
Steve Anton75737c02017-11-06 10:37:17 -0800864 cricket::IceConfig ParseIceConfig(
865 const PeerConnectionInterface::RTCConfiguration& config) const;
866
Steve Anton75737c02017-11-06 10:37:17 -0800867 // Implements DataChannelProviderInterface.
868 bool SendData(const cricket::SendDataParams& params,
869 const rtc::CopyOnWriteBuffer& payload,
870 cricket::SendDataResult* result) override;
871 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override;
872 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override;
873 void AddSctpDataStream(int sid) override;
874 void RemoveSctpDataStream(int sid) override;
875 bool ReadyToSendData() const override;
876
877 cricket::DataChannelType data_channel_type() const;
878
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800879 // Implements DataChannelSink.
880 void OnDataReceived(int channel_id,
881 DataMessageType type,
882 const rtc::CopyOnWriteBuffer& buffer) override;
883 void OnChannelClosing(int channel_id) override;
884 void OnChannelClosed(int channel_id) override;
885
Steve Anton75737c02017-11-06 10:37:17 -0800886 // Called when an RTCCertificate is generated or retrieved by
887 // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription.
888 void OnCertificateReady(
889 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
890 void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp);
891
Steve Anton75737c02017-11-06 10:37:17 -0800892 // Non-const versions of local_description()/remote_description(), for use
893 // internally.
Karl Wiberg739506e2019-04-03 11:37:28 +0200894 SessionDescriptionInterface* mutable_local_description()
895 RTC_RUN_ON(signaling_thread()) {
Steve Anton75737c02017-11-06 10:37:17 -0800896 return pending_local_description_ ? pending_local_description_.get()
897 : current_local_description_.get();
898 }
Karl Wiberg739506e2019-04-03 11:37:28 +0200899 SessionDescriptionInterface* mutable_remote_description()
900 RTC_RUN_ON(signaling_thread()) {
Steve Anton75737c02017-11-06 10:37:17 -0800901 return pending_remote_description_ ? pending_remote_description_.get()
902 : current_remote_description_.get();
903 }
904
905 // Updates the error state, signaling if necessary.
Steve Antonf8470812017-12-04 10:46:21 -0800906 void SetSessionError(SessionError error, const std::string& error_desc);
Steve Anton75737c02017-11-06 10:37:17 -0800907
Zhi Huange830e682018-03-30 10:48:35 -0700908 RTCError UpdateSessionState(SdpType type,
909 cricket::ContentSource source,
910 const cricket::SessionDescription* description);
Steve Anton75737c02017-11-06 10:37:17 -0800911 // Push the media parts of the local or remote session description
912 // down to all of the channels.
Karl Wiberg5966c502019-02-21 23:55:09 +0100913 RTCError PushdownMediaDescription(SdpType type, cricket::ContentSource source)
914 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800915
Steve Anton8a006912017-12-04 15:25:56 -0800916 RTCError PushdownTransportDescription(cricket::ContentSource source,
Steve Anton3828c062017-12-06 10:34:51 -0800917 SdpType type);
Steve Anton75737c02017-11-06 10:37:17 -0800918
919 // Returns true and the TransportInfo of the given |content_name|
920 // from |description|. Returns false if it's not available.
921 static bool GetTransportDescription(
922 const cricket::SessionDescription* description,
923 const std::string& content_name,
924 cricket::TransportDescription* info);
925
Steve Anton75737c02017-11-06 10:37:17 -0800926 // Enables media channels to allow sending of media.
Steve Antoned10bd92017-12-05 10:52:59 -0800927 // This enables media to flow on all configured audio/video channels and the
928 // RtpDataChannel.
Karl Wiberga58e1692019-03-26 13:33:43 +0100929 void EnableSending() RTC_RUN_ON(signaling_thread());
Steve Anton3fe1b152017-12-12 10:20:08 -0800930
Steve Anton8af21862017-12-15 11:20:13 -0800931 // Destroys all BaseChannels and destroys the SCTP data channel, if present.
Karl Wiberg85a4a932019-03-22 15:29:58 +0100932 void DestroyAllChannels() RTC_RUN_ON(signaling_thread());
Steve Anton3fe1b152017-12-12 10:20:08 -0800933
Steve Anton75737c02017-11-06 10:37:17 -0800934 // Returns the media index for a local ice candidate given the content name.
935 // Returns false if the local session description does not have a media
936 // content called |content_name|.
937 bool GetLocalCandidateMediaIndex(const std::string& content_name,
Karl Wiberg739506e2019-04-03 11:37:28 +0200938 int* sdp_mline_index)
939 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800940 // Uses all remote candidates in |remote_desc| in this session.
941 bool UseCandidatesInSessionDescription(
Karl Wiberg744310f2019-02-14 10:18:56 +0100942 const SessionDescriptionInterface* remote_desc)
943 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800944 // Uses |candidate| in this session.
Karl Wiberg744310f2019-02-14 10:18:56 +0100945 bool UseCandidate(const IceCandidateInterface* candidate)
946 RTC_RUN_ON(signaling_thread());
Guido Urdaneta41633172019-05-23 20:12:29 +0200947 RTCErrorOr<const cricket::ContentInfo*> FindContentInfo(
948 const SessionDescriptionInterface* description,
949 const IceCandidateInterface* candidate) RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800950 // Deletes the corresponding channel of contents that don't exist in |desc|.
951 // |desc| can be null. This means that all channels are deleted.
Karl Wiberg5966c502019-02-21 23:55:09 +0100952 void RemoveUnusedChannels(const cricket::SessionDescription* desc)
953 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800954
955 // Allocates media channels based on the |desc|. If |desc| doesn't have
956 // the BUNDLE option, this method will disable BUNDLE in PortAllocator.
957 // This method will also delete any existing media channels before creating.
Karl Wiberg5966c502019-02-21 23:55:09 +0100958 RTCError CreateChannels(const cricket::SessionDescription& desc)
959 RTC_RUN_ON(signaling_thread());
Steve Antondcc3c022017-12-22 16:02:54 -0800960
961 // If the BUNDLE policy is max-bundle, then we know for sure that all
962 // transports will be bundled from the start. This method returns the BUNDLE
963 // group if that's the case, or null if BUNDLE will be negotiated later. An
964 // error is returned if max-bundle is specified but the session description
965 // does not have a BUNDLE group.
966 RTCErrorOr<const cricket::ContentGroup*> GetEarlyBundleGroup(
Karl Wiberg5966c502019-02-21 23:55:09 +0100967 const cricket::SessionDescription& desc) const
968 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800969
970 // Helper methods to create media channels.
Karl Wiberg5966c502019-02-21 23:55:09 +0100971 cricket::VoiceChannel* CreateVoiceChannel(const std::string& mid)
972 RTC_RUN_ON(signaling_thread());
973 cricket::VideoChannel* CreateVideoChannel(const std::string& mid)
974 RTC_RUN_ON(signaling_thread());
975 bool CreateDataChannel(const std::string& mid) RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -0800976
Zhi Huange830e682018-03-30 10:48:35 -0700977 bool CreateSctpTransport_n(const std::string& mid);
Steve Anton75737c02017-11-06 10:37:17 -0800978 // For bundling.
Steve Anton75737c02017-11-06 10:37:17 -0800979 void DestroySctpTransport_n();
980 // SctpTransport signal handlers. Needed to marshal signals from the network
981 // to signaling thread.
982 void OnSctpTransportReadyToSendData_n();
983 // This may be called with "false" if the direction of the m= section causes
984 // us to tear down the SCTP connection.
985 void OnSctpTransportReadyToSendData_s(bool ready);
986 void OnSctpTransportDataReceived_n(const cricket::ReceiveDataParams& params,
987 const rtc::CopyOnWriteBuffer& payload);
988 // Beyond just firing the signal to the signaling thread, listens to SCTP
989 // CONTROL messages on unused SIDs and processes them as OPEN messages.
990 void OnSctpTransportDataReceived_s(const cricket::ReceiveDataParams& params,
991 const rtc::CopyOnWriteBuffer& payload);
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700992 void OnSctpClosingProcedureStartedRemotely_n(int sid);
993 void OnSctpClosingProcedureComplete_n(int sid);
Steve Anton75737c02017-11-06 10:37:17 -0800994
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800995 bool SetupMediaTransportForDataChannels_n(const std::string& mid)
996 RTC_RUN_ON(network_thread());
997 void OnMediaTransportStateChanged_n() RTC_RUN_ON(network_thread());
998 void TeardownMediaTransportForDataChannels_n() RTC_RUN_ON(network_thread());
999
Steve Anton75737c02017-11-06 10:37:17 -08001000 bool ValidateBundleSettings(const cricket::SessionDescription* desc);
1001 bool HasRtcpMuxEnabled(const cricket::ContentInfo* content);
1002 // Below methods are helper methods which verifies SDP.
Steve Anton8a006912017-12-04 15:25:56 -08001003 RTCError ValidateSessionDescription(const SessionDescriptionInterface* sdesc,
Karl Wiberg5966c502019-02-21 23:55:09 +01001004 cricket::ContentSource source)
1005 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001006
Steve Anton3828c062017-12-06 10:34:51 -08001007 // Check if a call to SetLocalDescription is acceptable with a session
1008 // description of the given type.
1009 bool ExpectSetLocalDescription(SdpType type);
1010 // Check if a call to SetRemoteDescription is acceptable with a session
1011 // description of the given type.
1012 bool ExpectSetRemoteDescription(SdpType type);
Steve Anton75737c02017-11-06 10:37:17 -08001013 // Verifies a=setup attribute as per RFC 5763.
1014 bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc,
Steve Anton3828c062017-12-06 10:34:51 -08001015 SdpType type);
Steve Anton75737c02017-11-06 10:37:17 -08001016
1017 // Returns true if we are ready to push down the remote candidate.
1018 // |remote_desc| is the new remote description, or NULL if the current remote
1019 // description should be used. Output |valid| is true if the candidate media
1020 // index is valid.
1021 bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate,
1022 const SessionDescriptionInterface* remote_desc,
Karl Wiberga58e1692019-03-26 13:33:43 +01001023 bool* valid) RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001024
1025 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
1026 // this session.
Karl Wiberg739506e2019-04-03 11:37:28 +02001027 bool SrtpRequired() const RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001028
Zhi Huange830e682018-03-30 10:48:35 -07001029 // JsepTransportController signal handlers.
Karl Wiberg744310f2019-02-14 10:18:56 +01001030 void OnTransportControllerConnectionState(cricket::IceConnectionState state)
1031 RTC_RUN_ON(signaling_thread());
1032 void OnTransportControllerGatheringState(cricket::IceGatheringState state)
1033 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001034 void OnTransportControllerCandidatesGathered(
1035 const std::string& transport_name,
Karl Wiberg744310f2019-02-14 10:18:56 +01001036 const std::vector<cricket::Candidate>& candidates)
1037 RTC_RUN_ON(signaling_thread());
Eldar Relloda13ea22019-06-01 12:23:43 +03001038 void OnTransportControllerCandidateError(
1039 const cricket::IceCandidateErrorEvent& event)
1040 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001041 void OnTransportControllerCandidatesRemoved(
Karl Wiberg744310f2019-02-14 10:18:56 +01001042 const std::vector<cricket::Candidate>& candidates)
1043 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001044 void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error);
1045
Steve Antonf8470812017-12-04 10:46:21 -08001046 const char* SessionErrorToString(SessionError error) const;
Karl Wiberga58e1692019-03-26 13:33:43 +01001047 std::string GetSessionErrorMsg() RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001048
Steve Anton8e20f172018-03-06 10:55:04 -08001049 // Report the UMA metric SdpFormatReceived for the given remote offer.
1050 void ReportSdpFormatReceived(const SessionDescriptionInterface& remote_offer);
1051
Steve Anton0ffaaa22018-02-23 10:31:30 -08001052 // Report inferred negotiated SDP semantics from a local/remote answer to the
1053 // UMA observer.
1054 void ReportNegotiatedSdpSemantics(const SessionDescriptionInterface& answer);
1055
Steve Anton75737c02017-11-06 10:37:17 -08001056 // Invoked when TransportController connection completion is signaled.
1057 // Reports stats for all transports in use.
Karl Wiberga58e1692019-03-26 13:33:43 +01001058 void ReportTransportStats() RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001059
1060 // Gather the usage of IPv4/IPv6 as best connection.
1061 void ReportBestConnectionState(const cricket::TransportStats& stats);
1062
Steve Antonc7b964c2018-02-01 14:39:45 -08001063 void ReportNegotiatedCiphers(const cricket::TransportStats& stats,
Karl Wiberg739506e2019-04-03 11:37:28 +02001064 const std::set<cricket::MediaType>& media_types)
1065 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001066
Harald Alvestrand8ebba742018-05-31 14:00:34 +02001067 void NoteUsageEvent(UsageEvent event);
Karl Wiberg744310f2019-02-14 10:18:56 +01001068 void ReportUsagePattern() const RTC_RUN_ON(signaling_thread());
Harald Alvestrand8ebba742018-05-31 14:00:34 +02001069
Steve Anton75737c02017-11-06 10:37:17 -08001070 void OnSentPacket_w(const rtc::SentPacket& sent_packet);
1071
Karl Wiberga58e1692019-03-26 13:33:43 +01001072 const std::string GetTransportName(const std::string& content_name)
1073 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001074
Steve Anton6fec8802017-12-04 10:37:29 -08001075 // Destroys and clears the BaseChannel associated with the given transceiver,
1076 // if such channel is set.
1077 void DestroyTransceiverChannel(
1078 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
1079 transceiver);
1080
1081 // Destroys the RTP data channel and/or the SCTP data channel and clears it.
Karl Wiberg85a4a932019-03-22 15:29:58 +01001082 void DestroyDataChannel() RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001083
Amit Hilbuchdd9390c2018-11-13 16:26:05 -08001084 // Destroys the given ChannelInterface.
1085 // The channel cannot be accessed after this method is called.
1086 void DestroyChannelInterface(cricket::ChannelInterface* channel);
Steve Anton6fec8802017-12-04 10:37:29 -08001087
Zhi Huang365381f2018-04-13 16:44:34 -07001088 // JsepTransportController::Observer override.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -07001089 //
1090 // Called by |transport_controller_| when processing transport information
1091 // from a session description, and the mapping from m= sections to transports
1092 // changed (as a result of BUNDLE negotiation, or m= sections being
1093 // rejected).
Piotr (Peter) Slatalacc8e8bb2018-11-15 08:26:19 -08001094 bool OnTransportChanged(const std::string& mid,
1095 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +01001096 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Karl Wibergac025892019-03-26 13:08:37 +01001097 MediaTransportInterface* media_transport) override;
Zhi Huange830e682018-03-30 10:48:35 -07001098
Guido Urdaneta1ff16c82019-05-20 19:31:53 +02001099 // RtpSenderBase::SetStreamsObserver override.
1100 void OnSetStreams() override;
1101
Harald Alvestrand7a1c7f72018-08-01 10:50:16 +02001102 // Returns the observer. Will crash on CHECK if the observer is removed.
Karl Wiberg744310f2019-02-14 10:18:56 +01001103 PeerConnectionObserver* Observer() const RTC_RUN_ON(signaling_thread());
Harald Alvestrand7a1c7f72018-08-01 10:50:16 +02001104
Benjamin Wright8c27cca2018-10-25 10:16:44 -07001105 // Returns the CryptoOptions for this PeerConnection. This will always
1106 // return the RTCConfiguration.crypto_options if set and will only default
1107 // back to the PeerConnectionFactory settings if nothing was set.
Karl Wiberg5966c502019-02-21 23:55:09 +01001108 CryptoOptions GetCryptoOptions() RTC_RUN_ON(signaling_thread());
Benjamin Wright8c27cca2018-10-25 10:16:44 -07001109
Anton Sukhanov98a462c2018-10-17 13:15:42 -07001110 // Returns rtp transport, result can not be nullptr.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001111 RtpTransportInternal* GetRtpTransport(const std::string& mid)
1112 RTC_RUN_ON(signaling_thread()) {
Anton Sukhanov98a462c2018-10-17 13:15:42 -07001113 auto rtp_transport = transport_controller_->GetRtpTransport(mid);
1114 RTC_DCHECK(rtp_transport);
1115 return rtp_transport;
1116 }
1117
Guido Urdaneta70c2db12019-04-16 12:24:14 +02001118 void UpdateNegotiationNeeded();
1119 bool CheckIfNegotiationIsNeeded();
1120
Karl Wiberg106d92d2019-02-14 10:17:47 +01001121 sigslot::signal1<DataChannel*> SignalDataChannelCreated_
1122 RTC_GUARDED_BY(signaling_thread());
Steve Anton2d8609c2018-01-23 16:38:46 -08001123
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 // Storing the factory as a scoped reference pointer ensures that the memory
1125 // in the PeerConnectionFactoryImpl remains available as long as the
1126 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
1127 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -07001128 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 // will refer to the same reference count.
Karl Wiberg744310f2019-02-14 10:18:56 +01001130 const rtc::scoped_refptr<PeerConnectionFactory> factory_;
1131 PeerConnectionObserver* observer_ RTC_GUARDED_BY(signaling_thread()) =
1132 nullptr;
terelius33860252017-05-12 23:37:18 -07001133
1134 // The EventLog needs to outlive |call_| (and any other object that uses it).
Karl Wibergb03ab712019-02-14 11:59:57 +01001135 std::unique_ptr<RtcEventLog> event_log_ RTC_GUARDED_BY(worker_thread());
1136
1137 // Points to the same thing as `event_log_`. Since it's const, we may read the
1138 // pointer (but not touch the object) from any thread.
1139 RtcEventLog* const event_log_ptr_ RTC_PT_GUARDED_BY(worker_thread());
terelius33860252017-05-12 23:37:18 -07001140
Karl Wiberg8d2e2282019-02-17 13:00:07 +01001141 SignalingState signaling_state_ RTC_GUARDED_BY(signaling_thread()) = kStable;
1142 IceConnectionState ice_connection_state_ RTC_GUARDED_BY(signaling_thread()) =
1143 kIceConnectionNew;
1144 PeerConnectionInterface::IceConnectionState standardized_ice_connection_state_
1145 RTC_GUARDED_BY(signaling_thread()) = kIceConnectionNew;
1146 PeerConnectionInterface::PeerConnectionState connection_state_
1147 RTC_GUARDED_BY(signaling_thread()) = PeerConnectionState::kNew;
Jonas Olsson635474e2018-10-18 15:58:17 +02001148
Karl Wiberg8d2e2282019-02-17 13:00:07 +01001149 IceGatheringState ice_gathering_state_ RTC_GUARDED_BY(signaling_thread()) =
1150 kIceGatheringNew;
Karl Wiberg5966c502019-02-21 23:55:09 +01001151 PeerConnectionInterface::RTCConfiguration configuration_
1152 RTC_GUARDED_BY(signaling_thread());
1153
Bjorn A Mellem5985a042019-06-28 14:19:38 -07001154 // Field-trial based configuration for datagram transport.
1155 const DatagramTransportConfig datagram_transport_config_;
1156
1157 // Final, resolved value for whether datagram transport is in use.
1158 bool use_datagram_transport_ RTC_GUARDED_BY(signaling_thread()) = false;
1159
Karl Wiberg5966c502019-02-21 23:55:09 +01001160 // Cache configuration_.use_media_transport so that we can access it from
1161 // other threads.
1162 // TODO(bugs.webrtc.org/9987): Caching just this bool and allowing the data
1163 // it's derived from to change is not necessarily sound. Stop doing it.
1164 rtc::RaceChecker use_media_transport_race_checker_;
1165 bool use_media_transport_ RTC_GUARDED_BY(use_media_transport_race_checker_) =
1166 configuration_.use_media_transport;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167
Zach Steine20867f2018-08-02 13:20:15 -07001168 // TODO(zstein): |async_resolver_factory_| can currently be nullptr if it
1169 // is not injected. It should be required once chromium supplies it.
Karl Wibergfb3be392019-03-22 14:13:22 +01001170 std::unique_ptr<AsyncResolverFactory> async_resolver_factory_
1171 RTC_GUARDED_BY(signaling_thread());
1172 std::unique_ptr<cricket::PortAllocator>
1173 port_allocator_; // TODO(bugs.webrtc.org/9987): Accessed on both
1174 // signaling and network thread.
1175 std::unique_ptr<rtc::SSLCertificateVerifier>
1176 tls_cert_verifier_; // TODO(bugs.webrtc.org/9987): Accessed on both
1177 // signaling and network thread.
deadbeefab9b2d12015-10-14 11:33:11 -07001178
zhihuang8f65cdf2016-05-06 18:40:30 -07001179 // One PeerConnection has only one RTCP CNAME.
1180 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
Karl Wibergfb3be392019-03-22 14:13:22 +01001181 const std::string rtcp_cname_;
zhihuang8f65cdf2016-05-06 18:40:30 -07001182
deadbeefab9b2d12015-10-14 11:33:11 -07001183 // Streams added via AddStream.
Karl Wiberg1e1e1022019-03-22 14:27:22 +01001184 const rtc::scoped_refptr<StreamCollection> local_streams_
1185 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001186 // Streams created as a result of SetRemoteDescription.
Karl Wiberg1e1e1022019-03-22 14:27:22 +01001187 const rtc::scoped_refptr<StreamCollection> remote_streams_
1188 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001189
Karl Wiberg1e1e1022019-03-22 14:27:22 +01001190 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_
1191 RTC_GUARDED_BY(signaling_thread());
deadbeefeb459812015-12-15 19:24:43 -08001192
Steve Anton4171afb2017-11-20 10:20:22 -08001193 // These lists store sender info seen in local/remote descriptions.
Karl Wibergc70999e2019-03-22 15:14:27 +01001194 std::vector<RtpSenderInfo> remote_audio_sender_infos_
1195 RTC_GUARDED_BY(signaling_thread());
1196 std::vector<RtpSenderInfo> remote_video_sender_infos_
1197 RTC_GUARDED_BY(signaling_thread());
1198 std::vector<RtpSenderInfo> local_audio_sender_infos_
1199 RTC_GUARDED_BY(signaling_thread());
1200 std::vector<RtpSenderInfo> local_video_sender_infos_
1201 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001202
Karl Wiberg85a4a932019-03-22 15:29:58 +01001203 SctpSidAllocator sid_allocator_ RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001204 // label -> DataChannel
Karl Wiberg85a4a932019-03-22 15:29:58 +01001205 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_
1206 RTC_GUARDED_BY(signaling_thread());
1207 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_
1208 RTC_GUARDED_BY(signaling_thread());
1209 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_
1210 RTC_GUARDED_BY(signaling_thread());
deadbeefab9b2d12015-10-14 11:33:11 -07001211
Karl Wiberg85a4a932019-03-22 15:29:58 +01001212 bool remote_peer_supports_msid_ RTC_GUARDED_BY(signaling_thread()) = false;
deadbeef70ab1a12015-09-28 16:53:55 -07001213
Karl Wibergac025892019-03-26 13:08:37 +01001214 // The unique_ptr belongs to the worker thread, but the Call object manages
1215 // its own thread safety.
Karl Wiberg6cab5c82019-03-26 09:57:01 +01001216 std::unique_ptr<Call> call_ RTC_GUARDED_BY(worker_thread());
1217
1218 // Points to the same thing as `call_`. Since it's const, we may read the
Karl Wibergac025892019-03-26 13:08:37 +01001219 // pointer from any thread.
1220 Call* const call_ptr_;
Karl Wiberg6cab5c82019-03-26 09:57:01 +01001221
1222 std::unique_ptr<StatsCollector> stats_
1223 RTC_GUARDED_BY(signaling_thread()); // A pointer is passed to senders_
1224 rtc::scoped_refptr<RTCStatsCollector> stats_collector_
1225 RTC_GUARDED_BY(signaling_thread());
terelius33860252017-05-12 23:37:18 -07001226
deadbeefa601f5c2016-06-06 14:27:39 -07001227 std::vector<
Steve Anton4171afb2017-11-20 10:20:22 -08001228 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001229 transceivers_; // TODO(bugs.webrtc.org/9987): Accessed on both signaling
1230 // and network thread.
1231
Henrik Boström5b147782018-12-04 11:25:05 +01001232 // In Unified Plan, if we encounter remote SDP that does not contain an a=msid
1233 // line we create and use a stream with a random ID for our receivers. This is
1234 // to support legacy endpoints that do not support the a=msid attribute (as
1235 // opposed to streamless tracks with "a=msid:-").
Karl Wiberga58e1692019-03-26 13:33:43 +01001236 rtc::scoped_refptr<MediaStreamInterface> missing_msid_default_stream_
1237 RTC_GUARDED_BY(signaling_thread());
Amit Hilbuchae3df542019-01-07 12:13:08 -08001238 // MIDs will be generated using this generator which will keep track of
1239 // all the MIDs that have been seen over the life of the PeerConnection.
Karl Wiberga58e1692019-03-26 13:33:43 +01001240 rtc::UniqueStringGenerator mid_generator_ RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001241
Karl Wiberga58e1692019-03-26 13:33:43 +01001242 SessionError session_error_ RTC_GUARDED_BY(signaling_thread()) =
1243 SessionError::kNone;
1244 std::string session_error_desc_ RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001245
Karl Wiberga58e1692019-03-26 13:33:43 +01001246 std::string session_id_ RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001247
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001248 std::unique_ptr<JsepTransportController>
1249 transport_controller_; // TODO(bugs.webrtc.org/9987): Accessed on both
1250 // signaling and network thread.
1251 std::unique_ptr<cricket::SctpTransportInternalFactory>
1252 sctp_factory_; // TODO(bugs.webrtc.org/9987): Accessed on both
1253 // signaling and network thread.
Steve Anton75737c02017-11-06 10:37:17 -08001254 // |rtp_data_channel_| is used if in RTP data channel mode, |sctp_transport_|
1255 // when using SCTP.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001256 cricket::RtpDataChannel* rtp_data_channel_ =
1257 nullptr; // TODO(bugs.webrtc.org/9987): Accessed on both
1258 // signaling and some other thread.
Steve Anton75737c02017-11-06 10:37:17 -08001259
Harald Alvestrandc85328f2019-02-28 07:51:00 +01001260 cricket::SctpTransportInternal* cricket_sctp_transport() {
1261 return sctp_transport_->internal();
1262 }
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001263 rtc::scoped_refptr<SctpTransport>
1264 sctp_transport_; // TODO(bugs.webrtc.org/9987): Accessed on both
1265 // signaling and network thread.
1266
Zhi Huange830e682018-03-30 10:48:35 -07001267 // |sctp_mid_| is the content name (MID) in SDP.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001268 absl::optional<std::string>
1269 sctp_mid_; // TODO(bugs.webrtc.org/9987): Accessed on both signaling
1270 // and network thread.
1271
Steve Anton75737c02017-11-06 10:37:17 -08001272 // Value cached on signaling thread. Only updated when SctpReadyToSendData
1273 // fires on the signaling thread.
Karl Wiberg2cc368f2019-04-02 11:31:56 +02001274 bool sctp_ready_to_send_data_ RTC_GUARDED_BY(signaling_thread()) = false;
1275
Steve Anton75737c02017-11-06 10:37:17 -08001276 // Same as signals provided by SctpTransport, but these are guaranteed to
1277 // fire on the signaling thread, whereas SctpTransport fires on the networking
1278 // thread.
1279 // |sctp_invoker_| is used so that any signals queued on the signaling thread
1280 // from the network thread are immediately discarded if the SctpTransport is
1281 // destroyed (due to m= section being rejected).
1282 // TODO(deadbeef): Use a proxy object to ensure that method calls/signals
1283 // are marshalled to the right thread. Could almost use proxy.h for this,
1284 // but it doesn't have a mechanism for marshalling sigslot::signals
Karl Wiberg7a651c6e2019-04-02 13:00:46 +02001285 std::unique_ptr<rtc::AsyncInvoker> sctp_invoker_
1286 RTC_GUARDED_BY(network_thread());
1287 sigslot::signal1<bool> SignalSctpReadyToSendData
1288 RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001289 sigslot::signal2<const cricket::ReceiveDataParams&,
1290 const rtc::CopyOnWriteBuffer&>
Karl Wiberg7a651c6e2019-04-02 13:00:46 +02001291 SignalSctpDataReceived RTC_GUARDED_BY(signaling_thread());
1292 sigslot::signal1<int> SignalSctpClosingProcedureStartedRemotely
1293 RTC_GUARDED_BY(signaling_thread());
1294 sigslot::signal1<int> SignalSctpClosingProcedureComplete
1295 RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001296
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001297 // Whether this peer is the caller. Set when the local description is applied.
1298 absl::optional<bool> is_caller_ RTC_GUARDED_BY(signaling_thread());
1299
1300 // Content name (MID) for media transport data channels in SDP.
Karl Wibergd9bf7202019-04-02 19:36:24 +02001301 absl::optional<std::string>
1302 media_transport_data_mid_; // TODO(bugs.webrtc.org/9987): Accessed on
1303 // both signaling and network thread.
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001304
1305 // Media transport used for data channels. Thread-safe.
Karl Wibergd9bf7202019-04-02 19:36:24 +02001306 MediaTransportInterface* media_transport_ =
1307 nullptr; // TODO(bugs.webrtc.org/9987): Object is thread safe, but
1308 // pointer accessed on both signaling and network thread.
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001309
1310 // Cached value of whether the media transport is ready to send.
1311 bool media_transport_ready_to_send_data_ RTC_GUARDED_BY(signaling_thread()) =
1312 false;
1313
1314 // Used to invoke media transport signals on the signaling thread.
Karl Wiberg739506e2019-04-03 11:37:28 +02001315 std::unique_ptr<rtc::AsyncInvoker> media_transport_invoker_
1316 RTC_GUARDED_BY(network_thread());
Bjorn Mellem175aa2e2018-11-08 11:23:22 -08001317
1318 // Identical to the signals for SCTP, but from media transport:
1319 sigslot::signal1<bool> SignalMediaTransportWritable_s
1320 RTC_GUARDED_BY(signaling_thread());
1321 sigslot::signal2<const cricket::ReceiveDataParams&,
1322 const rtc::CopyOnWriteBuffer&>
1323 SignalMediaTransportReceivedData_s RTC_GUARDED_BY(signaling_thread());
1324 sigslot::signal1<int> SignalMediaTransportChannelClosing_s
1325 RTC_GUARDED_BY(signaling_thread());
1326 sigslot::signal1<int> SignalMediaTransportChannelClosed_s
1327 RTC_GUARDED_BY(signaling_thread());
1328
Karl Wiberg739506e2019-04-03 11:37:28 +02001329 std::unique_ptr<SessionDescriptionInterface> current_local_description_
1330 RTC_GUARDED_BY(signaling_thread());
1331 std::unique_ptr<SessionDescriptionInterface> pending_local_description_
1332 RTC_GUARDED_BY(signaling_thread());
1333 std::unique_ptr<SessionDescriptionInterface> current_remote_description_
1334 RTC_GUARDED_BY(signaling_thread());
1335 std::unique_ptr<SessionDescriptionInterface> pending_remote_description_
1336 RTC_GUARDED_BY(signaling_thread());
1337 bool dtls_enabled_ RTC_GUARDED_BY(signaling_thread()) = false;
Steve Anton75737c02017-11-06 10:37:17 -08001338 // Specifies which kind of data channel is allowed. This is controlled
1339 // by the chrome command-line flag and constraints:
1340 // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled,
1341 // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is
1342 // not set or false, SCTP is allowed (DCT_SCTP);
1343 // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP);
1344 // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE).
Karl Wibergf73f7d62019-04-08 15:36:53 +02001345 cricket::DataChannelType data_channel_type_ =
1346 cricket::DCT_NONE; // TODO(bugs.webrtc.org/9987): Accessed on both
1347 // signaling and network thread.
Steve Anton75737c02017-11-06 10:37:17 -08001348
Karl Wibergf73f7d62019-04-08 15:36:53 +02001349 // List of content names for which the remote side triggered an ICE restart.
1350 std::set<std::string> pending_ice_restarts_
1351 RTC_GUARDED_BY(signaling_thread());
1352
1353 std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_
1354 RTC_GUARDED_BY(signaling_thread());
Steve Anton75737c02017-11-06 10:37:17 -08001355
1356 // Member variables for caching global options.
Karl Wibergf73f7d62019-04-08 15:36:53 +02001357 cricket::AudioOptions audio_options_ RTC_GUARDED_BY(signaling_thread());
1358 cricket::VideoOptions video_options_ RTC_GUARDED_BY(signaling_thread());
Harald Alvestrand8ebba742018-05-31 14:00:34 +02001359
Karl Wibergf73f7d62019-04-08 15:36:53 +02001360 int usage_event_accumulator_ RTC_GUARDED_BY(signaling_thread()) = 0;
1361 bool return_histogram_very_quickly_ RTC_GUARDED_BY(signaling_thread()) =
1362 false;
Amit Hilbuchbcd39d42019-01-25 17:13:56 -08001363
1364 // This object should be used to generate any SSRC that is not explicitly
1365 // specified by the user (or by the remote party).
1366 // The generator is not used directly, instead it is passed on to the
1367 // channel manager and the session description factory.
Karl Wibergf73f7d62019-04-08 15:36:53 +02001368 rtc::UniqueRandomIdGenerator ssrc_generator_
1369 RTC_GUARDED_BY(signaling_thread());
Jonas Orelanda3aa9bd2019-04-17 07:38:40 +02001370
1371 // A video bitrate allocator factory.
1372 // This can injected using the PeerConnectionDependencies,
1373 // or else the CreateBuiltinVideoBitrateAllocatorFactory() will be called.
1374 // Note that one can still choose to override this in a MediaEngine
1375 // if one wants too.
1376 std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
1377 video_bitrate_allocator_factory_;
1378
Henrik Boström79b69802019-07-18 11:16:56 +02001379 std::unique_ptr<LocalIceCredentialsToReplace>
1380 local_ice_credentials_to_replace_ RTC_GUARDED_BY(signaling_thread());
Guido Urdaneta70c2db12019-04-16 12:24:14 +02001381 bool is_negotiation_needed_ RTC_GUARDED_BY(signaling_thread()) = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001382};
1383
1384} // namespace webrtc
1385
Steve Anton10542f22019-01-11 09:11:00 -08001386#endif // PC_PEER_CONNECTION_H_