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