blob: ae6b537bda942300c34a7be2aeff01bfe28fe9de [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"
Steve Anton4171afb2017-11-20 10:20:22 -080025#include "pc/rtptransceiver.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "pc/statscollector.h"
27#include "pc/streamcollection.h"
Steve Anton75737c02017-11-06 10:37:17 -080028#include "pc/webrtcsessiondescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
30namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031
deadbeefeb459812015-12-15 19:24:43 -080032class MediaStreamObserver;
perkjf0dcfe22016-03-10 18:32:00 +010033class VideoRtpReceiver;
skvlad11a9cbf2016-10-07 11:53:05 -070034class RtcEventLog;
deadbeefab9b2d12015-10-14 11:33:11 -070035
Steve Anton75737c02017-11-06 10:37:17 -080036// Statistics for all the transports of the session.
37// TODO(pthatcher): Think of a better name for this. We already have
38// a TransportStats in transport.h. Perhaps TransportsStats?
39struct SessionStats {
40 std::map<std::string, std::string> proxy_to_transport;
41 std::map<std::string, cricket::TransportStats> transport_stats;
42};
Steve Antonba818672017-11-06 10:21:57 -080043
Steve Anton75737c02017-11-06 10:37:17 -080044struct ChannelNamePair {
45 ChannelNamePair(const std::string& content_name,
46 const std::string& transport_name)
47 : content_name(content_name), transport_name(transport_name) {}
48 std::string content_name;
49 std::string transport_name;
50};
51
52struct ChannelNamePairs {
53 rtc::Optional<ChannelNamePair> voice;
54 rtc::Optional<ChannelNamePair> video;
55 rtc::Optional<ChannelNamePair> data;
56};
57
58// PeerConnection is the implementation of the PeerConnection object as defined
59// by the PeerConnectionInterface API surface.
60// The class currently is solely responsible for the following:
61// - Managing the session state machine (signaling state).
62// - Creating and initializing lower-level objects, like PortAllocator and
63// BaseChannels.
64// - Owning and managing the life cycle of the RtpSender/RtpReceiver and track
65// objects.
66// - Tracking the current and pending local/remote session descriptions.
67// The class currently is jointly responsible for the following:
68// - Parsing and interpreting SDP.
69// - Generating offers and answers based on the current state.
70// - The ICE state machine.
71// - Generating stats.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072class PeerConnection : public PeerConnectionInterface,
Steve Anton75737c02017-11-06 10:37:17 -080073 public DataChannelProviderInterface,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074 public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 public sigslot::has_slots<> {
76 public:
zhihuang38ede132017-06-15 12:52:32 -070077 explicit PeerConnection(PeerConnectionFactory* factory,
78 std::unique_ptr<RtcEventLog> event_log,
79 std::unique_ptr<Call> call);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080
deadbeef653b8e02015-11-11 12:55:10 -080081 bool Initialize(
82 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -070083 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020084 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef653b8e02015-11-11 12:55:10 -080085 PeerConnectionObserver* observer);
86
deadbeefa67696b2015-09-29 11:56:26 -070087 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
88 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
89 bool AddStream(MediaStreamInterface* local_stream) override;
90 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091
deadbeefe1f9d832016-01-14 15:35:42 -080092 rtc::scoped_refptr<RtpSenderInterface> AddTrack(
93 MediaStreamTrackInterface* track,
94 std::vector<MediaStreamInterface*> streams) override;
95 bool RemoveTrack(RtpSenderInterface* sender) override;
96
Steve Anton8c0f7a72017-10-03 10:03:10 -070097 // Gets the DTLS SSL certificate associated with the audio transport on the
98 // remote side. This will become populated once the DTLS connection with the
99 // peer has been completed, as indicated by the ICE connection state
100 // transitioning to kIceConnectionCompleted.
101 // Note that this will be removed once we implement RTCDtlsTransport which
102 // has standardized method for getting this information.
103 // See https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface
104 std::unique_ptr<rtc::SSLCertificate> GetRemoteAudioSSLCertificate();
105
deadbeefa67696b2015-09-29 11:56:26 -0700106 rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
107 AudioTrackInterface* track) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108
deadbeeffac06552015-11-25 11:26:01 -0800109 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800110 const std::string& kind,
111 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -0800112
deadbeef70ab1a12015-09-28 16:53:55 -0700113 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
114 const override;
115 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
116 const override;
117
deadbeefa67696b2015-09-29 11:56:26 -0700118 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700120 const DataChannelInit* config) override;
121 bool GetStats(StatsObserver* observer,
122 webrtc::MediaStreamTrackInterface* track,
123 StatsOutputLevel level) override;
hbos74e1a4f2016-09-15 23:33:01 -0700124 void GetStats(RTCStatsCollectorCallback* callback) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125
deadbeefa67696b2015-09-29 11:56:26 -0700126 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
deadbeefa67696b2015-09-29 11:56:26 -0700128 IceConnectionState ice_connection_state() override;
129 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130
deadbeefa67696b2015-09-29 11:56:26 -0700131 const SessionDescriptionInterface* local_description() const override;
132 const SessionDescriptionInterface* remote_description() const override;
deadbeeffe4a8a42016-12-20 17:56:17 -0800133 const SessionDescriptionInterface* current_local_description() const override;
134 const SessionDescriptionInterface* current_remote_description()
135 const override;
136 const SessionDescriptionInterface* pending_local_description() const override;
137 const SessionDescriptionInterface* pending_remote_description()
138 const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139
140 // JSEP01
htaa2a49d92016-03-04 02:51:39 -0800141 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700142 void CreateOffer(CreateSessionDescriptionObserver* observer,
143 const MediaConstraintsInterface* constraints) override;
144 void CreateOffer(CreateSessionDescriptionObserver* observer,
145 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800146 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700147 void CreateAnswer(CreateSessionDescriptionObserver* observer,
148 const MediaConstraintsInterface* constraints) override;
htaa2a49d92016-03-04 02:51:39 -0800149 void CreateAnswer(CreateSessionDescriptionObserver* observer,
150 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700151 void SetLocalDescription(SetSessionDescriptionObserver* observer,
152 SessionDescriptionInterface* desc) override;
153 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
154 SessionDescriptionInterface* desc) override;
deadbeef46c73892016-11-16 19:42:04 -0800155 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
deadbeefa67696b2015-09-29 11:56:26 -0700156 bool SetConfiguration(
deadbeef293e9262017-01-11 12:28:30 -0800157 const PeerConnectionInterface::RTCConfiguration& configuration,
158 RTCError* error) override;
159 bool SetConfiguration(
160 const PeerConnectionInterface::RTCConfiguration& configuration) override {
161 return SetConfiguration(configuration, nullptr);
162 }
deadbeefa67696b2015-09-29 11:56:26 -0700163 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700164 bool RemoveIceCandidates(
165 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166
deadbeefa67696b2015-09-29 11:56:26 -0700167 void RegisterUMAObserver(UMAObserver* observer) override;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000168
zstein4b979802017-06-02 14:37:37 -0700169 RTCError SetBitrate(const BitrateParameters& bitrate) override;
170
Alex Narest78609d52017-10-20 10:37:47 +0200171 void SetBitrateAllocationStrategy(
172 std::unique_ptr<rtc::BitrateAllocationStrategy>
173 bitrate_allocation_strategy) override;
174
henrika5f6bf242017-11-01 11:06:56 +0100175 void SetAudioPlayout(bool playout) override;
176 void SetAudioRecording(bool recording) override;
177
Elad Alon99c3fe52017-10-13 16:29:40 +0200178 RTC_DEPRECATED bool StartRtcEventLog(rtc::PlatformFile file,
179 int64_t max_size_bytes) override;
Zhi Huang33c5c7f2017-11-17 20:59:29 +0000180 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override;
ivoc14d5dbe2016-07-04 07:06:55 -0700181 void StopRtcEventLog() override;
182
deadbeefa67696b2015-09-29 11:56:26 -0700183 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184
hbos82ebe022016-11-14 01:41:09 -0800185 sigslot::signal1<DataChannel*> SignalDataChannelCreated;
186
deadbeefab9b2d12015-10-14 11:33:11 -0700187 // Virtual for unit tests.
188 virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
189 sctp_data_channels() const {
190 return sctp_data_channels_;
perkjd61bf802016-03-24 03:16:19 -0700191 }
deadbeefab9b2d12015-10-14 11:33:11 -0700192
Steve Anton978b8762017-09-29 12:15:02 -0700193 rtc::Thread* network_thread() const { return factory_->network_thread(); }
194 rtc::Thread* worker_thread() const { return factory_->worker_thread(); }
195 rtc::Thread* signaling_thread() const { return factory_->signaling_thread(); }
Steve Anton75737c02017-11-06 10:37:17 -0800196
197 // The SDP session ID as defined by RFC 3264.
198 virtual const std::string& session_id() const { return session_id_; }
199
200 // Returns true if we were the initial offerer.
201 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
202
203 // Returns stats for all channels of all transports.
204 // This avoids exposing the internal structures used to track them.
205 // The parameterless version creates |ChannelNamePairs| from |voice_channel|,
206 // |video_channel| and |voice_channel| if available - this requires it to be
207 // called on the signaling thread - and invokes the other |GetStats|. The
208 // other |GetStats| can be invoked on any thread; if not invoked on the
209 // network thread a thread hop will happen.
210 std::unique_ptr<SessionStats> GetSessionStats_s();
Steve Anton978b8762017-09-29 12:15:02 -0700211 virtual std::unique_ptr<SessionStats> GetSessionStats(
Steve Anton75737c02017-11-06 10:37:17 -0800212 const ChannelNamePairs& channel_name_pairs);
213
214 // virtual so it can be mocked in unit tests
Steve Anton978b8762017-09-29 12:15:02 -0700215 virtual bool GetLocalCertificate(
216 const std::string& transport_name,
Steve Anton75737c02017-11-06 10:37:17 -0800217 rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
Steve Anton978b8762017-09-29 12:15:02 -0700218 virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
Steve Anton75737c02017-11-06 10:37:17 -0800219 const std::string& transport_name);
220
221 virtual Call::Stats GetCallStats();
222
223 // Exposed for stats collecting.
224 // TODO(steveanton): Switch callers to use the plural form and remove these.
Steve Anton4171afb2017-11-20 10:20:22 -0800225 virtual cricket::VoiceChannel* voice_channel() const {
226 return static_cast<cricket::VoiceChannel*>(
227 GetAudioTransceiver()->internal()->channel());
Steve Anton978b8762017-09-29 12:15:02 -0700228 }
Steve Anton4171afb2017-11-20 10:20:22 -0800229 virtual cricket::VideoChannel* video_channel() const {
230 return static_cast<cricket::VideoChannel*>(
231 GetVideoTransceiver()->internal()->channel());
Steve Antond5585ca2017-10-23 14:49:26 -0700232 }
Steve Anton978b8762017-09-29 12:15:02 -0700233
Steve Anton75737c02017-11-06 10:37:17 -0800234 // Only valid when using deprecated RTP data channels.
235 virtual cricket::RtpDataChannel* rtp_data_channel() {
236 return rtp_data_channel_;
Steve Anton978b8762017-09-29 12:15:02 -0700237 }
Steve Anton75737c02017-11-06 10:37:17 -0800238 virtual rtc::Optional<std::string> sctp_content_name() const {
239 return sctp_content_name_;
240 }
241 virtual rtc::Optional<std::string> sctp_transport_name() const {
242 return sctp_transport_name_;
243 }
244
245 // Get the id used as a media stream track's "id" field from ssrc.
246 virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
247 virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
248
249 // Returns true if there was an ICE restart initiated by the remote offer.
250 bool IceRestartPending(const std::string& content_name) const;
251
252 // Returns true if the ICE restart flag above was set, and no ICE restart has
253 // occurred yet for this transport (by applying a local description with
254 // changed ufrag/password). If the transport has been deleted as a result of
255 // bundling, returns false.
256 bool NeedsIceRestart(const std::string& content_name) const;
257
258 // Get SSL role for an arbitrary m= section (handles bundling correctly).
259 // TODO(deadbeef): This is only used internally by the session description
260 // factory, it shouldn't really be public).
261 bool GetSslRole(const std::string& content_name, rtc::SSLRole* role);
262
263 enum Error {
264 ERROR_NONE = 0, // no error
265 ERROR_CONTENT = 1, // channel errors in SetLocalContent/SetRemoteContent
266 ERROR_TRANSPORT = 2, // transport error of some kind
267 };
Steve Anton978b8762017-09-29 12:15:02 -0700268
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700270 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271
272 private:
Steve Anton4171afb2017-11-20 10:20:22 -0800273 struct RtpSenderInfo {
274 RtpSenderInfo() : first_ssrc(0) {}
275 RtpSenderInfo(const std::string& stream_label,
276 const std::string sender_id,
277 uint32_t ssrc)
278 : stream_label(stream_label), sender_id(sender_id), first_ssrc(ssrc) {}
279 bool operator==(const RtpSenderInfo& other) {
deadbeefbda7e0b2015-12-08 17:13:40 -0800280 return this->stream_label == other.stream_label &&
Steve Anton4171afb2017-11-20 10:20:22 -0800281 this->sender_id == other.sender_id &&
282 this->first_ssrc == other.first_ssrc;
deadbeefbda7e0b2015-12-08 17:13:40 -0800283 }
deadbeefab9b2d12015-10-14 11:33:11 -0700284 std::string stream_label;
Steve Anton4171afb2017-11-20 10:20:22 -0800285 std::string sender_id;
286 // An RtpSender can have many SSRCs. The first one is used as a sort of ID
287 // for communicating with the lower layers.
288 uint32_t first_ssrc;
deadbeefab9b2d12015-10-14 11:33:11 -0700289 };
deadbeefab9b2d12015-10-14 11:33:11 -0700290
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291 // Implements MessageHandler.
deadbeefa67696b2015-09-29 11:56:26 -0700292 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293
Steve Anton4171afb2017-11-20 10:20:22 -0800294 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
295 GetSendersInternal() const;
296 std::vector<
297 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
298 GetReceiversInternal() const;
299
300 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
301 GetAudioTransceiver() const;
302 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
303 GetVideoTransceiver() const;
304
deadbeefab9b2d12015-10-14 11:33:11 -0700305 void CreateAudioReceiver(MediaStreamInterface* stream,
Steve Anton4171afb2017-11-20 10:20:22 -0800306 const RtpSenderInfo& remote_sender_info);
perkjf0dcfe22016-03-10 18:32:00 +0100307
deadbeefab9b2d12015-10-14 11:33:11 -0700308 void CreateVideoReceiver(MediaStreamInterface* stream,
Steve Anton4171afb2017-11-20 10:20:22 -0800309 const RtpSenderInfo& remote_sender_info);
Henrik Boström933d8b02017-10-10 10:05:16 -0700310 rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver(
Steve Anton4171afb2017-11-20 10:20:22 -0800311 const RtpSenderInfo& remote_sender_info);
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700312
313 // May be called either by AddStream/RemoveStream, or when a track is
314 // added/removed from a stream previously added via AddStream.
315 void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream);
316 void RemoveAudioTrack(AudioTrackInterface* track,
317 MediaStreamInterface* stream);
318 void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream);
319 void RemoveVideoTrack(VideoTrackInterface* track,
320 MediaStreamInterface* stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321
Steve Antonba818672017-11-06 10:21:57 -0800322 void SetIceConnectionState(IceConnectionState new_state);
323 // Called any time the IceGatheringState changes
324 void OnIceGatheringChange(IceGatheringState new_state);
325 // New ICE candidate has been gathered.
326 void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate);
327 // Some local ICE candidates have been removed.
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700328 void OnIceCandidatesRemoved(
Steve Antonba818672017-11-06 10:21:57 -0800329 const std::vector<cricket::Candidate>& candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330
Steve Antonba818672017-11-06 10:21:57 -0800331 // Update the state, signaling if necessary.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 void ChangeSignalingState(SignalingState signaling_state);
333
deadbeefeb459812015-12-15 19:24:43 -0800334 // Signals from MediaStreamObserver.
335 void OnAudioTrackAdded(AudioTrackInterface* track,
336 MediaStreamInterface* stream);
337 void OnAudioTrackRemoved(AudioTrackInterface* track,
338 MediaStreamInterface* stream);
339 void OnVideoTrackAdded(VideoTrackInterface* track,
340 MediaStreamInterface* stream);
341 void OnVideoTrackRemoved(VideoTrackInterface* track,
342 MediaStreamInterface* stream);
343
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
345 const std::string& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700346 void PostCreateSessionDescriptionFailure(
347 CreateSessionDescriptionObserver* observer,
348 const std::string& error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349
350 bool IsClosed() const {
351 return signaling_state_ == PeerConnectionInterface::kClosed;
352 }
353
deadbeefab9b2d12015-10-14 11:33:11 -0700354 // Returns a MediaSessionOptions struct with options decided by |options|,
355 // the local MediaStreams and DataChannels.
zhihuang1c378ed2017-08-17 14:10:50 -0700356 void GetOptionsForOffer(
deadbeefab9b2d12015-10-14 11:33:11 -0700357 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
358 cricket::MediaSessionOptions* session_options);
359
360 // Returns a MediaSessionOptions struct with options decided by
361 // |constraints|, the local MediaStreams and DataChannels.
zhihuang1c378ed2017-08-17 14:10:50 -0700362 void GetOptionsForAnswer(const RTCOfferAnswerOptions& options,
363 cricket::MediaSessionOptions* session_options);
htaa2a49d92016-03-04 02:51:39 -0800364
zhihuang1c378ed2017-08-17 14:10:50 -0700365 // Generates MediaDescriptionOptions for the |session_opts| based on existing
366 // local description or remote description.
367 void GenerateMediaDescriptionOptions(
368 const SessionDescriptionInterface* session_desc,
369 cricket::RtpTransceiverDirection audio_direction,
370 cricket::RtpTransceiverDirection video_direction,
371 rtc::Optional<size_t>* audio_index,
372 rtc::Optional<size_t>* video_index,
373 rtc::Optional<size_t>* data_index,
htaa2a49d92016-03-04 02:51:39 -0800374 cricket::MediaSessionOptions* session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700375
Steve Anton4171afb2017-11-20 10:20:22 -0800376 // Remove all local and remote senders of type |media_type|.
deadbeeffaac4972015-11-12 15:33:07 -0800377 // Called when a media type is rejected (m-line set to port 0).
Steve Anton4171afb2017-11-20 10:20:22 -0800378 void RemoveSenders(cricket::MediaType media_type);
deadbeeffaac4972015-11-12 15:33:07 -0800379
deadbeefbda7e0b2015-12-08 17:13:40 -0800380 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
381 // and existing MediaStreamTracks are removed if there is no corresponding
382 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
383 // is created if it doesn't exist; if false, it's removed if it exists.
384 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700385 // If a new MediaStream is created it is added to |new_streams|.
Steve Anton4171afb2017-11-20 10:20:22 -0800386 void UpdateRemoteSendersList(
deadbeefab9b2d12015-10-14 11:33:11 -0700387 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800388 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700389 cricket::MediaType media_type,
390 StreamCollection* new_streams);
391
Steve Anton4171afb2017-11-20 10:20:22 -0800392 // Triggered when a remote sender has been seen for the first time in a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700393 // session description. It creates a remote MediaStreamTrackInterface
394 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800395 void OnRemoteSenderAdded(const RtpSenderInfo& sender_info,
396 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700397
Steve Anton4171afb2017-11-20 10:20:22 -0800398 // Triggered when a remote sender has been removed from a remote session
399 // description. It removes the remote sender with id |sender_id| from a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700400 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800401 void OnRemoteSenderRemoved(const RtpSenderInfo& sender_info,
402 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700403
404 // Finds remote MediaStreams without any tracks and removes them from
405 // |remote_streams_| and notifies the observer that the MediaStreams no longer
406 // exist.
407 void UpdateEndedRemoteMediaStreams();
408
deadbeefab9b2d12015-10-14 11:33:11 -0700409 // Loops through the vector of |streams| and finds added and removed
410 // StreamParams since last time this method was called.
Steve Anton4171afb2017-11-20 10:20:22 -0800411 // For each new or removed StreamParam, OnLocalSenderSeen or
412 // OnLocalSenderRemoved is invoked.
413 void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams,
414 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700415
Steve Anton4171afb2017-11-20 10:20:22 -0800416 // Triggered when a local sender has been seen for the first time in a local
deadbeefab9b2d12015-10-14 11:33:11 -0700417 // session description.
418 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
419 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
420 // in a MediaStream in |local_streams_|
Steve Anton4171afb2017-11-20 10:20:22 -0800421 void OnLocalSenderAdded(const RtpSenderInfo& sender_info,
422 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700423
Steve Anton4171afb2017-11-20 10:20:22 -0800424 // Triggered when a local sender has been removed from a local session
deadbeefab9b2d12015-10-14 11:33:11 -0700425 // description.
426 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
427 // has been removed from the local SessionDescription and the stream can be
428 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
Steve Anton4171afb2017-11-20 10:20:22 -0800429 void OnLocalSenderRemoved(const RtpSenderInfo& sender_info,
430 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700431
432 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
433 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
434 void UpdateClosingRtpDataChannels(
435 const std::vector<std::string>& active_channels,
436 bool is_local_update);
437 void CreateRemoteRtpDataChannel(const std::string& label,
438 uint32_t remote_ssrc);
439
440 // Creates channel and adds it to the collection of DataChannels that will
441 // be offered in a SessionDescription.
442 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
443 const std::string& label,
444 const InternalDataChannelInit* config);
445
446 // Checks if any data channel has been added.
447 bool HasDataChannels() const;
448
449 void AllocateSctpSids(rtc::SSLRole role);
450 void OnSctpDataChannelClosed(DataChannel* channel);
451
deadbeefab9b2d12015-10-14 11:33:11 -0700452 void OnDataChannelDestroyed();
Steve Antonba818672017-11-06 10:21:57 -0800453 // Called when a valid data channel OPEN message is received.
deadbeefab9b2d12015-10-14 11:33:11 -0700454 void OnDataChannelOpenMessage(const std::string& label,
455 const InternalDataChannelInit& config);
456
Steve Anton4171afb2017-11-20 10:20:22 -0800457 // Returns true if the PeerConnection is configured to use Unified Plan
458 // semantics for creating offers/answers and setting local/remote
459 // descriptions. If this is true the RtpTransceiver API will also be available
460 // to the user. If this is false, Plan B semantics are assumed.
461 // TODO(steveanton): Flip the default to be Unified Plan once sufficient time
462 // has passed.
463 bool IsUnifiedPlan() const { return false; }
464
465 // Is there an RtpSender of the given type?
zhihuang1c378ed2017-08-17 14:10:50 -0700466 bool HasRtpSender(cricket::MediaType type) const;
deadbeeffac06552015-11-25 11:26:01 -0800467
Steve Anton4171afb2017-11-20 10:20:22 -0800468 // Return the RtpSender with the given track attached.
469 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
470 FindSenderForTrack(MediaStreamTrackInterface* track) const;
deadbeef70ab1a12015-09-28 16:53:55 -0700471
Steve Anton4171afb2017-11-20 10:20:22 -0800472 // Return the RtpSender with the given id, or null if none exists.
473 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
474 FindSenderById(const std::string& sender_id) const;
475
476 // Return the RtpReceiver with the given id, or null if none exists.
477 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
478 FindReceiverById(const std::string& receiver_id) const;
479
480 std::vector<RtpSenderInfo>* GetRemoteSenderInfos(
481 cricket::MediaType media_type);
482 std::vector<RtpSenderInfo>* GetLocalSenderInfos(
483 cricket::MediaType media_type);
484 const RtpSenderInfo* FindSenderInfo(const std::vector<RtpSenderInfo>& infos,
485 const std::string& stream_label,
486 const std::string sender_id) const;
deadbeefab9b2d12015-10-14 11:33:11 -0700487
488 // Returns the specified SCTP DataChannel in sctp_data_channels_,
489 // or nullptr if not found.
490 DataChannel* FindDataChannelBySid(int sid) const;
491
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700492 // Called when first configuring the port allocator.
deadbeef91dd5672016-05-18 16:55:30 -0700493 bool InitializePortAllocator_n(const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 12:28:30 -0800494 // Called when SetConfiguration is called to apply the supported subset
495 // of the configuration on the network thread.
496 bool ReconfigurePortAllocator_n(
497 const cricket::ServerAddresses& stun_servers,
498 const std::vector<cricket::RelayServerConfig>& turn_servers,
499 IceTransportsType type,
500 int candidate_pool_size,
Jonas Orelandbdcee282017-10-10 14:01:40 +0200501 bool prune_turn_ports,
502 webrtc::TurnCustomizer* turn_customizer);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700503
Elad Alon99c3fe52017-10-13 16:29:40 +0200504 // Starts output of an RTC event log to the given output object.
ivoc14d5dbe2016-07-04 07:06:55 -0700505 // This function should only be called from the worker thread.
Zhi Huang33c5c7f2017-11-17 20:59:29 +0000506 bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output);
Elad Alon99c3fe52017-10-13 16:29:40 +0200507
Elad Alonacb24172017-10-06 14:32:13 +0200508 // Stops recording an RTC event log.
ivoc14d5dbe2016-07-04 07:06:55 -0700509 // This function should only be called from the worker thread.
510 void StopRtcEventLog_w();
511
Steve Anton038834f2017-07-14 15:59:59 -0700512 // Ensures the configuration doesn't have any parameters with invalid values,
513 // or values that conflict with other parameters.
514 //
515 // Returns RTCError::OK() if there are no issues.
516 RTCError ValidateConfiguration(const RTCConfiguration& config) const;
517
Steve Antonba818672017-11-06 10:21:57 -0800518 cricket::ChannelManager* channel_manager() const;
519 MetricsObserverInterface* metrics_observer() const;
520
Steve Anton75737c02017-11-06 10:37:17 -0800521 // Indicates the type of SessionDescription in a call to SetLocalDescription
522 // and SetRemoteDescription.
523 enum Action {
524 kOffer,
525 kPrAnswer,
526 kAnswer,
527 };
528
529 // Returns the last error in the session. See the enum above for details.
530 Error error() const { return error_; }
531 const std::string& error_desc() const { return error_desc_; }
532
Steve Anton75737c02017-11-06 10:37:17 -0800533 cricket::BaseChannel* GetChannel(const std::string& content_name);
534
535 // Get current SSL role used by SCTP's underlying transport.
536 bool GetSctpSslRole(rtc::SSLRole* role);
537
Steve Anton75737c02017-11-06 10:37:17 -0800538 bool SetLocalDescription(std::unique_ptr<SessionDescriptionInterface> desc,
539 std::string* err_desc);
540 bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc,
541 std::string* err_desc);
542
Steve Anton75737c02017-11-06 10:37:17 -0800543 cricket::IceConfig ParseIceConfig(
544 const PeerConnectionInterface::RTCConfiguration& config) const;
545
Steve Anton75737c02017-11-06 10:37:17 -0800546 // Implements DataChannelProviderInterface.
547 bool SendData(const cricket::SendDataParams& params,
548 const rtc::CopyOnWriteBuffer& payload,
549 cricket::SendDataResult* result) override;
550 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override;
551 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override;
552 void AddSctpDataStream(int sid) override;
553 void RemoveSctpDataStream(int sid) override;
554 bool ReadyToSendData() const override;
555
556 cricket::DataChannelType data_channel_type() const;
557
Steve Anton75737c02017-11-06 10:37:17 -0800558 // Called when an RTCCertificate is generated or retrieved by
559 // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription.
560 void OnCertificateReady(
561 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
562 void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp);
563
564 cricket::TransportController* transport_controller() const {
565 return transport_controller_.get();
566 }
567
568 // Return all managed, non-null channels.
569 std::vector<cricket::BaseChannel*> Channels() const;
570
571 // Non-const versions of local_description()/remote_description(), for use
572 // internally.
573 SessionDescriptionInterface* mutable_local_description() {
574 return pending_local_description_ ? pending_local_description_.get()
575 : current_local_description_.get();
576 }
577 SessionDescriptionInterface* mutable_remote_description() {
578 return pending_remote_description_ ? pending_remote_description_.get()
579 : current_remote_description_.get();
580 }
581
582 // Updates the error state, signaling if necessary.
583 void SetError(Error error, const std::string& error_desc);
584
585 bool UpdateSessionState(Action action,
586 cricket::ContentSource source,
587 std::string* err_desc);
588 Action GetAction(const std::string& type);
589 // Push the media parts of the local or remote session description
590 // down to all of the channels.
591 bool PushdownMediaDescription(cricket::ContentAction action,
592 cricket::ContentSource source,
593 std::string* error_desc);
594 bool PushdownSctpParameters_n(cricket::ContentSource source);
595
596 bool PushdownTransportDescription(cricket::ContentSource source,
597 cricket::ContentAction action,
598 std::string* error_desc);
599
600 // Helper methods to push local and remote transport descriptions.
601 bool PushdownLocalTransportDescription(
602 const cricket::SessionDescription* sdesc,
603 cricket::ContentAction action,
604 std::string* error_desc);
605 bool PushdownRemoteTransportDescription(
606 const cricket::SessionDescription* sdesc,
607 cricket::ContentAction action,
608 std::string* error_desc);
609
610 // Returns true and the TransportInfo of the given |content_name|
611 // from |description|. Returns false if it's not available.
612 static bool GetTransportDescription(
613 const cricket::SessionDescription* description,
614 const std::string& content_name,
615 cricket::TransportDescription* info);
616
617 // Returns the name of the transport channel when BUNDLE is enabled, or
618 // nullptr if the channel is not part of any bundle.
619 const std::string* GetBundleTransportName(
620 const cricket::ContentInfo* content,
621 const cricket::ContentGroup* bundle);
622
623 // Cause all the BaseChannels in the bundle group to have the same
624 // transport channel.
625 bool EnableBundle(const cricket::ContentGroup& bundle);
626
627 // Enables media channels to allow sending of media.
628 void EnableChannels();
629 // Returns the media index for a local ice candidate given the content name.
630 // Returns false if the local session description does not have a media
631 // content called |content_name|.
632 bool GetLocalCandidateMediaIndex(const std::string& content_name,
633 int* sdp_mline_index);
634 // Uses all remote candidates in |remote_desc| in this session.
635 bool UseCandidatesInSessionDescription(
636 const SessionDescriptionInterface* remote_desc);
637 // Uses |candidate| in this session.
638 bool UseCandidate(const IceCandidateInterface* candidate);
639 // Deletes the corresponding channel of contents that don't exist in |desc|.
640 // |desc| can be null. This means that all channels are deleted.
641 void RemoveUnusedChannels(const cricket::SessionDescription* desc);
642
643 // Allocates media channels based on the |desc|. If |desc| doesn't have
644 // the BUNDLE option, this method will disable BUNDLE in PortAllocator.
645 // This method will also delete any existing media channels before creating.
646 bool CreateChannels(const cricket::SessionDescription* desc);
647
648 // Helper methods to create media channels.
649 bool CreateVoiceChannel(const cricket::ContentInfo* content,
650 const std::string* bundle_transport);
651 bool CreateVideoChannel(const cricket::ContentInfo* content,
652 const std::string* bundle_transport);
653 bool CreateDataChannel(const cricket::ContentInfo* content,
654 const std::string* bundle_transport);
655
656 std::unique_ptr<SessionStats> GetSessionStats_n(
657 const ChannelNamePairs& channel_name_pairs);
658
659 bool CreateSctpTransport_n(const std::string& content_name,
660 const std::string& transport_name);
661 // For bundling.
662 void ChangeSctpTransport_n(const std::string& transport_name);
663 void DestroySctpTransport_n();
664 // SctpTransport signal handlers. Needed to marshal signals from the network
665 // to signaling thread.
666 void OnSctpTransportReadyToSendData_n();
667 // This may be called with "false" if the direction of the m= section causes
668 // us to tear down the SCTP connection.
669 void OnSctpTransportReadyToSendData_s(bool ready);
670 void OnSctpTransportDataReceived_n(const cricket::ReceiveDataParams& params,
671 const rtc::CopyOnWriteBuffer& payload);
672 // Beyond just firing the signal to the signaling thread, listens to SCTP
673 // CONTROL messages on unused SIDs and processes them as OPEN messages.
674 void OnSctpTransportDataReceived_s(const cricket::ReceiveDataParams& params,
675 const rtc::CopyOnWriteBuffer& payload);
676 void OnSctpStreamClosedRemotely_n(int sid);
677
678 bool ValidateBundleSettings(const cricket::SessionDescription* desc);
679 bool HasRtcpMuxEnabled(const cricket::ContentInfo* content);
680 // Below methods are helper methods which verifies SDP.
681 bool ValidateSessionDescription(const SessionDescriptionInterface* sdesc,
682 cricket::ContentSource source,
683 std::string* err_desc);
684
685 // Check if a call to SetLocalDescription is acceptable with |action|.
686 bool ExpectSetLocalDescription(Action action);
687 // Check if a call to SetRemoteDescription is acceptable with |action|.
688 bool ExpectSetRemoteDescription(Action action);
689 // Verifies a=setup attribute as per RFC 5763.
690 bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc,
691 Action action);
692
693 // Returns true if we are ready to push down the remote candidate.
694 // |remote_desc| is the new remote description, or NULL if the current remote
695 // description should be used. Output |valid| is true if the candidate media
696 // index is valid.
697 bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate,
698 const SessionDescriptionInterface* remote_desc,
699 bool* valid);
700
701 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
702 // this session.
703 bool SrtpRequired() const;
704
705 // TransportController signal handlers.
706 void OnTransportControllerConnectionState(cricket::IceConnectionState state);
707 void OnTransportControllerGatheringState(cricket::IceGatheringState state);
708 void OnTransportControllerCandidatesGathered(
709 const std::string& transport_name,
710 const std::vector<cricket::Candidate>& candidates);
711 void OnTransportControllerCandidatesRemoved(
712 const std::vector<cricket::Candidate>& candidates);
713 void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error);
714
715 std::string GetSessionErrorMsg();
716
717 // Invoked when TransportController connection completion is signaled.
718 // Reports stats for all transports in use.
719 void ReportTransportStats();
720
721 // Gather the usage of IPv4/IPv6 as best connection.
722 void ReportBestConnectionState(const cricket::TransportStats& stats);
723
724 void ReportNegotiatedCiphers(const cricket::TransportStats& stats);
725
726 void OnSentPacket_w(const rtc::SentPacket& sent_packet);
727
728 const std::string GetTransportName(const std::string& content_name);
729
730 void DestroyRtcpTransport_n(const std::string& transport_name);
731 void RemoveAndDestroyVideoChannel(cricket::VideoChannel* video_channel);
732 void DestroyVideoChannel(cricket::VideoChannel* video_channel);
733 void RemoveAndDestroyVoiceChannel(cricket::VoiceChannel* voice_channel);
734 void DestroyVoiceChannel(cricket::VoiceChannel* voice_channel);
735 void DestroyDataChannel();
736
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 // Storing the factory as a scoped reference pointer ensures that the memory
738 // in the PeerConnectionFactoryImpl remains available as long as the
739 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
740 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -0700741 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 // will refer to the same reference count.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000743 rtc::scoped_refptr<PeerConnectionFactory> factory_;
Steve Antonba818672017-11-06 10:21:57 -0800744 PeerConnectionObserver* observer_ = nullptr;
745 UMAObserver* uma_observer_ = nullptr;
terelius33860252017-05-12 23:37:18 -0700746
747 // The EventLog needs to outlive |call_| (and any other object that uses it).
748 std::unique_ptr<RtcEventLog> event_log_;
749
Steve Antonba818672017-11-06 10:21:57 -0800750 SignalingState signaling_state_ = kStable;
751 IceConnectionState ice_connection_state_ = kIceConnectionNew;
752 IceGatheringState ice_gathering_state_ = kIceGatheringNew;
deadbeef46c73892016-11-16 19:42:04 -0800753 PeerConnectionInterface::RTCConfiguration configuration_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754
kwibergd1fe2812016-04-27 06:47:29 -0700755 std::unique_ptr<cricket::PortAllocator> port_allocator_;
deadbeefab9b2d12015-10-14 11:33:11 -0700756
zhihuang8f65cdf2016-05-06 18:40:30 -0700757 // One PeerConnection has only one RTCP CNAME.
758 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
759 std::string rtcp_cname_;
760
deadbeefab9b2d12015-10-14 11:33:11 -0700761 // Streams added via AddStream.
762 rtc::scoped_refptr<StreamCollection> local_streams_;
763 // Streams created as a result of SetRemoteDescription.
764 rtc::scoped_refptr<StreamCollection> remote_streams_;
765
kwibergd1fe2812016-04-27 06:47:29 -0700766 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
deadbeefeb459812015-12-15 19:24:43 -0800767
Steve Anton4171afb2017-11-20 10:20:22 -0800768 // These lists store sender info seen in local/remote descriptions.
769 std::vector<RtpSenderInfo> remote_audio_sender_infos_;
770 std::vector<RtpSenderInfo> remote_video_sender_infos_;
771 std::vector<RtpSenderInfo> local_audio_sender_infos_;
772 std::vector<RtpSenderInfo> local_video_sender_infos_;
deadbeefab9b2d12015-10-14 11:33:11 -0700773
774 SctpSidAllocator sid_allocator_;
775 // label -> DataChannel
776 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
777 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
deadbeefbd292462015-12-14 18:15:29 -0800778 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
deadbeefab9b2d12015-10-14 11:33:11 -0700779
deadbeefbda7e0b2015-12-08 17:13:40 -0800780 bool remote_peer_supports_msid_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700781
terelius33860252017-05-12 23:37:18 -0700782 std::unique_ptr<Call> call_;
terelius33860252017-05-12 23:37:18 -0700783 std::unique_ptr<StatsCollector> stats_; // A pointer is passed to senders_
784 rtc::scoped_refptr<RTCStatsCollector> stats_collector_;
785
deadbeefa601f5c2016-06-06 14:27:39 -0700786 std::vector<
Steve Anton4171afb2017-11-20 10:20:22 -0800787 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
788 transceivers_;
Steve Anton75737c02017-11-06 10:37:17 -0800789
790 Error error_ = ERROR_NONE;
791 std::string error_desc_;
792
793 std::string session_id_;
794 rtc::Optional<bool> initial_offerer_;
795
796 std::unique_ptr<cricket::TransportController> transport_controller_;
797 std::unique_ptr<cricket::SctpTransportInternalFactory> sctp_factory_;
Steve Anton75737c02017-11-06 10:37:17 -0800798 // |rtp_data_channel_| is used if in RTP data channel mode, |sctp_transport_|
799 // when using SCTP.
800 cricket::RtpDataChannel* rtp_data_channel_ = nullptr;
801
802 std::unique_ptr<cricket::SctpTransportInternal> sctp_transport_;
803 // |sctp_transport_name_| keeps track of what DTLS transport the SCTP
804 // transport is using (which can change due to bundling).
805 rtc::Optional<std::string> sctp_transport_name_;
806 // |sctp_content_name_| is the content name (MID) in SDP.
807 rtc::Optional<std::string> sctp_content_name_;
808 // Value cached on signaling thread. Only updated when SctpReadyToSendData
809 // fires on the signaling thread.
810 bool sctp_ready_to_send_data_ = false;
811 // Same as signals provided by SctpTransport, but these are guaranteed to
812 // fire on the signaling thread, whereas SctpTransport fires on the networking
813 // thread.
814 // |sctp_invoker_| is used so that any signals queued on the signaling thread
815 // from the network thread are immediately discarded if the SctpTransport is
816 // destroyed (due to m= section being rejected).
817 // TODO(deadbeef): Use a proxy object to ensure that method calls/signals
818 // are marshalled to the right thread. Could almost use proxy.h for this,
819 // but it doesn't have a mechanism for marshalling sigslot::signals
820 std::unique_ptr<rtc::AsyncInvoker> sctp_invoker_;
821 sigslot::signal1<bool> SignalSctpReadyToSendData;
822 sigslot::signal2<const cricket::ReceiveDataParams&,
823 const rtc::CopyOnWriteBuffer&>
824 SignalSctpDataReceived;
825 sigslot::signal1<int> SignalSctpStreamClosedRemotely;
826
827 std::unique_ptr<SessionDescriptionInterface> current_local_description_;
828 std::unique_ptr<SessionDescriptionInterface> pending_local_description_;
829 std::unique_ptr<SessionDescriptionInterface> current_remote_description_;
830 std::unique_ptr<SessionDescriptionInterface> pending_remote_description_;
831 bool dtls_enabled_ = false;
832 // Specifies which kind of data channel is allowed. This is controlled
833 // by the chrome command-line flag and constraints:
834 // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled,
835 // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is
836 // not set or false, SCTP is allowed (DCT_SCTP);
837 // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP);
838 // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE).
839 cricket::DataChannelType data_channel_type_ = cricket::DCT_NONE;
840 // List of content names for which the remote side triggered an ICE restart.
841 std::set<std::string> pending_ice_restarts_;
842
843 std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_;
844
845 // Member variables for caching global options.
846 cricket::AudioOptions audio_options_;
847 cricket::VideoOptions video_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848};
849
850} // namespace webrtc
851
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200852#endif // PC_PEERCONNECTION_H_