| 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 "call/call_factory.h" |
| 12 |
| 13 | #include <stdio.h> |
| 14 |
| 15 | #include <memory> |
| 16 | #include <string> |
| 17 | #include <utility> |
| 18 |
| 19 | #include "absl/types/optional.h" |
| 20 | #include "api/test/simulated_network.h" |
| 21 | #include "call/call.h" |
| 22 | #include "call/degraded_call.h" |
| 23 | #include "call/rtp_transport_config.h" |
| 24 | #include "rtc_base/checks.h" |
| 25 | #include "system_wrappers/include/field_trial.h" |
| 26 |
| 27 | namespace webrtc { |
| 28 | namespace { |
| 29 | bool ParseConfigParam(std::string exp_name, int* field) { |
| 30 | std::string group = field_trial::FindFullName(exp_name); |
| 31 | if (group.empty()) |
| 32 | return false; |
| 33 |
| 34 | return (sscanf(group.c_str(), "%d", field) == 1); |
| 35 | } |
| 36 |
| 37 | absl::optional<webrtc::BuiltInNetworkBehaviorConfig> ParseDegradationConfig( |
| 38 | bool send) { |
| 39 | std::string exp_prefix = "WebRTCFakeNetwork"; |
| 40 | if (send) { |
| 41 | exp_prefix += "Send"; |
| 42 | } else { |
| 43 | exp_prefix += "Receive"; |
| 44 | } |
| 45 |
| 46 | webrtc::BuiltInNetworkBehaviorConfig config; |
| 47 | bool configured = false; |
| 48 | configured |= |
| 49 | ParseConfigParam(exp_prefix + "DelayMs", &config.queue_delay_ms); |
| 50 | configured |= ParseConfigParam(exp_prefix + "DelayStdDevMs", |
| 51 | &config.delay_standard_deviation_ms); |
| 52 | int queue_length = 0; |
| 53 | if (ParseConfigParam(exp_prefix + "QueueLength", &queue_length)) { |
| 54 | RTC_CHECK_GE(queue_length, 0); |
| 55 | config.queue_length_packets = queue_length; |
| 56 | configured = true; |
| 57 | } |
| 58 | configured |= |
| 59 | ParseConfigParam(exp_prefix + "CapacityKbps", &config.link_capacity_kbps); |
| 60 | configured |= |
| 61 | ParseConfigParam(exp_prefix + "LossPercent", &config.loss_percent); |
| 62 | int allow_reordering = 0; |
| 63 | if (ParseConfigParam(exp_prefix + "AllowReordering", &allow_reordering)) { |
| 64 | config.allow_reordering = true; |
| 65 | configured = true; |
| 66 | } |
| 67 | configured |= ParseConfigParam(exp_prefix + "AvgBurstLossLength", |
| 68 | &config.avg_burst_loss_length); |
| 69 | return configured |
| 70 | ? absl::optional<webrtc::BuiltInNetworkBehaviorConfig>(config) |
| 71 | : absl::nullopt; |
| 72 | } |
| 73 | } // namespace |
| 74 |
| 75 | CallFactory::CallFactory() { |
| 76 | call_thread_.Detach(); |
| 77 | } |
| 78 |
| 79 | Call* CallFactory::CreateCall(const Call::Config& config) { |
| 80 | RTC_DCHECK_RUN_ON(&call_thread_); |
| 81 | absl::optional<webrtc::BuiltInNetworkBehaviorConfig> send_degradation_config = |
| 82 | ParseDegradationConfig(true); |
| 83 | absl::optional<webrtc::BuiltInNetworkBehaviorConfig> |
| 84 | receive_degradation_config = ParseDegradationConfig(false); |
| 85 |
| 86 | RtpTransportConfig transportConfig = config.ExtractTransportConfig(); |
| 87 |
| 88 | if (send_degradation_config || receive_degradation_config) { |
| 89 | return new DegradedCall( |
| 90 | std::unique_ptr<Call>(Call::Create( |
| 91 | config, Clock::GetRealTimeClock(), |
| 92 | SharedModuleThread::Create( |
| 93 | ProcessThread::Create("ModuleProcessThread"), nullptr), |
| 94 | config.rtp_transport_controller_send_factory->Create( |
| 95 | transportConfig, Clock::GetRealTimeClock(), |
| 96 | ProcessThread::Create("PacerThread")))), |
| 97 | send_degradation_config, receive_degradation_config, |
| 98 | config.task_queue_factory); |
| 99 | } |
| 100 |
| 101 | if (!module_thread_) { |
| 102 | module_thread_ = SharedModuleThread::Create( |
| 103 | ProcessThread::Create("SharedModThread"), [this]() { |
| 104 | RTC_DCHECK_RUN_ON(&call_thread_); |
| 105 | module_thread_ = nullptr; |
| 106 | }); |
| 107 | } |
| 108 |
| 109 | return Call::Create(config, Clock::GetRealTimeClock(), module_thread_, |
| 110 | config.rtp_transport_controller_send_factory->Create( |
| 111 | transportConfig, Clock::GetRealTimeClock(), |
| 112 | ProcessThread::Create("PacerThread"))); |
| 113 | } |
| 114 |
| 115 | std::unique_ptr<CallFactoryInterface> CreateCallFactory() { |
| 116 | return std::unique_ptr<CallFactoryInterface>(new CallFactory()); |
| 117 | } |
| 118 |
| 119 | } // namespace webrtc |
| 120 |