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.

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