You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

390 lines
12 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include <stdio.h>
  11. #include <memory>
  12. #include <string>
  13. #include <vector>
  14. #include "absl/flags/flag.h"
  15. #include "absl/flags/parse.h"
  16. #include "absl/types/optional.h"
  17. #include "api/test/simulated_network.h"
  18. #include "api/test/video_quality_test_fixture.h"
  19. #include "api/transport/bitrate_settings.h"
  20. #include "api/video_codecs/video_codec.h"
  21. #include "rtc_base/checks.h"
  22. #include "rtc_base/logging.h"
  23. #include "rtc_base/string_encode.h"
  24. #include "system_wrappers/include/field_trial.h"
  25. #include "test/field_trial.h"
  26. #include "test/gtest.h"
  27. #include "test/run_test.h"
  28. #include "video/video_quality_test.h"
  29. using ::webrtc::BitrateConstraints;
  30. using ::webrtc::BuiltInNetworkBehaviorConfig;
  31. using ::webrtc::InterLayerPredMode;
  32. using ::webrtc::SdpVideoFormat;
  33. using ::webrtc::VideoQualityTest;
  34. // Flags common with video loopback, with different default values.
  35. ABSL_FLAG(int, width, 1850, "Video width (crops source).");
  36. size_t Width() {
  37. return static_cast<size_t>(absl::GetFlag(FLAGS_width));
  38. }
  39. ABSL_FLAG(int, height, 1110, "Video height (crops source).");
  40. size_t Height() {
  41. return static_cast<size_t>(absl::GetFlag(FLAGS_height));
  42. }
  43. ABSL_FLAG(int, fps, 5, "Frames per second.");
  44. int Fps() {
  45. return absl::GetFlag(FLAGS_fps);
  46. }
  47. ABSL_FLAG(int, min_bitrate, 50, "Call and stream min bitrate in kbps.");
  48. int MinBitrateKbps() {
  49. return absl::GetFlag(FLAGS_min_bitrate);
  50. }
  51. ABSL_FLAG(int, start_bitrate, 300, "Call start bitrate in kbps.");
  52. int StartBitrateKbps() {
  53. return absl::GetFlag(FLAGS_start_bitrate);
  54. }
  55. ABSL_FLAG(int, target_bitrate, 200, "Stream target bitrate in kbps.");
  56. int TargetBitrateKbps() {
  57. return absl::GetFlag(FLAGS_target_bitrate);
  58. }
  59. ABSL_FLAG(int, max_bitrate, 1000, "Call and stream max bitrate in kbps.");
  60. int MaxBitrateKbps() {
  61. return absl::GetFlag(FLAGS_max_bitrate);
  62. }
  63. ABSL_FLAG(int, num_temporal_layers, 2, "Number of temporal layers to use.");
  64. int NumTemporalLayers() {
  65. return absl::GetFlag(FLAGS_num_temporal_layers);
  66. }
  67. // Flags common with video loopback, with equal default values.
  68. ABSL_FLAG(std::string, codec, "VP8", "Video codec to use.");
  69. std::string Codec() {
  70. return absl::GetFlag(FLAGS_codec);
  71. }
  72. ABSL_FLAG(std::string,
  73. rtc_event_log_name,
  74. "",
  75. "Filename for rtc event log. Two files "
  76. "with \"_send\" and \"_recv\" suffixes will be created.");
  77. std::string RtcEventLogName() {
  78. return absl::GetFlag(FLAGS_rtc_event_log_name);
  79. }
  80. ABSL_FLAG(std::string,
  81. rtp_dump_name,
  82. "",
  83. "Filename for dumped received RTP stream.");
  84. std::string RtpDumpName() {
  85. return absl::GetFlag(FLAGS_rtp_dump_name);
  86. }
  87. ABSL_FLAG(int,
  88. selected_tl,
  89. -1,
  90. "Temporal layer to show or analyze. -1 to disable filtering.");
  91. int SelectedTL() {
  92. return absl::GetFlag(FLAGS_selected_tl);
  93. }
  94. ABSL_FLAG(
  95. int,
  96. duration,
  97. 0,
  98. "Duration of the test in seconds. If 0, rendered will be shown instead.");
  99. int DurationSecs() {
  100. return absl::GetFlag(FLAGS_duration);
  101. }
  102. ABSL_FLAG(std::string, output_filename, "", "Target graph data filename.");
  103. std::string OutputFilename() {
  104. return absl::GetFlag(FLAGS_output_filename);
  105. }
  106. ABSL_FLAG(std::string,
  107. graph_title,
  108. "",
  109. "If empty, title will be generated automatically.");
  110. std::string GraphTitle() {
  111. return absl::GetFlag(FLAGS_graph_title);
  112. }
  113. ABSL_FLAG(int, loss_percent, 0, "Percentage of packets randomly lost.");
  114. int LossPercent() {
  115. return absl::GetFlag(FLAGS_loss_percent);
  116. }
  117. ABSL_FLAG(int,
  118. link_capacity,
  119. 0,
  120. "Capacity (kbps) of the fake link. 0 means infinite.");
  121. int LinkCapacityKbps() {
  122. return absl::GetFlag(FLAGS_link_capacity);
  123. }
  124. ABSL_FLAG(int, queue_size, 0, "Size of the bottleneck link queue in packets.");
  125. int QueueSize() {
  126. return absl::GetFlag(FLAGS_queue_size);
  127. }
  128. ABSL_FLAG(int,
  129. avg_propagation_delay_ms,
  130. 0,
  131. "Average link propagation delay in ms.");
  132. int AvgPropagationDelayMs() {
  133. return absl::GetFlag(FLAGS_avg_propagation_delay_ms);
  134. }
  135. ABSL_FLAG(int,
  136. std_propagation_delay_ms,
  137. 0,
  138. "Link propagation delay standard deviation in ms.");
  139. int StdPropagationDelayMs() {
  140. return absl::GetFlag(FLAGS_std_propagation_delay_ms);
  141. }
  142. ABSL_FLAG(int, num_streams, 0, "Number of streams to show or analyze.");
  143. int NumStreams() {
  144. return absl::GetFlag(FLAGS_num_streams);
  145. }
  146. ABSL_FLAG(int,
  147. selected_stream,
  148. 0,
  149. "ID of the stream to show or analyze. "
  150. "Set to the number of streams to show them all.");
  151. int SelectedStream() {
  152. return absl::GetFlag(FLAGS_selected_stream);
  153. }
  154. ABSL_FLAG(int, num_spatial_layers, 1, "Number of spatial layers to use.");
  155. int NumSpatialLayers() {
  156. return absl::GetFlag(FLAGS_num_spatial_layers);
  157. }
  158. ABSL_FLAG(int,
  159. inter_layer_pred,
  160. 0,
  161. "Inter-layer prediction mode. "
  162. "0 - enabled, 1 - disabled, 2 - enabled only for key pictures.");
  163. InterLayerPredMode InterLayerPred() {
  164. if (absl::GetFlag(FLAGS_inter_layer_pred) == 0) {
  165. return webrtc::InterLayerPredMode::kOn;
  166. } else if (absl::GetFlag(FLAGS_inter_layer_pred) == 1) {
  167. return webrtc::InterLayerPredMode::kOff;
  168. } else {
  169. RTC_DCHECK_EQ(absl::GetFlag(FLAGS_inter_layer_pred), 2);
  170. return webrtc::InterLayerPredMode::kOnKeyPic;
  171. }
  172. }
  173. ABSL_FLAG(int,
  174. selected_sl,
  175. -1,
  176. "Spatial layer to show or analyze. -1 to disable filtering.");
  177. int SelectedSL() {
  178. return absl::GetFlag(FLAGS_selected_sl);
  179. }
  180. ABSL_FLAG(std::string,
  181. stream0,
  182. "",
  183. "Comma separated values describing VideoStream for stream #0.");
  184. std::string Stream0() {
  185. return absl::GetFlag(FLAGS_stream0);
  186. }
  187. ABSL_FLAG(std::string,
  188. stream1,
  189. "",
  190. "Comma separated values describing VideoStream for stream #1.");
  191. std::string Stream1() {
  192. return absl::GetFlag(FLAGS_stream1);
  193. }
  194. ABSL_FLAG(std::string,
  195. sl0,
  196. "",
  197. "Comma separated values describing SpatialLayer for layer #0.");
  198. std::string SL0() {
  199. return absl::GetFlag(FLAGS_sl0);
  200. }
  201. ABSL_FLAG(std::string,
  202. sl1,
  203. "",
  204. "Comma separated values describing SpatialLayer for layer #1.");
  205. std::string SL1() {
  206. return absl::GetFlag(FLAGS_sl1);
  207. }
  208. ABSL_FLAG(std::string,
  209. 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");
  213. std::string EncodedFramePath() {
  214. return absl::GetFlag(FLAGS_encoded_frame_path);
  215. }
  216. ABSL_FLAG(bool, logs, false, "print logs to stderr");
  217. ABSL_FLAG(bool, send_side_bwe, true, "Use send-side bandwidth estimation");
  218. ABSL_FLAG(bool, generic_descriptor, false, "Use the generic frame descriptor.");
  219. ABSL_FLAG(bool, allow_reordering, false, "Allow packet reordering to occur");
  220. ABSL_FLAG(
  221. std::string,
  222. force_fieldtrials,
  223. "",
  224. "Field trials control experimental feature code which can be forced. "
  225. "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
  226. " will assign the group Enable to field trial WebRTC-FooFeature. Multiple "
  227. "trials are separated by \"/\"");
  228. // Screenshare-specific flags.
  229. ABSL_FLAG(int,
  230. min_transmit_bitrate,
  231. 400,
  232. "Min transmit bitrate incl. padding.");
  233. int MinTransmitBitrateKbps() {
  234. return absl::GetFlag(FLAGS_min_transmit_bitrate);
  235. }
  236. ABSL_FLAG(bool,
  237. generate_slides,
  238. false,
  239. "Whether to use randomly generated slides or read them from files.");
  240. bool GenerateSlides() {
  241. return absl::GetFlag(FLAGS_generate_slides);
  242. }
  243. ABSL_FLAG(int,
  244. slide_change_interval,
  245. 10,
  246. "Interval (in seconds) between simulated slide changes.");
  247. int SlideChangeInterval() {
  248. return absl::GetFlag(FLAGS_slide_change_interval);
  249. }
  250. ABSL_FLAG(
  251. int,
  252. scroll_duration,
  253. 0,
  254. "Duration (in seconds) during which a slide will be scrolled into place.");
  255. int ScrollDuration() {
  256. return absl::GetFlag(FLAGS_scroll_duration);
  257. }
  258. ABSL_FLAG(std::string,
  259. slides,
  260. "",
  261. "Comma-separated list of *.yuv files to display as slides.");
  262. std::vector<std::string> Slides() {
  263. std::vector<std::string> slides;
  264. std::string slides_list = absl::GetFlag(FLAGS_slides);
  265. rtc::tokenize(slides_list, ',', &slides);
  266. return slides;
  267. }
  268. void Loopback() {
  269. BuiltInNetworkBehaviorConfig pipe_config;
  270. pipe_config.loss_percent = LossPercent();
  271. pipe_config.link_capacity_kbps = LinkCapacityKbps();
  272. pipe_config.queue_length_packets = QueueSize();
  273. pipe_config.queue_delay_ms = AvgPropagationDelayMs();
  274. pipe_config.delay_standard_deviation_ms = StdPropagationDelayMs();
  275. pipe_config.allow_reordering = absl::GetFlag(FLAGS_allow_reordering);
  276. BitrateConstraints call_bitrate_config;
  277. call_bitrate_config.min_bitrate_bps = MinBitrateKbps() * 1000;
  278. call_bitrate_config.start_bitrate_bps = StartBitrateKbps() * 1000;
  279. call_bitrate_config.max_bitrate_bps = -1; // Don't cap bandwidth estimate.
  280. VideoQualityTest::Params params;
  281. params.call = {absl::GetFlag(FLAGS_send_side_bwe),
  282. absl::GetFlag(FLAGS_generic_descriptor), call_bitrate_config};
  283. params.video[0] = {true,
  284. Width(),
  285. Height(),
  286. Fps(),
  287. MinBitrateKbps() * 1000,
  288. TargetBitrateKbps() * 1000,
  289. MaxBitrateKbps() * 1000,
  290. false,
  291. Codec(),
  292. NumTemporalLayers(),
  293. SelectedTL(),
  294. MinTransmitBitrateKbps() * 1000,
  295. false, // ULPFEC disabled.
  296. false, // FlexFEC disabled.
  297. false, // Automatic scaling disabled.
  298. "",
  299. 0, // capture_device_index.
  300. SdpVideoFormat::Parameters()};
  301. params.screenshare[0] = {true, GenerateSlides(), SlideChangeInterval(),
  302. ScrollDuration(), Slides()};
  303. params.analyzer = {"screenshare", 0.0, 0.0, DurationSecs(),
  304. OutputFilename(), GraphTitle()};
  305. params.config = pipe_config;
  306. params.logging = {RtcEventLogName(), RtpDumpName(), EncodedFramePath()};
  307. if (NumStreams() > 1 && Stream0().empty() && Stream1().empty()) {
  308. params.ss[0].infer_streams = true;
  309. }
  310. std::vector<std::string> stream_descriptors;
  311. stream_descriptors.push_back(Stream0());
  312. stream_descriptors.push_back(Stream1());
  313. std::vector<std::string> SL_descriptors;
  314. SL_descriptors.push_back(SL0());
  315. SL_descriptors.push_back(SL1());
  316. VideoQualityTest::FillScalabilitySettings(
  317. &params, 0, stream_descriptors, NumStreams(), SelectedStream(),
  318. NumSpatialLayers(), SelectedSL(), InterLayerPred(), SL_descriptors);
  319. auto fixture = std::make_unique<VideoQualityTest>(nullptr);
  320. if (DurationSecs()) {
  321. fixture->RunWithAnalyzer(params);
  322. } else {
  323. fixture->RunWithRenderers(params);
  324. }
  325. }
  326. int main(int argc, char* argv[]) {
  327. ::testing::InitGoogleTest(&argc, argv);
  328. absl::ParseCommandLine(argc, argv);
  329. rtc::LogMessage::SetLogToStderr(absl::GetFlag(FLAGS_logs));
  330. // InitFieldTrialsFromString stores the char*, so the char array must outlive
  331. // the application.
  332. const std::string field_trials = absl::GetFlag(FLAGS_force_fieldtrials);
  333. webrtc::field_trial::InitFieldTrialsFromString(field_trials.c_str());
  334. webrtc::test::RunTest(Loopback);
  335. return 0;
  336. }