henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef PC_PEERCONNECTION_H_ |
| 12 | #define PC_PEERCONNECTION_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
perkj | d61bf80 | 2016-03-24 10:16:19 | [diff] [blame] | 14 | #include <map> |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 15 | #include <memory> |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 16 | #include <set> |
| 17 | #include <string> |
perkj | d61bf80 | 2016-03-24 10:16:19 | [diff] [blame] | 18 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "api/peerconnectioninterface.h" |
Jonas Oreland | bdcee28 | 2017-10-10 12:01:40 | [diff] [blame] | 21 | #include "api/turncustomizer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 22 | #include "pc/iceserverparsing.h" |
| 23 | #include "pc/peerconnectionfactory.h" |
| 24 | #include "pc/rtcstatscollector.h" |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 25 | #include "pc/rtptransceiver.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 26 | #include "pc/statscollector.h" |
| 27 | #include "pc/streamcollection.h" |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 28 | #include "pc/webrtcsessiondescriptionfactory.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 31 | |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 32 | class MediaStreamObserver; |
perkj | f0dcfe2 | 2016-03-10 17:32:00 | [diff] [blame] | 33 | class VideoRtpReceiver; |
skvlad | 11a9cbf | 2016-10-07 18:53:05 | [diff] [blame] | 34 | class RtcEventLog; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 35 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 36 | // Statistics for all the transports of the session. |
| 37 | // TODO(pthatcher): Think of a better name for this. We already have |
| 38 | // a TransportStats in transport.h. Perhaps TransportsStats? |
| 39 | struct SessionStats { |
| 40 | std::map<std::string, std::string> proxy_to_transport; |
| 41 | std::map<std::string, cricket::TransportStats> transport_stats; |
| 42 | }; |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 43 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 44 | struct ChannelNamePair { |
| 45 | ChannelNamePair(const std::string& content_name, |
| 46 | const std::string& transport_name) |
| 47 | : content_name(content_name), transport_name(transport_name) {} |
| 48 | std::string content_name; |
| 49 | std::string transport_name; |
| 50 | }; |
| 51 | |
| 52 | struct ChannelNamePairs { |
| 53 | rtc::Optional<ChannelNamePair> voice; |
| 54 | rtc::Optional<ChannelNamePair> video; |
| 55 | rtc::Optional<ChannelNamePair> data; |
| 56 | }; |
| 57 | |
| 58 | // PeerConnection is the implementation of the PeerConnection object as defined |
| 59 | // by the PeerConnectionInterface API surface. |
| 60 | // The class currently is solely responsible for the following: |
| 61 | // - Managing the session state machine (signaling state). |
| 62 | // - Creating and initializing lower-level objects, like PortAllocator and |
| 63 | // BaseChannels. |
| 64 | // - Owning and managing the life cycle of the RtpSender/RtpReceiver and track |
| 65 | // objects. |
| 66 | // - Tracking the current and pending local/remote session descriptions. |
| 67 | // The class currently is jointly responsible for the following: |
| 68 | // - Parsing and interpreting SDP. |
| 69 | // - Generating offers and answers based on the current state. |
| 70 | // - The ICE state machine. |
| 71 | // - Generating stats. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 72 | class PeerConnection : public PeerConnectionInterface, |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 73 | public DataChannelProviderInterface, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 74 | public rtc::MessageHandler, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 75 | public sigslot::has_slots<> { |
| 76 | public: |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 77 | explicit PeerConnection(PeerConnectionFactory* factory, |
| 78 | std::unique_ptr<RtcEventLog> event_log, |
| 79 | std::unique_ptr<Call> call); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 80 | |
deadbeef | 653b8e0 | 2015-11-11 20:55:10 | [diff] [blame] | 81 | bool Initialize( |
| 82 | const PeerConnectionInterface::RTCConfiguration& configuration, |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 83 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 84 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 653b8e0 | 2015-11-11 20:55:10 | [diff] [blame] | 85 | PeerConnectionObserver* observer); |
| 86 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 87 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override; |
| 88 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override; |
| 89 | bool AddStream(MediaStreamInterface* local_stream) override; |
| 90 | void RemoveStream(MediaStreamInterface* local_stream) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 91 | |
deadbeef | e1f9d83 | 2016-01-14 23:35:42 | [diff] [blame] | 92 | rtc::scoped_refptr<RtpSenderInterface> AddTrack( |
| 93 | MediaStreamTrackInterface* track, |
| 94 | std::vector<MediaStreamInterface*> streams) override; |
| 95 | bool RemoveTrack(RtpSenderInterface* sender) override; |
| 96 | |
Steve Anton | 8c0f7a7 | 2017-10-03 17:03:10 | [diff] [blame] | 97 | // Gets the DTLS SSL certificate associated with the audio transport on the |
| 98 | // remote side. This will become populated once the DTLS connection with the |
| 99 | // peer has been completed, as indicated by the ICE connection state |
| 100 | // transitioning to kIceConnectionCompleted. |
| 101 | // Note that this will be removed once we implement RTCDtlsTransport which |
| 102 | // has standardized method for getting this information. |
| 103 | // See https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface |
| 104 | std::unique_ptr<rtc::SSLCertificate> GetRemoteAudioSSLCertificate(); |
| 105 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 106 | rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( |
| 107 | AudioTrackInterface* track) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 108 | |
deadbeef | fac0655 | 2015-11-25 19:26:01 | [diff] [blame] | 109 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
deadbeef | bd7d8f7 | 2015-12-19 00:58:44 | [diff] [blame] | 110 | const std::string& kind, |
| 111 | const std::string& stream_id) override; |
deadbeef | fac0655 | 2015-11-25 19:26:01 | [diff] [blame] | 112 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 113 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 114 | const override; |
| 115 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 116 | const override; |
| 117 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 118 | rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 119 | const std::string& label, |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 120 | const DataChannelInit* config) override; |
| 121 | bool GetStats(StatsObserver* observer, |
| 122 | webrtc::MediaStreamTrackInterface* track, |
| 123 | StatsOutputLevel level) override; |
hbos | 74e1a4f | 2016-09-16 06:33:01 | [diff] [blame] | 124 | void GetStats(RTCStatsCollectorCallback* callback) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 125 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 126 | SignalingState signaling_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 127 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 128 | IceConnectionState ice_connection_state() override; |
| 129 | IceGatheringState ice_gathering_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 130 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 131 | const SessionDescriptionInterface* local_description() const override; |
| 132 | const SessionDescriptionInterface* remote_description() const override; |
deadbeef | fe4a8a4 | 2016-12-21 01:56:17 | [diff] [blame] | 133 | const SessionDescriptionInterface* current_local_description() const override; |
| 134 | const SessionDescriptionInterface* current_remote_description() |
| 135 | const override; |
| 136 | const SessionDescriptionInterface* pending_local_description() const override; |
| 137 | const SessionDescriptionInterface* pending_remote_description() |
| 138 | const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 139 | |
| 140 | // JSEP01 |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 141 | // Deprecated, use version without constraints. |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 142 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 143 | const MediaConstraintsInterface* constraints) override; |
| 144 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 145 | const RTCOfferAnswerOptions& options) override; |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 146 | // Deprecated, use version without constraints. |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 147 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 148 | const MediaConstraintsInterface* constraints) override; |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 149 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 150 | const RTCOfferAnswerOptions& options) override; |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 151 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 152 | SessionDescriptionInterface* desc) override; |
Henrik Boström | a4ecf55 | 2017-11-23 14:17:07 | [diff] [blame] | 153 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 154 | SessionDescriptionInterface* desc) override; |
Henrik Boström | 3163867 | 2017-11-23 16:48:32 | [diff] [blame^] | 155 | void SetRemoteDescription( |
| 156 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 157 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) |
| 158 | override; |
deadbeef | 46c7389 | 2016-11-17 03:42:04 | [diff] [blame] | 159 | PeerConnectionInterface::RTCConfiguration GetConfiguration() override; |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 160 | bool SetConfiguration( |
deadbeef | 293e926 | 2017-01-11 20:28:30 | [diff] [blame] | 161 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 162 | RTCError* error) override; |
| 163 | bool SetConfiguration( |
| 164 | const PeerConnectionInterface::RTCConfiguration& configuration) override { |
| 165 | return SetConfiguration(configuration, nullptr); |
| 166 | } |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 167 | bool AddIceCandidate(const IceCandidateInterface* candidate) override; |
Honghai Zhang | 7fb69db | 2016-03-14 18:59:18 | [diff] [blame] | 168 | bool RemoveIceCandidates( |
| 169 | const std::vector<cricket::Candidate>& candidates) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 170 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 171 | void RegisterUMAObserver(UMAObserver* observer) override; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 | [diff] [blame] | 172 | |
zstein | 4b97980 | 2017-06-02 21:37:37 | [diff] [blame] | 173 | RTCError SetBitrate(const BitrateParameters& bitrate) override; |
| 174 | |
Alex Narest | 78609d5 | 2017-10-20 08:37:47 | [diff] [blame] | 175 | void SetBitrateAllocationStrategy( |
| 176 | std::unique_ptr<rtc::BitrateAllocationStrategy> |
| 177 | bitrate_allocation_strategy) override; |
| 178 | |
henrika | 5f6bf24 | 2017-11-01 10:06:56 | [diff] [blame] | 179 | void SetAudioPlayout(bool playout) override; |
| 180 | void SetAudioRecording(bool recording) override; |
| 181 | |
Elad Alon | 99c3fe5 | 2017-10-13 14:29:40 | [diff] [blame] | 182 | RTC_DEPRECATED bool StartRtcEventLog(rtc::PlatformFile file, |
| 183 | int64_t max_size_bytes) override; |
Bjorn Terelius | de93943 | 2017-11-20 16:38:14 | [diff] [blame] | 184 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output, |
| 185 | int64_t output_period_ms) override; |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 186 | void StopRtcEventLog() override; |
| 187 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 188 | void Close() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 189 | |
hbos | 82ebe02 | 2016-11-14 09:41:09 | [diff] [blame] | 190 | sigslot::signal1<DataChannel*> SignalDataChannelCreated; |
| 191 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 192 | // Virtual for unit tests. |
| 193 | virtual const std::vector<rtc::scoped_refptr<DataChannel>>& |
| 194 | sctp_data_channels() const { |
| 195 | return sctp_data_channels_; |
perkj | d61bf80 | 2016-03-24 10:16:19 | [diff] [blame] | 196 | } |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 197 | |
Steve Anton | 978b876 | 2017-09-29 19:15:02 | [diff] [blame] | 198 | rtc::Thread* network_thread() const { return factory_->network_thread(); } |
| 199 | rtc::Thread* worker_thread() const { return factory_->worker_thread(); } |
| 200 | rtc::Thread* signaling_thread() const { return factory_->signaling_thread(); } |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 201 | |
| 202 | // The SDP session ID as defined by RFC 3264. |
| 203 | virtual const std::string& session_id() const { return session_id_; } |
| 204 | |
| 205 | // Returns true if we were the initial offerer. |
| 206 | bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; } |
| 207 | |
| 208 | // Returns stats for all channels of all transports. |
| 209 | // This avoids exposing the internal structures used to track them. |
| 210 | // The parameterless version creates |ChannelNamePairs| from |voice_channel|, |
| 211 | // |video_channel| and |voice_channel| if available - this requires it to be |
| 212 | // called on the signaling thread - and invokes the other |GetStats|. The |
| 213 | // other |GetStats| can be invoked on any thread; if not invoked on the |
| 214 | // network thread a thread hop will happen. |
| 215 | std::unique_ptr<SessionStats> GetSessionStats_s(); |
Steve Anton | 978b876 | 2017-09-29 19:15:02 | [diff] [blame] | 216 | virtual std::unique_ptr<SessionStats> GetSessionStats( |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 217 | const ChannelNamePairs& channel_name_pairs); |
| 218 | |
| 219 | // virtual so it can be mocked in unit tests |
Steve Anton | 978b876 | 2017-09-29 19:15:02 | [diff] [blame] | 220 | virtual bool GetLocalCertificate( |
| 221 | const std::string& transport_name, |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 222 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate); |
Steve Anton | 978b876 | 2017-09-29 19:15:02 | [diff] [blame] | 223 | virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate( |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 224 | const std::string& transport_name); |
| 225 | |
| 226 | virtual Call::Stats GetCallStats(); |
| 227 | |
| 228 | // Exposed for stats collecting. |
| 229 | // TODO(steveanton): Switch callers to use the plural form and remove these. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 230 | virtual cricket::VoiceChannel* voice_channel() const { |
| 231 | return static_cast<cricket::VoiceChannel*>( |
| 232 | GetAudioTransceiver()->internal()->channel()); |
Steve Anton | 978b876 | 2017-09-29 19:15:02 | [diff] [blame] | 233 | } |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 234 | virtual cricket::VideoChannel* video_channel() const { |
| 235 | return static_cast<cricket::VideoChannel*>( |
| 236 | GetVideoTransceiver()->internal()->channel()); |
Steve Anton | d5585ca | 2017-10-23 21:49:26 | [diff] [blame] | 237 | } |
Steve Anton | 978b876 | 2017-09-29 19:15:02 | [diff] [blame] | 238 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 239 | // Only valid when using deprecated RTP data channels. |
| 240 | virtual cricket::RtpDataChannel* rtp_data_channel() { |
| 241 | return rtp_data_channel_; |
Steve Anton | 978b876 | 2017-09-29 19:15:02 | [diff] [blame] | 242 | } |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 243 | virtual rtc::Optional<std::string> sctp_content_name() const { |
| 244 | return sctp_content_name_; |
| 245 | } |
| 246 | virtual rtc::Optional<std::string> sctp_transport_name() const { |
| 247 | return sctp_transport_name_; |
| 248 | } |
| 249 | |
| 250 | // Get the id used as a media stream track's "id" field from ssrc. |
| 251 | virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id); |
| 252 | virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id); |
| 253 | |
| 254 | // Returns true if there was an ICE restart initiated by the remote offer. |
| 255 | bool IceRestartPending(const std::string& content_name) const; |
| 256 | |
| 257 | // Returns true if the ICE restart flag above was set, and no ICE restart has |
| 258 | // occurred yet for this transport (by applying a local description with |
| 259 | // changed ufrag/password). If the transport has been deleted as a result of |
| 260 | // bundling, returns false. |
| 261 | bool NeedsIceRestart(const std::string& content_name) const; |
| 262 | |
| 263 | // Get SSL role for an arbitrary m= section (handles bundling correctly). |
| 264 | // TODO(deadbeef): This is only used internally by the session description |
| 265 | // factory, it shouldn't really be public). |
| 266 | bool GetSslRole(const std::string& content_name, rtc::SSLRole* role); |
| 267 | |
| 268 | enum Error { |
| 269 | ERROR_NONE = 0, // no error |
| 270 | ERROR_CONTENT = 1, // channel errors in SetLocalContent/SetRemoteContent |
| 271 | ERROR_TRANSPORT = 2, // transport error of some kind |
| 272 | }; |
Steve Anton | 978b876 | 2017-09-29 19:15:02 | [diff] [blame] | 273 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 274 | protected: |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 275 | ~PeerConnection() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 276 | |
| 277 | private: |
Henrik Boström | 3163867 | 2017-11-23 16:48:32 | [diff] [blame^] | 278 | class SetRemoteDescriptionObserverAdapter; |
| 279 | friend class SetRemoteDescriptionObserverAdapter; |
| 280 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 281 | struct RtpSenderInfo { |
| 282 | RtpSenderInfo() : first_ssrc(0) {} |
| 283 | RtpSenderInfo(const std::string& stream_label, |
| 284 | const std::string sender_id, |
| 285 | uint32_t ssrc) |
| 286 | : stream_label(stream_label), sender_id(sender_id), first_ssrc(ssrc) {} |
| 287 | bool operator==(const RtpSenderInfo& other) { |
deadbeef | bda7e0b | 2015-12-09 01:13:40 | [diff] [blame] | 288 | return this->stream_label == other.stream_label && |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 289 | this->sender_id == other.sender_id && |
| 290 | this->first_ssrc == other.first_ssrc; |
deadbeef | bda7e0b | 2015-12-09 01:13:40 | [diff] [blame] | 291 | } |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 292 | std::string stream_label; |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 293 | std::string sender_id; |
| 294 | // An RtpSender can have many SSRCs. The first one is used as a sort of ID |
| 295 | // for communicating with the lower layers. |
| 296 | uint32_t first_ssrc; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 297 | }; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 298 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 299 | // Implements MessageHandler. |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 300 | void OnMessage(rtc::Message* msg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 301 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 302 | std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>> |
| 303 | GetSendersInternal() const; |
| 304 | std::vector< |
| 305 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>> |
| 306 | GetReceiversInternal() const; |
| 307 | |
| 308 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 309 | GetAudioTransceiver() const; |
| 310 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 311 | GetVideoTransceiver() const; |
| 312 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 313 | void CreateAudioReceiver(MediaStreamInterface* stream, |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 314 | const RtpSenderInfo& remote_sender_info); |
perkj | f0dcfe2 | 2016-03-10 17:32:00 | [diff] [blame] | 315 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 316 | void CreateVideoReceiver(MediaStreamInterface* stream, |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 317 | const RtpSenderInfo& remote_sender_info); |
Henrik Boström | 933d8b0 | 2017-10-10 17:05:16 | [diff] [blame] | 318 | rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver( |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 319 | const RtpSenderInfo& remote_sender_info); |
korniltsev.anatoly | ec390b5 | 2017-07-25 00:00:25 | [diff] [blame] | 320 | |
| 321 | // May be called either by AddStream/RemoveStream, or when a track is |
| 322 | // added/removed from a stream previously added via AddStream. |
| 323 | void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream); |
| 324 | void RemoveAudioTrack(AudioTrackInterface* track, |
| 325 | MediaStreamInterface* stream); |
| 326 | void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream); |
| 327 | void RemoveVideoTrack(VideoTrackInterface* track, |
| 328 | MediaStreamInterface* stream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 329 | |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 330 | void SetIceConnectionState(IceConnectionState new_state); |
| 331 | // Called any time the IceGatheringState changes |
| 332 | void OnIceGatheringChange(IceGatheringState new_state); |
| 333 | // New ICE candidate has been gathered. |
| 334 | void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate); |
| 335 | // Some local ICE candidates have been removed. |
Honghai Zhang | 7fb69db | 2016-03-14 18:59:18 | [diff] [blame] | 336 | void OnIceCandidatesRemoved( |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 337 | const std::vector<cricket::Candidate>& candidates); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 338 | |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 339 | // Update the state, signaling if necessary. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 340 | void ChangeSignalingState(SignalingState signaling_state); |
| 341 | |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 342 | // Signals from MediaStreamObserver. |
| 343 | void OnAudioTrackAdded(AudioTrackInterface* track, |
| 344 | MediaStreamInterface* stream); |
| 345 | void OnAudioTrackRemoved(AudioTrackInterface* track, |
| 346 | MediaStreamInterface* stream); |
| 347 | void OnVideoTrackAdded(VideoTrackInterface* track, |
| 348 | MediaStreamInterface* stream); |
| 349 | void OnVideoTrackRemoved(VideoTrackInterface* track, |
| 350 | MediaStreamInterface* stream); |
| 351 | |
Henrik Boström | 3163867 | 2017-11-23 16:48:32 | [diff] [blame^] | 352 | void PostSetSessionDescriptionSuccess( |
| 353 | SetSessionDescriptionObserver* observer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 354 | void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, |
| 355 | const std::string& error); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 356 | void PostCreateSessionDescriptionFailure( |
| 357 | CreateSessionDescriptionObserver* observer, |
| 358 | const std::string& error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 359 | |
| 360 | bool IsClosed() const { |
| 361 | return signaling_state_ == PeerConnectionInterface::kClosed; |
| 362 | } |
| 363 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 364 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 365 | // the local MediaStreams and DataChannels. |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 366 | void GetOptionsForOffer( |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 367 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 368 | cricket::MediaSessionOptions* session_options); |
| 369 | |
| 370 | // Returns a MediaSessionOptions struct with options decided by |
| 371 | // |constraints|, the local MediaStreams and DataChannels. |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 372 | void GetOptionsForAnswer(const RTCOfferAnswerOptions& options, |
| 373 | cricket::MediaSessionOptions* session_options); |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 374 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 375 | // Generates MediaDescriptionOptions for the |session_opts| based on existing |
| 376 | // local description or remote description. |
| 377 | void GenerateMediaDescriptionOptions( |
| 378 | const SessionDescriptionInterface* session_desc, |
| 379 | cricket::RtpTransceiverDirection audio_direction, |
| 380 | cricket::RtpTransceiverDirection video_direction, |
| 381 | rtc::Optional<size_t>* audio_index, |
| 382 | rtc::Optional<size_t>* video_index, |
| 383 | rtc::Optional<size_t>* data_index, |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 384 | cricket::MediaSessionOptions* session_options); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 385 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 386 | // Remove all local and remote senders of type |media_type|. |
deadbeef | faac497 | 2015-11-12 23:33:07 | [diff] [blame] | 387 | // Called when a media type is rejected (m-line set to port 0). |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 388 | void RemoveSenders(cricket::MediaType media_type); |
deadbeef | faac497 | 2015-11-12 23:33:07 | [diff] [blame] | 389 | |
deadbeef | bda7e0b | 2015-12-09 01:13:40 | [diff] [blame] | 390 | // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 391 | // and existing MediaStreamTracks are removed if there is no corresponding |
| 392 | // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 393 | // is created if it doesn't exist; if false, it's removed if it exists. |
| 394 | // |media_type| is the type of the |streams| and can be either audio or video. |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 395 | // If a new MediaStream is created it is added to |new_streams|. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 396 | void UpdateRemoteSendersList( |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 397 | const std::vector<cricket::StreamParams>& streams, |
deadbeef | bda7e0b | 2015-12-09 01:13:40 | [diff] [blame] | 398 | bool default_track_needed, |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 399 | cricket::MediaType media_type, |
| 400 | StreamCollection* new_streams); |
| 401 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 402 | // Triggered when a remote sender has been seen for the first time in a remote |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 403 | // session description. It creates a remote MediaStreamTrackInterface |
| 404 | // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 405 | void OnRemoteSenderAdded(const RtpSenderInfo& sender_info, |
| 406 | cricket::MediaType media_type); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 407 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 408 | // Triggered when a remote sender has been removed from a remote session |
| 409 | // description. It removes the remote sender with id |sender_id| from a remote |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 410 | // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 411 | void OnRemoteSenderRemoved(const RtpSenderInfo& sender_info, |
| 412 | cricket::MediaType media_type); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 413 | |
| 414 | // Finds remote MediaStreams without any tracks and removes them from |
| 415 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 416 | // exist. |
| 417 | void UpdateEndedRemoteMediaStreams(); |
| 418 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 419 | // Loops through the vector of |streams| and finds added and removed |
| 420 | // StreamParams since last time this method was called. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 421 | // For each new or removed StreamParam, OnLocalSenderSeen or |
| 422 | // OnLocalSenderRemoved is invoked. |
| 423 | void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams, |
| 424 | cricket::MediaType media_type); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 425 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 426 | // Triggered when a local sender has been seen for the first time in a local |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 427 | // session description. |
| 428 | // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
| 429 | // streams in the local SessionDescription can be mapped to a MediaStreamTrack |
| 430 | // in a MediaStream in |local_streams_| |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 431 | void OnLocalSenderAdded(const RtpSenderInfo& sender_info, |
| 432 | cricket::MediaType media_type); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 433 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 434 | // Triggered when a local sender has been removed from a local session |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 435 | // description. |
| 436 | // This method triggers DestroyAudioSender or DestroyVideoSender if a stream |
| 437 | // has been removed from the local SessionDescription and the stream can be |
| 438 | // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 439 | void OnLocalSenderRemoved(const RtpSenderInfo& sender_info, |
| 440 | cricket::MediaType media_type); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 441 | |
| 442 | void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 443 | void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 444 | void UpdateClosingRtpDataChannels( |
| 445 | const std::vector<std::string>& active_channels, |
| 446 | bool is_local_update); |
| 447 | void CreateRemoteRtpDataChannel(const std::string& label, |
| 448 | uint32_t remote_ssrc); |
| 449 | |
| 450 | // Creates channel and adds it to the collection of DataChannels that will |
| 451 | // be offered in a SessionDescription. |
| 452 | rtc::scoped_refptr<DataChannel> InternalCreateDataChannel( |
| 453 | const std::string& label, |
| 454 | const InternalDataChannelInit* config); |
| 455 | |
| 456 | // Checks if any data channel has been added. |
| 457 | bool HasDataChannels() const; |
| 458 | |
| 459 | void AllocateSctpSids(rtc::SSLRole role); |
| 460 | void OnSctpDataChannelClosed(DataChannel* channel); |
| 461 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 462 | void OnDataChannelDestroyed(); |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 463 | // Called when a valid data channel OPEN message is received. |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 464 | void OnDataChannelOpenMessage(const std::string& label, |
| 465 | const InternalDataChannelInit& config); |
| 466 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 467 | // Returns true if the PeerConnection is configured to use Unified Plan |
| 468 | // semantics for creating offers/answers and setting local/remote |
| 469 | // descriptions. If this is true the RtpTransceiver API will also be available |
| 470 | // to the user. If this is false, Plan B semantics are assumed. |
Steve Anton | 79e7960 | 2017-11-20 18:25:56 | [diff] [blame] | 471 | // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once |
| 472 | // sufficient time has passed. |
| 473 | bool IsUnifiedPlan() const { |
| 474 | return configuration_.sdp_semantics == SdpSemantics::kUnifiedPlan; |
| 475 | } |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 476 | |
| 477 | // Is there an RtpSender of the given type? |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 478 | bool HasRtpSender(cricket::MediaType type) const; |
deadbeef | fac0655 | 2015-11-25 19:26:01 | [diff] [blame] | 479 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 480 | // Return the RtpSender with the given track attached. |
| 481 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> |
| 482 | FindSenderForTrack(MediaStreamTrackInterface* track) const; |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 483 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 484 | // Return the RtpSender with the given id, or null if none exists. |
| 485 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> |
| 486 | FindSenderById(const std::string& sender_id) const; |
| 487 | |
| 488 | // Return the RtpReceiver with the given id, or null if none exists. |
| 489 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
| 490 | FindReceiverById(const std::string& receiver_id) const; |
| 491 | |
| 492 | std::vector<RtpSenderInfo>* GetRemoteSenderInfos( |
| 493 | cricket::MediaType media_type); |
| 494 | std::vector<RtpSenderInfo>* GetLocalSenderInfos( |
| 495 | cricket::MediaType media_type); |
| 496 | const RtpSenderInfo* FindSenderInfo(const std::vector<RtpSenderInfo>& infos, |
| 497 | const std::string& stream_label, |
| 498 | const std::string sender_id) const; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 499 | |
| 500 | // Returns the specified SCTP DataChannel in sctp_data_channels_, |
| 501 | // or nullptr if not found. |
| 502 | DataChannel* FindDataChannelBySid(int sid) const; |
| 503 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 504 | // Called when first configuring the port allocator. |
deadbeef | 91dd567 | 2016-05-18 23:55:30 | [diff] [blame] | 505 | bool InitializePortAllocator_n(const RTCConfiguration& configuration); |
deadbeef | 293e926 | 2017-01-11 20:28:30 | [diff] [blame] | 506 | // Called when SetConfiguration is called to apply the supported subset |
| 507 | // of the configuration on the network thread. |
| 508 | bool ReconfigurePortAllocator_n( |
| 509 | const cricket::ServerAddresses& stun_servers, |
| 510 | const std::vector<cricket::RelayServerConfig>& turn_servers, |
| 511 | IceTransportsType type, |
| 512 | int candidate_pool_size, |
Jonas Oreland | bdcee28 | 2017-10-10 12:01:40 | [diff] [blame] | 513 | bool prune_turn_ports, |
| 514 | webrtc::TurnCustomizer* turn_customizer); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 515 | |
Elad Alon | 99c3fe5 | 2017-10-13 14:29:40 | [diff] [blame] | 516 | // Starts output of an RTC event log to the given output object. |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 517 | // This function should only be called from the worker thread. |
Bjorn Terelius | de93943 | 2017-11-20 16:38:14 | [diff] [blame] | 518 | bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output, |
| 519 | int64_t output_period_ms); |
Elad Alon | 99c3fe5 | 2017-10-13 14:29:40 | [diff] [blame] | 520 | |
Elad Alon | acb2417 | 2017-10-06 12:32:13 | [diff] [blame] | 521 | // Stops recording an RTC event log. |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 522 | // This function should only be called from the worker thread. |
| 523 | void StopRtcEventLog_w(); |
| 524 | |
Steve Anton | 038834f | 2017-07-14 22:59:59 | [diff] [blame] | 525 | // Ensures the configuration doesn't have any parameters with invalid values, |
| 526 | // or values that conflict with other parameters. |
| 527 | // |
| 528 | // Returns RTCError::OK() if there are no issues. |
| 529 | RTCError ValidateConfiguration(const RTCConfiguration& config) const; |
| 530 | |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 531 | cricket::ChannelManager* channel_manager() const; |
| 532 | MetricsObserverInterface* metrics_observer() const; |
| 533 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 534 | // Indicates the type of SessionDescription in a call to SetLocalDescription |
| 535 | // and SetRemoteDescription. |
| 536 | enum Action { |
| 537 | kOffer, |
| 538 | kPrAnswer, |
| 539 | kAnswer, |
| 540 | }; |
| 541 | |
| 542 | // Returns the last error in the session. See the enum above for details. |
| 543 | Error error() const { return error_; } |
| 544 | const std::string& error_desc() const { return error_desc_; } |
| 545 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 546 | cricket::BaseChannel* GetChannel(const std::string& content_name); |
| 547 | |
| 548 | // Get current SSL role used by SCTP's underlying transport. |
| 549 | bool GetSctpSslRole(rtc::SSLRole* role); |
| 550 | |
Henrik Boström | 3163867 | 2017-11-23 16:48:32 | [diff] [blame^] | 551 | // Validates and takes ownership of the description, setting it as the current |
| 552 | // or pending description (depending on the description's action) if it is |
| 553 | // valid. Also updates ice role, candidates, creates and destroys channels. |
| 554 | bool SetCurrentOrPendingLocalDescription( |
| 555 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 556 | std::string* err_desc); |
| 557 | bool SetCurrentOrPendingRemoteDescription( |
| 558 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 559 | std::string* err_desc); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 560 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 561 | cricket::IceConfig ParseIceConfig( |
| 562 | const PeerConnectionInterface::RTCConfiguration& config) const; |
| 563 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 564 | // Implements DataChannelProviderInterface. |
| 565 | bool SendData(const cricket::SendDataParams& params, |
| 566 | const rtc::CopyOnWriteBuffer& payload, |
| 567 | cricket::SendDataResult* result) override; |
| 568 | bool ConnectDataChannel(DataChannel* webrtc_data_channel) override; |
| 569 | void DisconnectDataChannel(DataChannel* webrtc_data_channel) override; |
| 570 | void AddSctpDataStream(int sid) override; |
| 571 | void RemoveSctpDataStream(int sid) override; |
| 572 | bool ReadyToSendData() const override; |
| 573 | |
| 574 | cricket::DataChannelType data_channel_type() const; |
| 575 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 576 | // Called when an RTCCertificate is generated or retrieved by |
| 577 | // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription. |
| 578 | void OnCertificateReady( |
| 579 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
| 580 | void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp); |
| 581 | |
| 582 | cricket::TransportController* transport_controller() const { |
| 583 | return transport_controller_.get(); |
| 584 | } |
| 585 | |
| 586 | // Return all managed, non-null channels. |
| 587 | std::vector<cricket::BaseChannel*> Channels() const; |
| 588 | |
| 589 | // Non-const versions of local_description()/remote_description(), for use |
| 590 | // internally. |
| 591 | SessionDescriptionInterface* mutable_local_description() { |
| 592 | return pending_local_description_ ? pending_local_description_.get() |
| 593 | : current_local_description_.get(); |
| 594 | } |
| 595 | SessionDescriptionInterface* mutable_remote_description() { |
| 596 | return pending_remote_description_ ? pending_remote_description_.get() |
| 597 | : current_remote_description_.get(); |
| 598 | } |
| 599 | |
| 600 | // Updates the error state, signaling if necessary. |
| 601 | void SetError(Error error, const std::string& error_desc); |
| 602 | |
| 603 | bool UpdateSessionState(Action action, |
| 604 | cricket::ContentSource source, |
| 605 | std::string* err_desc); |
| 606 | Action GetAction(const std::string& type); |
| 607 | // Push the media parts of the local or remote session description |
| 608 | // down to all of the channels. |
| 609 | bool PushdownMediaDescription(cricket::ContentAction action, |
| 610 | cricket::ContentSource source, |
| 611 | std::string* error_desc); |
| 612 | bool PushdownSctpParameters_n(cricket::ContentSource source); |
| 613 | |
| 614 | bool PushdownTransportDescription(cricket::ContentSource source, |
| 615 | cricket::ContentAction action, |
| 616 | std::string* error_desc); |
| 617 | |
| 618 | // Helper methods to push local and remote transport descriptions. |
| 619 | bool PushdownLocalTransportDescription( |
| 620 | const cricket::SessionDescription* sdesc, |
| 621 | cricket::ContentAction action, |
| 622 | std::string* error_desc); |
| 623 | bool PushdownRemoteTransportDescription( |
| 624 | const cricket::SessionDescription* sdesc, |
| 625 | cricket::ContentAction action, |
| 626 | std::string* error_desc); |
| 627 | |
| 628 | // Returns true and the TransportInfo of the given |content_name| |
| 629 | // from |description|. Returns false if it's not available. |
| 630 | static bool GetTransportDescription( |
| 631 | const cricket::SessionDescription* description, |
| 632 | const std::string& content_name, |
| 633 | cricket::TransportDescription* info); |
| 634 | |
| 635 | // Returns the name of the transport channel when BUNDLE is enabled, or |
| 636 | // nullptr if the channel is not part of any bundle. |
| 637 | const std::string* GetBundleTransportName( |
| 638 | const cricket::ContentInfo* content, |
| 639 | const cricket::ContentGroup* bundle); |
| 640 | |
| 641 | // Cause all the BaseChannels in the bundle group to have the same |
| 642 | // transport channel. |
| 643 | bool EnableBundle(const cricket::ContentGroup& bundle); |
| 644 | |
| 645 | // Enables media channels to allow sending of media. |
| 646 | void EnableChannels(); |
| 647 | // Returns the media index for a local ice candidate given the content name. |
| 648 | // Returns false if the local session description does not have a media |
| 649 | // content called |content_name|. |
| 650 | bool GetLocalCandidateMediaIndex(const std::string& content_name, |
| 651 | int* sdp_mline_index); |
| 652 | // Uses all remote candidates in |remote_desc| in this session. |
| 653 | bool UseCandidatesInSessionDescription( |
| 654 | const SessionDescriptionInterface* remote_desc); |
| 655 | // Uses |candidate| in this session. |
| 656 | bool UseCandidate(const IceCandidateInterface* candidate); |
| 657 | // Deletes the corresponding channel of contents that don't exist in |desc|. |
| 658 | // |desc| can be null. This means that all channels are deleted. |
| 659 | void RemoveUnusedChannels(const cricket::SessionDescription* desc); |
| 660 | |
| 661 | // Allocates media channels based on the |desc|. If |desc| doesn't have |
| 662 | // the BUNDLE option, this method will disable BUNDLE in PortAllocator. |
| 663 | // This method will also delete any existing media channels before creating. |
| 664 | bool CreateChannels(const cricket::SessionDescription* desc); |
| 665 | |
| 666 | // Helper methods to create media channels. |
| 667 | bool CreateVoiceChannel(const cricket::ContentInfo* content, |
| 668 | const std::string* bundle_transport); |
| 669 | bool CreateVideoChannel(const cricket::ContentInfo* content, |
| 670 | const std::string* bundle_transport); |
| 671 | bool CreateDataChannel(const cricket::ContentInfo* content, |
| 672 | const std::string* bundle_transport); |
| 673 | |
| 674 | std::unique_ptr<SessionStats> GetSessionStats_n( |
| 675 | const ChannelNamePairs& channel_name_pairs); |
| 676 | |
| 677 | bool CreateSctpTransport_n(const std::string& content_name, |
| 678 | const std::string& transport_name); |
| 679 | // For bundling. |
| 680 | void ChangeSctpTransport_n(const std::string& transport_name); |
| 681 | void DestroySctpTransport_n(); |
| 682 | // SctpTransport signal handlers. Needed to marshal signals from the network |
| 683 | // to signaling thread. |
| 684 | void OnSctpTransportReadyToSendData_n(); |
| 685 | // This may be called with "false" if the direction of the m= section causes |
| 686 | // us to tear down the SCTP connection. |
| 687 | void OnSctpTransportReadyToSendData_s(bool ready); |
| 688 | void OnSctpTransportDataReceived_n(const cricket::ReceiveDataParams& params, |
| 689 | const rtc::CopyOnWriteBuffer& payload); |
| 690 | // Beyond just firing the signal to the signaling thread, listens to SCTP |
| 691 | // CONTROL messages on unused SIDs and processes them as OPEN messages. |
| 692 | void OnSctpTransportDataReceived_s(const cricket::ReceiveDataParams& params, |
| 693 | const rtc::CopyOnWriteBuffer& payload); |
| 694 | void OnSctpStreamClosedRemotely_n(int sid); |
| 695 | |
| 696 | bool ValidateBundleSettings(const cricket::SessionDescription* desc); |
| 697 | bool HasRtcpMuxEnabled(const cricket::ContentInfo* content); |
| 698 | // Below methods are helper methods which verifies SDP. |
| 699 | bool ValidateSessionDescription(const SessionDescriptionInterface* sdesc, |
| 700 | cricket::ContentSource source, |
| 701 | std::string* err_desc); |
| 702 | |
| 703 | // Check if a call to SetLocalDescription is acceptable with |action|. |
| 704 | bool ExpectSetLocalDescription(Action action); |
| 705 | // Check if a call to SetRemoteDescription is acceptable with |action|. |
| 706 | bool ExpectSetRemoteDescription(Action action); |
| 707 | // Verifies a=setup attribute as per RFC 5763. |
| 708 | bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc, |
| 709 | Action action); |
| 710 | |
| 711 | // Returns true if we are ready to push down the remote candidate. |
| 712 | // |remote_desc| is the new remote description, or NULL if the current remote |
| 713 | // description should be used. Output |valid| is true if the candidate media |
| 714 | // index is valid. |
| 715 | bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate, |
| 716 | const SessionDescriptionInterface* remote_desc, |
| 717 | bool* valid); |
| 718 | |
| 719 | // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by |
| 720 | // this session. |
| 721 | bool SrtpRequired() const; |
| 722 | |
| 723 | // TransportController signal handlers. |
| 724 | void OnTransportControllerConnectionState(cricket::IceConnectionState state); |
| 725 | void OnTransportControllerGatheringState(cricket::IceGatheringState state); |
| 726 | void OnTransportControllerCandidatesGathered( |
| 727 | const std::string& transport_name, |
| 728 | const std::vector<cricket::Candidate>& candidates); |
| 729 | void OnTransportControllerCandidatesRemoved( |
| 730 | const std::vector<cricket::Candidate>& candidates); |
| 731 | void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error); |
| 732 | |
| 733 | std::string GetSessionErrorMsg(); |
| 734 | |
| 735 | // Invoked when TransportController connection completion is signaled. |
| 736 | // Reports stats for all transports in use. |
| 737 | void ReportTransportStats(); |
| 738 | |
| 739 | // Gather the usage of IPv4/IPv6 as best connection. |
| 740 | void ReportBestConnectionState(const cricket::TransportStats& stats); |
| 741 | |
| 742 | void ReportNegotiatedCiphers(const cricket::TransportStats& stats); |
| 743 | |
| 744 | void OnSentPacket_w(const rtc::SentPacket& sent_packet); |
| 745 | |
| 746 | const std::string GetTransportName(const std::string& content_name); |
| 747 | |
| 748 | void DestroyRtcpTransport_n(const std::string& transport_name); |
| 749 | void RemoveAndDestroyVideoChannel(cricket::VideoChannel* video_channel); |
| 750 | void DestroyVideoChannel(cricket::VideoChannel* video_channel); |
| 751 | void RemoveAndDestroyVoiceChannel(cricket::VoiceChannel* voice_channel); |
| 752 | void DestroyVoiceChannel(cricket::VoiceChannel* voice_channel); |
| 753 | void DestroyDataChannel(); |
| 754 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 755 | // Storing the factory as a scoped reference pointer ensures that the memory |
| 756 | // in the PeerConnectionFactoryImpl remains available as long as the |
| 757 | // PeerConnection is running. It is passed to PeerConnection as a raw pointer. |
| 758 | // However, since the reference counting is done in the |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 759 | // PeerConnectionFactoryInterface all instances created using the raw pointer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 760 | // will refer to the same reference count. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 761 | rtc::scoped_refptr<PeerConnectionFactory> factory_; |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 762 | PeerConnectionObserver* observer_ = nullptr; |
| 763 | UMAObserver* uma_observer_ = nullptr; |
terelius | 3386025 | 2017-05-13 06:37:18 | [diff] [blame] | 764 | |
| 765 | // The EventLog needs to outlive |call_| (and any other object that uses it). |
| 766 | std::unique_ptr<RtcEventLog> event_log_; |
| 767 | |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 768 | SignalingState signaling_state_ = kStable; |
| 769 | IceConnectionState ice_connection_state_ = kIceConnectionNew; |
| 770 | IceGatheringState ice_gathering_state_ = kIceGatheringNew; |
deadbeef | 46c7389 | 2016-11-17 03:42:04 | [diff] [blame] | 771 | PeerConnectionInterface::RTCConfiguration configuration_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 772 | |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 773 | std::unique_ptr<cricket::PortAllocator> port_allocator_; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 774 | |
zhihuang | 8f65cdf | 2016-05-07 01:40:30 | [diff] [blame] | 775 | // One PeerConnection has only one RTCP CNAME. |
| 776 | // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9 |
| 777 | std::string rtcp_cname_; |
| 778 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 779 | // Streams added via AddStream. |
| 780 | rtc::scoped_refptr<StreamCollection> local_streams_; |
| 781 | // Streams created as a result of SetRemoteDescription. |
| 782 | rtc::scoped_refptr<StreamCollection> remote_streams_; |
| 783 | |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 784 | std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_; |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 785 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 786 | // These lists store sender info seen in local/remote descriptions. |
| 787 | std::vector<RtpSenderInfo> remote_audio_sender_infos_; |
| 788 | std::vector<RtpSenderInfo> remote_video_sender_infos_; |
| 789 | std::vector<RtpSenderInfo> local_audio_sender_infos_; |
| 790 | std::vector<RtpSenderInfo> local_video_sender_infos_; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 791 | |
| 792 | SctpSidAllocator sid_allocator_; |
| 793 | // label -> DataChannel |
| 794 | std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; |
| 795 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; |
deadbeef | bd29246 | 2015-12-15 02:15:29 | [diff] [blame] | 796 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 797 | |
deadbeef | bda7e0b | 2015-12-09 01:13:40 | [diff] [blame] | 798 | bool remote_peer_supports_msid_ = false; |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 799 | |
terelius | 3386025 | 2017-05-13 06:37:18 | [diff] [blame] | 800 | std::unique_ptr<Call> call_; |
terelius | 3386025 | 2017-05-13 06:37:18 | [diff] [blame] | 801 | std::unique_ptr<StatsCollector> stats_; // A pointer is passed to senders_ |
| 802 | rtc::scoped_refptr<RTCStatsCollector> stats_collector_; |
| 803 | |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 804 | std::vector< |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 805 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 806 | transceivers_; |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 807 | |
| 808 | Error error_ = ERROR_NONE; |
| 809 | std::string error_desc_; |
| 810 | |
| 811 | std::string session_id_; |
| 812 | rtc::Optional<bool> initial_offerer_; |
| 813 | |
| 814 | std::unique_ptr<cricket::TransportController> transport_controller_; |
| 815 | std::unique_ptr<cricket::SctpTransportInternalFactory> sctp_factory_; |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 816 | // |rtp_data_channel_| is used if in RTP data channel mode, |sctp_transport_| |
| 817 | // when using SCTP. |
| 818 | cricket::RtpDataChannel* rtp_data_channel_ = nullptr; |
| 819 | |
| 820 | std::unique_ptr<cricket::SctpTransportInternal> sctp_transport_; |
| 821 | // |sctp_transport_name_| keeps track of what DTLS transport the SCTP |
| 822 | // transport is using (which can change due to bundling). |
| 823 | rtc::Optional<std::string> sctp_transport_name_; |
| 824 | // |sctp_content_name_| is the content name (MID) in SDP. |
| 825 | rtc::Optional<std::string> sctp_content_name_; |
| 826 | // Value cached on signaling thread. Only updated when SctpReadyToSendData |
| 827 | // fires on the signaling thread. |
| 828 | bool sctp_ready_to_send_data_ = false; |
| 829 | // Same as signals provided by SctpTransport, but these are guaranteed to |
| 830 | // fire on the signaling thread, whereas SctpTransport fires on the networking |
| 831 | // thread. |
| 832 | // |sctp_invoker_| is used so that any signals queued on the signaling thread |
| 833 | // from the network thread are immediately discarded if the SctpTransport is |
| 834 | // destroyed (due to m= section being rejected). |
| 835 | // TODO(deadbeef): Use a proxy object to ensure that method calls/signals |
| 836 | // are marshalled to the right thread. Could almost use proxy.h for this, |
| 837 | // but it doesn't have a mechanism for marshalling sigslot::signals |
| 838 | std::unique_ptr<rtc::AsyncInvoker> sctp_invoker_; |
| 839 | sigslot::signal1<bool> SignalSctpReadyToSendData; |
| 840 | sigslot::signal2<const cricket::ReceiveDataParams&, |
| 841 | const rtc::CopyOnWriteBuffer&> |
| 842 | SignalSctpDataReceived; |
| 843 | sigslot::signal1<int> SignalSctpStreamClosedRemotely; |
| 844 | |
| 845 | std::unique_ptr<SessionDescriptionInterface> current_local_description_; |
| 846 | std::unique_ptr<SessionDescriptionInterface> pending_local_description_; |
| 847 | std::unique_ptr<SessionDescriptionInterface> current_remote_description_; |
| 848 | std::unique_ptr<SessionDescriptionInterface> pending_remote_description_; |
| 849 | bool dtls_enabled_ = false; |
| 850 | // Specifies which kind of data channel is allowed. This is controlled |
| 851 | // by the chrome command-line flag and constraints: |
| 852 | // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled, |
| 853 | // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is |
| 854 | // not set or false, SCTP is allowed (DCT_SCTP); |
| 855 | // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP); |
| 856 | // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE). |
| 857 | cricket::DataChannelType data_channel_type_ = cricket::DCT_NONE; |
| 858 | // List of content names for which the remote side triggered an ICE restart. |
| 859 | std::set<std::string> pending_ice_restarts_; |
| 860 | |
| 861 | std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_; |
| 862 | |
| 863 | // Member variables for caching global options. |
| 864 | cricket::AudioOptions audio_options_; |
| 865 | cricket::VideoOptions video_options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 866 | }; |
| 867 | |
| 868 | } // namespace webrtc |
| 869 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 870 | #endif // PC_PEERCONNECTION_H_ |