Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 1 | /* |
kjellander | 95ed4e6 | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 3 | * |
kjellander | 95ed4e6 | 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. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 9 | */ |
| 10 | |
ossu | 25e4ac7 | 2017-01-23 12:56:25 | [diff] [blame] | 11 | #ifndef WEBRTC_PC_PEERCONNECTION_H_ |
| 12 | #define WEBRTC_PC_PEERCONNECTION_H_ |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 13 | |
| 14 | #include <string> |
perkj | 3c013b3 | 2016-03-24 10:16:19 | [diff] [blame] | 15 | #include <map> |
kwiberg | b4bfca4 | 2016-04-27 13:47:29 | [diff] [blame] | 16 | #include <memory> |
perkj | 3c013b3 | 2016-03-24 10:16:19 | [diff] [blame] | 17 | #include <vector> |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 18 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 19 | #include "webrtc/api/peerconnectioninterface.h" |
ossu | 25e4ac7 | 2017-01-23 12:56:25 | [diff] [blame] | 20 | #include "webrtc/pc/peerconnectionfactory.h" |
| 21 | #include "webrtc/pc/rtcstatscollector.h" |
| 22 | #include "webrtc/pc/rtpreceiver.h" |
| 23 | #include "webrtc/pc/rtpsender.h" |
| 24 | #include "webrtc/pc/statscollector.h" |
| 25 | #include "webrtc/pc/streamcollection.h" |
| 26 | #include "webrtc/pc/webrtcsession.h" |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | |
| 30 | class MediaStreamObserver; |
perkj | 3cf02c5 | 2016-03-10 17:32:00 | [diff] [blame] | 31 | class VideoRtpReceiver; |
skvlad | 14ccce8 | 2016-10-07 18:53:05 | [diff] [blame] | 32 | class RtcEventLog; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 33 | |
| 34 | // Populates |session_options| from |rtc_options|, and returns true if options |
| 35 | // are valid. |
deadbeef | 516d536 | 2016-02-24 01:24:52 | [diff] [blame] | 36 | // |session_options|->transport_options map entries must exist in order for |
| 37 | // them to be populated from |rtc_options|. |
hta | dbc360d | 2016-03-04 10:51:39 | [diff] [blame] | 38 | bool ExtractMediaSessionOptions( |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 39 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
hta | 7436f8c | 2016-03-10 21:35:55 | [diff] [blame] | 40 | bool is_offer, |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 41 | cricket::MediaSessionOptions* session_options); |
| 42 | |
| 43 | // Populates |session_options| from |constraints|, and returns true if all |
| 44 | // mandatory constraints are satisfied. |
deadbeef | 516d536 | 2016-02-24 01:24:52 | [diff] [blame] | 45 | // Assumes that |session_options|->transport_options map entries exist. |
hta | dbc360d | 2016-03-04 10:51:39 | [diff] [blame] | 46 | // Will also set defaults if corresponding constraints are not present: |
| 47 | // recv_audio=true, recv_video=true, bundle_enabled=true. |
| 48 | // Other fields will be left with existing values. |
| 49 | // |
| 50 | // Deprecated. Will be removed once callers that use constraints are gone. |
| 51 | // TODO(hta): Remove when callers are gone. |
| 52 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=5617 |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 53 | bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
| 54 | cricket::MediaSessionOptions* session_options); |
| 55 | |
| 56 | // Parses the URLs for each server in |servers| to build |stun_servers| and |
deadbeef | a496afa | 2017-01-11 20:28:30 | [diff] [blame] | 57 | // |turn_servers|. Can return SYNTAX_ERROR if the URL is malformed, or |
| 58 | // INVALID_PARAMETER if a TURN server is missing |username| or |password|. |
| 59 | RTCErrorType ParseIceServers( |
| 60 | const PeerConnectionInterface::IceServers& servers, |
| 61 | cricket::ServerAddresses* stun_servers, |
| 62 | std::vector<cricket::RelayServerConfig>* turn_servers); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 63 | |
| 64 | // PeerConnection implements the PeerConnectionInterface interface. |
| 65 | // It uses WebRtcSession to implement the PeerConnection functionality. |
| 66 | class PeerConnection : public PeerConnectionInterface, |
| 67 | public IceObserver, |
| 68 | public rtc::MessageHandler, |
| 69 | public sigslot::has_slots<> { |
| 70 | public: |
| 71 | explicit PeerConnection(PeerConnectionFactory* factory); |
| 72 | |
| 73 | bool Initialize( |
| 74 | const PeerConnectionInterface::RTCConfiguration& configuration, |
kwiberg | b4bfca4 | 2016-04-27 13:47:29 | [diff] [blame] | 75 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | b894201 | 2016-06-01 09:44:18 | [diff] [blame] | 76 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 77 | PeerConnectionObserver* observer); |
| 78 | |
| 79 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override; |
| 80 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override; |
| 81 | bool AddStream(MediaStreamInterface* local_stream) override; |
| 82 | void RemoveStream(MediaStreamInterface* local_stream) override; |
| 83 | |
| 84 | rtc::scoped_refptr<RtpSenderInterface> AddTrack( |
| 85 | MediaStreamTrackInterface* track, |
| 86 | std::vector<MediaStreamInterface*> streams) override; |
| 87 | bool RemoveTrack(RtpSenderInterface* sender) override; |
| 88 | |
| 89 | virtual WebRtcSession* session() { return session_.get(); } |
| 90 | |
| 91 | rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( |
| 92 | AudioTrackInterface* track) override; |
| 93 | |
| 94 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
| 95 | const std::string& kind, |
| 96 | const std::string& stream_id) override; |
| 97 | |
| 98 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 99 | const override; |
| 100 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 101 | const override; |
| 102 | |
| 103 | rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
| 104 | const std::string& label, |
| 105 | const DataChannelInit* config) override; |
| 106 | bool GetStats(StatsObserver* observer, |
| 107 | webrtc::MediaStreamTrackInterface* track, |
| 108 | StatsOutputLevel level) override; |
hbos | 4220421 | 2016-09-16 06:33:01 | [diff] [blame] | 109 | void GetStats(RTCStatsCollectorCallback* callback) override; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 110 | |
| 111 | SignalingState signaling_state() override; |
| 112 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 113 | IceConnectionState ice_connection_state() override; |
| 114 | IceGatheringState ice_gathering_state() override; |
| 115 | |
| 116 | const SessionDescriptionInterface* local_description() const override; |
| 117 | const SessionDescriptionInterface* remote_description() const override; |
deadbeef | c7d4f49 | 2016-12-21 01:56:17 | [diff] [blame] | 118 | const SessionDescriptionInterface* current_local_description() const override; |
| 119 | const SessionDescriptionInterface* current_remote_description() |
| 120 | const override; |
| 121 | const SessionDescriptionInterface* pending_local_description() const override; |
| 122 | const SessionDescriptionInterface* pending_remote_description() |
| 123 | const override; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 124 | |
| 125 | // JSEP01 |
hta | dbc360d | 2016-03-04 10:51:39 | [diff] [blame] | 126 | // Deprecated, use version without constraints. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 127 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 128 | const MediaConstraintsInterface* constraints) override; |
| 129 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 130 | const RTCOfferAnswerOptions& options) override; |
hta | dbc360d | 2016-03-04 10:51:39 | [diff] [blame] | 131 | // Deprecated, use version without constraints. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 132 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 133 | const MediaConstraintsInterface* constraints) override; |
hta | dbc360d | 2016-03-04 10:51:39 | [diff] [blame] | 134 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 135 | const RTCOfferAnswerOptions& options) override; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 136 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 137 | SessionDescriptionInterface* desc) override; |
| 138 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 139 | SessionDescriptionInterface* desc) override; |
deadbeef | 4d0d012 | 2016-11-17 03:42:04 | [diff] [blame] | 140 | PeerConnectionInterface::RTCConfiguration GetConfiguration() override; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 141 | bool SetConfiguration( |
deadbeef | a496afa | 2017-01-11 20:28:30 | [diff] [blame] | 142 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 143 | RTCError* error) override; |
| 144 | bool SetConfiguration( |
| 145 | const PeerConnectionInterface::RTCConfiguration& configuration) override { |
| 146 | return SetConfiguration(configuration, nullptr); |
| 147 | } |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 148 | bool AddIceCandidate(const IceCandidateInterface* candidate) override; |
Honghai Zhang | 615cf0b | 2016-03-14 18:59:18 | [diff] [blame] | 149 | bool RemoveIceCandidates( |
| 150 | const std::vector<cricket::Candidate>& candidates) override; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 151 | |
| 152 | void RegisterUMAObserver(UMAObserver* observer) override; |
| 153 | |
ivoc | 23ea12e | 2016-07-04 14:06:55 | [diff] [blame] | 154 | bool StartRtcEventLog(rtc::PlatformFile file, |
| 155 | int64_t max_size_bytes) override; |
| 156 | void StopRtcEventLog() override; |
| 157 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 158 | void Close() override; |
| 159 | |
hbos | 0177daa | 2016-11-14 09:41:09 | [diff] [blame] | 160 | sigslot::signal1<DataChannel*> SignalDataChannelCreated; |
| 161 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 162 | // Virtual for unit tests. |
| 163 | virtual const std::vector<rtc::scoped_refptr<DataChannel>>& |
| 164 | sctp_data_channels() const { |
| 165 | return sctp_data_channels_; |
perkj | 3c013b3 | 2016-03-24 10:16:19 | [diff] [blame] | 166 | } |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 167 | |
| 168 | protected: |
| 169 | ~PeerConnection() override; |
| 170 | |
| 171 | private: |
| 172 | struct TrackInfo { |
| 173 | TrackInfo() : ssrc(0) {} |
| 174 | TrackInfo(const std::string& stream_label, |
| 175 | const std::string track_id, |
| 176 | uint32_t ssrc) |
| 177 | : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {} |
| 178 | bool operator==(const TrackInfo& other) { |
| 179 | return this->stream_label == other.stream_label && |
| 180 | this->track_id == other.track_id && this->ssrc == other.ssrc; |
| 181 | } |
| 182 | std::string stream_label; |
| 183 | std::string track_id; |
| 184 | uint32_t ssrc; |
| 185 | }; |
| 186 | typedef std::vector<TrackInfo> TrackInfos; |
| 187 | |
| 188 | // Implements MessageHandler. |
| 189 | void OnMessage(rtc::Message* msg) override; |
| 190 | |
| 191 | void CreateAudioReceiver(MediaStreamInterface* stream, |
perkj | 3c013b3 | 2016-03-24 10:16:19 | [diff] [blame] | 192 | const std::string& track_id, |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 193 | uint32_t ssrc); |
perkj | 3cf02c5 | 2016-03-10 17:32:00 | [diff] [blame] | 194 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 195 | void CreateVideoReceiver(MediaStreamInterface* stream, |
perkj | 3cf02c5 | 2016-03-10 17:32:00 | [diff] [blame] | 196 | const std::string& track_id, |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 197 | uint32_t ssrc); |
perkj | 3c013b3 | 2016-03-24 10:16:19 | [diff] [blame] | 198 | void DestroyReceiver(const std::string& track_id); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 199 | void DestroyAudioSender(MediaStreamInterface* stream, |
| 200 | AudioTrackInterface* audio_track, |
| 201 | uint32_t ssrc); |
| 202 | void DestroyVideoSender(MediaStreamInterface* stream, |
| 203 | VideoTrackInterface* video_track); |
| 204 | |
| 205 | // Implements IceObserver |
| 206 | void OnIceConnectionChange(IceConnectionState new_state) override; |
| 207 | void OnIceGatheringChange(IceGatheringState new_state) override; |
| 208 | void OnIceCandidate(const IceCandidateInterface* candidate) override; |
Honghai Zhang | 615cf0b | 2016-03-14 18:59:18 | [diff] [blame] | 209 | void OnIceCandidatesRemoved( |
| 210 | const std::vector<cricket::Candidate>& candidates) override; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 211 | void OnIceConnectionReceivingChange(bool receiving) override; |
| 212 | |
| 213 | // Signals from WebRtcSession. |
| 214 | void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state); |
| 215 | void ChangeSignalingState(SignalingState signaling_state); |
| 216 | |
| 217 | // Signals from MediaStreamObserver. |
| 218 | void OnAudioTrackAdded(AudioTrackInterface* track, |
| 219 | MediaStreamInterface* stream); |
| 220 | void OnAudioTrackRemoved(AudioTrackInterface* track, |
| 221 | MediaStreamInterface* stream); |
| 222 | void OnVideoTrackAdded(VideoTrackInterface* track, |
| 223 | MediaStreamInterface* stream); |
| 224 | void OnVideoTrackRemoved(VideoTrackInterface* track, |
| 225 | MediaStreamInterface* stream); |
| 226 | |
| 227 | rtc::Thread* signaling_thread() const { |
| 228 | return factory_->signaling_thread(); |
| 229 | } |
| 230 | |
deadbeef | e0e24f9 | 2016-05-18 23:55:30 | [diff] [blame] | 231 | rtc::Thread* network_thread() const { return factory_->network_thread(); } |
Taylor Brandstetter | a52f9db | 2016-05-13 15:15:11 | [diff] [blame] | 232 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 233 | void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, |
| 234 | const std::string& error); |
| 235 | void PostCreateSessionDescriptionFailure( |
| 236 | CreateSessionDescriptionObserver* observer, |
| 237 | const std::string& error); |
| 238 | |
| 239 | bool IsClosed() const { |
| 240 | return signaling_state_ == PeerConnectionInterface::kClosed; |
| 241 | } |
| 242 | |
| 243 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 244 | // the local MediaStreams and DataChannels. |
| 245 | virtual bool GetOptionsForOffer( |
| 246 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 247 | cricket::MediaSessionOptions* session_options); |
| 248 | |
| 249 | // Returns a MediaSessionOptions struct with options decided by |
| 250 | // |constraints|, the local MediaStreams and DataChannels. |
hta | dbc360d | 2016-03-04 10:51:39 | [diff] [blame] | 251 | // Deprecated, use version without constraints. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 252 | virtual bool GetOptionsForAnswer( |
| 253 | const MediaConstraintsInterface* constraints, |
| 254 | cricket::MediaSessionOptions* session_options); |
hta | dbc360d | 2016-03-04 10:51:39 | [diff] [blame] | 255 | virtual bool GetOptionsForAnswer( |
| 256 | const RTCOfferAnswerOptions& options, |
| 257 | cricket::MediaSessionOptions* session_options); |
| 258 | |
Honghai Zhang | 774bc41 | 2016-08-31 15:18:11 | [diff] [blame] | 259 | void InitializeOptionsForAnswer( |
| 260 | cricket::MediaSessionOptions* session_options); |
| 261 | |
hta | dbc360d | 2016-03-04 10:51:39 | [diff] [blame] | 262 | // Helper function for options processing. |
| 263 | // Deprecated. |
| 264 | virtual void FinishOptionsForAnswer( |
| 265 | cricket::MediaSessionOptions* session_options); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 266 | |
| 267 | // Remove all local and remote tracks of type |media_type|. |
| 268 | // Called when a media type is rejected (m-line set to port 0). |
| 269 | void RemoveTracks(cricket::MediaType media_type); |
| 270 | |
| 271 | // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 272 | // and existing MediaStreamTracks are removed if there is no corresponding |
| 273 | // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 274 | // is created if it doesn't exist; if false, it's removed if it exists. |
| 275 | // |media_type| is the type of the |streams| and can be either audio or video. |
| 276 | // If a new MediaStream is created it is added to |new_streams|. |
| 277 | void UpdateRemoteStreamsList( |
| 278 | const std::vector<cricket::StreamParams>& streams, |
| 279 | bool default_track_needed, |
| 280 | cricket::MediaType media_type, |
| 281 | StreamCollection* new_streams); |
| 282 | |
| 283 | // Triggered when a remote track has been seen for the first time in a remote |
| 284 | // session description. It creates a remote MediaStreamTrackInterface |
| 285 | // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
| 286 | void OnRemoteTrackSeen(const std::string& stream_label, |
| 287 | const std::string& track_id, |
| 288 | uint32_t ssrc, |
| 289 | cricket::MediaType media_type); |
| 290 | |
| 291 | // Triggered when a remote track has been removed from a remote session |
| 292 | // description. It removes the remote track with id |track_id| from a remote |
| 293 | // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
| 294 | void OnRemoteTrackRemoved(const std::string& stream_label, |
| 295 | const std::string& track_id, |
| 296 | cricket::MediaType media_type); |
| 297 | |
| 298 | // Finds remote MediaStreams without any tracks and removes them from |
| 299 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 300 | // exist. |
| 301 | void UpdateEndedRemoteMediaStreams(); |
| 302 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 303 | // Loops through the vector of |streams| and finds added and removed |
| 304 | // StreamParams since last time this method was called. |
| 305 | // For each new or removed StreamParam, OnLocalTrackSeen or |
| 306 | // OnLocalTrackRemoved is invoked. |
| 307 | void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, |
| 308 | cricket::MediaType media_type); |
| 309 | |
| 310 | // Triggered when a local track has been seen for the first time in a local |
| 311 | // session description. |
| 312 | // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
| 313 | // streams in the local SessionDescription can be mapped to a MediaStreamTrack |
| 314 | // in a MediaStream in |local_streams_| |
| 315 | void OnLocalTrackSeen(const std::string& stream_label, |
| 316 | const std::string& track_id, |
| 317 | uint32_t ssrc, |
| 318 | cricket::MediaType media_type); |
| 319 | |
| 320 | // Triggered when a local track has been removed from a local session |
| 321 | // description. |
| 322 | // This method triggers DestroyAudioSender or DestroyVideoSender if a stream |
| 323 | // has been removed from the local SessionDescription and the stream can be |
| 324 | // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|. |
| 325 | void OnLocalTrackRemoved(const std::string& stream_label, |
| 326 | const std::string& track_id, |
| 327 | uint32_t ssrc, |
| 328 | cricket::MediaType media_type); |
| 329 | |
| 330 | void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 331 | void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 332 | void UpdateClosingRtpDataChannels( |
| 333 | const std::vector<std::string>& active_channels, |
| 334 | bool is_local_update); |
| 335 | void CreateRemoteRtpDataChannel(const std::string& label, |
| 336 | uint32_t remote_ssrc); |
| 337 | |
| 338 | // Creates channel and adds it to the collection of DataChannels that will |
| 339 | // be offered in a SessionDescription. |
| 340 | rtc::scoped_refptr<DataChannel> InternalCreateDataChannel( |
| 341 | const std::string& label, |
| 342 | const InternalDataChannelInit* config); |
| 343 | |
| 344 | // Checks if any data channel has been added. |
| 345 | bool HasDataChannels() const; |
| 346 | |
| 347 | void AllocateSctpSids(rtc::SSLRole role); |
| 348 | void OnSctpDataChannelClosed(DataChannel* channel); |
| 349 | |
| 350 | // Notifications from WebRtcSession relating to BaseChannels. |
Taylor Brandstetter | bc1f6bd | 2016-06-27 23:30:35 | [diff] [blame] | 351 | void OnVoiceChannelCreated(); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 352 | void OnVoiceChannelDestroyed(); |
Taylor Brandstetter | bc1f6bd | 2016-06-27 23:30:35 | [diff] [blame] | 353 | void OnVideoChannelCreated(); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 354 | void OnVideoChannelDestroyed(); |
| 355 | void OnDataChannelCreated(); |
| 356 | void OnDataChannelDestroyed(); |
| 357 | // Called when the cricket::DataChannel receives a message indicating that a |
| 358 | // webrtc::DataChannel should be opened. |
| 359 | void OnDataChannelOpenMessage(const std::string& label, |
| 360 | const InternalDataChannelInit& config); |
| 361 | |
deadbeef | 0fec214 | 2016-06-06 21:27:39 | [diff] [blame] | 362 | RtpSenderInternal* FindSenderById(const std::string& id); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 363 | |
deadbeef | 0fec214 | 2016-06-06 21:27:39 | [diff] [blame] | 364 | std::vector<rtc::scoped_refptr< |
| 365 | RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 366 | FindSenderForTrack(MediaStreamTrackInterface* track); |
deadbeef | 0fec214 | 2016-06-06 21:27:39 | [diff] [blame] | 367 | std::vector<rtc::scoped_refptr< |
| 368 | RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator |
perkj | 3c013b3 | 2016-03-24 10:16:19 | [diff] [blame] | 369 | FindReceiverForTrack(const std::string& track_id); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 370 | |
| 371 | TrackInfos* GetRemoteTracks(cricket::MediaType media_type); |
| 372 | TrackInfos* GetLocalTracks(cricket::MediaType media_type); |
| 373 | const TrackInfo* FindTrackInfo(const TrackInfos& infos, |
| 374 | const std::string& stream_label, |
| 375 | const std::string track_id) const; |
| 376 | |
| 377 | // Returns the specified SCTP DataChannel in sctp_data_channels_, |
| 378 | // or nullptr if not found. |
| 379 | DataChannel* FindDataChannelBySid(int sid) const; |
| 380 | |
Taylor Brandstetter | a52f9db | 2016-05-13 15:15:11 | [diff] [blame] | 381 | // Called when first configuring the port allocator. |
deadbeef | e0e24f9 | 2016-05-18 23:55:30 | [diff] [blame] | 382 | bool InitializePortAllocator_n(const RTCConfiguration& configuration); |
deadbeef | a496afa | 2017-01-11 20:28:30 | [diff] [blame] | 383 | // Called when SetConfiguration is called to apply the supported subset |
| 384 | // of the configuration on the network thread. |
| 385 | bool ReconfigurePortAllocator_n( |
| 386 | const cricket::ServerAddresses& stun_servers, |
| 387 | const std::vector<cricket::RelayServerConfig>& turn_servers, |
| 388 | IceTransportsType type, |
| 389 | int candidate_pool_size, |
| 390 | bool prune_turn_ports); |
Taylor Brandstetter | a52f9db | 2016-05-13 15:15:11 | [diff] [blame] | 391 | |
ivoc | 23ea12e | 2016-07-04 14:06:55 | [diff] [blame] | 392 | // Starts recording an Rtc EventLog using the supplied platform file. |
| 393 | // This function should only be called from the worker thread. |
| 394 | bool StartRtcEventLog_w(rtc::PlatformFile file, int64_t max_size_bytes); |
| 395 | // Starts recording an Rtc EventLog using the supplied platform file. |
| 396 | // This function should only be called from the worker thread. |
| 397 | void StopRtcEventLog_w(); |
| 398 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 399 | // Storing the factory as a scoped reference pointer ensures that the memory |
| 400 | // in the PeerConnectionFactoryImpl remains available as long as the |
| 401 | // PeerConnection is running. It is passed to PeerConnection as a raw pointer. |
| 402 | // However, since the reference counting is done in the |
| 403 | // PeerConnectionFactoryInterface all instances created using the raw pointer |
| 404 | // will refer to the same reference count. |
| 405 | rtc::scoped_refptr<PeerConnectionFactory> factory_; |
| 406 | PeerConnectionObserver* observer_; |
| 407 | UMAObserver* uma_observer_; |
| 408 | SignalingState signaling_state_; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 409 | IceConnectionState ice_connection_state_; |
| 410 | IceGatheringState ice_gathering_state_; |
deadbeef | 4d0d012 | 2016-11-17 03:42:04 | [diff] [blame] | 411 | PeerConnectionInterface::RTCConfiguration configuration_; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 412 | |
kwiberg | b4bfca4 | 2016-04-27 13:47:29 | [diff] [blame] | 413 | std::unique_ptr<cricket::PortAllocator> port_allocator_; |
skvlad | 14ccce8 | 2016-10-07 18:53:05 | [diff] [blame] | 414 | // The EventLog needs to outlive the media controller. |
| 415 | std::unique_ptr<RtcEventLog> event_log_; |
kwiberg | b4bfca4 | 2016-04-27 13:47:29 | [diff] [blame] | 416 | std::unique_ptr<MediaControllerInterface> media_controller_; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 417 | |
zhihuang | 8b8f8ff | 2016-05-07 01:40:30 | [diff] [blame] | 418 | // One PeerConnection has only one RTCP CNAME. |
| 419 | // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9 |
| 420 | std::string rtcp_cname_; |
| 421 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 422 | // Streams added via AddStream. |
| 423 | rtc::scoped_refptr<StreamCollection> local_streams_; |
| 424 | // Streams created as a result of SetRemoteDescription. |
| 425 | rtc::scoped_refptr<StreamCollection> remote_streams_; |
| 426 | |
kwiberg | b4bfca4 | 2016-04-27 13:47:29 | [diff] [blame] | 427 | std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 428 | |
| 429 | // These lists store track info seen in local/remote descriptions. |
| 430 | TrackInfos remote_audio_tracks_; |
| 431 | TrackInfos remote_video_tracks_; |
| 432 | TrackInfos local_audio_tracks_; |
| 433 | TrackInfos local_video_tracks_; |
| 434 | |
| 435 | SctpSidAllocator sid_allocator_; |
| 436 | // label -> DataChannel |
| 437 | std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; |
| 438 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; |
| 439 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_; |
| 440 | |
| 441 | bool remote_peer_supports_msid_ = false; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 442 | |
deadbeef | 0fec214 | 2016-06-06 21:27:39 | [diff] [blame] | 443 | std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>> |
| 444 | senders_; |
| 445 | std::vector< |
| 446 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>> |
| 447 | receivers_; |
kwiberg | b4bfca4 | 2016-04-27 13:47:29 | [diff] [blame] | 448 | std::unique_ptr<WebRtcSession> session_; |
kwiberg | b4bfca4 | 2016-04-27 13:47:29 | [diff] [blame] | 449 | std::unique_ptr<StatsCollector> stats_; |
hbos | 4220421 | 2016-09-16 06:33:01 | [diff] [blame] | 450 | rtc::scoped_refptr<RTCStatsCollector> stats_collector_; |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 451 | }; |
| 452 | |
| 453 | } // namespace webrtc |
| 454 | |
ossu | 25e4ac7 | 2017-01-23 12:56:25 | [diff] [blame] | 455 | #endif // WEBRTC_PC_PEERCONNECTION_H_ |