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 <string> 15 #include <vector> 16 17 #include "api/test/videocodec_test_stats.h" 18 #include "api/video_codecs/h264_profile_level_id.h" 19 #include "api/video_codecs/video_decoder_factory.h" 20 #include "api/video_codecs/video_encoder_factory.h" 21 #include "modules/video_coding/include/video_codec_interface.h" 22 23 namespace webrtc { 24 namespace test { 25 26 // Rates for the encoder and the frame number when to apply profile. 27 struct RateProfile { 28 size_t target_kbps; 29 double input_fps; 30 size_t frame_num; 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 56 // NOTE: This class is still under development and may change without notice. 57 class VideoCodecTestFixture { 58 public: 59 class EncodedFrameChecker { 60 public: 61 virtual ~EncodedFrameChecker() = default; 62 virtual void CheckEncodedFrame(VideoCodecType codec, 63 const EncodedImage& encoded_frame) const = 0; 64 }; 65 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; 85 86 // Name of this config, to be used for accounting by the test runner. 87 std::string test_name; 88 89 // Plain name of YUV file to process without file extension. 90 std::string filename; 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; 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 122 // Simulate frames arriving in real-time by adding delays between frames. 123 bool encode_in_real_time = false; 124 125 // Codec settings to use. 126 VideoCodec codec_settings; 127 128 // Name of the codec being tested. 129 std::string codec_name; 130 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 139 // H.264 specific settings. 140 struct H264CodecSettings { 141 H264Profile profile = H264Profile::kProfileConstrainedBaseline; 142 H264PacketizationMode packetization_mode = 143 H264PacketizationMode::NonInterleaved; 144 } h264_codec_settings; 145 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; 151 152 // Path to a directory where encoded or/and decoded video should be saved. 153 std::string output_path; 154 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; 160 161 // Enables quality analysis for dropped frames. 162 bool analyze_quality_of_dropped_frames = false; 163 }; 164 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, 170 const BitstreamThresholds* bs_thresholds) = 0; 171 virtual VideoCodecTestStats& GetStats() = 0; 172 }; 173 174 } // namespace test 175 } // namespace webrtc 176 177 #endif // API_TEST_VIDEOCODEC_TEST_FIXTURE_H_ 178