henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_PEER_CONNECTION_H_ |
| 12 | #define PC_PEER_CONNECTION_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 14 | #include <stdint.h> |
Artem Titov | d15a575 | 2021-02-10 14:31:24 +0100 | [diff] [blame] | 15 | |
Tomas Gunnarsson | 1e40a0c | 2020-09-28 10:39:31 +0200 | [diff] [blame] | 16 | #include <functional> |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 17 | #include <map> |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 18 | #include <memory> |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 19 | #include <set> |
| 20 | #include <string> |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 21 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 23 | #include "absl/types/optional.h" |
| 24 | #include "api/adaptation/resource.h" |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 25 | #include "api/async_dns_resolver.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 26 | #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" |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 30 | #include "api/field_trials_view.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 31 | #include "api/ice_transport_interface.h" |
| 32 | #include "api/jsep.h" |
| 33 | #include "api/media_stream_interface.h" |
| 34 | #include "api/media_types.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 35 | #include "api/peer_connection_interface.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 36 | #include "api/rtc_error.h" |
| 37 | #include "api/rtc_event_log/rtc_event_log.h" |
| 38 | #include "api/rtc_event_log_output.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 39 | #include "api/rtp_receiver_interface.h" |
| 40 | #include "api/rtp_sender_interface.h" |
| 41 | #include "api/rtp_transceiver_interface.h" |
| 42 | #include "api/scoped_refptr.h" |
| 43 | #include "api/sctp_transport_interface.h" |
Artem Titov | d15a575 | 2021-02-10 14:31:24 +0100 | [diff] [blame] | 44 | #include "api/sequence_checker.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 45 | #include "api/set_local_description_observer_interface.h" |
| 46 | #include "api/set_remote_description_observer_interface.h" |
| 47 | #include "api/stats/rtc_stats_collector_callback.h" |
| 48 | #include "api/transport/bitrate_settings.h" |
Niels Möller | 65f17ca | 2019-09-12 13:59:36 +0200 | [diff] [blame] | 49 | #include "api/transport/data_channel_transport_interface.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 50 | #include "api/transport/enums.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 51 | #include "api/turn_customizer.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 52 | #include "call/call.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 53 | #include "p2p/base/ice_transport_internal.h" |
| 54 | #include "p2p/base/port.h" |
| 55 | #include "p2p/base/port_allocator.h" |
| 56 | #include "p2p/base/transport_description.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 57 | #include "pc/channel_interface.h" |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 +0000 | [diff] [blame] | 58 | #include "pc/connection_context.h" |
Harald Alvestrand | 05e4d08 | 2019-12-03 14:04:21 +0100 | [diff] [blame] | 59 | #include "pc/data_channel_controller.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 60 | #include "pc/data_channel_utils.h" |
| 61 | #include "pc/dtls_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 62 | #include "pc/jsep_transport_controller.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 63 | #include "pc/peer_connection_internal.h" |
Harald Alvestrand | 1090e44 | 2020-10-05 07:01:09 +0000 | [diff] [blame] | 64 | #include "pc/peer_connection_message_handler.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 65 | #include "pc/rtc_stats_collector.h" |
| 66 | #include "pc/rtp_transceiver.h" |
Harald Alvestrand | e15fb15 | 2020-10-19 13:28:05 +0000 | [diff] [blame] | 67 | #include "pc/rtp_transmission_manager.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 68 | #include "pc/rtp_transport_internal.h" |
| 69 | #include "pc/sctp_data_channel.h" |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 70 | #include "pc/sdp_offer_answer.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 71 | #include "pc/session_description.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 72 | #include "pc/stats_collector.h" |
Harald Alvestrand | 38b768c | 2020-09-29 11:54:05 +0000 | [diff] [blame] | 73 | #include "pc/transceiver_list.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 74 | #include "pc/transport_stats.h" |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 75 | #include "pc/usage_pattern.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 76 | #include "rtc_base/checks.h" |
| 77 | #include "rtc_base/copy_on_write_buffer.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 78 | #include "rtc_base/rtc_certificate.h" |
| 79 | #include "rtc_base/ssl_certificate.h" |
| 80 | #include "rtc_base/ssl_stream_adapter.h" |
Tomas Gunnarsson | 1e40a0c | 2020-09-28 10:39:31 +0200 | [diff] [blame] | 81 | #include "rtc_base/task_utils/pending_task_safety_flag.h" |
Harald Alvestrand | 1f7eab6 | 2020-10-18 16:51:47 +0000 | [diff] [blame] | 82 | #include "rtc_base/third_party/sigslot/sigslot.h" |
| 83 | #include "rtc_base/thread.h" |
| 84 | #include "rtc_base/thread_annotations.h" |
Harald Alvestrand | 8546666 | 2021-04-19 21:21:36 +0000 | [diff] [blame] | 85 | #include "rtc_base/weak_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | |
Harald Alvestrand | 9e334b7 | 2022-05-04 13:38:31 +0000 | [diff] [blame] | 87 | namespace cricket { |
| 88 | class ChannelManager; |
| 89 | } |
| 90 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 93 | // PeerConnection is the implementation of the PeerConnection object as defined |
| 94 | // by the PeerConnectionInterface API surface. |
| 95 | // The class currently is solely responsible for the following: |
| 96 | // - Managing the session state machine (signaling state). |
| 97 | // - Creating and initializing lower-level objects, like PortAllocator and |
| 98 | // BaseChannels. |
| 99 | // - Owning and managing the life cycle of the RtpSender/RtpReceiver and track |
| 100 | // objects. |
| 101 | // - Tracking the current and pending local/remote session descriptions. |
| 102 | // The class currently is jointly responsible for the following: |
| 103 | // - Parsing and interpreting SDP. |
| 104 | // - Generating offers and answers based on the current state. |
| 105 | // - The ICE state machine. |
| 106 | // - Generating stats. |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 107 | class PeerConnection : public PeerConnectionInternal, |
Harald Alvestrand | 5b84f38 | 2022-02-08 10:49:09 +0000 | [diff] [blame] | 108 | public JsepTransportController::Observer { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | public: |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 110 | // Creates a PeerConnection and initializes it with the given values. |
| 111 | // If the initialization fails, the function releases the PeerConnection |
| 112 | // and returns nullptr. |
| 113 | // |
| 114 | // Note that the function takes ownership of dependencies, and will |
| 115 | // either use them or release them, whether it succeeds or fails. |
Harald Alvestrand | a3dd772 | 2020-11-27 08:05:42 +0000 | [diff] [blame] | 116 | static RTCErrorOr<rtc::scoped_refptr<PeerConnection>> Create( |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 117 | rtc::scoped_refptr<ConnectionContext> context, |
Harald Alvestrand | 4da4a87 | 2020-11-04 10:34:21 +0000 | [diff] [blame] | 118 | const PeerConnectionFactoryInterface::Options& options, |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 119 | std::unique_ptr<RtcEventLog> event_log, |
| 120 | std::unique_ptr<Call> call, |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 121 | const PeerConnectionInterface::RTCConfiguration& configuration, |
Benjamin Wright | cab5888 | 2018-05-02 15:12:47 -0700 | [diff] [blame] | 122 | PeerConnectionDependencies dependencies); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 123 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 124 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override; |
| 125 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override; |
| 126 | bool AddStream(MediaStreamInterface* local_stream) override; |
| 127 | void RemoveStream(MediaStreamInterface* local_stream) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 129 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack( |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 130 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 131 | const std::vector<std::string>& stream_ids) override; |
Harald Alvestrand | 09a0d01 | 2022-01-04 19:42:07 +0000 | [diff] [blame] | 132 | RTCError RemoveTrackOrError( |
Steve Anton | 24db573 | 2018-07-23 10:27:33 -0700 | [diff] [blame] | 133 | rtc::scoped_refptr<RtpSenderInterface> sender) override; |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 134 | |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 135 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 136 | rtc::scoped_refptr<MediaStreamTrackInterface> track) override; |
| 137 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 138 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 139 | const RtpTransceiverInit& init) override; |
| 140 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 141 | cricket::MediaType media_type) override; |
| 142 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 143 | cricket::MediaType media_type, |
| 144 | const RtpTransceiverInit& init) override; |
| 145 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 146 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 147 | const std::string& kind, |
| 148 | const std::string& stream_id) override; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 149 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 150 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 151 | const override; |
| 152 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 153 | const override; |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 154 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers() |
| 155 | const override; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 156 | |
Harald Alvestrand | a9af50f | 2021-05-21 13:33:51 +0000 | [diff] [blame] | 157 | RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>> CreateDataChannelOrError( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 158 | const std::string& label, |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 159 | const DataChannelInit* config) override; |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 160 | // WARNING: LEGACY. See peerconnectioninterface.h |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 161 | bool GetStats(StatsObserver* observer, |
| 162 | webrtc::MediaStreamTrackInterface* track, |
| 163 | StatsOutputLevel level) override; |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 164 | // Spec-complaint GetStats(). See peerconnectioninterface.h |
hbos | 74e1a4f | 2016-09-15 23:33:01 -0700 | [diff] [blame] | 165 | void GetStats(RTCStatsCollectorCallback* callback) override; |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 166 | void GetStats( |
| 167 | rtc::scoped_refptr<RtpSenderInterface> selector, |
| 168 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override; |
| 169 | void GetStats( |
| 170 | rtc::scoped_refptr<RtpReceiverInterface> selector, |
| 171 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override; |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 172 | void ClearStatsCache() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 173 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 174 | SignalingState signaling_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 175 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 176 | IceConnectionState ice_connection_state() override; |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 177 | IceConnectionState ice_connection_state_internal() override { |
| 178 | return ice_connection_state(); |
| 179 | } |
Jonas Olsson | 1204690 | 2018-12-06 11:25:14 +0100 | [diff] [blame] | 180 | IceConnectionState standardized_ice_connection_state() override; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 181 | PeerConnectionState peer_connection_state() override; |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 182 | IceGatheringState ice_gathering_state() override; |
Harald Alvestrand | 61f74d9 | 2020-03-02 11:20:00 +0100 | [diff] [blame] | 183 | absl::optional<bool> can_trickle_ice_candidates() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 184 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 185 | const SessionDescriptionInterface* local_description() const override; |
| 186 | const SessionDescriptionInterface* remote_description() const override; |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 187 | const SessionDescriptionInterface* current_local_description() const override; |
| 188 | const SessionDescriptionInterface* current_remote_description() |
| 189 | const override; |
| 190 | const SessionDescriptionInterface* pending_local_description() const override; |
| 191 | const SessionDescriptionInterface* pending_remote_description() |
| 192 | const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 193 | |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 194 | void RestartIce() override; |
| 195 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 196 | // JSEP01 |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 197 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 198 | const RTCOfferAnswerOptions& options) override; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 199 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 200 | const RTCOfferAnswerOptions& options) override; |
Henrik Boström | 831ae4e | 2020-07-29 12:04:00 +0200 | [diff] [blame] | 201 | |
| 202 | void SetLocalDescription( |
| 203 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 204 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer) |
| 205 | override; |
| 206 | void SetLocalDescription( |
| 207 | rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer) |
| 208 | override; |
| 209 | // TODO(https://crbug.com/webrtc/11798): Delete these methods in favor of the |
| 210 | // ones taking SetLocalDescriptionObserverInterface as argument. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 211 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 212 | SessionDescriptionInterface* desc) override; |
Henrik Boström | 4e19670 | 2019-10-30 10:35:50 +0100 | [diff] [blame] | 213 | void SetLocalDescription(SetSessionDescriptionObserver* observer) override; |
Henrik Boström | 831ae4e | 2020-07-29 12:04:00 +0200 | [diff] [blame] | 214 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 215 | void SetRemoteDescription( |
| 216 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 217 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) |
| 218 | override; |
Henrik Boström | 831ae4e | 2020-07-29 12:04:00 +0200 | [diff] [blame] | 219 | // TODO(https://crbug.com/webrtc/11798): Delete this methods in favor of the |
| 220 | // ones taking SetRemoteDescriptionObserverInterface as argument. |
| 221 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 222 | SessionDescriptionInterface* desc) override; |
| 223 | |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 224 | PeerConnectionInterface::RTCConfiguration GetConfiguration() override; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 225 | RTCError SetConfiguration( |
| 226 | const PeerConnectionInterface::RTCConfiguration& configuration) override; |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 227 | bool AddIceCandidate(const IceCandidateInterface* candidate) override; |
Henrik Boström | ee6f4f6 | 2019-11-06 12:36:12 +0100 | [diff] [blame] | 228 | void AddIceCandidate(std::unique_ptr<IceCandidateInterface> candidate, |
| 229 | std::function<void(RTCError)> callback) override; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 230 | bool RemoveIceCandidates( |
| 231 | const std::vector<cricket::Candidate>& candidates) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | |
Niels Möller | 0c4f7be | 2018-05-07 14:01:37 +0200 | [diff] [blame] | 233 | RTCError SetBitrate(const BitrateSettings& bitrate) override; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 234 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 235 | void SetAudioPlayout(bool playout) override; |
| 236 | void SetAudioRecording(bool recording) override; |
| 237 | |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 238 | rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid( |
| 239 | const std::string& mid) override; |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 240 | rtc::scoped_refptr<DtlsTransport> LookupDtlsTransportByMidInternal( |
| 241 | const std::string& mid); |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 242 | |
Harald Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 243 | rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const override; |
| 244 | |
Henrik Boström | 4c1e7cc | 2020-06-11 12:26:53 +0200 | [diff] [blame] | 245 | void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) override; |
| 246 | |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 247 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output, |
| 248 | int64_t output_period_ms) override; |
Niels Möller | f00ca1a | 2019-05-10 11:33:12 +0200 | [diff] [blame] | 249 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override; |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 250 | void StopRtcEventLog() override; |
| 251 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 252 | void Close() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | |
Taylor Brandstetter | c88fe70 | 2020-08-03 16:36:16 -0700 | [diff] [blame] | 254 | rtc::Thread* signaling_thread() const final { |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 +0000 | [diff] [blame] | 255 | return context_->signaling_thread(); |
Taylor Brandstetter | c88fe70 | 2020-08-03 16:36:16 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Karl Wiberg | 4ae6347 | 2019-02-22 00:57:06 +0100 | [diff] [blame] | 258 | rtc::Thread* network_thread() const final { |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 +0000 | [diff] [blame] | 259 | return context_->network_thread(); |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 260 | } |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 +0000 | [diff] [blame] | 261 | rtc::Thread* worker_thread() const final { return context_->worker_thread(); } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 262 | |
Karl Wiberg | a58e169 | 2019-03-26 13:33:43 +0100 | [diff] [blame] | 263 | std::string session_id() const override { |
Karl Wiberg | a58e169 | 2019-03-26 13:33:43 +0100 | [diff] [blame] | 264 | return session_id_; |
| 265 | } |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 266 | |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 267 | bool initial_offerer() const override { |
Karl Wiberg | 2cc368f | 2019-04-02 11:31:56 +0200 | [diff] [blame] | 268 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Harald Alvestrand | bc32c56 | 2022-02-09 12:08:47 +0000 | [diff] [blame] | 269 | return sdp_handler_->initial_offerer(); |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 270 | } |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 271 | |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 272 | std::vector< |
| 273 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 274 | GetTransceiversInternal() const override { |
Karl Wiberg | a58e169 | 2019-03-26 13:33:43 +0100 | [diff] [blame] | 275 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Harald Alvestrand | e15fb15 | 2020-10-19 13:28:05 +0000 | [diff] [blame] | 276 | return rtp_manager()->transceivers()->List(); |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Mirko Bonadei | e0bc8d2 | 2022-02-08 07:41:25 +0000 | [diff] [blame] | 279 | sigslot::signal1<SctpDataChannel*>& SignalSctpDataChannelCreated() override { |
| 280 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 281 | return data_channel_controller_.SignalSctpDataChannelCreated(); |
| 282 | } |
| 283 | |
Taylor Brandstetter | 3a034e1 | 2020-07-09 15:32:34 -0700 | [diff] [blame] | 284 | std::vector<DataChannelStats> GetDataChannelStats() const override; |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 285 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 286 | absl::optional<std::string> sctp_transport_name() const override; |
Tomas Gunnarsson | bfd9ba8 | 2021-04-18 11:55:57 +0200 | [diff] [blame] | 287 | absl::optional<std::string> sctp_mid() const override; |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 288 | |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 289 | cricket::CandidateStatsList GetPooledCandidateStats() const override; |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 290 | std::map<std::string, cricket::TransportStats> GetTransportStatsByNames( |
| 291 | const std::set<std::string>& transport_names) override; |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 292 | Call::Stats GetCallStats() override; |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 293 | |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 294 | bool GetLocalCertificate( |
| 295 | const std::string& transport_name, |
| 296 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override; |
Taylor Brandstetter | c392866 | 2018-02-23 13:04:51 -0800 | [diff] [blame] | 297 | std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 298 | const std::string& transport_name) override; |
| 299 | bool IceRestartPending(const std::string& content_name) const override; |
| 300 | bool NeedsIceRestart(const std::string& content_name) const override; |
| 301 | bool GetSslRole(const std::string& content_name, rtc::SSLRole* role) override; |
Mirko Bonadei | e0bc8d2 | 2022-02-08 07:41:25 +0000 | [diff] [blame] | 302 | |
Harald Alvestrand | 05e4d08 | 2019-12-03 14:04:21 +0100 | [diff] [blame] | 303 | // Functions needed by DataChannelController |
Harald Alvestrand | 5b84f38 | 2022-02-08 10:49:09 +0000 | [diff] [blame] | 304 | void NoteDataAddedEvent() override { NoteUsageEvent(UsageEvent::DATA_ADDED); } |
Harald Alvestrand | 05e4d08 | 2019-12-03 14:04:21 +0100 | [diff] [blame] | 305 | // Returns the observer. Will crash on CHECK if the observer is removed. |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 306 | PeerConnectionObserver* Observer() const override; |
| 307 | bool IsClosed() const override { |
Harald Alvestrand | 05e4d08 | 2019-12-03 14:04:21 +0100 | [diff] [blame] | 308 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Tomas Gunnarsson | 2efb8a5 | 2021-04-01 16:26:57 +0200 | [diff] [blame] | 309 | return !sdp_handler_ || |
| 310 | sdp_handler_->signaling_state() == PeerConnectionInterface::kClosed; |
Harald Alvestrand | 05e4d08 | 2019-12-03 14:04:21 +0100 | [diff] [blame] | 311 | } |
| 312 | // Get current SSL role used by SCTP's underlying transport. |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 313 | bool GetSctpSslRole(rtc::SSLRole* role) override; |
Harald Alvestrand | 05e4d08 | 2019-12-03 14:04:21 +0100 | [diff] [blame] | 314 | // Handler for the "channel closed" signal |
Harald Alvestrand | 5b84f38 | 2022-02-08 10:49:09 +0000 | [diff] [blame] | 315 | void OnSctpDataChannelClosed(DataChannelInterface* channel) override; |
Harald Alvestrand | 05e4d08 | 2019-12-03 14:04:21 +0100 | [diff] [blame] | 316 | |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 317 | bool ShouldFireNegotiationNeededEvent(uint32_t event_id) override; |
| 318 | |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 319 | // Functions needed by SdpOfferAnswerHandler |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 320 | StatsCollector* stats() override { |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 321 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 322 | return stats_.get(); |
| 323 | } |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 324 | DataChannelController* data_channel_controller() override { |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 325 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 326 | return &data_channel_controller_; |
| 327 | } |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 328 | bool dtls_enabled() const override { |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 329 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 330 | return dtls_enabled_; |
| 331 | } |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 332 | const PeerConnectionInterface::RTCConfiguration* configuration() |
| 333 | const override { |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 334 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 335 | return &configuration_; |
| 336 | } |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 337 | PeerConnectionMessageHandler* message_handler() override { |
Harald Alvestrand | 1090e44 | 2020-10-05 07:01:09 +0000 | [diff] [blame] | 338 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 339 | return &message_handler_; |
| 340 | } |
Harald Alvestrand | cdcfab0 | 2020-09-28 13:02:07 +0000 | [diff] [blame] | 341 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 342 | RtpTransmissionManager* rtp_manager() override { return rtp_manager_.get(); } |
| 343 | const RtpTransmissionManager* rtp_manager() const override { |
Harald Alvestrand | e15fb15 | 2020-10-19 13:28:05 +0000 | [diff] [blame] | 344 | return rtp_manager_.get(); |
| 345 | } |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 346 | |
Harald Alvestrand | bc32c56 | 2022-02-09 12:08:47 +0000 | [diff] [blame] | 347 | JsepTransportController* transport_controller_s() override { |
| 348 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 349 | return transport_controller_copy_; |
| 350 | } |
| 351 | JsepTransportController* transport_controller_n() override { |
| 352 | RTC_DCHECK_RUN_ON(network_thread()); |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 353 | return transport_controller_.get(); |
| 354 | } |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 355 | cricket::PortAllocator* port_allocator() override { |
| 356 | return port_allocator_.get(); |
| 357 | } |
| 358 | Call* call_ptr() override { return call_ptr_; } |
Harald Alvestrand | 763f5a9 | 2020-10-22 10:39:40 +0000 | [diff] [blame] | 359 | |
| 360 | ConnectionContext* context() { return context_.get(); } |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 361 | const PeerConnectionFactoryInterface::Options* options() const override { |
Harald Alvestrand | 4da4a87 | 2020-11-04 10:34:21 +0000 | [diff] [blame] | 362 | return &options_; |
| 363 | } |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 364 | void SetIceConnectionState(IceConnectionState new_state) override; |
| 365 | void NoteUsageEvent(UsageEvent event) override; |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 366 | |
Tomas Gunnarsson | 8cb9706 | 2021-02-08 18:57:04 +0100 | [diff] [blame] | 367 | // Asynchronously adds a remote candidate on the network thread. |
| 368 | void AddRemoteCandidate(const std::string& mid, |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 369 | const cricket::Candidate& candidate) override; |
Tomas Gunnarsson | 8cb9706 | 2021-02-08 18:57:04 +0100 | [diff] [blame] | 370 | |
Philipp Hancke | 844c759 | 2021-01-18 11:25:31 +0100 | [diff] [blame] | 371 | // Report the UMA metric SdpFormatReceived for the given remote description. |
| 372 | void ReportSdpFormatReceived( |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 373 | const SessionDescriptionInterface& remote_description) override; |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 374 | |
Philipp Hancke | 54b925c | 2021-01-28 09:56:39 +0100 | [diff] [blame] | 375 | // Report the UMA metric BundleUsage for the given remote description. |
| 376 | void ReportSdpBundleUsage( |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 377 | const SessionDescriptionInterface& remote_description) override; |
Philipp Hancke | 54b925c | 2021-01-28 09:56:39 +0100 | [diff] [blame] | 378 | |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 379 | // Returns true if the PeerConnection is configured to use Unified Plan |
| 380 | // semantics for creating offers/answers and setting local/remote |
| 381 | // descriptions. If this is true the RtpTransceiver API will also be available |
| 382 | // to the user. If this is false, Plan B semantics are assumed. |
| 383 | // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once |
| 384 | // sufficient time has passed. |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 385 | bool IsUnifiedPlan() const override { |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 386 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 387 | return is_unified_plan_; |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 388 | } |
Henrik Boström | f8187e0 | 2021-04-26 21:04:26 +0200 | [diff] [blame] | 389 | bool ValidateBundleSettings( |
| 390 | const cricket::SessionDescription* desc, |
| 391 | const std::map<std::string, const cricket::ContentGroup*>& |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 392 | bundle_groups_by_mid) override; |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 393 | |
Harald Alvestrand | 7af57c6 | 2021-04-16 11:12:14 +0000 | [diff] [blame] | 394 | // Returns the MID for the data section associated with the |
| 395 | // SCTP data channel, if it has been set. If no data |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 396 | // channels are configured this will return nullopt. |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 397 | absl::optional<std::string> GetDataMid() const override; |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 398 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 399 | void SetSctpDataMid(const std::string& mid) override; |
Tomas Gunnarsson | 92eebef | 2021-02-10 13:05:44 +0100 | [diff] [blame] | 400 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 401 | void ResetSctpDataMid() override; |
Tomas Gunnarsson | 92eebef | 2021-02-10 13:05:44 +0100 | [diff] [blame] | 402 | |
| 403 | // Asynchronously calls SctpTransport::Start() on the network thread for |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 404 | // `sctp_mid()` if set. Called as part of setting the local description. |
Tomas Gunnarsson | 92eebef | 2021-02-10 13:05:44 +0100 | [diff] [blame] | 405 | void StartSctpTransport(int local_port, |
| 406 | int remote_port, |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 407 | int max_message_size) override; |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 408 | |
| 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 Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 412 | CryptoOptions GetCryptoOptions() override; |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 413 | |
| 414 | // Internal implementation for AddTransceiver family of methods. If |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 415 | // `fire_callback` is set, fires OnRenegotiationNeeded callback if successful. |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 416 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 417 | cricket::MediaType media_type, |
| 418 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 419 | const RtpTransceiverInit& init, |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 420 | bool fire_callback = true) override; |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 421 | |
| 422 | // Returns rtp transport, result can not be nullptr. |
Tomas Gunnarsson | 92eebef | 2021-02-10 13:05:44 +0100 | [diff] [blame] | 423 | RtpTransportInternal* GetRtpTransport(const std::string& mid); |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 424 | |
| 425 | // Returns true if SRTP (either using DTLS-SRTP or SDES) is required by |
| 426 | // this session. |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 427 | bool SrtpRequired() const override; |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 428 | |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 429 | bool SetupDataChannelTransport_n(const std::string& mid) override |
Harald Alvestrand | 653429c | 2020-10-19 16:05:20 +0000 | [diff] [blame] | 430 | RTC_RUN_ON(network_thread()); |
Harald Alvestrand | 5b66130 | 2022-01-28 13:08:34 +0000 | [diff] [blame] | 431 | void TeardownDataChannelTransport_n() override RTC_RUN_ON(network_thread()); |
Harald Alvestrand | e15fb15 | 2020-10-19 13:28:05 +0000 | [diff] [blame] | 432 | |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 +0000 | [diff] [blame] | 433 | const FieldTrialsView& trials() const override { return *trials_; } |
| 434 | |
| 435 | bool ConfiguredForMedia() const; |
| 436 | |
Harald Alvestrand | 05e4d08 | 2019-12-03 14:04:21 +0100 | [diff] [blame] | 437 | // Functions made public for testing. |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 438 | void ReturnHistogramVeryQuicklyForTesting() { |
Karl Wiberg | f73f7d6 | 2019-04-08 15:36:53 +0200 | [diff] [blame] | 439 | RTC_DCHECK_RUN_ON(signaling_thread()); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 440 | return_histogram_very_quickly_ = true; |
| 441 | } |
Harald Alvestrand | 7a1c7f7 | 2018-08-01 10:50:16 +0200 | [diff] [blame] | 442 | void RequestUsagePatternReportForTesting(); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 443 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 444 | protected: |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 445 | // Available for rtc::scoped_refptr creation |
Harald Alvestrand | 4da4a87 | 2020-11-04 10:34:21 +0000 | [diff] [blame] | 446 | PeerConnection(rtc::scoped_refptr<ConnectionContext> context, |
| 447 | const PeerConnectionFactoryInterface::Options& options, |
| 448 | bool is_unified_plan, |
| 449 | std::unique_ptr<RtcEventLog> event_log, |
| 450 | std::unique_ptr<Call> call, |
Tommi | c3257d0 | 2021-02-10 17:40:08 +0000 | [diff] [blame] | 451 | PeerConnectionDependencies& dependencies, |
| 452 | bool dtls_enabled); |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 453 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 454 | ~PeerConnection() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 455 | |
| 456 | private: |
Harald Alvestrand | a3dd772 | 2020-11-27 08:05:42 +0000 | [diff] [blame] | 457 | RTCError Initialize( |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 458 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 459 | PeerConnectionDependencies dependencies); |
Harald Alvestrand | bc32c56 | 2022-02-09 12:08:47 +0000 | [diff] [blame] | 460 | JsepTransportController* InitializeTransportController_n( |
Tommi | c3257d0 | 2021-02-10 17:40:08 +0000 | [diff] [blame] | 461 | const RTCConfiguration& configuration, |
| 462 | const PeerConnectionDependencies& dependencies) |
| 463 | RTC_RUN_ON(network_thread()); |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 464 | |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 465 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>> |
Karl Wiberg | a58e169 | 2019-03-26 13:33:43 +0100 | [diff] [blame] | 466 | FindTransceiverBySender(rtc::scoped_refptr<RtpSenderInterface> sender) |
| 467 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 468 | |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 469 | void SetStandardizedIceConnectionState( |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 470 | PeerConnectionInterface::IceConnectionState new_state) |
| 471 | RTC_RUN_ON(signaling_thread()); |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 472 | void SetConnectionState( |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 473 | PeerConnectionInterface::PeerConnectionState new_state) |
| 474 | RTC_RUN_ON(signaling_thread()); |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 475 | |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 476 | // Called any time the IceGatheringState changes. |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 477 | void OnIceGatheringChange(IceGatheringState new_state) |
| 478 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 479 | // New ICE candidate has been gathered. |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 480 | void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate) |
| 481 | RTC_RUN_ON(signaling_thread()); |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 482 | // Gathering of an ICE candidate failed. |
Eldar Rello | 0095d37 | 2019-12-02 22:22:07 +0200 | [diff] [blame] | 483 | void OnIceCandidateError(const std::string& address, |
| 484 | int port, |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 485 | const std::string& url, |
| 486 | int error_code, |
| 487 | const std::string& error_text) |
| 488 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 489 | // Some local ICE candidates have been removed. |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 490 | void OnIceCandidatesRemoved(const std::vector<cricket::Candidate>& candidates) |
| 491 | RTC_RUN_ON(signaling_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 492 | |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 493 | void OnSelectedCandidatePairChanged( |
| 494 | const cricket::CandidatePairChangeEvent& event) |
| 495 | RTC_RUN_ON(signaling_thread()); |
| 496 | |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 497 | void OnNegotiationNeeded(); |
| 498 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 499 | // Called when first configuring the port allocator. |
Karl Wiberg | fb3be39 | 2019-03-22 14:13:22 +0100 | [diff] [blame] | 500 | struct InitializePortAllocatorResult { |
| 501 | bool enable_ipv6; |
| 502 | }; |
| 503 | InitializePortAllocatorResult InitializePortAllocator_n( |
Harald Alvestrand | b2a7478 | 2018-06-28 13:54:07 +0200 | [diff] [blame] | 504 | const cricket::ServerAddresses& stun_servers, |
| 505 | const std::vector<cricket::RelayServerConfig>& turn_servers, |
| 506 | const RTCConfiguration& configuration); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 507 | // Called when SetConfiguration is called to apply the supported subset |
| 508 | // of the configuration on the network thread. |
| 509 | bool ReconfigurePortAllocator_n( |
| 510 | const cricket::ServerAddresses& stun_servers, |
| 511 | const std::vector<cricket::RelayServerConfig>& turn_servers, |
| 512 | IceTransportsType type, |
| 513 | int candidate_pool_size, |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 514 | PortPrunePolicy turn_port_prune_policy, |
Qingsi Wang | db53f8e | 2018-02-20 14:45:49 -0800 | [diff] [blame] | 515 | webrtc::TurnCustomizer* turn_customizer, |
Karl Wiberg | 739506e | 2019-04-03 11:37:28 +0200 | [diff] [blame] | 516 | absl::optional<int> stun_candidate_keepalive_interval, |
| 517 | bool have_local_description); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 518 | |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 519 | // Starts output of an RTC event log to the given output object. |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 520 | // This function should only be called from the worker thread. |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 521 | bool StartRtcEventLog_w(std::unique_ptr<RtcEventLogOutput> output, |
| 522 | int64_t output_period_ms); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 523 | |
Elad Alon | acb2417 | 2017-10-06 14:32:13 +0200 | [diff] [blame] | 524 | // Stops recording an RTC event log. |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 525 | // This function should only be called from the worker thread. |
| 526 | void StopRtcEventLog_w(); |
| 527 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 528 | // Returns true and the TransportInfo of the given `content_name` |
| 529 | // from `description`. Returns false if it's not available. |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 530 | static bool GetTransportDescription( |
| 531 | const cricket::SessionDescription* description, |
| 532 | const std::string& content_name, |
| 533 | cricket::TransportDescription* info); |
| 534 | |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 535 | // Returns the media index for a local ice candidate given the content name. |
| 536 | // Returns false if the local session description does not have a media |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 537 | // content called `content_name`. |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 538 | bool GetLocalCandidateMediaIndex(const std::string& content_name, |
Karl Wiberg | 739506e | 2019-04-03 11:37:28 +0200 | [diff] [blame] | 539 | int* sdp_mline_index) |
| 540 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 541 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 542 | // JsepTransportController signal handlers. |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 543 | void OnTransportControllerConnectionState(cricket::IceConnectionState state) |
| 544 | RTC_RUN_ON(signaling_thread()); |
| 545 | void OnTransportControllerGatheringState(cricket::IceGatheringState state) |
| 546 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 547 | void OnTransportControllerCandidatesGathered( |
| 548 | const std::string& transport_name, |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 549 | const std::vector<cricket::Candidate>& candidates) |
| 550 | RTC_RUN_ON(signaling_thread()); |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 551 | void OnTransportControllerCandidateError( |
| 552 | const cricket::IceCandidateErrorEvent& event) |
| 553 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 554 | void OnTransportControllerCandidatesRemoved( |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 555 | const std::vector<cricket::Candidate>& candidates) |
| 556 | RTC_RUN_ON(signaling_thread()); |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 557 | void OnTransportControllerCandidateChanged( |
| 558 | const cricket::CandidatePairChangeEvent& event) |
| 559 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 560 | void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error); |
| 561 | |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 562 | // Invoked when TransportController connection completion is signaled. |
| 563 | // Reports stats for all transports in use. |
Tomas Gunnarsson | 2001dc3 | 2021-04-06 11:36:00 +0200 | [diff] [blame] | 564 | void ReportTransportStats() RTC_RUN_ON(network_thread()); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 565 | |
| 566 | // Gather the usage of IPv4/IPv6 as best connection. |
Tommi | c3257d0 | 2021-02-10 17:40:08 +0000 | [diff] [blame] | 567 | static void ReportBestConnectionState(const cricket::TransportStats& stats); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 568 | |
Tommi | c3257d0 | 2021-02-10 17:40:08 +0000 | [diff] [blame] | 569 | static void ReportNegotiatedCiphers( |
| 570 | bool dtls_enabled, |
| 571 | const cricket::TransportStats& stats, |
| 572 | const std::set<cricket::MediaType>& media_types); |
Qingsi Wang | 1ba5dec | 2019-08-19 11:57:17 -0700 | [diff] [blame] | 573 | void ReportIceCandidateCollected(const cricket::Candidate& candidate) |
| 574 | RTC_RUN_ON(signaling_thread()); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 575 | |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 576 | void ReportUsagePattern() const RTC_RUN_ON(signaling_thread()); |
Harald Alvestrand | 8ebba74 | 2018-05-31 14:00:34 +0200 | [diff] [blame] | 577 | |
Tomas Gunnarsson | 8cb9706 | 2021-02-08 18:57:04 +0100 | [diff] [blame] | 578 | void ReportRemoteIceCandidateAdded(const cricket::Candidate& candidate); |
| 579 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 580 | // JsepTransportController::Observer override. |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 581 | // |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 582 | // Called by `transport_controller_` when processing transport information |
Taylor Brandstetter | cbaa254 | 2018-04-16 16:42:14 -0700 | [diff] [blame] | 583 | // from a session description, and the mapping from m= sections to transports |
| 584 | // changed (as a result of BUNDLE negotiation, or m= sections being |
| 585 | // rejected). |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 586 | bool OnTransportChanged( |
| 587 | const std::string& mid, |
| 588 | RtpTransportInternal* rtp_transport, |
| 589 | rtc::scoped_refptr<DtlsTransport> dtls_transport, |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 590 | DataChannelTransportInterface* data_channel_transport) override; |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 591 | |
Tomas Gunnarsson | 1e40a0c | 2020-09-28 10:39:31 +0200 | [diff] [blame] | 592 | std::function<void(const rtc::CopyOnWriteBuffer& packet, |
| 593 | int64_t packet_time_us)> |
| 594 | InitializeRtcpCallback(); |
| 595 | |
Harald Alvestrand | 9e334b7 | 2022-05-04 13:38:31 +0000 | [diff] [blame] | 596 | cricket::ChannelManager* channel_manager() { |
| 597 | return context_->channel_manager(); |
| 598 | } |
| 599 | |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 +0000 | [diff] [blame] | 600 | const rtc::scoped_refptr<ConnectionContext> context_; |
Jonas Oreland | 6c7f984 | 2022-04-19 17:24:10 +0200 | [diff] [blame] | 601 | // Field trials active for this PeerConnection is the first of: |
| 602 | // a) Specified in PeerConnectionDependencies (owned). |
| 603 | // b) Accessed via ConnectionContext (e.g PeerConnectionFactoryDependencies> |
| 604 | // c) Created as Default (FieldTrialBasedConfig). |
| 605 | const webrtc::AlwaysValidPointer<const FieldTrialsView, FieldTrialBasedConfig> |
| 606 | trials_; |
Harald Alvestrand | 4da4a87 | 2020-11-04 10:34:21 +0000 | [diff] [blame] | 607 | const PeerConnectionFactoryInterface::Options options_; |
Karl Wiberg | 744310f | 2019-02-14 10:18:56 +0100 | [diff] [blame] | 608 | PeerConnectionObserver* observer_ RTC_GUARDED_BY(signaling_thread()) = |
| 609 | nullptr; |
terelius | 3386025 | 2017-05-12 23:37:18 -0700 | [diff] [blame] | 610 | |
Harald Alvestrand | 6216693 | 2020-10-26 08:30:41 +0000 | [diff] [blame] | 611 | const bool is_unified_plan_; |
| 612 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 613 | // The EventLog needs to outlive `call_` (and any other object that uses it). |
Karl Wiberg | b03ab71 | 2019-02-14 11:59:57 +0100 | [diff] [blame] | 614 | std::unique_ptr<RtcEventLog> event_log_ RTC_GUARDED_BY(worker_thread()); |
| 615 | |
| 616 | // Points to the same thing as `event_log_`. Since it's const, we may read the |
| 617 | // pointer (but not touch the object) from any thread. |
| 618 | RtcEventLog* const event_log_ptr_ RTC_PT_GUARDED_BY(worker_thread()); |
terelius | 3386025 | 2017-05-12 23:37:18 -0700 | [diff] [blame] | 619 | |
Karl Wiberg | 8d2e228 | 2019-02-17 13:00:07 +0100 | [diff] [blame] | 620 | IceConnectionState ice_connection_state_ RTC_GUARDED_BY(signaling_thread()) = |
| 621 | kIceConnectionNew; |
| 622 | PeerConnectionInterface::IceConnectionState standardized_ice_connection_state_ |
| 623 | RTC_GUARDED_BY(signaling_thread()) = kIceConnectionNew; |
| 624 | PeerConnectionInterface::PeerConnectionState connection_state_ |
| 625 | RTC_GUARDED_BY(signaling_thread()) = PeerConnectionState::kNew; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 626 | |
Karl Wiberg | 8d2e228 | 2019-02-17 13:00:07 +0100 | [diff] [blame] | 627 | IceGatheringState ice_gathering_state_ RTC_GUARDED_BY(signaling_thread()) = |
| 628 | kIceGatheringNew; |
Karl Wiberg | 5966c50 | 2019-02-21 23:55:09 +0100 | [diff] [blame] | 629 | PeerConnectionInterface::RTCConfiguration configuration_ |
| 630 | RTC_GUARDED_BY(signaling_thread()); |
| 631 | |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 632 | const std::unique_ptr<AsyncDnsResolverFactoryInterface> |
| 633 | async_dns_resolver_factory_; |
Karl Wiberg | fb3be39 | 2019-03-22 14:13:22 +0100 | [diff] [blame] | 634 | std::unique_ptr<cricket::PortAllocator> |
| 635 | port_allocator_; // TODO(bugs.webrtc.org/9987): Accessed on both |
| 636 | // signaling and network thread. |
Harald Alvestrand | fd9a8f8 | 2020-10-26 14:17:02 +0000 | [diff] [blame] | 637 | const std::unique_ptr<webrtc::IceTransportFactory> |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 638 | ice_transport_factory_; // TODO(bugs.webrtc.org/9987): Accessed on the |
| 639 | // signaling thread but the underlying raw |
| 640 | // pointer is given to |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 641 | // `jsep_transport_controller_` and used on the |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 642 | // network thread. |
Harald Alvestrand | f598e49 | 2020-11-04 05:54:10 +0000 | [diff] [blame] | 643 | const std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier_ |
| 644 | RTC_GUARDED_BY(network_thread()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 645 | |
Karl Wiberg | ac02589 | 2019-03-26 13:08:37 +0100 | [diff] [blame] | 646 | // The unique_ptr belongs to the worker thread, but the Call object manages |
| 647 | // its own thread safety. |
Karl Wiberg | 6cab5c8 | 2019-03-26 09:57:01 +0100 | [diff] [blame] | 648 | std::unique_ptr<Call> call_ RTC_GUARDED_BY(worker_thread()); |
Tomas Gunnarsson | 92eebef | 2021-02-10 13:05:44 +0100 | [diff] [blame] | 649 | ScopedTaskSafety signaling_thread_safety_; |
| 650 | rtc::scoped_refptr<PendingTaskSafetyFlag> network_thread_safety_; |
Tommi | c3257d0 | 2021-02-10 17:40:08 +0000 | [diff] [blame] | 651 | rtc::scoped_refptr<PendingTaskSafetyFlag> worker_thread_safety_; |
Sebastian Jansson | 1b83a9e | 2019-09-18 18:22:12 +0200 | [diff] [blame] | 652 | |
Karl Wiberg | 6cab5c8 | 2019-03-26 09:57:01 +0100 | [diff] [blame] | 653 | // Points to the same thing as `call_`. Since it's const, we may read the |
Karl Wiberg | ac02589 | 2019-03-26 13:08:37 +0100 | [diff] [blame] | 654 | // pointer from any thread. |
Tomas Gunnarsson | 1e40a0c | 2020-09-28 10:39:31 +0200 | [diff] [blame] | 655 | // TODO(bugs.webrtc.org/11992): Remove this workaround (and potential dangling |
| 656 | // pointer). |
Karl Wiberg | ac02589 | 2019-03-26 13:08:37 +0100 | [diff] [blame] | 657 | Call* const call_ptr_; |
Karl Wiberg | 6cab5c8 | 2019-03-26 09:57:01 +0100 | [diff] [blame] | 658 | |
| 659 | std::unique_ptr<StatsCollector> stats_ |
| 660 | RTC_GUARDED_BY(signaling_thread()); // A pointer is passed to senders_ |
| 661 | rtc::scoped_refptr<RTCStatsCollector> stats_collector_ |
| 662 | RTC_GUARDED_BY(signaling_thread()); |
Karl Wiberg | 2cc368f | 2019-04-02 11:31:56 +0200 | [diff] [blame] | 663 | |
Tomas Gunnarsson | 97a387d | 2021-03-29 21:04:29 +0200 | [diff] [blame] | 664 | const std::string session_id_; |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 665 | |
Harald Alvestrand | bc32c56 | 2022-02-09 12:08:47 +0000 | [diff] [blame] | 666 | // The transport controller is set and used on the network thread. |
| 667 | // Some functions pass the value of the transport_controller_ pointer |
| 668 | // around as arguments while running on the signaling thread; these |
| 669 | // use the transport_controller_copy. |
| 670 | std::unique_ptr<JsepTransportController> transport_controller_ |
| 671 | RTC_GUARDED_BY(network_thread()); |
| 672 | JsepTransportController* transport_controller_copy_ |
| 673 | RTC_GUARDED_BY(signaling_thread()) = nullptr; |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 674 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 675 | // `sctp_mid_` is the content name (MID) in SDP. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 676 | // Note: this is used as the data channel MID by both SCTP and data channel |
| 677 | // transports. It is set when either transport is initialized and unset when |
| 678 | // both transports are deleted. |
Harald Alvestrand | 7a829a8 | 2020-02-12 07:38:21 +0100 | [diff] [blame] | 679 | // There is one copy on the signaling thread and another copy on the |
| 680 | // networking thread. Changes are always initiated from the signaling |
| 681 | // thread, but applied first on the networking thread via an invoke(). |
| 682 | absl::optional<std::string> sctp_mid_s_ RTC_GUARDED_BY(signaling_thread()); |
| 683 | absl::optional<std::string> sctp_mid_n_ RTC_GUARDED_BY(network_thread()); |
Tomas Gunnarsson | 92eebef | 2021-02-10 13:05:44 +0100 | [diff] [blame] | 684 | std::string sctp_transport_name_s_ RTC_GUARDED_BY(signaling_thread()); |
Karl Wiberg | 2cc368f | 2019-04-02 11:31:56 +0200 | [diff] [blame] | 685 | |
Harald Alvestrand | 9cd199d | 2020-10-27 07:10:43 +0000 | [diff] [blame] | 686 | // The machinery for handling offers and answers. Const after initialization. |
| 687 | std::unique_ptr<SdpOfferAnswerHandler> sdp_handler_ |
Harald Alvestrand | 00c62ed | 2021-10-20 08:52:12 +0000 | [diff] [blame] | 688 | RTC_GUARDED_BY(signaling_thread()) RTC_PT_GUARDED_BY(signaling_thread()); |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 689 | |
Tommi | c3257d0 | 2021-02-10 17:40:08 +0000 | [diff] [blame] | 690 | const bool dtls_enabled_; |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 691 | |
Harald Alvestrand | 44d0dff | 2020-10-09 05:43:53 +0000 | [diff] [blame] | 692 | UsagePattern usage_pattern_ RTC_GUARDED_BY(signaling_thread()); |
Karl Wiberg | f73f7d6 | 2019-04-08 15:36:53 +0200 | [diff] [blame] | 693 | bool return_histogram_very_quickly_ RTC_GUARDED_BY(signaling_thread()) = |
| 694 | false; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 695 | |
Harald Alvestrand | 00c62ed | 2021-10-20 08:52:12 +0000 | [diff] [blame] | 696 | // The DataChannelController is accessed from both the signaling thread |
| 697 | // and networking thread. It is a thread-aware object. |
Harald Alvestrand | 00cf34c | 2019-12-02 09:56:02 +0100 | [diff] [blame] | 698 | DataChannelController data_channel_controller_; |
Harald Alvestrand | 1090e44 | 2020-10-05 07:01:09 +0000 | [diff] [blame] | 699 | |
| 700 | // Machinery for handling messages posted to oneself |
Harald Alvestrand | 00c62ed | 2021-10-20 08:52:12 +0000 | [diff] [blame] | 701 | PeerConnectionMessageHandler message_handler_ |
| 702 | RTC_GUARDED_BY(signaling_thread()); |
Harald Alvestrand | e15fb15 | 2020-10-19 13:28:05 +0000 | [diff] [blame] | 703 | |
| 704 | // Administration of senders, receivers and transceivers |
| 705 | // Accessed on both signaling and network thread. Const after Initialize(). |
| 706 | std::unique_ptr<RtpTransmissionManager> rtp_manager_; |
Lahiru Ginnaliya Gamathige | 70f9e24 | 2021-01-27 23:32:46 -0800 | [diff] [blame] | 707 | |
Philipp Hancke | cd0373f | 2021-02-24 11:04:30 +0100 | [diff] [blame] | 708 | // Did the connectionState ever change to `connected`? |
| 709 | // Used to gather metrics only the first such state change. |
| 710 | bool was_ever_connected_ RTC_GUARDED_BY(signaling_thread()) = false; |
Harald Alvestrand | 00c62ed | 2021-10-20 08:52:12 +0000 | [diff] [blame] | 711 | |
| 712 | // This variable needs to be the last one in the class. |
| 713 | rtc::WeakPtrFactory<PeerConnection> weak_factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 714 | }; |
| 715 | |
| 716 | } // namespace webrtc |
| 717 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 718 | #endif // PC_PEER_CONNECTION_H_ |