1 /* 2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef TEST_PC_E2E_PEER_CONNECTION_QUALITY_TEST_H_ 11 #define TEST_PC_E2E_PEER_CONNECTION_QUALITY_TEST_H_ 12 13 #include <memory> 14 #include <queue> 15 #include <string> 16 #include <vector> 17 18 #include "absl/strings/string_view.h" 19 #include "api/task_queue/task_queue_factory.h" 20 #include "api/test/audio_quality_analyzer_interface.h" 21 #include "api/test/peerconnection_quality_test_fixture.h" 22 #include "api/test/time_controller.h" 23 #include "api/units/time_delta.h" 24 #include "api/units/timestamp.h" 25 #include "rtc_base/synchronization/mutex.h" 26 #include "rtc_base/task_queue_for_test.h" 27 #include "rtc_base/thread.h" 28 #include "rtc_base/thread_annotations.h" 29 #include "system_wrappers/include/clock.h" 30 #include "test/field_trial.h" 31 #include "test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.h" 32 #include "test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h" 33 #include "test/pc/e2e/analyzer_helper.h" 34 #include "test/pc/e2e/media/media_helper.h" 35 #include "test/pc/e2e/peer_configurer.h" 36 #include "test/pc/e2e/peer_connection_quality_test_params.h" 37 #include "test/pc/e2e/sdp/sdp_changer.h" 38 #include "test/pc/e2e/test_activities_executor.h" 39 #include "test/pc/e2e/test_peer.h" 40 41 namespace webrtc { 42 namespace webrtc_pc_e2e { 43 44 class PeerConnectionE2EQualityTest 45 : public PeerConnectionE2EQualityTestFixture { 46 public: 47 using RunParams = PeerConnectionE2EQualityTestFixture::RunParams; 48 using VideoConfig = PeerConnectionE2EQualityTestFixture::VideoConfig; 49 using VideoSimulcastConfig = 50 PeerConnectionE2EQualityTestFixture::VideoSimulcastConfig; 51 using PeerConfigurer = PeerConnectionE2EQualityTestFixture::PeerConfigurer; 52 using QualityMetricsReporter = 53 PeerConnectionE2EQualityTestFixture::QualityMetricsReporter; 54 55 PeerConnectionE2EQualityTest( 56 std::string test_case_name, 57 TimeController& time_controller, 58 std::unique_ptr<AudioQualityAnalyzerInterface> audio_quality_analyzer, 59 std::unique_ptr<VideoQualityAnalyzerInterface> video_quality_analyzer); 60 61 ~PeerConnectionE2EQualityTest() override = default; 62 63 void ExecuteAt(TimeDelta target_time_since_start, 64 std::function<void(TimeDelta)> func) override; 65 void ExecuteEvery(TimeDelta initial_delay_since_start, 66 TimeDelta interval, 67 std::function<void(TimeDelta)> func) override; 68 69 void AddQualityMetricsReporter(std::unique_ptr<QualityMetricsReporter> 70 quality_metrics_reporter) override; 71 72 void AddPeer(rtc::Thread* network_thread, 73 rtc::NetworkManager* network_manager, 74 rtc::FunctionView<void(PeerConfigurer*)> configurer) override; 75 void Run(RunParams run_params) override; 76 GetRealTestDuration()77 TimeDelta GetRealTestDuration() const override { 78 MutexLock lock(&lock_); 79 RTC_CHECK_NE(real_test_duration_, TimeDelta::Zero()); 80 return real_test_duration_; 81 } 82 83 private: 84 // For some functionality some field trials have to be enabled, so we will 85 // enable them here. 86 void SetupRequiredFieldTrials(const RunParams& run_params); 87 void OnTrackCallback(absl::string_view peer_name, 88 rtc::scoped_refptr<RtpTransceiverInterface> transceiver, 89 std::vector<VideoConfig> remote_video_configs); 90 // Have to be run on the signaling thread. 91 void SetupCallOnSignalingThread(const RunParams& run_params); 92 void TearDownCallOnSignalingThread(); 93 void SetPeerCodecPreferences(TestPeer* peer, const RunParams& run_params); 94 std::unique_ptr<SignalingInterceptor> CreateSignalingInterceptor( 95 const RunParams& run_params); 96 void WaitUntilIceCandidatesGathered(rtc::Thread* signaling_thread); 97 void WaitUntilPeersAreConnected(rtc::Thread* signaling_thread); 98 void ExchangeOfferAnswer(SignalingInterceptor* signaling_interceptor); 99 void ExchangeIceCandidates(SignalingInterceptor* signaling_interceptor); 100 void StartVideo( 101 const std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>>& 102 sources); 103 void TearDownCall(); 104 void ReportGeneralTestResults(); 105 Timestamp Now() const; 106 107 TimeController& time_controller_; 108 const std::unique_ptr<TaskQueueFactory> task_queue_factory_; 109 std::string test_case_name_; 110 std::unique_ptr<VideoQualityAnalyzerInjectionHelper> 111 video_quality_analyzer_injection_helper_; 112 std::unique_ptr<MediaHelper> media_helper_; 113 std::unique_ptr<SingleProcessEncodedImageDataInjector> 114 encoded_image_id_controller_; 115 std::unique_ptr<AudioQualityAnalyzerInterface> audio_quality_analyzer_; 116 std::unique_ptr<TestActivitiesExecutor> executor_; 117 118 std::vector<std::unique_ptr<PeerConfigurerImpl>> peer_configurations_; 119 120 std::unique_ptr<test::ScopedFieldTrials> override_field_trials_ = nullptr; 121 122 std::unique_ptr<TestPeer> alice_; 123 std::unique_ptr<TestPeer> bob_; 124 std::vector<std::unique_ptr<QualityMetricsReporter>> 125 quality_metrics_reporters_; 126 127 std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>> 128 alice_video_sources_; 129 std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>> 130 bob_video_sources_; 131 std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>> 132 output_video_sinks_; 133 AnalyzerHelper analyzer_helper_; 134 135 mutable Mutex lock_; 136 TimeDelta real_test_duration_ RTC_GUARDED_BY(lock_) = TimeDelta::Zero(); 137 138 // Task queue, that is used for running activities during test call. 139 // This task queue will be created before call set up and will be destroyed 140 // immediately before call tear down. 141 std::unique_ptr<TaskQueueForTest> task_queue_; 142 143 bool alice_connected_ = false; 144 bool bob_connected_ = false; 145 }; 146 147 } // namespace webrtc_pc_e2e 148 } // namespace webrtc 149 150 #endif // TEST_PC_E2E_PEER_CONNECTION_QUALITY_TEST_H_ 151