Nuke TickTime::UseFakeClock.
Removes the global simulated time that affects (or breaks) following
tests in the same binary and replaces it with SimulatedClock.
BUG=webrtc:5318
R=mflodman@webrtc.org
Review URL: https://codereview.webrtc.org/1512853002 .
Cr-Commit-Position: refs/heads/master@{#10947}
diff --git a/webrtc/audio/audio_send_stream_unittest.cc b/webrtc/audio/audio_send_stream_unittest.cc
index f907575..be1f8c5 100644
--- a/webrtc/audio/audio_send_stream_unittest.cc
+++ b/webrtc/audio/audio_send_stream_unittest.cc
@@ -52,6 +52,7 @@
struct ConfigHelper {
ConfigHelper()
: stream_config_(nullptr),
+ call_stats_(Clock::GetRealTimeClock()),
process_thread_(ProcessThread::Create("AudioTestThread")),
congestion_controller_(process_thread_.get(),
&call_stats_,
diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc
index f6efa6d..28f1315 100644
--- a/webrtc/call/call.cc
+++ b/webrtc/call/call.cc
@@ -117,7 +117,7 @@
void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_);
void UpdateReceiveHistograms();
- const Clock* const clock_;
+ Clock* const clock_;
const int num_cpu_cores_;
const rtc::scoped_ptr<ProcessThread> module_process_thread_;
@@ -182,7 +182,7 @@
: clock_(Clock::GetRealTimeClock()),
num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
- call_stats_(new CallStats()),
+ call_stats_(new CallStats(clock_)),
bitrate_allocator_(new BitrateAllocator()),
config_(config),
network_enabled_(true),
diff --git a/webrtc/call/congestion_controller.cc b/webrtc/call/congestion_controller.cc
index 18c880c..d2f9c63 100644
--- a/webrtc/call/congestion_controller.cc
+++ b/webrtc/call/congestion_controller.cc
@@ -147,7 +147,7 @@
CongestionController::CongestionController(ProcessThread* process_thread,
CallStats* call_stats,
BitrateObserver* bitrate_observer)
- : remb_(new VieRemb()),
+ : remb_(new VieRemb(Clock::GetRealTimeClock())),
packet_router_(new PacketRouter()),
pacer_(new PacedSender(Clock::GetRealTimeClock(),
packet_router_.get(),
diff --git a/webrtc/system_wrappers/include/tick_util.h b/webrtc/system_wrappers/include/tick_util.h
index f8a5ef7..52f9b4a 100644
--- a/webrtc/system_wrappers/include/tick_util.h
+++ b/webrtc/system_wrappers/include/tick_util.h
@@ -65,19 +65,9 @@
// Returns a TickInterval that is the difference in ticks beween rhs and lhs.
friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs);
- // Call to engage the fake clock. This is useful for tests since relying on
- // a real clock often makes the test flaky.
- static void UseFakeClock(int64_t start_millisecond);
-
- // Advance the fake clock. Must be called after UseFakeClock.
- static void AdvanceFakeClock(int64_t milliseconds);
-
private:
static int64_t QueryOsForTicks();
- static bool use_fake_clock_;
- static int64_t fake_ticks_;
-
int64_t ticks_;
};
@@ -166,10 +156,7 @@
}
inline TickTime TickTime::Now() {
- if (use_fake_clock_)
- return TickTime(fake_ticks_);
- else
- return TickTime(QueryOsForTicks());
+ return TickTime(QueryOsForTicks());
}
inline int64_t TickTime::Ticks() const {
diff --git a/webrtc/system_wrappers/source/tick_util.cc b/webrtc/system_wrappers/source/tick_util.cc
index cae817d..8d94289 100644
--- a/webrtc/system_wrappers/source/tick_util.cc
+++ b/webrtc/system_wrappers/source/tick_util.cc
@@ -14,9 +14,6 @@
namespace webrtc {
-bool TickTime::use_fake_clock_ = false;
-int64_t TickTime::fake_ticks_ = 0;
-
int64_t TickTime::MillisecondTimestamp() {
return TicksToMilliseconds(TickTime::Now().Ticks());
}
@@ -82,16 +79,6 @@
#endif
}
-void TickTime::UseFakeClock(int64_t start_millisecond) {
- use_fake_clock_ = true;
- fake_ticks_ = MillisecondsToTicks(start_millisecond);
-}
-
-void TickTime::AdvanceFakeClock(int64_t milliseconds) {
- assert(use_fake_clock_);
- fake_ticks_ += MillisecondsToTicks(milliseconds);
-}
-
// Gets the native system tick count. The actual unit, resolution, and epoch
// varies by platform:
// Windows: Milliseconds of uptime with rollover count in the upper 32-bits.
diff --git a/webrtc/test/direct_transport.cc b/webrtc/test/direct_transport.cc
index b5c5f81..88fee35 100644
--- a/webrtc/test/direct_transport.cc
+++ b/webrtc/test/direct_transport.cc
@@ -27,7 +27,7 @@
thread_(NetworkProcess, this, "NetworkProcess"),
clock_(Clock::GetRealTimeClock()),
shutting_down_(false),
- fake_network_(config) {
+ fake_network_(clock_, config) {
thread_.Start();
}
diff --git a/webrtc/test/fake_network_pipe.cc b/webrtc/test/fake_network_pipe.cc
index c360593..4e43122 100644
--- a/webrtc/test/fake_network_pipe.cc
+++ b/webrtc/test/fake_network_pipe.cc
@@ -16,7 +16,7 @@
#include <algorithm>
#include "webrtc/call.h"
-#include "webrtc/system_wrappers/include/tick_util.h"
+#include "webrtc/system_wrappers/include/clock.h"
namespace webrtc {
@@ -70,14 +70,15 @@
int64_t arrival_time_;
};
-FakeNetworkPipe::FakeNetworkPipe(const FakeNetworkPipe::Config& config)
- : packet_receiver_(NULL),
+FakeNetworkPipe::FakeNetworkPipe(Clock* clock,
+ const FakeNetworkPipe::Config& config)
+ : clock_(clock),
+ packet_receiver_(NULL),
config_(config),
dropped_packets_(0),
sent_packets_(0),
total_packet_delay_(0),
- next_process_time_(TickTime::MillisecondTimestamp()) {
-}
+ next_process_time_(clock_->TimeInMilliseconds()) {}
FakeNetworkPipe::~FakeNetworkPipe() {
while (!capacity_link_.empty()) {
@@ -112,7 +113,7 @@
return;
}
- int64_t time_now = TickTime::MillisecondTimestamp();
+ int64_t time_now = clock_->TimeInMilliseconds();
// Delay introduced by the link capacity.
int64_t capacity_delay_ms = 0;
@@ -149,7 +150,7 @@
}
void FakeNetworkPipe::Process() {
- int64_t time_now = TickTime::MillisecondTimestamp();
+ int64_t time_now = clock_->TimeInMilliseconds();
std::queue<NetworkPacket*> packets_to_deliver;
{
rtc::CritScope crit(&lock_);
@@ -210,8 +211,8 @@
const int64_t kDefaultProcessIntervalMs = 30;
if (capacity_link_.size() == 0 || delay_link_.size() == 0)
return kDefaultProcessIntervalMs;
- return std::max<int64_t>(
- next_process_time_ - TickTime::MillisecondTimestamp(), 0);
+ return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(),
+ 0);
}
} // namespace webrtc
diff --git a/webrtc/test/fake_network_pipe.h b/webrtc/test/fake_network_pipe.h
index 74189a5..33661c7 100644
--- a/webrtc/test/fake_network_pipe.h
+++ b/webrtc/test/fake_network_pipe.h
@@ -21,6 +21,7 @@
namespace webrtc {
+class Clock;
class CriticalSectionWrapper;
class NetworkPacket;
class PacketReceiver;
@@ -33,26 +34,20 @@
class FakeNetworkPipe {
public:
struct Config {
- Config()
- : queue_length_packets(0),
- queue_delay_ms(0),
- delay_standard_deviation_ms(0),
- link_capacity_kbps(0),
- loss_percent(0) {
- }
+ Config() {}
// Queue length in number of packets.
- size_t queue_length_packets;
+ size_t queue_length_packets = 0;
// Delay in addition to capacity induced delay.
- int queue_delay_ms;
+ int queue_delay_ms = 0;
// Standard deviation of the extra delay.
- int delay_standard_deviation_ms;
+ int delay_standard_deviation_ms = 0;
// Link capacity in kbps.
- int link_capacity_kbps;
+ int link_capacity_kbps = 0;
// Random packet loss.
- int loss_percent;
+ int loss_percent = 0;
};
- explicit FakeNetworkPipe(const FakeNetworkPipe::Config& config);
+ FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config);
~FakeNetworkPipe();
// Must not be called in parallel with SendPacket or Process.
@@ -76,6 +71,7 @@
size_t sent_packets() { return sent_packets_; }
private:
+ Clock* const clock_;
mutable rtc::CriticalSection lock_;
PacketReceiver* packet_receiver_;
std::queue<NetworkPacket*> capacity_link_;
diff --git a/webrtc/test/fake_network_pipe_unittest.cc b/webrtc/test/fake_network_pipe_unittest.cc
index 02438c5..ff18993 100644
--- a/webrtc/test/fake_network_pipe_unittest.cc
+++ b/webrtc/test/fake_network_pipe_unittest.cc
@@ -13,7 +13,7 @@
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/call.h"
-#include "webrtc/system_wrappers/include/tick_util.h"
+#include "webrtc/system_wrappers/include/clock.h"
#include "webrtc/test/fake_network_pipe.h"
using ::testing::_;
@@ -39,9 +39,11 @@
};
class FakeNetworkPipeTest : public ::testing::Test {
+ public:
+ FakeNetworkPipeTest() : fake_clock_(12345) {}
+
protected:
virtual void SetUp() {
- TickTime::UseFakeClock(12345);
receiver_.reset(new MockReceiver());
ON_CALL(*receiver_, DeliverPacket(_, _, _, _))
.WillByDefault(Return(PacketReceiver::DELIVERY_OK));
@@ -61,6 +63,7 @@
return 8 * kPacketSize / capacity_kbps;
}
+ SimulatedClock fake_clock_;
rtc::scoped_ptr<MockReceiver> receiver_;
};
@@ -71,7 +74,8 @@
FakeNetworkPipe::Config config;
config.queue_length_packets = 20;
config.link_capacity_kbps = 80;
- rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
+ rtc::scoped_ptr<FakeNetworkPipe> pipe(
+ new FakeNetworkPipe(&fake_clock_, config));
pipe->SetReceiver(receiver_.get());
// Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to
@@ -89,17 +93,17 @@
pipe->Process();
// Advance enough time to release one packet.
- TickTime::AdvanceFakeClock(kPacketTimeMs);
+ fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
pipe->Process();
// Release all but one packet
- TickTime::AdvanceFakeClock(9 * kPacketTimeMs - 1);
+ fake_clock_.AdvanceTimeMilliseconds(9 * kPacketTimeMs - 1);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(8);
pipe->Process();
// And the last one.
- TickTime::AdvanceFakeClock(1);
+ fake_clock_.AdvanceTimeMilliseconds(1);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
pipe->Process();
}
@@ -110,7 +114,8 @@
config.queue_length_packets = 20;
config.queue_delay_ms = 100;
config.link_capacity_kbps = 80;
- rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
+ rtc::scoped_ptr<FakeNetworkPipe> pipe(
+ new FakeNetworkPipe(&fake_clock_, config));
pipe->SetReceiver(receiver_.get());
const int kNumPackets = 2;
@@ -122,17 +127,17 @@
kPacketSize);
// Increase more than kPacketTimeMs, but not more than the extra delay.
- TickTime::AdvanceFakeClock(kPacketTimeMs);
+ fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
pipe->Process();
// Advance the network delay to get the first packet.
- TickTime::AdvanceFakeClock(config.queue_delay_ms);
+ fake_clock_.AdvanceTimeMilliseconds(config.queue_delay_ms);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
pipe->Process();
// Advance one more kPacketTimeMs to get the last packet.
- TickTime::AdvanceFakeClock(kPacketTimeMs);
+ fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
pipe->Process();
}
@@ -143,7 +148,8 @@
FakeNetworkPipe::Config config;
config.queue_length_packets = 2;
config.link_capacity_kbps = 80;
- rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
+ rtc::scoped_ptr<FakeNetworkPipe> pipe(
+ new FakeNetworkPipe(&fake_clock_, config));
pipe->SetReceiver(receiver_.get());
const int kPacketSize = 1000;
@@ -155,7 +161,7 @@
// Increase time enough to deliver all three packets, verify only two are
// delivered.
- TickTime::AdvanceFakeClock(3 * kPacketTimeMs);
+ fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2);
pipe->Process();
}
@@ -166,7 +172,8 @@
config.queue_length_packets = 2;
config.queue_delay_ms = 20;
config.link_capacity_kbps = 80;
- rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
+ rtc::scoped_ptr<FakeNetworkPipe> pipe(
+ new FakeNetworkPipe(&fake_clock_, config));
pipe->SetReceiver(receiver_.get());
const int kPacketSize = 1000;
@@ -175,7 +182,8 @@
// Send three packets and verify only 2 are delivered.
SendPackets(pipe.get(), 3, kPacketSize);
- TickTime::AdvanceFakeClock(3 * kPacketTimeMs + config.queue_delay_ms);
+ fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs +
+ config.queue_delay_ms);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2);
pipe->Process();
@@ -194,7 +202,8 @@
FakeNetworkPipe::Config config;
config.queue_length_packets = 20;
config.link_capacity_kbps = 80;
- rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
+ rtc::scoped_ptr<FakeNetworkPipe> pipe(
+ new FakeNetworkPipe(&fake_clock_, config));
pipe->SetReceiver(receiver_.get());
// Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to
@@ -212,7 +221,7 @@
// Advance time in steps to release one packet at a time.
for (int i = 0; i < kNumPackets; ++i) {
- TickTime::AdvanceFakeClock(packet_time_ms);
+ fake_clock_.AdvanceTimeMilliseconds(packet_time_ms);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
pipe->Process();
}
@@ -234,14 +243,14 @@
// Advance time in steps to release one packet at a time.
for (int i = 0; i < kNumPackets; ++i) {
- TickTime::AdvanceFakeClock(packet_time_ms);
+ fake_clock_.AdvanceTimeMilliseconds(packet_time_ms);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
pipe->Process();
}
// Check that all the packets were sent.
EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets());
- TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess());
+ fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess());
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
pipe->Process();
}
@@ -252,7 +261,8 @@
FakeNetworkPipe::Config config;
config.queue_length_packets = 20;
config.link_capacity_kbps = 80;
- rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
+ rtc::scoped_ptr<FakeNetworkPipe> pipe(
+ new FakeNetworkPipe(&fake_clock_, config));
pipe->SetReceiver(receiver_.get());
// Add 10 packets of 1000 bytes, = 80 kb.
@@ -280,21 +290,21 @@
// Advance time in steps to release one packet at a time.
for (int i = 0; i < kNumPackets; ++i) {
- TickTime::AdvanceFakeClock(packet_time_1_ms);
+ fake_clock_.AdvanceTimeMilliseconds(packet_time_1_ms);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
pipe->Process();
}
// Advance time in steps to release one packet at a time.
for (int i = 0; i < kNumPackets; ++i) {
- TickTime::AdvanceFakeClock(packet_time_2_ms);
+ fake_clock_.AdvanceTimeMilliseconds(packet_time_2_ms);
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
pipe->Process();
}
// Check that all the packets were sent.
EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets());
- TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess());
+ fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess());
EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
pipe->Process();
}
diff --git a/webrtc/video_engine/call_stats.cc b/webrtc/video_engine/call_stats.cc
index 4d5338c..2b87d7e 100644
--- a/webrtc/video_engine/call_stats.cc
+++ b/webrtc/video_engine/call_stats.cc
@@ -89,26 +89,25 @@
RTC_DISALLOW_COPY_AND_ASSIGN(RtcpObserver);
};
-CallStats::CallStats()
- : crit_(CriticalSectionWrapper::CreateCriticalSection()),
+CallStats::CallStats(Clock* clock)
+ : clock_(clock),
+ crit_(CriticalSectionWrapper::CreateCriticalSection()),
rtcp_rtt_stats_(new RtcpObserver(this)),
- last_process_time_(TickTime::MillisecondTimestamp()),
+ last_process_time_(clock_->TimeInMilliseconds()),
max_rtt_ms_(0),
- avg_rtt_ms_(0) {
-}
+ avg_rtt_ms_(0) {}
CallStats::~CallStats() {
assert(observers_.empty());
}
int64_t CallStats::TimeUntilNextProcess() {
- return last_process_time_ + kUpdateIntervalMs -
- TickTime::MillisecondTimestamp();
+ return last_process_time_ + kUpdateIntervalMs - clock_->TimeInMilliseconds();
}
int32_t CallStats::Process() {
CriticalSectionScoped cs(crit_.get());
- int64_t now = TickTime::MillisecondTimestamp();
+ int64_t now = clock_->TimeInMilliseconds();
if (now < last_process_time_ + kUpdateIntervalMs)
return 0;
@@ -161,7 +160,7 @@
void CallStats::OnRttUpdate(int64_t rtt) {
CriticalSectionScoped cs(crit_.get());
- reports_.push_back(RttTime(rtt, TickTime::MillisecondTimestamp()));
+ reports_.push_back(RttTime(rtt, clock_->TimeInMilliseconds()));
}
} // namespace webrtc
diff --git a/webrtc/video_engine/call_stats.h b/webrtc/video_engine/call_stats.h
index d0a0b53..0dd7bdb 100644
--- a/webrtc/video_engine/call_stats.h
+++ b/webrtc/video_engine/call_stats.h
@@ -16,6 +16,7 @@
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/include/module.h"
+#include "webrtc/system_wrappers/include/clock.h"
namespace webrtc {
@@ -28,7 +29,7 @@
public:
friend class RtcpObserver;
- CallStats();
+ explicit CallStats(Clock* clock);
~CallStats();
// Implements Module, to use the process thread.
@@ -57,6 +58,7 @@
int64_t avg_rtt_ms() const;
private:
+ Clock* const clock_;
// Protecting all members.
rtc::scoped_ptr<CriticalSectionWrapper> crit_;
// Observer receiving statistics updates.
diff --git a/webrtc/video_engine/call_stats_unittest.cc b/webrtc/video_engine/call_stats_unittest.cc
index bfba5cb..ec7e856 100644
--- a/webrtc/video_engine/call_stats_unittest.cc
+++ b/webrtc/video_engine/call_stats_unittest.cc
@@ -31,11 +31,12 @@
};
class CallStatsTest : public ::testing::Test {
+ public:
+ CallStatsTest() : fake_clock_(12345) {}
+
protected:
- virtual void SetUp() {
- TickTime::UseFakeClock(12345);
- call_stats_.reset(new CallStats());
- }
+ virtual void SetUp() { call_stats_.reset(new CallStats(&fake_clock_)); }
+ SimulatedClock fake_clock_;
rtc::scoped_ptr<CallStats> call_stats_;
};
@@ -43,7 +44,7 @@
MockStatsObserver stats_observer;
RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats();
call_stats_->RegisterStatsObserver(&stats_observer);
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_EQ(0, rtcp_rtt_stats->LastProcessedRtt());
const int64_t kRtt = 25;
@@ -53,7 +54,7 @@
EXPECT_EQ(kRtt, rtcp_rtt_stats->LastProcessedRtt());
const int64_t kRttTimeOutMs = 1500 + 10;
- TickTime::AdvanceFakeClock(kRttTimeOutMs);
+ fake_clock_.AdvanceTimeMilliseconds(kRttTimeOutMs);
EXPECT_CALL(stats_observer, OnRttUpdate(_, _)).Times(0);
call_stats_->Process();
EXPECT_EQ(0, rtcp_rtt_stats->LastProcessedRtt());
@@ -72,18 +73,18 @@
call_stats_->Process();
// Advance clock and verify we get an update.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(stats_observer, OnRttUpdate(_, _)).Times(1);
call_stats_->Process();
// Advance clock just too little to get an update.
- TickTime::AdvanceFakeClock(999);
+ fake_clock_.AdvanceTimeMilliseconds(999);
rtcp_rtt_stats->OnRttUpdate(100);
EXPECT_CALL(stats_observer, OnRttUpdate(_, _)).Times(0);
call_stats_->Process();
// Advance enough to trigger a new update.
- TickTime::AdvanceFakeClock(1);
+ fake_clock_.AdvanceTimeMilliseconds(1);
EXPECT_CALL(stats_observer, OnRttUpdate(_, _)).Times(1);
call_stats_->Process();
@@ -106,7 +107,7 @@
rtcp_rtt_stats->OnRttUpdate(kRtt);
// Verify both observers are updated.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)).Times(1);
EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)).Times(1);
call_stats_->Process();
@@ -115,7 +116,7 @@
// observer.
call_stats_->DeregisterStatsObserver(&stats_observer_2);
rtcp_rtt_stats->OnRttUpdate(kRtt);
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)).Times(1);
EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)).Times(0);
call_stats_->Process();
@@ -123,7 +124,7 @@
// Deregister the first observer.
call_stats_->DeregisterStatsObserver(&stats_observer_1);
rtcp_rtt_stats->OnRttUpdate(kRtt);
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)).Times(0);
EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)).Times(0);
call_stats_->Process();
@@ -136,7 +137,7 @@
RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats();
// Advance clock to be ready for an update.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
// Set a first value and verify the callback is triggered.
const int64_t kFirstRtt = 100;
@@ -145,7 +146,7 @@
call_stats_->Process();
// Increase rtt and verify the new value is reported.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
const int64_t kHighRtt = kFirstRtt + 20;
const int64_t kAvgRtt1 = 103;
rtcp_rtt_stats->OnRttUpdate(kHighRtt);
@@ -155,7 +156,7 @@
// Increase time enough for a new update, but not too much to make the
// rtt invalid. Report a lower rtt and verify the old/high value still is sent
// in the callback.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
const int64_t kLowRtt = kFirstRtt - 20;
const int64_t kAvgRtt2 = 102;
rtcp_rtt_stats->OnRttUpdate(kLowRtt);
@@ -164,7 +165,7 @@
// Advance time to make the high report invalid, the lower rtt should now be
// in the callback.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
const int64_t kAvgRtt3 = 95;
EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt3, kLowRtt)).Times(1);
call_stats_->Process();
@@ -176,7 +177,7 @@
MockStatsObserver stats_observer;
call_stats_->RegisterStatsObserver(&stats_observer);
RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats();
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
// Set a first values and verify that LastProcessedRtt initially returns the
// average rtt.
@@ -190,7 +191,7 @@
EXPECT_EQ(kAvgRtt, rtcp_rtt_stats->LastProcessedRtt());
// Update values and verify LastProcessedRtt.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
rtcp_rtt_stats->OnRttUpdate(kRttLow);
rtcp_rtt_stats->OnRttUpdate(kRttHigh);
EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt, kRttHigh)).Times(1);
diff --git a/webrtc/video_engine/vie_remb.cc b/webrtc/video_engine/vie_remb.cc
index 3901d6d..de9b8c4 100644
--- a/webrtc/video_engine/vie_remb.cc
+++ b/webrtc/video_engine/vie_remb.cc
@@ -27,9 +27,10 @@
// % threshold for if we should send a new REMB asap.
const unsigned int kSendThresholdPercent = 97;
-VieRemb::VieRemb()
- : list_crit_(CriticalSectionWrapper::CreateCriticalSection()),
- last_remb_time_(TickTime::MillisecondTimestamp()),
+VieRemb::VieRemb(Clock* clock)
+ : clock_(clock),
+ list_crit_(CriticalSectionWrapper::CreateCriticalSection()),
+ last_remb_time_(clock_->TimeInMilliseconds()),
last_send_bitrate_(0),
bitrate_(0) {}
@@ -105,13 +106,13 @@
if (new_remb_bitrate < kSendThresholdPercent * last_send_bitrate_ / 100) {
// The new bitrate estimate is less than kSendThresholdPercent % of the
// last report. Send a REMB asap.
- last_remb_time_ = TickTime::MillisecondTimestamp() - kRembSendIntervalMs;
+ last_remb_time_ = clock_->TimeInMilliseconds() - kRembSendIntervalMs;
}
}
bitrate_ = bitrate;
// Calculate total receive bitrate estimate.
- int64_t now = TickTime::MillisecondTimestamp();
+ int64_t now = clock_->TimeInMilliseconds();
if (now - last_remb_time_ < kRembSendIntervalMs) {
list_crit_->Leave();
diff --git a/webrtc/video_engine/vie_remb.h b/webrtc/video_engine/vie_remb.h
index 6a79ffe..3275951 100644
--- a/webrtc/video_engine/vie_remb.h
+++ b/webrtc/video_engine/vie_remb.h
@@ -28,7 +28,7 @@
class VieRemb : public RemoteBitrateObserver {
public:
- VieRemb();
+ explicit VieRemb(Clock* clock);
~VieRemb();
// Called to add a receive channel to include in the REMB packet.
@@ -57,6 +57,7 @@
private:
typedef std::list<RtpRtcp*> RtpModules;
+ Clock* const clock_;
rtc::scoped_ptr<CriticalSectionWrapper> list_crit_;
// The last time a REMB was sent.
diff --git a/webrtc/video_engine/vie_remb_unittest.cc b/webrtc/video_engine/vie_remb_unittest.cc
index f319d0d..bde3274 100644
--- a/webrtc/video_engine/vie_remb_unittest.cc
+++ b/webrtc/video_engine/vie_remb_unittest.cc
@@ -30,12 +30,15 @@
namespace webrtc {
class ViERembTest : public ::testing::Test {
+ public:
+ ViERembTest() : fake_clock_(12345) {}
+
protected:
virtual void SetUp() {
- TickTime::UseFakeClock(12345);
process_thread_.reset(new NiceMock<MockProcessThread>);
- vie_remb_.reset(new VieRemb());
+ vie_remb_.reset(new VieRemb(&fake_clock_));
}
+ SimulatedClock fake_clock_;
rtc::scoped_ptr<MockProcessThread> process_thread_;
rtc::scoped_ptr<VieRemb> vie_remb_;
};
@@ -51,7 +54,7 @@
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs))
.Times(1);
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
@@ -76,7 +79,7 @@
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
// Call OnReceiveBitrateChanged twice to get a first estimate.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs))
.Times(1);
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
@@ -105,7 +108,7 @@
// Call OnReceiveBitrateChanged twice to get a first estimate.
EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate[0], ssrcs))
.Times(1);
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100);
@@ -133,7 +136,7 @@
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
// Call OnReceiveBitrateChanged twice to get a first estimate.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate, ssrcs))
.Times(1);
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
@@ -167,7 +170,7 @@
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
// Call OnReceiveBitrateChanged twice to get a first estimate.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate, ssrcs))
.Times(1);
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
@@ -203,7 +206,7 @@
vie_remb_->AddRembSender(&rtp);
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
// Call OnReceiveBitrateChanged twice to get a first estimate.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(rtp, SetREMBData(_, _))
.Times(1);
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
@@ -235,7 +238,7 @@
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
// Call OnReceiveBitrateChanged twice to get a first estimate.
- TickTime::AdvanceFakeClock(1000);
+ fake_clock_.AdvanceTimeMilliseconds(1000);
EXPECT_CALL(rtp, SetREMBData(_, _))
.Times(1);
vie_remb_->OnReceiveBitrateChanged(ssrcs, bitrate_estimate);