Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef PC_TEST_INTEGRATION_TEST_HELPERS_H_ |
| 12 | #define PC_TEST_INTEGRATION_TEST_HELPERS_H_ |
| 13 | |
| 14 | #include <limits.h> |
| 15 | #include <stdint.h> |
| 16 | #include <stdio.h> |
| 17 | |
| 18 | #include <algorithm> |
| 19 | #include <functional> |
Taylor Brandstetter | 1c7ecef | 2021-08-11 19:38:35 | [diff] [blame] | 20 | #include <limits> |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 21 | #include <list> |
| 22 | #include <map> |
| 23 | #include <memory> |
| 24 | #include <set> |
| 25 | #include <string> |
| 26 | #include <utility> |
| 27 | #include <vector> |
| 28 | |
| 29 | #include "absl/algorithm/container.h" |
Niels Möller | 7ee4594 | 2022-05-05 07:30:35 | [diff] [blame] | 30 | #include "absl/memory/memory.h" |
Ali Tofigh | b7821ce | 2022-07-12 14:08:13 | [diff] [blame] | 31 | #include "absl/strings/string_view.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 32 | #include "absl/types/optional.h" |
| 33 | #include "api/audio_options.h" |
| 34 | #include "api/call/call_factory_interface.h" |
| 35 | #include "api/candidate.h" |
| 36 | #include "api/crypto/crypto_options.h" |
| 37 | #include "api/data_channel_interface.h" |
Jonas Oreland | e62c2f2 | 2022-03-29 09:04:48 | [diff] [blame] | 38 | #include "api/field_trials_view.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 39 | #include "api/ice_transport_interface.h" |
| 40 | #include "api/jsep.h" |
| 41 | #include "api/media_stream_interface.h" |
| 42 | #include "api/media_types.h" |
| 43 | #include "api/peer_connection_interface.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 44 | #include "api/rtc_error.h" |
| 45 | #include "api/rtc_event_log/rtc_event_log_factory.h" |
| 46 | #include "api/rtc_event_log/rtc_event_log_factory_interface.h" |
| 47 | #include "api/rtc_event_log_output.h" |
| 48 | #include "api/rtp_receiver_interface.h" |
| 49 | #include "api/rtp_sender_interface.h" |
| 50 | #include "api/rtp_transceiver_interface.h" |
| 51 | #include "api/scoped_refptr.h" |
| 52 | #include "api/stats/rtc_stats.h" |
| 53 | #include "api/stats/rtc_stats_report.h" |
| 54 | #include "api/stats/rtcstats_objects.h" |
| 55 | #include "api/task_queue/default_task_queue_factory.h" |
Artem Titov | c374d11 | 2022-06-16 19:27:45 | [diff] [blame] | 56 | #include "api/task_queue/pending_task_safety_flag.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 57 | #include "api/task_queue/task_queue_factory.h" |
| 58 | #include "api/transport/field_trial_based_config.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 59 | #include "api/uma_metrics.h" |
Danil Chapovalov | a30439b | 2022-07-07 08:08:49 | [diff] [blame] | 60 | #include "api/units/time_delta.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 61 | #include "api/video/video_rotation.h" |
| 62 | #include "api/video_codecs/sdp_video_format.h" |
| 63 | #include "api/video_codecs/video_decoder_factory.h" |
| 64 | #include "api/video_codecs/video_encoder_factory.h" |
| 65 | #include "call/call.h" |
| 66 | #include "logging/rtc_event_log/fake_rtc_event_log_factory.h" |
| 67 | #include "media/base/media_engine.h" |
| 68 | #include "media/base/stream_params.h" |
| 69 | #include "media/engine/fake_webrtc_video_engine.h" |
| 70 | #include "media/engine/webrtc_media_engine.h" |
| 71 | #include "media/engine/webrtc_media_engine_defaults.h" |
| 72 | #include "modules/audio_device/include/audio_device.h" |
| 73 | #include "modules/audio_processing/include/audio_processing.h" |
| 74 | #include "modules/audio_processing/test/audio_processing_builder_for_testing.h" |
| 75 | #include "p2p/base/fake_ice_transport.h" |
| 76 | #include "p2p/base/ice_transport_internal.h" |
| 77 | #include "p2p/base/mock_async_resolver.h" |
| 78 | #include "p2p/base/p2p_constants.h" |
| 79 | #include "p2p/base/port.h" |
| 80 | #include "p2p/base/port_allocator.h" |
| 81 | #include "p2p/base/port_interface.h" |
| 82 | #include "p2p/base/test_stun_server.h" |
| 83 | #include "p2p/base/test_turn_customizer.h" |
| 84 | #include "p2p/base/test_turn_server.h" |
| 85 | #include "p2p/client/basic_port_allocator.h" |
| 86 | #include "pc/dtmf_sender.h" |
| 87 | #include "pc/local_audio_source.h" |
| 88 | #include "pc/media_session.h" |
| 89 | #include "pc/peer_connection.h" |
| 90 | #include "pc/peer_connection_factory.h" |
Markus Handell | a1b8201 | 2021-05-26 16:56:30 | [diff] [blame] | 91 | #include "pc/peer_connection_proxy.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 92 | #include "pc/rtp_media_utils.h" |
| 93 | #include "pc/session_description.h" |
| 94 | #include "pc/test/fake_audio_capture_module.h" |
| 95 | #include "pc/test/fake_periodic_video_source.h" |
| 96 | #include "pc/test/fake_periodic_video_track_source.h" |
| 97 | #include "pc/test/fake_rtc_certificate_generator.h" |
| 98 | #include "pc/test/fake_video_track_renderer.h" |
| 99 | #include "pc/test/mock_peer_connection_observers.h" |
| 100 | #include "pc/video_track_source.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 101 | #include "rtc_base/checks.h" |
Evan Shrubsole | 7619b7c | 2022-03-01 09:42:44 | [diff] [blame] | 102 | #include "rtc_base/event.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 103 | #include "rtc_base/fake_clock.h" |
| 104 | #include "rtc_base/fake_mdns_responder.h" |
| 105 | #include "rtc_base/fake_network.h" |
| 106 | #include "rtc_base/firewall_socket_server.h" |
| 107 | #include "rtc_base/gunit.h" |
| 108 | #include "rtc_base/helpers.h" |
| 109 | #include "rtc_base/ip_address.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 110 | #include "rtc_base/logging.h" |
| 111 | #include "rtc_base/mdns_responder_interface.h" |
| 112 | #include "rtc_base/numerics/safe_conversions.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 113 | #include "rtc_base/rtc_certificate_generator.h" |
| 114 | #include "rtc_base/socket_address.h" |
| 115 | #include "rtc_base/ssl_stream_adapter.h" |
Danil Chapovalov | 2aaef45 | 2022-08-12 13:55:11 | [diff] [blame] | 116 | #include "rtc_base/task_queue_for_test.h" |
Evan Shrubsole | 7619b7c | 2022-03-01 09:42:44 | [diff] [blame] | 117 | #include "rtc_base/task_utils/repeating_task.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 118 | #include "rtc_base/test_certificate_verifier.h" |
| 119 | #include "rtc_base/thread.h" |
Evan Shrubsole | 7619b7c | 2022-03-01 09:42:44 | [diff] [blame] | 120 | #include "rtc_base/thread_annotations.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 121 | #include "rtc_base/time_utils.h" |
| 122 | #include "rtc_base/virtual_socket_server.h" |
| 123 | #include "system_wrappers/include/metrics.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 124 | #include "test/gmock.h" |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 125 | #include "test/scoped_key_value_config.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 126 | |
| 127 | namespace webrtc { |
| 128 | |
| 129 | using ::cricket::ContentInfo; |
| 130 | using ::cricket::StreamParams; |
| 131 | using ::rtc::SocketAddress; |
| 132 | using ::testing::_; |
| 133 | using ::testing::Combine; |
| 134 | using ::testing::Contains; |
| 135 | using ::testing::DoAll; |
| 136 | using ::testing::ElementsAre; |
| 137 | using ::testing::NiceMock; |
| 138 | using ::testing::Return; |
| 139 | using ::testing::SetArgPointee; |
| 140 | using ::testing::UnorderedElementsAreArray; |
| 141 | using ::testing::Values; |
| 142 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 143 | |
| 144 | static const int kDefaultTimeout = 10000; |
| 145 | static const int kMaxWaitForStatsMs = 3000; |
| 146 | static const int kMaxWaitForActivationMs = 5000; |
| 147 | static const int kMaxWaitForFramesMs = 10000; |
| 148 | // Default number of audio/video frames to wait for before considering a test |
| 149 | // successful. |
| 150 | static const int kDefaultExpectedAudioFrameCount = 3; |
| 151 | static const int kDefaultExpectedVideoFrameCount = 3; |
| 152 | |
| 153 | static const char kDataChannelLabel[] = "data_channel"; |
| 154 | |
| 155 | // SRTP cipher name negotiated by the tests. This must be updated if the |
| 156 | // default changes. |
Mirko Bonadei | 7750d80 | 2021-07-26 15:27:42 | [diff] [blame] | 157 | static const int kDefaultSrtpCryptoSuite = rtc::kSrtpAes128CmSha1_80; |
| 158 | static const int kDefaultSrtpCryptoSuiteGcm = rtc::kSrtpAeadAes256Gcm; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 159 | |
| 160 | static const SocketAddress kDefaultLocalAddress("192.168.1.1", 0); |
| 161 | |
| 162 | // Helper function for constructing offer/answer options to initiate an ICE |
| 163 | // restart. |
| 164 | PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions(); |
| 165 | |
| 166 | // Remove all stream information (SSRCs, track IDs, etc.) and "msid-semantic" |
| 167 | // attribute from received SDP, simulating a legacy endpoint. |
| 168 | void RemoveSsrcsAndMsids(cricket::SessionDescription* desc); |
| 169 | |
| 170 | // Removes all stream information besides the stream ids, simulating an |
| 171 | // endpoint that only signals a=msid lines to convey stream_ids. |
| 172 | void RemoveSsrcsAndKeepMsids(cricket::SessionDescription* desc); |
| 173 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 174 | int FindFirstMediaStatsIndexByKind( |
| 175 | const std::string& kind, |
Henrik Boström | 323e9df | 2022-12-24 09:33:39 | [diff] [blame] | 176 | const std::vector<const webrtc::RTCInboundRTPStreamStats*>& inbound_rtps); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 177 | |
Evan Shrubsole | 7619b7c | 2022-03-01 09:42:44 | [diff] [blame] | 178 | class TaskQueueMetronome : public webrtc::Metronome { |
| 179 | public: |
Markus Handell | be400e4 | 2022-11-08 11:14:23 | [diff] [blame] | 180 | explicit TaskQueueMetronome(TimeDelta tick_period); |
Markus Handell | 15a82c9 | 2022-11-10 09:53:27 | [diff] [blame] | 181 | ~TaskQueueMetronome() override; |
Evan Shrubsole | 7619b7c | 2022-03-01 09:42:44 | [diff] [blame] | 182 | |
| 183 | // webrtc::Metronome implementation. |
Markus Handell | be400e4 | 2022-11-08 11:14:23 | [diff] [blame] | 184 | void RequestCallOnNextTick(absl::AnyInvocable<void() &&> callback) override; |
Evan Shrubsole | 7619b7c | 2022-03-01 09:42:44 | [diff] [blame] | 185 | TimeDelta TickPeriod() const override; |
| 186 | |
| 187 | private: |
Evan Shrubsole | 7619b7c | 2022-03-01 09:42:44 | [diff] [blame] | 188 | const TimeDelta tick_period_; |
Markus Handell | 15a82c9 | 2022-11-10 09:53:27 | [diff] [blame] | 189 | SequenceChecker sequence_checker_; |
Markus Handell | be400e4 | 2022-11-08 11:14:23 | [diff] [blame] | 190 | std::vector<absl::AnyInvocable<void() &&>> callbacks_; |
Markus Handell | 15a82c9 | 2022-11-10 09:53:27 | [diff] [blame] | 191 | ScopedTaskSafetyDetached safety_; |
Evan Shrubsole | 7619b7c | 2022-03-01 09:42:44 | [diff] [blame] | 192 | }; |
| 193 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 194 | class SignalingMessageReceiver { |
| 195 | public: |
| 196 | virtual void ReceiveSdpMessage(SdpType type, const std::string& msg) = 0; |
| 197 | virtual void ReceiveIceMessage(const std::string& sdp_mid, |
| 198 | int sdp_mline_index, |
| 199 | const std::string& msg) = 0; |
| 200 | |
| 201 | protected: |
| 202 | SignalingMessageReceiver() {} |
| 203 | virtual ~SignalingMessageReceiver() {} |
| 204 | }; |
| 205 | |
| 206 | class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface { |
| 207 | public: |
| 208 | explicit MockRtpReceiverObserver(cricket::MediaType media_type) |
| 209 | : expected_media_type_(media_type) {} |
| 210 | |
| 211 | void OnFirstPacketReceived(cricket::MediaType media_type) override { |
| 212 | ASSERT_EQ(expected_media_type_, media_type); |
| 213 | first_packet_received_ = true; |
| 214 | } |
| 215 | |
| 216 | bool first_packet_received() const { return first_packet_received_; } |
| 217 | |
| 218 | virtual ~MockRtpReceiverObserver() {} |
| 219 | |
| 220 | private: |
| 221 | bool first_packet_received_ = false; |
| 222 | cricket::MediaType expected_media_type_; |
| 223 | }; |
| 224 | |
| 225 | // Helper class that wraps a peer connection, observes it, and can accept |
| 226 | // signaling messages from another wrapper. |
| 227 | // |
| 228 | // Uses a fake network, fake A/V capture, and optionally fake |
| 229 | // encoders/decoders, though they aren't used by default since they don't |
| 230 | // advertise support of any codecs. |
| 231 | // TODO(steveanton): See how this could become a subclass of |
| 232 | // PeerConnectionWrapper defined in peerconnectionwrapper.h. |
| 233 | class PeerConnectionIntegrationWrapper : public webrtc::PeerConnectionObserver, |
| 234 | public SignalingMessageReceiver { |
| 235 | public: |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 236 | webrtc::PeerConnectionFactoryInterface* pc_factory() const { |
| 237 | return peer_connection_factory_.get(); |
| 238 | } |
| 239 | |
| 240 | webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); } |
| 241 | |
| 242 | // If a signaling message receiver is set (via ConnectFakeSignaling), this |
| 243 | // will set the whole offer/answer exchange in motion. Just need to wait for |
| 244 | // the signaling state to reach "stable". |
| 245 | void CreateAndSetAndSignalOffer() { |
| 246 | auto offer = CreateOfferAndWait(); |
| 247 | ASSERT_NE(nullptr, offer); |
| 248 | EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(offer))); |
| 249 | } |
| 250 | |
| 251 | // Sets the options to be used when CreateAndSetAndSignalOffer is called, or |
| 252 | // when a remote offer is received (via fake signaling) and an answer is |
| 253 | // generated. By default, uses default options. |
| 254 | void SetOfferAnswerOptions( |
| 255 | const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
| 256 | offer_answer_options_ = options; |
| 257 | } |
| 258 | |
| 259 | // Set a callback to be invoked when SDP is received via the fake signaling |
| 260 | // channel, which provides an opportunity to munge (modify) the SDP. This is |
| 261 | // used to test SDP being applied that a PeerConnection would normally not |
| 262 | // generate, but a non-JSEP endpoint might. |
| 263 | void SetReceivedSdpMunger( |
| 264 | std::function<void(cricket::SessionDescription*)> munger) { |
| 265 | received_sdp_munger_ = std::move(munger); |
| 266 | } |
| 267 | |
| 268 | // Similar to the above, but this is run on SDP immediately after it's |
| 269 | // generated. |
| 270 | void SetGeneratedSdpMunger( |
| 271 | std::function<void(cricket::SessionDescription*)> munger) { |
| 272 | generated_sdp_munger_ = std::move(munger); |
| 273 | } |
| 274 | |
| 275 | // Set a callback to be invoked when a remote offer is received via the fake |
| 276 | // signaling channel. This provides an opportunity to change the |
| 277 | // PeerConnection state before an answer is created and sent to the caller. |
| 278 | void SetRemoteOfferHandler(std::function<void()> handler) { |
| 279 | remote_offer_handler_ = std::move(handler); |
| 280 | } |
| 281 | |
| 282 | void SetRemoteAsyncResolver(rtc::MockAsyncResolver* resolver) { |
| 283 | remote_async_resolver_ = resolver; |
| 284 | } |
| 285 | |
| 286 | // Every ICE connection state in order that has been seen by the observer. |
| 287 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 288 | ice_connection_state_history() const { |
| 289 | return ice_connection_state_history_; |
| 290 | } |
| 291 | void clear_ice_connection_state_history() { |
| 292 | ice_connection_state_history_.clear(); |
| 293 | } |
| 294 | |
| 295 | // Every standardized ICE connection state in order that has been seen by the |
| 296 | // observer. |
| 297 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 298 | standardized_ice_connection_state_history() const { |
| 299 | return standardized_ice_connection_state_history_; |
| 300 | } |
| 301 | |
| 302 | // Every PeerConnection state in order that has been seen by the observer. |
| 303 | std::vector<PeerConnectionInterface::PeerConnectionState> |
| 304 | peer_connection_state_history() const { |
| 305 | return peer_connection_state_history_; |
| 306 | } |
| 307 | |
| 308 | // Every ICE gathering state in order that has been seen by the observer. |
| 309 | std::vector<PeerConnectionInterface::IceGatheringState> |
| 310 | ice_gathering_state_history() const { |
| 311 | return ice_gathering_state_history_; |
| 312 | } |
| 313 | std::vector<cricket::CandidatePairChangeEvent> |
| 314 | ice_candidate_pair_change_history() const { |
| 315 | return ice_candidate_pair_change_history_; |
| 316 | } |
| 317 | |
| 318 | // Every PeerConnection signaling state in order that has been seen by the |
| 319 | // observer. |
| 320 | std::vector<PeerConnectionInterface::SignalingState> |
| 321 | peer_connection_signaling_state_history() const { |
| 322 | return peer_connection_signaling_state_history_; |
| 323 | } |
| 324 | |
| 325 | void AddAudioVideoTracks() { |
| 326 | AddAudioTrack(); |
| 327 | AddVideoTrack(); |
| 328 | } |
| 329 | |
| 330 | rtc::scoped_refptr<RtpSenderInterface> AddAudioTrack() { |
| 331 | return AddTrack(CreateLocalAudioTrack()); |
| 332 | } |
| 333 | |
| 334 | rtc::scoped_refptr<RtpSenderInterface> AddVideoTrack() { |
| 335 | return AddTrack(CreateLocalVideoTrack()); |
| 336 | } |
| 337 | |
| 338 | rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack() { |
| 339 | cricket::AudioOptions options; |
| 340 | // Disable highpass filter so that we can get all the test audio frames. |
| 341 | options.highpass_filter = false; |
| 342 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
| 343 | peer_connection_factory_->CreateAudioSource(options); |
| 344 | // TODO(perkj): Test audio source when it is implemented. Currently audio |
| 345 | // always use the default input. |
| 346 | return peer_connection_factory_->CreateAudioTrack(rtc::CreateRandomUuid(), |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 347 | source.get()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack() { |
| 351 | webrtc::FakePeriodicVideoSource::Config config; |
| 352 | config.timestamp_offset_ms = rtc::TimeMillis(); |
| 353 | return CreateLocalVideoTrackInternal(config); |
| 354 | } |
| 355 | |
| 356 | rtc::scoped_refptr<webrtc::VideoTrackInterface> |
| 357 | CreateLocalVideoTrackWithConfig( |
| 358 | webrtc::FakePeriodicVideoSource::Config config) { |
| 359 | return CreateLocalVideoTrackInternal(config); |
| 360 | } |
| 361 | |
| 362 | rtc::scoped_refptr<webrtc::VideoTrackInterface> |
| 363 | CreateLocalVideoTrackWithRotation(webrtc::VideoRotation rotation) { |
| 364 | webrtc::FakePeriodicVideoSource::Config config; |
| 365 | config.rotation = rotation; |
| 366 | config.timestamp_offset_ms = rtc::TimeMillis(); |
| 367 | return CreateLocalVideoTrackInternal(config); |
| 368 | } |
| 369 | |
| 370 | rtc::scoped_refptr<RtpSenderInterface> AddTrack( |
| 371 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 372 | const std::vector<std::string>& stream_ids = {}) { |
Harald Alvestrand | 8101e7b | 2022-05-23 14:57:47 | [diff] [blame] | 373 | EXPECT_TRUE(track); |
| 374 | if (!track) { |
| 375 | return nullptr; |
| 376 | } |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 377 | auto result = pc()->AddTrack(track, stream_ids); |
| 378 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
Harald Alvestrand | 8101e7b | 2022-05-23 14:57:47 | [diff] [blame] | 379 | if (result.ok()) { |
| 380 | return result.MoveValue(); |
| 381 | } else { |
| 382 | return nullptr; |
| 383 | } |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceiversOfType( |
| 387 | cricket::MediaType media_type) { |
| 388 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers; |
| 389 | for (const auto& receiver : pc()->GetReceivers()) { |
| 390 | if (receiver->media_type() == media_type) { |
| 391 | receivers.push_back(receiver); |
| 392 | } |
| 393 | } |
| 394 | return receivers; |
| 395 | } |
| 396 | |
| 397 | rtc::scoped_refptr<RtpTransceiverInterface> GetFirstTransceiverOfType( |
| 398 | cricket::MediaType media_type) { |
| 399 | for (auto transceiver : pc()->GetTransceivers()) { |
| 400 | if (transceiver->receiver()->media_type() == media_type) { |
| 401 | return transceiver; |
| 402 | } |
| 403 | } |
| 404 | return nullptr; |
| 405 | } |
| 406 | |
| 407 | bool SignalingStateStable() { |
| 408 | return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable; |
| 409 | } |
| 410 | |
Philipp Hancke | 1fe14f2 | 2022-06-17 09:34:31 | [diff] [blame] | 411 | bool IceGatheringStateComplete() { |
| 412 | return pc()->ice_gathering_state() == |
| 413 | webrtc::PeerConnectionInterface::kIceGatheringComplete; |
| 414 | } |
| 415 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 416 | void CreateDataChannel() { CreateDataChannel(nullptr); } |
| 417 | |
| 418 | void CreateDataChannel(const webrtc::DataChannelInit* init) { |
| 419 | CreateDataChannel(kDataChannelLabel, init); |
| 420 | } |
| 421 | |
| 422 | void CreateDataChannel(const std::string& label, |
| 423 | const webrtc::DataChannelInit* init) { |
Florent Castelli | 7242440 | 2022-04-06 01:45:10 | [diff] [blame] | 424 | auto data_channel_or_error = pc()->CreateDataChannelOrError(label, init); |
| 425 | ASSERT_TRUE(data_channel_or_error.ok()); |
| 426 | data_channels_.push_back(data_channel_or_error.MoveValue()); |
Harald Alvestrand | 06c87a1 | 2022-02-11 13:12:16 | [diff] [blame] | 427 | ASSERT_TRUE(data_channels_.back().get() != nullptr); |
| 428 | data_observers_.push_back( |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 429 | std::make_unique<MockDataChannelObserver>(data_channels_.back().get())); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 430 | } |
| 431 | |
Harald Alvestrand | 06c87a1 | 2022-02-11 13:12:16 | [diff] [blame] | 432 | // Return the last observed data channel. |
| 433 | DataChannelInterface* data_channel() { |
| 434 | if (data_channels_.size() == 0) { |
| 435 | return nullptr; |
| 436 | } |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 437 | return data_channels_.back().get(); |
Harald Alvestrand | 06c87a1 | 2022-02-11 13:12:16 | [diff] [blame] | 438 | } |
| 439 | // Return all data channels. |
Florent Castelli | d4d97eb | 2022-05-03 22:28:06 | [diff] [blame] | 440 | std::vector<rtc::scoped_refptr<DataChannelInterface>>& data_channels() { |
Harald Alvestrand | 06c87a1 | 2022-02-11 13:12:16 | [diff] [blame] | 441 | return data_channels_; |
| 442 | } |
| 443 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 444 | const MockDataChannelObserver* data_observer() const { |
Harald Alvestrand | 06c87a1 | 2022-02-11 13:12:16 | [diff] [blame] | 445 | if (data_observers_.size() == 0) { |
| 446 | return nullptr; |
| 447 | } |
| 448 | return data_observers_.back().get(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 449 | } |
| 450 | |
Florent Castelli | d4d97eb | 2022-05-03 22:28:06 | [diff] [blame] | 451 | std::vector<std::unique_ptr<MockDataChannelObserver>>& data_observers() { |
| 452 | return data_observers_; |
| 453 | } |
| 454 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 455 | int audio_frames_received() const { |
| 456 | return fake_audio_capture_module_->frames_received(); |
| 457 | } |
| 458 | |
| 459 | // Takes minimum of video frames received for each track. |
| 460 | // |
| 461 | // Can be used like: |
| 462 | // EXPECT_GE(expected_frames, min_video_frames_received_per_track()); |
| 463 | // |
| 464 | // To ensure that all video tracks received at least a certain number of |
| 465 | // frames. |
| 466 | int min_video_frames_received_per_track() const { |
| 467 | int min_frames = INT_MAX; |
| 468 | if (fake_video_renderers_.empty()) { |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | for (const auto& pair : fake_video_renderers_) { |
| 473 | min_frames = std::min(min_frames, pair.second->num_rendered_frames()); |
| 474 | } |
| 475 | return min_frames; |
| 476 | } |
| 477 | |
| 478 | // Returns a MockStatsObserver in a state after stats gathering finished, |
| 479 | // which can be used to access the gathered stats. |
| 480 | rtc::scoped_refptr<MockStatsObserver> OldGetStatsForTrack( |
| 481 | webrtc::MediaStreamTrackInterface* track) { |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 482 | auto observer = rtc::make_ref_counted<MockStatsObserver>(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 483 | EXPECT_TRUE(peer_connection_->GetStats( |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 484 | observer.get(), nullptr, |
| 485 | PeerConnectionInterface::kStatsOutputLevelStandard)); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 486 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 487 | return observer; |
| 488 | } |
| 489 | |
| 490 | // Version that doesn't take a track "filter", and gathers all stats. |
| 491 | rtc::scoped_refptr<MockStatsObserver> OldGetStats() { |
| 492 | return OldGetStatsForTrack(nullptr); |
| 493 | } |
| 494 | |
| 495 | // Synchronously gets stats and returns them. If it times out, fails the test |
| 496 | // and returns null. |
| 497 | rtc::scoped_refptr<const webrtc::RTCStatsReport> NewGetStats() { |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 498 | auto callback = |
| 499 | rtc::make_ref_counted<webrtc::MockRTCStatsCollectorCallback>(); |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 500 | peer_connection_->GetStats(callback.get()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 501 | EXPECT_TRUE_WAIT(callback->called(), kDefaultTimeout); |
| 502 | return callback->report(); |
| 503 | } |
| 504 | |
| 505 | int rendered_width() { |
| 506 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 507 | return fake_video_renderers_.empty() |
| 508 | ? 0 |
| 509 | : fake_video_renderers_.begin()->second->width(); |
| 510 | } |
| 511 | |
| 512 | int rendered_height() { |
| 513 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 514 | return fake_video_renderers_.empty() |
| 515 | ? 0 |
| 516 | : fake_video_renderers_.begin()->second->height(); |
| 517 | } |
| 518 | |
| 519 | double rendered_aspect_ratio() { |
| 520 | if (rendered_height() == 0) { |
| 521 | return 0.0; |
| 522 | } |
| 523 | return static_cast<double>(rendered_width()) / rendered_height(); |
| 524 | } |
| 525 | |
| 526 | webrtc::VideoRotation rendered_rotation() { |
| 527 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 528 | return fake_video_renderers_.empty() |
| 529 | ? webrtc::kVideoRotation_0 |
| 530 | : fake_video_renderers_.begin()->second->rotation(); |
| 531 | } |
| 532 | |
| 533 | int local_rendered_width() { |
| 534 | return local_video_renderer_ ? local_video_renderer_->width() : 0; |
| 535 | } |
| 536 | |
| 537 | int local_rendered_height() { |
| 538 | return local_video_renderer_ ? local_video_renderer_->height() : 0; |
| 539 | } |
| 540 | |
| 541 | double local_rendered_aspect_ratio() { |
| 542 | if (local_rendered_height() == 0) { |
| 543 | return 0.0; |
| 544 | } |
| 545 | return static_cast<double>(local_rendered_width()) / |
| 546 | local_rendered_height(); |
| 547 | } |
| 548 | |
| 549 | size_t number_of_remote_streams() { |
| 550 | if (!pc()) { |
| 551 | return 0; |
| 552 | } |
| 553 | return pc()->remote_streams()->count(); |
| 554 | } |
| 555 | |
| 556 | StreamCollectionInterface* remote_streams() const { |
| 557 | if (!pc()) { |
| 558 | ADD_FAILURE(); |
| 559 | return nullptr; |
| 560 | } |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 561 | return pc()->remote_streams().get(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | StreamCollectionInterface* local_streams() { |
| 565 | if (!pc()) { |
| 566 | ADD_FAILURE(); |
| 567 | return nullptr; |
| 568 | } |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 569 | return pc()->local_streams().get(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | webrtc::PeerConnectionInterface::SignalingState signaling_state() { |
| 573 | return pc()->signaling_state(); |
| 574 | } |
| 575 | |
| 576 | webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { |
| 577 | return pc()->ice_connection_state(); |
| 578 | } |
| 579 | |
| 580 | webrtc::PeerConnectionInterface::IceConnectionState |
| 581 | standardized_ice_connection_state() { |
| 582 | return pc()->standardized_ice_connection_state(); |
| 583 | } |
| 584 | |
| 585 | webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { |
| 586 | return pc()->ice_gathering_state(); |
| 587 | } |
| 588 | |
| 589 | // Returns a MockRtpReceiverObserver for each RtpReceiver returned by |
| 590 | // GetReceivers. They're updated automatically when a remote offer/answer |
| 591 | // from the fake signaling channel is applied, or when |
| 592 | // ResetRtpReceiverObservers below is called. |
| 593 | const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& |
| 594 | rtp_receiver_observers() { |
| 595 | return rtp_receiver_observers_; |
| 596 | } |
| 597 | |
| 598 | void ResetRtpReceiverObservers() { |
| 599 | rtp_receiver_observers_.clear(); |
| 600 | for (const rtc::scoped_refptr<RtpReceiverInterface>& receiver : |
| 601 | pc()->GetReceivers()) { |
| 602 | std::unique_ptr<MockRtpReceiverObserver> observer( |
| 603 | new MockRtpReceiverObserver(receiver->media_type())); |
| 604 | receiver->SetObserver(observer.get()); |
| 605 | rtp_receiver_observers_.push_back(std::move(observer)); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | rtc::FakeNetworkManager* network_manager() const { |
| 610 | return fake_network_manager_.get(); |
| 611 | } |
| 612 | cricket::PortAllocator* port_allocator() const { return port_allocator_; } |
| 613 | |
| 614 | webrtc::FakeRtcEventLogFactory* event_log_factory() const { |
| 615 | return event_log_factory_; |
| 616 | } |
| 617 | |
| 618 | const cricket::Candidate& last_candidate_gathered() const { |
| 619 | return last_candidate_gathered_; |
| 620 | } |
| 621 | const cricket::IceCandidateErrorEvent& error_event() const { |
| 622 | return error_event_; |
| 623 | } |
| 624 | |
| 625 | // Sets the mDNS responder for the owned fake network manager and keeps a |
| 626 | // reference to the responder. |
| 627 | void SetMdnsResponder( |
| 628 | std::unique_ptr<webrtc::FakeMdnsResponder> mdns_responder) { |
| 629 | RTC_DCHECK(mdns_responder != nullptr); |
| 630 | mdns_responder_ = mdns_responder.get(); |
| 631 | network_manager()->set_mdns_responder(std::move(mdns_responder)); |
| 632 | } |
| 633 | |
| 634 | // Returns null on failure. |
| 635 | std::unique_ptr<SessionDescriptionInterface> CreateOfferAndWait() { |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 636 | auto observer = |
| 637 | rtc::make_ref_counted<MockCreateSessionDescriptionObserver>(); |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 638 | pc()->CreateOffer(observer.get(), offer_answer_options_); |
| 639 | return WaitForDescriptionFromObserver(observer.get()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 640 | } |
| 641 | bool Rollback() { |
| 642 | return SetRemoteDescription( |
| 643 | webrtc::CreateSessionDescription(SdpType::kRollback, "")); |
| 644 | } |
| 645 | |
| 646 | // Functions for querying stats. |
| 647 | void StartWatchingDelayStats() { |
| 648 | // Get the baseline numbers for audio_packets and audio_delay. |
| 649 | auto received_stats = NewGetStats(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 650 | auto rtp_stats = |
| 651 | received_stats->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>()[0]; |
Henrik Boström | 2fb8307 | 2022-10-06 11:37:11 | [diff] [blame] | 652 | ASSERT_TRUE(rtp_stats->relative_packet_arrival_delay.is_defined()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 653 | ASSERT_TRUE(rtp_stats->packets_received.is_defined()); |
| 654 | ASSERT_TRUE(rtp_stats->track_id.is_defined()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 655 | rtp_stats_id_ = rtp_stats->id(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 656 | audio_packets_stat_ = *rtp_stats->packets_received; |
Henrik Boström | 2fb8307 | 2022-10-06 11:37:11 | [diff] [blame] | 657 | audio_delay_stat_ = *rtp_stats->relative_packet_arrival_delay; |
| 658 | audio_samples_stat_ = *rtp_stats->total_samples_received; |
| 659 | audio_concealed_stat_ = *rtp_stats->concealed_samples; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | void UpdateDelayStats(std::string tag, int desc_size) { |
| 663 | auto report = NewGetStats(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 664 | auto rtp_stats = |
| 665 | report->GetAs<webrtc::RTCInboundRTPStreamStats>(rtp_stats_id_); |
| 666 | ASSERT_TRUE(rtp_stats); |
| 667 | auto delta_packets = *rtp_stats->packets_received - audio_packets_stat_; |
| 668 | auto delta_rpad = |
Henrik Boström | 2fb8307 | 2022-10-06 11:37:11 | [diff] [blame] | 669 | *rtp_stats->relative_packet_arrival_delay - audio_delay_stat_; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 670 | auto recent_delay = delta_packets > 0 ? delta_rpad / delta_packets : -1; |
| 671 | // The purpose of these checks is to sound the alarm early if we introduce |
| 672 | // serious regressions. The numbers are not acceptable for production, but |
| 673 | // occur on slow bots. |
| 674 | // |
| 675 | // An average relative packet arrival delay over the renegotiation of |
| 676 | // > 100 ms indicates that something is dramatically wrong, and will impact |
| 677 | // quality for sure. |
| 678 | // Worst bots: |
| 679 | // linux_x86_dbg at 0.206 |
| 680 | #if !defined(NDEBUG) |
| 681 | EXPECT_GT(0.25, recent_delay) << tag << " size " << desc_size; |
| 682 | #else |
| 683 | EXPECT_GT(0.1, recent_delay) << tag << " size " << desc_size; |
| 684 | #endif |
| 685 | auto delta_samples = |
Henrik Boström | 2fb8307 | 2022-10-06 11:37:11 | [diff] [blame] | 686 | *rtp_stats->total_samples_received - audio_samples_stat_; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 687 | auto delta_concealed = |
Henrik Boström | 2fb8307 | 2022-10-06 11:37:11 | [diff] [blame] | 688 | *rtp_stats->concealed_samples - audio_concealed_stat_; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 689 | // These limits should be adjusted down as we improve: |
| 690 | // |
| 691 | // Concealing more than 4000 samples during a renegotiation is unacceptable. |
| 692 | // But some bots are slow. |
| 693 | |
| 694 | // Worst bots: |
| 695 | // linux_more_configs bot at conceal count 5184 |
| 696 | // android_arm_rel at conceal count 9241 |
| 697 | // linux_x86_dbg at 15174 |
| 698 | #if !defined(NDEBUG) |
| 699 | EXPECT_GT(18000U, delta_concealed) << "Concealed " << delta_concealed |
| 700 | << " of " << delta_samples << " samples"; |
| 701 | #else |
| 702 | EXPECT_GT(15000U, delta_concealed) << "Concealed " << delta_concealed |
| 703 | << " of " << delta_samples << " samples"; |
| 704 | #endif |
| 705 | // Concealing more than 20% of samples during a renegotiation is |
| 706 | // unacceptable. |
| 707 | // Worst bots: |
Harald Alvestrand | a52fc6f | 2021-11-05 11:45:08 | [diff] [blame] | 708 | // Nondebug: Linux32 Release at conceal rate 0.606597 (CI run) |
| 709 | // Debug: linux_x86_dbg bot at conceal rate 0.854 |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 710 | if (delta_samples > 0) { |
| 711 | #if !defined(NDEBUG) |
Harald Alvestrand | a52fc6f | 2021-11-05 11:45:08 | [diff] [blame] | 712 | EXPECT_LT(1.0 * delta_concealed / delta_samples, 0.95) |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 713 | << "Concealed " << delta_concealed << " of " << delta_samples |
| 714 | << " samples"; |
| 715 | #else |
Harald Alvestrand | a52fc6f | 2021-11-05 11:45:08 | [diff] [blame] | 716 | EXPECT_LT(1.0 * delta_concealed / delta_samples, 0.7) |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 717 | << "Concealed " << delta_concealed << " of " << delta_samples |
| 718 | << " samples"; |
| 719 | #endif |
| 720 | } |
| 721 | // Increment trailing counters |
| 722 | audio_packets_stat_ = *rtp_stats->packets_received; |
Henrik Boström | 2fb8307 | 2022-10-06 11:37:11 | [diff] [blame] | 723 | audio_delay_stat_ = *rtp_stats->relative_packet_arrival_delay; |
| 724 | audio_samples_stat_ = *rtp_stats->total_samples_received; |
| 725 | audio_concealed_stat_ = *rtp_stats->concealed_samples; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 726 | } |
| 727 | |
Taylor Brandstetter | 1c7ecef | 2021-08-11 19:38:35 | [diff] [blame] | 728 | // Sets number of candidates expected |
| 729 | void ExpectCandidates(int candidate_count) { |
| 730 | candidates_expected_ = candidate_count; |
| 731 | } |
| 732 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 733 | private: |
Niels Möller | 4f0a919 | 2021-09-03 06:54:06 | [diff] [blame] | 734 | // Constructor used by friend class PeerConnectionIntegrationBaseTest. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 735 | explicit PeerConnectionIntegrationWrapper(const std::string& debug_name) |
| 736 | : debug_name_(debug_name) {} |
| 737 | |
| 738 | bool Init(const PeerConnectionFactory::Options* options, |
| 739 | const PeerConnectionInterface::RTCConfiguration* config, |
| 740 | webrtc::PeerConnectionDependencies dependencies, |
Byoungchan Lee | d197e0b | 2022-05-30 14:59:55 | [diff] [blame] | 741 | rtc::SocketServer* socket_server, |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 742 | rtc::Thread* network_thread, |
| 743 | rtc::Thread* worker_thread, |
| 744 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory, |
| 745 | bool reset_encoder_factory, |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 | [diff] [blame] | 746 | bool reset_decoder_factory, |
| 747 | bool create_media_engine) { |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 748 | // There's an error in this test code if Init ends up being called twice. |
| 749 | RTC_DCHECK(!peer_connection_); |
| 750 | RTC_DCHECK(!peer_connection_factory_); |
| 751 | |
| 752 | fake_network_manager_.reset(new rtc::FakeNetworkManager()); |
| 753 | fake_network_manager_->AddInterface(kDefaultLocalAddress); |
| 754 | |
| 755 | std::unique_ptr<cricket::PortAllocator> port_allocator( |
Byoungchan Lee | d197e0b | 2022-05-30 14:59:55 | [diff] [blame] | 756 | new cricket::BasicPortAllocator( |
| 757 | fake_network_manager_.get(), |
| 758 | std::make_unique<rtc::BasicPacketSocketFactory>(socket_server))); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 759 | port_allocator_ = port_allocator.get(); |
| 760 | fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
| 761 | if (!fake_audio_capture_module_) { |
| 762 | return false; |
| 763 | } |
| 764 | rtc::Thread* const signaling_thread = rtc::Thread::Current(); |
| 765 | |
| 766 | webrtc::PeerConnectionFactoryDependencies pc_factory_dependencies; |
| 767 | pc_factory_dependencies.network_thread = network_thread; |
| 768 | pc_factory_dependencies.worker_thread = worker_thread; |
| 769 | pc_factory_dependencies.signaling_thread = signaling_thread; |
| 770 | pc_factory_dependencies.task_queue_factory = |
| 771 | webrtc::CreateDefaultTaskQueueFactory(); |
| 772 | pc_factory_dependencies.trials = std::make_unique<FieldTrialBasedConfig>(); |
Markus Handell | be400e4 | 2022-11-08 11:14:23 | [diff] [blame] | 773 | pc_factory_dependencies.metronome = |
| 774 | std::make_unique<TaskQueueMetronome>(TimeDelta::Millis(8)); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 775 | cricket::MediaEngineDependencies media_deps; |
| 776 | media_deps.task_queue_factory = |
| 777 | pc_factory_dependencies.task_queue_factory.get(); |
| 778 | media_deps.adm = fake_audio_capture_module_; |
| 779 | webrtc::SetMediaEngineDefaults(&media_deps); |
| 780 | |
| 781 | if (reset_encoder_factory) { |
| 782 | media_deps.video_encoder_factory.reset(); |
| 783 | } |
| 784 | if (reset_decoder_factory) { |
| 785 | media_deps.video_decoder_factory.reset(); |
| 786 | } |
| 787 | |
| 788 | if (!media_deps.audio_processing) { |
| 789 | // If the standard Creation method for APM returns a null pointer, instead |
| 790 | // use the builder for testing to create an APM object. |
| 791 | media_deps.audio_processing = AudioProcessingBuilderForTesting().Create(); |
| 792 | } |
| 793 | |
| 794 | media_deps.trials = pc_factory_dependencies.trials.get(); |
| 795 | |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 | [diff] [blame] | 796 | if (create_media_engine) { |
| 797 | pc_factory_dependencies.media_engine = |
| 798 | cricket::CreateMediaEngine(std::move(media_deps)); |
| 799 | } |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 800 | pc_factory_dependencies.call_factory = webrtc::CreateCallFactory(); |
| 801 | if (event_log_factory) { |
| 802 | event_log_factory_ = event_log_factory.get(); |
| 803 | pc_factory_dependencies.event_log_factory = std::move(event_log_factory); |
| 804 | } else { |
| 805 | pc_factory_dependencies.event_log_factory = |
| 806 | std::make_unique<webrtc::RtcEventLogFactory>( |
| 807 | pc_factory_dependencies.task_queue_factory.get()); |
| 808 | } |
| 809 | peer_connection_factory_ = webrtc::CreateModularPeerConnectionFactory( |
| 810 | std::move(pc_factory_dependencies)); |
| 811 | |
| 812 | if (!peer_connection_factory_) { |
| 813 | return false; |
| 814 | } |
| 815 | if (options) { |
| 816 | peer_connection_factory_->SetOptions(*options); |
| 817 | } |
| 818 | if (config) { |
| 819 | sdp_semantics_ = config->sdp_semantics; |
| 820 | } |
| 821 | |
| 822 | dependencies.allocator = std::move(port_allocator); |
| 823 | peer_connection_ = CreatePeerConnection(config, std::move(dependencies)); |
| 824 | return peer_connection_.get() != nullptr; |
| 825 | } |
| 826 | |
| 827 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
| 828 | const PeerConnectionInterface::RTCConfiguration* config, |
| 829 | webrtc::PeerConnectionDependencies dependencies) { |
| 830 | PeerConnectionInterface::RTCConfiguration modified_config; |
Henrik Boström | 62995db | 2022-01-03 08:58:10 | [diff] [blame] | 831 | modified_config.sdp_semantics = sdp_semantics_; |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 832 | // If `config` is null, this will result in a default configuration being |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 833 | // used. |
| 834 | if (config) { |
| 835 | modified_config = *config; |
| 836 | } |
| 837 | // Disable resolution adaptation; we don't want it interfering with the |
| 838 | // test results. |
| 839 | // TODO(deadbeef): Do something more robust. Since we're testing for aspect |
| 840 | // ratios and not specific resolutions, is this even necessary? |
| 841 | modified_config.set_cpu_adaptation(false); |
| 842 | |
| 843 | dependencies.observer = this; |
Florent Castelli | 7242440 | 2022-04-06 01:45:10 | [diff] [blame] | 844 | auto peer_connection_or_error = |
| 845 | peer_connection_factory_->CreatePeerConnectionOrError( |
| 846 | modified_config, std::move(dependencies)); |
| 847 | return peer_connection_or_error.ok() ? peer_connection_or_error.MoveValue() |
| 848 | : nullptr; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | void set_signaling_message_receiver( |
| 852 | SignalingMessageReceiver* signaling_message_receiver) { |
| 853 | signaling_message_receiver_ = signaling_message_receiver; |
| 854 | } |
| 855 | |
| 856 | void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; } |
| 857 | |
| 858 | void set_signal_ice_candidates(bool signal) { |
| 859 | signal_ice_candidates_ = signal; |
| 860 | } |
| 861 | |
| 862 | rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrackInternal( |
| 863 | webrtc::FakePeriodicVideoSource::Config config) { |
| 864 | // Set max frame rate to 10fps to reduce the risk of test flakiness. |
| 865 | // TODO(deadbeef): Do something more robust. |
| 866 | config.frame_interval_ms = 100; |
| 867 | |
| 868 | video_track_sources_.emplace_back( |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 869 | rtc::make_ref_counted<webrtc::FakePeriodicVideoTrackSource>( |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 870 | config, false /* remote */)); |
| 871 | rtc::scoped_refptr<webrtc::VideoTrackInterface> track( |
| 872 | peer_connection_factory_->CreateVideoTrack( |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 873 | rtc::CreateRandomUuid(), video_track_sources_.back().get())); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 874 | if (!local_video_renderer_) { |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 875 | local_video_renderer_.reset( |
| 876 | new webrtc::FakeVideoTrackRenderer(track.get())); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 877 | } |
| 878 | return track; |
| 879 | } |
| 880 | |
| 881 | void HandleIncomingOffer(const std::string& msg) { |
| 882 | RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingOffer"; |
| 883 | std::unique_ptr<SessionDescriptionInterface> desc = |
| 884 | webrtc::CreateSessionDescription(SdpType::kOffer, msg); |
| 885 | if (received_sdp_munger_) { |
| 886 | received_sdp_munger_(desc->description()); |
| 887 | } |
| 888 | |
| 889 | EXPECT_TRUE(SetRemoteDescription(std::move(desc))); |
| 890 | // Setting a remote description may have changed the number of receivers, |
| 891 | // so reset the receiver observers. |
| 892 | ResetRtpReceiverObservers(); |
| 893 | if (remote_offer_handler_) { |
| 894 | remote_offer_handler_(); |
| 895 | } |
| 896 | auto answer = CreateAnswer(); |
| 897 | ASSERT_NE(nullptr, answer); |
| 898 | EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(answer))); |
| 899 | } |
| 900 | |
| 901 | void HandleIncomingAnswer(const std::string& msg) { |
| 902 | RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingAnswer"; |
| 903 | std::unique_ptr<SessionDescriptionInterface> desc = |
| 904 | webrtc::CreateSessionDescription(SdpType::kAnswer, msg); |
| 905 | if (received_sdp_munger_) { |
| 906 | received_sdp_munger_(desc->description()); |
| 907 | } |
| 908 | |
| 909 | EXPECT_TRUE(SetRemoteDescription(std::move(desc))); |
| 910 | // Set the RtpReceiverObserver after receivers are created. |
| 911 | ResetRtpReceiverObservers(); |
| 912 | } |
| 913 | |
| 914 | // Returns null on failure. |
| 915 | std::unique_ptr<SessionDescriptionInterface> CreateAnswer() { |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 916 | auto observer = |
| 917 | rtc::make_ref_counted<MockCreateSessionDescriptionObserver>(); |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 918 | pc()->CreateAnswer(observer.get(), offer_answer_options_); |
| 919 | return WaitForDescriptionFromObserver(observer.get()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | std::unique_ptr<SessionDescriptionInterface> WaitForDescriptionFromObserver( |
| 923 | MockCreateSessionDescriptionObserver* observer) { |
| 924 | EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout); |
| 925 | if (!observer->result()) { |
| 926 | return nullptr; |
| 927 | } |
| 928 | auto description = observer->MoveDescription(); |
| 929 | if (generated_sdp_munger_) { |
| 930 | generated_sdp_munger_(description->description()); |
| 931 | } |
| 932 | return description; |
| 933 | } |
| 934 | |
| 935 | // Setting the local description and sending the SDP message over the fake |
| 936 | // signaling channel are combined into the same method because the SDP |
| 937 | // message needs to be sent as soon as SetLocalDescription finishes, without |
| 938 | // waiting for the observer to be called. This ensures that ICE candidates |
| 939 | // don't outrace the description. |
| 940 | bool SetLocalDescriptionAndSendSdpMessage( |
| 941 | std::unique_ptr<SessionDescriptionInterface> desc) { |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 942 | auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 943 | RTC_LOG(LS_INFO) << debug_name_ << ": SetLocalDescriptionAndSendSdpMessage"; |
| 944 | SdpType type = desc->GetType(); |
| 945 | std::string sdp; |
| 946 | EXPECT_TRUE(desc->ToString(&sdp)); |
| 947 | RTC_LOG(LS_INFO) << debug_name_ << ": local SDP contents=\n" << sdp; |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 948 | pc()->SetLocalDescription(observer.get(), desc.release()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 949 | RemoveUnusedVideoRenderers(); |
| 950 | // As mentioned above, we need to send the message immediately after |
| 951 | // SetLocalDescription. |
| 952 | SendSdpMessage(type, sdp); |
| 953 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 954 | return true; |
| 955 | } |
| 956 | |
| 957 | bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc) { |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 958 | auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 959 | RTC_LOG(LS_INFO) << debug_name_ << ": SetRemoteDescription"; |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 960 | pc()->SetRemoteDescription(observer.get(), desc.release()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 961 | RemoveUnusedVideoRenderers(); |
| 962 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 963 | return observer->result(); |
| 964 | } |
| 965 | |
| 966 | // This is a work around to remove unused fake_video_renderers from |
| 967 | // transceivers that have either stopped or are no longer receiving. |
| 968 | void RemoveUnusedVideoRenderers() { |
| 969 | if (sdp_semantics_ != SdpSemantics::kUnifiedPlan) { |
| 970 | return; |
| 971 | } |
| 972 | auto transceivers = pc()->GetTransceivers(); |
| 973 | std::set<std::string> active_renderers; |
| 974 | for (auto& transceiver : transceivers) { |
| 975 | // Note - we don't check for direction here. This function is called |
| 976 | // before direction is set, and in that case, we should not remove |
| 977 | // the renderer. |
| 978 | if (transceiver->receiver()->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 979 | active_renderers.insert(transceiver->receiver()->track()->id()); |
| 980 | } |
| 981 | } |
| 982 | for (auto it = fake_video_renderers_.begin(); |
| 983 | it != fake_video_renderers_.end();) { |
| 984 | // Remove fake video renderers belonging to any non-active transceivers. |
| 985 | if (!active_renderers.count(it->first)) { |
| 986 | it = fake_video_renderers_.erase(it); |
| 987 | } else { |
| 988 | it++; |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 993 | // Simulate sending a blob of SDP with delay `signaling_delay_ms_` (0 by |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 994 | // default). |
| 995 | void SendSdpMessage(SdpType type, const std::string& msg) { |
| 996 | if (signaling_delay_ms_ == 0) { |
| 997 | RelaySdpMessageIfReceiverExists(type, msg); |
| 998 | } else { |
Niels Möller | 6097b0f | 2021-03-11 15:46:27 | [diff] [blame] | 999 | rtc::Thread::Current()->PostDelayedTask( |
Danil Chapovalov | a30439b | 2022-07-07 08:08:49 | [diff] [blame] | 1000 | SafeTask(task_safety_.flag(), |
| 1001 | [this, type, msg] { |
| 1002 | RelaySdpMessageIfReceiverExists(type, msg); |
| 1003 | }), |
| 1004 | TimeDelta::Millis(signaling_delay_ms_)); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | void RelaySdpMessageIfReceiverExists(SdpType type, const std::string& msg) { |
| 1009 | if (signaling_message_receiver_) { |
| 1010 | signaling_message_receiver_->ReceiveSdpMessage(type, msg); |
| 1011 | } |
| 1012 | } |
| 1013 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1014 | // Simulate trickling an ICE candidate with delay `signaling_delay_ms_` (0 by |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1015 | // default). |
| 1016 | void SendIceMessage(const std::string& sdp_mid, |
| 1017 | int sdp_mline_index, |
| 1018 | const std::string& msg) { |
| 1019 | if (signaling_delay_ms_ == 0) { |
| 1020 | RelayIceMessageIfReceiverExists(sdp_mid, sdp_mline_index, msg); |
| 1021 | } else { |
Niels Möller | 6097b0f | 2021-03-11 15:46:27 | [diff] [blame] | 1022 | rtc::Thread::Current()->PostDelayedTask( |
Danil Chapovalov | a30439b | 2022-07-07 08:08:49 | [diff] [blame] | 1023 | SafeTask(task_safety_.flag(), |
| 1024 | [this, sdp_mid, sdp_mline_index, msg] { |
| 1025 | RelayIceMessageIfReceiverExists(sdp_mid, sdp_mline_index, |
| 1026 | msg); |
| 1027 | }), |
| 1028 | TimeDelta::Millis(signaling_delay_ms_)); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | void RelayIceMessageIfReceiverExists(const std::string& sdp_mid, |
| 1033 | int sdp_mline_index, |
| 1034 | const std::string& msg) { |
| 1035 | if (signaling_message_receiver_) { |
| 1036 | signaling_message_receiver_->ReceiveIceMessage(sdp_mid, sdp_mline_index, |
| 1037 | msg); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | // SignalingMessageReceiver callbacks. |
| 1042 | void ReceiveSdpMessage(SdpType type, const std::string& msg) override { |
| 1043 | if (type == SdpType::kOffer) { |
| 1044 | HandleIncomingOffer(msg); |
| 1045 | } else { |
| 1046 | HandleIncomingAnswer(msg); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | void ReceiveIceMessage(const std::string& sdp_mid, |
| 1051 | int sdp_mline_index, |
| 1052 | const std::string& msg) override { |
| 1053 | RTC_LOG(LS_INFO) << debug_name_ << ": ReceiveIceMessage"; |
Niels Möller | 7ee4594 | 2022-05-05 07:30:35 | [diff] [blame] | 1054 | absl::optional<RTCError> result; |
| 1055 | pc()->AddIceCandidate(absl::WrapUnique(webrtc::CreateIceCandidate( |
| 1056 | sdp_mid, sdp_mline_index, msg, nullptr)), |
| 1057 | [&result](RTCError r) { result = r; }); |
| 1058 | EXPECT_TRUE_WAIT(result.has_value(), kDefaultTimeout); |
| 1059 | EXPECT_TRUE(result.value().ok()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | // PeerConnectionObserver callbacks. |
| 1063 | void OnSignalingChange( |
| 1064 | webrtc::PeerConnectionInterface::SignalingState new_state) override { |
| 1065 | EXPECT_EQ(pc()->signaling_state(), new_state); |
| 1066 | peer_connection_signaling_state_history_.push_back(new_state); |
| 1067 | } |
| 1068 | void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver, |
| 1069 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& |
| 1070 | streams) override { |
| 1071 | if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 1072 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
| 1073 | static_cast<VideoTrackInterface*>(receiver->track().get())); |
| 1074 | ASSERT_TRUE(fake_video_renderers_.find(video_track->id()) == |
| 1075 | fake_video_renderers_.end()); |
| 1076 | fake_video_renderers_[video_track->id()] = |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 1077 | std::make_unique<FakeVideoTrackRenderer>(video_track.get()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | void OnRemoveTrack( |
| 1081 | rtc::scoped_refptr<RtpReceiverInterface> receiver) override { |
| 1082 | if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 1083 | auto it = fake_video_renderers_.find(receiver->track()->id()); |
| 1084 | if (it != fake_video_renderers_.end()) { |
| 1085 | fake_video_renderers_.erase(it); |
| 1086 | } else { |
| 1087 | RTC_LOG(LS_ERROR) << "OnRemoveTrack called for non-active renderer"; |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | void OnRenegotiationNeeded() override {} |
| 1092 | void OnIceConnectionChange( |
| 1093 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 1094 | EXPECT_EQ(pc()->ice_connection_state(), new_state); |
| 1095 | ice_connection_state_history_.push_back(new_state); |
| 1096 | } |
| 1097 | void OnStandardizedIceConnectionChange( |
| 1098 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 1099 | standardized_ice_connection_state_history_.push_back(new_state); |
| 1100 | } |
| 1101 | void OnConnectionChange( |
| 1102 | webrtc::PeerConnectionInterface::PeerConnectionState new_state) override { |
| 1103 | peer_connection_state_history_.push_back(new_state); |
| 1104 | } |
| 1105 | |
| 1106 | void OnIceGatheringChange( |
| 1107 | webrtc::PeerConnectionInterface::IceGatheringState new_state) override { |
| 1108 | EXPECT_EQ(pc()->ice_gathering_state(), new_state); |
| 1109 | ice_gathering_state_history_.push_back(new_state); |
| 1110 | } |
| 1111 | |
| 1112 | void OnIceSelectedCandidatePairChanged( |
| 1113 | const cricket::CandidatePairChangeEvent& event) { |
| 1114 | ice_candidate_pair_change_history_.push_back(event); |
| 1115 | } |
| 1116 | |
| 1117 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
| 1118 | RTC_LOG(LS_INFO) << debug_name_ << ": OnIceCandidate"; |
| 1119 | |
| 1120 | if (remote_async_resolver_) { |
| 1121 | const auto& local_candidate = candidate->candidate(); |
| 1122 | if (local_candidate.address().IsUnresolvedIP()) { |
| 1123 | RTC_DCHECK(local_candidate.type() == cricket::LOCAL_PORT_TYPE); |
| 1124 | rtc::SocketAddress resolved_addr(local_candidate.address()); |
| 1125 | const auto resolved_ip = mdns_responder_->GetMappedAddressForName( |
| 1126 | local_candidate.address().hostname()); |
| 1127 | RTC_DCHECK(!resolved_ip.IsNil()); |
| 1128 | resolved_addr.SetResolvedIP(resolved_ip); |
| 1129 | EXPECT_CALL(*remote_async_resolver_, GetResolvedAddress(_, _)) |
| 1130 | .WillOnce(DoAll(SetArgPointee<1>(resolved_addr), Return(true))); |
| 1131 | EXPECT_CALL(*remote_async_resolver_, Destroy(_)); |
| 1132 | } |
| 1133 | } |
| 1134 | |
Taylor Brandstetter | 1c7ecef | 2021-08-11 19:38:35 | [diff] [blame] | 1135 | // Check if we expected to have a candidate. |
| 1136 | EXPECT_GT(candidates_expected_, 1); |
| 1137 | candidates_expected_--; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1138 | std::string ice_sdp; |
| 1139 | EXPECT_TRUE(candidate->ToString(&ice_sdp)); |
| 1140 | if (signaling_message_receiver_ == nullptr || !signal_ice_candidates_) { |
| 1141 | // Remote party may be deleted. |
| 1142 | return; |
| 1143 | } |
| 1144 | SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp); |
| 1145 | last_candidate_gathered_ = candidate->candidate(); |
| 1146 | } |
| 1147 | void OnIceCandidateError(const std::string& address, |
| 1148 | int port, |
| 1149 | const std::string& url, |
| 1150 | int error_code, |
| 1151 | const std::string& error_text) override { |
| 1152 | error_event_ = cricket::IceCandidateErrorEvent(address, port, url, |
| 1153 | error_code, error_text); |
| 1154 | } |
| 1155 | void OnDataChannel( |
| 1156 | rtc::scoped_refptr<DataChannelInterface> data_channel) override { |
| 1157 | RTC_LOG(LS_INFO) << debug_name_ << ": OnDataChannel"; |
Harald Alvestrand | 06c87a1 | 2022-02-11 13:12:16 | [diff] [blame] | 1158 | data_channels_.push_back(data_channel); |
| 1159 | data_observers_.push_back( |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 1160 | std::make_unique<MockDataChannelObserver>(data_channel.get())); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | std::string debug_name_; |
| 1164 | |
| 1165 | std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_; |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1166 | // Reference to the mDNS responder owned by `fake_network_manager_` after set. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1167 | webrtc::FakeMdnsResponder* mdns_responder_ = nullptr; |
| 1168 | |
| 1169 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 1170 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
| 1171 | peer_connection_factory_; |
| 1172 | |
| 1173 | cricket::PortAllocator* port_allocator_; |
| 1174 | // Needed to keep track of number of frames sent. |
| 1175 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
| 1176 | // Needed to keep track of number of frames received. |
| 1177 | std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 1178 | fake_video_renderers_; |
| 1179 | // Needed to ensure frames aren't received for removed tracks. |
| 1180 | std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 1181 | removed_fake_video_renderers_; |
| 1182 | |
| 1183 | // For remote peer communication. |
| 1184 | SignalingMessageReceiver* signaling_message_receiver_ = nullptr; |
| 1185 | int signaling_delay_ms_ = 0; |
| 1186 | bool signal_ice_candidates_ = true; |
| 1187 | cricket::Candidate last_candidate_gathered_; |
| 1188 | cricket::IceCandidateErrorEvent error_event_; |
| 1189 | |
| 1190 | // Store references to the video sources we've created, so that we can stop |
| 1191 | // them, if required. |
| 1192 | std::vector<rtc::scoped_refptr<webrtc::VideoTrackSource>> |
| 1193 | video_track_sources_; |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1194 | // `local_video_renderer_` attached to the first created local video track. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1195 | std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_; |
| 1196 | |
| 1197 | SdpSemantics sdp_semantics_; |
| 1198 | PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; |
| 1199 | std::function<void(cricket::SessionDescription*)> received_sdp_munger_; |
| 1200 | std::function<void(cricket::SessionDescription*)> generated_sdp_munger_; |
| 1201 | std::function<void()> remote_offer_handler_; |
| 1202 | rtc::MockAsyncResolver* remote_async_resolver_ = nullptr; |
Harald Alvestrand | 06c87a1 | 2022-02-11 13:12:16 | [diff] [blame] | 1203 | // All data channels either created or observed on this peerconnection |
| 1204 | std::vector<rtc::scoped_refptr<DataChannelInterface>> data_channels_; |
| 1205 | std::vector<std::unique_ptr<MockDataChannelObserver>> data_observers_; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1206 | |
| 1207 | std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_; |
| 1208 | |
| 1209 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1210 | ice_connection_state_history_; |
| 1211 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1212 | standardized_ice_connection_state_history_; |
| 1213 | std::vector<PeerConnectionInterface::PeerConnectionState> |
| 1214 | peer_connection_state_history_; |
| 1215 | std::vector<PeerConnectionInterface::IceGatheringState> |
| 1216 | ice_gathering_state_history_; |
| 1217 | std::vector<cricket::CandidatePairChangeEvent> |
| 1218 | ice_candidate_pair_change_history_; |
| 1219 | std::vector<PeerConnectionInterface::SignalingState> |
| 1220 | peer_connection_signaling_state_history_; |
| 1221 | webrtc::FakeRtcEventLogFactory* event_log_factory_; |
| 1222 | |
Taylor Brandstetter | 1c7ecef | 2021-08-11 19:38:35 | [diff] [blame] | 1223 | // Number of ICE candidates expected. The default is no limit. |
| 1224 | int candidates_expected_ = std::numeric_limits<int>::max(); |
| 1225 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1226 | // Variables for tracking delay stats on an audio track |
| 1227 | int audio_packets_stat_ = 0; |
| 1228 | double audio_delay_stat_ = 0.0; |
| 1229 | uint64_t audio_samples_stat_ = 0; |
| 1230 | uint64_t audio_concealed_stat_ = 0; |
| 1231 | std::string rtp_stats_id_; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1232 | |
Niels Möller | 6097b0f | 2021-03-11 15:46:27 | [diff] [blame] | 1233 | ScopedTaskSafety task_safety_; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1234 | |
| 1235 | friend class PeerConnectionIntegrationBaseTest; |
| 1236 | }; |
| 1237 | |
| 1238 | class MockRtcEventLogOutput : public webrtc::RtcEventLogOutput { |
| 1239 | public: |
| 1240 | virtual ~MockRtcEventLogOutput() = default; |
| 1241 | MOCK_METHOD(bool, IsActive, (), (const, override)); |
Björn Terelius | 63299a3 | 2022-07-05 08:58:52 | [diff] [blame] | 1242 | MOCK_METHOD(bool, Write, (absl::string_view), (override)); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1243 | }; |
| 1244 | |
| 1245 | // This helper object is used for both specifying how many audio/video frames |
| 1246 | // are expected to be received for a caller/callee. It provides helper functions |
| 1247 | // to specify these expectations. The object initially starts in a state of no |
| 1248 | // expectations. |
| 1249 | class MediaExpectations { |
| 1250 | public: |
| 1251 | enum ExpectFrames { |
| 1252 | kExpectSomeFrames, |
| 1253 | kExpectNoFrames, |
| 1254 | kNoExpectation, |
| 1255 | }; |
| 1256 | |
| 1257 | void ExpectBidirectionalAudioAndVideo() { |
| 1258 | ExpectBidirectionalAudio(); |
| 1259 | ExpectBidirectionalVideo(); |
| 1260 | } |
| 1261 | |
| 1262 | void ExpectBidirectionalAudio() { |
| 1263 | CallerExpectsSomeAudio(); |
| 1264 | CalleeExpectsSomeAudio(); |
| 1265 | } |
| 1266 | |
| 1267 | void ExpectNoAudio() { |
| 1268 | CallerExpectsNoAudio(); |
| 1269 | CalleeExpectsNoAudio(); |
| 1270 | } |
| 1271 | |
| 1272 | void ExpectBidirectionalVideo() { |
| 1273 | CallerExpectsSomeVideo(); |
| 1274 | CalleeExpectsSomeVideo(); |
| 1275 | } |
| 1276 | |
| 1277 | void ExpectNoVideo() { |
| 1278 | CallerExpectsNoVideo(); |
| 1279 | CalleeExpectsNoVideo(); |
| 1280 | } |
| 1281 | |
| 1282 | void CallerExpectsSomeAudioAndVideo() { |
| 1283 | CallerExpectsSomeAudio(); |
| 1284 | CallerExpectsSomeVideo(); |
| 1285 | } |
| 1286 | |
| 1287 | void CalleeExpectsSomeAudioAndVideo() { |
| 1288 | CalleeExpectsSomeAudio(); |
| 1289 | CalleeExpectsSomeVideo(); |
| 1290 | } |
| 1291 | |
| 1292 | // Caller's audio functions. |
| 1293 | void CallerExpectsSomeAudio( |
| 1294 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1295 | caller_audio_expectation_ = kExpectSomeFrames; |
| 1296 | caller_audio_frames_expected_ = expected_audio_frames; |
| 1297 | } |
| 1298 | |
| 1299 | void CallerExpectsNoAudio() { |
| 1300 | caller_audio_expectation_ = kExpectNoFrames; |
| 1301 | caller_audio_frames_expected_ = 0; |
| 1302 | } |
| 1303 | |
| 1304 | // Caller's video functions. |
| 1305 | void CallerExpectsSomeVideo( |
| 1306 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1307 | caller_video_expectation_ = kExpectSomeFrames; |
| 1308 | caller_video_frames_expected_ = expected_video_frames; |
| 1309 | } |
| 1310 | |
| 1311 | void CallerExpectsNoVideo() { |
| 1312 | caller_video_expectation_ = kExpectNoFrames; |
| 1313 | caller_video_frames_expected_ = 0; |
| 1314 | } |
| 1315 | |
| 1316 | // Callee's audio functions. |
| 1317 | void CalleeExpectsSomeAudio( |
| 1318 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1319 | callee_audio_expectation_ = kExpectSomeFrames; |
| 1320 | callee_audio_frames_expected_ = expected_audio_frames; |
| 1321 | } |
| 1322 | |
| 1323 | void CalleeExpectsNoAudio() { |
| 1324 | callee_audio_expectation_ = kExpectNoFrames; |
| 1325 | callee_audio_frames_expected_ = 0; |
| 1326 | } |
| 1327 | |
| 1328 | // Callee's video functions. |
| 1329 | void CalleeExpectsSomeVideo( |
| 1330 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1331 | callee_video_expectation_ = kExpectSomeFrames; |
| 1332 | callee_video_frames_expected_ = expected_video_frames; |
| 1333 | } |
| 1334 | |
| 1335 | void CalleeExpectsNoVideo() { |
| 1336 | callee_video_expectation_ = kExpectNoFrames; |
| 1337 | callee_video_frames_expected_ = 0; |
| 1338 | } |
| 1339 | |
| 1340 | ExpectFrames caller_audio_expectation_ = kNoExpectation; |
| 1341 | ExpectFrames caller_video_expectation_ = kNoExpectation; |
| 1342 | ExpectFrames callee_audio_expectation_ = kNoExpectation; |
| 1343 | ExpectFrames callee_video_expectation_ = kNoExpectation; |
| 1344 | int caller_audio_frames_expected_ = 0; |
| 1345 | int caller_video_frames_expected_ = 0; |
| 1346 | int callee_audio_frames_expected_ = 0; |
| 1347 | int callee_video_frames_expected_ = 0; |
| 1348 | }; |
| 1349 | |
| 1350 | class MockIceTransport : public webrtc::IceTransportInterface { |
| 1351 | public: |
| 1352 | MockIceTransport(const std::string& name, int component) |
| 1353 | : internal_(std::make_unique<cricket::FakeIceTransport>( |
| 1354 | name, |
| 1355 | component, |
| 1356 | nullptr /* network_thread */)) {} |
| 1357 | ~MockIceTransport() = default; |
| 1358 | cricket::IceTransportInternal* internal() { return internal_.get(); } |
| 1359 | |
| 1360 | private: |
| 1361 | std::unique_ptr<cricket::FakeIceTransport> internal_; |
| 1362 | }; |
| 1363 | |
| 1364 | class MockIceTransportFactory : public IceTransportFactory { |
| 1365 | public: |
| 1366 | ~MockIceTransportFactory() override = default; |
| 1367 | rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 1368 | const std::string& transport_name, |
| 1369 | int component, |
| 1370 | IceTransportInit init) { |
| 1371 | RecordIceTransportCreated(); |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 1372 | return rtc::make_ref_counted<MockIceTransport>(transport_name, component); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1373 | } |
| 1374 | MOCK_METHOD(void, RecordIceTransportCreated, ()); |
| 1375 | }; |
| 1376 | |
| 1377 | // Tests two PeerConnections connecting to each other end-to-end, using a |
| 1378 | // virtual network, fake A/V capture and fake encoder/decoders. The |
| 1379 | // PeerConnections share the threads/socket servers, but use separate versions |
| 1380 | // of everything else (including "PeerConnectionFactory"s). |
| 1381 | class PeerConnectionIntegrationBaseTest : public ::testing::Test { |
| 1382 | public: |
Florent Castelli | a6983c6 | 2021-05-06 08:50:07 | [diff] [blame] | 1383 | PeerConnectionIntegrationBaseTest( |
| 1384 | SdpSemantics sdp_semantics, |
| 1385 | absl::optional<std::string> field_trials = absl::nullopt) |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1386 | : sdp_semantics_(sdp_semantics), |
| 1387 | ss_(new rtc::VirtualSocketServer()), |
| 1388 | fss_(new rtc::FirewallSocketServer(ss_.get())), |
| 1389 | network_thread_(new rtc::Thread(fss_.get())), |
Florent Castelli | a6983c6 | 2021-05-06 08:50:07 | [diff] [blame] | 1390 | worker_thread_(rtc::Thread::Create()), |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 1391 | // TODO(bugs.webrtc.org/10335): Pass optional ScopedKeyValueConfig. |
| 1392 | field_trials_(new test::ScopedKeyValueConfig( |
| 1393 | field_trials.has_value() ? *field_trials : "")) { |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1394 | network_thread_->SetName("PCNetworkThread", this); |
| 1395 | worker_thread_->SetName("PCWorkerThread", this); |
| 1396 | RTC_CHECK(network_thread_->Start()); |
| 1397 | RTC_CHECK(worker_thread_->Start()); |
| 1398 | webrtc::metrics::Reset(); |
| 1399 | } |
| 1400 | |
| 1401 | ~PeerConnectionIntegrationBaseTest() { |
| 1402 | // The PeerConnections should be deleted before the TurnCustomizers. |
| 1403 | // A TurnPort is created with a raw pointer to a TurnCustomizer. The |
| 1404 | // TurnPort has the same lifetime as the PeerConnection, so it's expected |
| 1405 | // that the TurnCustomizer outlives the life of the PeerConnection or else |
| 1406 | // when Send() is called it will hit a seg fault. |
| 1407 | if (caller_) { |
| 1408 | caller_->set_signaling_message_receiver(nullptr); |
Tomas Gunnarsson | 2efb8a5 | 2021-04-01 14:26:57 | [diff] [blame] | 1409 | caller_->pc()->Close(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1410 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
| 1411 | } |
| 1412 | if (callee_) { |
| 1413 | callee_->set_signaling_message_receiver(nullptr); |
Tomas Gunnarsson | 2efb8a5 | 2021-04-01 14:26:57 | [diff] [blame] | 1414 | callee_->pc()->Close(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1415 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
| 1416 | } |
| 1417 | |
| 1418 | // If turn servers were created for the test they need to be destroyed on |
| 1419 | // the network thread. |
Danil Chapovalov | 2aaef45 | 2022-08-12 13:55:11 | [diff] [blame] | 1420 | SendTask(network_thread(), [this] { |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1421 | turn_servers_.clear(); |
| 1422 | turn_customizers_.clear(); |
| 1423 | }); |
| 1424 | } |
| 1425 | |
| 1426 | bool SignalingStateStable() { |
| 1427 | return caller_->SignalingStateStable() && callee_->SignalingStateStable(); |
| 1428 | } |
| 1429 | |
| 1430 | bool DtlsConnected() { |
| 1431 | // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS |
| 1432 | // are connected. This is an important distinction. Once we have separate |
| 1433 | // ICE and DTLS state, this check needs to use the DTLS state. |
| 1434 | return (callee()->ice_connection_state() == |
| 1435 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1436 | callee()->ice_connection_state() == |
| 1437 | webrtc::PeerConnectionInterface::kIceConnectionCompleted) && |
| 1438 | (caller()->ice_connection_state() == |
| 1439 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1440 | caller()->ice_connection_state() == |
| 1441 | webrtc::PeerConnectionInterface::kIceConnectionCompleted); |
| 1442 | } |
| 1443 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1444 | // When `event_log_factory` is null, the default implementation of the event |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1445 | // log factory will be used. |
| 1446 | std::unique_ptr<PeerConnectionIntegrationWrapper> CreatePeerConnectionWrapper( |
| 1447 | const std::string& debug_name, |
| 1448 | const PeerConnectionFactory::Options* options, |
| 1449 | const RTCConfiguration* config, |
| 1450 | webrtc::PeerConnectionDependencies dependencies, |
| 1451 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory, |
| 1452 | bool reset_encoder_factory, |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 | [diff] [blame] | 1453 | bool reset_decoder_factory, |
| 1454 | bool create_media_engine = true) { |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1455 | RTCConfiguration modified_config; |
| 1456 | if (config) { |
| 1457 | modified_config = *config; |
| 1458 | } |
| 1459 | modified_config.sdp_semantics = sdp_semantics_; |
| 1460 | if (!dependencies.cert_generator) { |
| 1461 | dependencies.cert_generator = |
| 1462 | std::make_unique<FakeRTCCertificateGenerator>(); |
| 1463 | } |
| 1464 | std::unique_ptr<PeerConnectionIntegrationWrapper> client( |
| 1465 | new PeerConnectionIntegrationWrapper(debug_name)); |
| 1466 | |
| 1467 | if (!client->Init(options, &modified_config, std::move(dependencies), |
Byoungchan Lee | d197e0b | 2022-05-30 14:59:55 | [diff] [blame] | 1468 | fss_.get(), network_thread_.get(), worker_thread_.get(), |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1469 | std::move(event_log_factory), reset_encoder_factory, |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 | [diff] [blame] | 1470 | reset_decoder_factory, create_media_engine)) { |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1471 | return nullptr; |
| 1472 | } |
| 1473 | return client; |
| 1474 | } |
| 1475 | |
| 1476 | std::unique_ptr<PeerConnectionIntegrationWrapper> |
| 1477 | CreatePeerConnectionWrapperWithFakeRtcEventLog( |
| 1478 | const std::string& debug_name, |
| 1479 | const PeerConnectionFactory::Options* options, |
| 1480 | const RTCConfiguration* config, |
| 1481 | webrtc::PeerConnectionDependencies dependencies) { |
| 1482 | return CreatePeerConnectionWrapper( |
| 1483 | debug_name, options, config, std::move(dependencies), |
| 1484 | std::make_unique<webrtc::FakeRtcEventLogFactory>(), |
| 1485 | /*reset_encoder_factory=*/false, |
| 1486 | /*reset_decoder_factory=*/false); |
| 1487 | } |
| 1488 | |
| 1489 | bool CreatePeerConnectionWrappers() { |
| 1490 | return CreatePeerConnectionWrappersWithConfig( |
| 1491 | PeerConnectionInterface::RTCConfiguration(), |
| 1492 | PeerConnectionInterface::RTCConfiguration()); |
| 1493 | } |
| 1494 | |
| 1495 | bool CreatePeerConnectionWrappersWithSdpSemantics( |
| 1496 | SdpSemantics caller_semantics, |
| 1497 | SdpSemantics callee_semantics) { |
| 1498 | // Can't specify the sdp_semantics in the passed-in configuration since it |
| 1499 | // will be overwritten by CreatePeerConnectionWrapper with whatever is |
| 1500 | // stored in sdp_semantics_. So get around this by modifying the instance |
| 1501 | // variable before calling CreatePeerConnectionWrapper for the caller and |
| 1502 | // callee PeerConnections. |
| 1503 | SdpSemantics original_semantics = sdp_semantics_; |
| 1504 | sdp_semantics_ = caller_semantics; |
| 1505 | caller_ = CreatePeerConnectionWrapper( |
| 1506 | "Caller", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
| 1507 | nullptr, |
| 1508 | /*reset_encoder_factory=*/false, |
| 1509 | /*reset_decoder_factory=*/false); |
| 1510 | sdp_semantics_ = callee_semantics; |
| 1511 | callee_ = CreatePeerConnectionWrapper( |
| 1512 | "Callee", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
| 1513 | nullptr, |
| 1514 | /*reset_encoder_factory=*/false, |
| 1515 | /*reset_decoder_factory=*/false); |
| 1516 | sdp_semantics_ = original_semantics; |
| 1517 | return caller_ && callee_; |
| 1518 | } |
| 1519 | |
| 1520 | bool CreatePeerConnectionWrappersWithConfig( |
| 1521 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1522 | const PeerConnectionInterface::RTCConfiguration& callee_config) { |
| 1523 | caller_ = CreatePeerConnectionWrapper( |
| 1524 | "Caller", nullptr, &caller_config, |
| 1525 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1526 | /*reset_encoder_factory=*/false, |
| 1527 | /*reset_decoder_factory=*/false); |
| 1528 | callee_ = CreatePeerConnectionWrapper( |
| 1529 | "Callee", nullptr, &callee_config, |
| 1530 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1531 | /*reset_encoder_factory=*/false, |
| 1532 | /*reset_decoder_factory=*/false); |
| 1533 | return caller_ && callee_; |
| 1534 | } |
| 1535 | |
| 1536 | bool CreatePeerConnectionWrappersWithConfigAndDeps( |
| 1537 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1538 | webrtc::PeerConnectionDependencies caller_dependencies, |
| 1539 | const PeerConnectionInterface::RTCConfiguration& callee_config, |
| 1540 | webrtc::PeerConnectionDependencies callee_dependencies) { |
| 1541 | caller_ = |
| 1542 | CreatePeerConnectionWrapper("Caller", nullptr, &caller_config, |
| 1543 | std::move(caller_dependencies), nullptr, |
| 1544 | /*reset_encoder_factory=*/false, |
| 1545 | /*reset_decoder_factory=*/false); |
| 1546 | callee_ = |
| 1547 | CreatePeerConnectionWrapper("Callee", nullptr, &callee_config, |
| 1548 | std::move(callee_dependencies), nullptr, |
| 1549 | /*reset_encoder_factory=*/false, |
| 1550 | /*reset_decoder_factory=*/false); |
| 1551 | return caller_ && callee_; |
| 1552 | } |
| 1553 | |
| 1554 | bool CreatePeerConnectionWrappersWithOptions( |
| 1555 | const PeerConnectionFactory::Options& caller_options, |
| 1556 | const PeerConnectionFactory::Options& callee_options) { |
| 1557 | caller_ = CreatePeerConnectionWrapper( |
| 1558 | "Caller", &caller_options, nullptr, |
| 1559 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1560 | /*reset_encoder_factory=*/false, |
| 1561 | /*reset_decoder_factory=*/false); |
| 1562 | callee_ = CreatePeerConnectionWrapper( |
| 1563 | "Callee", &callee_options, nullptr, |
| 1564 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1565 | /*reset_encoder_factory=*/false, |
| 1566 | /*reset_decoder_factory=*/false); |
| 1567 | return caller_ && callee_; |
| 1568 | } |
| 1569 | |
| 1570 | bool CreatePeerConnectionWrappersWithFakeRtcEventLog() { |
| 1571 | PeerConnectionInterface::RTCConfiguration default_config; |
| 1572 | caller_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
| 1573 | "Caller", nullptr, &default_config, |
| 1574 | webrtc::PeerConnectionDependencies(nullptr)); |
| 1575 | callee_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
| 1576 | "Callee", nullptr, &default_config, |
| 1577 | webrtc::PeerConnectionDependencies(nullptr)); |
| 1578 | return caller_ && callee_; |
| 1579 | } |
| 1580 | |
| 1581 | std::unique_ptr<PeerConnectionIntegrationWrapper> |
| 1582 | CreatePeerConnectionWrapperWithAlternateKey() { |
| 1583 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 1584 | new FakeRTCCertificateGenerator()); |
| 1585 | cert_generator->use_alternate_key(); |
| 1586 | |
| 1587 | webrtc::PeerConnectionDependencies dependencies(nullptr); |
| 1588 | dependencies.cert_generator = std::move(cert_generator); |
| 1589 | return CreatePeerConnectionWrapper("New Peer", nullptr, nullptr, |
| 1590 | std::move(dependencies), nullptr, |
| 1591 | /*reset_encoder_factory=*/false, |
| 1592 | /*reset_decoder_factory=*/false); |
| 1593 | } |
| 1594 | |
| 1595 | bool CreateOneDirectionalPeerConnectionWrappers(bool caller_to_callee) { |
| 1596 | caller_ = CreatePeerConnectionWrapper( |
| 1597 | "Caller", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
| 1598 | nullptr, |
| 1599 | /*reset_encoder_factory=*/!caller_to_callee, |
| 1600 | /*reset_decoder_factory=*/caller_to_callee); |
| 1601 | callee_ = CreatePeerConnectionWrapper( |
| 1602 | "Callee", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
| 1603 | nullptr, |
| 1604 | /*reset_encoder_factory=*/caller_to_callee, |
| 1605 | /*reset_decoder_factory=*/!caller_to_callee); |
| 1606 | return caller_ && callee_; |
| 1607 | } |
| 1608 | |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 | [diff] [blame] | 1609 | bool CreatePeerConnectionWrappersWithoutMediaEngine() { |
| 1610 | caller_ = CreatePeerConnectionWrapper( |
| 1611 | "Caller", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
| 1612 | nullptr, |
| 1613 | /*reset_encoder_factory=*/false, |
| 1614 | /*reset_decoder_factory=*/false, |
| 1615 | /*create_media_engine=*/false); |
| 1616 | callee_ = CreatePeerConnectionWrapper( |
| 1617 | "Callee", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
| 1618 | nullptr, |
| 1619 | /*reset_encoder_factory=*/false, |
| 1620 | /*reset_decoder_factory=*/false, |
| 1621 | /*create_media_engine=*/false); |
| 1622 | return caller_ && callee_; |
| 1623 | } |
| 1624 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1625 | cricket::TestTurnServer* CreateTurnServer( |
| 1626 | rtc::SocketAddress internal_address, |
| 1627 | rtc::SocketAddress external_address, |
| 1628 | cricket::ProtocolType type = cricket::ProtocolType::PROTO_UDP, |
| 1629 | const std::string& common_name = "test turn server") { |
| 1630 | rtc::Thread* thread = network_thread(); |
Niels Möller | 6dd4997 | 2021-11-24 13:05:55 | [diff] [blame] | 1631 | rtc::SocketFactory* socket_factory = fss_.get(); |
Danil Chapovalov | 2aaef45 | 2022-08-12 13:55:11 | [diff] [blame] | 1632 | std::unique_ptr<cricket::TestTurnServer> turn_server; |
| 1633 | SendTask(network_thread(), [&] { |
| 1634 | turn_server = std::make_unique<cricket::TestTurnServer>( |
| 1635 | thread, socket_factory, internal_address, external_address, type, |
| 1636 | /*ignore_bad_certs=*/true, common_name); |
| 1637 | }); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1638 | turn_servers_.push_back(std::move(turn_server)); |
| 1639 | // Interactions with the turn server should be done on the network thread. |
| 1640 | return turn_servers_.back().get(); |
| 1641 | } |
| 1642 | |
| 1643 | cricket::TestTurnCustomizer* CreateTurnCustomizer() { |
Danil Chapovalov | 2aaef45 | 2022-08-12 13:55:11 | [diff] [blame] | 1644 | std::unique_ptr<cricket::TestTurnCustomizer> turn_customizer; |
| 1645 | SendTask(network_thread(), [&] { |
| 1646 | turn_customizer = std::make_unique<cricket::TestTurnCustomizer>(); |
| 1647 | }); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1648 | turn_customizers_.push_back(std::move(turn_customizer)); |
| 1649 | // Interactions with the turn customizer should be done on the network |
| 1650 | // thread. |
| 1651 | return turn_customizers_.back().get(); |
| 1652 | } |
| 1653 | |
| 1654 | // Checks that the function counters for a TestTurnCustomizer are greater than |
| 1655 | // 0. |
| 1656 | void ExpectTurnCustomizerCountersIncremented( |
| 1657 | cricket::TestTurnCustomizer* turn_customizer) { |
Danil Chapovalov | 2aaef45 | 2022-08-12 13:55:11 | [diff] [blame] | 1658 | SendTask(network_thread(), [turn_customizer] { |
| 1659 | EXPECT_GT(turn_customizer->allow_channel_data_cnt_, 0u); |
| 1660 | EXPECT_GT(turn_customizer->modify_cnt_, 0u); |
| 1661 | }); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | // Once called, SDP blobs and ICE candidates will be automatically signaled |
| 1665 | // between PeerConnections. |
| 1666 | void ConnectFakeSignaling() { |
| 1667 | caller_->set_signaling_message_receiver(callee_.get()); |
| 1668 | callee_->set_signaling_message_receiver(caller_.get()); |
| 1669 | } |
| 1670 | |
| 1671 | // Once called, SDP blobs will be automatically signaled between |
| 1672 | // PeerConnections. Note that ICE candidates will not be signaled unless they |
| 1673 | // are in the exchanged SDP blobs. |
| 1674 | void ConnectFakeSignalingForSdpOnly() { |
| 1675 | ConnectFakeSignaling(); |
| 1676 | SetSignalIceCandidates(false); |
| 1677 | } |
| 1678 | |
| 1679 | void SetSignalingDelayMs(int delay_ms) { |
| 1680 | caller_->set_signaling_delay_ms(delay_ms); |
| 1681 | callee_->set_signaling_delay_ms(delay_ms); |
| 1682 | } |
| 1683 | |
| 1684 | void SetSignalIceCandidates(bool signal) { |
| 1685 | caller_->set_signal_ice_candidates(signal); |
| 1686 | callee_->set_signal_ice_candidates(signal); |
| 1687 | } |
| 1688 | |
| 1689 | // Messages may get lost on the unreliable DataChannel, so we send multiple |
| 1690 | // times to avoid test flakiness. |
| 1691 | void SendRtpDataWithRetries(webrtc::DataChannelInterface* dc, |
| 1692 | const std::string& data, |
| 1693 | int retries) { |
| 1694 | for (int i = 0; i < retries; ++i) { |
| 1695 | dc->Send(DataBuffer(data)); |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | rtc::Thread* network_thread() { return network_thread_.get(); } |
| 1700 | |
| 1701 | rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); } |
| 1702 | |
| 1703 | PeerConnectionIntegrationWrapper* caller() { return caller_.get(); } |
| 1704 | |
Harald Alvestrand | 4f7486a | 2022-06-02 11:35:49 | [diff] [blame] | 1705 | // Destroy peerconnections. |
| 1706 | // This can be used to ensure that all pointers to on-stack mocks |
| 1707 | // get dropped before exit. |
| 1708 | void DestroyPeerConnections() { |
| 1709 | if (caller_) { |
| 1710 | caller_->pc()->Close(); |
| 1711 | } |
| 1712 | if (callee_) { |
| 1713 | callee_->pc()->Close(); |
| 1714 | } |
| 1715 | caller_.reset(); |
| 1716 | callee_.reset(); |
| 1717 | } |
| 1718 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1719 | // Set the `caller_` to the `wrapper` passed in and return the |
| 1720 | // original `caller_`. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1721 | PeerConnectionIntegrationWrapper* SetCallerPcWrapperAndReturnCurrent( |
| 1722 | PeerConnectionIntegrationWrapper* wrapper) { |
| 1723 | PeerConnectionIntegrationWrapper* old = caller_.release(); |
| 1724 | caller_.reset(wrapper); |
| 1725 | return old; |
| 1726 | } |
| 1727 | |
| 1728 | PeerConnectionIntegrationWrapper* callee() { return callee_.get(); } |
| 1729 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1730 | // Set the `callee_` to the `wrapper` passed in and return the |
| 1731 | // original `callee_`. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1732 | PeerConnectionIntegrationWrapper* SetCalleePcWrapperAndReturnCurrent( |
| 1733 | PeerConnectionIntegrationWrapper* wrapper) { |
| 1734 | PeerConnectionIntegrationWrapper* old = callee_.release(); |
| 1735 | callee_.reset(wrapper); |
| 1736 | return old; |
| 1737 | } |
| 1738 | |
| 1739 | void SetPortAllocatorFlags(uint32_t caller_flags, uint32_t callee_flags) { |
Danil Chapovalov | 2aaef45 | 2022-08-12 13:55:11 | [diff] [blame] | 1740 | SendTask(network_thread(), [this, caller_flags] { |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1741 | caller()->port_allocator()->set_flags(caller_flags); |
| 1742 | }); |
Danil Chapovalov | 2aaef45 | 2022-08-12 13:55:11 | [diff] [blame] | 1743 | SendTask(network_thread(), [this, callee_flags] { |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1744 | callee()->port_allocator()->set_flags(callee_flags); |
| 1745 | }); |
| 1746 | } |
| 1747 | |
| 1748 | rtc::FirewallSocketServer* firewall() const { return fss_.get(); } |
| 1749 | |
| 1750 | // Expects the provided number of new frames to be received within |
| 1751 | // kMaxWaitForFramesMs. The new expected frames are specified in |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1752 | // `media_expectations`. Returns false if any of the expectations were |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1753 | // not met. |
| 1754 | bool ExpectNewFrames(const MediaExpectations& media_expectations) { |
| 1755 | // Make sure there are no bogus tracks confusing the issue. |
| 1756 | caller()->RemoveUnusedVideoRenderers(); |
| 1757 | callee()->RemoveUnusedVideoRenderers(); |
| 1758 | // First initialize the expected frame counts based upon the current |
| 1759 | // frame count. |
| 1760 | int total_caller_audio_frames_expected = caller()->audio_frames_received(); |
| 1761 | if (media_expectations.caller_audio_expectation_ == |
| 1762 | MediaExpectations::kExpectSomeFrames) { |
| 1763 | total_caller_audio_frames_expected += |
| 1764 | media_expectations.caller_audio_frames_expected_; |
| 1765 | } |
| 1766 | int total_caller_video_frames_expected = |
| 1767 | caller()->min_video_frames_received_per_track(); |
| 1768 | if (media_expectations.caller_video_expectation_ == |
| 1769 | MediaExpectations::kExpectSomeFrames) { |
| 1770 | total_caller_video_frames_expected += |
| 1771 | media_expectations.caller_video_frames_expected_; |
| 1772 | } |
| 1773 | int total_callee_audio_frames_expected = callee()->audio_frames_received(); |
| 1774 | if (media_expectations.callee_audio_expectation_ == |
| 1775 | MediaExpectations::kExpectSomeFrames) { |
| 1776 | total_callee_audio_frames_expected += |
| 1777 | media_expectations.callee_audio_frames_expected_; |
| 1778 | } |
| 1779 | int total_callee_video_frames_expected = |
| 1780 | callee()->min_video_frames_received_per_track(); |
| 1781 | if (media_expectations.callee_video_expectation_ == |
| 1782 | MediaExpectations::kExpectSomeFrames) { |
| 1783 | total_callee_video_frames_expected += |
| 1784 | media_expectations.callee_video_frames_expected_; |
| 1785 | } |
| 1786 | |
| 1787 | // Wait for the expected frames. |
| 1788 | EXPECT_TRUE_WAIT(caller()->audio_frames_received() >= |
| 1789 | total_caller_audio_frames_expected && |
| 1790 | caller()->min_video_frames_received_per_track() >= |
| 1791 | total_caller_video_frames_expected && |
| 1792 | callee()->audio_frames_received() >= |
| 1793 | total_callee_audio_frames_expected && |
| 1794 | callee()->min_video_frames_received_per_track() >= |
| 1795 | total_callee_video_frames_expected, |
| 1796 | kMaxWaitForFramesMs); |
| 1797 | bool expectations_correct = |
| 1798 | caller()->audio_frames_received() >= |
| 1799 | total_caller_audio_frames_expected && |
| 1800 | caller()->min_video_frames_received_per_track() >= |
| 1801 | total_caller_video_frames_expected && |
| 1802 | callee()->audio_frames_received() >= |
| 1803 | total_callee_audio_frames_expected && |
| 1804 | callee()->min_video_frames_received_per_track() >= |
| 1805 | total_callee_video_frames_expected; |
| 1806 | |
| 1807 | // After the combined wait, print out a more detailed message upon |
| 1808 | // failure. |
| 1809 | EXPECT_GE(caller()->audio_frames_received(), |
| 1810 | total_caller_audio_frames_expected); |
| 1811 | EXPECT_GE(caller()->min_video_frames_received_per_track(), |
| 1812 | total_caller_video_frames_expected); |
| 1813 | EXPECT_GE(callee()->audio_frames_received(), |
| 1814 | total_callee_audio_frames_expected); |
| 1815 | EXPECT_GE(callee()->min_video_frames_received_per_track(), |
| 1816 | total_callee_video_frames_expected); |
| 1817 | |
| 1818 | // We want to make sure nothing unexpected was received. |
| 1819 | if (media_expectations.caller_audio_expectation_ == |
| 1820 | MediaExpectations::kExpectNoFrames) { |
| 1821 | EXPECT_EQ(caller()->audio_frames_received(), |
| 1822 | total_caller_audio_frames_expected); |
| 1823 | if (caller()->audio_frames_received() != |
| 1824 | total_caller_audio_frames_expected) { |
| 1825 | expectations_correct = false; |
| 1826 | } |
| 1827 | } |
| 1828 | if (media_expectations.caller_video_expectation_ == |
| 1829 | MediaExpectations::kExpectNoFrames) { |
| 1830 | EXPECT_EQ(caller()->min_video_frames_received_per_track(), |
| 1831 | total_caller_video_frames_expected); |
| 1832 | if (caller()->min_video_frames_received_per_track() != |
| 1833 | total_caller_video_frames_expected) { |
| 1834 | expectations_correct = false; |
| 1835 | } |
| 1836 | } |
| 1837 | if (media_expectations.callee_audio_expectation_ == |
| 1838 | MediaExpectations::kExpectNoFrames) { |
| 1839 | EXPECT_EQ(callee()->audio_frames_received(), |
| 1840 | total_callee_audio_frames_expected); |
| 1841 | if (callee()->audio_frames_received() != |
| 1842 | total_callee_audio_frames_expected) { |
| 1843 | expectations_correct = false; |
| 1844 | } |
| 1845 | } |
| 1846 | if (media_expectations.callee_video_expectation_ == |
| 1847 | MediaExpectations::kExpectNoFrames) { |
| 1848 | EXPECT_EQ(callee()->min_video_frames_received_per_track(), |
| 1849 | total_callee_video_frames_expected); |
| 1850 | if (callee()->min_video_frames_received_per_track() != |
| 1851 | total_callee_video_frames_expected) { |
| 1852 | expectations_correct = false; |
| 1853 | } |
| 1854 | } |
| 1855 | return expectations_correct; |
| 1856 | } |
| 1857 | |
| 1858 | void ClosePeerConnections() { |
Tomas Gunnarsson | 2efb8a5 | 2021-04-01 14:26:57 | [diff] [blame] | 1859 | if (caller()) |
| 1860 | caller()->pc()->Close(); |
| 1861 | if (callee()) |
| 1862 | callee()->pc()->Close(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | void TestNegotiatedCipherSuite( |
| 1866 | const PeerConnectionFactory::Options& caller_options, |
| 1867 | const PeerConnectionFactory::Options& callee_options, |
| 1868 | int expected_cipher_suite) { |
| 1869 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(caller_options, |
| 1870 | callee_options)); |
| 1871 | ConnectFakeSignaling(); |
| 1872 | caller()->AddAudioVideoTracks(); |
| 1873 | callee()->AddAudioVideoTracks(); |
| 1874 | caller()->CreateAndSetAndSignalOffer(); |
| 1875 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 1876 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite), |
| 1877 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
| 1878 | // TODO(bugs.webrtc.org/9456): Fix it. |
| 1879 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 1880 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 1881 | expected_cipher_suite)); |
| 1882 | } |
| 1883 | |
| 1884 | void TestGcmNegotiationUsesCipherSuite(bool local_gcm_enabled, |
| 1885 | bool remote_gcm_enabled, |
| 1886 | bool aes_ctr_enabled, |
| 1887 | int expected_cipher_suite) { |
| 1888 | PeerConnectionFactory::Options caller_options; |
| 1889 | caller_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1890 | local_gcm_enabled; |
| 1891 | caller_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = |
| 1892 | aes_ctr_enabled; |
| 1893 | PeerConnectionFactory::Options callee_options; |
| 1894 | callee_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1895 | remote_gcm_enabled; |
| 1896 | callee_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = |
| 1897 | aes_ctr_enabled; |
| 1898 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 1899 | expected_cipher_suite); |
| 1900 | } |
| 1901 | |
Jonas Oreland | e62c2f2 | 2022-03-29 09:04:48 | [diff] [blame] | 1902 | const FieldTrialsView& trials() const { return *field_trials_.get(); } |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 1903 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1904 | protected: |
| 1905 | SdpSemantics sdp_semantics_; |
| 1906 | |
| 1907 | private: |
Niels Möller | 83830f3 | 2022-05-20 07:12:57 | [diff] [blame] | 1908 | rtc::AutoThread main_thread_; // Used as the signal thread by most tests. |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1909 | // `ss_` is used by `network_thread_` so it must be destroyed later. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1910 | std::unique_ptr<rtc::VirtualSocketServer> ss_; |
| 1911 | std::unique_ptr<rtc::FirewallSocketServer> fss_; |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1912 | // `network_thread_` and `worker_thread_` are used by both |
| 1913 | // `caller_` and `callee_` so they must be destroyed |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1914 | // later. |
| 1915 | std::unique_ptr<rtc::Thread> network_thread_; |
| 1916 | std::unique_ptr<rtc::Thread> worker_thread_; |
| 1917 | // The turn servers and turn customizers should be accessed & deleted on the |
| 1918 | // network thread to avoid a race with the socket read/write that occurs |
| 1919 | // on the network thread. |
| 1920 | std::vector<std::unique_ptr<cricket::TestTurnServer>> turn_servers_; |
| 1921 | std::vector<std::unique_ptr<cricket::TestTurnCustomizer>> turn_customizers_; |
| 1922 | std::unique_ptr<PeerConnectionIntegrationWrapper> caller_; |
| 1923 | std::unique_ptr<PeerConnectionIntegrationWrapper> callee_; |
Jonas Oreland | e62c2f2 | 2022-03-29 09:04:48 | [diff] [blame] | 1924 | std::unique_ptr<FieldTrialsView> field_trials_; |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 | [diff] [blame] | 1925 | }; |
| 1926 | |
| 1927 | } // namespace webrtc |
| 1928 | |
| 1929 | #endif // PC_TEST_INTEGRATION_TEST_HELPERS_H_ |