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

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

Issue 2887303003: Implement kBalanced degradation preference. (Closed)
Patch Set: address comments Created 3 years, 7 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
« webrtc/video/vie_encoder.cc ('K') | « 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 16 matching lines...) Expand all
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 // TODO(kthelgason): Lower this limit when better testing 32 // TODO(kthelgason): Lower this limit when better testing
33 // on MediaCodec and fallback implementations are in place. 33 // on MediaCodec and fallback implementations are in place.
34 const int kMinPixelsPerFrame = 320 * 180; 34 const int kMinPixelsPerFrame = 320 * 180;
35 const int kMinFramerateFps = 2; 35 const int kMinFramerateFps = 2;
36 const int64_t kFrameTimeoutMs = 100; 36 const int64_t kFrameTimeoutMs = 100;
37 const int kBpsLimitFor15Fps = 500000;
38 const int kBpsLimitFor10Fps = 130000;
39 const int kBpsLimitFor7Fps = 60000;
37 } // namespace 40 } // namespace
38 41
39 namespace webrtc { 42 namespace webrtc {
40 43
41 using DegredationPreference = VideoSendStream::DegradationPreference; 44 using DegredationPreference = VideoSendStream::DegradationPreference;
42 using ScaleReason = AdaptationObserverInterface::AdaptReason; 45 using ScaleReason = AdaptationObserverInterface::AdaptReason;
43 using ::testing::_; 46 using ::testing::_;
44 using ::testing::Return; 47 using ::testing::Return;
45 48
46 namespace { 49 namespace {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count); 307 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count);
305 EXPECT_GT(wants1.max_pixel_count, 0); 308 EXPECT_GT(wants1.max_pixel_count, 0);
306 } 309 }
307 310
308 void VerifyFpsMaxResolutionGt(const rtc::VideoSinkWants& wants1, 311 void VerifyFpsMaxResolutionGt(const rtc::VideoSinkWants& wants1,
309 const rtc::VideoSinkWants& wants2) { 312 const rtc::VideoSinkWants& wants2) {
310 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps); 313 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps);
311 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count); 314 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count);
312 } 315 }
313 316
317 void VerifyFpsMaxResolutionEq(const rtc::VideoSinkWants& wants1,
318 const rtc::VideoSinkWants& wants2) {
319 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps);
320 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count);
321 }
322
323 void VerifyFpsLtResolutionEq(const rtc::VideoSinkWants& wants1,
324 const rtc::VideoSinkWants& wants2) {
325 EXPECT_LT(wants1.max_framerate_fps, wants2.max_framerate_fps);
326 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count);
327 }
328
329 void VerifyFpsGtResolutionEq(const rtc::VideoSinkWants& wants1,
330 const rtc::VideoSinkWants& wants2) {
331 EXPECT_GT(wants1.max_framerate_fps, wants2.max_framerate_fps);
332 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count);
333 }
334
335 void VerifyFpsEqResolutionLt(const rtc::VideoSinkWants& wants1,
336 const rtc::VideoSinkWants& wants2) {
337 EXPECT_EQ(wants1.max_framerate_fps, wants2.max_framerate_fps);
338 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count);
339 EXPECT_GT(wants1.max_pixel_count, 0);
340 }
341
342 void VerifyFpsEqResolutionGt(const rtc::VideoSinkWants& wants1,
343 const rtc::VideoSinkWants& wants2) {
344 EXPECT_EQ(wants1.max_framerate_fps, wants2.max_framerate_fps);
345 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count);
346 }
347
314 void VerifyFpsMaxResolutionLt(const rtc::VideoSinkWants& wants, 348 void VerifyFpsMaxResolutionLt(const rtc::VideoSinkWants& wants,
315 int pixel_count) { 349 int pixel_count) {
316 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps); 350 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps);
317 EXPECT_LT(wants.max_pixel_count, pixel_count); 351 EXPECT_LT(wants.max_pixel_count, pixel_count);
318 EXPECT_GT(wants.max_pixel_count, 0); 352 EXPECT_GT(wants.max_pixel_count, 0);
319 } 353 }
320 354
321 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) { 355 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) {
322 EXPECT_LT(wants.max_framerate_fps, fps); 356 EXPECT_LT(wants.max_framerate_fps, fps);
323 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); 357 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count);
324 EXPECT_FALSE(wants.target_pixel_count); 358 EXPECT_FALSE(wants.target_pixel_count);
325 } 359 }
326 360
361 void VerifyFpsEqResolutionMax(const rtc::VideoSinkWants& wants,
362 int expected_fps) {
363 EXPECT_EQ(expected_fps, wants.max_framerate_fps);
364 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count);
365 EXPECT_FALSE(wants.target_pixel_count);
366 }
367
327 class TestEncoder : public test::FakeEncoder { 368 class TestEncoder : public test::FakeEncoder {
328 public: 369 public:
329 TestEncoder() 370 TestEncoder()
330 : FakeEncoder(Clock::GetRealTimeClock()), 371 : FakeEncoder(Clock::GetRealTimeClock()),
331 continue_encode_event_(false, false) {} 372 continue_encode_event_(false, false) {}
332 373
333 VideoCodec codec_config() const { 374 VideoCodec codec_config() const {
334 rtc::CritScope lock(&crit_sect_); 375 rtc::CritScope lock(&crit_sect_);
335 return config_; 376 return config_;
336 } 377 }
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 video_source_.sink_wants().target_pixel_count.value_or(0)); 842 video_source_.sink_wants().target_pixel_count.value_or(0));
802 EXPECT_EQ(frame_width * frame_height * 4, 843 EXPECT_EQ(frame_width * frame_height * 4,
803 video_source_.sink_wants().max_pixel_count); 844 video_source_.sink_wants().max_pixel_count);
804 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 845 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
805 EXPECT_EQ(kMaxDowngrades + 1, 846 EXPECT_EQ(kMaxDowngrades + 1,
806 stats_proxy_->GetStats().number_of_cpu_adapt_changes); 847 stats_proxy_->GetStats().number_of_cpu_adapt_changes);
807 848
808 vie_encoder_->Stop(); 849 vie_encoder_->Stop();
809 } 850 }
810 851
852 TEST_F(ViEEncoderTest, TestMaxCpuResolutionDowngrades_BalancedMode_NoFpsLimit) {
853 const int kMaxDowngrades = ViEEncoder::kMaxCpuResolutionDowngrades;
854 const int kWidth = 1280;
855 const int kHeight = 720;
856 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps + 1, 0, 0);
857
858 // Enable kBalanced preference, no initial limitation.
859 AdaptingFrameForwarder source;
860 source.set_adaptation_enabled(true);
861 vie_encoder_->SetSource(&source,
862 VideoSendStream::DegradationPreference::kBalanced);
863 VerifyNoLimitation(source.sink_wants());
864 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
865 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
866
867 // Trigger adapt down kMaxCpuDowngrades times.
868 int t = 1;
869 for (int i = 1; i <= kMaxDowngrades; ++i) {
870 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight));
871 sink_.WaitForEncodedFrame(t++);
872 vie_encoder_->TriggerCpuOveruse();
873 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants());
874 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
875 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
876 }
877
878 // Trigger adapt down, max cpu downgrades reach, expect no change.
879 rtc::VideoSinkWants last_wants = source.sink_wants();
880 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight));
881 sink_.WaitForEncodedFrame(t++);
882 vie_encoder_->TriggerCpuOveruse();
883 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants);
884 EXPECT_EQ(last_wants.max_pixel_count, source.sink_wants().max_pixel_count);
885 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
886 EXPECT_EQ(kMaxDowngrades,
887 stats_proxy_->GetStats().number_of_cpu_adapt_changes);
888
889 // Trigger adapt up kMaxCpuDowngrades times.
890 for (int i = 1; i <= kMaxDowngrades; ++i) {
891 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight));
892 sink_.WaitForEncodedFrame(t++);
893 vie_encoder_->TriggerCpuNormalUsage();
894 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
895 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count);
896 EXPECT_EQ(kMaxDowngrades + i,
897 stats_proxy_->GetStats().number_of_cpu_adapt_changes);
898 }
899
900 VerifyNoLimitation(source.sink_wants());
901 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
902
903 vie_encoder_->Stop();
904 }
811 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) { 905 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) {
812 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 906 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
813 VerifyNoLimitation(video_source_.sink_wants()); 907 VerifyNoLimitation(video_source_.sink_wants());
814 908
815 const int kFrameWidth = 1280; 909 const int kFrameWidth = 1280;
816 const int kFrameHeight = 720; 910 const int kFrameHeight = 720;
817 const int kFrameIntervalMs = 1000 / 30; 911 const int kFrameIntervalMs = 1000 / 30;
818 912
819 int frame_timestamp = 1; 913 int frame_timestamp = 1;
820 914
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 } 1135 }
1042 1136
1043 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { 1137 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) {
1044 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1138 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1045 1139
1046 const int kWidth = 1280; 1140 const int kWidth = 1280;
1047 const int kHeight = 720; 1141 const int kHeight = 720;
1048 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); 1142 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1049 sink_.WaitForEncodedFrame(1); 1143 sink_.WaitForEncodedFrame(1);
1050 VideoSendStream::Stats stats = stats_proxy_->GetStats(); 1144 VideoSendStream::Stats stats = stats_proxy_->GetStats();
1051 EXPECT_FALSE(stats.cpu_limited_resolution);
1052 EXPECT_FALSE(stats.bw_limited_resolution); 1145 EXPECT_FALSE(stats.bw_limited_resolution);
1146 EXPECT_FALSE(stats.bw_limited_framerate);
1053 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); 1147 EXPECT_EQ(0, stats.number_of_quality_adapt_changes);
1054 1148
1055 // Set new source with adaptation still enabled. 1149 // Set new source with adaptation still enabled.
1056 test::FrameForwarder new_video_source; 1150 test::FrameForwarder new_video_source;
1057 vie_encoder_->SetSource(&new_video_source, 1151 vie_encoder_->SetSource(&new_video_source,
1058 VideoSendStream::DegradationPreference::kBalanced); 1152 VideoSendStream::DegradationPreference::kBalanced);
1059 1153
1060 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); 1154 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1061 sink_.WaitForEncodedFrame(2); 1155 sink_.WaitForEncodedFrame(2);
1062 stats = stats_proxy_->GetStats(); 1156 stats = stats_proxy_->GetStats();
1063 EXPECT_FALSE(stats.cpu_limited_resolution);
1064 EXPECT_FALSE(stats.bw_limited_resolution); 1157 EXPECT_FALSE(stats.bw_limited_resolution);
1158 EXPECT_FALSE(stats.bw_limited_framerate);
1065 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); 1159 EXPECT_EQ(0, stats.number_of_quality_adapt_changes);
1066 1160
1067 // Trigger adapt down. 1161 // Trigger adapt down.
1068 vie_encoder_->TriggerQualityLow(); 1162 vie_encoder_->TriggerQualityLow();
1069 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); 1163 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight));
1070 sink_.WaitForEncodedFrame(3); 1164 sink_.WaitForEncodedFrame(3);
1071 stats = stats_proxy_->GetStats(); 1165 stats = stats_proxy_->GetStats();
1072 EXPECT_FALSE(stats.cpu_limited_resolution);
1073 EXPECT_TRUE(stats.bw_limited_resolution); 1166 EXPECT_TRUE(stats.bw_limited_resolution);
1167 EXPECT_FALSE(stats.bw_limited_framerate);
1074 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); 1168 EXPECT_EQ(1, stats.number_of_quality_adapt_changes);
1075 1169
1076 // Set new source with adaptation still enabled. 1170 // Set new source with adaptation still enabled.
1077 vie_encoder_->SetSource(&new_video_source, 1171 vie_encoder_->SetSource(&new_video_source,
1078 VideoSendStream::DegradationPreference::kBalanced); 1172 VideoSendStream::DegradationPreference::kBalanced);
1079 1173
1080 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); 1174 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight));
1081 sink_.WaitForEncodedFrame(4); 1175 sink_.WaitForEncodedFrame(4);
1082 stats = stats_proxy_->GetStats(); 1176 stats = stats_proxy_->GetStats();
1083 EXPECT_FALSE(stats.cpu_limited_resolution);
1084 EXPECT_TRUE(stats.bw_limited_resolution); 1177 EXPECT_TRUE(stats.bw_limited_resolution);
1178 EXPECT_FALSE(stats.bw_limited_framerate);
1085 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); 1179 EXPECT_EQ(1, stats.number_of_quality_adapt_changes);
1086 1180
1087 // Disable resolution scaling. 1181 // Disable resolution scaling.
1088 vie_encoder_->SetSource( 1182 vie_encoder_->SetSource(
1089 &new_video_source, 1183 &new_video_source,
1090 VideoSendStream::DegradationPreference::kMaintainResolution); 1184 VideoSendStream::DegradationPreference::kMaintainResolution);
1091 1185
1092 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); 1186 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight));
1093 sink_.WaitForEncodedFrame(5); 1187 sink_.WaitForEncodedFrame(5);
1094 stats = stats_proxy_->GetStats(); 1188 stats = stats_proxy_->GetStats();
1095 EXPECT_FALSE(stats.cpu_limited_resolution);
1096 EXPECT_FALSE(stats.bw_limited_resolution); 1189 EXPECT_FALSE(stats.bw_limited_resolution);
1190 EXPECT_FALSE(stats.bw_limited_framerate);
1097 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); 1191 EXPECT_EQ(1, stats.number_of_quality_adapt_changes);
1098 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); 1192 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes);
1099 1193
1100 vie_encoder_->Stop(); 1194 vie_encoder_->Stop();
1101 } 1195 }
1102 1196
1103 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { 1197 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) {
1104 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1198 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1105 1199
1106 const int kWidth = 1280; 1200 const int kWidth = 1280;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1241 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1148 1242
1149 const int kWidth = 1280; 1243 const int kWidth = 1280;
1150 const int kHeight = 720; 1244 const int kHeight = 720;
1151 int sequence = 1; 1245 int sequence = 1;
1152 1246
1153 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); 1247 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight));
1154 sink_.WaitForEncodedFrame(sequence++); 1248 sink_.WaitForEncodedFrame(sequence++);
1155 VideoSendStream::Stats stats = stats_proxy_->GetStats(); 1249 VideoSendStream::Stats stats = stats_proxy_->GetStats();
1156 EXPECT_FALSE(stats.cpu_limited_resolution); 1250 EXPECT_FALSE(stats.cpu_limited_resolution);
1251 EXPECT_FALSE(stats.cpu_limited_framerate);
1157 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); 1252 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes);
1158 1253
1159 // Trigger CPU overuse, should now adapt down. 1254 // Trigger CPU overuse, should now adapt down.
1160 vie_encoder_->TriggerCpuOveruse(); 1255 vie_encoder_->TriggerCpuOveruse();
1161 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); 1256 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight));
1162 sink_.WaitForEncodedFrame(sequence++); 1257 sink_.WaitForEncodedFrame(sequence++);
1163 stats = stats_proxy_->GetStats(); 1258 stats = stats_proxy_->GetStats();
1164 EXPECT_TRUE(stats.cpu_limited_resolution); 1259 EXPECT_TRUE(stats.cpu_limited_resolution);
1260 EXPECT_FALSE(stats.cpu_limited_framerate);
1165 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); 1261 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
1166 1262
1167 // Set new source with adaptation still enabled. 1263 // Set new source with adaptation still enabled.
1168 test::FrameForwarder new_video_source; 1264 test::FrameForwarder new_video_source;
1169 vie_encoder_->SetSource( 1265 vie_encoder_->SetSource(
1170 &new_video_source, 1266 &new_video_source,
1171 VideoSendStream::DegradationPreference::kMaintainFramerate); 1267 VideoSendStream::DegradationPreference::kMaintainFramerate);
1172 1268
1173 new_video_source.IncomingCapturedFrame( 1269 new_video_source.IncomingCapturedFrame(
1174 CreateFrame(sequence, kWidth, kHeight)); 1270 CreateFrame(sequence, kWidth, kHeight));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 // Disable CPU adaptation. 1308 // Disable CPU adaptation.
1213 vie_encoder_->SetSource( 1309 vie_encoder_->SetSource(
1214 &new_video_source, 1310 &new_video_source,
1215 VideoSendStream::DegradationPreference::kDegradationDisabled); 1311 VideoSendStream::DegradationPreference::kDegradationDisabled);
1216 new_video_source.IncomingCapturedFrame( 1312 new_video_source.IncomingCapturedFrame(
1217 CreateFrame(sequence, kWidth, kHeight)); 1313 CreateFrame(sequence, kWidth, kHeight));
1218 sink_.WaitForEncodedFrame(sequence++); 1314 sink_.WaitForEncodedFrame(sequence++);
1219 1315
1220 stats = stats_proxy_->GetStats(); 1316 stats = stats_proxy_->GetStats();
1221 EXPECT_FALSE(stats.cpu_limited_resolution); 1317 EXPECT_FALSE(stats.cpu_limited_resolution);
1318 EXPECT_FALSE(stats.cpu_limited_framerate);
1222 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); 1319 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes);
1223 1320
1224 // Try to trigger overuse. Should not succeed. 1321 // Try to trigger overuse. Should not succeed.
1225 stats_proxy_->SetMockStats(mock_stats); 1322 stats_proxy_->SetMockStats(mock_stats);
1226 vie_encoder_->TriggerCpuOveruse(); 1323 vie_encoder_->TriggerCpuOveruse();
1227 stats_proxy_->ResetMockStats(); 1324 stats_proxy_->ResetMockStats();
1228 1325
1229 stats = stats_proxy_->GetStats(); 1326 stats = stats_proxy_->GetStats();
1230 EXPECT_FALSE(stats.cpu_limited_resolution); 1327 EXPECT_FALSE(stats.cpu_limited_resolution);
1328 EXPECT_FALSE(stats.cpu_limited_framerate);
1231 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); 1329 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes);
1232 1330
1233 // Switch back the source with resolution adaptation enabled. 1331 // Switch back the source with resolution adaptation enabled.
1234 vie_encoder_->SetSource( 1332 vie_encoder_->SetSource(
1235 &video_source_, 1333 &video_source_,
1236 VideoSendStream::DegradationPreference::kMaintainFramerate); 1334 VideoSendStream::DegradationPreference::kMaintainFramerate);
1237 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); 1335 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight));
1238 sink_.WaitForEncodedFrame(sequence++); 1336 sink_.WaitForEncodedFrame(sequence++);
1239 stats = stats_proxy_->GetStats(); 1337 stats = stats_proxy_->GetStats();
1240 EXPECT_TRUE(stats.cpu_limited_resolution); 1338 EXPECT_TRUE(stats.cpu_limited_resolution);
1339 EXPECT_FALSE(stats.cpu_limited_framerate);
1241 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); 1340 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes);
1242 1341
1243 // Trigger CPU normal usage. 1342 // Trigger CPU normal usage.
1244 vie_encoder_->TriggerCpuNormalUsage(); 1343 vie_encoder_->TriggerCpuNormalUsage();
1245 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); 1344 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight));
1246 sink_.WaitForEncodedFrame(sequence++); 1345 sink_.WaitForEncodedFrame(sequence++);
1247 stats = stats_proxy_->GetStats(); 1346 stats = stats_proxy_->GetStats();
1248 EXPECT_FALSE(stats.cpu_limited_resolution); 1347 EXPECT_FALSE(stats.cpu_limited_resolution);
1348 EXPECT_FALSE(stats.cpu_limited_framerate);
1249 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); 1349 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes);
1250 1350
1251 // Back to the source with adaptation off, set it back to maintain-resolution. 1351 // Back to the source with adaptation off, set it back to maintain-resolution.
1252 vie_encoder_->SetSource( 1352 vie_encoder_->SetSource(
1253 &new_video_source, 1353 &new_video_source,
1254 VideoSendStream::DegradationPreference::kMaintainResolution); 1354 VideoSendStream::DegradationPreference::kMaintainResolution);
1255 new_video_source.IncomingCapturedFrame( 1355 new_video_source.IncomingCapturedFrame(
1256 CreateFrame(sequence, kWidth, kHeight)); 1356 CreateFrame(sequence, kWidth, kHeight));
1257 sink_.WaitForEncodedFrame(sequence++); 1357 sink_.WaitForEncodedFrame(sequence++);
1258 stats = stats_proxy_->GetStats(); 1358 stats = stats_proxy_->GetStats();
1259 // Disabled, since we previously switched the source too disabled. 1359 // Disabled, since we previously switched the source to disabled.
1260 EXPECT_FALSE(stats.cpu_limited_resolution); 1360 EXPECT_FALSE(stats.cpu_limited_resolution);
1361 EXPECT_TRUE(stats.cpu_limited_framerate);
1261 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); 1362 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes);
1262 1363
1263 // Trigger CPU normal usage. 1364 // Trigger CPU normal usage.
1264 vie_encoder_->TriggerCpuNormalUsage(); 1365 vie_encoder_->TriggerCpuNormalUsage();
1265 new_video_source.IncomingCapturedFrame( 1366 new_video_source.IncomingCapturedFrame(
1266 CreateFrame(sequence, kWidth, kHeight)); 1367 CreateFrame(sequence, kWidth, kHeight));
1267 sink_.WaitForEncodedFrame(sequence++); 1368 sink_.WaitForEncodedFrame(sequence++);
1268 stats = stats_proxy_->GetStats(); 1369 stats = stats_proxy_->GetStats();
1269 EXPECT_FALSE(stats.cpu_limited_resolution); 1370 EXPECT_FALSE(stats.cpu_limited_resolution);
1371 EXPECT_FALSE(stats.cpu_limited_framerate);
1270 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); 1372 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes);
1271 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); 1373 EXPECT_EQ(0, stats.number_of_quality_adapt_changes);
1272 1374
1273 vie_encoder_->Stop(); 1375 vie_encoder_->Stop();
1274 } 1376 }
1275 1377
1276 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { 1378 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) {
1277 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1379 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1278 1380
1279 const int kWidth = 1280; 1381 const int kWidth = 1280;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 1463
1362 // Trigger adapt down for same input resolution, expect no change. 1464 // Trigger adapt down for same input resolution, expect no change.
1363 vie_encoder_->TriggerCpuOveruse(); 1465 vie_encoder_->TriggerCpuOveruse();
1364 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); 1466 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count);
1365 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1467 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1366 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1468 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1367 1469
1368 vie_encoder_->Stop(); 1470 vie_encoder_->Stop();
1369 } 1471 }
1370 1472
1473 TEST_F(ViEEncoderTest, SkipsSameOrLargerAdaptDownRequest_BalancedMode) {
1474 const int kWidth = 1280;
1475 const int kHeight = 720;
1476 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps + 1, 0, 0);
1477
1478 // Enable kBalanced preference, no initial limitation.
1479 test::FrameForwarder source;
1480 vie_encoder_->SetSource(&source,
1481 VideoSendStream::DegradationPreference::kBalanced);
1482 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1483 sink_.WaitForEncodedFrame(1);
1484 VerifyNoLimitation(source.sink_wants());
1485
1486 // Trigger adapt down, expect scaled down resolution.
1487 vie_encoder_->TriggerQualityLow();
1488 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1489 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1490 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1491 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count;
1492
1493 // Trigger adapt down for same input resolution, expect no change.
1494 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1495 sink_.WaitForEncodedFrame(2);
1496 vie_encoder_->TriggerQualityLow();
1497 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count);
1498 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1499 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1500
1501 // Trigger adapt down for larger input resolution, expect no change.
1502 source.IncomingCapturedFrame(CreateFrame(3, kWidth + 1, kHeight + 1));
1503 sink_.WaitForEncodedFrame(3);
1504 vie_encoder_->TriggerQualityLow();
1505 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count);
1506 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1507 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1508
1509 vie_encoder_->Stop();
1510 }
1511
1371 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainFramerateMode) { 1512 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainFramerateMode) {
1372 const int kWidth = 1280; 1513 const int kWidth = 1280;
1373 const int kHeight = 720; 1514 const int kHeight = 720;
1374 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1515 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1375 1516
1376 // Enable kMaintainFramerate preference, no initial limitation. 1517 // Enable kMaintainFramerate preference, no initial limitation.
1377 test::FrameForwarder source; 1518 test::FrameForwarder source;
1378 vie_encoder_->SetSource( 1519 vie_encoder_->SetSource(
1379 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); 1520 &source, VideoSendStream::DegradationPreference::kMaintainFramerate);
1380 1521
(...skipping 30 matching lines...) Expand all
1411 1552
1412 // Trigger adapt up, expect no change. 1553 // Trigger adapt up, expect no change.
1413 vie_encoder_->TriggerCpuNormalUsage(); 1554 vie_encoder_->TriggerCpuNormalUsage();
1414 VerifyNoLimitation(source.sink_wants()); 1555 VerifyNoLimitation(source.sink_wants());
1415 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); 1556 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1416 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1557 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1417 1558
1418 vie_encoder_->Stop(); 1559 vie_encoder_->Stop();
1419 } 1560 }
1420 1561
1562 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_BalancedMode) {
1563 const int kWidth = 1280;
1564 const int kHeight = 720;
1565 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1566
1567 // Enable kBalanced preference, no initial limitation.
1568 test::FrameForwarder source;
1569 vie_encoder_->SetSource(&source,
1570 VideoSendStream::DegradationPreference::kBalanced);
1571
1572 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1573 sink_.WaitForEncodedFrame(kWidth, kHeight);
1574 VerifyNoLimitation(source.sink_wants());
1575 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1576 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1577 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1578
1579 // Trigger adapt up, expect no change.
1580 vie_encoder_->TriggerQualityHigh();
1581 VerifyNoLimitation(source.sink_wants());
1582 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1583 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1584 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1585
1586 vie_encoder_->Stop();
1587 }
1588
1421 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_DisabledMode) { 1589 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_DisabledMode) {
1422 const int kWidth = 1280; 1590 const int kWidth = 1280;
1423 const int kHeight = 720; 1591 const int kHeight = 720;
1424 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1592 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1425 1593
1426 // Enable kDegradationDisabled preference, no initial limitation. 1594 // Enable kDegradationDisabled preference, no initial limitation.
1427 test::FrameForwarder source; 1595 test::FrameForwarder source;
1428 vie_encoder_->SetSource( 1596 vie_encoder_->SetSource(
1429 &source, VideoSendStream::DegradationPreference::kDegradationDisabled); 1597 &source, VideoSendStream::DegradationPreference::kDegradationDisabled);
1430 1598
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); 1771 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight));
1604 sink_.WaitForEncodedFrame(kWidth, kHeight); 1772 sink_.WaitForEncodedFrame(kWidth, kHeight);
1605 VerifyNoLimitation(source.sink_wants()); 1773 VerifyNoLimitation(source.sink_wants());
1606 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1774 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1607 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1775 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1608 1776
1609 vie_encoder_->Stop(); 1777 vie_encoder_->Stop();
1610 } 1778 }
1611 1779
1612 TEST_F(ViEEncoderTest, 1780 TEST_F(ViEEncoderTest,
1781 AdaptsResolutionUpAndDownTwiceForLowQuality_BalancedMode_NoFpsLimit) {
1782 const int kWidth = 1280;
1783 const int kHeight = 720;
1784 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps + 1, 0, 0);
1785
1786 // Enable kBalanced preference, no initial limitation.
1787 AdaptingFrameForwarder source;
1788 source.set_adaptation_enabled(true);
1789 vie_encoder_->SetSource(&source,
1790 VideoSendStream::DegradationPreference::kBalanced);
1791
1792 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1793 sink_.WaitForEncodedFrame(kWidth, kHeight);
1794 VerifyNoLimitation(source.sink_wants());
1795 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1796 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1797
1798 // Trigger adapt down, expect scaled down resolution.
1799 vie_encoder_->TriggerQualityLow();
1800 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1801 sink_.WaitForEncodedFrame(2);
1802 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1803 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1804 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1805
1806 // Trigger adapt up, expect no restriction.
1807 vie_encoder_->TriggerQualityHigh();
1808 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight));
1809 sink_.WaitForEncodedFrame(kWidth, kHeight);
1810 VerifyNoLimitation(source.sink_wants());
1811 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1812 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1813
1814 // Trigger adapt down, expect scaled down resolution.
1815 vie_encoder_->TriggerQualityLow();
1816 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight));
1817 sink_.WaitForEncodedFrame(4);
1818 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1819 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1820 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1821
1822 // Trigger adapt up, expect no restriction.
1823 vie_encoder_->TriggerQualityHigh();
1824 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight));
1825 sink_.WaitForEncodedFrame(kWidth, kHeight);
1826 VerifyNoLimitation(source.sink_wants());
1827 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1828 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1829
1830 vie_encoder_->Stop();
1831 }
1832
1833 TEST_F(ViEEncoderTest,
1613 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { 1834 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) {
1614 const int kWidth = 1280; 1835 const int kWidth = 1280;
1615 const int kHeight = 720; 1836 const int kHeight = 720;
1616 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1837 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1617 1838
1618 // Enable kMaintainFramerate preference, no initial limitation. 1839 // Enable kMaintainFramerate preference, no initial limitation.
1619 AdaptingFrameForwarder source; 1840 AdaptingFrameForwarder source;
1620 source.set_adaptation_enabled(true); 1841 source.set_adaptation_enabled(true);
1621 vie_encoder_->SetSource( 1842 vie_encoder_->SetSource(
1622 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); 1843 &source, VideoSendStream::DegradationPreference::kMaintainFramerate);
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); 2132 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight));
1912 sink_.WaitForEncodedFrame(1); 2133 sink_.WaitForEncodedFrame(1);
1913 vie_encoder_->TriggerCpuOveruse(); 2134 vie_encoder_->TriggerCpuOveruse();
1914 VerifyNoLimitation(source.sink_wants()); 2135 VerifyNoLimitation(source.sink_wants());
1915 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 2136 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1916 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 2137 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1917 2138
1918 vie_encoder_->Stop(); 2139 vie_encoder_->Stop();
1919 } 2140 }
1920 2141
2142 TEST_F(ViEEncoderTest, ResolutionNotAdaptedForTooSmallFrame_BalancedMode) {
2143 const int kTooSmallWidth = 10;
2144 const int kTooSmallHeight = 10;
2145 const int kFpsLimit = 7;
2146 vie_encoder_->OnBitrateUpdated(kBpsLimitFor7Fps, 0, 0);
2147
2148 // Enable kBalanced preference, no initial limitation.
2149 test::FrameForwarder source;
2150 vie_encoder_->SetSource(&source,
2151 VideoSendStream::DegradationPreference::kBalanced);
2152 VerifyNoLimitation(source.sink_wants());
2153 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2154 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2155
2156 // Trigger adapt down, expect limited framerate.
2157 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight));
2158 sink_.WaitForEncodedFrame(1);
2159 vie_encoder_->TriggerQualityLow();
2160 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit);
2161 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2162 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2163 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2164
2165 // Trigger adapt down, too small frame, expect no change.
2166 source.IncomingCapturedFrame(CreateFrame(2, kTooSmallWidth, kTooSmallHeight));
2167 sink_.WaitForEncodedFrame(2);
2168 vie_encoder_->TriggerQualityLow();
2169 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit);
2170 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2171 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2172 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2173
2174 vie_encoder_->Stop();
2175 }
2176
1921 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { 2177 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) {
1922 fake_encoder_.ForceInitEncodeFailure(true); 2178 fake_encoder_.ForceInitEncodeFailure(true);
1923 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 2179 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1924 ResetEncoder("VP8", 2, 1, true); 2180 ResetEncoder("VP8", 2, 1, true);
1925 const int kFrameWidth = 1280; 2181 const int kFrameWidth = 1280;
1926 const int kFrameHeight = 720; 2182 const int kFrameHeight = 720;
1927 video_source_.IncomingCapturedFrame( 2183 video_source_.IncomingCapturedFrame(
1928 CreateFrame(1, kFrameWidth, kFrameHeight)); 2184 CreateFrame(1, kFrameWidth, kFrameHeight));
1929 sink_.ExpectDroppedFrame(); 2185 sink_.ExpectDroppedFrame();
1930 vie_encoder_->Stop(); 2186 vie_encoder_->Stop();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 // Insert frames at min fps, all should go through. 2361 // Insert frames at min fps, all should go through.
2106 for (int i = 0; i < 10; ++i) { 2362 for (int i = 0; i < 10; ++i) {
2107 timestamp_ms += kMinFpsFrameInterval; 2363 timestamp_ms += kMinFpsFrameInterval;
2108 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); 2364 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000);
2109 video_source_.IncomingCapturedFrame( 2365 video_source_.IncomingCapturedFrame(
2110 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); 2366 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight));
2111 sink_.WaitForEncodedFrame(timestamp_ms); 2367 sink_.WaitForEncodedFrame(timestamp_ms);
2112 } 2368 }
2113 vie_encoder_->Stop(); 2369 vie_encoder_->Stop();
2114 } 2370 }
2371
2372 TEST_F(ViEEncoderTest, AdaptsResolutionAndFramerateForLowQuality_BalancedMode) {
2373 const int kWidth = 1280;
2374 const int kHeight = 720;
2375 const int64_t kFrameIntervalMs = 150;
2376 int64_t timestamp_ms = kFrameIntervalMs;
2377 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps, 0, 0);
2378
2379 // Enable kBalanced preference, no initial limitation.
2380 AdaptingFrameForwarder source;
2381 source.set_adaptation_enabled(true);
2382 vie_encoder_->SetSource(&source,
2383 VideoSendStream::DegradationPreference::kBalanced);
2384 timestamp_ms += kFrameIntervalMs;
2385 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2386 sink_.WaitForEncodedFrame(kWidth, kHeight);
2387 VerifyNoLimitation(source.sink_wants());
2388 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2389 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2390 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2391
2392 // Trigger adapt down, expect scaled down resolution (960x540@30fps).
2393 vie_encoder_->TriggerQualityLow();
2394 timestamp_ms += kFrameIntervalMs;
2395 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2396 sink_.WaitForEncodedFrame(timestamp_ms);
2397 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
2398 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2399 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2400 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2401
2402 // Trigger adapt down, expect scaled down resolution (640x360@30fps).
2403 vie_encoder_->TriggerQualityLow();
2404 timestamp_ms += kFrameIntervalMs;
2405 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2406 sink_.WaitForEncodedFrame(timestamp_ms);
2407 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants());
2408 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2409 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2410 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2411
2412 // Trigger adapt down, expect reduced fps (640x360@15fps).
2413 vie_encoder_->TriggerQualityLow();
2414 timestamp_ms += kFrameIntervalMs;
2415 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2416 sink_.WaitForEncodedFrame(timestamp_ms);
2417 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants());
2418 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2419 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2420 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2421
2422 // Trigger adapt down, expect scaled down resolution (480x270@15fps).
2423 vie_encoder_->OnBitrateUpdated(kBpsLimitFor10Fps, 0, 0);
2424 vie_encoder_->TriggerQualityLow();
2425 timestamp_ms += kFrameIntervalMs;
2426 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2427 sink_.WaitForEncodedFrame(timestamp_ms);
2428 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants());
2429 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2430 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2431 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2432
2433 // Restrict bitrate, trigger adapt down, expect reduced fps (480x270@10fps).
2434 vie_encoder_->TriggerQualityLow();
2435 timestamp_ms += kFrameIntervalMs;
2436 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2437 sink_.WaitForEncodedFrame(timestamp_ms);
2438 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants());
2439 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2440 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2441 EXPECT_EQ(5, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2442
2443 // Trigger adapt down, expect scaled down resolution (320x180@10fps).
2444 vie_encoder_->TriggerQualityLow();
2445 timestamp_ms += kFrameIntervalMs;
2446 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2447 sink_.WaitForEncodedFrame(timestamp_ms);
2448 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants());
2449 rtc::VideoSinkWants last_wants = source.sink_wants();
2450 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2451 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2452 EXPECT_EQ(6, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2453
2454 // Trigger adapt down, min resolution reached, expect no change.
2455 vie_encoder_->TriggerQualityLow();
2456 timestamp_ms += kFrameIntervalMs;
2457 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2458 sink_.WaitForEncodedFrame(timestamp_ms);
2459 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants);
2460 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2461 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2462 EXPECT_EQ(6, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2463
2464 // Trigger adapt up, expect upscaled resolution (480x270@10fps).
2465 vie_encoder_->TriggerQualityHigh();
2466 timestamp_ms += kFrameIntervalMs;
2467 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2468 sink_.WaitForEncodedFrame(timestamp_ms);
2469 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants());
2470 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2471 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2472 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2473
2474 // Increase bitrate, trigger adapt up, expect increased fps (480x270@15fps).
2475 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps + 1, 0, 0);
2476 vie_encoder_->TriggerQualityHigh();
2477 timestamp_ms += kFrameIntervalMs;
2478 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2479 sink_.WaitForEncodedFrame(timestamp_ms);
2480 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants());
2481 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2482 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2483 EXPECT_EQ(8, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2484
2485 // Trigger adapt up, expect upscaled resolution (640x360@15fps).
2486 vie_encoder_->TriggerQualityHigh();
2487 timestamp_ms += kFrameIntervalMs;
2488 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2489 sink_.WaitForEncodedFrame(timestamp_ms);
2490 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants());
2491 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2492 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2493 EXPECT_EQ(9, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2494
2495 // Trigger adapt up, expect increased fps (640x360@30fps).
2496 vie_encoder_->TriggerQualityHigh();
2497 timestamp_ms += kFrameIntervalMs;
2498 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2499 sink_.WaitForEncodedFrame(timestamp_ms);
2500 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants());
2501 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2502 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2503 EXPECT_EQ(10, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2504
2505 // Trigger adapt up, expect upscaled resolution (960x540@30fps).
2506 vie_encoder_->TriggerQualityHigh();
2507 timestamp_ms += kFrameIntervalMs;
2508 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2509 sink_.WaitForEncodedFrame(timestamp_ms);
2510 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
2511 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2512 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2513 EXPECT_EQ(11, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2514
2515 // Trigger adapt up, expect no restriction (1280x720fps@30fps).
2516 vie_encoder_->TriggerQualityHigh();
2517 timestamp_ms += kFrameIntervalMs;
2518 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2519 sink_.WaitForEncodedFrame(kWidth, kHeight);
2520 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
2521 VerifyNoLimitation(source.sink_wants());
2522 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2523 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2524 EXPECT_EQ(12, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2525
2526 // Trigger adapt up, expect no change.
2527 vie_encoder_->TriggerQualityHigh();
2528 VerifyNoLimitation(source.sink_wants());
2529 EXPECT_EQ(12, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2530
2531 vie_encoder_->Stop();
2532 }
2533
2534 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Framerate) {
2535 const int kWidth = 1280;
2536 const int kHeight = 720;
2537 const int64_t kFrameIntervalMs = 150;
2538 int64_t timestamp_ms = kFrameIntervalMs;
2539 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps, 0, 0);
2540
2541 // Enable kBalanced preference, no initial limitation.
2542 AdaptingFrameForwarder source;
2543 source.set_adaptation_enabled(true);
2544 vie_encoder_->SetSource(&source,
2545 VideoSendStream::DegradationPreference::kBalanced);
2546 timestamp_ms += kFrameIntervalMs;
2547 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2548 sink_.WaitForEncodedFrame(kWidth, kHeight);
2549 VerifyNoLimitation(source.sink_wants());
2550 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2551 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2552 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2553 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2554 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2555 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2556
2557 // Trigger cpu adapt down, expect scaled down resolution (960x540@30fps).
2558 vie_encoder_->TriggerCpuOveruse();
2559 timestamp_ms += kFrameIntervalMs;
2560 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2561 sink_.WaitForEncodedFrame(timestamp_ms);
2562 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
2563 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2564 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2565 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2566 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2567 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2568 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2569
2570 // Trigger cpu adapt down, expect scaled down resolution (640x360@30fps).
2571 vie_encoder_->TriggerCpuOveruse();
2572 timestamp_ms += kFrameIntervalMs;
2573 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2574 sink_.WaitForEncodedFrame(timestamp_ms);
2575 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants());
2576 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2577 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2578 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2579 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2580 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2581 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2582
2583 // Trigger quality adapt down, expect reduced fps (640x360@15fps).
2584 vie_encoder_->TriggerQualityLow();
2585 timestamp_ms += kFrameIntervalMs;
2586 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2587 sink_.WaitForEncodedFrame(timestamp_ms);
2588 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants());
2589 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2590 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2591 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2592 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2593 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2594 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2595
2596 // Trigger cpu adapt up, expect increased fps (640x360@30fps).
2597 vie_encoder_->TriggerCpuNormalUsage();
2598 timestamp_ms += kFrameIntervalMs;
2599 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2600 sink_.WaitForEncodedFrame(timestamp_ms);
2601 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants());
2602 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2603 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2604 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2605 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2606 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2607 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2608
2609 // Trigger quality adapt up, expect upscaled resolution (960x540@30fps).
2610 vie_encoder_->TriggerQualityHigh();
2611 timestamp_ms += kFrameIntervalMs;
2612 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2613 sink_.WaitForEncodedFrame(timestamp_ms);
2614 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
2615 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2616 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2617 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
2618 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2619 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2620 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2621
2622 // Trigger cpu adapt up, expect no restriction (1280x720fps@30fps).
2623 vie_encoder_->TriggerCpuNormalUsage();
2624 timestamp_ms += kFrameIntervalMs;
2625 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2626 sink_.WaitForEncodedFrame(kWidth, kHeight);
2627 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
2628 VerifyNoLimitation(source.sink_wants());
2629 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2630 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2631 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2632 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2633 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2634 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2635
2636 // Trigger adapt up, expect no change.
2637 vie_encoder_->TriggerQualityHigh();
2638 VerifyNoLimitation(source.sink_wants());
2639 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2640 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2641
2642 vie_encoder_->Stop();
2643 }
2644
2645 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Resolution) {
2646 const int kWidth = 640;
2647 const int kHeight = 360;
2648 const int kFpsLimit = 15;
2649 const int64_t kFrameIntervalMs = 150;
2650 int64_t timestamp_ms = kFrameIntervalMs;
2651 vie_encoder_->OnBitrateUpdated(kBpsLimitFor15Fps, 0, 0);
2652
2653 // Enable kBalanced preference, no initial limitation.
2654 AdaptingFrameForwarder source;
2655 source.set_adaptation_enabled(true);
2656 vie_encoder_->SetSource(&source,
2657 VideoSendStream::DegradationPreference::kBalanced);
2658 timestamp_ms += kFrameIntervalMs;
2659 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2660 sink_.WaitForEncodedFrame(kWidth, kHeight);
2661 VerifyNoLimitation(source.sink_wants());
2662 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2663 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2664 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2665 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2666 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2667 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2668
2669 // Trigger cpu adapt down, expect scaled down framerate (640x360@15fps).
2670 vie_encoder_->TriggerCpuOveruse();
2671 timestamp_ms += kFrameIntervalMs;
2672 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2673 sink_.WaitForEncodedFrame(timestamp_ms);
2674 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit);
2675 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2676 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2677 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2678 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate);
2679 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2680 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2681
2682 // Trigger quality adapt down, expect scaled down resolution (480x270@15fps).
2683 vie_encoder_->TriggerQualityLow();
2684 timestamp_ms += kFrameIntervalMs;
2685 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2686 sink_.WaitForEncodedFrame(timestamp_ms);
2687 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants());
2688 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
2689 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2690 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2691 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate);
2692 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2693 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2694
2695 // Trigger cpu adapt up, expect upscaled resolution (640x360@15fps).
2696 vie_encoder_->TriggerCpuNormalUsage();
2697 timestamp_ms += kFrameIntervalMs;
2698 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2699 sink_.WaitForEncodedFrame(timestamp_ms);
2700 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants());
2701 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2702 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate);
2703 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2704 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2705 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2706 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2707
2708 // Trigger quality adapt up, expect increased fps (640x360@30fps).
2709 vie_encoder_->TriggerQualityHigh();
2710 timestamp_ms += kFrameIntervalMs;
2711 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight));
2712 sink_.WaitForEncodedFrame(timestamp_ms);
2713 VerifyNoLimitation(source.sink_wants());
2714 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
2715 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate);
2716 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
2717 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
2718 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2719 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2720
2721 // Trigger adapt up, expect no change.
2722 vie_encoder_->TriggerQualityHigh();
2723 VerifyNoLimitation(source.sink_wants());
2724 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
2725 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
2726
2727 vie_encoder_->Stop();
2728 }
2729
2115 } // namespace webrtc 2730 } // namespace webrtc
OLDNEW
« webrtc/video/vie_encoder.cc ('K') | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698