| 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/create_call.h" |
| 12 |
| 13 | #include <stdio.h> |
| 14 |
| 15 | #include <memory> |
| 16 | #include <string> |
| 17 | #include <utility> |
| 18 | #include <vector> |
| 19 |
| 20 | #include "absl/types/optional.h" |
| 21 | #include "api/test/simulated_network.h" |
| 22 | #include "api/units/time_delta.h" |
| 23 | #include "call/call.h" |
| 24 | #include "call/degraded_call.h" |
| 25 | #include "rtc_base/checks.h" |
| 26 | #include "rtc_base/experiments/field_trial_list.h" |
| 27 | #include "rtc_base/experiments/field_trial_parser.h" |
| 28 |
| 29 | namespace webrtc { |
| 30 | namespace { |
| 31 | using TimeScopedNetworkConfig = DegradedCall::TimeScopedNetworkConfig; |
| 32 |
| 33 | std::vector<TimeScopedNetworkConfig> GetNetworkConfigs( |
| 34 | const FieldTrialsView& trials, |
| 35 | bool send) { |
| 36 | FieldTrialStructList<TimeScopedNetworkConfig> trials_list( |
| 37 | {FieldTrialStructMember("queue_length_packets", |
| 38 | [](TimeScopedNetworkConfig* p) { |
| 39 | // FieldTrialParser does not natively support |
| 40 | // size_t type, so use this ugly cast as |
| 41 | // workaround. |
| 42 | return reinterpret_cast<unsigned*>( |
| 43 | &p->queue_length_packets); |
| 44 | }), |
| 45 | FieldTrialStructMember( |
| 46 | "queue_delay_ms", |
| 47 | [](TimeScopedNetworkConfig* p) { return &p->queue_delay_ms; }), |
| 48 | FieldTrialStructMember("delay_standard_deviation_ms", |
| 49 | [](TimeScopedNetworkConfig* p) { |
| 50 | return &p->delay_standard_deviation_ms; |
| 51 | }), |
| 52 | FieldTrialStructMember( |
| 53 | "link_capacity_kbps", |
| 54 | [](TimeScopedNetworkConfig* p) { return &p->link_capacity_kbps; }), |
| 55 | FieldTrialStructMember( |
| 56 | "loss_percent", |
| 57 | [](TimeScopedNetworkConfig* p) { return &p->loss_percent; }), |
| 58 | FieldTrialStructMember( |
| 59 | "allow_reordering", |
| 60 | [](TimeScopedNetworkConfig* p) { return &p->allow_reordering; }), |
| 61 | FieldTrialStructMember("avg_burst_loss_length", |
| 62 | [](TimeScopedNetworkConfig* p) { |
| 63 | return &p->avg_burst_loss_length; |
| 64 | }), |
| 65 | FieldTrialStructMember( |
| 66 | "packet_overhead", |
| 67 | [](TimeScopedNetworkConfig* p) { return &p->packet_overhead; }), |
| 68 | FieldTrialStructMember( |
| 69 | "duration", |
| 70 | [](TimeScopedNetworkConfig* p) { return &p->duration; })}, |
| 71 | {}); |
| 72 | ParseFieldTrial({&trials_list}, |
| 73 | trials.Lookup(send ? "WebRTC-FakeNetworkSendConfig" |
| 74 | : "WebRTC-FakeNetworkReceiveConfig")); |
| 75 | return trials_list.Get(); |
| 76 | } |
| 77 |
| 78 | } // namespace |
| 79 |
| 80 | std::unique_ptr<Call> CreateCall(const CallConfig& config) { |
| 81 | std::vector<DegradedCall::TimeScopedNetworkConfig> send_degradation_configs = |
| 82 | GetNetworkConfigs(config.env.field_trials(), /*send=*/true); |
| 83 | std::vector<DegradedCall::TimeScopedNetworkConfig> |
| 84 | receive_degradation_configs = |
| 85 | GetNetworkConfigs(config.env.field_trials(), /*send=*/false); |
| 86 |
| 87 | std::unique_ptr<Call> call = Call::Create(config); |
| 88 |
| 89 | if (!send_degradation_configs.empty() || |
| 90 | !receive_degradation_configs.empty()) { |
| 91 | return std::make_unique<DegradedCall>( |
| 92 | std::move(call), send_degradation_configs, receive_degradation_configs); |
| 93 | } |
| 94 |
| 95 | return call; |
| 96 | } |
| 97 |
| 98 | } // namespace webrtc |
| 99 |