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