xref: /aosp_15_r20/external/webrtc/video/video_quality_test.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2015 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 VIDEO_VIDEO_QUALITY_TEST_H_
11 #define VIDEO_VIDEO_QUALITY_TEST_H_
12 
13 #include <map>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "api/fec_controller.h"
19 #include "api/rtc_event_log/rtc_event_log_factory.h"
20 #include "api/task_queue/task_queue_base.h"
21 #include "api/task_queue/task_queue_factory.h"
22 #include "api/test/frame_generator_interface.h"
23 #include "api/test/video_quality_test_fixture.h"
24 #include "api/video/video_bitrate_allocator_factory.h"
25 #include "call/fake_network_pipe.h"
26 #include "media/engine/internal_decoder_factory.h"
27 #include "media/engine/internal_encoder_factory.h"
28 #include "test/call_test.h"
29 #include "test/layer_filtering_transport.h"
30 #include "video/video_analyzer.h"
31 #ifdef WEBRTC_WIN
32 #include "modules/audio_device/win/core_audio_utility_win.h"
33 #include "rtc_base/win/scoped_com_initializer.h"
34 #endif
35 
36 namespace webrtc {
37 
38 class VideoQualityTest : public test::CallTest,
39                          public VideoQualityTestFixtureInterface {
40  public:
41   explicit VideoQualityTest(
42       std::unique_ptr<InjectionComponents> injection_components);
43 
44   void RunWithAnalyzer(const Params& params) override;
45   void RunWithRenderers(const Params& params) override;
46 
payload_type_map()47   const std::map<uint8_t, webrtc::MediaType>& payload_type_map() override {
48     return payload_type_map_;
49   }
50 
51   static void FillScalabilitySettings(
52       Params* params,
53       size_t video_idx,
54       const std::vector<std::string>& stream_descriptors,
55       int num_streams,
56       size_t selected_stream,
57       int num_spatial_layers,
58       int selected_sl,
59       InterLayerPredMode inter_layer_pred,
60       const std::vector<std::string>& sl_descriptors);
61 
62   // Helper static methods.
63   static VideoStream DefaultVideoStream(const Params& params, size_t video_idx);
64   static VideoStream DefaultThumbnailStream();
65   static std::vector<int> ParseCSV(const std::string& str);
66 
67  protected:
68   std::map<uint8_t, webrtc::MediaType> payload_type_map_;
69 
70   // No-op implementation to be able to instantiate this class from non-TEST_F
71   // locations.
72   void TestBody() override;
73 
74   // Helper methods accessing only params_.
75   std::string GenerateGraphTitle() const;
76   void CheckParamsAndInjectionComponents();
77 
78   // Helper methods for setting up the call.
79   void CreateCapturers();
80   std::unique_ptr<test::FrameGeneratorInterface> CreateFrameGenerator(
81       size_t video_idx);
82   void SetupThumbnailCapturers(size_t num_thumbnail_streams);
83   std::unique_ptr<VideoDecoder> CreateVideoDecoder(
84       const SdpVideoFormat& format);
85   std::unique_ptr<VideoEncoder> CreateVideoEncoder(const SdpVideoFormat& format,
86                                                    VideoAnalyzer* analyzer);
87   void SetupVideo(Transport* send_transport, Transport* recv_transport);
88   void SetupThumbnails(Transport* send_transport, Transport* recv_transport);
89   void StartAudioStreams();
90   void StartThumbnails();
91   void StopThumbnails();
92   void DestroyThumbnailStreams();
93   // Helper method for creating a real ADM (using hardware) for all platforms.
94   rtc::scoped_refptr<AudioDeviceModule> CreateAudioDevice();
95   void InitializeAudioDevice(Call::Config* send_call_config,
96                              Call::Config* recv_call_config,
97                              bool use_real_adm);
98   void SetupAudio(Transport* transport);
99 
100   void StartEncodedFrameLogs(VideoReceiveStreamInterface* stream);
101 
102   virtual std::unique_ptr<test::LayerFilteringTransport> CreateSendTransport();
103   virtual std::unique_ptr<test::DirectTransport> CreateReceiveTransport();
104 
105   std::vector<std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>>
106       thumbnail_capturers_;
107   Clock* const clock_;
108   const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
109   RtcEventLogFactory rtc_event_log_factory_;
110 
111   test::FunctionVideoDecoderFactory video_decoder_factory_;
112   std::unique_ptr<VideoDecoderFactory> decoder_factory_;
113   test::FunctionVideoEncoderFactory video_encoder_factory_;
114   test::FunctionVideoEncoderFactory video_encoder_factory_with_analyzer_;
115   std::unique_ptr<VideoBitrateAllocatorFactory>
116       video_bitrate_allocator_factory_;
117   std::unique_ptr<VideoEncoderFactory> encoder_factory_;
118   std::vector<VideoSendStream::Config> thumbnail_send_configs_;
119   std::vector<VideoEncoderConfig> thumbnail_encoder_configs_;
120   std::vector<VideoSendStream*> thumbnail_send_streams_;
121   std::vector<VideoReceiveStreamInterface::Config> thumbnail_receive_configs_;
122   std::vector<VideoReceiveStreamInterface*> thumbnail_receive_streams_;
123 
124   int receive_logs_;
125   int send_logs_;
126 
127   Params params_;
128   std::unique_ptr<InjectionComponents> injection_components_;
129 
130   // Set non-null when running with analyzer.
131   std::unique_ptr<VideoAnalyzer> analyzer_;
132 
133   // Note: not same as similarly named member in CallTest. This is the number of
134   // separate send streams, the one in CallTest is the number of substreams for
135   // a single send stream.
136   size_t num_video_streams_;
137 
138 #ifdef WEBRTC_WIN
139   // Windows Core Audio based ADM needs to run on a COM initialized thread.
140   // Only referenced in combination with --audio --use_real_adm flags.
141   std::unique_ptr<ScopedCOMInitializer> com_initializer_;
142 #endif
143 };
144 
145 }  // namespace webrtc
146 
147 #endif  // VIDEO_VIDEO_QUALITY_TEST_H_
148