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