blob: 3087160e4329aad293f4ce272d7b5b426f5b17ff [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;
deadbeefab9b2d12015-10-14 11:33:11 -070032
deadbeefab9b2d12015-10-14 11:33:11 -070033// Populates |session_options| from |rtc_options|, and returns true if options
34// are valid.
deadbeef0ed85b22016-02-23 17:24:52 -080035// |session_options|->transport_options map entries must exist in order for
36// them to be populated from |rtc_options|.
htaa2a49d92016-03-04 02:51:39 -080037bool ExtractMediaSessionOptions(
deadbeefab9b2d12015-10-14 11:33:11 -070038 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
htaaac2dea2016-03-10 13:35:55 -080039 bool is_offer,
deadbeefab9b2d12015-10-14 11:33:11 -070040 cricket::MediaSessionOptions* session_options);
41
42// Populates |session_options| from |constraints|, and returns true if all
43// mandatory constraints are satisfied.
deadbeef0ed85b22016-02-23 17:24:52 -080044// Assumes that |session_options|->transport_options map entries exist.
htaa2a49d92016-03-04 02:51:39 -080045// Will also set defaults if corresponding constraints are not present:
46// recv_audio=true, recv_video=true, bundle_enabled=true.
47// Other fields will be left with existing values.
48//
49// Deprecated. Will be removed once callers that use constraints are gone.
50// TODO(hta): Remove when callers are gone.
51// https://bugs.chromium.org/p/webrtc/issues/detail?id=5617
deadbeefab9b2d12015-10-14 11:33:11 -070052bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints,
53 cricket::MediaSessionOptions* session_options);
54
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080055// Parses the URLs for each server in |servers| to build |stun_servers| and
56// |turn_servers|.
deadbeef0a6c4ca2015-10-06 11:38:28 -070057bool ParseIceServers(const PeerConnectionInterface::IceServers& servers,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080058 cricket::ServerAddresses* stun_servers,
59 std::vector<cricket::RelayServerConfig>* turn_servers);
deadbeef0a6c4ca2015-10-06 11:38:28 -070060
deadbeef70ab1a12015-09-28 16:53:55 -070061// PeerConnection implements the PeerConnectionInterface interface.
deadbeefab9b2d12015-10-14 11:33:11 -070062// It uses WebRtcSession to implement the PeerConnection functionality.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063class PeerConnection : public PeerConnectionInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064 public IceObserver,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000065 public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 public sigslot::has_slots<> {
67 public:
68 explicit PeerConnection(PeerConnectionFactory* factory);
69
deadbeef653b8e02015-11-11 12:55:10 -080070 bool Initialize(
71 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -070072 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020073 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef653b8e02015-11-11 12:55:10 -080074 PeerConnectionObserver* observer);
75
deadbeefa67696b2015-09-29 11:56:26 -070076 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
77 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
78 bool AddStream(MediaStreamInterface* local_stream) override;
79 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080
deadbeefe1f9d832016-01-14 15:35:42 -080081 rtc::scoped_refptr<RtpSenderInterface> AddTrack(
82 MediaStreamTrackInterface* track,
83 std::vector<MediaStreamInterface*> streams) override;
84 bool RemoveTrack(RtpSenderInterface* sender) override;
85
deadbeefab9b2d12015-10-14 11:33:11 -070086 virtual WebRtcSession* session() { return session_.get(); }
87
deadbeefa67696b2015-09-29 11:56:26 -070088 rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
89 AudioTrackInterface* track) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
deadbeeffac06552015-11-25 11:26:01 -080091 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -080092 const std::string& kind,
93 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -080094
deadbeef70ab1a12015-09-28 16:53:55 -070095 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
96 const override;
97 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
98 const override;
99
deadbeefa67696b2015-09-29 11:56:26 -0700100 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -0700102 const DataChannelInit* config) override;
103 bool GetStats(StatsObserver* observer,
104 webrtc::MediaStreamTrackInterface* track,
105 StatsOutputLevel level) override;
hbos74e1a4f2016-09-15 23:33:01 -0700106 void GetStats(RTCStatsCollectorCallback* callback) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
deadbeefa67696b2015-09-29 11:56:26 -0700108 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
perkj68343a82016-08-29 23:51:13 -0700110 // TODO(bemasc): Remove ice_state() when callers are removed.
111 IceState ice_state() override;
deadbeefa67696b2015-09-29 11:56:26 -0700112 IceConnectionState ice_connection_state() override;
113 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114
deadbeefa67696b2015-09-29 11:56:26 -0700115 const SessionDescriptionInterface* local_description() const override;
116 const SessionDescriptionInterface* remote_description() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117
118 // JSEP01
htaa2a49d92016-03-04 02:51:39 -0800119 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700120 void CreateOffer(CreateSessionDescriptionObserver* observer,
121 const MediaConstraintsInterface* constraints) override;
122 void CreateOffer(CreateSessionDescriptionObserver* observer,
123 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800124 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700125 void CreateAnswer(CreateSessionDescriptionObserver* observer,
126 const MediaConstraintsInterface* constraints) override;
htaa2a49d92016-03-04 02:51:39 -0800127 void CreateAnswer(CreateSessionDescriptionObserver* observer,
128 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700129 void SetLocalDescription(SetSessionDescriptionObserver* observer,
130 SessionDescriptionInterface* desc) override;
131 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
132 SessionDescriptionInterface* desc) override;
133 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
deadbeefab9b2d12015-10-14 11:33:11 -0700147 // Virtual for unit tests.
148 virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
149 sctp_data_channels() const {
150 return sctp_data_channels_;
perkjd61bf802016-03-24 03:16:19 -0700151 }
deadbeefab9b2d12015-10-14 11:33:11 -0700152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700154 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155
156 private:
deadbeefab9b2d12015-10-14 11:33:11 -0700157 struct TrackInfo {
158 TrackInfo() : ssrc(0) {}
159 TrackInfo(const std::string& stream_label,
160 const std::string track_id,
161 uint32_t ssrc)
162 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {}
deadbeefbda7e0b2015-12-08 17:13:40 -0800163 bool operator==(const TrackInfo& other) {
164 return this->stream_label == other.stream_label &&
165 this->track_id == other.track_id && this->ssrc == other.ssrc;
166 }
deadbeefab9b2d12015-10-14 11:33:11 -0700167 std::string stream_label;
168 std::string track_id;
169 uint32_t ssrc;
170 };
171 typedef std::vector<TrackInfo> TrackInfos;
172
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 // Implements MessageHandler.
deadbeefa67696b2015-09-29 11:56:26 -0700174 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175
deadbeefab9b2d12015-10-14 11:33:11 -0700176 void CreateAudioReceiver(MediaStreamInterface* stream,
perkjd61bf802016-03-24 03:16:19 -0700177 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700178 uint32_t ssrc);
perkjf0dcfe22016-03-10 18:32:00 +0100179
deadbeefab9b2d12015-10-14 11:33:11 -0700180 void CreateVideoReceiver(MediaStreamInterface* stream,
perkjf0dcfe22016-03-10 18:32:00 +0100181 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700182 uint32_t ssrc);
perkjd61bf802016-03-24 03:16:19 -0700183 void DestroyReceiver(const std::string& track_id);
deadbeefab9b2d12015-10-14 11:33:11 -0700184 void DestroyAudioSender(MediaStreamInterface* stream,
185 AudioTrackInterface* audio_track,
186 uint32_t ssrc);
187 void DestroyVideoSender(MediaStreamInterface* stream,
188 VideoTrackInterface* video_track);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189
190 // Implements IceObserver
Peter Thatcher54360512015-07-08 11:08:35 -0700191 void OnIceConnectionChange(IceConnectionState new_state) override;
192 void OnIceGatheringChange(IceGatheringState new_state) override;
193 void OnIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700194 void OnIceCandidatesRemoved(
195 const std::vector<cricket::Candidate>& candidates) override;
Peter Thatcher54360512015-07-08 11:08:35 -0700196 void OnIceConnectionReceivingChange(bool receiving) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197
198 // Signals from WebRtcSession.
deadbeefd59daf82015-10-14 15:02:44 -0700199 void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 void ChangeSignalingState(SignalingState signaling_state);
201
deadbeefeb459812015-12-15 19:24:43 -0800202 // Signals from MediaStreamObserver.
203 void OnAudioTrackAdded(AudioTrackInterface* track,
204 MediaStreamInterface* stream);
205 void OnAudioTrackRemoved(AudioTrackInterface* track,
206 MediaStreamInterface* stream);
207 void OnVideoTrackAdded(VideoTrackInterface* track,
208 MediaStreamInterface* stream);
209 void OnVideoTrackRemoved(VideoTrackInterface* track,
210 MediaStreamInterface* stream);
211
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000212 rtc::Thread* signaling_thread() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 return factory_->signaling_thread();
214 }
215
deadbeef91dd5672016-05-18 16:55:30 -0700216 rtc::Thread* network_thread() const { return factory_->network_thread(); }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700217
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
219 const std::string& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700220 void PostCreateSessionDescriptionFailure(
221 CreateSessionDescriptionObserver* observer,
222 const std::string& error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223
224 bool IsClosed() const {
225 return signaling_state_ == PeerConnectionInterface::kClosed;
226 }
227
deadbeefab9b2d12015-10-14 11:33:11 -0700228 // Returns a MediaSessionOptions struct with options decided by |options|,
229 // the local MediaStreams and DataChannels.
230 virtual bool GetOptionsForOffer(
231 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
232 cricket::MediaSessionOptions* session_options);
233
234 // Returns a MediaSessionOptions struct with options decided by
235 // |constraints|, the local MediaStreams and DataChannels.
htaa2a49d92016-03-04 02:51:39 -0800236 // Deprecated, use version without constraints.
deadbeefab9b2d12015-10-14 11:33:11 -0700237 virtual bool GetOptionsForAnswer(
238 const MediaConstraintsInterface* constraints,
239 cricket::MediaSessionOptions* session_options);
htaa2a49d92016-03-04 02:51:39 -0800240 virtual bool GetOptionsForAnswer(
241 const RTCOfferAnswerOptions& options,
242 cricket::MediaSessionOptions* session_options);
243
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700244 void InitializeOptionsForAnswer(
245 cricket::MediaSessionOptions* session_options);
246
htaa2a49d92016-03-04 02:51:39 -0800247 // Helper function for options processing.
248 // Deprecated.
249 virtual void FinishOptionsForAnswer(
250 cricket::MediaSessionOptions* session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700251
deadbeeffaac4972015-11-12 15:33:07 -0800252 // Remove all local and remote tracks of type |media_type|.
253 // Called when a media type is rejected (m-line set to port 0).
254 void RemoveTracks(cricket::MediaType media_type);
255
deadbeefbda7e0b2015-12-08 17:13:40 -0800256 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
257 // and existing MediaStreamTracks are removed if there is no corresponding
258 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
259 // is created if it doesn't exist; if false, it's removed if it exists.
260 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700261 // If a new MediaStream is created it is added to |new_streams|.
262 void UpdateRemoteStreamsList(
263 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800264 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700265 cricket::MediaType media_type,
266 StreamCollection* new_streams);
267
268 // Triggered when a remote track has been seen for the first time in a remote
269 // session description. It creates a remote MediaStreamTrackInterface
270 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
271 void OnRemoteTrackSeen(const std::string& stream_label,
272 const std::string& track_id,
273 uint32_t ssrc,
274 cricket::MediaType media_type);
275
276 // Triggered when a remote track has been removed from a remote session
277 // description. It removes the remote track with id |track_id| from a remote
278 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
279 void OnRemoteTrackRemoved(const std::string& stream_label,
280 const std::string& track_id,
281 cricket::MediaType media_type);
282
283 // Finds remote MediaStreams without any tracks and removes them from
284 // |remote_streams_| and notifies the observer that the MediaStreams no longer
285 // exist.
286 void UpdateEndedRemoteMediaStreams();
287
deadbeefab9b2d12015-10-14 11:33:11 -0700288 // Loops through the vector of |streams| and finds added and removed
289 // StreamParams since last time this method was called.
290 // For each new or removed StreamParam, OnLocalTrackSeen or
291 // OnLocalTrackRemoved is invoked.
292 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams,
293 cricket::MediaType media_type);
294
295 // Triggered when a local track has been seen for the first time in a local
296 // session description.
297 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
298 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
299 // in a MediaStream in |local_streams_|
300 void OnLocalTrackSeen(const std::string& stream_label,
301 const std::string& track_id,
302 uint32_t ssrc,
303 cricket::MediaType media_type);
304
305 // Triggered when a local track has been removed from a local session
306 // description.
307 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
308 // has been removed from the local SessionDescription and the stream can be
309 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
310 void OnLocalTrackRemoved(const std::string& stream_label,
311 const std::string& track_id,
312 uint32_t ssrc,
313 cricket::MediaType media_type);
314
315 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
316 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
317 void UpdateClosingRtpDataChannels(
318 const std::vector<std::string>& active_channels,
319 bool is_local_update);
320 void CreateRemoteRtpDataChannel(const std::string& label,
321 uint32_t remote_ssrc);
322
323 // Creates channel and adds it to the collection of DataChannels that will
324 // be offered in a SessionDescription.
325 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
326 const std::string& label,
327 const InternalDataChannelInit* config);
328
329 // Checks if any data channel has been added.
330 bool HasDataChannels() const;
331
332 void AllocateSctpSids(rtc::SSLRole role);
333 void OnSctpDataChannelClosed(DataChannel* channel);
334
335 // Notifications from WebRtcSession relating to BaseChannels.
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700336 void OnVoiceChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700337 void OnVoiceChannelDestroyed();
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700338 void OnVideoChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700339 void OnVideoChannelDestroyed();
340 void OnDataChannelCreated();
341 void OnDataChannelDestroyed();
342 // Called when the cricket::DataChannel receives a message indicating that a
343 // webrtc::DataChannel should be opened.
344 void OnDataChannelOpenMessage(const std::string& label,
345 const InternalDataChannelInit& config);
346
deadbeefa601f5c2016-06-06 14:27:39 -0700347 RtpSenderInternal* FindSenderById(const std::string& id);
deadbeeffac06552015-11-25 11:26:01 -0800348
deadbeefa601f5c2016-06-06 14:27:39 -0700349 std::vector<rtc::scoped_refptr<
350 RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator
deadbeef70ab1a12015-09-28 16:53:55 -0700351 FindSenderForTrack(MediaStreamTrackInterface* track);
deadbeefa601f5c2016-06-06 14:27:39 -0700352 std::vector<rtc::scoped_refptr<
353 RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator
perkjd61bf802016-03-24 03:16:19 -0700354 FindReceiverForTrack(const std::string& track_id);
deadbeef70ab1a12015-09-28 16:53:55 -0700355
deadbeefab9b2d12015-10-14 11:33:11 -0700356 TrackInfos* GetRemoteTracks(cricket::MediaType media_type);
357 TrackInfos* GetLocalTracks(cricket::MediaType media_type);
358 const TrackInfo* FindTrackInfo(const TrackInfos& infos,
359 const std::string& stream_label,
360 const std::string track_id) const;
361
362 // Returns the specified SCTP DataChannel in sctp_data_channels_,
363 // or nullptr if not found.
364 DataChannel* FindDataChannelBySid(int sid) const;
365
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700366 // Called when first configuring the port allocator.
deadbeef91dd5672016-05-18 16:55:30 -0700367 bool InitializePortAllocator_n(const RTCConfiguration& configuration);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700368 // Called when SetConfiguration is called. Only a subset of the configuration
369 // is applied.
deadbeef91dd5672016-05-18 16:55:30 -0700370 bool ReconfigurePortAllocator_n(const RTCConfiguration& configuration);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700371
ivoc14d5dbe2016-07-04 07:06:55 -0700372 // Starts recording an Rtc EventLog using the supplied platform file.
373 // This function should only be called from the worker thread.
374 bool StartRtcEventLog_w(rtc::PlatformFile file, int64_t max_size_bytes);
375 // Starts recording an Rtc EventLog using the supplied platform file.
376 // This function should only be called from the worker thread.
377 void StopRtcEventLog_w();
378
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 // Storing the factory as a scoped reference pointer ensures that the memory
380 // in the PeerConnectionFactoryImpl remains available as long as the
381 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
382 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -0700383 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 // will refer to the same reference count.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000385 rtc::scoped_refptr<PeerConnectionFactory> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 PeerConnectionObserver* observer_;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000387 UMAObserver* uma_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 SignalingState signaling_state_;
perkj68343a82016-08-29 23:51:13 -0700389 // TODO(bemasc): Remove ice_state_.
390 IceState ice_state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 IceConnectionState ice_connection_state_;
392 IceGatheringState ice_gathering_state_;
393
kwibergd1fe2812016-04-27 06:47:29 -0700394 std::unique_ptr<cricket::PortAllocator> port_allocator_;
395 std::unique_ptr<MediaControllerInterface> media_controller_;
deadbeefab9b2d12015-10-14 11:33:11 -0700396
zhihuang8f65cdf2016-05-06 18:40:30 -0700397 // One PeerConnection has only one RTCP CNAME.
398 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
399 std::string rtcp_cname_;
400
deadbeefab9b2d12015-10-14 11:33:11 -0700401 // Streams added via AddStream.
402 rtc::scoped_refptr<StreamCollection> local_streams_;
403 // Streams created as a result of SetRemoteDescription.
404 rtc::scoped_refptr<StreamCollection> remote_streams_;
405
kwibergd1fe2812016-04-27 06:47:29 -0700406 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
deadbeefeb459812015-12-15 19:24:43 -0800407
deadbeefab9b2d12015-10-14 11:33:11 -0700408 // These lists store track info seen in local/remote descriptions.
409 TrackInfos remote_audio_tracks_;
410 TrackInfos remote_video_tracks_;
411 TrackInfos local_audio_tracks_;
412 TrackInfos local_video_tracks_;
413
414 SctpSidAllocator sid_allocator_;
415 // label -> DataChannel
416 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
417 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
deadbeefbd292462015-12-14 18:15:29 -0800418 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
deadbeefab9b2d12015-10-14 11:33:11 -0700419
deadbeefbda7e0b2015-12-08 17:13:40 -0800420 bool remote_peer_supports_msid_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700421
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700422 bool enable_ice_renomination_ = false;
423
deadbeefa601f5c2016-06-06 14:27:39 -0700424 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
425 senders_;
426 std::vector<
427 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
428 receivers_;
deadbeefab9b2d12015-10-14 11:33:11 -0700429
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_