blob: a3ebc47c6b3f26c4aa0c5fde7732e46d02264a73 [file] [log] [blame]
zhihuang38ede132017-06-15 19:52:321/*
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 Anton10542f22019-01-11 17:11:0011#include "call/call_factory.h"
zhihuang38ede132017-06-15 19:52:3212
Yves Gerey3e707812018-11-28 15:47:4913#include <stdio.h>
Jonas Olssona4d87372019-07-05 17:08:3314
zhihuang38ede132017-06-15 19:52:3215#include <memory>
Erik Språng09708512018-03-14 14:16:5016#include <string>
zhihuang38ede132017-06-15 19:52:3217
Danil Chapovalovb9b146c2018-06-15 10:28:0718#include "absl/types/optional.h"
Yves Gerey3e707812018-11-28 15:47:4919#include "api/test/simulated_network.h"
Niels Möller8366e172018-02-14 11:20:1320#include "call/call.h"
Erik Språng09708512018-03-14 14:16:5021#include "call/degraded_call.h"
Yves Gerey3e707812018-11-28 15:47:4922#include "rtc_base/checks.h"
Erik Språng09708512018-03-14 14:16:5023#include "system_wrappers/include/field_trial.h"
Niels Möller8366e172018-02-14 11:20:1324
zhihuang38ede132017-06-15 19:52:3225namespace webrtc {
Erik Språng09708512018-03-14 14:16:5026namespace {
27bool ParseConfigParam(std::string exp_name, int* field) {
28 std::string group = field_trial::FindFullName(exp_name);
Benjamin Wright41f9f2c2019-03-14 01:03:2929 if (group.empty())
Erik Språng09708512018-03-14 14:16:5030 return false;
31
32 return (sscanf(group.c_str(), "%d", field) == 1);
33}
34
Artem Titov75e36472018-10-08 10:28:5635absl::optional<webrtc::BuiltInNetworkBehaviorConfig> ParseDegradationConfig(
Erik Språng09708512018-03-14 14:16:5036 bool send) {
37 std::string exp_prefix = "WebRTCFakeNetwork";
38 if (send) {
39 exp_prefix += "Send";
40 } else {
41 exp_prefix += "Receive";
42 }
43
Artem Titov75e36472018-10-08 10:28:5644 webrtc::BuiltInNetworkBehaviorConfig config;
Erik Språng09708512018-03-14 14:16:5045 bool configured = false;
46 configured |=
47 ParseConfigParam(exp_prefix + "DelayMs", &config.queue_delay_ms);
48 configured |= ParseConfigParam(exp_prefix + "DelayStdDevMs",
49 &config.delay_standard_deviation_ms);
50 int queue_length = 0;
51 if (ParseConfigParam(exp_prefix + "QueueLength", &queue_length)) {
52 RTC_CHECK_GE(queue_length, 0);
53 config.queue_length_packets = queue_length;
54 configured = true;
55 }
56 configured |=
57 ParseConfigParam(exp_prefix + "CapacityKbps", &config.link_capacity_kbps);
58 configured |=
59 ParseConfigParam(exp_prefix + "LossPercent", &config.loss_percent);
60 int allow_reordering = 0;
61 if (ParseConfigParam(exp_prefix + "AllowReordering", &allow_reordering)) {
62 config.allow_reordering = true;
63 configured = true;
64 }
65 configured |= ParseConfigParam(exp_prefix + "AvgBurstLossLength",
66 &config.avg_burst_loss_length);
Artem Titov4ff63cc2018-08-23 08:54:5467 return configured
Artem Titov75e36472018-10-08 10:28:5668 ? absl::optional<webrtc::BuiltInNetworkBehaviorConfig>(config)
Artem Titov4ff63cc2018-08-23 08:54:5469 : absl::nullopt;
Erik Språng09708512018-03-14 14:16:5070}
71} // namespace
zhihuang38ede132017-06-15 19:52:3272
Tommi25c77c12020-05-25 15:44:5573CallFactory::CallFactory() {
74 call_thread_.Detach();
75}
76
zhihuang38ede132017-06-15 19:52:3277Call* CallFactory::CreateCall(const Call::Config& config) {
Tommi25c77c12020-05-25 15:44:5578 RTC_DCHECK_RUN_ON(&call_thread_);
Artem Titov75e36472018-10-08 10:28:5679 absl::optional<webrtc::BuiltInNetworkBehaviorConfig> send_degradation_config =
80 ParseDegradationConfig(true);
81 absl::optional<webrtc::BuiltInNetworkBehaviorConfig>
Artem Titov4ff63cc2018-08-23 08:54:5482 receive_degradation_config = ParseDegradationConfig(false);
Erik Språng09708512018-03-14 14:16:5083
84 if (send_degradation_config || receive_degradation_config) {
85 return new DegradedCall(std::unique_ptr<Call>(Call::Create(config)),
Erik Språngc6488192019-08-06 13:54:2386 send_degradation_config, receive_degradation_config,
87 config.task_queue_factory);
Erik Språng09708512018-03-14 14:16:5088 }
89
Tommi25c77c12020-05-25 15:44:5590 if (!module_thread_) {
91 module_thread_ = SharedModuleThread::Create("SharedModThread", [this]() {
92 RTC_DCHECK_RUN_ON(&call_thread_);
93 module_thread_ = nullptr;
94 });
95 }
96
97 return Call::Create(config, module_thread_);
zhihuang38ede132017-06-15 19:52:3298}
99
100std::unique_ptr<CallFactoryInterface> CreateCallFactory() {
101 return std::unique_ptr<CallFactoryInterface>(new CallFactory());
102}
103
104} // namespace webrtc