diff --git a/api/video_codecs/test/video_encoder_software_fallback_wrapper_unittest.cc b/api/video_codecs/test/video_encoder_software_fallback_wrapper_unittest.cc index 2a382efbef..201afc8ac1 100644 --- a/api/video_codecs/test/video_encoder_software_fallback_wrapper_unittest.cc +++ b/api/video_codecs/test/video_encoder_software_fallback_wrapper_unittest.cc @@ -352,7 +352,7 @@ class ForcedFallbackTest : public VideoEncoderSoftwareFallbackWrapperTest { protected: void SetUp() override { - clock_.SetTimeMicros(1234); + clock_.SetTime(Timestamp::us(1234)); ConfigureVp8Codec(); } diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc b/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc index e8d69ea03c..3e34d47d60 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc +++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc @@ -741,7 +741,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpReceiverReport) { } rtc::ScopedFakeClock fake_clock; - fake_clock.SetTimeMicros(static_cast(prng_.Rand()) * 1000); + fake_clock.SetTime(Timestamp::ms(prng_.Rand())); for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); @@ -757,7 +757,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpReceiverReport) { history_.push_back( absl::make_unique(buffer)); } - fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); + fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000))); } std::string encoded = @@ -780,7 +780,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpSenderReport) { } rtc::ScopedFakeClock fake_clock; - fake_clock.SetTimeMicros(static_cast(prng_.Rand()) * 1000); + fake_clock.SetTime(Timestamp::ms(prng_.Rand())); for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); @@ -796,7 +796,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpSenderReport) { history_.push_back( absl::make_unique(buffer)); } - fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); + fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000))); } std::string encoded = @@ -819,7 +819,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpExtendedReports) { } rtc::ScopedFakeClock fake_clock; - fake_clock.SetTimeMicros(static_cast(prng_.Rand()) * 1000); + fake_clock.SetTime(Timestamp::ms(prng_.Rand())); for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); @@ -835,7 +835,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpExtendedReports) { history_.push_back( absl::make_unique(buffer)); } - fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); + fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000))); } std::string encoded = @@ -858,7 +858,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpFir) { } rtc::ScopedFakeClock fake_clock; - fake_clock.SetTimeMicros(static_cast(prng_.Rand()) * 1000); + fake_clock.SetTime(Timestamp::ms(prng_.Rand())); for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); @@ -874,7 +874,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpFir) { history_.push_back( absl::make_unique(buffer)); } - fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); + fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000))); } std::string encoded = @@ -896,7 +896,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPli) { } rtc::ScopedFakeClock fake_clock; - fake_clock.SetTimeMicros(static_cast(prng_.Rand()) * 1000); + fake_clock.SetTime(Timestamp::ms(prng_.Rand())); for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); @@ -912,7 +912,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPli) { history_.push_back( absl::make_unique(buffer)); } - fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); + fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000))); } std::string encoded = @@ -934,7 +934,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpNack) { } rtc::ScopedFakeClock fake_clock; - fake_clock.SetTimeMicros(static_cast(prng_.Rand()) * 1000); + fake_clock.SetTime(Timestamp::ms(prng_.Rand())); for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); @@ -950,7 +950,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpNack) { history_.push_back( absl::make_unique(buffer)); } - fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); + fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000))); } std::string encoded = @@ -972,7 +972,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpRemb) { } rtc::ScopedFakeClock fake_clock; - fake_clock.SetTimeMicros(static_cast(prng_.Rand()) * 1000); + fake_clock.SetTime(Timestamp::ms(prng_.Rand())); for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); @@ -988,7 +988,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpRemb) { history_.push_back( absl::make_unique(buffer)); } - fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); + fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000))); } std::string encoded = @@ -1010,7 +1010,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpTransportFeedback) { } rtc::ScopedFakeClock fake_clock; - fake_clock.SetTimeMicros(static_cast(prng_.Rand()) * 1000); + fake_clock.SetTime(Timestamp::ms(prng_.Rand())); for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events; @@ -1027,7 +1027,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpTransportFeedback) { history_.push_back( absl::make_unique(buffer)); } - fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); + fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000))); } std::string encoded = @@ -1051,7 +1051,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpLossNotification) { } rtc::ScopedFakeClock fake_clock; - fake_clock.SetTimeMicros(static_cast(prng_.Rand()) * 1000); + fake_clock.SetTime(Timestamp::ms(prng_.Rand())); for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events; @@ -1068,7 +1068,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpLossNotification) { history_.push_back( absl::make_unique(buffer)); } - fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); + fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000))); } std::string encoded = diff --git a/logging/rtc_event_log/rtc_event_log_unittest.cc b/logging/rtc_event_log/rtc_event_log_unittest.cc index 2c57220440..bdd588b0ab 100644 --- a/logging/rtc_event_log/rtc_event_log_unittest.cc +++ b/logging/rtc_event_log/rtc_event_log_unittest.cc @@ -113,7 +113,7 @@ class RtcEventLogSession encoding_type_(std::get<2>(GetParam())), gen_(seed_ * 880001UL), verifier_(encoding_type_) { - clock_.SetTimeMicros(prng_.Rand()); + clock_.SetTime(Timestamp::us(prng_.Rand())); // Find the name of the current test, in order to use it as a temporary // filename. // TODO(terelius): Use a general utility function to generate a temp file. @@ -215,7 +215,7 @@ void RtcEventLogSession::WriteAudioRecvConfigs(size_t audio_recv_streams, RTC_CHECK(event_log != nullptr); uint32_t ssrc; for (size_t i = 0; i < audio_recv_streams; i++) { - clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); + clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20))); do { ssrc = prng_.Rand(); } while (SsrcUsed(ssrc, incoming_extensions_)); @@ -232,7 +232,7 @@ void RtcEventLogSession::WriteAudioSendConfigs(size_t audio_send_streams, RTC_CHECK(event_log != nullptr); uint32_t ssrc; for (size_t i = 0; i < audio_send_streams; i++) { - clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); + clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20))); do { ssrc = prng_.Rand(); } while (SsrcUsed(ssrc, outgoing_extensions_)); @@ -254,14 +254,14 @@ void RtcEventLogSession::WriteVideoRecvConfigs(size_t video_recv_streams, RtpHeaderExtensionMap all_extensions = ParsedRtcEventLog::GetDefaultHeaderExtensionMap(); - clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); + clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20))); uint32_t ssrc = prng_.Rand(); incoming_extensions_.emplace_back(prng_.Rand(), all_extensions); auto event = gen_.NewVideoReceiveStreamConfig(ssrc, all_extensions); event_log->Log(event->Copy()); video_recv_config_list_.push_back(std::move(event)); for (size_t i = 1; i < video_recv_streams; i++) { - clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); + clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20))); do { ssrc = prng_.Rand(); } while (SsrcUsed(ssrc, incoming_extensions_)); @@ -283,14 +283,14 @@ void RtcEventLogSession::WriteVideoSendConfigs(size_t video_send_streams, RtpHeaderExtensionMap all_extensions = ParsedRtcEventLog::GetDefaultHeaderExtensionMap(); - clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); + clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20))); uint32_t ssrc = prng_.Rand(); outgoing_extensions_.emplace_back(prng_.Rand(), all_extensions); auto event = gen_.NewVideoSendStreamConfig(ssrc, all_extensions); event_log->Log(event->Copy()); video_send_config_list_.push_back(std::move(event)); for (size_t i = 1; i < video_send_streams; i++) { - clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); + clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20))); do { ssrc = prng_.Rand(); } while (SsrcUsed(ssrc, outgoing_extensions_)); @@ -327,7 +327,7 @@ void RtcEventLogSession::WriteLog(EventCounts count, size_t remaining_events_at_start = remaining_events - num_events_before_start; for (; remaining_events > 0; remaining_events--) { if (remaining_events == remaining_events_at_start) { - clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); + clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20))); event_log->StartLogging( absl::make_unique(temp_filename_, 10000000), output_period_ms_); @@ -335,7 +335,7 @@ void RtcEventLogSession::WriteLog(EventCounts count, utc_start_time_us_ = rtc::TimeUTCMicros(); } - clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); + clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20))); size_t selection = prng_.Rand(remaining_events - 1); first_timestamp_ms_ = std::min(first_timestamp_ms_, rtc::TimeMillis()); last_timestamp_ms_ = std::max(last_timestamp_ms_, rtc::TimeMillis()); @@ -814,7 +814,7 @@ TEST_P(RtcEventLogCircularBufferTest, KeepsMostRecentEvents) { // TODO(terelius): Maybe make a separate RtcEventLogImplTest that can access // the size of the cyclic buffer? constexpr size_t kNumEvents = 20000; - constexpr int64_t kStartTime = 1000000; + constexpr int64_t kStartTimeSeconds = 1; constexpr int32_t kStartBitrate = 1000000; auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); @@ -825,7 +825,7 @@ TEST_P(RtcEventLogCircularBufferTest, KeepsMostRecentEvents) { std::unique_ptr fake_clock = absl::make_unique(); - fake_clock->SetTimeMicros(kStartTime); + fake_clock->SetTime(Timestamp::seconds(kStartTimeSeconds)); auto task_queue_factory = CreateDefaultTaskQueueFactory(); RtcEventLogFactory rtc_event_log_factory(task_queue_factory.get()); @@ -843,14 +843,14 @@ TEST_P(RtcEventLogCircularBufferTest, KeepsMostRecentEvents) { // consistency checks when we read back. log_dumper->Log(absl::make_unique( i, kStartBitrate + i * 1000)); - fake_clock->AdvanceTimeMicros(10000); + fake_clock->AdvanceTime(TimeDelta::ms(10)); } int64_t start_time_us = rtc::TimeMicros(); int64_t utc_start_time_us = rtc::TimeUTCMicros(); log_dumper->StartLogging( absl::make_unique(temp_filename, 10000000), RtcEventLog::kImmediateOutput); - fake_clock->AdvanceTimeMicros(10000); + fake_clock->AdvanceTime(TimeDelta::ms(10)); int64_t stop_time_us = rtc::TimeMicros(); log_dumper->StopLogging(); @@ -883,9 +883,9 @@ TEST_P(RtcEventLogCircularBufferTest, KeepsMostRecentEvents) { // destroyed before the new one is created, so we have to reset() first. fake_clock.reset(); fake_clock = absl::make_unique(); - fake_clock->SetTimeMicros(first_timestamp_us); + fake_clock->SetTime(Timestamp::us(first_timestamp_us)); for (size_t i = 1; i < probe_success_events.size(); i++) { - fake_clock->AdvanceTimeMicros(10000); + fake_clock->AdvanceTime(TimeDelta::ms(10)); verifier_.VerifyLoggedBweProbeSuccessEvent( RtcEventProbeResultSuccess(first_id + i, first_bitrate_bps + i * 1000), probe_success_events[i]); diff --git a/media/engine/webrtc_video_engine_unittest.cc b/media/engine/webrtc_video_engine_unittest.cc index 2b5a01dd21..b6deb57a08 100644 --- a/media/engine/webrtc_video_engine_unittest.cc +++ b/media/engine/webrtc_video_engine_unittest.cc @@ -225,7 +225,7 @@ class WebRtcVideoEngineTest : public ::testing::Test { decoder_factory_)) { // Ensure fake clock doesn't return 0, which will cause some initializations // fail inside RTP senders. - fake_clock_.AdvanceTimeMicros(1); + fake_clock_.AdvanceTime(webrtc::TimeDelta::us(1)); } protected: @@ -3472,7 +3472,7 @@ TEST_F(WebRtcVideoChannelTest, EstimatesNtpStartTimeCorrectly) { // This timestamp is kInitialTimestamp (-1) + kFrameOffsetMs * 90, which // triggers a constant-overflow warning, hence we're calculating it explicitly // here. - fake_clock_.AdvanceTimeMicros(kFrameOffsetMs * rtc::kNumMicrosecsPerMillisec); + fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(kFrameOffsetMs)); video_frame.set_timestamp(kFrameOffsetMs * 90 - 1); video_frame.set_ntp_time_ms(kInitialNtpTimeMs + kFrameOffsetMs); stream->InjectFrame(video_frame); diff --git a/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc b/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc index b3b531fca3..008d8d631c 100644 --- a/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc +++ b/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc @@ -56,7 +56,7 @@ std::unique_ptr CreateCodec(size_t num_channels) { absl::make_unique(); states->mock_audio_network_adaptor = nullptr; states->fake_clock.reset(new rtc::ScopedFakeClock()); - states->fake_clock->SetTimeMicros(kInitialTimeUs); + states->fake_clock->SetTime(Timestamp::us(kInitialTimeUs)); MockAudioNetworkAdaptor** mock_ptr = &states->mock_audio_network_adaptor; AudioEncoderOpusImpl::AudioNetworkAdaptorCreator creator = diff --git a/modules/rtp_rtcp/source/rtcp_transceiver_impl_unittest.cc b/modules/rtp_rtcp/source/rtcp_transceiver_impl_unittest.cc index 794dfedf5a..fac173522d 100644 --- a/modules/rtp_rtcp/source/rtcp_transceiver_impl_unittest.cc +++ b/modules/rtp_rtcp/source/rtcp_transceiver_impl_unittest.cc @@ -735,10 +735,10 @@ TEST(RtcpTransceiverImplTest, }; receive_sender_report(kRemoteSsrc1); - clock.AdvanceTimeMicros(100 * rtc::kNumMicrosecsPerMillisec); + clock.AdvanceTime(webrtc::TimeDelta::ms(100)); receive_sender_report(kRemoteSsrc2); - clock.AdvanceTimeMicros(100 * rtc::kNumMicrosecsPerMillisec); + clock.AdvanceTime(webrtc::TimeDelta::ms(100)); // Trigger ReceiverReport back. rtcp_transceiver.SendCompoundPacket(); diff --git a/modules/rtp_rtcp/source/time_util_unittest.cc b/modules/rtp_rtcp/source/time_util_unittest.cc index f4315e5d6d..906a458f50 100644 --- a/modules/rtp_rtcp/source/time_util_unittest.cc +++ b/modules/rtp_rtcp/source/time_util_unittest.cc @@ -21,18 +21,18 @@ TEST(TimeUtilTest, TimeMicrosToNtpDoesntChangeBetweenRuns) { // TimeMicrosToNtp is not pure: it behave differently between different // execution of the program, but should behave same during same execution. const int64_t time_us = 12345; - clock.SetTimeMicros(2); + clock.SetTime(Timestamp::us(2)); NtpTime time_ntp = TimeMicrosToNtp(time_us); - clock.SetTimeMicros(time_us); + clock.SetTime(Timestamp::us(time_us)); EXPECT_EQ(TimeMicrosToNtp(time_us), time_ntp); - clock.SetTimeMicros(1000000); + clock.SetTime(Timestamp::us(1000000)); EXPECT_EQ(TimeMicrosToNtp(time_us), time_ntp); } TEST(TimeUtilTest, TimeMicrosToNtpKeepsIntervals) { rtc::ScopedFakeClock clock; NtpTime time_ntp1 = TimeMicrosToNtp(rtc::TimeMicros()); - clock.AdvanceTimeMicros(20000); + clock.AdvanceTime(TimeDelta::ms(20)); NtpTime time_ntp2 = TimeMicrosToNtp(rtc::TimeMicros()); EXPECT_EQ(time_ntp2.ToMs() - time_ntp1.ToMs(), 20); } diff --git a/rtc_base/fake_clock.h b/rtc_base/fake_clock.h index 0a29f601d0..0ab9a937a8 100644 --- a/rtc_base/fake_clock.h +++ b/rtc_base/fake_clock.h @@ -51,13 +51,8 @@ class ThreadProcessingFakeClock : public ClockInterface { public: int64_t TimeNanos() const override { return clock_.TimeNanos(); } void SetTime(webrtc::Timestamp time); - void SetTimeMicros(int64_t micros) { - SetTime(webrtc::Timestamp ::us(micros)); - } void AdvanceTime(webrtc::TimeDelta delta); - void AdvanceTimeMicros(int64_t micros) { - AdvanceTime(webrtc::TimeDelta::us(micros)); - } + private: FakeClock clock_; }; diff --git a/rtc_base/fake_clock_unittest.cc b/rtc_base/fake_clock_unittest.cc index 00a2c89cb5..74073d0842 100644 --- a/rtc_base/fake_clock_unittest.cc +++ b/rtc_base/fake_clock_unittest.cc @@ -21,13 +21,13 @@ TEST(ScopedFakeClockTest, OverridesGlobalClock) { ScopedFakeClock scoped; EXPECT_EQ(rtc::TimeMicros(), 0); - scoped.AdvanceTimeMicros(1000); + scoped.AdvanceTime(webrtc::TimeDelta::ms(1)); EXPECT_EQ(rtc::TimeMicros(), 1000); - scoped.SetTimeMicros(kFixedTimeUs); + scoped.SetTime(webrtc::Timestamp::us(kFixedTimeUs)); EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs); - scoped.AdvanceTimeMicros(1000); + scoped.AdvanceTime(webrtc::TimeDelta::ms(1)); EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs + 1000); } diff --git a/video/encoder_bitrate_adjuster_unittest.cc b/video/encoder_bitrate_adjuster_unittest.cc index 27a38c4b8a..7caf123172 100644 --- a/video/encoder_bitrate_adjuster_unittest.cc +++ b/video/encoder_bitrate_adjuster_unittest.cc @@ -106,8 +106,7 @@ class EncoderBitrateAdjusterTest : public ::testing::Test { const int64_t start_us = rtc::TimeMicros(); while (rtc::TimeMicros() < start_us + (duration_ms * rtc::kNumMicrosecsPerMillisec)) { - clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / - target_framerate_fps_); + clock_.AdvanceTime(TimeDelta::seconds(1) / target_framerate_fps_); for (size_t si = 0; si < NumSpatialLayers(); ++si) { const std::vector& tl_pattern = kTlPatterns[NumTemporalLayers(si) - 1]; diff --git a/video/encoder_overshoot_detector_unittest.cc b/video/encoder_overshoot_detector_unittest.cc index 0c1a2989a1..d720d21d7c 100644 --- a/video/encoder_overshoot_detector_unittest.cc +++ b/video/encoder_overshoot_detector_unittest.cc @@ -39,16 +39,14 @@ class EncoderOvershootDetectorTest : public ::testing::Test { if (rtc::TimeMillis() == 0) { // Encode a first frame which by definition has no overuse factor. detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis()); - clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / - target_framerate_fps_); + clock_.AdvanceTime(TimeDelta::seconds(1) / target_framerate_fps_); } int64_t runtime_us = 0; while (runtime_us < test_duration_ms * 1000) { detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis()); runtime_us += rtc::kNumMicrosecsPerSec / target_framerate_fps_; - clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / - target_framerate_fps_); + clock_.AdvanceTime(TimeDelta::seconds(1) / target_framerate_fps_); } // At constant utilization, both network and media utilization should be @@ -82,7 +80,7 @@ TEST_F(EncoderOvershootDetectorTest, NoUtilizationIfNoRate) { detector_.GetNetworkRateUtilizationFactor(rtc::TimeMillis()).has_value()); detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis()); - clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec * time_interval_ms); + clock_.AdvanceTime(TimeDelta::ms(time_interval_ms)); EXPECT_TRUE( detector_.GetNetworkRateUtilizationFactor(rtc::TimeMillis()).has_value()); } @@ -148,7 +146,7 @@ TEST_F(EncoderOvershootDetectorTest, PartialOvershoot) { int i = 0; while (runtime_us < kWindowSizeMs * rtc::kNumMicrosecsPerMillisec) { runtime_us += rtc::kNumMicrosecsPerSec / target_framerate_fps_; - clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / target_framerate_fps_); + clock_.AdvanceTime(TimeDelta::seconds(1) / target_framerate_fps_); int frame_size_bytes = (i++ % 4 < 2) ? (ideal_frame_size_bytes * 120) / 100 : (ideal_frame_size_bytes * 80) / 100; detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis()); diff --git a/video/overuse_frame_detector_unittest.cc b/video/overuse_frame_detector_unittest.cc index ebabf113ee..cb454825c2 100644 --- a/video/overuse_frame_detector_unittest.cc +++ b/video/overuse_frame_detector_unittest.cc @@ -106,10 +106,10 @@ class OveruseFrameDetectorTest : public ::testing::Test, frame.set_timestamp(timestamp); int64_t capture_time_us = rtc::TimeMicros(); overuse_detector_->FrameCaptured(frame, capture_time_us); - clock_.AdvanceTimeMicros(delay_us); + clock_.AdvanceTime(TimeDelta::us(delay_us)); overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us, delay_us); - clock_.AdvanceTimeMicros(interval_us - delay_us); + clock_.AdvanceTime(TimeDelta::us(interval_us - delay_us)); timestamp += interval_us * 90 / 1000; } } @@ -135,7 +135,7 @@ class OveruseFrameDetectorTest : public ::testing::Test, int max_delay_us = 0; for (int delay_us : delays_us) { if (delay_us > max_delay_us) { - clock_.AdvanceTimeMicros(delay_us - max_delay_us); + clock_.AdvanceTime(TimeDelta::us(delay_us - max_delay_us)); max_delay_us = delay_us; } @@ -143,7 +143,7 @@ class OveruseFrameDetectorTest : public ::testing::Test, capture_time_us, delay_us); } overuse_detector_->CheckForOveruse(observer_); - clock_.AdvanceTimeMicros(interval_us - max_delay_us); + clock_.AdvanceTime(TimeDelta::us(interval_us - max_delay_us)); timestamp += interval_us * 90 / 1000; } } @@ -168,7 +168,7 @@ class OveruseFrameDetectorTest : public ::testing::Test, int interval_us = random.Rand(min_interval_us, max_interval_us); int64_t capture_time_us = rtc::TimeMicros(); overuse_detector_->FrameCaptured(frame, capture_time_us); - clock_.AdvanceTimeMicros(delay_us); + clock_.AdvanceTime(TimeDelta::us(delay_us)); overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us, absl::optional(delay_us)); @@ -176,7 +176,7 @@ class OveruseFrameDetectorTest : public ::testing::Test, overuse_detector_->CheckForOveruse(observer_); // Avoid turning clock backwards. if (interval_us > delay_us) - clock_.AdvanceTimeMicros(interval_us - delay_us); + clock_.AdvanceTime(TimeDelta::us(interval_us - delay_us)); timestamp += interval_us * 90 / 1000; } @@ -273,7 +273,7 @@ TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) { kProcessTimeUs); overuse_detector_->CheckForOveruse(&overuse_observer); EXPECT_EQ(0, overuse_observer.normaluse_); - clock_.AdvanceTimeMicros(kProcessIntervalUs); + clock_.AdvanceTime(TimeDelta::us(kProcessIntervalUs)); overuse_detector_->CheckForOveruse(&overuse_observer); EXPECT_EQ(1, overuse_observer.normaluse_); } @@ -349,14 +349,14 @@ TEST_F(OveruseFrameDetectorTest, MinFrameSamplesBeforeUpdating) { kProcessTimeUs); EXPECT_EQ(InitialUsage(), UsagePercent()); // Pass time far enough to digest all previous samples. - clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec); + clock_.AdvanceTime(TimeDelta::seconds(1)); InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); // The last sample has not been processed here. EXPECT_EQ(InitialUsage(), UsagePercent()); // Pass time far enough to digest all previous samples, 41 in total. - clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec); + clock_.AdvanceTime(TimeDelta::seconds(1)); InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); EXPECT_NE(InitialUsage(), UsagePercent()); @@ -384,7 +384,7 @@ TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) { frame.set_timestamp(static_cast(i)); int64_t capture_time_us = rtc::TimeMicros(); overuse_detector_->FrameCaptured(frame, capture_time_us); - clock_.AdvanceTimeMicros(kIntervalUs); + clock_.AdvanceTime(TimeDelta::us(kIntervalUs)); if (i > kNumFramesEncodingDelay) { overuse_detector_->FrameSent( static_cast(i - kNumFramesEncodingDelay), rtc::TimeMicros(), @@ -412,14 +412,14 @@ TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) { int64_t capture_time_us = rtc::TimeMicros(); overuse_detector_->FrameCaptured(frame, capture_time_us); // Encode and send first parts almost instantly. - clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec); + clock_.AdvanceTime(TimeDelta::ms(1)); overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us, rtc::kNumMicrosecsPerMillisec); // Encode heavier part, resulting in >85% usage total. - clock_.AdvanceTimeMicros(kDelayUs - rtc::kNumMicrosecsPerMillisec); + clock_.AdvanceTime(TimeDelta::us(kDelayUs) - TimeDelta::ms(1)); overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us, kDelayUs); - clock_.AdvanceTimeMicros(kIntervalUs - kDelayUs); + clock_.AdvanceTime(TimeDelta::us(kIntervalUs - kDelayUs)); timestamp += kIntervalUs * 90 / 1000; overuse_detector_->CheckForOveruse(observer_); } @@ -674,7 +674,7 @@ class OveruseFrameDetectorTest2 : public OveruseFrameDetectorTest { overuse_detector_->FrameSent(0 /* ignored timestamp */, 0 /* ignored send_time_us */, capture_time_us, delay_us); - clock_.AdvanceTimeMicros(interval_us); + clock_.AdvanceTime(TimeDelta::us(interval_us)); } } @@ -701,7 +701,7 @@ class OveruseFrameDetectorTest2 : public OveruseFrameDetectorTest { capture_time_us, delay_us); overuse_detector_->CheckForOveruse(observer_); - clock_.AdvanceTimeMicros(interval_us); + clock_.AdvanceTime(TimeDelta::us(interval_us)); } } @@ -751,7 +751,7 @@ TEST_F(OveruseFrameDetectorTest2, TriggerUnderuseWithMinProcessCount) { kProcessTimeUs); overuse_detector_->CheckForOveruse(&overuse_observer); EXPECT_EQ(0, overuse_observer.normaluse_); - clock_.AdvanceTimeMicros(kProcessIntervalUs); + clock_.AdvanceTime(TimeDelta::us(kProcessIntervalUs)); overuse_detector_->CheckForOveruse(&overuse_observer); EXPECT_EQ(1, overuse_observer.normaluse_); } @@ -862,7 +862,7 @@ TEST_F(OveruseFrameDetectorTest2, MeasuresMultipleConcurrentSamples) { frame.set_timestamp(static_cast(i)); int64_t capture_time_us = rtc::TimeMicros(); overuse_detector_->FrameCaptured(frame, capture_time_us); - clock_.AdvanceTimeMicros(kIntervalUs); + clock_.AdvanceTime(TimeDelta::us(kIntervalUs)); if (i > kNumFramesEncodingDelay) { overuse_detector_->FrameSent( static_cast(i - kNumFramesEncodingDelay), rtc::TimeMicros(), @@ -890,14 +890,14 @@ TEST_F(OveruseFrameDetectorTest2, UpdatesExistingSamples) { int64_t capture_time_us = rtc::TimeMicros(); overuse_detector_->FrameCaptured(frame, capture_time_us); // Encode and send first parts almost instantly. - clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec); + clock_.AdvanceTime(TimeDelta::ms(1)); overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us, rtc::kNumMicrosecsPerMillisec); // Encode heavier part, resulting in >85% usage total. - clock_.AdvanceTimeMicros(kDelayUs - rtc::kNumMicrosecsPerMillisec); + clock_.AdvanceTime(TimeDelta::us(kDelayUs) - TimeDelta::ms(1)); overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us, kDelayUs); - clock_.AdvanceTimeMicros(kIntervalUs - kDelayUs); + clock_.AdvanceTime(TimeDelta::us(kIntervalUs - kDelayUs)); timestamp += kIntervalUs * 90 / 1000; overuse_detector_->CheckForOveruse(observer_); } diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index 32420647e8..18ab5b90b0 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc @@ -320,7 +320,7 @@ class VideoStreamEncoderTest : public ::testing::Test { video_encoder_config.video_stream_factory->CreateEncoderStreams( codec_width_, codec_height_, video_encoder_config); max_framerate_ = streams[0].max_framerate; - fake_clock_.SetTimeMicros(1234); + fake_clock_.SetTime(Timestamp::us(1234)); ConfigureEncoder(std::move(video_encoder_config)); } @@ -527,28 +527,28 @@ class VideoStreamEncoderTest : public ::testing::Test { void WaitForEncodedFrame(int64_t expected_ntp_time) { sink_.WaitForEncodedFrame(expected_ntp_time); - fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); + fake_clock_.AdvanceTime(TimeDelta::seconds(1) / max_framerate_); } bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, int64_t timeout_ms) { bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, timeout_ms); - fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); + fake_clock_.AdvanceTime(TimeDelta::seconds(1) / max_framerate_); return ok; } void WaitForEncodedFrame(uint32_t expected_width, uint32_t expected_height) { sink_.WaitForEncodedFrame(expected_width, expected_height); - fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); + fake_clock_.AdvanceTime(TimeDelta::seconds(1) / max_framerate_); } void ExpectDroppedFrame() { sink_.ExpectDroppedFrame(); - fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); + fake_clock_.AdvanceTime(TimeDelta::seconds(1) / max_framerate_); } bool WaitForFrame(int64_t timeout_ms) { bool ok = sink_.WaitForFrame(timeout_ms); - fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); + fake_clock_.AdvanceTime(TimeDelta::seconds(1) / max_framerate_); return ok; } @@ -2334,7 +2334,9 @@ TEST_F(VideoStreamEncoderTest, CallsBitrateObserver) { fake_encoder_.GetAndResetLastBitrateAllocation(); // Check that encoder has been updated too, not just allocation observer. EXPECT_EQ(bitrate_allocation->get_sum_bps(), kLowTargetBitrateBps); - fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec / kDefaultFps); + // TODO(srte): The use of millisecs here looks like an error, but the tests + // fails using seconds, this should be investigated. + fake_clock_.AdvanceTime(TimeDelta::ms(1) / kDefaultFps); // Not called on second frame. EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) @@ -2342,7 +2344,7 @@ TEST_F(VideoStreamEncoderTest, CallsBitrateObserver) { video_source_.IncomingCapturedFrame( CreateFrame(rtc::TimeMillis(), codec_width_, codec_height_)); WaitForEncodedFrame(rtc::TimeMillis()); - fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec / kDefaultFps); + fake_clock_.AdvanceTime(TimeDelta::ms(1) / kDefaultFps); // Called after a process interval. const int64_t kProcessIntervalMs = @@ -2354,7 +2356,7 @@ TEST_F(VideoStreamEncoderTest, CallsBitrateObserver) { video_source_.IncomingCapturedFrame( CreateFrame(rtc::TimeMillis(), codec_width_, codec_height_)); WaitForEncodedFrame(rtc::TimeMillis()); - fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec / kDefaultFps); + fake_clock_.AdvanceTime(TimeDelta::ms(1) / kDefaultFps); } // Since rates are unchanged, encoder should not be reconfigured. @@ -2959,8 +2961,7 @@ TEST_F(VideoStreamEncoderTest, DoesntAdaptDownPastMinFramerate) { sink_.WaitForEncodedFrame(timestamp_ms); } timestamp_ms += kFrameIntervalMs; - fake_clock_.AdvanceTimeMicros(kFrameIntervalMs * - rtc::kNumMicrosecsPerMillisec); + fake_clock_.AdvanceTime(TimeDelta::ms(kFrameIntervalMs)); } // ...and then try to adapt again. video_stream_encoder_->TriggerCpuOveruse(); @@ -3497,9 +3498,8 @@ TEST_F(VideoStreamEncoderTest, DoesNotUpdateBitrateAllocationWhenSuspended) { // Skip ahead until a new periodic parameter update should have occured. timestamp_ms += vcm::VCMProcessTimer::kDefaultProcessIntervalMs; - fake_clock_.AdvanceTimeMicros( - vcm::VCMProcessTimer::kDefaultProcessIntervalMs * - rtc::kNumMicrosecsPerMillisec); + fake_clock_.AdvanceTime( + TimeDelta::ms(vcm::VCMProcessTimer::kDefaultProcessIntervalMs)); // Bitrate observer should not be called. EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(0);