blob: ef543a227ff19a33e4214c78c5c8c0eb0b76b1c2 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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.org28e20752013-07-10 00:45:369 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef PC_PEER_CONNECTION_H_
12#define PC_PEER_CONNECTION_H_
henrike@webrtc.org28e20752013-07-10 00:45:3613
Harald Alvestrand1f7eab62020-10-18 16:51:4714#include <stdint.h>
Artem Titovd15a5752021-02-10 13:31:2415
Tomas Gunnarsson1e40a0c2020-09-28 08:39:3116#include <functional>
perkjd61bf802016-03-24 10:16:1917#include <map>
kwibergd1fe2812016-04-27 13:47:2918#include <memory>
Steve Anton75737c02017-11-06 18:37:1719#include <set>
20#include <string>
perkjd61bf802016-03-24 10:16:1921#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:3622
Harald Alvestrand1f7eab62020-10-18 16:51:4723#include "absl/types/optional.h"
24#include "api/adaptation/resource.h"
Harald Alvestrand0ccfbd22021-04-08 07:25:0425#include "api/async_dns_resolver.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4726#include "api/candidate.h"
27#include "api/crypto/crypto_options.h"
28#include "api/data_channel_interface.h"
29#include "api/dtls_transport_interface.h"
Danil Chapovalov3bdb49b2023-11-30 07:59:3930#include "api/environment/environment.h"
Jonas Orelande62c2f22022-03-29 09:04:4831#include "api/field_trials_view.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4732#include "api/ice_transport_interface.h"
33#include "api/jsep.h"
34#include "api/media_stream_interface.h"
35#include "api/media_types.h"
Steve Anton10542f22019-01-11 17:11:0036#include "api/peer_connection_interface.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4737#include "api/rtc_error.h"
38#include "api/rtc_event_log/rtc_event_log.h"
39#include "api/rtc_event_log_output.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4740#include "api/rtp_receiver_interface.h"
41#include "api/rtp_sender_interface.h"
42#include "api/rtp_transceiver_interface.h"
43#include "api/scoped_refptr.h"
44#include "api/sctp_transport_interface.h"
Artem Titovd15a5752021-02-10 13:31:2445#include "api/sequence_checker.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4746#include "api/set_local_description_observer_interface.h"
47#include "api/set_remote_description_observer_interface.h"
48#include "api/stats/rtc_stats_collector_callback.h"
Artem Titovc374d112022-06-16 19:27:4549#include "api/task_queue/pending_task_safety_flag.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4750#include "api/transport/bitrate_settings.h"
Niels Möller65f17ca2019-09-12 11:59:3651#include "api/transport/data_channel_transport_interface.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4752#include "api/transport/enums.h"
Steve Anton10542f22019-01-11 17:11:0053#include "api/turn_customizer.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4754#include "call/call.h"
Per Ke1e94ad2023-03-30 14:53:5955#include "modules/rtp_rtcp/source/rtp_packet_received.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4756#include "p2p/base/ice_transport_internal.h"
57#include "p2p/base/port.h"
58#include "p2p/base/port_allocator.h"
59#include "p2p/base/transport_description.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4760#include "pc/channel_interface.h"
Harald Alvestranda39689c2020-10-15 08:34:3161#include "pc/connection_context.h"
Harald Alvestrand05e4d082019-12-03 13:04:2162#include "pc/data_channel_controller.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4763#include "pc/data_channel_utils.h"
64#include "pc/dtls_transport.h"
Steve Anton10542f22019-01-11 17:11:0065#include "pc/jsep_transport_controller.h"
Henrik Boströmf7859892022-07-04 12:36:3766#include "pc/legacy_stats_collector.h"
Steve Anton10542f22019-01-11 17:11:0067#include "pc/peer_connection_internal.h"
Harald Alvestrand1090e442020-10-05 07:01:0968#include "pc/peer_connection_message_handler.h"
Steve Anton10542f22019-01-11 17:11:0069#include "pc/rtc_stats_collector.h"
70#include "pc/rtp_transceiver.h"
Harald Alvestrande15fb152020-10-19 13:28:0571#include "pc/rtp_transmission_manager.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4772#include "pc/rtp_transport_internal.h"
73#include "pc/sctp_data_channel.h"
Harald Alvestrandcdcfab02020-09-28 13:02:0774#include "pc/sdp_offer_answer.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4775#include "pc/session_description.h"
Harald Alvestrand38b768c2020-09-29 11:54:0576#include "pc/transceiver_list.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4777#include "pc/transport_stats.h"
Harald Alvestrand44d0dff2020-10-09 05:43:5378#include "pc/usage_pattern.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4779#include "rtc_base/checks.h"
80#include "rtc_base/copy_on_write_buffer.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4781#include "rtc_base/rtc_certificate.h"
82#include "rtc_base/ssl_certificate.h"
83#include "rtc_base/ssl_stream_adapter.h"
Harald Alvestrand1f7eab62020-10-18 16:51:4784#include "rtc_base/thread.h"
85#include "rtc_base/thread_annotations.h"
Harald Alvestrand85466662021-04-19 21:21:3686#include "rtc_base/weak_ptr.h"
henrike@webrtc.org28e20752013-07-10 00:45:3687
88namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:3689
Steve Anton75737c02017-11-06 18:37:1790// PeerConnection is the implementation of the PeerConnection object as defined
91// by the PeerConnectionInterface API surface.
92// The class currently is solely responsible for the following:
93// - Managing the session state machine (signaling state).
94// - Creating and initializing lower-level objects, like PortAllocator and
95// BaseChannels.
96// - Owning and managing the life cycle of the RtpSender/RtpReceiver and track
97// objects.
98// - Tracking the current and pending local/remote session descriptions.
99// The class currently is jointly responsible for the following:
100// - Parsing and interpreting SDP.
101// - Generating offers and answers based on the current state.
102// - The ICE state machine.
103// - Generating stats.
Steve Anton2d8609c2018-01-24 00:38:46104class PeerConnection : public PeerConnectionInternal,
Harald Alvestrand5b84f382022-02-08 10:49:09105 public JsepTransportController::Observer {
henrike@webrtc.org28e20752013-07-10 00:45:36106 public:
Harald Alvestrand62166932020-10-26 08:30:41107 // Creates a PeerConnection and initializes it with the given values.
108 // If the initialization fails, the function releases the PeerConnection
109 // and returns nullptr.
110 //
111 // Note that the function takes ownership of dependencies, and will
112 // either use them or release them, whether it succeeds or fails.
Harald Alvestranda3dd7722020-11-27 08:05:42113 static RTCErrorOr<rtc::scoped_refptr<PeerConnection>> Create(
Danil Chapovalov3bdb49b2023-11-30 07:59:39114 const Environment& env,
Harald Alvestrand62166932020-10-26 08:30:41115 rtc::scoped_refptr<ConnectionContext> context,
Harald Alvestrand4da4a872020-11-04 10:34:21116 const PeerConnectionFactoryInterface::Options& options,
Harald Alvestrand62166932020-10-26 08:30:41117 std::unique_ptr<Call> call,
deadbeef653b8e02015-11-11 20:55:10118 const PeerConnectionInterface::RTCConfiguration& configuration,
Benjamin Wrightcab588882018-05-02 22:12:47119 PeerConnectionDependencies dependencies);
deadbeef653b8e02015-11-11 20:55:10120
deadbeefa67696b2015-09-29 18:56:26121 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
122 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;
123 bool AddStream(MediaStreamInterface* local_stream) override;
124 void RemoveStream(MediaStreamInterface* local_stream) override;
henrike@webrtc.org28e20752013-07-10 00:45:36125
Steve Anton2d6c76a2018-01-06 01:10:52126 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
Steve Antonf9381f02017-12-14 18:23:57127 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Seth Hampson845e8782018-03-02 19:34:10128 const std::vector<std::string>& stream_ids) override;
Jonas Oreland4b2a1062022-10-19 07:24:42129 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
130 rtc::scoped_refptr<MediaStreamTrackInterface> track,
131 const std::vector<std::string>& stream_ids,
132 const std::vector<RtpEncodingParameters>& init_send_encodings) override;
133 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
134 rtc::scoped_refptr<MediaStreamTrackInterface> track,
135 const std::vector<std::string>& stream_ids,
136 const std::vector<RtpEncodingParameters>* init_send_encodings);
Harald Alvestrand09a0d012022-01-04 19:42:07137 RTCError RemoveTrackOrError(
Steve Anton24db5732018-07-23 17:27:33138 rtc::scoped_refptr<RtpSenderInterface> sender) override;
deadbeefe1f9d832016-01-14 23:35:42139
Steve Anton9158ef62017-11-27 21:01:52140 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
141 rtc::scoped_refptr<MediaStreamTrackInterface> track) override;
142 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
143 rtc::scoped_refptr<MediaStreamTrackInterface> track,
144 const RtpTransceiverInit& init) override;
145 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
146 cricket::MediaType media_type) override;
147 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
148 cricket::MediaType media_type,
149 const RtpTransceiverInit& init) override;
150
deadbeeffac06552015-11-25 19:26:01151 rtc::scoped_refptr<RtpSenderInterface> CreateSender(
deadbeefbd7d8f72015-12-19 00:58:44152 const std::string& kind,
153 const std::string& stream_id) override;
deadbeeffac06552015-11-25 19:26:01154
deadbeef70ab1a12015-09-28 23:53:55155 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
156 const override;
157 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
158 const override;
Steve Anton9158ef62017-11-27 21:01:52159 std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers()
160 const override;
deadbeef70ab1a12015-09-28 23:53:55161
Harald Alvestranda9af50f2021-05-21 13:33:51162 RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>> CreateDataChannelOrError(
henrike@webrtc.org28e20752013-07-10 00:45:36163 const std::string& label,
deadbeefa67696b2015-09-29 18:56:26164 const DataChannelInit* config) override;
Henrik Boström1df1bf82018-03-20 12:24:20165 // WARNING: LEGACY. See peerconnectioninterface.h
deadbeefa67696b2015-09-29 18:56:26166 bool GetStats(StatsObserver* observer,
Harald Alvestranda6544372023-11-13 09:33:56167 MediaStreamTrackInterface* track,
deadbeefa67696b2015-09-29 18:56:26168 StatsOutputLevel level) override;
Henrik Boström1df1bf82018-03-20 12:24:20169 // Spec-complaint GetStats(). See peerconnectioninterface.h
hbos74e1a4f2016-09-16 06:33:01170 void GetStats(RTCStatsCollectorCallback* callback) override;
Henrik Boström1df1bf82018-03-20 12:24:20171 void GetStats(
172 rtc::scoped_refptr<RtpSenderInterface> selector,
173 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override;
174 void GetStats(
175 rtc::scoped_refptr<RtpReceiverInterface> selector,
176 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override;
Harald Alvestrand89061872018-01-02 13:08:34177 void ClearStatsCache() override;
henrike@webrtc.org28e20752013-07-10 00:45:36178
deadbeefa67696b2015-09-29 18:56:26179 SignalingState signaling_state() override;
henrike@webrtc.org28e20752013-07-10 00:45:36180
deadbeefa67696b2015-09-29 18:56:26181 IceConnectionState ice_connection_state() override;
Harald Alvestrand5b661302022-01-28 13:08:34182 IceConnectionState ice_connection_state_internal() override {
183 return ice_connection_state();
184 }
Jonas Olsson12046902018-12-06 10:25:14185 IceConnectionState standardized_ice_connection_state() override;
Jonas Olsson635474e2018-10-18 13:58:17186 PeerConnectionState peer_connection_state() override;
deadbeefa67696b2015-09-29 18:56:26187 IceGatheringState ice_gathering_state() override;
Harald Alvestrand61f74d92020-03-02 10:20:00188 absl::optional<bool> can_trickle_ice_candidates() override;
henrike@webrtc.org28e20752013-07-10 00:45:36189
deadbeefa67696b2015-09-29 18:56:26190 const SessionDescriptionInterface* local_description() const override;
191 const SessionDescriptionInterface* remote_description() const override;
deadbeeffe4a8a42016-12-21 01:56:17192 const SessionDescriptionInterface* current_local_description() const override;
193 const SessionDescriptionInterface* current_remote_description()
194 const override;
195 const SessionDescriptionInterface* pending_local_description() const override;
196 const SessionDescriptionInterface* pending_remote_description()
197 const override;
henrike@webrtc.org28e20752013-07-10 00:45:36198
Henrik Boström79b69802019-07-18 09:16:56199 void RestartIce() override;
200
henrike@webrtc.org28e20752013-07-10 00:45:36201 // JSEP01
deadbeefa67696b2015-09-29 18:56:26202 void CreateOffer(CreateSessionDescriptionObserver* observer,
203 const RTCOfferAnswerOptions& options) override;
htaa2a49d92016-03-04 10:51:39204 void CreateAnswer(CreateSessionDescriptionObserver* observer,
205 const RTCOfferAnswerOptions& options) override;
Henrik Boström831ae4e2020-07-29 10:04:00206
207 void SetLocalDescription(
208 std::unique_ptr<SessionDescriptionInterface> desc,
209 rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer)
210 override;
211 void SetLocalDescription(
212 rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer)
213 override;
214 // TODO(https://crbug.com/webrtc/11798): Delete these methods in favor of the
215 // ones taking SetLocalDescriptionObserverInterface as argument.
deadbeefa67696b2015-09-29 18:56:26216 void SetLocalDescription(SetSessionDescriptionObserver* observer,
217 SessionDescriptionInterface* desc) override;
Henrik Boström4e196702019-10-30 09:35:50218 void SetLocalDescription(SetSessionDescriptionObserver* observer) override;
Henrik Boström831ae4e2020-07-29 10:04:00219
Henrik Boström31638672017-11-23 16:48:32220 void SetRemoteDescription(
221 std::unique_ptr<SessionDescriptionInterface> desc,
222 rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer)
223 override;
Henrik Boström831ae4e2020-07-29 10:04:00224 // TODO(https://crbug.com/webrtc/11798): Delete this methods in favor of the
225 // ones taking SetRemoteDescriptionObserverInterface as argument.
226 void SetRemoteDescription(SetSessionDescriptionObserver* observer,
227 SessionDescriptionInterface* desc) override;
228
deadbeef46c73892016-11-17 03:42:04229 PeerConnectionInterface::RTCConfiguration GetConfiguration() override;
Niels Möller2579f0c2019-08-19 07:58:17230 RTCError SetConfiguration(
231 const PeerConnectionInterface::RTCConfiguration& configuration) override;
deadbeefa67696b2015-09-29 18:56:26232 bool AddIceCandidate(const IceCandidateInterface* candidate) override;
Henrik Boströmee6f4f62019-11-06 11:36:12233 void AddIceCandidate(std::unique_ptr<IceCandidateInterface> candidate,
234 std::function<void(RTCError)> callback) override;
Honghai Zhang7fb69db2016-03-14 18:59:18235 bool RemoveIceCandidates(
236 const std::vector<cricket::Candidate>& candidates) override;
henrike@webrtc.org28e20752013-07-10 00:45:36237
Niels Möller0c4f7be2018-05-07 12:01:37238 RTCError SetBitrate(const BitrateSettings& bitrate) override;
Per K39ac25d2024-02-07 13:16:20239 void ReconfigureBandwidthEstimation(
240 const BandwidthEstimationSettings& settings) override;
zstein4b979802017-06-02 21:37:37241
henrika5f6bf242017-11-01 10:06:56242 void SetAudioPlayout(bool playout) override;
243 void SetAudioRecording(bool recording) override;
244
Harald Alvestrandad88c882018-11-28 15:47:46245 rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid(
246 const std::string& mid) override;
Harald Alvestrand4a7b3ac2019-01-17 09:39:40247 rtc::scoped_refptr<DtlsTransport> LookupDtlsTransportByMidInternal(
248 const std::string& mid);
Harald Alvestrandad88c882018-11-28 15:47:46249
Harald Alvestrandc85328f2019-02-28 06:51:00250 rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const override;
251
Henrik Boström4c1e7cc2020-06-11 10:26:53252 void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) override;
253
Bjorn Tereliusde939432017-11-20 16:38:14254 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,
255 int64_t output_period_ms) override;
Niels Möllerf00ca1a2019-05-10 09:33:12256 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override;
ivoc14d5dbe2016-07-04 14:06:55257 void StopRtcEventLog() override;
258
deadbeefa67696b2015-09-29 18:56:26259 void Close() override;
henrike@webrtc.org28e20752013-07-10 00:45:36260
Taylor Brandstetterc88fe702020-08-03 23:36:16261 rtc::Thread* signaling_thread() const final {
Harald Alvestranda39689c2020-10-15 08:34:31262 return context_->signaling_thread();
Taylor Brandstetterc88fe702020-08-03 23:36:16263 }
264
Karl Wiberg4ae63472019-02-21 23:57:06265 rtc::Thread* network_thread() const final {
Harald Alvestranda39689c2020-10-15 08:34:31266 return context_->network_thread();
Steve Anton2d8609c2018-01-24 00:38:46267 }
Harald Alvestranda39689c2020-10-15 08:34:31268 rtc::Thread* worker_thread() const final { return context_->worker_thread(); }
deadbeefab9b2d12015-10-14 18:33:11269
Jared Siskinbceec842023-04-20 21:10:51270 std::string session_id() const override { return session_id_; }
Steve Anton75737c02017-11-06 18:37:17271
Steve Anton2d8609c2018-01-24 00:38:46272 bool initial_offerer() const override {
Karl Wiberg2cc368f2019-04-02 09:31:56273 RTC_DCHECK_RUN_ON(signaling_thread());
Harald Alvestrandbc32c562022-02-09 12:08:47274 return sdp_handler_->initial_offerer();
Steve Anton2d8609c2018-01-24 00:38:46275 }
Steve Anton75737c02017-11-06 18:37:17276
Steve Anton2d8609c2018-01-24 00:38:46277 std::vector<
278 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
Steve Antonb8867112018-02-13 18:07:54279 GetTransceiversInternal() const override {
Karl Wiberga58e1692019-03-26 12:33:43280 RTC_DCHECK_RUN_ON(signaling_thread());
Harald Alvestrand8101e7b2022-05-23 14:57:47281 if (!ConfiguredForMedia()) {
282 return {};
283 }
Harald Alvestrande15fb152020-10-19 13:28:05284 return rtp_manager()->transceivers()->List();
Steve Anton2d8609c2018-01-24 00:38:46285 }
286
Taylor Brandstetter3a034e12020-07-09 22:32:34287 std::vector<DataChannelStats> GetDataChannelStats() const override;
Steve Anton2d8609c2018-01-24 00:38:46288
Danil Chapovalov66cadcc2018-06-19 14:47:43289 absl::optional<std::string> sctp_transport_name() const override;
Tomas Gunnarssonbfd9ba82021-04-18 09:55:57290 absl::optional<std::string> sctp_mid() const override;
Steve Anton75737c02017-11-06 18:37:17291
Qingsi Wang72a43a12018-02-21 00:03:18292 cricket::CandidateStatsList GetPooledCandidateStats() const override;
Steve Anton5dfde182018-02-06 18:34:40293 std::map<std::string, cricket::TransportStats> GetTransportStatsByNames(
294 const std::set<std::string>& transport_names) override;
Steve Anton2d8609c2018-01-24 00:38:46295 Call::Stats GetCallStats() override;
Steve Anton75737c02017-11-06 18:37:17296
Fredrik Hernqvistefbe7532023-01-13 15:42:36297 absl::optional<AudioDeviceModule::Stats> GetAudioDeviceStats() override;
298
Steve Anton2d8609c2018-01-24 00:38:46299 bool GetLocalCertificate(
300 const std::string& transport_name,
301 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override;
Taylor Brandstetterc3928662018-02-23 21:04:51302 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Steve Anton2d8609c2018-01-24 00:38:46303 const std::string& transport_name) override;
304 bool IceRestartPending(const std::string& content_name) const override;
305 bool NeedsIceRestart(const std::string& content_name) const override;
306 bool GetSslRole(const std::string& content_name, rtc::SSLRole* role) override;
Mirko Bonadeie0bc8d22022-02-08 07:41:25307
Harald Alvestrand05e4d082019-12-03 13:04:21308 // Functions needed by DataChannelController
Harald Alvestrand5b84f382022-02-08 10:49:09309 void NoteDataAddedEvent() override { NoteUsageEvent(UsageEvent::DATA_ADDED); }
Harald Alvestrand05e4d082019-12-03 13:04:21310 // Returns the observer. Will crash on CHECK if the observer is removed.
Harald Alvestrand5b661302022-01-28 13:08:34311 PeerConnectionObserver* Observer() const override;
312 bool IsClosed() const override {
Harald Alvestrand05e4d082019-12-03 13:04:21313 RTC_DCHECK_RUN_ON(signaling_thread());
Tomas Gunnarsson2efb8a52021-04-01 14:26:57314 return !sdp_handler_ ||
315 sdp_handler_->signaling_state() == PeerConnectionInterface::kClosed;
Harald Alvestrand05e4d082019-12-03 13:04:21316 }
317 // Get current SSL role used by SCTP's underlying transport.
Tommi335d0842023-03-25 09:56:18318 absl::optional<rtc::SSLRole> GetSctpSslRole_n() override;
Tommid2afbaf2023-03-02 09:51:16319
320 void OnSctpDataChannelStateChanged(
Tommi56548982023-03-27 16:07:34321 int channel_id,
Tommid2afbaf2023-03-02 09:51:16322 DataChannelInterface::DataState state) override;
Harald Alvestrand05e4d082019-12-03 13:04:21323
Henrik Boströme574a312020-08-25 08:20:11324 bool ShouldFireNegotiationNeededEvent(uint32_t event_id) override;
325
Harald Alvestrandcdcfab02020-09-28 13:02:07326 // Functions needed by SdpOfferAnswerHandler
Henrik Boströmf7859892022-07-04 12:36:37327 LegacyStatsCollector* legacy_stats() override {
Harald Alvestrandcdcfab02020-09-28 13:02:07328 RTC_DCHECK_RUN_ON(signaling_thread());
Henrik Boströmf7859892022-07-04 12:36:37329 return legacy_stats_.get();
Harald Alvestrandcdcfab02020-09-28 13:02:07330 }
Harald Alvestrand5b661302022-01-28 13:08:34331 DataChannelController* data_channel_controller() override {
Harald Alvestrandcdcfab02020-09-28 13:02:07332 RTC_DCHECK_RUN_ON(signaling_thread());
333 return &data_channel_controller_;
334 }
Harald Alvestrand5b661302022-01-28 13:08:34335 bool dtls_enabled() const override {
Harald Alvestrandcdcfab02020-09-28 13:02:07336 RTC_DCHECK_RUN_ON(signaling_thread());
337 return dtls_enabled_;
338 }
Harald Alvestrand5b661302022-01-28 13:08:34339 const PeerConnectionInterface::RTCConfiguration* configuration()
340 const override {
Harald Alvestrandcdcfab02020-09-28 13:02:07341 RTC_DCHECK_RUN_ON(signaling_thread());
342 return &configuration_;
343 }
Harald Alvestrand5b661302022-01-28 13:08:34344 PeerConnectionMessageHandler* message_handler() override {
Harald Alvestrand1090e442020-10-05 07:01:09345 RTC_DCHECK_RUN_ON(signaling_thread());
346 return &message_handler_;
347 }
Harald Alvestrandcdcfab02020-09-28 13:02:07348
Harald Alvestrand5b661302022-01-28 13:08:34349 RtpTransmissionManager* rtp_manager() override { return rtp_manager_.get(); }
350 const RtpTransmissionManager* rtp_manager() const override {
Harald Alvestrande15fb152020-10-19 13:28:05351 return rtp_manager_.get();
352 }
Harald Alvestrand653429c2020-10-19 16:05:20353
Harald Alvestrandbc32c562022-02-09 12:08:47354 JsepTransportController* transport_controller_s() override {
355 RTC_DCHECK_RUN_ON(signaling_thread());
356 return transport_controller_copy_;
357 }
358 JsepTransportController* transport_controller_n() override {
359 RTC_DCHECK_RUN_ON(network_thread());
Harald Alvestrand653429c2020-10-19 16:05:20360 return transport_controller_.get();
361 }
Harald Alvestrand5b661302022-01-28 13:08:34362 cricket::PortAllocator* port_allocator() override {
363 return port_allocator_.get();
364 }
365 Call* call_ptr() override { return call_ptr_; }
Harald Alvestrand763f5a92020-10-22 10:39:40366
367 ConnectionContext* context() { return context_.get(); }
Harald Alvestrand5b661302022-01-28 13:08:34368 const PeerConnectionFactoryInterface::Options* options() const override {
Harald Alvestrand4da4a872020-11-04 10:34:21369 return &options_;
370 }
Harald Alvestrand5b661302022-01-28 13:08:34371 void SetIceConnectionState(IceConnectionState new_state) override;
372 void NoteUsageEvent(UsageEvent event) override;
Harald Alvestrand653429c2020-10-19 16:05:20373
Tomas Gunnarsson8cb97062021-02-08 17:57:04374 // Asynchronously adds a remote candidate on the network thread.
375 void AddRemoteCandidate(const std::string& mid,
Harald Alvestrand5b661302022-01-28 13:08:34376 const cricket::Candidate& candidate) override;
Tomas Gunnarsson8cb97062021-02-08 17:57:04377
Philipp Hancke54b925c2021-01-28 08:56:39378 // Report the UMA metric BundleUsage for the given remote description.
379 void ReportSdpBundleUsage(
Harald Alvestrand5b661302022-01-28 13:08:34380 const SessionDescriptionInterface& remote_description) override;
Philipp Hancke54b925c2021-01-28 08:56:39381
Philipp Hancke9799fe02022-07-06 07:26:41382 // Report several UMA metrics on establishing the connection.
383 void ReportFirstConnectUsageMetrics() RTC_RUN_ON(signaling_thread());
384
Harald Alvestrand653429c2020-10-19 16:05:20385 // Returns true if the PeerConnection is configured to use Unified Plan
386 // semantics for creating offers/answers and setting local/remote
387 // descriptions. If this is true the RtpTransceiver API will also be available
388 // to the user. If this is false, Plan B semantics are assumed.
389 // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once
390 // sufficient time has passed.
Harald Alvestrand5b661302022-01-28 13:08:34391 bool IsUnifiedPlan() const override {
Harald Alvestrand653429c2020-10-19 16:05:20392 RTC_DCHECK_RUN_ON(signaling_thread());
Harald Alvestrand62166932020-10-26 08:30:41393 return is_unified_plan_;
Harald Alvestrand653429c2020-10-19 16:05:20394 }
Henrik Boströmf8187e02021-04-26 19:04:26395 bool ValidateBundleSettings(
396 const cricket::SessionDescription* desc,
397 const std::map<std::string, const cricket::ContentGroup*>&
Harald Alvestrand5b661302022-01-28 13:08:34398 bundle_groups_by_mid) override;
Harald Alvestrand653429c2020-10-19 16:05:20399
Tommi840cf782023-10-21 14:47:56400 bool CreateDataChannelTransport(absl::string_view mid) override;
401 void DestroyDataChannelTransport(RTCError error) override;
Tomas Gunnarsson92eebef2021-02-10 12:05:44402
403 // Asynchronously calls SctpTransport::Start() on the network thread for
Artem Titov880fa812021-07-30 20:30:23404 // `sctp_mid()` if set. Called as part of setting the local description.
Tomas Gunnarsson92eebef2021-02-10 12:05:44405 void StartSctpTransport(int local_port,
406 int remote_port,
Harald Alvestrand5b661302022-01-28 13:08:34407 int max_message_size) override;
Harald Alvestrand653429c2020-10-19 16:05:20408
409 // Returns the CryptoOptions for this PeerConnection. This will always
410 // return the RTCConfiguration.crypto_options if set and will only default
411 // back to the PeerConnectionFactory settings if nothing was set.
Harald Alvestrand5b661302022-01-28 13:08:34412 CryptoOptions GetCryptoOptions() override;
Harald Alvestrand653429c2020-10-19 16:05:20413
414 // Internal implementation for AddTransceiver family of methods. If
Artem Titov880fa812021-07-30 20:30:23415 // `fire_callback` is set, fires OnRenegotiationNeeded callback if successful.
Harald Alvestrand653429c2020-10-19 16:05:20416 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
417 cricket::MediaType media_type,
418 rtc::scoped_refptr<MediaStreamTrackInterface> track,
419 const RtpTransceiverInit& init,
Harald Alvestrand5b661302022-01-28 13:08:34420 bool fire_callback = true) override;
Harald Alvestrand653429c2020-10-19 16:05:20421
Harald Alvestrand653429c2020-10-19 16:05:20422 // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
423 // this session.
Harald Alvestrand5b661302022-01-28 13:08:34424 bool SrtpRequired() const override;
Harald Alvestrand653429c2020-10-19 16:05:20425
Tommi840cf782023-10-21 14:47:56426 absl::optional<std::string> SetupDataChannelTransport_n(absl::string_view mid)
427 RTC_RUN_ON(network_thread());
428 void TeardownDataChannelTransport_n(RTCError error)
Tommib00d63c2023-04-12 17:49:53429 RTC_RUN_ON(network_thread());
Harald Alvestrande15fb152020-10-19 13:28:05430
Danil Chapovalov3bdb49b2023-11-30 07:59:39431 const FieldTrialsView& trials() const override { return env_.field_trials(); }
Harald Alvestrand35ba0c52022-05-05 07:37:41432
433 bool ConfiguredForMedia() const;
434
Harald Alvestrand05e4d082019-12-03 13:04:21435 // Functions made public for testing.
Harald Alvestrand19793842018-06-25 10:03:50436 void ReturnHistogramVeryQuicklyForTesting() {
Karl Wibergf73f7d62019-04-08 13:36:53437 RTC_DCHECK_RUN_ON(signaling_thread());
Harald Alvestrand19793842018-06-25 10:03:50438 return_histogram_very_quickly_ = true;
439 }
Harald Alvestrand7a1c7f72018-08-01 08:50:16440 void RequestUsagePatternReportForTesting();
Harald Alvestrand19793842018-06-25 10:03:50441
Tony Herre418bcf22024-06-17 15:28:40442 NetworkControllerInterface* GetNetworkController() override {
443 if (!worker_thread()->IsCurrent()) {
444 return worker_thread()->BlockingCall(
445 [this]() { return GetNetworkController(); });
446 }
447 RTC_DCHECK_RUN_ON(worker_thread());
448 RTC_DCHECK(call_);
449 return call_->GetTransportControllerSend()->GetNetworkController();
450 }
451
henrike@webrtc.org28e20752013-07-10 00:45:36452 protected:
Harald Alvestrand62166932020-10-26 08:30:41453 // Available for rtc::scoped_refptr creation
Danil Chapovalov3bdb49b2023-11-30 07:59:39454 PeerConnection(const Environment& env,
455 rtc::scoped_refptr<ConnectionContext> context,
Harald Alvestrand4da4a872020-11-04 10:34:21456 const PeerConnectionFactoryInterface::Options& options,
457 bool is_unified_plan,
Harald Alvestrand4da4a872020-11-04 10:34:21458 std::unique_ptr<Call> call,
Tommic3257d02021-02-10 17:40:08459 PeerConnectionDependencies& dependencies,
460 bool dtls_enabled);
Harald Alvestrand62166932020-10-26 08:30:41461
deadbeefa67696b2015-09-29 18:56:26462 ~PeerConnection() override;
henrike@webrtc.org28e20752013-07-10 00:45:36463
464 private:
Harald Alvestranda3dd7722020-11-27 08:05:42465 RTCError Initialize(
Harald Alvestrand62166932020-10-26 08:30:41466 const PeerConnectionInterface::RTCConfiguration& configuration,
467 PeerConnectionDependencies dependencies);
Harald Alvestrandbc32c562022-02-09 12:08:47468 JsepTransportController* InitializeTransportController_n(
Tommic3257d02021-02-10 17:40:08469 const RTCConfiguration& configuration,
470 const PeerConnectionDependencies& dependencies)
471 RTC_RUN_ON(network_thread());
Harald Alvestrand62166932020-10-26 08:30:41472
Steve Antonf9381f02017-12-14 18:23:57473 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
Karl Wiberga58e1692019-03-26 12:33:43474 FindTransceiverBySender(rtc::scoped_refptr<RtpSenderInterface> sender)
475 RTC_RUN_ON(signaling_thread());
Steve Antonf9381f02017-12-14 18:23:57476
Jonas Olsson635474e2018-10-18 13:58:17477 void SetStandardizedIceConnectionState(
Karl Wiberg744310f2019-02-14 09:18:56478 PeerConnectionInterface::IceConnectionState new_state)
479 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 13:58:17480 void SetConnectionState(
Karl Wiberg744310f2019-02-14 09:18:56481 PeerConnectionInterface::PeerConnectionState new_state)
482 RTC_RUN_ON(signaling_thread());
Jonas Olsson635474e2018-10-18 13:58:17483
Eldar Relloda13ea22019-06-01 09:23:43484 // Called any time the IceGatheringState changes.
Karl Wiberg744310f2019-02-14 09:18:56485 void OnIceGatheringChange(IceGatheringState new_state)
486 RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 18:21:57487 // New ICE candidate has been gathered.
Karl Wiberg744310f2019-02-14 09:18:56488 void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate)
489 RTC_RUN_ON(signaling_thread());
Eldar Relloda13ea22019-06-01 09:23:43490 // Gathering of an ICE candidate failed.
Eldar Rello0095d372019-12-02 20:22:07491 void OnIceCandidateError(const std::string& address,
492 int port,
Eldar Relloda13ea22019-06-01 09:23:43493 const std::string& url,
494 int error_code,
495 const std::string& error_text)
496 RTC_RUN_ON(signaling_thread());
Steve Antonba818672017-11-06 18:21:57497 // Some local ICE candidates have been removed.
Karl Wiberg744310f2019-02-14 09:18:56498 void OnIceCandidatesRemoved(const std::vector<cricket::Candidate>& candidates)
499 RTC_RUN_ON(signaling_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36500
Alex Drake00c7ecf2019-08-06 17:54:47501 void OnSelectedCandidatePairChanged(
502 const cricket::CandidatePairChangeEvent& event)
503 RTC_RUN_ON(signaling_thread());
504
Steve Anton52d86772018-02-20 23:48:12505 void OnNegotiationNeeded();
506
Taylor Brandstettera1c30352016-05-13 15:15:11507 // Called when first configuring the port allocator.
Karl Wibergfb3be392019-03-22 13:13:22508 struct InitializePortAllocatorResult {
509 bool enable_ipv6;
510 };
511 InitializePortAllocatorResult InitializePortAllocator_n(
Harald Alvestrandb2a74782018-06-28 11:54:07512 const cricket::ServerAddresses& stun_servers,
513 const std::vector<cricket::RelayServerConfig>& turn_servers,
514 const RTCConfiguration& configuration);
deadbeef293e9262017-01-11 20:28:30515 // Called when SetConfiguration is called to apply the supported subset
516 // of the configuration on the network thread.
517 bool ReconfigurePortAllocator_n(
518 const cricket::ServerAddresses& stun_servers,
519 const std::vector<cricket::RelayServerConfig>& turn_servers,
520 IceTransportsType type,
521 int candidate_pool_size,
Honghai Zhangf8998cf2019-10-14 18:27:50522 PortPrunePolicy turn_port_prune_policy,
Harald Alvestranda6544372023-11-13 09:33:56523 TurnCustomizer* turn_customizer,
Karl Wiberg739506e2019-04-03 09:37:28524 absl::optional<int> stun_candidate_keepalive_interval,
525 bool have_local_description);
Taylor Brandstettera1c30352016-05-13 15:15:11526
Elad Alon99c3fe52017-10-13 14:29:40527 // Starts output of an RTC event log to the given output object.
ivoc14d5dbe2016-07-04 14:06:55528 // This function should only be called from the worker thread.
Bjorn Tereliusde939432017-11-20 16:38:14529 bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output,
530 int64_t output_period_ms);
Elad Alon99c3fe52017-10-13 14:29:40531
Elad Alonacb24172017-10-06 12:32:13532 // Stops recording an RTC event log.
ivoc14d5dbe2016-07-04 14:06:55533 // This function should only be called from the worker thread.
534 void StopRtcEventLog_w();
535
Artem Titov880fa812021-07-30 20:30:23536 // Returns true and the TransportInfo of the given `content_name`
537 // from `description`. Returns false if it's not available.
Steve Anton75737c02017-11-06 18:37:17538 static bool GetTransportDescription(
539 const cricket::SessionDescription* description,
540 const std::string& content_name,
541 cricket::TransportDescription* info);
542
Steve Anton75737c02017-11-06 18:37:17543 // Returns the media index for a local ice candidate given the content name.
544 // Returns false if the local session description does not have a media
Artem Titov880fa812021-07-30 20:30:23545 // content called `content_name`.
Steve Anton75737c02017-11-06 18:37:17546 bool GetLocalCandidateMediaIndex(const std::string& content_name,
Karl Wiberg739506e2019-04-03 09:37:28547 int* sdp_mline_index)
548 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 18:37:17549
Zhi Huange830e682018-03-30 17:48:35550 // JsepTransportController signal handlers.
Karl Wiberg744310f2019-02-14 09:18:56551 void OnTransportControllerConnectionState(cricket::IceConnectionState state)
552 RTC_RUN_ON(signaling_thread());
553 void OnTransportControllerGatheringState(cricket::IceGatheringState state)
554 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 18:37:17555 void OnTransportControllerCandidatesGathered(
556 const std::string& transport_name,
Karl Wiberg744310f2019-02-14 09:18:56557 const std::vector<cricket::Candidate>& candidates)
558 RTC_RUN_ON(signaling_thread());
Eldar Relloda13ea22019-06-01 09:23:43559 void OnTransportControllerCandidateError(
560 const cricket::IceCandidateErrorEvent& event)
561 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 18:37:17562 void OnTransportControllerCandidatesRemoved(
Karl Wiberg744310f2019-02-14 09:18:56563 const std::vector<cricket::Candidate>& candidates)
564 RTC_RUN_ON(signaling_thread());
Alex Drake00c7ecf2019-08-06 17:54:47565 void OnTransportControllerCandidateChanged(
566 const cricket::CandidatePairChangeEvent& event)
567 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 18:37:17568 void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error);
569
Steve Anton75737c02017-11-06 18:37:17570 // Invoked when TransportController connection completion is signaled.
571 // Reports stats for all transports in use.
Tommidba22d32023-06-01 14:08:52572 void ReportTransportStats(std::vector<RtpTransceiverProxyRefPtr> transceivers)
573 RTC_RUN_ON(network_thread());
Steve Anton75737c02017-11-06 18:37:17574
575 // Gather the usage of IPv4/IPv6 as best connection.
Tommic3257d02021-02-10 17:40:08576 static void ReportBestConnectionState(const cricket::TransportStats& stats);
Steve Anton75737c02017-11-06 18:37:17577
Tommic3257d02021-02-10 17:40:08578 static void ReportNegotiatedCiphers(
579 bool dtls_enabled,
580 const cricket::TransportStats& stats,
581 const std::set<cricket::MediaType>& media_types);
Qingsi Wang1ba5dec2019-08-19 18:57:17582 void ReportIceCandidateCollected(const cricket::Candidate& candidate)
583 RTC_RUN_ON(signaling_thread());
Steve Anton75737c02017-11-06 18:37:17584
Karl Wiberg744310f2019-02-14 09:18:56585 void ReportUsagePattern() const RTC_RUN_ON(signaling_thread());
Harald Alvestrand8ebba742018-05-31 12:00:34586
Tomas Gunnarsson8cb97062021-02-08 17:57:04587 void ReportRemoteIceCandidateAdded(const cricket::Candidate& candidate);
588
Zhi Huang365381f2018-04-13 23:44:34589 // JsepTransportController::Observer override.
Taylor Brandstettercbaa2542018-04-16 23:42:14590 //
Artem Titov880fa812021-07-30 20:30:23591 // Called by `transport_controller_` when processing transport information
Taylor Brandstettercbaa2542018-04-16 23:42:14592 // from a session description, and the mapping from m= sections to transports
593 // changed (as a result of BUNDLE negotiation, or m= sections being
594 // rejected).
Bjorn A Mellemb689af42019-08-21 17:44:59595 bool OnTransportChanged(
596 const std::string& mid,
597 RtpTransportInternal* rtp_transport,
598 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Bjorn A Mellembc3eebc2019-09-23 21:53:54599 DataChannelTransportInterface* data_channel_transport) override;
Zhi Huange830e682018-03-30 17:48:35600
Henrik Boström46053e42023-01-20 12:18:53601 void SetSctpTransportName(std::string sctp_transport_name);
602
Tomas Gunnarsson1e40a0c2020-09-28 08:39:31603 std::function<void(const rtc::CopyOnWriteBuffer& packet,
604 int64_t packet_time_us)>
605 InitializeRtcpCallback();
606
Per Ke1e94ad2023-03-30 14:53:59607 std::function<void(const RtpPacketReceived& parsed_packet)>
608 InitializeUnDemuxablePacketHandler();
609
Danil Chapovalov3bdb49b2023-11-30 07:59:39610 const Environment env_;
Harald Alvestranda39689c2020-10-15 08:34:31611 const rtc::scoped_refptr<ConnectionContext> context_;
Harald Alvestrand4da4a872020-11-04 10:34:21612 const PeerConnectionFactoryInterface::Options options_;
Karl Wiberg744310f2019-02-14 09:18:56613 PeerConnectionObserver* observer_ RTC_GUARDED_BY(signaling_thread()) =
614 nullptr;
terelius33860252017-05-13 06:37:18615
Harald Alvestrand62166932020-10-26 08:30:41616 const bool is_unified_plan_;
617
Karl Wiberg8d2e2282019-02-17 12:00:07618 IceConnectionState ice_connection_state_ RTC_GUARDED_BY(signaling_thread()) =
619 kIceConnectionNew;
620 PeerConnectionInterface::IceConnectionState standardized_ice_connection_state_
621 RTC_GUARDED_BY(signaling_thread()) = kIceConnectionNew;
622 PeerConnectionInterface::PeerConnectionState connection_state_
623 RTC_GUARDED_BY(signaling_thread()) = PeerConnectionState::kNew;
Jonas Olsson635474e2018-10-18 13:58:17624
Karl Wiberg8d2e2282019-02-17 12:00:07625 IceGatheringState ice_gathering_state_ RTC_GUARDED_BY(signaling_thread()) =
626 kIceGatheringNew;
Karl Wiberg5966c502019-02-21 22:55:09627 PeerConnectionInterface::RTCConfiguration configuration_
628 RTC_GUARDED_BY(signaling_thread());
629
Harald Alvestrand0ccfbd22021-04-08 07:25:04630 const std::unique_ptr<AsyncDnsResolverFactoryInterface>
631 async_dns_resolver_factory_;
Karl Wibergfb3be392019-03-22 13:13:22632 std::unique_ptr<cricket::PortAllocator>
633 port_allocator_; // TODO(bugs.webrtc.org/9987): Accessed on both
634 // signaling and network thread.
Harald Alvestranda6544372023-11-13 09:33:56635 const std::unique_ptr<IceTransportFactory>
Qingsi Wang25ec8882019-11-15 20:33:05636 ice_transport_factory_; // TODO(bugs.webrtc.org/9987): Accessed on the
637 // signaling thread but the underlying raw
638 // pointer is given to
Artem Titov880fa812021-07-30 20:30:23639 // `jsep_transport_controller_` and used on the
Qingsi Wang25ec8882019-11-15 20:33:05640 // network thread.
Harald Alvestrandf598e492020-11-04 05:54:10641 const std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier_
642 RTC_GUARDED_BY(network_thread());
deadbeefab9b2d12015-10-14 18:33:11643
Karl Wibergac025892019-03-26 12:08:37644 // The unique_ptr belongs to the worker thread, but the Call object manages
645 // its own thread safety.
Karl Wiberg6cab5c82019-03-26 08:57:01646 std::unique_ptr<Call> call_ RTC_GUARDED_BY(worker_thread());
Tomas Gunnarsson92eebef2021-02-10 12:05:44647 ScopedTaskSafety signaling_thread_safety_;
648 rtc::scoped_refptr<PendingTaskSafetyFlag> network_thread_safety_;
Tommic3257d02021-02-10 17:40:08649 rtc::scoped_refptr<PendingTaskSafetyFlag> worker_thread_safety_;
Sebastian Jansson1b83a9e2019-09-18 16:22:12650
Karl Wiberg6cab5c82019-03-26 08:57:01651 // Points to the same thing as `call_`. Since it's const, we may read the
Karl Wibergac025892019-03-26 12:08:37652 // pointer from any thread.
Tomas Gunnarsson1e40a0c2020-09-28 08:39:31653 // TODO(bugs.webrtc.org/11992): Remove this workaround (and potential dangling
654 // pointer).
Karl Wibergac025892019-03-26 12:08:37655 Call* const call_ptr_;
Karl Wiberg6cab5c82019-03-26 08:57:01656
Henrik Boströmf7859892022-07-04 12:36:37657 std::unique_ptr<LegacyStatsCollector> legacy_stats_
Karl Wiberg6cab5c82019-03-26 08:57:01658 RTC_GUARDED_BY(signaling_thread()); // A pointer is passed to senders_
659 rtc::scoped_refptr<RTCStatsCollector> stats_collector_
660 RTC_GUARDED_BY(signaling_thread());
Karl Wiberg2cc368f2019-04-02 09:31:56661
Tomas Gunnarsson97a387d2021-03-29 19:04:29662 const std::string session_id_;
Steve Anton75737c02017-11-06 18:37:17663
Harald Alvestrandbc32c562022-02-09 12:08:47664 // The transport controller is set and used on the network thread.
665 // Some functions pass the value of the transport_controller_ pointer
666 // around as arguments while running on the signaling thread; these
667 // use the transport_controller_copy.
668 std::unique_ptr<JsepTransportController> transport_controller_
669 RTC_GUARDED_BY(network_thread());
670 JsepTransportController* transport_controller_copy_
671 RTC_GUARDED_BY(signaling_thread()) = nullptr;
Steve Anton75737c02017-11-06 18:37:17672
Artem Titov880fa812021-07-30 20:30:23673 // `sctp_mid_` is the content name (MID) in SDP.
Bjorn A Mellemb689af42019-08-21 17:44:59674 // Note: this is used as the data channel MID by both SCTP and data channel
675 // transports. It is set when either transport is initialized and unset when
676 // both transports are deleted.
Harald Alvestrand7a829a82020-02-12 06:38:21677 // There is one copy on the signaling thread and another copy on the
678 // networking thread. Changes are always initiated from the signaling
679 // thread, but applied first on the networking thread via an invoke().
680 absl::optional<std::string> sctp_mid_s_ RTC_GUARDED_BY(signaling_thread());
681 absl::optional<std::string> sctp_mid_n_ RTC_GUARDED_BY(network_thread());
Tomas Gunnarsson92eebef2021-02-10 12:05:44682 std::string sctp_transport_name_s_ RTC_GUARDED_BY(signaling_thread());
Karl Wiberg2cc368f2019-04-02 09:31:56683
Harald Alvestrand9cd199d2020-10-27 07:10:43684 // The machinery for handling offers and answers. Const after initialization.
685 std::unique_ptr<SdpOfferAnswerHandler> sdp_handler_
Harald Alvestrand00c62ed2021-10-20 08:52:12686 RTC_GUARDED_BY(signaling_thread()) RTC_PT_GUARDED_BY(signaling_thread());
Bjorn Mellem175aa2e2018-11-08 19:23:22687
Tommic3257d02021-02-10 17:40:08688 const bool dtls_enabled_;
Steve Anton75737c02017-11-06 18:37:17689
Harald Alvestrand44d0dff2020-10-09 05:43:53690 UsagePattern usage_pattern_ RTC_GUARDED_BY(signaling_thread());
Karl Wibergf73f7d62019-04-08 13:36:53691 bool return_histogram_very_quickly_ RTC_GUARDED_BY(signaling_thread()) =
692 false;
Amit Hilbuchbcd39d42019-01-26 01:13:56693
Harald Alvestrand00c62ed2021-10-20 08:52:12694 // The DataChannelController is accessed from both the signaling thread
695 // and networking thread. It is a thread-aware object.
Harald Alvestrand00cf34c2019-12-02 08:56:02696 DataChannelController data_channel_controller_;
Harald Alvestrand1090e442020-10-05 07:01:09697
698 // Machinery for handling messages posted to oneself
Harald Alvestrand00c62ed2021-10-20 08:52:12699 PeerConnectionMessageHandler message_handler_
700 RTC_GUARDED_BY(signaling_thread());
Harald Alvestrande15fb152020-10-19 13:28:05701
702 // Administration of senders, receivers and transceivers
703 // Accessed on both signaling and network thread. Const after Initialize().
704 std::unique_ptr<RtpTransmissionManager> rtp_manager_;
Lahiru Ginnaliya Gamathige70f9e242021-01-28 07:32:46705
Philipp Hanckecd0373f2021-02-24 10:04:30706 // Did the connectionState ever change to `connected`?
707 // Used to gather metrics only the first such state change.
708 bool was_ever_connected_ RTC_GUARDED_BY(signaling_thread()) = false;
Harald Alvestrand00c62ed2021-10-20 08:52:12709
710 // This variable needs to be the last one in the class.
711 rtc::WeakPtrFactory<PeerConnection> weak_factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36712};
713
714} // namespace webrtc
715
Steve Anton10542f22019-01-11 17:11:00716#endif // PC_PEER_CONNECTION_H_