You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1453 lines
66 KiB

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