blob: c4a9a60053db82ca9976340412334e70bae55a59 [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"
deadbeefa601f5c2016-06-06 14:27:39 -070021#include "webrtc/api/rtpreceiver.h"
22#include "webrtc/api/rtpsender.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010023#include "webrtc/api/statscollector.h"
24#include "webrtc/api/streamcollection.h"
25#include "webrtc/api/webrtcsession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026
27namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
deadbeefeb459812015-12-15 19:24:43 -080029class MediaStreamObserver;
perkjf0dcfe22016-03-10 18:32:00 +010030class VideoRtpReceiver;
deadbeefab9b2d12015-10-14 11:33:11 -070031
deadbeefab9b2d12015-10-14 11:33:11 -070032// Populates |session_options| from |rtc_options|, and returns true if options
33// are valid.
deadbeef0ed85b22016-02-23 17:24:52 -080034// |session_options|->transport_options map entries must exist in order for
35// them to be populated from |rtc_options|.
htaa2a49d92016-03-04 02:51:39 -080036bool ExtractMediaSessionOptions(
deadbeefab9b2d12015-10-14 11:33:11 -070037 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
htaaac2dea2016-03-10 13:35:55 -080038 bool is_offer,
deadbeefab9b2d12015-10-14 11:33:11 -070039 cricket::MediaSessionOptions* session_options);
40
41// Populates |session_options| from |constraints|, and returns true if all
42// mandatory constraints are satisfied.
deadbeef0ed85b22016-02-23 17:24:52 -080043// Assumes that |session_options|->transport_options map entries exist.
htaa2a49d92016-03-04 02:51:39 -080044// Will also set defaults if corresponding constraints are not present:
45// recv_audio=true, recv_video=true, bundle_enabled=true.
46// Other fields will be left with existing values.
47//
48// Deprecated. Will be removed once callers that use constraints are gone.
49// TODO(hta): Remove when callers are gone.
50// https://bugs.chromium.org/p/webrtc/issues/detail?id=5617
deadbeefab9b2d12015-10-14 11:33:11 -070051bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints,
52 cricket::MediaSessionOptions* session_options);
53
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080054// Parses the URLs for each server in |servers| to build |stun_servers| and
55// |turn_servers|.
deadbeef0a6c4ca2015-10-06 11:38:28 -070056bool ParseIceServers(const PeerConnectionInterface::IceServers& servers,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080057 cricket::ServerAddresses* stun_servers,
58 std::vector<cricket::RelayServerConfig>* turn_servers);
deadbeef0a6c4ca2015-10-06 11:38:28 -070059
deadbeef70ab1a12015-09-28 16:53:55 -070060// PeerConnection implements the PeerConnectionInterface interface.
deadbeefab9b2d12015-10-14 11:33:11 -070061// It uses WebRtcSession to implement the PeerConnection functionality.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062class PeerConnection : public PeerConnectionInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063 public IceObserver,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000064 public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065 public sigslot::has_slots<> {
66 public:
67 explicit PeerConnection(PeerConnectionFactory* factory);
68
deadbeef653b8e02015-11-11 12:55:10 -080069 bool Initialize(
70 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -070071 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020072 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef653b8e02015-11-11 12:55:10 -080073 PeerConnectionObserver* observer);
74
deadbeefa67696b2015-09-29 11:56:26 -070075 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
76 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
77 bool AddStream(MediaStreamInterface* local_stream) override;
78 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079
deadbeefe1f9d832016-01-14 15:35:42 -080080 rtc::scoped_refptr<RtpSenderInterface> AddTrack(
81 MediaStreamTrackInterface* track,
82 std::vector<MediaStreamInterface*> streams) override;
83 bool RemoveTrack(RtpSenderInterface* sender) override;
84
deadbeefab9b2d12015-10-14 11:33:11 -070085 virtual WebRtcSession* session() { return session_.get(); }
86
deadbeefa67696b2015-09-29 11:56:26 -070087 rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
88 AudioTrackInterface* track) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
deadbeeffac06552015-11-25 11:26:01 -080090 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -080091 const std::string& kind,
92 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -080093
deadbeef70ab1a12015-09-28 16:53:55 -070094 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
95 const override;
96 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
97 const override;
98
deadbeefa67696b2015-09-29 11:56:26 -070099 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700101 const DataChannelInit* config) override;
102 bool GetStats(StatsObserver* observer,
103 webrtc::MediaStreamTrackInterface* track,
104 StatsOutputLevel level) 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
108 // TODO(bemasc): Remove ice_state() when callers are removed.
deadbeefa67696b2015-09-29 11:56:26 -0700109 IceState ice_state() override;
110 IceConnectionState ice_connection_state() override;
111 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112
deadbeefa67696b2015-09-29 11:56:26 -0700113 const SessionDescriptionInterface* local_description() const override;
114 const SessionDescriptionInterface* remote_description() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115
116 // JSEP01
htaa2a49d92016-03-04 02:51:39 -0800117 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700118 void CreateOffer(CreateSessionDescriptionObserver* observer,
119 const MediaConstraintsInterface* constraints) override;
120 void CreateOffer(CreateSessionDescriptionObserver* observer,
121 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800122 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700123 void CreateAnswer(CreateSessionDescriptionObserver* observer,
124 const MediaConstraintsInterface* constraints) override;
htaa2a49d92016-03-04 02:51:39 -0800125 void CreateAnswer(CreateSessionDescriptionObserver* observer,
126 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700127 void SetLocalDescription(SetSessionDescriptionObserver* observer,
128 SessionDescriptionInterface* desc) override;
129 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
130 SessionDescriptionInterface* desc) override;
131 bool SetConfiguration(
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700132 const PeerConnectionInterface::RTCConfiguration& configuration) override;
deadbeefa67696b2015-09-29 11:56:26 -0700133 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700134 bool RemoveIceCandidates(
135 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136
deadbeefa67696b2015-09-29 11:56:26 -0700137 void RegisterUMAObserver(UMAObserver* observer) override;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000138
ivoc14d5dbe2016-07-04 07:06:55 -0700139 bool StartRtcEventLog(rtc::PlatformFile file,
140 int64_t max_size_bytes) override;
141 void StopRtcEventLog() override;
142
deadbeefa67696b2015-09-29 11:56:26 -0700143 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144
deadbeefab9b2d12015-10-14 11:33:11 -0700145 // Virtual for unit tests.
146 virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
147 sctp_data_channels() const {
148 return sctp_data_channels_;
perkjd61bf802016-03-24 03:16:19 -0700149 }
deadbeefab9b2d12015-10-14 11:33:11 -0700150
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700152 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153
154 private:
deadbeefab9b2d12015-10-14 11:33:11 -0700155 struct TrackInfo {
156 TrackInfo() : ssrc(0) {}
157 TrackInfo(const std::string& stream_label,
158 const std::string track_id,
159 uint32_t ssrc)
160 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {}
deadbeefbda7e0b2015-12-08 17:13:40 -0800161 bool operator==(const TrackInfo& other) {
162 return this->stream_label == other.stream_label &&
163 this->track_id == other.track_id && this->ssrc == other.ssrc;
164 }
deadbeefab9b2d12015-10-14 11:33:11 -0700165 std::string stream_label;
166 std::string track_id;
167 uint32_t ssrc;
168 };
169 typedef std::vector<TrackInfo> TrackInfos;
170
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 // Implements MessageHandler.
deadbeefa67696b2015-09-29 11:56:26 -0700172 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173
deadbeefab9b2d12015-10-14 11:33:11 -0700174 void CreateAudioReceiver(MediaStreamInterface* stream,
perkjd61bf802016-03-24 03:16:19 -0700175 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700176 uint32_t ssrc);
perkjf0dcfe22016-03-10 18:32:00 +0100177
deadbeefab9b2d12015-10-14 11:33:11 -0700178 void CreateVideoReceiver(MediaStreamInterface* stream,
perkjf0dcfe22016-03-10 18:32:00 +0100179 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700180 uint32_t ssrc);
perkjd61bf802016-03-24 03:16:19 -0700181 void DestroyReceiver(const std::string& track_id);
deadbeefab9b2d12015-10-14 11:33:11 -0700182 void DestroyAudioSender(MediaStreamInterface* stream,
183 AudioTrackInterface* audio_track,
184 uint32_t ssrc);
185 void DestroyVideoSender(MediaStreamInterface* stream,
186 VideoTrackInterface* video_track);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187
188 // Implements IceObserver
Peter Thatcher54360512015-07-08 11:08:35 -0700189 void OnIceConnectionChange(IceConnectionState new_state) override;
190 void OnIceGatheringChange(IceGatheringState new_state) override;
191 void OnIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700192 void OnIceCandidatesRemoved(
193 const std::vector<cricket::Candidate>& candidates) override;
Peter Thatcher54360512015-07-08 11:08:35 -0700194 void OnIceConnectionReceivingChange(bool receiving) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195
196 // Signals from WebRtcSession.
deadbeefd59daf82015-10-14 15:02:44 -0700197 void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 void ChangeSignalingState(SignalingState signaling_state);
199
deadbeefeb459812015-12-15 19:24:43 -0800200 // Signals from MediaStreamObserver.
201 void OnAudioTrackAdded(AudioTrackInterface* track,
202 MediaStreamInterface* stream);
203 void OnAudioTrackRemoved(AudioTrackInterface* track,
204 MediaStreamInterface* stream);
205 void OnVideoTrackAdded(VideoTrackInterface* track,
206 MediaStreamInterface* stream);
207 void OnVideoTrackRemoved(VideoTrackInterface* track,
208 MediaStreamInterface* stream);
209
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000210 rtc::Thread* signaling_thread() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 return factory_->signaling_thread();
212 }
213
deadbeef91dd5672016-05-18 16:55:30 -0700214 rtc::Thread* network_thread() const { return factory_->network_thread(); }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700215
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
217 const std::string& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700218 void PostCreateSessionDescriptionFailure(
219 CreateSessionDescriptionObserver* observer,
220 const std::string& error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221
222 bool IsClosed() const {
223 return signaling_state_ == PeerConnectionInterface::kClosed;
224 }
225
deadbeefab9b2d12015-10-14 11:33:11 -0700226 // Returns a MediaSessionOptions struct with options decided by |options|,
227 // the local MediaStreams and DataChannels.
228 virtual bool GetOptionsForOffer(
229 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
230 cricket::MediaSessionOptions* session_options);
231
232 // Returns a MediaSessionOptions struct with options decided by
233 // |constraints|, the local MediaStreams and DataChannels.
htaa2a49d92016-03-04 02:51:39 -0800234 // Deprecated, use version without constraints.
deadbeefab9b2d12015-10-14 11:33:11 -0700235 virtual bool GetOptionsForAnswer(
236 const MediaConstraintsInterface* constraints,
237 cricket::MediaSessionOptions* session_options);
htaa2a49d92016-03-04 02:51:39 -0800238 virtual bool GetOptionsForAnswer(
239 const RTCOfferAnswerOptions& options,
240 cricket::MediaSessionOptions* session_options);
241
242 // Helper function for options processing.
243 // Deprecated.
244 virtual void FinishOptionsForAnswer(
245 cricket::MediaSessionOptions* session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700246
deadbeeffaac4972015-11-12 15:33:07 -0800247 // Remove all local and remote tracks of type |media_type|.
248 // Called when a media type is rejected (m-line set to port 0).
249 void RemoveTracks(cricket::MediaType media_type);
250
deadbeefbda7e0b2015-12-08 17:13:40 -0800251 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
252 // and existing MediaStreamTracks are removed if there is no corresponding
253 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
254 // is created if it doesn't exist; if false, it's removed if it exists.
255 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700256 // If a new MediaStream is created it is added to |new_streams|.
257 void UpdateRemoteStreamsList(
258 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800259 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700260 cricket::MediaType media_type,
261 StreamCollection* new_streams);
262
263 // Triggered when a remote track has been seen for the first time in a remote
264 // session description. It creates a remote MediaStreamTrackInterface
265 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
266 void OnRemoteTrackSeen(const std::string& stream_label,
267 const std::string& track_id,
268 uint32_t ssrc,
269 cricket::MediaType media_type);
270
271 // Triggered when a remote track has been removed from a remote session
272 // description. It removes the remote track with id |track_id| from a remote
273 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
274 void OnRemoteTrackRemoved(const std::string& stream_label,
275 const std::string& track_id,
276 cricket::MediaType media_type);
277
278 // Finds remote MediaStreams without any tracks and removes them from
279 // |remote_streams_| and notifies the observer that the MediaStreams no longer
280 // exist.
281 void UpdateEndedRemoteMediaStreams();
282
deadbeefab9b2d12015-10-14 11:33:11 -0700283 // Loops through the vector of |streams| and finds added and removed
284 // StreamParams since last time this method was called.
285 // For each new or removed StreamParam, OnLocalTrackSeen or
286 // OnLocalTrackRemoved is invoked.
287 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams,
288 cricket::MediaType media_type);
289
290 // Triggered when a local track has been seen for the first time in a local
291 // session description.
292 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
293 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
294 // in a MediaStream in |local_streams_|
295 void OnLocalTrackSeen(const std::string& stream_label,
296 const std::string& track_id,
297 uint32_t ssrc,
298 cricket::MediaType media_type);
299
300 // Triggered when a local track has been removed from a local session
301 // description.
302 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
303 // has been removed from the local SessionDescription and the stream can be
304 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
305 void OnLocalTrackRemoved(const std::string& stream_label,
306 const std::string& track_id,
307 uint32_t ssrc,
308 cricket::MediaType media_type);
309
310 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
311 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
312 void UpdateClosingRtpDataChannels(
313 const std::vector<std::string>& active_channels,
314 bool is_local_update);
315 void CreateRemoteRtpDataChannel(const std::string& label,
316 uint32_t remote_ssrc);
317
318 // Creates channel and adds it to the collection of DataChannels that will
319 // be offered in a SessionDescription.
320 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
321 const std::string& label,
322 const InternalDataChannelInit* config);
323
324 // Checks if any data channel has been added.
325 bool HasDataChannels() const;
326
327 void AllocateSctpSids(rtc::SSLRole role);
328 void OnSctpDataChannelClosed(DataChannel* channel);
329
330 // Notifications from WebRtcSession relating to BaseChannels.
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700331 void OnVoiceChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700332 void OnVoiceChannelDestroyed();
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700333 void OnVideoChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700334 void OnVideoChannelDestroyed();
335 void OnDataChannelCreated();
336 void OnDataChannelDestroyed();
337 // Called when the cricket::DataChannel receives a message indicating that a
338 // webrtc::DataChannel should be opened.
339 void OnDataChannelOpenMessage(const std::string& label,
340 const InternalDataChannelInit& config);
341
deadbeefa601f5c2016-06-06 14:27:39 -0700342 RtpSenderInternal* FindSenderById(const std::string& id);
deadbeeffac06552015-11-25 11:26:01 -0800343
deadbeefa601f5c2016-06-06 14:27:39 -0700344 std::vector<rtc::scoped_refptr<
345 RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator
deadbeef70ab1a12015-09-28 16:53:55 -0700346 FindSenderForTrack(MediaStreamTrackInterface* track);
deadbeefa601f5c2016-06-06 14:27:39 -0700347 std::vector<rtc::scoped_refptr<
348 RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator
perkjd61bf802016-03-24 03:16:19 -0700349 FindReceiverForTrack(const std::string& track_id);
deadbeef70ab1a12015-09-28 16:53:55 -0700350
deadbeefab9b2d12015-10-14 11:33:11 -0700351 TrackInfos* GetRemoteTracks(cricket::MediaType media_type);
352 TrackInfos* GetLocalTracks(cricket::MediaType media_type);
353 const TrackInfo* FindTrackInfo(const TrackInfos& infos,
354 const std::string& stream_label,
355 const std::string track_id) const;
356
357 // Returns the specified SCTP DataChannel in sctp_data_channels_,
358 // or nullptr if not found.
359 DataChannel* FindDataChannelBySid(int sid) const;
360
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700361 // Called when first configuring the port allocator.
deadbeef91dd5672016-05-18 16:55:30 -0700362 bool InitializePortAllocator_n(const RTCConfiguration& configuration);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700363 // Called when SetConfiguration is called. Only a subset of the configuration
364 // is applied.
deadbeef91dd5672016-05-18 16:55:30 -0700365 bool ReconfigurePortAllocator_n(const RTCConfiguration& configuration);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700366
ivoc14d5dbe2016-07-04 07:06:55 -0700367 // Starts recording an Rtc EventLog using the supplied platform file.
368 // This function should only be called from the worker thread.
369 bool StartRtcEventLog_w(rtc::PlatformFile file, int64_t max_size_bytes);
370 // Starts recording an Rtc EventLog using the supplied platform file.
371 // This function should only be called from the worker thread.
372 void StopRtcEventLog_w();
373
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 // Storing the factory as a scoped reference pointer ensures that the memory
375 // in the PeerConnectionFactoryImpl remains available as long as the
376 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
377 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -0700378 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 // will refer to the same reference count.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000380 rtc::scoped_refptr<PeerConnectionFactory> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 PeerConnectionObserver* observer_;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000382 UMAObserver* uma_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 SignalingState signaling_state_;
384 // TODO(bemasc): Remove ice_state_.
385 IceState ice_state_;
386 IceConnectionState ice_connection_state_;
387 IceGatheringState ice_gathering_state_;
388
kwibergd1fe2812016-04-27 06:47:29 -0700389 std::unique_ptr<cricket::PortAllocator> port_allocator_;
390 std::unique_ptr<MediaControllerInterface> media_controller_;
deadbeefab9b2d12015-10-14 11:33:11 -0700391
zhihuang8f65cdf2016-05-06 18:40:30 -0700392 // One PeerConnection has only one RTCP CNAME.
393 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
394 std::string rtcp_cname_;
395
deadbeefab9b2d12015-10-14 11:33:11 -0700396 // Streams added via AddStream.
397 rtc::scoped_refptr<StreamCollection> local_streams_;
398 // Streams created as a result of SetRemoteDescription.
399 rtc::scoped_refptr<StreamCollection> remote_streams_;
400
kwibergd1fe2812016-04-27 06:47:29 -0700401 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
deadbeefeb459812015-12-15 19:24:43 -0800402
deadbeefab9b2d12015-10-14 11:33:11 -0700403 // These lists store track info seen in local/remote descriptions.
404 TrackInfos remote_audio_tracks_;
405 TrackInfos remote_video_tracks_;
406 TrackInfos local_audio_tracks_;
407 TrackInfos local_video_tracks_;
408
409 SctpSidAllocator sid_allocator_;
410 // label -> DataChannel
411 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
412 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
deadbeefbd292462015-12-14 18:15:29 -0800413 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
deadbeefab9b2d12015-10-14 11:33:11 -0700414
deadbeefbda7e0b2015-12-08 17:13:40 -0800415 bool remote_peer_supports_msid_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700416
deadbeefa601f5c2016-06-06 14:27:39 -0700417 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
418 senders_;
419 std::vector<
420 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
421 receivers_;
deadbeefab9b2d12015-10-14 11:33:11 -0700422
kwibergd1fe2812016-04-27 06:47:29 -0700423 std::unique_ptr<WebRtcSession> session_;
kwibergd1fe2812016-04-27 06:47:29 -0700424 std::unique_ptr<StatsCollector> stats_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425};
426
427} // namespace webrtc
428
Henrik Kjellander15583c12016-02-10 10:53:12 +0100429#endif // WEBRTC_API_PEERCONNECTION_H_