• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/metrics/metrics_logger.h"
22 #include "api/test/pclf/media_configuration.h"
23 #include "api/test/pclf/media_quality_test_params.h"
24 #include "api/test/pclf/peer_configurer.h"
25 #include "api/test/peerconnection_quality_test_fixture.h"
26 #include "api/test/time_controller.h"
27 #include "api/units/time_delta.h"
28 #include "api/units/timestamp.h"
29 #include "rtc_base/synchronization/mutex.h"
30 #include "rtc_base/task_queue_for_test.h"
31 #include "rtc_base/thread.h"
32 #include "rtc_base/thread_annotations.h"
33 #include "system_wrappers/include/clock.h"
34 #include "test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.h"
35 #include "test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h"
36 #include "test/pc/e2e/analyzer_helper.h"
37 #include "test/pc/e2e/media/media_helper.h"
38 #include "test/pc/e2e/sdp/sdp_changer.h"
39 #include "test/pc/e2e/test_activities_executor.h"
40 #include "test/pc/e2e/test_peer.h"
41 
42 namespace webrtc {
43 namespace webrtc_pc_e2e {
44 
45 class PeerConnectionE2EQualityTest
46     : public PeerConnectionE2EQualityTestFixture {
47  public:
48   using QualityMetricsReporter =
49       PeerConnectionE2EQualityTestFixture::QualityMetricsReporter;
50 
51   PeerConnectionE2EQualityTest(
52       std::string test_case_name,
53       TimeController& time_controller,
54       std::unique_ptr<AudioQualityAnalyzerInterface> audio_quality_analyzer,
55       std::unique_ptr<VideoQualityAnalyzerInterface> video_quality_analyzer);
56   PeerConnectionE2EQualityTest(
57       std::string test_case_name,
58       TimeController& time_controller,
59       std::unique_ptr<AudioQualityAnalyzerInterface> audio_quality_analyzer,
60       std::unique_ptr<VideoQualityAnalyzerInterface> video_quality_analyzer,
61       test::MetricsLogger* metrics_logger);
62 
63   ~PeerConnectionE2EQualityTest() override = default;
64 
65   void ExecuteAt(TimeDelta target_time_since_start,
66                  std::function<void(TimeDelta)> func) override;
67   void ExecuteEvery(TimeDelta initial_delay_since_start,
68                     TimeDelta interval,
69                     std::function<void(TimeDelta)> func) override;
70 
71   void AddQualityMetricsReporter(std::unique_ptr<QualityMetricsReporter>
72                                      quality_metrics_reporter) override;
73 
74   PeerHandle* AddPeer(std::unique_ptr<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   class PeerHandleImpl : public PeerHandle {
85    public:
86     ~PeerHandleImpl() override = default;
87   };
88 
89   // For some functionality some field trials have to be enabled, they will be
90   // enabled in Run().
91   std::string GetFieldTrials(const RunParams& run_params);
92   void OnTrackCallback(absl::string_view peer_name,
93                        VideoSubscription peer_subscription,
94                        rtc::scoped_refptr<RtpTransceiverInterface> transceiver,
95                        std::vector<VideoConfig> remote_video_configs);
96   // Have to be run on the signaling thread.
97   void SetupCallOnSignalingThread(const RunParams& run_params);
98   void TearDownCallOnSignalingThread();
99   void SetPeerCodecPreferences(TestPeer* peer);
100   std::unique_ptr<SignalingInterceptor> CreateSignalingInterceptor(
101       const RunParams& run_params);
102   void WaitUntilIceCandidatesGathered(rtc::Thread* signaling_thread);
103   void WaitUntilPeersAreConnected(rtc::Thread* signaling_thread);
104   void ExchangeOfferAnswer(SignalingInterceptor* signaling_interceptor);
105   void ExchangeIceCandidates(SignalingInterceptor* signaling_interceptor);
106   void StartVideo(
107       const std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>>&
108           sources);
109   void TearDownCall();
110   void ReportGeneralTestResults();
111   Timestamp Now() const;
112 
113   TimeController& time_controller_;
114   const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
115   std::string test_case_name_;
116   std::unique_ptr<VideoQualityAnalyzerInjectionHelper>
117       video_quality_analyzer_injection_helper_;
118   std::unique_ptr<MediaHelper> media_helper_;
119   std::unique_ptr<EncodedImageDataPropagator> encoded_image_data_propagator_;
120   std::unique_ptr<AudioQualityAnalyzerInterface> audio_quality_analyzer_;
121   std::unique_ptr<TestActivitiesExecutor> executor_;
122   test::MetricsLogger* const metrics_logger_;
123 
124   std::vector<std::unique_ptr<PeerConfigurer>> peer_configurations_;
125   std::vector<PeerHandleImpl> peer_handles_;
126 
127   std::unique_ptr<TestPeer> alice_;
128   std::unique_ptr<TestPeer> bob_;
129   std::vector<std::unique_ptr<QualityMetricsReporter>>
130       quality_metrics_reporters_;
131 
132   std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>>
133       alice_video_sources_;
134   std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>>
135       bob_video_sources_;
136   std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>>
137       output_video_sinks_;
138   AnalyzerHelper analyzer_helper_;
139 
140   mutable Mutex lock_;
141   TimeDelta real_test_duration_ RTC_GUARDED_BY(lock_) = TimeDelta::Zero();
142 
143   // Task queue, that is used for running activities during test call.
144   // This task queue will be created before call set up and will be destroyed
145   // immediately before call tear down.
146   std::unique_ptr<TaskQueueForTest> task_queue_;
147 
148   bool alice_connected_ = false;
149   bool bob_connected_ = false;
150 };
151 
152 }  // namespace webrtc_pc_e2e
153 }  // namespace webrtc
154 
155 #endif  // TEST_PC_E2E_PEER_CONNECTION_QUALITY_TEST_H_
156