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

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

Issue 2800403002: Scale counter and resolution downgrade stats may be incorrect. (Closed)
Patch Set: address comments Created 3 years, 8 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
« no previous file with comments | « 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 11 matching lines...) Expand all
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
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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(kWidth, kHeight);
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 (960x540).
1523 vie_encoder_->TriggerCpuOveruse();
1524 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1525 sink_.WaitForEncodedFrame(2);
1526 VerifyResolutionLimitationLessThan(source.sink_wants(), kWidth * kHeight);
1527 rtc::VideoSinkWants last_wants = source.sink_wants();
1528 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1529 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1530 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1531 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1532
1533 // Trigger cpu adapt down, expect scaled down resolution (640x360).
1534 vie_encoder_->TriggerCpuOveruse();
1535 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight));
1536 sink_.WaitForEncodedFrame(3);
1537 EXPECT_LT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count);
1538 last_wants = source.sink_wants();
1539 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1540 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1541 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1542 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1543
1544 // Trigger cpu adapt down, max cpu downgrades reached, expect no change.
1545 vie_encoder_->TriggerCpuOveruse();
1546 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight));
1547 sink_.WaitForEncodedFrame(4);
1548 EXPECT_EQ(last_wants.max_pixel_count, source.sink_wants().max_pixel_count);
1549 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1550 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1551 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1552 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1553
1554 // Trigger quality adapt down, expect scaled down resolution (480x270).
1555 vie_encoder_->TriggerQualityLow();
1556 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight));
1557 sink_.WaitForEncodedFrame(5);
1558 EXPECT_LT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count);
1559 last_wants = source.sink_wants();
1560 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1561 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1562 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1563 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1564
1565 // Trigger cpu adapt up, expect upscaled resolution (640x360).
1566 vie_encoder_->TriggerCpuNormalUsage();
1567 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight));
1568 sink_.WaitForEncodedFrame(6);
1569 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count);
1570 last_wants = source.sink_wants();
1571 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1572 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1573 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1574 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1575
1576 // Trigger cpu adapt up, expect upscaled resolution (960x540).
1577 vie_encoder_->TriggerCpuNormalUsage();
1578 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight));
1579 sink_.WaitForEncodedFrame(7);
1580 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count);
1581 last_wants = source.sink_wants();
1582 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1583 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1584 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1585 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1586
1587 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540).
1588 vie_encoder_->TriggerCpuNormalUsage();
1589 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight));
1590 sink_.WaitForEncodedFrame(8);
1591 EXPECT_EQ(last_wants.max_pixel_count, source.sink_wants().max_pixel_count);
1592 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1593 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1594 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1595 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1596
1597 // Trigger quality adapt up, expect no restriction (1280x720).
1598 vie_encoder_->TriggerQualityHigh();
1599 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight));
1600 sink_.WaitForEncodedFrame(kWidth, kHeight);
1601 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count);
1602 VerifyNoLimitation(source.sink_wants());
1603 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1604 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1605 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1606 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1607
1608 vie_encoder_->Stop();
1609 }
1427 1610
1428 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { 1611 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) {
1429 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1612 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1430 1613
1431 const int kWidth = 640; 1614 const int kWidth = 640;
1432 const int kHeight = 360; 1615 const int kHeight = 360;
1433 1616
1434 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { 1617 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
1435 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); 1618 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight));
1436 sink_.WaitForEncodedFrame(i); 1619 sink_.WaitForEncodedFrame(i);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 VideoSendStream::DegradationPreference::kBalanced); 1758 VideoSendStream::DegradationPreference::kBalanced);
1576 1759
1577 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); 1760 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1578 // Frame should not be dropped, even if it's too large. 1761 // Frame should not be dropped, even if it's too large.
1579 sink_.WaitForEncodedFrame(1); 1762 sink_.WaitForEncodedFrame(1);
1580 1763
1581 vie_encoder_->Stop(); 1764 vie_encoder_->Stop();
1582 fake_encoder_.SetQualityScaling(true); 1765 fake_encoder_.SetQualityScaling(true);
1583 } 1766 }
1584 1767
1768 TEST_F(ViEEncoderTest,
1769 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) {
1770 const int kTooSmallWidth = 10;
1771 const int kTooSmallHeight = 10;
1772 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1773
1774 // Enable kMaintainFramerate preference, no initial limitation.
1775 test::FrameForwarder source;
1776 vie_encoder_->SetSource(
1777 &source, VideoSendStream::DegradationPreference::kMaintainFramerate);
1778 VerifyNoLimitation(source.sink_wants());
1779 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1780
1781 // Trigger adapt down, too small frame, expect no change.
1782 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight));
1783 sink_.WaitForEncodedFrame(1);
1784 vie_encoder_->TriggerCpuOveruse();
1785 VerifyNoLimitation(source.sink_wants());
1786 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1787 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1788
1789 vie_encoder_->Stop();
1790 }
1791
1585 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { 1792 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) {
1586 fake_encoder_.ForceInitEncodeFailure(true); 1793 fake_encoder_.ForceInitEncodeFailure(true);
1587 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1794 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1588 ResetEncoder("VP8", 2, 1, true); 1795 ResetEncoder("VP8", 2, 1, true);
1589 const int kFrameWidth = 1280; 1796 const int kFrameWidth = 1280;
1590 const int kFrameHeight = 720; 1797 const int kFrameHeight = 720;
1591 video_source_.IncomingCapturedFrame( 1798 video_source_.IncomingCapturedFrame(
1592 CreateFrame(1, kFrameWidth, kFrameHeight)); 1799 CreateFrame(1, kFrameWidth, kFrameHeight));
1593 sink_.ExpectDroppedFrame(); 1800 sink_.ExpectDroppedFrame();
1594 vie_encoder_->Stop(); 1801 vie_encoder_->Stop();
1595 } 1802 }
1596 1803
1597 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. 1804 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions.
1598 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse) { 1805 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse_MaintainFramerateMode) {
1599 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1806 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1600 1807
1601 const int kFrameWidth = 1280; 1808 const int kFrameWidth = 1280;
1602 const int kFrameHeight = 720; 1809 const int kFrameHeight = 720;
1603 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as 1810 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as
1604 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). 1811 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan().
1605 video_source_.set_adaptation_enabled(true); 1812 video_source_.set_adaptation_enabled(true);
1606 1813
1607 video_source_.IncomingCapturedFrame( 1814 video_source_.IncomingCapturedFrame(
1608 CreateFrame(1, kFrameWidth, kFrameHeight)); 1815 CreateFrame(1, kFrameWidth, kFrameHeight));
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 for (int i = 0; i < 10; ++i) { 1977 for (int i = 0; i < 10; ++i) {
1771 timestamp_ms += kMinFpsFrameInterval; 1978 timestamp_ms += kMinFpsFrameInterval;
1772 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); 1979 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000);
1773 video_source_.IncomingCapturedFrame( 1980 video_source_.IncomingCapturedFrame(
1774 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); 1981 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight));
1775 sink_.WaitForEncodedFrame(timestamp_ms); 1982 sink_.WaitForEncodedFrame(timestamp_ms);
1776 } 1983 }
1777 vie_encoder_->Stop(); 1984 vie_encoder_->Stop();
1778 } 1985 }
1779 } // namespace webrtc 1986 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698