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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 stream.temporal_layer_thresholds_bps.resize(num_temporal_layers_ - 1); | 124 stream.temporal_layer_thresholds_bps.resize(num_temporal_layers_ - 1); |
125 } | 125 } |
126 return streams; | 126 return streams; |
127 } | 127 } |
128 const size_t num_temporal_layers_; | 128 const size_t num_temporal_layers_; |
129 }; | 129 }; |
130 | 130 |
131 class AdaptingFrameForwarder : public test::FrameForwarder { | 131 class AdaptingFrameForwarder : public test::FrameForwarder { |
132 public: | 132 public: |
133 AdaptingFrameForwarder() : adaptation_enabled_(false) {} | 133 AdaptingFrameForwarder() : adaptation_enabled_(false) {} |
134 virtual ~AdaptingFrameForwarder() {} | 134 ~AdaptingFrameForwarder() override {} |
135 | 135 |
136 void set_adaptation_enabled(bool enabled) { | 136 void set_adaptation_enabled(bool enabled) { |
137 rtc::CritScope cs(&crit_); | 137 rtc::CritScope cs(&crit_); |
138 adaptation_enabled_ = enabled; | 138 adaptation_enabled_ = enabled; |
139 } | 139 } |
140 | 140 |
141 bool adaption_enabled() { | 141 bool adaption_enabled() const { |
142 rtc::CritScope cs(&crit_); | 142 rtc::CritScope cs(&crit_); |
143 return adaptation_enabled_; | 143 return adaptation_enabled_; |
144 } | 144 } |
145 | 145 |
146 void IncomingCapturedFrame(const VideoFrame& video_frame) override { | 146 void IncomingCapturedFrame(const VideoFrame& video_frame) override { |
147 int cropped_width = 0; | 147 int cropped_width = 0; |
148 int cropped_height = 0; | 148 int cropped_height = 0; |
149 int out_width = 0; | 149 int out_width = 0; |
150 int out_height = 0; | 150 int out_height = 0; |
151 if (adaption_enabled()) { | 151 if (adaption_enabled()) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 frame.set_timestamp_us(ntp_time_ms * 1000); | 283 frame.set_timestamp_us(ntp_time_ms * 1000); |
284 return frame; | 284 return frame; |
285 } | 285 } |
286 | 286 |
287 class TestEncoder : public test::FakeEncoder { | 287 class TestEncoder : public test::FakeEncoder { |
288 public: | 288 public: |
289 TestEncoder() | 289 TestEncoder() |
290 : FakeEncoder(Clock::GetRealTimeClock()), | 290 : FakeEncoder(Clock::GetRealTimeClock()), |
291 continue_encode_event_(false, false) {} | 291 continue_encode_event_(false, false) {} |
292 | 292 |
293 VideoCodec codec_config() { | 293 VideoCodec codec_config() const { |
294 rtc::CritScope lock(&crit_sect_); | 294 rtc::CritScope lock(&crit_sect_); |
295 return config_; | 295 return config_; |
296 } | 296 } |
297 | 297 |
298 void BlockNextEncode() { | 298 void BlockNextEncode() { |
299 rtc::CritScope lock(&local_crit_sect_); | 299 rtc::CritScope lock(&local_crit_sect_); |
300 block_next_encode_ = true; | 300 block_next_encode_ = true; |
301 } | 301 } |
302 | 302 |
303 VideoEncoder::ScalingSettings GetScalingSettings() const override { | 303 VideoEncoder::ScalingSettings GetScalingSettings() const override { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 | 424 |
425 bool WaitForFrame(int64_t timeout_ms) { | 425 bool WaitForFrame(int64_t timeout_ms) { |
426 return encoded_frame_event_.Wait(timeout_ms); | 426 return encoded_frame_event_.Wait(timeout_ms); |
427 } | 427 } |
428 | 428 |
429 void SetExpectNoFrames() { | 429 void SetExpectNoFrames() { |
430 rtc::CritScope lock(&crit_); | 430 rtc::CritScope lock(&crit_); |
431 expect_frames_ = false; | 431 expect_frames_ = false; |
432 } | 432 } |
433 | 433 |
434 int number_of_reconfigurations() { | 434 int number_of_reconfigurations() const { |
435 rtc::CritScope lock(&crit_); | 435 rtc::CritScope lock(&crit_); |
436 return number_of_reconfigurations_; | 436 return number_of_reconfigurations_; |
437 } | 437 } |
438 | 438 |
439 int last_min_transmit_bitrate() { | 439 int last_min_transmit_bitrate() const { |
440 rtc::CritScope lock(&crit_); | 440 rtc::CritScope lock(&crit_); |
441 return min_transmit_bitrate_bps_; | 441 return min_transmit_bitrate_bps_; |
442 } | 442 } |
443 | 443 |
444 private: | 444 private: |
445 Result OnEncodedImage( | 445 Result OnEncodedImage( |
446 const EncodedImage& encoded_image, | 446 const EncodedImage& encoded_image, |
447 const CodecSpecificInfo* codec_specific_info, | 447 const CodecSpecificInfo* codec_specific_info, |
448 const RTPFragmentationHeader* fragmentation) override { | 448 const RTPFragmentationHeader* fragmentation) override { |
449 rtc::CritScope lock(&crit_); | 449 rtc::CritScope lock(&crit_); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 &new_video_source, | 867 &new_video_source, |
868 VideoSendStream::DegradationPreference::kMaintainResolution); | 868 VideoSendStream::DegradationPreference::kMaintainResolution); |
869 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 869 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
870 EXPECT_EQ(std::numeric_limits<int>::max(), | 870 EXPECT_EQ(std::numeric_limits<int>::max(), |
871 new_video_source.sink_wants().max_pixel_count); | 871 new_video_source.sink_wants().max_pixel_count); |
872 EXPECT_TRUE(new_video_source.sink_wants().max_framerate_fps); | 872 EXPECT_TRUE(new_video_source.sink_wants().max_framerate_fps); |
873 | 873 |
874 vie_encoder_->Stop(); | 874 vie_encoder_->Stop(); |
875 } | 875 } |
876 | 876 |
877 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) { | 877 TEST_F(ViEEncoderTest, StatsTracksQualityAdaptationStats) { |
878 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 878 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
879 | 879 |
880 int frame_width = 1280; | 880 const int kWidth = 1280; |
881 int frame_height = 720; | 881 const int kHeight = 720; |
882 | 882 |
883 video_source_.IncomingCapturedFrame( | 883 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
884 CreateFrame(1, frame_width, frame_height)); | 884 sink_.WaitForEncodedFrame(1); |
| 885 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 886 EXPECT_FALSE(stats.bw_limited_resolution); |
| 887 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
| 888 |
| 889 // Trigger adapt down. |
| 890 vie_encoder_->TriggerQualityLow(); |
| 891 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 892 sink_.WaitForEncodedFrame(2); |
| 893 |
| 894 stats = stats_proxy_->GetStats(); |
| 895 EXPECT_TRUE(stats.bw_limited_resolution); |
| 896 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
| 897 |
| 898 // Trigger adapt up. |
| 899 vie_encoder_->TriggerQualityHigh(); |
| 900 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 901 sink_.WaitForEncodedFrame(3); |
| 902 |
| 903 stats = stats_proxy_->GetStats(); |
| 904 EXPECT_FALSE(stats.bw_limited_resolution); |
| 905 EXPECT_EQ(2, stats.number_of_quality_adapt_changes); |
| 906 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
| 907 |
| 908 vie_encoder_->Stop(); |
| 909 } |
| 910 |
| 911 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStats) { |
| 912 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 913 |
| 914 const int kWidth = 1280; |
| 915 const int kHeight = 720; |
| 916 |
| 917 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
885 sink_.WaitForEncodedFrame(1); | 918 sink_.WaitForEncodedFrame(1); |
886 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 919 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
887 EXPECT_FALSE(stats.cpu_limited_resolution); | 920 EXPECT_FALSE(stats.cpu_limited_resolution); |
888 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 921 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
889 | 922 |
890 // Trigger CPU overuse. | 923 // Trigger CPU overuse. |
891 vie_encoder_->TriggerCpuOveruse(); | 924 vie_encoder_->TriggerCpuOveruse(); |
892 video_source_.IncomingCapturedFrame( | 925 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
893 CreateFrame(2, frame_width, frame_height)); | |
894 sink_.WaitForEncodedFrame(2); | 926 sink_.WaitForEncodedFrame(2); |
895 | 927 |
896 stats = stats_proxy_->GetStats(); | 928 stats = stats_proxy_->GetStats(); |
897 EXPECT_TRUE(stats.cpu_limited_resolution); | 929 EXPECT_TRUE(stats.cpu_limited_resolution); |
898 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 930 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
899 | 931 |
900 // Trigger CPU normal use. | 932 // Trigger CPU normal use. |
901 vie_encoder_->TriggerCpuNormalUsage(); | 933 vie_encoder_->TriggerCpuNormalUsage(); |
902 video_source_.IncomingCapturedFrame( | 934 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
903 CreateFrame(3, frame_width, frame_height)); | |
904 sink_.WaitForEncodedFrame(3); | 935 sink_.WaitForEncodedFrame(3); |
905 | 936 |
906 stats = stats_proxy_->GetStats(); | 937 stats = stats_proxy_->GetStats(); |
907 EXPECT_FALSE(stats.cpu_limited_resolution); | 938 EXPECT_FALSE(stats.cpu_limited_resolution); |
908 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 939 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 940 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
909 | 941 |
910 vie_encoder_->Stop(); | 942 vie_encoder_->Stop(); |
911 } | 943 } |
912 | 944 |
913 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { | 945 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { |
914 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 946 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
915 | 947 |
916 int frame_width = 1280; | 948 const int kWidth = 1280; |
917 int frame_height = 720; | 949 const int kHeight = 720; |
918 video_source_.IncomingCapturedFrame( | 950 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
919 CreateFrame(1, frame_width, frame_height)); | |
920 sink_.WaitForEncodedFrame(1); | 951 sink_.WaitForEncodedFrame(1); |
921 | |
922 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 952 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
923 EXPECT_FALSE(stats.cpu_limited_resolution); | 953 EXPECT_FALSE(stats.cpu_limited_resolution); |
924 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 954 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
925 | 955 |
| 956 // Trigger CPU overuse. |
926 vie_encoder_->TriggerCpuOveruse(); | 957 vie_encoder_->TriggerCpuOveruse(); |
927 | 958 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
928 video_source_.IncomingCapturedFrame( | |
929 CreateFrame(2, frame_width, frame_height)); | |
930 sink_.WaitForEncodedFrame(2); | 959 sink_.WaitForEncodedFrame(2); |
931 stats = stats_proxy_->GetStats(); | 960 stats = stats_proxy_->GetStats(); |
932 EXPECT_TRUE(stats.cpu_limited_resolution); | 961 EXPECT_TRUE(stats.cpu_limited_resolution); |
933 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 962 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
934 | 963 |
935 // Set new source with adaptation still enabled. | 964 // Set new source with adaptation still enabled. |
936 test::FrameForwarder new_video_source; | 965 test::FrameForwarder new_video_source; |
937 vie_encoder_->SetSource( | 966 vie_encoder_->SetSource( |
938 &new_video_source, | 967 &new_video_source, |
939 VideoSendStream::DegradationPreference::kMaintainFramerate); | 968 VideoSendStream::DegradationPreference::kMaintainFramerate); |
940 | 969 |
941 new_video_source.IncomingCapturedFrame( | 970 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
942 CreateFrame(3, frame_width, frame_height)); | |
943 sink_.WaitForEncodedFrame(3); | 971 sink_.WaitForEncodedFrame(3); |
944 stats = stats_proxy_->GetStats(); | 972 stats = stats_proxy_->GetStats(); |
945 EXPECT_TRUE(stats.cpu_limited_resolution); | 973 EXPECT_TRUE(stats.cpu_limited_resolution); |
946 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 974 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
947 | 975 |
948 // Set adaptation disabled. | 976 // Set adaptation disabled. |
949 vie_encoder_->SetSource( | 977 vie_encoder_->SetSource( |
950 &new_video_source, | 978 &new_video_source, |
951 VideoSendStream::DegradationPreference::kDegradationDisabled); | 979 VideoSendStream::DegradationPreference::kDegradationDisabled); |
952 | 980 |
953 new_video_source.IncomingCapturedFrame( | 981 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
954 CreateFrame(4, frame_width, frame_height)); | |
955 sink_.WaitForEncodedFrame(4); | 982 sink_.WaitForEncodedFrame(4); |
956 stats = stats_proxy_->GetStats(); | 983 stats = stats_proxy_->GetStats(); |
957 EXPECT_FALSE(stats.cpu_limited_resolution); | 984 EXPECT_FALSE(stats.cpu_limited_resolution); |
958 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 985 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
959 | 986 |
960 // Set adaptation back to enabled. | 987 // Set adaptation back to enabled. |
961 vie_encoder_->SetSource( | 988 vie_encoder_->SetSource( |
962 &new_video_source, | 989 &new_video_source, |
963 VideoSendStream::DegradationPreference::kMaintainFramerate); | 990 VideoSendStream::DegradationPreference::kMaintainFramerate); |
964 | 991 |
965 new_video_source.IncomingCapturedFrame( | 992 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
966 CreateFrame(5, frame_width, frame_height)); | |
967 sink_.WaitForEncodedFrame(5); | 993 sink_.WaitForEncodedFrame(5); |
968 stats = stats_proxy_->GetStats(); | 994 stats = stats_proxy_->GetStats(); |
969 EXPECT_TRUE(stats.cpu_limited_resolution); | 995 EXPECT_TRUE(stats.cpu_limited_resolution); |
970 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 996 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
971 | 997 |
| 998 // Trigger CPU normal use. |
972 vie_encoder_->TriggerCpuNormalUsage(); | 999 vie_encoder_->TriggerCpuNormalUsage(); |
973 | 1000 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
974 new_video_source.IncomingCapturedFrame( | |
975 CreateFrame(6, frame_width, frame_height)); | |
976 sink_.WaitForEncodedFrame(6); | 1001 sink_.WaitForEncodedFrame(6); |
977 stats = stats_proxy_->GetStats(); | 1002 stats = stats_proxy_->GetStats(); |
978 EXPECT_FALSE(stats.cpu_limited_resolution); | 1003 EXPECT_FALSE(stats.cpu_limited_resolution); |
979 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1004 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
980 | 1005 |
981 vie_encoder_->Stop(); | 1006 vie_encoder_->Stop(); |
982 } | 1007 } |
983 | 1008 |
984 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { | 1009 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { |
985 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1010 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
986 | 1011 |
987 int frame_width = 1280; | 1012 const int kWidth = 1280; |
988 int frame_height = 720; | 1013 const int kHeight = 720; |
989 video_source_.IncomingCapturedFrame( | 1014 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
990 CreateFrame(1, frame_width, frame_height)); | |
991 sink_.WaitForEncodedFrame(1); | 1015 sink_.WaitForEncodedFrame(1); |
992 | |
993 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1016 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
994 EXPECT_FALSE(stats.cpu_limited_resolution); | 1017 EXPECT_FALSE(stats.cpu_limited_resolution); |
995 EXPECT_FALSE(stats.bw_limited_resolution); | 1018 EXPECT_FALSE(stats.bw_limited_resolution); |
996 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1019 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
997 | 1020 |
998 // Set new source with adaptation still enabled. | 1021 // Set new source with adaptation still enabled. |
999 test::FrameForwarder new_video_source; | 1022 test::FrameForwarder new_video_source; |
1000 vie_encoder_->SetSource(&new_video_source, | 1023 vie_encoder_->SetSource(&new_video_source, |
1001 VideoSendStream::DegradationPreference::kBalanced); | 1024 VideoSendStream::DegradationPreference::kBalanced); |
1002 | 1025 |
1003 new_video_source.IncomingCapturedFrame( | 1026 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1004 CreateFrame(2, frame_width, frame_height)); | |
1005 sink_.WaitForEncodedFrame(2); | 1027 sink_.WaitForEncodedFrame(2); |
1006 stats = stats_proxy_->GetStats(); | 1028 stats = stats_proxy_->GetStats(); |
1007 EXPECT_FALSE(stats.cpu_limited_resolution); | 1029 EXPECT_FALSE(stats.cpu_limited_resolution); |
1008 EXPECT_FALSE(stats.bw_limited_resolution); | 1030 EXPECT_FALSE(stats.bw_limited_resolution); |
1009 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1031 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1010 | 1032 |
| 1033 // Trigger adapt down. |
1011 vie_encoder_->TriggerQualityLow(); | 1034 vie_encoder_->TriggerQualityLow(); |
1012 | 1035 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1013 new_video_source.IncomingCapturedFrame( | |
1014 CreateFrame(3, frame_width, frame_height)); | |
1015 sink_.WaitForEncodedFrame(3); | 1036 sink_.WaitForEncodedFrame(3); |
1016 stats = stats_proxy_->GetStats(); | 1037 stats = stats_proxy_->GetStats(); |
1017 EXPECT_FALSE(stats.cpu_limited_resolution); | 1038 EXPECT_FALSE(stats.cpu_limited_resolution); |
1018 EXPECT_TRUE(stats.bw_limited_resolution); | 1039 EXPECT_TRUE(stats.bw_limited_resolution); |
| 1040 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1019 | 1041 |
| 1042 // Set new source with adaptation still enabled. |
1020 vie_encoder_->SetSource(&new_video_source, | 1043 vie_encoder_->SetSource(&new_video_source, |
1021 VideoSendStream::DegradationPreference::kBalanced); | 1044 VideoSendStream::DegradationPreference::kBalanced); |
1022 | 1045 |
1023 new_video_source.IncomingCapturedFrame( | 1046 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1024 CreateFrame(4, frame_width, frame_height)); | |
1025 sink_.WaitForEncodedFrame(4); | 1047 sink_.WaitForEncodedFrame(4); |
1026 stats = stats_proxy_->GetStats(); | 1048 stats = stats_proxy_->GetStats(); |
1027 EXPECT_FALSE(stats.cpu_limited_resolution); | 1049 EXPECT_FALSE(stats.cpu_limited_resolution); |
1028 EXPECT_TRUE(stats.bw_limited_resolution); | 1050 EXPECT_TRUE(stats.bw_limited_resolution); |
| 1051 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1029 | 1052 |
1030 // Set adaptation disabled. | 1053 // Set adaptation disabled. |
1031 vie_encoder_->SetSource( | 1054 vie_encoder_->SetSource( |
1032 &new_video_source, | 1055 &new_video_source, |
1033 VideoSendStream::DegradationPreference::kMaintainResolution); | 1056 VideoSendStream::DegradationPreference::kMaintainResolution); |
1034 | 1057 |
1035 new_video_source.IncomingCapturedFrame( | 1058 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1036 CreateFrame(5, frame_width, frame_height)); | |
1037 sink_.WaitForEncodedFrame(5); | 1059 sink_.WaitForEncodedFrame(5); |
1038 stats = stats_proxy_->GetStats(); | 1060 stats = stats_proxy_->GetStats(); |
1039 EXPECT_FALSE(stats.cpu_limited_resolution); | 1061 EXPECT_FALSE(stats.cpu_limited_resolution); |
1040 EXPECT_FALSE(stats.bw_limited_resolution); | 1062 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1063 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
| 1064 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1041 | 1065 |
1042 vie_encoder_->Stop(); | 1066 vie_encoder_->Stop(); |
1043 } | 1067 } |
1044 | 1068 |
1045 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { | 1069 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { |
1046 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1070 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1047 | 1071 |
1048 const int kWidth = 1280; | 1072 const int kWidth = 1280; |
1049 const int kHeight = 720; | 1073 const int kHeight = 720; |
1050 video_source_.set_adaptation_enabled(true); | 1074 video_source_.set_adaptation_enabled(true); |
(...skipping 30 matching lines...) Expand all Loading... |
1081 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1105 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1082 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1106 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1083 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1107 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1084 | 1108 |
1085 vie_encoder_->Stop(); | 1109 vie_encoder_->Stop(); |
1086 } | 1110 } |
1087 | 1111 |
1088 TEST_F(ViEEncoderTest, StatsTracksAdaptationStatsWhenSwitchingSource) { | 1112 TEST_F(ViEEncoderTest, StatsTracksAdaptationStatsWhenSwitchingSource) { |
1089 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1113 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1090 | 1114 |
1091 int frame_width = 1280; | 1115 int kWidth = 1280; |
1092 int frame_height = 720; | 1116 int kHeight = 720; |
1093 int sequence = 1; | 1117 int sequence = 1; |
1094 | 1118 |
1095 video_source_.IncomingCapturedFrame( | 1119 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1096 CreateFrame(sequence, frame_width, frame_height)); | |
1097 sink_.WaitForEncodedFrame(sequence++); | 1120 sink_.WaitForEncodedFrame(sequence++); |
1098 | 1121 |
1099 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1122 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1100 EXPECT_FALSE(stats.cpu_limited_resolution); | 1123 EXPECT_FALSE(stats.cpu_limited_resolution); |
1101 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1124 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1102 | 1125 |
1103 // Trigger CPU overuse again, should now adapt down. | 1126 // Trigger CPU overuse again, should now adapt down. |
1104 vie_encoder_->TriggerCpuOveruse(); | 1127 vie_encoder_->TriggerCpuOveruse(); |
1105 video_source_.IncomingCapturedFrame( | 1128 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1106 CreateFrame(sequence, frame_width, frame_height)); | |
1107 sink_.WaitForEncodedFrame(sequence++); | 1129 sink_.WaitForEncodedFrame(sequence++); |
1108 | 1130 |
1109 stats = stats_proxy_->GetStats(); | 1131 stats = stats_proxy_->GetStats(); |
1110 EXPECT_TRUE(stats.cpu_limited_resolution); | 1132 EXPECT_TRUE(stats.cpu_limited_resolution); |
1111 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1133 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1112 | 1134 |
1113 // Set new source with adaptation still enabled. | 1135 // Set new source with adaptation still enabled. |
1114 test::FrameForwarder new_video_source; | 1136 test::FrameForwarder new_video_source; |
1115 vie_encoder_->SetSource( | 1137 vie_encoder_->SetSource( |
1116 &new_video_source, | 1138 &new_video_source, |
1117 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1139 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1118 | 1140 |
1119 new_video_source.IncomingCapturedFrame( | 1141 new_video_source.IncomingCapturedFrame( |
1120 CreateFrame(sequence, frame_width, frame_height)); | 1142 CreateFrame(sequence, kWidth, kHeight)); |
1121 sink_.WaitForEncodedFrame(sequence++); | 1143 sink_.WaitForEncodedFrame(sequence++); |
1122 stats = stats_proxy_->GetStats(); | 1144 stats = stats_proxy_->GetStats(); |
1123 EXPECT_TRUE(stats.cpu_limited_resolution); | 1145 EXPECT_TRUE(stats.cpu_limited_resolution); |
1124 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1146 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1125 | 1147 |
1126 // Set cpu adaptation by frame dropping. | 1148 // Set cpu adaptation by frame dropping. |
1127 vie_encoder_->SetSource( | 1149 vie_encoder_->SetSource( |
1128 &new_video_source, | 1150 &new_video_source, |
1129 VideoSendStream::DegradationPreference::kMaintainResolution); | 1151 VideoSendStream::DegradationPreference::kMaintainResolution); |
1130 new_video_source.IncomingCapturedFrame( | 1152 new_video_source.IncomingCapturedFrame( |
1131 CreateFrame(sequence, frame_width, frame_height)); | 1153 CreateFrame(sequence, kWidth, kHeight)); |
1132 sink_.WaitForEncodedFrame(sequence++); | 1154 sink_.WaitForEncodedFrame(sequence++); |
1133 stats = stats_proxy_->GetStats(); | 1155 stats = stats_proxy_->GetStats(); |
1134 // Not adapted at first. | 1156 // Not adapted at first. |
1135 EXPECT_FALSE(stats.cpu_limited_resolution); | 1157 EXPECT_FALSE(stats.cpu_limited_resolution); |
1136 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1158 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1137 | 1159 |
1138 // Force an input frame rate to be available, or the adaptation call won't | 1160 // Force an input frame rate to be available, or the adaptation call won't |
1139 // know what framerate to adapt form. | 1161 // know what framerate to adapt form. |
1140 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); | 1162 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); |
1141 mock_stats.input_frame_rate = 30; | 1163 mock_stats.input_frame_rate = 30; |
1142 stats_proxy_->SetMockStats(mock_stats); | 1164 stats_proxy_->SetMockStats(mock_stats); |
1143 vie_encoder_->TriggerCpuOveruse(); | 1165 vie_encoder_->TriggerCpuOveruse(); |
1144 stats_proxy_->ResetMockStats(); | 1166 stats_proxy_->ResetMockStats(); |
1145 | 1167 |
1146 new_video_source.IncomingCapturedFrame( | 1168 new_video_source.IncomingCapturedFrame( |
1147 CreateFrame(sequence, frame_width, frame_height)); | 1169 CreateFrame(sequence, kWidth, kHeight)); |
1148 sink_.WaitForEncodedFrame(sequence++); | 1170 sink_.WaitForEncodedFrame(sequence++); |
1149 | 1171 |
1150 // Framerate now adapted. | 1172 // Framerate now adapted. |
1151 stats = stats_proxy_->GetStats(); | 1173 stats = stats_proxy_->GetStats(); |
1152 EXPECT_TRUE(stats.cpu_limited_resolution); | 1174 EXPECT_TRUE(stats.cpu_limited_resolution); |
1153 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1175 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1154 | 1176 |
1155 // Disable CPU adaptation. | 1177 // Disable CPU adaptation. |
1156 vie_encoder_->SetSource( | 1178 vie_encoder_->SetSource( |
1157 &new_video_source, | 1179 &new_video_source, |
1158 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1180 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1159 new_video_source.IncomingCapturedFrame( | 1181 new_video_source.IncomingCapturedFrame( |
1160 CreateFrame(sequence, frame_width, frame_height)); | 1182 CreateFrame(sequence, kWidth, kHeight)); |
1161 sink_.WaitForEncodedFrame(sequence++); | 1183 sink_.WaitForEncodedFrame(sequence++); |
1162 | 1184 |
1163 stats = stats_proxy_->GetStats(); | 1185 stats = stats_proxy_->GetStats(); |
1164 EXPECT_FALSE(stats.cpu_limited_resolution); | 1186 EXPECT_FALSE(stats.cpu_limited_resolution); |
1165 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1187 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1166 | 1188 |
1167 // Try to trigger overuse. Should not succeed. | 1189 // Try to trigger overuse. Should not succeed. |
1168 stats_proxy_->SetMockStats(mock_stats); | 1190 stats_proxy_->SetMockStats(mock_stats); |
1169 vie_encoder_->TriggerCpuOveruse(); | 1191 vie_encoder_->TriggerCpuOveruse(); |
1170 stats_proxy_->ResetMockStats(); | 1192 stats_proxy_->ResetMockStats(); |
1171 | 1193 |
1172 stats = stats_proxy_->GetStats(); | 1194 stats = stats_proxy_->GetStats(); |
1173 EXPECT_FALSE(stats.cpu_limited_resolution); | 1195 EXPECT_FALSE(stats.cpu_limited_resolution); |
1174 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1196 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1175 | 1197 |
1176 // Switch back the source with resolution adaptation enabled. | 1198 // Switch back the source with resolution adaptation enabled. |
1177 vie_encoder_->SetSource( | 1199 vie_encoder_->SetSource( |
1178 &video_source_, | 1200 &video_source_, |
1179 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1201 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1180 video_source_.IncomingCapturedFrame( | 1202 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1181 CreateFrame(sequence, frame_width, frame_height)); | |
1182 sink_.WaitForEncodedFrame(sequence++); | 1203 sink_.WaitForEncodedFrame(sequence++); |
1183 stats = stats_proxy_->GetStats(); | 1204 stats = stats_proxy_->GetStats(); |
1184 EXPECT_TRUE(stats.cpu_limited_resolution); | 1205 EXPECT_TRUE(stats.cpu_limited_resolution); |
1185 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1206 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1186 | 1207 |
1187 // Trigger CPU normal usage. | 1208 // Trigger CPU normal usage. |
1188 vie_encoder_->TriggerCpuNormalUsage(); | 1209 vie_encoder_->TriggerCpuNormalUsage(); |
1189 video_source_.IncomingCapturedFrame( | 1210 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1190 CreateFrame(sequence, frame_width, frame_height)); | |
1191 sink_.WaitForEncodedFrame(sequence++); | 1211 sink_.WaitForEncodedFrame(sequence++); |
1192 stats = stats_proxy_->GetStats(); | 1212 stats = stats_proxy_->GetStats(); |
1193 EXPECT_FALSE(stats.cpu_limited_resolution); | 1213 EXPECT_FALSE(stats.cpu_limited_resolution); |
1194 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1214 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1195 | 1215 |
1196 // Back to the source with adaptation off, set it back to maintain-resolution. | 1216 // Back to the source with adaptation off, set it back to maintain-resolution. |
1197 vie_encoder_->SetSource( | 1217 vie_encoder_->SetSource( |
1198 &new_video_source, | 1218 &new_video_source, |
1199 VideoSendStream::DegradationPreference::kMaintainResolution); | 1219 VideoSendStream::DegradationPreference::kMaintainResolution); |
1200 new_video_source.IncomingCapturedFrame( | 1220 new_video_source.IncomingCapturedFrame( |
1201 CreateFrame(sequence, frame_width, frame_height)); | 1221 CreateFrame(sequence, kWidth, kHeight)); |
1202 sink_.WaitForEncodedFrame(sequence++); | 1222 sink_.WaitForEncodedFrame(sequence++); |
1203 stats = stats_proxy_->GetStats(); | 1223 stats = stats_proxy_->GetStats(); |
1204 // Disabled, since we previously switched the source too disabled. | 1224 // Disabled, since we previously switched the source too disabled. |
1205 EXPECT_FALSE(stats.cpu_limited_resolution); | 1225 EXPECT_FALSE(stats.cpu_limited_resolution); |
1206 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1226 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1207 | 1227 |
1208 // Trigger CPU normal usage. | 1228 // Trigger CPU normal usage. |
1209 vie_encoder_->TriggerCpuNormalUsage(); | 1229 vie_encoder_->TriggerCpuNormalUsage(); |
1210 new_video_source.IncomingCapturedFrame( | 1230 new_video_source.IncomingCapturedFrame( |
1211 CreateFrame(sequence, frame_width, frame_height)); | 1231 CreateFrame(sequence, kWidth, kHeight)); |
1212 sink_.WaitForEncodedFrame(sequence++); | 1232 sink_.WaitForEncodedFrame(sequence++); |
1213 stats = stats_proxy_->GetStats(); | 1233 stats = stats_proxy_->GetStats(); |
1214 EXPECT_FALSE(stats.cpu_limited_resolution); | 1234 EXPECT_FALSE(stats.cpu_limited_resolution); |
1215 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); | 1235 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); |
1216 | 1236 |
1217 vie_encoder_->Stop(); | 1237 vie_encoder_->Stop(); |
1218 } | 1238 } |
1219 | 1239 |
1220 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { | 1240 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { |
1221 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1241 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1222 | 1242 |
1223 video_source_.IncomingCapturedFrame(CreateFrame(1, 1280, 720)); | 1243 const int kWidth = 1280; |
| 1244 const int kHeight = 720; |
| 1245 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1224 sink_.WaitForEncodedFrame(1); | 1246 sink_.WaitForEncodedFrame(1); |
1225 | 1247 |
1226 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1248 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1227 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, | 1249 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, |
1228 stats.preferred_media_bitrate_bps); | 1250 stats.preferred_media_bitrate_bps); |
1229 | 1251 |
1230 vie_encoder_->Stop(); | 1252 vie_encoder_->Stop(); |
1231 } | 1253 } |
1232 | 1254 |
1233 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 1255 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
1234 int frame_width = 1280; | 1256 const int kWidth = 1280; |
1235 int frame_height = 720; | 1257 const int kHeight = 720; |
1236 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1258 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1237 | 1259 |
1238 // Expect no scaling to begin with | 1260 // Expect no scaling to begin with. |
1239 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 1261 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
1240 EXPECT_EQ(std::numeric_limits<int>::max(), | 1262 EXPECT_EQ(std::numeric_limits<int>::max(), |
1241 video_source_.sink_wants().max_pixel_count); | 1263 video_source_.sink_wants().max_pixel_count); |
1242 | 1264 |
1243 video_source_.IncomingCapturedFrame( | 1265 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1244 CreateFrame(1, frame_width, frame_height)); | |
1245 sink_.WaitForEncodedFrame(1); | 1266 sink_.WaitForEncodedFrame(1); |
1246 | 1267 |
1247 // Trigger scale down | 1268 // Trigger scale down. |
1248 vie_encoder_->TriggerQualityLow(); | 1269 vie_encoder_->TriggerQualityLow(); |
1249 | 1270 |
1250 video_source_.IncomingCapturedFrame( | 1271 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1251 CreateFrame(2, frame_width, frame_height)); | |
1252 sink_.WaitForEncodedFrame(2); | 1272 sink_.WaitForEncodedFrame(2); |
1253 | 1273 |
1254 // Expect a scale down. | 1274 // Expect a scale down. |
1255 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 1275 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
1256 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 1276 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
1257 frame_width * frame_height); | |
1258 | 1277 |
1259 // Set adaptation disabled. | 1278 // Set adaptation disabled. |
1260 test::FrameForwarder new_video_source; | 1279 test::FrameForwarder new_video_source; |
1261 vie_encoder_->SetSource( | 1280 vie_encoder_->SetSource( |
1262 &new_video_source, | 1281 &new_video_source, |
1263 VideoSendStream::DegradationPreference::kMaintainResolution); | 1282 VideoSendStream::DegradationPreference::kMaintainResolution); |
1264 | 1283 |
1265 // Trigger scale down | 1284 // Trigger scale down. |
1266 vie_encoder_->TriggerQualityLow(); | 1285 vie_encoder_->TriggerQualityLow(); |
1267 new_video_source.IncomingCapturedFrame( | 1286 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1268 CreateFrame(3, frame_width, frame_height)); | |
1269 sink_.WaitForEncodedFrame(3); | 1287 sink_.WaitForEncodedFrame(3); |
1270 | 1288 |
1271 // Expect no scaling | 1289 // Expect no scaling. |
1272 EXPECT_EQ(std::numeric_limits<int>::max(), | 1290 EXPECT_EQ(std::numeric_limits<int>::max(), |
1273 new_video_source.sink_wants().max_pixel_count); | 1291 new_video_source.sink_wants().max_pixel_count); |
1274 | 1292 |
1275 // Trigger scale up | 1293 // Trigger scale up. |
1276 vie_encoder_->TriggerQualityHigh(); | 1294 vie_encoder_->TriggerQualityHigh(); |
1277 new_video_source.IncomingCapturedFrame( | 1295 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1278 CreateFrame(4, frame_width, frame_height)); | |
1279 sink_.WaitForEncodedFrame(4); | 1296 sink_.WaitForEncodedFrame(4); |
1280 | 1297 |
1281 // Expect nothing to change, still no scaling | 1298 // Expect nothing to change, still no scaling |
1282 EXPECT_EQ(std::numeric_limits<int>::max(), | 1299 EXPECT_EQ(std::numeric_limits<int>::max(), |
1283 new_video_source.sink_wants().max_pixel_count); | 1300 new_video_source.sink_wants().max_pixel_count); |
1284 | 1301 |
1285 vie_encoder_->Stop(); | 1302 vie_encoder_->Stop(); |
1286 } | 1303 } |
1287 | 1304 |
1288 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { | 1305 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { |
1289 int frame_width = 1280; | 1306 int frame_width = 1280; |
1290 int frame_height = 720; | 1307 int frame_height = 720; |
1291 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1308 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1292 | 1309 |
1293 for (size_t i = 1; i <= 10; i++) { | 1310 for (size_t i = 1; i <= 10; i++) { |
1294 video_source_.IncomingCapturedFrame( | 1311 video_source_.IncomingCapturedFrame( |
1295 CreateFrame(i, frame_width, frame_height)); | 1312 CreateFrame(i, frame_width, frame_height)); |
1296 sink_.WaitForEncodedFrame(i); | 1313 sink_.WaitForEncodedFrame(i); |
1297 // Trigger scale down | 1314 // Trigger scale down. |
1298 vie_encoder_->TriggerQualityLow(); | 1315 vie_encoder_->TriggerQualityLow(); |
1299 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); | 1316 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); |
1300 } | 1317 } |
1301 | 1318 |
1302 vie_encoder_->Stop(); | 1319 vie_encoder_->Stop(); |
1303 } | 1320 } |
1304 | 1321 |
1305 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { | 1322 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { |
1306 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1323 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1307 | 1324 |
1308 int frame_width = 640; | 1325 const int kWidth = 640; |
1309 int frame_height = 360; | 1326 const int kHeight = 360; |
1310 | 1327 |
1311 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 1328 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
1312 video_source_.IncomingCapturedFrame( | 1329 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1313 CreateFrame(i, frame_width, frame_height)); | |
1314 sink_.WaitForEncodedFrame(i); | 1330 sink_.WaitForEncodedFrame(i); |
1315 } | 1331 } |
1316 | 1332 |
1317 vie_encoder_->TriggerCpuOveruse(); | 1333 vie_encoder_->TriggerCpuOveruse(); |
1318 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 1334 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
1319 video_source_.IncomingCapturedFrame( | 1335 video_source_.IncomingCapturedFrame(CreateFrame( |
1320 CreateFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + i, | 1336 SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); |
1321 frame_width, frame_height)); | |
1322 sink_.WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + | 1337 sink_.WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + |
1323 i); | 1338 i); |
1324 } | 1339 } |
1325 | 1340 |
1326 vie_encoder_->Stop(); | 1341 vie_encoder_->Stop(); |
1327 vie_encoder_.reset(); | 1342 vie_encoder_.reset(); |
1328 stats_proxy_.reset(); | 1343 stats_proxy_.reset(); |
1329 | 1344 |
1330 EXPECT_EQ(1, | 1345 EXPECT_EQ(1, |
1331 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 1346 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1386 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
1372 .Times(1); | 1387 .Times(1); |
1373 video_source_.IncomingCapturedFrame(CreateFrame( | 1388 video_source_.IncomingCapturedFrame(CreateFrame( |
1374 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); | 1389 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); |
1375 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); | 1390 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); |
1376 | 1391 |
1377 vie_encoder_->Stop(); | 1392 vie_encoder_->Stop(); |
1378 } | 1393 } |
1379 | 1394 |
1380 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { | 1395 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { |
1381 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1396 const int kTooLowBitrateForFrameSizeBps = 10000; |
1382 int frame_width = 640; | 1397 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
1383 int frame_height = 360; | 1398 const int kWidth = 640; |
| 1399 const int kHeight = 360; |
1384 | 1400 |
1385 video_source_.IncomingCapturedFrame( | 1401 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1386 CreateFrame(1, frame_width, frame_height)); | |
1387 | 1402 |
1388 // Expect to drop this frame, the wait should time out. | 1403 // Expect to drop this frame, the wait should time out. |
1389 sink_.ExpectDroppedFrame(); | 1404 sink_.ExpectDroppedFrame(); |
1390 | 1405 |
1391 // Expect the sink_wants to specify a scaled frame. | 1406 // Expect the sink_wants to specify a scaled frame. |
1392 EXPECT_LT(video_source_.sink_wants().max_pixel_count, 1000 * 1000); | 1407 EXPECT_LT(video_source_.sink_wants().max_pixel_count, 1000 * 1000); |
1393 | 1408 |
1394 int last_pixel_count = video_source_.sink_wants().max_pixel_count; | 1409 int last_pixel_count = video_source_.sink_wants().max_pixel_count; |
1395 | 1410 |
1396 // Next frame is scaled | 1411 // Next frame is scaled. |
1397 video_source_.IncomingCapturedFrame( | 1412 video_source_.IncomingCapturedFrame( |
1398 CreateFrame(2, frame_width * 3 / 4, frame_height * 3 / 4)); | 1413 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); |
1399 | 1414 |
1400 // Expect to drop this frame, the wait should time out. | 1415 // Expect to drop this frame, the wait should time out. |
1401 sink_.ExpectDroppedFrame(); | 1416 sink_.ExpectDroppedFrame(); |
1402 | 1417 |
1403 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); | 1418 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); |
1404 | 1419 |
1405 vie_encoder_->Stop(); | 1420 vie_encoder_->Stop(); |
1406 } | 1421 } |
1407 | 1422 |
1408 TEST_F(ViEEncoderTest, NrOfDroppedFramesLimited) { | 1423 TEST_F(ViEEncoderTest, NrOfDroppedFramesLimitedWhenBitrateIsTooLow) { |
1409 // 1kbps. This can never be achieved. | 1424 const int kTooLowBitrateForFrameSizeBps = 10000; |
1410 vie_encoder_->OnBitrateUpdated(1000, 0, 0); | 1425 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
1411 int frame_width = 640; | 1426 const int kWidth = 640; |
1412 int frame_height = 360; | 1427 const int kHeight = 360; |
1413 | 1428 |
1414 // We expect the n initial frames to get dropped. | 1429 // We expect the n initial frames to get dropped. |
1415 int i; | 1430 int i; |
1416 for (i = 1; i <= kMaxInitialFramedrop; ++i) { | 1431 for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
1417 video_source_.IncomingCapturedFrame( | 1432 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1418 CreateFrame(i, frame_width, frame_height)); | |
1419 sink_.ExpectDroppedFrame(); | 1433 sink_.ExpectDroppedFrame(); |
1420 } | 1434 } |
1421 // The n+1th frame should not be dropped, even though it's size is too large. | 1435 // The n+1th frame should not be dropped, even though it's size is too large. |
1422 video_source_.IncomingCapturedFrame( | 1436 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1423 CreateFrame(i, frame_width, frame_height)); | |
1424 sink_.WaitForEncodedFrame(i); | 1437 sink_.WaitForEncodedFrame(i); |
1425 | 1438 |
1426 // Expect the sink_wants to specify a scaled frame. | 1439 // Expect the sink_wants to specify a scaled frame. |
1427 EXPECT_LT(video_source_.sink_wants().max_pixel_count, 1000 * 1000); | 1440 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
1428 | 1441 |
1429 vie_encoder_->Stop(); | 1442 vie_encoder_->Stop(); |
1430 } | 1443 } |
1431 | 1444 |
1432 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { | 1445 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { |
1433 int frame_width = 640; | 1446 const int kWidth = 640; |
1434 int frame_height = 360; | 1447 const int kHeight = 360; |
1435 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1448 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
1436 | 1449 |
1437 // Set degradation preference. | 1450 // Set degradation preference. |
1438 vie_encoder_->SetSource( | 1451 vie_encoder_->SetSource( |
1439 &video_source_, | 1452 &video_source_, |
1440 VideoSendStream::DegradationPreference::kMaintainResolution); | 1453 VideoSendStream::DegradationPreference::kMaintainResolution); |
1441 | 1454 |
1442 video_source_.IncomingCapturedFrame( | 1455 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1443 CreateFrame(1, frame_width, frame_height)); | |
1444 // Frame should not be dropped, even if it's too large. | 1456 // Frame should not be dropped, even if it's too large. |
1445 sink_.WaitForEncodedFrame(1); | 1457 sink_.WaitForEncodedFrame(1); |
1446 | 1458 |
1447 vie_encoder_->Stop(); | 1459 vie_encoder_->Stop(); |
1448 } | 1460 } |
1449 | 1461 |
1450 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { | 1462 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { |
1451 int frame_width = 640; | 1463 const int kWidth = 640; |
1452 int frame_height = 360; | 1464 const int kHeight = 360; |
1453 fake_encoder_.SetQualityScaling(false); | 1465 fake_encoder_.SetQualityScaling(false); |
1454 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1466 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
1455 // Force quality scaler reconfiguration by resetting the source. | 1467 // Force quality scaler reconfiguration by resetting the source. |
1456 vie_encoder_->SetSource(&video_source_, | 1468 vie_encoder_->SetSource(&video_source_, |
1457 VideoSendStream::DegradationPreference::kBalanced); | 1469 VideoSendStream::DegradationPreference::kBalanced); |
1458 | 1470 |
1459 video_source_.IncomingCapturedFrame( | 1471 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1460 CreateFrame(1, frame_width, frame_height)); | |
1461 // Frame should not be dropped, even if it's too large. | 1472 // Frame should not be dropped, even if it's too large. |
1462 sink_.WaitForEncodedFrame(1); | 1473 sink_.WaitForEncodedFrame(1); |
1463 | 1474 |
1464 vie_encoder_->Stop(); | 1475 vie_encoder_->Stop(); |
1465 fake_encoder_.SetQualityScaling(true); | 1476 fake_encoder_.SetQualityScaling(true); |
1466 } | 1477 } |
1467 | 1478 |
1468 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. | 1479 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. |
1469 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse) { | 1480 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse) { |
1470 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1481 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1471 | 1482 |
1472 const int kFrameWidth = 1280; | 1483 const int kFrameWidth = 1280; |
1473 const int kFrameHeight = 720; | 1484 const int kFrameHeight = 720; |
1474 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as | 1485 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as |
1475 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). | 1486 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). |
1476 video_source_.set_adaptation_enabled(true); | 1487 video_source_.set_adaptation_enabled(true); |
1477 | 1488 |
1478 video_source_.IncomingCapturedFrame( | 1489 video_source_.IncomingCapturedFrame( |
1479 CreateFrame(1, kFrameWidth, kFrameHeight)); | 1490 CreateFrame(1, kFrameWidth, kFrameHeight)); |
1480 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1491 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
1481 | 1492 |
1482 // Trigger CPU overuse, downscale by 3/4. | 1493 // Trigger CPU overuse, downscale by 3/4. |
1483 vie_encoder_->TriggerCpuOveruse(); | 1494 vie_encoder_->TriggerCpuOveruse(); |
1484 video_source_.IncomingCapturedFrame( | 1495 video_source_.IncomingCapturedFrame( |
1485 CreateFrame(2, kFrameWidth, kFrameHeight)); | 1496 CreateFrame(2, kFrameWidth, kFrameHeight)); |
1486 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); | 1497 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
1487 | 1498 |
1488 // Trigger CPU normal use, return to original resolution; | 1499 // Trigger CPU normal use, return to original resolution. |
1489 vie_encoder_->TriggerCpuNormalUsage(); | 1500 vie_encoder_->TriggerCpuNormalUsage(); |
1490 video_source_.IncomingCapturedFrame( | 1501 video_source_.IncomingCapturedFrame( |
1491 CreateFrame(3, kFrameWidth, kFrameHeight)); | 1502 CreateFrame(3, kFrameWidth, kFrameHeight)); |
1492 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1503 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
1493 | 1504 |
1494 vie_encoder_->Stop(); | 1505 vie_encoder_->Stop(); |
1495 } | 1506 } |
1496 | 1507 |
1497 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { | 1508 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { |
1498 fake_encoder_.ForceInitEncodeFailure(true); | 1509 fake_encoder_.ForceInitEncodeFailure(true); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 for (int i = 0; i < 10; ++i) { | 1664 for (int i = 0; i < 10; ++i) { |
1654 timestamp_ms += kMinFpsFrameInterval; | 1665 timestamp_ms += kMinFpsFrameInterval; |
1655 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); | 1666 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); |
1656 video_source_.IncomingCapturedFrame( | 1667 video_source_.IncomingCapturedFrame( |
1657 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 1668 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
1658 sink_.WaitForEncodedFrame(timestamp_ms); | 1669 sink_.WaitForEncodedFrame(timestamp_ms); |
1659 } | 1670 } |
1660 vie_encoder_->Stop(); | 1671 vie_encoder_->Stop(); |
1661 } | 1672 } |
1662 } // namespace webrtc | 1673 } // namespace webrtc |
OLD | NEW |