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