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" |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 18 | #include "api/video_codecs/video_decoder_factory.h" |
| 19 | #include "api/video_codecs/video_encoder_factory.h" |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 20 | #include "modules/video_coding/include/video_codec_interface.h" |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | namespace test { |
| 24 | |
Sergey Silkin | d716fb9 | 2019-01-07 16:54:57 +0100 | [diff] [blame] | 25 | // 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] | 26 | struct RateProfile { |
| 27 | size_t target_kbps; |
| 28 | size_t input_fps; |
Sergey Silkin | d716fb9 | 2019-01-07 16:54:57 +0100 | [diff] [blame] | 29 | size_t frame_num; |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | struct RateControlThresholds { |
| 33 | double max_avg_bitrate_mismatch_percent; |
| 34 | double max_time_to_reach_target_bitrate_sec; |
| 35 | // TODO(ssilkin): Use absolute threshold for framerate. |
| 36 | double max_avg_framerate_mismatch_percent; |
| 37 | double max_avg_buffer_level_sec; |
| 38 | double max_max_key_frame_delay_sec; |
| 39 | double max_max_delta_frame_delay_sec; |
| 40 | size_t max_num_spatial_resizes; |
| 41 | size_t max_num_key_frames; |
| 42 | }; |
| 43 | |
| 44 | struct QualityThresholds { |
| 45 | double min_avg_psnr; |
| 46 | double min_min_psnr; |
| 47 | double min_avg_ssim; |
| 48 | double min_min_ssim; |
| 49 | }; |
| 50 | |
| 51 | struct BitstreamThresholds { |
| 52 | size_t max_max_nalu_size_bytes; |
| 53 | }; |
| 54 | |
Rasmus Brandt | 7c1ccfa | 2018-05-25 11:58:44 +0200 | [diff] [blame] | 55 | // 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] | 56 | class VideoCodecTestFixture { |
| 57 | public: |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 58 | class EncodedFrameChecker { |
| 59 | public: |
| 60 | virtual ~EncodedFrameChecker() = default; |
| 61 | virtual void CheckEncodedFrame(webrtc::VideoCodecType codec, |
| 62 | const EncodedImage& encoded_frame) const = 0; |
| 63 | }; |
Rasmus Brandt | 7c1ccfa | 2018-05-25 11:58:44 +0200 | [diff] [blame] | 64 | |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 65 | struct Config { |
| 66 | Config(); |
| 67 | void SetCodecSettings(std::string codec_name, |
| 68 | size_t num_simulcast_streams, |
| 69 | size_t num_spatial_layers, |
| 70 | size_t num_temporal_layers, |
| 71 | bool denoising_on, |
| 72 | bool frame_dropper_on, |
| 73 | bool spatial_resize_on, |
| 74 | size_t width, |
| 75 | size_t height); |
| 76 | |
| 77 | size_t NumberOfCores() const; |
| 78 | size_t NumberOfTemporalLayers() const; |
| 79 | size_t NumberOfSpatialLayers() const; |
| 80 | size_t NumberOfSimulcastStreams() const; |
| 81 | |
| 82 | std::string ToString() const; |
| 83 | std::string CodecName() const; |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 84 | |
| 85 | // Plain name of YUV file to process without file extension. |
| 86 | std::string filename; |
| 87 | |
| 88 | // File to process. This must be a video file in the YUV format. |
| 89 | std::string filepath; |
| 90 | |
| 91 | // Number of frames to process. |
| 92 | size_t num_frames = 0; |
| 93 | |
| 94 | // Bitstream constraints. |
| 95 | size_t max_payload_size_bytes = 1440; |
| 96 | |
| 97 | // Should we decode the encoded frames? |
| 98 | bool decode = true; |
| 99 | |
| 100 | // Force the encoder and decoder to use a single core for processing. |
| 101 | bool use_single_core = false; |
| 102 | |
| 103 | // Should cpu usage be measured? |
| 104 | // If set to true, the encoding will run in real-time. |
| 105 | bool measure_cpu = false; |
| 106 | |
Kári Tristan Helgason | f167762 | 2018-08-24 13:21:26 +0200 | [diff] [blame] | 107 | // Simulate frames arriving in real-time by adding delays between frames. |
| 108 | bool encode_in_real_time = false; |
| 109 | |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 110 | // Codec settings to use. |
| 111 | webrtc::VideoCodec codec_settings; |
| 112 | |
| 113 | // Name of the codec being tested. |
| 114 | std::string codec_name; |
| 115 | |
| 116 | // H.264 specific settings. |
| 117 | struct H264CodecSettings { |
| 118 | H264::Profile profile = H264::kProfileConstrainedBaseline; |
| 119 | H264PacketizationMode packetization_mode = |
| 120 | webrtc::H264PacketizationMode::NonInterleaved; |
| 121 | } h264_codec_settings; |
| 122 | |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 123 | // Custom checker that will be called for each frame. |
| 124 | const EncodedFrameChecker* encoded_frame_checker = nullptr; |
| 125 | |
| 126 | // Print out frame level stats. |
| 127 | bool print_frame_level_stats = false; |
Rasmus Brandt | 7c1ccfa | 2018-05-25 11:58:44 +0200 | [diff] [blame] | 128 | |
| 129 | // Should video be saved persistently to disk for post-run visualization? |
| 130 | struct VisualizationParams { |
| 131 | bool save_encoded_ivf = false; |
| 132 | bool save_decoded_y4m = false; |
| 133 | } visualization_params; |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 134 | }; |
| 135 | |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 136 | virtual ~VideoCodecTestFixture() = default; |
| 137 | |
| 138 | virtual void RunTest(const std::vector<RateProfile>& rate_profiles, |
| 139 | const std::vector<RateControlThresholds>* rc_thresholds, |
| 140 | const std::vector<QualityThresholds>* quality_thresholds, |
Rasmus Brandt | 7c1ccfa | 2018-05-25 11:58:44 +0200 | [diff] [blame] | 141 | const BitstreamThresholds* bs_thresholds) = 0; |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 142 | virtual VideoCodecTestStats& GetStats() = 0; |
Kári Tristan Helgason | 9d96e92 | 2018-05-04 11:56:55 +0200 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | } // namespace test |
| 146 | } // namespace webrtc |
| 147 | |
| 148 | #endif // API_TEST_VIDEOCODEC_TEST_FIXTURE_H_ |