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 | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 45 | class MediaStreamObserver; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 46 | class RemoteMediaStreamFactory; |
| 47 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 48 | // Populates |session_options| from |rtc_options|, and returns true if options |
| 49 | // are valid. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 50 | bool ConvertRtcOptionsForOffer( |
| 51 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 52 | cricket::MediaSessionOptions* session_options); |
| 53 | |
| 54 | // Populates |session_options| from |constraints|, and returns true if all |
| 55 | // mandatory constraints are satisfied. |
| 56 | bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
| 57 | cricket::MediaSessionOptions* session_options); |
| 58 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame^] | 59 | // Parses the URLs for each server in |servers| to build |stun_servers| and |
| 60 | // |turn_servers|. |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 61 | bool ParseIceServers(const PeerConnectionInterface::IceServers& servers, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame^] | 62 | cricket::ServerAddresses* stun_servers, |
| 63 | std::vector<cricket::RelayServerConfig>* turn_servers); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 64 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 65 | // PeerConnection implements the PeerConnectionInterface interface. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 66 | // It uses WebRtcSession to implement the PeerConnection functionality. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | class PeerConnection : public PeerConnectionInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | public IceObserver, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 69 | public rtc::MessageHandler, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | public sigslot::has_slots<> { |
| 71 | public: |
| 72 | explicit PeerConnection(PeerConnectionFactory* factory); |
| 73 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 74 | bool Initialize( |
| 75 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 76 | const MediaConstraintsInterface* constraints, |
| 77 | rtc::scoped_ptr<cricket::PortAllocator> allocator, |
| 78 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 79 | PeerConnectionObserver* observer); |
| 80 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 81 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override; |
| 82 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override; |
| 83 | bool AddStream(MediaStreamInterface* local_stream) override; |
| 84 | void RemoveStream(MediaStreamInterface* local_stream) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 86 | virtual WebRtcSession* session() { return session_.get(); } |
| 87 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 88 | rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( |
| 89 | AudioTrackInterface* track) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 91 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 92 | const std::string& kind, |
| 93 | const std::string& stream_id) override; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 94 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 95 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 96 | const override; |
| 97 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 98 | const override; |
| 99 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 100 | rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | const std::string& label, |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 102 | const DataChannelInit* config) override; |
| 103 | bool GetStats(StatsObserver* observer, |
| 104 | webrtc::MediaStreamTrackInterface* track, |
| 105 | StatsOutputLevel level) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 106 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 107 | SignalingState signaling_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | |
| 109 | // TODO(bemasc): Remove ice_state() when callers are removed. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 110 | IceState ice_state() override; |
| 111 | IceConnectionState ice_connection_state() override; |
| 112 | IceGatheringState ice_gathering_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 114 | const SessionDescriptionInterface* local_description() const override; |
| 115 | const SessionDescriptionInterface* remote_description() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | |
| 117 | // JSEP01 |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 118 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 119 | const MediaConstraintsInterface* constraints) override; |
| 120 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 121 | const RTCOfferAnswerOptions& options) override; |
| 122 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 123 | const MediaConstraintsInterface* constraints) override; |
| 124 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 125 | SessionDescriptionInterface* desc) override; |
| 126 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 127 | SessionDescriptionInterface* desc) override; |
| 128 | bool SetConfiguration( |
| 129 | const PeerConnectionInterface::RTCConfiguration& config) override; |
| 130 | bool AddIceCandidate(const IceCandidateInterface* candidate) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 131 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 132 | void RegisterUMAObserver(UMAObserver* observer) override; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 133 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 134 | void Close() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 136 | // Virtual for unit tests. |
| 137 | virtual const std::vector<rtc::scoped_refptr<DataChannel>>& |
| 138 | sctp_data_channels() const { |
| 139 | return sctp_data_channels_; |
| 140 | }; |
| 141 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | protected: |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 143 | ~PeerConnection() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 144 | |
| 145 | private: |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 146 | struct TrackInfo { |
| 147 | TrackInfo() : ssrc(0) {} |
| 148 | TrackInfo(const std::string& stream_label, |
| 149 | const std::string track_id, |
| 150 | uint32_t ssrc) |
| 151 | : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {} |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 152 | bool operator==(const TrackInfo& other) { |
| 153 | return this->stream_label == other.stream_label && |
| 154 | this->track_id == other.track_id && this->ssrc == other.ssrc; |
| 155 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 156 | std::string stream_label; |
| 157 | std::string track_id; |
| 158 | uint32_t ssrc; |
| 159 | }; |
| 160 | typedef std::vector<TrackInfo> TrackInfos; |
| 161 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 162 | // Implements MessageHandler. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 163 | void OnMessage(rtc::Message* msg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 165 | void CreateAudioReceiver(MediaStreamInterface* stream, |
| 166 | AudioTrackInterface* audio_track, |
| 167 | uint32_t ssrc); |
| 168 | void CreateVideoReceiver(MediaStreamInterface* stream, |
| 169 | VideoTrackInterface* video_track, |
| 170 | uint32_t ssrc); |
| 171 | void DestroyAudioReceiver(MediaStreamInterface* stream, |
| 172 | AudioTrackInterface* audio_track); |
| 173 | void DestroyVideoReceiver(MediaStreamInterface* stream, |
| 174 | VideoTrackInterface* video_track); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 175 | void DestroyAudioSender(MediaStreamInterface* stream, |
| 176 | AudioTrackInterface* audio_track, |
| 177 | uint32_t ssrc); |
| 178 | void DestroyVideoSender(MediaStreamInterface* stream, |
| 179 | VideoTrackInterface* video_track); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | |
| 181 | // Implements IceObserver |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 182 | void OnIceConnectionChange(IceConnectionState new_state) override; |
| 183 | void OnIceGatheringChange(IceGatheringState new_state) override; |
| 184 | void OnIceCandidate(const IceCandidateInterface* candidate) override; |
| 185 | void OnIceComplete() override; |
| 186 | void OnIceConnectionReceivingChange(bool receiving) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | |
| 188 | // Signals from WebRtcSession. |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 189 | void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 190 | void ChangeSignalingState(SignalingState signaling_state); |
| 191 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 192 | // Signals from MediaStreamObserver. |
| 193 | void OnAudioTrackAdded(AudioTrackInterface* track, |
| 194 | MediaStreamInterface* stream); |
| 195 | void OnAudioTrackRemoved(AudioTrackInterface* track, |
| 196 | MediaStreamInterface* stream); |
| 197 | void OnVideoTrackAdded(VideoTrackInterface* track, |
| 198 | MediaStreamInterface* stream); |
| 199 | void OnVideoTrackRemoved(VideoTrackInterface* track, |
| 200 | MediaStreamInterface* stream); |
| 201 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 202 | rtc::Thread* signaling_thread() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 203 | return factory_->signaling_thread(); |
| 204 | } |
| 205 | |
| 206 | void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, |
| 207 | const std::string& error); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 208 | void PostCreateSessionDescriptionFailure( |
| 209 | CreateSessionDescriptionObserver* observer, |
| 210 | const std::string& error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 211 | |
| 212 | bool IsClosed() const { |
| 213 | return signaling_state_ == PeerConnectionInterface::kClosed; |
| 214 | } |
| 215 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 216 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 217 | // the local MediaStreams and DataChannels. |
| 218 | virtual bool GetOptionsForOffer( |
| 219 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 220 | cricket::MediaSessionOptions* session_options); |
| 221 | |
| 222 | // Returns a MediaSessionOptions struct with options decided by |
| 223 | // |constraints|, the local MediaStreams and DataChannels. |
| 224 | virtual bool GetOptionsForAnswer( |
| 225 | const MediaConstraintsInterface* constraints, |
| 226 | cricket::MediaSessionOptions* session_options); |
| 227 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 228 | // Remove all local and remote tracks of type |media_type|. |
| 229 | // Called when a media type is rejected (m-line set to port 0). |
| 230 | void RemoveTracks(cricket::MediaType media_type); |
| 231 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 232 | // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 233 | // and existing MediaStreamTracks are removed if there is no corresponding |
| 234 | // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 235 | // is created if it doesn't exist; if false, it's removed if it exists. |
| 236 | // |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] | 237 | // If a new MediaStream is created it is added to |new_streams|. |
| 238 | void UpdateRemoteStreamsList( |
| 239 | const std::vector<cricket::StreamParams>& streams, |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 240 | bool default_track_needed, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 241 | cricket::MediaType media_type, |
| 242 | StreamCollection* new_streams); |
| 243 | |
| 244 | // Triggered when a remote track has been seen for the first time in a remote |
| 245 | // session description. It creates a remote MediaStreamTrackInterface |
| 246 | // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
| 247 | void OnRemoteTrackSeen(const std::string& stream_label, |
| 248 | const std::string& track_id, |
| 249 | uint32_t ssrc, |
| 250 | cricket::MediaType media_type); |
| 251 | |
| 252 | // Triggered when a remote track has been removed from a remote session |
| 253 | // description. It removes the remote track with id |track_id| from a remote |
| 254 | // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
| 255 | void OnRemoteTrackRemoved(const std::string& stream_label, |
| 256 | const std::string& track_id, |
| 257 | cricket::MediaType media_type); |
| 258 | |
| 259 | // Finds remote MediaStreams without any tracks and removes them from |
| 260 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 261 | // exist. |
| 262 | void UpdateEndedRemoteMediaStreams(); |
| 263 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 264 | // Set the MediaStreamTrackInterface::TrackState to |kEnded| on all remote |
| 265 | // tracks of type |media_type|. |
| 266 | void EndRemoteTracks(cricket::MediaType media_type); |
| 267 | |
| 268 | // Loops through the vector of |streams| and finds added and removed |
| 269 | // StreamParams since last time this method was called. |
| 270 | // For each new or removed StreamParam, OnLocalTrackSeen or |
| 271 | // OnLocalTrackRemoved is invoked. |
| 272 | void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, |
| 273 | cricket::MediaType media_type); |
| 274 | |
| 275 | // Triggered when a local track has been seen for the first time in a local |
| 276 | // session description. |
| 277 | // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
| 278 | // streams in the local SessionDescription can be mapped to a MediaStreamTrack |
| 279 | // in a MediaStream in |local_streams_| |
| 280 | void OnLocalTrackSeen(const std::string& stream_label, |
| 281 | const std::string& track_id, |
| 282 | uint32_t ssrc, |
| 283 | cricket::MediaType media_type); |
| 284 | |
| 285 | // Triggered when a local track has been removed from a local session |
| 286 | // description. |
| 287 | // This method triggers DestroyAudioSender or DestroyVideoSender if a stream |
| 288 | // has been removed from the local SessionDescription and the stream can be |
| 289 | // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|. |
| 290 | void OnLocalTrackRemoved(const std::string& stream_label, |
| 291 | const std::string& track_id, |
| 292 | uint32_t ssrc, |
| 293 | cricket::MediaType media_type); |
| 294 | |
| 295 | void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 296 | void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 297 | void UpdateClosingRtpDataChannels( |
| 298 | const std::vector<std::string>& active_channels, |
| 299 | bool is_local_update); |
| 300 | void CreateRemoteRtpDataChannel(const std::string& label, |
| 301 | uint32_t remote_ssrc); |
| 302 | |
| 303 | // Creates channel and adds it to the collection of DataChannels that will |
| 304 | // be offered in a SessionDescription. |
| 305 | rtc::scoped_refptr<DataChannel> InternalCreateDataChannel( |
| 306 | const std::string& label, |
| 307 | const InternalDataChannelInit* config); |
| 308 | |
| 309 | // Checks if any data channel has been added. |
| 310 | bool HasDataChannels() const; |
| 311 | |
| 312 | void AllocateSctpSids(rtc::SSLRole role); |
| 313 | void OnSctpDataChannelClosed(DataChannel* channel); |
| 314 | |
| 315 | // Notifications from WebRtcSession relating to BaseChannels. |
| 316 | void OnVoiceChannelDestroyed(); |
| 317 | void OnVideoChannelDestroyed(); |
| 318 | void OnDataChannelCreated(); |
| 319 | void OnDataChannelDestroyed(); |
| 320 | // Called when the cricket::DataChannel receives a message indicating that a |
| 321 | // webrtc::DataChannel should be opened. |
| 322 | void OnDataChannelOpenMessage(const std::string& label, |
| 323 | const InternalDataChannelInit& config); |
| 324 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 325 | RtpSenderInterface* FindSenderById(const std::string& id); |
| 326 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 327 | std::vector<rtc::scoped_refptr<RtpSenderInterface>>::iterator |
| 328 | FindSenderForTrack(MediaStreamTrackInterface* track); |
| 329 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator |
| 330 | FindReceiverForTrack(MediaStreamTrackInterface* track); |
| 331 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 332 | TrackInfos* GetRemoteTracks(cricket::MediaType media_type); |
| 333 | TrackInfos* GetLocalTracks(cricket::MediaType media_type); |
| 334 | const TrackInfo* FindTrackInfo(const TrackInfos& infos, |
| 335 | const std::string& stream_label, |
| 336 | const std::string track_id) const; |
| 337 | |
| 338 | // Returns the specified SCTP DataChannel in sctp_data_channels_, |
| 339 | // or nullptr if not found. |
| 340 | DataChannel* FindDataChannelBySid(int sid) const; |
| 341 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 342 | // Storing the factory as a scoped reference pointer ensures that the memory |
| 343 | // in the PeerConnectionFactoryImpl remains available as long as the |
| 344 | // PeerConnection is running. It is passed to PeerConnection as a raw pointer. |
| 345 | // However, since the reference counting is done in the |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 346 | // PeerConnectionFactoryInterface all instances created using the raw pointer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 347 | // will refer to the same reference count. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 348 | rtc::scoped_refptr<PeerConnectionFactory> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 349 | PeerConnectionObserver* observer_; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 350 | UMAObserver* uma_observer_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 351 | SignalingState signaling_state_; |
| 352 | // TODO(bemasc): Remove ice_state_. |
| 353 | IceState ice_state_; |
| 354 | IceConnectionState ice_connection_state_; |
| 355 | IceGatheringState ice_gathering_state_; |
| 356 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 357 | rtc::scoped_ptr<cricket::PortAllocator> port_allocator_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 358 | rtc::scoped_ptr<MediaControllerInterface> media_controller_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 359 | |
| 360 | // Streams added via AddStream. |
| 361 | rtc::scoped_refptr<StreamCollection> local_streams_; |
| 362 | // Streams created as a result of SetRemoteDescription. |
| 363 | rtc::scoped_refptr<StreamCollection> remote_streams_; |
| 364 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 365 | std::vector<rtc::scoped_ptr<MediaStreamObserver>> stream_observers_; |
| 366 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 367 | // These lists store track info seen in local/remote descriptions. |
| 368 | TrackInfos remote_audio_tracks_; |
| 369 | TrackInfos remote_video_tracks_; |
| 370 | TrackInfos local_audio_tracks_; |
| 371 | TrackInfos local_video_tracks_; |
| 372 | |
| 373 | SctpSidAllocator sid_allocator_; |
| 374 | // label -> DataChannel |
| 375 | std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; |
| 376 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; |
deadbeef | bd29246 | 2015-12-14 18:15:29 -0800 | [diff] [blame] | 377 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 378 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 379 | bool remote_peer_supports_msid_ = false; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 380 | rtc::scoped_ptr<RemoteMediaStreamFactory> remote_stream_factory_; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 381 | |
| 382 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders_; |
| 383 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 384 | |
| 385 | // The session_ scoped_ptr is declared at the bottom of PeerConnection |
| 386 | // because its destruction fires signals (such as VoiceChannelDestroyed) |
| 387 | // which will trigger some final actions in PeerConnection... |
| 388 | rtc::scoped_ptr<WebRtcSession> session_; |
| 389 | // ... But stats_ depends on session_ so it should be destroyed even earlier. |
| 390 | rtc::scoped_ptr<StatsCollector> stats_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | } // namespace webrtc |
| 394 | |
| 395 | #endif // TALK_APP_WEBRTC_PEERCONNECTION_H_ |