blob: dbf20993e2136a0f0708f52ad6716f9de7e50cd5 [file] [log] [blame]
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +02001/*
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
11#ifndef API_TEST_VIDEOCODEC_TEST_FIXTURE_H_
12#define API_TEST_VIDEOCODEC_TEST_FIXTURE_H_
13
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020014#include <string>
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +020015#include <vector>
16
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020017#include "api/test/videocodec_test_stats.h"
Johannes Kron3cd7a0f2021-08-19 12:13:06 +020018#include "api/video_codecs/h264_profile_level_id.h"
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +020019#include "api/video_codecs/video_decoder_factory.h"
20#include "api/video_codecs/video_encoder_factory.h"
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020021#include "modules/video_coding/include/video_codec_interface.h"
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +020022
23namespace webrtc {
24namespace test {
25
Sergey Silkind716fb92019-01-07 16:54:57 +010026// Rates for the encoder and the frame number when to apply profile.
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +020027struct RateProfile {
28 size_t target_kbps;
Sergey Silkin44cec0b2019-07-11 14:20:38 +020029 double input_fps;
Sergey Silkind716fb92019-01-07 16:54:57 +010030 size_t frame_num;
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +020031};
32
33struct RateControlThresholds {
34 double max_avg_bitrate_mismatch_percent;
35 double max_time_to_reach_target_bitrate_sec;
36 // TODO(ssilkin): Use absolute threshold for framerate.
37 double max_avg_framerate_mismatch_percent;
38 double max_avg_buffer_level_sec;
39 double max_max_key_frame_delay_sec;
40 double max_max_delta_frame_delay_sec;
41 size_t max_num_spatial_resizes;
42 size_t max_num_key_frames;
43};
44
45struct QualityThresholds {
46 double min_avg_psnr;
47 double min_min_psnr;
48 double min_avg_ssim;
49 double min_min_ssim;
50};
51
52struct BitstreamThresholds {
53 size_t max_max_nalu_size_bytes;
54};
55
Rasmus Brandt7c1ccfa2018-05-25 11:58:44 +020056// NOTE: This class is still under development and may change without notice.
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +020057class VideoCodecTestFixture {
58 public:
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020059 class EncodedFrameChecker {
60 public:
61 virtual ~EncodedFrameChecker() = default;
Johannes Kronc3fcee72021-04-19 09:09:26 +020062 virtual void CheckEncodedFrame(VideoCodecType codec,
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020063 const EncodedImage& encoded_frame) const = 0;
64 };
Rasmus Brandt7c1ccfa2018-05-25 11:58:44 +020065
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020066 struct Config {
67 Config();
68 void SetCodecSettings(std::string codec_name,
69 size_t num_simulcast_streams,
70 size_t num_spatial_layers,
71 size_t num_temporal_layers,
72 bool denoising_on,
73 bool frame_dropper_on,
74 bool spatial_resize_on,
75 size_t width,
76 size_t height);
77
78 size_t NumberOfCores() const;
79 size_t NumberOfTemporalLayers() const;
80 size_t NumberOfSpatialLayers() const;
81 size_t NumberOfSimulcastStreams() const;
82
83 std::string ToString() const;
84 std::string CodecName() const;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020085
Rasmus Brandt6f0aafa2019-03-07 14:27:57 +010086 // Name of this config, to be used for accounting by the test runner.
87 std::string test_name;
88
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020089 // Plain name of YUV file to process without file extension.
90 std::string filename;
Erik Språngebe5acb2020-12-03 16:18:44 +010091 // Dimensions of test clip. Falls back to (codec_settings.width/height) if
92 // not set.
93 absl::optional<int> clip_width;
94 absl::optional<int> clip_height;
95 // Framerate of input clip. Defaults to 30fps if not set.
96 absl::optional<int> clip_fps;
97
98 // The resolution at which psnr/ssim comparisons should be made. Frames
99 // will be scaled to this size if different.
100 absl::optional<int> reference_width;
101 absl::optional<int> reference_height;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200102
103 // File to process. This must be a video file in the YUV format.
104 std::string filepath;
105
106 // Number of frames to process.
107 size_t num_frames = 0;
108
109 // Bitstream constraints.
110 size_t max_payload_size_bytes = 1440;
111
112 // Should we decode the encoded frames?
113 bool decode = true;
114
115 // Force the encoder and decoder to use a single core for processing.
116 bool use_single_core = false;
117
118 // Should cpu usage be measured?
119 // If set to true, the encoding will run in real-time.
120 bool measure_cpu = false;
121
Kári Tristan Helgasonf1677622018-08-24 13:21:26 +0200122 // Simulate frames arriving in real-time by adding delays between frames.
123 bool encode_in_real_time = false;
124
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200125 // Codec settings to use.
Johannes Kronc3fcee72021-04-19 09:09:26 +0200126 VideoCodec codec_settings;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200127
128 // Name of the codec being tested.
129 std::string codec_name;
130
Sergey Silkin984cf9b2021-11-22 08:00:32 +0100131 // Encoder and decoder format and parameters. If provided, format is used to
132 // instantiate the codec. If not provided, the test creates and uses the
133 // default `SdpVideoFormat` based on `codec_name`.
134 // Encoder and decoder name (`SdpVideoFormat::name`) should be the same as
135 // `codec_name`.
136 absl::optional<SdpVideoFormat> encoder_format;
137 absl::optional<SdpVideoFormat> decoder_format;
138
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200139 // H.264 specific settings.
140 struct H264CodecSettings {
Johannes Kronc3fcee72021-04-19 09:09:26 +0200141 H264Profile profile = H264Profile::kProfileConstrainedBaseline;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200142 H264PacketizationMode packetization_mode =
Johannes Kronc3fcee72021-04-19 09:09:26 +0200143 H264PacketizationMode::NonInterleaved;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200144 } h264_codec_settings;
145
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200146 // Custom checker that will be called for each frame.
147 const EncodedFrameChecker* encoded_frame_checker = nullptr;
148
149 // Print out frame level stats.
150 bool print_frame_level_stats = false;
Rasmus Brandt7c1ccfa2018-05-25 11:58:44 +0200151
Sergey Silkindf8fd282019-11-05 15:14:51 +0100152 // Path to a directory where encoded or/and decoded video should be saved.
153 std::string output_path;
154
Rasmus Brandt7c1ccfa2018-05-25 11:58:44 +0200155 // Should video be saved persistently to disk for post-run visualization?
156 struct VisualizationParams {
157 bool save_encoded_ivf = false;
158 bool save_decoded_y4m = false;
159 } visualization_params;
Sergey Silkinb72cc6d2020-10-29 08:29:26 +0100160
161 // Enables quality analysis for dropped frames.
162 bool analyze_quality_of_dropped_frames = false;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200163 };
164
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +0200165 virtual ~VideoCodecTestFixture() = default;
166
167 virtual void RunTest(const std::vector<RateProfile>& rate_profiles,
168 const std::vector<RateControlThresholds>* rc_thresholds,
169 const std::vector<QualityThresholds>* quality_thresholds,
Rasmus Brandt7c1ccfa2018-05-25 11:58:44 +0200170 const BitstreamThresholds* bs_thresholds) = 0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200171 virtual VideoCodecTestStats& GetStats() = 0;
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +0200172};
173
174} // namespace test
175} // namespace webrtc
176
177#endif // API_TEST_VIDEOCODEC_TEST_FIXTURE_H_