blob: f8b6a54cad253860586f31ca1d70c16537703d18 [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
ossu7bb87ee2017-01-23 04:56:25 -080011#ifndef WEBRTC_PC_PEERCONNECTION_H_
12#define WEBRTC_PC_PEERCONNECTION_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <string>
perkjd61bf802016-03-24 03:16:19 -070015#include <map>
kwibergd1fe2812016-04-27 06:47:29 -070016#include <memory>
perkjd61bf802016-03-24 03:16:19 -070017#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
Henrik Kjellander15583c12016-02-10 10:53:12 +010019#include "webrtc/api/peerconnectioninterface.h"
deadbeef1dcb1642017-03-29 21:08:16 -070020#include "webrtc/pc/iceserverparsing.h"
ossu7bb87ee2017-01-23 04:56:25 -080021#include "webrtc/pc/peerconnectionfactory.h"
22#include "webrtc/pc/rtcstatscollector.h"
23#include "webrtc/pc/rtpreceiver.h"
24#include "webrtc/pc/rtpsender.h"
25#include "webrtc/pc/statscollector.h"
26#include "webrtc/pc/streamcollection.h"
27#include "webrtc/pc/webrtcsession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
29namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
deadbeefeb459812015-12-15 19:24:43 -080031class MediaStreamObserver;
perkjf0dcfe22016-03-10 18:32:00 +010032class VideoRtpReceiver;
skvlad11a9cbf2016-10-07 11:53:05 -070033class RtcEventLog;
deadbeefab9b2d12015-10-14 11:33:11 -070034
deadbeefab9b2d12015-10-14 11:33:11 -070035// Populates |session_options| from |rtc_options|, and returns true if options
36// are valid.
deadbeef0ed85b22016-02-23 17:24:52 -080037// |session_options|->transport_options map entries must exist in order for
38// them to be populated from |rtc_options|.
htaa2a49d92016-03-04 02:51:39 -080039bool ExtractMediaSessionOptions(
deadbeefab9b2d12015-10-14 11:33:11 -070040 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
htaaac2dea2016-03-10 13:35:55 -080041 bool is_offer,
deadbeefab9b2d12015-10-14 11:33:11 -070042 cricket::MediaSessionOptions* session_options);
43
44// Populates |session_options| from |constraints|, and returns true if all
45// mandatory constraints are satisfied.
deadbeef0ed85b22016-02-23 17:24:52 -080046// Assumes that |session_options|->transport_options map entries exist.
htaa2a49d92016-03-04 02:51:39 -080047// Will also set defaults if corresponding constraints are not present:
48// recv_audio=true, recv_video=true, bundle_enabled=true.
49// Other fields will be left with existing values.
50//
51// Deprecated. Will be removed once callers that use constraints are gone.
52// TODO(hta): Remove when callers are gone.
53// https://bugs.chromium.org/p/webrtc/issues/detail?id=5617
deadbeefab9b2d12015-10-14 11:33:11 -070054bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints,
55 cricket::MediaSessionOptions* session_options);
56
deadbeef70ab1a12015-09-28 16:53:55 -070057// PeerConnection implements the PeerConnectionInterface interface.
deadbeefab9b2d12015-10-14 11:33:11 -070058// It uses WebRtcSession to implement the PeerConnection functionality.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059class PeerConnection : public PeerConnectionInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060 public IceObserver,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000061 public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 public sigslot::has_slots<> {
63 public:
zhihuang38ede132017-06-15 12:52:32 -070064 explicit PeerConnection(PeerConnectionFactory* factory,
65 std::unique_ptr<RtcEventLog> event_log,
66 std::unique_ptr<Call> call);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067
deadbeef653b8e02015-11-11 12:55:10 -080068 bool Initialize(
69 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -070070 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020071 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef653b8e02015-11-11 12:55:10 -080072 PeerConnectionObserver* observer);
73
deadbeefa67696b2015-09-29 11:56:26 -070074 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
75 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
76 bool AddStream(MediaStreamInterface* local_stream) override;
77 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078
deadbeefe1f9d832016-01-14 15:35:42 -080079 rtc::scoped_refptr<RtpSenderInterface> AddTrack(
80 MediaStreamTrackInterface* track,
81 std::vector<MediaStreamInterface*> streams) override;
82 bool RemoveTrack(RtpSenderInterface* sender) override;
83
deadbeefab9b2d12015-10-14 11:33:11 -070084 virtual WebRtcSession* session() { return session_.get(); }
85
deadbeefa67696b2015-09-29 11:56:26 -070086 rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
87 AudioTrackInterface* track) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088
deadbeeffac06552015-11-25 11:26:01 -080089 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -080090 const std::string& kind,
91 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -080092
deadbeef70ab1a12015-09-28 16:53:55 -070093 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
94 const override;
95 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
96 const override;
97
deadbeefa67696b2015-09-29 11:56:26 -070098 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700100 const DataChannelInit* config) override;
101 bool GetStats(StatsObserver* observer,
102 webrtc::MediaStreamTrackInterface* track,
103 StatsOutputLevel level) override;
hbos74e1a4f2016-09-15 23:33:01 -0700104 void GetStats(RTCStatsCollectorCallback* callback) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
deadbeefa67696b2015-09-29 11:56:26 -0700106 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
deadbeefa67696b2015-09-29 11:56:26 -0700108 IceConnectionState ice_connection_state() override;
109 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110
deadbeefa67696b2015-09-29 11:56:26 -0700111 const SessionDescriptionInterface* local_description() const override;
112 const SessionDescriptionInterface* remote_description() const override;
deadbeeffe4a8a42016-12-20 17:56:17 -0800113 const SessionDescriptionInterface* current_local_description() const override;
114 const SessionDescriptionInterface* current_remote_description()
115 const override;
116 const SessionDescriptionInterface* pending_local_description() const override;
117 const SessionDescriptionInterface* pending_remote_description()
118 const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119
120 // JSEP01
htaa2a49d92016-03-04 02:51:39 -0800121 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700122 void CreateOffer(CreateSessionDescriptionObserver* observer,
123 const MediaConstraintsInterface* constraints) override;
124 void CreateOffer(CreateSessionDescriptionObserver* observer,
125 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800126 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700127 void CreateAnswer(CreateSessionDescriptionObserver* observer,
128 const MediaConstraintsInterface* constraints) override;
htaa2a49d92016-03-04 02:51:39 -0800129 void CreateAnswer(CreateSessionDescriptionObserver* observer,
130 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700131 void SetLocalDescription(SetSessionDescriptionObserver* observer,
132 SessionDescriptionInterface* desc) override;
133 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
134 SessionDescriptionInterface* desc) override;
deadbeef46c73892016-11-16 19:42:04 -0800135 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
deadbeefa67696b2015-09-29 11:56:26 -0700136 bool SetConfiguration(
deadbeef293e9262017-01-11 12:28:30 -0800137 const PeerConnectionInterface::RTCConfiguration& configuration,
138 RTCError* error) override;
139 bool SetConfiguration(
140 const PeerConnectionInterface::RTCConfiguration& configuration) override {
141 return SetConfiguration(configuration, nullptr);
142 }
deadbeefa67696b2015-09-29 11:56:26 -0700143 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700144 bool RemoveIceCandidates(
145 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146
deadbeefa67696b2015-09-29 11:56:26 -0700147 void RegisterUMAObserver(UMAObserver* observer) override;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000148
zstein4b979802017-06-02 14:37:37 -0700149 RTCError SetBitrate(const BitrateParameters& bitrate) override;
150
ivoc14d5dbe2016-07-04 07:06:55 -0700151 bool StartRtcEventLog(rtc::PlatformFile file,
152 int64_t max_size_bytes) override;
153 void StopRtcEventLog() override;
154
deadbeefa67696b2015-09-29 11:56:26 -0700155 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156
hbos82ebe022016-11-14 01:41:09 -0800157 sigslot::signal1<DataChannel*> SignalDataChannelCreated;
158
deadbeefab9b2d12015-10-14 11:33:11 -0700159 // Virtual for unit tests.
160 virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
161 sctp_data_channels() const {
162 return sctp_data_channels_;
perkjd61bf802016-03-24 03:16:19 -0700163 }
deadbeefab9b2d12015-10-14 11:33:11 -0700164
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700166 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167
168 private:
deadbeefab9b2d12015-10-14 11:33:11 -0700169 struct TrackInfo {
170 TrackInfo() : ssrc(0) {}
171 TrackInfo(const std::string& stream_label,
172 const std::string track_id,
173 uint32_t ssrc)
174 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {}
deadbeefbda7e0b2015-12-08 17:13:40 -0800175 bool operator==(const TrackInfo& other) {
176 return this->stream_label == other.stream_label &&
177 this->track_id == other.track_id && this->ssrc == other.ssrc;
178 }
deadbeefab9b2d12015-10-14 11:33:11 -0700179 std::string stream_label;
180 std::string track_id;
181 uint32_t ssrc;
182 };
183 typedef std::vector<TrackInfo> TrackInfos;
184
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 // Implements MessageHandler.
deadbeefa67696b2015-09-29 11:56:26 -0700186 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187
deadbeefab9b2d12015-10-14 11:33:11 -0700188 void CreateAudioReceiver(MediaStreamInterface* stream,
perkjd61bf802016-03-24 03:16:19 -0700189 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700190 uint32_t ssrc);
perkjf0dcfe22016-03-10 18:32:00 +0100191
deadbeefab9b2d12015-10-14 11:33:11 -0700192 void CreateVideoReceiver(MediaStreamInterface* stream,
perkjf0dcfe22016-03-10 18:32:00 +0100193 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700194 uint32_t ssrc);
perkjd61bf802016-03-24 03:16:19 -0700195 void DestroyReceiver(const std::string& track_id);
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700196
197 // May be called either by AddStream/RemoveStream, or when a track is
198 // added/removed from a stream previously added via AddStream.
199 void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream);
200 void RemoveAudioTrack(AudioTrackInterface* track,
201 MediaStreamInterface* stream);
202 void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream);
203 void RemoveVideoTrack(VideoTrackInterface* track,
204 MediaStreamInterface* stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205
206 // Implements IceObserver
zstein6dfd53a2017-03-06 13:49:03 -0800207 void OnIceConnectionStateChange(IceConnectionState new_state) override;
Peter Thatcher54360512015-07-08 11:08:35 -0700208 void OnIceGatheringChange(IceGatheringState new_state) override;
jbauch81bf7b02017-03-25 08:31:12 -0700209 void OnIceCandidate(
210 std::unique_ptr<IceCandidateInterface> candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700211 void OnIceCandidatesRemoved(
212 const std::vector<cricket::Candidate>& candidates) override;
Peter Thatcher54360512015-07-08 11:08:35 -0700213 void OnIceConnectionReceivingChange(bool receiving) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214
215 // Signals from WebRtcSession.
deadbeefd59daf82015-10-14 15:02:44 -0700216 void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 void ChangeSignalingState(SignalingState signaling_state);
218
deadbeefeb459812015-12-15 19:24:43 -0800219 // Signals from MediaStreamObserver.
220 void OnAudioTrackAdded(AudioTrackInterface* track,
221 MediaStreamInterface* stream);
222 void OnAudioTrackRemoved(AudioTrackInterface* track,
223 MediaStreamInterface* stream);
224 void OnVideoTrackAdded(VideoTrackInterface* track,
225 MediaStreamInterface* stream);
226 void OnVideoTrackRemoved(VideoTrackInterface* track,
227 MediaStreamInterface* stream);
228
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000229 rtc::Thread* signaling_thread() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 return factory_->signaling_thread();
231 }
232
deadbeef91dd5672016-05-18 16:55:30 -0700233 rtc::Thread* network_thread() const { return factory_->network_thread(); }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700234
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
236 const std::string& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700237 void PostCreateSessionDescriptionFailure(
238 CreateSessionDescriptionObserver* observer,
239 const std::string& error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240
241 bool IsClosed() const {
242 return signaling_state_ == PeerConnectionInterface::kClosed;
243 }
244
deadbeefab9b2d12015-10-14 11:33:11 -0700245 // Returns a MediaSessionOptions struct with options decided by |options|,
246 // the local MediaStreams and DataChannels.
247 virtual bool GetOptionsForOffer(
248 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
249 cricket::MediaSessionOptions* session_options);
250
251 // Returns a MediaSessionOptions struct with options decided by
252 // |constraints|, the local MediaStreams and DataChannels.
htaa2a49d92016-03-04 02:51:39 -0800253 // Deprecated, use version without constraints.
deadbeefab9b2d12015-10-14 11:33:11 -0700254 virtual bool GetOptionsForAnswer(
255 const MediaConstraintsInterface* constraints,
256 cricket::MediaSessionOptions* session_options);
htaa2a49d92016-03-04 02:51:39 -0800257 virtual bool GetOptionsForAnswer(
258 const RTCOfferAnswerOptions& options,
259 cricket::MediaSessionOptions* session_options);
260
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700261 void InitializeOptionsForAnswer(
262 cricket::MediaSessionOptions* session_options);
263
htaa2a49d92016-03-04 02:51:39 -0800264 // Helper function for options processing.
265 // Deprecated.
266 virtual void FinishOptionsForAnswer(
267 cricket::MediaSessionOptions* session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700268
deadbeeffaac4972015-11-12 15:33:07 -0800269 // Remove all local and remote tracks of type |media_type|.
270 // Called when a media type is rejected (m-line set to port 0).
271 void RemoveTracks(cricket::MediaType media_type);
272
deadbeefbda7e0b2015-12-08 17:13:40 -0800273 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
274 // and existing MediaStreamTracks are removed if there is no corresponding
275 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
276 // is created if it doesn't exist; if false, it's removed if it exists.
277 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700278 // If a new MediaStream is created it is added to |new_streams|.
279 void UpdateRemoteStreamsList(
280 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800281 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700282 cricket::MediaType media_type,
283 StreamCollection* new_streams);
284
285 // Triggered when a remote track has been seen for the first time in a remote
286 // session description. It creates a remote MediaStreamTrackInterface
287 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
288 void OnRemoteTrackSeen(const std::string& stream_label,
289 const std::string& track_id,
290 uint32_t ssrc,
291 cricket::MediaType media_type);
292
293 // Triggered when a remote track has been removed from a remote session
294 // description. It removes the remote track with id |track_id| from a remote
295 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
296 void OnRemoteTrackRemoved(const std::string& stream_label,
297 const std::string& track_id,
298 cricket::MediaType media_type);
299
300 // Finds remote MediaStreams without any tracks and removes them from
301 // |remote_streams_| and notifies the observer that the MediaStreams no longer
302 // exist.
303 void UpdateEndedRemoteMediaStreams();
304
deadbeefab9b2d12015-10-14 11:33:11 -0700305 // Loops through the vector of |streams| and finds added and removed
306 // StreamParams since last time this method was called.
307 // For each new or removed StreamParam, OnLocalTrackSeen or
308 // OnLocalTrackRemoved is invoked.
309 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams,
310 cricket::MediaType media_type);
311
312 // Triggered when a local track has been seen for the first time in a local
313 // session description.
314 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
315 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
316 // in a MediaStream in |local_streams_|
317 void OnLocalTrackSeen(const std::string& stream_label,
318 const std::string& track_id,
319 uint32_t ssrc,
320 cricket::MediaType media_type);
321
322 // Triggered when a local track has been removed from a local session
323 // description.
324 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
325 // has been removed from the local SessionDescription and the stream can be
326 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
327 void OnLocalTrackRemoved(const std::string& stream_label,
328 const std::string& track_id,
329 uint32_t ssrc,
330 cricket::MediaType media_type);
331
332 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
333 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
334 void UpdateClosingRtpDataChannels(
335 const std::vector<std::string>& active_channels,
336 bool is_local_update);
337 void CreateRemoteRtpDataChannel(const std::string& label,
338 uint32_t remote_ssrc);
339
340 // Creates channel and adds it to the collection of DataChannels that will
341 // be offered in a SessionDescription.
342 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
343 const std::string& label,
344 const InternalDataChannelInit* config);
345
346 // Checks if any data channel has been added.
347 bool HasDataChannels() const;
348
349 void AllocateSctpSids(rtc::SSLRole role);
350 void OnSctpDataChannelClosed(DataChannel* channel);
351
352 // Notifications from WebRtcSession relating to BaseChannels.
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700353 void OnVoiceChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700354 void OnVoiceChannelDestroyed();
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700355 void OnVideoChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700356 void OnVideoChannelDestroyed();
357 void OnDataChannelCreated();
358 void OnDataChannelDestroyed();
359 // Called when the cricket::DataChannel receives a message indicating that a
360 // webrtc::DataChannel should be opened.
361 void OnDataChannelOpenMessage(const std::string& label,
362 const InternalDataChannelInit& config);
363
deadbeefa601f5c2016-06-06 14:27:39 -0700364 RtpSenderInternal* FindSenderById(const std::string& id);
deadbeeffac06552015-11-25 11:26:01 -0800365
deadbeefa601f5c2016-06-06 14:27:39 -0700366 std::vector<rtc::scoped_refptr<
367 RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator
deadbeef70ab1a12015-09-28 16:53:55 -0700368 FindSenderForTrack(MediaStreamTrackInterface* track);
deadbeefa601f5c2016-06-06 14:27:39 -0700369 std::vector<rtc::scoped_refptr<
370 RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator
perkjd61bf802016-03-24 03:16:19 -0700371 FindReceiverForTrack(const std::string& track_id);
deadbeef70ab1a12015-09-28 16:53:55 -0700372
deadbeefab9b2d12015-10-14 11:33:11 -0700373 TrackInfos* GetRemoteTracks(cricket::MediaType media_type);
374 TrackInfos* GetLocalTracks(cricket::MediaType media_type);
375 const TrackInfo* FindTrackInfo(const TrackInfos& infos,
376 const std::string& stream_label,
377 const std::string track_id) const;
378
379 // Returns the specified SCTP DataChannel in sctp_data_channels_,
380 // or nullptr if not found.
381 DataChannel* FindDataChannelBySid(int sid) const;
382
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700383 // Called when first configuring the port allocator.
deadbeef91dd5672016-05-18 16:55:30 -0700384 bool InitializePortAllocator_n(const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 12:28:30 -0800385 // Called when SetConfiguration is called to apply the supported subset
386 // of the configuration on the network thread.
387 bool ReconfigurePortAllocator_n(
388 const cricket::ServerAddresses& stun_servers,
389 const std::vector<cricket::RelayServerConfig>& turn_servers,
390 IceTransportsType type,
391 int candidate_pool_size,
392 bool prune_turn_ports);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700393
ivoc14d5dbe2016-07-04 07:06:55 -0700394 // Starts recording an Rtc EventLog using the supplied platform file.
395 // This function should only be called from the worker thread.
396 bool StartRtcEventLog_w(rtc::PlatformFile file, int64_t max_size_bytes);
397 // Starts recording an Rtc EventLog using the supplied platform file.
398 // This function should only be called from the worker thread.
399 void StopRtcEventLog_w();
400
Steve Anton038834f2017-07-14 15:59:59 -0700401 // Ensures the configuration doesn't have any parameters with invalid values,
402 // or values that conflict with other parameters.
403 //
404 // Returns RTCError::OK() if there are no issues.
405 RTCError ValidateConfiguration(const RTCConfiguration& config) const;
406
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 // Storing the factory as a scoped reference pointer ensures that the memory
408 // in the PeerConnectionFactoryImpl remains available as long as the
409 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
410 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -0700411 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 // will refer to the same reference count.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000413 rtc::scoped_refptr<PeerConnectionFactory> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 PeerConnectionObserver* observer_;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000415 UMAObserver* uma_observer_;
terelius33860252017-05-12 23:37:18 -0700416
417 // The EventLog needs to outlive |call_| (and any other object that uses it).
418 std::unique_ptr<RtcEventLog> event_log_;
419
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420 SignalingState signaling_state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 IceConnectionState ice_connection_state_;
422 IceGatheringState ice_gathering_state_;
deadbeef46c73892016-11-16 19:42:04 -0800423 PeerConnectionInterface::RTCConfiguration configuration_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424
kwibergd1fe2812016-04-27 06:47:29 -0700425 std::unique_ptr<cricket::PortAllocator> port_allocator_;
deadbeefab9b2d12015-10-14 11:33:11 -0700426
zhihuang8f65cdf2016-05-06 18:40:30 -0700427 // One PeerConnection has only one RTCP CNAME.
428 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
429 std::string rtcp_cname_;
430
deadbeefab9b2d12015-10-14 11:33:11 -0700431 // Streams added via AddStream.
432 rtc::scoped_refptr<StreamCollection> local_streams_;
433 // Streams created as a result of SetRemoteDescription.
434 rtc::scoped_refptr<StreamCollection> remote_streams_;
435
kwibergd1fe2812016-04-27 06:47:29 -0700436 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
deadbeefeb459812015-12-15 19:24:43 -0800437
deadbeefab9b2d12015-10-14 11:33:11 -0700438 // These lists store track info seen in local/remote descriptions.
439 TrackInfos remote_audio_tracks_;
440 TrackInfos remote_video_tracks_;
441 TrackInfos local_audio_tracks_;
442 TrackInfos local_video_tracks_;
443
444 SctpSidAllocator sid_allocator_;
445 // label -> DataChannel
446 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
447 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
deadbeefbd292462015-12-14 18:15:29 -0800448 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
deadbeefab9b2d12015-10-14 11:33:11 -0700449
deadbeefbda7e0b2015-12-08 17:13:40 -0800450 bool remote_peer_supports_msid_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700451
terelius33860252017-05-12 23:37:18 -0700452 std::unique_ptr<Call> call_;
453 std::unique_ptr<WebRtcSession> session_;
454 std::unique_ptr<StatsCollector> stats_; // A pointer is passed to senders_
455 rtc::scoped_refptr<RTCStatsCollector> stats_collector_;
456
deadbeefa601f5c2016-06-06 14:27:39 -0700457 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
458 senders_;
459 std::vector<
460 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
461 receivers_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462};
463
464} // namespace webrtc
465
ossu7bb87ee2017-01-23 04:56:25 -0800466#endif // WEBRTC_PC_PEERCONNECTION_H_