Update rtc::Event::Wait call sites to use TimeDelta.

Bug: webrtc:14366
Change-Id: I949c1d26f030696b18153afef977633c9a5bd4cf
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272003
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37835}
This commit is contained in:
Markus Handell 2022-08-19 08:16:48 +00:00 committed by WebRTC LUCI CQ
parent 4d715385e1
commit 2cfc1af78a
62 changed files with 302 additions and 297 deletions

View File

@ -14,6 +14,7 @@
#include <utility> #include <utility>
#include "api/function_view.h" #include "api/function_view.h"
#include "api/units/time_delta.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "rtc_base/task_queue_for_test.h" #include "rtc_base/task_queue_for_test.h"
@ -47,7 +48,7 @@ void RunOnDifferentThread(rtc::FunctionView<void()> run) {
thread_has_run_event.Set(); thread_has_run_event.Set();
}, },
"thread"); "thread");
EXPECT_TRUE(thread_has_run_event.Wait(1000)); EXPECT_TRUE(thread_has_run_event.Wait(TimeDelta::Seconds(1)));
} }
} // namespace } // namespace

View File

@ -49,7 +49,7 @@ TEST_P(TaskQueueTest, PostAndCheckCurrent) {
EXPECT_TRUE(queue->IsCurrent()); EXPECT_TRUE(queue->IsCurrent());
event.Set(); event.Set();
}); });
EXPECT_TRUE(event.Wait(1000)); EXPECT_TRUE(event.Wait(TimeDelta::Seconds(1)));
} }
TEST_P(TaskQueueTest, PostCustomTask) { TEST_P(TaskQueueTest, PostCustomTask) {
@ -68,7 +68,7 @@ TEST_P(TaskQueueTest, PostCustomTask) {
} my_task(&ran); } my_task(&ran);
queue->PostTask(my_task); queue->PostTask(my_task);
EXPECT_TRUE(ran.Wait(1000)); EXPECT_TRUE(ran.Wait(TimeDelta::Seconds(1)));
} }
TEST_P(TaskQueueTest, PostDelayedZero) { TEST_P(TaskQueueTest, PostDelayedZero) {
@ -77,7 +77,7 @@ TEST_P(TaskQueueTest, PostDelayedZero) {
auto queue = CreateTaskQueue(factory, "PostDelayedZero"); auto queue = CreateTaskQueue(factory, "PostDelayedZero");
queue->PostDelayedTask([&event] { event.Set(); }, TimeDelta::Zero()); queue->PostDelayedTask([&event] { event.Set(); }, TimeDelta::Zero());
EXPECT_TRUE(event.Wait(1000)); EXPECT_TRUE(event.Wait(TimeDelta::Seconds(1)));
} }
TEST_P(TaskQueueTest, PostFromQueue) { TEST_P(TaskQueueTest, PostFromQueue) {
@ -87,7 +87,7 @@ TEST_P(TaskQueueTest, PostFromQueue) {
queue->PostTask( queue->PostTask(
[&event, &queue] { queue->PostTask([&event] { event.Set(); }); }); [&event, &queue] { queue->PostTask([&event] { event.Set(); }); });
EXPECT_TRUE(event.Wait(1000)); EXPECT_TRUE(event.Wait(TimeDelta::Seconds(1)));
} }
TEST_P(TaskQueueTest, PostDelayed) { TEST_P(TaskQueueTest, PostDelayed) {
@ -103,7 +103,7 @@ TEST_P(TaskQueueTest, PostDelayed) {
event.Set(); event.Set();
}, },
TimeDelta::Millis(100)); TimeDelta::Millis(100));
EXPECT_TRUE(event.Wait(1000)); EXPECT_TRUE(event.Wait(TimeDelta::Seconds(1)));
int64_t end = rtc::TimeMillis(); int64_t end = rtc::TimeMillis();
// These tests are a little relaxed due to how "powerful" our test bots can // These tests are a little relaxed due to how "powerful" our test bots can
// be. Most recently we've seen windows bots fire the callback after 94-99ms, // be. Most recently we've seen windows bots fire the callback after 94-99ms,
@ -128,7 +128,7 @@ TEST_P(TaskQueueTest, PostMultipleDelayed) {
} }
for (rtc::Event& e : events) for (rtc::Event& e : events)
EXPECT_TRUE(e.Wait(1000)); EXPECT_TRUE(e.Wait(TimeDelta::Seconds(1)));
} }
TEST_P(TaskQueueTest, PostDelayedAfterDestruct) { TEST_P(TaskQueueTest, PostDelayedAfterDestruct) {
@ -142,8 +142,8 @@ TEST_P(TaskQueueTest, PostDelayedAfterDestruct) {
// Destroy the queue. // Destroy the queue.
queue = nullptr; queue = nullptr;
// Task might outlive the TaskQueue, but still should be deleted. // Task might outlive the TaskQueue, but still should be deleted.
EXPECT_TRUE(deleted.Wait(1000)); EXPECT_TRUE(deleted.Wait(TimeDelta::Seconds(1)));
EXPECT_FALSE(run.Wait(0)); // and should not run. EXPECT_FALSE(run.Wait(TimeDelta::Zero())); // and should not run.
} }
TEST_P(TaskQueueTest, PostAndReuse) { TEST_P(TaskQueueTest, PostAndReuse) {
@ -182,7 +182,7 @@ TEST_P(TaskQueueTest, PostAndReuse) {
ReusedTask task(&call_count, reply_queue.get(), &event); ReusedTask task(&call_count, reply_queue.get(), &event);
post_queue->PostTask(std::move(task)); post_queue->PostTask(std::move(task));
EXPECT_TRUE(event.Wait(1000)); EXPECT_TRUE(event.Wait(TimeDelta::Seconds(1)));
} }
TEST_P(TaskQueueTest, PostALot) { TEST_P(TaskQueueTest, PostALot) {
@ -196,7 +196,7 @@ TEST_P(TaskQueueTest, PostALot) {
event_.Set(); event_.Set();
} }
} }
bool Wait(int give_up_after_ms) { return event_.Wait(give_up_after_ms); } bool Wait(TimeDelta give_up_after) { return event_.Wait(give_up_after); }
private: private:
webrtc_impl::RefCounter count_; webrtc_impl::RefCounter count_;
@ -232,7 +232,7 @@ TEST_P(TaskQueueTest, PostALot) {
// Expect all tasks are destroyed eventually. In some task queue // Expect all tasks are destroyed eventually. In some task queue
// implementations that might happen on a different thread after task queue is // implementations that might happen on a different thread after task queue is
// destroyed. // destroyed.
EXPECT_TRUE(all_destroyed.Wait(60000)); EXPECT_TRUE(all_destroyed.Wait(TimeDelta::Minutes(1)));
EXPECT_LE(tasks_executed, kTaskCount); EXPECT_LE(tasks_executed, kTaskCount);
} }
@ -266,7 +266,7 @@ TEST_P(TaskQueueTest, PostTwoWithSharedUnprotectedState) {
// Check, that state changing tasks didn't start yet. // Check, that state changing tasks didn't start yet.
EXPECT_EQ(state.state, 0); EXPECT_EQ(state.state, 0);
}); });
EXPECT_TRUE(done.Wait(1000)); EXPECT_TRUE(done.Wait(TimeDelta::Seconds(1)));
} }
// TaskQueueTest is a set of tests for any implementation of the TaskQueueBase. // TaskQueueTest is a set of tests for any implementation of the TaskQueueBase.

View File

@ -141,7 +141,7 @@ TEST_F(AudioEgressTest, ProcessAudioWithMute) {
fake_clock_.AdvanceTimeMilliseconds(10); fake_clock_.AdvanceTimeMilliseconds(10);
} }
event.Wait(/*ms=*/1000); event.Wait(TimeDelta::Seconds(1));
EXPECT_EQ(rtp_count, kExpected); EXPECT_EQ(rtp_count, kExpected);
// we expect on pcmu payload to result in 255 for silenced payload // we expect on pcmu payload to result in 255 for silenced payload
@ -177,7 +177,7 @@ TEST_F(AudioEgressTest, ProcessAudioWithSineWave) {
fake_clock_.AdvanceTimeMilliseconds(10); fake_clock_.AdvanceTimeMilliseconds(10);
} }
event.Wait(/*ms=*/1000); event.Wait(TimeDelta::Seconds(1));
EXPECT_EQ(rtp_count, kExpected); EXPECT_EQ(rtp_count, kExpected);
// we expect on pcmu to result in < 255 for payload with sine wave // we expect on pcmu to result in < 255 for payload with sine wave
@ -211,7 +211,7 @@ TEST_F(AudioEgressTest, SkipAudioEncodingAfterStopSend) {
fake_clock_.AdvanceTimeMilliseconds(10); fake_clock_.AdvanceTimeMilliseconds(10);
} }
event.Wait(/*ms=*/1000); event.Wait(TimeDelta::Seconds(1));
EXPECT_EQ(rtp_count, kExpected); EXPECT_EQ(rtp_count, kExpected);
// Now stop send and yet feed more data. // Now stop send and yet feed more data.
@ -287,7 +287,7 @@ TEST_F(AudioEgressTest, SendDTMF) {
fake_clock_.AdvanceTimeMilliseconds(10); fake_clock_.AdvanceTimeMilliseconds(10);
} }
event.Wait(/*ms=*/1000); event.Wait(TimeDelta::Seconds(1));
EXPECT_EQ(dtmf_count, kExpected); EXPECT_EQ(dtmf_count, kExpected);
} }
@ -312,7 +312,7 @@ TEST_F(AudioEgressTest, TestAudioInputLevelAndEnergyDuration) {
fake_clock_.AdvanceTimeMilliseconds(10); fake_clock_.AdvanceTimeMilliseconds(10);
} }
event.Wait(/*give_up_after_ms=*/1000); event.Wait(/*give_up_after=*/TimeDelta::Seconds(1));
EXPECT_EQ(rtp_count, kExpected); EXPECT_EQ(rtp_count, kExpected);
constexpr double kExpectedEnergy = 0.00016809565587789564; constexpr double kExpectedEnergy = 0.00016809565587789564;

View File

@ -122,7 +122,7 @@ TEST_F(AudioIngressTest, GetAudioFrameAfterRtpReceived) {
EXPECT_CALL(transport_, SendRtp).WillRepeatedly(Invoke(handle_rtp)); EXPECT_CALL(transport_, SendRtp).WillRepeatedly(Invoke(handle_rtp));
egress_->SendAudioData(GetAudioFrame(0)); egress_->SendAudioData(GetAudioFrame(0));
egress_->SendAudioData(GetAudioFrame(1)); egress_->SendAudioData(GetAudioFrame(1));
event.Wait(/*ms=*/1000); event.Wait(TimeDelta::Seconds(1));
AudioFrame audio_frame; AudioFrame audio_frame;
EXPECT_EQ( EXPECT_EQ(
@ -155,7 +155,7 @@ TEST_F(AudioIngressTest, TestSpeechOutputLevelAndEnergyDuration) {
egress_->SendAudioData(GetAudioFrame(i)); egress_->SendAudioData(GetAudioFrame(i));
fake_clock_.AdvanceTimeMilliseconds(10); fake_clock_.AdvanceTimeMilliseconds(10);
} }
event.Wait(/*give_up_after_ms=*/1000); event.Wait(/*give_up_after=*/TimeDelta::Seconds(1));
for (int i = 0; i < kNumRtp * 2; ++i) { for (int i = 0; i < kNumRtp * 2; ++i) {
AudioFrame audio_frame; AudioFrame audio_frame;
@ -182,7 +182,7 @@ TEST_F(AudioIngressTest, PreferredSampleRate) {
EXPECT_CALL(transport_, SendRtp).WillRepeatedly(Invoke(handle_rtp)); EXPECT_CALL(transport_, SendRtp).WillRepeatedly(Invoke(handle_rtp));
egress_->SendAudioData(GetAudioFrame(0)); egress_->SendAudioData(GetAudioFrame(0));
egress_->SendAudioData(GetAudioFrame(1)); egress_->SendAudioData(GetAudioFrame(1));
event.Wait(/*ms=*/1000); event.Wait(TimeDelta::Seconds(1));
AudioFrame audio_frame; AudioFrame audio_frame;
EXPECT_EQ( EXPECT_EQ(
@ -214,7 +214,7 @@ TEST_F(AudioIngressTest, GetMutedAudioFrameAfterRtpReceivedAndStopPlay) {
egress_->SendAudioData(GetAudioFrame(i)); egress_->SendAudioData(GetAudioFrame(i));
fake_clock_.AdvanceTimeMilliseconds(10); fake_clock_.AdvanceTimeMilliseconds(10);
} }
event.Wait(/*give_up_after_ms=*/1000); event.Wait(/*give_up_after=*/TimeDelta::Seconds(1));
for (int i = 0; i < kNumRtp * 2; ++i) { for (int i = 0; i < kNumRtp * 2; ++i) {
AudioFrame audio_frame; AudioFrame audio_frame;

View File

@ -31,7 +31,7 @@ namespace {
const int kDefaultFrameRate = 30; const int kDefaultFrameRate = 30;
const int kDefaultFrameSize = 1280 * 720; const int kDefaultFrameSize = 1280 * 720;
const int kDefaultTimeoutMs = 5000; constexpr TimeDelta kDefaultTimeout = TimeDelta::Seconds(5);
class VideoSourceRestrictionsListenerForTesting class VideoSourceRestrictionsListenerForTesting
: public VideoSourceRestrictionsListener { : public VideoSourceRestrictionsListener {
@ -434,7 +434,7 @@ TEST_F(ResourceAdaptationProcessorTest,
[&]() { resource_->SetUsageState(ResourceUsageState::kOveruse); }); [&]() { resource_->SetUsageState(ResourceUsageState::kOveruse); });
EXPECT_EQ_WAIT(1u, restrictions_listener_.restrictions_updated_count(), EXPECT_EQ_WAIT(1u, restrictions_listener_.restrictions_updated_count(),
kDefaultTimeoutMs); kDefaultTimeout.ms());
} }
TEST_F(ResourceAdaptationProcessorTest, TEST_F(ResourceAdaptationProcessorTest,
@ -452,7 +452,7 @@ TEST_F(ResourceAdaptationProcessorTest,
resource_event.Set(); resource_event.Set();
}); });
EXPECT_TRUE(resource_event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(resource_event.Wait(kDefaultTimeout));
// Now destroy the processor while handling the overuse is in flight. // Now destroy the processor while handling the overuse is in flight.
DestroyProcessor(); DestroyProcessor();
@ -474,7 +474,7 @@ TEST_F(ResourceAdaptationProcessorTest,
resource_->SetUsageState(ResourceUsageState::kOveruse); resource_->SetUsageState(ResourceUsageState::kOveruse);
overuse_event.Set(); overuse_event.Set();
}); });
EXPECT_TRUE(overuse_event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(overuse_event.Wait(kDefaultTimeout));
// Once we know the overuse task is queued, remove `resource_` so that // Once we know the overuse task is queued, remove `resource_` so that
// `processor_` is not listening to it. // `processor_` is not listening to it.
processor_->RemoveResource(resource_); processor_->RemoveResource(resource_);

View File

@ -81,7 +81,7 @@ class LogObserver {
} }
} }
bool Wait() { return done_.Wait(test::CallTest::kDefaultTimeout.ms()); } bool Wait() { return done_.Wait(test::CallTest::kDefaultTimeout); }
void PushExpectedLogLine(absl::string_view expected_log_line) { void PushExpectedLogLine(absl::string_view expected_log_line) {
MutexLock lock(&mutex_); MutexLock lock(&mutex_);

View File

@ -867,7 +867,7 @@ TEST_F(CallPerfTest, MAYBE_KeepsHighBitrateWhenReconfiguringSender) {
} }
void PerformTest() override { void PerformTest() override {
ASSERT_TRUE(time_to_reconfigure_.Wait(kDefaultTimeout.ms())) ASSERT_TRUE(time_to_reconfigure_.Wait(kDefaultTimeout))
<< "Timed out before receiving an initial high bitrate."; << "Timed out before receiving an initial high bitrate.";
frame_generator_->ChangeResolution(kDefaultWidth * 2, kDefaultHeight * 2); frame_generator_->ChangeResolution(kDefaultWidth * 2, kDefaultHeight * 2);
SendTask(task_queue_, [&]() { SendTask(task_queue_, [&]() {

View File

@ -24,7 +24,8 @@ namespace cricket {
namespace { namespace {
static const int kEventTimeoutMs = 10000; static constexpr webrtc::TimeDelta kEventTimeout =
webrtc::TimeDelta::Seconds(10);
} // namespace } // namespace
@ -171,7 +172,7 @@ webrtc::VideoEncoder::EncoderInfo FakeWebRtcVideoEncoder::GetEncoderInfo()
} }
bool FakeWebRtcVideoEncoder::WaitForInitEncode() { bool FakeWebRtcVideoEncoder::WaitForInitEncode() {
return init_encode_event_.Wait(kEventTimeoutMs); return init_encode_event_.Wait(kEventTimeout);
} }
webrtc::VideoCodec FakeWebRtcVideoEncoder::GetCodecSettings() { webrtc::VideoCodec FakeWebRtcVideoEncoder::GetCodecSettings() {
@ -228,12 +229,13 @@ FakeWebRtcVideoEncoderFactory::CreateVideoEncoder(
bool FakeWebRtcVideoEncoderFactory::WaitForCreatedVideoEncoders( bool FakeWebRtcVideoEncoderFactory::WaitForCreatedVideoEncoders(
int num_encoders) { int num_encoders) {
int64_t start_offset_ms = rtc::TimeMillis(); int64_t start_offset_ms = rtc::TimeMillis();
int64_t wait_time = kEventTimeoutMs; int64_t wait_time = kEventTimeout.ms();
do { do {
if (GetNumCreatedEncoders() >= num_encoders) if (GetNumCreatedEncoders() >= num_encoders)
return true; return true;
wait_time = kEventTimeoutMs - (rtc::TimeMillis() - start_offset_ms); wait_time = kEventTimeout.ms() - (rtc::TimeMillis() - start_offset_ms);
} while (wait_time > 0 && created_video_encoder_event_.Wait(wait_time)); } while (wait_time > 0 && created_video_encoder_event_.Wait(
webrtc::TimeDelta::Millis(wait_time)));
return false; return false;
} }

View File

@ -479,9 +479,7 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
insert_packet_thread_.Finalize(); insert_packet_thread_.Finalize();
} }
bool RunTest() { bool RunTest() { return test_complete_.Wait(TimeDelta::Minutes(10)); }
return test_complete_.Wait(10 * 60 * 1000); // 10 minutes' timeout.
}
virtual bool TestDone() { virtual bool TestDone() {
if (packet_cb_.num_calls() > kNumPackets) { if (packet_cb_.num_calls() > kNumPackets) {
@ -736,9 +734,7 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi {
codec_registration_thread_.Finalize(); codec_registration_thread_.Finalize();
} }
bool RunTest() { bool RunTest() { return test_complete_.Wait(TimeDelta::Minutes(10)); }
return test_complete_.Wait(10 * 60 * 1000); // 10 minutes' timeout.
}
bool CbReceiveImpl() { bool CbReceiveImpl() {
SleepMs(1); SleepMs(1);

View File

@ -80,15 +80,15 @@ namespace {
// an event indicating that the test was OK. // an event indicating that the test was OK.
static constexpr size_t kNumCallbacks = 10; static constexpr size_t kNumCallbacks = 10;
// Max amount of time we wait for an event to be set while counting callbacks. // Max amount of time we wait for an event to be set while counting callbacks.
static constexpr size_t kTestTimeOutInMilliseconds = 10 * 1000; static constexpr TimeDelta kTestTimeOut = TimeDelta::Seconds(10);
// Average number of audio callbacks per second assuming 10ms packet size. // Average number of audio callbacks per second assuming 10ms packet size.
static constexpr size_t kNumCallbacksPerSecond = 100; static constexpr size_t kNumCallbacksPerSecond = 100;
// Run the full-duplex test during this time (unit is in seconds). // Run the full-duplex test during this time (unit is in seconds).
static constexpr size_t kFullDuplexTimeInSec = 5; static constexpr TimeDelta kFullDuplexTime = TimeDelta::Seconds(5);
// Length of round-trip latency measurements. Number of deteced impulses // Length of round-trip latency measurements. Number of deteced impulses
// shall be kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1 since the // shall be kImpulseFrequencyInHz * kMeasureLatencyTime - 1 since the
// last transmitted pulse is not used. // last transmitted pulse is not used.
static constexpr size_t kMeasureLatencyTimeInSec = 10; static constexpr TimeDelta kMeasureLatencyTime = TimeDelta::Seconds(10);
// Sets the number of impulses per second in the latency test. // Sets the number of impulses per second in the latency test.
static constexpr size_t kImpulseFrequencyInHz = 1; static constexpr size_t kImpulseFrequencyInHz = 1;
// Utilized in round-trip latency measurements to avoid capturing noise samples. // Utilized in round-trip latency measurements to avoid capturing noise samples.
@ -974,7 +974,7 @@ TEST_P(MAYBE_AudioDeviceTest, StartStopPlayoutWithInternalRestart) {
.Times(AtLeast(kNumCallbacks)); .Times(AtLeast(kNumCallbacks));
EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock));
StartPlayout(); StartPlayout();
event()->Wait(kTestTimeOutInMilliseconds); event()->Wait(kTestTimeOut);
EXPECT_TRUE(audio_device()->Playing()); EXPECT_TRUE(audio_device()->Playing());
// Restart playout but without stopping the internal audio thread. // Restart playout but without stopping the internal audio thread.
// This procedure uses a non-public test API and it emulates what happens // This procedure uses a non-public test API and it emulates what happens
@ -997,7 +997,7 @@ TEST_P(MAYBE_AudioDeviceTest, StartStopPlayoutWithInternalRestart) {
mock.ResetCallbackCounters(); mock.ResetCallbackCounters();
EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _)) EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _))
.Times(AtLeast(kNumCallbacks)); .Times(AtLeast(kNumCallbacks));
event()->Wait(kTestTimeOutInMilliseconds); event()->Wait(kTestTimeOut);
EXPECT_TRUE(audio_device()->Playing()); EXPECT_TRUE(audio_device()->Playing());
// Stop playout and the audio thread after successful internal restart. // Stop playout and the audio thread after successful internal restart.
StopPlayout(); StopPlayout();
@ -1020,7 +1020,7 @@ TEST_P(MAYBE_AudioDeviceTest, StartStopRecordingWithInternalRestart) {
.Times(AtLeast(kNumCallbacks)); .Times(AtLeast(kNumCallbacks));
EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock));
StartRecording(); StartRecording();
event()->Wait(kTestTimeOutInMilliseconds); event()->Wait(kTestTimeOut);
EXPECT_TRUE(audio_device()->Recording()); EXPECT_TRUE(audio_device()->Recording());
// Restart recording but without stopping the internal audio thread. // Restart recording but without stopping the internal audio thread.
// This procedure uses a non-public test API and it emulates what happens // This procedure uses a non-public test API and it emulates what happens
@ -1044,7 +1044,7 @@ TEST_P(MAYBE_AudioDeviceTest, StartStopRecordingWithInternalRestart) {
EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _, EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _,
false, _)) false, _))
.Times(AtLeast(kNumCallbacks)); .Times(AtLeast(kNumCallbacks));
event()->Wait(kTestTimeOutInMilliseconds); event()->Wait(kTestTimeOut);
EXPECT_TRUE(audio_device()->Recording()); EXPECT_TRUE(audio_device()->Recording());
// Stop recording and the audio thread after successful internal restart. // Stop recording and the audio thread after successful internal restart.
StopRecording(); StopRecording();
@ -1065,7 +1065,7 @@ TEST_P(MAYBE_AudioDeviceTest, StartPlayoutVerifyCallbacks) {
.Times(AtLeast(kNumCallbacks)); .Times(AtLeast(kNumCallbacks));
EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock));
StartPlayout(); StartPlayout();
event()->Wait(kTestTimeOutInMilliseconds); event()->Wait(kTestTimeOut);
StopPlayout(); StopPlayout();
PreTearDown(); PreTearDown();
} }
@ -1098,7 +1098,7 @@ TEST_P(MAYBE_AudioDeviceTest, MAYBE_StartRecordingVerifyCallbacks) {
.Times(AtLeast(kNumCallbacks)); .Times(AtLeast(kNumCallbacks));
EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock));
StartRecording(); StartRecording();
event()->Wait(kTestTimeOutInMilliseconds); event()->Wait(kTestTimeOut);
StopRecording(); StopRecording();
PreTearDown(); PreTearDown();
} }
@ -1117,7 +1117,7 @@ TEST_P(MAYBE_AudioDeviceTest, MAYBE_StartPlayoutAndRecordingVerifyCallbacks) {
EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock));
StartPlayout(); StartPlayout();
StartRecording(); StartRecording();
event()->Wait(kTestTimeOutInMilliseconds); event()->Wait(kTestTimeOut);
StopRecording(); StopRecording();
StopPlayout(); StopPlayout();
PreTearDown(); PreTearDown();
@ -1140,7 +1140,7 @@ TEST_P(MAYBE_AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) {
NiceMock<MockAudioTransport> mock(TransportType::kPlayAndRecord); NiceMock<MockAudioTransport> mock(TransportType::kPlayAndRecord);
FifoAudioStream audio_stream; FifoAudioStream audio_stream;
mock.HandleCallbacks(event(), &audio_stream, mock.HandleCallbacks(event(), &audio_stream,
kFullDuplexTimeInSec * kNumCallbacksPerSecond); kFullDuplexTime.seconds() * kNumCallbacksPerSecond);
EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock));
// Run both sides using the same channel configuration to avoid conversions // Run both sides using the same channel configuration to avoid conversions
// between mono/stereo while running in full duplex mode. Also, some devices // between mono/stereo while running in full duplex mode. Also, some devices
@ -1151,8 +1151,7 @@ TEST_P(MAYBE_AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) {
EXPECT_EQ(0, audio_device()->SetSpeakerVolume(0)); EXPECT_EQ(0, audio_device()->SetSpeakerVolume(0));
StartPlayout(); StartPlayout();
StartRecording(); StartRecording();
event()->Wait(static_cast<int>( event()->Wait(std::max(kTestTimeOut, kFullDuplexTime));
std::max(kTestTimeOutInMilliseconds, 1000 * kFullDuplexTimeInSec)));
StopRecording(); StopRecording();
StopPlayout(); StopPlayout();
PreTearDown(); PreTearDown();
@ -1204,14 +1203,13 @@ TEST_P(MAYBE_AudioDeviceTest, DISABLED_MeasureLoopbackLatency) {
NiceMock<MockAudioTransport> mock(TransportType::kPlayAndRecord); NiceMock<MockAudioTransport> mock(TransportType::kPlayAndRecord);
LatencyAudioStream audio_stream; LatencyAudioStream audio_stream;
mock.HandleCallbacks(event(), &audio_stream, mock.HandleCallbacks(event(), &audio_stream,
kMeasureLatencyTimeInSec * kNumCallbacksPerSecond); kMeasureLatencyTime.seconds() * kNumCallbacksPerSecond);
EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock));
EXPECT_EQ(0, audio_device()->SetStereoPlayout(true)); EXPECT_EQ(0, audio_device()->SetStereoPlayout(true));
EXPECT_EQ(0, audio_device()->SetStereoRecording(true)); EXPECT_EQ(0, audio_device()->SetStereoRecording(true));
StartPlayout(); StartPlayout();
StartRecording(); StartRecording();
event()->Wait(static_cast<int>( event()->Wait(std::max(kTestTimeOut, kMeasureLatencyTime));
std::max(kTestTimeOutInMilliseconds, 1000 * kMeasureLatencyTimeInSec)));
StopRecording(); StopRecording();
StopPlayout(); StopPlayout();
// Avoid concurrent access to audio_stream. // Avoid concurrent access to audio_stream.
@ -1219,7 +1217,7 @@ TEST_P(MAYBE_AudioDeviceTest, DISABLED_MeasureLoopbackLatency) {
// Verify that a sufficient number of transmitted impulses are detected. // Verify that a sufficient number of transmitted impulses are detected.
EXPECT_GE(audio_stream.num_latency_values(), EXPECT_GE(audio_stream.num_latency_values(),
static_cast<size_t>( static_cast<size_t>(
kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 2)); kImpulseFrequencyInHz * kMeasureLatencyTime.seconds() - 2));
// Print out min, max and average delay values for debugging purposes. // Print out min, max and average delay values for debugging purposes.
audio_stream.PrintResults(); audio_stream.PrintResults();
} }

View File

@ -142,10 +142,9 @@ class TestAudioDeviceModuleImpl
return capturing_; return capturing_;
} }
// Blocks until the Recorder stops producing data. // Blocks forever until the Recorder stops producing data.
// Returns false if `timeout_ms` passes before that happens. void WaitForRecordingEnd() override {
bool WaitForRecordingEnd() override { done_capturing_.Wait(rtc::Event::kForever);
return done_capturing_.Wait(rtc::Event::kForever);
} }
private: private:

View File

@ -140,9 +140,8 @@ class TestAudioDeviceModule : public AudioDeviceModule {
bool Playing() const override = 0; bool Playing() const override = 0;
bool Recording() const override = 0; bool Recording() const override = 0;
// Blocks until the Recorder stops producing data. // Blocks forever until the Recorder stops producing data.
// Returns false if `timeout_ms` passes before that happens. virtual void WaitForRecordingEnd() = 0;
virtual bool WaitForRecordingEnd() = 0;
}; };
} // namespace webrtc } // namespace webrtc

View File

@ -1059,7 +1059,7 @@ int32_t AudioDeviceLinuxPulse::StartRecording() {
// The audio thread will signal when recording has started. // The audio thread will signal when recording has started.
_timeEventRec.Set(); _timeEventRec.Set();
if (!_recStartEvent.Wait(10000)) { if (!_recStartEvent.Wait(TimeDelta::Seconds(10))) {
{ {
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
_startRec = false; _startRec = false;
@ -1174,7 +1174,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() {
// The audio thread will signal when playout has started. // The audio thread will signal when playout has started.
_timeEventPlay.Set(); _timeEventPlay.Set();
if (!_playStartEvent.Wait(10000)) { if (!_playStartEvent.Wait(TimeDelta::Seconds(10))) {
{ {
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
_startPlay = false; _startPlay = false;
@ -1977,7 +1977,7 @@ int32_t AudioDeviceLinuxPulse::ProcessRecordedData(int8_t* bufferData,
} }
bool AudioDeviceLinuxPulse::PlayThreadProcess() { bool AudioDeviceLinuxPulse::PlayThreadProcess() {
if (!_timeEventPlay.Wait(1000)) { if (!_timeEventPlay.Wait(TimeDelta::Seconds(1))) {
return true; return true;
} }
@ -2149,7 +2149,7 @@ bool AudioDeviceLinuxPulse::PlayThreadProcess() {
} }
bool AudioDeviceLinuxPulse::RecThreadProcess() { bool AudioDeviceLinuxPulse::RecThreadProcess() {
if (!_timeEventRec.Wait(1000)) { if (!_timeEventRec.Wait(TimeDelta::Seconds(1))) {
return true; return true;
} }

View File

@ -1357,7 +1357,7 @@ int32_t AudioDeviceMac::StopRecording() {
_recording = false; _recording = false;
_doStop = true; // Signal to io proc to stop audio device _doStop = true; // Signal to io proc to stop audio device
mutex_.Unlock(); // Cannot be under lock, risk of deadlock mutex_.Unlock(); // Cannot be under lock, risk of deadlock
if (!_stopEvent.Wait(2000)) { if (!_stopEvent.Wait(TimeDelta::Seconds(2))) {
MutexLock lockScoped(&mutex_); MutexLock lockScoped(&mutex_);
RTC_LOG(LS_WARNING) << "Timed out stopping the shared IOProc." RTC_LOG(LS_WARNING) << "Timed out stopping the shared IOProc."
"We may have failed to detect a device removal."; "We may have failed to detect a device removal.";
@ -1467,7 +1467,7 @@ int32_t AudioDeviceMac::StopPlayout() {
_playing = false; _playing = false;
_doStop = true; // Signal to io proc to stop audio device _doStop = true; // Signal to io proc to stop audio device
mutex_.Unlock(); // Cannot be under lock, risk of deadlock mutex_.Unlock(); // Cannot be under lock, risk of deadlock
if (!_stopEvent.Wait(2000)) { if (!_stopEvent.Wait(TimeDelta::Seconds(2))) {
MutexLock lockScoped(&mutex_); MutexLock lockScoped(&mutex_);
RTC_LOG(LS_WARNING) << "Timed out stopping the render IOProc." RTC_LOG(LS_WARNING) << "Timed out stopping the render IOProc."
"We may have failed to detect a device removal."; "We may have failed to detect a device removal.";

View File

@ -27,7 +27,7 @@ namespace webrtc {
namespace { namespace {
constexpr int kMaxFrameSize = 480; constexpr int kMaxFrameSize = 480;
constexpr int kTestTimeOutLimit = 10 * 60 * 1000; constexpr TimeDelta kTestTimeOutLimit = TimeDelta::Minutes(10);
class AudioProcessingImplLockTest; class AudioProcessingImplLockTest;

View File

@ -426,7 +426,8 @@ class CallSimulator : public ::testing::TestWithParam<SimulationConfig> {
static const float kCaptureInputFloatLevel; static const float kCaptureInputFloatLevel;
static const float kRenderInputFloatLevel; static const float kRenderInputFloatLevel;
static const int kMinNumFramesToProcess = 150; static const int kMinNumFramesToProcess = 150;
static const int32_t kTestTimeout = 3 * 10 * kMinNumFramesToProcess; static constexpr TimeDelta kTestTimeout =
TimeDelta::Millis(3 * 10 * kMinNumFramesToProcess);
// Stop all running threads. // Stop all running threads.
void StopThreads() { void StopThreads() {

View File

@ -13,6 +13,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "api/units/time_delta.h"
#include "api/units/timestamp.h" #include "api/units/timestamp.h"
#include "modules/rtp_rtcp/source/rtcp_packet/remote_estimate.h" #include "modules/rtp_rtcp/source/rtcp_packet/remote_estimate.h"
#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h" #include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
@ -52,12 +53,12 @@ class MockMediaReceiverRtcpObserver : public webrtc::MediaReceiverRtcpObserver {
(override)); (override));
}; };
constexpr int kTimeoutMs = 1000; constexpr webrtc::TimeDelta kTimeout = webrtc::TimeDelta::Seconds(1);
void WaitPostedTasks(TaskQueueForTest* queue) { void WaitPostedTasks(TaskQueueForTest* queue) {
rtc::Event done; rtc::Event done;
queue->PostTask([&done] { done.Set(); }); queue->PostTask([&done] { done.Set(); });
ASSERT_TRUE(done.Wait(kTimeoutMs)); ASSERT_TRUE(done.Wait(kTimeout));
} }
TEST(RtcpTransceiverTest, SendsRtcpOnTaskQueueWhenCreatedOffTaskQueue) { TEST(RtcpTransceiverTest, SendsRtcpOnTaskQueueWhenCreatedOffTaskQueue) {
@ -133,13 +134,13 @@ TEST(RtcpTransceiverTest, CanBeDestroyedWithoutBlocking) {
rtc::Event done; rtc::Event done;
rtc::Event heavy_task; rtc::Event heavy_task;
queue.PostTask([&] { queue.PostTask([&] {
EXPECT_TRUE(heavy_task.Wait(kTimeoutMs)); EXPECT_TRUE(heavy_task.Wait(kTimeout));
done.Set(); done.Set();
}); });
delete rtcp_transceiver; delete rtcp_transceiver;
heavy_task.Set(); heavy_task.Set();
EXPECT_TRUE(done.Wait(kTimeoutMs)); EXPECT_TRUE(done.Wait(kTimeout));
} }
TEST(RtcpTransceiverTest, MaySendPacketsAfterDestructor) { // i.e. Be careful! TEST(RtcpTransceiverTest, MaySendPacketsAfterDestructor) { // i.e. Be careful!
@ -153,7 +154,7 @@ TEST(RtcpTransceiverTest, MaySendPacketsAfterDestructor) { // i.e. Be careful!
auto* rtcp_transceiver = new RtcpTransceiver(config); auto* rtcp_transceiver = new RtcpTransceiver(config);
rtc::Event heavy_task; rtc::Event heavy_task;
queue.PostTask([&] { EXPECT_TRUE(heavy_task.Wait(kTimeoutMs)); }); queue.PostTask([&] { EXPECT_TRUE(heavy_task.Wait(kTimeout)); });
rtcp_transceiver->SendCompoundPacket(); rtcp_transceiver->SendCompoundPacket();
delete rtcp_transceiver; delete rtcp_transceiver;
@ -199,7 +200,7 @@ TEST(RtcpTransceiverTest, DoesntPostToRtcpObserverAfterCallToRemove) {
}); });
rtcp_transceiver.ReceivePacket(CreateSenderReport(kRemoteSsrc, 2)); rtcp_transceiver.ReceivePacket(CreateSenderReport(kRemoteSsrc, 2));
EXPECT_TRUE(observer_deleted.Wait(kTimeoutMs)); EXPECT_TRUE(observer_deleted.Wait(kTimeout));
WaitPostedTasks(&queue); WaitPostedTasks(&queue);
} }
@ -218,7 +219,7 @@ TEST(RtcpTransceiverTest, RemoveMediaReceiverRtcpObserverIsNonBlocking) {
rtc::Event queue_blocker; rtc::Event queue_blocker;
rtc::Event observer_deleted; rtc::Event observer_deleted;
queue.PostTask([&] { EXPECT_TRUE(queue_blocker.Wait(kTimeoutMs)); }); queue.PostTask([&] { EXPECT_TRUE(queue_blocker.Wait(kTimeout)); });
rtcp_transceiver.RemoveMediaReceiverRtcpObserver(kRemoteSsrc, observer.get(), rtcp_transceiver.RemoveMediaReceiverRtcpObserver(kRemoteSsrc, observer.get(),
/*on_removed=*/[&] { /*on_removed=*/[&] {
observer.reset(); observer.reset();
@ -227,7 +228,7 @@ TEST(RtcpTransceiverTest, RemoveMediaReceiverRtcpObserverIsNonBlocking) {
EXPECT_THAT(observer, Not(IsNull())); EXPECT_THAT(observer, Not(IsNull()));
queue_blocker.Set(); queue_blocker.Set();
EXPECT_TRUE(observer_deleted.Wait(kTimeoutMs)); EXPECT_TRUE(observer_deleted.Wait(kTimeout));
} }
TEST(RtcpTransceiverTest, CanCallSendCompoundPacketFromAnyThread) { TEST(RtcpTransceiverTest, CanCallSendCompoundPacketFromAnyThread) {
@ -279,7 +280,7 @@ TEST(RtcpTransceiverTest, DoesntSendPacketsAfterStopCallback) {
done.Set(); done.Set();
}); });
rtcp_transceiver = nullptr; rtcp_transceiver = nullptr;
EXPECT_TRUE(done.Wait(kTimeoutMs)); EXPECT_TRUE(done.Wait(kTimeout));
} }
TEST(RtcpTransceiverTest, SendsCombinedRtcpPacketOnTaskQueue) { TEST(RtcpTransceiverTest, SendsCombinedRtcpPacketOnTaskQueue) {

View File

@ -18,8 +18,10 @@
#include "modules/video_coding/include/video_error_codes.h" #include "modules/video_coding/include/video_error_codes.h"
#include "test/video_codec_settings.h" #include "test/video_codec_settings.h"
static const int kEncodeTimeoutMs = 100; static constexpr webrtc::TimeDelta kEncodeTimeout =
static const int kDecodeTimeoutMs = 25; webrtc::TimeDelta::Millis(100);
static constexpr webrtc::TimeDelta kDecodeTimeout =
webrtc::TimeDelta::Millis(25);
// Set bitrate to get higher quality. // Set bitrate to get higher quality.
static const int kStartBitrate = 300; static const int kStartBitrate = 300;
static const int kMaxBitrate = 4000; static const int kMaxBitrate = 4000;
@ -136,7 +138,7 @@ void VideoCodecUnitTest::SetWaitForEncodedFramesThreshold(size_t num_frames) {
bool VideoCodecUnitTest::WaitForEncodedFrames( bool VideoCodecUnitTest::WaitForEncodedFrames(
std::vector<EncodedImage>* frames, std::vector<EncodedImage>* frames,
std::vector<CodecSpecificInfo>* codec_specific_info) { std::vector<CodecSpecificInfo>* codec_specific_info) {
EXPECT_TRUE(encoded_frame_event_.Wait(kEncodeTimeoutMs)) EXPECT_TRUE(encoded_frame_event_.Wait(kEncodeTimeout))
<< "Timed out while waiting for encoded frame."; << "Timed out while waiting for encoded frame.";
// This becomes unsafe if there are multiple threads waiting for frames. // This becomes unsafe if there are multiple threads waiting for frames.
MutexLock lock(&encoded_frame_section_); MutexLock lock(&encoded_frame_section_);
@ -157,7 +159,7 @@ bool VideoCodecUnitTest::WaitForEncodedFrames(
bool VideoCodecUnitTest::WaitForDecodedFrame(std::unique_ptr<VideoFrame>* frame, bool VideoCodecUnitTest::WaitForDecodedFrame(std::unique_ptr<VideoFrame>* frame,
absl::optional<uint8_t>* qp) { absl::optional<uint8_t>* qp) {
bool ret = decoded_frame_event_.Wait(kDecodeTimeoutMs); bool ret = decoded_frame_event_.Wait(kDecodeTimeout);
EXPECT_TRUE(ret) << "Timed out while waiting for a decoded frame."; EXPECT_TRUE(ret) << "Timed out while waiting for a decoded frame.";
// This becomes unsafe if there are multiple threads waiting for frames. // This becomes unsafe if there are multiple threads waiting for frames.
MutexLock lock(&decoded_frame_section_); MutexLock lock(&decoded_frame_section_);

View File

@ -23,8 +23,10 @@ class EventWrapperImpl : public EventWrapper {
return true; return true;
} }
// TODO(bugs.webrtc.org/14366): Migrate to TimeDelta.
EventTypeWrapper Wait(int max_time_ms) override { EventTypeWrapper Wait(int max_time_ms) override {
return event_.Wait(max_time_ms) ? kEventSignaled : kEventTimeout; return event_.Wait(TimeDelta::Millis(max_time_ms)) ? kEventSignaled
: kEventTimeout;
} }
private: private:

View File

@ -38,6 +38,7 @@ class EventWrapper {
// Depending on timing. // Depending on timing.
// //
// `max_time_ms` is the maximum time to wait in milliseconds. // `max_time_ms` is the maximum time to wait in milliseconds.
// TODO(bugs.webrtc.org/14366): Migrate to TimeDelta.
virtual EventTypeWrapper Wait(int max_time_ms) = 0; virtual EventTypeWrapper Wait(int max_time_ms) = 0;
}; };

View File

@ -13,6 +13,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "api/units/time_delta.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/experiments/encoder_info_settings.h" #include "rtc_base/experiments/encoder_info_settings.h"
@ -25,8 +26,8 @@ namespace webrtc {
namespace { namespace {
constexpr int kFramerateFps = 30; constexpr int kFramerateFps = 30;
constexpr int kDefaultBitrateStateUpdateIntervalSeconds = 5; constexpr TimeDelta kDefaultBitrateStateUpdateInterval = TimeDelta::Seconds(5);
constexpr int kDefaultEncodeDeltaTimeMs = 33; // 1/30(s) => 33(ms) constexpr TimeDelta kDefaultEncodeTime = TimeDelta::Seconds(1) / kFramerateFps;
} // namespace } // namespace
@ -158,8 +159,9 @@ class BandwidthQualityScalerTest
total_frame_nums += frame_config.frame_num; total_frame_nums += frame_config.frame_num;
} }
EXPECT_EQ(kFramerateFps * kDefaultBitrateStateUpdateIntervalSeconds, EXPECT_EQ(
total_frame_nums); kFramerateFps * kDefaultBitrateStateUpdateInterval.seconds(),
total_frame_nums);
uint32_t time_send_to_scaler_ms_ = rtc::TimeMillis(); uint32_t time_send_to_scaler_ms_ = rtc::TimeMillis();
for (size_t i = 0; i < frame_configs.size(); ++i) { for (size_t i = 0; i < frame_configs.size(); ++i) {
@ -169,7 +171,7 @@ class BandwidthQualityScalerTest
config.actual_width * config.actual_height); config.actual_width * config.actual_height);
EXPECT_TRUE(suitable_bitrate); EXPECT_TRUE(suitable_bitrate);
for (int j = 0; j <= config.frame_num; ++j) { for (int j = 0; j <= config.frame_num; ++j) {
time_send_to_scaler_ms_ += kDefaultEncodeDeltaTimeMs; time_send_to_scaler_ms_ += kDefaultEncodeTime.ms();
int frame_size_bytes = int frame_size_bytes =
GetFrameSizeBytes(config, suitable_bitrate.value()); GetFrameSizeBytes(config, suitable_bitrate.value());
RTC_CHECK(frame_size_bytes > 0); RTC_CHECK(frame_size_bytes > 0);
@ -203,8 +205,8 @@ TEST_P(BandwidthQualityScalerTest, AllNormalFrame_640x360) {
// When resolution is 640*360, experimental working bitrate range is // When resolution is 640*360, experimental working bitrate range is
// [500000,800000] bps. Encoded bitrate is 654253, so it falls in the range // [500000,800000] bps. Encoded bitrate is 654253, so it falls in the range
// without any operation(up/down). // without any operation(up/down).
EXPECT_FALSE(handler_->event_.Wait( EXPECT_FALSE(handler_->event_.Wait(TimeDelta::Millis(
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())); bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())));
EXPECT_EQ(0, handler_->adapt_down_event_count_); EXPECT_EQ(0, handler_->adapt_down_event_count_);
EXPECT_EQ(0, handler_->adapt_up_event_count_); EXPECT_EQ(0, handler_->adapt_up_event_count_);
} }
@ -217,8 +219,8 @@ TEST_P(BandwidthQualityScalerTest, AllNoramlFrame_AboveMaxBandwidth_640x360) {
// When resolution is 640*360, experimental working bitrate range is // When resolution is 640*360, experimental working bitrate range is
// [500000,800000] bps. Encoded bitrate is 1208000 > 800000 * 0.95, so it // [500000,800000] bps. Encoded bitrate is 1208000 > 800000 * 0.95, so it
// triggers adapt_up_event_count_. // triggers adapt_up_event_count_.
EXPECT_TRUE(handler_->event_.Wait( EXPECT_TRUE(handler_->event_.Wait(TimeDelta::Millis(
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())); bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())));
EXPECT_EQ(0, handler_->adapt_down_event_count_); EXPECT_EQ(0, handler_->adapt_down_event_count_);
EXPECT_EQ(1, handler_->adapt_up_event_count_); EXPECT_EQ(1, handler_->adapt_up_event_count_);
} }
@ -231,8 +233,8 @@ TEST_P(BandwidthQualityScalerTest, AllNormalFrame_Underuse_640x360) {
// When resolution is 640*360, experimental working bitrate range is // When resolution is 640*360, experimental working bitrate range is
// [500000,800000] bps. Encoded bitrate is 377379 < 500000 * 0.8, so it // [500000,800000] bps. Encoded bitrate is 377379 < 500000 * 0.8, so it
// triggers adapt_down_event_count_. // triggers adapt_down_event_count_.
EXPECT_TRUE(handler_->event_.Wait( EXPECT_TRUE(handler_->event_.Wait(TimeDelta::Millis(
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())); bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())));
EXPECT_EQ(1, handler_->adapt_down_event_count_); EXPECT_EQ(1, handler_->adapt_down_event_count_);
EXPECT_EQ(0, handler_->adapt_up_event_count_); EXPECT_EQ(0, handler_->adapt_up_event_count_);
} }
@ -249,8 +251,8 @@ TEST_P(BandwidthQualityScalerTest, FixedFrameTypeTest1_640x360) {
// When resolution is 640*360, experimental working bitrate range is // When resolution is 640*360, experimental working bitrate range is
// [500000,800000] bps. Encoded bitrate is 1059462 > 800000 * 0.95, so it // [500000,800000] bps. Encoded bitrate is 1059462 > 800000 * 0.95, so it
// triggers adapt_up_event_count_. // triggers adapt_up_event_count_.
EXPECT_TRUE(handler_->event_.Wait( EXPECT_TRUE(handler_->event_.Wait(TimeDelta::Millis(
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())); bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())));
EXPECT_EQ(0, handler_->adapt_down_event_count_); EXPECT_EQ(0, handler_->adapt_down_event_count_);
EXPECT_EQ(1, handler_->adapt_up_event_count_); EXPECT_EQ(1, handler_->adapt_up_event_count_);
} }
@ -267,8 +269,8 @@ TEST_P(BandwidthQualityScalerTest, FixedFrameTypeTest2_640x360) {
// When resolution is 640*360, experimental working bitrate range is // When resolution is 640*360, experimental working bitrate range is
// [500000,800000] bps. Encoded bitrate is 1059462 > 800000 * 0.95, so it // [500000,800000] bps. Encoded bitrate is 1059462 > 800000 * 0.95, so it
// triggers adapt_up_event_count_. // triggers adapt_up_event_count_.
EXPECT_TRUE(handler_->event_.Wait( EXPECT_TRUE(handler_->event_.Wait(TimeDelta::Millis(
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())); bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs())));
EXPECT_EQ(0, handler_->adapt_down_event_count_); EXPECT_EQ(0, handler_->adapt_down_event_count_);
EXPECT_EQ(1, handler_->adapt_up_event_count_); EXPECT_EQ(1, handler_->adapt_up_event_count_);
} }

View File

@ -13,6 +13,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "api/units/time_delta.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/task_queue_for_test.h" #include "rtc_base/task_queue_for_test.h"
@ -25,7 +26,7 @@ static const int kFramerate = 30;
static const int kLowQp = 15; static const int kLowQp = 15;
static const int kHighQp = 40; static const int kHighQp = 40;
static const int kMinFramesNeededToScale = 60; // From quality_scaler.cc. static const int kMinFramesNeededToScale = 60; // From quality_scaler.cc.
static const size_t kDefaultTimeoutMs = 150; static constexpr TimeDelta kDefaultTimeout = TimeDelta::Millis(150);
} // namespace } // namespace
class FakeQpUsageHandler : public QualityScalerQpUsageHandlerInterface { class FakeQpUsageHandler : public QualityScalerQpUsageHandlerInterface {
@ -119,21 +120,21 @@ INSTANTIATE_TEST_SUITE_P(
TEST_P(QualityScalerTest, DownscalesAfterContinuousFramedrop) { TEST_P(QualityScalerTest, DownscalesAfterContinuousFramedrop) {
task_queue_.SendTask([this] { TriggerScale(kScaleDown); }); task_queue_.SendTask([this] { TriggerScale(kScaleDown); });
EXPECT_TRUE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(1, handler_->adapt_down_events_); EXPECT_EQ(1, handler_->adapt_down_events_);
EXPECT_EQ(0, handler_->adapt_up_events_); EXPECT_EQ(0, handler_->adapt_up_events_);
} }
TEST_P(QualityScalerTest, KeepsScaleAtHighQp) { TEST_P(QualityScalerTest, KeepsScaleAtHighQp) {
task_queue_.SendTask([this] { TriggerScale(kKeepScaleAtHighQp); }); task_queue_.SendTask([this] { TriggerScale(kKeepScaleAtHighQp); });
EXPECT_FALSE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_FALSE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(0, handler_->adapt_down_events_); EXPECT_EQ(0, handler_->adapt_down_events_);
EXPECT_EQ(0, handler_->adapt_up_events_); EXPECT_EQ(0, handler_->adapt_up_events_);
} }
TEST_P(QualityScalerTest, DownscalesAboveHighQp) { TEST_P(QualityScalerTest, DownscalesAboveHighQp) {
task_queue_.SendTask([this] { TriggerScale(kScaleDownAboveHighQp); }); task_queue_.SendTask([this] { TriggerScale(kScaleDownAboveHighQp); });
EXPECT_TRUE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(1, handler_->adapt_down_events_); EXPECT_EQ(1, handler_->adapt_down_events_);
EXPECT_EQ(0, handler_->adapt_up_events_); EXPECT_EQ(0, handler_->adapt_up_events_);
} }
@ -146,7 +147,7 @@ TEST_P(QualityScalerTest, DownscalesAfterTwoThirdsFramedrop) {
qs_->ReportQp(kHighQp, 0); qs_->ReportQp(kHighQp, 0);
} }
}); });
EXPECT_TRUE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(1, handler_->adapt_down_events_); EXPECT_EQ(1, handler_->adapt_down_events_);
EXPECT_EQ(0, handler_->adapt_up_events_); EXPECT_EQ(0, handler_->adapt_up_events_);
} }
@ -158,7 +159,7 @@ TEST_P(QualityScalerTest, DoesNotDownscaleAfterHalfFramedrop) {
qs_->ReportQp(kHighQp, 0); qs_->ReportQp(kHighQp, 0);
} }
}); });
EXPECT_FALSE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_FALSE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(0, handler_->adapt_down_events_); EXPECT_EQ(0, handler_->adapt_down_events_);
EXPECT_EQ(0, handler_->adapt_up_events_); EXPECT_EQ(0, handler_->adapt_up_events_);
} }
@ -173,32 +174,32 @@ TEST_P(QualityScalerTest, DownscalesAfterTwoThirdsIfFieldTrialEnabled) {
qs_->ReportQp(kHighQp, 0); qs_->ReportQp(kHighQp, 0);
} }
}); });
EXPECT_EQ(kDownScaleExpected, handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_EQ(kDownScaleExpected, handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(kDownScaleExpected ? 1 : 0, handler_->adapt_down_events_); EXPECT_EQ(kDownScaleExpected ? 1 : 0, handler_->adapt_down_events_);
EXPECT_EQ(0, handler_->adapt_up_events_); EXPECT_EQ(0, handler_->adapt_up_events_);
} }
TEST_P(QualityScalerTest, KeepsScaleOnNormalQp) { TEST_P(QualityScalerTest, KeepsScaleOnNormalQp) {
task_queue_.SendTask([this] { TriggerScale(kKeepScaleAboveLowQp); }); task_queue_.SendTask([this] { TriggerScale(kKeepScaleAboveLowQp); });
EXPECT_FALSE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_FALSE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(0, handler_->adapt_down_events_); EXPECT_EQ(0, handler_->adapt_down_events_);
EXPECT_EQ(0, handler_->adapt_up_events_); EXPECT_EQ(0, handler_->adapt_up_events_);
} }
TEST_P(QualityScalerTest, UpscalesAfterLowQp) { TEST_P(QualityScalerTest, UpscalesAfterLowQp) {
task_queue_.SendTask([this] { TriggerScale(kScaleUp); }); task_queue_.SendTask([this] { TriggerScale(kScaleUp); });
EXPECT_TRUE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(0, handler_->adapt_down_events_); EXPECT_EQ(0, handler_->adapt_down_events_);
EXPECT_EQ(1, handler_->adapt_up_events_); EXPECT_EQ(1, handler_->adapt_up_events_);
} }
TEST_P(QualityScalerTest, ScalesDownAndBackUp) { TEST_P(QualityScalerTest, ScalesDownAndBackUp) {
task_queue_.SendTask([this] { TriggerScale(kScaleDown); }); task_queue_.SendTask([this] { TriggerScale(kScaleDown); });
EXPECT_TRUE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(1, handler_->adapt_down_events_); EXPECT_EQ(1, handler_->adapt_down_events_);
EXPECT_EQ(0, handler_->adapt_up_events_); EXPECT_EQ(0, handler_->adapt_up_events_);
task_queue_.SendTask([this] { TriggerScale(kScaleUp); }); task_queue_.SendTask([this] { TriggerScale(kScaleUp); });
EXPECT_TRUE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(1, handler_->adapt_down_events_); EXPECT_EQ(1, handler_->adapt_down_events_);
EXPECT_EQ(1, handler_->adapt_up_events_); EXPECT_EQ(1, handler_->adapt_up_events_);
} }
@ -210,13 +211,13 @@ TEST_P(QualityScalerTest, DoesNotScaleUntilEnoughFramesObserved) {
qs_->ReportQp(kLowQp, 0); qs_->ReportQp(kLowQp, 0);
} }
}); });
EXPECT_FALSE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_FALSE(handler_->event.Wait(kDefaultTimeout));
task_queue_.SendTask([this] { task_queue_.SendTask([this] {
// Send 1 more. Enough frames observed, should result in an adapt // Send 1 more. Enough frames observed, should result in an adapt
// request. // request.
qs_->ReportQp(kLowQp, 0); qs_->ReportQp(kLowQp, 0);
}); });
EXPECT_TRUE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(0, handler_->adapt_down_events_); EXPECT_EQ(0, handler_->adapt_down_events_);
EXPECT_EQ(1, handler_->adapt_up_events_); EXPECT_EQ(1, handler_->adapt_up_events_);
@ -225,7 +226,7 @@ TEST_P(QualityScalerTest, DoesNotScaleUntilEnoughFramesObserved) {
// Not enough frames to make a decision. // Not enough frames to make a decision.
qs_->ReportQp(kLowQp, 0); qs_->ReportQp(kLowQp, 0);
}); });
EXPECT_FALSE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_FALSE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(0, handler_->adapt_down_events_); EXPECT_EQ(0, handler_->adapt_down_events_);
EXPECT_EQ(1, handler_->adapt_up_events_); EXPECT_EQ(1, handler_->adapt_up_events_);
} }
@ -236,7 +237,7 @@ TEST_P(QualityScalerTest, ScalesDownAndBackUpWithMinFramesNeeded) {
qs_->ReportQp(kHighQp + 1, 0); qs_->ReportQp(kHighQp + 1, 0);
} }
}); });
EXPECT_TRUE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(1, handler_->adapt_down_events_); EXPECT_EQ(1, handler_->adapt_down_events_);
EXPECT_EQ(0, handler_->adapt_up_events_); EXPECT_EQ(0, handler_->adapt_up_events_);
// Samples cleared. // Samples cleared.
@ -245,7 +246,7 @@ TEST_P(QualityScalerTest, ScalesDownAndBackUpWithMinFramesNeeded) {
qs_->ReportQp(kLowQp, 0); qs_->ReportQp(kLowQp, 0);
} }
}); });
EXPECT_TRUE(handler_->event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(handler_->event.Wait(kDefaultTimeout));
EXPECT_EQ(1, handler_->adapt_down_events_); EXPECT_EQ(1, handler_->adapt_down_events_);
EXPECT_EQ(1, handler_->adapt_up_events_); EXPECT_EQ(1, handler_->adapt_up_events_);
} }

View File

@ -569,7 +569,7 @@ TEST_F(PeerConnectionFactoryTest, LocalRendering) {
} }
TEST(PeerConnectionFactoryDependenciesTest, UsesNetworkManager) { TEST(PeerConnectionFactoryDependenciesTest, UsesNetworkManager) {
constexpr int64_t kWaitTimeoutMs = 10000; constexpr webrtc::TimeDelta kWaitTimeout = webrtc::TimeDelta::Seconds(10);
auto mock_network_manager = std::make_unique<NiceMock<MockNetworkManager>>(); auto mock_network_manager = std::make_unique<NiceMock<MockNetworkManager>>();
rtc::Event called; rtc::Event called;
@ -590,11 +590,11 @@ TEST(PeerConnectionFactoryDependenciesTest, UsesNetworkManager) {
config, webrtc::PeerConnectionDependencies(&observer)); config, webrtc::PeerConnectionDependencies(&observer));
ASSERT_TRUE(pc.ok()); ASSERT_TRUE(pc.ok());
called.Wait(kWaitTimeoutMs); called.Wait(kWaitTimeout);
} }
TEST(PeerConnectionFactoryDependenciesTest, UsesPacketSocketFactory) { TEST(PeerConnectionFactoryDependenciesTest, UsesPacketSocketFactory) {
constexpr int64_t kWaitTimeoutMs = 10000; constexpr webrtc::TimeDelta kWaitTimeout = webrtc::TimeDelta::Seconds(10);
auto mock_socket_factory = auto mock_socket_factory =
std::make_unique<NiceMock<rtc::MockPacketSocketFactory>>(); std::make_unique<NiceMock<rtc::MockPacketSocketFactory>>();
@ -625,5 +625,5 @@ TEST(PeerConnectionFactoryDependenciesTest, UsesPacketSocketFactory) {
config, webrtc::PeerConnectionDependencies(&observer)); config, webrtc::PeerConnectionDependencies(&observer));
ASSERT_TRUE(pc.ok()); ASSERT_TRUE(pc.ok());
called.Wait(kWaitTimeoutMs); called.Wait(kWaitTimeout);
} }

View File

@ -77,7 +77,7 @@ TaskQueueMetronome::~TaskQueueMetronome() {
tick_task_.Stop(); tick_task_.Stop();
stop_event.Set(); stop_event.Set();
}); });
stop_event.Wait(1000); stop_event.Wait(TimeDelta::Seconds(1));
} }
void TaskQueueMetronome::AddListener(TickListener* listener) { void TaskQueueMetronome::AddListener(TickListener* listener) {

View File

@ -905,6 +905,7 @@ rtc_library("null_socket_server") {
":rtc_event", ":rtc_event",
":socket", ":socket",
":socket_server", ":socket_server",
"../api/units:time_delta",
"system:rtc_export", "system:rtc_export",
] ]
} }

View File

@ -33,9 +33,9 @@ namespace rtc {
namespace { namespace {
const int kLongTime = 10000; // 10 seconds constexpr webrtc::TimeDelta kLongTime = webrtc::TimeDelta::Seconds(10);
const int kNumThreads = 16; constexpr int kNumThreads = 16;
const int kOperationsToRun = 1000; constexpr int kOperationsToRun = 1000;
class UniqueValueVerifier { class UniqueValueVerifier {
public: public:

View File

@ -123,11 +123,12 @@ class EventLogger final {
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview // https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
void Log() { void Log() {
RTC_DCHECK(output_file_); RTC_DCHECK(output_file_);
static const int kLoggingIntervalMs = 100; static constexpr webrtc::TimeDelta kLoggingInterval =
webrtc::TimeDelta::Millis(100);
fprintf(output_file_, "{ \"traceEvents\": [\n"); fprintf(output_file_, "{ \"traceEvents\": [\n");
bool has_logged_event = false; bool has_logged_event = false;
while (true) { while (true) {
bool shutting_down = shutdown_event_.Wait(kLoggingIntervalMs); bool shutting_down = shutdown_event_.Wait(kLoggingInterval);
std::vector<TraceEvent> events; std::vector<TraceEvent> events;
{ {
webrtc::MutexLock lock(&mutex_); webrtc::MutexLock lock(&mutex_);

View File

@ -10,6 +10,7 @@
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "api/units/time_delta.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#include "test/gtest.h" #include "test/gtest.h"
@ -18,28 +19,28 @@ namespace rtc {
TEST(EventTest, InitiallySignaled) { TEST(EventTest, InitiallySignaled) {
Event event(false, true); Event event(false, true);
ASSERT_TRUE(event.Wait(0)); ASSERT_TRUE(event.Wait(webrtc::TimeDelta::Zero()));
} }
TEST(EventTest, ManualReset) { TEST(EventTest, ManualReset) {
Event event(true, false); Event event(true, false);
ASSERT_FALSE(event.Wait(0)); ASSERT_FALSE(event.Wait(webrtc::TimeDelta::Zero()));
event.Set(); event.Set();
ASSERT_TRUE(event.Wait(0)); ASSERT_TRUE(event.Wait(webrtc::TimeDelta::Zero()));
ASSERT_TRUE(event.Wait(0)); ASSERT_TRUE(event.Wait(webrtc::TimeDelta::Zero()));
event.Reset(); event.Reset();
ASSERT_FALSE(event.Wait(0)); ASSERT_FALSE(event.Wait(webrtc::TimeDelta::Zero()));
} }
TEST(EventTest, AutoReset) { TEST(EventTest, AutoReset) {
Event event; Event event;
ASSERT_FALSE(event.Wait(0)); ASSERT_FALSE(event.Wait(webrtc::TimeDelta::Zero()));
event.Set(); event.Set();
ASSERT_TRUE(event.Wait(0)); ASSERT_TRUE(event.Wait(webrtc::TimeDelta::Zero()));
ASSERT_FALSE(event.Wait(0)); ASSERT_FALSE(event.Wait(webrtc::TimeDelta::Zero()));
} }
class SignalerThread { class SignalerThread {
@ -49,7 +50,7 @@ class SignalerThread {
reader_ = reader; reader_ = reader;
thread_ = PlatformThread::SpawnJoinable( thread_ = PlatformThread::SpawnJoinable(
[this] { [this] {
while (!stop_event_.Wait(0)) { while (!stop_event_.Wait(webrtc::TimeDelta::Zero())) {
writer_->Set(); writer_->Set();
reader_->Wait(Event::kForever); reader_->Wait(Event::kForever);
} }
@ -81,7 +82,7 @@ TEST(EventTest, DISABLED_PerformanceSingleThread) {
Event event; Event event;
for (int i = 0; i < kNumIterations; ++i) { for (int i = 0; i < kNumIterations; ++i) {
event.Set(); event.Set();
event.Wait(0); event.Wait(webrtc::TimeDelta::Zero());
} }
} }

View File

@ -10,8 +10,10 @@
#include "rtc_base/null_socket_server.h" #include "rtc_base/null_socket_server.h"
#include "api/units/time_delta.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/socket_server.h"
namespace rtc { namespace rtc {
@ -25,7 +27,7 @@ bool NullSocketServer::Wait(int cms, bool process_io) {
event_.Wait(/*give_up_after=*/cms == kForever event_.Wait(/*give_up_after=*/cms == kForever
? Event::kForever ? Event::kForever
: webrtc::TimeDelta::Millis(cms), : webrtc::TimeDelta::Millis(cms),
/*warn_after_ms=*/Event::kForever); /*warn_after=*/Event::kForever);
return true; return true;
} }

View File

@ -246,7 +246,8 @@ TEST(OperationsChainTest, AsynchronousOperation) {
operation_tracker_proxy.PostAsynchronousOperation( operation_tracker_proxy.PostAsynchronousOperation(
&unblock_async_operation_event); &unblock_async_operation_event);
// This should not be signaled until we unblock the operation. // This should not be signaled until we unblock the operation.
EXPECT_FALSE(async_operation_completed_event->Wait(0)); EXPECT_FALSE(
async_operation_completed_event->Wait(webrtc::TimeDelta::Zero()));
// Unblock the operation and wait for it to complete. // Unblock the operation and wait for it to complete.
unblock_async_operation_event.Set(); unblock_async_operation_event.Set();
async_operation_completed_event->Wait(Event::kForever); async_operation_completed_event->Wait(Event::kForever);
@ -264,13 +265,13 @@ TEST(OperationsChainTest,
operation_tracker.BindSynchronousOperation(&event0)); operation_tracker.BindSynchronousOperation(&event0));
// This should already be signaled. (If it wasn't, waiting wouldn't help, // This should already be signaled. (If it wasn't, waiting wouldn't help,
// because we'd be blocking the only thread that exists.) // because we'd be blocking the only thread that exists.)
EXPECT_TRUE(event0.Wait(0)); EXPECT_TRUE(event0.Wait(webrtc::TimeDelta::Zero()));
// Chaining another operation should also execute immediately because the // Chaining another operation should also execute immediately because the
// chain should already be empty. // chain should already be empty.
Event event1; Event event1;
operations_chain->ChainOperation( operations_chain->ChainOperation(
operation_tracker.BindSynchronousOperation(&event1)); operation_tracker.BindSynchronousOperation(&event1));
EXPECT_TRUE(event1.Wait(0)); EXPECT_TRUE(event1.Wait(webrtc::TimeDelta::Zero()));
} }
TEST(OperationsChainTest, AsynchronousOperationBlocksSynchronousOperation) { TEST(OperationsChainTest, AsynchronousOperationBlocksSynchronousOperation) {
@ -290,7 +291,7 @@ TEST(OperationsChainTest, AsynchronousOperationBlocksSynchronousOperation) {
sync_operation_completed_event->Wait(Event::kForever); sync_operation_completed_event->Wait(Event::kForever);
// The asynchronous avent should have blocked the synchronous event, meaning // The asynchronous avent should have blocked the synchronous event, meaning
// this should already be signaled. // this should already be signaled.
EXPECT_TRUE(async_operation_completed_event->Wait(0)); EXPECT_TRUE(async_operation_completed_event->Wait(webrtc::TimeDelta::Zero()));
} }
TEST(OperationsChainTest, OperationsAreExecutedInOrder) { TEST(OperationsChainTest, OperationsAreExecutedInOrder) {

View File

@ -34,7 +34,7 @@ TEST(PlatformThreadTest, StartFinalize) {
EXPECT_FALSE(thread.empty()); EXPECT_FALSE(thread.empty());
thread.Finalize(); thread.Finalize();
EXPECT_TRUE(thread.empty()); EXPECT_TRUE(thread.empty());
done.Wait(30000); done.Wait(webrtc::TimeDelta::Seconds(30));
} }
TEST(PlatformThreadTest, MovesEmpty) { TEST(PlatformThreadTest, MovesEmpty) {
@ -54,7 +54,7 @@ TEST(PlatformThreadTest, MovesHandles) {
thread2 = std::move(thread1); thread2 = std::move(thread1);
EXPECT_TRUE(thread1.empty()); EXPECT_TRUE(thread1.empty());
EXPECT_FALSE(thread2.empty()); EXPECT_FALSE(thread2.empty());
done.Wait(30000); done.Wait(webrtc::TimeDelta::Seconds(30));
} }
TEST(PlatformThreadTest, TEST(PlatformThreadTest,
@ -81,7 +81,7 @@ TEST(PlatformThreadTest, JoinsThread) {
// This test flakes if there are problems with the join implementation. // This test flakes if there are problems with the join implementation.
rtc::Event event; rtc::Event event;
PlatformThread::SpawnJoinable([&] { event.Set(); }, "T"); PlatformThread::SpawnJoinable([&] { event.Set(); }, "T");
EXPECT_TRUE(event.Wait(/*give_up_after_ms=*/0)); EXPECT_TRUE(event.Wait(/*give_up_after=*/webrtc::TimeDelta::Zero()));
} }
TEST(PlatformThreadTest, StopsBeforeDetachedThreadExits) { TEST(PlatformThreadTest, StopsBeforeDetachedThreadExits) {

View File

@ -106,7 +106,7 @@ TEST_F(RateLimitTest, WindowSizeLimits) {
EXPECT_FALSE(rate_limiter->SetWindowSize(kWindowSizeMs + 1)); EXPECT_FALSE(rate_limiter->SetWindowSize(kWindowSizeMs + 1));
} }
static const int64_t kMaxTimeoutMs = 30000; static constexpr TimeDelta kMaxTimeout = TimeDelta::Seconds(30);
class ThreadTask { class ThreadTask {
public: public:
@ -115,7 +115,7 @@ class ThreadTask {
virtual ~ThreadTask() {} virtual ~ThreadTask() {}
void Run() { void Run() {
start_signal_.Wait(kMaxTimeoutMs); start_signal_.Wait(kMaxTimeout);
DoRun(); DoRun();
end_signal_.Set(); end_signal_.Set();
} }
@ -177,13 +177,13 @@ TEST_F(RateLimitTest, MultiThreadedUsage) {
[&use_rate_task] { use_rate_task.Run(); }, "Thread3"); [&use_rate_task] { use_rate_task.Run(); }, "Thread3");
set_window_size_task.start_signal_.Set(); set_window_size_task.start_signal_.Set();
EXPECT_TRUE(set_window_size_task.end_signal_.Wait(kMaxTimeoutMs)); EXPECT_TRUE(set_window_size_task.end_signal_.Wait(kMaxTimeout));
set_max_rate_task.start_signal_.Set(); set_max_rate_task.start_signal_.Set();
EXPECT_TRUE(set_max_rate_task.end_signal_.Wait(kMaxTimeoutMs)); EXPECT_TRUE(set_max_rate_task.end_signal_.Wait(kMaxTimeout));
use_rate_task.start_signal_.Set(); use_rate_task.start_signal_.Set();
EXPECT_TRUE(use_rate_task.end_signal_.Wait(kMaxTimeoutMs)); EXPECT_TRUE(use_rate_task.end_signal_.Wait(kMaxTimeout));
// All rate consumed. // All rate consumed.
EXPECT_FALSE(rate_limiter->TryUseRate(1)); EXPECT_FALSE(rate_limiter->TryUseRate(1));

View File

@ -129,7 +129,7 @@ class LockRunner : public rtc::MessageHandlerAutoCleanup {
} }
private: private:
static constexpr int kLongTime = 10000; // 10 seconds static constexpr TimeDelta kLongTime = TimeDelta::Seconds(10);
static constexpr int kOperationsToRun = 1000; static constexpr int kOperationsToRun = 1000;
std::atomic<int> threads_active_; std::atomic<int> threads_active_;

View File

@ -62,6 +62,7 @@ class TaskQueueStdlib final : public TaskQueueBase {
using OrderId = uint64_t; using OrderId = uint64_t;
struct DelayedEntryTimeout { struct DelayedEntryTimeout {
// TODO(bugs.webrtc.org/13756): Migrate to Timestamp.
int64_t next_fire_at_us{}; int64_t next_fire_at_us{};
OrderId order{}; OrderId order{};
@ -74,13 +75,7 @@ class TaskQueueStdlib final : public TaskQueueBase {
struct NextTask { struct NextTask {
bool final_task = false; bool final_task = false;
absl::AnyInvocable<void() &&> run_task; absl::AnyInvocable<void() &&> run_task;
// TODO(bugs.webrtc.org/14366): While transitioning to TimeDelta, WebRTC and TimeDelta sleep_time = rtc::Event::kForever;
// Chromium has a different idea about what type rtc::Event::kForever is.
// Code can't assume rtc::Event::kForever is the same type as timed wait
// arguments.
// Change `sleep_time_ms` to be explicit type, default value
// `rtc::Event::kForever` once transition is complete.
absl::optional<int64_t> sleep_time_ms;
}; };
static rtc::PlatformThread InitializeThread(TaskQueueStdlib* me, static rtc::PlatformThread InitializeThread(TaskQueueStdlib* me,
@ -224,8 +219,8 @@ TaskQueueStdlib::NextTask TaskQueueStdlib::GetNextTask() {
return result; return result;
} }
result.sleep_time_ms = result.sleep_time = TimeDelta::Millis(
DivideRoundUp(delay_info.next_fire_at_us - tick_us, 1'000); DivideRoundUp(delay_info.next_fire_at_us - tick_us, 1'000));
} }
if (pending_queue_.size() > 0) { if (pending_queue_.size() > 0) {
@ -252,15 +247,7 @@ void TaskQueueStdlib::ProcessTasks() {
continue; continue;
} }
// TODO(bugs.webrtc.org/14366): While transitioning to TimeDelta, WebRTC and flag_notify_.Wait(task.sleep_time);
// Chromium has a different idea about what type rtc::Event::kForever is.
// Code can't assume rtc::Event::kForever is the same type as timed wait
// arguments.
// Simplify after transitioning is complete.
if (task.sleep_time_ms.has_value())
flag_notify_.Wait(task.sleep_time_ms.value());
else
flag_notify_.Wait(rtc::Event::kForever);
} }
} }

View File

@ -71,7 +71,7 @@ TEST(TaskQueueTest, DISABLED_PostDelayedHighRes) {
uint32_t start = Time(); uint32_t start = Time();
queue.PostDelayedTask([&event, &queue] { CheckCurrent(&event, &queue); }, queue.PostDelayedTask([&event, &queue] { CheckCurrent(&event, &queue); },
TimeDelta::Millis(3)); TimeDelta::Millis(3));
EXPECT_TRUE(event.Wait(1000)); EXPECT_TRUE(event.Wait(webrtc::TimeDelta::Seconds(1)));
uint32_t end = TimeMillis(); uint32_t end = TimeMillis();
// These tests are a little relaxed due to how "powerful" our test bots can // These tests are a little relaxed due to how "powerful" our test bots can
// be. Most recently we've seen windows bots fire the callback after 94-99ms, // be. Most recently we've seen windows bots fire the callback after 94-99ms,

View File

@ -226,7 +226,7 @@ TEST(RepeatingTaskTest, CancelDelayedTaskBeforeItRuns) {
task_queue.Get(), TimeDelta::Millis(100), MoveOnlyClosure(&mock)); task_queue.Get(), TimeDelta::Millis(100), MoveOnlyClosure(&mock));
task_queue.PostTask( task_queue.PostTask(
[handle = std::move(handle)]() mutable { handle.Stop(); }); [handle = std::move(handle)]() mutable { handle.Stop(); });
EXPECT_TRUE(done.Wait(kTimeout.ms())); EXPECT_TRUE(done.Wait(kTimeout));
} }
TEST(RepeatingTaskTest, CancelTaskAfterItRuns) { TEST(RepeatingTaskTest, CancelTaskAfterItRuns) {
@ -239,7 +239,7 @@ TEST(RepeatingTaskTest, CancelTaskAfterItRuns) {
RepeatingTaskHandle::Start(task_queue.Get(), MoveOnlyClosure(&mock)); RepeatingTaskHandle::Start(task_queue.Get(), MoveOnlyClosure(&mock));
task_queue.PostTask( task_queue.PostTask(
[handle = std::move(handle)]() mutable { handle.Stop(); }); [handle = std::move(handle)]() mutable { handle.Stop(); });
EXPECT_TRUE(done.Wait(kTimeout.ms())); EXPECT_TRUE(done.Wait(kTimeout));
} }
TEST(RepeatingTaskTest, TaskCanStopItself) { TEST(RepeatingTaskTest, TaskCanStopItself) {
@ -282,7 +282,7 @@ TEST(RepeatingTaskTest, ZeroReturnValueRepostsTheTask) {
})); }));
TaskQueueForTest task_queue("queue"); TaskQueueForTest task_queue("queue");
RepeatingTaskHandle::Start(task_queue.Get(), MoveOnlyClosure(&closure)); RepeatingTaskHandle::Start(task_queue.Get(), MoveOnlyClosure(&closure));
EXPECT_TRUE(done.Wait(kTimeout.ms())); EXPECT_TRUE(done.Wait(kTimeout));
} }
TEST(RepeatingTaskTest, StartPeriodicTask) { TEST(RepeatingTaskTest, StartPeriodicTask) {
@ -297,7 +297,7 @@ TEST(RepeatingTaskTest, StartPeriodicTask) {
})); }));
TaskQueueForTest task_queue("queue"); TaskQueueForTest task_queue("queue");
RepeatingTaskHandle::Start(task_queue.Get(), closure.AsStdFunction()); RepeatingTaskHandle::Start(task_queue.Get(), closure.AsStdFunction());
EXPECT_TRUE(done.Wait(kTimeout.ms())); EXPECT_TRUE(done.Wait(kTimeout));
} }
TEST(RepeatingTaskTest, Example) { TEST(RepeatingTaskTest, Example) {

View File

@ -1111,7 +1111,7 @@ TEST(ThreadPostDelayedTaskTest, InvokesInDelayOrder) {
first.Set(); first.Set();
// Only if the chain is invoked in delay order will the last event be set. // Only if the chain is invoked in delay order will the last event be set.
clock.AdvanceTime(TimeDelta::Millis(11)); clock.AdvanceTime(TimeDelta::Millis(11));
EXPECT_TRUE(fourth.Wait(0)); EXPECT_TRUE(fourth.Wait(TimeDelta::Zero()));
} }
TEST(ThreadPostDelayedTaskTest, IsCurrentTaskQueue) { TEST(ThreadPostDelayedTaskTest, IsCurrentTaskQueue) {

View File

@ -282,7 +282,7 @@ TEST(FakeClock, SettingTimeWakesThreads) {
// Advance the fake clock, expecting the worker thread to wake up // Advance the fake clock, expecting the worker thread to wake up
// and dispatch the message instantly. // and dispatch the message instantly.
clock.AdvanceTime(webrtc::TimeDelta::Seconds(60u)); clock.AdvanceTime(webrtc::TimeDelta::Seconds(60u));
EXPECT_TRUE(message_handler_dispatched.Wait(0)); EXPECT_TRUE(message_handler_dispatched.Wait(webrtc::TimeDelta::Zero()));
worker->Stop(); worker->Stop();
SetClockForTesting(nullptr); SetClockForTesting(nullptr);

View File

@ -18,7 +18,9 @@
#include <vector> #include <vector>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "api/units/time_delta.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/event.h"
#include "rtc_base/fake_clock.h" #include "rtc_base/fake_clock.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/physical_socket_server.h" #include "rtc_base/physical_socket_server.h"
@ -620,7 +622,8 @@ bool VirtualSocketServer::Wait(int cmsWait, bool process_io) {
// any real I/O. Received packets come in the form of queued messages, so // any real I/O. Received packets come in the form of queued messages, so
// Thread will ensure WakeUp is called if another thread sends a // Thread will ensure WakeUp is called if another thread sends a
// packet. // packet.
wakeup_.Wait(cmsWait); wakeup_.Wait(cmsWait == kForever ? Event::kForever
: webrtc::TimeDelta::Millis(cmsWait));
return true; return true;
} }

View File

@ -56,7 +56,7 @@ constexpr int kMaxFramerate = 30;
// We use very big value here to ensure that codec won't hit any limits. // We use very big value here to ensure that codec won't hit any limits.
constexpr uint32_t kBitrateBps = 100000000; constexpr uint32_t kBitrateBps = 100000000;
constexpr int kKeyFrameIntervalMs = 30000; constexpr int kKeyFrameIntervalMs = 30000;
constexpr int kMaxFrameEncodeWaitTimeoutMs = 2000; constexpr TimeDelta kMaxFrameEncodeWaitTimeout = TimeDelta::Seconds(2);
constexpr int kFrameLogInterval = 100; constexpr int kFrameLogInterval = 100;
static const VideoEncoder::Capabilities kCapabilities(false); static const VideoEncoder::Capabilities kCapabilities(false);
@ -88,8 +88,8 @@ class IvfFileWriterEncodedCallback : public EncodedImageCallback {
return Result(Result::Error::OK); return Result(Result::Error::OK);
} }
void WaitNextFrameWritten(int timeout_ms) { void WaitNextFrameWritten(TimeDelta timeout) {
RTC_CHECK(next_frame_written_.Wait(timeout_ms)); RTC_CHECK(next_frame_written_.Wait(timeout));
next_frame_written_.Reset(); next_frame_written_.Reset();
} }
@ -171,8 +171,8 @@ class Encoder {
}); });
} }
void WaitNextFrameWritten(int timeout_ms) { void WaitNextFrameWritten(TimeDelta timeout) {
ivf_writer_callback_->WaitNextFrameWritten(timeout_ms); ivf_writer_callback_->WaitNextFrameWritten(timeout);
} }
private: private:
@ -226,7 +226,7 @@ void WriteVideoFile(std::string input_file_name,
last_frame_timestamp = timestamp; last_frame_timestamp = timestamp;
encoder.Encode(frame); encoder.Encode(frame);
encoder.WaitNextFrameWritten(kMaxFrameEncodeWaitTimeoutMs); encoder.WaitNextFrameWritten(kMaxFrameEncodeWaitTimeout);
if ((i + 1) % kFrameLogInterval == 0) { if ((i + 1) % kFrameLogInterval == 0) {
RTC_LOG(LS_INFO) << i + 1 << " out of " << frames_count RTC_LOG(LS_INFO) << i + 1 << " out of " << frames_count

View File

@ -382,7 +382,7 @@ class RtpReplayer final {
CreateRtpReader(rtp_dump_path); CreateRtpReader(rtp_dump_path);
// Wait for streams creation. // Wait for streams creation.
sync_event.Wait(/*give_up_after_ms=*/10000); sync_event.Wait(/*give_up_after=*/TimeDelta::Seconds(10));
if (stream_state == nullptr || rtp_reader == nullptr) { if (stream_state == nullptr || rtp_reader == nullptr) {
return; return;
@ -402,7 +402,7 @@ class RtpReplayer final {
call.reset(); call.reset();
sync_event.Set(); sync_event.Set();
}); });
sync_event.Wait(/*give_up_after_ms=*/10000); sync_event.Wait(/*give_up_after=*/TimeDelta::Seconds(10));
} }
private: private:
@ -612,7 +612,7 @@ class RtpReplayer final {
/* packet_time_us */ -1); /* packet_time_us */ -1);
event.Set(); event.Set();
}); });
event.Wait(/*give_up_after_ms=*/10000); event.Wait(/*give_up_after=*/TimeDelta::Seconds(10));
switch (result) { switch (result) {
case PacketReceiver::DELIVERY_OK: case PacketReceiver::DELIVERY_OK:
break; break;

View File

@ -18,6 +18,7 @@
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "api/task_queue/pending_task_safety_flag.h" #include "api/task_queue/pending_task_safety_flag.h"
#include "rtc_base/event.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
@ -305,8 +306,10 @@ void FakeNetworkSocketServer::SetMessageQueue(rtc::Thread* thread) {
// Always returns true (if return false, it won't be invoked again...) // Always returns true (if return false, it won't be invoked again...)
bool FakeNetworkSocketServer::Wait(int cms, bool process_io) { bool FakeNetworkSocketServer::Wait(int cms, bool process_io) {
RTC_DCHECK(thread_ == rtc::Thread::Current()); RTC_DCHECK(thread_ == rtc::Thread::Current());
if (cms != 0) if (cms != 0) {
wakeup_.Wait(cms); wakeup_.Wait(cms == kForever ? rtc::Event::kForever
: TimeDelta::Millis(cms));
}
return true; return true;
} }

View File

@ -350,7 +350,7 @@ void DefaultVideoQualityAnalyzerFramesComparator::ProcessComparisons() {
comparison_available_event_.Set(); comparison_available_event_.Set();
return; return;
} }
comparison_available_event_.Wait(1000); comparison_available_event_.Wait(TimeDelta::Seconds(1));
continue; continue;
} }

View File

@ -21,7 +21,7 @@ namespace webrtc {
namespace webrtc_pc_e2e { namespace webrtc_pc_e2e {
namespace { namespace {
constexpr int kStatsWaitTimeoutMs = 1000; constexpr TimeDelta kStatsWaitTimeout = TimeDelta::Seconds(1);
// Field trial which controls whether to report standard-compliant bytes // Field trial which controls whether to report standard-compliant bytes
// sent/received per stream. If enabled, padding and headers are not included // sent/received per stream. If enabled, padding and headers are not included
@ -100,7 +100,7 @@ NetworkQualityMetricsReporter::PopulateStats(
stats = std::move(s); stats = std::move(s);
wait.Set(); wait.Set();
}); });
bool stats_received = wait.Wait(kStatsWaitTimeoutMs); bool stats_received = wait.Wait(kStatsWaitTimeout);
RTC_CHECK(stats_received); RTC_CHECK(stats_received);
return stats; return stats;
} }

View File

@ -39,7 +39,7 @@ namespace webrtc {
namespace webrtc_pc_e2e { namespace webrtc_pc_e2e {
namespace { namespace {
constexpr int kStatsWaitTimeoutMs = 1000; constexpr TimeDelta kStatsWaitTimeout = TimeDelta::Seconds(1);
// Field trial which controls whether to report standard-compliant bytes // Field trial which controls whether to report standard-compliant bytes
// sent/received per stream. If enabled, padding and headers are not included // sent/received per stream. If enabled, padding and headers are not included
@ -56,7 +56,7 @@ std::unique_ptr<EmulatedNetworkStats> PopulateStats(
stats = std::move(s); stats = std::move(s);
stats_loaded.Set(); stats_loaded.Set();
}); });
bool stats_received = stats_loaded.Wait(kStatsWaitTimeoutMs); bool stats_received = stats_loaded.Wait(kStatsWaitTimeout);
RTC_CHECK(stats_received); RTC_CHECK(stats_received);
return stats; return stats;
} }

View File

@ -17,6 +17,7 @@
#include "api/array_view.h" #include "api/array_view.h"
#include "api/test/simulated_network.h" #include "api/test/simulated_network.h"
#include "api/units/time_delta.h"
#include "call/simulated_packet_receiver.h" #include "call/simulated_packet_receiver.h"
#include "call/video_send_stream.h" #include "call/video_send_stream.h"
#include "modules/rtp_rtcp/source/rtp_util.h" #include "modules/rtp_rtcp/source/rtp_util.h"
@ -26,7 +27,7 @@
#include "test/gtest.h" #include "test/gtest.h"
namespace { namespace {
const int kShortTimeoutMs = 500; constexpr webrtc::TimeDelta kShortTimeout = webrtc::TimeDelta::Millis(500);
} }
namespace webrtc { namespace webrtc {
@ -45,10 +46,10 @@ class RtpRtcpObserver {
virtual bool Wait() { virtual bool Wait() {
if (field_trial::IsEnabled("WebRTC-QuickPerfTest")) { if (field_trial::IsEnabled("WebRTC-QuickPerfTest")) {
observation_complete_.Wait(kShortTimeoutMs); observation_complete_.Wait(kShortTimeout);
return true; return true;
} }
return observation_complete_.Wait(timeout_ms_); return observation_complete_.Wait(timeout_);
} }
virtual Action OnSendRtp(const uint8_t* packet, size_t length) { virtual Action OnSendRtp(const uint8_t* packet, size_t length) {
@ -69,13 +70,12 @@ class RtpRtcpObserver {
protected: protected:
RtpRtcpObserver() : RtpRtcpObserver(TimeDelta::Zero()) {} RtpRtcpObserver() : RtpRtcpObserver(TimeDelta::Zero()) {}
explicit RtpRtcpObserver(TimeDelta event_timeout) explicit RtpRtcpObserver(TimeDelta event_timeout) : timeout_(event_timeout) {}
: timeout_ms_(event_timeout.ms()) {}
rtc::Event observation_complete_; rtc::Event observation_complete_;
private: private:
const int timeout_ms_; const TimeDelta timeout_;
}; };
class PacketTransport : public test::DirectTransport { class PacketTransport : public test::DirectTransport {

View File

@ -27,7 +27,7 @@ namespace webrtc {
namespace test { namespace test {
namespace { namespace {
constexpr int kMaxNextFrameWaitTemeoutMs = 1000; constexpr TimeDelta kMaxNextFrameWaitTimeout = TimeDelta::Seconds(1);
} // namespace } // namespace
@ -80,9 +80,9 @@ FrameGeneratorInterface::VideoFrameData IvfVideoFrameGenerator::NextFrame() {
RTC_CHECK_EQ(WEBRTC_VIDEO_CODEC_OK, RTC_CHECK_EQ(WEBRTC_VIDEO_CODEC_OK,
video_decoder_->Decode(*image, /*missing_frames=*/false, video_decoder_->Decode(*image, /*missing_frames=*/false,
/*render_time_ms=*/0)); /*render_time_ms=*/0));
bool decoded = next_frame_decoded_.Wait(kMaxNextFrameWaitTemeoutMs); bool decoded = next_frame_decoded_.Wait(kMaxNextFrameWaitTimeout);
RTC_CHECK(decoded) << "Failed to decode next frame in " RTC_CHECK(decoded) << "Failed to decode next frame in "
<< kMaxNextFrameWaitTemeoutMs << "ms. Can't continue"; << kMaxNextFrameWaitTimeout << ". Can't continue";
MutexLock frame_lock(&frame_decode_lock_); MutexLock frame_lock(&frame_decode_lock_);
rtc::scoped_refptr<VideoFrameBuffer> buffer = rtc::scoped_refptr<VideoFrameBuffer> buffer =

View File

@ -8,11 +8,14 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "test/testsupport/ivf_video_frame_generator.h"
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/test/create_frame_generator.h" #include "api/test/create_frame_generator.h"
#include "api/units/time_delta.h"
#include "api/video/encoded_image.h" #include "api/video/encoded_image.h"
#include "api/video/video_codec_type.h" #include "api/video/video_codec_type.h"
#include "api/video_codecs/video_codec.h" #include "api/video_codecs/video_codec.h"
@ -28,7 +31,6 @@
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/file_utils.h" #include "test/testsupport/file_utils.h"
#include "test/testsupport/ivf_video_frame_generator.h"
#include "test/video_codec_settings.h" #include "test/video_codec_settings.h"
#if defined(WEBRTC_USE_H264) #if defined(WEBRTC_USE_H264)
@ -45,7 +47,7 @@ constexpr int kWidth = 320;
constexpr int kHeight = 240; constexpr int kHeight = 240;
constexpr int kVideoFramesCount = 30; constexpr int kVideoFramesCount = 30;
constexpr int kMaxFramerate = 30; constexpr int kMaxFramerate = 30;
constexpr int kMaxFrameEncodeWaitTimeoutMs = 2000; constexpr TimeDelta kMaxFrameEncodeWaitTimeout = TimeDelta::Seconds(2);
static const VideoEncoder::Capabilities kCapabilities(false); static const VideoEncoder::Capabilities kCapabilities(false);
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM64) #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM64)
@ -80,8 +82,8 @@ class IvfFileWriterEncodedCallback : public EncodedImageCallback {
return Result(Result::Error::OK); return Result(Result::Error::OK);
} }
bool WaitForExpectedFramesReceived(int timeout_ms) { bool WaitForExpectedFramesReceived(TimeDelta timeout) {
return expected_frames_count_received_.Wait(timeout_ms); return expected_frames_count_received_.Wait(timeout);
} }
private: private:
@ -153,7 +155,7 @@ class IvfVideoFrameGeneratorTest : public ::testing::Test {
} }
ASSERT_TRUE(ivf_writer_callback.WaitForExpectedFramesReceived( ASSERT_TRUE(ivf_writer_callback.WaitForExpectedFramesReceived(
kMaxFrameEncodeWaitTimeoutMs)); kMaxFrameEncodeWaitTimeout));
} }
std::string file_name_; std::string file_name_;

View File

@ -140,7 +140,7 @@ TEST(ExternalTimeControllerTest, YieldForTask) {
rtc::Event event; rtc::Event event;
task_queue.PostTask([&] { event.Set(); }); task_queue.PostTask([&] { event.Set(); });
EXPECT_TRUE(event.Wait(200)); EXPECT_TRUE(event.Wait(TimeDelta::Millis(200)));
} }
TEST(ExternalTimeControllerTest, TasksYieldToEachOther) { TEST(ExternalTimeControllerTest, TasksYieldToEachOther) {
@ -157,7 +157,7 @@ TEST(ExternalTimeControllerTest, TasksYieldToEachOther) {
task_queue.PostTask([&] { task_queue.PostTask([&] {
rtc::Event event; rtc::Event event;
other_queue.PostTask([&] { event.Set(); }); other_queue.PostTask([&] { event.Set(); });
EXPECT_TRUE(event.Wait(200)); EXPECT_TRUE(event.Wait(TimeDelta::Millis(200)));
}); });
time_simulation.AdvanceTime(TimeDelta::Millis(300)); time_simulation.AdvanceTime(TimeDelta::Millis(300));

View File

@ -137,7 +137,7 @@ TEST(SimulatedTimeControllerTest, ThreadYeildsOnSynchronousCall) {
// Wait() triggers YieldExecution() which will runs message processing on // Wait() triggers YieldExecution() which will runs message processing on
// all threads that are not in the yielded set. // all threads that are not in the yielded set.
yield_event.Wait(0); yield_event.Wait(TimeDelta::Zero());
}); });
// Since we are doing an invoke from the main thread, we don't expect the main // Since we are doing an invoke from the main thread, we don't expect the main
// thread message loop to be processed. // thread message loop to be processed.

View File

@ -165,7 +165,7 @@ TEST_P(SimulatedRealTimeControllerConformanceTest,
execution_order.Executed(2); execution_order.Executed(2);
event.Set(); event.Set();
}); });
EXPECT_TRUE(event.Wait(/*give_up_after_ms=*/100)); EXPECT_TRUE(event.Wait(/*give_up_after=*/TimeDelta::Millis(100)));
time_controller->AdvanceTime(TimeDelta::Millis(100)); time_controller->AdvanceTime(TimeDelta::Millis(100));
EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2})); EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2}));
// Destroy `task_queue` before `execution_order` to be sure `execution_order` // Destroy `task_queue` before `execution_order` to be sure `execution_order`

View File

@ -454,7 +454,7 @@ TEST_F(OveruseFrameDetectorTest, RunOnTqNormalUsage) {
kDelayUs2); kDelayUs2);
}); });
EXPECT_TRUE(event.Wait(10000)); EXPECT_TRUE(event.Wait(TimeDelta::Seconds(10)));
} }
// TODO(crbug.com/webrtc/12846): investigate why the test fails on MAC bots. // TODO(crbug.com/webrtc/12846): investigate why the test fails on MAC bots.
@ -936,7 +936,7 @@ TEST_F(OveruseFrameDetectorTest2, RunOnTqNormalUsage) {
kDelayUs2); kDelayUs2);
}); });
EXPECT_TRUE(event.Wait(10000)); EXPECT_TRUE(event.Wait(TimeDelta::Seconds(10)));
} }
// Models screencast, with irregular arrival of frames which are heavy // Models screencast, with irregular arrival of frames which are heavy

View File

@ -88,7 +88,7 @@ TEST_F(CallOperationEndToEndTest, RendersSingleDelayedFrame) {
event_.Set(); event_.Set();
} }
bool Wait() { return event_.Wait(kDefaultTimeout.ms()); } bool Wait() { return event_.Wait(kDefaultTimeout); }
rtc::Event event_; rtc::Event event_;
} renderer; } renderer;
@ -159,7 +159,7 @@ TEST_F(CallOperationEndToEndTest, TransmitsFirstFrame) {
public: public:
void OnFrame(const VideoFrame& video_frame) override { event_.Set(); } void OnFrame(const VideoFrame& video_frame) override { event_.Set(); }
bool Wait() { return event_.Wait(kDefaultTimeout.ms()); } bool Wait() { return event_.Wait(kDefaultTimeout); }
rtc::Event event_; rtc::Event event_;
} renderer; } renderer;

View File

@ -45,7 +45,7 @@ TEST(MultiStreamEndToEndTest, SendsAndReceivesMultipleStreams) {
uint32_t Ssrc() { return ssrc_; } uint32_t Ssrc() { return ssrc_; }
bool Wait() { return done_.Wait(30 * 1000); } bool Wait() { return done_.Wait(TimeDelta::Seconds(30)); }
private: private:
const MultiStreamTester::CodecSettings& settings_; const MultiStreamTester::CodecSettings& settings_;

View File

@ -235,7 +235,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
} }
void PerformTest() override { void PerformTest() override {
EXPECT_TRUE(encoded_frames_.Wait(kDefaultTimeout.ms())) EXPECT_TRUE(encoded_frames_.Wait(kDefaultTimeout))
<< "No frames received by the encoder."; << "No frames received by the encoder.";
SendTask(task_queue_.get(), [this]() { SendTask(task_queue_.get(), [this]() {
@ -323,7 +323,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
bool sender_done = false; bool sender_done = false;
bool receiver_done = false; bool receiver_done = false;
while (!sender_done || !receiver_done) { while (!sender_done || !receiver_done) {
packet_event_.Wait(kSilenceTimeoutMs); packet_event_.Wait(TimeDelta::Millis(kSilenceTimeoutMs));
int64_t time_now_ms = clock_->TimeInMilliseconds(); int64_t time_now_ms = clock_->TimeInMilliseconds();
MutexLock lock(&test_mutex_); MutexLock lock(&test_mutex_);
if (sender_down) { if (sender_down) {

View File

@ -55,7 +55,7 @@ TEST_F(SsrcEndToEndTest, UnknownRtpPacketGivesUnknownSsrcReturnCode) {
explicit PacketInputObserver(PacketReceiver* receiver) explicit PacketInputObserver(PacketReceiver* receiver)
: receiver_(receiver) {} : receiver_(receiver) {}
bool Wait() { return delivered_packet_.Wait(kDefaultTimeout.ms()); } bool Wait() { return delivered_packet_.Wait(kDefaultTimeout); }
private: private:
DeliveryStatus DeliverPacket(MediaType media_type, DeliveryStatus DeliverPacket(MediaType media_type,

View File

@ -308,7 +308,7 @@ TEST_F(StatsEndToEndTest, GetStats) {
int64_t time_until_timeout_ms = stop_time_ms - now_ms; int64_t time_until_timeout_ms = stop_time_ms - now_ms;
if (time_until_timeout_ms > 0) if (time_until_timeout_ms > 0)
check_stats_event_.Wait(time_until_timeout_ms); check_stats_event_.Wait(TimeDelta::Millis(time_until_timeout_ms));
now_ms = clock->TimeInMilliseconds(); now_ms = clock->TimeInMilliseconds();
} }

View File

@ -35,7 +35,7 @@ enum : int { // The first valid value is 1.
TEST(TransportFeedbackMultiStreamTest, AssignsTransportSequenceNumbers) { TEST(TransportFeedbackMultiStreamTest, AssignsTransportSequenceNumbers) {
static constexpr int kSendRtxPayloadType = 98; static constexpr int kSendRtxPayloadType = 98;
static constexpr int kDefaultTimeoutMs = 30 * 1000; static constexpr TimeDelta kDefaultTimeout = TimeDelta::Seconds(30);
static constexpr int kNackRtpHistoryMs = 1000; static constexpr int kNackRtpHistoryMs = 1000;
static constexpr uint32_t kSendRtxSsrcs[MultiStreamTester::kNumStreams] = { static constexpr uint32_t kSendRtxSsrcs[MultiStreamTester::kNumStreams] = {
0xBADCAFD, 0xBADCAFE, 0xBADCAFF}; 0xBADCAFD, 0xBADCAFE, 0xBADCAFF};
@ -146,7 +146,7 @@ TEST(TransportFeedbackMultiStreamTest, AssignsTransportSequenceNumbers) {
MutexLock lock(&lock_); MutexLock lock(&lock_);
started_ = true; started_ = true;
} }
return done_.Wait(kDefaultTimeoutMs); return done_.Wait(kDefaultTimeout);
} }
private: private:
@ -278,10 +278,9 @@ class TransportFeedbackTester : public test::EndToEndTest {
void PerformTest() override { void PerformTest() override {
constexpr TimeDelta kDisabledFeedbackTimeout = TimeDelta::Seconds(5); constexpr TimeDelta kDisabledFeedbackTimeout = TimeDelta::Seconds(5);
EXPECT_EQ(feedback_enabled_, EXPECT_EQ(feedback_enabled_,
observation_complete_.Wait((feedback_enabled_ observation_complete_.Wait(feedback_enabled_
? test::CallTest::kDefaultTimeout ? test::CallTest::kDefaultTimeout
: kDisabledFeedbackTimeout) : kDisabledFeedbackTimeout));
.ms()));
} }
void OnCallsCreated(Call* sender_call, Call* receiver_call) override { void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
@ -415,8 +414,8 @@ TEST_F(TransportFeedbackEndToEndTest,
} }
void PerformTest() override { void PerformTest() override {
const int64_t kFailureTimeoutMs = 10000; constexpr TimeDelta kFailureTimeout = TimeDelta::Seconds(10);
EXPECT_TRUE(observation_complete_.Wait(kFailureTimeoutMs)) EXPECT_TRUE(observation_complete_.Wait(kFailureTimeout))
<< "Stream not continued after congestion window full."; << "Stream not continued after congestion window full.";
} }

View File

@ -44,11 +44,11 @@ namespace {
constexpr TimeDelta kSendStatsPollingInterval = TimeDelta::Seconds(1); constexpr TimeDelta kSendStatsPollingInterval = TimeDelta::Seconds(1);
constexpr size_t kMaxComparisons = 10; constexpr size_t kMaxComparisons = 10;
// How often is keep alive message printed. // How often is keep alive message printed.
constexpr int kKeepAliveIntervalSeconds = 30; constexpr TimeDelta kKeepAliveInterval = TimeDelta::Seconds(30);
// Interval between checking that the test is over. // Interval between checking that the test is over.
constexpr int kProbingIntervalMs = 500; constexpr TimeDelta kProbingInterval = TimeDelta::Millis(500);
constexpr int kKeepAliveIntervalIterations = constexpr int kKeepAliveIntervalIterations =
kKeepAliveIntervalSeconds * 1000 / kProbingIntervalMs; kKeepAliveInterval.ms() / kProbingInterval.ms();
bool IsFlexfec(int payload_type) { bool IsFlexfec(int payload_type) {
return payload_type == test::CallTest::kFlexfecPayloadType; return payload_type == test::CallTest::kFlexfecPayloadType;
@ -361,7 +361,7 @@ void VideoAnalyzer::Wait() {
int last_frames_captured = -1; int last_frames_captured = -1;
int iteration = 0; int iteration = 0;
while (!done_.Wait(kProbingIntervalMs)) { while (!done_.Wait(kProbingInterval)) {
int frames_processed; int frames_processed;
int frames_captured; int frames_captured;
{ {
@ -545,7 +545,7 @@ bool VideoAnalyzer::CompareFrames() {
if (!PopComparison(&comparison)) { if (!PopComparison(&comparison)) {
// Wait until new comparison task is available, or test is done. // Wait until new comparison task is available, or test is done.
// If done, wake up remaining threads waiting. // If done, wake up remaining threads waiting.
comparison_available_event_.Wait(1000); comparison_available_event_.Wait(TimeDelta::Seconds(1));
if (AllFramesRecorded()) { if (AllFramesRecorded()) {
comparison_available_event_.Set(); comparison_available_event_.Set();
return false; return false;

View File

@ -862,7 +862,7 @@ TEST_F(VideoSendStreamImplTest, DisablesPaddingOnPausedEncoder) {
TimeDelta::Seconds(5)); TimeDelta::Seconds(5));
// Pause the test suite so that the last delayed task executes. // Pause the test suite so that the last delayed task executes.
ASSERT_TRUE(done.Wait(10000)); ASSERT_TRUE(done.Wait(TimeDelta::Seconds(10)));
} }
TEST_F(VideoSendStreamImplTest, KeepAliveOnDroppedFrame) { TEST_F(VideoSendStreamImplTest, KeepAliveOnDroppedFrame) {
@ -895,7 +895,7 @@ TEST_F(VideoSendStreamImplTest, KeepAliveOnDroppedFrame) {
done.Set(); done.Set();
}, },
TimeDelta::Seconds(2)); TimeDelta::Seconds(2));
ASSERT_TRUE(done.Wait(5000)); ASSERT_TRUE(done.Wait(TimeDelta::Seconds(5)));
} }
TEST_F(VideoSendStreamImplTest, ConfiguresBitratesForSvc) { TEST_F(VideoSendStreamImplTest, ConfiguresBitratesForSvc) {

View File

@ -2036,7 +2036,7 @@ TEST_F(VideoSendStreamTest,
} }
} }
EXPECT_TRUE( EXPECT_TRUE(
init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeout.ms())); init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeout));
{ {
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
EXPECT_EQ(width, last_initialized_frame_width_); EXPECT_EQ(width, last_initialized_frame_width_);
@ -2122,8 +2122,7 @@ TEST_F(VideoSendStreamTest, CanReconfigureToUseStartBitrateAbovePreviousMax) {
} }
bool WaitForStartBitrate() { bool WaitForStartBitrate() {
return start_bitrate_changed_.Wait( return start_bitrate_changed_.Wait(VideoSendStreamTest::kDefaultTimeout);
VideoSendStreamTest::kDefaultTimeout.ms());
} }
private: private:
@ -2201,7 +2200,7 @@ class StartStopBitrateObserver : public test::FakeEncoder {
} }
bool WaitForEncoderInit() { bool WaitForEncoderInit() {
return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeout.ms()); return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeout);
} }
bool WaitBitrateChanged(WaitUntil until) { bool WaitBitrateChanged(WaitUntil until) {
@ -2218,7 +2217,7 @@ class StartStopBitrateObserver : public test::FakeEncoder {
(until == WaitUntil::kZero && *bitrate_kbps == 0)) { (until == WaitUntil::kZero && *bitrate_kbps == 0)) {
return true; return true;
} }
} while (bitrate_changed_.Wait(VideoSendStreamTest::kDefaultTimeout.ms())); } while (bitrate_changed_.Wait(VideoSendStreamTest::kDefaultTimeout));
return false; return false;
} }
@ -2410,8 +2409,7 @@ class VideoCodecConfigObserver : public test::SendTest,
GetEncoderSpecificSettings() const; GetEncoderSpecificSettings() const;
void PerformTest() override { void PerformTest() override {
EXPECT_TRUE( EXPECT_TRUE(init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeout));
init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeout.ms()));
ASSERT_EQ(1, FakeEncoder::GetNumInitializations()) ASSERT_EQ(1, FakeEncoder::GetNumInitializations())
<< "VideoEncoder not initialized."; << "VideoEncoder not initialized.";
@ -2421,8 +2419,7 @@ class VideoCodecConfigObserver : public test::SendTest,
SendTask(task_queue_, [&]() { SendTask(task_queue_, [&]() {
stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); stream_->ReconfigureVideoEncoder(std::move(encoder_config_));
}); });
ASSERT_TRUE( ASSERT_TRUE(init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeout));
init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeout.ms()));
EXPECT_EQ(2, FakeEncoder::GetNumInitializations()) EXPECT_EQ(2, FakeEncoder::GetNumInitializations())
<< "ReconfigureVideoEncoder did not reinitialize the encoder with " << "ReconfigureVideoEncoder did not reinitialize the encoder with "
"new encoder settings."; "new encoder settings.";
@ -2785,8 +2782,9 @@ TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) {
return; return;
} }
} while (bitrate_changed_event_.Wait( } while (bitrate_changed_event_.Wait(
std::max(int64_t{1}, VideoSendStreamTest::kDefaultTimeout.ms() - std::max(TimeDelta::Millis(1),
(rtc::TimeMillis() - start_time)))); VideoSendStreamTest::kDefaultTimeout -
TimeDelta::Millis(rtc::TimeMillis() - start_time))));
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
EXPECT_EQ(target_bitrate_, expected_bitrate) EXPECT_EQ(target_bitrate_, expected_bitrate)
<< "Timed out while waiting encoder rate to be set."; << "Timed out while waiting encoder rate to be set.";
@ -2826,10 +2824,9 @@ TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) {
void PerformTest() override { void PerformTest() override {
ASSERT_TRUE(create_rate_allocator_event_.Wait( ASSERT_TRUE(create_rate_allocator_event_.Wait(
VideoSendStreamTest::kDefaultTimeout.ms())) VideoSendStreamTest::kDefaultTimeout))
<< "Timed out while waiting for rate allocator to be created."; << "Timed out while waiting for rate allocator to be created.";
ASSERT_TRUE( ASSERT_TRUE(init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeout))
init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeout.ms()))
<< "Timed out while waiting for encoder to be configured."; << "Timed out while waiting for encoder to be configured.";
WaitForSetRates(kStartBitrateKbps); WaitForSetRates(kStartBitrateKbps);
BitrateConstraints bitrate_config; BitrateConstraints bitrate_config;
@ -2846,7 +2843,7 @@ TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) {
send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy());
}); });
ASSERT_TRUE(create_rate_allocator_event_.Wait( ASSERT_TRUE(create_rate_allocator_event_.Wait(
VideoSendStreamTest::kDefaultTimeout.ms())); VideoSendStreamTest::kDefaultTimeout));
EXPECT_EQ(2, num_rate_allocator_creations_) EXPECT_EQ(2, num_rate_allocator_creations_)
<< "Rate allocator should have been recreated."; << "Rate allocator should have been recreated.";
@ -2858,7 +2855,7 @@ TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) {
send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy());
}); });
ASSERT_TRUE(create_rate_allocator_event_.Wait( ASSERT_TRUE(create_rate_allocator_event_.Wait(
VideoSendStreamTest::kDefaultTimeout.ms())); VideoSendStreamTest::kDefaultTimeout));
EXPECT_EQ(3, num_rate_allocator_creations_) EXPECT_EQ(3, num_rate_allocator_creations_)
<< "Rate allocator should have been recreated."; << "Rate allocator should have been recreated.";
@ -3736,8 +3733,8 @@ TEST_F(VideoSendStreamTest, RemoveOverheadFromBandwidth) {
// At a bitrate of 60kbps with a packet size of 1200B video and an // At a bitrate of 60kbps with a packet size of 1200B video and an
// overhead of 40B per packet video produces 2240bps overhead. // overhead of 40B per packet video produces 2240bps overhead.
// So the encoder BW should be set to 57760bps. // So the encoder BW should be set to 57760bps.
EXPECT_TRUE(bitrate_changed_event_.Wait( EXPECT_TRUE(
VideoSendStreamTest::kDefaultTimeout.ms())); bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeout));
{ {
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
EXPECT_LE(max_bitrate_bps_, 57760u); EXPECT_LE(max_bitrate_bps_, 57760u);
@ -3952,8 +3949,7 @@ class ContentSwitchTest : public test::SendTest {
void PerformTest() override { void PerformTest() override {
while (GetStreamState() != StreamState::kAfterSwitchBack) { while (GetStreamState() != StreamState::kAfterSwitchBack) {
ASSERT_TRUE( ASSERT_TRUE(content_switch_event_.Wait(test::CallTest::kDefaultTimeout));
content_switch_event_.Wait(test::CallTest::kDefaultTimeout.ms()));
(*stream_resetter_)(send_stream_config_, encoder_config_, this); (*stream_resetter_)(send_stream_config_, encoder_config_, this);
} }

View File

@ -97,7 +97,7 @@ const int kQpLow = 1;
const int kQpHigh = 2; const int kQpHigh = 2;
const int kMinFramerateFps = 2; const int kMinFramerateFps = 2;
const int kMinBalancedFramerateFps = 7; const int kMinBalancedFramerateFps = 7;
const int64_t kFrameTimeoutMs = 100; constexpr TimeDelta kFrameTimeout = TimeDelta::Millis(100);
const size_t kMaxPayloadLength = 1440; const size_t kMaxPayloadLength = 1440;
const DataRate kTargetBitrate = DataRate::KilobitsPerSec(1000); const DataRate kTargetBitrate = DataRate::KilobitsPerSec(1000);
const DataRate kLowTargetBitrate = DataRate::KilobitsPerSec(100); const DataRate kLowTargetBitrate = DataRate::KilobitsPerSec(100);
@ -409,7 +409,7 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder {
FakeVideoSourceRestrictionsListener listener; FakeVideoSourceRestrictionsListener listener;
AddRestrictionsListenerForTesting(&listener); AddRestrictionsListenerForTesting(&listener);
SetSource(source, degradation_preference); SetSource(source, degradation_preference);
listener.restrictions_updated_event()->Wait(5000); listener.restrictions_updated_event()->Wait(TimeDelta::Seconds(5));
RemoveRestrictionsListenerForTesting(&listener); RemoveRestrictionsListenerForTesting(&listener);
} }
@ -418,7 +418,8 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder {
const DegradationPreference& degradation_preference) { const DegradationPreference& degradation_preference) {
overuse_detector_proxy_->framerate_updated_event()->Reset(); overuse_detector_proxy_->framerate_updated_event()->Reset();
SetSource(source, degradation_preference); SetSource(source, degradation_preference);
overuse_detector_proxy_->framerate_updated_event()->Wait(5000); overuse_detector_proxy_->framerate_updated_event()->Wait(
TimeDelta::Seconds(5));
} }
void OnBitrateUpdatedAndWaitForManagedResources( void OnBitrateUpdatedAndWaitForManagedResources(
@ -447,7 +448,7 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder {
fake_cpu_resource_->SetUsageState(ResourceUsageState::kOveruse); fake_cpu_resource_->SetUsageState(ResourceUsageState::kOveruse);
event.Set(); event.Set();
}); });
ASSERT_TRUE(event.Wait(5000)); ASSERT_TRUE(event.Wait(TimeDelta::Seconds(5)));
time_controller_->AdvanceTime(TimeDelta::Zero()); time_controller_->AdvanceTime(TimeDelta::Zero());
} }
@ -457,7 +458,7 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder {
fake_cpu_resource_->SetUsageState(ResourceUsageState::kUnderuse); fake_cpu_resource_->SetUsageState(ResourceUsageState::kUnderuse);
event.Set(); event.Set();
}); });
ASSERT_TRUE(event.Wait(5000)); ASSERT_TRUE(event.Wait(TimeDelta::Seconds(5)));
time_controller_->AdvanceTime(TimeDelta::Zero()); time_controller_->AdvanceTime(TimeDelta::Zero());
} }
@ -468,7 +469,7 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder {
fake_quality_resource_->SetUsageState(ResourceUsageState::kOveruse); fake_quality_resource_->SetUsageState(ResourceUsageState::kOveruse);
event.Set(); event.Set();
}); });
ASSERT_TRUE(event.Wait(5000)); ASSERT_TRUE(event.Wait(TimeDelta::Seconds(5)));
time_controller_->AdvanceTime(TimeDelta::Zero()); time_controller_->AdvanceTime(TimeDelta::Zero());
} }
void TriggerQualityHigh() { void TriggerQualityHigh() {
@ -477,7 +478,7 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder {
fake_quality_resource_->SetUsageState(ResourceUsageState::kUnderuse); fake_quality_resource_->SetUsageState(ResourceUsageState::kUnderuse);
event.Set(); event.Set();
}); });
ASSERT_TRUE(event.Wait(5000)); ASSERT_TRUE(event.Wait(TimeDelta::Seconds(5)));
time_controller_->AdvanceTime(TimeDelta::Zero()); time_controller_->AdvanceTime(TimeDelta::Zero());
} }
@ -821,7 +822,7 @@ class MockVideoSourceInterface : public rtc::VideoSourceInterface<VideoFrame> {
class VideoStreamEncoderTest : public ::testing::Test { class VideoStreamEncoderTest : public ::testing::Test {
public: public:
static const int kDefaultTimeoutMs = 1000; static constexpr TimeDelta kDefaultTimeout = TimeDelta::Seconds(1);
VideoStreamEncoderTest() VideoStreamEncoderTest()
: video_send_config_(VideoSendStream::Config(nullptr)), : video_send_config_(VideoSendStream::Config(nullptr)),
@ -1012,8 +1013,8 @@ class VideoStreamEncoderTest : public ::testing::Test {
AdvanceTime(TimeDelta::Seconds(1) / max_framerate_); AdvanceTime(TimeDelta::Seconds(1) / max_framerate_);
} }
bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, int64_t timeout_ms) { bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, TimeDelta timeout) {
bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, timeout_ms); bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, timeout);
AdvanceTime(TimeDelta::Seconds(1) / max_framerate_); AdvanceTime(TimeDelta::Seconds(1) / max_framerate_);
return ok; return ok;
} }
@ -1028,8 +1029,8 @@ class VideoStreamEncoderTest : public ::testing::Test {
AdvanceTime(TimeDelta::Seconds(1) / max_framerate_); AdvanceTime(TimeDelta::Seconds(1) / max_framerate_);
} }
bool WaitForFrame(int64_t timeout_ms) { bool WaitForFrame(TimeDelta timeout) {
bool ok = sink_.WaitForFrame(timeout_ms); bool ok = sink_.WaitForFrame(timeout);
AdvanceTime(TimeDelta::Seconds(1) / max_framerate_); AdvanceTime(TimeDelta::Seconds(1) / max_framerate_);
return ok; return ok;
} }
@ -1370,14 +1371,13 @@ class VideoStreamEncoderTest : public ::testing::Test {
} }
void WaitForEncodedFrame(int64_t expected_ntp_time) { void WaitForEncodedFrame(int64_t expected_ntp_time) {
EXPECT_TRUE( EXPECT_TRUE(TimedWaitForEncodedFrame(expected_ntp_time, kDefaultTimeout));
TimedWaitForEncodedFrame(expected_ntp_time, kDefaultTimeoutMs));
} }
bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, bool TimedWaitForEncodedFrame(int64_t expected_ntp_time,
int64_t timeout_ms) { TimeDelta timeout) {
uint32_t timestamp = 0; uint32_t timestamp = 0;
if (!WaitForFrame(timeout_ms)) if (!WaitForFrame(timeout))
return false; return false;
{ {
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
@ -1389,7 +1389,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
void WaitForEncodedFrame(uint32_t expected_width, void WaitForEncodedFrame(uint32_t expected_width,
uint32_t expected_height) { uint32_t expected_height) {
EXPECT_TRUE(WaitForFrame(kDefaultTimeoutMs)); EXPECT_TRUE(WaitForFrame(kDefaultTimeout));
CheckLastFrameSizeMatches(expected_width, expected_height); CheckLastFrameSizeMatches(expected_width, expected_height);
} }
@ -1415,12 +1415,14 @@ class VideoStreamEncoderTest : public ::testing::Test {
EXPECT_EQ(expected_rotation, rotation); EXPECT_EQ(expected_rotation, rotation);
} }
void ExpectDroppedFrame() { EXPECT_FALSE(WaitForFrame(100)); } void ExpectDroppedFrame() {
EXPECT_FALSE(WaitForFrame(TimeDelta::Millis(100)));
}
bool WaitForFrame(int64_t timeout_ms) { bool WaitForFrame(TimeDelta timeout) {
RTC_DCHECK(time_controller_->GetMainThread()->IsCurrent()); RTC_DCHECK(time_controller_->GetMainThread()->IsCurrent());
time_controller_->AdvanceTime(TimeDelta::Zero()); time_controller_->AdvanceTime(TimeDelta::Zero());
bool ret = encoded_frame_event_.Wait(timeout_ms); bool ret = encoded_frame_event_.Wait(timeout);
time_controller_->AdvanceTime(TimeDelta::Zero()); time_controller_->AdvanceTime(TimeDelta::Zero());
return ret; return ret;
} }
@ -1625,7 +1627,7 @@ TEST_F(VideoStreamEncoderTest, EncodeOneFrame) {
rtc::Event frame_destroyed_event; rtc::Event frame_destroyed_event;
video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event));
WaitForEncodedFrame(1); WaitForEncodedFrame(1);
EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeout));
video_stream_encoder_->Stop(); video_stream_encoder_->Stop();
} }
@ -1639,7 +1641,7 @@ TEST_F(VideoStreamEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) {
AdvanceTime(TimeDelta::Millis(10)); AdvanceTime(TimeDelta::Millis(10));
video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr));
AdvanceTime(TimeDelta::Zero()); AdvanceTime(TimeDelta::Zero());
EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeout));
video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources( video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources(
kTargetBitrate, kTargetBitrate, kTargetBitrate, 0, 0, 0); kTargetBitrate, kTargetBitrate, kTargetBitrate, 0, 0, 0);
@ -1700,7 +1702,7 @@ TEST_F(VideoStreamEncoderTest, DropsFrameAfterStop) {
sink_.SetExpectNoFrames(); sink_.SetExpectNoFrames();
rtc::Event frame_destroyed_event; rtc::Event frame_destroyed_event;
video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event));
EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeout));
} }
TEST_F(VideoStreamEncoderTest, DropsPendingFramesOnSlowEncode) { TEST_F(VideoStreamEncoderTest, DropsPendingFramesOnSlowEncode) {
@ -4285,14 +4287,14 @@ TEST_F(BalancedDegradationTest,
// Insert frame, expect scaled down: // Insert frame, expect scaled down:
// framerate (640x360@24fps) -> resolution (480x270@24fps). // framerate (640x360@24fps) -> resolution (480x270@24fps).
InsertFrame(); InsertFrame();
EXPECT_FALSE(WaitForFrame(1000)); EXPECT_FALSE(WaitForFrame(TimeDelta::Seconds(1)));
EXPECT_LT(source_.sink_wants().max_pixel_count, kWidth * kHeight); EXPECT_LT(source_.sink_wants().max_pixel_count, kWidth * kHeight);
EXPECT_EQ(source_.sink_wants().max_framerate_fps, 24); EXPECT_EQ(source_.sink_wants().max_framerate_fps, 24);
// Insert frame, expect scaled down: // Insert frame, expect scaled down:
// resolution (320x180@24fps). // resolution (320x180@24fps).
InsertFrame(); InsertFrame();
EXPECT_FALSE(WaitForFrame(1000)); EXPECT_FALSE(WaitForFrame(TimeDelta::Seconds(1)));
EXPECT_LT(source_.sink_wants().max_pixel_count, EXPECT_LT(source_.sink_wants().max_pixel_count,
source_.last_wants().max_pixel_count); source_.last_wants().max_pixel_count);
EXPECT_EQ(source_.sink_wants().max_framerate_fps, 24); EXPECT_EQ(source_.sink_wants().max_framerate_fps, 24);
@ -6395,7 +6397,7 @@ TEST_F(VideoStreamEncoderTest,
timestamp_ms += kFrameIntervalMs; timestamp_ms += kFrameIntervalMs;
video_source_.IncomingCapturedFrame( video_source_.IncomingCapturedFrame(
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight));
if (!WaitForFrame(kFrameTimeoutMs)) { if (!WaitForFrame(kFrameTimeout)) {
++num_frames_dropped; ++num_frames_dropped;
} else { } else {
sink_.CheckLastFrameSizeMatches(kFrameWidth, kFrameHeight); sink_.CheckLastFrameSizeMatches(kFrameWidth, kFrameHeight);
@ -6414,7 +6416,7 @@ TEST_F(VideoStreamEncoderTest,
timestamp_ms += kFrameIntervalMs; timestamp_ms += kFrameIntervalMs;
video_source_.IncomingCapturedFrame( video_source_.IncomingCapturedFrame(
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight));
if (!WaitForFrame(kFrameTimeoutMs)) { if (!WaitForFrame(kFrameTimeout)) {
++num_frames_dropped; ++num_frames_dropped;
} else { } else {
sink_.CheckLastFrameSizeMatches(kFrameWidth, kFrameHeight); sink_.CheckLastFrameSizeMatches(kFrameWidth, kFrameHeight);
@ -6430,7 +6432,7 @@ TEST_F(VideoStreamEncoderTest,
timestamp_ms += kFrameIntervalMs; timestamp_ms += kFrameIntervalMs;
video_source_.IncomingCapturedFrame( video_source_.IncomingCapturedFrame(
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight));
if (!WaitForFrame(kFrameTimeoutMs)) { if (!WaitForFrame(kFrameTimeout)) {
++num_frames_dropped; ++num_frames_dropped;
} else { } else {
sink_.CheckLastFrameSizeMatches(kFrameWidth, kFrameHeight); sink_.CheckLastFrameSizeMatches(kFrameWidth, kFrameHeight);
@ -6446,7 +6448,7 @@ TEST_F(VideoStreamEncoderTest,
timestamp_ms += kFrameIntervalMs; timestamp_ms += kFrameIntervalMs;
video_source_.IncomingCapturedFrame( video_source_.IncomingCapturedFrame(
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight));
if (!WaitForFrame(kFrameTimeoutMs)) { if (!WaitForFrame(kFrameTimeout)) {
++num_frames_dropped; ++num_frames_dropped;
} else { } else {
sink_.CheckLastFrameSizeMatches(kFrameWidth, kFrameHeight); sink_.CheckLastFrameSizeMatches(kFrameWidth, kFrameHeight);
@ -6988,7 +6990,7 @@ TEST_F(VideoStreamEncoderTest, PeriodicallyUpdatesChannelParameters) {
// Insert 30fps frames for just a little more than the forced update period. // Insert 30fps frames for just a little more than the forced update period.
const int kVcmTimerIntervalFrames = (kProcessIntervalMs * kHighFps) / 1000; const int kVcmTimerIntervalFrames = (kProcessIntervalMs * kHighFps) / 1000;
const int kFrameIntervalMs = 1000 / kHighFps; constexpr TimeDelta kFrameInterval = TimeDelta::Seconds(1) / kHighFps;
max_framerate_ = kHighFps; max_framerate_ = kHighFps;
for (int i = 0; i < kVcmTimerIntervalFrames + 2; ++i) { for (int i = 0; i < kVcmTimerIntervalFrames + 2; ++i) {
video_source_.IncomingCapturedFrame( video_source_.IncomingCapturedFrame(
@ -6997,8 +6999,8 @@ TEST_F(VideoStreamEncoderTest, PeriodicallyUpdatesChannelParameters) {
// be dropped if the encoder hans't been updated with the new higher target // be dropped if the encoder hans't been updated with the new higher target
// framerate yet, causing it to overshoot the target bitrate and then // framerate yet, causing it to overshoot the target bitrate and then
// suffering the wrath of the media optimizer. // suffering the wrath of the media optimizer.
TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameIntervalMs); TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameInterval);
timestamp_ms += kFrameIntervalMs; timestamp_ms += kFrameInterval.ms();
} }
// Don expect correct measurement just yet, but it should be higher than // Don expect correct measurement just yet, but it should be higher than
@ -7145,7 +7147,8 @@ TEST_F(VideoStreamEncoderTest, DropsFramesWhenEncoderOvershoots) {
video_source_.IncomingCapturedFrame( video_source_.IncomingCapturedFrame(
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight));
// Wait up to two frame durations for a frame to arrive. // Wait up to two frame durations for a frame to arrive.
if (!TimedWaitForEncodedFrame(timestamp_ms, 2 * 1000 / kFps)) { if (!TimedWaitForEncodedFrame(timestamp_ms,
2 * TimeDelta::Seconds(1) / kFps)) {
++num_dropped; ++num_dropped;
} }
timestamp_ms += 1000 / kFps; timestamp_ms += 1000 / kFps;
@ -7182,7 +7185,8 @@ TEST_F(VideoStreamEncoderTest, DropsFramesWhenEncoderOvershoots) {
video_source_.IncomingCapturedFrame( video_source_.IncomingCapturedFrame(
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight));
// Wait up to two frame durations for a frame to arrive. // Wait up to two frame durations for a frame to arrive.
if (!TimedWaitForEncodedFrame(timestamp_ms, 2 * 1000 / kFps)) { if (!TimedWaitForEncodedFrame(timestamp_ms,
2 * TimeDelta::Seconds(1) / kFps)) {
++num_dropped; ++num_dropped;
} }
timestamp_ms += 1000 / kFps; timestamp_ms += 1000 / kFps;
@ -7651,7 +7655,7 @@ TEST_F(VideoStreamEncoderTest, EncoderSelectorBrokenEncoderSwitch) {
.WillOnce([&encode_attempted]() { encode_attempted.Set(); }); .WillOnce([&encode_attempted]() { encode_attempted.Set(); });
video_source_.IncomingCapturedFrame(CreateFrame(1, kDontCare, kDontCare)); video_source_.IncomingCapturedFrame(CreateFrame(1, kDontCare, kDontCare));
encode_attempted.Wait(3000); encode_attempted.Wait(TimeDelta::Seconds(3));
AdvanceTime(TimeDelta::Zero()); AdvanceTime(TimeDelta::Zero());
@ -7695,7 +7699,7 @@ TEST_F(VideoStreamEncoderTest, SwitchEncoderOnInitFailureWithEncoderSelector) {
.WillOnce([&encode_attempted]() { encode_attempted.Set(); }); .WillOnce([&encode_attempted]() { encode_attempted.Set(); });
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
encode_attempted.Wait(3000); encode_attempted.Wait(TimeDelta::Seconds(3));
AdvanceTime(TimeDelta::Zero()); AdvanceTime(TimeDelta::Zero());
@ -7737,7 +7741,7 @@ TEST_F(VideoStreamEncoderTest,
.WillOnce([&encode_attempted]() { encode_attempted.Set(); }); .WillOnce([&encode_attempted]() { encode_attempted.Set(); });
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
encode_attempted.Wait(3000); encode_attempted.Wait(TimeDelta::Seconds(3));
AdvanceTime(TimeDelta::Zero()); AdvanceTime(TimeDelta::Zero());
@ -7788,7 +7792,7 @@ TEST_F(VideoStreamEncoderTest, NullEncoderReturnSwitch) {
.WillOnce([&encode_attempted]() { encode_attempted.Set(); }); .WillOnce([&encode_attempted]() { encode_attempted.Set(); });
video_source_.IncomingCapturedFrame(CreateFrame(1, kDontCare, kDontCare)); video_source_.IncomingCapturedFrame(CreateFrame(1, kDontCare, kDontCare));
encode_attempted.Wait(3000); encode_attempted.Wait(TimeDelta::Seconds(3));
AdvanceTime(TimeDelta::Zero()); AdvanceTime(TimeDelta::Zero());
@ -8165,7 +8169,7 @@ TEST_F(VideoStreamEncoderTest, QpPresent_QpKept) {
CodecSpecificInfo codec_info; CodecSpecificInfo codec_info;
codec_info.codecType = kVideoCodecVP8; codec_info.codecType = kVideoCodecVP8;
fake_encoder_.InjectEncodedImage(encoded_image, &codec_info); fake_encoder_.InjectEncodedImage(encoded_image, &codec_info);
EXPECT_TRUE(sink_.WaitForFrame(kDefaultTimeoutMs)); EXPECT_TRUE(sink_.WaitForFrame(kDefaultTimeout));
EXPECT_EQ(sink_.GetLastEncodedImage().qp_, 123); EXPECT_EQ(sink_.GetLastEncodedImage().qp_, 123);
video_stream_encoder_->Stop(); video_stream_encoder_->Stop();
} }
@ -8187,7 +8191,7 @@ TEST_F(VideoStreamEncoderTest, QpAbsent_QpParsed) {
CodecSpecificInfo codec_info; CodecSpecificInfo codec_info;
codec_info.codecType = kVideoCodecVP8; codec_info.codecType = kVideoCodecVP8;
fake_encoder_.InjectEncodedImage(encoded_image, &codec_info); fake_encoder_.InjectEncodedImage(encoded_image, &codec_info);
EXPECT_TRUE(sink_.WaitForFrame(kDefaultTimeoutMs)); EXPECT_TRUE(sink_.WaitForFrame(kDefaultTimeout));
EXPECT_EQ(sink_.GetLastEncodedImage().qp_, 25); EXPECT_EQ(sink_.GetLastEncodedImage().qp_, 25);
video_stream_encoder_->Stop(); video_stream_encoder_->Stop();
} }
@ -8210,7 +8214,7 @@ TEST_F(VideoStreamEncoderTest, QpAbsentParsingDisabled_QpAbsent) {
CodecSpecificInfo codec_info; CodecSpecificInfo codec_info;
codec_info.codecType = kVideoCodecVP8; codec_info.codecType = kVideoCodecVP8;
fake_encoder_.InjectEncodedImage(encoded_image, &codec_info); fake_encoder_.InjectEncodedImage(encoded_image, &codec_info);
EXPECT_TRUE(sink_.WaitForFrame(kDefaultTimeoutMs)); EXPECT_TRUE(sink_.WaitForFrame(kDefaultTimeout));
EXPECT_EQ(sink_.GetLastEncodedImage().qp_, -1); EXPECT_EQ(sink_.GetLastEncodedImage().qp_, -1);
video_stream_encoder_->Stop(); video_stream_encoder_->Stop();
} }
@ -8619,7 +8623,7 @@ TEST_F(VideoStreamEncoderTest,
// Frame should be dropped and destroyed. // Frame should be dropped and destroyed.
ExpectDroppedFrame(); ExpectDroppedFrame();
EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeout));
EXPECT_EQ(video_source_.refresh_frames_requested_, 0); EXPECT_EQ(video_source_.refresh_frames_requested_, 0);
// Set bitrates, unpausing the encoder and triggering a request for a refresh // Set bitrates, unpausing the encoder and triggering a request for a refresh