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 <srte@webrtc.org> Reviewed-by: Christoffer Rodbro <crodbro@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25451}
This commit is contained in:
parent
693432d9fa
commit
71822866c6
@ -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",
|
||||
|
||||
@ -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<int64_t> 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<int64_t>((delay_us + 500) / 1000, 0);
|
||||
absl::optional<int64_t> delivery_us = network_behavior_->NextDeliveryTimeUs();
|
||||
if (delivery_us) {
|
||||
int64_t delay_us = *delivery_us - clock_->TimeInMicroseconds();
|
||||
return std::max<int64_t>((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
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user