blob: d5d525aa127219b7ce4b489b241ef734b4d8f0f7 [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
ilnik98436952017-07-13 00:47:03 -0700136DEFINE_string(rtc_event_log_name, "", "Filename for rtc event log.");
137std::string RtcEventLogName() {
138 return static_cast<std::string>(FLAG_rtc_event_log_name);
139}
140
141DEFINE_string(rtp_dump_name, "", "Filename for dumped received RTP stream.");
142std::string RtpDumpName() {
143 return static_cast<std::string>(FLAG_rtp_dump_name);
144}
145
sprang1168fd42017-06-21 09:00:17 -0700146DEFINE_int(std_propagation_delay_ms,
147 0,
148 "Link propagation delay standard deviation in ms.");
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000149int StdPropagationDelayMs() {
sprang1168fd42017-06-21 09:00:17 -0700150 return static_cast<int>(FLAG_std_propagation_delay_ms);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000151}
152
sprang1168fd42017-06-21 09:00:17 -0700153DEFINE_int(num_streams, 0, "Number of streams to show or analyze.");
154int NumStreams() {
155 return static_cast<int>(FLAG_num_streams);
156}
157
158DEFINE_int(selected_stream,
159 0,
160 "ID of the stream to show or analyze. "
161 "Set to the number of streams to show them all.");
sprangce4aef12015-11-02 07:23:20 -0800162int SelectedStream() {
sprang1168fd42017-06-21 09:00:17 -0700163 return static_cast<int>(FLAG_selected_stream);
sprangce4aef12015-11-02 07:23:20 -0800164}
165
sprang1168fd42017-06-21 09:00:17 -0700166DEFINE_int(num_spatial_layers, 1, "Number of spatial layers to use.");
sprangce4aef12015-11-02 07:23:20 -0800167int NumSpatialLayers() {
sprang1168fd42017-06-21 09:00:17 -0700168 return static_cast<int>(FLAG_num_spatial_layers);
sprangce4aef12015-11-02 07:23:20 -0800169}
170
sprang1168fd42017-06-21 09:00:17 -0700171DEFINE_int(selected_sl,
172 -1,
173 "Spatial layer to show or analyze. -1 to disable filtering.");
sprangce4aef12015-11-02 07:23:20 -0800174int SelectedSL() {
sprang1168fd42017-06-21 09:00:17 -0700175 return static_cast<int>(FLAG_selected_sl);
sprangce4aef12015-11-02 07:23:20 -0800176}
177
178DEFINE_string(stream0,
179 "",
180 "Comma separated values describing VideoStream for stream #0.");
181std::string Stream0() {
sprang1168fd42017-06-21 09:00:17 -0700182 return static_cast<std::string>(FLAG_stream0);
sprangce4aef12015-11-02 07:23:20 -0800183}
184
185DEFINE_string(stream1,
186 "",
187 "Comma separated values describing VideoStream for stream #1.");
188std::string Stream1() {
sprang1168fd42017-06-21 09:00:17 -0700189 return static_cast<std::string>(FLAG_stream1);
sprangce4aef12015-11-02 07:23:20 -0800190}
191
192DEFINE_string(sl0,
193 "",
194 "Comma separated values describing SpatialLayer for layer #0.");
195std::string SL0() {
sprang1168fd42017-06-21 09:00:17 -0700196 return static_cast<std::string>(FLAG_sl0);
sprangce4aef12015-11-02 07:23:20 -0800197}
198
199DEFINE_string(sl1,
200 "",
201 "Comma separated values describing SpatialLayer for layer #1.");
202std::string SL1() {
sprang1168fd42017-06-21 09:00:17 -0700203 return static_cast<std::string>(FLAG_sl1);
sprangce4aef12015-11-02 07:23:20 -0800204}
205
palmkviste75f2042016-09-28 06:19:48 -0700206DEFINE_string(encoded_frame_path,
207 "",
208 "The base path for encoded frame logs. Created files will have "
209 "the form <encoded_frame_path>.<n>.(recv|send.<m>).ivf");
210std::string EncodedFramePath() {
sprang1168fd42017-06-21 09:00:17 -0700211 return static_cast<std::string>(FLAG_encoded_frame_path);
palmkviste75f2042016-09-28 06:19:48 -0700212}
213
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000214DEFINE_bool(logs, false, "print logs to stderr");
215
sprangce4aef12015-11-02 07:23:20 -0800216DEFINE_bool(send_side_bwe, true, "Use send-side bandwidth estimation");
217
philipela2c55232016-01-26 08:41:53 -0800218DEFINE_bool(allow_reordering, false, "Allow packet reordering to occur");
219
brandtra62f5822016-11-17 00:21:13 -0800220DEFINE_bool(use_ulpfec, false, "Use RED+ULPFEC forward error correction.");
221
222DEFINE_bool(use_flexfec, false, "Use FlexFEC forward error correction.");
philipel274c1dc2016-05-04 06:21:01 -0700223
minyue73208662016-08-18 06:28:55 -0700224DEFINE_bool(audio, false, "Add audio stream");
225
226DEFINE_bool(audio_video_sync, false, "Sync audio and video stream (no effect if"
227 " audio is false)");
228
minyue4c8b9422017-03-21 04:11:43 -0700229DEFINE_bool(audio_dtx, false, "Enable audio DTX (no effect if audio is false)");
230
minyuea27172d2016-11-01 05:59:29 -0700231DEFINE_bool(video, true, "Add video stream");
232
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000233DEFINE_string(
234 force_fieldtrials,
235 "",
236 "Field trials control experimental feature code which can be forced. "
237 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
238 " will assign the group Enable to field trial WebRTC-FooFeature. Multiple "
239 "trials are separated by \"/\"");
pbos9874ee02015-06-22 04:44:26 -0700240
sprangce4aef12015-11-02 07:23:20 -0800241// Video-specific flags.
ivica5d6a06c2015-09-17 05:30:24 -0700242DEFINE_string(clip,
243 "",
244 "Name of the clip to show. If empty, using chroma generator.");
245std::string Clip() {
sprang1168fd42017-06-21 09:00:17 -0700246 return static_cast<std::string>(FLAG_clip);
ivica5d6a06c2015-09-17 05:30:24 -0700247}
248
sprang1168fd42017-06-21 09:00:17 -0700249DEFINE_bool(help, false, "prints this message");
250
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000251} // namespace flags
252
253void Loopback() {
ivica5d6a06c2015-09-17 05:30:24 -0700254 FakeNetworkPipe::Config pipe_config;
255 pipe_config.loss_percent = flags::LossPercent();
philipel536378b2016-05-31 03:20:23 -0700256 pipe_config.avg_burst_loss_length = flags::AvgBurstLossLength();
ivica5d6a06c2015-09-17 05:30:24 -0700257 pipe_config.link_capacity_kbps = flags::LinkCapacityKbps();
258 pipe_config.queue_length_packets = flags::QueueSize();
259 pipe_config.queue_delay_ms = flags::AvgPropagationDelayMs();
260 pipe_config.delay_standard_deviation_ms = flags::StdPropagationDelayMs();
sprang1168fd42017-06-21 09:00:17 -0700261 pipe_config.allow_reordering = flags::FLAG_allow_reordering;
ivica5d6a06c2015-09-17 05:30:24 -0700262
263 Call::Config::BitrateConfig call_bitrate_config;
264 call_bitrate_config.min_bitrate_bps = flags::MinBitrateKbps() * 1000;
265 call_bitrate_config.start_bitrate_bps = flags::StartBitrateKbps() * 1000;
266 call_bitrate_config.max_bitrate_bps = flags::MaxBitrateKbps() * 1000;
267
minyue73208662016-08-18 06:28:55 -0700268 VideoQualityTest::Params params;
ilnik98436952017-07-13 00:47:03 -0700269 params.call = {flags::FLAG_send_side_bwe, call_bitrate_config, 0};
sprang1168fd42017-06-21 09:00:17 -0700270 params.video = {flags::FLAG_video,
minyue626bc952016-10-31 05:47:02 -0700271 flags::Width(),
272 flags::Height(),
273 flags::Fps(),
274 flags::MinBitrateKbps() * 1000,
275 flags::TargetBitrateKbps() * 1000,
276 flags::MaxBitrateKbps() * 1000,
sprang1168fd42017-06-21 09:00:17 -0700277 flags::FLAG_suspend_below_min_bitrate,
minyue626bc952016-10-31 05:47:02 -0700278 flags::Codec(),
279 flags::NumTemporalLayers(),
280 flags::SelectedTL(),
281 0, // No min transmit bitrate.
sprang1168fd42017-06-21 09:00:17 -0700282 flags::FLAG_use_ulpfec,
283 flags::FLAG_use_flexfec,
Tarun Chawla8e857d12017-05-31 19:20:57 +0530284 flags::Clip(),
285 flags::GetCaptureDevice()};
sprang1168fd42017-06-21 09:00:17 -0700286 params.audio = {flags::FLAG_audio, flags::FLAG_audio_video_sync,
287 flags::FLAG_audio_dtx};
ilnik98436952017-07-13 00:47:03 -0700288 params.logging = {flags::FLAG_logs, flags::FLAG_rtc_event_log_name,
289 flags::FLAG_rtp_dump_name, flags::FLAG_encoded_frame_path};
asapersson3ec3da62016-10-11 16:20:33 -0700290 params.screenshare.enabled = false;
minyue73208662016-08-18 06:28:55 -0700291 params.analyzer = {"video", 0.0, 0.0, flags::DurationSecs(),
292 flags::OutputFilename(), flags::GraphTitle()};
293 params.pipe = pipe_config;
sprang1168fd42017-06-21 09:00:17 -0700294
295 if (flags::NumStreams() > 1 && flags::Stream0().empty() &&
296 flags::Stream1().empty()) {
297 params.ss.infer_streams = true;
298 }
ivica5d6a06c2015-09-17 05:30:24 -0700299
sprangce4aef12015-11-02 07:23:20 -0800300 std::vector<std::string> stream_descriptors;
301 stream_descriptors.push_back(flags::Stream0());
302 stream_descriptors.push_back(flags::Stream1());
303 std::vector<std::string> SL_descriptors;
304 SL_descriptors.push_back(flags::SL0());
305 SL_descriptors.push_back(flags::SL1());
306 VideoQualityTest::FillScalabilitySettings(
sprang1168fd42017-06-21 09:00:17 -0700307 &params, stream_descriptors, flags::NumStreams(), flags::SelectedStream(),
sprangce4aef12015-11-02 07:23:20 -0800308 flags::NumSpatialLayers(), flags::SelectedSL(), SL_descriptors);
309
ivica5d6a06c2015-09-17 05:30:24 -0700310 VideoQualityTest test;
sprangce4aef12015-11-02 07:23:20 -0800311 if (flags::DurationSecs()) {
sprang7a975f72015-10-12 06:33:21 -0700312 test.RunWithAnalyzer(params);
sprangce4aef12015-11-02 07:23:20 -0800313 } else {
minyue73208662016-08-18 06:28:55 -0700314 test.RunWithRenderers(params);
sprangce4aef12015-11-02 07:23:20 -0800315 }
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000316}
317} // namespace webrtc
318
319int main(int argc, char* argv[]) {
320 ::testing::InitGoogleTest(&argc, argv);
sprang1168fd42017-06-21 09:00:17 -0700321 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
322 if (webrtc::flags::FLAG_help) {
323 rtc::FlagList::Print(nullptr, false);
324 return 0;
325 }
326
327 // InitFieldTrialsFromString needs a reference to an std::string instance,
328 // with a scope that outlives the test.
329 std::string field_trials = webrtc::flags::FLAG_force_fieldtrials;
330 webrtc::test::InitFieldTrialsFromString(field_trials);
sprang89c4a7e2017-06-30 13:27:40 -0700331
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000332 webrtc::test::RunTest(webrtc::Loopback);
333 return 0;
334}