blob: 2aa634c7002703b61bdd78621fe057034c287145 [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"
ossu7bb87ee2017-01-23 04:56:25 -080020#include "webrtc/pc/peerconnectionfactory.h"
21#include "webrtc/pc/rtcstatscollector.h"
22#include "webrtc/pc/rtpreceiver.h"
23#include "webrtc/pc/rtpsender.h"
24#include "webrtc/pc/statscollector.h"
25#include "webrtc/pc/streamcollection.h"
26#include "webrtc/pc/webrtcsession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
28namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
deadbeefeb459812015-12-15 19:24:43 -080030class MediaStreamObserver;
perkjf0dcfe22016-03-10 18:32:00 +010031class VideoRtpReceiver;
skvlad11a9cbf2016-10-07 11:53:05 -070032class RtcEventLog;
deadbeefab9b2d12015-10-14 11:33:11 -070033
deadbeefab9b2d12015-10-14 11:33:11 -070034// Populates |session_options| from |rtc_options|, and returns true if options
35// are valid.
deadbeef0ed85b22016-02-23 17:24:52 -080036// |session_options|->transport_options map entries must exist in order for
37// them to be populated from |rtc_options|.
htaa2a49d92016-03-04 02:51:39 -080038bool ExtractMediaSessionOptions(
deadbeefab9b2d12015-10-14 11:33:11 -070039 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
htaaac2dea2016-03-10 13:35:55 -080040 bool is_offer,
deadbeefab9b2d12015-10-14 11:33:11 -070041 cricket::MediaSessionOptions* session_options);
42
43// Populates |session_options| from |constraints|, and returns true if all
44// mandatory constraints are satisfied.
deadbeef0ed85b22016-02-23 17:24:52 -080045// Assumes that |session_options|->transport_options map entries exist.
htaa2a49d92016-03-04 02:51:39 -080046// Will also set defaults if corresponding constraints are not present:
47// recv_audio=true, recv_video=true, bundle_enabled=true.
48// Other fields will be left with existing values.
49//
50// Deprecated. Will be removed once callers that use constraints are gone.
51// TODO(hta): Remove when callers are gone.
52// https://bugs.chromium.org/p/webrtc/issues/detail?id=5617
deadbeefab9b2d12015-10-14 11:33:11 -070053bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints,
54 cricket::MediaSessionOptions* session_options);
55
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080056// Parses the URLs for each server in |servers| to build |stun_servers| and
deadbeef293e9262017-01-11 12:28:30 -080057// |turn_servers|. Can return SYNTAX_ERROR if the URL is malformed, or
58// INVALID_PARAMETER if a TURN server is missing |username| or |password|.
59RTCErrorType ParseIceServers(
60 const PeerConnectionInterface::IceServers& servers,
61 cricket::ServerAddresses* stun_servers,
62 std::vector<cricket::RelayServerConfig>* turn_servers);
deadbeef0a6c4ca2015-10-06 11:38:28 -070063
deadbeef70ab1a12015-09-28 16:53:55 -070064// PeerConnection implements the PeerConnectionInterface interface.
deadbeefab9b2d12015-10-14 11:33:11 -070065// It uses WebRtcSession to implement the PeerConnection functionality.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066class PeerConnection : public PeerConnectionInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 public IceObserver,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000068 public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069 public sigslot::has_slots<> {
70 public:
71 explicit PeerConnection(PeerConnectionFactory* factory);
72
deadbeef653b8e02015-11-11 12:55:10 -080073 bool Initialize(
74 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -070075 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020076 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef653b8e02015-11-11 12:55:10 -080077 PeerConnectionObserver* observer);
78
deadbeefa67696b2015-09-29 11:56:26 -070079 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
80 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
81 bool AddStream(MediaStreamInterface* local_stream) override;
82 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
deadbeefe1f9d832016-01-14 15:35:42 -080084 rtc::scoped_refptr<RtpSenderInterface> AddTrack(
85 MediaStreamTrackInterface* track,
86 std::vector<MediaStreamInterface*> streams) override;
87 bool RemoveTrack(RtpSenderInterface* sender) override;
88
deadbeefab9b2d12015-10-14 11:33:11 -070089 virtual WebRtcSession* session() { return session_.get(); }
90
deadbeefa67696b2015-09-29 11:56:26 -070091 rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
92 AudioTrackInterface* track) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093
deadbeeffac06552015-11-25 11:26:01 -080094 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -080095 const std::string& kind,
96 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -080097
deadbeef70ab1a12015-09-28 16:53:55 -070098 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
99 const override;
100 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
101 const override;
102
deadbeefa67696b2015-09-29 11:56:26 -0700103 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700105 const DataChannelInit* config) override;
106 bool GetStats(StatsObserver* observer,
107 webrtc::MediaStreamTrackInterface* track,
108 StatsOutputLevel level) override;
hbos74e1a4f2016-09-15 23:33:01 -0700109 void GetStats(RTCStatsCollectorCallback* callback) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110
deadbeefa67696b2015-09-29 11:56:26 -0700111 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112
deadbeefa67696b2015-09-29 11:56:26 -0700113 IceConnectionState ice_connection_state() override;
114 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115
deadbeefa67696b2015-09-29 11:56:26 -0700116 const SessionDescriptionInterface* local_description() const override;
117 const SessionDescriptionInterface* remote_description() const override;
deadbeeffe4a8a42016-12-20 17:56:17 -0800118 const SessionDescriptionInterface* current_local_description() const override;
119 const SessionDescriptionInterface* current_remote_description()
120 const override;
121 const SessionDescriptionInterface* pending_local_description() const override;
122 const SessionDescriptionInterface* pending_remote_description()
123 const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124
125 // JSEP01
htaa2a49d92016-03-04 02:51:39 -0800126 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700127 void CreateOffer(CreateSessionDescriptionObserver* observer,
128 const MediaConstraintsInterface* constraints) override;
129 void CreateOffer(CreateSessionDescriptionObserver* observer,
130 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800131 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700132 void CreateAnswer(CreateSessionDescriptionObserver* observer,
133 const MediaConstraintsInterface* constraints) override;
htaa2a49d92016-03-04 02:51:39 -0800134 void CreateAnswer(CreateSessionDescriptionObserver* observer,
135 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700136 void SetLocalDescription(SetSessionDescriptionObserver* observer,
137 SessionDescriptionInterface* desc) override;
138 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
139 SessionDescriptionInterface* desc) override;
deadbeef46c73892016-11-16 19:42:04 -0800140 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
deadbeefa67696b2015-09-29 11:56:26 -0700141 bool SetConfiguration(
deadbeef293e9262017-01-11 12:28:30 -0800142 const PeerConnectionInterface::RTCConfiguration& configuration,
143 RTCError* error) override;
144 bool SetConfiguration(
145 const PeerConnectionInterface::RTCConfiguration& configuration) override {
146 return SetConfiguration(configuration, nullptr);
147 }
deadbeefa67696b2015-09-29 11:56:26 -0700148 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700149 bool RemoveIceCandidates(
150 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151
deadbeefa67696b2015-09-29 11:56:26 -0700152 void RegisterUMAObserver(UMAObserver* observer) override;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000153
ivoc14d5dbe2016-07-04 07:06:55 -0700154 bool StartRtcEventLog(rtc::PlatformFile file,
155 int64_t max_size_bytes) override;
156 void StopRtcEventLog() override;
157
deadbeefa67696b2015-09-29 11:56:26 -0700158 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159
hbos82ebe022016-11-14 01:41:09 -0800160 sigslot::signal1<DataChannel*> SignalDataChannelCreated;
161
deadbeefab9b2d12015-10-14 11:33:11 -0700162 // Virtual for unit tests.
163 virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
164 sctp_data_channels() const {
165 return sctp_data_channels_;
perkjd61bf802016-03-24 03:16:19 -0700166 }
deadbeefab9b2d12015-10-14 11:33:11 -0700167
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700169 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170
171 private:
deadbeefab9b2d12015-10-14 11:33:11 -0700172 struct TrackInfo {
173 TrackInfo() : ssrc(0) {}
174 TrackInfo(const std::string& stream_label,
175 const std::string track_id,
176 uint32_t ssrc)
177 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {}
deadbeefbda7e0b2015-12-08 17:13:40 -0800178 bool operator==(const TrackInfo& other) {
179 return this->stream_label == other.stream_label &&
180 this->track_id == other.track_id && this->ssrc == other.ssrc;
181 }
deadbeefab9b2d12015-10-14 11:33:11 -0700182 std::string stream_label;
183 std::string track_id;
184 uint32_t ssrc;
185 };
186 typedef std::vector<TrackInfo> TrackInfos;
187
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 // Implements MessageHandler.
deadbeefa67696b2015-09-29 11:56:26 -0700189 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190
deadbeefab9b2d12015-10-14 11:33:11 -0700191 void CreateAudioReceiver(MediaStreamInterface* stream,
perkjd61bf802016-03-24 03:16:19 -0700192 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700193 uint32_t ssrc);
perkjf0dcfe22016-03-10 18:32:00 +0100194
deadbeefab9b2d12015-10-14 11:33:11 -0700195 void CreateVideoReceiver(MediaStreamInterface* stream,
perkjf0dcfe22016-03-10 18:32:00 +0100196 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700197 uint32_t ssrc);
perkjd61bf802016-03-24 03:16:19 -0700198 void DestroyReceiver(const std::string& track_id);
deadbeefab9b2d12015-10-14 11:33:11 -0700199 void DestroyAudioSender(MediaStreamInterface* stream,
200 AudioTrackInterface* audio_track,
201 uint32_t ssrc);
202 void DestroyVideoSender(MediaStreamInterface* stream,
203 VideoTrackInterface* video_track);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204
205 // Implements IceObserver
zstein6dfd53a2017-03-06 13:49:03 -0800206 void OnIceConnectionStateChange(IceConnectionState new_state) override;
Peter Thatcher54360512015-07-08 11:08:35 -0700207 void OnIceGatheringChange(IceGatheringState new_state) override;
jbauch81bf7b02017-03-25 08:31:12 -0700208 void OnIceCandidate(
209 std::unique_ptr<IceCandidateInterface> candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700210 void OnIceCandidatesRemoved(
211 const std::vector<cricket::Candidate>& candidates) override;
Peter Thatcher54360512015-07-08 11:08:35 -0700212 void OnIceConnectionReceivingChange(bool receiving) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213
214 // Signals from WebRtcSession.
deadbeefd59daf82015-10-14 15:02:44 -0700215 void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 void ChangeSignalingState(SignalingState signaling_state);
217
deadbeefeb459812015-12-15 19:24:43 -0800218 // Signals from MediaStreamObserver.
219 void OnAudioTrackAdded(AudioTrackInterface* track,
220 MediaStreamInterface* stream);
221 void OnAudioTrackRemoved(AudioTrackInterface* track,
222 MediaStreamInterface* stream);
223 void OnVideoTrackAdded(VideoTrackInterface* track,
224 MediaStreamInterface* stream);
225 void OnVideoTrackRemoved(VideoTrackInterface* track,
226 MediaStreamInterface* stream);
227
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000228 rtc::Thread* signaling_thread() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 return factory_->signaling_thread();
230 }
231
deadbeef91dd5672016-05-18 16:55:30 -0700232 rtc::Thread* network_thread() const { return factory_->network_thread(); }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700233
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
235 const std::string& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700236 void PostCreateSessionDescriptionFailure(
237 CreateSessionDescriptionObserver* observer,
238 const std::string& error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
240 bool IsClosed() const {
241 return signaling_state_ == PeerConnectionInterface::kClosed;
242 }
243
deadbeefab9b2d12015-10-14 11:33:11 -0700244 // Returns a MediaSessionOptions struct with options decided by |options|,
245 // the local MediaStreams and DataChannels.
246 virtual bool GetOptionsForOffer(
247 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
248 cricket::MediaSessionOptions* session_options);
249
250 // Returns a MediaSessionOptions struct with options decided by
251 // |constraints|, the local MediaStreams and DataChannels.
htaa2a49d92016-03-04 02:51:39 -0800252 // Deprecated, use version without constraints.
deadbeefab9b2d12015-10-14 11:33:11 -0700253 virtual bool GetOptionsForAnswer(
254 const MediaConstraintsInterface* constraints,
255 cricket::MediaSessionOptions* session_options);
htaa2a49d92016-03-04 02:51:39 -0800256 virtual bool GetOptionsForAnswer(
257 const RTCOfferAnswerOptions& options,
258 cricket::MediaSessionOptions* session_options);
259
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700260 void InitializeOptionsForAnswer(
261 cricket::MediaSessionOptions* session_options);
262
htaa2a49d92016-03-04 02:51:39 -0800263 // Helper function for options processing.
264 // Deprecated.
265 virtual void FinishOptionsForAnswer(
266 cricket::MediaSessionOptions* session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700267
deadbeeffaac4972015-11-12 15:33:07 -0800268 // Remove all local and remote tracks of type |media_type|.
269 // Called when a media type is rejected (m-line set to port 0).
270 void RemoveTracks(cricket::MediaType media_type);
271
deadbeefbda7e0b2015-12-08 17:13:40 -0800272 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
273 // and existing MediaStreamTracks are removed if there is no corresponding
274 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
275 // is created if it doesn't exist; if false, it's removed if it exists.
276 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700277 // If a new MediaStream is created it is added to |new_streams|.
278 void UpdateRemoteStreamsList(
279 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800280 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700281 cricket::MediaType media_type,
282 StreamCollection* new_streams);
283
284 // Triggered when a remote track has been seen for the first time in a remote
285 // session description. It creates a remote MediaStreamTrackInterface
286 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
287 void OnRemoteTrackSeen(const std::string& stream_label,
288 const std::string& track_id,
289 uint32_t ssrc,
290 cricket::MediaType media_type);
291
292 // Triggered when a remote track has been removed from a remote session
293 // description. It removes the remote track with id |track_id| from a remote
294 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
295 void OnRemoteTrackRemoved(const std::string& stream_label,
296 const std::string& track_id,
297 cricket::MediaType media_type);
298
299 // Finds remote MediaStreams without any tracks and removes them from
300 // |remote_streams_| and notifies the observer that the MediaStreams no longer
301 // exist.
302 void UpdateEndedRemoteMediaStreams();
303
deadbeefab9b2d12015-10-14 11:33:11 -0700304 // Loops through the vector of |streams| and finds added and removed
305 // StreamParams since last time this method was called.
306 // For each new or removed StreamParam, OnLocalTrackSeen or
307 // OnLocalTrackRemoved is invoked.
308 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams,
309 cricket::MediaType media_type);
310
311 // Triggered when a local track has been seen for the first time in a local
312 // session description.
313 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
314 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
315 // in a MediaStream in |local_streams_|
316 void OnLocalTrackSeen(const std::string& stream_label,
317 const std::string& track_id,
318 uint32_t ssrc,
319 cricket::MediaType media_type);
320
321 // Triggered when a local track has been removed from a local session
322 // description.
323 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
324 // has been removed from the local SessionDescription and the stream can be
325 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
326 void OnLocalTrackRemoved(const std::string& stream_label,
327 const std::string& track_id,
328 uint32_t ssrc,
329 cricket::MediaType media_type);
330
331 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
332 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
333 void UpdateClosingRtpDataChannels(
334 const std::vector<std::string>& active_channels,
335 bool is_local_update);
336 void CreateRemoteRtpDataChannel(const std::string& label,
337 uint32_t remote_ssrc);
338
339 // Creates channel and adds it to the collection of DataChannels that will
340 // be offered in a SessionDescription.
341 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
342 const std::string& label,
343 const InternalDataChannelInit* config);
344
345 // Checks if any data channel has been added.
346 bool HasDataChannels() const;
347
348 void AllocateSctpSids(rtc::SSLRole role);
349 void OnSctpDataChannelClosed(DataChannel* channel);
350
351 // Notifications from WebRtcSession relating to BaseChannels.
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700352 void OnVoiceChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700353 void OnVoiceChannelDestroyed();
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700354 void OnVideoChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700355 void OnVideoChannelDestroyed();
356 void OnDataChannelCreated();
357 void OnDataChannelDestroyed();
358 // Called when the cricket::DataChannel receives a message indicating that a
359 // webrtc::DataChannel should be opened.
360 void OnDataChannelOpenMessage(const std::string& label,
361 const InternalDataChannelInit& config);
362
deadbeefa601f5c2016-06-06 14:27:39 -0700363 RtpSenderInternal* FindSenderById(const std::string& id);
deadbeeffac06552015-11-25 11:26:01 -0800364
deadbeefa601f5c2016-06-06 14:27:39 -0700365 std::vector<rtc::scoped_refptr<
366 RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator
deadbeef70ab1a12015-09-28 16:53:55 -0700367 FindSenderForTrack(MediaStreamTrackInterface* track);
deadbeefa601f5c2016-06-06 14:27:39 -0700368 std::vector<rtc::scoped_refptr<
369 RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator
perkjd61bf802016-03-24 03:16:19 -0700370 FindReceiverForTrack(const std::string& track_id);
deadbeef70ab1a12015-09-28 16:53:55 -0700371
deadbeefab9b2d12015-10-14 11:33:11 -0700372 TrackInfos* GetRemoteTracks(cricket::MediaType media_type);
373 TrackInfos* GetLocalTracks(cricket::MediaType media_type);
374 const TrackInfo* FindTrackInfo(const TrackInfos& infos,
375 const std::string& stream_label,
376 const std::string track_id) const;
377
378 // Returns the specified SCTP DataChannel in sctp_data_channels_,
379 // or nullptr if not found.
380 DataChannel* FindDataChannelBySid(int sid) const;
381
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700382 // Called when first configuring the port allocator.
deadbeef91dd5672016-05-18 16:55:30 -0700383 bool InitializePortAllocator_n(const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 12:28:30 -0800384 // Called when SetConfiguration is called to apply the supported subset
385 // of the configuration on the network thread.
386 bool ReconfigurePortAllocator_n(
387 const cricket::ServerAddresses& stun_servers,
388 const std::vector<cricket::RelayServerConfig>& turn_servers,
389 IceTransportsType type,
390 int candidate_pool_size,
391 bool prune_turn_ports);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700392
ivoc14d5dbe2016-07-04 07:06:55 -0700393 // Starts recording an Rtc EventLog using the supplied platform file.
394 // This function should only be called from the worker thread.
395 bool StartRtcEventLog_w(rtc::PlatformFile file, int64_t max_size_bytes);
396 // Starts recording an Rtc EventLog using the supplied platform file.
397 // This function should only be called from the worker thread.
398 void StopRtcEventLog_w();
399
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 // Storing the factory as a scoped reference pointer ensures that the memory
401 // in the PeerConnectionFactoryImpl remains available as long as the
402 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
403 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -0700404 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 // will refer to the same reference count.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000406 rtc::scoped_refptr<PeerConnectionFactory> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 PeerConnectionObserver* observer_;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000408 UMAObserver* uma_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409 SignalingState signaling_state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 IceConnectionState ice_connection_state_;
411 IceGatheringState ice_gathering_state_;
deadbeef46c73892016-11-16 19:42:04 -0800412 PeerConnectionInterface::RTCConfiguration configuration_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413
kwibergd1fe2812016-04-27 06:47:29 -0700414 std::unique_ptr<cricket::PortAllocator> port_allocator_;
skvlad11a9cbf2016-10-07 11:53:05 -0700415 // The EventLog needs to outlive the media controller.
416 std::unique_ptr<RtcEventLog> event_log_;
kwibergd1fe2812016-04-27 06:47:29 -0700417 std::unique_ptr<MediaControllerInterface> media_controller_;
deadbeefab9b2d12015-10-14 11:33:11 -0700418
zhihuang8f65cdf2016-05-06 18:40:30 -0700419 // One PeerConnection has only one RTCP CNAME.
420 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
421 std::string rtcp_cname_;
422
deadbeefab9b2d12015-10-14 11:33:11 -0700423 // Streams added via AddStream.
424 rtc::scoped_refptr<StreamCollection> local_streams_;
425 // Streams created as a result of SetRemoteDescription.
426 rtc::scoped_refptr<StreamCollection> remote_streams_;
427
kwibergd1fe2812016-04-27 06:47:29 -0700428 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
deadbeefeb459812015-12-15 19:24:43 -0800429
deadbeefab9b2d12015-10-14 11:33:11 -0700430 // These lists store track info seen in local/remote descriptions.
431 TrackInfos remote_audio_tracks_;
432 TrackInfos remote_video_tracks_;
433 TrackInfos local_audio_tracks_;
434 TrackInfos local_video_tracks_;
435
436 SctpSidAllocator sid_allocator_;
437 // label -> DataChannel
438 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
439 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
deadbeefbd292462015-12-14 18:15:29 -0800440 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
deadbeefab9b2d12015-10-14 11:33:11 -0700441
deadbeefbda7e0b2015-12-08 17:13:40 -0800442 bool remote_peer_supports_msid_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700443
deadbeefa601f5c2016-06-06 14:27:39 -0700444 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
445 senders_;
446 std::vector<
447 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
448 receivers_;
kwibergd1fe2812016-04-27 06:47:29 -0700449 std::unique_ptr<WebRtcSession> session_;
kwibergd1fe2812016-04-27 06:47:29 -0700450 std::unique_ptr<StatsCollector> stats_;
hbos74e1a4f2016-09-15 23:33:01 -0700451 rtc::scoped_refptr<RTCStatsCollector> stats_collector_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452};
453
454} // namespace webrtc
455
ossu7bb87ee2017-01-23 04:56:25 -0800456#endif // WEBRTC_PC_PEERCONNECTION_H_