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