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) {} |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame^] | 164 | bool operator==(const TrackInfo& other) { |
| 165 | return this->stream_label == other.stream_label && |
| 166 | this->track_id == other.track_id && this->ssrc == other.ssrc; |
| 167 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 168 | std::string stream_label; |
| 169 | std::string track_id; |
| 170 | uint32_t ssrc; |
| 171 | }; |
| 172 | typedef std::vector<TrackInfo> TrackInfos; |
| 173 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 174 | // Implements MessageHandler. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 175 | void OnMessage(rtc::Message* msg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 177 | void CreateAudioReceiver(MediaStreamInterface* stream, |
| 178 | AudioTrackInterface* audio_track, |
| 179 | uint32_t ssrc); |
| 180 | void CreateVideoReceiver(MediaStreamInterface* stream, |
| 181 | VideoTrackInterface* video_track, |
| 182 | uint32_t ssrc); |
| 183 | void DestroyAudioReceiver(MediaStreamInterface* stream, |
| 184 | AudioTrackInterface* audio_track); |
| 185 | void DestroyVideoReceiver(MediaStreamInterface* stream, |
| 186 | VideoTrackInterface* video_track); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 187 | void DestroyAudioSender(MediaStreamInterface* stream, |
| 188 | AudioTrackInterface* audio_track, |
| 189 | uint32_t ssrc); |
| 190 | void DestroyVideoSender(MediaStreamInterface* stream, |
| 191 | VideoTrackInterface* video_track); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | |
| 193 | // Implements IceObserver |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 194 | void OnIceConnectionChange(IceConnectionState new_state) override; |
| 195 | void OnIceGatheringChange(IceGatheringState new_state) override; |
| 196 | void OnIceCandidate(const IceCandidateInterface* candidate) override; |
| 197 | void OnIceComplete() override; |
| 198 | void OnIceConnectionReceivingChange(bool receiving) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | |
| 200 | // Signals from WebRtcSession. |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 201 | void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 202 | void ChangeSignalingState(SignalingState signaling_state); |
| 203 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 204 | rtc::Thread* signaling_thread() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 205 | return factory_->signaling_thread(); |
| 206 | } |
| 207 | |
| 208 | void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, |
| 209 | const std::string& error); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 210 | void PostCreateSessionDescriptionFailure( |
| 211 | CreateSessionDescriptionObserver* observer, |
| 212 | const std::string& error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 213 | |
| 214 | bool IsClosed() const { |
| 215 | return signaling_state_ == PeerConnectionInterface::kClosed; |
| 216 | } |
| 217 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 218 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 219 | // the local MediaStreams and DataChannels. |
| 220 | virtual bool GetOptionsForOffer( |
| 221 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 222 | cricket::MediaSessionOptions* session_options); |
| 223 | |
| 224 | // Returns a MediaSessionOptions struct with options decided by |
| 225 | // |constraints|, the local MediaStreams and DataChannels. |
| 226 | virtual bool GetOptionsForAnswer( |
| 227 | const MediaConstraintsInterface* constraints, |
| 228 | cricket::MediaSessionOptions* session_options); |
| 229 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 230 | // Remove all local and remote tracks of type |media_type|. |
| 231 | // Called when a media type is rejected (m-line set to port 0). |
| 232 | void RemoveTracks(cricket::MediaType media_type); |
| 233 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame^] | 234 | // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 235 | // and existing MediaStreamTracks are removed if there is no corresponding |
| 236 | // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 237 | // is created if it doesn't exist; if false, it's removed if it exists. |
| 238 | // |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] | 239 | // If a new MediaStream is created it is added to |new_streams|. |
| 240 | void UpdateRemoteStreamsList( |
| 241 | const std::vector<cricket::StreamParams>& streams, |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame^] | 242 | bool default_track_needed, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 243 | cricket::MediaType media_type, |
| 244 | StreamCollection* new_streams); |
| 245 | |
| 246 | // Triggered when a remote track has been seen for the first time in a remote |
| 247 | // session description. It creates a remote MediaStreamTrackInterface |
| 248 | // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
| 249 | void OnRemoteTrackSeen(const std::string& stream_label, |
| 250 | const std::string& track_id, |
| 251 | uint32_t ssrc, |
| 252 | cricket::MediaType media_type); |
| 253 | |
| 254 | // Triggered when a remote track has been removed from a remote session |
| 255 | // description. It removes the remote track with id |track_id| from a remote |
| 256 | // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
| 257 | void OnRemoteTrackRemoved(const std::string& stream_label, |
| 258 | const std::string& track_id, |
| 259 | cricket::MediaType media_type); |
| 260 | |
| 261 | // Finds remote MediaStreams without any tracks and removes them from |
| 262 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 263 | // exist. |
| 264 | void UpdateEndedRemoteMediaStreams(); |
| 265 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 266 | // Set the MediaStreamTrackInterface::TrackState to |kEnded| on all remote |
| 267 | // tracks of type |media_type|. |
| 268 | void EndRemoteTracks(cricket::MediaType media_type); |
| 269 | |
| 270 | // Loops through the vector of |streams| and finds added and removed |
| 271 | // StreamParams since last time this method was called. |
| 272 | // For each new or removed StreamParam, OnLocalTrackSeen or |
| 273 | // OnLocalTrackRemoved is invoked. |
| 274 | void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, |
| 275 | cricket::MediaType media_type); |
| 276 | |
| 277 | // Triggered when a local track has been seen for the first time in a local |
| 278 | // session description. |
| 279 | // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
| 280 | // streams in the local SessionDescription can be mapped to a MediaStreamTrack |
| 281 | // in a MediaStream in |local_streams_| |
| 282 | void OnLocalTrackSeen(const std::string& stream_label, |
| 283 | const std::string& track_id, |
| 284 | uint32_t ssrc, |
| 285 | cricket::MediaType media_type); |
| 286 | |
| 287 | // Triggered when a local track has been removed from a local session |
| 288 | // description. |
| 289 | // This method triggers DestroyAudioSender or DestroyVideoSender if a stream |
| 290 | // has been removed from the local SessionDescription and the stream can be |
| 291 | // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|. |
| 292 | void OnLocalTrackRemoved(const std::string& stream_label, |
| 293 | const std::string& track_id, |
| 294 | uint32_t ssrc, |
| 295 | cricket::MediaType media_type); |
| 296 | |
| 297 | void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 298 | void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 299 | void UpdateClosingRtpDataChannels( |
| 300 | const std::vector<std::string>& active_channels, |
| 301 | bool is_local_update); |
| 302 | void CreateRemoteRtpDataChannel(const std::string& label, |
| 303 | uint32_t remote_ssrc); |
| 304 | |
| 305 | // Creates channel and adds it to the collection of DataChannels that will |
| 306 | // be offered in a SessionDescription. |
| 307 | rtc::scoped_refptr<DataChannel> InternalCreateDataChannel( |
| 308 | const std::string& label, |
| 309 | const InternalDataChannelInit* config); |
| 310 | |
| 311 | // Checks if any data channel has been added. |
| 312 | bool HasDataChannels() const; |
| 313 | |
| 314 | void AllocateSctpSids(rtc::SSLRole role); |
| 315 | void OnSctpDataChannelClosed(DataChannel* channel); |
| 316 | |
| 317 | // Notifications from WebRtcSession relating to BaseChannels. |
| 318 | void OnVoiceChannelDestroyed(); |
| 319 | void OnVideoChannelDestroyed(); |
| 320 | void OnDataChannelCreated(); |
| 321 | void OnDataChannelDestroyed(); |
| 322 | // Called when the cricket::DataChannel receives a message indicating that a |
| 323 | // webrtc::DataChannel should be opened. |
| 324 | void OnDataChannelOpenMessage(const std::string& label, |
| 325 | const InternalDataChannelInit& config); |
| 326 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 327 | RtpSenderInterface* FindSenderById(const std::string& id); |
| 328 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 329 | std::vector<rtc::scoped_refptr<RtpSenderInterface>>::iterator |
| 330 | FindSenderForTrack(MediaStreamTrackInterface* track); |
| 331 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator |
| 332 | FindReceiverForTrack(MediaStreamTrackInterface* track); |
| 333 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 334 | TrackInfos* GetRemoteTracks(cricket::MediaType media_type); |
| 335 | TrackInfos* GetLocalTracks(cricket::MediaType media_type); |
| 336 | const TrackInfo* FindTrackInfo(const TrackInfos& infos, |
| 337 | const std::string& stream_label, |
| 338 | const std::string track_id) const; |
| 339 | |
| 340 | // Returns the specified SCTP DataChannel in sctp_data_channels_, |
| 341 | // or nullptr if not found. |
| 342 | DataChannel* FindDataChannelBySid(int sid) const; |
| 343 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 344 | // Storing the factory as a scoped reference pointer ensures that the memory |
| 345 | // in the PeerConnectionFactoryImpl remains available as long as the |
| 346 | // PeerConnection is running. It is passed to PeerConnection as a raw pointer. |
| 347 | // However, since the reference counting is done in the |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 348 | // PeerConnectionFactoryInterface all instances created using the raw pointer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 349 | // will refer to the same reference count. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 350 | rtc::scoped_refptr<PeerConnectionFactory> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 351 | PeerConnectionObserver* observer_; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 352 | UMAObserver* uma_observer_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 353 | SignalingState signaling_state_; |
| 354 | // TODO(bemasc): Remove ice_state_. |
| 355 | IceState ice_state_; |
| 356 | IceConnectionState ice_connection_state_; |
| 357 | IceGatheringState ice_gathering_state_; |
| 358 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 359 | rtc::scoped_ptr<cricket::PortAllocator> port_allocator_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 360 | rtc::scoped_ptr<MediaControllerInterface> media_controller_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 361 | |
| 362 | // Streams added via AddStream. |
| 363 | rtc::scoped_refptr<StreamCollection> local_streams_; |
| 364 | // Streams created as a result of SetRemoteDescription. |
| 365 | rtc::scoped_refptr<StreamCollection> remote_streams_; |
| 366 | |
| 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_; |
| 377 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame^] | 378 | bool remote_peer_supports_msid_ = false; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 379 | rtc::scoped_ptr<RemoteMediaStreamFactory> remote_stream_factory_; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 380 | |
| 381 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders_; |
| 382 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 383 | |
| 384 | // The session_ scoped_ptr is declared at the bottom of PeerConnection |
| 385 | // because its destruction fires signals (such as VoiceChannelDestroyed) |
| 386 | // which will trigger some final actions in PeerConnection... |
| 387 | rtc::scoped_ptr<WebRtcSession> session_; |
| 388 | // ... But stats_ depends on session_ so it should be destroyed even earlier. |
| 389 | rtc::scoped_ptr<StatsCollector> stats_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 390 | }; |
| 391 | |
| 392 | } // namespace webrtc |
| 393 | |
| 394 | #endif // TALK_APP_WEBRTC_PEERCONNECTION_H_ |