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> |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 14 | #include <memory> |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 15 | #include <string> |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 16 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 18 | #include "api/test/simulated_network.h" |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 19 | #include "call/call.h" |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 20 | #include "call/degraded_call.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 21 | #include "rtc_base/checks.h" |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 22 | #include "system_wrappers/include/field_trial.h" |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 23 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 24 | namespace webrtc { |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 25 | namespace { |
| 26 | bool ParseConfigParam(std::string exp_name, int* field) { |
| 27 | std::string group = field_trial::FindFullName(exp_name); |
| 28 | if (group == "") |
| 29 | return false; |
| 30 | |
| 31 | return (sscanf(group.c_str(), "%d", field) == 1); |
| 32 | } |
| 33 | |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 34 | absl::optional<webrtc::BuiltInNetworkBehaviorConfig> ParseDegradationConfig( |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 35 | bool send) { |
| 36 | std::string exp_prefix = "WebRTCFakeNetwork"; |
| 37 | if (send) { |
| 38 | exp_prefix += "Send"; |
| 39 | } else { |
| 40 | exp_prefix += "Receive"; |
| 41 | } |
| 42 | |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 43 | webrtc::BuiltInNetworkBehaviorConfig config; |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 44 | bool configured = false; |
| 45 | configured |= |
| 46 | ParseConfigParam(exp_prefix + "DelayMs", &config.queue_delay_ms); |
| 47 | configured |= ParseConfigParam(exp_prefix + "DelayStdDevMs", |
| 48 | &config.delay_standard_deviation_ms); |
| 49 | int queue_length = 0; |
| 50 | if (ParseConfigParam(exp_prefix + "QueueLength", &queue_length)) { |
| 51 | RTC_CHECK_GE(queue_length, 0); |
| 52 | config.queue_length_packets = queue_length; |
| 53 | configured = true; |
| 54 | } |
| 55 | configured |= |
| 56 | ParseConfigParam(exp_prefix + "CapacityKbps", &config.link_capacity_kbps); |
| 57 | configured |= |
| 58 | ParseConfigParam(exp_prefix + "LossPercent", &config.loss_percent); |
| 59 | int allow_reordering = 0; |
| 60 | if (ParseConfigParam(exp_prefix + "AllowReordering", &allow_reordering)) { |
| 61 | config.allow_reordering = true; |
| 62 | configured = true; |
| 63 | } |
| 64 | configured |= ParseConfigParam(exp_prefix + "AvgBurstLossLength", |
| 65 | &config.avg_burst_loss_length); |
Artem Titov | 4ff63cc | 2018-08-23 10:54:54 +0200 | [diff] [blame] | 66 | return configured |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 67 | ? absl::optional<webrtc::BuiltInNetworkBehaviorConfig>(config) |
Artem Titov | 4ff63cc | 2018-08-23 10:54:54 +0200 | [diff] [blame] | 68 | : absl::nullopt; |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 69 | } |
| 70 | } // namespace |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 71 | |
| 72 | Call* CallFactory::CreateCall(const Call::Config& config) { |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 73 | absl::optional<webrtc::BuiltInNetworkBehaviorConfig> send_degradation_config = |
| 74 | ParseDegradationConfig(true); |
| 75 | absl::optional<webrtc::BuiltInNetworkBehaviorConfig> |
Artem Titov | 4ff63cc | 2018-08-23 10:54:54 +0200 | [diff] [blame] | 76 | receive_degradation_config = ParseDegradationConfig(false); |
Erik Språng | 0970851 | 2018-03-14 15:16:50 +0100 | [diff] [blame] | 77 | |
| 78 | if (send_degradation_config || receive_degradation_config) { |
| 79 | return new DegradedCall(std::unique_ptr<Call>(Call::Create(config)), |
| 80 | send_degradation_config, |
| 81 | receive_degradation_config); |
| 82 | } |
| 83 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 84 | return Call::Create(config); |
| 85 | } |
| 86 | |
| 87 | std::unique_ptr<CallFactoryInterface> CreateCallFactory() { |
| 88 | return std::unique_ptr<CallFactoryInterface>(new CallFactory()); |
| 89 | } |
| 90 | |
| 91 | } // namespace webrtc |