1/*
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
13#include "gflags/gflags.h"
14#include "testing/gtest/include/gtest/gtest.h"
15
16#include "webrtc/test/field_trial.h"
17#include "webrtc/test/run_test.h"
18#include "webrtc/video/video_quality_test.h"
19
20namespace webrtc {
21namespace flags {
22
23// Flags common with video loopback, with different default values.
24DEFINE_int32(width, 1850, "Video width (crops source).");
25size_t Width() {
26  return static_cast<size_t>(FLAGS_width);
27}
28
29DEFINE_int32(height, 1110, "Video height (crops source).");
30size_t Height() {
31  return static_cast<size_t>(FLAGS_height);
32}
33
34DEFINE_int32(fps, 5, "Frames per second.");
35int Fps() {
36  return static_cast<int>(FLAGS_fps);
37}
38
39DEFINE_int32(min_bitrate, 50, "Call and stream min bitrate in kbps.");
40int MinBitrateKbps() {
41  return static_cast<int>(FLAGS_min_bitrate);
42}
43
44DEFINE_int32(start_bitrate, 200, "Call start bitrate in kbps.");
45int StartBitrateKbps() {
46  return static_cast<int>(FLAGS_start_bitrate);
47}
48
49DEFINE_int32(target_bitrate, 2000, "Stream target bitrate in kbps.");
50int TargetBitrateKbps() {
51  return static_cast<int>(FLAGS_target_bitrate);
52}
53
54DEFINE_int32(max_bitrate, 2000, "Call and stream max bitrate in kbps.");
55int MaxBitrateKbps() {
56  return static_cast<int>(FLAGS_max_bitrate);
57}
58
59DEFINE_int32(num_temporal_layers, 2, "Number of temporal layers to use.");
60int NumTemporalLayers() {
61  return static_cast<int>(FLAGS_num_temporal_layers);
62}
63
64// Flags common with video loopback, with equal default values.
65DEFINE_string(codec, "VP8", "Video codec to use.");
66std::string Codec() {
67  return static_cast<std::string>(FLAGS_codec);
68}
69
70DEFINE_int32(selected_tl,
71             -1,
72             "Temporal layer to show or analyze. -1 to disable filtering.");
73int SelectedTL() {
74  return static_cast<int>(FLAGS_selected_tl);
75}
76
77DEFINE_int32(
78    duration,
79    0,
80    "Duration of the test in seconds. If 0, rendered will be shown instead.");
81int DurationSecs() {
82  return static_cast<int>(FLAGS_duration);
83}
84
85DEFINE_string(output_filename, "", "Target graph data filename.");
86std::string OutputFilename() {
87  return static_cast<std::string>(FLAGS_output_filename);
88}
89
90DEFINE_string(graph_title,
91              "",
92              "If empty, title will be generated automatically.");
93std::string GraphTitle() {
94  return static_cast<std::string>(FLAGS_graph_title);
95}
96
97DEFINE_int32(loss_percent, 0, "Percentage of packets randomly lost.");
98int LossPercent() {
99  return static_cast<int>(FLAGS_loss_percent);
100}
101
102DEFINE_int32(link_capacity,
103             0,
104             "Capacity (kbps) of the fake link. 0 means infinite.");
105int LinkCapacityKbps() {
106  return static_cast<int>(FLAGS_link_capacity);
107}
108
109DEFINE_int32(queue_size, 0, "Size of the bottleneck link queue in packets.");
110int QueueSize() {
111  return static_cast<int>(FLAGS_queue_size);
112}
113
114DEFINE_int32(avg_propagation_delay_ms,
115             0,
116             "Average link propagation delay in ms.");
117int AvgPropagationDelayMs() {
118  return static_cast<int>(FLAGS_avg_propagation_delay_ms);
119}
120
121DEFINE_int32(std_propagation_delay_ms,
122             0,
123             "Link propagation delay standard deviation in ms.");
124int StdPropagationDelayMs() {
125  return static_cast<int>(FLAGS_std_propagation_delay_ms);
126}
127
128DEFINE_int32(selected_stream, 0, "ID of the stream to show or analyze.");
129int SelectedStream() {
130  return static_cast<int>(FLAGS_selected_stream);
131}
132
133DEFINE_int32(num_spatial_layers, 1, "Number of spatial layers to use.");
134int NumSpatialLayers() {
135  return static_cast<int>(FLAGS_num_spatial_layers);
136}
137
138DEFINE_int32(selected_sl,
139             -1,
140             "Spatial layer to show or analyze. -1 to disable filtering.");
141int SelectedSL() {
142  return static_cast<int>(FLAGS_selected_sl);
143}
144
145DEFINE_string(stream0,
146              "",
147              "Comma separated values describing VideoStream for stream #0.");
148std::string Stream0() {
149  return static_cast<std::string>(FLAGS_stream0);
150}
151
152DEFINE_string(stream1,
153              "",
154              "Comma separated values describing VideoStream for stream #1.");
155std::string Stream1() {
156  return static_cast<std::string>(FLAGS_stream1);
157}
158
159DEFINE_string(sl0,
160              "",
161              "Comma separated values describing SpatialLayer for layer #0.");
162std::string SL0() {
163  return static_cast<std::string>(FLAGS_sl0);
164}
165
166DEFINE_string(sl1,
167              "",
168              "Comma separated values describing SpatialLayer for layer #1.");
169std::string SL1() {
170  return static_cast<std::string>(FLAGS_sl1);
171}
172
173DEFINE_bool(logs, false, "print logs to stderr");
174
175DEFINE_bool(send_side_bwe, true, "Use send-side bandwidth estimation");
176
177DEFINE_string(
178    force_fieldtrials,
179    "",
180    "Field trials control experimental feature code which can be forced. "
181    "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
182    " will assign the group Enable to field trial WebRTC-FooFeature. Multiple "
183    "trials are separated by \"/\"");
184
185// Screenshare-specific flags.
186DEFINE_int32(min_transmit_bitrate, 400, "Min transmit bitrate incl. padding.");
187int MinTransmitBitrateKbps() {
188  return FLAGS_min_transmit_bitrate;
189}
190
191DEFINE_int32(slide_change_interval,
192             10,
193             "Interval (in seconds) between simulated slide changes.");
194int SlideChangeInterval() {
195  return static_cast<int>(FLAGS_slide_change_interval);
196}
197
198DEFINE_int32(
199    scroll_duration,
200    0,
201    "Duration (in seconds) during which a slide will be scrolled into place.");
202int ScrollDuration() {
203  return static_cast<int>(FLAGS_scroll_duration);
204}
205
206}  // namespace flags
207
208void Loopback() {
209  FakeNetworkPipe::Config pipe_config;
210  pipe_config.loss_percent = flags::LossPercent();
211  pipe_config.link_capacity_kbps = flags::LinkCapacityKbps();
212  pipe_config.queue_length_packets = flags::QueueSize();
213  pipe_config.queue_delay_ms = flags::AvgPropagationDelayMs();
214  pipe_config.delay_standard_deviation_ms = flags::StdPropagationDelayMs();
215
216  Call::Config::BitrateConfig call_bitrate_config;
217  call_bitrate_config.min_bitrate_bps = flags::MinBitrateKbps() * 1000;
218  call_bitrate_config.start_bitrate_bps = flags::StartBitrateKbps() * 1000;
219  call_bitrate_config.max_bitrate_bps = flags::MaxBitrateKbps() * 1000;
220
221  VideoQualityTest::Params params{
222      {flags::Width(), flags::Height(), flags::Fps(),
223       flags::MinBitrateKbps() * 1000, flags::TargetBitrateKbps() * 1000,
224       flags::MaxBitrateKbps() * 1000, flags::Codec(),
225       flags::NumTemporalLayers(), flags::SelectedTL(),
226       flags::MinTransmitBitrateKbps() * 1000, call_bitrate_config,
227       flags::FLAGS_send_side_bwe},
228      {},  // Video specific.
229      {true, flags::SlideChangeInterval(), flags::ScrollDuration()},
230      {"screenshare", 0.0, 0.0, flags::DurationSecs(), flags::OutputFilename(),
231       flags::GraphTitle()},
232      pipe_config,
233      flags::FLAGS_logs};
234
235  std::vector<std::string> stream_descriptors;
236  stream_descriptors.push_back(flags::Stream0());
237  stream_descriptors.push_back(flags::Stream1());
238  std::vector<std::string> SL_descriptors;
239  SL_descriptors.push_back(flags::SL0());
240  SL_descriptors.push_back(flags::SL1());
241  VideoQualityTest::FillScalabilitySettings(
242      &params, stream_descriptors, flags::SelectedStream(),
243      flags::NumSpatialLayers(), flags::SelectedSL(), SL_descriptors);
244
245  VideoQualityTest test;
246  if (flags::DurationSecs()) {
247    test.RunWithAnalyzer(params);
248  } else {
249    test.RunWithVideoRenderer(params);
250  }
251}
252}  // namespace webrtc
253
254int main(int argc, char* argv[]) {
255  ::testing::InitGoogleTest(&argc, argv);
256  google::ParseCommandLineFlags(&argc, &argv, true);
257  webrtc::test::InitFieldTrialsFromString(
258      webrtc::flags::FLAGS_force_fieldtrials);
259  webrtc::test::RunTest(webrtc::Loopback);
260  return 0;
261}
262