blob: 1913e601e0841b7d7226cdc34a1a563c7321ee63 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_PEERCONNECTION_H_
12#define 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/peerconnectioninterface.h"
20#include "pc/iceserverparsing.h"
21#include "pc/peerconnectionfactory.h"
22#include "pc/rtcstatscollector.h"
23#include "pc/rtpreceiver.h"
24#include "pc/rtpsender.h"
25#include "pc/statscollector.h"
26#include "pc/streamcollection.h"
27#include "pc/webrtcsession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
29namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
deadbeefeb459812015-12-15 19:24:43 -080031class MediaStreamObserver;
perkjf0dcfe22016-03-10 18:32:00 +010032class VideoRtpReceiver;
skvlad11a9cbf2016-10-07 11:53:05 -070033class RtcEventLog;
deadbeefab9b2d12015-10-14 11:33:11 -070034
zhihuang1c378ed2017-08-17 14:10:50 -070035// TODO(zhihuang): Remove this declaration when the WebRtcSession tests don't
36// need it.
37void ExtractSharedMediaSessionOptions(
deadbeefab9b2d12015-10-14 11:33:11 -070038 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
39 cricket::MediaSessionOptions* session_options);
40
deadbeef70ab1a12015-09-28 16:53:55 -070041// PeerConnection implements the PeerConnectionInterface interface.
deadbeefab9b2d12015-10-14 11:33:11 -070042// It uses WebRtcSession to implement the PeerConnection functionality.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043class PeerConnection : public PeerConnectionInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044 public IceObserver,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000045 public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046 public sigslot::has_slots<> {
47 public:
zhihuang38ede132017-06-15 12:52:32 -070048 explicit PeerConnection(PeerConnectionFactory* factory,
49 std::unique_ptr<RtcEventLog> event_log,
50 std::unique_ptr<Call> call);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
deadbeef653b8e02015-11-11 12:55:10 -080052 bool Initialize(
53 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -070054 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020055 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef653b8e02015-11-11 12:55:10 -080056 PeerConnectionObserver* observer);
57
deadbeefa67696b2015-09-29 11:56:26 -070058 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
59 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
60 bool AddStream(MediaStreamInterface* local_stream) override;
61 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062
deadbeefe1f9d832016-01-14 15:35:42 -080063 rtc::scoped_refptr<RtpSenderInterface> AddTrack(
64 MediaStreamTrackInterface* track,
65 std::vector<MediaStreamInterface*> streams) override;
66 bool RemoveTrack(RtpSenderInterface* sender) override;
67
Steve Anton978b8762017-09-29 12:15:02 -070068 // TODO(steveanton): Remove this once all clients have switched to using the
69 // PeerConnection shims for WebRtcSession methods instead of the methods
70 // directly via this getter.
71 virtual WebRtcSession* session() { return session_; }
Alex Loikobf667942017-09-29 10:44:31 +000072
deadbeefa67696b2015-09-29 11:56:26 -070073 rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
74 AudioTrackInterface* track) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
deadbeeffac06552015-11-25 11:26:01 -080076 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-18 16:58:44 -080077 const std::string& kind,
78 const std::string& stream_id) override;
deadbeeffac06552015-11-25 11:26:01 -080079
deadbeef70ab1a12015-09-28 16:53:55 -070080 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
81 const override;
82 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
83 const override;
84
deadbeefa67696b2015-09-29 11:56:26 -070085 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 const std::string& label,
deadbeefa67696b2015-09-29 11:56:26 -070087 const DataChannelInit* config) override;
88 bool GetStats(StatsObserver* observer,
89 webrtc::MediaStreamTrackInterface* track,
90 StatsOutputLevel level) override;
hbos74e1a4f2016-09-15 23:33:01 -070091 void GetStats(RTCStatsCollectorCallback* callback) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
deadbeefa67696b2015-09-29 11:56:26 -070093 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094
deadbeefa67696b2015-09-29 11:56:26 -070095 IceConnectionState ice_connection_state() override;
96 IceGatheringState ice_gathering_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097
deadbeefa67696b2015-09-29 11:56:26 -070098 const SessionDescriptionInterface* local_description() const override;
99 const SessionDescriptionInterface* remote_description() const override;
deadbeeffe4a8a42016-12-20 17:56:17 -0800100 const SessionDescriptionInterface* current_local_description() const override;
101 const SessionDescriptionInterface* current_remote_description()
102 const override;
103 const SessionDescriptionInterface* pending_local_description() const override;
104 const SessionDescriptionInterface* pending_remote_description()
105 const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106
107 // JSEP01
htaa2a49d92016-03-04 02:51:39 -0800108 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700109 void CreateOffer(CreateSessionDescriptionObserver* observer,
110 const MediaConstraintsInterface* constraints) override;
111 void CreateOffer(CreateSessionDescriptionObserver* observer,
112 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 02:51:39 -0800113 // Deprecated, use version without constraints.
deadbeefa67696b2015-09-29 11:56:26 -0700114 void CreateAnswer(CreateSessionDescriptionObserver* observer,
115 const MediaConstraintsInterface* constraints) override;
htaa2a49d92016-03-04 02:51:39 -0800116 void CreateAnswer(CreateSessionDescriptionObserver* observer,
117 const RTCOfferAnswerOptions& options) override;
deadbeefa67696b2015-09-29 11:56:26 -0700118 void SetLocalDescription(SetSessionDescriptionObserver* observer,
119 SessionDescriptionInterface* desc) override;
120 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
121 SessionDescriptionInterface* desc) override;
deadbeef46c73892016-11-16 19:42:04 -0800122 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
deadbeefa67696b2015-09-29 11:56:26 -0700123 bool SetConfiguration(
deadbeef293e9262017-01-11 12:28:30 -0800124 const PeerConnectionInterface::RTCConfiguration& configuration,
125 RTCError* error) override;
126 bool SetConfiguration(
127 const PeerConnectionInterface::RTCConfiguration& configuration) override {
128 return SetConfiguration(configuration, nullptr);
129 }
deadbeefa67696b2015-09-29 11:56:26 -0700130 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700131 bool RemoveIceCandidates(
132 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133
deadbeefa67696b2015-09-29 11:56:26 -0700134 void RegisterUMAObserver(UMAObserver* observer) override;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000135
zstein4b979802017-06-02 14:37:37 -0700136 RTCError SetBitrate(const BitrateParameters& bitrate) override;
137
ivoc14d5dbe2016-07-04 07:06:55 -0700138 bool StartRtcEventLog(rtc::PlatformFile file,
139 int64_t max_size_bytes) override;
140 void StopRtcEventLog() override;
141
deadbeefa67696b2015-09-29 11:56:26 -0700142 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143
hbos82ebe022016-11-14 01:41:09 -0800144 sigslot::signal1<DataChannel*> SignalDataChannelCreated;
145
deadbeefab9b2d12015-10-14 11:33:11 -0700146 // Virtual for unit tests.
147 virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
148 sctp_data_channels() const {
149 return sctp_data_channels_;
perkjd61bf802016-03-24 03:16:19 -0700150 }
deadbeefab9b2d12015-10-14 11:33:11 -0700151
Steve Anton978b8762017-09-29 12:15:02 -0700152 // TODO(steveanton): These methods are temporarily added to facilitate work
153 // towards merging WebRtcSession into PeerConnection. To make this easier, we
154 // want only PeerConnection to interact with WebRtcSession so they can be
155 // merged easily. A few outside classes still access WebRtcSession methods
156 // directly, so these have been added to PeerConnection to remove the
157 // dependency from WebRtcSession.
158
159 rtc::Thread* network_thread() const { return factory_->network_thread(); }
160 rtc::Thread* worker_thread() const { return factory_->worker_thread(); }
161 rtc::Thread* signaling_thread() const { return factory_->signaling_thread(); }
162 virtual const std::string& session_id() const { return session_->id(); }
163 virtual bool session_created() const { return session_ != nullptr; }
164 virtual bool initial_offerer() const { return session_->initial_offerer(); }
165 virtual std::unique_ptr<SessionStats> GetSessionStats_s() {
166 return session_->GetStats_s();
167 }
168 virtual std::unique_ptr<SessionStats> GetSessionStats(
169 const ChannelNamePairs& channel_name_pairs) {
170 return session_->GetStats(channel_name_pairs);
171 }
172 virtual bool GetLocalCertificate(
173 const std::string& transport_name,
174 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) {
175 return session_->GetLocalCertificate(transport_name, certificate);
176 }
177 virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
178 const std::string& transport_name) {
179 return session_->GetRemoteSSLCertificate(transport_name);
180 }
181 virtual Call::Stats GetCallStats() { return session_->GetCallStats(); }
182 virtual cricket::VoiceChannel* voice_channel() {
183 return session_->voice_channel();
184 }
185 virtual cricket::VideoChannel* video_channel() {
186 return session_->video_channel();
187 }
188 virtual cricket::RtpDataChannel* rtp_data_channel() {
189 return session_->rtp_data_channel();
190 }
191 virtual rtc::Optional<std::string> sctp_content_name() const {
192 return session_->sctp_content_name();
193 }
194 virtual rtc::Optional<std::string> sctp_transport_name() const {
195 return session_->sctp_transport_name();
196 }
197 virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id) {
198 return session_->GetLocalTrackIdBySsrc(ssrc, track_id);
199 }
200 virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id) {
201 return session_->GetRemoteTrackIdBySsrc(ssrc, track_id);
202 }
203
204 // This is needed for stats tests to inject a MockWebRtcSession. Once
205 // WebRtcSession has been merged in, this will no longer be needed.
206 void set_session_for_testing(WebRtcSession* session) {
207 session_ = session;
208 }
209
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 protected:
deadbeefa67696b2015-09-29 11:56:26 -0700211 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212
213 private:
deadbeefab9b2d12015-10-14 11:33:11 -0700214 struct TrackInfo {
215 TrackInfo() : ssrc(0) {}
216 TrackInfo(const std::string& stream_label,
217 const std::string track_id,
218 uint32_t ssrc)
219 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {}
deadbeefbda7e0b2015-12-08 17:13:40 -0800220 bool operator==(const TrackInfo& other) {
221 return this->stream_label == other.stream_label &&
222 this->track_id == other.track_id && this->ssrc == other.ssrc;
223 }
deadbeefab9b2d12015-10-14 11:33:11 -0700224 std::string stream_label;
225 std::string track_id;
226 uint32_t ssrc;
227 };
228 typedef std::vector<TrackInfo> TrackInfos;
229
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 // Implements MessageHandler.
deadbeefa67696b2015-09-29 11:56:26 -0700231 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232
deadbeefab9b2d12015-10-14 11:33:11 -0700233 void CreateAudioReceiver(MediaStreamInterface* stream,
perkjd61bf802016-03-24 03:16:19 -0700234 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700235 uint32_t ssrc);
perkjf0dcfe22016-03-10 18:32:00 +0100236
deadbeefab9b2d12015-10-14 11:33:11 -0700237 void CreateVideoReceiver(MediaStreamInterface* stream,
perkjf0dcfe22016-03-10 18:32:00 +0100238 const std::string& track_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700239 uint32_t ssrc);
perkjd61bf802016-03-24 03:16:19 -0700240 void DestroyReceiver(const std::string& track_id);
korniltsev.anatolyec390b52017-07-24 17:00:25 -0700241
242 // May be called either by AddStream/RemoveStream, or when a track is
243 // added/removed from a stream previously added via AddStream.
244 void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream);
245 void RemoveAudioTrack(AudioTrackInterface* track,
246 MediaStreamInterface* stream);
247 void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream);
248 void RemoveVideoTrack(VideoTrackInterface* track,
249 MediaStreamInterface* stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250
251 // Implements IceObserver
zstein6dfd53a2017-03-06 13:49:03 -0800252 void OnIceConnectionStateChange(IceConnectionState new_state) override;
Peter Thatcher54360512015-07-08 11:08:35 -0700253 void OnIceGatheringChange(IceGatheringState new_state) override;
jbauch81bf7b02017-03-25 08:31:12 -0700254 void OnIceCandidate(
255 std::unique_ptr<IceCandidateInterface> candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700256 void OnIceCandidatesRemoved(
257 const std::vector<cricket::Candidate>& candidates) override;
Peter Thatcher54360512015-07-08 11:08:35 -0700258 void OnIceConnectionReceivingChange(bool receiving) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259
260 // Signals from WebRtcSession.
deadbeefd59daf82015-10-14 15:02:44 -0700261 void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 void ChangeSignalingState(SignalingState signaling_state);
263
deadbeefeb459812015-12-15 19:24:43 -0800264 // Signals from MediaStreamObserver.
265 void OnAudioTrackAdded(AudioTrackInterface* track,
266 MediaStreamInterface* stream);
267 void OnAudioTrackRemoved(AudioTrackInterface* track,
268 MediaStreamInterface* stream);
269 void OnVideoTrackAdded(VideoTrackInterface* track,
270 MediaStreamInterface* stream);
271 void OnVideoTrackRemoved(VideoTrackInterface* track,
272 MediaStreamInterface* stream);
273
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
275 const std::string& error);
deadbeefab9b2d12015-10-14 11:33:11 -0700276 void PostCreateSessionDescriptionFailure(
277 CreateSessionDescriptionObserver* observer,
278 const std::string& error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279
280 bool IsClosed() const {
281 return signaling_state_ == PeerConnectionInterface::kClosed;
282 }
283
deadbeefab9b2d12015-10-14 11:33:11 -0700284 // Returns a MediaSessionOptions struct with options decided by |options|,
285 // the local MediaStreams and DataChannels.
zhihuang1c378ed2017-08-17 14:10:50 -0700286 void GetOptionsForOffer(
deadbeefab9b2d12015-10-14 11:33:11 -0700287 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
288 cricket::MediaSessionOptions* session_options);
289
290 // Returns a MediaSessionOptions struct with options decided by
291 // |constraints|, the local MediaStreams and DataChannels.
zhihuang1c378ed2017-08-17 14:10:50 -0700292 void GetOptionsForAnswer(const RTCOfferAnswerOptions& options,
293 cricket::MediaSessionOptions* session_options);
htaa2a49d92016-03-04 02:51:39 -0800294
zhihuang1c378ed2017-08-17 14:10:50 -0700295 // Generates MediaDescriptionOptions for the |session_opts| based on existing
296 // local description or remote description.
297 void GenerateMediaDescriptionOptions(
298 const SessionDescriptionInterface* session_desc,
299 cricket::RtpTransceiverDirection audio_direction,
300 cricket::RtpTransceiverDirection video_direction,
301 rtc::Optional<size_t>* audio_index,
302 rtc::Optional<size_t>* video_index,
303 rtc::Optional<size_t>* data_index,
htaa2a49d92016-03-04 02:51:39 -0800304 cricket::MediaSessionOptions* session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700305
deadbeeffaac4972015-11-12 15:33:07 -0800306 // Remove all local and remote tracks of type |media_type|.
307 // Called when a media type is rejected (m-line set to port 0).
308 void RemoveTracks(cricket::MediaType media_type);
309
deadbeefbda7e0b2015-12-08 17:13:40 -0800310 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|,
311 // and existing MediaStreamTracks are removed if there is no corresponding
312 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack
313 // is created if it doesn't exist; if false, it's removed if it exists.
314 // |media_type| is the type of the |streams| and can be either audio or video.
deadbeefab9b2d12015-10-14 11:33:11 -0700315 // If a new MediaStream is created it is added to |new_streams|.
316 void UpdateRemoteStreamsList(
317 const std::vector<cricket::StreamParams>& streams,
deadbeefbda7e0b2015-12-08 17:13:40 -0800318 bool default_track_needed,
deadbeefab9b2d12015-10-14 11:33:11 -0700319 cricket::MediaType media_type,
320 StreamCollection* new_streams);
321
322 // Triggered when a remote track has been seen for the first time in a remote
323 // session description. It creates a remote MediaStreamTrackInterface
324 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
325 void OnRemoteTrackSeen(const std::string& stream_label,
326 const std::string& track_id,
327 uint32_t ssrc,
328 cricket::MediaType media_type);
329
330 // Triggered when a remote track has been removed from a remote session
331 // description. It removes the remote track with id |track_id| from a remote
332 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
333 void OnRemoteTrackRemoved(const std::string& stream_label,
334 const std::string& track_id,
335 cricket::MediaType media_type);
336
337 // Finds remote MediaStreams without any tracks and removes them from
338 // |remote_streams_| and notifies the observer that the MediaStreams no longer
339 // exist.
340 void UpdateEndedRemoteMediaStreams();
341
deadbeefab9b2d12015-10-14 11:33:11 -0700342 // Loops through the vector of |streams| and finds added and removed
343 // StreamParams since last time this method was called.
344 // For each new or removed StreamParam, OnLocalTrackSeen or
345 // OnLocalTrackRemoved is invoked.
346 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams,
347 cricket::MediaType media_type);
348
349 // Triggered when a local track has been seen for the first time in a local
350 // session description.
351 // This method triggers CreateAudioSender or CreateVideoSender if the rtp
352 // streams in the local SessionDescription can be mapped to a MediaStreamTrack
353 // in a MediaStream in |local_streams_|
354 void OnLocalTrackSeen(const std::string& stream_label,
355 const std::string& track_id,
356 uint32_t ssrc,
357 cricket::MediaType media_type);
358
359 // Triggered when a local track has been removed from a local session
360 // description.
361 // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
362 // has been removed from the local SessionDescription and the stream can be
363 // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
364 void OnLocalTrackRemoved(const std::string& stream_label,
365 const std::string& track_id,
366 uint32_t ssrc,
367 cricket::MediaType media_type);
368
369 void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
370 void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
371 void UpdateClosingRtpDataChannels(
372 const std::vector<std::string>& active_channels,
373 bool is_local_update);
374 void CreateRemoteRtpDataChannel(const std::string& label,
375 uint32_t remote_ssrc);
376
377 // Creates channel and adds it to the collection of DataChannels that will
378 // be offered in a SessionDescription.
379 rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
380 const std::string& label,
381 const InternalDataChannelInit* config);
382
383 // Checks if any data channel has been added.
384 bool HasDataChannels() const;
385
386 void AllocateSctpSids(rtc::SSLRole role);
387 void OnSctpDataChannelClosed(DataChannel* channel);
388
389 // Notifications from WebRtcSession relating to BaseChannels.
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700390 void OnVoiceChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700391 void OnVoiceChannelDestroyed();
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700392 void OnVideoChannelCreated();
deadbeefab9b2d12015-10-14 11:33:11 -0700393 void OnVideoChannelDestroyed();
394 void OnDataChannelCreated();
395 void OnDataChannelDestroyed();
396 // Called when the cricket::DataChannel receives a message indicating that a
397 // webrtc::DataChannel should be opened.
398 void OnDataChannelOpenMessage(const std::string& label,
399 const InternalDataChannelInit& config);
400
zhihuang1c378ed2017-08-17 14:10:50 -0700401 bool HasRtpSender(cricket::MediaType type) const;
deadbeefa601f5c2016-06-06 14:27:39 -0700402 RtpSenderInternal* FindSenderById(const std::string& id);
deadbeeffac06552015-11-25 11:26:01 -0800403
deadbeefa601f5c2016-06-06 14:27:39 -0700404 std::vector<rtc::scoped_refptr<
405 RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator
deadbeef70ab1a12015-09-28 16:53:55 -0700406 FindSenderForTrack(MediaStreamTrackInterface* track);
deadbeefa601f5c2016-06-06 14:27:39 -0700407 std::vector<rtc::scoped_refptr<
408 RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator
perkjd61bf802016-03-24 03:16:19 -0700409 FindReceiverForTrack(const std::string& track_id);
deadbeef70ab1a12015-09-28 16:53:55 -0700410
deadbeefab9b2d12015-10-14 11:33:11 -0700411 TrackInfos* GetRemoteTracks(cricket::MediaType media_type);
412 TrackInfos* GetLocalTracks(cricket::MediaType media_type);
413 const TrackInfo* FindTrackInfo(const TrackInfos& infos,
414 const std::string& stream_label,
415 const std::string track_id) const;
416
417 // Returns the specified SCTP DataChannel in sctp_data_channels_,
418 // or nullptr if not found.
419 DataChannel* FindDataChannelBySid(int sid) const;
420
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700421 // Called when first configuring the port allocator.
deadbeef91dd5672016-05-18 16:55:30 -0700422 bool InitializePortAllocator_n(const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 12:28:30 -0800423 // Called when SetConfiguration is called to apply the supported subset
424 // of the configuration on the network thread.
425 bool ReconfigurePortAllocator_n(
426 const cricket::ServerAddresses& stun_servers,
427 const std::vector<cricket::RelayServerConfig>& turn_servers,
428 IceTransportsType type,
429 int candidate_pool_size,
430 bool prune_turn_ports);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700431
ivoc14d5dbe2016-07-04 07:06:55 -0700432 // Starts recording an Rtc EventLog using the supplied platform file.
433 // This function should only be called from the worker thread.
434 bool StartRtcEventLog_w(rtc::PlatformFile file, int64_t max_size_bytes);
435 // Starts recording an Rtc EventLog using the supplied platform file.
436 // This function should only be called from the worker thread.
437 void StopRtcEventLog_w();
438
Steve Anton038834f2017-07-14 15:59:59 -0700439 // Ensures the configuration doesn't have any parameters with invalid values,
440 // or values that conflict with other parameters.
441 //
442 // Returns RTCError::OK() if there are no issues.
443 RTCError ValidateConfiguration(const RTCConfiguration& config) const;
444
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 // Storing the factory as a scoped reference pointer ensures that the memory
446 // in the PeerConnectionFactoryImpl remains available as long as the
447 // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
448 // However, since the reference counting is done in the
deadbeefab9b2d12015-10-14 11:33:11 -0700449 // PeerConnectionFactoryInterface all instances created using the raw pointer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 // will refer to the same reference count.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000451 rtc::scoped_refptr<PeerConnectionFactory> factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 PeerConnectionObserver* observer_;
buildbot@webrtc.org1567b8c2014-05-08 19:54:16 +0000453 UMAObserver* uma_observer_;
terelius33860252017-05-12 23:37:18 -0700454
455 // The EventLog needs to outlive |call_| (and any other object that uses it).
456 std::unique_ptr<RtcEventLog> event_log_;
457
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 SignalingState signaling_state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 IceConnectionState ice_connection_state_;
460 IceGatheringState ice_gathering_state_;
deadbeef46c73892016-11-16 19:42:04 -0800461 PeerConnectionInterface::RTCConfiguration configuration_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462
kwibergd1fe2812016-04-27 06:47:29 -0700463 std::unique_ptr<cricket::PortAllocator> port_allocator_;
deadbeefab9b2d12015-10-14 11:33:11 -0700464
zhihuang8f65cdf2016-05-06 18:40:30 -0700465 // One PeerConnection has only one RTCP CNAME.
466 // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
467 std::string rtcp_cname_;
468
deadbeefab9b2d12015-10-14 11:33:11 -0700469 // Streams added via AddStream.
470 rtc::scoped_refptr<StreamCollection> local_streams_;
471 // Streams created as a result of SetRemoteDescription.
472 rtc::scoped_refptr<StreamCollection> remote_streams_;
473
kwibergd1fe2812016-04-27 06:47:29 -0700474 std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
deadbeefeb459812015-12-15 19:24:43 -0800475
deadbeefab9b2d12015-10-14 11:33:11 -0700476 // These lists store track info seen in local/remote descriptions.
477 TrackInfos remote_audio_tracks_;
478 TrackInfos remote_video_tracks_;
479 TrackInfos local_audio_tracks_;
480 TrackInfos local_video_tracks_;
481
482 SctpSidAllocator sid_allocator_;
483 // label -> DataChannel
484 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
485 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
deadbeefbd292462015-12-14 18:15:29 -0800486 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
deadbeefab9b2d12015-10-14 11:33:11 -0700487
deadbeefbda7e0b2015-12-08 17:13:40 -0800488 bool remote_peer_supports_msid_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700489
terelius33860252017-05-12 23:37:18 -0700490 std::unique_ptr<Call> call_;
Steve Anton978b8762017-09-29 12:15:02 -0700491 WebRtcSession* session_;
492 std::unique_ptr<WebRtcSession> owned_session_;
terelius33860252017-05-12 23:37:18 -0700493 std::unique_ptr<StatsCollector> stats_; // A pointer is passed to senders_
494 rtc::scoped_refptr<RTCStatsCollector> stats_collector_;
495
deadbeefa601f5c2016-06-06 14:27:39 -0700496 std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
497 senders_;
498 std::vector<
499 rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
500 receivers_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501};
502
503} // namespace webrtc
504
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200505#endif // PC_PEERCONNECTION_H_