2020-08-14 16:58:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "call/call_factory.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2022-03-11 16:49:54 +00:00
|
|
|
#include <utility>
|
2020-08-14 16:58:22 +00:00
|
|
|
|
|
|
|
#include "absl/types/optional.h"
|
|
|
|
#include "api/test/simulated_network.h"
|
|
|
|
#include "call/call.h"
|
|
|
|
#include "call/degraded_call.h"
|
2022-03-11 16:49:54 +00:00
|
|
|
#include "call/rtp_transport_config.h"
|
2020-08-14 16:58:22 +00:00
|
|
|
#include "rtc_base/checks.h"
|
2022-03-13 01:58:00 +00:00
|
|
|
#include "system_wrappers/include/field_trial.h"
|
2020-08-14 16:58:22 +00:00
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
namespace {
|
2022-03-13 01:58:00 +00:00
|
|
|
bool ParseConfigParam(std::string exp_name, int* field) {
|
|
|
|
std::string group = field_trial::FindFullName(exp_name);
|
2020-08-14 16:58:22 +00:00
|
|
|
if (group.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (sscanf(group.c_str(), "%d", field) == 1);
|
|
|
|
}
|
|
|
|
|
2022-03-13 01:58:00 +00:00
|
|
|
absl::optional<webrtc::BuiltInNetworkBehaviorConfig> ParseDegradationConfig(
|
2020-08-14 16:58:22 +00:00
|
|
|
bool send) {
|
|
|
|
std::string exp_prefix = "WebRTCFakeNetwork";
|
|
|
|
if (send) {
|
|
|
|
exp_prefix += "Send";
|
|
|
|
} else {
|
|
|
|
exp_prefix += "Receive";
|
|
|
|
}
|
|
|
|
|
2022-03-13 01:58:00 +00:00
|
|
|
webrtc::BuiltInNetworkBehaviorConfig config;
|
2020-08-14 16:58:22 +00:00
|
|
|
bool configured = false;
|
|
|
|
configured |=
|
2022-03-13 01:58:00 +00:00
|
|
|
ParseConfigParam(exp_prefix + "DelayMs", &config.queue_delay_ms);
|
|
|
|
configured |= ParseConfigParam(exp_prefix + "DelayStdDevMs",
|
2020-08-14 16:58:22 +00:00
|
|
|
&config.delay_standard_deviation_ms);
|
|
|
|
int queue_length = 0;
|
2022-03-13 01:58:00 +00:00
|
|
|
if (ParseConfigParam(exp_prefix + "QueueLength", &queue_length)) {
|
2020-08-14 16:58:22 +00:00
|
|
|
RTC_CHECK_GE(queue_length, 0);
|
|
|
|
config.queue_length_packets = queue_length;
|
|
|
|
configured = true;
|
|
|
|
}
|
2022-03-13 01:58:00 +00:00
|
|
|
configured |=
|
|
|
|
ParseConfigParam(exp_prefix + "CapacityKbps", &config.link_capacity_kbps);
|
|
|
|
configured |=
|
|
|
|
ParseConfigParam(exp_prefix + "LossPercent", &config.loss_percent);
|
2020-08-14 16:58:22 +00:00
|
|
|
int allow_reordering = 0;
|
2022-03-13 01:58:00 +00:00
|
|
|
if (ParseConfigParam(exp_prefix + "AllowReordering", &allow_reordering)) {
|
2020-08-14 16:58:22 +00:00
|
|
|
config.allow_reordering = true;
|
|
|
|
configured = true;
|
|
|
|
}
|
2022-03-13 01:58:00 +00:00
|
|
|
configured |= ParseConfigParam(exp_prefix + "AvgBurstLossLength",
|
2020-08-14 16:58:22 +00:00
|
|
|
&config.avg_burst_loss_length);
|
2022-03-13 01:58:00 +00:00
|
|
|
return configured
|
|
|
|
? absl::optional<webrtc::BuiltInNetworkBehaviorConfig>(config)
|
|
|
|
: absl::nullopt;
|
2020-08-14 16:58:22 +00:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CallFactory::CallFactory() {
|
|
|
|
call_thread_.Detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
Call* CallFactory::CreateCall(const Call::Config& config) {
|
|
|
|
RTC_DCHECK_RUN_ON(&call_thread_);
|
2022-03-13 01:58:00 +00:00
|
|
|
absl::optional<webrtc::BuiltInNetworkBehaviorConfig> send_degradation_config =
|
|
|
|
ParseDegradationConfig(true);
|
|
|
|
absl::optional<webrtc::BuiltInNetworkBehaviorConfig>
|
|
|
|
receive_degradation_config = ParseDegradationConfig(false);
|
2022-03-11 16:49:54 +00:00
|
|
|
|
|
|
|
RtpTransportConfig transportConfig = config.ExtractTransportConfig();
|
|
|
|
|
2022-03-13 01:58:00 +00:00
|
|
|
if (send_degradation_config || receive_degradation_config) {
|
2022-03-11 16:49:54 +00:00
|
|
|
return new DegradedCall(
|
|
|
|
std::unique_ptr<Call>(Call::Create(
|
|
|
|
config, Clock::GetRealTimeClock(),
|
|
|
|
SharedModuleThread::Create(
|
|
|
|
ProcessThread::Create("ModuleProcessThread"), nullptr),
|
|
|
|
config.rtp_transport_controller_send_factory->Create(
|
|
|
|
transportConfig, Clock::GetRealTimeClock(),
|
|
|
|
ProcessThread::Create("PacerThread")))),
|
2022-03-13 01:58:00 +00:00
|
|
|
send_degradation_config, receive_degradation_config,
|
|
|
|
config.task_queue_factory);
|
2020-08-14 16:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!module_thread_) {
|
|
|
|
module_thread_ = SharedModuleThread::Create(
|
|
|
|
ProcessThread::Create("SharedModThread"), [this]() {
|
|
|
|
RTC_DCHECK_RUN_ON(&call_thread_);
|
|
|
|
module_thread_ = nullptr;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-11 16:49:54 +00:00
|
|
|
return Call::Create(config, Clock::GetRealTimeClock(), module_thread_,
|
|
|
|
config.rtp_transport_controller_send_factory->Create(
|
|
|
|
transportConfig, Clock::GetRealTimeClock(),
|
|
|
|
ProcessThread::Create("PacerThread")));
|
2020-08-14 16:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CallFactoryInterface> CreateCallFactory() {
|
|
|
|
return std::unique_ptr<CallFactoryInterface>(new CallFactory());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace webrtc
|