zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "call/call_factory.h" |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <stdio.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 15 | #include <memory> |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 16 | #include <string> |
Vojin Ilic | 504fc19 | 2021-05-31 14:02:28 +0200 | [diff] [blame] | 17 | #include <utility> |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 18 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 19 | #include "absl/types/optional.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "api/test/simulated_network.h" |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 21 | #include "call/call.h" |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 22 | #include "call/degraded_call.h" |
Vojin Ilic | 504fc19 | 2021-05-31 14:02:28 +0200 | [diff] [blame] | 23 | #include "call/rtp_transport_config.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 24 | #include "rtc_base/checks.h" |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 25 | #include "system_wrappers/include/field_trial.h" |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 26 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 27 | namespace webrtc { |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 28 | namespace { |
| 29 | bool ParseConfigParam(std::string exp_name, int* field) { |
| 30 | std::string group = field_trial::FindFullName(exp_name); |
Benjamin Wright | 41f9f2c | 2019-03-13 18:03:29 -0700 | [diff] [blame] | 31 | if (group.empty()) |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 32 | return false; |
| 33 | |
| 34 | return (sscanf(group.c_str(), "%d", field) == 1); |
| 35 | } |
| 36 | |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 37 | absl::optional<webrtc::BuiltInNetworkBehaviorConfig> ParseDegradationConfig( |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 38 | bool send) { |
| 39 | std::string exp_prefix = "WebRTCFakeNetwork"; |
| 40 | if (send) { |
| 41 | exp_prefix += "Send"; |
| 42 | } else { |
| 43 | exp_prefix += "Receive"; |
| 44 | } |
| 45 | |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 46 | webrtc::BuiltInNetworkBehaviorConfig config; |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 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); |
Artem Titov | 4ff63cc | 2018-08-23 10:54:54 +0200 | [diff] [blame] | 69 | return configured |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 70 | ? absl::optional<webrtc::BuiltInNetworkBehaviorConfig>(config) |
Artem Titov | 4ff63cc | 2018-08-23 10:54:54 +0200 | [diff] [blame] | 71 | : absl::nullopt; |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 72 | } |
| 73 | } // namespace |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 74 | |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 75 | CallFactory::CallFactory() { |
| 76 | call_thread_.Detach(); |
| 77 | } |
| 78 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 79 | Call* CallFactory::CreateCall(const Call::Config& config) { |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 80 | RTC_DCHECK_RUN_ON(&call_thread_); |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 81 | absl::optional<webrtc::BuiltInNetworkBehaviorConfig> send_degradation_config = |
| 82 | ParseDegradationConfig(true); |
| 83 | absl::optional<webrtc::BuiltInNetworkBehaviorConfig> |
Artem Titov | 4ff63cc | 2018-08-23 10:54:54 +0200 | [diff] [blame] | 84 | receive_degradation_config = ParseDegradationConfig(false); |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 85 | |
Vojin Ilic | 504fc19 | 2021-05-31 14:02:28 +0200 | [diff] [blame] | 86 | RtpTransportConfig transportConfig = config.ExtractTransportConfig(); |
| 87 | |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 88 | if (send_degradation_config || receive_degradation_config) { |
Vojin Ilic | 504fc19 | 2021-05-31 14:02:28 +0200 | [diff] [blame] | 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); |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 101 | if (!module_thread_) { |
Per Kjellander | 4c50e70 | 2020-06-30 14:39:43 +0200 | [diff] [blame] | 102 | module_thread_ = SharedModuleThread::Create( |
| 103 | ProcessThread::Create("SharedModThread"), [this]() { |
| 104 | RTC_DCHECK_RUN_ON(&call_thread_); |
| 105 | module_thread_ = nullptr; |
| 106 | }); |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Vojin Ilic | 504fc19 | 2021-05-31 14:02:28 +0200 | [diff] [blame] | 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"))); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | std::unique_ptr<CallFactoryInterface> CreateCallFactory() { |
| 116 | return std::unique_ptr<CallFactoryInterface>(new CallFactory()); |
| 117 | } |
| 118 | |
| 119 | } // namespace webrtc |