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 11 matching lines...) Expand all Loading... | |
22 #include "webrtc/system_wrappers/include/sleep.h" | 22 #include "webrtc/system_wrappers/include/sleep.h" |
23 #include "webrtc/test/encoder_settings.h" | 23 #include "webrtc/test/encoder_settings.h" |
24 #include "webrtc/test/fake_encoder.h" | 24 #include "webrtc/test/fake_encoder.h" |
25 #include "webrtc/test/frame_generator.h" | 25 #include "webrtc/test/frame_generator.h" |
26 #include "webrtc/test/gmock.h" | 26 #include "webrtc/test/gmock.h" |
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 #if defined(WEBRTC_ANDROID) | |
33 // TODO(kthelgason): Lower this limit when better testing | 32 // TODO(kthelgason): Lower this limit when better testing |
34 // on MediaCodec and fallback implementations are in place. | 33 // on MediaCodec and fallback implementations are in place. |
35 const int kMinPixelsPerFrame = 320 * 180; | 34 const int kMinPixelsPerFrame = 320 * 180; |
36 #else | |
37 const int kMinPixelsPerFrame = 120 * 90; | |
38 #endif | |
39 const int kMinFramerateFps = 2; | 35 const int kMinFramerateFps = 2; |
40 const int64_t kFrameTimeoutMs = 100; | 36 const int64_t kFrameTimeoutMs = 100; |
41 } // namespace | 37 } // namespace |
42 | 38 |
43 namespace webrtc { | 39 namespace webrtc { |
44 | 40 |
45 using DegredationPreference = VideoSendStream::DegradationPreference; | 41 using DegredationPreference = VideoSendStream::DegradationPreference; |
46 using ScaleReason = AdaptationObserverInterface::AdaptReason; | 42 using ScaleReason = AdaptationObserverInterface::AdaptReason; |
47 using ::testing::_; | 43 using ::testing::_; |
48 using ::testing::Return; | 44 using ::testing::Return; |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 } | 715 } |
720 | 716 |
721 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { | 717 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { |
722 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); | 718 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); |
723 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); | 719 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); |
724 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); | 720 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); |
725 vie_encoder_->Stop(); | 721 vie_encoder_->Stop(); |
726 } | 722 } |
727 | 723 |
728 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { | 724 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { |
725 const int kMaxDowngrades = ViEEncoder::kMaxCpuResolutionDowngrades; | |
729 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 726 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
730 | 727 |
731 VerifyNoLimitation(video_source_.sink_wants()); | 728 VerifyNoLimitation(video_source_.sink_wants()); |
732 | 729 |
733 int frame_width = 1280; | 730 int frame_width = 1280; |
734 int frame_height = 720; | 731 int frame_height = 720; |
735 | 732 |
736 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should | 733 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should |
737 // request lower resolution. | 734 // request lower resolution. |
738 for (int i = 1; i <= ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { | 735 for (int i = 1; i <= kMaxDowngrades; ++i) { |
739 video_source_.IncomingCapturedFrame( | 736 video_source_.IncomingCapturedFrame( |
740 CreateFrame(i, frame_width, frame_height)); | 737 CreateFrame(i, frame_width, frame_height)); |
741 sink_.WaitForEncodedFrame(i); | 738 sink_.WaitForEncodedFrame(i); |
742 | 739 |
743 vie_encoder_->TriggerCpuOveruse(); | 740 vie_encoder_->TriggerCpuOveruse(); |
744 | 741 |
745 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 742 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
746 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 743 EXPECT_LT(video_source_.sink_wants().max_pixel_count, |
747 frame_width * frame_height); | 744 frame_width * frame_height); |
745 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
746 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
748 | 747 |
749 frame_width /= 2; | 748 frame_width /= 2; |
750 frame_height /= 2; | 749 frame_height /= 2; |
751 } | 750 } |
752 | 751 |
753 // Trigger CPU overuse one more time. This should not trigger a request for | 752 // Trigger CPU overuse one more time. This should not trigger a request for |
754 // lower resolution. | 753 // lower resolution. |
755 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); | 754 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); |
756 video_source_.IncomingCapturedFrame(CreateFrame( | 755 video_source_.IncomingCapturedFrame( |
757 ViEEncoder::kMaxCpuResolutionDowngrades + 1, frame_width, frame_height)); | 756 CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); |
758 sink_.WaitForEncodedFrame(ViEEncoder::kMaxCpuResolutionDowngrades + 1); | 757 sink_.WaitForEncodedFrame(kMaxDowngrades + 1); |
759 vie_encoder_->TriggerCpuOveruse(); | 758 vie_encoder_->TriggerCpuOveruse(); |
760 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, | 759 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, |
761 current_wants.target_pixel_count); | 760 current_wants.target_pixel_count); |
762 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, | 761 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, |
763 current_wants.max_pixel_count); | 762 current_wants.max_pixel_count); |
763 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
764 EXPECT_EQ(kMaxDowngrades, | |
765 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
764 | 766 |
765 // Trigger CPU normal use. | 767 // Trigger CPU normal use. |
766 vie_encoder_->TriggerCpuNormalUsage(); | 768 vie_encoder_->TriggerCpuNormalUsage(); |
767 EXPECT_EQ(frame_width * frame_height * 5 / 3, | 769 EXPECT_EQ(frame_width * frame_height * 5 / 3, |
768 video_source_.sink_wants().target_pixel_count.value_or(0)); | 770 video_source_.sink_wants().target_pixel_count.value_or(0)); |
769 EXPECT_EQ(frame_width * frame_height * 4, | 771 EXPECT_EQ(frame_width * frame_height * 4, |
770 video_source_.sink_wants().max_pixel_count); | 772 video_source_.sink_wants().max_pixel_count); |
773 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
774 EXPECT_EQ(kMaxDowngrades + 1, | |
775 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
771 | 776 |
772 vie_encoder_->Stop(); | 777 vie_encoder_->Stop(); |
773 } | 778 } |
774 | 779 |
775 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) { | 780 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) { |
776 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 781 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
777 VerifyNoLimitation(video_source_.sink_wants()); | 782 VerifyNoLimitation(video_source_.sink_wants()); |
778 | 783 |
779 const int kFrameWidth = 1280; | 784 const int kFrameWidth = 1280; |
780 const int kFrameHeight = 720; | 785 const int kFrameHeight = 720; |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1277 | 1282 |
1278 // Expect no scaling. | 1283 // Expect no scaling. |
1279 EXPECT_EQ(std::numeric_limits<int>::max(), | 1284 EXPECT_EQ(std::numeric_limits<int>::max(), |
1280 new_video_source.sink_wants().max_pixel_count); | 1285 new_video_source.sink_wants().max_pixel_count); |
1281 | 1286 |
1282 // Trigger scale up. | 1287 // Trigger scale up. |
1283 vie_encoder_->TriggerQualityHigh(); | 1288 vie_encoder_->TriggerQualityHigh(); |
1284 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1289 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1285 sink_.WaitForEncodedFrame(4); | 1290 sink_.WaitForEncodedFrame(4); |
1286 | 1291 |
1287 // Expect nothing to change, still no scaling. | 1292 // Expect nothing to change, still no scaling |
kthelgason
2017/04/19 08:23:04
accident?
åsapersson
2017/04/20 13:44:47
yes
| |
1288 EXPECT_EQ(std::numeric_limits<int>::max(), | 1293 EXPECT_EQ(std::numeric_limits<int>::max(), |
1289 new_video_source.sink_wants().max_pixel_count); | 1294 new_video_source.sink_wants().max_pixel_count); |
1290 | 1295 |
1291 vie_encoder_->Stop(); | 1296 vie_encoder_->Stop(); |
1292 } | 1297 } |
1293 | 1298 |
1294 TEST_F(ViEEncoderTest, SkipsSameAdaptDownRequest_MaintainFramerateMode) { | 1299 TEST_F(ViEEncoderTest, SkipsSameAdaptDownRequest_MaintainFramerateMode) { |
1295 const int kWidth = 1280; | 1300 const int kWidth = 1280; |
1296 const int kHeight = 720; | 1301 const int kHeight = 720; |
1297 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1302 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1401 // Trigger adapt up, expect no restriction. | 1406 // Trigger adapt up, expect no restriction. |
1402 vie_encoder_->TriggerQualityHigh(); | 1407 vie_encoder_->TriggerQualityHigh(); |
1403 VerifyNoLimitation(source.sink_wants()); | 1408 VerifyNoLimitation(source.sink_wants()); |
1404 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1409 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1405 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1410 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1406 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1411 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1407 | 1412 |
1408 vie_encoder_->Stop(); | 1413 vie_encoder_->Stop(); |
1409 } | 1414 } |
1410 | 1415 |
1411 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { | 1416 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetResolutionLimit) { |
1412 int frame_width = 1280; | 1417 const int kWidth = 1280; |
1413 int frame_height = 720; | 1418 const int kHeight = 720; |
1419 const size_t kNumFrames = 10; | |
1420 | |
1414 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1421 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1415 | 1422 |
1416 for (size_t i = 1; i <= 10; i++) { | 1423 // Enable adapter, expected input resolutions when downscaling: |
1417 video_source_.IncomingCapturedFrame( | 1424 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) |
1418 CreateFrame(i, frame_width, frame_height)); | 1425 video_source_.set_adaptation_enabled(true); |
1426 | |
1427 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | |
1428 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1429 | |
1430 int downscales = 0; | |
1431 for (size_t i = 1; i <= kNumFrames; i++) { | |
1432 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | |
1419 sink_.WaitForEncodedFrame(i); | 1433 sink_.WaitForEncodedFrame(i); |
1434 | |
1420 // Trigger scale down. | 1435 // Trigger scale down. |
1436 rtc::VideoSinkWants last_wants = video_source_.sink_wants(); | |
1421 vie_encoder_->TriggerQualityLow(); | 1437 vie_encoder_->TriggerQualityLow(); |
1422 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); | 1438 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); |
1439 | |
1440 if (video_source_.sink_wants().max_pixel_count < last_wants.max_pixel_count) | |
1441 ++downscales; | |
1442 | |
1443 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | |
1444 EXPECT_EQ(downscales, | |
1445 stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1446 EXPECT_GT(downscales, 0); | |
1423 } | 1447 } |
1448 vie_encoder_->Stop(); | |
1449 } | |
1450 | |
1451 TEST_F(ViEEncoderTest, | |
1452 AdaptsResolutionUpAndDownTwiceOnOveruse_MaintainFramerateMode) { | |
1453 const int kWidth = 1280; | |
1454 const int kHeight = 720; | |
1455 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
1456 | |
1457 // Enable kMaintainFramerate preference, no initial limitation. | |
1458 AdaptingFrameForwarder source; | |
1459 source.set_adaptation_enabled(true); | |
1460 vie_encoder_->SetSource( | |
1461 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | |
1462 | |
1463 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | |
1464 sink_.WaitForEncodedFrame(1); | |
1465 VerifyNoLimitation(source.sink_wants()); | |
1466 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1467 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1468 | |
1469 // Trigger adapt down, expect scaled down resolution. | |
1470 vie_encoder_->TriggerCpuOveruse(); | |
1471 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | |
1472 sink_.WaitForEncodedFrame(2); | |
1473 VerifyResolutionLimitationLessThan(source.sink_wants(), kWidth * kHeight); | |
1474 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1475 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1476 | |
1477 // Trigger adapt up, expect no restriction. | |
1478 vie_encoder_->TriggerCpuNormalUsage(); | |
1479 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | |
1480 sink_.WaitForEncodedFrame(3); | |
1481 VerifyNoLimitation(source.sink_wants()); | |
1482 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1483 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1484 | |
1485 // Trigger adapt down, expect scaled down resolution. | |
1486 vie_encoder_->TriggerCpuOveruse(); | |
1487 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | |
1488 sink_.WaitForEncodedFrame(4); | |
1489 VerifyResolutionLimitationLessThan(source.sink_wants(), kWidth * kHeight); | |
1490 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1491 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1492 | |
1493 // Trigger adapt up, expect no restriction. | |
1494 vie_encoder_->TriggerCpuNormalUsage(); | |
1495 VerifyNoLimitation(source.sink_wants()); | |
1496 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1497 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1424 | 1498 |
1425 vie_encoder_->Stop(); | 1499 vie_encoder_->Stop(); |
1426 } | 1500 } |
1501 | |
1502 TEST_F(ViEEncoderTest, | |
1503 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { | |
1504 const int kWidth = 1280; | |
1505 const int kHeight = 720; | |
1506 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
1507 | |
1508 // Enable kMaintainFramerate preference, no initial limitation. | |
1509 AdaptingFrameForwarder source; | |
1510 source.set_adaptation_enabled(true); | |
1511 vie_encoder_->SetSource( | |
1512 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | |
1513 | |
1514 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | |
1515 sink_.WaitForEncodedFrame(1280, 720); | |
1516 VerifyNoLimitation(source.sink_wants()); | |
1517 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1518 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | |
1519 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1520 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1521 | |
1522 // Trigger cpu adapt down, expect scaled down resolution. | |
1523 vie_encoder_->TriggerCpuOveruse(); | |
1524 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | |
1525 sink_.WaitForEncodedFrame(960, 540); | |
kthelgason
2017/04/19 08:23:04
I've tried to avoid making assumptions about the s
åsapersson
2017/04/20 13:44:47
Done.
| |
1526 VerifyResolutionLimitationLessThan(source.sink_wants(), kWidth * kHeight); | |
1527 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1528 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | |
1529 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1530 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1531 | |
1532 // Trigger cpu adapt down, expect scaled down resolution. | |
1533 vie_encoder_->TriggerCpuOveruse(); | |
1534 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | |
1535 sink_.WaitForEncodedFrame(640, 360); | |
1536 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1537 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | |
1538 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1539 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1540 | |
1541 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. | |
1542 vie_encoder_->TriggerCpuOveruse(); | |
1543 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | |
1544 sink_.WaitForEncodedFrame(640, 360); | |
1545 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1546 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | |
1547 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1548 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1549 | |
1550 // Trigger quality adapt down, expect scaled down resolution. | |
1551 vie_encoder_->TriggerQualityLow(); | |
1552 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | |
1553 sink_.WaitForEncodedFrame(480, 270); | |
1554 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1555 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | |
1556 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1557 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1558 | |
1559 // Trigger cpu adapt up, expect upscaled resolution. | |
1560 vie_encoder_->TriggerCpuNormalUsage(); | |
1561 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); | |
1562 sink_.WaitForEncodedFrame(640, 360); | |
1563 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1564 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | |
1565 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1566 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1567 | |
1568 // Trigger cpu adapt up, expect upscaled resolution. | |
1569 vie_encoder_->TriggerCpuNormalUsage(); | |
1570 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); | |
1571 sink_.WaitForEncodedFrame(960, 540); | |
1572 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1573 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | |
1574 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1575 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1576 | |
1577 // Trigger cpu adapt up, no cpu downgrades, expect no change. | |
1578 vie_encoder_->TriggerCpuNormalUsage(); | |
1579 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); | |
1580 sink_.WaitForEncodedFrame(960, 540); | |
1581 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1582 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | |
1583 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1584 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1585 | |
1586 // Trigger quality adapt up, expect no restriction. | |
1587 vie_encoder_->TriggerQualityHigh(); | |
1588 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); | |
1589 sink_.WaitForEncodedFrame(1280, 720); | |
1590 VerifyNoLimitation(source.sink_wants()); | |
1591 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1592 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | |
1593 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1594 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | |
1595 | |
1596 vie_encoder_->Stop(); | |
1597 } | |
1427 | 1598 |
1428 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { | 1599 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { |
1429 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1600 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1430 | 1601 |
1431 const int kWidth = 640; | 1602 const int kWidth = 640; |
1432 const int kHeight = 360; | 1603 const int kHeight = 360; |
1433 | 1604 |
1434 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 1605 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
1435 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1606 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1436 sink_.WaitForEncodedFrame(i); | 1607 sink_.WaitForEncodedFrame(i); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1575 VideoSendStream::DegradationPreference::kBalanced); | 1746 VideoSendStream::DegradationPreference::kBalanced); |
1576 | 1747 |
1577 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1748 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1578 // Frame should not be dropped, even if it's too large. | 1749 // Frame should not be dropped, even if it's too large. |
1579 sink_.WaitForEncodedFrame(1); | 1750 sink_.WaitForEncodedFrame(1); |
1580 | 1751 |
1581 vie_encoder_->Stop(); | 1752 vie_encoder_->Stop(); |
1582 fake_encoder_.SetQualityScaling(true); | 1753 fake_encoder_.SetQualityScaling(true); |
1583 } | 1754 } |
1584 | 1755 |
1756 TEST_F(ViEEncoderTest, | |
1757 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) { | |
1758 const int kTooSmallWidth = 10; | |
1759 const int kTooSmallHeight = 10; | |
1760 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
1761 | |
1762 // Enable kMaintainFramerate preference, no initial limitation. | |
1763 test::FrameForwarder source; | |
1764 vie_encoder_->SetSource( | |
1765 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | |
1766 VerifyNoLimitation(source.sink_wants()); | |
1767 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1768 | |
1769 // Trigger adapt down, too small frame, expect no change. | |
1770 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); | |
1771 sink_.WaitForEncodedFrame(1); | |
1772 vie_encoder_->TriggerCpuOveruse(); | |
1773 VerifyNoLimitation(source.sink_wants()); | |
1774 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | |
1775 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | |
1776 | |
1777 vie_encoder_->Stop(); | |
1778 } | |
1779 | |
1585 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { | 1780 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { |
1586 fake_encoder_.ForceInitEncodeFailure(true); | 1781 fake_encoder_.ForceInitEncodeFailure(true); |
1587 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1782 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1588 ResetEncoder("VP8", 2, 1, true); | 1783 ResetEncoder("VP8", 2, 1, true); |
1589 const int kFrameWidth = 1280; | 1784 const int kFrameWidth = 1280; |
1590 const int kFrameHeight = 720; | 1785 const int kFrameHeight = 720; |
1591 video_source_.IncomingCapturedFrame( | 1786 video_source_.IncomingCapturedFrame( |
1592 CreateFrame(1, kFrameWidth, kFrameHeight)); | 1787 CreateFrame(1, kFrameWidth, kFrameHeight)); |
1593 sink_.ExpectDroppedFrame(); | 1788 sink_.ExpectDroppedFrame(); |
1594 vie_encoder_->Stop(); | 1789 vie_encoder_->Stop(); |
1595 } | 1790 } |
1596 | 1791 |
1597 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. | 1792 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. |
1598 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse) { | 1793 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse_MaintainFramerateMode) { |
1599 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1794 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1600 | 1795 |
1601 const int kFrameWidth = 1280; | 1796 const int kFrameWidth = 1280; |
1602 const int kFrameHeight = 720; | 1797 const int kFrameHeight = 720; |
1603 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as | 1798 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as |
1604 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). | 1799 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). |
1605 video_source_.set_adaptation_enabled(true); | 1800 video_source_.set_adaptation_enabled(true); |
1606 | 1801 |
1607 video_source_.IncomingCapturedFrame( | 1802 video_source_.IncomingCapturedFrame( |
1608 CreateFrame(1, kFrameWidth, kFrameHeight)); | 1803 CreateFrame(1, kFrameWidth, kFrameHeight)); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1770 for (int i = 0; i < 10; ++i) { | 1965 for (int i = 0; i < 10; ++i) { |
1771 timestamp_ms += kMinFpsFrameInterval; | 1966 timestamp_ms += kMinFpsFrameInterval; |
1772 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); | 1967 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); |
1773 video_source_.IncomingCapturedFrame( | 1968 video_source_.IncomingCapturedFrame( |
1774 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 1969 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
1775 sink_.WaitForEncodedFrame(timestamp_ms); | 1970 sink_.WaitForEncodedFrame(timestamp_ms); |
1776 } | 1971 } |
1777 vie_encoder_->Stop(); | 1972 vie_encoder_->Stop(); |
1778 } | 1973 } |
1779 } // namespace webrtc | 1974 } // namespace webrtc |
OLD | NEW |