blob: 70fd86779f538ad07df0308c65c08cfbacd2ab22 [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#ifndef WEBRTC_API_PEERCONNECTION_H_
12#define WEBRTC_API_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/peerconnectionfactory.h"
20#include "webrtc/api/peerconnectioninterface.h"
hbos74e1a4f2016-09-15 23:33:01 -070021#include "webrtc/api/rtcstatscollector.h"
deadbeefa601f5c2016-06-06 14:27:39 -070022#include "webrtc/api/rtpreceiver.h"
23#include "webrtc/api/rtpsender.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010024#include "webrtc/api/statscollector.h"
25#include "webrtc/api/streamcollection.h"
26#include "webrtc/api/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
57// |turn_servers|.
deadbeef0a6c4ca2015-10-06 11:38:28 -070058bool ParseIceServers(const PeerConnectionInterface::IceServers& servers,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080059 cricket::ServerAddresses* stun_servers,
60 std::vector<cricket::RelayServerConfig>* turn_servers);
deadbeef0a6c4ca2015-10-06 11:38:28 -070061
deadbeef70ab1a12015-09-28 16:53:55 -070062// PeerConnection implements the PeerConnectionInterface interface.
deadbeefab9b2d12015-10-14 11:33:11 -070063// It uses WebRtcSession to implement the PeerConnection functionality.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064class PeerConnection : public PeerConnectionInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065 public IceObserver,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000066 public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 public sigslot::has_slots<> {
68 public:
69 explicit PeerConnection(PeerConnectionFactory* factory);
70
deadbeef653b8e02015-11-11 12:55:10 -080071 bool Initialize(
72 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -070073 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020074 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef653b8e02015-11-11 12:55:10 -080075 PeerConnectionObserver* observer);
76
deadbeefa67696b2015-09-29 11:56:26 -070077 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
78 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
79 bool AddStream(MediaStreamInterface* local_stream) override;
80 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081
deadbeefe1f9d832016-01-14 15:35:42 -080082 rtc::scoped_refptr<RtpSenderInterface> AddTrack(
83 MediaStreamTrackInterface* track,
84 std::vector<MediaStreamInterface*> streams) override;
85 bool RemoveTrack(RtpSenderInterface* sender) override;
86
deadbeefab9b2d12015-10-14 11:33:11 -070087 virtual WebRtcSession* session() { return session_.get(); }
88
deadbeefa67696b2015-09-29 11:56:26 -070089 rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
90 AudioTrackInterface* track) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091
deadbeeffac06552015-11-25 11:26:01 -080092 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -080093 const std::string& kind,
94 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -080095
deadbeef70ab1a12015-09-28 16:53:55 -070096 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
97 const override;
98 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
99 const override;
100
deadbeefa67696b2015-09-29 11:56:26 -0700101 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700103 const DataChannelInit* config) override;
104 bool GetStats(StatsObserver* observer,
105 webrtc::MediaStreamTrackInterface* track,
106 StatsOutputLevel level) override;
hbos74e1a4f2016-09-15 23:33:01 -0700107 void GetStats(RTCStatsCollectorCallback* callback) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108
deadbeefa67696b2015-09-29 11:56:26 -0700109 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110
deadbeefa67696b2015-09-29 11:56:26 -0700111 IceConnectionState ice_connection_state() override;
112 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113
deadbeefa67696b2015-09-29 11:56:26 -0700114 const SessionDescriptionInterface* local_description() const override;
115 const SessionDescriptionInterface* remote_description() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
117 // JSEP01
htaa2a49d92016-03-04 02:51:39 -0800118 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700119 void CreateOffer(CreateSessionDescriptionObserver* observer,
120 const MediaConstraintsInterface* constraints) override;
121 void CreateOffer(CreateSessionDescriptionObserver* observer,
122 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800123 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700124 void CreateAnswer(CreateSessionDescriptionObserver* observer,
125 const MediaConstraintsInterface* constraints) override;
htaa2a49d92016-03-04 02:51:39 -0800126 void CreateAnswer(CreateSessionDescriptionObserver* observer,
127 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700128 void SetLocalDescription(SetSessionDescriptionObserver* observer,
129 SessionDescriptionInterface* desc) override;
130 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
131 SessionDescriptionInterface* desc) override;
deadbeef46c73892016-11-16 19:42:04 -0800132 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
deadbeefa67696b2015-09-29 11:56:26 -0700133 bool SetConfiguration(
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700134 const PeerConnectionInterface::RTCConfiguration& configuration) override;
deadbeefa67696b2015-09-29 11:56:26 -0700135 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700136 bool RemoveIceCandidates(
137 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138
deadbeefa67696b2015-09-29 11:56:26 -0700139 void RegisterUMAObserver(UMAObserver* observer) override;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000140
ivoc14d5dbe2016-07-04 07:06:55 -0700141 bool StartRtcEventLog(rtc::PlatformFile file,
142 int64_t max_size_bytes) override;
143 void StopRtcEventLog() override;
144
deadbeefa67696b2015-09-29 11:56:26 -0700145 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146
hbos82ebe022016-11-14 01:41:09 -0800147 sigslot::signal1<DataChannel*> SignalDataChannelCreated;
148
deadbeefab9b2d12015-10-14 11:33:11 -0700149 // Virtual for unit tests.
150 virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
151 sctp_data_channels() const {
152 return sctp_data_channels_;
perkjd61bf802016-03-24 03:16:19 -0700153 }
deadbeefab9b2d12015-10-14 11:33:11 -0700154
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700156 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157
158 private:
deadbeefab9b2d12015-10-14 11:33:11 -0700159 struct TrackInfo {
160 TrackInfo() : ssrc(0) {}
161 TrackInfo(const std::string& stream_label,
162 const std::string track_id,
163 uint32_t ssrc)
164 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {}
deadbeefbda7e0b2015-12-08 17:13:40 -0800165 bool operator==(const TrackInfo& other) {
166 return this->stream_label == other.stream_label &&
167 this->track_id == other.track_id && this->ssrc == other.ssrc;
168 }
deadbeefab9b2d12015-10-14 11:33:11 -0700169 std::string stream_label;
170 std::string track_id;
171 uint32_t ssrc;
172 };
173 typedef std::vector<TrackInfo> TrackInfos;
174
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 // Implements MessageHandler.
deadbeefa67696b2015-09-29 11:56:26 -0700176 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177
deadbeefab9b2d12015-10-14 11:33:11 -0700178 void CreateAudioReceiver(MediaStreamInterface* stream,
perkjd61bf802016-03-24 03:16:19 -0700179 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700180 uint32_t ssrc);
perkjf0dcfe22016-03-10 18:32:00 +0100181
deadbeefab9b2d12015-10-14 11:33:11 -0700182 void CreateVideoReceiver(MediaStreamInterface* stream,
perkjf0dcfe22016-03-10 18:32:00 +0100183 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700184 uint32_t ssrc);
perkjd61bf802016-03-24 03:16:19 -0700185 void DestroyReceiver(const std::string& track_id);
deadbeefab9b2d12015-10-14 11:33:11 -0700186 void DestroyAudioSender(MediaStreamInterface* stream,
187 AudioTrackInterface* audio_track,
188 uint32_t ssrc);
189 void DestroyVideoSender(MediaStreamInterface* stream,
190 VideoTrackInterface* video_track);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191
192 // Implements IceObserver
Peter Thatcher54360512015-07-08 11:08:35 -0700193 void OnIceConnectionChange(IceConnectionState new_state) override;
194 void OnIceGatheringChange(IceGatheringState new_state) override;
195 void OnIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700196 void OnIceCandidatesRemoved(
197 const std::vector<cricket::Candidate>& candidates) override;
Peter Thatcher54360512015-07-08 11:08:35 -0700198 void OnIceConnectionReceivingChange(bool receiving) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199
200 // Signals from WebRtcSession.
deadbeefd59daf82015-10-14 15:02:44 -0700201 void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 void ChangeSignalingState(SignalingState signaling_state);
203
deadbeefeb459812015-12-15 19:24:43 -0800204 // Signals from MediaStreamObserver.
205 void OnAudioTrackAdded(AudioTrackInterface* track,
206 MediaStreamInterface* stream);
207 void OnAudioTrackRemoved(AudioTrackInterface* track,
208 MediaStreamInterface* stream);
209 void OnVideoTrackAdded(VideoTrackInterface* track,
210 MediaStreamInterface* stream);
211 void OnVideoTrackRemoved(VideoTrackInterface* track,
212 MediaStreamInterface* stream);
213
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000214 rtc::Thread* signaling_thread() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 return factory_->signaling_thread();
216 }
217
deadbeef91dd5672016-05-18 16:55:30 -0700218 rtc::Thread* network_thread() const { return factory_->network_thread(); }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700219
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
221 const std::string& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700222 void PostCreateSessionDescriptionFailure(
223 CreateSessionDescriptionObserver* observer,
224 const std::string& error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225
226 bool IsClosed() const {
227 return signaling_state_ == PeerConnectionInterface::kClosed;
228 }
229
deadbeefab9b2d12015-10-14 11:33:11 -0700230 // Returns a MediaSessionOptions struct with options decided by |options|,
231 // the local MediaStreams and DataChannels.
232 virtual bool GetOptionsForOffer(
233 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
234 cricket::MediaSessionOptions* session_options);
235
236 // Returns a MediaSessionOptions struct with options decided by
237 // |constraints|, the local MediaStreams and DataChannels.
htaa2a49d92016-03-04 02:51:39 -0800238 // Deprecated, use version without constraints.
deadbeefab9b2d12015-10-14 11:33:11 -0700239 virtual bool GetOptionsForAnswer(
240 const MediaConstraintsInterface* constraints,
241 cricket::MediaSessionOptions* session_options);
htaa2a49d92016-03-04 02:51:39 -0800242 virtual bool GetOptionsForAnswer(
243 const RTCOfferAnswerOptions& options,
244 cricket::MediaSessionOptions* session_options);
245
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700246 void InitializeOptionsForAnswer(
247 cricket::MediaSessionOptions* session_options);
248
htaa2a49d92016-03-04 02:51:39 -0800249 // Helper function for options processing.
250 // Deprecated.
251 virtual void FinishOptionsForAnswer(
252 cricket::MediaSessionOptions* session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700253
deadbeeffaac4972015-11-12 15:33:07 -0800254 // Remove all local and remote tracks of type |media_type|.
255 // Called when a media type is rejected (m-line set to port 0).
256 void RemoveTracks(cricket::MediaType media_type);
257
deadbeefbda7e0b2015-12-08 17:13:40 -0800258 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
259 // and existing MediaStreamTracks are removed if there is no corresponding
260 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
261 // is created if it doesn't exist; if false, it's removed if it exists.
262 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700263 // If a new MediaStream is created it is added to |new_streams|.
264 void UpdateRemoteStreamsList(
265 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800266 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700267 cricket::MediaType media_type,
268 StreamCollection* new_streams);
269
270 // Triggered when a remote track has been seen for the first time in a remote
271 // session description. It creates a remote MediaStreamTrackInterface
272 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
273 void OnRemoteTrackSeen(const std::string& stream_label,
274 const std::string& track_id,
275 uint32_t ssrc,
276 cricket::MediaType media_type);
277
278 // Triggered when a remote track has been removed from a remote session
279 // description. It removes the remote track with id |track_id| from a remote
280 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
281 void OnRemoteTrackRemoved(const std::string& stream_label,
282 const std::string& track_id,
283 cricket::MediaType media_type);
284
285 // Finds remote MediaStreams without any tracks and removes them from
286 // |remote_streams_| and notifies the observer that the MediaStreams no longer
287 // exist.
288 void UpdateEndedRemoteMediaStreams();
289
deadbeefab9b2d12015-10-14 11:33:11 -0700290 // Loops through the vector of |streams| and finds added and removed
291 // StreamParams since last time this method was called.
292 // For each new or removed StreamParam, OnLocalTrackSeen or
293 // OnLocalTrackRemoved is invoked.
294 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams,
295 cricket::MediaType media_type);
296
297 // Triggered when a local track has been seen for the first time in a local
298 // session description.
299 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
300 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
301 // in a MediaStream in |local_streams_|
302 void OnLocalTrackSeen(const std::string& stream_label,
303 const std::string& track_id,
304 uint32_t ssrc,
305 cricket::MediaType media_type);
306
307 // Triggered when a local track has been removed from a local session
308 // description.
309 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
310 // has been removed from the local SessionDescription and the stream can be
311 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
312 void OnLocalTrackRemoved(const std::string& stream_label,
313 const std::string& track_id,
314 uint32_t ssrc,
315 cricket::MediaType media_type);
316
317 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
318 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
319 void UpdateClosingRtpDataChannels(
320 const std::vector<std::string>& active_channels,
321 bool is_local_update);
322 void CreateRemoteRtpDataChannel(const std::string& label,
323 uint32_t remote_ssrc);
324
325 // Creates channel and adds it to the collection of DataChannels that will
326 // be offered in a SessionDescription.
327 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
328 const std::string& label,
329 const InternalDataChannelInit* config);
330
331 // Checks if any data channel has been added.
332 bool HasDataChannels() const;
333
334 void AllocateSctpSids(rtc::SSLRole role);
335 void OnSctpDataChannelClosed(DataChannel* channel);
336
337 // Notifications from WebRtcSession relating to BaseChannels.
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700338 void OnVoiceChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700339 void OnVoiceChannelDestroyed();
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700340 void OnVideoChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700341 void OnVideoChannelDestroyed();
342 void OnDataChannelCreated();
343 void OnDataChannelDestroyed();
344 // Called when the cricket::DataChannel receives a message indicating that a
345 // webrtc::DataChannel should be opened.
346 void OnDataChannelOpenMessage(const std::string& label,
347 const InternalDataChannelInit& config);
348
deadbeefa601f5c2016-06-06 14:27:39 -0700349 RtpSenderInternal* FindSenderById(const std::string& id);
deadbeeffac06552015-11-25 11:26:01 -0800350
deadbeefa601f5c2016-06-06 14:27:39 -0700351 std::vector<rtc::scoped_refptr<
352 RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator
deadbeef70ab1a12015-09-28 16:53:55 -0700353 FindSenderForTrack(MediaStreamTrackInterface* track);
deadbeefa601f5c2016-06-06 14:27:39 -0700354 std::vector<rtc::scoped_refptr<
355 RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator
perkjd61bf802016-03-24 03:16:19 -0700356 FindReceiverForTrack(const std::string& track_id);
deadbeef70ab1a12015-09-28 16:53:55 -0700357
deadbeefab9b2d12015-10-14 11:33:11 -0700358 TrackInfos* GetRemoteTracks(cricket::MediaType media_type);
359 TrackInfos* GetLocalTracks(cricket::MediaType media_type);
360 const TrackInfo* FindTrackInfo(const TrackInfos& infos,
361 const std::string& stream_label,
362 const std::string track_id) const;
363
364 // Returns the specified SCTP DataChannel in sctp_data_channels_,
365 // or nullptr if not found.
366 DataChannel* FindDataChannelBySid(int sid) const;
367
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700368 // Called when first configuring the port allocator.
deadbeef91dd5672016-05-18 16:55:30 -0700369 bool InitializePortAllocator_n(const RTCConfiguration& configuration);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700370 // Called when SetConfiguration is called. Only a subset of the configuration
371 // is applied.
deadbeef91dd5672016-05-18 16:55:30 -0700372 bool ReconfigurePortAllocator_n(const RTCConfiguration& configuration);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700373
ivoc14d5dbe2016-07-04 07:06:55 -0700374 // Starts recording an Rtc EventLog using the supplied platform file.
375 // This function should only be called from the worker thread.
376 bool StartRtcEventLog_w(rtc::PlatformFile file, int64_t max_size_bytes);
377 // Starts recording an Rtc EventLog using the supplied platform file.
378 // This function should only be called from the worker thread.
379 void StopRtcEventLog_w();
380
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 // Storing the factory as a scoped reference pointer ensures that the memory
382 // in the PeerConnectionFactoryImpl remains available as long as the
383 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
384 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -0700385 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 // will refer to the same reference count.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000387 rtc::scoped_refptr<PeerConnectionFactory> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 PeerConnectionObserver* observer_;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000389 UMAObserver* uma_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 SignalingState signaling_state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 IceConnectionState ice_connection_state_;
392 IceGatheringState ice_gathering_state_;
deadbeef46c73892016-11-16 19:42:04 -0800393 PeerConnectionInterface::RTCConfiguration configuration_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394
kwibergd1fe2812016-04-27 06:47:29 -0700395 std::unique_ptr<cricket::PortAllocator> port_allocator_;
skvlad11a9cbf2016-10-07 11:53:05 -0700396 // The EventLog needs to outlive the media controller.
397 std::unique_ptr<RtcEventLog> event_log_;
kwibergd1fe2812016-04-27 06:47:29 -0700398 std::unique_ptr<MediaControllerInterface> media_controller_;
deadbeefab9b2d12015-10-14 11:33:11 -0700399
zhihuang8f65cdf2016-05-06 18:40:30 -0700400 // One PeerConnection has only one RTCP CNAME.
401 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
402 std::string rtcp_cname_;
403
deadbeefab9b2d12015-10-14 11:33:11 -0700404 // Streams added via AddStream.
405 rtc::scoped_refptr<StreamCollection> local_streams_;
406 // Streams created as a result of SetRemoteDescription.
407 rtc::scoped_refptr<StreamCollection> remote_streams_;
408
kwibergd1fe2812016-04-27 06:47:29 -0700409 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
deadbeefeb459812015-12-15 19:24:43 -0800410
deadbeefab9b2d12015-10-14 11:33:11 -0700411 // These lists store track info seen in local/remote descriptions.
412 TrackInfos remote_audio_tracks_;
413 TrackInfos remote_video_tracks_;
414 TrackInfos local_audio_tracks_;
415 TrackInfos local_video_tracks_;
416
417 SctpSidAllocator sid_allocator_;
418 // label -> DataChannel
419 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
420 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
deadbeefbd292462015-12-14 18:15:29 -0800421 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
deadbeefab9b2d12015-10-14 11:33:11 -0700422
deadbeefbda7e0b2015-12-08 17:13:40 -0800423 bool remote_peer_supports_msid_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700424
deadbeefa601f5c2016-06-06 14:27:39 -0700425 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
426 senders_;
427 std::vector<
428 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
429 receivers_;
kwibergd1fe2812016-04-27 06:47:29 -0700430 std::unique_ptr<WebRtcSession> session_;
kwibergd1fe2812016-04-27 06:47:29 -0700431 std::unique_ptr<StatsCollector> stats_;
hbos74e1a4f2016-09-15 23:33:01 -0700432 rtc::scoped_refptr<RTCStatsCollector> stats_collector_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433};
434
435} // namespace webrtc
436
Henrik Kjellander15583c12016-02-10 10:53:12 +0100437#endif // WEBRTC_API_PEERCONNECTION_H_