blob: 52fd7bb9884102bd4f76d224ea39e6e5a778ad41 [file] [log] [blame]
sprang@webrtc.org131bea82015-02-18 12:46:061/*
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 04:47:3113#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:0618
19namespace webrtc {
sprang@webrtc.org131bea82015-02-18 12:46:0620namespace flags {
21
sprangce4aef12015-11-02 15:23:2022// Flags common with screenshare loopback, with different default values.
sprang1168fd42017-06-21 16:00:1723DEFINE_int(width, 640, "Video width.");
sprang@webrtc.org131bea82015-02-18 12:46:0624size_t Width() {
sprang1168fd42017-06-21 16:00:1725 return static_cast<size_t>(FLAG_width);
sprang@webrtc.org131bea82015-02-18 12:46:0626}
27
sprang1168fd42017-06-21 16:00:1728DEFINE_int(height, 480, "Video height.");
sprang@webrtc.org131bea82015-02-18 12:46:0629size_t Height() {
sprang1168fd42017-06-21 16:00:1730 return static_cast<size_t>(FLAG_height);
sprang@webrtc.org131bea82015-02-18 12:46:0631}
32
sprang1168fd42017-06-21 16:00:1733DEFINE_int(fps, 30, "Frames per second.");
sprang@webrtc.org131bea82015-02-18 12:46:0634int Fps() {
sprang1168fd42017-06-21 16:00:1735 return static_cast<int>(FLAG_fps);
sprang@webrtc.org131bea82015-02-18 12:46:0636}
37
sprang1168fd42017-06-21 16:00:1738DEFINE_int(capture_device_index, 0, "Capture device to select");
Tarun Chawla8e857d12017-05-31 13:50:5739size_t GetCaptureDevice() {
sprang1168fd42017-06-21 16:00:1740 return static_cast<size_t>(FLAG_capture_device_index);
Tarun Chawla8e857d12017-05-31 13:50:5741}
42
sprang1168fd42017-06-21 16:00:1743DEFINE_int(min_bitrate, 50, "Call and stream min bitrate in kbps.");
ivica5d6a06c2015-09-17 12:30:2444int MinBitrateKbps() {
sprang1168fd42017-06-21 16:00:1745 return static_cast<int>(FLAG_min_bitrate);
sprang@webrtc.org131bea82015-02-18 12:46:0646}
47
sprang1168fd42017-06-21 16:00:1748DEFINE_int(start_bitrate, 300, "Call start bitrate in kbps.");
ivica5d6a06c2015-09-17 12:30:2449int StartBitrateKbps() {
sprang1168fd42017-06-21 16:00:1750 return static_cast<int>(FLAG_start_bitrate);
sprang@webrtc.org131bea82015-02-18 12:46:0651}
52
sprang1168fd42017-06-21 16:00:1753DEFINE_int(target_bitrate, 800, "Stream target bitrate in kbps.");
ivica5d6a06c2015-09-17 12:30:2454int TargetBitrateKbps() {
sprang1168fd42017-06-21 16:00:1755 return static_cast<int>(FLAG_target_bitrate);
sprang@webrtc.org131bea82015-02-18 12:46:0656}
57
sprang1168fd42017-06-21 16:00:1758DEFINE_int(max_bitrate, 800, "Call and stream max bitrate in kbps.");
ivica5d6a06c2015-09-17 12:30:2459int MaxBitrateKbps() {
sprang1168fd42017-06-21 16:00:1760 return static_cast<int>(FLAG_max_bitrate);
ivica5d6a06c2015-09-17 12:30:2461}
sprang@webrtc.org131bea82015-02-18 12:46:0662
mflodman48a4beb2016-07-01 11:03:5963DEFINE_bool(suspend_below_min_bitrate,
64 false,
65 "Suspends video below the configured min bitrate.");
66
sprang1168fd42017-06-21 16:00:1767DEFINE_int(num_temporal_layers,
68 1,
69 "Number of temporal layers. Set to 1-4 to override.");
sprangce4aef12015-11-02 15:23:2070int NumTemporalLayers() {
sprang1168fd42017-06-21 16:00:1771 return static_cast<int>(FLAG_num_temporal_layers);
sprangce4aef12015-11-02 15:23:2072}
73
74// Flags common with screenshare loopback, with equal default values.
sprang@webrtc.org131bea82015-02-18 12:46:0675DEFINE_string(codec, "VP8", "Video codec to use.");
76std::string Codec() {
sprang1168fd42017-06-21 16:00:1777 return static_cast<std::string>(FLAG_codec);
sprang@webrtc.org131bea82015-02-18 12:46:0678}
79
sprang1168fd42017-06-21 16:00:1780DEFINE_int(selected_tl,
81 -1,
82 "Temporal layer to show or analyze. -1 to disable filtering.");
sprangce4aef12015-11-02 15:23:2083int SelectedTL() {
sprang1168fd42017-06-21 16:00:1784 return static_cast<int>(FLAG_selected_tl);
sprangce4aef12015-11-02 15:23:2085}
86
sprang1168fd42017-06-21 16:00:1787DEFINE_int(
sprangce4aef12015-11-02 15:23:2088 duration,
89 0,
90 "Duration of the test in seconds. If 0, rendered will be shown instead.");
91int DurationSecs() {
sprang1168fd42017-06-21 16:00:1792 return static_cast<int>(FLAG_duration);
sprangce4aef12015-11-02 15:23:2093}
94
95DEFINE_string(output_filename, "", "Target graph data filename.");
96std::string OutputFilename() {
sprang1168fd42017-06-21 16:00:1797 return static_cast<std::string>(FLAG_output_filename);
sprangce4aef12015-11-02 15:23:2098}
99
100DEFINE_string(graph_title,
101 "",
102 "If empty, title will be generated automatically.");
103std::string GraphTitle() {
sprang1168fd42017-06-21 16:00:17104 return static_cast<std::string>(FLAG_graph_title);
sprangce4aef12015-11-02 15:23:20105}
106
sprang1168fd42017-06-21 16:00:17107DEFINE_int(loss_percent, 0, "Percentage of packets randomly lost.");
sprang@webrtc.org131bea82015-02-18 12:46:06108int LossPercent() {
sprang1168fd42017-06-21 16:00:17109 return static_cast<int>(FLAG_loss_percent);
sprang@webrtc.org131bea82015-02-18 12:46:06110}
111
sprang1168fd42017-06-21 16:00:17112DEFINE_int(avg_burst_loss_length, -1, "Average burst length of lost packets.");
philipel536378b2016-05-31 10:20:23113int AvgBurstLossLength() {
sprang1168fd42017-06-21 16:00:17114 return static_cast<int>(FLAG_avg_burst_loss_length);
philipel536378b2016-05-31 10:20:23115}
116
sprang1168fd42017-06-21 16:00:17117DEFINE_int(link_capacity,
118 0,
119 "Capacity (kbps) of the fake link. 0 means infinite.");
ivica5d6a06c2015-09-17 12:30:24120int LinkCapacityKbps() {
sprang1168fd42017-06-21 16:00:17121 return static_cast<int>(FLAG_link_capacity);
sprang@webrtc.org131bea82015-02-18 12:46:06122}
123
sprang1168fd42017-06-21 16:00:17124DEFINE_int(queue_size, 0, "Size of the bottleneck link queue in packets.");
sprang@webrtc.org131bea82015-02-18 12:46:06125int QueueSize() {
sprang1168fd42017-06-21 16:00:17126 return static_cast<int>(FLAG_queue_size);
sprang@webrtc.org131bea82015-02-18 12:46:06127}
128
sprang1168fd42017-06-21 16:00:17129DEFINE_int(avg_propagation_delay_ms,
130 0,
131 "Average link propagation delay in ms.");
sprang@webrtc.org131bea82015-02-18 12:46:06132int AvgPropagationDelayMs() {
sprang1168fd42017-06-21 16:00:17133 return static_cast<int>(FLAG_avg_propagation_delay_ms);
sprang@webrtc.org131bea82015-02-18 12:46:06134}
135
Ilya Nikolaevskiya4259f62017-12-05 12:19:45136DEFINE_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 07:47:03140std::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 16:00:17149DEFINE_int(std_propagation_delay_ms,
150 0,
151 "Link propagation delay standard deviation in ms.");
sprang@webrtc.org131bea82015-02-18 12:46:06152int StdPropagationDelayMs() {
sprang1168fd42017-06-21 16:00:17153 return static_cast<int>(FLAG_std_propagation_delay_ms);
sprang@webrtc.org131bea82015-02-18 12:46:06154}
155
sprang1168fd42017-06-21 16:00:17156DEFINE_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 15:23:20165int SelectedStream() {
sprang1168fd42017-06-21 16:00:17166 return static_cast<int>(FLAG_selected_stream);
sprangce4aef12015-11-02 15:23:20167}
168
sprang1168fd42017-06-21 16:00:17169DEFINE_int(num_spatial_layers, 1, "Number of spatial layers to use.");
sprangce4aef12015-11-02 15:23:20170int NumSpatialLayers() {
sprang1168fd42017-06-21 16:00:17171 return static_cast<int>(FLAG_num_spatial_layers);
sprangce4aef12015-11-02 15:23:20172}
173
sprang1168fd42017-06-21 16:00:17174DEFINE_int(selected_sl,
175 -1,
176 "Spatial layer to show or analyze. -1 to disable filtering.");
sprangce4aef12015-11-02 15:23:20177int SelectedSL() {
sprang1168fd42017-06-21 16:00:17178 return static_cast<int>(FLAG_selected_sl);
sprangce4aef12015-11-02 15:23:20179}
180
181DEFINE_string(stream0,
182 "",
183 "Comma separated values describing VideoStream for stream #0.");
184std::string Stream0() {
sprang1168fd42017-06-21 16:00:17185 return static_cast<std::string>(FLAG_stream0);
sprangce4aef12015-11-02 15:23:20186}
187
188DEFINE_string(stream1,
189 "",
190 "Comma separated values describing VideoStream for stream #1.");
191std::string Stream1() {
sprang1168fd42017-06-21 16:00:17192 return static_cast<std::string>(FLAG_stream1);
sprangce4aef12015-11-02 15:23:20193}
194
195DEFINE_string(sl0,
196 "",
197 "Comma separated values describing SpatialLayer for layer #0.");
198std::string SL0() {
sprang1168fd42017-06-21 16:00:17199 return static_cast<std::string>(FLAG_sl0);
sprangce4aef12015-11-02 15:23:20200}
201
202DEFINE_string(sl1,
203 "",
204 "Comma separated values describing SpatialLayer for layer #1.");
205std::string SL1() {
sprang1168fd42017-06-21 16:00:17206 return static_cast<std::string>(FLAG_sl1);
sprangce4aef12015-11-02 15:23:20207}
208
palmkviste75f2042016-09-28 13:19:48209DEFINE_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 16:00:17214 return static_cast<std::string>(FLAG_encoded_frame_path);
palmkviste75f2042016-09-28 13:19:48215}
216
sprang@webrtc.org131bea82015-02-18 12:46:06217DEFINE_bool(logs, false, "print logs to stderr");
218
sprangce4aef12015-11-02 15:23:20219DEFINE_bool(send_side_bwe, true, "Use send-side bandwidth estimation");
220
philipela2c55232016-01-26 16:41:53221DEFINE_bool(allow_reordering, false, "Allow packet reordering to occur");
222
brandtra62f5822016-11-17 08:21:13223DEFINE_bool(use_ulpfec, false, "Use RED+ULPFEC forward error correction.");
224
225DEFINE_bool(use_flexfec, false, "Use FlexFEC forward error correction.");
philipel274c1dc2016-05-04 13:21:01226
minyue73208662016-08-18 13:28:55227DEFINE_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 11:11:43232DEFINE_bool(audio_dtx, false, "Enable audio DTX (no effect if audio is false)");
233
minyuea27172d2016-11-01 12:59:29234DEFINE_bool(video, true, "Add video stream");
235
sprang@webrtc.org131bea82015-02-18 12:46:06236DEFINE_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 11:44:26243
sprangce4aef12015-11-02 15:23:20244// Video-specific flags.
ivica5d6a06c2015-09-17 12:30:24245DEFINE_string(clip,
246 "",
247 "Name of the clip to show. If empty, using chroma generator.");
248std::string Clip() {
sprang1168fd42017-06-21 16:00:17249 return static_cast<std::string>(FLAG_clip);
ivica5d6a06c2015-09-17 12:30:24250}
251
sprang1168fd42017-06-21 16:00:17252DEFINE_bool(help, false, "prints this message");
253
sprang@webrtc.org131bea82015-02-18 12:46:06254} // namespace flags
255
256void Loopback() {
ivica5d6a06c2015-09-17 12:30:24257 FakeNetworkPipe::Config pipe_config;
258 pipe_config.loss_percent = flags::LossPercent();
philipel536378b2016-05-31 10:20:23259 pipe_config.avg_burst_loss_length = flags::AvgBurstLossLength();
ivica5d6a06c2015-09-17 12:30:24260 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 16:00:17264 pipe_config.allow_reordering = flags::FLAG_allow_reordering;
ivica5d6a06c2015-09-17 12:30:24265
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 13:28:55271 VideoQualityTest::Params params;
ilnik98436952017-07-13 07:47:03272 params.call = {flags::FLAG_send_side_bwe, call_bitrate_config, 0};
sprang1168fd42017-06-21 16:00:17273 params.video = {flags::FLAG_video,
minyue626bc952016-10-31 12:47:02274 flags::Width(),
275 flags::Height(),
276 flags::Fps(),
277 flags::MinBitrateKbps() * 1000,
278 flags::TargetBitrateKbps() * 1000,
279 flags::MaxBitrateKbps() * 1000,
sprang1168fd42017-06-21 16:00:17280 flags::FLAG_suspend_below_min_bitrate,
minyue626bc952016-10-31 12:47:02281 flags::Codec(),
282 flags::NumTemporalLayers(),
283 flags::SelectedTL(),
284 0, // No min transmit bitrate.
sprang1168fd42017-06-21 16:00:17285 flags::FLAG_use_ulpfec,
286 flags::FLAG_use_flexfec,
Tarun Chawla8e857d12017-05-31 13:50:57287 flags::Clip(),
288 flags::GetCaptureDevice()};
sprang1168fd42017-06-21 16:00:17289 params.audio = {flags::FLAG_audio, flags::FLAG_audio_video_sync,
290 flags::FLAG_audio_dtx};
ilnik98436952017-07-13 07:47:03291 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 23:20:33293 params.screenshare.enabled = false;
minyue73208662016-08-18 13:28:55294 params.analyzer = {"video", 0.0, 0.0, flags::DurationSecs(),
295 flags::OutputFilename(), flags::GraphTitle()};
296 params.pipe = pipe_config;
sprang1168fd42017-06-21 16:00:17297
298 if (flags::NumStreams() > 1 && flags::Stream0().empty() &&
299 flags::Stream1().empty()) {
300 params.ss.infer_streams = true;
301 }
ivica5d6a06c2015-09-17 12:30:24302
sprangce4aef12015-11-02 15:23:20303 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 16:00:17310 &params, stream_descriptors, flags::NumStreams(), flags::SelectedStream(),
sprangce4aef12015-11-02 15:23:20311 flags::NumSpatialLayers(), flags::SelectedSL(), SL_descriptors);
312
ivica5d6a06c2015-09-17 12:30:24313 VideoQualityTest test;
sprangce4aef12015-11-02 15:23:20314 if (flags::DurationSecs()) {
sprang7a975f72015-10-12 13:33:21315 test.RunWithAnalyzer(params);
sprangce4aef12015-11-02 15:23:20316 } else {
minyue73208662016-08-18 13:28:55317 test.RunWithRenderers(params);
sprangce4aef12015-11-02 15:23:20318 }
sprang@webrtc.org131bea82015-02-18 12:46:06319}
320} // namespace webrtc
321
322int main(int argc, char* argv[]) {
323 ::testing::InitGoogleTest(&argc, argv);
sprang1168fd42017-06-21 16:00:17324 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 20:27:40334
sprang@webrtc.org131bea82015-02-18 12:46:06335 webrtc::test::RunTest(webrtc::Loopback);
336 return 0;
337}