Index: webrtc/video/overuse_frame_detector_unittest.cc |
diff --git a/webrtc/video/overuse_frame_detector_unittest.cc b/webrtc/video/overuse_frame_detector_unittest.cc |
index 2c53f7df3cedb0b1a8c9d876bd2a066a543c9aa9..2ed3fae14042bc19c855860773aa536a567d9cef 100644 |
--- a/webrtc/video/overuse_frame_detector_unittest.cc |
+++ b/webrtc/video/overuse_frame_detector_unittest.cc |
@@ -12,7 +12,7 @@ |
#include "webrtc/api/video/i420_buffer.h" |
#include "webrtc/base/event.h" |
-#include "webrtc/system_wrappers/include/clock.h" |
+#include "webrtc/base/fakeclock.h" |
#include "webrtc/test/gmock.h" |
#include "webrtc/test/gtest.h" |
#include "webrtc/video/overuse_frame_detector.h" |
@@ -26,9 +26,8 @@ using ::testing::InvokeWithoutArgs; |
namespace { |
const int kWidth = 640; |
const int kHeight = 480; |
- const int kFrameInterval33ms = 33; |
- const int kProcessIntervalMs = 5000; |
- const int kProcessTime5ms = 5; |
+ const int kFrameIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; |
+ const int kProcessTimeUs = 5 * rtc::kNumMicrosecsPerMillisec; |
} // namespace |
class MockCpuOveruseObserver : public ScalingObserverInterface { |
@@ -56,13 +55,11 @@ class CpuOveruseObserverImpl : public ScalingObserverInterface { |
class OveruseFrameDetectorUnderTest : public OveruseFrameDetector { |
public: |
- OveruseFrameDetectorUnderTest(Clock* clock, |
- const CpuOveruseOptions& options, |
+ OveruseFrameDetectorUnderTest(const CpuOveruseOptions& options, |
ScalingObserverInterface* overuse_observer, |
EncodedFrameObserver* encoder_timing, |
CpuOveruseMetricsObserver* metrics_observer) |
- : OveruseFrameDetector(clock, |
- options, |
+ : OveruseFrameDetector(options, |
overuse_observer, |
encoder_timing, |
metrics_observer) {} |
@@ -75,7 +72,6 @@ class OveruseFrameDetectorTest : public ::testing::Test, |
public CpuOveruseMetricsObserver { |
protected: |
void SetUp() override { |
- clock_.reset(new SimulatedClock(1234)); |
observer_.reset(new MockCpuOveruseObserver()); |
options_.min_process_count = 0; |
ReinitializeOveruseDetector(); |
@@ -83,7 +79,7 @@ class OveruseFrameDetectorTest : public ::testing::Test, |
void ReinitializeOveruseDetector() { |
overuse_detector_.reset(new OveruseFrameDetectorUnderTest( |
- clock_.get(), options_, observer_.get(), nullptr, this)); |
+ options_, observer_.get(), nullptr, this)); |
} |
void OnEncodedFrameTimeMeasured(int encode_time_ms, |
@@ -97,20 +93,20 @@ class OveruseFrameDetectorTest : public ::testing::Test, |
} |
void InsertAndSendFramesWithInterval(int num_frames, |
- int interval_ms, |
+ int interval_us, |
int width, |
int height, |
- int delay_ms) { |
+ int delay_us) { |
VideoFrame frame(I420Buffer::Create(width, height), |
webrtc::kVideoRotation_0, 0); |
uint32_t timestamp = 0; |
while (num_frames-- > 0) { |
frame.set_timestamp(timestamp); |
- overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds()); |
- clock_->AdvanceTimeMilliseconds(delay_ms); |
- overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds()); |
- clock_->AdvanceTimeMilliseconds(interval_ms - delay_ms); |
- timestamp += interval_ms * 90; |
+ overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); |
+ clock_.AdvanceTimeMicros(delay_us); |
+ overuse_detector_->FrameSent(timestamp, rtc::TimeMicros()); |
+ clock_.AdvanceTimeMicros(interval_us - delay_us); |
+ timestamp += interval_us * 90 / 1000; |
} |
} |
@@ -119,31 +115,32 @@ class OveruseFrameDetectorTest : public ::testing::Test, |
// the usage. From the tests where these are used, adding another sample |
// doesn't affect the expected outcome (this is mainly to check initial |
// values and whether the overuse detector has been reset or not). |
- InsertAndSendFramesWithInterval(2, 1000, width, height, kFrameInterval33ms); |
+ InsertAndSendFramesWithInterval(2, rtc::kNumMicrosecsPerSec, |
+ width, height, kFrameIntervalUs); |
} |
void TriggerOveruse(int num_times) { |
- const int kDelayMs = 32; |
+ const int kDelayUs = 32 * rtc::kNumMicrosecsPerMillisec; |
for (int i = 0; i < num_times; ++i) { |
InsertAndSendFramesWithInterval( |
- 1000, kFrameInterval33ms, kWidth, kHeight, kDelayMs); |
+ 1000, kFrameIntervalUs, kWidth, kHeight, kDelayUs); |
overuse_detector_->CheckForOveruse(); |
} |
} |
void TriggerUnderuse() { |
- const int kDelayMs1 = 5; |
- const int kDelayMs2 = 6; |
+ const int kDelayUs1 = 5000; |
+ const int kDelayUs2 = 6000; |
InsertAndSendFramesWithInterval( |
- 1300, kFrameInterval33ms, kWidth, kHeight, kDelayMs1); |
+ 1300, kFrameIntervalUs, kWidth, kHeight, kDelayUs1); |
InsertAndSendFramesWithInterval( |
- 1, kFrameInterval33ms, kWidth, kHeight, kDelayMs2); |
+ 1, kFrameIntervalUs, kWidth, kHeight, kDelayUs2); |
overuse_detector_->CheckForOveruse(); |
} |
int UsagePercent() { return metrics_.encode_usage_percent; } |
CpuOveruseOptions options_; |
- std::unique_ptr<SimulatedClock> clock_; |
+ rtc::ScopedFakeClock clock_; |
std::unique_ptr<MockCpuOveruseObserver> observer_; |
std::unique_ptr<OveruseFrameDetectorUnderTest> overuse_detector_; |
CpuOveruseMetrics metrics_; |
@@ -171,7 +168,7 @@ TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) { |
TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) { |
overuse_detector_.reset(new OveruseFrameDetectorUnderTest( |
- clock_.get(), options_, nullptr, nullptr, this)); |
+ options_, nullptr, nullptr, this)); |
EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)).Times(0); |
TriggerOveruse(options_.high_threshold_consecutive_count); |
EXPECT_CALL(*(observer_.get()), ScaleUp(reason_)).Times(0); |
@@ -187,15 +184,16 @@ TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) { |
} |
TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) { |
+ const int kProcessIntervalUs = 5 * rtc::kNumMicrosecsPerSec; |
options_.min_process_count = 1; |
CpuOveruseObserverImpl overuse_observer; |
overuse_detector_.reset(new OveruseFrameDetectorUnderTest( |
- clock_.get(), options_, &overuse_observer, nullptr, this)); |
+ options_, &overuse_observer, nullptr, this)); |
InsertAndSendFramesWithInterval( |
- 1200, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
+ 1200, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); |
overuse_detector_->CheckForOveruse(); |
EXPECT_EQ(0, overuse_observer.normaluse_); |
- clock_->AdvanceTimeMilliseconds(kProcessIntervalMs); |
+ clock_.AdvanceTimeMicros(kProcessIntervalUs); |
overuse_detector_->CheckForOveruse(); |
EXPECT_EQ(1, overuse_observer.normaluse_); |
} |
@@ -224,15 +222,15 @@ TEST_F(OveruseFrameDetectorTest, IncorrectConsecutiveCountTriggersNoOveruse) { |
TEST_F(OveruseFrameDetectorTest, ProcessingUsage) { |
InsertAndSendFramesWithInterval( |
- 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
- EXPECT_EQ(kProcessTime5ms * 100 / kFrameInterval33ms, UsagePercent()); |
+ 1000, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); |
+ EXPECT_EQ(kProcessTimeUs * 100 / kFrameIntervalUs, UsagePercent()); |
} |
TEST_F(OveruseFrameDetectorTest, ResetAfterResolutionChange) { |
ForceUpdate(kWidth, kHeight); |
EXPECT_EQ(InitialUsage(), UsagePercent()); |
InsertAndSendFramesWithInterval( |
- 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
+ 1000, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); |
EXPECT_NE(InitialUsage(), UsagePercent()); |
// Verify reset (with new width/height). |
ForceUpdate(kWidth, kHeight + 1); |
@@ -243,15 +241,16 @@ TEST_F(OveruseFrameDetectorTest, ResetAfterFrameTimeout) { |
ForceUpdate(kWidth, kHeight); |
EXPECT_EQ(InitialUsage(), UsagePercent()); |
InsertAndSendFramesWithInterval( |
- 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
+ 1000, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); |
EXPECT_NE(InitialUsage(), UsagePercent()); |
InsertAndSendFramesWithInterval( |
- 2, options_.frame_timeout_interval_ms, kWidth, kHeight, kProcessTime5ms); |
+ 2, options_.frame_timeout_interval_ms * |
+ rtc::kNumMicrosecsPerMillisec, kWidth, kHeight, kProcessTimeUs); |
EXPECT_NE(InitialUsage(), UsagePercent()); |
// Verify reset. |
InsertAndSendFramesWithInterval( |
- 2, options_.frame_timeout_interval_ms + 1, kWidth, kHeight, |
- kProcessTime5ms); |
+ 2, (options_.frame_timeout_interval_ms + 1) * |
+ rtc::kNumMicrosecsPerMillisec, kWidth, kHeight, kProcessTimeUs); |
ForceUpdate(kWidth, kHeight); |
EXPECT_EQ(InitialUsage(), UsagePercent()); |
} |
@@ -260,19 +259,19 @@ TEST_F(OveruseFrameDetectorTest, MinFrameSamplesBeforeUpdating) { |
options_.min_frame_samples = 40; |
ReinitializeOveruseDetector(); |
InsertAndSendFramesWithInterval( |
- 40, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
+ 40, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); |
EXPECT_EQ(InitialUsage(), UsagePercent()); |
// Pass time far enough to digest all previous samples. |
- clock_->AdvanceTimeMilliseconds(1000); |
- InsertAndSendFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight, |
- kProcessTime5ms); |
+ clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec); |
+ InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight, |
+ kProcessTimeUs); |
// The last sample has not been processed here. |
EXPECT_EQ(InitialUsage(), UsagePercent()); |
// Pass time far enough to digest all previous samples, 41 in total. |
- clock_->AdvanceTimeMilliseconds(1000); |
+ clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec); |
InsertAndSendFramesWithInterval( |
- 1, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
+ 1, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); |
EXPECT_NE(InitialUsage(), UsagePercent()); |
} |
@@ -284,19 +283,19 @@ TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) { |
TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) { |
EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)) |
.Times(testing::AtLeast(1)); |
- static const int kIntervalMs = 33; |
+ static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; |
static const size_t kNumFramesEncodingDelay = 3; |
VideoFrame frame(I420Buffer::Create(kWidth, kHeight), |
webrtc::kVideoRotation_0, 0); |
for (size_t i = 0; i < 1000; ++i) { |
// Unique timestamps. |
frame.set_timestamp(static_cast<uint32_t>(i)); |
- overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds()); |
- clock_->AdvanceTimeMilliseconds(kIntervalMs); |
+ overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); |
+ clock_.AdvanceTimeMicros(kIntervalUs); |
if (i > kNumFramesEncodingDelay) { |
overuse_detector_->FrameSent( |
static_cast<uint32_t>(i - kNumFramesEncodingDelay), |
- clock_->TimeInMilliseconds()); |
+ rtc::TimeMicros()); |
} |
overuse_detector_->CheckForOveruse(); |
} |
@@ -306,22 +305,22 @@ TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) { |
// >85% encoding time should trigger overuse. |
EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)) |
.Times(testing::AtLeast(1)); |
- static const int kIntervalMs = 33; |
- static const int kDelayMs = 30; |
+ static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; |
+ static const int kDelayUs = 30 * rtc::kNumMicrosecsPerMillisec; |
VideoFrame frame(I420Buffer::Create(kWidth, kHeight), |
webrtc::kVideoRotation_0, 0); |
uint32_t timestamp = 0; |
for (size_t i = 0; i < 1000; ++i) { |
frame.set_timestamp(timestamp); |
- overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds()); |
+ overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); |
// Encode and send first parts almost instantly. |
- clock_->AdvanceTimeMilliseconds(1); |
- overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds()); |
+ clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec); |
+ overuse_detector_->FrameSent(timestamp, rtc::TimeMicros()); |
// Encode heavier part, resulting in >85% usage total. |
- clock_->AdvanceTimeMilliseconds(kDelayMs - 1); |
- overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds()); |
- clock_->AdvanceTimeMilliseconds(kIntervalMs - kDelayMs); |
- timestamp += kIntervalMs * 90; |
+ clock_.AdvanceTimeMicros(kDelayUs - rtc::kNumMicrosecsPerMillisec); |
+ overuse_detector_->FrameSent(timestamp, rtc::TimeMicros()); |
+ clock_.AdvanceTimeMicros(kIntervalUs - kDelayUs); |
+ timestamp += kIntervalUs * 90 / 1000; |
overuse_detector_->CheckForOveruse(); |
} |
} |
@@ -345,12 +344,12 @@ TEST_F(OveruseFrameDetectorTest, RunOnTqNormalUsage) { |
})); |
queue.PostTask([this, &event] { |
- const int kDelayMs1 = 5; |
- const int kDelayMs2 = 6; |
- InsertAndSendFramesWithInterval(1300, kFrameInterval33ms, kWidth, kHeight, |
- kDelayMs1); |
- InsertAndSendFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight, |
- kDelayMs2); |
+ const int kDelayUs1 = 5 * rtc::kNumMicrosecsPerMillisec; |
+ const int kDelayUs2 = 6 * rtc::kNumMicrosecsPerMillisec; |
+ InsertAndSendFramesWithInterval(1300, kFrameIntervalUs, kWidth, kHeight, |
+ kDelayUs1); |
+ InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight, |
+ kDelayUs2); |
}); |
EXPECT_TRUE(event.Wait(10000)); |