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