xref: /aosp_15_r20/external/webrtc/api/test/videocodec_test_fixture.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #ifndef API_TEST_VIDEOCODEC_TEST_FIXTURE_H_
12*d9f75844SAndroid Build Coastguard Worker #define API_TEST_VIDEOCODEC_TEST_FIXTURE_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <string>
15*d9f75844SAndroid Build Coastguard Worker #include <vector>
16*d9f75844SAndroid Build Coastguard Worker 
17*d9f75844SAndroid Build Coastguard Worker #include "api/test/videocodec_test_stats.h"
18*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/h264_profile_level_id.h"
19*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/video_decoder_factory.h"
20*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/video_encoder_factory.h"
21*d9f75844SAndroid Build Coastguard Worker #include "modules/video_coding/include/video_codec_interface.h"
22*d9f75844SAndroid Build Coastguard Worker 
23*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
24*d9f75844SAndroid Build Coastguard Worker namespace test {
25*d9f75844SAndroid Build Coastguard Worker 
26*d9f75844SAndroid Build Coastguard Worker // Rates for the encoder and the frame number when to apply profile.
27*d9f75844SAndroid Build Coastguard Worker struct RateProfile {
28*d9f75844SAndroid Build Coastguard Worker   size_t target_kbps;
29*d9f75844SAndroid Build Coastguard Worker   double input_fps;
30*d9f75844SAndroid Build Coastguard Worker   size_t frame_num;
31*d9f75844SAndroid Build Coastguard Worker };
32*d9f75844SAndroid Build Coastguard Worker 
33*d9f75844SAndroid Build Coastguard Worker struct RateControlThresholds {
34*d9f75844SAndroid Build Coastguard Worker   double max_avg_bitrate_mismatch_percent;
35*d9f75844SAndroid Build Coastguard Worker   double max_time_to_reach_target_bitrate_sec;
36*d9f75844SAndroid Build Coastguard Worker   // TODO(ssilkin): Use absolute threshold for framerate.
37*d9f75844SAndroid Build Coastguard Worker   double max_avg_framerate_mismatch_percent;
38*d9f75844SAndroid Build Coastguard Worker   double max_avg_buffer_level_sec;
39*d9f75844SAndroid Build Coastguard Worker   double max_max_key_frame_delay_sec;
40*d9f75844SAndroid Build Coastguard Worker   double max_max_delta_frame_delay_sec;
41*d9f75844SAndroid Build Coastguard Worker   size_t max_num_spatial_resizes;
42*d9f75844SAndroid Build Coastguard Worker   size_t max_num_key_frames;
43*d9f75844SAndroid Build Coastguard Worker };
44*d9f75844SAndroid Build Coastguard Worker 
45*d9f75844SAndroid Build Coastguard Worker struct QualityThresholds {
46*d9f75844SAndroid Build Coastguard Worker   double min_avg_psnr;
47*d9f75844SAndroid Build Coastguard Worker   double min_min_psnr;
48*d9f75844SAndroid Build Coastguard Worker   double min_avg_ssim;
49*d9f75844SAndroid Build Coastguard Worker   double min_min_ssim;
50*d9f75844SAndroid Build Coastguard Worker };
51*d9f75844SAndroid Build Coastguard Worker 
52*d9f75844SAndroid Build Coastguard Worker struct BitstreamThresholds {
53*d9f75844SAndroid Build Coastguard Worker   size_t max_max_nalu_size_bytes;
54*d9f75844SAndroid Build Coastguard Worker };
55*d9f75844SAndroid Build Coastguard Worker 
56*d9f75844SAndroid Build Coastguard Worker // NOTE: This class is still under development and may change without notice.
57*d9f75844SAndroid Build Coastguard Worker class VideoCodecTestFixture {
58*d9f75844SAndroid Build Coastguard Worker  public:
59*d9f75844SAndroid Build Coastguard Worker   class EncodedFrameChecker {
60*d9f75844SAndroid Build Coastguard Worker    public:
61*d9f75844SAndroid Build Coastguard Worker     virtual ~EncodedFrameChecker() = default;
62*d9f75844SAndroid Build Coastguard Worker     virtual void CheckEncodedFrame(VideoCodecType codec,
63*d9f75844SAndroid Build Coastguard Worker                                    const EncodedImage& encoded_frame) const = 0;
64*d9f75844SAndroid Build Coastguard Worker   };
65*d9f75844SAndroid Build Coastguard Worker 
66*d9f75844SAndroid Build Coastguard Worker   struct Config {
67*d9f75844SAndroid Build Coastguard Worker     Config();
68*d9f75844SAndroid Build Coastguard Worker     void SetCodecSettings(std::string codec_name,
69*d9f75844SAndroid Build Coastguard Worker                           size_t num_simulcast_streams,
70*d9f75844SAndroid Build Coastguard Worker                           size_t num_spatial_layers,
71*d9f75844SAndroid Build Coastguard Worker                           size_t num_temporal_layers,
72*d9f75844SAndroid Build Coastguard Worker                           bool denoising_on,
73*d9f75844SAndroid Build Coastguard Worker                           bool frame_dropper_on,
74*d9f75844SAndroid Build Coastguard Worker                           bool spatial_resize_on,
75*d9f75844SAndroid Build Coastguard Worker                           size_t width,
76*d9f75844SAndroid Build Coastguard Worker                           size_t height);
77*d9f75844SAndroid Build Coastguard Worker 
78*d9f75844SAndroid Build Coastguard Worker     size_t NumberOfCores() const;
79*d9f75844SAndroid Build Coastguard Worker     size_t NumberOfTemporalLayers() const;
80*d9f75844SAndroid Build Coastguard Worker     size_t NumberOfSpatialLayers() const;
81*d9f75844SAndroid Build Coastguard Worker     size_t NumberOfSimulcastStreams() const;
82*d9f75844SAndroid Build Coastguard Worker 
83*d9f75844SAndroid Build Coastguard Worker     std::string ToString() const;
84*d9f75844SAndroid Build Coastguard Worker     std::string CodecName() const;
85*d9f75844SAndroid Build Coastguard Worker 
86*d9f75844SAndroid Build Coastguard Worker     // Name of this config, to be used for accounting by the test runner.
87*d9f75844SAndroid Build Coastguard Worker     std::string test_name;
88*d9f75844SAndroid Build Coastguard Worker 
89*d9f75844SAndroid Build Coastguard Worker     // Plain name of YUV file to process without file extension.
90*d9f75844SAndroid Build Coastguard Worker     std::string filename;
91*d9f75844SAndroid Build Coastguard Worker     // Dimensions of test clip. Falls back to (codec_settings.width/height) if
92*d9f75844SAndroid Build Coastguard Worker     // not set.
93*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> clip_width;
94*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> clip_height;
95*d9f75844SAndroid Build Coastguard Worker     // Framerate of input clip. Defaults to 30fps if not set.
96*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> clip_fps;
97*d9f75844SAndroid Build Coastguard Worker 
98*d9f75844SAndroid Build Coastguard Worker     // The resolution at which psnr/ssim comparisons should be made. Frames
99*d9f75844SAndroid Build Coastguard Worker     // will be scaled to this size if different.
100*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> reference_width;
101*d9f75844SAndroid Build Coastguard Worker     absl::optional<int> reference_height;
102*d9f75844SAndroid Build Coastguard Worker 
103*d9f75844SAndroid Build Coastguard Worker     // File to process. This must be a video file in the YUV format.
104*d9f75844SAndroid Build Coastguard Worker     std::string filepath;
105*d9f75844SAndroid Build Coastguard Worker 
106*d9f75844SAndroid Build Coastguard Worker     // Number of frames to process.
107*d9f75844SAndroid Build Coastguard Worker     size_t num_frames = 0;
108*d9f75844SAndroid Build Coastguard Worker 
109*d9f75844SAndroid Build Coastguard Worker     // Bitstream constraints.
110*d9f75844SAndroid Build Coastguard Worker     size_t max_payload_size_bytes = 1440;
111*d9f75844SAndroid Build Coastguard Worker 
112*d9f75844SAndroid Build Coastguard Worker     // Should we decode the encoded frames?
113*d9f75844SAndroid Build Coastguard Worker     bool decode = true;
114*d9f75844SAndroid Build Coastguard Worker 
115*d9f75844SAndroid Build Coastguard Worker     // Force the encoder and decoder to use a single core for processing.
116*d9f75844SAndroid Build Coastguard Worker     bool use_single_core = false;
117*d9f75844SAndroid Build Coastguard Worker 
118*d9f75844SAndroid Build Coastguard Worker     // Should cpu usage be measured?
119*d9f75844SAndroid Build Coastguard Worker     // If set to true, the encoding will run in real-time.
120*d9f75844SAndroid Build Coastguard Worker     bool measure_cpu = false;
121*d9f75844SAndroid Build Coastguard Worker 
122*d9f75844SAndroid Build Coastguard Worker     // Simulate frames arriving in real-time by adding delays between frames.
123*d9f75844SAndroid Build Coastguard Worker     bool encode_in_real_time = false;
124*d9f75844SAndroid Build Coastguard Worker 
125*d9f75844SAndroid Build Coastguard Worker     // Codec settings to use.
126*d9f75844SAndroid Build Coastguard Worker     VideoCodec codec_settings;
127*d9f75844SAndroid Build Coastguard Worker 
128*d9f75844SAndroid Build Coastguard Worker     // Name of the codec being tested.
129*d9f75844SAndroid Build Coastguard Worker     std::string codec_name;
130*d9f75844SAndroid Build Coastguard Worker 
131*d9f75844SAndroid Build Coastguard Worker     // Encoder and decoder format and parameters. If provided, format is used to
132*d9f75844SAndroid Build Coastguard Worker     // instantiate the codec. If not provided, the test creates and uses the
133*d9f75844SAndroid Build Coastguard Worker     // default `SdpVideoFormat` based on `codec_name`.
134*d9f75844SAndroid Build Coastguard Worker     // Encoder and decoder name (`SdpVideoFormat::name`) should be the same as
135*d9f75844SAndroid Build Coastguard Worker     // `codec_name`.
136*d9f75844SAndroid Build Coastguard Worker     absl::optional<SdpVideoFormat> encoder_format;
137*d9f75844SAndroid Build Coastguard Worker     absl::optional<SdpVideoFormat> decoder_format;
138*d9f75844SAndroid Build Coastguard Worker 
139*d9f75844SAndroid Build Coastguard Worker     // H.264 specific settings.
140*d9f75844SAndroid Build Coastguard Worker     struct H264CodecSettings {
141*d9f75844SAndroid Build Coastguard Worker       H264Profile profile = H264Profile::kProfileConstrainedBaseline;
142*d9f75844SAndroid Build Coastguard Worker       H264PacketizationMode packetization_mode =
143*d9f75844SAndroid Build Coastguard Worker           H264PacketizationMode::NonInterleaved;
144*d9f75844SAndroid Build Coastguard Worker     } h264_codec_settings;
145*d9f75844SAndroid Build Coastguard Worker 
146*d9f75844SAndroid Build Coastguard Worker     // Custom checker that will be called for each frame.
147*d9f75844SAndroid Build Coastguard Worker     const EncodedFrameChecker* encoded_frame_checker = nullptr;
148*d9f75844SAndroid Build Coastguard Worker 
149*d9f75844SAndroid Build Coastguard Worker     // Print out frame level stats.
150*d9f75844SAndroid Build Coastguard Worker     bool print_frame_level_stats = false;
151*d9f75844SAndroid Build Coastguard Worker 
152*d9f75844SAndroid Build Coastguard Worker     // Path to a directory where encoded or/and decoded video should be saved.
153*d9f75844SAndroid Build Coastguard Worker     std::string output_path;
154*d9f75844SAndroid Build Coastguard Worker 
155*d9f75844SAndroid Build Coastguard Worker     // Should video be saved persistently to disk for post-run visualization?
156*d9f75844SAndroid Build Coastguard Worker     struct VisualizationParams {
157*d9f75844SAndroid Build Coastguard Worker       bool save_encoded_ivf = false;
158*d9f75844SAndroid Build Coastguard Worker       bool save_decoded_y4m = false;
159*d9f75844SAndroid Build Coastguard Worker     } visualization_params;
160*d9f75844SAndroid Build Coastguard Worker 
161*d9f75844SAndroid Build Coastguard Worker     // Enables quality analysis for dropped frames.
162*d9f75844SAndroid Build Coastguard Worker     bool analyze_quality_of_dropped_frames = false;
163*d9f75844SAndroid Build Coastguard Worker   };
164*d9f75844SAndroid Build Coastguard Worker 
165*d9f75844SAndroid Build Coastguard Worker   virtual ~VideoCodecTestFixture() = default;
166*d9f75844SAndroid Build Coastguard Worker 
167*d9f75844SAndroid Build Coastguard Worker   virtual void RunTest(const std::vector<RateProfile>& rate_profiles,
168*d9f75844SAndroid Build Coastguard Worker                        const std::vector<RateControlThresholds>* rc_thresholds,
169*d9f75844SAndroid Build Coastguard Worker                        const std::vector<QualityThresholds>* quality_thresholds,
170*d9f75844SAndroid Build Coastguard Worker                        const BitstreamThresholds* bs_thresholds) = 0;
171*d9f75844SAndroid Build Coastguard Worker   virtual VideoCodecTestStats& GetStats() = 0;
172*d9f75844SAndroid Build Coastguard Worker };
173*d9f75844SAndroid Build Coastguard Worker 
174*d9f75844SAndroid Build Coastguard Worker }  // namespace test
175*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
176*d9f75844SAndroid Build Coastguard Worker 
177*d9f75844SAndroid Build Coastguard Worker #endif  // API_TEST_VIDEOCODEC_TEST_FIXTURE_H_
178