blob: 68e063750c4d6f553bf85a48ed701a02e759c2f8 [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"
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020020#include "modules/video_coding/include/video_codec_interface.h"
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +020021
22namespace webrtc {
23namespace test {
24
25// Rates for the encoder and the frame number when to change profile.
26struct RateProfile {
27 size_t target_kbps;
28 size_t input_fps;
29 size_t frame_index_rate_update;
30};
31
32struct 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
44struct QualityThresholds {
45 double min_avg_psnr;
46 double min_min_psnr;
47 double min_avg_ssim;
48 double min_min_ssim;
49};
50
51struct BitstreamThresholds {
52 size_t max_max_nalu_size_bytes;
53};
54
55// Should video files be saved persistently to disk for post-run visualization?
56struct VisualizationParams {
57 bool save_encoded_ivf;
58 bool save_decoded_y4m;
59};
60
61class VideoCodecTestFixture {
62 public:
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020063 class EncodedFrameChecker {
64 public:
65 virtual ~EncodedFrameChecker() = default;
66 virtual void CheckEncodedFrame(webrtc::VideoCodecType codec,
67 const EncodedImage& encoded_frame) const = 0;
68 };
69 struct Config {
70 Config();
71 void SetCodecSettings(std::string codec_name,
72 size_t num_simulcast_streams,
73 size_t num_spatial_layers,
74 size_t num_temporal_layers,
75 bool denoising_on,
76 bool frame_dropper_on,
77 bool spatial_resize_on,
78 size_t width,
79 size_t height);
80
81 size_t NumberOfCores() const;
82 size_t NumberOfTemporalLayers() const;
83 size_t NumberOfSpatialLayers() const;
84 size_t NumberOfSimulcastStreams() const;
85
86 std::string ToString() const;
87 std::string CodecName() const;
88 bool IsAsyncCodec() const;
89
90 // Plain name of YUV file to process without file extension.
91 std::string filename;
92
93 // File to process. This must be a video file in the YUV format.
94 std::string filepath;
95
96 // Number of frames to process.
97 size_t num_frames = 0;
98
99 // Bitstream constraints.
100 size_t max_payload_size_bytes = 1440;
101
102 // Should we decode the encoded frames?
103 bool decode = true;
104
105 // Force the encoder and decoder to use a single core for processing.
106 bool use_single_core = false;
107
108 // Should cpu usage be measured?
109 // If set to true, the encoding will run in real-time.
110 bool measure_cpu = false;
111
112 // If > 0: forces the encoder to create a keyframe every Nth frame.
113 size_t keyframe_interval = 0;
114
115 // Codec settings to use.
116 webrtc::VideoCodec codec_settings;
117
118 // Name of the codec being tested.
119 std::string codec_name;
120
121 // H.264 specific settings.
122 struct H264CodecSettings {
123 H264::Profile profile = H264::kProfileConstrainedBaseline;
124 H264PacketizationMode packetization_mode =
125 webrtc::H264PacketizationMode::NonInterleaved;
126 } h264_codec_settings;
127
128 // Should hardware accelerated codecs be used?
129 bool hw_encoder = false;
130 bool hw_decoder = false;
131
132 // Should the encoder be wrapped in a SimulcastEncoderAdapter?
133 bool simulcast_adapted_encoder = false;
134
135 // Should the hardware codecs be wrapped in software fallbacks?
136 bool sw_fallback_encoder = false;
137 bool sw_fallback_decoder = false;
138
139 // Custom checker that will be called for each frame.
140 const EncodedFrameChecker* encoded_frame_checker = nullptr;
141
142 // Print out frame level stats.
143 bool print_frame_level_stats = false;
144 };
145
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +0200146 virtual ~VideoCodecTestFixture() = default;
147
148 virtual void RunTest(const std::vector<RateProfile>& rate_profiles,
149 const std::vector<RateControlThresholds>* rc_thresholds,
150 const std::vector<QualityThresholds>* quality_thresholds,
151 const BitstreamThresholds* bs_thresholds,
152 const VisualizationParams* visualization_params) = 0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200153 virtual VideoCodecTestStats& GetStats() = 0;
Kári Tristan Helgason9d96e922018-05-04 11:56:55 +0200154};
155
156} // namespace test
157} // namespace webrtc
158
159#endif // API_TEST_VIDEOCODEC_TEST_FIXTURE_H_