blob: 4c8983bc470a225bf93d0d76758b30563e582755 [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 Anton9158ef62017-11-27 13:01:52 -080097 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
98 rtc::scoped_refptr<MediaStreamTrackInterface> track) override;
99 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
100 rtc::scoped_refptr<MediaStreamTrackInterface> track,
101 const RtpTransceiverInit& init) override;
102 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
103 cricket::MediaType media_type) override;
104 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
105 cricket::MediaType media_type,
106 const RtpTransceiverInit& init) override;
107
Steve Anton8c0f7a72017-10-03 10:03:10 -0700108 // Gets the DTLS SSL certificate associated with the audio transport on the
109 // remote side. This will become populated once the DTLS connection with the
110 // peer has been completed, as indicated by the ICE connection state
111 // transitioning to kIceConnectionCompleted.
112 // Note that this will be removed once we implement RTCDtlsTransport which
113 // has standardized method for getting this information.
114 // See https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface
115 std::unique_ptr<rtc::SSLCertificate> GetRemoteAudioSSLCertificate();
116
deadbeefa67696b2015-09-29 11:56:26 -0700117 rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
118 AudioTrackInterface* track) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119
deadbeeffac06552015-11-25 11:26:01 -0800120 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -0800121 const std::string& kind,
122 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -0800123
deadbeef70ab1a12015-09-28 16:53:55 -0700124 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
125 const override;
126 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
127 const override;
Steve Anton9158ef62017-11-27 13:01:52 -0800128 std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers()
129 const override;
deadbeef70ab1a12015-09-28 16:53:55 -0700130
deadbeefa67696b2015-09-29 11:56:26 -0700131 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700133 const DataChannelInit* config) override;
134 bool GetStats(StatsObserver* observer,
135 webrtc::MediaStreamTrackInterface* track,
136 StatsOutputLevel level) override;
hbos74e1a4f2016-09-15 23:33:01 -0700137 void GetStats(RTCStatsCollectorCallback* callback) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138
deadbeefa67696b2015-09-29 11:56:26 -0700139 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140
deadbeefa67696b2015-09-29 11:56:26 -0700141 IceConnectionState ice_connection_state() override;
142 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143
deadbeefa67696b2015-09-29 11:56:26 -0700144 const SessionDescriptionInterface* local_description() const override;
145 const SessionDescriptionInterface* remote_description() const override;
deadbeeffe4a8a42016-12-20 17:56:17 -0800146 const SessionDescriptionInterface* current_local_description() const override;
147 const SessionDescriptionInterface* current_remote_description()
148 const override;
149 const SessionDescriptionInterface* pending_local_description() const override;
150 const SessionDescriptionInterface* pending_remote_description()
151 const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152
153 // JSEP01
htaa2a49d92016-03-04 02:51:39 -0800154 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700155 void CreateOffer(CreateSessionDescriptionObserver* observer,
156 const MediaConstraintsInterface* constraints) override;
157 void CreateOffer(CreateSessionDescriptionObserver* observer,
158 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800159 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700160 void CreateAnswer(CreateSessionDescriptionObserver* observer,
161 const MediaConstraintsInterface* constraints) override;
htaa2a49d92016-03-04 02:51:39 -0800162 void CreateAnswer(CreateSessionDescriptionObserver* observer,
163 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700164 void SetLocalDescription(SetSessionDescriptionObserver* observer,
165 SessionDescriptionInterface* desc) override;
Henrik Boströma4ecf552017-11-23 14:17:07 +0000166 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
167 SessionDescriptionInterface* desc) override;
Henrik Boström31638672017-11-23 17:48:32 +0100168 void SetRemoteDescription(
169 std::unique_ptr<SessionDescriptionInterface> desc,
170 rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer)
171 override;
deadbeef46c73892016-11-16 19:42:04 -0800172 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
deadbeefa67696b2015-09-29 11:56:26 -0700173 bool SetConfiguration(
deadbeef293e9262017-01-11 12:28:30 -0800174 const PeerConnectionInterface::RTCConfiguration& configuration,
175 RTCError* error) override;
176 bool SetConfiguration(
177 const PeerConnectionInterface::RTCConfiguration& configuration) override {
178 return SetConfiguration(configuration, nullptr);
179 }
deadbeefa67696b2015-09-29 11:56:26 -0700180 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700181 bool RemoveIceCandidates(
182 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183
deadbeefa67696b2015-09-29 11:56:26 -0700184 void RegisterUMAObserver(UMAObserver* observer) override;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000185
zstein4b979802017-06-02 14:37:37 -0700186 RTCError SetBitrate(const BitrateParameters& bitrate) override;
187
Alex Narest78609d52017-10-20 10:37:47 +0200188 void SetBitrateAllocationStrategy(
189 std::unique_ptr<rtc::BitrateAllocationStrategy>
190 bitrate_allocation_strategy) override;
191
henrika5f6bf242017-11-01 11:06:56 +0100192 void SetAudioPlayout(bool playout) override;
193 void SetAudioRecording(bool recording) override;
194
Elad Alon99c3fe52017-10-13 16:29:40 +0200195 RTC_DEPRECATED bool StartRtcEventLog(rtc::PlatformFile file,
196 int64_t max_size_bytes) override;
Bjorn Tereliusde939432017-11-20 17:38:14 +0100197 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,
198 int64_t output_period_ms) override;
ivoc14d5dbe2016-07-04 07:06:55 -0700199 void StopRtcEventLog() override;
200
deadbeefa67696b2015-09-29 11:56:26 -0700201 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202
hbos82ebe022016-11-14 01:41:09 -0800203 sigslot::signal1<DataChannel*> SignalDataChannelCreated;
204
deadbeefab9b2d12015-10-14 11:33:11 -0700205 // Virtual for unit tests.
206 virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
207 sctp_data_channels() const {
208 return sctp_data_channels_;
perkjd61bf802016-03-24 03:16:19 -0700209 }
deadbeefab9b2d12015-10-14 11:33:11 -0700210
Steve Anton978b8762017-09-29 12:15:02 -0700211 rtc::Thread* network_thread() const { return factory_->network_thread(); }
212 rtc::Thread* worker_thread() const { return factory_->worker_thread(); }
213 rtc::Thread* signaling_thread() const { return factory_->signaling_thread(); }
Steve Anton75737c02017-11-06 10:37:17 -0800214
215 // The SDP session ID as defined by RFC 3264.
216 virtual const std::string& session_id() const { return session_id_; }
217
218 // Returns true if we were the initial offerer.
219 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
220
221 // Returns stats for all channels of all transports.
222 // This avoids exposing the internal structures used to track them.
223 // The parameterless version creates |ChannelNamePairs| from |voice_channel|,
224 // |video_channel| and |voice_channel| if available - this requires it to be
225 // called on the signaling thread - and invokes the other |GetStats|. The
226 // other |GetStats| can be invoked on any thread; if not invoked on the
227 // network thread a thread hop will happen.
228 std::unique_ptr<SessionStats> GetSessionStats_s();
Steve Anton978b8762017-09-29 12:15:02 -0700229 virtual std::unique_ptr<SessionStats> GetSessionStats(
Steve Anton75737c02017-11-06 10:37:17 -0800230 const ChannelNamePairs& channel_name_pairs);
231
232 // virtual so it can be mocked in unit tests
Steve Anton978b8762017-09-29 12:15:02 -0700233 virtual bool GetLocalCertificate(
234 const std::string& transport_name,
Steve Anton75737c02017-11-06 10:37:17 -0800235 rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
Steve Anton978b8762017-09-29 12:15:02 -0700236 virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
Steve Anton75737c02017-11-06 10:37:17 -0800237 const std::string& transport_name);
238
239 virtual Call::Stats GetCallStats();
240
241 // Exposed for stats collecting.
242 // TODO(steveanton): Switch callers to use the plural form and remove these.
Steve Anton4171afb2017-11-20 10:20:22 -0800243 virtual cricket::VoiceChannel* voice_channel() const {
244 return static_cast<cricket::VoiceChannel*>(
245 GetAudioTransceiver()->internal()->channel());
Steve Anton978b8762017-09-29 12:15:02 -0700246 }
Steve Anton4171afb2017-11-20 10:20:22 -0800247 virtual cricket::VideoChannel* video_channel() const {
248 return static_cast<cricket::VideoChannel*>(
249 GetVideoTransceiver()->internal()->channel());
Steve Antond5585ca2017-10-23 14:49:26 -0700250 }
Steve Anton978b8762017-09-29 12:15:02 -0700251
Steve Anton75737c02017-11-06 10:37:17 -0800252 // Only valid when using deprecated RTP data channels.
253 virtual cricket::RtpDataChannel* rtp_data_channel() {
254 return rtp_data_channel_;
Steve Anton978b8762017-09-29 12:15:02 -0700255 }
Steve Anton75737c02017-11-06 10:37:17 -0800256 virtual rtc::Optional<std::string> sctp_content_name() const {
257 return sctp_content_name_;
258 }
259 virtual rtc::Optional<std::string> sctp_transport_name() const {
260 return sctp_transport_name_;
261 }
262
263 // Get the id used as a media stream track's "id" field from ssrc.
264 virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
265 virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
266
267 // Returns true if there was an ICE restart initiated by the remote offer.
268 bool IceRestartPending(const std::string& content_name) const;
269
270 // Returns true if the ICE restart flag above was set, and no ICE restart has
271 // occurred yet for this transport (by applying a local description with
272 // changed ufrag/password). If the transport has been deleted as a result of
273 // bundling, returns false.
274 bool NeedsIceRestart(const std::string& content_name) const;
275
276 // Get SSL role for an arbitrary m= section (handles bundling correctly).
277 // TODO(deadbeef): This is only used internally by the session description
278 // factory, it shouldn't really be public).
279 bool GetSslRole(const std::string& content_name, rtc::SSLRole* role);
280
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700282 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283
284 private:
Henrik Boström31638672017-11-23 17:48:32 +0100285 class SetRemoteDescriptionObserverAdapter;
286 friend class SetRemoteDescriptionObserverAdapter;
287
Steve Anton4171afb2017-11-20 10:20:22 -0800288 struct RtpSenderInfo {
289 RtpSenderInfo() : first_ssrc(0) {}
290 RtpSenderInfo(const std::string& stream_label,
291 const std::string sender_id,
292 uint32_t ssrc)
293 : stream_label(stream_label), sender_id(sender_id), first_ssrc(ssrc) {}
294 bool operator==(const RtpSenderInfo& other) {
deadbeefbda7e0b2015-12-08 17:13:40 -0800295 return this->stream_label == other.stream_label &&
Steve Anton4171afb2017-11-20 10:20:22 -0800296 this->sender_id == other.sender_id &&
297 this->first_ssrc == other.first_ssrc;
deadbeefbda7e0b2015-12-08 17:13:40 -0800298 }
deadbeefab9b2d12015-10-14 11:33:11 -0700299 std::string stream_label;
Steve Anton4171afb2017-11-20 10:20:22 -0800300 std::string sender_id;
301 // An RtpSender can have many SSRCs. The first one is used as a sort of ID
302 // for communicating with the lower layers.
303 uint32_t first_ssrc;
deadbeefab9b2d12015-10-14 11:33:11 -0700304 };
deadbeefab9b2d12015-10-14 11:33:11 -0700305
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 // Implements MessageHandler.
deadbeefa67696b2015-09-29 11:56:26 -0700307 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308
Steve Anton4171afb2017-11-20 10:20:22 -0800309 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
310 GetSendersInternal() const;
311 std::vector<
312 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
313 GetReceiversInternal() const;
314
315 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
316 GetAudioTransceiver() const;
317 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
318 GetVideoTransceiver() const;
319
deadbeefab9b2d12015-10-14 11:33:11 -0700320 void CreateAudioReceiver(MediaStreamInterface* stream,
Steve Anton4171afb2017-11-20 10:20:22 -0800321 const RtpSenderInfo& remote_sender_info);
perkjf0dcfe22016-03-10 18:32:00 +0100322
deadbeefab9b2d12015-10-14 11:33:11 -0700323 void CreateVideoReceiver(MediaStreamInterface* stream,
Steve Anton4171afb2017-11-20 10:20:22 -0800324 const RtpSenderInfo& remote_sender_info);
Henrik Boström933d8b02017-10-10 10:05:16 -0700325 rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver(
Steve Anton4171afb2017-11-20 10:20:22 -0800326 const RtpSenderInfo& remote_sender_info);
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700327
328 // May be called either by AddStream/RemoveStream, or when a track is
329 // added/removed from a stream previously added via AddStream.
330 void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream);
331 void RemoveAudioTrack(AudioTrackInterface* track,
332 MediaStreamInterface* stream);
333 void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream);
334 void RemoveVideoTrack(VideoTrackInterface* track,
335 MediaStreamInterface* stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336
Steve Anton9158ef62017-11-27 13:01:52 -0800337 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
338 cricket::MediaType media_type,
339 rtc::scoped_refptr<MediaStreamTrackInterface> track,
340 const RtpTransceiverInit& init);
341
Steve Antonba818672017-11-06 10:21:57 -0800342 void SetIceConnectionState(IceConnectionState new_state);
343 // Called any time the IceGatheringState changes
344 void OnIceGatheringChange(IceGatheringState new_state);
345 // New ICE candidate has been gathered.
346 void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate);
347 // Some local ICE candidates have been removed.
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700348 void OnIceCandidatesRemoved(
Steve Antonba818672017-11-06 10:21:57 -0800349 const std::vector<cricket::Candidate>& candidates);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350
Steve Antonba818672017-11-06 10:21:57 -0800351 // Update the state, signaling if necessary.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 void ChangeSignalingState(SignalingState signaling_state);
353
deadbeefeb459812015-12-15 19:24:43 -0800354 // Signals from MediaStreamObserver.
355 void OnAudioTrackAdded(AudioTrackInterface* track,
356 MediaStreamInterface* stream);
357 void OnAudioTrackRemoved(AudioTrackInterface* track,
358 MediaStreamInterface* stream);
359 void OnVideoTrackAdded(VideoTrackInterface* track,
360 MediaStreamInterface* stream);
361 void OnVideoTrackRemoved(VideoTrackInterface* track,
362 MediaStreamInterface* stream);
363
Henrik Boström31638672017-11-23 17:48:32 +0100364 void PostSetSessionDescriptionSuccess(
365 SetSessionDescriptionObserver* observer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
367 const std::string& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700368 void PostCreateSessionDescriptionFailure(
369 CreateSessionDescriptionObserver* observer,
370 const std::string& error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371
Steve Anton8a006912017-12-04 15:25:56 -0800372 // Synchronous implementations of SetLocalDescription/SetRemoteDescription
373 // that return an RTCError instead of invoking a callback.
374 RTCError ApplyLocalDescription(
375 std::unique_ptr<SessionDescriptionInterface> desc);
376 RTCError ApplyRemoteDescription(
377 std::unique_ptr<SessionDescriptionInterface> desc);
378
Steve Antoned10bd92017-12-05 10:52:59 -0800379 // Returns the media section in the given session description that is
380 // associated with the RtpTransceiver. Returns null if none found or this
381 // RtpTransceiver is not associated. Logic varies depending on the
382 // SdpSemantics specified in the configuration.
383 const cricket::ContentInfo* FindMediaSectionForTransceiver(
384 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
385 transceiver,
386 const SessionDescriptionInterface* sdesc) const;
387
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 bool IsClosed() const {
389 return signaling_state_ == PeerConnectionInterface::kClosed;
390 }
391
deadbeefab9b2d12015-10-14 11:33:11 -0700392 // Returns a MediaSessionOptions struct with options decided by |options|,
393 // the local MediaStreams and DataChannels.
zhihuang1c378ed2017-08-17 14:10:50 -0700394 void GetOptionsForOffer(
deadbeefab9b2d12015-10-14 11:33:11 -0700395 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
396 cricket::MediaSessionOptions* session_options);
397
398 // Returns a MediaSessionOptions struct with options decided by
399 // |constraints|, the local MediaStreams and DataChannels.
zhihuang1c378ed2017-08-17 14:10:50 -0700400 void GetOptionsForAnswer(const RTCOfferAnswerOptions& options,
401 cricket::MediaSessionOptions* session_options);
htaa2a49d92016-03-04 02:51:39 -0800402
zhihuang1c378ed2017-08-17 14:10:50 -0700403 // Generates MediaDescriptionOptions for the |session_opts| based on existing
404 // local description or remote description.
405 void GenerateMediaDescriptionOptions(
406 const SessionDescriptionInterface* session_desc,
Steve Anton1d03a752017-11-27 14:30:09 -0800407 RtpTransceiverDirection audio_direction,
408 RtpTransceiverDirection video_direction,
zhihuang1c378ed2017-08-17 14:10:50 -0700409 rtc::Optional<size_t>* audio_index,
410 rtc::Optional<size_t>* video_index,
411 rtc::Optional<size_t>* data_index,
htaa2a49d92016-03-04 02:51:39 -0800412 cricket::MediaSessionOptions* session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700413
Steve Anton4171afb2017-11-20 10:20:22 -0800414 // Remove all local and remote senders of type |media_type|.
deadbeeffaac4972015-11-12 15:33:07 -0800415 // Called when a media type is rejected (m-line set to port 0).
Steve Anton4171afb2017-11-20 10:20:22 -0800416 void RemoveSenders(cricket::MediaType media_type);
deadbeeffaac4972015-11-12 15:33:07 -0800417
deadbeefbda7e0b2015-12-08 17:13:40 -0800418 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
419 // and existing MediaStreamTracks are removed if there is no corresponding
420 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
421 // is created if it doesn't exist; if false, it's removed if it exists.
422 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700423 // If a new MediaStream is created it is added to |new_streams|.
Steve Anton4171afb2017-11-20 10:20:22 -0800424 void UpdateRemoteSendersList(
deadbeefab9b2d12015-10-14 11:33:11 -0700425 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800426 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700427 cricket::MediaType media_type,
428 StreamCollection* new_streams);
429
Steve Anton4171afb2017-11-20 10:20:22 -0800430 // Triggered when a remote sender has been seen for the first time in a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700431 // session description. It creates a remote MediaStreamTrackInterface
432 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800433 void OnRemoteSenderAdded(const RtpSenderInfo& sender_info,
434 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700435
Steve Anton4171afb2017-11-20 10:20:22 -0800436 // Triggered when a remote sender has been removed from a remote session
437 // description. It removes the remote sender with id |sender_id| from a remote
deadbeefab9b2d12015-10-14 11:33:11 -0700438 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
Steve Anton4171afb2017-11-20 10:20:22 -0800439 void OnRemoteSenderRemoved(const RtpSenderInfo& sender_info,
440 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700441
442 // Finds remote MediaStreams without any tracks and removes them from
443 // |remote_streams_| and notifies the observer that the MediaStreams no longer
444 // exist.
445 void UpdateEndedRemoteMediaStreams();
446
deadbeefab9b2d12015-10-14 11:33:11 -0700447 // Loops through the vector of |streams| and finds added and removed
448 // StreamParams since last time this method was called.
Steve Anton4171afb2017-11-20 10:20:22 -0800449 // For each new or removed StreamParam, OnLocalSenderSeen or
450 // OnLocalSenderRemoved is invoked.
451 void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams,
452 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700453
Steve Anton4171afb2017-11-20 10:20:22 -0800454 // Triggered when a local sender has been seen for the first time in a local
deadbeefab9b2d12015-10-14 11:33:11 -0700455 // session description.
456 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
457 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
458 // in a MediaStream in |local_streams_|
Steve Anton4171afb2017-11-20 10:20:22 -0800459 void OnLocalSenderAdded(const RtpSenderInfo& sender_info,
460 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700461
Steve Anton4171afb2017-11-20 10:20:22 -0800462 // Triggered when a local sender has been removed from a local session
deadbeefab9b2d12015-10-14 11:33:11 -0700463 // description.
464 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
465 // has been removed from the local SessionDescription and the stream can be
466 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
Steve Anton4171afb2017-11-20 10:20:22 -0800467 void OnLocalSenderRemoved(const RtpSenderInfo& sender_info,
468 cricket::MediaType media_type);
deadbeefab9b2d12015-10-14 11:33:11 -0700469
470 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
471 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
472 void UpdateClosingRtpDataChannels(
473 const std::vector<std::string>& active_channels,
474 bool is_local_update);
475 void CreateRemoteRtpDataChannel(const std::string& label,
476 uint32_t remote_ssrc);
477
478 // Creates channel and adds it to the collection of DataChannels that will
479 // be offered in a SessionDescription.
480 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
481 const std::string& label,
482 const InternalDataChannelInit* config);
483
484 // Checks if any data channel has been added.
485 bool HasDataChannels() const;
486
487 void AllocateSctpSids(rtc::SSLRole role);
488 void OnSctpDataChannelClosed(DataChannel* channel);
489
deadbeefab9b2d12015-10-14 11:33:11 -0700490 void OnDataChannelDestroyed();
Steve Antonba818672017-11-06 10:21:57 -0800491 // Called when a valid data channel OPEN message is received.
deadbeefab9b2d12015-10-14 11:33:11 -0700492 void OnDataChannelOpenMessage(const std::string& label,
493 const InternalDataChannelInit& config);
494
Steve Anton4171afb2017-11-20 10:20:22 -0800495 // Returns true if the PeerConnection is configured to use Unified Plan
496 // semantics for creating offers/answers and setting local/remote
497 // descriptions. If this is true the RtpTransceiver API will also be available
498 // to the user. If this is false, Plan B semantics are assumed.
Steve Anton79e79602017-11-20 10:25:56 -0800499 // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once
500 // sufficient time has passed.
501 bool IsUnifiedPlan() const {
502 return configuration_.sdp_semantics == SdpSemantics::kUnifiedPlan;
503 }
Steve Anton4171afb2017-11-20 10:20:22 -0800504
505 // Is there an RtpSender of the given type?
zhihuang1c378ed2017-08-17 14:10:50 -0700506 bool HasRtpSender(cricket::MediaType type) const;
deadbeeffac06552015-11-25 11:26:01 -0800507
Steve Anton4171afb2017-11-20 10:20:22 -0800508 // Return the RtpSender with the given track attached.
509 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
510 FindSenderForTrack(MediaStreamTrackInterface* track) const;
deadbeef70ab1a12015-09-28 16:53:55 -0700511
Steve Anton4171afb2017-11-20 10:20:22 -0800512 // Return the RtpSender with the given id, or null if none exists.
513 rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>
514 FindSenderById(const std::string& sender_id) const;
515
516 // Return the RtpReceiver with the given id, or null if none exists.
517 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
518 FindReceiverById(const std::string& receiver_id) const;
519
520 std::vector<RtpSenderInfo>* GetRemoteSenderInfos(
521 cricket::MediaType media_type);
522 std::vector<RtpSenderInfo>* GetLocalSenderInfos(
523 cricket::MediaType media_type);
524 const RtpSenderInfo* FindSenderInfo(const std::vector<RtpSenderInfo>& infos,
525 const std::string& stream_label,
526 const std::string sender_id) const;
deadbeefab9b2d12015-10-14 11:33:11 -0700527
528 // Returns the specified SCTP DataChannel in sctp_data_channels_,
529 // or nullptr if not found.
530 DataChannel* FindDataChannelBySid(int sid) const;
531
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700532 // Called when first configuring the port allocator.
deadbeef91dd5672016-05-18 16:55:30 -0700533 bool InitializePortAllocator_n(const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 12:28:30 -0800534 // Called when SetConfiguration is called to apply the supported subset
535 // of the configuration on the network thread.
536 bool ReconfigurePortAllocator_n(
537 const cricket::ServerAddresses& stun_servers,
538 const std::vector<cricket::RelayServerConfig>& turn_servers,
539 IceTransportsType type,
540 int candidate_pool_size,
Jonas Orelandbdcee282017-10-10 14:01:40 +0200541 bool prune_turn_ports,
542 webrtc::TurnCustomizer* turn_customizer);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700543
Elad Alon99c3fe52017-10-13 16:29:40 +0200544 // Starts output of an RTC event log to the given output object.
ivoc14d5dbe2016-07-04 07:06:55 -0700545 // This function should only be called from the worker thread.
Bjorn Tereliusde939432017-11-20 17:38:14 +0100546 bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output,
547 int64_t output_period_ms);
Elad Alon99c3fe52017-10-13 16:29:40 +0200548
Elad Alonacb24172017-10-06 14:32:13 +0200549 // Stops recording an RTC event log.
ivoc14d5dbe2016-07-04 07:06:55 -0700550 // This function should only be called from the worker thread.
551 void StopRtcEventLog_w();
552
Steve Anton038834f2017-07-14 15:59:59 -0700553 // Ensures the configuration doesn't have any parameters with invalid values,
554 // or values that conflict with other parameters.
555 //
556 // Returns RTCError::OK() if there are no issues.
557 RTCError ValidateConfiguration(const RTCConfiguration& config) const;
558
Steve Antonba818672017-11-06 10:21:57 -0800559 cricket::ChannelManager* channel_manager() const;
560 MetricsObserverInterface* metrics_observer() const;
561
Steve Antonf8470812017-12-04 10:46:21 -0800562 enum class SessionError {
563 kNone, // No error.
564 kContent, // Error in BaseChannel SetLocalContent/SetRemoteContent.
565 kTransport, // Error from the underlying transport.
566 };
567
Steve Anton75737c02017-11-06 10:37:17 -0800568 // Returns the last error in the session. See the enum above for details.
Steve Antonf8470812017-12-04 10:46:21 -0800569 SessionError session_error() const { return session_error_; }
570 const std::string& session_error_desc() const { return session_error_desc_; }
Steve Anton75737c02017-11-06 10:37:17 -0800571
Steve Anton75737c02017-11-06 10:37:17 -0800572 cricket::BaseChannel* GetChannel(const std::string& content_name);
573
574 // Get current SSL role used by SCTP's underlying transport.
575 bool GetSctpSslRole(rtc::SSLRole* role);
576
Steve Anton75737c02017-11-06 10:37:17 -0800577 cricket::IceConfig ParseIceConfig(
578 const PeerConnectionInterface::RTCConfiguration& config) const;
579
Steve Anton75737c02017-11-06 10:37:17 -0800580 // Implements DataChannelProviderInterface.
581 bool SendData(const cricket::SendDataParams& params,
582 const rtc::CopyOnWriteBuffer& payload,
583 cricket::SendDataResult* result) override;
584 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override;
585 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override;
586 void AddSctpDataStream(int sid) override;
587 void RemoveSctpDataStream(int sid) override;
588 bool ReadyToSendData() const override;
589
590 cricket::DataChannelType data_channel_type() const;
591
Steve Anton75737c02017-11-06 10:37:17 -0800592 // Called when an RTCCertificate is generated or retrieved by
593 // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription.
594 void OnCertificateReady(
595 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
596 void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp);
597
598 cricket::TransportController* transport_controller() const {
599 return transport_controller_.get();
600 }
601
602 // Return all managed, non-null channels.
603 std::vector<cricket::BaseChannel*> Channels() const;
604
605 // Non-const versions of local_description()/remote_description(), for use
606 // internally.
607 SessionDescriptionInterface* mutable_local_description() {
608 return pending_local_description_ ? pending_local_description_.get()
609 : current_local_description_.get();
610 }
611 SessionDescriptionInterface* mutable_remote_description() {
612 return pending_remote_description_ ? pending_remote_description_.get()
613 : current_remote_description_.get();
614 }
615
616 // Updates the error state, signaling if necessary.
Steve Antonf8470812017-12-04 10:46:21 -0800617 void SetSessionError(SessionError error, const std::string& error_desc);
Steve Anton75737c02017-11-06 10:37:17 -0800618
Steve Anton20393062017-12-04 16:24:52 -0800619 RTCError UpdateSessionState(cricket::ContentAction action,
620 cricket::ContentSource source);
Steve Anton75737c02017-11-06 10:37:17 -0800621 // Push the media parts of the local or remote session description
622 // down to all of the channels.
Steve Anton8a006912017-12-04 15:25:56 -0800623 RTCError PushdownMediaDescription(cricket::ContentAction action,
624 cricket::ContentSource source);
Steve Anton75737c02017-11-06 10:37:17 -0800625 bool PushdownSctpParameters_n(cricket::ContentSource source);
626
Steve Anton8a006912017-12-04 15:25:56 -0800627 RTCError PushdownTransportDescription(cricket::ContentSource source,
628 cricket::ContentAction action);
Steve Anton75737c02017-11-06 10:37:17 -0800629
630 // Returns true and the TransportInfo of the given |content_name|
631 // from |description|. Returns false if it's not available.
632 static bool GetTransportDescription(
633 const cricket::SessionDescription* description,
634 const std::string& content_name,
635 cricket::TransportDescription* info);
636
Steve Antoneda6ccd2017-12-04 10:21:55 -0800637 // Returns the transport name for the given media section identified by |mid|.
638 // If BUNDLE is enabled and the media section is part of the bundle group,
639 // the transport name will be the first mid in the bundle group. Otherwise,
640 // the transport name will be the mid of the media section.
641 std::string GetTransportNameForMediaSection(
642 const std::string& mid,
643 const cricket::ContentGroup* bundle_group) const;
Steve Anton75737c02017-11-06 10:37:17 -0800644
645 // Cause all the BaseChannels in the bundle group to have the same
646 // transport channel.
647 bool EnableBundle(const cricket::ContentGroup& bundle);
648
649 // Enables media channels to allow sending of media.
Steve Antoned10bd92017-12-05 10:52:59 -0800650 // This enables media to flow on all configured audio/video channels and the
651 // RtpDataChannel.
652 void EnableSending();
Steve Anton75737c02017-11-06 10:37:17 -0800653 // Returns the media index for a local ice candidate given the content name.
654 // Returns false if the local session description does not have a media
655 // content called |content_name|.
656 bool GetLocalCandidateMediaIndex(const std::string& content_name,
657 int* sdp_mline_index);
658 // Uses all remote candidates in |remote_desc| in this session.
659 bool UseCandidatesInSessionDescription(
660 const SessionDescriptionInterface* remote_desc);
661 // Uses |candidate| in this session.
662 bool UseCandidate(const IceCandidateInterface* candidate);
663 // Deletes the corresponding channel of contents that don't exist in |desc|.
664 // |desc| can be null. This means that all channels are deleted.
665 void RemoveUnusedChannels(const cricket::SessionDescription* desc);
666
667 // Allocates media channels based on the |desc|. If |desc| doesn't have
668 // the BUNDLE option, this method will disable BUNDLE in PortAllocator.
669 // This method will also delete any existing media channels before creating.
Steve Anton8a006912017-12-04 15:25:56 -0800670 RTCError CreateChannels(const cricket::SessionDescription* desc);
Steve Anton75737c02017-11-06 10:37:17 -0800671
672 // Helper methods to create media channels.
Steve Antoneda6ccd2017-12-04 10:21:55 -0800673 cricket::VoiceChannel* CreateVoiceChannel(const std::string& mid,
674 const std::string& transport_name);
675 cricket::VideoChannel* CreateVideoChannel(const std::string& mid,
676 const std::string& transport_name);
677 bool CreateDataChannel(const std::string& mid,
678 const std::string& transport_name);
Steve Anton75737c02017-11-06 10:37:17 -0800679
680 std::unique_ptr<SessionStats> GetSessionStats_n(
681 const ChannelNamePairs& channel_name_pairs);
682
683 bool CreateSctpTransport_n(const std::string& content_name,
684 const std::string& transport_name);
685 // For bundling.
686 void ChangeSctpTransport_n(const std::string& transport_name);
687 void DestroySctpTransport_n();
688 // SctpTransport signal handlers. Needed to marshal signals from the network
689 // to signaling thread.
690 void OnSctpTransportReadyToSendData_n();
691 // This may be called with "false" if the direction of the m= section causes
692 // us to tear down the SCTP connection.
693 void OnSctpTransportReadyToSendData_s(bool ready);
694 void OnSctpTransportDataReceived_n(const cricket::ReceiveDataParams& params,
695 const rtc::CopyOnWriteBuffer& payload);
696 // Beyond just firing the signal to the signaling thread, listens to SCTP
697 // CONTROL messages on unused SIDs and processes them as OPEN messages.
698 void OnSctpTransportDataReceived_s(const cricket::ReceiveDataParams& params,
699 const rtc::CopyOnWriteBuffer& payload);
700 void OnSctpStreamClosedRemotely_n(int sid);
701
702 bool ValidateBundleSettings(const cricket::SessionDescription* desc);
703 bool HasRtcpMuxEnabled(const cricket::ContentInfo* content);
704 // Below methods are helper methods which verifies SDP.
Steve Anton8a006912017-12-04 15:25:56 -0800705 RTCError ValidateSessionDescription(const SessionDescriptionInterface* sdesc,
706 cricket::ContentSource source);
Steve Anton75737c02017-11-06 10:37:17 -0800707
708 // Check if a call to SetLocalDescription is acceptable with |action|.
Steve Anton20393062017-12-04 16:24:52 -0800709 bool ExpectSetLocalDescription(cricket::ContentAction action);
Steve Anton75737c02017-11-06 10:37:17 -0800710 // Check if a call to SetRemoteDescription is acceptable with |action|.
Steve Anton20393062017-12-04 16:24:52 -0800711 bool ExpectSetRemoteDescription(cricket::ContentAction action);
Steve Anton75737c02017-11-06 10:37:17 -0800712 // Verifies a=setup attribute as per RFC 5763.
713 bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc,
Steve Anton20393062017-12-04 16:24:52 -0800714 cricket::ContentAction action);
Steve Anton75737c02017-11-06 10:37:17 -0800715
716 // Returns true if we are ready to push down the remote candidate.
717 // |remote_desc| is the new remote description, or NULL if the current remote
718 // description should be used. Output |valid| is true if the candidate media
719 // index is valid.
720 bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate,
721 const SessionDescriptionInterface* remote_desc,
722 bool* valid);
723
724 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
725 // this session.
726 bool SrtpRequired() const;
727
728 // TransportController signal handlers.
729 void OnTransportControllerConnectionState(cricket::IceConnectionState state);
730 void OnTransportControllerGatheringState(cricket::IceGatheringState state);
731 void OnTransportControllerCandidatesGathered(
732 const std::string& transport_name,
733 const std::vector<cricket::Candidate>& candidates);
734 void OnTransportControllerCandidatesRemoved(
735 const std::vector<cricket::Candidate>& candidates);
736 void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error);
737
Steve Antonf8470812017-12-04 10:46:21 -0800738 const char* SessionErrorToString(SessionError error) const;
Steve Anton75737c02017-11-06 10:37:17 -0800739 std::string GetSessionErrorMsg();
740
741 // Invoked when TransportController connection completion is signaled.
742 // Reports stats for all transports in use.
743 void ReportTransportStats();
744
745 // Gather the usage of IPv4/IPv6 as best connection.
746 void ReportBestConnectionState(const cricket::TransportStats& stats);
747
748 void ReportNegotiatedCiphers(const cricket::TransportStats& stats);
749
750 void OnSentPacket_w(const rtc::SentPacket& sent_packet);
751
752 const std::string GetTransportName(const std::string& content_name);
753
754 void DestroyRtcpTransport_n(const std::string& transport_name);
Steve Anton6fec8802017-12-04 10:37:29 -0800755
756 // Destroys and clears the BaseChannel associated with the given transceiver,
757 // if such channel is set.
758 void DestroyTransceiverChannel(
759 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
760 transceiver);
761
762 // Destroys the RTP data channel and/or the SCTP data channel and clears it.
Steve Anton75737c02017-11-06 10:37:17 -0800763 void DestroyDataChannel();
764
Steve Anton6fec8802017-12-04 10:37:29 -0800765 // Destroys the given BaseChannel. The channel cannot be accessed after this
766 // method is called.
767 void DestroyBaseChannel(cricket::BaseChannel* channel);
768
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 // Storing the factory as a scoped reference pointer ensures that the memory
770 // in the PeerConnectionFactoryImpl remains available as long as the
771 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
772 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -0700773 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 // will refer to the same reference count.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000775 rtc::scoped_refptr<PeerConnectionFactory> factory_;
Steve Antonba818672017-11-06 10:21:57 -0800776 PeerConnectionObserver* observer_ = nullptr;
777 UMAObserver* uma_observer_ = nullptr;
terelius33860252017-05-12 23:37:18 -0700778
779 // The EventLog needs to outlive |call_| (and any other object that uses it).
780 std::unique_ptr<RtcEventLog> event_log_;
781
Steve Antonba818672017-11-06 10:21:57 -0800782 SignalingState signaling_state_ = kStable;
783 IceConnectionState ice_connection_state_ = kIceConnectionNew;
784 IceGatheringState ice_gathering_state_ = kIceGatheringNew;
deadbeef46c73892016-11-16 19:42:04 -0800785 PeerConnectionInterface::RTCConfiguration configuration_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786
kwibergd1fe2812016-04-27 06:47:29 -0700787 std::unique_ptr<cricket::PortAllocator> port_allocator_;
deadbeefab9b2d12015-10-14 11:33:11 -0700788
zhihuang8f65cdf2016-05-06 18:40:30 -0700789 // One PeerConnection has only one RTCP CNAME.
790 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
791 std::string rtcp_cname_;
792
deadbeefab9b2d12015-10-14 11:33:11 -0700793 // Streams added via AddStream.
794 rtc::scoped_refptr<StreamCollection> local_streams_;
795 // Streams created as a result of SetRemoteDescription.
796 rtc::scoped_refptr<StreamCollection> remote_streams_;
797
kwibergd1fe2812016-04-27 06:47:29 -0700798 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
deadbeefeb459812015-12-15 19:24:43 -0800799
Steve Anton4171afb2017-11-20 10:20:22 -0800800 // These lists store sender info seen in local/remote descriptions.
801 std::vector<RtpSenderInfo> remote_audio_sender_infos_;
802 std::vector<RtpSenderInfo> remote_video_sender_infos_;
803 std::vector<RtpSenderInfo> local_audio_sender_infos_;
804 std::vector<RtpSenderInfo> local_video_sender_infos_;
deadbeefab9b2d12015-10-14 11:33:11 -0700805
806 SctpSidAllocator sid_allocator_;
807 // label -> DataChannel
808 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
809 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
deadbeefbd292462015-12-14 18:15:29 -0800810 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
deadbeefab9b2d12015-10-14 11:33:11 -0700811
deadbeefbda7e0b2015-12-08 17:13:40 -0800812 bool remote_peer_supports_msid_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700813
terelius33860252017-05-12 23:37:18 -0700814 std::unique_ptr<Call> call_;
terelius33860252017-05-12 23:37:18 -0700815 std::unique_ptr<StatsCollector> stats_; // A pointer is passed to senders_
816 rtc::scoped_refptr<RTCStatsCollector> stats_collector_;
817
deadbeefa601f5c2016-06-06 14:27:39 -0700818 std::vector<
Steve Anton4171afb2017-11-20 10:20:22 -0800819 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
820 transceivers_;
Steve Anton75737c02017-11-06 10:37:17 -0800821
Steve Antonf8470812017-12-04 10:46:21 -0800822 SessionError session_error_ = SessionError::kNone;
823 std::string session_error_desc_;
Steve Anton75737c02017-11-06 10:37:17 -0800824
825 std::string session_id_;
826 rtc::Optional<bool> initial_offerer_;
827
828 std::unique_ptr<cricket::TransportController> transport_controller_;
829 std::unique_ptr<cricket::SctpTransportInternalFactory> sctp_factory_;
Steve Anton75737c02017-11-06 10:37:17 -0800830 // |rtp_data_channel_| is used if in RTP data channel mode, |sctp_transport_|
831 // when using SCTP.
832 cricket::RtpDataChannel* rtp_data_channel_ = nullptr;
833
834 std::unique_ptr<cricket::SctpTransportInternal> sctp_transport_;
835 // |sctp_transport_name_| keeps track of what DTLS transport the SCTP
836 // transport is using (which can change due to bundling).
837 rtc::Optional<std::string> sctp_transport_name_;
838 // |sctp_content_name_| is the content name (MID) in SDP.
839 rtc::Optional<std::string> sctp_content_name_;
840 // Value cached on signaling thread. Only updated when SctpReadyToSendData
841 // fires on the signaling thread.
842 bool sctp_ready_to_send_data_ = false;
843 // Same as signals provided by SctpTransport, but these are guaranteed to
844 // fire on the signaling thread, whereas SctpTransport fires on the networking
845 // thread.
846 // |sctp_invoker_| is used so that any signals queued on the signaling thread
847 // from the network thread are immediately discarded if the SctpTransport is
848 // destroyed (due to m= section being rejected).
849 // TODO(deadbeef): Use a proxy object to ensure that method calls/signals
850 // are marshalled to the right thread. Could almost use proxy.h for this,
851 // but it doesn't have a mechanism for marshalling sigslot::signals
852 std::unique_ptr<rtc::AsyncInvoker> sctp_invoker_;
853 sigslot::signal1<bool> SignalSctpReadyToSendData;
854 sigslot::signal2<const cricket::ReceiveDataParams&,
855 const rtc::CopyOnWriteBuffer&>
856 SignalSctpDataReceived;
857 sigslot::signal1<int> SignalSctpStreamClosedRemotely;
858
859 std::unique_ptr<SessionDescriptionInterface> current_local_description_;
860 std::unique_ptr<SessionDescriptionInterface> pending_local_description_;
861 std::unique_ptr<SessionDescriptionInterface> current_remote_description_;
862 std::unique_ptr<SessionDescriptionInterface> pending_remote_description_;
863 bool dtls_enabled_ = false;
864 // Specifies which kind of data channel is allowed. This is controlled
865 // by the chrome command-line flag and constraints:
866 // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled,
867 // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is
868 // not set or false, SCTP is allowed (DCT_SCTP);
869 // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP);
870 // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE).
871 cricket::DataChannelType data_channel_type_ = cricket::DCT_NONE;
872 // List of content names for which the remote side triggered an ICE restart.
873 std::set<std::string> pending_ice_restarts_;
874
875 std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_;
876
877 // Member variables for caching global options.
878 cricket::AudioOptions audio_options_;
879 cricket::VideoOptions video_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880};
881
882} // namespace webrtc
883
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200884#endif // PC_PEERCONNECTION_H_