From 19f51434e84589a8065fb9b20f059ff6b52dd853 Mon Sep 17 00:00:00 2001 From: philipel Date: Thu, 7 Sep 2017 09:08:50 -0700 Subject: [PATCH] Keep track of the capacity delay error in the FakeNetworkPipe. The FakeNetworkPipe use millisecond precision to calculate the delay induced by the size of the packet being sent. The problem is that it rounds the delay down to the closest millisecond which can cause a significant error in the actual throughput. We keep track of that error to compensate the delay cause by subsequent packets. BUG=None Review-Url: https://codereview.webrtc.org/3010653002 Cr-Commit-Position: refs/heads/master@{#19732} --- webrtc/test/fake_network_pipe.cc | 12 ++++++++++-- webrtc/test/fake_network_pipe.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/webrtc/test/fake_network_pipe.cc b/webrtc/test/fake_network_pipe.cc index bb9d6b1322..61ac91858c 100644 --- a/webrtc/test/fake_network_pipe.cc +++ b/webrtc/test/fake_network_pipe.cc @@ -132,8 +132,16 @@ void FakeNetworkPipe::SendPacket(const uint8_t* data, size_t data_length) { // Delay introduced by the link capacity. int64_t capacity_delay_ms = 0; - if (config_.link_capacity_kbps > 0) - capacity_delay_ms = data_length / (config_.link_capacity_kbps / 8); + if (config_.link_capacity_kbps > 0) { + const int bytes_per_millisecond = config_.link_capacity_kbps / 8; + // To round to the closest millisecond we add half a milliseconds worth of + // bytes to the delay calculation. + capacity_delay_ms = (data_length + capacity_delay_error_bytes_ + + bytes_per_millisecond / 2) / + bytes_per_millisecond; + capacity_delay_error_bytes_ += + data_length - capacity_delay_ms * bytes_per_millisecond; + } int64_t network_start_time = time_now; // Check if there already are packets on the link and change network start diff --git a/webrtc/test/fake_network_pipe.h b/webrtc/test/fake_network_pipe.h index 039cc84de8..d7e0c5d9c2 100644 --- a/webrtc/test/fake_network_pipe.h +++ b/webrtc/test/fake_network_pipe.h @@ -176,6 +176,8 @@ class FakeNetworkPipe { int64_t last_log_time_; + int64_t capacity_delay_error_bytes_ = 0; + RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe); };