henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2012 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef TALK_APP_WEBRTC_PEERCONNECTION_H_ |
| 29 | #define TALK_APP_WEBRTC_PEERCONNECTION_H_ |
| 30 | |
| 31 | #include <string> |
| 32 | |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 33 | #include "talk/app/webrtc/dtlsidentitystore.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | #include "talk/app/webrtc/peerconnectionfactory.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 35 | #include "talk/app/webrtc/peerconnectioninterface.h" |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 36 | #include "talk/app/webrtc/rtpreceiverinterface.h" |
| 37 | #include "talk/app/webrtc/rtpsenderinterface.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | #include "talk/app/webrtc/statscollector.h" |
| 39 | #include "talk/app/webrtc/streamcollection.h" |
| 40 | #include "talk/app/webrtc/webrtcsession.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 41 | #include "webrtc/base/scoped_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | |
| 43 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 45 | class RemoteMediaStreamFactory; |
| 46 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration> |
| 48 | StunConfigurations; |
| 49 | typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration> |
| 50 | TurnConfigurations; |
| 51 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 52 | // Populates |session_options| from |rtc_options|, and returns true if options |
| 53 | // are valid. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 54 | bool ConvertRtcOptionsForOffer( |
| 55 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 56 | cricket::MediaSessionOptions* session_options); |
| 57 | |
| 58 | // Populates |session_options| from |constraints|, and returns true if all |
| 59 | // mandatory constraints are satisfied. |
| 60 | bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
| 61 | cricket::MediaSessionOptions* session_options); |
| 62 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 63 | // Parses the URLs for each server in |servers| to build |stun_config| and |
| 64 | // |turn_config|. |
| 65 | bool ParseIceServers(const PeerConnectionInterface::IceServers& servers, |
| 66 | StunConfigurations* stun_config, |
| 67 | TurnConfigurations* turn_config); |
| 68 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 69 | // PeerConnection implements the PeerConnectionInterface interface. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 70 | // It uses WebRtcSession to implement the PeerConnection functionality. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 71 | class PeerConnection : public PeerConnectionInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | public IceObserver, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 73 | public rtc::MessageHandler, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | public sigslot::has_slots<> { |
| 75 | public: |
| 76 | explicit PeerConnection(PeerConnectionFactory* factory); |
| 77 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 78 | // TODO(deadbeef): Remove this overload of Initialize once everyone is moved |
| 79 | // to the new version. |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 80 | bool Initialize( |
| 81 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 82 | const MediaConstraintsInterface* constraints, |
| 83 | PortAllocatorFactoryInterface* allocator_factory, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 84 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 85 | PeerConnectionObserver* observer); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 86 | |
| 87 | bool Initialize( |
| 88 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 89 | const MediaConstraintsInterface* constraints, |
| 90 | rtc::scoped_ptr<cricket::PortAllocator> allocator, |
| 91 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 92 | PeerConnectionObserver* observer); |
| 93 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 94 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override; |
| 95 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override; |
| 96 | bool AddStream(MediaStreamInterface* local_stream) override; |
| 97 | void RemoveStream(MediaStreamInterface* local_stream) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 99 | virtual WebRtcSession* session() { return session_.get(); } |
| 100 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 101 | rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( |
| 102 | AudioTrackInterface* track) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame^] | 104 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
| 105 | const std::string& kind) override; |
| 106 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 107 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 108 | const override; |
| 109 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 110 | const override; |
| 111 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 112 | rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | const std::string& label, |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 114 | const DataChannelInit* config) override; |
| 115 | bool GetStats(StatsObserver* observer, |
| 116 | webrtc::MediaStreamTrackInterface* track, |
| 117 | StatsOutputLevel level) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 119 | SignalingState signaling_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | |
| 121 | // TODO(bemasc): Remove ice_state() when callers are removed. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 122 | IceState ice_state() override; |
| 123 | IceConnectionState ice_connection_state() override; |
| 124 | IceGatheringState ice_gathering_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 126 | const SessionDescriptionInterface* local_description() const override; |
| 127 | const SessionDescriptionInterface* remote_description() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | |
| 129 | // JSEP01 |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 130 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 131 | const MediaConstraintsInterface* constraints) override; |
| 132 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 133 | const RTCOfferAnswerOptions& options) override; |
| 134 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 135 | const MediaConstraintsInterface* constraints) override; |
| 136 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 137 | SessionDescriptionInterface* desc) override; |
| 138 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 139 | SessionDescriptionInterface* desc) override; |
| 140 | bool SetConfiguration( |
| 141 | const PeerConnectionInterface::RTCConfiguration& config) override; |
| 142 | bool AddIceCandidate(const IceCandidateInterface* candidate) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 144 | void RegisterUMAObserver(UMAObserver* observer) override; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 145 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 146 | void Close() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 147 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 148 | // Virtual for unit tests. |
| 149 | virtual const std::vector<rtc::scoped_refptr<DataChannel>>& |
| 150 | sctp_data_channels() const { |
| 151 | return sctp_data_channels_; |
| 152 | }; |
| 153 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 154 | protected: |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 155 | ~PeerConnection() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | |
| 157 | private: |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 158 | struct TrackInfo { |
| 159 | TrackInfo() : ssrc(0) {} |
| 160 | TrackInfo(const std::string& stream_label, |
| 161 | const std::string track_id, |
| 162 | uint32_t ssrc) |
| 163 | : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {} |
| 164 | std::string stream_label; |
| 165 | std::string track_id; |
| 166 | uint32_t ssrc; |
| 167 | }; |
| 168 | typedef std::vector<TrackInfo> TrackInfos; |
| 169 | |
| 170 | struct RemotePeerInfo { |
| 171 | RemotePeerInfo() |
| 172 | : msid_supported(false), |
| 173 | default_audio_track_needed(false), |
| 174 | default_video_track_needed(false) {} |
| 175 | // True if it has been discovered that the remote peer support MSID. |
| 176 | bool msid_supported; |
| 177 | // The remote peer indicates in the session description that audio will be |
| 178 | // sent but no MSID is given. |
| 179 | bool default_audio_track_needed; |
| 180 | // The remote peer indicates in the session description that video will be |
| 181 | // sent but no MSID is given. |
| 182 | bool default_video_track_needed; |
| 183 | |
| 184 | bool IsDefaultMediaStreamNeeded() { |
| 185 | return !msid_supported && |
| 186 | (default_audio_track_needed || default_video_track_needed); |
| 187 | } |
| 188 | }; |
| 189 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 190 | // Implements MessageHandler. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 191 | void OnMessage(rtc::Message* msg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 193 | void CreateAudioReceiver(MediaStreamInterface* stream, |
| 194 | AudioTrackInterface* audio_track, |
| 195 | uint32_t ssrc); |
| 196 | void CreateVideoReceiver(MediaStreamInterface* stream, |
| 197 | VideoTrackInterface* video_track, |
| 198 | uint32_t ssrc); |
| 199 | void DestroyAudioReceiver(MediaStreamInterface* stream, |
| 200 | AudioTrackInterface* audio_track); |
| 201 | void DestroyVideoReceiver(MediaStreamInterface* stream, |
| 202 | VideoTrackInterface* video_track); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 203 | void DestroyAudioSender(MediaStreamInterface* stream, |
| 204 | AudioTrackInterface* audio_track, |
| 205 | uint32_t ssrc); |
| 206 | void DestroyVideoSender(MediaStreamInterface* stream, |
| 207 | VideoTrackInterface* video_track); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | |
| 209 | // Implements IceObserver |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 210 | void OnIceConnectionChange(IceConnectionState new_state) override; |
| 211 | void OnIceGatheringChange(IceGatheringState new_state) override; |
| 212 | void OnIceCandidate(const IceCandidateInterface* candidate) override; |
| 213 | void OnIceComplete() override; |
| 214 | void OnIceConnectionReceivingChange(bool receiving) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | |
| 216 | // Signals from WebRtcSession. |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 217 | void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 218 | void ChangeSignalingState(SignalingState signaling_state); |
| 219 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 220 | rtc::Thread* signaling_thread() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | return factory_->signaling_thread(); |
| 222 | } |
| 223 | |
| 224 | void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, |
| 225 | const std::string& error); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 226 | void PostCreateSessionDescriptionFailure( |
| 227 | CreateSessionDescriptionObserver* observer, |
| 228 | const std::string& error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 229 | |
| 230 | bool IsClosed() const { |
| 231 | return signaling_state_ == PeerConnectionInterface::kClosed; |
| 232 | } |
| 233 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 234 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 235 | // the local MediaStreams and DataChannels. |
| 236 | virtual bool GetOptionsForOffer( |
| 237 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 238 | cricket::MediaSessionOptions* session_options); |
| 239 | |
| 240 | // Returns a MediaSessionOptions struct with options decided by |
| 241 | // |constraints|, the local MediaStreams and DataChannels. |
| 242 | virtual bool GetOptionsForAnswer( |
| 243 | const MediaConstraintsInterface* constraints, |
| 244 | cricket::MediaSessionOptions* session_options); |
| 245 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 246 | // Remove all local and remote tracks of type |media_type|. |
| 247 | // Called when a media type is rejected (m-line set to port 0). |
| 248 | void RemoveTracks(cricket::MediaType media_type); |
| 249 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 250 | // Makes sure a MediaStream Track is created for each StreamParam in |
| 251 | // |streams|. |media_type| is the type of the |streams| and can be either |
| 252 | // audio or video. |
| 253 | // If a new MediaStream is created it is added to |new_streams|. |
| 254 | void UpdateRemoteStreamsList( |
| 255 | const std::vector<cricket::StreamParams>& streams, |
| 256 | cricket::MediaType media_type, |
| 257 | StreamCollection* new_streams); |
| 258 | |
| 259 | // Triggered when a remote track has been seen for the first time in a remote |
| 260 | // session description. It creates a remote MediaStreamTrackInterface |
| 261 | // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
| 262 | void OnRemoteTrackSeen(const std::string& stream_label, |
| 263 | const std::string& track_id, |
| 264 | uint32_t ssrc, |
| 265 | cricket::MediaType media_type); |
| 266 | |
| 267 | // Triggered when a remote track has been removed from a remote session |
| 268 | // description. It removes the remote track with id |track_id| from a remote |
| 269 | // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
| 270 | void OnRemoteTrackRemoved(const std::string& stream_label, |
| 271 | const std::string& track_id, |
| 272 | cricket::MediaType media_type); |
| 273 | |
| 274 | // Finds remote MediaStreams without any tracks and removes them from |
| 275 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 276 | // exist. |
| 277 | void UpdateEndedRemoteMediaStreams(); |
| 278 | |
| 279 | void MaybeCreateDefaultStream(); |
| 280 | |
| 281 | // Set the MediaStreamTrackInterface::TrackState to |kEnded| on all remote |
| 282 | // tracks of type |media_type|. |
| 283 | void EndRemoteTracks(cricket::MediaType media_type); |
| 284 | |
| 285 | // Loops through the vector of |streams| and finds added and removed |
| 286 | // StreamParams since last time this method was called. |
| 287 | // For each new or removed StreamParam, OnLocalTrackSeen or |
| 288 | // OnLocalTrackRemoved is invoked. |
| 289 | void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, |
| 290 | cricket::MediaType media_type); |
| 291 | |
| 292 | // Triggered when a local track has been seen for the first time in a local |
| 293 | // session description. |
| 294 | // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
| 295 | // streams in the local SessionDescription can be mapped to a MediaStreamTrack |
| 296 | // in a MediaStream in |local_streams_| |
| 297 | void OnLocalTrackSeen(const std::string& stream_label, |
| 298 | const std::string& track_id, |
| 299 | uint32_t ssrc, |
| 300 | cricket::MediaType media_type); |
| 301 | |
| 302 | // Triggered when a local track has been removed from a local session |
| 303 | // description. |
| 304 | // This method triggers DestroyAudioSender or DestroyVideoSender if a stream |
| 305 | // has been removed from the local SessionDescription and the stream can be |
| 306 | // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|. |
| 307 | void OnLocalTrackRemoved(const std::string& stream_label, |
| 308 | const std::string& track_id, |
| 309 | uint32_t ssrc, |
| 310 | cricket::MediaType media_type); |
| 311 | |
| 312 | void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 313 | void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 314 | void UpdateClosingRtpDataChannels( |
| 315 | const std::vector<std::string>& active_channels, |
| 316 | bool is_local_update); |
| 317 | void CreateRemoteRtpDataChannel(const std::string& label, |
| 318 | uint32_t remote_ssrc); |
| 319 | |
| 320 | // Creates channel and adds it to the collection of DataChannels that will |
| 321 | // be offered in a SessionDescription. |
| 322 | rtc::scoped_refptr<DataChannel> InternalCreateDataChannel( |
| 323 | const std::string& label, |
| 324 | const InternalDataChannelInit* config); |
| 325 | |
| 326 | // Checks if any data channel has been added. |
| 327 | bool HasDataChannels() const; |
| 328 | |
| 329 | void AllocateSctpSids(rtc::SSLRole role); |
| 330 | void OnSctpDataChannelClosed(DataChannel* channel); |
| 331 | |
| 332 | // Notifications from WebRtcSession relating to BaseChannels. |
| 333 | void OnVoiceChannelDestroyed(); |
| 334 | void OnVideoChannelDestroyed(); |
| 335 | void OnDataChannelCreated(); |
| 336 | void OnDataChannelDestroyed(); |
| 337 | // Called when the cricket::DataChannel receives a message indicating that a |
| 338 | // webrtc::DataChannel should be opened. |
| 339 | void OnDataChannelOpenMessage(const std::string& label, |
| 340 | const InternalDataChannelInit& config); |
| 341 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame^] | 342 | RtpSenderInterface* FindSenderById(const std::string& id); |
| 343 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 344 | std::vector<rtc::scoped_refptr<RtpSenderInterface>>::iterator |
| 345 | FindSenderForTrack(MediaStreamTrackInterface* track); |
| 346 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator |
| 347 | FindReceiverForTrack(MediaStreamTrackInterface* track); |
| 348 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 349 | TrackInfos* GetRemoteTracks(cricket::MediaType media_type); |
| 350 | TrackInfos* GetLocalTracks(cricket::MediaType media_type); |
| 351 | const TrackInfo* FindTrackInfo(const TrackInfos& infos, |
| 352 | const std::string& stream_label, |
| 353 | const std::string track_id) const; |
| 354 | |
| 355 | // Returns the specified SCTP DataChannel in sctp_data_channels_, |
| 356 | // or nullptr if not found. |
| 357 | DataChannel* FindDataChannelBySid(int sid) const; |
| 358 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 359 | // Storing the factory as a scoped reference pointer ensures that the memory |
| 360 | // in the PeerConnectionFactoryImpl remains available as long as the |
| 361 | // PeerConnection is running. It is passed to PeerConnection as a raw pointer. |
| 362 | // However, since the reference counting is done in the |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 363 | // PeerConnectionFactoryInterface all instances created using the raw pointer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 364 | // will refer to the same reference count. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 365 | rtc::scoped_refptr<PeerConnectionFactory> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 366 | PeerConnectionObserver* observer_; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 367 | UMAObserver* uma_observer_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 368 | SignalingState signaling_state_; |
| 369 | // TODO(bemasc): Remove ice_state_. |
| 370 | IceState ice_state_; |
| 371 | IceConnectionState ice_connection_state_; |
| 372 | IceGatheringState ice_gathering_state_; |
| 373 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 374 | rtc::scoped_ptr<cricket::PortAllocator> port_allocator_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 375 | rtc::scoped_ptr<MediaControllerInterface> media_controller_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 376 | |
| 377 | // Streams added via AddStream. |
| 378 | rtc::scoped_refptr<StreamCollection> local_streams_; |
| 379 | // Streams created as a result of SetRemoteDescription. |
| 380 | rtc::scoped_refptr<StreamCollection> remote_streams_; |
| 381 | |
| 382 | // These lists store track info seen in local/remote descriptions. |
| 383 | TrackInfos remote_audio_tracks_; |
| 384 | TrackInfos remote_video_tracks_; |
| 385 | TrackInfos local_audio_tracks_; |
| 386 | TrackInfos local_video_tracks_; |
| 387 | |
| 388 | SctpSidAllocator sid_allocator_; |
| 389 | // label -> DataChannel |
| 390 | std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; |
| 391 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; |
| 392 | |
| 393 | RemotePeerInfo remote_info_; |
| 394 | rtc::scoped_ptr<RemoteMediaStreamFactory> remote_stream_factory_; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 395 | |
| 396 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders_; |
| 397 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 398 | |
| 399 | // The session_ scoped_ptr is declared at the bottom of PeerConnection |
| 400 | // because its destruction fires signals (such as VoiceChannelDestroyed) |
| 401 | // which will trigger some final actions in PeerConnection... |
| 402 | rtc::scoped_ptr<WebRtcSession> session_; |
| 403 | // ... But stats_ depends on session_ so it should be destroyed even earlier. |
| 404 | rtc::scoped_ptr<StatsCollector> stats_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 405 | }; |
| 406 | |
| 407 | } // namespace webrtc |
| 408 | |
| 409 | #endif // TALK_APP_WEBRTC_PEERCONNECTION_H_ |