Index: webrtc/media/base/videoadapter_unittest.cc |
diff --git a/webrtc/media/base/videoadapter_unittest.cc b/webrtc/media/base/videoadapter_unittest.cc |
index a1c910c5ca4c1610242c8107c5ae4bce04f66a38..d128860891262e6e5e7f2b3a7dfea3bc3e66b7c7 100644 |
--- a/webrtc/media/base/videoadapter_unittest.cc |
+++ b/webrtc/media/base/videoadapter_unittest.cc |
@@ -24,17 +24,6 @@ |
namespace cricket { |
-namespace { |
-static const uint32_t kWaitTimeout = 3000U; // 3 seconds. |
-static const uint32_t kShortWaitTimeout = 1000U; // 1 second. |
- void UpdateCpuLoad(CoordinatedVideoAdapter* adapter, |
- int current_cpus, int max_cpus, float process_load, float system_load) { |
- adapter->set_cpu_load_min_samples(1); |
- adapter->OnCpuLoadUpdated(current_cpus, max_cpus, |
- process_load, system_load); |
- } |
-} |
- |
class VideoAdapterTest : public testing::Test { |
public: |
virtual void SetUp() { |
@@ -412,11 +401,6 @@ TEST(CoordinatedVideoAdapterTest, TestCoordinatedWithoutCpuAdaptation) { |
EXPECT_EQ(640, adapter.output_format().width); |
EXPECT_EQ(400, adapter.output_format().height); |
- // Cpu load is high, but cpu adaptation is disabled. Adapt nothing. |
- adapter.OnCpuLoadUpdated(1, 1, 0.99f, 0.99f); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
// Encoder resolution request: downgrade with different size. Adapt nothing. |
adapter.OnEncoderResolutionRequest(320, 200, |
CoordinatedVideoAdapter::DOWNGRADE); |
@@ -531,230 +515,6 @@ TEST(CoordinatedVideoAdapterTest, TestCoordinatedWithoutCpuAdaptation) { |
EXPECT_EQ(300, adapter.output_format().height); |
} |
-TEST(CoordinatedVideoAdapterTest, TestCoordinatedWithCpuAdaptation) { |
- CoordinatedVideoAdapter adapter; |
- adapter.set_cpu_adaptation(true); |
- EXPECT_FALSE(adapter.cpu_smoothing()); |
- VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), FOURCC_I420); |
- adapter.SetInputFormat(format); |
- |
- // Server format request 640x400. |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
- // Process load is medium, but system load is high. Downgrade. |
- UpdateCpuLoad(&adapter, 1, 1, 0.55f, 0.98f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // CPU high, but cpu adaptation disabled. Adapt nothing. |
- adapter.set_cpu_adaptation(false); |
- adapter.OnCpuLoadUpdated(1, 1, 0.55f, 0.98f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- adapter.set_cpu_adaptation(true); |
- |
- // System load is high, but time has not elaspsed. Adapt nothing. |
- adapter.set_cpu_load_min_samples(2); |
- adapter.OnCpuLoadUpdated(1, 1, 0.55f, 0.98f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // Process load is medium, but system load is high. Downgrade. |
- UpdateCpuLoad(&adapter, 1, 1, 0.55f, 0.98f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Test reason for adapting is CPU. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_CPU, |
- adapter.adapt_reason()); |
- |
- // Server format request 320x200. Same as CPU. Do nothing. |
- format.width = 320; |
- format.height = 200; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Test reason for adapting is CPU and VIEW. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_CPU + |
- CoordinatedVideoAdapter::ADAPTREASON_VIEW, |
- adapter.adapt_reason()); |
- |
- // Process load and system load are normal. Adapt nothing. |
- UpdateCpuLoad(&adapter, 1, 1, 0.5f, 0.8f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Process load and system load are low, but view is still low. Adapt nothing. |
- UpdateCpuLoad(&adapter, 1, 1, 0.2f, 0.3f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Test reason for adapting is VIEW. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_VIEW, |
- adapter.adapt_reason()); |
- |
- // Server format request 640x400. Cpu is still low. Upgrade. |
- format.width = 640; |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // Test reason for adapting is CPU. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_CPU, |
- adapter.adapt_reason()); |
- |
- // Encoder resolution request: downgrade. |
- adapter.OnEncoderResolutionRequest(480, 300, |
- CoordinatedVideoAdapter::DOWNGRADE); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Test reason for adapting is BANDWIDTH. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH, |
- adapter.adapt_reason()); |
- |
- // Process load and system load are low. Constrained by GD. Adapt nothing |
- adapter.OnCpuLoadUpdated(1, 1, 0.2f, 0.3f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Encoder resolution request: upgrade. |
- adapter.OnEncoderResolutionRequest(320, 200, |
- CoordinatedVideoAdapter::UPGRADE); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // Encoder resolution request: upgrade. Constrained by CPU. |
- adapter.OnEncoderResolutionRequest(480, 300, |
- CoordinatedVideoAdapter::UPGRADE); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // Server format request 640x400. Constrained by CPU. |
- format.width = 640; |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
-} |
- |
-TEST(CoordinatedVideoAdapterTest, TestCoordinatedWithCpuRequest) { |
- CoordinatedVideoAdapter adapter; |
- adapter.set_cpu_adaptation(true); |
- EXPECT_FALSE(adapter.cpu_smoothing()); |
- VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), FOURCC_I420); |
- adapter.SetInputFormat(format); |
- |
- // Server format request 640x400. |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
- // CPU resolution request: downgrade. Adapt down. |
- adapter.OnCpuResolutionRequest(CoordinatedVideoAdapter::DOWNGRADE); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // CPU resolution request: keep. Do nothing. |
- adapter.OnCpuResolutionRequest(CoordinatedVideoAdapter::KEEP); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // CPU resolution request: downgrade, but cpu adaptation disabled. |
- // Adapt nothing. |
- adapter.set_cpu_adaptation(false); |
- adapter.OnCpuResolutionRequest(CoordinatedVideoAdapter::DOWNGRADE); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // CPU resolution request: downgrade. Adapt down. |
- adapter.set_cpu_adaptation(true); |
- adapter.OnCpuResolutionRequest(CoordinatedVideoAdapter::DOWNGRADE); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Test reason for adapting is CPU. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_CPU, |
- adapter.adapt_reason()); |
- |
- // CPU resolution request: downgrade, but already at minimum. Do nothing. |
- adapter.OnCpuResolutionRequest(CoordinatedVideoAdapter::DOWNGRADE); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Server format request 320x200. Same as CPU. Do nothing. |
- format.width = 320; |
- format.height = 200; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Test reason for adapting is CPU and VIEW. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_CPU + |
- CoordinatedVideoAdapter::ADAPTREASON_VIEW, |
- adapter.adapt_reason()); |
- |
- // CPU resolution request: upgrade, but view request still low. Do nothing. |
- adapter.OnCpuResolutionRequest(CoordinatedVideoAdapter::UPGRADE); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Test reason for adapting is VIEW. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_VIEW, |
- adapter.adapt_reason()); |
- |
- // Server format request 640x400. Cpu is still low. Upgrade. |
- format.width = 640; |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // Test reason for adapting is CPU. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_CPU, |
- adapter.adapt_reason()); |
- |
- // Encoder resolution request: downgrade. |
- adapter.OnEncoderResolutionRequest(480, 300, |
- CoordinatedVideoAdapter::DOWNGRADE); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Test reason for adapting is BANDWIDTH. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH, |
- adapter.adapt_reason()); |
- |
- // Process load and system load are low. Constrained by GD. Adapt nothing |
- adapter.OnCpuLoadUpdated(1, 1, 0.2f, 0.3f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Encoder resolution request: upgrade. |
- adapter.OnEncoderResolutionRequest(320, 200, |
- CoordinatedVideoAdapter::UPGRADE); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // Encoder resolution request: upgrade. Constrained by CPU. |
- adapter.OnEncoderResolutionRequest(480, 300, |
- CoordinatedVideoAdapter::UPGRADE); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // Server format request 640x400. Constrained by CPU. |
- format.width = 640; |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
-} |
- |
TEST(CoordinatedVideoAdapterTest, TestViewRequestPlusCameraSwitch) { |
CoordinatedVideoAdapter adapter; |
adapter.set_view_switch(true); |
@@ -816,17 +576,6 @@ TEST(CoordinatedVideoAdapterTest, TestVGAWidth) { |
VideoFormat out_format = adapter.AdaptFrameResolution(640, 360); |
EXPECT_EQ(640, out_format.width); |
EXPECT_EQ(360, out_format.height); |
- |
- // Similarly, no-op adapt requests for other reasons shouldn't change |
- // adaptation state (before a previous bug, the previous EXPECTs would |
- // fail and the following would succeed, as the no-op CPU request would |
- // fix the adaptation state). |
- adapter.set_cpu_adaptation(true); |
- UpdateCpuLoad(&adapter, 1, 1, 0.7f, 0.7f); |
- out_format = adapter.AdaptFrameResolution(640, 360); |
- |
- EXPECT_EQ(640, out_format.width); |
- EXPECT_EQ(360, out_format.height); |
} |
// When adapting resolution for CPU or GD, the quantity of pixels that the |
@@ -858,163 +607,11 @@ TEST(CoordinatedVideoAdapterTest, TestCoordinatedViewRequestDown) { |
EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_VIEW, adapter.adapt_reason()); |
} |
-// Test that we downgrade video for cpu up to two times. |
-TEST(CoordinatedVideoAdapterTest, TestCpuDowngradeTimes) { |
- CoordinatedVideoAdapter adapter; |
- adapter.set_cpu_adaptation(true); |
- EXPECT_FALSE(adapter.cpu_smoothing()); |
- VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), FOURCC_I420); |
- adapter.SetInputFormat(format); |
- |
- // Server format request 640x400. |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
- // Process load and system load are low. Do not change the cpu desired format |
- // and do not adapt. |
- adapter.OnCpuLoadUpdated(1, 1, 0.2f, 0.3f); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
- // System load is high. Downgrade. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // System load is high. Downgrade again. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // System load is still high. Do not downgrade any more. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Process load and system load are low. Upgrade. |
- UpdateCpuLoad(&adapter, 1, 1, 0.2f, 0.3f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // System load is high. Downgrade. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // System load is still high. Do not downgrade any more. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
-} |
- |
-// Test that we respect CPU adapter threshold values. |
-TEST(CoordinatedVideoAdapterTest, TestAdapterCpuThreshold) { |
- CoordinatedVideoAdapter adapter; |
- adapter.set_cpu_adaptation(true); |
- EXPECT_FALSE(adapter.cpu_smoothing()); |
- VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), FOURCC_I420); |
- adapter.SetInputFormat(format); |
- |
- // Server format request 640x400. |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
- // Process load and system load are low. Do not change the cpu desired format |
- // and do not adapt. |
- adapter.OnCpuLoadUpdated(1, 1, 0.2f, 0.3f); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
- // System load is high. Downgrade. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // Test reason for adapting is CPU. |
- EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_CPU, adapter.adapt_reason()); |
- |
- // System load is high. Normally downgrade but threshold is high. Do nothing. |
- adapter.set_high_system_threshold(0.98f); // Set threshold high. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(300, adapter.output_format().height); |
- |
- // System load is medium. Normally do nothing, threshold is low. Adapt down. |
- adapter.set_high_system_threshold(0.75f); // Set threshold low. |
- UpdateCpuLoad(&adapter, 1, 1, 0.8f, 0.8f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
-} |
- |
- |
-// Test that for an upgrade cpu request, we actually upgrade the desired format; |
-// for a downgrade request, we downgrade from the output format. |
-TEST(CoordinatedVideoAdapterTest, TestRealCpuUpgrade) { |
- CoordinatedVideoAdapter adapter; |
- adapter.set_cpu_adaptation(true); |
- adapter.set_cpu_smoothing(true); |
- VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), FOURCC_I420); |
- adapter.SetInputFormat(format); |
- |
- // Server format request 640x400. |
- format.width = 640; |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
- // Process load and system load are low. Do not change the cpu desired format |
- // and do not adapt. |
- UpdateCpuLoad(&adapter, 1, 1, 0.2f, 0.3f); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
- // Server format request 320x200. |
- format.width = 320; |
- format.height = 200; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Process load and system load are low. Do not change the cpu desired format |
- // and do not adapt. |
- UpdateCpuLoad(&adapter, 1, 1, 0.2f, 0.3f); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Server format request 640x400. Set to 640x400 immediately. |
- format.width = 640; |
- format.height = 400; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(400, adapter.output_format().height); |
- |
- // Server format request 320x200. |
- format.width = 320; |
- format.height = 200; |
- adapter.OnOutputFormatRequest(format); |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
- |
- // Process load is high, but system is not. Do not change the cpu desired |
- // format and do not adapt. |
- for (size_t i = 0; i < 10; ++i) { |
- UpdateCpuLoad(&adapter, 1, 1, 0.75f, 0.8f); |
- } |
- EXPECT_EQ(320, adapter.output_format().width); |
- EXPECT_EQ(200, adapter.output_format().height); |
-} |
- |
// Test that for an upgrade encoder request, we actually upgrade the desired |
// format; for a downgrade request, we downgrade from the output format. |
TEST(CoordinatedVideoAdapterTest, TestRealEncoderUpgrade) { |
CoordinatedVideoAdapter adapter; |
adapter.set_cpu_adaptation(true); |
- adapter.set_cpu_smoothing(true); |
VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), FOURCC_I420); |
adapter.SetInputFormat(format); |
@@ -1139,152 +736,5 @@ TEST(CoordinatedVideoAdapterTest, TestNormalizeOutputFormat) { |
EXPECT_EQ(VideoFormat::FpsToInterval(15), adapter.output_format().interval); |
} |
-// Test that we downgrade video for cpu up to two times. |
-TEST_F(VideoAdapterTest, CpuDowngradeAndSignal) { |
- CoordinatedVideoAdapter adapter; |
- CpuAdapterListener cpu_listener; |
- adapter.SignalCpuAdaptationUnable.connect( |
- &cpu_listener, &CpuAdapterListener::OnCpuAdaptationSignalled); |
- |
- adapter.set_cpu_adaptation(true); |
- EXPECT_FALSE(adapter.cpu_smoothing()); |
- VideoFormat format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); |
- adapter.SetInputFormat(format); |
- adapter.OnOutputFormatRequest(format); |
- |
- // System load is high. Downgrade. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- |
- // System load is high. Downgrade again. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- |
- // System load is still high. Do not downgrade any more. Ensure we have not |
- // signalled until after the cpu warning though. |
- EXPECT_TRUE(!cpu_listener.received_cpu_signal()); |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- EXPECT_TRUE_WAIT(cpu_listener.received_cpu_signal(), kWaitTimeout); |
-} |
- |
-// Test that we downgrade video for cpu up to two times. |
-TEST_F(VideoAdapterTest, CpuDowngradeAndDontSignal) { |
- CoordinatedVideoAdapter adapter; |
- CpuAdapterListener cpu_listener; |
- adapter.SignalCpuAdaptationUnable.connect( |
- &cpu_listener, &CpuAdapterListener::OnCpuAdaptationSignalled); |
- |
- adapter.set_cpu_adaptation(true); |
- adapter.set_cpu_smoothing(true); |
- VideoFormat format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); |
- adapter.SetInputFormat(format); |
- adapter.OnOutputFormatRequest(format); |
- |
- // System load is high. Downgrade. |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- |
- // System load is high, process is not, Do not downgrade again. |
- UpdateCpuLoad(&adapter, 1, 1, 0.25f, 0.95f); |
- |
- // System load is high, process is not, Do not downgrade again and do not |
- // signal. |
- adapter.set_cpu_adaptation(false); |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- rtc::Thread::Current()->ProcessMessages(kShortWaitTimeout); |
- EXPECT_TRUE(!cpu_listener.received_cpu_signal()); |
- adapter.set_cpu_adaptation(true); |
-} |
- |
-// Test that we require enough time before we downgrade. |
-TEST_F(VideoAdapterTest, CpuMinTimeRequirement) { |
- CoordinatedVideoAdapter adapter; |
- CpuAdapterListener cpu_listener; |
- adapter.SignalCpuAdaptationUnable.connect( |
- &cpu_listener, &CpuAdapterListener::OnCpuAdaptationSignalled); |
- |
- adapter.set_cpu_adaptation(true); |
- adapter.set_cpu_smoothing(true); |
- VideoFormat format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); |
- adapter.SetInputFormat(format); |
- adapter.OnOutputFormatRequest(format); |
- |
- EXPECT_EQ(3, adapter.cpu_load_min_samples()); |
- adapter.set_cpu_load_min_samples(5); |
- |
- for (size_t i = 0; i < 4; ++i) { |
- adapter.OnCpuLoadUpdated(1, 1, 1.0f, 1.0f); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(360, adapter.output_format().height); |
- } |
- // The computed cpu load should now be around 93.5%, with the coefficient of |
- // 0.4 and a seed value of 0.5. That should be high enough to adapt, but it |
- // isn't enough samples, so we shouldn't have adapted on any of the previous |
- // samples. |
- |
- // One more sample is enough, though, once enough time has passed. |
- adapter.OnCpuLoadUpdated(1, 1, 1.0f, 1.0f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(270, adapter.output_format().height); |
- |
- // Now the cpu is lower, but we still need enough samples to upgrade. |
- for (size_t i = 0; i < 4; ++i) { |
- adapter.OnCpuLoadUpdated(1, 1, 0.1f, 0.1f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(270, adapter.output_format().height); |
- } |
- |
- // One more sample is enough, once time has elapsed. |
- adapter.OnCpuLoadUpdated(1, 1, 1.0f, 1.0f); |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(360, adapter.output_format().height); |
-} |
- |
-TEST_F(VideoAdapterTest, CpuIgnoresSpikes) { |
- CoordinatedVideoAdapter adapter; |
- CpuAdapterListener cpu_listener; |
- adapter.SignalCpuAdaptationUnable.connect( |
- &cpu_listener, &CpuAdapterListener::OnCpuAdaptationSignalled); |
- |
- adapter.set_cpu_adaptation(true); |
- adapter.set_cpu_smoothing(true); |
- VideoFormat format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); |
- adapter.SetInputFormat(format); |
- adapter.OnOutputFormatRequest(format); |
- |
- // System load is high. Downgrade. |
- for (size_t i = 0; i < 5; ++i) { |
- UpdateCpuLoad(&adapter, 1, 1, 0.95f, 0.95f); |
- } |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(270, adapter.output_format().height); |
- |
- // Now we're in a state where we could upgrade or downgrade, so get to a |
- // steady state of about 75% cpu usage. |
- for (size_t i = 0; i < 5; ++i) { |
- UpdateCpuLoad(&adapter, 1, 1, 0.75f, 0.75f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(270, adapter.output_format().height); |
- } |
- |
- // Now, the cpu spikes for two samples, but then goes back to |
- // normal. This shouldn't cause adaptation. |
- UpdateCpuLoad(&adapter, 1, 1, 0.90f, 0.90f); |
- UpdateCpuLoad(&adapter, 1, 1, 0.90f, 0.90f); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(270, adapter.output_format().height); |
- // Back to the steady state for awhile. |
- for (size_t i = 0; i < 5; ++i) { |
- UpdateCpuLoad(&adapter, 1, 1, 0.75, 0.75); |
- EXPECT_EQ(480, adapter.output_format().width); |
- EXPECT_EQ(270, adapter.output_format().height); |
- } |
- |
- // Now, system cpu usage is starting to drop down. But it takes a bit before |
- // it gets all the way there. |
- for (size_t i = 0; i < 10; ++i) { |
- UpdateCpuLoad(&adapter, 1, 1, 0.5f, 0.5f); |
- } |
- EXPECT_EQ(640, adapter.output_format().width); |
- EXPECT_EQ(360, adapter.output_format().height); |
-} |
- |
} // namespace cricket |
#endif // HAVE_WEBRTC_VIDEO |