From 71822866c65d33f4964decd5de31cefe4b592fd0 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Tue, 30 Oct 2018 08:23:27 +0100 Subject: [PATCH] Allow FakeNetworkPipe to wake up its processing thread Bug: webrtc:9630 Change-Id: I2b09593f175e3f3e1fe0d990515aa70c2481161b Reviewed-on: https://webrtc-review.googlesource.com/c/95144 Commit-Queue: Sebastian Jansson Reviewed-by: Christoffer Rodbro Cr-Commit-Position: refs/heads/master@{#25451} --- call/BUILD.gn | 1 + call/fake_network_pipe.cc | 34 ++++++++++++++++++---------------- call/fake_network_pipe.h | 7 ++++--- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/call/BUILD.gn b/call/BUILD.gn index 21d1ac1c94..0b65c3c60a 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -290,6 +290,7 @@ rtc_source_set("fake_network") { "../api:simulated_network_api", "../api:transport_api", "../modules:module_api", + "../modules/utility", "../rtc_base:rtc_base_approved", "../rtc_base:sequenced_task_checker", "../system_wrappers", diff --git a/call/fake_network_pipe.cc b/call/fake_network_pipe.cc index 7222dfd0ab..3bd2e8f48b 100644 --- a/call/fake_network_pipe.cc +++ b/call/fake_network_pipe.cc @@ -18,6 +18,7 @@ #include "call/call.h" #include "call/fake_network_pipe.h" #include "call/simulated_network.h" +#include "modules/utility/include/process_thread.h" #include "rtc_base/logging.h" #include "system_wrappers/include/clock.h" @@ -90,7 +91,6 @@ FakeNetworkPipe::FakeNetworkPipe( dropped_packets_(0), sent_packets_(0), total_packet_delay_us_(0), - next_process_time_us_(clock_->TimeInMicroseconds()), last_log_time_us_(clock_->TimeInMicroseconds()) {} FakeNetworkPipe::FakeNetworkPipe( @@ -105,7 +105,6 @@ FakeNetworkPipe::FakeNetworkPipe( dropped_packets_(0), sent_packets_(0), total_packet_delay_us_(0), - next_process_time_us_(clock_->TimeInMicroseconds()), last_log_time_us_(clock_->TimeInMicroseconds()) {} FakeNetworkPipe::~FakeNetworkPipe() = default; @@ -169,6 +168,12 @@ bool FakeNetworkPipe::EnqueuePacket(rtc::CopyOnWriteBuffer packet, packets_in_flight_.pop_back(); ++dropped_packets_; } + if (network_behavior_->NextDeliveryTimeUs()) { + rtc::CritScope crit(&process_thread_lock_); + if (process_thread_) + process_thread_->WakeUp(nullptr); + } + return sent; } @@ -264,10 +269,6 @@ void FakeNetworkPipe::Process() { packets_to_deliver.pop(); DeliverNetworkPacket(&packet); } - absl::optional delivery_us = network_behavior_->NextDeliveryTimeUs(); - next_process_time_us_ = delivery_us - ? *delivery_us - : time_now_us + kDefaultProcessIntervalMs * 1000; } void FakeNetworkPipe::DeliverNetworkPacket(NetworkPacket* packet) { @@ -294,8 +295,17 @@ void FakeNetworkPipe::DeliverNetworkPacket(NetworkPacket* packet) { int64_t FakeNetworkPipe::TimeUntilNextProcess() { rtc::CritScope crit(&process_lock_); - int64_t delay_us = next_process_time_us_ - clock_->TimeInMicroseconds(); - return std::max((delay_us + 500) / 1000, 0); + absl::optional delivery_us = network_behavior_->NextDeliveryTimeUs(); + if (delivery_us) { + int64_t delay_us = *delivery_us - clock_->TimeInMicroseconds(); + return std::max((delay_us + 500) / 1000, 0); + } + return kDefaultProcessIntervalMs; +} + +void FakeNetworkPipe::ProcessThreadAttached(ProcessThread* process_thread) { + rtc::CritScope cs(&process_thread_lock_); + process_thread_ = process_thread; } bool FakeNetworkPipe::HasTransport() const { @@ -323,12 +333,4 @@ int64_t FakeNetworkPipe::GetTimeInMicroseconds() const { return clock_->TimeInMicroseconds(); } -bool FakeNetworkPipe::ShouldProcess(int64_t time_now_us) const { - return time_now_us >= next_process_time_us_; -} - -void FakeNetworkPipe::SetTimeToNextProcess(int64_t skip_us) { - next_process_time_us_ += skip_us; -} - } // namespace webrtc diff --git a/call/fake_network_pipe.h b/call/fake_network_pipe.h index 372c7c5ddf..56007a9976 100644 --- a/call/fake_network_pipe.h +++ b/call/fake_network_pipe.h @@ -140,6 +140,7 @@ class FakeNetworkPipe : public webrtc::SimulatedPacketReceiverInterface, // packets ready to be delivered. void Process() override; int64_t TimeUntilNextProcess() override; + void ProcessThreadAttached(ProcessThread* process_thread) override; // Get statistics. float PercentageLoss(); @@ -194,6 +195,9 @@ class FakeNetworkPipe : public webrtc::SimulatedPacketReceiverInterface, // processes, such as the packet queues. rtc::CriticalSection process_lock_; + rtc::CriticalSection process_thread_lock_; + ProcessThread* process_thread_ RTC_GUARDED_BY(process_thread_lock_) = nullptr; + // Packets are added at the back of the deque, this makes the deque ordered // by increasing send time. The common case when removing packets from the // deque is removing early packets, which will be close to the front of the @@ -207,9 +211,6 @@ class FakeNetworkPipe : public webrtc::SimulatedPacketReceiverInterface, size_t dropped_packets_ RTC_GUARDED_BY(process_lock_); size_t sent_packets_ RTC_GUARDED_BY(process_lock_); int64_t total_packet_delay_us_ RTC_GUARDED_BY(process_lock_); - - int64_t next_process_time_us_; - int64_t last_log_time_us_; RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe);