blob: 26ed9b9d36282de9e0e4fef530f09dc4028e00d7 [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
sprang@webrtc.org131bea82015-02-18 12:46:06 +000013#include "gflags/gflags.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.
sprang@webrtc.org131bea82015-02-18 12:46:06 +000023DEFINE_int32(width, 640, "Video width.");
24size_t Width() {
25 return static_cast<size_t>(FLAGS_width);
26}
27
28DEFINE_int32(height, 480, "Video height.");
29size_t Height() {
30 return static_cast<size_t>(FLAGS_height);
31}
32
33DEFINE_int32(fps, 30, "Frames per second.");
34int Fps() {
35 return static_cast<int>(FLAGS_fps);
36}
37
ivica5d6a06c2015-09-17 05:30:24 -070038DEFINE_int32(min_bitrate, 50, "Call and stream min bitrate in kbps.");
39int MinBitrateKbps() {
40 return static_cast<int>(FLAGS_min_bitrate);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000041}
42
ivica5d6a06c2015-09-17 05:30:24 -070043DEFINE_int32(start_bitrate, 300, "Call start bitrate in kbps.");
44int StartBitrateKbps() {
45 return static_cast<int>(FLAGS_start_bitrate);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000046}
47
ivica5d6a06c2015-09-17 05:30:24 -070048DEFINE_int32(target_bitrate, 800, "Stream target bitrate in kbps.");
49int TargetBitrateKbps() {
50 return static_cast<int>(FLAGS_target_bitrate);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000051}
52
ivica5d6a06c2015-09-17 05:30:24 -070053DEFINE_int32(max_bitrate, 800, "Call and stream max bitrate in kbps.");
54int MaxBitrateKbps() {
55 return static_cast<int>(FLAGS_max_bitrate);
56}
sprang@webrtc.org131bea82015-02-18 12:46:06 +000057
mflodman48a4beb2016-07-01 13:03:59 +020058DEFINE_bool(suspend_below_min_bitrate,
59 false,
60 "Suspends video below the configured min bitrate.");
61
sprangce4aef12015-11-02 07:23:20 -080062DEFINE_int32(num_temporal_layers,
63 1,
64 "Number of temporal layers. Set to 1-4 to override.");
65int NumTemporalLayers() {
66 return static_cast<int>(FLAGS_num_temporal_layers);
67}
68
69// Flags common with screenshare loopback, with equal default values.
sprang@webrtc.org131bea82015-02-18 12:46:06 +000070DEFINE_string(codec, "VP8", "Video codec to use.");
71std::string Codec() {
72 return static_cast<std::string>(FLAGS_codec);
73}
74
sprangce4aef12015-11-02 07:23:20 -080075DEFINE_int32(selected_tl,
76 -1,
77 "Temporal layer to show or analyze. -1 to disable filtering.");
78int SelectedTL() {
79 return static_cast<int>(FLAGS_selected_tl);
80}
81
82DEFINE_int32(
83 duration,
84 0,
85 "Duration of the test in seconds. If 0, rendered will be shown instead.");
86int DurationSecs() {
87 return static_cast<int>(FLAGS_duration);
88}
89
90DEFINE_string(output_filename, "", "Target graph data filename.");
91std::string OutputFilename() {
92 return static_cast<std::string>(FLAGS_output_filename);
93}
94
95DEFINE_string(graph_title,
96 "",
97 "If empty, title will be generated automatically.");
98std::string GraphTitle() {
99 return static_cast<std::string>(FLAGS_graph_title);
100}
101
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000102DEFINE_int32(loss_percent, 0, "Percentage of packets randomly lost.");
103int LossPercent() {
104 return static_cast<int>(FLAGS_loss_percent);
105}
106
philipelcb7b4492016-06-02 10:57:40 +0200107DEFINE_int32(avg_burst_loss_length,
108 -1,
109 "Average burst length of lost packets.");
philipel536378b2016-05-31 03:20:23 -0700110int AvgBurstLossLength() {
111 return static_cast<int>(FLAGS_avg_burst_loss_length);
112}
113
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000114DEFINE_int32(link_capacity,
115 0,
116 "Capacity (kbps) of the fake link. 0 means infinite.");
ivica5d6a06c2015-09-17 05:30:24 -0700117int LinkCapacityKbps() {
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000118 return static_cast<int>(FLAGS_link_capacity);
119}
120
121DEFINE_int32(queue_size, 0, "Size of the bottleneck link queue in packets.");
122int QueueSize() {
123 return static_cast<int>(FLAGS_queue_size);
124}
125
126DEFINE_int32(avg_propagation_delay_ms,
127 0,
128 "Average link propagation delay in ms.");
129int AvgPropagationDelayMs() {
130 return static_cast<int>(FLAGS_avg_propagation_delay_ms);
131}
132
133DEFINE_int32(std_propagation_delay_ms,
134 0,
135 "Link propagation delay standard deviation in ms.");
136int StdPropagationDelayMs() {
137 return static_cast<int>(FLAGS_std_propagation_delay_ms);
138}
139
sprangce4aef12015-11-02 07:23:20 -0800140DEFINE_int32(selected_stream, 0, "ID of the stream to show or analyze.");
141int SelectedStream() {
142 return static_cast<int>(FLAGS_selected_stream);
143}
144
145DEFINE_int32(num_spatial_layers, 1, "Number of spatial layers to use.");
146int NumSpatialLayers() {
147 return static_cast<int>(FLAGS_num_spatial_layers);
148}
149
150DEFINE_int32(selected_sl,
151 -1,
152 "Spatial layer to show or analyze. -1 to disable filtering.");
153int SelectedSL() {
154 return static_cast<int>(FLAGS_selected_sl);
155}
156
157DEFINE_string(stream0,
158 "",
159 "Comma separated values describing VideoStream for stream #0.");
160std::string Stream0() {
161 return static_cast<std::string>(FLAGS_stream0);
162}
163
164DEFINE_string(stream1,
165 "",
166 "Comma separated values describing VideoStream for stream #1.");
167std::string Stream1() {
168 return static_cast<std::string>(FLAGS_stream1);
169}
170
171DEFINE_string(sl0,
172 "",
173 "Comma separated values describing SpatialLayer for layer #0.");
174std::string SL0() {
175 return static_cast<std::string>(FLAGS_sl0);
176}
177
178DEFINE_string(sl1,
179 "",
180 "Comma separated values describing SpatialLayer for layer #1.");
181std::string SL1() {
182 return static_cast<std::string>(FLAGS_sl1);
183}
184
palmkviste75f2042016-09-28 06:19:48 -0700185DEFINE_string(encoded_frame_path,
186 "",
187 "The base path for encoded frame logs. Created files will have "
188 "the form <encoded_frame_path>.<n>.(recv|send.<m>).ivf");
189std::string EncodedFramePath() {
190 return static_cast<std::string>(FLAGS_encoded_frame_path);
191}
192
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000193DEFINE_bool(logs, false, "print logs to stderr");
194
sprangce4aef12015-11-02 07:23:20 -0800195DEFINE_bool(send_side_bwe, true, "Use send-side bandwidth estimation");
196
philipela2c55232016-01-26 08:41:53 -0800197DEFINE_bool(allow_reordering, false, "Allow packet reordering to occur");
198
philipel274c1dc2016-05-04 06:21:01 -0700199DEFINE_bool(use_fec, false, "Use forward error correction.");
200
minyue73208662016-08-18 06:28:55 -0700201DEFINE_bool(audio, false, "Add audio stream");
202
203DEFINE_bool(audio_video_sync, false, "Sync audio and video stream (no effect if"
204 " audio is false)");
205
minyuea27172d2016-11-01 05:59:29 -0700206DEFINE_bool(video, true, "Add video stream");
207
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000208DEFINE_string(
209 force_fieldtrials,
210 "",
211 "Field trials control experimental feature code which can be forced. "
212 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
213 " will assign the group Enable to field trial WebRTC-FooFeature. Multiple "
214 "trials are separated by \"/\"");
pbos9874ee02015-06-22 04:44:26 -0700215
sprangce4aef12015-11-02 07:23:20 -0800216// Video-specific flags.
ivica5d6a06c2015-09-17 05:30:24 -0700217DEFINE_string(clip,
218 "",
219 "Name of the clip to show. If empty, using chroma generator.");
220std::string Clip() {
221 return static_cast<std::string>(FLAGS_clip);
222}
223
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000224} // namespace flags
225
226void Loopback() {
ivica5d6a06c2015-09-17 05:30:24 -0700227 FakeNetworkPipe::Config pipe_config;
228 pipe_config.loss_percent = flags::LossPercent();
philipel536378b2016-05-31 03:20:23 -0700229 pipe_config.avg_burst_loss_length = flags::AvgBurstLossLength();
ivica5d6a06c2015-09-17 05:30:24 -0700230 pipe_config.link_capacity_kbps = flags::LinkCapacityKbps();
231 pipe_config.queue_length_packets = flags::QueueSize();
232 pipe_config.queue_delay_ms = flags::AvgPropagationDelayMs();
233 pipe_config.delay_standard_deviation_ms = flags::StdPropagationDelayMs();
philipela2c55232016-01-26 08:41:53 -0800234 pipe_config.allow_reordering = flags::FLAGS_allow_reordering;
ivica5d6a06c2015-09-17 05:30:24 -0700235
236 Call::Config::BitrateConfig call_bitrate_config;
237 call_bitrate_config.min_bitrate_bps = flags::MinBitrateKbps() * 1000;
238 call_bitrate_config.start_bitrate_bps = flags::StartBitrateKbps() * 1000;
239 call_bitrate_config.max_bitrate_bps = flags::MaxBitrateKbps() * 1000;
240
minyue73208662016-08-18 06:28:55 -0700241 VideoQualityTest::Params params;
minyue626bc952016-10-31 05:47:02 -0700242 params.call = {flags::FLAGS_send_side_bwe, call_bitrate_config};
minyuea27172d2016-11-01 05:59:29 -0700243 params.video = {flags::FLAGS_video,
minyue626bc952016-10-31 05:47:02 -0700244 flags::Width(),
245 flags::Height(),
246 flags::Fps(),
247 flags::MinBitrateKbps() * 1000,
248 flags::TargetBitrateKbps() * 1000,
249 flags::MaxBitrateKbps() * 1000,
250 flags::FLAGS_suspend_below_min_bitrate,
251 flags::Codec(),
252 flags::NumTemporalLayers(),
253 flags::SelectedTL(),
254 0, // No min transmit bitrate.
255 flags::FLAGS_use_fec,
256 flags::EncodedFramePath(),
257 flags::Clip()};
258 params.audio = {flags::FLAGS_audio, flags::FLAGS_audio_video_sync};
asapersson3ec3da62016-10-11 16:20:33 -0700259 params.screenshare.enabled = false;
minyue73208662016-08-18 06:28:55 -0700260 params.analyzer = {"video", 0.0, 0.0, flags::DurationSecs(),
261 flags::OutputFilename(), flags::GraphTitle()};
262 params.pipe = pipe_config;
263 params.logs = flags::FLAGS_logs;
ivica5d6a06c2015-09-17 05:30:24 -0700264
sprangce4aef12015-11-02 07:23:20 -0800265 std::vector<std::string> stream_descriptors;
266 stream_descriptors.push_back(flags::Stream0());
267 stream_descriptors.push_back(flags::Stream1());
268 std::vector<std::string> SL_descriptors;
269 SL_descriptors.push_back(flags::SL0());
270 SL_descriptors.push_back(flags::SL1());
271 VideoQualityTest::FillScalabilitySettings(
272 &params, stream_descriptors, flags::SelectedStream(),
273 flags::NumSpatialLayers(), flags::SelectedSL(), SL_descriptors);
274
ivica5d6a06c2015-09-17 05:30:24 -0700275 VideoQualityTest test;
sprangce4aef12015-11-02 07:23:20 -0800276 if (flags::DurationSecs()) {
sprang7a975f72015-10-12 06:33:21 -0700277 test.RunWithAnalyzer(params);
sprangce4aef12015-11-02 07:23:20 -0800278 } else {
minyue73208662016-08-18 06:28:55 -0700279 test.RunWithRenderers(params);
sprangce4aef12015-11-02 07:23:20 -0800280 }
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000281}
282} // namespace webrtc
283
284int main(int argc, char* argv[]) {
285 ::testing::InitGoogleTest(&argc, argv);
286 google::ParseCommandLineFlags(&argc, &argv, true);
287 webrtc::test::InitFieldTrialsFromString(
288 webrtc::flags::FLAGS_force_fieldtrials);
289 webrtc::test::RunTest(webrtc::Loopback);
290 return 0;
291}