OLD | NEW |
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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count); | 304 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count); |
305 EXPECT_GT(wants1.max_pixel_count, 0); | 305 EXPECT_GT(wants1.max_pixel_count, 0); |
306 } | 306 } |
307 | 307 |
308 void VerifyFpsMaxResolutionGt(const rtc::VideoSinkWants& wants1, | 308 void VerifyFpsMaxResolutionGt(const rtc::VideoSinkWants& wants1, |
309 const rtc::VideoSinkWants& wants2) { | 309 const rtc::VideoSinkWants& wants2) { |
310 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps); | 310 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps); |
311 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count); | 311 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count); |
312 } | 312 } |
313 | 313 |
| 314 void VerifyFpsMaxResolutionEq(const rtc::VideoSinkWants& wants1, |
| 315 const rtc::VideoSinkWants& wants2) { |
| 316 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps); |
| 317 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count); |
| 318 } |
| 319 |
| 320 void VerifyFpsLtResolutionEq(const rtc::VideoSinkWants& wants1, |
| 321 const rtc::VideoSinkWants& wants2) { |
| 322 EXPECT_LT(wants1.max_framerate_fps, wants2.max_framerate_fps); |
| 323 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count); |
| 324 } |
| 325 |
| 326 void VerifyFpsGtResolutionEq(const rtc::VideoSinkWants& wants1, |
| 327 const rtc::VideoSinkWants& wants2) { |
| 328 EXPECT_GT(wants1.max_framerate_fps, wants2.max_framerate_fps); |
| 329 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count); |
| 330 } |
| 331 |
| 332 void VerifyFpsEqResolutionLt(const rtc::VideoSinkWants& wants1, |
| 333 const rtc::VideoSinkWants& wants2) { |
| 334 EXPECT_EQ(wants1.max_framerate_fps, wants2.max_framerate_fps); |
| 335 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count); |
| 336 EXPECT_GT(wants1.max_pixel_count, 0); |
| 337 } |
| 338 |
| 339 void VerifyFpsEqResolutionGt(const rtc::VideoSinkWants& wants1, |
| 340 const rtc::VideoSinkWants& wants2) { |
| 341 EXPECT_EQ(wants1.max_framerate_fps, wants2.max_framerate_fps); |
| 342 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count); |
| 343 } |
| 344 |
314 void VerifyFpsMaxResolutionLt(const rtc::VideoSinkWants& wants, | 345 void VerifyFpsMaxResolutionLt(const rtc::VideoSinkWants& wants, |
315 int pixel_count) { | 346 int pixel_count) { |
316 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps); | 347 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps); |
317 EXPECT_LT(wants.max_pixel_count, pixel_count); | 348 EXPECT_LT(wants.max_pixel_count, pixel_count); |
318 EXPECT_GT(wants.max_pixel_count, 0); | 349 EXPECT_GT(wants.max_pixel_count, 0); |
319 } | 350 } |
320 | 351 |
321 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) { | 352 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) { |
322 EXPECT_LT(wants.max_framerate_fps, fps); | 353 EXPECT_LT(wants.max_framerate_fps, fps); |
323 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); | 354 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); |
324 EXPECT_FALSE(wants.target_pixel_count); | 355 EXPECT_FALSE(wants.target_pixel_count); |
325 } | 356 } |
326 | 357 |
| 358 void VerifyFpsEqResolutionMax(const rtc::VideoSinkWants& wants, |
| 359 int expected_fps) { |
| 360 EXPECT_EQ(expected_fps, wants.max_framerate_fps); |
| 361 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); |
| 362 EXPECT_FALSE(wants.target_pixel_count); |
| 363 } |
| 364 |
327 class TestEncoder : public test::FakeEncoder { | 365 class TestEncoder : public test::FakeEncoder { |
328 public: | 366 public: |
329 TestEncoder() | 367 TestEncoder() |
330 : FakeEncoder(Clock::GetRealTimeClock()), | 368 : FakeEncoder(Clock::GetRealTimeClock()), |
331 continue_encode_event_(false, false) {} | 369 continue_encode_event_(false, false) {} |
332 | 370 |
333 VideoCodec codec_config() const { | 371 VideoCodec codec_config() const { |
334 rtc::CritScope lock(&crit_sect_); | 372 rtc::CritScope lock(&crit_sect_); |
335 return config_; | 373 return config_; |
336 } | 374 } |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 video_source_.sink_wants().target_pixel_count.value_or(0)); | 839 video_source_.sink_wants().target_pixel_count.value_or(0)); |
802 EXPECT_EQ(frame_width * frame_height * 4, | 840 EXPECT_EQ(frame_width * frame_height * 4, |
803 video_source_.sink_wants().max_pixel_count); | 841 video_source_.sink_wants().max_pixel_count); |
804 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 842 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
805 EXPECT_EQ(kMaxDowngrades + 1, | 843 EXPECT_EQ(kMaxDowngrades + 1, |
806 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 844 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
807 | 845 |
808 vie_encoder_->Stop(); | 846 vie_encoder_->Stop(); |
809 } | 847 } |
810 | 848 |
| 849 TEST_F(ViEEncoderTest, TestMaxCpuResolutionDowngrades_BalancedMode_NoFpsLimit) { |
| 850 const int kMaxDowngrades = ViEEncoder::kMaxCpuResolutionDowngrades; |
| 851 const int kWidth = 1280; |
| 852 const int kHeight = 720; |
| 853 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 854 |
| 855 // Enable kBalanced preference, no initial limitation. |
| 856 AdaptingFrameForwarder source; |
| 857 source.set_adaptation_enabled(true); |
| 858 vie_encoder_->SetSource(&source, |
| 859 VideoSendStream::DegradationPreference::kBalanced); |
| 860 VerifyNoLimitation(source.sink_wants()); |
| 861 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 862 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 863 |
| 864 // Trigger adapt down kMaxCpuDowngrades times. |
| 865 int t = 1; |
| 866 for (int i = 1; i <= kMaxDowngrades; ++i) { |
| 867 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight)); |
| 868 sink_.WaitForEncodedFrame(t++); |
| 869 vie_encoder_->TriggerCpuOveruse(); |
| 870 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
| 871 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 872 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 873 } |
| 874 |
| 875 // Trigger adapt down, max cpu downgrades reach, expect no change. |
| 876 rtc::VideoSinkWants last_wants = source.sink_wants(); |
| 877 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight)); |
| 878 sink_.WaitForEncodedFrame(t++); |
| 879 vie_encoder_->TriggerCpuOveruse(); |
| 880 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
| 881 EXPECT_EQ(last_wants.max_pixel_count, source.sink_wants().max_pixel_count); |
| 882 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 883 EXPECT_EQ(kMaxDowngrades, |
| 884 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 885 |
| 886 // Trigger adapt up kMaxCpuDowngrades times. |
| 887 for (int i = 1; i <= kMaxDowngrades; ++i) { |
| 888 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight)); |
| 889 sink_.WaitForEncodedFrame(t++); |
| 890 vie_encoder_->TriggerCpuNormalUsage(); |
| 891 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 892 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count); |
| 893 EXPECT_EQ(kMaxDowngrades + i, |
| 894 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 895 } |
| 896 |
| 897 VerifyNoLimitation(source.sink_wants()); |
| 898 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 899 |
| 900 vie_encoder_->Stop(); |
| 901 } |
811 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) { | 902 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) { |
812 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 903 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
813 VerifyNoLimitation(video_source_.sink_wants()); | 904 VerifyNoLimitation(video_source_.sink_wants()); |
814 | 905 |
815 const int kFrameWidth = 1280; | 906 const int kFrameWidth = 1280; |
816 const int kFrameHeight = 720; | 907 const int kFrameHeight = 720; |
817 const int kFrameIntervalMs = 1000 / 30; | 908 const int kFrameIntervalMs = 1000 / 30; |
818 | 909 |
819 int frame_timestamp = 1; | 910 int frame_timestamp = 1; |
820 | 911 |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 | 1460 |
1370 // Trigger adapt down for same input resolution, expect no change. | 1461 // Trigger adapt down for same input resolution, expect no change. |
1371 vie_encoder_->TriggerCpuOveruse(); | 1462 vie_encoder_->TriggerCpuOveruse(); |
1372 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); | 1463 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); |
1373 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1464 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1374 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1465 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1375 | 1466 |
1376 vie_encoder_->Stop(); | 1467 vie_encoder_->Stop(); |
1377 } | 1468 } |
1378 | 1469 |
| 1470 TEST_F(ViEEncoderTest, SkipsSameOrLargerAdaptDownRequest_BalancedMode) { |
| 1471 const int kWidth = 1280; |
| 1472 const int kHeight = 720; |
| 1473 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1474 |
| 1475 // Enable kBalanced preference, no initial limitation. |
| 1476 test::FrameForwarder source; |
| 1477 vie_encoder_->SetSource(&source, |
| 1478 VideoSendStream::DegradationPreference::kBalanced); |
| 1479 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1480 sink_.WaitForEncodedFrame(1); |
| 1481 VerifyNoLimitation(source.sink_wants()); |
| 1482 |
| 1483 // Trigger adapt down, expect scaled down resolution. |
| 1484 vie_encoder_->TriggerQualityLow(); |
| 1485 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 1486 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1487 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1488 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; |
| 1489 |
| 1490 // Trigger adapt down for same input resolution, expect no change. |
| 1491 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1492 sink_.WaitForEncodedFrame(2); |
| 1493 vie_encoder_->TriggerQualityLow(); |
| 1494 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); |
| 1495 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1496 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1497 |
| 1498 // Trigger adapt down for larger input resolution, expect no change. |
| 1499 source.IncomingCapturedFrame(CreateFrame(3, kWidth + 1, kHeight + 1)); |
| 1500 sink_.WaitForEncodedFrame(3); |
| 1501 vie_encoder_->TriggerQualityLow(); |
| 1502 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); |
| 1503 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1504 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1505 |
| 1506 vie_encoder_->Stop(); |
| 1507 } |
| 1508 |
1379 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainFramerateMode) { | 1509 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainFramerateMode) { |
1380 const int kWidth = 1280; | 1510 const int kWidth = 1280; |
1381 const int kHeight = 720; | 1511 const int kHeight = 720; |
1382 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1512 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1383 | 1513 |
1384 // Enable kMaintainFramerate preference, no initial limitation. | 1514 // Enable kMaintainFramerate preference, no initial limitation. |
1385 test::FrameForwarder source; | 1515 test::FrameForwarder source; |
1386 vie_encoder_->SetSource( | 1516 vie_encoder_->SetSource( |
1387 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1517 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1388 | 1518 |
(...skipping 30 matching lines...) Expand all Loading... |
1419 | 1549 |
1420 // Trigger adapt up, expect no change. | 1550 // Trigger adapt up, expect no change. |
1421 vie_encoder_->TriggerCpuNormalUsage(); | 1551 vie_encoder_->TriggerCpuNormalUsage(); |
1422 VerifyNoLimitation(source.sink_wants()); | 1552 VerifyNoLimitation(source.sink_wants()); |
1423 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1553 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1424 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1554 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1425 | 1555 |
1426 vie_encoder_->Stop(); | 1556 vie_encoder_->Stop(); |
1427 } | 1557 } |
1428 | 1558 |
| 1559 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_BalancedMode) { |
| 1560 const int kWidth = 1280; |
| 1561 const int kHeight = 720; |
| 1562 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1563 |
| 1564 // Enable kBalanced preference, no initial limitation. |
| 1565 test::FrameForwarder source; |
| 1566 vie_encoder_->SetSource(&source, |
| 1567 VideoSendStream::DegradationPreference::kBalanced); |
| 1568 |
| 1569 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1570 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 1571 VerifyNoLimitation(source.sink_wants()); |
| 1572 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1573 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 1574 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1575 |
| 1576 // Trigger adapt up, expect no change. |
| 1577 vie_encoder_->TriggerQualityHigh(); |
| 1578 VerifyNoLimitation(source.sink_wants()); |
| 1579 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1580 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 1581 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1582 |
| 1583 vie_encoder_->Stop(); |
| 1584 } |
| 1585 |
1429 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_DisabledMode) { | 1586 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_DisabledMode) { |
1430 const int kWidth = 1280; | 1587 const int kWidth = 1280; |
1431 const int kHeight = 720; | 1588 const int kHeight = 720; |
1432 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1589 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1433 | 1590 |
1434 // Enable kDegradationDisabled preference, no initial limitation. | 1591 // Enable kDegradationDisabled preference, no initial limitation. |
1435 test::FrameForwarder source; | 1592 test::FrameForwarder source; |
1436 vie_encoder_->SetSource( | 1593 vie_encoder_->SetSource( |
1437 &source, VideoSendStream::DegradationPreference::kDegradationDisabled); | 1594 &source, VideoSendStream::DegradationPreference::kDegradationDisabled); |
1438 | 1595 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1768 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1612 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1769 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1613 VerifyNoLimitation(source.sink_wants()); | 1770 VerifyNoLimitation(source.sink_wants()); |
1614 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1771 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1615 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1772 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1616 | 1773 |
1617 vie_encoder_->Stop(); | 1774 vie_encoder_->Stop(); |
1618 } | 1775 } |
1619 | 1776 |
1620 TEST_F(ViEEncoderTest, | 1777 TEST_F(ViEEncoderTest, |
| 1778 AdaptsResolutionUpAndDownTwiceForLowQuality_BalancedMode_NoFpsLimit) { |
| 1779 const int kWidth = 1280; |
| 1780 const int kHeight = 720; |
| 1781 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1782 |
| 1783 // Enable kBalanced preference, no initial limitation. |
| 1784 AdaptingFrameForwarder source; |
| 1785 source.set_adaptation_enabled(true); |
| 1786 vie_encoder_->SetSource(&source, |
| 1787 VideoSendStream::DegradationPreference::kBalanced); |
| 1788 |
| 1789 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1790 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 1791 VerifyNoLimitation(source.sink_wants()); |
| 1792 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1793 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1794 |
| 1795 // Trigger adapt down, expect scaled down resolution. |
| 1796 vie_encoder_->TriggerQualityLow(); |
| 1797 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1798 sink_.WaitForEncodedFrame(2); |
| 1799 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 1800 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1801 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1802 |
| 1803 // Trigger adapt up, expect no restriction. |
| 1804 vie_encoder_->TriggerQualityHigh(); |
| 1805 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 1806 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 1807 VerifyNoLimitation(source.sink_wants()); |
| 1808 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1809 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1810 |
| 1811 // Trigger adapt down, expect scaled down resolution. |
| 1812 vie_encoder_->TriggerQualityLow(); |
| 1813 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
| 1814 sink_.WaitForEncodedFrame(4); |
| 1815 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 1816 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1817 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1818 |
| 1819 // Trigger adapt up, expect no restriction. |
| 1820 vie_encoder_->TriggerQualityHigh(); |
| 1821 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
| 1822 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 1823 VerifyNoLimitation(source.sink_wants()); |
| 1824 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1825 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1826 |
| 1827 vie_encoder_->Stop(); |
| 1828 } |
| 1829 |
| 1830 TEST_F(ViEEncoderTest, |
1621 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { | 1831 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { |
1622 const int kWidth = 1280; | 1832 const int kWidth = 1280; |
1623 const int kHeight = 720; | 1833 const int kHeight = 720; |
1624 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1834 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1625 | 1835 |
1626 // Enable kMaintainFramerate preference, no initial limitation. | 1836 // Enable kMaintainFramerate preference, no initial limitation. |
1627 AdaptingFrameForwarder source; | 1837 AdaptingFrameForwarder source; |
1628 source.set_adaptation_enabled(true); | 1838 source.set_adaptation_enabled(true); |
1629 vie_encoder_->SetSource( | 1839 vie_encoder_->SetSource( |
1630 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1840 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1919 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); | 2129 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); |
1920 sink_.WaitForEncodedFrame(1); | 2130 sink_.WaitForEncodedFrame(1); |
1921 vie_encoder_->TriggerCpuOveruse(); | 2131 vie_encoder_->TriggerCpuOveruse(); |
1922 VerifyNoLimitation(source.sink_wants()); | 2132 VerifyNoLimitation(source.sink_wants()); |
1923 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2133 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1924 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2134 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1925 | 2135 |
1926 vie_encoder_->Stop(); | 2136 vie_encoder_->Stop(); |
1927 } | 2137 } |
1928 | 2138 |
| 2139 TEST_F(ViEEncoderTest, ResolutionNotAdaptedForTooSmallFrame_BalancedMode) { |
| 2140 const int kTooSmallWidth = 10; |
| 2141 const int kTooSmallHeight = 10; |
| 2142 const int kFpsLimit = 7; |
| 2143 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2144 |
| 2145 // Enable kBalanced preference, no initial limitation. |
| 2146 test::FrameForwarder source; |
| 2147 vie_encoder_->SetSource(&source, |
| 2148 VideoSendStream::DegradationPreference::kBalanced); |
| 2149 VerifyNoLimitation(source.sink_wants()); |
| 2150 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2151 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2152 |
| 2153 // Trigger adapt down, expect limited framerate. |
| 2154 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); |
| 2155 sink_.WaitForEncodedFrame(1); |
| 2156 vie_encoder_->TriggerQualityLow(); |
| 2157 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); |
| 2158 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2159 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2160 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2161 |
| 2162 // Trigger adapt down, too small frame, expect no change. |
| 2163 source.IncomingCapturedFrame(CreateFrame(2, kTooSmallWidth, kTooSmallHeight)); |
| 2164 sink_.WaitForEncodedFrame(2); |
| 2165 vie_encoder_->TriggerQualityLow(); |
| 2166 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); |
| 2167 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2168 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2169 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2170 |
| 2171 vie_encoder_->Stop(); |
| 2172 } |
| 2173 |
1929 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { | 2174 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { |
1930 fake_encoder_.ForceInitEncodeFailure(true); | 2175 fake_encoder_.ForceInitEncodeFailure(true); |
1931 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2176 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1932 ResetEncoder("VP8", 2, 1, true); | 2177 ResetEncoder("VP8", 2, 1, true); |
1933 const int kFrameWidth = 1280; | 2178 const int kFrameWidth = 1280; |
1934 const int kFrameHeight = 720; | 2179 const int kFrameHeight = 720; |
1935 video_source_.IncomingCapturedFrame( | 2180 video_source_.IncomingCapturedFrame( |
1936 CreateFrame(1, kFrameWidth, kFrameHeight)); | 2181 CreateFrame(1, kFrameWidth, kFrameHeight)); |
1937 sink_.ExpectDroppedFrame(); | 2182 sink_.ExpectDroppedFrame(); |
1938 vie_encoder_->Stop(); | 2183 vie_encoder_->Stop(); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 sink_.WaitForFrame(kDefaultTimeoutMs); | 2356 sink_.WaitForFrame(kDefaultTimeoutMs); |
2112 | 2357 |
2113 // Insert frames at min fps, all should go through. | 2358 // Insert frames at min fps, all should go through. |
2114 for (int i = 0; i < 10; ++i) { | 2359 for (int i = 0; i < 10; ++i) { |
2115 timestamp_ms += kMinFpsFrameInterval; | 2360 timestamp_ms += kMinFpsFrameInterval; |
2116 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); | 2361 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); |
2117 video_source_.IncomingCapturedFrame( | 2362 video_source_.IncomingCapturedFrame( |
2118 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2363 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2119 sink_.WaitForEncodedFrame(timestamp_ms); | 2364 sink_.WaitForEncodedFrame(timestamp_ms); |
2120 } | 2365 } |
| 2366 |
2121 vie_encoder_->Stop(); | 2367 vie_encoder_->Stop(); |
2122 } | 2368 } |
| 2369 |
| 2370 TEST_F(ViEEncoderTest, AdaptsResolutionAndFramerateForLowQuality_BalancedMode) { |
| 2371 const int kWidth = 1280; |
| 2372 const int kHeight = 720; |
| 2373 const int64_t kFrameIntervalMs = 150; |
| 2374 int64_t timestamp_ms = kFrameIntervalMs; |
| 2375 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2376 |
| 2377 // Enable kBalanced preference, no initial limitation. |
| 2378 AdaptingFrameForwarder source; |
| 2379 source.set_adaptation_enabled(true); |
| 2380 vie_encoder_->SetSource(&source, |
| 2381 VideoSendStream::DegradationPreference::kBalanced); |
| 2382 timestamp_ms += kFrameIntervalMs; |
| 2383 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2384 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 2385 VerifyNoLimitation(source.sink_wants()); |
| 2386 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2387 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2388 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2389 |
| 2390 // Trigger adapt down, expect scaled down resolution (960x540@30fps). |
| 2391 vie_encoder_->TriggerQualityLow(); |
| 2392 timestamp_ms += kFrameIntervalMs; |
| 2393 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2394 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2395 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 2396 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2397 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2398 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2399 |
| 2400 // Trigger adapt down, expect scaled down resolution (640x360@30fps). |
| 2401 vie_encoder_->TriggerQualityLow(); |
| 2402 timestamp_ms += kFrameIntervalMs; |
| 2403 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2404 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2405 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
| 2406 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2407 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2408 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2409 |
| 2410 // Trigger adapt down, expect reduced fps (640x360@15fps). |
| 2411 vie_encoder_->TriggerQualityLow(); |
| 2412 timestamp_ms += kFrameIntervalMs; |
| 2413 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2414 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2415 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2416 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2417 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2418 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2419 |
| 2420 // Trigger adapt down, expect scaled down resolution (480x270@15fps). |
| 2421 vie_encoder_->TriggerQualityLow(); |
| 2422 timestamp_ms += kFrameIntervalMs; |
| 2423 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2424 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2425 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); |
| 2426 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2427 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2428 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2429 |
| 2430 // Restrict bitrate, trigger adapt down, expect reduced fps (480x270@10fps). |
| 2431 vie_encoder_->TriggerQualityLow(); |
| 2432 timestamp_ms += kFrameIntervalMs; |
| 2433 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2434 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2435 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2436 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2437 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2438 EXPECT_EQ(5, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2439 |
| 2440 // Trigger adapt down, expect scaled down resolution (320x180@10fps). |
| 2441 vie_encoder_->TriggerQualityLow(); |
| 2442 timestamp_ms += kFrameIntervalMs; |
| 2443 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2444 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2445 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); |
| 2446 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2447 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2448 EXPECT_EQ(6, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2449 |
| 2450 // Trigger adapt down, expect reduced fps (320x180@7fps). |
| 2451 vie_encoder_->TriggerQualityLow(); |
| 2452 timestamp_ms += kFrameIntervalMs; |
| 2453 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2454 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2455 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2456 rtc::VideoSinkWants last_wants = source.sink_wants(); |
| 2457 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2458 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2459 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2460 |
| 2461 // Trigger adapt down, min resolution reached, expect no change. |
| 2462 vie_encoder_->TriggerQualityLow(); |
| 2463 timestamp_ms += kFrameIntervalMs; |
| 2464 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2465 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2466 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
| 2467 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2468 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2469 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2470 |
| 2471 // Trigger adapt down, expect expect increased fps (320x180@10fps). |
| 2472 vie_encoder_->TriggerQualityHigh(); |
| 2473 timestamp_ms += kFrameIntervalMs; |
| 2474 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2475 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2476 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2477 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2478 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2479 EXPECT_EQ(8, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2480 |
| 2481 // Trigger adapt up, expect upscaled resolution (480x270@10fps). |
| 2482 vie_encoder_->TriggerQualityHigh(); |
| 2483 timestamp_ms += kFrameIntervalMs; |
| 2484 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2485 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2486 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); |
| 2487 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2488 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2489 EXPECT_EQ(9, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2490 |
| 2491 // Increase bitrate, trigger adapt up, expect increased fps (480x270@15fps). |
| 2492 vie_encoder_->TriggerQualityHigh(); |
| 2493 timestamp_ms += kFrameIntervalMs; |
| 2494 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2495 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2496 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2497 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2498 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2499 EXPECT_EQ(10, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2500 |
| 2501 // Trigger adapt up, expect upscaled resolution (640x360@15fps). |
| 2502 vie_encoder_->TriggerQualityHigh(); |
| 2503 timestamp_ms += kFrameIntervalMs; |
| 2504 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2505 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2506 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); |
| 2507 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2508 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2509 EXPECT_EQ(11, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2510 |
| 2511 // Trigger adapt up, expect increased fps (640x360@30fps). |
| 2512 vie_encoder_->TriggerQualityHigh(); |
| 2513 timestamp_ms += kFrameIntervalMs; |
| 2514 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2515 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2516 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); |
| 2517 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2518 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2519 EXPECT_EQ(12, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2520 |
| 2521 // Trigger adapt up, expect upscaled resolution (960x540@30fps). |
| 2522 vie_encoder_->TriggerQualityHigh(); |
| 2523 timestamp_ms += kFrameIntervalMs; |
| 2524 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2525 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2526 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 2527 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2528 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2529 EXPECT_EQ(13, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2530 |
| 2531 // Trigger adapt up, expect no restriction (1280x720fps@30fps). |
| 2532 vie_encoder_->TriggerQualityHigh(); |
| 2533 timestamp_ms += kFrameIntervalMs; |
| 2534 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2535 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 2536 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 2537 VerifyNoLimitation(source.sink_wants()); |
| 2538 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2539 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2540 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2541 |
| 2542 // Trigger adapt up, expect no change. |
| 2543 vie_encoder_->TriggerQualityHigh(); |
| 2544 VerifyNoLimitation(source.sink_wants()); |
| 2545 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2546 |
| 2547 vie_encoder_->Stop(); |
| 2548 } |
| 2549 |
| 2550 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Framerate) { |
| 2551 const int kWidth = 1280; |
| 2552 const int kHeight = 720; |
| 2553 const int64_t kFrameIntervalMs = 150; |
| 2554 int64_t timestamp_ms = kFrameIntervalMs; |
| 2555 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2556 |
| 2557 // Enable kBalanced preference, no initial limitation. |
| 2558 AdaptingFrameForwarder source; |
| 2559 source.set_adaptation_enabled(true); |
| 2560 vie_encoder_->SetSource(&source, |
| 2561 VideoSendStream::DegradationPreference::kBalanced); |
| 2562 timestamp_ms += kFrameIntervalMs; |
| 2563 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2564 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 2565 VerifyNoLimitation(source.sink_wants()); |
| 2566 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2567 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2568 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2569 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2570 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2571 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2572 |
| 2573 // Trigger cpu adapt down, expect scaled down resolution (960x540@30fps). |
| 2574 vie_encoder_->TriggerCpuOveruse(); |
| 2575 timestamp_ms += kFrameIntervalMs; |
| 2576 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2577 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2578 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 2579 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2580 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2581 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2582 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2583 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2584 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2585 |
| 2586 // Trigger cpu adapt down, expect scaled down resolution (640x360@30fps). |
| 2587 vie_encoder_->TriggerCpuOveruse(); |
| 2588 timestamp_ms += kFrameIntervalMs; |
| 2589 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2590 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2591 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
| 2592 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2593 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2594 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2595 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2596 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2597 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2598 |
| 2599 // Trigger quality adapt down, expect reduced fps (640x360@15fps). |
| 2600 vie_encoder_->TriggerQualityLow(); |
| 2601 timestamp_ms += kFrameIntervalMs; |
| 2602 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2603 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2604 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2605 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2606 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2607 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2608 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2609 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2610 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2611 |
| 2612 // Trigger cpu adapt up, expect increased fps (640x360@30fps). |
| 2613 vie_encoder_->TriggerCpuNormalUsage(); |
| 2614 timestamp_ms += kFrameIntervalMs; |
| 2615 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2616 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2617 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); |
| 2618 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2619 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2620 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2621 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2622 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2623 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2624 |
| 2625 // Trigger quality adapt up, expect upscaled resolution (960x540@30fps). |
| 2626 vie_encoder_->TriggerQualityHigh(); |
| 2627 timestamp_ms += kFrameIntervalMs; |
| 2628 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2629 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2630 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 2631 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2632 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2633 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2634 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2635 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2636 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2637 |
| 2638 // Trigger cpu adapt up, expect no restriction (1280x720fps@30fps). |
| 2639 vie_encoder_->TriggerCpuNormalUsage(); |
| 2640 timestamp_ms += kFrameIntervalMs; |
| 2641 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2642 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 2643 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 2644 VerifyNoLimitation(source.sink_wants()); |
| 2645 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2646 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2647 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2648 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2649 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2650 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2651 |
| 2652 // Trigger adapt up, expect no change. |
| 2653 vie_encoder_->TriggerQualityHigh(); |
| 2654 VerifyNoLimitation(source.sink_wants()); |
| 2655 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2656 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2657 |
| 2658 vie_encoder_->Stop(); |
| 2659 } |
| 2660 |
| 2661 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Resolution) { |
| 2662 const int kWidth = 640; |
| 2663 const int kHeight = 360; |
| 2664 const int kFpsLimit = 15; |
| 2665 const int64_t kFrameIntervalMs = 150; |
| 2666 int64_t timestamp_ms = kFrameIntervalMs; |
| 2667 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2668 |
| 2669 // Enable kBalanced preference, no initial limitation. |
| 2670 AdaptingFrameForwarder source; |
| 2671 source.set_adaptation_enabled(true); |
| 2672 vie_encoder_->SetSource(&source, |
| 2673 VideoSendStream::DegradationPreference::kBalanced); |
| 2674 timestamp_ms += kFrameIntervalMs; |
| 2675 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2676 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 2677 VerifyNoLimitation(source.sink_wants()); |
| 2678 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2679 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2680 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2681 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2682 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2683 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2684 |
| 2685 // Trigger cpu adapt down, expect scaled down framerate (640x360@15fps). |
| 2686 vie_encoder_->TriggerCpuOveruse(); |
| 2687 timestamp_ms += kFrameIntervalMs; |
| 2688 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2689 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2690 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); |
| 2691 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2692 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2693 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2694 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2695 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2696 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2697 |
| 2698 // Trigger quality adapt down, expect scaled down resolution (480x270@15fps). |
| 2699 vie_encoder_->TriggerQualityLow(); |
| 2700 timestamp_ms += kFrameIntervalMs; |
| 2701 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2702 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2703 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); |
| 2704 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2705 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2706 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2707 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2708 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2709 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2710 |
| 2711 // Trigger cpu adapt up, expect upscaled resolution (640x360@15fps). |
| 2712 vie_encoder_->TriggerCpuNormalUsage(); |
| 2713 timestamp_ms += kFrameIntervalMs; |
| 2714 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2715 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2716 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); |
| 2717 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2718 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2719 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2720 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2721 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2722 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2723 |
| 2724 // Trigger quality adapt up, expect increased fps (640x360@30fps). |
| 2725 vie_encoder_->TriggerQualityHigh(); |
| 2726 timestamp_ms += kFrameIntervalMs; |
| 2727 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2728 sink_.WaitForEncodedFrame(timestamp_ms); |
| 2729 VerifyNoLimitation(source.sink_wants()); |
| 2730 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2731 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2732 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2733 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2734 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2735 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2736 |
| 2737 // Trigger adapt up, expect no change. |
| 2738 vie_encoder_->TriggerQualityHigh(); |
| 2739 VerifyNoLimitation(source.sink_wants()); |
| 2740 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2741 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2742 |
| 2743 vie_encoder_->Stop(); |
| 2744 } |
| 2745 |
2123 } // namespace webrtc | 2746 } // namespace webrtc |
OLD | NEW |