henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef PC_PEERCONNECTION_H_ |
| 12 | #define PC_PEERCONNECTION_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <string> |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 15 | #include <map> |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 16 | #include <memory> |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 17 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/peerconnectioninterface.h" |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 20 | #include "api/turncustomizer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "pc/iceserverparsing.h" |
| 22 | #include "pc/peerconnectionfactory.h" |
| 23 | #include "pc/rtcstatscollector.h" |
| 24 | #include "pc/rtpreceiver.h" |
| 25 | #include "pc/rtpsender.h" |
| 26 | #include "pc/statscollector.h" |
| 27 | #include "pc/streamcollection.h" |
| 28 | #include "pc/webrtcsession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 31 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 32 | class MediaStreamObserver; |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 33 | class VideoRtpReceiver; |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 34 | class RtcEventLog; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 35 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 36 | // PeerConnection implements the PeerConnectionInterface interface. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 37 | // It uses WebRtcSession to implement the PeerConnection functionality. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | class PeerConnection : public PeerConnectionInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | public IceObserver, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 40 | public rtc::MessageHandler, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | public sigslot::has_slots<> { |
| 42 | public: |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 43 | explicit PeerConnection(PeerConnectionFactory* factory, |
| 44 | std::unique_ptr<RtcEventLog> event_log, |
| 45 | std::unique_ptr<Call> call); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 47 | bool Initialize( |
| 48 | const PeerConnectionInterface::RTCConfiguration& configuration, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 49 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 50 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 51 | PeerConnectionObserver* observer); |
| 52 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 53 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override; |
| 54 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override; |
| 55 | bool AddStream(MediaStreamInterface* local_stream) override; |
| 56 | void RemoveStream(MediaStreamInterface* local_stream) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 58 | rtc::scoped_refptr<RtpSenderInterface> AddTrack( |
| 59 | MediaStreamTrackInterface* track, |
| 60 | std::vector<MediaStreamInterface*> streams) override; |
| 61 | bool RemoveTrack(RtpSenderInterface* sender) override; |
| 62 | |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 63 | // TODO(steveanton): Remove this once all clients have switched to using the |
| 64 | // PeerConnection shims for WebRtcSession methods instead of the methods |
| 65 | // directly via this getter. |
| 66 | virtual WebRtcSession* session() { return session_; } |
Alex Loiko | bf66794 | 2017-09-29 10:44:31 +0000 | [diff] [blame] | 67 | |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 68 | // Gets the DTLS SSL certificate associated with the audio transport on the |
| 69 | // remote side. This will become populated once the DTLS connection with the |
| 70 | // peer has been completed, as indicated by the ICE connection state |
| 71 | // transitioning to kIceConnectionCompleted. |
| 72 | // Note that this will be removed once we implement RTCDtlsTransport which |
| 73 | // has standardized method for getting this information. |
| 74 | // See https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface |
| 75 | std::unique_ptr<rtc::SSLCertificate> GetRemoteAudioSSLCertificate(); |
| 76 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 77 | rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( |
| 78 | AudioTrackInterface* track) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 80 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 81 | const std::string& kind, |
| 82 | const std::string& stream_id) override; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 83 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 84 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 85 | const override; |
| 86 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 87 | const override; |
| 88 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 89 | rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | const std::string& label, |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 91 | const DataChannelInit* config) override; |
| 92 | bool GetStats(StatsObserver* observer, |
| 93 | webrtc::MediaStreamTrackInterface* track, |
| 94 | StatsOutputLevel level) override; |
hbos | 74e1a4f | 2016-09-15 23:33:01 -0700 | [diff] [blame] | 95 | void GetStats(RTCStatsCollectorCallback* callback) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 97 | SignalingState signaling_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 99 | IceConnectionState ice_connection_state() override; |
| 100 | IceGatheringState ice_gathering_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 102 | const SessionDescriptionInterface* local_description() const override; |
| 103 | const SessionDescriptionInterface* remote_description() const override; |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 104 | const SessionDescriptionInterface* current_local_description() const override; |
| 105 | const SessionDescriptionInterface* current_remote_description() |
| 106 | const override; |
| 107 | const SessionDescriptionInterface* pending_local_description() const override; |
| 108 | const SessionDescriptionInterface* pending_remote_description() |
| 109 | const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | |
| 111 | // JSEP01 |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 112 | // Deprecated, use version without constraints. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 113 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 114 | const MediaConstraintsInterface* constraints) override; |
| 115 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 116 | const RTCOfferAnswerOptions& options) override; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 117 | // Deprecated, use version without constraints. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 118 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 119 | const MediaConstraintsInterface* constraints) override; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 120 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 121 | const RTCOfferAnswerOptions& options) override; |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 122 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 123 | SessionDescriptionInterface* desc) override; |
| 124 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 125 | SessionDescriptionInterface* desc) override; |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 126 | PeerConnectionInterface::RTCConfiguration GetConfiguration() override; |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 127 | bool SetConfiguration( |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 128 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 129 | RTCError* error) override; |
| 130 | bool SetConfiguration( |
| 131 | const PeerConnectionInterface::RTCConfiguration& configuration) override { |
| 132 | return SetConfiguration(configuration, nullptr); |
| 133 | } |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 134 | bool AddIceCandidate(const IceCandidateInterface* candidate) override; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 135 | bool RemoveIceCandidates( |
| 136 | const std::vector<cricket::Candidate>& candidates) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 138 | void RegisterUMAObserver(UMAObserver* observer) override; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 139 | |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 140 | RTCError SetBitrate(const BitrateParameters& bitrate) override; |
| 141 | |
Alex Narest | 78609d5 | 2017-10-20 10:37:47 +0200 | [diff] [blame] | 142 | void SetBitrateAllocationStrategy( |
| 143 | std::unique_ptr<rtc::BitrateAllocationStrategy> |
| 144 | bitrate_allocation_strategy) override; |
| 145 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 146 | void SetAudioPlayout(bool playout) override; |
| 147 | void SetAudioRecording(bool recording) override; |
| 148 | |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 149 | RTC_DEPRECATED bool StartRtcEventLog(rtc::PlatformFile file, |
| 150 | int64_t max_size_bytes) override; |
| 151 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override; |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 152 | void StopRtcEventLog() override; |
| 153 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 154 | void Close() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 155 | |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 156 | sigslot::signal1<DataChannel*> SignalDataChannelCreated; |
| 157 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 158 | // Virtual for unit tests. |
| 159 | virtual const std::vector<rtc::scoped_refptr<DataChannel>>& |
| 160 | sctp_data_channels() const { |
| 161 | return sctp_data_channels_; |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 162 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 163 | |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 164 | // TODO(steveanton): These methods are temporarily added to facilitate work |
| 165 | // towards merging WebRtcSession into PeerConnection. To make this easier, we |
| 166 | // want only PeerConnection to interact with WebRtcSession so they can be |
| 167 | // merged easily. A few outside classes still access WebRtcSession methods |
| 168 | // directly, so these have been added to PeerConnection to remove the |
| 169 | // dependency from WebRtcSession. |
| 170 | |
| 171 | rtc::Thread* network_thread() const { return factory_->network_thread(); } |
| 172 | rtc::Thread* worker_thread() const { return factory_->worker_thread(); } |
| 173 | rtc::Thread* signaling_thread() const { return factory_->signaling_thread(); } |
| 174 | virtual const std::string& session_id() const { return session_->id(); } |
| 175 | virtual bool session_created() const { return session_ != nullptr; } |
| 176 | virtual bool initial_offerer() const { return session_->initial_offerer(); } |
| 177 | virtual std::unique_ptr<SessionStats> GetSessionStats_s() { |
| 178 | return session_->GetStats_s(); |
| 179 | } |
| 180 | virtual std::unique_ptr<SessionStats> GetSessionStats( |
| 181 | const ChannelNamePairs& channel_name_pairs) { |
| 182 | return session_->GetStats(channel_name_pairs); |
| 183 | } |
| 184 | virtual bool GetLocalCertificate( |
| 185 | const std::string& transport_name, |
| 186 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| 187 | return session_->GetLocalCertificate(transport_name, certificate); |
| 188 | } |
| 189 | virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate( |
| 190 | const std::string& transport_name) { |
| 191 | return session_->GetRemoteSSLCertificate(transport_name); |
| 192 | } |
| 193 | virtual Call::Stats GetCallStats() { return session_->GetCallStats(); } |
| 194 | virtual cricket::VoiceChannel* voice_channel() { |
| 195 | return session_->voice_channel(); |
| 196 | } |
| 197 | virtual cricket::VideoChannel* video_channel() { |
| 198 | return session_->video_channel(); |
| 199 | } |
| 200 | virtual cricket::RtpDataChannel* rtp_data_channel() { |
| 201 | return session_->rtp_data_channel(); |
| 202 | } |
| 203 | virtual rtc::Optional<std::string> sctp_content_name() const { |
| 204 | return session_->sctp_content_name(); |
| 205 | } |
| 206 | virtual rtc::Optional<std::string> sctp_transport_name() const { |
| 207 | return session_->sctp_transport_name(); |
| 208 | } |
| 209 | virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id) { |
| 210 | return session_->GetLocalTrackIdBySsrc(ssrc, track_id); |
| 211 | } |
| 212 | virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id) { |
| 213 | return session_->GetRemoteTrackIdBySsrc(ssrc, track_id); |
| 214 | } |
Steve Anton | d5585ca | 2017-10-23 14:49:26 -0700 | [diff] [blame] | 215 | bool IceRestartPending(const std::string& content_name) const { |
| 216 | return session_->IceRestartPending(content_name); |
| 217 | } |
| 218 | bool NeedsIceRestart(const std::string& content_name) const { |
| 219 | return session_->NeedsIceRestart(content_name); |
| 220 | } |
| 221 | bool GetSslRole(const std::string& content_name, rtc::SSLRole* role) { |
| 222 | return session_->GetSslRole(content_name, role); |
| 223 | } |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 224 | |
| 225 | // This is needed for stats tests to inject a MockWebRtcSession. Once |
| 226 | // WebRtcSession has been merged in, this will no longer be needed. |
| 227 | void set_session_for_testing(WebRtcSession* session) { |
| 228 | session_ = session; |
| 229 | } |
| 230 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 231 | protected: |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 232 | ~PeerConnection() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 233 | |
| 234 | private: |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 235 | struct TrackInfo { |
| 236 | TrackInfo() : ssrc(0) {} |
| 237 | TrackInfo(const std::string& stream_label, |
| 238 | const std::string track_id, |
| 239 | uint32_t ssrc) |
| 240 | : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {} |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 241 | bool operator==(const TrackInfo& other) { |
| 242 | return this->stream_label == other.stream_label && |
| 243 | this->track_id == other.track_id && this->ssrc == other.ssrc; |
| 244 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 245 | std::string stream_label; |
| 246 | std::string track_id; |
| 247 | uint32_t ssrc; |
| 248 | }; |
| 249 | typedef std::vector<TrackInfo> TrackInfos; |
| 250 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 251 | // Implements MessageHandler. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 252 | void OnMessage(rtc::Message* msg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 254 | void CreateAudioReceiver(MediaStreamInterface* stream, |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 255 | const std::string& track_id, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 256 | uint32_t ssrc); |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 257 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 258 | void CreateVideoReceiver(MediaStreamInterface* stream, |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 259 | const std::string& track_id, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 260 | uint32_t ssrc); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 261 | rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver( |
| 262 | const std::string& track_id); |
korniltsev.anatoly | ec390b5 | 2017-07-24 17:00:25 -0700 | [diff] [blame] | 263 | |
| 264 | // May be called either by AddStream/RemoveStream, or when a track is |
| 265 | // added/removed from a stream previously added via AddStream. |
| 266 | void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream); |
| 267 | void RemoveAudioTrack(AudioTrackInterface* track, |
| 268 | MediaStreamInterface* stream); |
| 269 | void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream); |
| 270 | void RemoveVideoTrack(VideoTrackInterface* track, |
| 271 | MediaStreamInterface* stream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 272 | |
| 273 | // Implements IceObserver |
zstein | 6dfd53a | 2017-03-06 13:49:03 -0800 | [diff] [blame] | 274 | void OnIceConnectionStateChange(IceConnectionState new_state) override; |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 275 | void OnIceGatheringChange(IceGatheringState new_state) override; |
jbauch | 81bf7b0 | 2017-03-25 08:31:12 -0700 | [diff] [blame] | 276 | void OnIceCandidate( |
| 277 | std::unique_ptr<IceCandidateInterface> candidate) override; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 278 | void OnIceCandidatesRemoved( |
| 279 | const std::vector<cricket::Candidate>& candidates) override; |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 280 | void OnIceConnectionReceivingChange(bool receiving) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 281 | |
| 282 | // Signals from WebRtcSession. |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 283 | void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 284 | void ChangeSignalingState(SignalingState signaling_state); |
| 285 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 286 | // Signals from MediaStreamObserver. |
| 287 | void OnAudioTrackAdded(AudioTrackInterface* track, |
| 288 | MediaStreamInterface* stream); |
| 289 | void OnAudioTrackRemoved(AudioTrackInterface* track, |
| 290 | MediaStreamInterface* stream); |
| 291 | void OnVideoTrackAdded(VideoTrackInterface* track, |
| 292 | MediaStreamInterface* stream); |
| 293 | void OnVideoTrackRemoved(VideoTrackInterface* track, |
| 294 | MediaStreamInterface* stream); |
| 295 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 296 | void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, |
| 297 | const std::string& error); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 298 | void PostCreateSessionDescriptionFailure( |
| 299 | CreateSessionDescriptionObserver* observer, |
| 300 | const std::string& error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 301 | |
| 302 | bool IsClosed() const { |
| 303 | return signaling_state_ == PeerConnectionInterface::kClosed; |
| 304 | } |
| 305 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 306 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 307 | // the local MediaStreams and DataChannels. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 308 | void GetOptionsForOffer( |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 309 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 310 | cricket::MediaSessionOptions* session_options); |
| 311 | |
| 312 | // Returns a MediaSessionOptions struct with options decided by |
| 313 | // |constraints|, the local MediaStreams and DataChannels. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 314 | void GetOptionsForAnswer(const RTCOfferAnswerOptions& options, |
| 315 | cricket::MediaSessionOptions* session_options); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 316 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 317 | // Generates MediaDescriptionOptions for the |session_opts| based on existing |
| 318 | // local description or remote description. |
| 319 | void GenerateMediaDescriptionOptions( |
| 320 | const SessionDescriptionInterface* session_desc, |
| 321 | cricket::RtpTransceiverDirection audio_direction, |
| 322 | cricket::RtpTransceiverDirection video_direction, |
| 323 | rtc::Optional<size_t>* audio_index, |
| 324 | rtc::Optional<size_t>* video_index, |
| 325 | rtc::Optional<size_t>* data_index, |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 326 | cricket::MediaSessionOptions* session_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 327 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 328 | // Remove all local and remote tracks of type |media_type|. |
| 329 | // Called when a media type is rejected (m-line set to port 0). |
| 330 | void RemoveTracks(cricket::MediaType media_type); |
| 331 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 332 | // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 333 | // and existing MediaStreamTracks are removed if there is no corresponding |
| 334 | // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 335 | // is created if it doesn't exist; if false, it's removed if it exists. |
| 336 | // |media_type| is the type of the |streams| and can be either audio or video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 337 | // If a new MediaStream is created it is added to |new_streams|. |
| 338 | void UpdateRemoteStreamsList( |
| 339 | const std::vector<cricket::StreamParams>& streams, |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 340 | bool default_track_needed, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 341 | cricket::MediaType media_type, |
| 342 | StreamCollection* new_streams); |
| 343 | |
| 344 | // Triggered when a remote track has been seen for the first time in a remote |
| 345 | // session description. It creates a remote MediaStreamTrackInterface |
| 346 | // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
| 347 | void OnRemoteTrackSeen(const std::string& stream_label, |
| 348 | const std::string& track_id, |
| 349 | uint32_t ssrc, |
| 350 | cricket::MediaType media_type); |
| 351 | |
| 352 | // Triggered when a remote track has been removed from a remote session |
| 353 | // description. It removes the remote track with id |track_id| from a remote |
| 354 | // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
| 355 | void OnRemoteTrackRemoved(const std::string& stream_label, |
| 356 | const std::string& track_id, |
| 357 | cricket::MediaType media_type); |
| 358 | |
| 359 | // Finds remote MediaStreams without any tracks and removes them from |
| 360 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 361 | // exist. |
| 362 | void UpdateEndedRemoteMediaStreams(); |
| 363 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 364 | // Loops through the vector of |streams| and finds added and removed |
| 365 | // StreamParams since last time this method was called. |
| 366 | // For each new or removed StreamParam, OnLocalTrackSeen or |
| 367 | // OnLocalTrackRemoved is invoked. |
| 368 | void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, |
| 369 | cricket::MediaType media_type); |
| 370 | |
| 371 | // Triggered when a local track has been seen for the first time in a local |
| 372 | // session description. |
| 373 | // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
| 374 | // streams in the local SessionDescription can be mapped to a MediaStreamTrack |
| 375 | // in a MediaStream in |local_streams_| |
| 376 | void OnLocalTrackSeen(const std::string& stream_label, |
| 377 | const std::string& track_id, |
| 378 | uint32_t ssrc, |
| 379 | cricket::MediaType media_type); |
| 380 | |
| 381 | // Triggered when a local track has been removed from a local session |
| 382 | // description. |
| 383 | // This method triggers DestroyAudioSender or DestroyVideoSender if a stream |
| 384 | // has been removed from the local SessionDescription and the stream can be |
| 385 | // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|. |
| 386 | void OnLocalTrackRemoved(const std::string& stream_label, |
| 387 | const std::string& track_id, |
| 388 | uint32_t ssrc, |
| 389 | cricket::MediaType media_type); |
| 390 | |
| 391 | void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 392 | void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 393 | void UpdateClosingRtpDataChannels( |
| 394 | const std::vector<std::string>& active_channels, |
| 395 | bool is_local_update); |
| 396 | void CreateRemoteRtpDataChannel(const std::string& label, |
| 397 | uint32_t remote_ssrc); |
| 398 | |
| 399 | // Creates channel and adds it to the collection of DataChannels that will |
| 400 | // be offered in a SessionDescription. |
| 401 | rtc::scoped_refptr<DataChannel> InternalCreateDataChannel( |
| 402 | const std::string& label, |
| 403 | const InternalDataChannelInit* config); |
| 404 | |
| 405 | // Checks if any data channel has been added. |
| 406 | bool HasDataChannels() const; |
| 407 | |
| 408 | void AllocateSctpSids(rtc::SSLRole role); |
| 409 | void OnSctpDataChannelClosed(DataChannel* channel); |
| 410 | |
| 411 | // Notifications from WebRtcSession relating to BaseChannels. |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 412 | void OnVoiceChannelCreated(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 413 | void OnVoiceChannelDestroyed(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 414 | void OnVideoChannelCreated(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 415 | void OnVideoChannelDestroyed(); |
| 416 | void OnDataChannelCreated(); |
| 417 | void OnDataChannelDestroyed(); |
| 418 | // Called when the cricket::DataChannel receives a message indicating that a |
| 419 | // webrtc::DataChannel should be opened. |
| 420 | void OnDataChannelOpenMessage(const std::string& label, |
| 421 | const InternalDataChannelInit& config); |
| 422 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 423 | bool HasRtpSender(cricket::MediaType type) const; |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 424 | RtpSenderInternal* FindSenderById(const std::string& id); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 425 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 426 | std::vector<rtc::scoped_refptr< |
| 427 | RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 428 | FindSenderForTrack(MediaStreamTrackInterface* track); |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 429 | std::vector<rtc::scoped_refptr< |
| 430 | RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 431 | FindReceiverForTrack(const std::string& track_id); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 432 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 433 | TrackInfos* GetRemoteTracks(cricket::MediaType media_type); |
| 434 | TrackInfos* GetLocalTracks(cricket::MediaType media_type); |
| 435 | const TrackInfo* FindTrackInfo(const TrackInfos& infos, |
| 436 | const std::string& stream_label, |
| 437 | const std::string track_id) const; |
| 438 | |
| 439 | // Returns the specified SCTP DataChannel in sctp_data_channels_, |
| 440 | // or nullptr if not found. |
| 441 | DataChannel* FindDataChannelBySid(int sid) const; |
| 442 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 443 | // Called when first configuring the port allocator. |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 444 | bool InitializePortAllocator_n(const RTCConfiguration& configuration); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 445 | // Called when SetConfiguration is called to apply the supported subset |
| 446 | // of the configuration on the network thread. |
| 447 | bool ReconfigurePortAllocator_n( |
| 448 | const cricket::ServerAddresses& stun_servers, |
| 449 | const std::vector<cricket::RelayServerConfig>& turn_servers, |
| 450 | IceTransportsType type, |
| 451 | int candidate_pool_size, |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 452 | bool prune_turn_ports, |
| 453 | webrtc::TurnCustomizer* turn_customizer); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 454 | |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 455 | // Starts output of an RTC event log to the given output object. |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 456 | // This function should only be called from the worker thread. |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 457 | bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output); |
| 458 | |
Elad Alon | acb2417 | 2017-10-06 14:32:13 +0200 | [diff] [blame] | 459 | // Stops recording an RTC event log. |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 460 | // This function should only be called from the worker thread. |
| 461 | void StopRtcEventLog_w(); |
| 462 | |
Steve Anton | 038834f | 2017-07-14 15:59:59 -0700 | [diff] [blame] | 463 | // Ensures the configuration doesn't have any parameters with invalid values, |
| 464 | // or values that conflict with other parameters. |
| 465 | // |
| 466 | // Returns RTCError::OK() if there are no issues. |
| 467 | RTCError ValidateConfiguration(const RTCConfiguration& config) const; |
| 468 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 469 | // Storing the factory as a scoped reference pointer ensures that the memory |
| 470 | // in the PeerConnectionFactoryImpl remains available as long as the |
| 471 | // PeerConnection is running. It is passed to PeerConnection as a raw pointer. |
| 472 | // However, since the reference counting is done in the |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 473 | // PeerConnectionFactoryInterface all instances created using the raw pointer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 474 | // will refer to the same reference count. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 475 | rtc::scoped_refptr<PeerConnectionFactory> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 476 | PeerConnectionObserver* observer_; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 477 | UMAObserver* uma_observer_; |
terelius | 3386025 | 2017-05-12 23:37:18 -0700 | [diff] [blame] | 478 | |
| 479 | // The EventLog needs to outlive |call_| (and any other object that uses it). |
| 480 | std::unique_ptr<RtcEventLog> event_log_; |
| 481 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 482 | SignalingState signaling_state_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 483 | IceConnectionState ice_connection_state_; |
| 484 | IceGatheringState ice_gathering_state_; |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 485 | PeerConnectionInterface::RTCConfiguration configuration_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 486 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 487 | std::unique_ptr<cricket::PortAllocator> port_allocator_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 488 | |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 489 | // One PeerConnection has only one RTCP CNAME. |
| 490 | // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9 |
| 491 | std::string rtcp_cname_; |
| 492 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 493 | // Streams added via AddStream. |
| 494 | rtc::scoped_refptr<StreamCollection> local_streams_; |
| 495 | // Streams created as a result of SetRemoteDescription. |
| 496 | rtc::scoped_refptr<StreamCollection> remote_streams_; |
| 497 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 498 | std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_; |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 499 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 500 | // These lists store track info seen in local/remote descriptions. |
| 501 | TrackInfos remote_audio_tracks_; |
| 502 | TrackInfos remote_video_tracks_; |
| 503 | TrackInfos local_audio_tracks_; |
| 504 | TrackInfos local_video_tracks_; |
| 505 | |
| 506 | SctpSidAllocator sid_allocator_; |
| 507 | // label -> DataChannel |
| 508 | std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; |
| 509 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; |
deadbeef | bd29246 | 2015-12-14 18:15:29 -0800 | [diff] [blame] | 510 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 511 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 512 | bool remote_peer_supports_msid_ = false; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 513 | |
terelius | 3386025 | 2017-05-12 23:37:18 -0700 | [diff] [blame] | 514 | std::unique_ptr<Call> call_; |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 515 | WebRtcSession* session_; |
| 516 | std::unique_ptr<WebRtcSession> owned_session_; |
terelius | 3386025 | 2017-05-12 23:37:18 -0700 | [diff] [blame] | 517 | std::unique_ptr<StatsCollector> stats_; // A pointer is passed to senders_ |
| 518 | rtc::scoped_refptr<RTCStatsCollector> stats_collector_; |
| 519 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 520 | std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>> |
| 521 | senders_; |
| 522 | std::vector< |
| 523 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>> |
| 524 | receivers_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 525 | }; |
| 526 | |
| 527 | } // namespace webrtc |
| 528 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 529 | #endif // PC_PEERCONNECTION_H_ |