OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 | 12 |
13 #include <map> | |
14 | |
15 #include "gflags/gflags.h" | 13 #include "gflags/gflags.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
17 | 15 |
18 #include "webrtc/base/checks.h" | |
19 #include "webrtc/test/field_trial.h" | 16 #include "webrtc/test/field_trial.h" |
20 #include "webrtc/test/frame_generator.h" | |
21 #include "webrtc/test/frame_generator_capturer.h" | |
22 #include "webrtc/test/run_test.h" | 17 #include "webrtc/test/run_test.h" |
23 #include "webrtc/test/testsupport/fileutils.h" | 18 #include "webrtc/video/video_quality_test.h" |
24 #include "webrtc/typedefs.h" | |
25 #include "webrtc/video/loopback.h" | |
26 #include "webrtc/video/video_send_stream.h" | |
27 | 19 |
28 namespace webrtc { | 20 namespace webrtc { |
29 namespace flags { | 21 namespace flags { |
30 | 22 |
31 DEFINE_int32(width, 1850, "Video width (crops source)."); | 23 DEFINE_int32(width, 1850, "Video width (crops source)."); |
32 size_t Width() { | 24 size_t Width() { |
33 return static_cast<size_t>(FLAGS_width); | 25 return static_cast<size_t>(FLAGS_width); |
34 } | 26 } |
35 | 27 |
36 DEFINE_int32(height, 1110, "Video height (crops source)."); | 28 DEFINE_int32(height, 1110, "Video height (crops source)."); |
(...skipping 14 matching lines...) Expand all Loading... |
51 } | 43 } |
52 | 44 |
53 DEFINE_int32( | 45 DEFINE_int32( |
54 scroll_duration, | 46 scroll_duration, |
55 0, | 47 0, |
56 "Duration (in seconds) during which a slide will be scrolled into place."); | 48 "Duration (in seconds) during which a slide will be scrolled into place."); |
57 int ScrollDuration() { | 49 int ScrollDuration() { |
58 return static_cast<int>(FLAGS_scroll_duration); | 50 return static_cast<int>(FLAGS_scroll_duration); |
59 } | 51 } |
60 | 52 |
61 DEFINE_int32(min_bitrate, 50, "Minimum video bitrate."); | 53 DEFINE_int32(min_bitrate, 50, "Call and stream min bitrate in kbps."); |
62 size_t MinBitrate() { | 54 int MinBitrateKbps() { |
63 return static_cast<size_t>(FLAGS_min_bitrate); | 55 return static_cast<int>(FLAGS_min_bitrate); |
64 } | 56 } |
65 | 57 |
66 DEFINE_int32(tl0_bitrate, 200, "Temporal layer 0 target bitrate."); | 58 DEFINE_int32(start_bitrate, 200, "Call start bitrate in kbps."); |
67 size_t StartBitrate() { | 59 int StartBitrateKbps() { |
68 return static_cast<size_t>(FLAGS_tl0_bitrate); | 60 return static_cast<int>(FLAGS_start_bitrate); |
69 } | 61 } |
70 | 62 |
71 DEFINE_int32(tl1_bitrate, 2000, "Temporal layer 1 target bitrate."); | 63 DEFINE_int32(target_bitrate, 2000, "Stream target bitrate in kbps."); |
72 size_t MaxBitrate() { | 64 int TargetBitrateKbps() { |
73 return static_cast<size_t>(FLAGS_tl1_bitrate); | 65 return static_cast<int>(FLAGS_target_bitrate); |
| 66 } |
| 67 |
| 68 DEFINE_int32(max_bitrate, 2000, "Call and stream max bitrate in kbps."); |
| 69 int MaxBitrateKbps() { |
| 70 return static_cast<int>(FLAGS_max_bitrate); |
74 } | 71 } |
75 | 72 |
76 DEFINE_int32(num_temporal_layers, 2, "Number of temporal layers to use."); | 73 DEFINE_int32(num_temporal_layers, 2, "Number of temporal layers to use."); |
77 int NumTemporalLayers() { | 74 size_t NumTemporalLayers() { |
78 return static_cast<int>(FLAGS_num_temporal_layers); | 75 return static_cast<size_t>(FLAGS_num_temporal_layers); |
79 } | |
80 | |
81 DEFINE_int32(num_spatial_layers, 1, "Number of spatial layers to use."); | |
82 int NumSpatialLayers() { | |
83 return static_cast<int>(FLAGS_num_spatial_layers); | |
84 } | 76 } |
85 | 77 |
86 DEFINE_int32( | 78 DEFINE_int32( |
87 tl_discard_threshold, | 79 tl_discard_threshold, |
88 0, | 80 0, |
89 "Discard TLs with id greater or equal the threshold. 0 to disable."); | 81 "Discard TLs with id greater or equal the threshold. 0 to disable."); |
90 int TLDiscardThreshold() { | 82 size_t TLDiscardThreshold() { |
91 return static_cast<int>(FLAGS_tl_discard_threshold); | 83 return static_cast<size_t>(FLAGS_tl_discard_threshold); |
92 } | |
93 | |
94 DEFINE_int32( | |
95 sl_discard_threshold, | |
96 0, | |
97 "Discard SLs with id greater or equal the threshold. 0 to disable."); | |
98 int SLDiscardThreshold() { | |
99 return static_cast<int>(FLAGS_sl_discard_threshold); | |
100 } | 84 } |
101 | 85 |
102 DEFINE_int32(min_transmit_bitrate, 400, "Min transmit bitrate incl. padding."); | 86 DEFINE_int32(min_transmit_bitrate, 400, "Min transmit bitrate incl. padding."); |
103 int MinTransmitBitrate() { | 87 int MinTransmitBitrateKbps() { |
104 return FLAGS_min_transmit_bitrate; | 88 return FLAGS_min_transmit_bitrate; |
105 } | 89 } |
106 | 90 |
107 DEFINE_string(codec, "VP8", "Video codec to use."); | 91 DEFINE_string(codec, "VP8", "Video codec to use."); |
108 std::string Codec() { | 92 std::string Codec() { |
109 return static_cast<std::string>(FLAGS_codec); | 93 return static_cast<std::string>(FLAGS_codec); |
110 } | 94 } |
111 | 95 |
112 DEFINE_int32(loss_percent, 0, "Percentage of packets randomly lost."); | 96 DEFINE_int32(loss_percent, 0, "Percentage of packets randomly lost."); |
113 int LossPercent() { | 97 int LossPercent() { |
114 return static_cast<int>(FLAGS_loss_percent); | 98 return static_cast<int>(FLAGS_loss_percent); |
115 } | 99 } |
116 | 100 |
117 DEFINE_int32(link_capacity, | 101 DEFINE_int32(link_capacity, |
118 0, | 102 0, |
119 "Capacity (kbps) of the fake link. 0 means infinite."); | 103 "Capacity (kbps) of the fake link. 0 means infinite."); |
120 int LinkCapacity() { | 104 int LinkCapacityKbps() { |
121 return static_cast<int>(FLAGS_link_capacity); | 105 return static_cast<int>(FLAGS_link_capacity); |
122 } | 106 } |
123 | 107 |
124 DEFINE_int32(queue_size, 0, "Size of the bottleneck link queue in packets."); | 108 DEFINE_int32(queue_size, 0, "Size of the bottleneck link queue in packets."); |
125 int QueueSize() { | 109 int QueueSize() { |
126 return static_cast<int>(FLAGS_queue_size); | 110 return static_cast<int>(FLAGS_queue_size); |
127 } | 111 } |
128 | 112 |
129 DEFINE_int32(avg_propagation_delay_ms, | 113 DEFINE_int32(avg_propagation_delay_ms, |
130 0, | 114 0, |
131 "Average link propagation delay in ms."); | 115 "Average link propagation delay in ms."); |
132 int AvgPropagationDelayMs() { | 116 int AvgPropagationDelayMs() { |
133 return static_cast<int>(FLAGS_avg_propagation_delay_ms); | 117 return static_cast<int>(FLAGS_avg_propagation_delay_ms); |
134 } | 118 } |
135 | 119 |
136 DEFINE_int32(std_propagation_delay_ms, | 120 DEFINE_int32(std_propagation_delay_ms, |
137 0, | 121 0, |
138 "Link propagation delay standard deviation in ms."); | 122 "Link propagation delay standard deviation in ms."); |
139 int StdPropagationDelayMs() { | 123 int StdPropagationDelayMs() { |
140 return static_cast<int>(FLAGS_std_propagation_delay_ms); | 124 return static_cast<int>(FLAGS_std_propagation_delay_ms); |
141 } | 125 } |
142 | 126 |
143 DEFINE_bool(logs, false, "print logs to stderr"); | 127 DEFINE_bool(logs, false, "print logs to stderr"); |
144 | 128 |
145 DEFINE_string( | 129 DEFINE_string( |
| 130 output_filename, |
| 131 "", |
| 132 "Name of a target graph data file. If set, no preview will be shown."); |
| 133 std::string OutputFilename() { |
| 134 return static_cast<std::string>(FLAGS_output_filename); |
| 135 } |
| 136 |
| 137 DEFINE_int32(duration, 60, "Duration of the test in seconds."); |
| 138 int DurationSecs() { |
| 139 return static_cast<int>(FLAGS_duration); |
| 140 } |
| 141 |
| 142 DEFINE_string( |
146 force_fieldtrials, | 143 force_fieldtrials, |
147 "", | 144 "", |
148 "Field trials control experimental feature code which can be forced. " | 145 "Field trials control experimental feature code which can be forced. " |
149 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/" | 146 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/" |
150 " will assign the group Enable to field trial WebRTC-FooFeature. Multiple " | 147 " will assign the group Enable to field trial WebRTC-FooFeature. Multiple " |
151 "trials are separated by \"/\""); | 148 "trials are separated by \"/\""); |
152 } // namespace flags | 149 } // namespace flags |
153 | 150 |
154 class ScreenshareLoopback : public test::Loopback { | 151 void Loopback() { |
155 public: | 152 FakeNetworkPipe::Config pipe_config; |
156 explicit ScreenshareLoopback(const Config& config) : Loopback(config) { | 153 pipe_config.loss_percent = flags::LossPercent(); |
157 RTC_CHECK_GE(config.num_temporal_layers, 1u); | 154 pipe_config.link_capacity_kbps = flags::LinkCapacityKbps(); |
158 RTC_CHECK_LE(config.num_temporal_layers, 2u); | 155 pipe_config.queue_length_packets = flags::QueueSize(); |
159 RTC_CHECK_GE(config.num_spatial_layers, 1u); | 156 pipe_config.queue_delay_ms = flags::AvgPropagationDelayMs(); |
160 RTC_CHECK_LE(config.num_spatial_layers, 5u); | 157 pipe_config.delay_standard_deviation_ms = flags::StdPropagationDelayMs(); |
161 RTC_CHECK(config.num_spatial_layers == 1 || config.codec == "VP9"); | |
162 RTC_CHECK(config.num_spatial_layers == 1 || | |
163 config.num_temporal_layers == 1); | |
164 RTC_CHECK_LT(config.tl_discard_threshold, config.num_temporal_layers); | |
165 RTC_CHECK_LT(config.sl_discard_threshold, config.num_spatial_layers); | |
166 | 158 |
167 vp8_settings_ = VideoEncoder::GetDefaultVp8Settings(); | 159 Call::Config::BitrateConfig call_bitrate_config; |
168 vp8_settings_.denoisingOn = false; | 160 call_bitrate_config.min_bitrate_bps = flags::MinBitrateKbps() * 1000; |
169 vp8_settings_.frameDroppingOn = false; | 161 call_bitrate_config.start_bitrate_bps = flags::StartBitrateKbps() * 1000; |
170 vp8_settings_.numberOfTemporalLayers = | 162 call_bitrate_config.max_bitrate_bps = flags::MaxBitrateKbps() * 1000; |
171 static_cast<unsigned char>(config.num_temporal_layers); | |
172 | 163 |
173 vp9_settings_ = VideoEncoder::GetDefaultVp9Settings(); | 164 VideoQualityTest::Params params{ |
174 vp9_settings_.denoisingOn = false; | 165 { |
175 vp9_settings_.frameDroppingOn = false; | 166 flags::Width(), |
176 vp9_settings_.numberOfTemporalLayers = | 167 flags::Height(), |
177 static_cast<unsigned char>(config.num_temporal_layers); | 168 flags::Fps(), |
178 vp9_settings_.numberOfSpatialLayers = | 169 flags::MinBitrateKbps() * 1000, |
179 static_cast<unsigned char>(config.num_spatial_layers); | 170 flags::TargetBitrateKbps() * 1000, |
180 } | 171 flags::MaxBitrateKbps() * 1000, |
181 virtual ~ScreenshareLoopback() {} | 172 flags::Codec(), |
| 173 flags::NumTemporalLayers(), |
| 174 flags::MinTransmitBitrateKbps() * 1000, |
| 175 call_bitrate_config, |
| 176 flags::TLDiscardThreshold() |
| 177 }, |
| 178 {}, // Video specific. |
| 179 {true, flags::SlideChangeInterval(), flags::ScrollDuration()}, |
| 180 {"screenshare", 0.0, 0.0, flags::DurationSecs(), flags::OutputFilename()}, |
| 181 pipe_config, |
| 182 flags::FLAGS_logs}; |
182 | 183 |
183 protected: | 184 VideoQualityTest test; |
184 VideoEncoderConfig CreateEncoderConfig() override { | 185 if (flags::OutputFilename().empty()) |
185 VideoEncoderConfig encoder_config(test::Loopback::CreateEncoderConfig()); | 186 test.RunWithVideoRenderer(params); |
186 VideoStream* stream = &encoder_config.streams[0]; | 187 else |
187 encoder_config.content_type = VideoEncoderConfig::ContentType::kScreen; | 188 test.RunWithAnalyzer(params); |
188 encoder_config.min_transmit_bitrate_bps = flags::MinTransmitBitrate(); | |
189 int num_temporal_layers; | |
190 if (config_.codec == "VP8") { | |
191 encoder_config.encoder_specific_settings = &vp8_settings_; | |
192 num_temporal_layers = vp8_settings_.numberOfTemporalLayers; | |
193 } else if (config_.codec == "VP9") { | |
194 encoder_config.encoder_specific_settings = &vp9_settings_; | |
195 num_temporal_layers = vp9_settings_.numberOfTemporalLayers; | |
196 } else { | |
197 RTC_NOTREACHED() << "Codec not supported!"; | |
198 abort(); | |
199 } | |
200 stream->temporal_layer_thresholds_bps.clear(); | |
201 stream->target_bitrate_bps = | |
202 static_cast<int>(config_.start_bitrate_kbps) * 1000; | |
203 if (num_temporal_layers == 2) { | |
204 stream->temporal_layer_thresholds_bps.push_back( | |
205 stream->target_bitrate_bps); | |
206 } | |
207 return encoder_config; | |
208 } | |
209 | |
210 test::VideoCapturer* CreateCapturer(VideoSendStream* send_stream) override { | |
211 std::vector<std::string> slides; | |
212 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv")); | |
213 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv")); | |
214 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv")); | |
215 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv")); | |
216 | |
217 // Fixed for input resolution for prerecorded screenshare content. | |
218 const size_t kWidth = 1850; | |
219 const size_t kHeight = 1110; | |
220 RTC_CHECK_LE(flags::Width(), kWidth); | |
221 RTC_CHECK_LE(flags::Height(), kHeight); | |
222 RTC_CHECK_GT(flags::SlideChangeInterval(), 0); | |
223 const int kPauseDurationMs = | |
224 (flags::SlideChangeInterval() - flags::ScrollDuration()) * 1000; | |
225 RTC_CHECK_LE(flags::ScrollDuration(), flags::SlideChangeInterval()); | |
226 | |
227 test::FrameGenerator* frame_generator = | |
228 test::FrameGenerator::CreateScrollingInputFromYuvFiles( | |
229 Clock::GetRealTimeClock(), slides, kWidth, kHeight, flags::Width(), | |
230 flags::Height(), flags::ScrollDuration() * 1000, kPauseDurationMs); | |
231 | |
232 test::FrameGeneratorCapturer* capturer(new test::FrameGeneratorCapturer( | |
233 clock_, send_stream->Input(), frame_generator, flags::Fps())); | |
234 EXPECT_TRUE(capturer->Init()); | |
235 return capturer; | |
236 } | |
237 | |
238 VideoCodecVP8 vp8_settings_; | |
239 VideoCodecVP9 vp9_settings_; | |
240 }; | |
241 | |
242 void Loopback() { | |
243 test::Loopback::Config config{flags::Width(), | |
244 flags::Height(), | |
245 flags::Fps(), | |
246 flags::MinBitrate(), | |
247 flags::StartBitrate(), | |
248 flags::MaxBitrate(), | |
249 flags::MinTransmitBitrate(), | |
250 flags::Codec(), | |
251 flags::NumTemporalLayers(), | |
252 flags::NumSpatialLayers(), | |
253 flags::TLDiscardThreshold(), | |
254 flags::SLDiscardThreshold(), | |
255 flags::LossPercent(), | |
256 flags::LinkCapacity(), | |
257 flags::QueueSize(), | |
258 flags::AvgPropagationDelayMs(), | |
259 flags::StdPropagationDelayMs(), | |
260 flags::FLAGS_logs}; | |
261 ScreenshareLoopback loopback(config); | |
262 loopback.Run(); | |
263 } | 189 } |
264 } // namespace webrtc | 190 } // namespace webrtc |
265 | 191 |
266 int main(int argc, char* argv[]) { | 192 int main(int argc, char* argv[]) { |
267 ::testing::InitGoogleTest(&argc, argv); | 193 ::testing::InitGoogleTest(&argc, argv); |
268 google::ParseCommandLineFlags(&argc, &argv, true); | 194 google::ParseCommandLineFlags(&argc, &argv, true); |
269 webrtc::test::InitFieldTrialsFromString( | 195 webrtc::test::InitFieldTrialsFromString( |
270 webrtc::flags::FLAGS_force_fieldtrials); | 196 webrtc::flags::FLAGS_force_fieldtrials); |
271 webrtc::test::RunTest(webrtc::Loopback); | 197 webrtc::test::RunTest(webrtc::Loopback); |
272 return 0; | 198 return 0; |
273 } | 199 } |
OLD | NEW |