diff --git a/call/fake_network_pipe.cc b/call/fake_network_pipe.cc index 492eae2eb5..19a6ddc43a 100644 --- a/call/fake_network_pipe.cc +++ b/call/fake_network_pipe.cc @@ -117,6 +117,7 @@ FakeNetworkPipe::FakeNetworkPipe(Clock* clock, receiver_(nullptr), transport_(nullptr), random_(seed), + clock_offset_ms_(0), config_(), dropped_packets_(0), sent_packets_(0), @@ -134,6 +135,7 @@ FakeNetworkPipe::FakeNetworkPipe(Clock* clock, receiver_(nullptr), transport_(transport), random_(1), + clock_offset_ms_(0), config_(), dropped_packets_(0), sent_packets_(0), @@ -179,6 +181,11 @@ PacketReceiver::DeliveryStatus FakeNetworkPipe::DeliverPacket( : PacketReceiver::DELIVERY_PACKET_ERROR; } +void FakeNetworkPipe::SetClockOffset(int64_t offset_ms) { + rtc::CritScope crit(&config_lock_); + clock_offset_ms_ = offset_ms; +} + void FakeNetworkPipe::SetConfig(const FakeNetworkPipe::Config& config) { rtc::CritScope crit(&config_lock_); config_ = config; // Shallow copy of the struct. @@ -394,6 +401,7 @@ void FakeNetworkPipe::DeliverPacket(NetworkPacket* packet) { int64_t queue_time = packet->arrival_time() - packet->send_time(); RTC_CHECK(queue_time >= 0); packet_time.timestamp += (queue_time * 1000); + packet_time.timestamp += (clock_offset_ms_ * 1000); } receiver_->DeliverPacket(packet->media_type(), std::move(*packet->raw_packet()), packet_time); diff --git a/call/fake_network_pipe.h b/call/fake_network_pipe.h index bd3a79c8d7..3c6cfdd6b1 100644 --- a/call/fake_network_pipe.h +++ b/call/fake_network_pipe.h @@ -149,6 +149,8 @@ class FakeNetworkPipe : public Transport, public PacketReceiver, public Module { virtual ~FakeNetworkPipe(); + void SetClockOffset(int64_t offset_ms); + // Sets a new configuration. This won't affect packets already in the pipe. void SetConfig(const FakeNetworkPipe::Config& config); @@ -229,6 +231,8 @@ class FakeNetworkPipe : public Transport, public PacketReceiver, public Module { std::deque delay_link_; + int64_t clock_offset_ms_ RTC_GUARDED_BY(config_lock_); + // Link configuration. Config config_ RTC_GUARDED_BY(config_lock_); diff --git a/test/direct_transport.cc b/test/direct_transport.cc index dddbe58909..971130fe9e 100644 --- a/test/direct_transport.cc +++ b/test/direct_transport.cc @@ -68,6 +68,10 @@ DirectTransport::~DirectTransport() { task_queue_->CancelTask(next_scheduled_task_); } +void DirectTransport::SetClockOffset(int64_t offset_ms) { + fake_network_->SetClockOffset(offset_ms); +} + void DirectTransport::SetConfig(const FakeNetworkPipe::Config& config) { fake_network_->SetConfig(config); } diff --git a/test/direct_transport.h b/test/direct_transport.h index 2a59096889..d61282aae7 100644 --- a/test/direct_transport.h +++ b/test/direct_transport.h @@ -51,6 +51,8 @@ class DirectTransport : public Transport { ~DirectTransport() override; + void SetClockOffset(int64_t offset_ms); + void SetConfig(const FakeNetworkPipe::Config& config); RTC_DEPRECATED void StopSending();