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