Removes TimeMicros interface from ThreadProcessingFakeClock.

Bug: webrtc:9883
Change-Id: Ib48872f81f734b09e3ffa4d9d26da79177b02303
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/133341
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27668}
This commit is contained in:
Sebastian Jansson 2019-04-17 12:11:20 +02:00 committed by Commit Bot
parent e47aee3b86
commit 40889f35fc
13 changed files with 86 additions and 94 deletions

View File

@ -352,7 +352,7 @@ class ForcedFallbackTest : public VideoEncoderSoftwareFallbackWrapperTest {
protected: protected:
void SetUp() override { void SetUp() override {
clock_.SetTimeMicros(1234); clock_.SetTime(Timestamp::us(1234));
ConfigureVp8Codec(); ConfigureVp8Codec();
} }

View File

@ -741,7 +741,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpReceiverReport) {
} }
rtc::ScopedFakeClock fake_clock; rtc::ScopedFakeClock fake_clock;
fake_clock.SetTimeMicros(static_cast<int64_t>(prng_.Rand<uint32_t>()) * 1000); fake_clock.SetTime(Timestamp::ms(prng_.Rand<uint32_t>()));
for (auto direction : {kIncomingPacket, kOutgoingPacket}) { for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
std::vector<rtcp::ReceiverReport> events(event_count_); std::vector<rtcp::ReceiverReport> events(event_count_);
@ -757,7 +757,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpReceiverReport) {
history_.push_back( history_.push_back(
absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer)); absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
} }
fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000)));
} }
std::string encoded = std::string encoded =
@ -780,7 +780,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpSenderReport) {
} }
rtc::ScopedFakeClock fake_clock; rtc::ScopedFakeClock fake_clock;
fake_clock.SetTimeMicros(static_cast<int64_t>(prng_.Rand<uint32_t>()) * 1000); fake_clock.SetTime(Timestamp::ms(prng_.Rand<uint32_t>()));
for (auto direction : {kIncomingPacket, kOutgoingPacket}) { for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
std::vector<rtcp::SenderReport> events(event_count_); std::vector<rtcp::SenderReport> events(event_count_);
@ -796,7 +796,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpSenderReport) {
history_.push_back( history_.push_back(
absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer)); absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
} }
fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000)));
} }
std::string encoded = std::string encoded =
@ -819,7 +819,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpExtendedReports) {
} }
rtc::ScopedFakeClock fake_clock; rtc::ScopedFakeClock fake_clock;
fake_clock.SetTimeMicros(static_cast<int64_t>(prng_.Rand<uint32_t>()) * 1000); fake_clock.SetTime(Timestamp::ms(prng_.Rand<uint32_t>()));
for (auto direction : {kIncomingPacket, kOutgoingPacket}) { for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
std::vector<rtcp::ExtendedReports> events(event_count_); std::vector<rtcp::ExtendedReports> events(event_count_);
@ -835,7 +835,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpExtendedReports) {
history_.push_back( history_.push_back(
absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer)); absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
} }
fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000)));
} }
std::string encoded = std::string encoded =
@ -858,7 +858,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpFir) {
} }
rtc::ScopedFakeClock fake_clock; rtc::ScopedFakeClock fake_clock;
fake_clock.SetTimeMicros(static_cast<int64_t>(prng_.Rand<uint32_t>()) * 1000); fake_clock.SetTime(Timestamp::ms(prng_.Rand<uint32_t>()));
for (auto direction : {kIncomingPacket, kOutgoingPacket}) { for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
std::vector<rtcp::Fir> events(event_count_); std::vector<rtcp::Fir> events(event_count_);
@ -874,7 +874,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpFir) {
history_.push_back( history_.push_back(
absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer)); absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
} }
fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000)));
} }
std::string encoded = std::string encoded =
@ -896,7 +896,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPli) {
} }
rtc::ScopedFakeClock fake_clock; rtc::ScopedFakeClock fake_clock;
fake_clock.SetTimeMicros(static_cast<int64_t>(prng_.Rand<uint32_t>()) * 1000); fake_clock.SetTime(Timestamp::ms(prng_.Rand<uint32_t>()));
for (auto direction : {kIncomingPacket, kOutgoingPacket}) { for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
std::vector<rtcp::Pli> events(event_count_); std::vector<rtcp::Pli> events(event_count_);
@ -912,7 +912,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPli) {
history_.push_back( history_.push_back(
absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer)); absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
} }
fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000)));
} }
std::string encoded = std::string encoded =
@ -934,7 +934,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpNack) {
} }
rtc::ScopedFakeClock fake_clock; rtc::ScopedFakeClock fake_clock;
fake_clock.SetTimeMicros(static_cast<int64_t>(prng_.Rand<uint32_t>()) * 1000); fake_clock.SetTime(Timestamp::ms(prng_.Rand<uint32_t>()));
for (auto direction : {kIncomingPacket, kOutgoingPacket}) { for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
std::vector<rtcp::Nack> events(event_count_); std::vector<rtcp::Nack> events(event_count_);
@ -950,7 +950,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpNack) {
history_.push_back( history_.push_back(
absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer)); absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
} }
fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000)));
} }
std::string encoded = std::string encoded =
@ -972,7 +972,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpRemb) {
} }
rtc::ScopedFakeClock fake_clock; rtc::ScopedFakeClock fake_clock;
fake_clock.SetTimeMicros(static_cast<int64_t>(prng_.Rand<uint32_t>()) * 1000); fake_clock.SetTime(Timestamp::ms(prng_.Rand<uint32_t>()));
for (auto direction : {kIncomingPacket, kOutgoingPacket}) { for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
std::vector<rtcp::Remb> events(event_count_); std::vector<rtcp::Remb> events(event_count_);
@ -988,7 +988,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpRemb) {
history_.push_back( history_.push_back(
absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer)); absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
} }
fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000)));
} }
std::string encoded = std::string encoded =
@ -1010,7 +1010,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpTransportFeedback) {
} }
rtc::ScopedFakeClock fake_clock; rtc::ScopedFakeClock fake_clock;
fake_clock.SetTimeMicros(static_cast<int64_t>(prng_.Rand<uint32_t>()) * 1000); fake_clock.SetTime(Timestamp::ms(prng_.Rand<uint32_t>()));
for (auto direction : {kIncomingPacket, kOutgoingPacket}) { for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
std::vector<rtcp::TransportFeedback> events; std::vector<rtcp::TransportFeedback> events;
@ -1027,7 +1027,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpTransportFeedback) {
history_.push_back( history_.push_back(
absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer)); absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
} }
fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000)));
} }
std::string encoded = std::string encoded =
@ -1051,7 +1051,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpLossNotification) {
} }
rtc::ScopedFakeClock fake_clock; rtc::ScopedFakeClock fake_clock;
fake_clock.SetTimeMicros(static_cast<int64_t>(prng_.Rand<uint32_t>()) * 1000); fake_clock.SetTime(Timestamp::ms(prng_.Rand<uint32_t>()));
for (auto direction : {kIncomingPacket, kOutgoingPacket}) { for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
std::vector<rtcp::LossNotification> events; std::vector<rtcp::LossNotification> events;
@ -1068,7 +1068,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpLossNotification) {
history_.push_back( history_.push_back(
absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer)); absl::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
} }
fake_clock.AdvanceTimeMicros(prng_.Rand(0, 1000) * 1000); fake_clock.AdvanceTime(TimeDelta::ms(prng_.Rand(0, 1000)));
} }
std::string encoded = std::string encoded =

View File

@ -113,7 +113,7 @@ class RtcEventLogSession
encoding_type_(std::get<2>(GetParam())), encoding_type_(std::get<2>(GetParam())),
gen_(seed_ * 880001UL), gen_(seed_ * 880001UL),
verifier_(encoding_type_) { verifier_(encoding_type_) {
clock_.SetTimeMicros(prng_.Rand<uint32_t>()); clock_.SetTime(Timestamp::us(prng_.Rand<uint32_t>()));
// Find the name of the current test, in order to use it as a temporary // Find the name of the current test, in order to use it as a temporary
// filename. // filename.
// TODO(terelius): Use a general utility function to generate a temp file. // 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); RTC_CHECK(event_log != nullptr);
uint32_t ssrc; uint32_t ssrc;
for (size_t i = 0; i < audio_recv_streams; i++) { for (size_t i = 0; i < audio_recv_streams; i++) {
clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20)));
do { do {
ssrc = prng_.Rand<uint32_t>(); ssrc = prng_.Rand<uint32_t>();
} while (SsrcUsed(ssrc, incoming_extensions_)); } while (SsrcUsed(ssrc, incoming_extensions_));
@ -232,7 +232,7 @@ void RtcEventLogSession::WriteAudioSendConfigs(size_t audio_send_streams,
RTC_CHECK(event_log != nullptr); RTC_CHECK(event_log != nullptr);
uint32_t ssrc; uint32_t ssrc;
for (size_t i = 0; i < audio_send_streams; i++) { for (size_t i = 0; i < audio_send_streams; i++) {
clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20)));
do { do {
ssrc = prng_.Rand<uint32_t>(); ssrc = prng_.Rand<uint32_t>();
} while (SsrcUsed(ssrc, outgoing_extensions_)); } while (SsrcUsed(ssrc, outgoing_extensions_));
@ -254,14 +254,14 @@ void RtcEventLogSession::WriteVideoRecvConfigs(size_t video_recv_streams,
RtpHeaderExtensionMap all_extensions = RtpHeaderExtensionMap all_extensions =
ParsedRtcEventLog::GetDefaultHeaderExtensionMap(); ParsedRtcEventLog::GetDefaultHeaderExtensionMap();
clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20)));
uint32_t ssrc = prng_.Rand<uint32_t>(); uint32_t ssrc = prng_.Rand<uint32_t>();
incoming_extensions_.emplace_back(prng_.Rand<uint32_t>(), all_extensions); incoming_extensions_.emplace_back(prng_.Rand<uint32_t>(), all_extensions);
auto event = gen_.NewVideoReceiveStreamConfig(ssrc, all_extensions); auto event = gen_.NewVideoReceiveStreamConfig(ssrc, all_extensions);
event_log->Log(event->Copy()); event_log->Log(event->Copy());
video_recv_config_list_.push_back(std::move(event)); video_recv_config_list_.push_back(std::move(event));
for (size_t i = 1; i < video_recv_streams; i++) { for (size_t i = 1; i < video_recv_streams; i++) {
clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20)));
do { do {
ssrc = prng_.Rand<uint32_t>(); ssrc = prng_.Rand<uint32_t>();
} while (SsrcUsed(ssrc, incoming_extensions_)); } while (SsrcUsed(ssrc, incoming_extensions_));
@ -283,14 +283,14 @@ void RtcEventLogSession::WriteVideoSendConfigs(size_t video_send_streams,
RtpHeaderExtensionMap all_extensions = RtpHeaderExtensionMap all_extensions =
ParsedRtcEventLog::GetDefaultHeaderExtensionMap(); ParsedRtcEventLog::GetDefaultHeaderExtensionMap();
clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20)));
uint32_t ssrc = prng_.Rand<uint32_t>(); uint32_t ssrc = prng_.Rand<uint32_t>();
outgoing_extensions_.emplace_back(prng_.Rand<uint32_t>(), all_extensions); outgoing_extensions_.emplace_back(prng_.Rand<uint32_t>(), all_extensions);
auto event = gen_.NewVideoSendStreamConfig(ssrc, all_extensions); auto event = gen_.NewVideoSendStreamConfig(ssrc, all_extensions);
event_log->Log(event->Copy()); event_log->Log(event->Copy());
video_send_config_list_.push_back(std::move(event)); video_send_config_list_.push_back(std::move(event));
for (size_t i = 1; i < video_send_streams; i++) { for (size_t i = 1; i < video_send_streams; i++) {
clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20)));
do { do {
ssrc = prng_.Rand<uint32_t>(); ssrc = prng_.Rand<uint32_t>();
} while (SsrcUsed(ssrc, outgoing_extensions_)); } 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; size_t remaining_events_at_start = remaining_events - num_events_before_start;
for (; remaining_events > 0; remaining_events--) { for (; remaining_events > 0; remaining_events--) {
if (remaining_events == remaining_events_at_start) { if (remaining_events == remaining_events_at_start) {
clock_.AdvanceTimeMicros(prng_.Rand(20) * 1000); clock_.AdvanceTime(TimeDelta::ms(prng_.Rand(20)));
event_log->StartLogging( event_log->StartLogging(
absl::make_unique<RtcEventLogOutputFile>(temp_filename_, 10000000), absl::make_unique<RtcEventLogOutputFile>(temp_filename_, 10000000),
output_period_ms_); output_period_ms_);
@ -335,7 +335,7 @@ void RtcEventLogSession::WriteLog(EventCounts count,
utc_start_time_us_ = rtc::TimeUTCMicros(); 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); size_t selection = prng_.Rand(remaining_events - 1);
first_timestamp_ms_ = std::min(first_timestamp_ms_, rtc::TimeMillis()); first_timestamp_ms_ = std::min(first_timestamp_ms_, rtc::TimeMillis());
last_timestamp_ms_ = std::max(last_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 // TODO(terelius): Maybe make a separate RtcEventLogImplTest that can access
// the size of the cyclic buffer? // the size of the cyclic buffer?
constexpr size_t kNumEvents = 20000; constexpr size_t kNumEvents = 20000;
constexpr int64_t kStartTime = 1000000; constexpr int64_t kStartTimeSeconds = 1;
constexpr int32_t kStartBitrate = 1000000; constexpr int32_t kStartBitrate = 1000000;
auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
@ -825,7 +825,7 @@ TEST_P(RtcEventLogCircularBufferTest, KeepsMostRecentEvents) {
std::unique_ptr<rtc::ScopedFakeClock> fake_clock = std::unique_ptr<rtc::ScopedFakeClock> fake_clock =
absl::make_unique<rtc::ScopedFakeClock>(); absl::make_unique<rtc::ScopedFakeClock>();
fake_clock->SetTimeMicros(kStartTime); fake_clock->SetTime(Timestamp::seconds(kStartTimeSeconds));
auto task_queue_factory = CreateDefaultTaskQueueFactory(); auto task_queue_factory = CreateDefaultTaskQueueFactory();
RtcEventLogFactory rtc_event_log_factory(task_queue_factory.get()); RtcEventLogFactory rtc_event_log_factory(task_queue_factory.get());
@ -843,14 +843,14 @@ TEST_P(RtcEventLogCircularBufferTest, KeepsMostRecentEvents) {
// consistency checks when we read back. // consistency checks when we read back.
log_dumper->Log(absl::make_unique<RtcEventProbeResultSuccess>( log_dumper->Log(absl::make_unique<RtcEventProbeResultSuccess>(
i, kStartBitrate + i * 1000)); i, kStartBitrate + i * 1000));
fake_clock->AdvanceTimeMicros(10000); fake_clock->AdvanceTime(TimeDelta::ms(10));
} }
int64_t start_time_us = rtc::TimeMicros(); int64_t start_time_us = rtc::TimeMicros();
int64_t utc_start_time_us = rtc::TimeUTCMicros(); int64_t utc_start_time_us = rtc::TimeUTCMicros();
log_dumper->StartLogging( log_dumper->StartLogging(
absl::make_unique<RtcEventLogOutputFile>(temp_filename, 10000000), absl::make_unique<RtcEventLogOutputFile>(temp_filename, 10000000),
RtcEventLog::kImmediateOutput); RtcEventLog::kImmediateOutput);
fake_clock->AdvanceTimeMicros(10000); fake_clock->AdvanceTime(TimeDelta::ms(10));
int64_t stop_time_us = rtc::TimeMicros(); int64_t stop_time_us = rtc::TimeMicros();
log_dumper->StopLogging(); log_dumper->StopLogging();
@ -883,9 +883,9 @@ TEST_P(RtcEventLogCircularBufferTest, KeepsMostRecentEvents) {
// destroyed before the new one is created, so we have to reset() first. // destroyed before the new one is created, so we have to reset() first.
fake_clock.reset(); fake_clock.reset();
fake_clock = absl::make_unique<rtc::ScopedFakeClock>(); fake_clock = absl::make_unique<rtc::ScopedFakeClock>();
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++) { for (size_t i = 1; i < probe_success_events.size(); i++) {
fake_clock->AdvanceTimeMicros(10000); fake_clock->AdvanceTime(TimeDelta::ms(10));
verifier_.VerifyLoggedBweProbeSuccessEvent( verifier_.VerifyLoggedBweProbeSuccessEvent(
RtcEventProbeResultSuccess(first_id + i, first_bitrate_bps + i * 1000), RtcEventProbeResultSuccess(first_id + i, first_bitrate_bps + i * 1000),
probe_success_events[i]); probe_success_events[i]);

View File

@ -225,7 +225,7 @@ class WebRtcVideoEngineTest : public ::testing::Test {
decoder_factory_)) { decoder_factory_)) {
// Ensure fake clock doesn't return 0, which will cause some initializations // Ensure fake clock doesn't return 0, which will cause some initializations
// fail inside RTP senders. // fail inside RTP senders.
fake_clock_.AdvanceTimeMicros(1); fake_clock_.AdvanceTime(webrtc::TimeDelta::us(1));
} }
protected: protected:
@ -3472,7 +3472,7 @@ TEST_F(WebRtcVideoChannelTest, EstimatesNtpStartTimeCorrectly) {
// This timestamp is kInitialTimestamp (-1) + kFrameOffsetMs * 90, which // This timestamp is kInitialTimestamp (-1) + kFrameOffsetMs * 90, which
// triggers a constant-overflow warning, hence we're calculating it explicitly // triggers a constant-overflow warning, hence we're calculating it explicitly
// here. // here.
fake_clock_.AdvanceTimeMicros(kFrameOffsetMs * rtc::kNumMicrosecsPerMillisec); fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(kFrameOffsetMs));
video_frame.set_timestamp(kFrameOffsetMs * 90 - 1); video_frame.set_timestamp(kFrameOffsetMs * 90 - 1);
video_frame.set_ntp_time_ms(kInitialNtpTimeMs + kFrameOffsetMs); video_frame.set_ntp_time_ms(kInitialNtpTimeMs + kFrameOffsetMs);
stream->InjectFrame(video_frame); stream->InjectFrame(video_frame);

View File

@ -56,7 +56,7 @@ std::unique_ptr<AudioEncoderOpusStates> CreateCodec(size_t num_channels) {
absl::make_unique<AudioEncoderOpusStates>(); absl::make_unique<AudioEncoderOpusStates>();
states->mock_audio_network_adaptor = nullptr; states->mock_audio_network_adaptor = nullptr;
states->fake_clock.reset(new rtc::ScopedFakeClock()); 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; MockAudioNetworkAdaptor** mock_ptr = &states->mock_audio_network_adaptor;
AudioEncoderOpusImpl::AudioNetworkAdaptorCreator creator = AudioEncoderOpusImpl::AudioNetworkAdaptorCreator creator =

View File

@ -735,10 +735,10 @@ TEST(RtcpTransceiverImplTest,
}; };
receive_sender_report(kRemoteSsrc1); receive_sender_report(kRemoteSsrc1);
clock.AdvanceTimeMicros(100 * rtc::kNumMicrosecsPerMillisec); clock.AdvanceTime(webrtc::TimeDelta::ms(100));
receive_sender_report(kRemoteSsrc2); receive_sender_report(kRemoteSsrc2);
clock.AdvanceTimeMicros(100 * rtc::kNumMicrosecsPerMillisec); clock.AdvanceTime(webrtc::TimeDelta::ms(100));
// Trigger ReceiverReport back. // Trigger ReceiverReport back.
rtcp_transceiver.SendCompoundPacket(); rtcp_transceiver.SendCompoundPacket();

View File

@ -21,18 +21,18 @@ TEST(TimeUtilTest, TimeMicrosToNtpDoesntChangeBetweenRuns) {
// TimeMicrosToNtp is not pure: it behave differently between different // TimeMicrosToNtp is not pure: it behave differently between different
// execution of the program, but should behave same during same execution. // execution of the program, but should behave same during same execution.
const int64_t time_us = 12345; const int64_t time_us = 12345;
clock.SetTimeMicros(2); clock.SetTime(Timestamp::us(2));
NtpTime time_ntp = TimeMicrosToNtp(time_us); NtpTime time_ntp = TimeMicrosToNtp(time_us);
clock.SetTimeMicros(time_us); clock.SetTime(Timestamp::us(time_us));
EXPECT_EQ(TimeMicrosToNtp(time_us), time_ntp); EXPECT_EQ(TimeMicrosToNtp(time_us), time_ntp);
clock.SetTimeMicros(1000000); clock.SetTime(Timestamp::us(1000000));
EXPECT_EQ(TimeMicrosToNtp(time_us), time_ntp); EXPECT_EQ(TimeMicrosToNtp(time_us), time_ntp);
} }
TEST(TimeUtilTest, TimeMicrosToNtpKeepsIntervals) { TEST(TimeUtilTest, TimeMicrosToNtpKeepsIntervals) {
rtc::ScopedFakeClock clock; rtc::ScopedFakeClock clock;
NtpTime time_ntp1 = TimeMicrosToNtp(rtc::TimeMicros()); NtpTime time_ntp1 = TimeMicrosToNtp(rtc::TimeMicros());
clock.AdvanceTimeMicros(20000); clock.AdvanceTime(TimeDelta::ms(20));
NtpTime time_ntp2 = TimeMicrosToNtp(rtc::TimeMicros()); NtpTime time_ntp2 = TimeMicrosToNtp(rtc::TimeMicros());
EXPECT_EQ(time_ntp2.ToMs() - time_ntp1.ToMs(), 20); EXPECT_EQ(time_ntp2.ToMs() - time_ntp1.ToMs(), 20);
} }

View File

@ -51,13 +51,8 @@ class ThreadProcessingFakeClock : public ClockInterface {
public: public:
int64_t TimeNanos() const override { return clock_.TimeNanos(); } int64_t TimeNanos() const override { return clock_.TimeNanos(); }
void SetTime(webrtc::Timestamp time); void SetTime(webrtc::Timestamp time);
void SetTimeMicros(int64_t micros) {
SetTime(webrtc::Timestamp ::us(micros));
}
void AdvanceTime(webrtc::TimeDelta delta); void AdvanceTime(webrtc::TimeDelta delta);
void AdvanceTimeMicros(int64_t micros) {
AdvanceTime(webrtc::TimeDelta::us(micros));
}
private: private:
FakeClock clock_; FakeClock clock_;
}; };

View File

@ -21,13 +21,13 @@ TEST(ScopedFakeClockTest, OverridesGlobalClock) {
ScopedFakeClock scoped; ScopedFakeClock scoped;
EXPECT_EQ(rtc::TimeMicros(), 0); EXPECT_EQ(rtc::TimeMicros(), 0);
scoped.AdvanceTimeMicros(1000); scoped.AdvanceTime(webrtc::TimeDelta::ms(1));
EXPECT_EQ(rtc::TimeMicros(), 1000); EXPECT_EQ(rtc::TimeMicros(), 1000);
scoped.SetTimeMicros(kFixedTimeUs); scoped.SetTime(webrtc::Timestamp::us(kFixedTimeUs));
EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs); EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs);
scoped.AdvanceTimeMicros(1000); scoped.AdvanceTime(webrtc::TimeDelta::ms(1));
EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs + 1000); EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs + 1000);
} }

View File

@ -106,8 +106,7 @@ class EncoderBitrateAdjusterTest : public ::testing::Test {
const int64_t start_us = rtc::TimeMicros(); const int64_t start_us = rtc::TimeMicros();
while (rtc::TimeMicros() < while (rtc::TimeMicros() <
start_us + (duration_ms * rtc::kNumMicrosecsPerMillisec)) { start_us + (duration_ms * rtc::kNumMicrosecsPerMillisec)) {
clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / clock_.AdvanceTime(TimeDelta::seconds(1) / target_framerate_fps_);
target_framerate_fps_);
for (size_t si = 0; si < NumSpatialLayers(); ++si) { for (size_t si = 0; si < NumSpatialLayers(); ++si) {
const std::vector<int>& tl_pattern = const std::vector<int>& tl_pattern =
kTlPatterns[NumTemporalLayers(si) - 1]; kTlPatterns[NumTemporalLayers(si) - 1];

View File

@ -39,16 +39,14 @@ class EncoderOvershootDetectorTest : public ::testing::Test {
if (rtc::TimeMillis() == 0) { if (rtc::TimeMillis() == 0) {
// Encode a first frame which by definition has no overuse factor. // Encode a first frame which by definition has no overuse factor.
detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis()); detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis());
clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / clock_.AdvanceTime(TimeDelta::seconds(1) / target_framerate_fps_);
target_framerate_fps_);
} }
int64_t runtime_us = 0; int64_t runtime_us = 0;
while (runtime_us < test_duration_ms * 1000) { while (runtime_us < test_duration_ms * 1000) {
detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis()); detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis());
runtime_us += rtc::kNumMicrosecsPerSec / target_framerate_fps_; runtime_us += rtc::kNumMicrosecsPerSec / target_framerate_fps_;
clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / clock_.AdvanceTime(TimeDelta::seconds(1) / target_framerate_fps_);
target_framerate_fps_);
} }
// At constant utilization, both network and media utilization should be // 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_.GetNetworkRateUtilizationFactor(rtc::TimeMillis()).has_value());
detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis()); detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis());
clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec * time_interval_ms); clock_.AdvanceTime(TimeDelta::ms(time_interval_ms));
EXPECT_TRUE( EXPECT_TRUE(
detector_.GetNetworkRateUtilizationFactor(rtc::TimeMillis()).has_value()); detector_.GetNetworkRateUtilizationFactor(rtc::TimeMillis()).has_value());
} }
@ -148,7 +146,7 @@ TEST_F(EncoderOvershootDetectorTest, PartialOvershoot) {
int i = 0; int i = 0;
while (runtime_us < kWindowSizeMs * rtc::kNumMicrosecsPerMillisec) { while (runtime_us < kWindowSizeMs * rtc::kNumMicrosecsPerMillisec) {
runtime_us += rtc::kNumMicrosecsPerSec / target_framerate_fps_; 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 int frame_size_bytes = (i++ % 4 < 2) ? (ideal_frame_size_bytes * 120) / 100
: (ideal_frame_size_bytes * 80) / 100; : (ideal_frame_size_bytes * 80) / 100;
detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis()); detector_.OnEncodedFrame(frame_size_bytes, rtc::TimeMillis());

View File

@ -106,10 +106,10 @@ class OveruseFrameDetectorTest : public ::testing::Test,
frame.set_timestamp(timestamp); frame.set_timestamp(timestamp);
int64_t capture_time_us = rtc::TimeMicros(); int64_t capture_time_us = rtc::TimeMicros();
overuse_detector_->FrameCaptured(frame, capture_time_us); overuse_detector_->FrameCaptured(frame, capture_time_us);
clock_.AdvanceTimeMicros(delay_us); clock_.AdvanceTime(TimeDelta::us(delay_us));
overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(),
capture_time_us, delay_us); capture_time_us, delay_us);
clock_.AdvanceTimeMicros(interval_us - delay_us); clock_.AdvanceTime(TimeDelta::us(interval_us - delay_us));
timestamp += interval_us * 90 / 1000; timestamp += interval_us * 90 / 1000;
} }
} }
@ -135,7 +135,7 @@ class OveruseFrameDetectorTest : public ::testing::Test,
int max_delay_us = 0; int max_delay_us = 0;
for (int delay_us : delays_us) { for (int delay_us : delays_us) {
if (delay_us > max_delay_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; max_delay_us = delay_us;
} }
@ -143,7 +143,7 @@ class OveruseFrameDetectorTest : public ::testing::Test,
capture_time_us, delay_us); capture_time_us, delay_us);
} }
overuse_detector_->CheckForOveruse(observer_); 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; 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); int interval_us = random.Rand(min_interval_us, max_interval_us);
int64_t capture_time_us = rtc::TimeMicros(); int64_t capture_time_us = rtc::TimeMicros();
overuse_detector_->FrameCaptured(frame, capture_time_us); overuse_detector_->FrameCaptured(frame, capture_time_us);
clock_.AdvanceTimeMicros(delay_us); clock_.AdvanceTime(TimeDelta::us(delay_us));
overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(),
capture_time_us, capture_time_us,
absl::optional<int>(delay_us)); absl::optional<int>(delay_us));
@ -176,7 +176,7 @@ class OveruseFrameDetectorTest : public ::testing::Test,
overuse_detector_->CheckForOveruse(observer_); overuse_detector_->CheckForOveruse(observer_);
// Avoid turning clock backwards. // Avoid turning clock backwards.
if (interval_us > delay_us) if (interval_us > delay_us)
clock_.AdvanceTimeMicros(interval_us - delay_us); clock_.AdvanceTime(TimeDelta::us(interval_us - delay_us));
timestamp += interval_us * 90 / 1000; timestamp += interval_us * 90 / 1000;
} }
@ -273,7 +273,7 @@ TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) {
kProcessTimeUs); kProcessTimeUs);
overuse_detector_->CheckForOveruse(&overuse_observer); overuse_detector_->CheckForOveruse(&overuse_observer);
EXPECT_EQ(0, overuse_observer.normaluse_); EXPECT_EQ(0, overuse_observer.normaluse_);
clock_.AdvanceTimeMicros(kProcessIntervalUs); clock_.AdvanceTime(TimeDelta::us(kProcessIntervalUs));
overuse_detector_->CheckForOveruse(&overuse_observer); overuse_detector_->CheckForOveruse(&overuse_observer);
EXPECT_EQ(1, overuse_observer.normaluse_); EXPECT_EQ(1, overuse_observer.normaluse_);
} }
@ -349,14 +349,14 @@ TEST_F(OveruseFrameDetectorTest, MinFrameSamplesBeforeUpdating) {
kProcessTimeUs); kProcessTimeUs);
EXPECT_EQ(InitialUsage(), UsagePercent()); EXPECT_EQ(InitialUsage(), UsagePercent());
// Pass time far enough to digest all previous samples. // Pass time far enough to digest all previous samples.
clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec); clock_.AdvanceTime(TimeDelta::seconds(1));
InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight, InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight,
kProcessTimeUs); kProcessTimeUs);
// The last sample has not been processed here. // The last sample has not been processed here.
EXPECT_EQ(InitialUsage(), UsagePercent()); EXPECT_EQ(InitialUsage(), UsagePercent());
// Pass time far enough to digest all previous samples, 41 in total. // 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, InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight,
kProcessTimeUs); kProcessTimeUs);
EXPECT_NE(InitialUsage(), UsagePercent()); EXPECT_NE(InitialUsage(), UsagePercent());
@ -384,7 +384,7 @@ TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) {
frame.set_timestamp(static_cast<uint32_t>(i)); frame.set_timestamp(static_cast<uint32_t>(i));
int64_t capture_time_us = rtc::TimeMicros(); int64_t capture_time_us = rtc::TimeMicros();
overuse_detector_->FrameCaptured(frame, capture_time_us); overuse_detector_->FrameCaptured(frame, capture_time_us);
clock_.AdvanceTimeMicros(kIntervalUs); clock_.AdvanceTime(TimeDelta::us(kIntervalUs));
if (i > kNumFramesEncodingDelay) { if (i > kNumFramesEncodingDelay) {
overuse_detector_->FrameSent( overuse_detector_->FrameSent(
static_cast<uint32_t>(i - kNumFramesEncodingDelay), rtc::TimeMicros(), static_cast<uint32_t>(i - kNumFramesEncodingDelay), rtc::TimeMicros(),
@ -412,14 +412,14 @@ TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) {
int64_t capture_time_us = rtc::TimeMicros(); int64_t capture_time_us = rtc::TimeMicros();
overuse_detector_->FrameCaptured(frame, capture_time_us); overuse_detector_->FrameCaptured(frame, capture_time_us);
// Encode and send first parts almost instantly. // 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, overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us,
rtc::kNumMicrosecsPerMillisec); rtc::kNumMicrosecsPerMillisec);
// Encode heavier part, resulting in >85% usage total. // 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, overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us,
kDelayUs); kDelayUs);
clock_.AdvanceTimeMicros(kIntervalUs - kDelayUs); clock_.AdvanceTime(TimeDelta::us(kIntervalUs - kDelayUs));
timestamp += kIntervalUs * 90 / 1000; timestamp += kIntervalUs * 90 / 1000;
overuse_detector_->CheckForOveruse(observer_); overuse_detector_->CheckForOveruse(observer_);
} }
@ -674,7 +674,7 @@ class OveruseFrameDetectorTest2 : public OveruseFrameDetectorTest {
overuse_detector_->FrameSent(0 /* ignored timestamp */, overuse_detector_->FrameSent(0 /* ignored timestamp */,
0 /* ignored send_time_us */, 0 /* ignored send_time_us */,
capture_time_us, delay_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); capture_time_us, delay_us);
overuse_detector_->CheckForOveruse(observer_); overuse_detector_->CheckForOveruse(observer_);
clock_.AdvanceTimeMicros(interval_us); clock_.AdvanceTime(TimeDelta::us(interval_us));
} }
} }
@ -751,7 +751,7 @@ TEST_F(OveruseFrameDetectorTest2, TriggerUnderuseWithMinProcessCount) {
kProcessTimeUs); kProcessTimeUs);
overuse_detector_->CheckForOveruse(&overuse_observer); overuse_detector_->CheckForOveruse(&overuse_observer);
EXPECT_EQ(0, overuse_observer.normaluse_); EXPECT_EQ(0, overuse_observer.normaluse_);
clock_.AdvanceTimeMicros(kProcessIntervalUs); clock_.AdvanceTime(TimeDelta::us(kProcessIntervalUs));
overuse_detector_->CheckForOveruse(&overuse_observer); overuse_detector_->CheckForOveruse(&overuse_observer);
EXPECT_EQ(1, overuse_observer.normaluse_); EXPECT_EQ(1, overuse_observer.normaluse_);
} }
@ -862,7 +862,7 @@ TEST_F(OveruseFrameDetectorTest2, MeasuresMultipleConcurrentSamples) {
frame.set_timestamp(static_cast<uint32_t>(i)); frame.set_timestamp(static_cast<uint32_t>(i));
int64_t capture_time_us = rtc::TimeMicros(); int64_t capture_time_us = rtc::TimeMicros();
overuse_detector_->FrameCaptured(frame, capture_time_us); overuse_detector_->FrameCaptured(frame, capture_time_us);
clock_.AdvanceTimeMicros(kIntervalUs); clock_.AdvanceTime(TimeDelta::us(kIntervalUs));
if (i > kNumFramesEncodingDelay) { if (i > kNumFramesEncodingDelay) {
overuse_detector_->FrameSent( overuse_detector_->FrameSent(
static_cast<uint32_t>(i - kNumFramesEncodingDelay), rtc::TimeMicros(), static_cast<uint32_t>(i - kNumFramesEncodingDelay), rtc::TimeMicros(),
@ -890,14 +890,14 @@ TEST_F(OveruseFrameDetectorTest2, UpdatesExistingSamples) {
int64_t capture_time_us = rtc::TimeMicros(); int64_t capture_time_us = rtc::TimeMicros();
overuse_detector_->FrameCaptured(frame, capture_time_us); overuse_detector_->FrameCaptured(frame, capture_time_us);
// Encode and send first parts almost instantly. // 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, overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us,
rtc::kNumMicrosecsPerMillisec); rtc::kNumMicrosecsPerMillisec);
// Encode heavier part, resulting in >85% usage total. // 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, overuse_detector_->FrameSent(timestamp, rtc::TimeMicros(), capture_time_us,
kDelayUs); kDelayUs);
clock_.AdvanceTimeMicros(kIntervalUs - kDelayUs); clock_.AdvanceTime(TimeDelta::us(kIntervalUs - kDelayUs));
timestamp += kIntervalUs * 90 / 1000; timestamp += kIntervalUs * 90 / 1000;
overuse_detector_->CheckForOveruse(observer_); overuse_detector_->CheckForOveruse(observer_);
} }

View File

@ -320,7 +320,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
video_encoder_config.video_stream_factory->CreateEncoderStreams( video_encoder_config.video_stream_factory->CreateEncoderStreams(
codec_width_, codec_height_, video_encoder_config); codec_width_, codec_height_, video_encoder_config);
max_framerate_ = streams[0].max_framerate; max_framerate_ = streams[0].max_framerate;
fake_clock_.SetTimeMicros(1234); fake_clock_.SetTime(Timestamp::us(1234));
ConfigureEncoder(std::move(video_encoder_config)); ConfigureEncoder(std::move(video_encoder_config));
} }
@ -527,28 +527,28 @@ class VideoStreamEncoderTest : public ::testing::Test {
void WaitForEncodedFrame(int64_t expected_ntp_time) { void WaitForEncodedFrame(int64_t expected_ntp_time) {
sink_.WaitForEncodedFrame(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 TimedWaitForEncodedFrame(int64_t expected_ntp_time, int64_t timeout_ms) {
bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, 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; return ok;
} }
void WaitForEncodedFrame(uint32_t expected_width, uint32_t expected_height) { void WaitForEncodedFrame(uint32_t expected_width, uint32_t expected_height) {
sink_.WaitForEncodedFrame(expected_width, 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() { void ExpectDroppedFrame() {
sink_.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 WaitForFrame(int64_t timeout_ms) {
bool ok = sink_.WaitForFrame(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; return ok;
} }
@ -2334,7 +2334,9 @@ TEST_F(VideoStreamEncoderTest, CallsBitrateObserver) {
fake_encoder_.GetAndResetLastBitrateAllocation(); fake_encoder_.GetAndResetLastBitrateAllocation();
// Check that encoder has been updated too, not just allocation observer. // Check that encoder has been updated too, not just allocation observer.
EXPECT_EQ(bitrate_allocation->get_sum_bps(), kLowTargetBitrateBps); 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. // Not called on second frame.
EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
@ -2342,7 +2344,7 @@ TEST_F(VideoStreamEncoderTest, CallsBitrateObserver) {
video_source_.IncomingCapturedFrame( video_source_.IncomingCapturedFrame(
CreateFrame(rtc::TimeMillis(), codec_width_, codec_height_)); CreateFrame(rtc::TimeMillis(), codec_width_, codec_height_));
WaitForEncodedFrame(rtc::TimeMillis()); WaitForEncodedFrame(rtc::TimeMillis());
fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec / kDefaultFps); fake_clock_.AdvanceTime(TimeDelta::ms(1) / kDefaultFps);
// Called after a process interval. // Called after a process interval.
const int64_t kProcessIntervalMs = const int64_t kProcessIntervalMs =
@ -2354,7 +2356,7 @@ TEST_F(VideoStreamEncoderTest, CallsBitrateObserver) {
video_source_.IncomingCapturedFrame( video_source_.IncomingCapturedFrame(
CreateFrame(rtc::TimeMillis(), codec_width_, codec_height_)); CreateFrame(rtc::TimeMillis(), codec_width_, codec_height_));
WaitForEncodedFrame(rtc::TimeMillis()); 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. // Since rates are unchanged, encoder should not be reconfigured.
@ -2959,8 +2961,7 @@ TEST_F(VideoStreamEncoderTest, DoesntAdaptDownPastMinFramerate) {
sink_.WaitForEncodedFrame(timestamp_ms); sink_.WaitForEncodedFrame(timestamp_ms);
} }
timestamp_ms += kFrameIntervalMs; timestamp_ms += kFrameIntervalMs;
fake_clock_.AdvanceTimeMicros(kFrameIntervalMs * fake_clock_.AdvanceTime(TimeDelta::ms(kFrameIntervalMs));
rtc::kNumMicrosecsPerMillisec);
} }
// ...and then try to adapt again. // ...and then try to adapt again.
video_stream_encoder_->TriggerCpuOveruse(); video_stream_encoder_->TriggerCpuOveruse();
@ -3497,9 +3498,8 @@ TEST_F(VideoStreamEncoderTest, DoesNotUpdateBitrateAllocationWhenSuspended) {
// Skip ahead until a new periodic parameter update should have occured. // Skip ahead until a new periodic parameter update should have occured.
timestamp_ms += vcm::VCMProcessTimer::kDefaultProcessIntervalMs; timestamp_ms += vcm::VCMProcessTimer::kDefaultProcessIntervalMs;
fake_clock_.AdvanceTimeMicros( fake_clock_.AdvanceTime(
vcm::VCMProcessTimer::kDefaultProcessIntervalMs * TimeDelta::ms(vcm::VCMProcessTimer::kDefaultProcessIntervalMs));
rtc::kNumMicrosecsPerMillisec);
// Bitrate observer should not be called. // Bitrate observer should not be called.
EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(0); EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(0);