Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: webrtc/video/vie_encoder_unittest.cc

Issue 2887303003: Implement kBalanced degradation preference. (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« webrtc/video/vie_encoder.cc ('K') | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 16 matching lines...) Expand all
27 #include "webrtc/test/gtest.h" 27 #include "webrtc/test/gtest.h"
28 #include "webrtc/video/send_statistics_proxy.h" 28 #include "webrtc/video/send_statistics_proxy.h"
29 #include "webrtc/video/vie_encoder.h" 29 #include "webrtc/video/vie_encoder.h"
30 30
31 namespace { 31 namespace {
32 // TODO(kthelgason): Lower this limit when better testing 32 // TODO(kthelgason): Lower this limit when better testing
33 // on MediaCodec and fallback implementations are in place. 33 // on MediaCodec and fallback implementations are in place.
34 const int kMinPixelsPerFrame = 320 * 180; 34 const int kMinPixelsPerFrame = 320 * 180;
35 const int kMinFramerateFps = 2; 35 const int kMinFramerateFps = 2;
36 const int64_t kFrameTimeoutMs = 100; 36 const int64_t kFrameTimeoutMs = 100;
37 const int kBpsLimitFor15Fps = 500000;
38 const int kBpsLimitFor10Fps = 130000;
39 const int kBpsLimitFor7Fps = 60000;
37 } // namespace 40 } // namespace
38 41
39 namespace webrtc { 42 namespace webrtc {
40 43
41 using DegredationPreference = VideoSendStream::DegradationPreference; 44 using DegredationPreference = VideoSendStream::DegradationPreference;
42 using ScaleReason = AdaptationObserverInterface::AdaptReason; 45 using ScaleReason = AdaptationObserverInterface::AdaptReason;
43 using ::testing::_; 46 using ::testing::_;
44 using ::testing::Return; 47 using ::testing::Return;
45 48
46 namespace { 49 namespace {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count); 322 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count);
320 EXPECT_GT(wants1.max_pixel_count, 0); 323 EXPECT_GT(wants1.max_pixel_count, 0);
321 } 324 }
322 325
323 void VerifyFpsMaxResolutionGt(const rtc::VideoSinkWants& wants1, 326 void VerifyFpsMaxResolutionGt(const rtc::VideoSinkWants& wants1,
324 const rtc::VideoSinkWants& wants2) { 327 const rtc::VideoSinkWants& wants2) {
325 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps); 328 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps);
326 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count); 329 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count);
327 } 330 }
328 331
332 void VerifyFpsMaxResolutionEq(const rtc::VideoSinkWants& wants1,
333 const rtc::VideoSinkWants& wants2) {
334 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps);
335 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count);
336 }
337
338 void VerifyFpsLtResolutionEq(const rtc::VideoSinkWants& wants1,
339 const rtc::VideoSinkWants& wants2) {
340 EXPECT_LT(wants1.max_framerate_fps, wants2.max_framerate_fps);
341 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count);
342 }
343
344 void VerifyFpsGtResolutionEq(const rtc::VideoSinkWants& wants1,
345 const rtc::VideoSinkWants& wants2) {
346 EXPECT_GT(wants1.max_framerate_fps, wants2.max_framerate_fps);
347 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count);
348 }
349
350 void VerifyFpsEqResolutionLt(const rtc::VideoSinkWants& wants1,
351 const rtc::VideoSinkWants& wants2) {
352 EXPECT_EQ(wants1.max_framerate_fps, wants2.max_framerate_fps);
353 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count);
354 EXPECT_GT(wants1.max_pixel_count, 0);
355 }
356
357 void VerifyFpsEqResolutionGt(const rtc::VideoSinkWants& wants1,
358 const rtc::VideoSinkWants& wants2) {
359 EXPECT_EQ(wants1.max_framerate_fps, wants2.max_framerate_fps);
360 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count);
361 }
362
329 void VerifyFpsMaxResolutionLt(const rtc::VideoSinkWants& wants, 363 void VerifyFpsMaxResolutionLt(const rtc::VideoSinkWants& wants,
330 int pixel_count) { 364 int pixel_count) {
331 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps); 365 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps);
332 EXPECT_LT(wants.max_pixel_count, pixel_count); 366 EXPECT_LT(wants.max_pixel_count, pixel_count);
333 EXPECT_GT(wants.max_pixel_count, 0); 367 EXPECT_GT(wants.max_pixel_count, 0);
334 } 368 }
335 369
336 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) { 370 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) {
337 EXPECT_LT(wants.max_framerate_fps, fps); 371 EXPECT_LT(wants.max_framerate_fps, fps);
338 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); 372 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count);
339 EXPECT_FALSE(wants.target_pixel_count); 373 EXPECT_FALSE(wants.target_pixel_count);
340 } 374 }
341 375
376 void VerifyFpsEqResolutionMax(const rtc::VideoSinkWants& wants,
377 int expected_fps) {
378 EXPECT_EQ(expected_fps, wants.max_framerate_fps);
379 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count);
380 EXPECT_FALSE(wants.target_pixel_count);
381 }
382
342 void WaitForEncodedFrame(int64_t expected_ntp_time) { 383 void WaitForEncodedFrame(int64_t expected_ntp_time) {
343 sink_.WaitForEncodedFrame(expected_ntp_time); 384 sink_.WaitForEncodedFrame(expected_ntp_time);
344 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); 385 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_);
345 } 386 }
346 387
347 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, int64_t timeout_ms) { 388 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, int64_t timeout_ms) {
348 bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, timeout_ms); 389 bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, timeout_ms);
349 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); 390 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_);
350 return ok; 391 return ok;
351 } 392 }
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 video_source_.sink_wants().target_pixel_count.value_or(0)); 894 video_source_.sink_wants().target_pixel_count.value_or(0));
854 EXPECT_EQ(frame_width * frame_height * 4, 895 EXPECT_EQ(frame_width * frame_height * 4,
855 video_source_.sink_wants().max_pixel_count); 896 video_source_.sink_wants().max_pixel_count);
856 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 897 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
857 EXPECT_EQ(kMaxDowngrades + 1, 898 EXPECT_EQ(kMaxDowngrades + 1,
858 stats_proxy_->GetStats().number_of_cpu_adapt_changes); 899 stats_proxy_->GetStats().number_of_cpu_adapt_changes);
859 900
860 vie_encoder_->Stop(); 901 vie_encoder_->Stop();
861 } 902 }
862 903
904 TEST_F(ViEEncoderTest, TestMaxCpuResolutionDowngrades_BalancedMode_NoFpsLimit) {
905 const int kMaxDowngrades = ViEEncoder::kMaxCpuResolutionDowngrades;
906 const int kWidth = 1280;
907 const int kHeight = 720;
908 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps + 1, 0, 0);
909
910 // Enable kBalanced preference, no initial limitation.
911 AdaptingFrameForwarder source;
912 source.set_adaptation_enabled(true);
913 vie_encoder_->SetSource(&source,
914 VideoSendStream::DegradationPreference::kBalanced);
915 VerifyNoLimitation(source.sink_wants());
916 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
917 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
918
919 // Trigger adapt down kMaxCpuDowngrades times.
920 int t = 1;
921 for (int i = 1; i <= kMaxDowngrades; ++i) {
922 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight));
923 sink_.WaitForEncodedFrame(t++);
924 vie_encoder_->TriggerCpuOveruse();
925 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants());
926 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
927 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
928 }
929
930 // Trigger adapt down, max cpu downgrades reach, expect no change.
931 rtc::VideoSinkWants last_wants = source.sink_wants();
932 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight));
933 sink_.WaitForEncodedFrame(t++);
934 vie_encoder_->TriggerCpuOveruse();
935 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants);
936 EXPECT_EQ(last_wants.max_pixel_count, source.sink_wants().max_pixel_count);
937 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
938 EXPECT_EQ(kMaxDowngrades,
939 stats_proxy_->GetStats().number_of_cpu_adapt_changes);
940
941 // Trigger adapt up kMaxCpuDowngrades times.
942 for (int i = 1; i <= kMaxDowngrades; ++i) {
943 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight));
944 sink_.WaitForEncodedFrame(t++);
945 vie_encoder_->TriggerCpuNormalUsage();
946 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
947 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count);
948 EXPECT_EQ(kMaxDowngrades + i,
949 stats_proxy_->GetStats().number_of_cpu_adapt_changes);
950 }
951
952 VerifyNoLimitation(source.sink_wants());
953 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
954
955 vie_encoder_->Stop();
956 }
863 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) { 957 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) {
864 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 958 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
865 VerifyNoLimitation(video_source_.sink_wants()); 959 VerifyNoLimitation(video_source_.sink_wants());
866 960
867 const int kFrameWidth = 1280; 961 const int kFrameWidth = 1280;
868 const int kFrameHeight = 720; 962 const int kFrameHeight = 720;
869 const int kFrameIntervalMs = 1000 / 30; 963 const int kFrameIntervalMs = 1000 / 30;
870 964
871 int frame_timestamp = 1; 965 int frame_timestamp = 1;
872 966
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 1515
1422 // Trigger adapt down for same input resolution, expect no change. 1516 // Trigger adapt down for same input resolution, expect no change.
1423 vie_encoder_->TriggerCpuOveruse(); 1517 vie_encoder_->TriggerCpuOveruse();
1424 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); 1518 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count);
1425 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1519 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1426 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1520 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1427 1521
1428 vie_encoder_->Stop(); 1522 vie_encoder_->Stop();
1429 } 1523 }
1430 1524
1525 TEST_F(ViEEncoderTest, SkipsSameOrLargerAdaptDownRequest_BalancedMode) {
1526 const int kWidth = 1280;
1527 const int kHeight = 720;
1528 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps + 1, 0, 0);
1529
1530 // Enable kBalanced preference, no initial limitation.
1531 test::FrameForwarder source;
1532 vie_encoder_->SetSource(&source,
1533 VideoSendStream::DegradationPreference::kBalanced);
1534 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1535 sink_.WaitForEncodedFrame(1);
1536 VerifyNoLimitation(source.sink_wants());
1537
1538 // Trigger adapt down, expect scaled down resolution.
1539 vie_encoder_->TriggerQualityLow();
1540 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1541 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1542 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1543 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count;
1544
1545 // Trigger adapt down for same input resolution, expect no change.
1546 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1547 sink_.WaitForEncodedFrame(2);
1548 vie_encoder_->TriggerQualityLow();
1549 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count);
1550 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1551 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1552
1553 // Trigger adapt down for larger input resolution, expect no change.
1554 source.IncomingCapturedFrame(CreateFrame(3, kWidth + 1, kHeight + 1));
1555 sink_.WaitForEncodedFrame(3);
1556 vie_encoder_->TriggerQualityLow();
1557 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count);
1558 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1559 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1560
1561 vie_encoder_->Stop();
1562 }
1563
1431 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainFramerateMode) { 1564 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainFramerateMode) {
1432 const int kWidth = 1280; 1565 const int kWidth = 1280;
1433 const int kHeight = 720; 1566 const int kHeight = 720;
1434 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1567 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1435 1568
1436 // Enable kMaintainFramerate preference, no initial limitation. 1569 // Enable kMaintainFramerate preference, no initial limitation.
1437 test::FrameForwarder source; 1570 test::FrameForwarder source;
1438 vie_encoder_->SetSource( 1571 vie_encoder_->SetSource(
1439 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); 1572 &source, VideoSendStream::DegradationPreference::kMaintainFramerate);
1440 1573
(...skipping 30 matching lines...) Expand all
1471 1604
1472 // Trigger adapt up, expect no change. 1605 // Trigger adapt up, expect no change.
1473 vie_encoder_->TriggerCpuNormalUsage(); 1606 vie_encoder_->TriggerCpuNormalUsage();
1474 VerifyNoLimitation(source.sink_wants()); 1607 VerifyNoLimitation(source.sink_wants());
1475 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); 1608 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1476 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1609 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1477 1610
1478 vie_encoder_->Stop(); 1611 vie_encoder_->Stop();
1479 } 1612 }
1480 1613
1614 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_BalancedMode) {
1615 const int kWidth = 1280;
1616 const int kHeight = 720;
1617 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1618
1619 // Enable kBalanced preference, no initial limitation.
1620 test::FrameForwarder source;
1621 vie_encoder_->SetSource(&source,
1622 VideoSendStream::DegradationPreference::kBalanced);
1623
1624 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1625 sink_.WaitForEncodedFrame(kWidth, kHeight);
1626 VerifyNoLimitation(source.sink_wants());
1627 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1628 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1629 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1630
1631 // Trigger adapt up, expect no change.
1632 vie_encoder_->TriggerQualityHigh();
1633 VerifyNoLimitation(source.sink_wants());
1634 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1635 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1636 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1637
1638 vie_encoder_->Stop();
1639 }
1640
1481 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_DisabledMode) { 1641 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_DisabledMode) {
1482 const int kWidth = 1280; 1642 const int kWidth = 1280;
1483 const int kHeight = 720; 1643 const int kHeight = 720;
1484 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1644 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1485 1645
1486 // Enable kDegradationDisabled preference, no initial limitation. 1646 // Enable kDegradationDisabled preference, no initial limitation.
1487 test::FrameForwarder source; 1647 test::FrameForwarder source;
1488 vie_encoder_->SetSource( 1648 vie_encoder_->SetSource(
1489 &source, VideoSendStream::DegradationPreference::kDegradationDisabled); 1649 &source, VideoSendStream::DegradationPreference::kDegradationDisabled);
1490 1650
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); 1823 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight));
1664 sink_.WaitForEncodedFrame(kWidth, kHeight); 1824 sink_.WaitForEncodedFrame(kWidth, kHeight);
1665 VerifyNoLimitation(source.sink_wants()); 1825 VerifyNoLimitation(source.sink_wants());
1666 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1826 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1667 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1827 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1668 1828
1669 vie_encoder_->Stop(); 1829 vie_encoder_->Stop();
1670 } 1830 }
1671 1831
1672 TEST_F(ViEEncoderTest, 1832 TEST_F(ViEEncoderTest,
1833 AdaptsResolutionUpAndDownTwiceForLowQuality_BalancedMode_NoFpsLimit) {
1834 const int kWidth = 1280;
1835 const int kHeight = 720;
1836 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps + 1, 0, 0);
1837
1838 // Enable kBalanced preference, no initial limitation.
1839 AdaptingFrameForwarder source;
1840 source.set_adaptation_enabled(true);
1841 vie_encoder_->SetSource(&source,
1842 VideoSendStream::DegradationPreference::kBalanced);
1843
1844 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1845 sink_.WaitForEncodedFrame(kWidth, kHeight);
1846 VerifyNoLimitation(source.sink_wants());
1847 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1848 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1849
1850 // Trigger adapt down, expect scaled down resolution.
1851 vie_encoder_->TriggerQualityLow();
1852 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1853 sink_.WaitForEncodedFrame(2);
1854 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1855 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1856 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1857
1858 // Trigger adapt up, expect no restriction.
1859 vie_encoder_->TriggerQualityHigh();
1860 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight));
1861 sink_.WaitForEncodedFrame(kWidth, kHeight);
1862 VerifyNoLimitation(source.sink_wants());
1863 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1864 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1865
1866 // Trigger adapt down, expect scaled down resolution.
1867 vie_encoder_->TriggerQualityLow();
1868 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight));
1869 sink_.WaitForEncodedFrame(4);
1870 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1871 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1872 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1873
1874 // Trigger adapt up, expect no restriction.
1875 vie_encoder_->TriggerQualityHigh();
1876 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight));
1877 sink_.WaitForEncodedFrame(kWidth, kHeight);
1878 VerifyNoLimitation(source.sink_wants());
1879 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1880 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1881
1882 vie_encoder_->Stop();
1883 }
1884
1885 TEST_F(ViEEncoderTest,
1673 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { 1886 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) {
1674 const int kWidth = 1280; 1887 const int kWidth = 1280;
1675 const int kHeight = 720; 1888 const int kHeight = 720;
1676 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1889 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1677 1890
1678 // Enable kMaintainFramerate preference, no initial limitation. 1891 // Enable kMaintainFramerate preference, no initial limitation.
1679 AdaptingFrameForwarder source; 1892 AdaptingFrameForwarder source;
1680 source.set_adaptation_enabled(true); 1893 source.set_adaptation_enabled(true);
1681 vie_encoder_->SetSource( 1894 vie_encoder_->SetSource(
1682 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); 1895 &source, VideoSendStream::DegradationPreference::kMaintainFramerate);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); 2183 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight));
1971 WaitForEncodedFrame(1); 2184 WaitForEncodedFrame(1);
1972 vie_encoder_->TriggerCpuOveruse(); 2185 vie_encoder_->TriggerCpuOveruse();
1973 VerifyNoLimitation(source.sink_wants()); 2186 VerifyNoLimitation(source.sink_wants());
1974 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 2187 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1975 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 2188 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1976 2189
1977 vie_encoder_->Stop(); 2190 vie_encoder_->Stop();
1978 } 2191 }
1979 2192
2193 TEST_F(ViEEncoderTest, ResolutionNotAdaptedForTooSmallFrame_BalancedMode) {
2194 const int kTooSmallWidth = 10;
2195 const int kTooSmallHeight = 10;
2196 const int kFpsLimit = 7;
2197 vie_encoder_->OnBitrateUpdated(kBpsLimitFor7Fps, 0, 0);
2198
2199 // Enable kBalanced preference, no initial limitation.
2200 test::FrameForwarder source;
2201 vie_encoder_->SetSource(&source,
2202 VideoSendStream::DegradationPreference::kBalanced);
2203 VerifyNoLimitation(source.sink_wants());
2204 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2205 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2206
2207 // Trigger adapt down, expect limited framerate.
2208 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight));
2209 sink_.WaitForEncodedFrame(1);
2210 vie_encoder_->TriggerQualityLow();
2211 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit);
2212 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2213 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2214 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2215
2216 // Trigger adapt down, too small frame, expect no change.
2217 source.IncomingCapturedFrame(CreateFrame(2, kTooSmallWidth, kTooSmallHeight));
2218 sink_.WaitForEncodedFrame(2);
2219 vie_encoder_->TriggerQualityLow();
2220 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit);
2221 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2222 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2223 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2224
2225 vie_encoder_->Stop();
2226 }
2227
1980 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { 2228 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) {
1981 fake_encoder_.ForceInitEncodeFailure(true); 2229 fake_encoder_.ForceInitEncodeFailure(true);
1982 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 2230 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1983 ResetEncoder("VP8", 2, 1, true, false); 2231 ResetEncoder("VP8", 2, 1, true, false);
1984 const int kFrameWidth = 1280; 2232 const int kFrameWidth = 1280;
1985 const int kFrameHeight = 720; 2233 const int kFrameHeight = 720;
1986 video_source_.IncomingCapturedFrame( 2234 video_source_.IncomingCapturedFrame(
1987 CreateFrame(1, kFrameWidth, kFrameHeight)); 2235 CreateFrame(1, kFrameWidth, kFrameHeight));
1988 ExpectDroppedFrame(); 2236 ExpectDroppedFrame();
1989 vie_encoder_->Stop(); 2237 vie_encoder_->Stop();
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameIntervalMs); 2451 TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameIntervalMs);
2204 timestamp_ms += kFrameIntervalMs; 2452 timestamp_ms += kFrameIntervalMs;
2205 } 2453 }
2206 2454
2207 // Don expect correct measurement just yet, but it should be higher than 2455 // Don expect correct measurement just yet, but it should be higher than
2208 // before. 2456 // before.
2209 EXPECT_GT(fake_encoder_.GetConfiguredInputFramerate(), kLowFps); 2457 EXPECT_GT(fake_encoder_.GetConfiguredInputFramerate(), kLowFps);
2210 2458
2211 vie_encoder_->Stop(); 2459 vie_encoder_->Stop();
2212 } 2460 }
2461
2462 TEST_F(ViEEncoderTest, AdaptsResolutionAndFramerateForLowQuality_BalancedMode) {
2463 const int kWidth = 1280;
2464 const int kHeight = 720;
2465 const int64_t kFrameIntervalMs = 150;
2466 int64_t timestamp_ms = kFrameIntervalMs;
2467 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps, 0, 0);
2468
2469 // Enable kBalanced preference, no initial limitation.
2470 AdaptingFrameForwarder source;
2471 source.set_adaptation_enabled(true);
2472 vie_encoder_->SetSource(&source,
2473 VideoSendStream::DegradationPreference::kBalanced);
2474 timestamp_ms += kFrameIntervalMs;
2475 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2476 sink_.WaitForEncodedFrame(kWidth, kHeight);
2477 VerifyNoLimitation(source.sink_wants());
2478 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2479 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2480 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2481
2482 // Trigger adapt down, expect scaled down resolution (960x540@30fps).
2483 vie_encoder_->TriggerQualityLow();
2484 timestamp_ms += kFrameIntervalMs;
2485 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2486 sink_.WaitForEncodedFrame(timestamp_ms);
2487 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
2488 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2489 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2490 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2491
2492 // Trigger adapt down, expect scaled down resolution (640x360@30fps).
2493 vie_encoder_->TriggerQualityLow();
2494 timestamp_ms += kFrameIntervalMs;
2495 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2496 sink_.WaitForEncodedFrame(timestamp_ms);
2497 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants());
2498 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2499 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2500 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2501
2502 // Trigger adapt down, expect reduced fps (640x360@15fps).
2503 vie_encoder_->TriggerQualityLow();
2504 timestamp_ms += kFrameIntervalMs;
2505 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2506 sink_.WaitForEncodedFrame(timestamp_ms);
2507 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants());
2508 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2509 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2510 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2511
2512 // Trigger adapt down, expect scaled down resolution (480x270@15fps).
2513 vie_encoder_->OnBitrateUpdated(kBpsLimitFor10Fps, 0, 0);
2514 vie_encoder_->TriggerQualityLow();
2515 timestamp_ms += kFrameIntervalMs;
2516 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2517 sink_.WaitForEncodedFrame(timestamp_ms);
2518 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants());
2519 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2520 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2521 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2522
2523 // Restrict bitrate, trigger adapt down, expect reduced fps (480x270@10fps).
2524 vie_encoder_->TriggerQualityLow();
2525 timestamp_ms += kFrameIntervalMs;
2526 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2527 sink_.WaitForEncodedFrame(timestamp_ms);
2528 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants());
2529 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2530 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2531 EXPECT_EQ(5, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2532
2533 // Trigger adapt down, expect scaled down resolution (320x180@10fps).
2534 vie_encoder_->TriggerQualityLow();
2535 timestamp_ms += kFrameIntervalMs;
2536 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2537 sink_.WaitForEncodedFrame(timestamp_ms);
2538 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants());
2539 rtc::VideoSinkWants last_wants = source.sink_wants();
2540 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2541 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2542 EXPECT_EQ(6, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2543
2544 // Trigger adapt down, min resolution reached, expect no change.
2545 vie_encoder_->TriggerQualityLow();
2546 timestamp_ms += kFrameIntervalMs;
2547 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2548 sink_.WaitForEncodedFrame(timestamp_ms);
2549 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants);
2550 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2551 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2552 EXPECT_EQ(6, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2553
2554 // Trigger adapt up, expect upscaled resolution (480x270@10fps).
2555 vie_encoder_->TriggerQualityHigh();
2556 timestamp_ms += kFrameIntervalMs;
2557 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2558 sink_.WaitForEncodedFrame(timestamp_ms);
2559 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants());
2560 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2561 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2562 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2563
2564 // Increase bitrate, trigger adapt up, expect increased fps (480x270@15fps).
2565 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps + 1, 0, 0);
2566 vie_encoder_->TriggerQualityHigh();
2567 timestamp_ms += kFrameIntervalMs;
2568 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2569 sink_.WaitForEncodedFrame(timestamp_ms);
2570 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants());
2571 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2572 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2573 EXPECT_EQ(8, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2574
2575 // Trigger adapt up, expect upscaled resolution (640x360@15fps).
2576 vie_encoder_->TriggerQualityHigh();
2577 timestamp_ms += kFrameIntervalMs;
2578 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2579 sink_.WaitForEncodedFrame(timestamp_ms);
2580 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants());
2581 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2582 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2583 EXPECT_EQ(9, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2584
2585 // Trigger adapt up, expect increased fps (640x360@30fps).
2586 vie_encoder_->TriggerQualityHigh();
2587 timestamp_ms += kFrameIntervalMs;
2588 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2589 sink_.WaitForEncodedFrame(timestamp_ms);
2590 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants());
2591 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2592 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2593 EXPECT_EQ(10, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2594
2595 // Trigger adapt up, expect upscaled resolution (960x540@30fps).
2596 vie_encoder_->TriggerQualityHigh();
2597 timestamp_ms += kFrameIntervalMs;
2598 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2599 sink_.WaitForEncodedFrame(timestamp_ms);
2600 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
2601 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2602 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2603 EXPECT_EQ(11, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2604
2605 // Trigger adapt up, expect no restriction (1280x720fps@30fps).
2606 vie_encoder_->TriggerQualityHigh();
2607 timestamp_ms += kFrameIntervalMs;
2608 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2609 sink_.WaitForEncodedFrame(kWidth, kHeight);
2610 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
2611 VerifyNoLimitation(source.sink_wants());
2612 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2613 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2614 EXPECT_EQ(12, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2615
2616 // Trigger adapt up, expect no change.
2617 vie_encoder_->TriggerQualityHigh();
2618 VerifyNoLimitation(source.sink_wants());
2619 EXPECT_EQ(12, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2620
2621 vie_encoder_->Stop();
2622 }
2623
2624 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Framerate) {
2625 const int kWidth = 1280;
2626 const int kHeight = 720;
2627 const int64_t kFrameIntervalMs = 150;
2628 int64_t timestamp_ms = kFrameIntervalMs;
2629 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps, 0, 0);
2630
2631 // Enable kBalanced preference, no initial limitation.
2632 AdaptingFrameForwarder source;
2633 source.set_adaptation_enabled(true);
2634 vie_encoder_->SetSource(&source,
2635 VideoSendStream::DegradationPreference::kBalanced);
2636 timestamp_ms += kFrameIntervalMs;
2637 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2638 sink_.WaitForEncodedFrame(kWidth, kHeight);
2639 VerifyNoLimitation(source.sink_wants());
2640 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2641 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2642 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2643 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2644 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2645 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2646
2647 // Trigger cpu adapt down, expect scaled down resolution (960x540@30fps).
2648 vie_encoder_->TriggerCpuOveruse();
2649 timestamp_ms += kFrameIntervalMs;
2650 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2651 sink_.WaitForEncodedFrame(timestamp_ms);
2652 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
2653 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2654 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2655 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2656 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2657 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2658 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2659
2660 // Trigger cpu adapt down, expect scaled down resolution (640x360@30fps).
2661 vie_encoder_->TriggerCpuOveruse();
2662 timestamp_ms += kFrameIntervalMs;
2663 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2664 sink_.WaitForEncodedFrame(timestamp_ms);
2665 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants());
2666 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2667 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2668 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2669 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2670 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2671 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2672
2673 // Trigger quality adapt down, expect reduced fps (640x360@15fps).
2674 vie_encoder_->TriggerQualityLow();
2675 timestamp_ms += kFrameIntervalMs;
2676 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2677 sink_.WaitForEncodedFrame(timestamp_ms);
2678 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants());
2679 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2680 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2681 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2682 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2683 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2684 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2685
2686 // Trigger cpu adapt up, expect increased fps (640x360@30fps).
2687 vie_encoder_->TriggerCpuNormalUsage();
2688 timestamp_ms += kFrameIntervalMs;
2689 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2690 sink_.WaitForEncodedFrame(timestamp_ms);
2691 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants());
2692 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2693 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2694 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2695 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2696 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2697 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2698
2699 // Trigger quality adapt up, expect upscaled resolution (960x540@30fps).
2700 vie_encoder_->TriggerQualityHigh();
2701 timestamp_ms += kFrameIntervalMs;
2702 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2703 sink_.WaitForEncodedFrame(timestamp_ms);
2704 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
2705 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2706 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2707 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2708 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2709 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2710 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2711
2712 // Trigger cpu adapt up, expect no restriction (1280x720fps@30fps).
2713 vie_encoder_->TriggerCpuNormalUsage();
2714 timestamp_ms += kFrameIntervalMs;
2715 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2716 sink_.WaitForEncodedFrame(kWidth, kHeight);
2717 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
2718 VerifyNoLimitation(source.sink_wants());
2719 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2720 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2721 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2722 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2723 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2724 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2725
2726 // Trigger adapt up, expect no change.
2727 vie_encoder_->TriggerQualityHigh();
2728 VerifyNoLimitation(source.sink_wants());
2729 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2730 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2731
2732 vie_encoder_->Stop();
2733 }
2734
2735 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Resolution) {
2736 const int kWidth = 640;
2737 const int kHeight = 360;
2738 const int kFpsLimit = 15;
2739 const int64_t kFrameIntervalMs = 150;
2740 int64_t timestamp_ms = kFrameIntervalMs;
2741 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps, 0, 0);
2742
2743 // Enable kBalanced preference, no initial limitation.
2744 AdaptingFrameForwarder source;
2745 source.set_adaptation_enabled(true);
2746 vie_encoder_->SetSource(&source,
2747 VideoSendStream::DegradationPreference::kBalanced);
2748 timestamp_ms += kFrameIntervalMs;
2749 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2750 sink_.WaitForEncodedFrame(kWidth, kHeight);
2751 VerifyNoLimitation(source.sink_wants());
2752 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2753 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2754 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2755 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2756 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2757 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2758
2759 // Trigger cpu adapt down, expect scaled down framerate (640x360@15fps).
2760 vie_encoder_->TriggerCpuOveruse();
2761 timestamp_ms += kFrameIntervalMs;
2762 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2763 sink_.WaitForEncodedFrame(timestamp_ms);
2764 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit);
2765 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2766 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2767 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2768 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate);
2769 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2770 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2771
2772 // Trigger quality adapt down, expect scaled down resolution (480x270@15fps).
2773 vie_encoder_->TriggerQualityLow();
2774 timestamp_ms += kFrameIntervalMs;
2775 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2776 sink_.WaitForEncodedFrame(timestamp_ms);
2777 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants());
2778 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2779 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2780 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2781 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate);
2782 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2783 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2784
2785 // Trigger cpu adapt up, expect upscaled resolution (640x360@15fps).
2786 vie_encoder_->TriggerCpuNormalUsage();
2787 timestamp_ms += kFrameIntervalMs;
2788 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2789 sink_.WaitForEncodedFrame(timestamp_ms);
2790 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants());
2791 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2792 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2793 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2794 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2795 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2796 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2797
2798 // Trigger quality adapt up, expect increased fps (640x360@30fps).
2799 vie_encoder_->TriggerQualityHigh();
2800 timestamp_ms += kFrameIntervalMs;
2801 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2802 sink_.WaitForEncodedFrame(timestamp_ms);
2803 VerifyNoLimitation(source.sink_wants());
2804 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2805 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2806 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2807 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2808 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2809 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2810
2811 // Trigger adapt up, expect no change.
2812 vie_encoder_->TriggerQualityHigh();
2813 VerifyNoLimitation(source.sink_wants());
2814 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2815 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2816
2817 vie_encoder_->Stop();
2818 }
2819
2213 } // namespace webrtc 2820 } // namespace webrtc
OLDNEW
« webrtc/video/vie_encoder.cc ('K') | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698