| 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/test/frame_generator.h" | 22 #include "webrtc/test/frame_generator.h" |
| 23 #include "webrtc/test/gmock.h" | 23 #include "webrtc/test/gmock.h" |
| 24 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
| 25 #include "webrtc/video/send_statistics_proxy.h" | 25 #include "webrtc/video/send_statistics_proxy.h" |
| 26 #include "webrtc/video/vie_encoder.h" | 26 #include "webrtc/video/vie_encoder.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 #if defined(WEBRTC_ANDROID) | 29 #if defined(WEBRTC_ANDROID) |
| 30 // TODO(kthelgason): Lower this limit when better testing | 30 // TODO(kthelgason): Lower this limit when better testing |
| 31 // on MediaCodec and fallback implementations are in place. | 31 // on MediaCodec and fallback implementations are in place. |
| 32 const int kMinPixelsPerFrame = 320 * 180; | 32 const uint32_t kMinPixelsPerFrame = 320 * 180; |
| 33 #else | 33 #else |
| 34 const int kMinPixelsPerFrame = 120 * 90; | 34 const uint32_t kMinPixelsPerFrame = 120 * 90; |
| 35 #endif | 35 #endif |
| 36 } | 36 } |
| 37 | 37 |
| 38 namespace webrtc { | 38 namespace webrtc { |
| 39 | 39 |
| 40 using DegredationPreference = VideoSendStream::DegradationPreference; | 40 using DegredationPreference = VideoSendStream::DegradationPreference; |
| 41 using ScaleReason = AdaptationObserverInterface::AdaptReason; | 41 using ScaleReason = AdaptationObserverInterface::AdaptReason; |
| 42 using ::testing::_; | 42 using ::testing::_; |
| 43 using ::testing::Return; | 43 using ::testing::Return; |
| 44 | 44 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 adapted_frame.set_ntp_time_ms(video_frame.ntp_time_ms()); | 144 adapted_frame.set_ntp_time_ms(video_frame.ntp_time_ms()); |
| 145 test::FrameForwarder::IncomingCapturedFrame(adapted_frame); | 145 test::FrameForwarder::IncomingCapturedFrame(adapted_frame); |
| 146 } else { | 146 } else { |
| 147 test::FrameForwarder::IncomingCapturedFrame(video_frame); | 147 test::FrameForwarder::IncomingCapturedFrame(video_frame); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, | 151 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 152 const rtc::VideoSinkWants& wants) override { | 152 const rtc::VideoSinkWants& wants) override { |
| 153 rtc::CritScope cs(&crit_); | 153 rtc::CritScope cs(&crit_); |
| 154 adapter_.OnResolutionRequest(wants.target_pixel_count, | 154 adapter_.OnResolutionFramerateRequest(wants.pixel_count, |
| 155 wants.max_pixel_count); | 155 wants.framerate_fps_); |
| 156 test::FrameForwarder::AddOrUpdateSink(sink, wants); | 156 test::FrameForwarder::AddOrUpdateSink(sink, wants); |
| 157 } | 157 } |
| 158 | 158 |
| 159 cricket::VideoAdapter adapter_; | 159 cricket::VideoAdapter adapter_; |
| 160 bool adaptation_enabled_ GUARDED_BY(crit_); | 160 bool adaptation_enabled_ GUARDED_BY(crit_); |
| 161 }; | 161 }; |
| 162 } // namespace | 162 } // namespace |
| 163 | 163 |
| 164 class ViEEncoderTest : public ::testing::Test { | 164 class ViEEncoderTest : public ::testing::Test { |
| 165 public: | 165 public: |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { | 614 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { |
| 615 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); | 615 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); |
| 616 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); | 616 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); |
| 617 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); | 617 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); |
| 618 vie_encoder_->Stop(); | 618 vie_encoder_->Stop(); |
| 619 } | 619 } |
| 620 | 620 |
| 621 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { | 621 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { |
| 622 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 622 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 623 | 623 |
| 624 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 624 EXPECT_FALSE(video_source_.sink_wants().pixel_count); |
| 625 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | |
| 626 | 625 |
| 627 int frame_width = 1280; | 626 int frame_width = 1280; |
| 628 int frame_height = 720; | 627 int frame_height = 720; |
| 629 | 628 |
| 630 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should | 629 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should |
| 631 // request lower resolution. | 630 // request lower resolution. |
| 632 for (int i = 1; i <= ViEEncoder::kMaxCpuDowngrades; ++i) { | 631 for (int i = 1; i <= ViEEncoder::kMaxCpuDowngrades; ++i) { |
| 633 video_source_.IncomingCapturedFrame( | 632 video_source_.IncomingCapturedFrame( |
| 634 CreateFrame(i, frame_width, frame_height)); | 633 CreateFrame(i, frame_width, frame_height)); |
| 635 sink_.WaitForEncodedFrame(i); | 634 sink_.WaitForEncodedFrame(i); |
| 636 | 635 |
| 637 vie_encoder_->TriggerCpuOveruse(); | 636 vie_encoder_->TriggerCpuOveruse(); |
| 638 | 637 |
| 639 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 638 ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
| 640 EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( | 639 EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
| 641 std::numeric_limits<int>::max()), | 640 static_cast<uint32_t>(frame_width * frame_height)); |
| 642 frame_width * frame_height); | |
| 643 | 641 |
| 644 frame_width /= 2; | 642 frame_width /= 2; |
| 645 frame_height /= 2; | 643 frame_height /= 2; |
| 646 } | 644 } |
| 647 | 645 |
| 648 // Trigger CPU overuse one more time. This should not trigger a request for | 646 // Trigger CPU overuse one more time. This should not trigger a request for |
| 649 // lower resolution. | 647 // lower resolution. |
| 650 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); | 648 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); |
| 651 video_source_.IncomingCapturedFrame(CreateFrame( | 649 video_source_.IncomingCapturedFrame(CreateFrame( |
| 652 ViEEncoder::kMaxCpuDowngrades + 1, frame_width, frame_height)); | 650 ViEEncoder::kMaxCpuDowngrades + 1, frame_width, frame_height)); |
| 653 sink_.WaitForEncodedFrame(ViEEncoder::kMaxCpuDowngrades + 1); | 651 sink_.WaitForEncodedFrame(ViEEncoder::kMaxCpuDowngrades + 1); |
| 654 vie_encoder_->TriggerCpuOveruse(); | 652 vie_encoder_->TriggerCpuOveruse(); |
| 655 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, | 653 ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
| 656 current_wants.target_pixel_count); | 654 ASSERT_TRUE(static_cast<bool>(current_wants.pixel_count)); |
| 657 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, | 655 EXPECT_EQ(video_source_.sink_wants().pixel_count->min, |
| 658 current_wants.max_pixel_count); | 656 current_wants.pixel_count->min); |
| 657 EXPECT_EQ(video_source_.sink_wants().pixel_count->target, |
| 658 current_wants.pixel_count->target); |
| 659 EXPECT_EQ(video_source_.sink_wants().pixel_count->max, |
| 660 current_wants.pixel_count->max); |
| 659 | 661 |
| 660 // Trigger CPU normal use. | 662 // Trigger CPU normal use. |
| 661 vie_encoder_->TriggerCpuNormalUsage(); | 663 vie_encoder_->TriggerCpuNormalUsage(); |
| 662 EXPECT_EQ(frame_width * frame_height * 5 / 3, | 664 EXPECT_GT(video_source_.sink_wants().pixel_count->min, 0U); |
| 663 video_source_.sink_wants().target_pixel_count.value_or(0)); | 665 EXPECT_LE(video_source_.sink_wants().pixel_count->min, |
| 664 EXPECT_EQ(frame_width * frame_height * 4, | 666 video_source_.sink_wants().pixel_count->target); |
| 665 video_source_.sink_wants().max_pixel_count.value_or(0)); | 667 EXPECT_EQ(static_cast<uint32_t>(frame_width * frame_height * 5 / 3), |
| 668 video_source_.sink_wants().pixel_count->target); |
| 669 EXPECT_EQ(static_cast<uint32_t>(frame_width * frame_height * 4), |
| 670 video_source_.sink_wants().pixel_count->max); |
| 666 | 671 |
| 667 vie_encoder_->Stop(); | 672 vie_encoder_->Stop(); |
| 668 } | 673 } |
| 669 | 674 |
| 670 TEST_F(ViEEncoderTest, | 675 TEST_F(ViEEncoderTest, |
| 671 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { | 676 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { |
| 672 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 677 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 673 | 678 |
| 674 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 679 EXPECT_FALSE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
| 675 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | |
| 676 | 680 |
| 677 int frame_width = 1280; | 681 int frame_width = 1280; |
| 678 int frame_height = 720; | 682 int frame_height = 720; |
| 679 | 683 |
| 680 video_source_.IncomingCapturedFrame( | 684 video_source_.IncomingCapturedFrame( |
| 681 CreateFrame(1, frame_width, frame_height)); | 685 CreateFrame(1, frame_width, frame_height)); |
| 682 sink_.WaitForEncodedFrame(1); | 686 sink_.WaitForEncodedFrame(1); |
| 683 // Trigger CPU overuse. | 687 // Trigger CPU overuse. |
| 684 vie_encoder_->TriggerCpuOveruse(); | 688 vie_encoder_->TriggerCpuOveruse(); |
| 685 | 689 |
| 686 video_source_.IncomingCapturedFrame( | 690 video_source_.IncomingCapturedFrame( |
| 687 CreateFrame(2, frame_width, frame_height)); | 691 CreateFrame(2, frame_width, frame_height)); |
| 688 sink_.WaitForEncodedFrame(2); | 692 sink_.WaitForEncodedFrame(2); |
| 689 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 693 ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
| 690 EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( | 694 EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
| 691 std::numeric_limits<int>::max()), | 695 static_cast<uint32_t>(frame_width * frame_height)); |
| 692 frame_width * frame_height); | |
| 693 | 696 |
| 694 // Set new source. | 697 // Set new source. |
| 695 test::FrameForwarder new_video_source; | 698 test::FrameForwarder new_video_source; |
| 696 vie_encoder_->SetSource( | 699 vie_encoder_->SetSource( |
| 697 &new_video_source, | 700 &new_video_source, |
| 698 VideoSendStream::DegradationPreference::kMaintainResolution); | 701 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 699 | 702 |
| 700 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 703 EXPECT_FALSE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
| 701 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | |
| 702 | 704 |
| 703 new_video_source.IncomingCapturedFrame( | 705 new_video_source.IncomingCapturedFrame( |
| 704 CreateFrame(3, frame_width, frame_height)); | 706 CreateFrame(3, frame_width, frame_height)); |
| 705 sink_.WaitForEncodedFrame(3); | 707 sink_.WaitForEncodedFrame(3); |
| 706 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 708 EXPECT_FALSE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
| 707 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | |
| 708 | 709 |
| 709 // Calling SetSource with resolution scaling enabled apply the old SinkWants. | 710 // Calling SetSource with resolution scaling enabled apply the old SinkWants. |
| 710 vie_encoder_->SetSource(&new_video_source, | 711 vie_encoder_->SetSource(&new_video_source, |
| 711 VideoSendStream::DegradationPreference::kBalanced); | 712 VideoSendStream::DegradationPreference::kBalanced); |
| 712 EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or( | 713 ASSERT_TRUE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
| 713 std::numeric_limits<int>::max()), | 714 EXPECT_LT(new_video_source.sink_wants().pixel_count->max, |
| 714 frame_width * frame_height); | 715 static_cast<uint32_t>(frame_width * frame_height)); |
| 715 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | |
| 716 | 716 |
| 717 vie_encoder_->Stop(); | 717 vie_encoder_->Stop(); |
| 718 } | 718 } |
| 719 | 719 |
| 720 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) { | 720 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) { |
| 721 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 721 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 722 | 722 |
| 723 int frame_width = 1280; | 723 int frame_width = 1280; |
| 724 int frame_height = 720; | 724 int frame_height = 720; |
| 725 | 725 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 stats.preferred_media_bitrate_bps); | 964 stats.preferred_media_bitrate_bps); |
| 965 | 965 |
| 966 vie_encoder_->Stop(); | 966 vie_encoder_->Stop(); |
| 967 } | 967 } |
| 968 | 968 |
| 969 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 969 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
| 970 int frame_width = 1280; | 970 int frame_width = 1280; |
| 971 int frame_height = 720; | 971 int frame_height = 720; |
| 972 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 972 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 973 | 973 |
| 974 // Expect no scaling to begin with | 974 // Expect no scaling to begin with. |
| 975 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 975 EXPECT_FALSE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
| 976 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | |
| 977 | 976 |
| 978 video_source_.IncomingCapturedFrame( | 977 video_source_.IncomingCapturedFrame( |
| 979 CreateFrame(1, frame_width, frame_height)); | 978 CreateFrame(1, frame_width, frame_height)); |
| 980 sink_.WaitForEncodedFrame(1); | 979 sink_.WaitForEncodedFrame(1); |
| 981 | 980 |
| 982 // Trigger scale down | 981 // Trigger scale down. |
| 983 vie_encoder_->TriggerQualityLow(); | 982 vie_encoder_->TriggerQualityLow(); |
| 984 | 983 |
| 985 video_source_.IncomingCapturedFrame( | 984 video_source_.IncomingCapturedFrame( |
| 986 CreateFrame(2, frame_width, frame_height)); | 985 CreateFrame(2, frame_width, frame_height)); |
| 987 sink_.WaitForEncodedFrame(2); | 986 sink_.WaitForEncodedFrame(2); |
| 988 | 987 |
| 989 // Expect a scale down. | 988 // Expect a scale down. |
| 990 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 989 ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
| 991 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, | 990 EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
| 992 frame_width * frame_height); | 991 static_cast<uint32_t>(frame_width * frame_height)); |
| 993 | 992 |
| 994 // Set adaptation disabled. | 993 // Set adaptation disabled. |
| 995 test::FrameForwarder new_video_source; | 994 test::FrameForwarder new_video_source; |
| 996 vie_encoder_->SetSource( | 995 vie_encoder_->SetSource( |
| 997 &new_video_source, | 996 &new_video_source, |
| 998 VideoSendStream::DegradationPreference::kMaintainResolution); | 997 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 999 | 998 |
| 1000 // Trigger scale down | 999 // Trigger scale down. |
| 1001 vie_encoder_->TriggerQualityLow(); | 1000 vie_encoder_->TriggerQualityLow(); |
| 1002 new_video_source.IncomingCapturedFrame( | 1001 new_video_source.IncomingCapturedFrame( |
| 1003 CreateFrame(3, frame_width, frame_height)); | 1002 CreateFrame(3, frame_width, frame_height)); |
| 1004 sink_.WaitForEncodedFrame(3); | 1003 sink_.WaitForEncodedFrame(3); |
| 1005 | 1004 |
| 1006 // Expect no scaling | 1005 // Expect no scaling. |
| 1007 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | 1006 EXPECT_FALSE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
| 1008 | 1007 |
| 1009 // Trigger scale up | 1008 // Trigger scale up. |
| 1010 vie_encoder_->TriggerQualityHigh(); | 1009 vie_encoder_->TriggerQualityHigh(); |
| 1011 new_video_source.IncomingCapturedFrame( | 1010 new_video_source.IncomingCapturedFrame( |
| 1012 CreateFrame(4, frame_width, frame_height)); | 1011 CreateFrame(4, frame_width, frame_height)); |
| 1013 sink_.WaitForEncodedFrame(4); | 1012 sink_.WaitForEncodedFrame(4); |
| 1014 | 1013 |
| 1015 // Expect nothing to change, still no scaling | 1014 // Expect nothing to change, still no scaling. |
| 1016 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | 1015 EXPECT_FALSE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
| 1017 | 1016 |
| 1018 vie_encoder_->Stop(); | 1017 vie_encoder_->Stop(); |
| 1019 } | 1018 } |
| 1020 | 1019 |
| 1021 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { | 1020 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { |
| 1022 int frame_width = 1280; | 1021 int frame_width = 1280; |
| 1023 int frame_height = 720; | 1022 int frame_height = 720; |
| 1024 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1023 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1025 | 1024 |
| 1026 for (size_t i = 1; i <= 10; i++) { | 1025 for (size_t i = 1; i <= 10; i++) { |
| 1027 video_source_.IncomingCapturedFrame( | 1026 video_source_.IncomingCapturedFrame( |
| 1028 CreateFrame(i, frame_width, frame_height)); | 1027 CreateFrame(i, frame_width, frame_height)); |
| 1029 sink_.WaitForEncodedFrame(i); | 1028 sink_.WaitForEncodedFrame(i); |
| 1030 // Trigger scale down | 1029 // Trigger scale down |
| 1031 vie_encoder_->TriggerQualityLow(); | 1030 vie_encoder_->TriggerQualityLow(); |
| 1032 EXPECT_GE(*video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); | 1031 ASSERT_TRUE(video_source_.sink_wants().pixel_count); |
| 1032 EXPECT_GE(video_source_.sink_wants().pixel_count->min, kMinPixelsPerFrame); |
| 1033 EXPECT_GE(video_source_.sink_wants().pixel_count->max, kMinPixelsPerFrame); |
| 1033 } | 1034 } |
| 1034 | 1035 |
| 1035 vie_encoder_->Stop(); | 1036 vie_encoder_->Stop(); |
| 1036 } | 1037 } |
| 1037 | 1038 |
| 1038 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { | 1039 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { |
| 1039 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1040 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1040 | 1041 |
| 1041 int frame_width = 640; | 1042 int frame_width = 640; |
| 1042 int frame_height = 360; | 1043 int frame_height = 360; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 int frame_width = 640; | 1115 int frame_width = 640; |
| 1115 int frame_height = 360; | 1116 int frame_height = 360; |
| 1116 | 1117 |
| 1117 video_source_.IncomingCapturedFrame( | 1118 video_source_.IncomingCapturedFrame( |
| 1118 CreateFrame(1, frame_width, frame_height)); | 1119 CreateFrame(1, frame_width, frame_height)); |
| 1119 | 1120 |
| 1120 // Expect to drop this frame, the wait should time out. | 1121 // Expect to drop this frame, the wait should time out. |
| 1121 sink_.ExpectDroppedFrame(); | 1122 sink_.ExpectDroppedFrame(); |
| 1122 | 1123 |
| 1123 // Expect the sink_wants to specify a scaled frame. | 1124 // Expect the sink_wants to specify a scaled frame. |
| 1124 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 1125 ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
| 1125 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, 1000 * 1000); | 1126 EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
| 1127 static_cast<uint32_t>(1000 * 1000)); |
| 1126 | 1128 |
| 1127 int last_pixel_count = *video_source_.sink_wants().max_pixel_count; | 1129 int last_pixel_count = video_source_.sink_wants().pixel_count->max; |
| 1128 | 1130 |
| 1129 // Next frame is scaled | 1131 // Next frame is scaled. |
| 1130 video_source_.IncomingCapturedFrame( | 1132 video_source_.IncomingCapturedFrame( |
| 1131 CreateFrame(2, frame_width * 3 / 4, frame_height * 3 / 4)); | 1133 CreateFrame(2, frame_width * 3 / 4, frame_height * 3 / 4)); |
| 1132 | 1134 |
| 1133 // Expect to drop this frame, the wait should time out. | 1135 // Expect to drop this frame, the wait should time out. |
| 1134 sink_.ExpectDroppedFrame(); | 1136 sink_.ExpectDroppedFrame(); |
| 1135 | 1137 |
| 1136 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, last_pixel_count); | 1138 EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
| 1139 static_cast<uint32_t>(last_pixel_count)); |
| 1137 | 1140 |
| 1138 vie_encoder_->Stop(); | 1141 vie_encoder_->Stop(); |
| 1139 } | 1142 } |
| 1140 | 1143 |
| 1141 TEST_F(ViEEncoderTest, NrOfDroppedFramesLimited) { | 1144 TEST_F(ViEEncoderTest, NrOfDroppedFramesLimited) { |
| 1142 // 1kbps. This can never be achieved. | 1145 // 1kbps. This can never be achieved. |
| 1143 vie_encoder_->OnBitrateUpdated(1000, 0, 0); | 1146 vie_encoder_->OnBitrateUpdated(1000, 0, 0); |
| 1144 int frame_width = 640; | 1147 int frame_width = 640; |
| 1145 int frame_height = 360; | 1148 int frame_height = 360; |
| 1146 | 1149 |
| 1147 // We expect the n initial frames to get dropped. | 1150 // We expect the n initial frames to get dropped. |
| 1148 int i; | 1151 int i; |
| 1149 for (i = 1; i <= kMaxInitialFramedrop; ++i) { | 1152 for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
| 1150 video_source_.IncomingCapturedFrame( | 1153 video_source_.IncomingCapturedFrame( |
| 1151 CreateFrame(i, frame_width, frame_height)); | 1154 CreateFrame(i, frame_width, frame_height)); |
| 1152 sink_.ExpectDroppedFrame(); | 1155 sink_.ExpectDroppedFrame(); |
| 1153 } | 1156 } |
| 1154 // The n+1th frame should not be dropped, even though it's size is too large. | 1157 // The n+1th frame should not be dropped, even though it's size is too large. |
| 1155 video_source_.IncomingCapturedFrame( | 1158 video_source_.IncomingCapturedFrame( |
| 1156 CreateFrame(i, frame_width, frame_height)); | 1159 CreateFrame(i, frame_width, frame_height)); |
| 1157 sink_.WaitForEncodedFrame(i); | 1160 sink_.WaitForEncodedFrame(i); |
| 1158 | 1161 |
| 1159 // Expect the sink_wants to specify a scaled frame. | 1162 // Expect the sink_wants to specify a scaled frame. |
| 1160 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 1163 ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
| 1161 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, 1000 * 1000); | 1164 EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
| 1165 static_cast<uint32_t>(1000 * 1000)); |
| 1162 | 1166 |
| 1163 vie_encoder_->Stop(); | 1167 vie_encoder_->Stop(); |
| 1164 } | 1168 } |
| 1165 | 1169 |
| 1166 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { | 1170 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { |
| 1167 int frame_width = 640; | 1171 int frame_width = 640; |
| 1168 int frame_height = 360; | 1172 int frame_height = 360; |
| 1169 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1173 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 1170 | 1174 |
| 1171 // Set degradation preference. | 1175 // Set degradation preference. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 | 1225 |
| 1222 // Trigger CPU normal use, return to original resoluton; | 1226 // Trigger CPU normal use, return to original resoluton; |
| 1223 vie_encoder_->TriggerCpuNormalUsage(); | 1227 vie_encoder_->TriggerCpuNormalUsage(); |
| 1224 video_source_.IncomingCapturedFrame( | 1228 video_source_.IncomingCapturedFrame( |
| 1225 CreateFrame(3, kFrameWidth, kFrameHeight)); | 1229 CreateFrame(3, kFrameWidth, kFrameHeight)); |
| 1226 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1230 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 1227 | 1231 |
| 1228 vie_encoder_->Stop(); | 1232 vie_encoder_->Stop(); |
| 1229 } | 1233 } |
| 1230 } // namespace webrtc | 1234 } // namespace webrtc |
| OLD | NEW |