peer_connection_quality_test.h 6.0 KB

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