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.

92 lines
3.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2017 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 "call/call_factory.h"
  11. #include <stdio.h>
  12. #include <memory>
  13. #include <string>
  14. #include "absl/types/optional.h"
  15. #include "api/test/simulated_network.h"
  16. #include "call/call.h"
  17. #include "call/degraded_call.h"
  18. #include "rtc_base/checks.h"
  19. #include "system_wrappers/include/field_trial.h"
  20. namespace webrtc {
  21. namespace {
  22. bool ParseConfigParam(std::string exp_name, int* field) {
  23. std::string group = field_trial::FindFullName(exp_name);
  24. if (group.empty())
  25. return false;
  26. return (sscanf(group.c_str(), "%d", field) == 1);
  27. }
  28. absl::optional<webrtc::BuiltInNetworkBehaviorConfig> ParseDegradationConfig(
  29. bool send) {
  30. std::string exp_prefix = "WebRTCFakeNetwork";
  31. if (send) {
  32. exp_prefix += "Send";
  33. } else {
  34. exp_prefix += "Receive";
  35. }
  36. webrtc::BuiltInNetworkBehaviorConfig config;
  37. bool configured = false;
  38. configured |=
  39. ParseConfigParam(exp_prefix + "DelayMs", &config.queue_delay_ms);
  40. configured |= ParseConfigParam(exp_prefix + "DelayStdDevMs",
  41. &config.delay_standard_deviation_ms);
  42. int queue_length = 0;
  43. if (ParseConfigParam(exp_prefix + "QueueLength", &queue_length)) {
  44. RTC_CHECK_GE(queue_length, 0);
  45. config.queue_length_packets = queue_length;
  46. configured = true;
  47. }
  48. configured |=
  49. ParseConfigParam(exp_prefix + "CapacityKbps", &config.link_capacity_kbps);
  50. configured |=
  51. ParseConfigParam(exp_prefix + "LossPercent", &config.loss_percent);
  52. int allow_reordering = 0;
  53. if (ParseConfigParam(exp_prefix + "AllowReordering", &allow_reordering)) {
  54. config.allow_reordering = true;
  55. configured = true;
  56. }
  57. configured |= ParseConfigParam(exp_prefix + "AvgBurstLossLength",
  58. &config.avg_burst_loss_length);
  59. return configured
  60. ? absl::optional<webrtc::BuiltInNetworkBehaviorConfig>(config)
  61. : absl::nullopt;
  62. }
  63. } // namespace
  64. Call* CallFactory::CreateCall(const Call::Config& config) {
  65. absl::optional<webrtc::BuiltInNetworkBehaviorConfig> send_degradation_config =
  66. ParseDegradationConfig(true);
  67. absl::optional<webrtc::BuiltInNetworkBehaviorConfig>
  68. receive_degradation_config = ParseDegradationConfig(false);
  69. if (send_degradation_config || receive_degradation_config) {
  70. return new DegradedCall(std::unique_ptr<Call>(Call::Create(config)),
  71. send_degradation_config, receive_degradation_config,
  72. config.task_queue_factory);
  73. }
  74. return Call::Create(config);
  75. }
  76. std::unique_ptr<CallFactoryInterface> CreateCallFactory() {
  77. return std::unique_ptr<CallFactoryInterface>(new CallFactory());
  78. }
  79. } // namespace webrtc