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}
diff --git a/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc b/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc
index caaafa8..4a0de0d 100644
--- a/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc
+++ b/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc
@@ -60,9 +60,8 @@
   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
diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc
index ce28533..da8d505 100644
--- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc
+++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc
@@ -640,7 +640,7 @@
 }
 
 Timestamp DefaultVideoQualityAnalyzer::Now() {
-  return Timestamp::us(clock_->TimeInMicroseconds());
+  return clock_->CurrentTime();
 }
 
 DefaultVideoQualityAnalyzer::FrameStats::FrameStats(std::string stream_label,
diff --git a/test/pc/e2e/peer_connection_quality_test.cc b/test/pc/e2e/peer_connection_quality_test.cc
index 02fc914..944790e 100644
--- a/test/pc/e2e/peer_connection_quality_test.cc
+++ b/test/pc/e2e/peer_connection_quality_test.cc
@@ -946,7 +946,7 @@
 }
 
 Timestamp PeerConnectionE2EQualityTest::Now() const {
-  return Timestamp::us(clock_->TimeInMicroseconds());
+  return clock_->CurrentTime();
 }
 
 PeerConnectionE2EQualityTest::ScheduledActivity::ScheduledActivity(
diff --git a/test/scenario/network/fake_network_socket_server.cc b/test/scenario/network/fake_network_socket_server.cc
index fd6bc75..407f760 100644
--- a/test/scenario/network/fake_network_socket_server.cc
+++ b/test/scenario/network/fake_network_socket_server.cc
@@ -86,7 +86,7 @@
 }
 
 Timestamp FakeNetworkSocketServer::Now() const {
-  return Timestamp::us(clock_->TimeInMicroseconds());
+  return clock_->CurrentTime();
 }
 
 }  // namespace test
diff --git a/test/scenario/network/feedback_generator.cc b/test/scenario/network/feedback_generator.cc
index 9e96805..9512c47 100644
--- a/test/scenario/network/feedback_generator.cc
+++ b/test/scenario/network/feedback_generator.cc
@@ -28,7 +28,7 @@
                  {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) {
diff --git a/test/scenario/network/network_emulation.cc b/test/scenario/network/network_emulation.cc
index 194cf98..cb611e2 100644
--- a/test/scenario/network/network_emulation.cc
+++ b/test/scenario/network/network_emulation.cc
@@ -54,13 +54,13 @@
       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 @@
     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 @@
 
 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::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());
diff --git a/test/scenario/network/network_emulation_manager.cc b/test/scenario/network/network_emulation_manager.cc
index d85a6ff..8900ec4 100644
--- a/test/scenario/network/network_emulation_manager.cc
+++ b/test/scenario/network/network_emulation_manager.cc
@@ -289,7 +289,7 @@
 }
 
 Timestamp NetworkEmulationManagerImpl::Now() const {
-  return Timestamp::us(clock_->TimeInMicroseconds());
+  return clock_->CurrentTime();
 }
 
 }  // namespace test
diff --git a/test/scenario/network/traffic_route.cc b/test/scenario/network/traffic_route.cc
index 6727a24..7ede034 100644
--- a/test/scenario/network/traffic_route.cc
+++ b/test/scenario/network/traffic_route.cc
@@ -89,8 +89,7 @@
   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
diff --git a/test/scenario/network_node.cc b/test/scenario/network_node.cc
index e8b7646..1fc9655 100644
--- a/test/scenario/network_node.cc
+++ b/test/scenario/network_node.cc
@@ -98,7 +98,7 @@
 
 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_)
diff --git a/test/scenario/scenario.cc b/test/scenario/scenario.cc
index b430ea1..1845577 100644
--- a/test/scenario/scenario.cc
+++ b/test/scenario/scenario.cc
@@ -292,7 +292,7 @@
 }
 
 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 @@
 }
 
 Timestamp Scenario::Now() {
-  return Timestamp::us(clock_->TimeInMicroseconds());
+  return clock_->CurrentTime();
 }
 
 TimeDelta Scenario::TimeSinceStart() {
diff --git a/test/scenario/video_frame_matcher.cc b/test/scenario/video_frame_matcher.cc
index 1a5d4b4..98e276c 100644
--- a/test/scenario/video_frame_matcher.cc
+++ b/test/scenario/video_frame_matcher.cc
@@ -135,7 +135,7 @@
 
 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() {