From 7e85d670317392af1f4b140a428c41ddee1022d0 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Fri, 6 Apr 2018 09:56:21 +0200 Subject: [PATCH] Added SetClockOffset on FakeNetworkPipe. Added functionality on the FakeNetworkPipe to introduce arbitrary clock offsets. This offset is added to the reported receive time of all packets. This prepares for a later CL using this to test correction of receive time stamps. Bug: webrtc:9054 Change-Id: I811b3aa8359bc917f59443088d8a418368242db9 Reviewed-on: https://webrtc-review.googlesource.com/64726 Reviewed-by: Stefan Holmer Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#22763} --- call/fake_network_pipe.cc | 8 ++++++++ call/fake_network_pipe.h | 4 ++++ test/direct_transport.cc | 4 ++++ test/direct_transport.h | 2 ++ 4 files changed, 18 insertions(+) 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();