blob: 2ed40910b2a0829655cbeb3fe26c5544b029e60e [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"
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +020018#include "api/video_codecs/video_decoder_factory.h"
19#include "api/video_codecs/video_encoder_factory.h"
Niels Möller67615462020-08-12 12:04:31 +020020#include "media/base/h264_profile_level_id.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;
62 virtual void CheckEncodedFrame(webrtc::VideoCodecType codec,
63 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;
91
92 // File to process. This must be a video file in the YUV format.
93 std::string filepath;
94
95 // Number of frames to process.
96 size_t num_frames = 0;
97
98 // Bitstream constraints.
99 size_t max_payload_size_bytes = 1440;
100
101 // Should we decode the encoded frames?
102 bool decode = true;
103
104 // Force the encoder and decoder to use a single core for processing.
105 bool use_single_core = false;
106
107 // Should cpu usage be measured?
108 // If set to true, the encoding will run in real-time.
109 bool measure_cpu = false;
110
Kári Tristan Helgasonf1677622018-08-24 13:21:26 +0200111 // Simulate frames arriving in real-time by adding delays between frames.
112 bool encode_in_real_time = false;
113
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200114 // Codec settings to use.
115 webrtc::VideoCodec codec_settings;
116
117 // Name of the codec being tested.
118 std::string codec_name;
119
120 // H.264 specific settings.
121 struct H264CodecSettings {
122 H264::Profile profile = H264::kProfileConstrainedBaseline;
123 H264PacketizationMode packetization_mode =
124 webrtc::H264PacketizationMode::NonInterleaved;
125 } h264_codec_settings;
126
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200127 // Custom checker that will be called for each frame.
128 const EncodedFrameChecker* encoded_frame_checker = nullptr;
129
130 // Print out frame level stats.
131 bool print_frame_level_stats = false;
Rasmus Brandt7c1ccfa2018-05-25 11:58:44 +0200132
Sergey Silkindf8fd282019-11-05 15:14:51 +0100133 // Path to a directory where encoded or/and decoded video should be saved.
134 std::string output_path;
135
Rasmus Brandt7c1ccfa2018-05-25 11:58:44 +0200136 // Should video be saved persistently to disk for post-run visualization?
137 struct VisualizationParams {
138 bool save_encoded_ivf = false;
139 bool save_decoded_y4m = false;
140 } visualization_params;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200141 };
142
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +0200143 virtual ~VideoCodecTestFixture() = default;
144
145 virtual void RunTest(const std::vector<RateProfile>& rate_profiles,
146 const std::vector<RateControlThresholds>* rc_thresholds,
147 const std::vector<QualityThresholds>* quality_thresholds,
Rasmus Brandt7c1ccfa2018-05-25 11:58:44 +0200148 const BitstreamThresholds* bs_thresholds) = 0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200149 virtual VideoCodecTestStats& GetStats() = 0;
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +0200150};
151
152} // namespace test
153} // namespace webrtc
154
155#endif // API_TEST_VIDEOCODEC_TEST_FIXTURE_H_