blob: 52fd7bb9884102bd4f76d224ea39e6e5a778ad41 [file] [log] [blame]
sprang@webrtc.org131bea82015-02-18 12:46:06 +00001/*
2 * Copyright (c) 2015 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#include <stdio.h>
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/flags.h"
14#include "test/field_trial.h"
15#include "test/gtest.h"
16#include "test/run_test.h"
17#include "video/video_quality_test.h"
sprang@webrtc.org131bea82015-02-18 12:46:06 +000018
19namespace webrtc {
sprang@webrtc.org131bea82015-02-18 12:46:06 +000020namespace flags {
21
sprangce4aef12015-11-02 07:23:20 -080022// Flags common with screenshare loopback, with different default values.
sprang1168fd42017-06-21 09:00:17 -070023DEFINE_int(width, 640, "Video width.");
sprang@webrtc.org131bea82015-02-18 12:46:06 +000024size_t Width() {
sprang1168fd42017-06-21 09:00:17 -070025 return static_cast<size_t>(FLAG_width);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000026}
27
sprang1168fd42017-06-21 09:00:17 -070028DEFINE_int(height, 480, "Video height.");
sprang@webrtc.org131bea82015-02-18 12:46:06 +000029size_t Height() {
sprang1168fd42017-06-21 09:00:17 -070030 return static_cast<size_t>(FLAG_height);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000031}
32
sprang1168fd42017-06-21 09:00:17 -070033DEFINE_int(fps, 30, "Frames per second.");
sprang@webrtc.org131bea82015-02-18 12:46:06 +000034int Fps() {
sprang1168fd42017-06-21 09:00:17 -070035 return static_cast<int>(FLAG_fps);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000036}
37
sprang1168fd42017-06-21 09:00:17 -070038DEFINE_int(capture_device_index, 0, "Capture device to select");
Tarun Chawla8e857d12017-05-31 19:20:57 +053039size_t GetCaptureDevice() {
sprang1168fd42017-06-21 09:00:17 -070040 return static_cast<size_t>(FLAG_capture_device_index);
Tarun Chawla8e857d12017-05-31 19:20:57 +053041}
42
sprang1168fd42017-06-21 09:00:17 -070043DEFINE_int(min_bitrate, 50, "Call and stream min bitrate in kbps.");
ivica5d6a06c2015-09-17 05:30:24 -070044int MinBitrateKbps() {
sprang1168fd42017-06-21 09:00:17 -070045 return static_cast<int>(FLAG_min_bitrate);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000046}
47
sprang1168fd42017-06-21 09:00:17 -070048DEFINE_int(start_bitrate, 300, "Call start bitrate in kbps.");
ivica5d6a06c2015-09-17 05:30:24 -070049int StartBitrateKbps() {
sprang1168fd42017-06-21 09:00:17 -070050 return static_cast<int>(FLAG_start_bitrate);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000051}
52
sprang1168fd42017-06-21 09:00:17 -070053DEFINE_int(target_bitrate, 800, "Stream target bitrate in kbps.");
ivica5d6a06c2015-09-17 05:30:24 -070054int TargetBitrateKbps() {
sprang1168fd42017-06-21 09:00:17 -070055 return static_cast<int>(FLAG_target_bitrate);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000056}
57
sprang1168fd42017-06-21 09:00:17 -070058DEFINE_int(max_bitrate, 800, "Call and stream max bitrate in kbps.");
ivica5d6a06c2015-09-17 05:30:24 -070059int MaxBitrateKbps() {
sprang1168fd42017-06-21 09:00:17 -070060 return static_cast<int>(FLAG_max_bitrate);
ivica5d6a06c2015-09-17 05:30:24 -070061}
sprang@webrtc.org131bea82015-02-18 12:46:06 +000062
mflodman48a4beb2016-07-01 13:03:59 +020063DEFINE_bool(suspend_below_min_bitrate,
64 false,
65 "Suspends video below the configured min bitrate.");
66
sprang1168fd42017-06-21 09:00:17 -070067DEFINE_int(num_temporal_layers,
68 1,
69 "Number of temporal layers. Set to 1-4 to override.");
sprangce4aef12015-11-02 07:23:20 -080070int NumTemporalLayers() {
sprang1168fd42017-06-21 09:00:17 -070071 return static_cast<int>(FLAG_num_temporal_layers);
sprangce4aef12015-11-02 07:23:20 -080072}
73
74// Flags common with screenshare loopback, with equal default values.
sprang@webrtc.org131bea82015-02-18 12:46:06 +000075DEFINE_string(codec, "VP8", "Video codec to use.");
76std::string Codec() {
sprang1168fd42017-06-21 09:00:17 -070077 return static_cast<std::string>(FLAG_codec);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000078}
79
sprang1168fd42017-06-21 09:00:17 -070080DEFINE_int(selected_tl,
81 -1,
82 "Temporal layer to show or analyze. -1 to disable filtering.");
sprangce4aef12015-11-02 07:23:20 -080083int SelectedTL() {
sprang1168fd42017-06-21 09:00:17 -070084 return static_cast<int>(FLAG_selected_tl);
sprangce4aef12015-11-02 07:23:20 -080085}
86
sprang1168fd42017-06-21 09:00:17 -070087DEFINE_int(
sprangce4aef12015-11-02 07:23:20 -080088 duration,
89 0,
90 "Duration of the test in seconds. If 0, rendered will be shown instead.");
91int DurationSecs() {
sprang1168fd42017-06-21 09:00:17 -070092 return static_cast<int>(FLAG_duration);
sprangce4aef12015-11-02 07:23:20 -080093}
94
95DEFINE_string(output_filename, "", "Target graph data filename.");
96std::string OutputFilename() {
sprang1168fd42017-06-21 09:00:17 -070097 return static_cast<std::string>(FLAG_output_filename);
sprangce4aef12015-11-02 07:23:20 -080098}
99
100DEFINE_string(graph_title,
101 "",
102 "If empty, title will be generated automatically.");
103std::string GraphTitle() {
sprang1168fd42017-06-21 09:00:17 -0700104 return static_cast<std::string>(FLAG_graph_title);
sprangce4aef12015-11-02 07:23:20 -0800105}
106
sprang1168fd42017-06-21 09:00:17 -0700107DEFINE_int(loss_percent, 0, "Percentage of packets randomly lost.");
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000108int LossPercent() {
sprang1168fd42017-06-21 09:00:17 -0700109 return static_cast<int>(FLAG_loss_percent);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000110}
111
sprang1168fd42017-06-21 09:00:17 -0700112DEFINE_int(avg_burst_loss_length, -1, "Average burst length of lost packets.");
philipel536378b2016-05-31 03:20:23 -0700113int AvgBurstLossLength() {
sprang1168fd42017-06-21 09:00:17 -0700114 return static_cast<int>(FLAG_avg_burst_loss_length);
philipel536378b2016-05-31 03:20:23 -0700115}
116
sprang1168fd42017-06-21 09:00:17 -0700117DEFINE_int(link_capacity,
118 0,
119 "Capacity (kbps) of the fake link. 0 means infinite.");
ivica5d6a06c2015-09-17 05:30:24 -0700120int LinkCapacityKbps() {
sprang1168fd42017-06-21 09:00:17 -0700121 return static_cast<int>(FLAG_link_capacity);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000122}
123
sprang1168fd42017-06-21 09:00:17 -0700124DEFINE_int(queue_size, 0, "Size of the bottleneck link queue in packets.");
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000125int QueueSize() {
sprang1168fd42017-06-21 09:00:17 -0700126 return static_cast<int>(FLAG_queue_size);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000127}
128
sprang1168fd42017-06-21 09:00:17 -0700129DEFINE_int(avg_propagation_delay_ms,
130 0,
131 "Average link propagation delay in ms.");
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000132int AvgPropagationDelayMs() {
sprang1168fd42017-06-21 09:00:17 -0700133 return static_cast<int>(FLAG_avg_propagation_delay_ms);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000134}
135
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +0100136DEFINE_string(rtc_event_log_name,
137 "",
138 "Filename for rtc event log. Two files "
139 "with \"_send\" and \"_recv\" suffixes will be created.");
ilnik98436952017-07-13 00:47:03 -0700140std::string RtcEventLogName() {
141 return static_cast<std::string>(FLAG_rtc_event_log_name);
142}
143
144DEFINE_string(rtp_dump_name, "", "Filename for dumped received RTP stream.");
145std::string RtpDumpName() {
146 return static_cast<std::string>(FLAG_rtp_dump_name);
147}
148
sprang1168fd42017-06-21 09:00:17 -0700149DEFINE_int(std_propagation_delay_ms,
150 0,
151 "Link propagation delay standard deviation in ms.");
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000152int StdPropagationDelayMs() {
sprang1168fd42017-06-21 09:00:17 -0700153 return static_cast<int>(FLAG_std_propagation_delay_ms);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000154}
155
sprang1168fd42017-06-21 09:00:17 -0700156DEFINE_int(num_streams, 0, "Number of streams to show or analyze.");
157int NumStreams() {
158 return static_cast<int>(FLAG_num_streams);
159}
160
161DEFINE_int(selected_stream,
162 0,
163 "ID of the stream to show or analyze. "
164 "Set to the number of streams to show them all.");
sprangce4aef12015-11-02 07:23:20 -0800165int SelectedStream() {
sprang1168fd42017-06-21 09:00:17 -0700166 return static_cast<int>(FLAG_selected_stream);
sprangce4aef12015-11-02 07:23:20 -0800167}
168
sprang1168fd42017-06-21 09:00:17 -0700169DEFINE_int(num_spatial_layers, 1, "Number of spatial layers to use.");
sprangce4aef12015-11-02 07:23:20 -0800170int NumSpatialLayers() {
sprang1168fd42017-06-21 09:00:17 -0700171 return static_cast<int>(FLAG_num_spatial_layers);
sprangce4aef12015-11-02 07:23:20 -0800172}
173
sprang1168fd42017-06-21 09:00:17 -0700174DEFINE_int(selected_sl,
175 -1,
176 "Spatial layer to show or analyze. -1 to disable filtering.");
sprangce4aef12015-11-02 07:23:20 -0800177int SelectedSL() {
sprang1168fd42017-06-21 09:00:17 -0700178 return static_cast<int>(FLAG_selected_sl);
sprangce4aef12015-11-02 07:23:20 -0800179}
180
181DEFINE_string(stream0,
182 "",
183 "Comma separated values describing VideoStream for stream #0.");
184std::string Stream0() {
sprang1168fd42017-06-21 09:00:17 -0700185 return static_cast<std::string>(FLAG_stream0);
sprangce4aef12015-11-02 07:23:20 -0800186}
187
188DEFINE_string(stream1,
189 "",
190 "Comma separated values describing VideoStream for stream #1.");
191std::string Stream1() {
sprang1168fd42017-06-21 09:00:17 -0700192 return static_cast<std::string>(FLAG_stream1);
sprangce4aef12015-11-02 07:23:20 -0800193}
194
195DEFINE_string(sl0,
196 "",
197 "Comma separated values describing SpatialLayer for layer #0.");
198std::string SL0() {
sprang1168fd42017-06-21 09:00:17 -0700199 return static_cast<std::string>(FLAG_sl0);
sprangce4aef12015-11-02 07:23:20 -0800200}
201
202DEFINE_string(sl1,
203 "",
204 "Comma separated values describing SpatialLayer for layer #1.");
205std::string SL1() {
sprang1168fd42017-06-21 09:00:17 -0700206 return static_cast<std::string>(FLAG_sl1);
sprangce4aef12015-11-02 07:23:20 -0800207}
208
palmkviste75f2042016-09-28 06:19:48 -0700209DEFINE_string(encoded_frame_path,
210 "",
211 "The base path for encoded frame logs. Created files will have "
212 "the form <encoded_frame_path>.<n>.(recv|send.<m>).ivf");
213std::string EncodedFramePath() {
sprang1168fd42017-06-21 09:00:17 -0700214 return static_cast<std::string>(FLAG_encoded_frame_path);
palmkviste75f2042016-09-28 06:19:48 -0700215}
216
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000217DEFINE_bool(logs, false, "print logs to stderr");
218
sprangce4aef12015-11-02 07:23:20 -0800219DEFINE_bool(send_side_bwe, true, "Use send-side bandwidth estimation");
220
philipela2c55232016-01-26 08:41:53 -0800221DEFINE_bool(allow_reordering, false, "Allow packet reordering to occur");
222
brandtra62f5822016-11-17 00:21:13 -0800223DEFINE_bool(use_ulpfec, false, "Use RED+ULPFEC forward error correction.");
224
225DEFINE_bool(use_flexfec, false, "Use FlexFEC forward error correction.");
philipel274c1dc2016-05-04 06:21:01 -0700226
minyue73208662016-08-18 06:28:55 -0700227DEFINE_bool(audio, false, "Add audio stream");
228
229DEFINE_bool(audio_video_sync, false, "Sync audio and video stream (no effect if"
230 " audio is false)");
231
minyue4c8b9422017-03-21 04:11:43 -0700232DEFINE_bool(audio_dtx, false, "Enable audio DTX (no effect if audio is false)");
233
minyuea27172d2016-11-01 05:59:29 -0700234DEFINE_bool(video, true, "Add video stream");
235
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000236DEFINE_string(
237 force_fieldtrials,
238 "",
239 "Field trials control experimental feature code which can be forced. "
240 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
241 " will assign the group Enable to field trial WebRTC-FooFeature. Multiple "
242 "trials are separated by \"/\"");
pbos9874ee02015-06-22 04:44:26 -0700243
sprangce4aef12015-11-02 07:23:20 -0800244// Video-specific flags.
ivica5d6a06c2015-09-17 05:30:24 -0700245DEFINE_string(clip,
246 "",
247 "Name of the clip to show. If empty, using chroma generator.");
248std::string Clip() {
sprang1168fd42017-06-21 09:00:17 -0700249 return static_cast<std::string>(FLAG_clip);
ivica5d6a06c2015-09-17 05:30:24 -0700250}
251
sprang1168fd42017-06-21 09:00:17 -0700252DEFINE_bool(help, false, "prints this message");
253
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000254} // namespace flags
255
256void Loopback() {
ivica5d6a06c2015-09-17 05:30:24 -0700257 FakeNetworkPipe::Config pipe_config;
258 pipe_config.loss_percent = flags::LossPercent();
philipel536378b2016-05-31 03:20:23 -0700259 pipe_config.avg_burst_loss_length = flags::AvgBurstLossLength();
ivica5d6a06c2015-09-17 05:30:24 -0700260 pipe_config.link_capacity_kbps = flags::LinkCapacityKbps();
261 pipe_config.queue_length_packets = flags::QueueSize();
262 pipe_config.queue_delay_ms = flags::AvgPropagationDelayMs();
263 pipe_config.delay_standard_deviation_ms = flags::StdPropagationDelayMs();
sprang1168fd42017-06-21 09:00:17 -0700264 pipe_config.allow_reordering = flags::FLAG_allow_reordering;
ivica5d6a06c2015-09-17 05:30:24 -0700265
266 Call::Config::BitrateConfig call_bitrate_config;
267 call_bitrate_config.min_bitrate_bps = flags::MinBitrateKbps() * 1000;
268 call_bitrate_config.start_bitrate_bps = flags::StartBitrateKbps() * 1000;
269 call_bitrate_config.max_bitrate_bps = flags::MaxBitrateKbps() * 1000;
270
minyue73208662016-08-18 06:28:55 -0700271 VideoQualityTest::Params params;
ilnik98436952017-07-13 00:47:03 -0700272 params.call = {flags::FLAG_send_side_bwe, call_bitrate_config, 0};
sprang1168fd42017-06-21 09:00:17 -0700273 params.video = {flags::FLAG_video,
minyue626bc952016-10-31 05:47:02 -0700274 flags::Width(),
275 flags::Height(),
276 flags::Fps(),
277 flags::MinBitrateKbps() * 1000,
278 flags::TargetBitrateKbps() * 1000,
279 flags::MaxBitrateKbps() * 1000,
sprang1168fd42017-06-21 09:00:17 -0700280 flags::FLAG_suspend_below_min_bitrate,
minyue626bc952016-10-31 05:47:02 -0700281 flags::Codec(),
282 flags::NumTemporalLayers(),
283 flags::SelectedTL(),
284 0, // No min transmit bitrate.
sprang1168fd42017-06-21 09:00:17 -0700285 flags::FLAG_use_ulpfec,
286 flags::FLAG_use_flexfec,
Tarun Chawla8e857d12017-05-31 19:20:57 +0530287 flags::Clip(),
288 flags::GetCaptureDevice()};
sprang1168fd42017-06-21 09:00:17 -0700289 params.audio = {flags::FLAG_audio, flags::FLAG_audio_video_sync,
290 flags::FLAG_audio_dtx};
ilnik98436952017-07-13 00:47:03 -0700291 params.logging = {flags::FLAG_logs, flags::FLAG_rtc_event_log_name,
292 flags::FLAG_rtp_dump_name, flags::FLAG_encoded_frame_path};
asapersson3ec3da62016-10-11 16:20:33 -0700293 params.screenshare.enabled = false;
minyue73208662016-08-18 06:28:55 -0700294 params.analyzer = {"video", 0.0, 0.0, flags::DurationSecs(),
295 flags::OutputFilename(), flags::GraphTitle()};
296 params.pipe = pipe_config;
sprang1168fd42017-06-21 09:00:17 -0700297
298 if (flags::NumStreams() > 1 && flags::Stream0().empty() &&
299 flags::Stream1().empty()) {
300 params.ss.infer_streams = true;
301 }
ivica5d6a06c2015-09-17 05:30:24 -0700302
sprangce4aef12015-11-02 07:23:20 -0800303 std::vector<std::string> stream_descriptors;
304 stream_descriptors.push_back(flags::Stream0());
305 stream_descriptors.push_back(flags::Stream1());
306 std::vector<std::string> SL_descriptors;
307 SL_descriptors.push_back(flags::SL0());
308 SL_descriptors.push_back(flags::SL1());
309 VideoQualityTest::FillScalabilitySettings(
sprang1168fd42017-06-21 09:00:17 -0700310 &params, stream_descriptors, flags::NumStreams(), flags::SelectedStream(),
sprangce4aef12015-11-02 07:23:20 -0800311 flags::NumSpatialLayers(), flags::SelectedSL(), SL_descriptors);
312
ivica5d6a06c2015-09-17 05:30:24 -0700313 VideoQualityTest test;
sprangce4aef12015-11-02 07:23:20 -0800314 if (flags::DurationSecs()) {
sprang7a975f72015-10-12 06:33:21 -0700315 test.RunWithAnalyzer(params);
sprangce4aef12015-11-02 07:23:20 -0800316 } else {
minyue73208662016-08-18 06:28:55 -0700317 test.RunWithRenderers(params);
sprangce4aef12015-11-02 07:23:20 -0800318 }
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000319}
320} // namespace webrtc
321
322int main(int argc, char* argv[]) {
323 ::testing::InitGoogleTest(&argc, argv);
sprang1168fd42017-06-21 09:00:17 -0700324 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
325 if (webrtc::flags::FLAG_help) {
326 rtc::FlagList::Print(nullptr, false);
327 return 0;
328 }
329
330 // InitFieldTrialsFromString needs a reference to an std::string instance,
331 // with a scope that outlives the test.
332 std::string field_trials = webrtc::flags::FLAG_force_fieldtrials;
333 webrtc::test::InitFieldTrialsFromString(field_trials);
sprang89c4a7e2017-06-30 13:27:40 -0700334
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000335 webrtc::test::RunTest(webrtc::Loopback);
336 return 0;
337}