Using Clock::CurrentTime() where non-test behavior is unchanged.

This CL replaces all uses of Timestamp::us(Clock::TimeInMicroseconds())
with Clock::CurrentTime() which should be a no-op apart from slight
changes in checks.

Additionally instances of Timestamp::ms(Clock::TimeInMilliseconds()) in
test code is replaced. This slightly changes the behavior since the
timestamp will get increased resolution.

Timestamp::ms(Clock::TimeInMilliseconds()) in non-test code is untouched
to avoid changing behavior of production code.

Bug: webrtc:9883
Change-Id: I8047f4cb2ca735f44f11d32f9367aa3eb376ec04
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/142803
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28321}
This commit is contained in:
Sebastian Jansson
2019-06-19 09:39:34 +02:00
committed by Commit Bot
parent 18f1f0c1f5
commit b64ad0e72c
11 changed files with 18 additions and 20 deletions

View File

@ -60,9 +60,8 @@ void UpdateRateControl(const AimdRateControlStates& states,
states.aimd_rate_control->Update(&input, Timestamp::ms(now_ms));
}
void SetEstimate(const AimdRateControlStates& states, int bitrate_bps) {
states.aimd_rate_control->SetEstimate(
DataRate::bps(bitrate_bps),
Timestamp::ms(states.simulated_clock->TimeInMilliseconds()));
states.aimd_rate_control->SetEstimate(DataRate::bps(bitrate_bps),
states.simulated_clock->CurrentTime());
}
} // namespace

View File

@ -640,7 +640,7 @@ std::string DefaultVideoQualityAnalyzer::GetTestCaseName(
}
Timestamp DefaultVideoQualityAnalyzer::Now() {
return Timestamp::us(clock_->TimeInMicroseconds());
return clock_->CurrentTime();
}
DefaultVideoQualityAnalyzer::FrameStats::FrameStats(std::string stream_label,

View File

@ -946,7 +946,7 @@ test::VideoFrameWriter* PeerConnectionE2EQualityTest::MaybeCreateVideoWriter(
}
Timestamp PeerConnectionE2EQualityTest::Now() const {
return Timestamp::us(clock_->TimeInMicroseconds());
return clock_->CurrentTime();
}
PeerConnectionE2EQualityTest::ScheduledActivity::ScheduledActivity(

View File

@ -86,7 +86,7 @@ void FakeNetworkSocketServer::WakeUp() {
}
Timestamp FakeNetworkSocketServer::Now() const {
return Timestamp::us(clock_->TimeInMicroseconds());
return clock_->CurrentTime();
}
} // namespace test

View File

@ -28,7 +28,7 @@ FeedbackGeneratorImpl::FeedbackGeneratorImpl(
{net_.CreateEmulatedNode(absl::WrapUnique(ret_link_))})) {}
Timestamp FeedbackGeneratorImpl::Now() {
return Timestamp::ms(time_controller_.GetClock()->TimeInMilliseconds());
return time_controller_.GetClock()->CurrentTime();
}
void FeedbackGeneratorImpl::Sleep(TimeDelta duration) {

View File

@ -54,13 +54,13 @@ void LinkEmulation::HandlePacketReceived(EmulatedIpPacket packet) {
network_behavior_->NextDeliveryTimeUs();
if (!next_time_us)
return;
Timestamp current_time = Timestamp::us(clock_->TimeInMicroseconds());
Timestamp current_time = clock_->CurrentTime();
process_task_ = RepeatingTaskHandle::DelayedStart(
task_queue_->Get(),
std::max(TimeDelta::Zero(), Timestamp::us(*next_time_us) - current_time),
[this]() {
RTC_DCHECK_RUN_ON(task_queue_);
Timestamp current_time = Timestamp::us(clock_->TimeInMicroseconds());
Timestamp current_time = clock_->CurrentTime();
Process(current_time);
absl::optional<int64_t> next_time_us =
network_behavior_->NextDeliveryTimeUs();
@ -207,8 +207,8 @@ void EmulatedEndpoint::SendPacket(const rtc::SocketAddress& from,
EmulatedIpPacket packet;
};
task_queue_->PostTask(Closure{
this, EmulatedIpPacket(from, to, std::move(packet),
Timestamp::us(clock_->TimeInMicroseconds()))});
this,
EmulatedIpPacket(from, to, std::move(packet), clock_->CurrentTime())});
}
absl::optional<uint16_t> EmulatedEndpoint::BindReceiver(
@ -310,7 +310,7 @@ EmulatedNetworkStats EmulatedEndpoint::stats() {
void EmulatedEndpoint::UpdateSendStats(const EmulatedIpPacket& packet) {
RTC_DCHECK_RUN_ON(task_queue_);
Timestamp current_time = Timestamp::us(clock_->TimeInMicroseconds());
Timestamp current_time = clock_->CurrentTime();
if (stats_.first_packet_sent_time.IsInfinite()) {
stats_.first_packet_sent_time = current_time;
stats_.first_sent_packet_size = DataSize::bytes(packet.size());
@ -322,7 +322,7 @@ void EmulatedEndpoint::UpdateSendStats(const EmulatedIpPacket& packet) {
void EmulatedEndpoint::UpdateReceiveStats(const EmulatedIpPacket& packet) {
RTC_DCHECK_RUN_ON(task_queue_);
Timestamp current_time = Timestamp::us(clock_->TimeInMicroseconds());
Timestamp current_time = clock_->CurrentTime();
if (stats_.first_packet_received_time.IsInfinite()) {
stats_.first_packet_received_time = current_time;
stats_.first_received_packet_size = DataSize::bytes(packet.size());

View File

@ -289,7 +289,7 @@ NetworkEmulationManagerImpl::GetNextIPv4Address() {
}
Timestamp NetworkEmulationManagerImpl::Now() const {
return Timestamp::us(clock_->TimeInMicroseconds());
return clock_->CurrentTime();
}
} // namespace test

View File

@ -89,8 +89,7 @@ void TrafficRoute::SendPacket(size_t packet_size, uint16_t dest_port) {
receiver_->OnPacketReceived(EmulatedIpPacket(
/*from=*/rtc::SocketAddress(),
rtc::SocketAddress(endpoint_->GetPeerLocalAddress(), dest_port),
rtc::CopyOnWriteBuffer(packet_size),
Timestamp::us(clock_->TimeInMicroseconds())));
rtc::CopyOnWriteBuffer(packet_size), clock_->CurrentTime()));
}
} // namespace test

View File

@ -98,7 +98,7 @@ bool NetworkNodeTransport::SendRtp(const uint8_t* packet,
bool NetworkNodeTransport::SendRtcp(const uint8_t* packet, size_t length) {
rtc::CopyOnWriteBuffer buffer(packet, length);
Timestamp send_time = Timestamp::ms(sender_clock_->TimeInMilliseconds());
Timestamp send_time = sender_clock_->CurrentTime();
rtc::CritScope crit(&crit_sect_);
buffer.SetSize(length + packet_overhead_.bytes());
if (!send_net_)

View File

@ -292,7 +292,7 @@ void Scenario::RunUntil(TimeDelta target_time_since_start,
}
void Scenario::Start() {
start_time_ = Timestamp::us(clock_->TimeInMicroseconds());
start_time_ = clock_->CurrentTime();
for (auto& stream_pair : video_streams_)
stream_pair->receive()->Start();
for (auto& stream_pair : audio_streams_)
@ -324,7 +324,7 @@ void Scenario::Stop() {
}
Timestamp Scenario::Now() {
return Timestamp::us(clock_->TimeInMicroseconds());
return clock_->CurrentTime();
}
TimeDelta Scenario::TimeSinceStart() {

View File

@ -135,7 +135,7 @@ ForwardingCapturedFrameTap::~ForwardingCapturedFrameTap() {}
void ForwardingCapturedFrameTap::OnFrame(const VideoFrame& frame) {
RTC_CHECK(sink_);
matcher_->OnCapturedFrame(frame, Timestamp::ms(clock_->TimeInMilliseconds()));
matcher_->OnCapturedFrame(frame, clock_->CurrentTime());
sink_->OnFrame(frame);
}
void ForwardingCapturedFrameTap::OnDiscardedFrame() {