xref: /aosp_15_r20/external/webrtc/api/test/peerconnection_quality_test_fixture.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2018 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 API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_
11 #define API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_
12 
13 #include <stddef.h>
14 #include <stdint.h>
15 
16 #include <functional>
17 #include <map>
18 #include <memory>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #include "absl/base/macros.h"
24 #include "absl/memory/memory.h"
25 #include "absl/strings/string_view.h"
26 #include "absl/types/optional.h"
27 #include "api/array_view.h"
28 #include "api/async_resolver_factory.h"
29 #include "api/audio/audio_mixer.h"
30 #include "api/call/call_factory_interface.h"
31 #include "api/fec_controller.h"
32 #include "api/function_view.h"
33 #include "api/media_stream_interface.h"
34 #include "api/peer_connection_interface.h"
35 #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
36 #include "api/rtp_parameters.h"
37 #include "api/task_queue/task_queue_factory.h"
38 #include "api/test/audio_quality_analyzer_interface.h"
39 #include "api/test/frame_generator_interface.h"
40 #include "api/test/pclf/media_configuration.h"
41 #include "api/test/pclf/media_quality_test_params.h"
42 #include "api/test/pclf/peer_configurer.h"
43 #include "api/test/peer_network_dependencies.h"
44 #include "api/test/simulated_network.h"
45 #include "api/test/stats_observer_interface.h"
46 #include "api/test/track_id_stream_info_map.h"
47 #include "api/test/video/video_frame_writer.h"
48 #include "api/test/video_quality_analyzer_interface.h"
49 #include "api/transport/network_control.h"
50 #include "api/units/time_delta.h"
51 #include "api/video_codecs/video_decoder_factory.h"
52 #include "api/video_codecs/video_encoder.h"
53 #include "api/video_codecs/video_encoder_factory.h"
54 #include "media/base/media_constants.h"
55 #include "modules/audio_processing/include/audio_processing.h"
56 #include "rtc_base/checks.h"
57 #include "rtc_base/network.h"
58 #include "rtc_base/rtc_certificate_generator.h"
59 #include "rtc_base/ssl_certificate.h"
60 #include "rtc_base/thread.h"
61 
62 namespace webrtc {
63 namespace webrtc_pc_e2e {
64 
65 // API is in development. Can be changed/removed without notice.
66 class PeerConnectionE2EQualityTestFixture {
67  public:
68   // Represent an entity that will report quality metrics after test.
69   class QualityMetricsReporter : public StatsObserverInterface {
70    public:
71     virtual ~QualityMetricsReporter() = default;
72 
73     // Invoked by framework after peer connection factory and peer connection
74     // itself will be created but before offer/answer exchange will be started.
75     // `test_case_name` is name of test case, that should be used to report all
76     // metrics.
77     // `reporter_helper` is a pointer to a class that will allow track_id to
78     // stream_id matching. The caller is responsible for ensuring the
79     // TrackIdStreamInfoMap will be valid from Start() to
80     // StopAndReportResults().
81     virtual void Start(absl::string_view test_case_name,
82                        const TrackIdStreamInfoMap* reporter_helper) = 0;
83 
84     // Invoked by framework after call is ended and peer connection factory and
85     // peer connection are destroyed.
86     virtual void StopAndReportResults() = 0;
87   };
88 
89   // Represents single participant in call and can be used to perform different
90   // in-call actions. Might be extended in future.
91   class PeerHandle {
92    public:
93     virtual ~PeerHandle() = default;
94   };
95 
96   virtual ~PeerConnectionE2EQualityTestFixture() = default;
97 
98   // Add activity that will be executed on the best effort at least after
99   // `target_time_since_start` after call will be set up (after offer/answer
100   // exchange, ICE gathering will be done and ICE candidates will passed to
101   // remote side). `func` param is amount of time spent from the call set up.
102   virtual void ExecuteAt(TimeDelta target_time_since_start,
103                          std::function<void(TimeDelta)> func) = 0;
104   // Add activity that will be executed every `interval` with first execution
105   // on the best effort at least after `initial_delay_since_start` after call
106   // will be set up (after all participants will be connected). `func` param is
107   // amount of time spent from the call set up.
108   virtual void ExecuteEvery(TimeDelta initial_delay_since_start,
109                             TimeDelta interval,
110                             std::function<void(TimeDelta)> func) = 0;
111 
112   // Add stats reporter entity to observe the test.
113   virtual void AddQualityMetricsReporter(
114       std::unique_ptr<QualityMetricsReporter> quality_metrics_reporter) = 0;
115 
116   // Add a new peer to the call and return an object through which caller
117   // can configure peer's behavior.
118   // `network_dependencies` are used to provide networking for peer's peer
119   // connection. Members must be non-null.
120   // `configurer` function will be used to configure peer in the call.
121   virtual PeerHandle* AddPeer(std::unique_ptr<PeerConfigurer> configurer) = 0;
122 
123   // Runs the media quality test, which includes setting up the call with
124   // configured participants, running it according to provided `run_params` and
125   // terminating it properly at the end. During call duration media quality
126   // metrics are gathered, which are then reported to stdout and (if configured)
127   // to the json/protobuf output file through the WebRTC perf test results
128   // reporting system.
129   virtual void Run(RunParams run_params) = 0;
130 
131   // Returns real test duration - the time of test execution measured during
132   // test. Client must call this method only after test is finished (after
133   // Run(...) method returned). Test execution time is time from end of call
134   // setup (offer/answer, ICE candidates exchange done and ICE connected) to
135   // start of call tear down (PeerConnection closed).
136   virtual TimeDelta GetRealTestDuration() const = 0;
137 };
138 
139 }  // namespace webrtc_pc_e2e
140 }  // namespace webrtc
141 
142 #endif  // API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_
143