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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 TEST_F(ViEEncoderTest, | 578 TEST_F(ViEEncoderTest, |
579 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { | 579 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { |
580 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 580 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
581 | 581 |
582 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | 582 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
583 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); | 583 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
584 | 584 |
585 int frame_width = 1280; | 585 int frame_width = 1280; |
586 int frame_height = 720; | 586 int frame_height = 720; |
587 | 587 |
| 588 video_source_.IncomingCapturedFrame( |
| 589 CreateFrame(1, frame_width, frame_height)); |
| 590 sink_.WaitForEncodedFrame(1); |
588 // Trigger CPU overuse. | 591 // Trigger CPU overuse. |
589 vie_encoder_->TriggerCpuOveruse(); | 592 vie_encoder_->TriggerCpuOveruse(); |
590 | 593 |
591 video_source_.IncomingCapturedFrame( | 594 video_source_.IncomingCapturedFrame( |
592 CreateFrame(1, frame_width, frame_height)); | 595 CreateFrame(2, frame_width, frame_height)); |
593 sink_.WaitForEncodedFrame(1); | 596 sink_.WaitForEncodedFrame(2); |
594 EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( | 597 EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( |
595 std::numeric_limits<int>::max()), | 598 std::numeric_limits<int>::max()), |
596 frame_width * frame_height); | 599 frame_width * frame_height); |
597 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); | 600 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
598 | 601 |
599 // Set new source. | 602 // Set new source. |
600 test::FrameForwarder new_video_source; | 603 test::FrameForwarder new_video_source; |
601 vie_encoder_->SetSource( | 604 vie_encoder_->SetSource( |
602 &new_video_source, | 605 &new_video_source, |
603 VideoSendStream::DegradationPreference::kMaintainResolution); | 606 VideoSendStream::DegradationPreference::kMaintainResolution); |
604 | 607 |
605 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | 608 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
606 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); | 609 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); |
607 | 610 |
608 new_video_source.IncomingCapturedFrame( | 611 new_video_source.IncomingCapturedFrame( |
609 CreateFrame(2, frame_width, frame_height)); | 612 CreateFrame(3, frame_width, frame_height)); |
610 sink_.WaitForEncodedFrame(2); | 613 sink_.WaitForEncodedFrame(3); |
611 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | 614 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
612 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); | 615 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); |
613 | 616 |
614 // Calling SetSource with resolution scaling enabled apply the old SinkWants. | 617 // Calling SetSource with resolution scaling enabled apply the old SinkWants. |
615 vie_encoder_->SetSource(&new_video_source, | 618 vie_encoder_->SetSource(&new_video_source, |
616 VideoSendStream::DegradationPreference::kBalanced); | 619 VideoSendStream::DegradationPreference::kBalanced); |
617 EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or( | 620 EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or( |
618 std::numeric_limits<int>::max()), | 621 std::numeric_limits<int>::max()), |
619 frame_width * frame_height); | 622 frame_width * frame_height); |
620 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); | 623 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 870 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
868 const int kTargetBitrateBps = 100000; | 871 const int kTargetBitrateBps = 100000; |
869 int frame_width = 1280; | 872 int frame_width = 1280; |
870 int frame_height = 720; | 873 int frame_height = 720; |
871 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 874 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
872 | 875 |
873 // Expect no scaling to begin with | 876 // Expect no scaling to begin with |
874 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | 877 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
875 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); | 878 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
876 | 879 |
877 // Trigger scale down | |
878 vie_encoder_->TriggerQualityLow(); | |
879 video_source_.IncomingCapturedFrame( | 880 video_source_.IncomingCapturedFrame( |
880 CreateFrame(1, frame_width, frame_height)); | 881 CreateFrame(1, frame_width, frame_height)); |
881 sink_.WaitForEncodedFrame(1); | 882 sink_.WaitForEncodedFrame(1); |
882 | 883 |
| 884 // Trigger scale down |
| 885 vie_encoder_->TriggerQualityLow(); |
| 886 |
| 887 video_source_.IncomingCapturedFrame( |
| 888 CreateFrame(2, frame_width, frame_height)); |
| 889 sink_.WaitForEncodedFrame(2); |
| 890 |
883 // Expect a scale down. | 891 // Expect a scale down. |
884 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 892 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
885 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, | 893 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, |
886 frame_width * frame_height); | 894 frame_width * frame_height); |
887 | 895 |
888 // Set adaptation disabled. | 896 // Set adaptation disabled. |
889 test::FrameForwarder new_video_source; | 897 test::FrameForwarder new_video_source; |
890 vie_encoder_->SetSource( | 898 vie_encoder_->SetSource( |
891 &new_video_source, | 899 &new_video_source, |
892 VideoSendStream::DegradationPreference::kMaintainResolution); | 900 VideoSendStream::DegradationPreference::kMaintainResolution); |
893 | 901 |
894 // Trigger scale down | 902 // Trigger scale down |
895 vie_encoder_->TriggerQualityLow(); | 903 vie_encoder_->TriggerQualityLow(); |
896 new_video_source.IncomingCapturedFrame( | 904 new_video_source.IncomingCapturedFrame( |
897 CreateFrame(2, frame_width, frame_height)); | 905 CreateFrame(3, frame_width, frame_height)); |
898 sink_.WaitForEncodedFrame(2); | 906 sink_.WaitForEncodedFrame(3); |
899 | 907 |
900 // Expect no scaling | 908 // Expect no scaling |
901 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | 909 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
902 | 910 |
903 // Trigger scale up | 911 // Trigger scale up |
904 vie_encoder_->TriggerQualityHigh(); | 912 vie_encoder_->TriggerQualityHigh(); |
905 new_video_source.IncomingCapturedFrame( | 913 new_video_source.IncomingCapturedFrame( |
906 CreateFrame(3, frame_width, frame_height)); | 914 CreateFrame(4, frame_width, frame_height)); |
907 sink_.WaitForEncodedFrame(3); | 915 sink_.WaitForEncodedFrame(4); |
908 | 916 |
909 // Expect nothing to change, still no scaling | 917 // Expect nothing to change, still no scaling |
910 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | 918 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
911 | 919 |
912 vie_encoder_->Stop(); | 920 vie_encoder_->Stop(); |
913 } | 921 } |
914 | 922 |
| 923 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { |
| 924 const int kTargetBitrateBps = 100000; |
| 925 int frame_width = 1280; |
| 926 int frame_height = 720; |
| 927 // from vie_encoder.cc |
| 928 const int kMinPixelsPerFrame = 120 * 90; |
| 929 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 930 |
| 931 for (size_t i = 1; i <= 10; i++) { |
| 932 video_source_.IncomingCapturedFrame( |
| 933 CreateFrame(i, frame_width, frame_height)); |
| 934 sink_.WaitForEncodedFrame(i); |
| 935 // Trigger scale down |
| 936 vie_encoder_->TriggerQualityLow(); |
| 937 EXPECT_GE(*video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); |
| 938 } |
| 939 |
| 940 vie_encoder_->Stop(); |
| 941 } |
| 942 |
915 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { | 943 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { |
916 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 944 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
917 | 945 |
918 int frame_width = 640; | 946 int frame_width = 640; |
919 int frame_height = 360; | 947 int frame_height = 360; |
920 | 948 |
921 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 949 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
922 video_source_.IncomingCapturedFrame( | 950 video_source_.IncomingCapturedFrame( |
923 CreateFrame(i, frame_width, frame_height)); | 951 CreateFrame(i, frame_width, frame_height)); |
924 sink_.WaitForEncodedFrame(i); | 952 sink_.WaitForEncodedFrame(i); |
(...skipping 11 matching lines...) Expand all Loading... |
936 vie_encoder_->Stop(); | 964 vie_encoder_->Stop(); |
937 | 965 |
938 stats_proxy_.reset(); | 966 stats_proxy_.reset(); |
939 EXPECT_EQ(1, | 967 EXPECT_EQ(1, |
940 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 968 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
941 EXPECT_EQ( | 969 EXPECT_EQ( |
942 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); | 970 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
943 } | 971 } |
944 | 972 |
945 } // namespace webrtc | 973 } // namespace webrtc |
OLD | NEW |