Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 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 | |
| 11 | #ifndef API_TEST_VIDEOCODEC_TEST_FIXTURE_H_ |
| 12 | #define API_TEST_VIDEOCODEC_TEST_FIXTURE_H_ |
| 13 | |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 14 | #include <string> |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 17 | #include "api/test/videocodec_test_stats.h" |
Johannes Kron | 3cd7a0f | 2021-08-19 12:13:06 +0200 | [diff] [blame] | 18 | #include "api/video_codecs/h264_profile_level_id.h" |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 19 | #include "api/video_codecs/video_decoder_factory.h" |
| 20 | #include "api/video_codecs/video_encoder_factory.h" |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 21 | #include "modules/video_coding/include/video_codec_interface.h" |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | namespace test { |
| 25 | |
Sergey Silkin | d716fb9 | 2019-01-07 16:54:57 +0100 | [diff] [blame] | 26 | // Rates for the encoder and the frame number when to apply profile. |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 27 | struct RateProfile { |
| 28 | size_t target_kbps; |
Sergey Silkin | 44cec0b | 2019-07-11 14:20:38 +0200 | [diff] [blame] | 29 | double input_fps; |
Sergey Silkin | d716fb9 | 2019-01-07 16:54:57 +0100 | [diff] [blame] | 30 | size_t frame_num; |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | struct 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 | |
| 45 | struct QualityThresholds { |
| 46 | double min_avg_psnr; |
| 47 | double min_min_psnr; |
| 48 | double min_avg_ssim; |
| 49 | double min_min_ssim; |
| 50 | }; |
| 51 | |
| 52 | struct BitstreamThresholds { |
| 53 | size_t max_max_nalu_size_bytes; |
| 54 | }; |
| 55 | |
Rasmus Brandt | 7c1ccfa | 2018-05-25 11:58:44 +0200 | [diff] [blame] | 56 | // NOTE: This class is still under development and may change without notice. |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 57 | class VideoCodecTestFixture { |
| 58 | public: |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 59 | class EncodedFrameChecker { |
| 60 | public: |
| 61 | virtual ~EncodedFrameChecker() = default; |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 62 | virtual void CheckEncodedFrame(VideoCodecType codec, |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 63 | const EncodedImage& encoded_frame) const = 0; |
| 64 | }; |
Rasmus Brandt | 7c1ccfa | 2018-05-25 11:58:44 +0200 | [diff] [blame] | 65 | |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 66 | 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 Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 85 | |
Rasmus Brandt | 6f0aafa | 2019-03-07 14:27:57 +0100 | [diff] [blame] | 86 | // Name of this config, to be used for accounting by the test runner. |
| 87 | std::string test_name; |
| 88 | |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 89 | // Plain name of YUV file to process without file extension. |
| 90 | std::string filename; |
Erik Språng | ebe5acb | 2020-12-03 16:18:44 +0100 | [diff] [blame] | 91 | // 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 Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 102 | |
| 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 Helgason | f167762 | 2018-08-24 13:21:26 +0200 | [diff] [blame] | 122 | // Simulate frames arriving in real-time by adding delays between frames. |
| 123 | bool encode_in_real_time = false; |
| 124 | |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 125 | // Codec settings to use. |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 126 | VideoCodec codec_settings; |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 127 | |
| 128 | // Name of the codec being tested. |
| 129 | std::string codec_name; |
| 130 | |
Sergey Silkin | 984cf9b | 2021-11-22 08:00:32 +0100 | [diff] [blame] | 131 | // 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 Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 139 | // H.264 specific settings. |
| 140 | struct H264CodecSettings { |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 141 | H264Profile profile = H264Profile::kProfileConstrainedBaseline; |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 142 | H264PacketizationMode packetization_mode = |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 143 | H264PacketizationMode::NonInterleaved; |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 144 | } h264_codec_settings; |
| 145 | |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 146 | // 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 Brandt | 7c1ccfa | 2018-05-25 11:58:44 +0200 | [diff] [blame] | 151 | |
Sergey Silkin | df8fd28 | 2019-11-05 15:14:51 +0100 | [diff] [blame] | 152 | // Path to a directory where encoded or/and decoded video should be saved. |
| 153 | std::string output_path; |
| 154 | |
Rasmus Brandt | 7c1ccfa | 2018-05-25 11:58:44 +0200 | [diff] [blame] | 155 | // 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 Silkin | b72cc6d | 2020-10-29 08:29:26 +0100 | [diff] [blame] | 160 | |
| 161 | // Enables quality analysis for dropped frames. |
| 162 | bool analyze_quality_of_dropped_frames = false; |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 163 | }; |
| 164 | |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 165 | 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 Brandt | 7c1ccfa | 2018-05-25 11:58:44 +0200 | [diff] [blame] | 170 | const BitstreamThresholds* bs_thresholds) = 0; |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 171 | virtual VideoCodecTestStats& GetStats() = 0; |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | } // namespace test |
| 175 | } // namespace webrtc |
| 176 | |
| 177 | #endif // API_TEST_VIDEOCODEC_TEST_FIXTURE_H_ |