blob: 0c7962d7a5b9fa55c61e3310fceccabae20e9220 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_PEERCONNECTION_H_
12#define PC_PEERCONNECTION_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>
perkjd61bf802016-03-24 03:16:19 -070018#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/peerconnectioninterface.h"
Jonas Orelandbdcee282017-10-10 14:01:40 +020021#include "api/turncustomizer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "pc/iceserverparsing.h"
23#include "pc/peerconnectionfactory.h"
24#include "pc/rtcstatscollector.h"
25#include "pc/rtpreceiver.h"
26#include "pc/rtpsender.h"
27#include "pc/statscollector.h"
28#include "pc/streamcollection.h"
Steve Anton75737c02017-11-06 10:37:17 -080029#include "pc/webrtcsessiondescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
31namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
deadbeefeb459812015-12-15 19:24:43 -080033class MediaStreamObserver;
perkjf0dcfe22016-03-10 18:32:00 +010034class VideoRtpReceiver;
skvlad11a9cbf2016-10-07 11:53:05 -070035class RtcEventLog;
deadbeefab9b2d12015-10-14 11:33:11 -070036
Steve Anton75737c02017-11-06 10:37:17 -080037// Statistics for all the transports of the session.
38// TODO(pthatcher): Think of a better name for this. We already have
39// a TransportStats in transport.h. Perhaps TransportsStats?
40struct SessionStats {
41 std::map<std::string, std::string> proxy_to_transport;
42 std::map<std::string, cricket::TransportStats> transport_stats;
43};
Steve Antonba818672017-11-06 10:21:57 -080044
Steve Anton75737c02017-11-06 10:37:17 -080045struct ChannelNamePair {
46 ChannelNamePair(const std::string& content_name,
47 const std::string& transport_name)
48 : content_name(content_name), transport_name(transport_name) {}
49 std::string content_name;
50 std::string transport_name;
51};
52
53struct ChannelNamePairs {
54 rtc::Optional<ChannelNamePair> voice;
55 rtc::Optional<ChannelNamePair> video;
56 rtc::Optional<ChannelNamePair> data;
57};
58
59// PeerConnection is the implementation of the PeerConnection object as defined
60// by the PeerConnectionInterface API surface.
61// The class currently is solely responsible for the following:
62// - Managing the session state machine (signaling state).
63// - Creating and initializing lower-level objects, like PortAllocator and
64// BaseChannels.
65// - Owning and managing the life cycle of the RtpSender/RtpReceiver and track
66// objects.
67// - Tracking the current and pending local/remote session descriptions.
68// The class currently is jointly responsible for the following:
69// - Parsing and interpreting SDP.
70// - Generating offers and answers based on the current state.
71// - The ICE state machine.
72// - Generating stats.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073class PeerConnection : public PeerConnectionInterface,
Steve Anton75737c02017-11-06 10:37:17 -080074 public DataChannelProviderInterface,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000075 public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 public sigslot::has_slots<> {
77 public:
zhihuang38ede132017-06-15 12:52:32 -070078 explicit PeerConnection(PeerConnectionFactory* factory,
79 std::unique_ptr<RtcEventLog> event_log,
80 std::unique_ptr<Call> call);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081
deadbeef653b8e02015-11-11 12:55:10 -080082 bool Initialize(
83 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -070084 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020085 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef653b8e02015-11-11 12:55:10 -080086 PeerConnectionObserver* observer);
87
deadbeefa67696b2015-09-29 11:56:26 -070088 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
89 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
90 bool AddStream(MediaStreamInterface* local_stream) override;
91 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
deadbeefe1f9d832016-01-14 15:35:42 -080093 rtc::scoped_refptr<RtpSenderInterface> AddTrack(
94 MediaStreamTrackInterface* track,
95 std::vector<MediaStreamInterface*> streams) override;
96 bool RemoveTrack(RtpSenderInterface* sender) override;
97
Steve Anton8c0f7a72017-10-03 10:03:10 -070098 // Gets the DTLS SSL certificate associated with the audio transport on the
99 // remote side. This will become populated once the DTLS connection with the
100 // peer has been completed, as indicated by the ICE connection state
101 // transitioning to kIceConnectionCompleted.
102 // Note that this will be removed once we implement RTCDtlsTransport which
103 // has standardized method for getting this information.
104 // See https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface
105 std::unique_ptr<rtc::SSLCertificate> GetRemoteAudioSSLCertificate();
106
deadbeefa67696b2015-09-29 11:56:26 -0700107 rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
108 AudioTrackInterface* track) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
deadbeeffac06552015-11-25 11:26:01 -0800110 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800111 const std::string& kind,
112 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -0800113
deadbeef70ab1a12015-09-28 16:53:55 -0700114 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
115 const override;
116 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
117 const override;
118
deadbeefa67696b2015-09-29 11:56:26 -0700119 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700121 const DataChannelInit* config) override;
122 bool GetStats(StatsObserver* observer,
123 webrtc::MediaStreamTrackInterface* track,
124 StatsOutputLevel level) override;
hbos74e1a4f2016-09-15 23:33:01 -0700125 void GetStats(RTCStatsCollectorCallback* callback) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126
deadbeefa67696b2015-09-29 11:56:26 -0700127 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128
deadbeefa67696b2015-09-29 11:56:26 -0700129 IceConnectionState ice_connection_state() override;
130 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131
deadbeefa67696b2015-09-29 11:56:26 -0700132 const SessionDescriptionInterface* local_description() const override;
133 const SessionDescriptionInterface* remote_description() const override;
deadbeeffe4a8a42016-12-20 17:56:17 -0800134 const SessionDescriptionInterface* current_local_description() const override;
135 const SessionDescriptionInterface* current_remote_description()
136 const override;
137 const SessionDescriptionInterface* pending_local_description() const override;
138 const SessionDescriptionInterface* pending_remote_description()
139 const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140
141 // JSEP01
htaa2a49d92016-03-04 02:51:39 -0800142 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700143 void CreateOffer(CreateSessionDescriptionObserver* observer,
144 const MediaConstraintsInterface* constraints) override;
145 void CreateOffer(CreateSessionDescriptionObserver* observer,
146 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800147 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700148 void CreateAnswer(CreateSessionDescriptionObserver* observer,
149 const MediaConstraintsInterface* constraints) override;
htaa2a49d92016-03-04 02:51:39 -0800150 void CreateAnswer(CreateSessionDescriptionObserver* observer,
151 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700152 void SetLocalDescription(SetSessionDescriptionObserver* observer,
153 SessionDescriptionInterface* desc) override;
154 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
155 SessionDescriptionInterface* desc) override;
deadbeef46c73892016-11-16 19:42:04 -0800156 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
deadbeefa67696b2015-09-29 11:56:26 -0700157 bool SetConfiguration(
deadbeef293e9262017-01-11 12:28:30 -0800158 const PeerConnectionInterface::RTCConfiguration& configuration,
159 RTCError* error) override;
160 bool SetConfiguration(
161 const PeerConnectionInterface::RTCConfiguration& configuration) override {
162 return SetConfiguration(configuration, nullptr);
163 }
deadbeefa67696b2015-09-29 11:56:26 -0700164 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700165 bool RemoveIceCandidates(
166 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167
deadbeefa67696b2015-09-29 11:56:26 -0700168 void RegisterUMAObserver(UMAObserver* observer) override;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000169
zstein4b979802017-06-02 14:37:37 -0700170 RTCError SetBitrate(const BitrateParameters& bitrate) override;
171
Alex Narest78609d52017-10-20 10:37:47 +0200172 void SetBitrateAllocationStrategy(
173 std::unique_ptr<rtc::BitrateAllocationStrategy>
174 bitrate_allocation_strategy) override;
175
henrika5f6bf242017-11-01 11:06:56 +0100176 void SetAudioPlayout(bool playout) override;
177 void SetAudioRecording(bool recording) override;
178
Elad Alon99c3fe52017-10-13 16:29:40 +0200179 RTC_DEPRECATED bool StartRtcEventLog(rtc::PlatformFile file,
180 int64_t max_size_bytes) override;
181 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override;
ivoc14d5dbe2016-07-04 07:06:55 -0700182 void StopRtcEventLog() override;
183
deadbeefa67696b2015-09-29 11:56:26 -0700184 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185
hbos82ebe022016-11-14 01:41:09 -0800186 sigslot::signal1<DataChannel*> SignalDataChannelCreated;
187
deadbeefab9b2d12015-10-14 11:33:11 -0700188 // Virtual for unit tests.
189 virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
190 sctp_data_channels() const {
191 return sctp_data_channels_;
perkjd61bf802016-03-24 03:16:19 -0700192 }
deadbeefab9b2d12015-10-14 11:33:11 -0700193
Steve Anton978b8762017-09-29 12:15:02 -0700194 rtc::Thread* network_thread() const { return factory_->network_thread(); }
195 rtc::Thread* worker_thread() const { return factory_->worker_thread(); }
196 rtc::Thread* signaling_thread() const { return factory_->signaling_thread(); }
Steve Anton75737c02017-11-06 10:37:17 -0800197
198 // The SDP session ID as defined by RFC 3264.
199 virtual const std::string& session_id() const { return session_id_; }
200
201 // Returns true if we were the initial offerer.
202 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
203
204 // Returns stats for all channels of all transports.
205 // This avoids exposing the internal structures used to track them.
206 // The parameterless version creates |ChannelNamePairs| from |voice_channel|,
207 // |video_channel| and |voice_channel| if available - this requires it to be
208 // called on the signaling thread - and invokes the other |GetStats|. The
209 // other |GetStats| can be invoked on any thread; if not invoked on the
210 // network thread a thread hop will happen.
211 std::unique_ptr<SessionStats> GetSessionStats_s();
Steve Anton978b8762017-09-29 12:15:02 -0700212 virtual std::unique_ptr<SessionStats> GetSessionStats(
Steve Anton75737c02017-11-06 10:37:17 -0800213 const ChannelNamePairs& channel_name_pairs);
214
215 // virtual so it can be mocked in unit tests
Steve Anton978b8762017-09-29 12:15:02 -0700216 virtual bool GetLocalCertificate(
217 const std::string& transport_name,
Steve Anton75737c02017-11-06 10:37:17 -0800218 rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
Steve Anton978b8762017-09-29 12:15:02 -0700219 virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
Steve Anton75737c02017-11-06 10:37:17 -0800220 const std::string& transport_name);
221
222 virtual Call::Stats GetCallStats();
223
224 // Exposed for stats collecting.
225 // TODO(steveanton): Switch callers to use the plural form and remove these.
Steve Anton978b8762017-09-29 12:15:02 -0700226 virtual cricket::VoiceChannel* voice_channel() {
Steve Anton75737c02017-11-06 10:37:17 -0800227 if (voice_channels_.empty()) {
228 return nullptr;
229 } else {
230 return voice_channels_[0];
231 }
Steve Anton978b8762017-09-29 12:15:02 -0700232 }
233 virtual cricket::VideoChannel* video_channel() {
Steve Anton75737c02017-11-06 10:37:17 -0800234 if (video_channels_.empty()) {
235 return nullptr;
236 } else {
237 return video_channels_[0];
238 }
Steve Antond5585ca2017-10-23 14:49:26 -0700239 }
Steve Anton978b8762017-09-29 12:15:02 -0700240
Steve Anton75737c02017-11-06 10:37:17 -0800241 // Only valid when using deprecated RTP data channels.
242 virtual cricket::RtpDataChannel* rtp_data_channel() {
243 return rtp_data_channel_;
Steve Anton978b8762017-09-29 12:15:02 -0700244 }
Steve Anton75737c02017-11-06 10:37:17 -0800245 virtual rtc::Optional<std::string> sctp_content_name() const {
246 return sctp_content_name_;
247 }
248 virtual rtc::Optional<std::string> sctp_transport_name() const {
249 return sctp_transport_name_;
250 }
251
252 // Get the id used as a media stream track's "id" field from ssrc.
253 virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
254 virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
255
256 // Returns true if there was an ICE restart initiated by the remote offer.
257 bool IceRestartPending(const std::string& content_name) const;
258
259 // Returns true if the ICE restart flag above was set, and no ICE restart has
260 // occurred yet for this transport (by applying a local description with
261 // changed ufrag/password). If the transport has been deleted as a result of
262 // bundling, returns false.
263 bool NeedsIceRestart(const std::string& content_name) const;
264
265 // Get SSL role for an arbitrary m= section (handles bundling correctly).
266 // TODO(deadbeef): This is only used internally by the session description
267 // factory, it shouldn't really be public).
268 bool GetSslRole(const std::string& content_name, rtc::SSLRole* role);
269
270 enum Error {
271 ERROR_NONE = 0, // no error
272 ERROR_CONTENT = 1, // channel errors in SetLocalContent/SetRemoteContent
273 ERROR_TRANSPORT = 2, // transport error of some kind
274 };
Steve Anton978b8762017-09-29 12:15:02 -0700275
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700277 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278
279 private:
deadbeefab9b2d12015-10-14 11:33:11 -0700280 struct TrackInfo {
281 TrackInfo() : ssrc(0) {}
282 TrackInfo(const std::string& stream_label,
283 const std::string track_id,
284 uint32_t ssrc)
285 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {}
deadbeefbda7e0b2015-12-08 17:13:40 -0800286 bool operator==(const TrackInfo& other) {
287 return this->stream_label == other.stream_label &&
288 this->track_id == other.track_id && this->ssrc == other.ssrc;
289 }
deadbeefab9b2d12015-10-14 11:33:11 -0700290 std::string stream_label;
291 std::string track_id;
292 uint32_t ssrc;
293 };
294 typedef std::vector<TrackInfo> TrackInfos;
295
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 // Implements MessageHandler.
deadbeefa67696b2015-09-29 11:56:26 -0700297 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298
deadbeefab9b2d12015-10-14 11:33:11 -0700299 void CreateAudioReceiver(MediaStreamInterface* stream,
perkjd61bf802016-03-24 03:16:19 -0700300 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700301 uint32_t ssrc);
perkjf0dcfe22016-03-10 18:32:00 +0100302
deadbeefab9b2d12015-10-14 11:33:11 -0700303 void CreateVideoReceiver(MediaStreamInterface* stream,
perkjf0dcfe22016-03-10 18:32:00 +0100304 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700305 uint32_t ssrc);
Henrik Boström933d8b02017-10-10 10:05:16 -0700306 rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver(
307 const std::string& track_id);
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700308
309 // May be called either by AddStream/RemoveStream, or when a track is
310 // added/removed from a stream previously added via AddStream.
311 void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream);
312 void RemoveAudioTrack(AudioTrackInterface* track,
313 MediaStreamInterface* stream);
314 void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream);
315 void RemoveVideoTrack(VideoTrackInterface* track,
316 MediaStreamInterface* stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317
Steve Antonba818672017-11-06 10:21:57 -0800318 void SetIceConnectionState(IceConnectionState new_state);
319 // Called any time the IceGatheringState changes
320 void OnIceGatheringChange(IceGatheringState new_state);
321 // New ICE candidate has been gathered.
322 void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate);
323 // Some local ICE candidates have been removed.
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700324 void OnIceCandidatesRemoved(
Steve Antonba818672017-11-06 10:21:57 -0800325 const std::vector<cricket::Candidate>& candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326
Steve Antonba818672017-11-06 10:21:57 -0800327 // Update the state, signaling if necessary.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 void ChangeSignalingState(SignalingState signaling_state);
329
deadbeefeb459812015-12-15 19:24:43 -0800330 // Signals from MediaStreamObserver.
331 void OnAudioTrackAdded(AudioTrackInterface* track,
332 MediaStreamInterface* stream);
333 void OnAudioTrackRemoved(AudioTrackInterface* track,
334 MediaStreamInterface* stream);
335 void OnVideoTrackAdded(VideoTrackInterface* track,
336 MediaStreamInterface* stream);
337 void OnVideoTrackRemoved(VideoTrackInterface* track,
338 MediaStreamInterface* stream);
339
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
341 const std::string& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700342 void PostCreateSessionDescriptionFailure(
343 CreateSessionDescriptionObserver* observer,
344 const std::string& error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345
346 bool IsClosed() const {
347 return signaling_state_ == PeerConnectionInterface::kClosed;
348 }
349
deadbeefab9b2d12015-10-14 11:33:11 -0700350 // Returns a MediaSessionOptions struct with options decided by |options|,
351 // the local MediaStreams and DataChannels.
zhihuang1c378ed2017-08-17 14:10:50 -0700352 void GetOptionsForOffer(
deadbeefab9b2d12015-10-14 11:33:11 -0700353 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
354 cricket::MediaSessionOptions* session_options);
355
356 // Returns a MediaSessionOptions struct with options decided by
357 // |constraints|, the local MediaStreams and DataChannels.
zhihuang1c378ed2017-08-17 14:10:50 -0700358 void GetOptionsForAnswer(const RTCOfferAnswerOptions& options,
359 cricket::MediaSessionOptions* session_options);
htaa2a49d92016-03-04 02:51:39 -0800360
zhihuang1c378ed2017-08-17 14:10:50 -0700361 // Generates MediaDescriptionOptions for the |session_opts| based on existing
362 // local description or remote description.
363 void GenerateMediaDescriptionOptions(
364 const SessionDescriptionInterface* session_desc,
365 cricket::RtpTransceiverDirection audio_direction,
366 cricket::RtpTransceiverDirection video_direction,
367 rtc::Optional<size_t>* audio_index,
368 rtc::Optional<size_t>* video_index,
369 rtc::Optional<size_t>* data_index,
htaa2a49d92016-03-04 02:51:39 -0800370 cricket::MediaSessionOptions* session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700371
deadbeeffaac4972015-11-12 15:33:07 -0800372 // Remove all local and remote tracks of type |media_type|.
373 // Called when a media type is rejected (m-line set to port 0).
374 void RemoveTracks(cricket::MediaType media_type);
375
deadbeefbda7e0b2015-12-08 17:13:40 -0800376 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
377 // and existing MediaStreamTracks are removed if there is no corresponding
378 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
379 // is created if it doesn't exist; if false, it's removed if it exists.
380 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700381 // If a new MediaStream is created it is added to |new_streams|.
382 void UpdateRemoteStreamsList(
383 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800384 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700385 cricket::MediaType media_type,
386 StreamCollection* new_streams);
387
388 // Triggered when a remote track has been seen for the first time in a remote
389 // session description. It creates a remote MediaStreamTrackInterface
390 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
391 void OnRemoteTrackSeen(const std::string& stream_label,
392 const std::string& track_id,
393 uint32_t ssrc,
394 cricket::MediaType media_type);
395
396 // Triggered when a remote track has been removed from a remote session
397 // description. It removes the remote track with id |track_id| from a remote
398 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
399 void OnRemoteTrackRemoved(const std::string& stream_label,
400 const std::string& track_id,
401 cricket::MediaType media_type);
402
403 // Finds remote MediaStreams without any tracks and removes them from
404 // |remote_streams_| and notifies the observer that the MediaStreams no longer
405 // exist.
406 void UpdateEndedRemoteMediaStreams();
407
deadbeefab9b2d12015-10-14 11:33:11 -0700408 // Loops through the vector of |streams| and finds added and removed
409 // StreamParams since last time this method was called.
410 // For each new or removed StreamParam, OnLocalTrackSeen or
411 // OnLocalTrackRemoved is invoked.
412 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams,
413 cricket::MediaType media_type);
414
415 // Triggered when a local track has been seen for the first time in a local
416 // session description.
417 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
418 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
419 // in a MediaStream in |local_streams_|
420 void OnLocalTrackSeen(const std::string& stream_label,
421 const std::string& track_id,
422 uint32_t ssrc,
423 cricket::MediaType media_type);
424
425 // Triggered when a local track has been removed from a local session
426 // description.
427 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
428 // has been removed from the local SessionDescription and the stream can be
429 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
430 void OnLocalTrackRemoved(const std::string& stream_label,
431 const std::string& track_id,
432 uint32_t ssrc,
433 cricket::MediaType media_type);
434
435 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
436 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
437 void UpdateClosingRtpDataChannels(
438 const std::vector<std::string>& active_channels,
439 bool is_local_update);
440 void CreateRemoteRtpDataChannel(const std::string& label,
441 uint32_t remote_ssrc);
442
443 // Creates channel and adds it to the collection of DataChannels that will
444 // be offered in a SessionDescription.
445 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
446 const std::string& label,
447 const InternalDataChannelInit* config);
448
449 // Checks if any data channel has been added.
450 bool HasDataChannels() const;
451
452 void AllocateSctpSids(rtc::SSLRole role);
453 void OnSctpDataChannelClosed(DataChannel* channel);
454
Steve Antonba818672017-11-06 10:21:57 -0800455 // Called when voice_channel_, video_channel_ and
456 // rtp_data_channel_/sctp_transport_ are created and destroyed. As a result
457 // of, for example, setting a new description.
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700458 void OnVoiceChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700459 void OnVoiceChannelDestroyed();
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700460 void OnVideoChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700461 void OnVideoChannelDestroyed();
462 void OnDataChannelCreated();
463 void OnDataChannelDestroyed();
Steve Antonba818672017-11-06 10:21:57 -0800464 // Called when a valid data channel OPEN message is received.
deadbeefab9b2d12015-10-14 11:33:11 -0700465 void OnDataChannelOpenMessage(const std::string& label,
466 const InternalDataChannelInit& config);
467
zhihuang1c378ed2017-08-17 14:10:50 -0700468 bool HasRtpSender(cricket::MediaType type) const;
deadbeefa601f5c2016-06-06 14:27:39 -0700469 RtpSenderInternal* FindSenderById(const std::string& id);
deadbeeffac06552015-11-25 11:26:01 -0800470
deadbeefa601f5c2016-06-06 14:27:39 -0700471 std::vector<rtc::scoped_refptr<
472 RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator
deadbeef70ab1a12015-09-28 16:53:55 -0700473 FindSenderForTrack(MediaStreamTrackInterface* track);
deadbeefa601f5c2016-06-06 14:27:39 -0700474 std::vector<rtc::scoped_refptr<
475 RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator
perkjd61bf802016-03-24 03:16:19 -0700476 FindReceiverForTrack(const std::string& track_id);
deadbeef70ab1a12015-09-28 16:53:55 -0700477
deadbeefab9b2d12015-10-14 11:33:11 -0700478 TrackInfos* GetRemoteTracks(cricket::MediaType media_type);
479 TrackInfos* GetLocalTracks(cricket::MediaType media_type);
480 const TrackInfo* FindTrackInfo(const TrackInfos& infos,
481 const std::string& stream_label,
482 const std::string track_id) const;
483
484 // Returns the specified SCTP DataChannel in sctp_data_channels_,
485 // or nullptr if not found.
486 DataChannel* FindDataChannelBySid(int sid) const;
487
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700488 // Called when first configuring the port allocator.
deadbeef91dd5672016-05-18 16:55:30 -0700489 bool InitializePortAllocator_n(const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 12:28:30 -0800490 // Called when SetConfiguration is called to apply the supported subset
491 // of the configuration on the network thread.
492 bool ReconfigurePortAllocator_n(
493 const cricket::ServerAddresses& stun_servers,
494 const std::vector<cricket::RelayServerConfig>& turn_servers,
495 IceTransportsType type,
496 int candidate_pool_size,
Jonas Orelandbdcee282017-10-10 14:01:40 +0200497 bool prune_turn_ports,
498 webrtc::TurnCustomizer* turn_customizer);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700499
Elad Alon99c3fe52017-10-13 16:29:40 +0200500 // Starts output of an RTC event log to the given output object.
ivoc14d5dbe2016-07-04 07:06:55 -0700501 // This function should only be called from the worker thread.
Elad Alon99c3fe52017-10-13 16:29:40 +0200502 bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output);
503
Elad Alonacb24172017-10-06 14:32:13 +0200504 // Stops recording an RTC event log.
ivoc14d5dbe2016-07-04 07:06:55 -0700505 // This function should only be called from the worker thread.
506 void StopRtcEventLog_w();
507
Steve Anton038834f2017-07-14 15:59:59 -0700508 // Ensures the configuration doesn't have any parameters with invalid values,
509 // or values that conflict with other parameters.
510 //
511 // Returns RTCError::OK() if there are no issues.
512 RTCError ValidateConfiguration(const RTCConfiguration& config) const;
513
Steve Antonba818672017-11-06 10:21:57 -0800514 cricket::ChannelManager* channel_manager() const;
515 MetricsObserverInterface* metrics_observer() const;
516
Steve Anton75737c02017-11-06 10:37:17 -0800517 // Indicates the type of SessionDescription in a call to SetLocalDescription
518 // and SetRemoteDescription.
519 enum Action {
520 kOffer,
521 kPrAnswer,
522 kAnswer,
523 };
524
525 // Returns the last error in the session. See the enum above for details.
526 Error error() const { return error_; }
527 const std::string& error_desc() const { return error_desc_; }
528
529 virtual std::vector<cricket::VoiceChannel*> voice_channels() const {
530 return voice_channels_;
531 }
532 virtual std::vector<cricket::VideoChannel*> video_channels() const {
533 return video_channels_;
534 }
535
536 cricket::BaseChannel* GetChannel(const std::string& content_name);
537
538 // Get current SSL role used by SCTP's underlying transport.
539 bool GetSctpSslRole(rtc::SSLRole* role);
540
541 void CreateOffer(
542 CreateSessionDescriptionObserver* observer,
543 const PeerConnectionInterface::RTCOfferAnswerOptions& options,
544 const cricket::MediaSessionOptions& session_options);
545 void CreateAnswer(CreateSessionDescriptionObserver* observer,
546 const cricket::MediaSessionOptions& session_options);
547 bool SetLocalDescription(std::unique_ptr<SessionDescriptionInterface> desc,
548 std::string* err_desc);
549 bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc,
550 std::string* err_desc);
551
552 bool ProcessIceMessage(const IceCandidateInterface* ice_candidate);
553
554 bool RemoveRemoteIceCandidates(
555 const std::vector<cricket::Candidate>& candidates);
556
557 cricket::IceConfig ParseIceConfig(
558 const PeerConnectionInterface::RTCConfiguration& config) const;
559
560 void SetIceConfig(const cricket::IceConfig& ice_config);
561
562 // Start gathering candidates for any new transports, or transports doing an
563 // ICE restart.
564 void MaybeStartGathering();
565
566 // Implements DataChannelProviderInterface.
567 bool SendData(const cricket::SendDataParams& params,
568 const rtc::CopyOnWriteBuffer& payload,
569 cricket::SendDataResult* result) override;
570 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override;
571 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override;
572 void AddSctpDataStream(int sid) override;
573 void RemoveSctpDataStream(int sid) override;
574 bool ReadyToSendData() const override;
575
576 cricket::DataChannelType data_channel_type() const;
577
578 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
579 // set, offers should generate new ufrags/passwords until an ICE restart
580 // occurs.
581 void SetNeedsIceRestartFlag();
582
583 // Called when an RTCCertificate is generated or retrieved by
584 // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription.
585 void OnCertificateReady(
586 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
587 void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp);
588
589 cricket::TransportController* transport_controller() const {
590 return transport_controller_.get();
591 }
592
593 // Return all managed, non-null channels.
594 std::vector<cricket::BaseChannel*> Channels() const;
595
596 // Non-const versions of local_description()/remote_description(), for use
597 // internally.
598 SessionDescriptionInterface* mutable_local_description() {
599 return pending_local_description_ ? pending_local_description_.get()
600 : current_local_description_.get();
601 }
602 SessionDescriptionInterface* mutable_remote_description() {
603 return pending_remote_description_ ? pending_remote_description_.get()
604 : current_remote_description_.get();
605 }
606
607 // Updates the error state, signaling if necessary.
608 void SetError(Error error, const std::string& error_desc);
609
610 bool UpdateSessionState(Action action,
611 cricket::ContentSource source,
612 std::string* err_desc);
613 Action GetAction(const std::string& type);
614 // Push the media parts of the local or remote session description
615 // down to all of the channels.
616 bool PushdownMediaDescription(cricket::ContentAction action,
617 cricket::ContentSource source,
618 std::string* error_desc);
619 bool PushdownSctpParameters_n(cricket::ContentSource source);
620
621 bool PushdownTransportDescription(cricket::ContentSource source,
622 cricket::ContentAction action,
623 std::string* error_desc);
624
625 // Helper methods to push local and remote transport descriptions.
626 bool PushdownLocalTransportDescription(
627 const cricket::SessionDescription* sdesc,
628 cricket::ContentAction action,
629 std::string* error_desc);
630 bool PushdownRemoteTransportDescription(
631 const cricket::SessionDescription* sdesc,
632 cricket::ContentAction action,
633 std::string* error_desc);
634
635 // Returns true and the TransportInfo of the given |content_name|
636 // from |description|. Returns false if it's not available.
637 static bool GetTransportDescription(
638 const cricket::SessionDescription* description,
639 const std::string& content_name,
640 cricket::TransportDescription* info);
641
642 // Returns the name of the transport channel when BUNDLE is enabled, or
643 // nullptr if the channel is not part of any bundle.
644 const std::string* GetBundleTransportName(
645 const cricket::ContentInfo* content,
646 const cricket::ContentGroup* bundle);
647
648 // Cause all the BaseChannels in the bundle group to have the same
649 // transport channel.
650 bool EnableBundle(const cricket::ContentGroup& bundle);
651
652 // Enables media channels to allow sending of media.
653 void EnableChannels();
654 // Returns the media index for a local ice candidate given the content name.
655 // Returns false if the local session description does not have a media
656 // content called |content_name|.
657 bool GetLocalCandidateMediaIndex(const std::string& content_name,
658 int* sdp_mline_index);
659 // Uses all remote candidates in |remote_desc| in this session.
660 bool UseCandidatesInSessionDescription(
661 const SessionDescriptionInterface* remote_desc);
662 // Uses |candidate| in this session.
663 bool UseCandidate(const IceCandidateInterface* candidate);
664 // Deletes the corresponding channel of contents that don't exist in |desc|.
665 // |desc| can be null. This means that all channels are deleted.
666 void RemoveUnusedChannels(const cricket::SessionDescription* desc);
667
668 // Allocates media channels based on the |desc|. If |desc| doesn't have
669 // the BUNDLE option, this method will disable BUNDLE in PortAllocator.
670 // This method will also delete any existing media channels before creating.
671 bool CreateChannels(const cricket::SessionDescription* desc);
672
673 // Helper methods to create media channels.
674 bool CreateVoiceChannel(const cricket::ContentInfo* content,
675 const std::string* bundle_transport);
676 bool CreateVideoChannel(const cricket::ContentInfo* content,
677 const std::string* bundle_transport);
678 bool CreateDataChannel(const cricket::ContentInfo* content,
679 const std::string* bundle_transport);
680
681 std::unique_ptr<SessionStats> GetSessionStats_n(
682 const ChannelNamePairs& channel_name_pairs);
683
684 bool CreateSctpTransport_n(const std::string& content_name,
685 const std::string& transport_name);
686 // For bundling.
687 void ChangeSctpTransport_n(const std::string& transport_name);
688 void DestroySctpTransport_n();
689 // SctpTransport signal handlers. Needed to marshal signals from the network
690 // to signaling thread.
691 void OnSctpTransportReadyToSendData_n();
692 // This may be called with "false" if the direction of the m= section causes
693 // us to tear down the SCTP connection.
694 void OnSctpTransportReadyToSendData_s(bool ready);
695 void OnSctpTransportDataReceived_n(const cricket::ReceiveDataParams& params,
696 const rtc::CopyOnWriteBuffer& payload);
697 // Beyond just firing the signal to the signaling thread, listens to SCTP
698 // CONTROL messages on unused SIDs and processes them as OPEN messages.
699 void OnSctpTransportDataReceived_s(const cricket::ReceiveDataParams& params,
700 const rtc::CopyOnWriteBuffer& payload);
701 void OnSctpStreamClosedRemotely_n(int sid);
702
703 bool ValidateBundleSettings(const cricket::SessionDescription* desc);
704 bool HasRtcpMuxEnabled(const cricket::ContentInfo* content);
705 // Below methods are helper methods which verifies SDP.
706 bool ValidateSessionDescription(const SessionDescriptionInterface* sdesc,
707 cricket::ContentSource source,
708 std::string* err_desc);
709
710 // Check if a call to SetLocalDescription is acceptable with |action|.
711 bool ExpectSetLocalDescription(Action action);
712 // Check if a call to SetRemoteDescription is acceptable with |action|.
713 bool ExpectSetRemoteDescription(Action action);
714 // Verifies a=setup attribute as per RFC 5763.
715 bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc,
716 Action action);
717
718 // Returns true if we are ready to push down the remote candidate.
719 // |remote_desc| is the new remote description, or NULL if the current remote
720 // description should be used. Output |valid| is true if the candidate media
721 // index is valid.
722 bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate,
723 const SessionDescriptionInterface* remote_desc,
724 bool* valid);
725
726 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
727 // this session.
728 bool SrtpRequired() const;
729
730 // TransportController signal handlers.
731 void OnTransportControllerConnectionState(cricket::IceConnectionState state);
732 void OnTransportControllerGatheringState(cricket::IceGatheringState state);
733 void OnTransportControllerCandidatesGathered(
734 const std::string& transport_name,
735 const std::vector<cricket::Candidate>& candidates);
736 void OnTransportControllerCandidatesRemoved(
737 const std::vector<cricket::Candidate>& candidates);
738 void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error);
739
740 std::string GetSessionErrorMsg();
741
742 // Invoked when TransportController connection completion is signaled.
743 // Reports stats for all transports in use.
744 void ReportTransportStats();
745
746 // Gather the usage of IPv4/IPv6 as best connection.
747 void ReportBestConnectionState(const cricket::TransportStats& stats);
748
749 void ReportNegotiatedCiphers(const cricket::TransportStats& stats);
750
751 void OnSentPacket_w(const rtc::SentPacket& sent_packet);
752
753 const std::string GetTransportName(const std::string& content_name);
754
755 void DestroyRtcpTransport_n(const std::string& transport_name);
756 void RemoveAndDestroyVideoChannel(cricket::VideoChannel* video_channel);
757 void DestroyVideoChannel(cricket::VideoChannel* video_channel);
758 void RemoveAndDestroyVoiceChannel(cricket::VoiceChannel* voice_channel);
759 void DestroyVoiceChannel(cricket::VoiceChannel* voice_channel);
760 void DestroyDataChannel();
761
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 // Storing the factory as a scoped reference pointer ensures that the memory
763 // in the PeerConnectionFactoryImpl remains available as long as the
764 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
765 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -0700766 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 // will refer to the same reference count.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000768 rtc::scoped_refptr<PeerConnectionFactory> factory_;
Steve Antonba818672017-11-06 10:21:57 -0800769 PeerConnectionObserver* observer_ = nullptr;
770 UMAObserver* uma_observer_ = nullptr;
terelius33860252017-05-12 23:37:18 -0700771
772 // The EventLog needs to outlive |call_| (and any other object that uses it).
773 std::unique_ptr<RtcEventLog> event_log_;
774
Steve Antonba818672017-11-06 10:21:57 -0800775 SignalingState signaling_state_ = kStable;
776 IceConnectionState ice_connection_state_ = kIceConnectionNew;
777 IceGatheringState ice_gathering_state_ = kIceGatheringNew;
deadbeef46c73892016-11-16 19:42:04 -0800778 PeerConnectionInterface::RTCConfiguration configuration_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779
kwibergd1fe2812016-04-27 06:47:29 -0700780 std::unique_ptr<cricket::PortAllocator> port_allocator_;
deadbeefab9b2d12015-10-14 11:33:11 -0700781
zhihuang8f65cdf2016-05-06 18:40:30 -0700782 // One PeerConnection has only one RTCP CNAME.
783 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
784 std::string rtcp_cname_;
785
deadbeefab9b2d12015-10-14 11:33:11 -0700786 // Streams added via AddStream.
787 rtc::scoped_refptr<StreamCollection> local_streams_;
788 // Streams created as a result of SetRemoteDescription.
789 rtc::scoped_refptr<StreamCollection> remote_streams_;
790
kwibergd1fe2812016-04-27 06:47:29 -0700791 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
deadbeefeb459812015-12-15 19:24:43 -0800792
deadbeefab9b2d12015-10-14 11:33:11 -0700793 // These lists store track info seen in local/remote descriptions.
794 TrackInfos remote_audio_tracks_;
795 TrackInfos remote_video_tracks_;
796 TrackInfos local_audio_tracks_;
797 TrackInfos local_video_tracks_;
798
799 SctpSidAllocator sid_allocator_;
800 // label -> DataChannel
801 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
802 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
deadbeefbd292462015-12-14 18:15:29 -0800803 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
deadbeefab9b2d12015-10-14 11:33:11 -0700804
deadbeefbda7e0b2015-12-08 17:13:40 -0800805 bool remote_peer_supports_msid_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700806
terelius33860252017-05-12 23:37:18 -0700807 std::unique_ptr<Call> call_;
terelius33860252017-05-12 23:37:18 -0700808 std::unique_ptr<StatsCollector> stats_; // A pointer is passed to senders_
809 rtc::scoped_refptr<RTCStatsCollector> stats_collector_;
810
deadbeefa601f5c2016-06-06 14:27:39 -0700811 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
812 senders_;
813 std::vector<
814 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
815 receivers_;
Steve Anton75737c02017-11-06 10:37:17 -0800816
817 Error error_ = ERROR_NONE;
818 std::string error_desc_;
819
820 std::string session_id_;
821 rtc::Optional<bool> initial_offerer_;
822
823 std::unique_ptr<cricket::TransportController> transport_controller_;
824 std::unique_ptr<cricket::SctpTransportInternalFactory> sctp_factory_;
825 // TODO(steveanton): voice_channels_ and video_channels_ used to be a single
826 // VoiceChannel/VideoChannel respectively but are being changed to support
827 // multiple m= lines in unified plan. But until more work is done, these can
828 // only have 0 or 1 channel each.
829 // These channels are owned by ChannelManager.
830 std::vector<cricket::VoiceChannel*> voice_channels_;
831 std::vector<cricket::VideoChannel*> video_channels_;
832 // |rtp_data_channel_| is used if in RTP data channel mode, |sctp_transport_|
833 // when using SCTP.
834 cricket::RtpDataChannel* rtp_data_channel_ = nullptr;
835
836 std::unique_ptr<cricket::SctpTransportInternal> sctp_transport_;
837 // |sctp_transport_name_| keeps track of what DTLS transport the SCTP
838 // transport is using (which can change due to bundling).
839 rtc::Optional<std::string> sctp_transport_name_;
840 // |sctp_content_name_| is the content name (MID) in SDP.
841 rtc::Optional<std::string> sctp_content_name_;
842 // Value cached on signaling thread. Only updated when SctpReadyToSendData
843 // fires on the signaling thread.
844 bool sctp_ready_to_send_data_ = false;
845 // Same as signals provided by SctpTransport, but these are guaranteed to
846 // fire on the signaling thread, whereas SctpTransport fires on the networking
847 // thread.
848 // |sctp_invoker_| is used so that any signals queued on the signaling thread
849 // from the network thread are immediately discarded if the SctpTransport is
850 // destroyed (due to m= section being rejected).
851 // TODO(deadbeef): Use a proxy object to ensure that method calls/signals
852 // are marshalled to the right thread. Could almost use proxy.h for this,
853 // but it doesn't have a mechanism for marshalling sigslot::signals
854 std::unique_ptr<rtc::AsyncInvoker> sctp_invoker_;
855 sigslot::signal1<bool> SignalSctpReadyToSendData;
856 sigslot::signal2<const cricket::ReceiveDataParams&,
857 const rtc::CopyOnWriteBuffer&>
858 SignalSctpDataReceived;
859 sigslot::signal1<int> SignalSctpStreamClosedRemotely;
860
861 std::unique_ptr<SessionDescriptionInterface> current_local_description_;
862 std::unique_ptr<SessionDescriptionInterface> pending_local_description_;
863 std::unique_ptr<SessionDescriptionInterface> current_remote_description_;
864 std::unique_ptr<SessionDescriptionInterface> pending_remote_description_;
865 bool dtls_enabled_ = false;
866 // Specifies which kind of data channel is allowed. This is controlled
867 // by the chrome command-line flag and constraints:
868 // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled,
869 // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is
870 // not set or false, SCTP is allowed (DCT_SCTP);
871 // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP);
872 // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE).
873 cricket::DataChannelType data_channel_type_ = cricket::DCT_NONE;
874 // List of content names for which the remote side triggered an ICE restart.
875 std::set<std::string> pending_ice_restarts_;
876
877 std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_;
878
879 // Member variables for caching global options.
880 cricket::AudioOptions audio_options_;
881 cricket::VideoOptions video_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882};
883
884} // namespace webrtc
885
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200886#endif // PC_PEERCONNECTION_H_