Run degraded fake network on Call's network thread.

This avoids creating a dedicated task queue that potentially contends
with the network thread.

Bug: webrtc:251043
Change-Id: I2d54486c4235dac44b79f89d4f3d81b4d3de4026
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/252282
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36058}
This commit is contained in:
Erik Språng 2022-02-23 11:34:46 +01:00 committed by WebRTC LUCI CQ
parent 6589def397
commit 42abc13d17
3 changed files with 23 additions and 25 deletions

View File

@ -165,8 +165,7 @@ Call* CallFactory::CreateCall(const Call::Config& config) {
config.rtp_transport_controller_send_factory->Create(
transportConfig, Clock::GetRealTimeClock(),
ProcessThread::Create("PacerThread")))),
send_degradation_configs, receive_degradation_configs,
config.task_queue_factory);
send_degradation_configs, receive_degradation_configs);
}
if (!module_thread_) {

View File

@ -18,13 +18,13 @@
namespace webrtc {
DegradedCall::FakeNetworkPipeOnTaskQueue::FakeNetworkPipeOnTaskQueue(
TaskQueueFactory* task_queue_factory,
TaskQueueBase* task_queue,
const ScopedTaskSafety& task_safety,
Clock* clock,
std::unique_ptr<NetworkBehaviorInterface> network_behavior)
: clock_(clock),
task_queue_(task_queue_factory->CreateTaskQueue(
"DegradedSendQueue",
TaskQueueFactory::Priority::NORMAL)),
task_queue_(task_queue),
task_safety_(task_safety),
pipe_(clock, std::move(network_behavior)) {}
void DegradedCall::FakeNetworkPipeOnTaskQueue::SendRtp(
@ -61,21 +61,22 @@ bool DegradedCall::FakeNetworkPipeOnTaskQueue::Process() {
return false;
}
task_queue_.PostTask([this, time_to_next]() {
RTC_DCHECK_RUN_ON(&task_queue_);
task_queue_->PostTask(ToQueuedTask(task_safety_, [this, time_to_next] {
RTC_DCHECK_RUN_ON(task_queue_);
int64_t next_process_time = *time_to_next + clock_->TimeInMilliseconds();
if (!next_process_ms_ || next_process_time < *next_process_ms_) {
next_process_ms_ = next_process_time;
task_queue_.PostDelayedHighPrecisionTask(
[this]() {
RTC_DCHECK_RUN_ON(&task_queue_);
if (!Process()) {
next_process_ms_.reset();
}
},
task_queue_->PostDelayedHighPrecisionTask(
ToQueuedTask(task_safety_,
[this] {
RTC_DCHECK_RUN_ON(task_queue_);
if (!Process()) {
next_process_ms_.reset();
}
}),
*time_to_next);
}
});
}));
return true;
}
@ -128,11 +129,9 @@ bool DegradedCall::FakeNetworkPipeTransportAdapter::SendRtcp(
DegradedCall::DegradedCall(
std::unique_ptr<Call> call,
const std::vector<TimeScopedNetworkConfig>& send_configs,
const std::vector<TimeScopedNetworkConfig>& receive_configs,
TaskQueueFactory* task_queue_factory)
const std::vector<TimeScopedNetworkConfig>& receive_configs)
: clock_(Clock::GetRealTimeClock()),
call_(std::move(call)),
task_queue_factory_(task_queue_factory),
send_config_index_(0),
send_configs_(send_configs),
send_simulated_network_(nullptr),
@ -154,7 +153,7 @@ DegradedCall::DegradedCall(
auto network = std::make_unique<SimulatedNetwork>(send_configs_[0]);
send_simulated_network_ = network.get();
send_pipe_ = std::make_unique<FakeNetworkPipeOnTaskQueue>(
task_queue_factory_, clock_, std::move(network));
call_->network_thread(), task_safety_, clock_, std::move(network));
if (send_configs_.size() > 1) {
call_->network_thread()->PostDelayedTask(
ToQueuedTask(task_safety_, [this] { UpdateSendNetworkConfig(); }),

View File

@ -52,8 +52,7 @@ class DegradedCall : public Call, private PacketReceiver {
explicit DegradedCall(
std::unique_ptr<Call> call,
const std::vector<TimeScopedNetworkConfig>& send_configs,
const std::vector<TimeScopedNetworkConfig>& receive_configs,
TaskQueueFactory* task_queue_factory);
const std::vector<TimeScopedNetworkConfig>& receive_configs);
~DegradedCall() override;
// Implements Call.
@ -115,7 +114,8 @@ class DegradedCall : public Call, private PacketReceiver {
class FakeNetworkPipeOnTaskQueue {
public:
FakeNetworkPipeOnTaskQueue(
TaskQueueFactory* task_queue_factory,
TaskQueueBase* task_queue,
const ScopedTaskSafety& task_safety,
Clock* clock,
std::unique_ptr<NetworkBehaviorInterface> network_behavior);
@ -134,7 +134,8 @@ class DegradedCall : public Call, private PacketReceiver {
bool Process();
Clock* const clock_;
rtc::TaskQueue task_queue_;
TaskQueueBase* const task_queue_;
const ScopedTaskSafety& task_safety_;
FakeNetworkPipe pipe_;
absl::optional<int64_t> next_process_ms_ RTC_GUARDED_BY(&task_queue_);
};
@ -171,7 +172,6 @@ class DegradedCall : public Call, private PacketReceiver {
Clock* const clock_;
const std::unique_ptr<Call> call_;
ScopedTaskSafety task_safety_;
TaskQueueFactory* const task_queue_factory_;
size_t send_config_index_;
const std::vector<TimeScopedNetworkConfig> send_configs_;
SimulatedNetwork* send_simulated_network_;