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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_PEER_CONNECTION_H_ |
| 12 | #define PC_PEER_CONNECTION_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> |
Henrik Boström | 79b6980 | 2019-07-18 09:16:56 | [diff] [blame] | 18 | #include <utility> |
perkj | d61bf80 | 2016-03-24 10:16:19 | [diff] [blame] | 19 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 20 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 21 | #include "api/peer_connection_interface.h" |
Niels Möller | 65f17ca | 2019-09-12 11:59:36 | [diff] [blame] | 22 | #include "api/transport/data_channel_transport_interface.h" |
| 23 | #include "api/transport/media/media_transport_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 24 | #include "api/turn_customizer.h" |
| 25 | #include "pc/ice_server_parsing.h" |
| 26 | #include "pc/jsep_transport_controller.h" |
| 27 | #include "pc/peer_connection_factory.h" |
| 28 | #include "pc/peer_connection_internal.h" |
| 29 | #include "pc/rtc_stats_collector.h" |
Guido Urdaneta | 1ff16c8 | 2019-05-20 17:31:53 | [diff] [blame] | 30 | #include "pc/rtp_sender.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 31 | #include "pc/rtp_transceiver.h" |
Harald Alvestrand | c85328f | 2019-02-28 06:51:00 | [diff] [blame] | 32 | #include "pc/sctp_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 33 | #include "pc/stats_collector.h" |
| 34 | #include "pc/stream_collection.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 35 | #include "pc/webrtc_session_description_factory.h" |
Jonas Olsson | 0182a03 | 2019-07-09 10:31:20 | [diff] [blame] | 36 | #include "rtc_base/experiments/field_trial_parser.h" |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 37 | #include "rtc_base/race_checker.h" |
Amit Hilbuch | dbb49df | 2019-01-23 22:54:24 | [diff] [blame] | 38 | #include "rtc_base/unique_id_generator.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 39 | |
| 40 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 41 | |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 42 | class MediaStreamObserver; |
perkj | f0dcfe2 | 2016-03-10 17:32:00 | [diff] [blame] | 43 | class VideoRtpReceiver; |
skvlad | 11a9cbf | 2016-10-07 18:53:05 | [diff] [blame] | 44 | class RtcEventLog; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 45 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 46 | // PeerConnection is the implementation of the PeerConnection object as defined |
| 47 | // by the PeerConnectionInterface API surface. |
| 48 | // The class currently is solely responsible for the following: |
| 49 | // - Managing the session state machine (signaling state). |
| 50 | // - Creating and initializing lower-level objects, like PortAllocator and |
| 51 | // BaseChannels. |
| 52 | // - Owning and managing the life cycle of the RtpSender/RtpReceiver and track |
| 53 | // objects. |
| 54 | // - Tracking the current and pending local/remote session descriptions. |
| 55 | // The class currently is jointly responsible for the following: |
| 56 | // - Parsing and interpreting SDP. |
| 57 | // - Generating offers and answers based on the current state. |
| 58 | // - The ICE state machine. |
| 59 | // - Generating stats. |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 60 | class PeerConnection : public PeerConnectionInternal, |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 61 | public DataChannelProviderInterface, |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 62 | public DataChannelSink, |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 63 | public JsepTransportController::Observer, |
Guido Urdaneta | 1ff16c8 | 2019-05-20 17:31:53 | [diff] [blame] | 64 | public RtpSenderBase::SetStreamsObserver, |
Steve Anton | ad18276 | 2018-09-05 20:22:40 | [diff] [blame] | 65 | public rtc::MessageHandler, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 66 | public sigslot::has_slots<> { |
| 67 | public: |
Qingsi Wang | 1ba5dec | 2019-08-19 18:57:17 | [diff] [blame] | 68 | // A bit in the usage pattern is registered when its defining event occurs at |
| 69 | // least once. |
Harald Alvestrand | 8ebba74 | 2018-05-31 12:00:34 | [diff] [blame] | 70 | enum class UsageEvent : int { |
| 71 | TURN_SERVER_ADDED = 0x01, |
| 72 | STUN_SERVER_ADDED = 0x02, |
| 73 | DATA_ADDED = 0x04, |
| 74 | AUDIO_ADDED = 0x08, |
| 75 | VIDEO_ADDED = 0x10, |
Qingsi Wang | 1ba5dec | 2019-08-19 18:57:17 | [diff] [blame] | 76 | // |SetLocalDescription| returns successfully. |
| 77 | SET_LOCAL_DESCRIPTION_SUCCEEDED = 0x20, |
| 78 | // |SetRemoteDescription| returns successfully. |
| 79 | SET_REMOTE_DESCRIPTION_SUCCEEDED = 0x40, |
| 80 | // A local candidate (with type host, server-reflexive, or relay) is |
| 81 | // collected. |
Harald Alvestrand | 8ebba74 | 2018-05-31 12:00:34 | [diff] [blame] | 82 | CANDIDATE_COLLECTED = 0x80, |
Qingsi Wang | 1ba5dec | 2019-08-19 18:57:17 | [diff] [blame] | 83 | // A remote candidate is successfully added via |AddIceCandidate|. |
| 84 | ADD_ICE_CANDIDATE_SUCCEEDED = 0x100, |
Harald Alvestrand | 8ebba74 | 2018-05-31 12:00:34 | [diff] [blame] | 85 | ICE_STATE_CONNECTED = 0x200, |
Qingsi Wang | 7fc821d | 2018-07-12 19:54:53 | [diff] [blame] | 86 | CLOSE_CALLED = 0x400, |
Qingsi Wang | 1ba5dec | 2019-08-19 18:57:17 | [diff] [blame] | 87 | // A local candidate with private IP is collected. |
Harald Alvestrand | 056d811 | 2018-07-16 17:18:58 | [diff] [blame] | 88 | PRIVATE_CANDIDATE_COLLECTED = 0x800, |
Qingsi Wang | 1ba5dec | 2019-08-19 18:57:17 | [diff] [blame] | 89 | // A remote candidate with private IP is added, either via AddiceCandidate |
| 90 | // or from the remote description. |
Jeroen de Borst | af242c8 | 2019-04-24 20:13:48 | [diff] [blame] | 91 | REMOTE_PRIVATE_CANDIDATE_ADDED = 0x1000, |
Qingsi Wang | 1ba5dec | 2019-08-19 18:57:17 | [diff] [blame] | 92 | // A local mDNS candidate is collected. |
Jeroen de Borst | af242c8 | 2019-04-24 20:13:48 | [diff] [blame] | 93 | MDNS_CANDIDATE_COLLECTED = 0x2000, |
Qingsi Wang | 1ba5dec | 2019-08-19 18:57:17 | [diff] [blame] | 94 | // A remote mDNS candidate is added, either via AddIceCandidate or from the |
| 95 | // remote description. |
Jeroen de Borst | af242c8 | 2019-04-24 20:13:48 | [diff] [blame] | 96 | REMOTE_MDNS_CANDIDATE_ADDED = 0x4000, |
Qingsi Wang | 1ba5dec | 2019-08-19 18:57:17 | [diff] [blame] | 97 | // A local candidate with IPv6 address is collected. |
| 98 | IPV6_CANDIDATE_COLLECTED = 0x8000, |
| 99 | // A remote candidate with IPv6 address is added, either via AddIceCandidate |
| 100 | // or from the remote description. |
| 101 | REMOTE_IPV6_CANDIDATE_ADDED = 0x10000, |
| 102 | // A remote candidate (with type host, server-reflexive, or relay) is |
| 103 | // successfully added, either via AddIceCandidate or from the remote |
| 104 | // description. |
| 105 | REMOTE_CANDIDATE_ADDED = 0x20000, |
Qingsi Wang | cc46b10c | 2019-09-12 18:19:01 | [diff] [blame] | 106 | // An explicit host-host candidate pair is selected, i.e. both the local and |
| 107 | // the remote candidates have the host type. This does not include candidate |
| 108 | // pairs formed with equivalent prflx remote candidates, e.g. a host-prflx |
| 109 | // pair where the prflx candidate has the same base as a host candidate of |
| 110 | // the remote peer. |
| 111 | DIRECT_CONNECTION_SELECTED = 0x40000, |
| 112 | MAX_VALUE = 0x80000, |
Harald Alvestrand | 8ebba74 | 2018-05-31 12:00:34 | [diff] [blame] | 113 | }; |
| 114 | |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 115 | explicit PeerConnection(PeerConnectionFactory* factory, |
| 116 | std::unique_ptr<RtcEventLog> event_log, |
| 117 | std::unique_ptr<Call> call); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 118 | |
deadbeef | 653b8e0 | 2015-11-11 20:55:10 | [diff] [blame] | 119 | bool Initialize( |
| 120 | const PeerConnectionInterface::RTCConfiguration& configuration, |
Benjamin Wright | cab58888 | 2018-05-02 22:12:47 | [diff] [blame] | 121 | PeerConnectionDependencies dependencies); |
deadbeef | 653b8e0 | 2015-11-11 20:55:10 | [diff] [blame] | 122 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 123 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override; |
| 124 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override; |
| 125 | bool AddStream(MediaStreamInterface* local_stream) override; |
| 126 | void RemoveStream(MediaStreamInterface* local_stream) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 127 | |
Steve Anton | 2d6c76a | 2018-01-06 01:10:52 | [diff] [blame] | 128 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack( |
Steve Anton | f9381f0 | 2017-12-14 18:23:57 | [diff] [blame] | 129 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 130 | const std::vector<std::string>& stream_ids) override; |
deadbeef | e1f9d83 | 2016-01-14 23:35:42 | [diff] [blame] | 131 | bool RemoveTrack(RtpSenderInterface* sender) override; |
Steve Anton | 24db573 | 2018-07-23 17:27:33 | [diff] [blame] | 132 | RTCError RemoveTrackNew( |
| 133 | rtc::scoped_refptr<RtpSenderInterface> sender) override; |
deadbeef | e1f9d83 | 2016-01-14 23:35:42 | [diff] [blame] | 134 | |
Steve Anton | 9158ef6 | 2017-11-27 21:01:52 | [diff] [blame] | 135 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 136 | rtc::scoped_refptr<MediaStreamTrackInterface> track) override; |
| 137 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 138 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 139 | const RtpTransceiverInit& init) override; |
| 140 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 141 | cricket::MediaType media_type) override; |
| 142 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 143 | cricket::MediaType media_type, |
| 144 | const RtpTransceiverInit& init) override; |
| 145 | |
Steve Anton | 8c0f7a7 | 2017-10-03 17:03:10 | [diff] [blame] | 146 | // Gets the DTLS SSL certificate associated with the audio transport on the |
| 147 | // remote side. This will become populated once the DTLS connection with the |
| 148 | // peer has been completed, as indicated by the ICE connection state |
| 149 | // transitioning to kIceConnectionCompleted. |
| 150 | // Note that this will be removed once we implement RTCDtlsTransport which |
| 151 | // has standardized method for getting this information. |
| 152 | // See https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface |
| 153 | std::unique_ptr<rtc::SSLCertificate> GetRemoteAudioSSLCertificate(); |
| 154 | |
Zhi Huang | 70b820f | 2018-01-27 22:16:15 | [diff] [blame] | 155 | // Version of the above method that returns the full certificate chain. |
| 156 | std::unique_ptr<rtc::SSLCertChain> GetRemoteAudioSSLCertChain(); |
| 157 | |
deadbeef | fac0655 | 2015-11-25 19:26:01 | [diff] [blame] | 158 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
deadbeef | bd7d8f7 | 2015-12-19 00:58:44 | [diff] [blame] | 159 | const std::string& kind, |
| 160 | const std::string& stream_id) override; |
deadbeef | fac0655 | 2015-11-25 19:26:01 | [diff] [blame] | 161 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 162 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 163 | const override; |
| 164 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 165 | const override; |
Steve Anton | 9158ef6 | 2017-11-27 21:01:52 | [diff] [blame] | 166 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers() |
| 167 | const override; |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 168 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 169 | rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 170 | const std::string& label, |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 171 | const DataChannelInit* config) override; |
Henrik Boström | 1df1bf8 | 2018-03-20 12:24:20 | [diff] [blame] | 172 | // WARNING: LEGACY. See peerconnectioninterface.h |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 173 | bool GetStats(StatsObserver* observer, |
| 174 | webrtc::MediaStreamTrackInterface* track, |
| 175 | StatsOutputLevel level) override; |
Henrik Boström | 1df1bf8 | 2018-03-20 12:24:20 | [diff] [blame] | 176 | // Spec-complaint GetStats(). See peerconnectioninterface.h |
hbos | 74e1a4f | 2016-09-16 06:33:01 | [diff] [blame] | 177 | void GetStats(RTCStatsCollectorCallback* callback) override; |
Henrik Boström | 1df1bf8 | 2018-03-20 12:24:20 | [diff] [blame] | 178 | void GetStats( |
| 179 | rtc::scoped_refptr<RtpSenderInterface> selector, |
| 180 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override; |
| 181 | void GetStats( |
| 182 | rtc::scoped_refptr<RtpReceiverInterface> selector, |
| 183 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override; |
Harald Alvestrand | 8906187 | 2018-01-02 13:08:34 | [diff] [blame] | 184 | void ClearStatsCache() 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 | SignalingState signaling_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 187 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 188 | IceConnectionState ice_connection_state() override; |
Jonas Olsson | 1204690 | 2018-12-06 10:25:14 | [diff] [blame] | 189 | IceConnectionState standardized_ice_connection_state() override; |
Jonas Olsson | 635474e | 2018-10-18 13:58:17 | [diff] [blame] | 190 | PeerConnectionState peer_connection_state() override; |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 191 | IceGatheringState ice_gathering_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 192 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 193 | const SessionDescriptionInterface* local_description() const override; |
| 194 | const SessionDescriptionInterface* remote_description() const override; |
deadbeef | fe4a8a4 | 2016-12-21 01:56:17 | [diff] [blame] | 195 | const SessionDescriptionInterface* current_local_description() const override; |
| 196 | const SessionDescriptionInterface* current_remote_description() |
| 197 | const override; |
| 198 | const SessionDescriptionInterface* pending_local_description() const override; |
| 199 | const SessionDescriptionInterface* pending_remote_description() |
| 200 | const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 201 | |
Henrik Boström | 79b6980 | 2019-07-18 09:16:56 | [diff] [blame] | 202 | void RestartIce() override; |
| 203 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 204 | // JSEP01 |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 205 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 206 | const RTCOfferAnswerOptions& options) override; |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 207 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 208 | const RTCOfferAnswerOptions& options) override; |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 209 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 210 | SessionDescriptionInterface* desc) override; |
Henrik Boström | a4ecf55 | 2017-11-23 14:17:07 | [diff] [blame] | 211 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 212 | SessionDescriptionInterface* desc) override; |
Henrik Boström | 3163867 | 2017-11-23 16:48:32 | [diff] [blame] | 213 | void SetRemoteDescription( |
| 214 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 215 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) |
| 216 | override; |
deadbeef | 46c7389 | 2016-11-17 03:42:04 | [diff] [blame] | 217 | PeerConnectionInterface::RTCConfiguration GetConfiguration() override; |
Niels Möller | 2579f0c | 2019-08-19 07:58:17 | [diff] [blame] | 218 | RTCError SetConfiguration( |
| 219 | const PeerConnectionInterface::RTCConfiguration& configuration) override; |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 220 | bool AddIceCandidate(const IceCandidateInterface* candidate) override; |
Honghai Zhang | 7fb69db | 2016-03-14 18:59:18 | [diff] [blame] | 221 | bool RemoveIceCandidates( |
| 222 | const std::vector<cricket::Candidate>& candidates) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 223 | |
Niels Möller | 0c4f7be | 2018-05-07 12:01:37 | [diff] [blame] | 224 | RTCError SetBitrate(const BitrateSettings& bitrate) override; |
zstein | 4b97980 | 2017-06-02 21:37:37 | [diff] [blame] | 225 | |
henrika | 5f6bf24 | 2017-11-01 10:06:56 | [diff] [blame] | 226 | void SetAudioPlayout(bool playout) override; |
| 227 | void SetAudioRecording(bool recording) override; |
| 228 | |
Harald Alvestrand | ad88c88 | 2018-11-28 15:47:46 | [diff] [blame] | 229 | rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid( |
| 230 | const std::string& mid) override; |
Harald Alvestrand | 4a7b3ac | 2019-01-17 09:39:40 | [diff] [blame] | 231 | rtc::scoped_refptr<DtlsTransport> LookupDtlsTransportByMidInternal( |
| 232 | const std::string& mid); |
Harald Alvestrand | ad88c88 | 2018-11-28 15:47:46 | [diff] [blame] | 233 | |
Harald Alvestrand | c85328f | 2019-02-28 06:51:00 | [diff] [blame] | 234 | rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const override; |
| 235 | |
Bjorn Terelius | de93943 | 2017-11-20 16:38:14 | [diff] [blame] | 236 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output, |
| 237 | int64_t output_period_ms) override; |
Niels Möller | f00ca1a | 2019-05-10 09:33:12 | [diff] [blame] | 238 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override; |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 239 | void StopRtcEventLog() override; |
| 240 | |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 241 | void Close() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 242 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 243 | // PeerConnectionInternal implementation. |
Karl Wiberg | 4ae6347 | 2019-02-21 23:57:06 | [diff] [blame] | 244 | rtc::Thread* network_thread() const final { |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 245 | return factory_->network_thread(); |
| 246 | } |
Karl Wiberg | 4ae6347 | 2019-02-21 23:57:06 | [diff] [blame] | 247 | rtc::Thread* worker_thread() const final { return factory_->worker_thread(); } |
| 248 | rtc::Thread* signaling_thread() const final { |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 249 | return factory_->signaling_thread(); |
perkj | d61bf80 | 2016-03-24 10:16:19 | [diff] [blame] | 250 | } |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 251 | |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 252 | std::string session_id() const override { |
| 253 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 254 | return session_id_; |
| 255 | } |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 256 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 257 | bool initial_offerer() const override { |
Karl Wiberg | 2cc368f | 2019-04-02 09:31:56 | [diff] [blame] | 258 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 259 | return transport_controller_ && transport_controller_->initial_offerer(); |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 260 | } |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 261 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 262 | std::vector< |
| 263 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
Steve Anton | b886711 | 2018-02-13 18:07:54 | [diff] [blame] | 264 | GetTransceiversInternal() const override { |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 265 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 266 | return transceivers_; |
| 267 | } |
| 268 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 269 | sigslot::signal1<DataChannel*>& SignalDataChannelCreated() override { |
| 270 | return SignalDataChannelCreated_; |
| 271 | } |
| 272 | |
| 273 | cricket::RtpDataChannel* rtp_data_channel() const override { |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 274 | return rtp_data_channel_; |
Steve Anton | 978b876 | 2017-09-29 19:15:02 | [diff] [blame] | 275 | } |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 276 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 277 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels() |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 278 | const override { |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 279 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 280 | return sctp_data_channels_; |
| 281 | } |
| 282 | |
Danil Chapovalov | 66cadcc | 2018-06-19 14:47:43 | [diff] [blame] | 283 | absl::optional<std::string> sctp_content_name() const override { |
Karl Wiberg | 2cc368f | 2019-04-02 09:31:56 | [diff] [blame] | 284 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 285 | return sctp_mid_; |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 286 | } |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 287 | |
Danil Chapovalov | 66cadcc | 2018-06-19 14:47:43 | [diff] [blame] | 288 | absl::optional<std::string> sctp_transport_name() const override; |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 289 | |
Qingsi Wang | 72a43a1 | 2018-02-21 00:03:18 | [diff] [blame] | 290 | cricket::CandidateStatsList GetPooledCandidateStats() const override; |
Steve Anton | 5dfde18 | 2018-02-06 18:34:40 | [diff] [blame] | 291 | std::map<std::string, std::string> GetTransportNamesByMid() const override; |
| 292 | std::map<std::string, cricket::TransportStats> GetTransportStatsByNames( |
| 293 | const std::set<std::string>& transport_names) override; |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 294 | Call::Stats GetCallStats() override; |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 295 | |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 296 | bool GetLocalCertificate( |
| 297 | const std::string& transport_name, |
| 298 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override; |
Taylor Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 299 | std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 300 | const std::string& transport_name) override; |
| 301 | bool IceRestartPending(const std::string& content_name) const override; |
| 302 | bool NeedsIceRestart(const std::string& content_name) const override; |
| 303 | bool GetSslRole(const std::string& content_name, rtc::SSLRole* role) override; |
Steve Anton | 7464fca | 2018-01-19 19:10:37 | [diff] [blame] | 304 | |
Harald Alvestrand | 1979384 | 2018-06-25 10:03:50 | [diff] [blame] | 305 | void ReturnHistogramVeryQuicklyForTesting() { |
Karl Wiberg | f73f7d6 | 2019-04-08 13:36:53 | [diff] [blame] | 306 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Harald Alvestrand | 1979384 | 2018-06-25 10:03:50 | [diff] [blame] | 307 | return_histogram_very_quickly_ = true; |
| 308 | } |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 08:50:16 | [diff] [blame] | 309 | void RequestUsagePatternReportForTesting(); |
Harald Alvestrand | 1979384 | 2018-06-25 10:03:50 | [diff] [blame] | 310 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 311 | protected: |
deadbeef | a67696b | 2015-09-29 18:56:26 | [diff] [blame] | 312 | ~PeerConnection() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 313 | |
| 314 | private: |
Henrik Boström | 3163867 | 2017-11-23 16:48:32 | [diff] [blame] | 315 | class SetRemoteDescriptionObserverAdapter; |
| 316 | friend class SetRemoteDescriptionObserverAdapter; |
Henrik Boström | 79b6980 | 2019-07-18 09:16:56 | [diff] [blame] | 317 | // Represents the [[LocalIceCredentialsToReplace]] internal slot in the spec. |
| 318 | // It makes the next CreateOffer() produce new ICE credentials even if |
| 319 | // RTCOfferAnswerOptions::ice_restart is false. |
| 320 | // https://w3c.github.io/webrtc-pc/#dfn-localufragstoreplace |
| 321 | // TODO(hbos): When JsepTransportController/JsepTransport supports rollback, |
| 322 | // move this type of logic to JsepTransportController/JsepTransport. |
| 323 | class LocalIceCredentialsToReplace; |
Henrik Boström | 3163867 | 2017-11-23 16:48:32 | [diff] [blame] | 324 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 325 | struct RtpSenderInfo { |
| 326 | RtpSenderInfo() : first_ssrc(0) {} |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 327 | RtpSenderInfo(const std::string& stream_id, |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 328 | const std::string sender_id, |
| 329 | uint32_t ssrc) |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 330 | : stream_id(stream_id), sender_id(sender_id), first_ssrc(ssrc) {} |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 331 | bool operator==(const RtpSenderInfo& other) { |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 332 | return this->stream_id == other.stream_id && |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 333 | this->sender_id == other.sender_id && |
| 334 | this->first_ssrc == other.first_ssrc; |
deadbeef | bda7e0b | 2015-12-09 01:13:40 | [diff] [blame] | 335 | } |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 336 | std::string stream_id; |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 337 | std::string sender_id; |
| 338 | // An RtpSender can have many SSRCs. The first one is used as a sort of ID |
| 339 | // for communicating with the lower layers. |
| 340 | uint32_t first_ssrc; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 341 | }; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 342 | |
Bjorn A Mellem | 5985a04 | 2019-06-28 21:19:38 | [diff] [blame] | 343 | // Field-trial based configuration for datagram transport. |
| 344 | struct DatagramTransportConfig { |
| 345 | explicit DatagramTransportConfig(const std::string& field_trial) |
| 346 | : enabled("enabled", true), default_value("default_value", false) { |
| 347 | ParseFieldTrial({&enabled, &default_value}, field_trial); |
| 348 | } |
| 349 | |
| 350 | // Whether datagram transport support is enabled at all. Defaults to true, |
| 351 | // allowing datagram transport to be used if (a) the application provides a |
| 352 | // factory for it and (b) the configuration specifies its use. This flag |
| 353 | // provides a kill-switch to force-disable datagram transport across all |
| 354 | // applications, without code changes. |
| 355 | FieldTrialFlag enabled; |
| 356 | |
| 357 | // Whether the datagram transport is enabled or disabled by default. |
| 358 | // Defaults to false, meaning that applications must configure use of |
| 359 | // datagram transport through RTCConfiguration. If set to true, |
| 360 | // applications will use the datagram transport by default (but may still |
| 361 | // explicitly configure themselves not to use it through RTCConfiguration). |
| 362 | FieldTrialFlag default_value; |
| 363 | }; |
| 364 | |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 365 | // Field-trial based configuration for datagram transport data channels. |
| 366 | struct DatagramTransportDataChannelConfig { |
| 367 | explicit DatagramTransportDataChannelConfig(const std::string& field_trial) |
Bjorn A Mellem | 7da4e56 | 2019-09-26 18:02:11 | [diff] [blame] | 368 | : enabled("enabled", true), |
| 369 | default_value("default_value", false), |
| 370 | receive_only("receive_only", false) { |
| 371 | ParseFieldTrial({&enabled, &default_value, &receive_only}, field_trial); |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | // Whether datagram transport data channel support is enabled at all. |
| 375 | // Defaults to true, allowing datagram transport to be used if (a) the |
| 376 | // application provides a factory for it and (b) the configuration specifies |
| 377 | // its use. This flag provides a kill-switch to force-disable datagram |
| 378 | // transport across all applications, without code changes. |
| 379 | FieldTrialFlag enabled; |
| 380 | |
| 381 | // Whether the datagram transport data channels are enabled or disabled by |
| 382 | // default. Defaults to false, meaning that applications must configure use |
| 383 | // of datagram transport through RTCConfiguration. If set to true, |
| 384 | // applications will use the datagram transport by default (but may still |
| 385 | // explicitly configure themselves not to use it through RTCConfiguration). |
| 386 | FieldTrialFlag default_value; |
Bjorn A Mellem | 7da4e56 | 2019-09-26 18:02:11 | [diff] [blame] | 387 | |
| 388 | // Whether the datagram transport is enabled in receive-only mode. If true, |
| 389 | // and if the datagram transport is enabled, it will only be used when |
| 390 | // receiving incoming calls, not when placing outgoing calls. |
| 391 | FieldTrialFlag receive_only; |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 392 | }; |
| 393 | |
Eldar Rello | 5ab79e6 | 2019-10-09 15:29:44 | [diff] [blame] | 394 | // Captures partial state to be used for rollback. Applicable only in |
| 395 | // Unified Plan. |
| 396 | class TransceiverStableState { |
| 397 | public: |
| 398 | TransceiverStableState() {} |
| 399 | TransceiverStableState(RtpTransceiverDirection direction, |
| 400 | absl::optional<std::string> mid, |
| 401 | absl::optional<size_t> mline_index, |
| 402 | bool newly_created) |
| 403 | : direction_(direction), |
| 404 | mid_(mid), |
| 405 | mline_index_(mline_index), |
| 406 | newly_created_(newly_created) {} |
| 407 | RtpTransceiverDirection direction() const { return direction_; } |
| 408 | absl::optional<std::string> mid() const { return mid_; } |
| 409 | absl::optional<size_t> mline_index() const { return mline_index_; } |
| 410 | bool newly_created() const { return newly_created_; } |
| 411 | |
| 412 | private: |
| 413 | RtpTransceiverDirection direction_ = RtpTransceiverDirection::kRecvOnly; |
| 414 | absl::optional<std::string> mid_; |
| 415 | absl::optional<size_t> mline_index_; |
| 416 | // Indicates that the transceiver was created as part of applying a |
| 417 | // description to track potential need for removing transceiver during |
| 418 | // rollback. |
| 419 | bool newly_created_ = false; |
| 420 | }; |
| 421 | |
Steve Anton | ad18276 | 2018-09-05 20:22:40 | [diff] [blame] | 422 | // Implements MessageHandler. |
| 423 | void OnMessage(rtc::Message* msg) override; |
| 424 | |
Steve Anton | afb0bb7 | 2018-02-20 19:35:37 | [diff] [blame] | 425 | // Plan B helpers for getting the voice/video media channels for the single |
| 426 | // audio/video transceiver, if it exists. |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 427 | cricket::VoiceMediaChannel* voice_media_channel() const |
| 428 | RTC_RUN_ON(signaling_thread()); |
| 429 | cricket::VideoMediaChannel* video_media_channel() const |
| 430 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 6077675 | 2018-01-10 19:51:34 | [diff] [blame] | 431 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 432 | std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>> |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 433 | GetSendersInternal() const RTC_RUN_ON(signaling_thread()); |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 434 | std::vector< |
| 435 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>> |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 436 | GetReceiversInternal() const RTC_RUN_ON(signaling_thread()); |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 437 | |
| 438 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 439 | GetAudioTransceiver() const RTC_RUN_ON(signaling_thread()); |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 440 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 441 | GetVideoTransceiver() const RTC_RUN_ON(signaling_thread()); |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 442 | |
Steve Anton | afb0bb7 | 2018-02-20 19:35:37 | [diff] [blame] | 443 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 444 | GetFirstAudioTransceiver() const RTC_RUN_ON(signaling_thread()); |
Steve Anton | afb0bb7 | 2018-02-20 19:35:37 | [diff] [blame] | 445 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 446 | void CreateAudioReceiver(MediaStreamInterface* stream, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 447 | const RtpSenderInfo& remote_sender_info) |
| 448 | RTC_RUN_ON(signaling_thread()); |
perkj | f0dcfe2 | 2016-03-10 17:32:00 | [diff] [blame] | 449 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 450 | void CreateVideoReceiver(MediaStreamInterface* stream, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 451 | const RtpSenderInfo& remote_sender_info) |
| 452 | RTC_RUN_ON(signaling_thread()); |
Henrik Boström | 933d8b0 | 2017-10-10 17:05:16 | [diff] [blame] | 453 | rtc::scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver( |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 454 | const RtpSenderInfo& remote_sender_info) RTC_RUN_ON(signaling_thread()); |
korniltsev.anatoly | ec390b5 | 2017-07-25 00:00:25 | [diff] [blame] | 455 | |
| 456 | // May be called either by AddStream/RemoveStream, or when a track is |
| 457 | // added/removed from a stream previously added via AddStream. |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 458 | void AddAudioTrack(AudioTrackInterface* track, MediaStreamInterface* stream) |
| 459 | RTC_RUN_ON(signaling_thread()); |
korniltsev.anatoly | ec390b5 | 2017-07-25 00:00:25 | [diff] [blame] | 460 | void RemoveAudioTrack(AudioTrackInterface* track, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 461 | MediaStreamInterface* stream) |
| 462 | RTC_RUN_ON(signaling_thread()); |
| 463 | void AddVideoTrack(VideoTrackInterface* track, MediaStreamInterface* stream) |
| 464 | RTC_RUN_ON(signaling_thread()); |
korniltsev.anatoly | ec390b5 | 2017-07-25 00:00:25 | [diff] [blame] | 465 | void RemoveVideoTrack(VideoTrackInterface* track, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 466 | MediaStreamInterface* stream) |
| 467 | RTC_RUN_ON(signaling_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 468 | |
Steve Anton | f9381f0 | 2017-12-14 18:23:57 | [diff] [blame] | 469 | // AddTrack implementation when Unified Plan is specified. |
| 470 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackUnifiedPlan( |
| 471 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 472 | const std::vector<std::string>& stream_ids) |
| 473 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | f9381f0 | 2017-12-14 18:23:57 | [diff] [blame] | 474 | // AddTrack implementation when Plan B is specified. |
| 475 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrackPlanB( |
| 476 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 477 | const std::vector<std::string>& stream_ids) |
| 478 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | f9381f0 | 2017-12-14 18:23:57 | [diff] [blame] | 479 | |
| 480 | // Returns the first RtpTransceiver suitable for a newly added track, if such |
| 481 | // transceiver is available. |
| 482 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 483 | FindFirstTransceiverForAddedTrack( |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 484 | rtc::scoped_refptr<MediaStreamTrackInterface> track) |
| 485 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | f9381f0 | 2017-12-14 18:23:57 | [diff] [blame] | 486 | |
Steve Anton | f9381f0 | 2017-12-14 18:23:57 | [diff] [blame] | 487 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 488 | FindTransceiverBySender(rtc::scoped_refptr<RtpSenderInterface> sender) |
| 489 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | f9381f0 | 2017-12-14 18:23:57 | [diff] [blame] | 490 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 491 | // Internal implementation for AddTransceiver family of methods. If |
| 492 | // |fire_callback| is set, fires OnRenegotiationNeeded callback if successful. |
Steve Anton | 9158ef6 | 2017-11-27 21:01:52 | [diff] [blame] | 493 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 494 | cricket::MediaType media_type, |
| 495 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 496 | const RtpTransceiverInit& init, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 497 | bool fire_callback = true) RTC_RUN_ON(signaling_thread()); |
Steve Anton | 9158ef6 | 2017-11-27 21:01:52 | [diff] [blame] | 498 | |
Steve Anton | 02ee47c | 2018-01-11 00:26:06 | [diff] [blame] | 499 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> |
| 500 | CreateSender(cricket::MediaType media_type, |
Steve Anton | 111fdfd | 2018-06-25 20:03:36 | [diff] [blame] | 501 | const std::string& id, |
Steve Anton | 02ee47c | 2018-01-11 00:26:06 | [diff] [blame] | 502 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Florent Castelli | 892acf0 | 2018-10-01 20:47:20 | [diff] [blame] | 503 | const std::vector<std::string>& stream_ids, |
| 504 | const std::vector<RtpEncodingParameters>& send_encodings); |
Steve Anton | 02ee47c | 2018-01-11 00:26:06 | [diff] [blame] | 505 | |
| 506 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
| 507 | CreateReceiver(cricket::MediaType media_type, const std::string& receiver_id); |
| 508 | |
Steve Anton | f9381f0 | 2017-12-14 18:23:57 | [diff] [blame] | 509 | // Create a new RtpTransceiver of the given type and add it to the list of |
| 510 | // transceivers. |
| 511 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Steve Anton | 02ee47c | 2018-01-11 00:26:06 | [diff] [blame] | 512 | CreateAndAddTransceiver( |
| 513 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender, |
| 514 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 515 | receiver) RTC_RUN_ON(signaling_thread()); |
Steve Anton | f9381f0 | 2017-12-14 18:23:57 | [diff] [blame] | 516 | |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 517 | void SetIceConnectionState(IceConnectionState new_state) |
| 518 | RTC_RUN_ON(signaling_thread()); |
Jonas Olsson | 635474e | 2018-10-18 13:58:17 | [diff] [blame] | 519 | void SetStandardizedIceConnectionState( |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 520 | PeerConnectionInterface::IceConnectionState new_state) |
| 521 | RTC_RUN_ON(signaling_thread()); |
Jonas Olsson | 635474e | 2018-10-18 13:58:17 | [diff] [blame] | 522 | void SetConnectionState( |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 523 | PeerConnectionInterface::PeerConnectionState new_state) |
| 524 | RTC_RUN_ON(signaling_thread()); |
Jonas Olsson | 635474e | 2018-10-18 13:58:17 | [diff] [blame] | 525 | |
Eldar Rello | da13ea2 | 2019-06-01 09:23:43 | [diff] [blame] | 526 | // Called any time the IceGatheringState changes. |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 527 | void OnIceGatheringChange(IceGatheringState new_state) |
| 528 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 529 | // New ICE candidate has been gathered. |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 530 | void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate) |
| 531 | RTC_RUN_ON(signaling_thread()); |
Eldar Rello | da13ea2 | 2019-06-01 09:23:43 | [diff] [blame] | 532 | // Gathering of an ICE candidate failed. |
| 533 | void OnIceCandidateError(const std::string& host_candidate, |
| 534 | const std::string& url, |
| 535 | int error_code, |
| 536 | const std::string& error_text) |
| 537 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 538 | // Some local ICE candidates have been removed. |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 539 | void OnIceCandidatesRemoved(const std::vector<cricket::Candidate>& candidates) |
| 540 | RTC_RUN_ON(signaling_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 541 | |
Alex Drake | 00c7ecf | 2019-08-06 17:54:47 | [diff] [blame] | 542 | void OnSelectedCandidatePairChanged( |
| 543 | const cricket::CandidatePairChangeEvent& event) |
| 544 | RTC_RUN_ON(signaling_thread()); |
| 545 | |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 546 | // Update the state, signaling if necessary. |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 547 | void ChangeSignalingState(SignalingState signaling_state) |
| 548 | RTC_RUN_ON(signaling_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 549 | |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 550 | // Signals from MediaStreamObserver. |
| 551 | void OnAudioTrackAdded(AudioTrackInterface* track, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 552 | MediaStreamInterface* stream) |
| 553 | RTC_RUN_ON(signaling_thread()); |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 554 | void OnAudioTrackRemoved(AudioTrackInterface* track, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 555 | MediaStreamInterface* stream) |
| 556 | RTC_RUN_ON(signaling_thread()); |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 557 | void OnVideoTrackAdded(VideoTrackInterface* track, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 558 | MediaStreamInterface* stream) |
| 559 | RTC_RUN_ON(signaling_thread()); |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 560 | void OnVideoTrackRemoved(VideoTrackInterface* track, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 561 | MediaStreamInterface* stream) |
| 562 | RTC_RUN_ON(signaling_thread()); |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 563 | |
Henrik Boström | 3163867 | 2017-11-23 16:48:32 | [diff] [blame] | 564 | void PostSetSessionDescriptionSuccess( |
| 565 | SetSessionDescriptionObserver* observer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 566 | void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, |
Steve Anton | ad18276 | 2018-09-05 20:22:40 | [diff] [blame] | 567 | RTCError&& error); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 568 | void PostCreateSessionDescriptionFailure( |
| 569 | CreateSessionDescriptionObserver* observer, |
Harald Alvestrand | 5081c0c | 2018-03-09 14:18:03 | [diff] [blame] | 570 | RTCError error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 571 | |
Steve Anton | 8a00691 | 2017-12-04 23:25:56 | [diff] [blame] | 572 | // Synchronous implementations of SetLocalDescription/SetRemoteDescription |
| 573 | // that return an RTCError instead of invoking a callback. |
| 574 | RTCError ApplyLocalDescription( |
| 575 | std::unique_ptr<SessionDescriptionInterface> desc); |
| 576 | RTCError ApplyRemoteDescription( |
| 577 | std::unique_ptr<SessionDescriptionInterface> desc); |
| 578 | |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 579 | // Updates the local RtpTransceivers according to the JSEP rules. Called as |
| 580 | // part of setting the local/remote description. |
| 581 | RTCError UpdateTransceiversAndDataChannels( |
| 582 | cricket::ContentSource source, |
Seth Hampson | ae8a90a | 2018-02-13 23:33:48 | [diff] [blame] | 583 | const SessionDescriptionInterface& new_session, |
| 584 | const SessionDescriptionInterface* old_local_description, |
Karl Wiberg | 106d92d | 2019-02-14 09:17:47 | [diff] [blame] | 585 | const SessionDescriptionInterface* old_remote_description) |
| 586 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 587 | |
| 588 | // Either creates or destroys the transceiver's BaseChannel according to the |
| 589 | // given media section. |
| 590 | RTCError UpdateTransceiverChannel( |
| 591 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 592 | transceiver, |
| 593 | const cricket::ContentInfo& content, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 594 | const cricket::ContentGroup* bundle_group) RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 595 | |
Steve Anton | fa2260d | 2017-12-29 00:38:23 | [diff] [blame] | 596 | // Either creates or destroys the local data channel according to the given |
| 597 | // media section. |
| 598 | RTCError UpdateDataChannel(cricket::ContentSource source, |
| 599 | const cricket::ContentInfo& content, |
Karl Wiberg | 106d92d | 2019-02-14 09:17:47 | [diff] [blame] | 600 | const cricket::ContentGroup* bundle_group) |
| 601 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | fa2260d | 2017-12-29 00:38:23 | [diff] [blame] | 602 | |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 603 | // Associate the given transceiver according to the JSEP rules. |
| 604 | RTCErrorOr< |
| 605 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
| 606 | AssociateTransceiver(cricket::ContentSource source, |
Seth Hampson | ae8a90a | 2018-02-13 23:33:48 | [diff] [blame] | 607 | SdpType type, |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 608 | size_t mline_index, |
| 609 | const cricket::ContentInfo& content, |
Seth Hampson | ae8a90a | 2018-02-13 23:33:48 | [diff] [blame] | 610 | const cricket::ContentInfo* old_local_content, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 611 | const cricket::ContentInfo* old_remote_content) |
| 612 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 613 | |
| 614 | // Returns the RtpTransceiver, if found, that is associated to the given MID. |
| 615 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 616 | GetAssociatedTransceiver(const std::string& mid) const |
| 617 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 618 | |
| 619 | // Returns the RtpTransceiver, if found, that was assigned to the given mline |
| 620 | // index in CreateOffer. |
| 621 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 622 | GetTransceiverByMLineIndex(size_t mline_index) const |
| 623 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 624 | |
| 625 | // Returns an RtpTransciever, if available, that can be used to receive the |
| 626 | // given media type according to JSEP rules. |
| 627 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 628 | FindAvailableTransceiverToReceive(cricket::MediaType media_type) const |
| 629 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 630 | |
Steve Anton | ed10bd9 | 2017-12-05 18:52:59 | [diff] [blame] | 631 | // Returns the media section in the given session description that is |
| 632 | // associated with the RtpTransceiver. Returns null if none found or this |
| 633 | // RtpTransceiver is not associated. Logic varies depending on the |
| 634 | // SdpSemantics specified in the configuration. |
| 635 | const cricket::ContentInfo* FindMediaSectionForTransceiver( |
| 636 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 637 | transceiver, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 638 | const SessionDescriptionInterface* sdesc) const |
| 639 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | ed10bd9 | 2017-12-05 18:52:59 | [diff] [blame] | 640 | |
Henrik Boström | afa07dd | 2018-12-20 10:06:02 | [diff] [blame] | 641 | // Runs the algorithm **set the associated remote streams** specified in |
| 642 | // https://w3c.github.io/webrtc-pc/#set-associated-remote-streams. |
| 643 | void SetAssociatedRemoteStreams( |
| 644 | rtc::scoped_refptr<RtpReceiverInternal> receiver, |
| 645 | const std::vector<std::string>& stream_ids, |
| 646 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* added_streams, |
Karl Wiberg | 1e1e102 | 2019-03-22 13:27:22 | [diff] [blame] | 647 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams) |
| 648 | RTC_RUN_ON(signaling_thread()); |
Henrik Boström | afa07dd | 2018-12-20 10:06:02 | [diff] [blame] | 649 | |
Steve Anton | 0f5400a | 2018-07-17 21:25:36 | [diff] [blame] | 650 | // Runs the algorithm **process the removal of a remote track** specified in |
| 651 | // the WebRTC specification. |
| 652 | // This method will update the following lists: |
| 653 | // |remove_list| is the list of transceivers for which the receiving track is |
| 654 | // being removed. |
| 655 | // |removed_streams| is the list of streams which no longer have a receiving |
| 656 | // track so should be removed. |
| 657 | // https://w3c.github.io/webrtc-pc/#process-remote-track-removal |
| 658 | void ProcessRemovalOfRemoteTrack( |
| 659 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 660 | transceiver, |
| 661 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>* remove_list, |
Karl Wiberg | 1e1e102 | 2019-03-22 13:27:22 | [diff] [blame] | 662 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams) |
| 663 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 0f5400a | 2018-07-17 21:25:36 | [diff] [blame] | 664 | |
Henrik Boström | afa07dd | 2018-12-20 10:06:02 | [diff] [blame] | 665 | void RemoveRemoteStreamsIfEmpty( |
| 666 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& |
| 667 | remote_streams, |
Karl Wiberg | 1e1e102 | 2019-03-22 13:27:22 | [diff] [blame] | 668 | std::vector<rtc::scoped_refptr<MediaStreamInterface>>* removed_streams) |
| 669 | RTC_RUN_ON(signaling_thread()); |
Henrik Boström | afa07dd | 2018-12-20 10:06:02 | [diff] [blame] | 670 | |
Steve Anton | 52d8677 | 2018-02-20 23:48:12 | [diff] [blame] | 671 | void OnNegotiationNeeded(); |
| 672 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 673 | bool IsClosed() const { |
Karl Wiberg | 8d2e228 | 2019-02-17 12:00:07 | [diff] [blame] | 674 | RTC_DCHECK_RUN_ON(signaling_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 675 | return signaling_state_ == PeerConnectionInterface::kClosed; |
| 676 | } |
| 677 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 678 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 679 | // the local MediaStreams and DataChannels. |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 680 | void GetOptionsForOffer(const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 681 | offer_answer_options, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 682 | cricket::MediaSessionOptions* session_options) |
| 683 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 684 | void GetOptionsForPlanBOffer( |
| 685 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 686 | offer_answer_options, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 687 | cricket::MediaSessionOptions* session_options) |
| 688 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 689 | void GetOptionsForUnifiedPlanOffer( |
| 690 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 691 | offer_answer_options, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 692 | cricket::MediaSessionOptions* session_options) |
| 693 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 694 | |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 695 | RTCError HandleLegacyOfferOptions(const RTCOfferAnswerOptions& options) |
| 696 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 697 | void RemoveRecvDirectionFromReceivingTransceiversOfType( |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 698 | cricket::MediaType media_type) RTC_RUN_ON(signaling_thread()); |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 699 | void AddUpToOneReceivingTransceiverOfType(cricket::MediaType media_type); |
| 700 | std::vector< |
| 701 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 702 | GetReceivingTransceiversOfType(cricket::MediaType media_type) |
| 703 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 704 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 705 | // Returns a MediaSessionOptions struct with options decided by |
| 706 | // |constraints|, the local MediaStreams and DataChannels. |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 707 | void GetOptionsForAnswer(const RTCOfferAnswerOptions& offer_answer_options, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 708 | cricket::MediaSessionOptions* session_options) |
| 709 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 710 | void GetOptionsForPlanBAnswer( |
| 711 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 712 | offer_answer_options, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 713 | cricket::MediaSessionOptions* session_options) |
| 714 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 715 | void GetOptionsForUnifiedPlanAnswer( |
| 716 | const PeerConnectionInterface::RTCOfferAnswerOptions& |
| 717 | offer_answer_options, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 718 | cricket::MediaSessionOptions* session_options) |
| 719 | RTC_RUN_ON(signaling_thread()); |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 720 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 721 | // Generates MediaDescriptionOptions for the |session_opts| based on existing |
| 722 | // local description or remote description. |
| 723 | void GenerateMediaDescriptionOptions( |
| 724 | const SessionDescriptionInterface* session_desc, |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 725 | RtpTransceiverDirection audio_direction, |
| 726 | RtpTransceiverDirection video_direction, |
Danil Chapovalov | 66cadcc | 2018-06-19 14:47:43 | [diff] [blame] | 727 | absl::optional<size_t>* audio_index, |
| 728 | absl::optional<size_t>* video_index, |
| 729 | absl::optional<size_t>* data_index, |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 730 | cricket::MediaSessionOptions* session_options) |
| 731 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 732 | |
Steve Anton | fa2260d | 2017-12-29 00:38:23 | [diff] [blame] | 733 | // Generates the active MediaDescriptionOptions for the local data channel |
| 734 | // given the specified MID. |
| 735 | cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForActiveData( |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 736 | const std::string& mid) const RTC_RUN_ON(signaling_thread()); |
Steve Anton | fa2260d | 2017-12-29 00:38:23 | [diff] [blame] | 737 | |
| 738 | // Generates the rejected MediaDescriptionOptions for the local data channel |
| 739 | // given the specified MID. |
| 740 | cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForRejectedData( |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 741 | const std::string& mid) const RTC_RUN_ON(signaling_thread()); |
Steve Anton | fa2260d | 2017-12-29 00:38:23 | [diff] [blame] | 742 | |
| 743 | // Returns the MID for the data section associated with either the |
| 744 | // RtpDataChannel or SCTP data channel, if it has been set. If no data |
| 745 | // channels are configured this will return nullopt. |
Karl Wiberg | 2cc368f | 2019-04-02 09:31:56 | [diff] [blame] | 746 | absl::optional<std::string> GetDataMid() const RTC_RUN_ON(signaling_thread()); |
Steve Anton | fa2260d | 2017-12-29 00:38:23 | [diff] [blame] | 747 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 748 | // Remove all local and remote senders of type |media_type|. |
deadbeef | faac497 | 2015-11-12 23:33:07 | [diff] [blame] | 749 | // Called when a media type is rejected (m-line set to port 0). |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 750 | void RemoveSenders(cricket::MediaType media_type) |
| 751 | RTC_RUN_ON(signaling_thread()); |
deadbeef | faac497 | 2015-11-12 23:33:07 | [diff] [blame] | 752 | |
deadbeef | bda7e0b | 2015-12-09 01:13:40 | [diff] [blame] | 753 | // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 754 | // and existing MediaStreamTracks are removed if there is no corresponding |
| 755 | // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 756 | // is created if it doesn't exist; if false, it's removed if it exists. |
| 757 | // |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] | 758 | // If a new MediaStream is created it is added to |new_streams|. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 759 | void UpdateRemoteSendersList( |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 760 | const std::vector<cricket::StreamParams>& streams, |
deadbeef | bda7e0b | 2015-12-09 01:13:40 | [diff] [blame] | 761 | bool default_track_needed, |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 762 | cricket::MediaType media_type, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 763 | StreamCollection* new_streams) RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 764 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 765 | // 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] | 766 | // session description. It creates a remote MediaStreamTrackInterface |
| 767 | // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 768 | void OnRemoteSenderAdded(const RtpSenderInfo& sender_info, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 769 | cricket::MediaType media_type) |
| 770 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 771 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 772 | // Triggered when a remote sender has been removed from a remote session |
| 773 | // description. It removes the remote sender with id |sender_id| from a remote |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 774 | // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 775 | void OnRemoteSenderRemoved(const RtpSenderInfo& sender_info, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 776 | cricket::MediaType media_type) |
| 777 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 778 | |
| 779 | // Finds remote MediaStreams without any tracks and removes them from |
| 780 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 781 | // exist. |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 782 | void UpdateEndedRemoteMediaStreams() RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 783 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 784 | // Loops through the vector of |streams| and finds added and removed |
| 785 | // StreamParams since last time this method was called. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 786 | // For each new or removed StreamParam, OnLocalSenderSeen or |
| 787 | // OnLocalSenderRemoved is invoked. |
| 788 | void UpdateLocalSenders(const std::vector<cricket::StreamParams>& streams, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 789 | cricket::MediaType media_type) |
| 790 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 791 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 792 | // 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] | 793 | // session description. |
| 794 | // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
| 795 | // streams in the local SessionDescription can be mapped to a MediaStreamTrack |
| 796 | // in a MediaStream in |local_streams_| |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 797 | void OnLocalSenderAdded(const RtpSenderInfo& sender_info, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 798 | cricket::MediaType media_type) |
| 799 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 800 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 801 | // Triggered when a local sender has been removed from a local session |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 802 | // description. |
| 803 | // This method triggers DestroyAudioSender or DestroyVideoSender if a stream |
| 804 | // has been removed from the local SessionDescription and the stream can be |
| 805 | // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|. |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 806 | void OnLocalSenderRemoved(const RtpSenderInfo& sender_info, |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 807 | cricket::MediaType media_type) |
| 808 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 809 | |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 810 | void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams) |
| 811 | RTC_RUN_ON(signaling_thread()); |
Karl Wiberg | 106d92d | 2019-02-14 09:17:47 | [diff] [blame] | 812 | void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams) |
| 813 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 814 | void UpdateClosingRtpDataChannels( |
| 815 | const std::vector<std::string>& active_channels, |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 816 | bool is_local_update) RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 817 | void CreateRemoteRtpDataChannel(const std::string& label, |
Karl Wiberg | 106d92d | 2019-02-14 09:17:47 | [diff] [blame] | 818 | uint32_t remote_ssrc) |
| 819 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 820 | |
| 821 | // Creates channel and adds it to the collection of DataChannels that will |
| 822 | // be offered in a SessionDescription. |
| 823 | rtc::scoped_refptr<DataChannel> InternalCreateDataChannel( |
| 824 | const std::string& label, |
Karl Wiberg | 106d92d | 2019-02-14 09:17:47 | [diff] [blame] | 825 | const InternalDataChannelInit* config) RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 826 | |
| 827 | // Checks if any data channel has been added. |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 828 | bool HasDataChannels() const RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 829 | |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 830 | void AllocateSctpSids(rtc::SSLRole role) RTC_RUN_ON(signaling_thread()); |
| 831 | void OnSctpDataChannelClosed(DataChannel* channel) |
| 832 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 833 | |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 834 | void OnDataChannelDestroyed() RTC_RUN_ON(signaling_thread()); |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 835 | // Called when a valid data channel OPEN message is received. |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 836 | void OnDataChannelOpenMessage(const std::string& label, |
Karl Wiberg | 106d92d | 2019-02-14 09:17:47 | [diff] [blame] | 837 | const InternalDataChannelInit& config) |
| 838 | RTC_RUN_ON(signaling_thread()); |
| 839 | |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 840 | // Parses and handles open messages. Returns true if the message is an open |
| 841 | // message, false otherwise. |
| 842 | bool HandleOpenMessage_s(const cricket::ReceiveDataParams& params, |
| 843 | const rtc::CopyOnWriteBuffer& buffer) |
| 844 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 845 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 846 | // Returns true if the PeerConnection is configured to use Unified Plan |
| 847 | // semantics for creating offers/answers and setting local/remote |
| 848 | // descriptions. If this is true the RtpTransceiver API will also be available |
| 849 | // to the user. If this is false, Plan B semantics are assumed. |
Steve Anton | 79e7960 | 2017-11-20 18:25:56 | [diff] [blame] | 850 | // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once |
| 851 | // sufficient time has passed. |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 852 | bool IsUnifiedPlan() const RTC_RUN_ON(signaling_thread()) { |
Steve Anton | 79e7960 | 2017-11-20 18:25:56 | [diff] [blame] | 853 | return configuration_.sdp_semantics == SdpSemantics::kUnifiedPlan; |
| 854 | } |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 855 | |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 856 | // The offer/answer machinery assumes the media section MID is present and |
| 857 | // unique. To support legacy end points that do not supply a=mid lines, this |
| 858 | // method will modify the session description to add MIDs generated according |
| 859 | // to the SDP semantics. |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 860 | void FillInMissingRemoteMids(cricket::SessionDescription* remote_description) |
| 861 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 862 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 863 | // Is there an RtpSender of the given type? |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 864 | bool HasRtpSender(cricket::MediaType type) const |
| 865 | RTC_RUN_ON(signaling_thread()); |
deadbeef | fac0655 | 2015-11-25 19:26:01 | [diff] [blame] | 866 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 867 | // Return the RtpSender with the given track attached. |
| 868 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 869 | FindSenderForTrack(MediaStreamTrackInterface* track) const |
| 870 | RTC_RUN_ON(signaling_thread()); |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 871 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 872 | // Return the RtpSender with the given id, or null if none exists. |
| 873 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 874 | FindSenderById(const std::string& sender_id) const |
| 875 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 876 | |
| 877 | // Return the RtpReceiver with the given id, or null if none exists. |
| 878 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 879 | FindReceiverById(const std::string& receiver_id) const |
| 880 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 881 | |
| 882 | std::vector<RtpSenderInfo>* GetRemoteSenderInfos( |
| 883 | cricket::MediaType media_type); |
| 884 | std::vector<RtpSenderInfo>* GetLocalSenderInfos( |
| 885 | cricket::MediaType media_type); |
| 886 | const RtpSenderInfo* FindSenderInfo(const std::vector<RtpSenderInfo>& infos, |
Emircan Uysaler | bc609eaa | 2018-03-27 21:57:18 | [diff] [blame] | 887 | const std::string& stream_id, |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 888 | const std::string sender_id) const; |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 889 | |
| 890 | // Returns the specified SCTP DataChannel in sctp_data_channels_, |
| 891 | // or nullptr if not found. |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 892 | DataChannel* FindDataChannelBySid(int sid) const |
| 893 | RTC_RUN_ON(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 894 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 895 | // Called when first configuring the port allocator. |
Karl Wiberg | fb3be39 | 2019-03-22 13:13:22 | [diff] [blame] | 896 | struct InitializePortAllocatorResult { |
| 897 | bool enable_ipv6; |
| 898 | }; |
| 899 | InitializePortAllocatorResult InitializePortAllocator_n( |
Harald Alvestrand | b2a7478 | 2018-06-28 11:54:07 | [diff] [blame] | 900 | const cricket::ServerAddresses& stun_servers, |
| 901 | const std::vector<cricket::RelayServerConfig>& turn_servers, |
| 902 | const RTCConfiguration& configuration); |
deadbeef | 293e926 | 2017-01-11 20:28:30 | [diff] [blame] | 903 | // Called when SetConfiguration is called to apply the supported subset |
| 904 | // of the configuration on the network thread. |
| 905 | bool ReconfigurePortAllocator_n( |
| 906 | const cricket::ServerAddresses& stun_servers, |
| 907 | const std::vector<cricket::RelayServerConfig>& turn_servers, |
| 908 | IceTransportsType type, |
| 909 | int candidate_pool_size, |
Honghai Zhang | f8998cf | 2019-10-14 18:27:50 | [diff] [blame^] | 910 | PortPrunePolicy turn_port_prune_policy, |
Qingsi Wang | db53f8e | 2018-02-20 22:45:49 | [diff] [blame] | 911 | webrtc::TurnCustomizer* turn_customizer, |
Karl Wiberg | 739506e | 2019-04-03 09:37:28 | [diff] [blame] | 912 | absl::optional<int> stun_candidate_keepalive_interval, |
| 913 | bool have_local_description); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 914 | |
Elad Alon | 99c3fe5 | 2017-10-13 14:29:40 | [diff] [blame] | 915 | // Starts output of an RTC event log to the given output object. |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 916 | // This function should only be called from the worker thread. |
Bjorn Terelius | de93943 | 2017-11-20 16:38:14 | [diff] [blame] | 917 | bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output, |
| 918 | int64_t output_period_ms); |
Elad Alon | 99c3fe5 | 2017-10-13 14:29:40 | [diff] [blame] | 919 | |
Elad Alon | acb2417 | 2017-10-06 12:32:13 | [diff] [blame] | 920 | // Stops recording an RTC event log. |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 921 | // This function should only be called from the worker thread. |
| 922 | void StopRtcEventLog_w(); |
| 923 | |
Steve Anton | 038834f | 2017-07-14 22:59:59 | [diff] [blame] | 924 | // Ensures the configuration doesn't have any parameters with invalid values, |
| 925 | // or values that conflict with other parameters. |
| 926 | // |
| 927 | // Returns RTCError::OK() if there are no issues. |
| 928 | RTCError ValidateConfiguration(const RTCConfiguration& config) const; |
| 929 | |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 930 | cricket::ChannelManager* channel_manager() const; |
Steve Anton | ba81867 | 2017-11-06 18:21:57 | [diff] [blame] | 931 | |
Steve Anton | f847081 | 2017-12-04 18:46:21 | [diff] [blame] | 932 | enum class SessionError { |
| 933 | kNone, // No error. |
| 934 | kContent, // Error in BaseChannel SetLocalContent/SetRemoteContent. |
| 935 | kTransport, // Error from the underlying transport. |
| 936 | }; |
| 937 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 938 | // Returns the last error in the session. See the enum above for details. |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 939 | SessionError session_error() const RTC_RUN_ON(signaling_thread()) { |
| 940 | return session_error_; |
| 941 | } |
Steve Anton | f847081 | 2017-12-04 18:46:21 | [diff] [blame] | 942 | const std::string& session_error_desc() const { return session_error_desc_; } |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 943 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 944 | cricket::ChannelInterface* GetChannel(const std::string& content_name); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 945 | |
| 946 | // Get current SSL role used by SCTP's underlying transport. |
| 947 | bool GetSctpSslRole(rtc::SSLRole* role); |
| 948 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 949 | cricket::IceConfig ParseIceConfig( |
| 950 | const PeerConnectionInterface::RTCConfiguration& config) const; |
| 951 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 952 | // Implements DataChannelProviderInterface. |
| 953 | bool SendData(const cricket::SendDataParams& params, |
| 954 | const rtc::CopyOnWriteBuffer& payload, |
| 955 | cricket::SendDataResult* result) override; |
| 956 | bool ConnectDataChannel(DataChannel* webrtc_data_channel) override; |
| 957 | void DisconnectDataChannel(DataChannel* webrtc_data_channel) override; |
| 958 | void AddSctpDataStream(int sid) override; |
| 959 | void RemoveSctpDataStream(int sid) override; |
| 960 | bool ReadyToSendData() const override; |
| 961 | |
| 962 | cricket::DataChannelType data_channel_type() const; |
| 963 | |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 964 | // Implements DataChannelSink. |
| 965 | void OnDataReceived(int channel_id, |
| 966 | DataMessageType type, |
| 967 | const rtc::CopyOnWriteBuffer& buffer) override; |
| 968 | void OnChannelClosing(int channel_id) override; |
| 969 | void OnChannelClosed(int channel_id) override; |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 970 | void OnReadyToSend() override; |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 971 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 972 | // Called when an RTCCertificate is generated or retrieved by |
| 973 | // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription. |
| 974 | void OnCertificateReady( |
| 975 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
| 976 | void OnDtlsSrtpSetupFailure(cricket::BaseChannel*, bool rtcp); |
| 977 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 978 | // Non-const versions of local_description()/remote_description(), for use |
| 979 | // internally. |
Karl Wiberg | 739506e | 2019-04-03 09:37:28 | [diff] [blame] | 980 | SessionDescriptionInterface* mutable_local_description() |
| 981 | RTC_RUN_ON(signaling_thread()) { |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 982 | return pending_local_description_ ? pending_local_description_.get() |
| 983 | : current_local_description_.get(); |
| 984 | } |
Karl Wiberg | 739506e | 2019-04-03 09:37:28 | [diff] [blame] | 985 | SessionDescriptionInterface* mutable_remote_description() |
| 986 | RTC_RUN_ON(signaling_thread()) { |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 987 | return pending_remote_description_ ? pending_remote_description_.get() |
| 988 | : current_remote_description_.get(); |
| 989 | } |
| 990 | |
| 991 | // Updates the error state, signaling if necessary. |
Steve Anton | f847081 | 2017-12-04 18:46:21 | [diff] [blame] | 992 | void SetSessionError(SessionError error, const std::string& error_desc); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 993 | |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 994 | RTCError UpdateSessionState(SdpType type, |
| 995 | cricket::ContentSource source, |
| 996 | const cricket::SessionDescription* description); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 997 | // Push the media parts of the local or remote session description |
| 998 | // down to all of the channels. |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 999 | RTCError PushdownMediaDescription(SdpType type, cricket::ContentSource source) |
| 1000 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1001 | |
Steve Anton | 8a00691 | 2017-12-04 23:25:56 | [diff] [blame] | 1002 | RTCError PushdownTransportDescription(cricket::ContentSource source, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 1003 | SdpType type); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1004 | |
| 1005 | // Returns true and the TransportInfo of the given |content_name| |
| 1006 | // from |description|. Returns false if it's not available. |
| 1007 | static bool GetTransportDescription( |
| 1008 | const cricket::SessionDescription* description, |
| 1009 | const std::string& content_name, |
| 1010 | cricket::TransportDescription* info); |
| 1011 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1012 | // Enables media channels to allow sending of media. |
Steve Anton | ed10bd9 | 2017-12-05 18:52:59 | [diff] [blame] | 1013 | // This enables media to flow on all configured audio/video channels and the |
| 1014 | // RtpDataChannel. |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 1015 | void EnableSending() RTC_RUN_ON(signaling_thread()); |
Steve Anton | 3fe1b15 | 2017-12-12 18:20:08 | [diff] [blame] | 1016 | |
Steve Anton | 8af2186 | 2017-12-15 19:20:13 | [diff] [blame] | 1017 | // Destroys all BaseChannels and destroys the SCTP data channel, if present. |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 1018 | void DestroyAllChannels() RTC_RUN_ON(signaling_thread()); |
Steve Anton | 3fe1b15 | 2017-12-12 18:20:08 | [diff] [blame] | 1019 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1020 | // Returns the media index for a local ice candidate given the content name. |
| 1021 | // Returns false if the local session description does not have a media |
| 1022 | // content called |content_name|. |
| 1023 | bool GetLocalCandidateMediaIndex(const std::string& content_name, |
Karl Wiberg | 739506e | 2019-04-03 09:37:28 | [diff] [blame] | 1024 | int* sdp_mline_index) |
| 1025 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1026 | // Uses all remote candidates in |remote_desc| in this session. |
| 1027 | bool UseCandidatesInSessionDescription( |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 1028 | const SessionDescriptionInterface* remote_desc) |
| 1029 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1030 | // Uses |candidate| in this session. |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 1031 | bool UseCandidate(const IceCandidateInterface* candidate) |
| 1032 | RTC_RUN_ON(signaling_thread()); |
Guido Urdaneta | 4163317 | 2019-05-23 18:12:29 | [diff] [blame] | 1033 | RTCErrorOr<const cricket::ContentInfo*> FindContentInfo( |
| 1034 | const SessionDescriptionInterface* description, |
| 1035 | const IceCandidateInterface* candidate) RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1036 | // Deletes the corresponding channel of contents that don't exist in |desc|. |
| 1037 | // |desc| can be null. This means that all channels are deleted. |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 1038 | void RemoveUnusedChannels(const cricket::SessionDescription* desc) |
| 1039 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1040 | |
| 1041 | // Allocates media channels based on the |desc|. If |desc| doesn't have |
| 1042 | // the BUNDLE option, this method will disable BUNDLE in PortAllocator. |
| 1043 | // This method will also delete any existing media channels before creating. |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 1044 | RTCError CreateChannels(const cricket::SessionDescription& desc) |
| 1045 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | dcc3c02 | 2017-12-23 00:02:54 | [diff] [blame] | 1046 | |
| 1047 | // If the BUNDLE policy is max-bundle, then we know for sure that all |
| 1048 | // transports will be bundled from the start. This method returns the BUNDLE |
| 1049 | // group if that's the case, or null if BUNDLE will be negotiated later. An |
| 1050 | // error is returned if max-bundle is specified but the session description |
| 1051 | // does not have a BUNDLE group. |
| 1052 | RTCErrorOr<const cricket::ContentGroup*> GetEarlyBundleGroup( |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 1053 | const cricket::SessionDescription& desc) const |
| 1054 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1055 | |
| 1056 | // Helper methods to create media channels. |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 1057 | cricket::VoiceChannel* CreateVoiceChannel(const std::string& mid) |
| 1058 | RTC_RUN_ON(signaling_thread()); |
| 1059 | cricket::VideoChannel* CreateVideoChannel(const std::string& mid) |
| 1060 | RTC_RUN_ON(signaling_thread()); |
| 1061 | bool CreateDataChannel(const std::string& mid) RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1062 | |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1063 | bool SetupDataChannelTransport_n(const std::string& mid) |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 1064 | RTC_RUN_ON(network_thread()); |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1065 | void TeardownDataChannelTransport_n() RTC_RUN_ON(network_thread()); |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 1066 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1067 | bool ValidateBundleSettings(const cricket::SessionDescription* desc); |
| 1068 | bool HasRtcpMuxEnabled(const cricket::ContentInfo* content); |
| 1069 | // Below methods are helper methods which verifies SDP. |
Steve Anton | 8a00691 | 2017-12-04 23:25:56 | [diff] [blame] | 1070 | RTCError ValidateSessionDescription(const SessionDescriptionInterface* sdesc, |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 1071 | cricket::ContentSource source) |
| 1072 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1073 | |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 1074 | // Check if a call to SetLocalDescription is acceptable with a session |
| 1075 | // description of the given type. |
| 1076 | bool ExpectSetLocalDescription(SdpType type); |
| 1077 | // Check if a call to SetRemoteDescription is acceptable with a session |
| 1078 | // description of the given type. |
| 1079 | bool ExpectSetRemoteDescription(SdpType type); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1080 | // Verifies a=setup attribute as per RFC 5763. |
| 1081 | bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 1082 | SdpType type); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1083 | |
| 1084 | // Returns true if we are ready to push down the remote candidate. |
| 1085 | // |remote_desc| is the new remote description, or NULL if the current remote |
| 1086 | // description should be used. Output |valid| is true if the candidate media |
| 1087 | // index is valid. |
| 1088 | bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate, |
| 1089 | const SessionDescriptionInterface* remote_desc, |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 1090 | bool* valid) RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1091 | |
| 1092 | // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by |
| 1093 | // this session. |
Karl Wiberg | 739506e | 2019-04-03 09:37:28 | [diff] [blame] | 1094 | bool SrtpRequired() const RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1095 | |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 1096 | // JsepTransportController signal handlers. |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 1097 | void OnTransportControllerConnectionState(cricket::IceConnectionState state) |
| 1098 | RTC_RUN_ON(signaling_thread()); |
| 1099 | void OnTransportControllerGatheringState(cricket::IceGatheringState state) |
| 1100 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1101 | void OnTransportControllerCandidatesGathered( |
| 1102 | const std::string& transport_name, |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 1103 | const std::vector<cricket::Candidate>& candidates) |
| 1104 | RTC_RUN_ON(signaling_thread()); |
Eldar Rello | da13ea2 | 2019-06-01 09:23:43 | [diff] [blame] | 1105 | void OnTransportControllerCandidateError( |
| 1106 | const cricket::IceCandidateErrorEvent& event) |
| 1107 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1108 | void OnTransportControllerCandidatesRemoved( |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 1109 | const std::vector<cricket::Candidate>& candidates) |
| 1110 | RTC_RUN_ON(signaling_thread()); |
Alex Drake | 00c7ecf | 2019-08-06 17:54:47 | [diff] [blame] | 1111 | void OnTransportControllerCandidateChanged( |
| 1112 | const cricket::CandidatePairChangeEvent& event) |
| 1113 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1114 | void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error); |
| 1115 | |
Steve Anton | f847081 | 2017-12-04 18:46:21 | [diff] [blame] | 1116 | const char* SessionErrorToString(SessionError error) const; |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 1117 | std::string GetSessionErrorMsg() RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1118 | |
Steve Anton | 8e20f17 | 2018-03-06 18:55:04 | [diff] [blame] | 1119 | // Report the UMA metric SdpFormatReceived for the given remote offer. |
| 1120 | void ReportSdpFormatReceived(const SessionDescriptionInterface& remote_offer); |
| 1121 | |
Steve Anton | 0ffaaa2 | 2018-02-23 18:31:30 | [diff] [blame] | 1122 | // Report inferred negotiated SDP semantics from a local/remote answer to the |
| 1123 | // UMA observer. |
| 1124 | void ReportNegotiatedSdpSemantics(const SessionDescriptionInterface& answer); |
| 1125 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1126 | // Invoked when TransportController connection completion is signaled. |
| 1127 | // Reports stats for all transports in use. |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 1128 | void ReportTransportStats() RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1129 | |
| 1130 | // Gather the usage of IPv4/IPv6 as best connection. |
| 1131 | void ReportBestConnectionState(const cricket::TransportStats& stats); |
| 1132 | |
Steve Anton | c7b964c | 2018-02-01 22:39:45 | [diff] [blame] | 1133 | void ReportNegotiatedCiphers(const cricket::TransportStats& stats, |
Karl Wiberg | 739506e | 2019-04-03 09:37:28 | [diff] [blame] | 1134 | const std::set<cricket::MediaType>& media_types) |
| 1135 | RTC_RUN_ON(signaling_thread()); |
Qingsi Wang | 1ba5dec | 2019-08-19 18:57:17 | [diff] [blame] | 1136 | void ReportIceCandidateCollected(const cricket::Candidate& candidate) |
| 1137 | RTC_RUN_ON(signaling_thread()); |
| 1138 | void ReportRemoteIceCandidateAdded(const cricket::Candidate& candidate) |
| 1139 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1140 | |
Harald Alvestrand | 8ebba74 | 2018-05-31 12:00:34 | [diff] [blame] | 1141 | void NoteUsageEvent(UsageEvent event); |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 1142 | void ReportUsagePattern() const RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | 8ebba74 | 2018-05-31 12:00:34 | [diff] [blame] | 1143 | |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1144 | void OnSentPacket_w(const rtc::SentPacket& sent_packet); |
| 1145 | |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 1146 | const std::string GetTransportName(const std::string& content_name) |
| 1147 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1148 | |
Steve Anton | 6fec880 | 2017-12-04 18:37:29 | [diff] [blame] | 1149 | // Destroys and clears the BaseChannel associated with the given transceiver, |
| 1150 | // if such channel is set. |
| 1151 | void DestroyTransceiverChannel( |
| 1152 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
| 1153 | transceiver); |
| 1154 | |
| 1155 | // Destroys the RTP data channel and/or the SCTP data channel and clears it. |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 1156 | void DestroyDataChannel() RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1157 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 1158 | // Destroys the given ChannelInterface. |
| 1159 | // The channel cannot be accessed after this method is called. |
| 1160 | void DestroyChannelInterface(cricket::ChannelInterface* channel); |
Steve Anton | 6fec880 | 2017-12-04 18:37:29 | [diff] [blame] | 1161 | |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 1162 | // JsepTransportController::Observer override. |
Taylor Brandstetter | cbaa254 | 2018-04-16 23:42:14 | [diff] [blame] | 1163 | // |
| 1164 | // Called by |transport_controller_| when processing transport information |
| 1165 | // from a session description, and the mapping from m= sections to transports |
| 1166 | // changed (as a result of BUNDLE negotiation, or m= sections being |
| 1167 | // rejected). |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1168 | bool OnTransportChanged( |
| 1169 | const std::string& mid, |
| 1170 | RtpTransportInternal* rtp_transport, |
| 1171 | rtc::scoped_refptr<DtlsTransport> dtls_transport, |
| 1172 | MediaTransportInterface* media_transport, |
Bjorn A Mellem | bc3eebc | 2019-09-23 21:53:54 | [diff] [blame] | 1173 | DataChannelTransportInterface* data_channel_transport) override; |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 1174 | |
Guido Urdaneta | 1ff16c8 | 2019-05-20 17:31:53 | [diff] [blame] | 1175 | // RtpSenderBase::SetStreamsObserver override. |
| 1176 | void OnSetStreams() override; |
| 1177 | |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 08:50:16 | [diff] [blame] | 1178 | // Returns the observer. Will crash on CHECK if the observer is removed. |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 1179 | PeerConnectionObserver* Observer() const RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 08:50:16 | [diff] [blame] | 1180 | |
Benjamin Wright | 8c27cca | 2018-10-25 17:16:44 | [diff] [blame] | 1181 | // Returns the CryptoOptions for this PeerConnection. This will always |
| 1182 | // return the RTCConfiguration.crypto_options if set and will only default |
| 1183 | // back to the PeerConnectionFactory settings if nothing was set. |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 1184 | CryptoOptions GetCryptoOptions() RTC_RUN_ON(signaling_thread()); |
Benjamin Wright | 8c27cca | 2018-10-25 17:16:44 | [diff] [blame] | 1185 | |
Anton Sukhanov | 98a462c | 2018-10-17 20:15:42 | [diff] [blame] | 1186 | // Returns rtp transport, result can not be nullptr. |
Karl Wiberg | 2cc368f | 2019-04-02 09:31:56 | [diff] [blame] | 1187 | RtpTransportInternal* GetRtpTransport(const std::string& mid) |
| 1188 | RTC_RUN_ON(signaling_thread()) { |
Anton Sukhanov | 98a462c | 2018-10-17 20:15:42 | [diff] [blame] | 1189 | auto rtp_transport = transport_controller_->GetRtpTransport(mid); |
| 1190 | RTC_DCHECK(rtp_transport); |
| 1191 | return rtp_transport; |
| 1192 | } |
| 1193 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 10:24:14 | [diff] [blame] | 1194 | void UpdateNegotiationNeeded(); |
| 1195 | bool CheckIfNegotiationIsNeeded(); |
Eldar Rello | 5ab79e6 | 2019-10-09 15:29:44 | [diff] [blame] | 1196 | RTCError Rollback(); |
Guido Urdaneta | 70c2db1 | 2019-04-16 10:24:14 | [diff] [blame] | 1197 | |
Karl Wiberg | 106d92d | 2019-02-14 09:17:47 | [diff] [blame] | 1198 | sigslot::signal1<DataChannel*> SignalDataChannelCreated_ |
| 1199 | RTC_GUARDED_BY(signaling_thread()); |
Steve Anton | 2d8609c | 2018-01-24 00:38:46 | [diff] [blame] | 1200 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1201 | // Storing the factory as a scoped reference pointer ensures that the memory |
| 1202 | // in the PeerConnectionFactoryImpl remains available as long as the |
| 1203 | // PeerConnection is running. It is passed to PeerConnection as a raw pointer. |
| 1204 | // However, since the reference counting is done in the |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 1205 | // PeerConnectionFactoryInterface all instances created using the raw pointer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1206 | // will refer to the same reference count. |
Karl Wiberg | 744310f | 2019-02-14 09:18:56 | [diff] [blame] | 1207 | const rtc::scoped_refptr<PeerConnectionFactory> factory_; |
| 1208 | PeerConnectionObserver* observer_ RTC_GUARDED_BY(signaling_thread()) = |
| 1209 | nullptr; |
terelius | 3386025 | 2017-05-13 06:37:18 | [diff] [blame] | 1210 | |
| 1211 | // The EventLog needs to outlive |call_| (and any other object that uses it). |
Karl Wiberg | b03ab71 | 2019-02-14 10:59:57 | [diff] [blame] | 1212 | std::unique_ptr<RtcEventLog> event_log_ RTC_GUARDED_BY(worker_thread()); |
| 1213 | |
| 1214 | // Points to the same thing as `event_log_`. Since it's const, we may read the |
| 1215 | // pointer (but not touch the object) from any thread. |
| 1216 | RtcEventLog* const event_log_ptr_ RTC_PT_GUARDED_BY(worker_thread()); |
terelius | 3386025 | 2017-05-13 06:37:18 | [diff] [blame] | 1217 | |
Karl Wiberg | 8d2e228 | 2019-02-17 12:00:07 | [diff] [blame] | 1218 | SignalingState signaling_state_ RTC_GUARDED_BY(signaling_thread()) = kStable; |
| 1219 | IceConnectionState ice_connection_state_ RTC_GUARDED_BY(signaling_thread()) = |
| 1220 | kIceConnectionNew; |
| 1221 | PeerConnectionInterface::IceConnectionState standardized_ice_connection_state_ |
| 1222 | RTC_GUARDED_BY(signaling_thread()) = kIceConnectionNew; |
| 1223 | PeerConnectionInterface::PeerConnectionState connection_state_ |
| 1224 | RTC_GUARDED_BY(signaling_thread()) = PeerConnectionState::kNew; |
Jonas Olsson | 635474e | 2018-10-18 13:58:17 | [diff] [blame] | 1225 | |
Karl Wiberg | 8d2e228 | 2019-02-17 12:00:07 | [diff] [blame] | 1226 | IceGatheringState ice_gathering_state_ RTC_GUARDED_BY(signaling_thread()) = |
| 1227 | kIceGatheringNew; |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 1228 | PeerConnectionInterface::RTCConfiguration configuration_ |
| 1229 | RTC_GUARDED_BY(signaling_thread()); |
| 1230 | |
Bjorn A Mellem | 5985a04 | 2019-06-28 21:19:38 | [diff] [blame] | 1231 | // Field-trial based configuration for datagram transport. |
| 1232 | const DatagramTransportConfig datagram_transport_config_; |
| 1233 | |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1234 | // Field-trial based configuration for datagram transport data channels. |
Bjorn A Mellem | 7da4e56 | 2019-09-26 18:02:11 | [diff] [blame] | 1235 | const DatagramTransportDataChannelConfig |
| 1236 | datagram_transport_data_channel_config_; |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1237 | |
Bjorn A Mellem | 5985a04 | 2019-06-28 21:19:38 | [diff] [blame] | 1238 | // Final, resolved value for whether datagram transport is in use. |
| 1239 | bool use_datagram_transport_ RTC_GUARDED_BY(signaling_thread()) = false; |
| 1240 | |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1241 | // Equivalent of |use_datagram_transport_|, but for its use with data |
| 1242 | // channels. |
| 1243 | bool use_datagram_transport_for_data_channels_ |
| 1244 | RTC_GUARDED_BY(signaling_thread()) = false; |
| 1245 | |
Bjorn A Mellem | 7da4e56 | 2019-09-26 18:02:11 | [diff] [blame] | 1246 | // Resolved value of whether to use data channels only for incoming calls. |
| 1247 | bool use_datagram_transport_for_data_channels_receive_only_ |
| 1248 | RTC_GUARDED_BY(signaling_thread()) = false; |
| 1249 | |
Karl Wiberg | 5966c50 | 2019-02-21 22:55:09 | [diff] [blame] | 1250 | // Cache configuration_.use_media_transport so that we can access it from |
| 1251 | // other threads. |
| 1252 | // TODO(bugs.webrtc.org/9987): Caching just this bool and allowing the data |
| 1253 | // it's derived from to change is not necessarily sound. Stop doing it. |
| 1254 | rtc::RaceChecker use_media_transport_race_checker_; |
| 1255 | bool use_media_transport_ RTC_GUARDED_BY(use_media_transport_race_checker_) = |
| 1256 | configuration_.use_media_transport; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1257 | |
Zach Stein | e20867f | 2018-08-02 20:20:15 | [diff] [blame] | 1258 | // TODO(zstein): |async_resolver_factory_| can currently be nullptr if it |
| 1259 | // is not injected. It should be required once chromium supplies it. |
Karl Wiberg | fb3be39 | 2019-03-22 13:13:22 | [diff] [blame] | 1260 | std::unique_ptr<AsyncResolverFactory> async_resolver_factory_ |
| 1261 | RTC_GUARDED_BY(signaling_thread()); |
| 1262 | std::unique_ptr<cricket::PortAllocator> |
| 1263 | port_allocator_; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1264 | // signaling and network thread. |
| 1265 | std::unique_ptr<rtc::SSLCertificateVerifier> |
| 1266 | tls_cert_verifier_; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1267 | // signaling and network thread. |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 1268 | |
zhihuang | 8f65cdf | 2016-05-07 01:40:30 | [diff] [blame] | 1269 | // One PeerConnection has only one RTCP CNAME. |
| 1270 | // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9 |
Karl Wiberg | fb3be39 | 2019-03-22 13:13:22 | [diff] [blame] | 1271 | const std::string rtcp_cname_; |
zhihuang | 8f65cdf | 2016-05-07 01:40:30 | [diff] [blame] | 1272 | |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 1273 | // Streams added via AddStream. |
Karl Wiberg | 1e1e102 | 2019-03-22 13:27:22 | [diff] [blame] | 1274 | const rtc::scoped_refptr<StreamCollection> local_streams_ |
| 1275 | RTC_GUARDED_BY(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 1276 | // Streams created as a result of SetRemoteDescription. |
Karl Wiberg | 1e1e102 | 2019-03-22 13:27:22 | [diff] [blame] | 1277 | const rtc::scoped_refptr<StreamCollection> remote_streams_ |
| 1278 | RTC_GUARDED_BY(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 1279 | |
Karl Wiberg | 1e1e102 | 2019-03-22 13:27:22 | [diff] [blame] | 1280 | std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_ |
| 1281 | RTC_GUARDED_BY(signaling_thread()); |
deadbeef | eb45981 | 2015-12-16 03:24:43 | [diff] [blame] | 1282 | |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 1283 | // These lists store sender info seen in local/remote descriptions. |
Karl Wiberg | c70999e | 2019-03-22 14:14:27 | [diff] [blame] | 1284 | std::vector<RtpSenderInfo> remote_audio_sender_infos_ |
| 1285 | RTC_GUARDED_BY(signaling_thread()); |
| 1286 | std::vector<RtpSenderInfo> remote_video_sender_infos_ |
| 1287 | RTC_GUARDED_BY(signaling_thread()); |
| 1288 | std::vector<RtpSenderInfo> local_audio_sender_infos_ |
| 1289 | RTC_GUARDED_BY(signaling_thread()); |
| 1290 | std::vector<RtpSenderInfo> local_video_sender_infos_ |
| 1291 | RTC_GUARDED_BY(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 1292 | |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 1293 | SctpSidAllocator sid_allocator_ RTC_GUARDED_BY(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 1294 | // label -> DataChannel |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 1295 | std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_ |
| 1296 | RTC_GUARDED_BY(signaling_thread()); |
| 1297 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_ |
| 1298 | RTC_GUARDED_BY(signaling_thread()); |
| 1299 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_ |
| 1300 | RTC_GUARDED_BY(signaling_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 1301 | |
Karl Wiberg | 85a4a93 | 2019-03-22 14:29:58 | [diff] [blame] | 1302 | bool remote_peer_supports_msid_ RTC_GUARDED_BY(signaling_thread()) = false; |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 1303 | |
Karl Wiberg | ac02589 | 2019-03-26 12:08:37 | [diff] [blame] | 1304 | // The unique_ptr belongs to the worker thread, but the Call object manages |
| 1305 | // its own thread safety. |
Karl Wiberg | 6cab5c8 | 2019-03-26 08:57:01 | [diff] [blame] | 1306 | std::unique_ptr<Call> call_ RTC_GUARDED_BY(worker_thread()); |
| 1307 | |
Sebastian Jansson | 1b83a9e | 2019-09-18 16:22:12 | [diff] [blame] | 1308 | rtc::AsyncInvoker rtcp_invoker_ RTC_GUARDED_BY(network_thread()); |
| 1309 | |
Karl Wiberg | 6cab5c8 | 2019-03-26 08:57:01 | [diff] [blame] | 1310 | // Points to the same thing as `call_`. Since it's const, we may read the |
Karl Wiberg | ac02589 | 2019-03-26 12:08:37 | [diff] [blame] | 1311 | // pointer from any thread. |
| 1312 | Call* const call_ptr_; |
Karl Wiberg | 6cab5c8 | 2019-03-26 08:57:01 | [diff] [blame] | 1313 | |
| 1314 | std::unique_ptr<StatsCollector> stats_ |
| 1315 | RTC_GUARDED_BY(signaling_thread()); // A pointer is passed to senders_ |
| 1316 | rtc::scoped_refptr<RTCStatsCollector> stats_collector_ |
| 1317 | RTC_GUARDED_BY(signaling_thread()); |
Eldar Rello | 5ab79e6 | 2019-10-09 15:29:44 | [diff] [blame] | 1318 | // Holds changes made to transceivers during applying descriptors for |
| 1319 | // potential rollback. Gets cleared once signaling state goes to stable. |
| 1320 | std::map<rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>, |
| 1321 | TransceiverStableState> |
| 1322 | transceiver_stable_states_by_transceivers_; |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 1323 | std::vector< |
Steve Anton | 4171afb | 2017-11-20 18:20:22 | [diff] [blame] | 1324 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
Karl Wiberg | 2cc368f | 2019-04-02 09:31:56 | [diff] [blame] | 1325 | transceivers_; // TODO(bugs.webrtc.org/9987): Accessed on both signaling |
| 1326 | // and network thread. |
| 1327 | |
Henrik Boström | 5b14778 | 2018-12-04 10:25:05 | [diff] [blame] | 1328 | // In Unified Plan, if we encounter remote SDP that does not contain an a=msid |
| 1329 | // line we create and use a stream with a random ID for our receivers. This is |
| 1330 | // to support legacy endpoints that do not support the a=msid attribute (as |
| 1331 | // opposed to streamless tracks with "a=msid:-"). |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 1332 | rtc::scoped_refptr<MediaStreamInterface> missing_msid_default_stream_ |
| 1333 | RTC_GUARDED_BY(signaling_thread()); |
Amit Hilbuch | ae3df54 | 2019-01-07 20:13:08 | [diff] [blame] | 1334 | // MIDs will be generated using this generator which will keep track of |
| 1335 | // all the MIDs that have been seen over the life of the PeerConnection. |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 1336 | rtc::UniqueStringGenerator mid_generator_ RTC_GUARDED_BY(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1337 | |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 1338 | SessionError session_error_ RTC_GUARDED_BY(signaling_thread()) = |
| 1339 | SessionError::kNone; |
| 1340 | std::string session_error_desc_ RTC_GUARDED_BY(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1341 | |
Karl Wiberg | a58e169 | 2019-03-26 12:33:43 | [diff] [blame] | 1342 | std::string session_id_ RTC_GUARDED_BY(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1343 | |
Karl Wiberg | 2cc368f | 2019-04-02 09:31:56 | [diff] [blame] | 1344 | std::unique_ptr<JsepTransportController> |
| 1345 | transport_controller_; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1346 | // signaling and network thread. |
| 1347 | std::unique_ptr<cricket::SctpTransportInternalFactory> |
| 1348 | sctp_factory_; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1349 | // signaling and network thread. |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1350 | // |rtp_data_channel_| is used if in RTP data channel mode, |sctp_transport_| |
| 1351 | // when using SCTP. |
Karl Wiberg | 2cc368f | 2019-04-02 09:31:56 | [diff] [blame] | 1352 | cricket::RtpDataChannel* rtp_data_channel_ = |
| 1353 | nullptr; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1354 | // signaling and some other thread. |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1355 | |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 1356 | // |sctp_mid_| is the content name (MID) in SDP. |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1357 | // Note: this is used as the data channel MID by both SCTP and data channel |
| 1358 | // transports. It is set when either transport is initialized and unset when |
| 1359 | // both transports are deleted. |
Karl Wiberg | 2cc368f | 2019-04-02 09:31:56 | [diff] [blame] | 1360 | absl::optional<std::string> |
| 1361 | sctp_mid_; // TODO(bugs.webrtc.org/9987): Accessed on both signaling |
| 1362 | // and network thread. |
| 1363 | |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 1364 | // Whether this peer is the caller. Set when the local description is applied. |
| 1365 | absl::optional<bool> is_caller_ RTC_GUARDED_BY(signaling_thread()); |
| 1366 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 21:53:54 | [diff] [blame] | 1367 | // Plugin transport used for data channels. Pointer may be accessed and |
| 1368 | // checked from any thread, but the object may only be touched on the |
| 1369 | // network thread. |
| 1370 | // TODO(bugs.webrtc.org/9987): Accessed on both signaling and network thread. |
| 1371 | DataChannelTransportInterface* data_channel_transport_; |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 1372 | |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1373 | // Cached value of whether the data channel transport is ready to send. |
| 1374 | bool data_channel_transport_ready_to_send_ |
| 1375 | RTC_GUARDED_BY(signaling_thread()) = false; |
| 1376 | |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1377 | // Used to invoke data channel transport signals on the signaling thread. |
| 1378 | std::unique_ptr<rtc::AsyncInvoker> data_channel_transport_invoker_ |
Karl Wiberg | 739506e | 2019-04-03 09:37:28 | [diff] [blame] | 1379 | RTC_GUARDED_BY(network_thread()); |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 1380 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 21:53:54 | [diff] [blame] | 1381 | // Signals from |data_channel_transport_|. These are invoked on the signaling |
| 1382 | // thread. |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1383 | sigslot::signal1<bool> SignalDataChannelTransportWritable_s |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 1384 | RTC_GUARDED_BY(signaling_thread()); |
| 1385 | sigslot::signal2<const cricket::ReceiveDataParams&, |
| 1386 | const rtc::CopyOnWriteBuffer&> |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1387 | SignalDataChannelTransportReceivedData_s |
| 1388 | RTC_GUARDED_BY(signaling_thread()); |
| 1389 | sigslot::signal1<int> SignalDataChannelTransportChannelClosing_s |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 1390 | RTC_GUARDED_BY(signaling_thread()); |
Bjorn A Mellem | b689af4 | 2019-08-21 17:44:59 | [diff] [blame] | 1391 | sigslot::signal1<int> SignalDataChannelTransportChannelClosed_s |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 1392 | RTC_GUARDED_BY(signaling_thread()); |
| 1393 | |
Karl Wiberg | 739506e | 2019-04-03 09:37:28 | [diff] [blame] | 1394 | std::unique_ptr<SessionDescriptionInterface> current_local_description_ |
| 1395 | RTC_GUARDED_BY(signaling_thread()); |
| 1396 | std::unique_ptr<SessionDescriptionInterface> pending_local_description_ |
| 1397 | RTC_GUARDED_BY(signaling_thread()); |
| 1398 | std::unique_ptr<SessionDescriptionInterface> current_remote_description_ |
| 1399 | RTC_GUARDED_BY(signaling_thread()); |
| 1400 | std::unique_ptr<SessionDescriptionInterface> pending_remote_description_ |
| 1401 | RTC_GUARDED_BY(signaling_thread()); |
| 1402 | bool dtls_enabled_ RTC_GUARDED_BY(signaling_thread()) = false; |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1403 | // Specifies which kind of data channel is allowed. This is controlled |
| 1404 | // by the chrome command-line flag and constraints: |
| 1405 | // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled, |
| 1406 | // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is |
| 1407 | // not set or false, SCTP is allowed (DCT_SCTP); |
| 1408 | // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP); |
| 1409 | // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE). |
Karl Wiberg | f73f7d6 | 2019-04-08 13:36:53 | [diff] [blame] | 1410 | cricket::DataChannelType data_channel_type_ = |
| 1411 | cricket::DCT_NONE; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 1412 | // signaling and network thread. |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1413 | |
Karl Wiberg | f73f7d6 | 2019-04-08 13:36:53 | [diff] [blame] | 1414 | // List of content names for which the remote side triggered an ICE restart. |
| 1415 | std::set<std::string> pending_ice_restarts_ |
| 1416 | RTC_GUARDED_BY(signaling_thread()); |
| 1417 | |
| 1418 | std::unique_ptr<WebRtcSessionDescriptionFactory> webrtc_session_desc_factory_ |
| 1419 | RTC_GUARDED_BY(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 18:37:17 | [diff] [blame] | 1420 | |
| 1421 | // Member variables for caching global options. |
Karl Wiberg | f73f7d6 | 2019-04-08 13:36:53 | [diff] [blame] | 1422 | cricket::AudioOptions audio_options_ RTC_GUARDED_BY(signaling_thread()); |
| 1423 | cricket::VideoOptions video_options_ RTC_GUARDED_BY(signaling_thread()); |
Harald Alvestrand | 8ebba74 | 2018-05-31 12:00:34 | [diff] [blame] | 1424 | |
Karl Wiberg | f73f7d6 | 2019-04-08 13:36:53 | [diff] [blame] | 1425 | int usage_event_accumulator_ RTC_GUARDED_BY(signaling_thread()) = 0; |
| 1426 | bool return_histogram_very_quickly_ RTC_GUARDED_BY(signaling_thread()) = |
| 1427 | false; |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 1428 | |
| 1429 | // This object should be used to generate any SSRC that is not explicitly |
| 1430 | // specified by the user (or by the remote party). |
| 1431 | // The generator is not used directly, instead it is passed on to the |
| 1432 | // channel manager and the session description factory. |
Karl Wiberg | f73f7d6 | 2019-04-08 13:36:53 | [diff] [blame] | 1433 | rtc::UniqueRandomIdGenerator ssrc_generator_ |
| 1434 | RTC_GUARDED_BY(signaling_thread()); |
Jonas Oreland | a3aa9bd | 2019-04-17 05:38:40 | [diff] [blame] | 1435 | |
| 1436 | // A video bitrate allocator factory. |
| 1437 | // This can injected using the PeerConnectionDependencies, |
| 1438 | // or else the CreateBuiltinVideoBitrateAllocatorFactory() will be called. |
| 1439 | // Note that one can still choose to override this in a MediaEngine |
| 1440 | // if one wants too. |
| 1441 | std::unique_ptr<webrtc::VideoBitrateAllocatorFactory> |
| 1442 | video_bitrate_allocator_factory_; |
| 1443 | |
Henrik Boström | 79b6980 | 2019-07-18 09:16:56 | [diff] [blame] | 1444 | std::unique_ptr<LocalIceCredentialsToReplace> |
| 1445 | local_ice_credentials_to_replace_ RTC_GUARDED_BY(signaling_thread()); |
Guido Urdaneta | 70c2db1 | 2019-04-16 10:24:14 | [diff] [blame] | 1446 | bool is_negotiation_needed_ RTC_GUARDED_BY(signaling_thread()) = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1447 | }; |
| 1448 | |
| 1449 | } // namespace webrtc |
| 1450 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 1451 | #endif // PC_PEER_CONNECTION_H_ |