blob: dc8de56adec6e75ad73f4b24d95d6fc909d5ca9d [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
sprang1168fd42017-06-21 09:00:17 -070013#include "webrtc/base/flags.h"
sprang@webrtc.org131bea82015-02-18 12:46:06 +000014#include "webrtc/test/field_trial.h"
kwibergac9f8762016-09-30 22:29:43 -070015#include "webrtc/test/gtest.h"
sprang@webrtc.org131bea82015-02-18 12:46:06 +000016#include "webrtc/test/run_test.h"
ivica5d6a06c2015-09-17 05:30:24 -070017#include "webrtc/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
sprang1168fd42017-06-21 09:00:17 -0700136DEFINE_int(std_propagation_delay_ms,
137 0,
138 "Link propagation delay standard deviation in ms.");
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000139int StdPropagationDelayMs() {
sprang1168fd42017-06-21 09:00:17 -0700140 return static_cast<int>(FLAG_std_propagation_delay_ms);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000141}
142
sprang1168fd42017-06-21 09:00:17 -0700143DEFINE_int(num_streams, 0, "Number of streams to show or analyze.");
144int NumStreams() {
145 return static_cast<int>(FLAG_num_streams);
146}
147
148DEFINE_int(selected_stream,
149 0,
150 "ID of the stream to show or analyze. "
151 "Set to the number of streams to show them all.");
sprangce4aef12015-11-02 07:23:20 -0800152int SelectedStream() {
sprang1168fd42017-06-21 09:00:17 -0700153 return static_cast<int>(FLAG_selected_stream);
sprangce4aef12015-11-02 07:23:20 -0800154}
155
sprang1168fd42017-06-21 09:00:17 -0700156DEFINE_int(num_spatial_layers, 1, "Number of spatial layers to use.");
sprangce4aef12015-11-02 07:23:20 -0800157int NumSpatialLayers() {
sprang1168fd42017-06-21 09:00:17 -0700158 return static_cast<int>(FLAG_num_spatial_layers);
sprangce4aef12015-11-02 07:23:20 -0800159}
160
sprang1168fd42017-06-21 09:00:17 -0700161DEFINE_int(selected_sl,
162 -1,
163 "Spatial layer to show or analyze. -1 to disable filtering.");
sprangce4aef12015-11-02 07:23:20 -0800164int SelectedSL() {
sprang1168fd42017-06-21 09:00:17 -0700165 return static_cast<int>(FLAG_selected_sl);
sprangce4aef12015-11-02 07:23:20 -0800166}
167
168DEFINE_string(stream0,
169 "",
170 "Comma separated values describing VideoStream for stream #0.");
171std::string Stream0() {
sprang1168fd42017-06-21 09:00:17 -0700172 return static_cast<std::string>(FLAG_stream0);
sprangce4aef12015-11-02 07:23:20 -0800173}
174
175DEFINE_string(stream1,
176 "",
177 "Comma separated values describing VideoStream for stream #1.");
178std::string Stream1() {
sprang1168fd42017-06-21 09:00:17 -0700179 return static_cast<std::string>(FLAG_stream1);
sprangce4aef12015-11-02 07:23:20 -0800180}
181
182DEFINE_string(sl0,
183 "",
184 "Comma separated values describing SpatialLayer for layer #0.");
185std::string SL0() {
sprang1168fd42017-06-21 09:00:17 -0700186 return static_cast<std::string>(FLAG_sl0);
sprangce4aef12015-11-02 07:23:20 -0800187}
188
189DEFINE_string(sl1,
190 "",
191 "Comma separated values describing SpatialLayer for layer #1.");
192std::string SL1() {
sprang1168fd42017-06-21 09:00:17 -0700193 return static_cast<std::string>(FLAG_sl1);
sprangce4aef12015-11-02 07:23:20 -0800194}
195
palmkviste75f2042016-09-28 06:19:48 -0700196DEFINE_string(encoded_frame_path,
197 "",
198 "The base path for encoded frame logs. Created files will have "
199 "the form <encoded_frame_path>.<n>.(recv|send.<m>).ivf");
200std::string EncodedFramePath() {
sprang1168fd42017-06-21 09:00:17 -0700201 return static_cast<std::string>(FLAG_encoded_frame_path);
palmkviste75f2042016-09-28 06:19:48 -0700202}
203
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000204DEFINE_bool(logs, false, "print logs to stderr");
205
sprangce4aef12015-11-02 07:23:20 -0800206DEFINE_bool(send_side_bwe, true, "Use send-side bandwidth estimation");
207
philipela2c55232016-01-26 08:41:53 -0800208DEFINE_bool(allow_reordering, false, "Allow packet reordering to occur");
209
brandtra62f5822016-11-17 00:21:13 -0800210DEFINE_bool(use_ulpfec, false, "Use RED+ULPFEC forward error correction.");
211
212DEFINE_bool(use_flexfec, false, "Use FlexFEC forward error correction.");
philipel274c1dc2016-05-04 06:21:01 -0700213
minyue73208662016-08-18 06:28:55 -0700214DEFINE_bool(audio, false, "Add audio stream");
215
216DEFINE_bool(audio_video_sync, false, "Sync audio and video stream (no effect if"
217 " audio is false)");
218
minyue4c8b9422017-03-21 04:11:43 -0700219DEFINE_bool(audio_dtx, false, "Enable audio DTX (no effect if audio is false)");
220
minyuea27172d2016-11-01 05:59:29 -0700221DEFINE_bool(video, true, "Add video stream");
222
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000223DEFINE_string(
224 force_fieldtrials,
225 "",
226 "Field trials control experimental feature code which can be forced. "
227 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
228 " will assign the group Enable to field trial WebRTC-FooFeature. Multiple "
229 "trials are separated by \"/\"");
pbos9874ee02015-06-22 04:44:26 -0700230
sprangce4aef12015-11-02 07:23:20 -0800231// Video-specific flags.
ivica5d6a06c2015-09-17 05:30:24 -0700232DEFINE_string(clip,
233 "",
234 "Name of the clip to show. If empty, using chroma generator.");
235std::string Clip() {
sprang1168fd42017-06-21 09:00:17 -0700236 return static_cast<std::string>(FLAG_clip);
ivica5d6a06c2015-09-17 05:30:24 -0700237}
238
sprang1168fd42017-06-21 09:00:17 -0700239DEFINE_bool(help, false, "prints this message");
240
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000241} // namespace flags
242
243void Loopback() {
ivica5d6a06c2015-09-17 05:30:24 -0700244 FakeNetworkPipe::Config pipe_config;
245 pipe_config.loss_percent = flags::LossPercent();
philipel536378b2016-05-31 03:20:23 -0700246 pipe_config.avg_burst_loss_length = flags::AvgBurstLossLength();
ivica5d6a06c2015-09-17 05:30:24 -0700247 pipe_config.link_capacity_kbps = flags::LinkCapacityKbps();
248 pipe_config.queue_length_packets = flags::QueueSize();
249 pipe_config.queue_delay_ms = flags::AvgPropagationDelayMs();
250 pipe_config.delay_standard_deviation_ms = flags::StdPropagationDelayMs();
sprang1168fd42017-06-21 09:00:17 -0700251 pipe_config.allow_reordering = flags::FLAG_allow_reordering;
ivica5d6a06c2015-09-17 05:30:24 -0700252
253 Call::Config::BitrateConfig call_bitrate_config;
254 call_bitrate_config.min_bitrate_bps = flags::MinBitrateKbps() * 1000;
255 call_bitrate_config.start_bitrate_bps = flags::StartBitrateKbps() * 1000;
256 call_bitrate_config.max_bitrate_bps = flags::MaxBitrateKbps() * 1000;
257
minyue73208662016-08-18 06:28:55 -0700258 VideoQualityTest::Params params;
sprang1168fd42017-06-21 09:00:17 -0700259 params.call = {flags::FLAG_send_side_bwe, call_bitrate_config};
260 params.video = {flags::FLAG_video,
minyue626bc952016-10-31 05:47:02 -0700261 flags::Width(),
262 flags::Height(),
263 flags::Fps(),
264 flags::MinBitrateKbps() * 1000,
265 flags::TargetBitrateKbps() * 1000,
266 flags::MaxBitrateKbps() * 1000,
sprang1168fd42017-06-21 09:00:17 -0700267 flags::FLAG_suspend_below_min_bitrate,
minyue626bc952016-10-31 05:47:02 -0700268 flags::Codec(),
269 flags::NumTemporalLayers(),
270 flags::SelectedTL(),
271 0, // No min transmit bitrate.
sprang1168fd42017-06-21 09:00:17 -0700272 flags::FLAG_use_ulpfec,
273 flags::FLAG_use_flexfec,
minyue626bc952016-10-31 05:47:02 -0700274 flags::EncodedFramePath(),
Tarun Chawla8e857d12017-05-31 19:20:57 +0530275 flags::Clip(),
276 flags::GetCaptureDevice()};
sprang1168fd42017-06-21 09:00:17 -0700277 params.audio = {flags::FLAG_audio, flags::FLAG_audio_video_sync,
278 flags::FLAG_audio_dtx};
asapersson3ec3da62016-10-11 16:20:33 -0700279 params.screenshare.enabled = false;
minyue73208662016-08-18 06:28:55 -0700280 params.analyzer = {"video", 0.0, 0.0, flags::DurationSecs(),
281 flags::OutputFilename(), flags::GraphTitle()};
282 params.pipe = pipe_config;
sprang1168fd42017-06-21 09:00:17 -0700283 params.logs = flags::FLAG_logs;
284
285 if (flags::NumStreams() > 1 && flags::Stream0().empty() &&
286 flags::Stream1().empty()) {
287 params.ss.infer_streams = true;
288 }
ivica5d6a06c2015-09-17 05:30:24 -0700289
sprangce4aef12015-11-02 07:23:20 -0800290 std::vector<std::string> stream_descriptors;
291 stream_descriptors.push_back(flags::Stream0());
292 stream_descriptors.push_back(flags::Stream1());
293 std::vector<std::string> SL_descriptors;
294 SL_descriptors.push_back(flags::SL0());
295 SL_descriptors.push_back(flags::SL1());
296 VideoQualityTest::FillScalabilitySettings(
sprang1168fd42017-06-21 09:00:17 -0700297 &params, stream_descriptors, flags::NumStreams(), flags::SelectedStream(),
sprangce4aef12015-11-02 07:23:20 -0800298 flags::NumSpatialLayers(), flags::SelectedSL(), SL_descriptors);
299
ivica5d6a06c2015-09-17 05:30:24 -0700300 VideoQualityTest test;
sprangce4aef12015-11-02 07:23:20 -0800301 if (flags::DurationSecs()) {
sprang7a975f72015-10-12 06:33:21 -0700302 test.RunWithAnalyzer(params);
sprangce4aef12015-11-02 07:23:20 -0800303 } else {
minyue73208662016-08-18 06:28:55 -0700304 test.RunWithRenderers(params);
sprangce4aef12015-11-02 07:23:20 -0800305 }
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000306}
307} // namespace webrtc
308
309int main(int argc, char* argv[]) {
310 ::testing::InitGoogleTest(&argc, argv);
sprang1168fd42017-06-21 09:00:17 -0700311 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
312 if (webrtc::flags::FLAG_help) {
313 rtc::FlagList::Print(nullptr, false);
314 return 0;
315 }
316
317 // InitFieldTrialsFromString needs a reference to an std::string instance,
318 // with a scope that outlives the test.
319 std::string field_trials = webrtc::flags::FLAG_force_fieldtrials;
320 webrtc::test::InitFieldTrialsFromString(field_trials);
sprang89c4a7e2017-06-30 13:27:40 -0700321
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000322 webrtc::test::RunTest(webrtc::Loopback);
323 return 0;
324}