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