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

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

Issue 2871623002: Update video adaptation stats to support degradations in both resolution and framerate. (Closed)
Patch Set: 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
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void set_adaptation_enabled(bool enabled) { 132 void set_adaptation_enabled(bool enabled) {
133 rtc::CritScope cs(&crit_); 133 rtc::CritScope cs(&crit_);
134 adaptation_enabled_ = enabled; 134 adaptation_enabled_ = enabled;
135 } 135 }
136 136
137 bool adaption_enabled() const { 137 bool adaption_enabled() const {
138 rtc::CritScope cs(&crit_); 138 rtc::CritScope cs(&crit_);
139 return adaptation_enabled_; 139 return adaptation_enabled_;
140 } 140 }
141 141
142 rtc::VideoSinkWants last_wants() const {
143 rtc::CritScope cs(&crit_);
144 return last_wants_;
145 }
146
142 void IncomingCapturedFrame(const VideoFrame& video_frame) override { 147 void IncomingCapturedFrame(const VideoFrame& video_frame) override {
143 int cropped_width = 0; 148 int cropped_width = 0;
144 int cropped_height = 0; 149 int cropped_height = 0;
145 int out_width = 0; 150 int out_width = 0;
146 int out_height = 0; 151 int out_height = 0;
147 if (adaption_enabled()) { 152 if (adaption_enabled()) {
148 if (adapter_.AdaptFrameResolution( 153 if (adapter_.AdaptFrameResolution(
149 video_frame.width(), video_frame.height(), 154 video_frame.width(), video_frame.height(),
150 video_frame.timestamp_us() * 1000, &cropped_width, 155 video_frame.timestamp_us() * 1000, &cropped_width,
151 &cropped_height, &out_width, &out_height)) { 156 &cropped_height, &out_width, &out_height)) {
152 VideoFrame adapted_frame(new rtc::RefCountedObject<TestBuffer>( 157 VideoFrame adapted_frame(new rtc::RefCountedObject<TestBuffer>(
153 nullptr, out_width, out_height), 158 nullptr, out_width, out_height),
154 99, 99, kVideoRotation_0); 159 99, 99, kVideoRotation_0);
155 adapted_frame.set_ntp_time_ms(video_frame.ntp_time_ms()); 160 adapted_frame.set_ntp_time_ms(video_frame.ntp_time_ms());
156 test::FrameForwarder::IncomingCapturedFrame(adapted_frame); 161 test::FrameForwarder::IncomingCapturedFrame(adapted_frame);
157 } 162 }
158 } else { 163 } else {
159 test::FrameForwarder::IncomingCapturedFrame(video_frame); 164 test::FrameForwarder::IncomingCapturedFrame(video_frame);
160 } 165 }
161 } 166 }
162 167
163 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, 168 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
164 const rtc::VideoSinkWants& wants) override { 169 const rtc::VideoSinkWants& wants) override {
165 rtc::CritScope cs(&crit_); 170 rtc::CritScope cs(&crit_);
171 last_wants_ = sink_wants();
166 adapter_.OnResolutionFramerateRequest(wants.target_pixel_count, 172 adapter_.OnResolutionFramerateRequest(wants.target_pixel_count,
167 wants.max_pixel_count, 173 wants.max_pixel_count,
168 wants.max_framerate_fps); 174 wants.max_framerate_fps);
169 test::FrameForwarder::AddOrUpdateSink(sink, wants); 175 test::FrameForwarder::AddOrUpdateSink(sink, wants);
170 } 176 }
171
172 cricket::VideoAdapter adapter_; 177 cricket::VideoAdapter adapter_;
173 bool adaptation_enabled_ GUARDED_BY(crit_); 178 bool adaptation_enabled_ GUARDED_BY(crit_);
179 rtc::VideoSinkWants last_wants_ GUARDED_BY(crit_);
174 }; 180 };
175 181
176 class MockableSendStatisticsProxy : public SendStatisticsProxy { 182 class MockableSendStatisticsProxy : public SendStatisticsProxy {
177 public: 183 public:
178 MockableSendStatisticsProxy(Clock* clock, 184 MockableSendStatisticsProxy(Clock* clock,
179 const VideoSendStream::Config& config, 185 const VideoSendStream::Config& config,
180 VideoEncoderConfig::ContentType content_type) 186 VideoEncoderConfig::ContentType content_type)
181 : SendStatisticsProxy(clock, config, content_type) {} 187 : SendStatisticsProxy(clock, config, content_type) {}
182 188
183 VideoSendStream::Stats GetStats() override { 189 VideoSendStream::Stats GetStats() override {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 VideoFrame CreateFrame(int64_t ntp_time_ms, int width, int height) const { 280 VideoFrame CreateFrame(int64_t ntp_time_ms, int width, int height) const {
275 VideoFrame frame( 281 VideoFrame frame(
276 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99, 282 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99,
277 kVideoRotation_0); 283 kVideoRotation_0);
278 frame.set_ntp_time_ms(ntp_time_ms); 284 frame.set_ntp_time_ms(ntp_time_ms);
279 frame.set_timestamp_us(ntp_time_ms * 1000); 285 frame.set_timestamp_us(ntp_time_ms * 1000);
280 return frame; 286 return frame;
281 } 287 }
282 288
283 void VerifyNoLimitation(const rtc::VideoSinkWants& wants) { 289 void VerifyNoLimitation(const rtc::VideoSinkWants& wants) {
290 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps);
291 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count);
284 EXPECT_FALSE(wants.target_pixel_count); 292 EXPECT_FALSE(wants.target_pixel_count);
285 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count);
286 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps);
287 } 293 }
288 294
289 void VerifyResolutionLimitationLessThan(const rtc::VideoSinkWants& wants, 295 void VerifyFpsEqResolutionEq(const rtc::VideoSinkWants& wants1,
290 int pixel_count) { 296 const rtc::VideoSinkWants& wants2) {
297 EXPECT_EQ(wants1.max_framerate_fps, wants2.max_framerate_fps);
298 EXPECT_EQ(wants1.max_pixel_count, wants2.max_pixel_count);
299 }
300
301 void VerifyFpsMaxResolutionLt(const rtc::VideoSinkWants& wants1,
302 const rtc::VideoSinkWants& wants2) {
303 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps);
304 EXPECT_LT(wants1.max_pixel_count, wants2.max_pixel_count);
305 EXPECT_GT(wants1.max_pixel_count, 0);
306 }
307
308 void VerifyFpsMaxResolutionGt(const rtc::VideoSinkWants& wants1,
309 const rtc::VideoSinkWants& wants2) {
310 EXPECT_EQ(std::numeric_limits<int>::max(), wants1.max_framerate_fps);
311 EXPECT_GT(wants1.max_pixel_count, wants2.max_pixel_count);
312 }
313
314 void VerifyFpsMaxResolutionLt(const rtc::VideoSinkWants& wants,
315 int pixel_count) {
316 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps);
291 EXPECT_LT(wants.max_pixel_count, pixel_count); 317 EXPECT_LT(wants.max_pixel_count, pixel_count);
292 EXPECT_GT(wants.max_pixel_count, 0); 318 EXPECT_GT(wants.max_pixel_count, 0);
293 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_framerate_fps); 319 }
320
321 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) {
322 EXPECT_LT(wants.max_framerate_fps, fps);
323 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count);
324 EXPECT_FALSE(wants.target_pixel_count);
294 } 325 }
295 326
296 class TestEncoder : public test::FakeEncoder { 327 class TestEncoder : public test::FakeEncoder {
297 public: 328 public:
298 TestEncoder() 329 TestEncoder()
299 : FakeEncoder(Clock::GetRealTimeClock()), 330 : FakeEncoder(Clock::GetRealTimeClock()),
300 continue_encode_event_(false, false) {} 331 continue_encode_event_(false, false) {}
301 332
302 VideoCodec codec_config() const { 333 VideoCodec codec_config() const {
303 rtc::CritScope lock(&crit_sect_); 334 rtc::CritScope lock(&crit_sect_);
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 } 970 }
940 971
941 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { 972 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) {
942 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 973 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
943 974
944 const int kWidth = 1280; 975 const int kWidth = 1280;
945 const int kHeight = 720; 976 const int kHeight = 720;
946 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); 977 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
947 sink_.WaitForEncodedFrame(1); 978 sink_.WaitForEncodedFrame(1);
948 VideoSendStream::Stats stats = stats_proxy_->GetStats(); 979 VideoSendStream::Stats stats = stats_proxy_->GetStats();
980 EXPECT_FALSE(stats.bw_limited_resolution);
949 EXPECT_FALSE(stats.cpu_limited_resolution); 981 EXPECT_FALSE(stats.cpu_limited_resolution);
950 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); 982 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes);
951 983
952 // Trigger CPU overuse. 984 // Trigger CPU overuse.
953 vie_encoder_->TriggerCpuOveruse(); 985 vie_encoder_->TriggerCpuOveruse();
954 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); 986 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
955 sink_.WaitForEncodedFrame(2); 987 sink_.WaitForEncodedFrame(2);
956 stats = stats_proxy_->GetStats(); 988 stats = stats_proxy_->GetStats();
989 EXPECT_FALSE(stats.bw_limited_resolution);
957 EXPECT_TRUE(stats.cpu_limited_resolution); 990 EXPECT_TRUE(stats.cpu_limited_resolution);
958 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); 991 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
959 992
960 // Set new source with adaptation still enabled. 993 // Set new source with adaptation still enabled.
961 test::FrameForwarder new_video_source; 994 test::FrameForwarder new_video_source;
962 vie_encoder_->SetSource( 995 vie_encoder_->SetSource(
963 &new_video_source, 996 &new_video_source,
964 VideoSendStream::DegradationPreference::kMaintainFramerate); 997 VideoSendStream::DegradationPreference::kMaintainFramerate);
965 998
966 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); 999 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight));
967 sink_.WaitForEncodedFrame(3); 1000 sink_.WaitForEncodedFrame(3);
968 stats = stats_proxy_->GetStats(); 1001 stats = stats_proxy_->GetStats();
1002 EXPECT_FALSE(stats.bw_limited_resolution);
969 EXPECT_TRUE(stats.cpu_limited_resolution); 1003 EXPECT_TRUE(stats.cpu_limited_resolution);
970 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); 1004 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
971 1005
972 // Set adaptation disabled. 1006 // Set adaptation disabled.
973 vie_encoder_->SetSource( 1007 vie_encoder_->SetSource(
974 &new_video_source, 1008 &new_video_source,
975 VideoSendStream::DegradationPreference::kDegradationDisabled); 1009 VideoSendStream::DegradationPreference::kDegradationDisabled);
976 1010
977 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); 1011 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight));
978 sink_.WaitForEncodedFrame(4); 1012 sink_.WaitForEncodedFrame(4);
979 stats = stats_proxy_->GetStats(); 1013 stats = stats_proxy_->GetStats();
1014 EXPECT_FALSE(stats.bw_limited_resolution);
980 EXPECT_FALSE(stats.cpu_limited_resolution); 1015 EXPECT_FALSE(stats.cpu_limited_resolution);
981 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); 1016 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
982 1017
983 // Set adaptation back to enabled. 1018 // Set adaptation back to enabled.
984 vie_encoder_->SetSource( 1019 vie_encoder_->SetSource(
985 &new_video_source, 1020 &new_video_source,
986 VideoSendStream::DegradationPreference::kMaintainFramerate); 1021 VideoSendStream::DegradationPreference::kMaintainFramerate);
987 1022
988 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); 1023 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight));
989 sink_.WaitForEncodedFrame(5); 1024 sink_.WaitForEncodedFrame(5);
990 stats = stats_proxy_->GetStats(); 1025 stats = stats_proxy_->GetStats();
1026 EXPECT_FALSE(stats.bw_limited_resolution);
991 EXPECT_TRUE(stats.cpu_limited_resolution); 1027 EXPECT_TRUE(stats.cpu_limited_resolution);
992 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); 1028 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
993 1029
994 // Trigger CPU normal use. 1030 // Trigger CPU normal use.
995 vie_encoder_->TriggerCpuNormalUsage(); 1031 vie_encoder_->TriggerCpuNormalUsage();
996 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); 1032 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight));
997 sink_.WaitForEncodedFrame(6); 1033 sink_.WaitForEncodedFrame(6);
998 stats = stats_proxy_->GetStats(); 1034 stats = stats_proxy_->GetStats();
1035 EXPECT_FALSE(stats.bw_limited_resolution);
999 EXPECT_FALSE(stats.cpu_limited_resolution); 1036 EXPECT_FALSE(stats.cpu_limited_resolution);
1000 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); 1037 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes);
1001 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); 1038 EXPECT_EQ(0, stats.number_of_quality_adapt_changes);
1002 1039
1003 vie_encoder_->Stop(); 1040 vie_encoder_->Stop();
1004 } 1041 }
1005 1042
1006 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { 1043 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) {
1007 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1044 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1008 1045
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 test::FrameForwarder new_video_source; 1168 test::FrameForwarder new_video_source;
1132 vie_encoder_->SetSource( 1169 vie_encoder_->SetSource(
1133 &new_video_source, 1170 &new_video_source,
1134 VideoSendStream::DegradationPreference::kMaintainFramerate); 1171 VideoSendStream::DegradationPreference::kMaintainFramerate);
1135 1172
1136 new_video_source.IncomingCapturedFrame( 1173 new_video_source.IncomingCapturedFrame(
1137 CreateFrame(sequence, kWidth, kHeight)); 1174 CreateFrame(sequence, kWidth, kHeight));
1138 sink_.WaitForEncodedFrame(sequence++); 1175 sink_.WaitForEncodedFrame(sequence++);
1139 stats = stats_proxy_->GetStats(); 1176 stats = stats_proxy_->GetStats();
1140 EXPECT_TRUE(stats.cpu_limited_resolution); 1177 EXPECT_TRUE(stats.cpu_limited_resolution);
1178 EXPECT_FALSE(stats.cpu_limited_framerate);
1141 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); 1179 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
1142 1180
1143 // Set cpu adaptation by frame dropping. 1181 // Set cpu adaptation by frame dropping.
1144 vie_encoder_->SetSource( 1182 vie_encoder_->SetSource(
1145 &new_video_source, 1183 &new_video_source,
1146 VideoSendStream::DegradationPreference::kMaintainResolution); 1184 VideoSendStream::DegradationPreference::kMaintainResolution);
1147 new_video_source.IncomingCapturedFrame( 1185 new_video_source.IncomingCapturedFrame(
1148 CreateFrame(sequence, kWidth, kHeight)); 1186 CreateFrame(sequence, kWidth, kHeight));
1149 sink_.WaitForEncodedFrame(sequence++); 1187 sink_.WaitForEncodedFrame(sequence++);
1150 stats = stats_proxy_->GetStats(); 1188 stats = stats_proxy_->GetStats();
1151 // Not adapted at first. 1189 // Not adapted at first.
1152 EXPECT_FALSE(stats.cpu_limited_resolution); 1190 EXPECT_FALSE(stats.cpu_limited_resolution);
1191 EXPECT_FALSE(stats.cpu_limited_framerate);
1153 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); 1192 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
1154 1193
1155 // Force an input frame rate to be available, or the adaptation call won't 1194 // Force an input frame rate to be available, or the adaptation call won't
1156 // know what framerate to adapt form. 1195 // know what framerate to adapt from.
1157 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); 1196 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats();
1158 mock_stats.input_frame_rate = 30; 1197 mock_stats.input_frame_rate = 30;
1159 stats_proxy_->SetMockStats(mock_stats); 1198 stats_proxy_->SetMockStats(mock_stats);
1160 vie_encoder_->TriggerCpuOveruse(); 1199 vie_encoder_->TriggerCpuOveruse();
1161 stats_proxy_->ResetMockStats(); 1200 stats_proxy_->ResetMockStats();
1162 1201
1163 new_video_source.IncomingCapturedFrame( 1202 new_video_source.IncomingCapturedFrame(
1164 CreateFrame(sequence, kWidth, kHeight)); 1203 CreateFrame(sequence, kWidth, kHeight));
1165 sink_.WaitForEncodedFrame(sequence++); 1204 sink_.WaitForEncodedFrame(sequence++);
1166 1205
1167 // Framerate now adapted. 1206 // Framerate now adapted.
1168 stats = stats_proxy_->GetStats(); 1207 stats = stats_proxy_->GetStats();
1169 EXPECT_TRUE(stats.cpu_limited_resolution); 1208 EXPECT_FALSE(stats.cpu_limited_resolution);
1209 EXPECT_TRUE(stats.cpu_limited_framerate);
1170 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); 1210 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes);
1171 1211
1172 // Disable CPU adaptation. 1212 // Disable CPU adaptation.
1173 vie_encoder_->SetSource( 1213 vie_encoder_->SetSource(
1174 &new_video_source, 1214 &new_video_source,
1175 VideoSendStream::DegradationPreference::kDegradationDisabled); 1215 VideoSendStream::DegradationPreference::kDegradationDisabled);
1176 new_video_source.IncomingCapturedFrame( 1216 new_video_source.IncomingCapturedFrame(
1177 CreateFrame(sequence, kWidth, kHeight)); 1217 CreateFrame(sequence, kWidth, kHeight));
1178 sink_.WaitForEncodedFrame(sequence++); 1218 sink_.WaitForEncodedFrame(sequence++);
1179 1219
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); 1347 &source, VideoSendStream::DegradationPreference::kMaintainFramerate);
1308 1348
1309 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); 1349 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1310 sink_.WaitForEncodedFrame(1); 1350 sink_.WaitForEncodedFrame(1);
1311 VerifyNoLimitation(source.sink_wants()); 1351 VerifyNoLimitation(source.sink_wants());
1312 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1352 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1313 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1353 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1314 1354
1315 // Trigger adapt down, expect scaled down resolution. 1355 // Trigger adapt down, expect scaled down resolution.
1316 vie_encoder_->TriggerCpuOveruse(); 1356 vie_encoder_->TriggerCpuOveruse();
1317 VerifyResolutionLimitationLessThan(source.sink_wants(), kWidth * kHeight); 1357 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1318 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; 1358 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count;
1319 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1359 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1320 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1360 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1321 1361
1322 // Trigger adapt down for same input resolution, expect no change. 1362 // Trigger adapt down for same input resolution, expect no change.
1323 vie_encoder_->TriggerCpuOveruse(); 1363 vie_encoder_->TriggerCpuOveruse();
1324 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); 1364 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count);
1325 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1365 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1326 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1366 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1327 1367
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1399 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1360 1400
1361 // Enable kMaintainResolution preference, no initial limitation. 1401 // Enable kMaintainResolution preference, no initial limitation.
1362 test::FrameForwarder source; 1402 test::FrameForwarder source;
1363 vie_encoder_->SetSource( 1403 vie_encoder_->SetSource(
1364 &source, VideoSendStream::DegradationPreference::kMaintainResolution); 1404 &source, VideoSendStream::DegradationPreference::kMaintainResolution);
1365 1405
1366 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); 1406 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1367 sink_.WaitForEncodedFrame(kWidth, kHeight); 1407 sink_.WaitForEncodedFrame(kWidth, kHeight);
1368 VerifyNoLimitation(source.sink_wants()); 1408 VerifyNoLimitation(source.sink_wants());
1369 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1409 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1370 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1410 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1371 1411
1372 // Trigger adapt up, expect no change. 1412 // Trigger adapt up, expect no change.
1373 vie_encoder_->TriggerCpuNormalUsage(); 1413 vie_encoder_->TriggerCpuNormalUsage();
1374 VerifyNoLimitation(source.sink_wants()); 1414 VerifyNoLimitation(source.sink_wants());
1375 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1415 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1376 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1416 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1377 1417
1378 vie_encoder_->Stop(); 1418 vie_encoder_->Stop();
1379 } 1419 }
1380 1420
1421 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_DisabledMode) {
1422 const int kWidth = 1280;
1423 const int kHeight = 720;
1424 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1425
1426 // Enable kDegradationDisabled preference, no initial limitation.
1427 test::FrameForwarder source;
1428 vie_encoder_->SetSource(
1429 &source, VideoSendStream::DegradationPreference::kDegradationDisabled);
1430
1431 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1432 sink_.WaitForEncodedFrame(kWidth, kHeight);
1433 VerifyNoLimitation(source.sink_wants());
1434 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1435 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1436 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1437
1438 // Trigger adapt up, expect no change.
1439 vie_encoder_->TriggerQualityHigh();
1440 VerifyNoLimitation(source.sink_wants());
1441 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1442 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate);
1443 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1444
1445 vie_encoder_->Stop();
1446 }
1447
1381 TEST_F(ViEEncoderTest, AdaptsResolutionForLowQuality_MaintainFramerateMode) { 1448 TEST_F(ViEEncoderTest, AdaptsResolutionForLowQuality_MaintainFramerateMode) {
1382 const int kWidth = 1280; 1449 const int kWidth = 1280;
1383 const int kHeight = 720; 1450 const int kHeight = 720;
1384 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1451 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1385 1452
1386 // Enable kMaintainFramerate preference, no initial limitation. 1453 // Enable kMaintainFramerate preference, no initial limitation.
1387 AdaptingFrameForwarder source; 1454 AdaptingFrameForwarder source;
1388 source.set_adaptation_enabled(true); 1455 source.set_adaptation_enabled(true);
1389 vie_encoder_->SetSource( 1456 vie_encoder_->SetSource(
1390 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); 1457 &source, VideoSendStream::DegradationPreference::kMaintainFramerate);
1391 1458
1392 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); 1459 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1393 sink_.WaitForEncodedFrame(1); 1460 sink_.WaitForEncodedFrame(1);
1394 VerifyNoLimitation(source.sink_wants()); 1461 VerifyNoLimitation(source.sink_wants());
1395 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); 1462 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1396 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1463 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1397 1464
1398 // Trigger adapt down, expect scaled down resolution. 1465 // Trigger adapt down, expect scaled down resolution.
1399 vie_encoder_->TriggerQualityLow(); 1466 vie_encoder_->TriggerQualityLow();
1400 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); 1467 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1401 sink_.WaitForEncodedFrame(2); 1468 sink_.WaitForEncodedFrame(2);
1402 VerifyResolutionLimitationLessThan(source.sink_wants(), kWidth * kHeight); 1469 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1403 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); 1470 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1404 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1471 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1405 1472
1406 // Trigger adapt up, expect no restriction. 1473 // Trigger adapt up, expect no restriction.
1407 vie_encoder_->TriggerQualityHigh(); 1474 vie_encoder_->TriggerQualityHigh();
1408 VerifyNoLimitation(source.sink_wants()); 1475 VerifyNoLimitation(source.sink_wants());
1409 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); 1476 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1410 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1477 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1411 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1478 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1412 1479
1413 vie_encoder_->Stop(); 1480 vie_encoder_->Stop();
1414 } 1481 }
1415 1482
1483 TEST_F(ViEEncoderTest, AdaptsFramerateForLowQuality_MaintainResolutionMode) {
1484 const int kWidth = 1280;
1485 const int kHeight = 720;
1486 const int kInputFps = 30;
1487 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1488
1489 VideoSendStream::Stats stats = stats_proxy_->GetStats();
1490 stats.input_frame_rate = kInputFps;
1491 stats_proxy_->SetMockStats(stats);
1492
1493 // Expect no scaling to begin with (preference: kMaintainFramerate).
1494 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1495 sink_.WaitForEncodedFrame(1);
1496 VerifyNoLimitation(video_source_.sink_wants());
1497
1498 // Trigger adapt down, expect scaled down resolution.
1499 vie_encoder_->TriggerQualityLow();
1500 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1501 sink_.WaitForEncodedFrame(2);
1502 VerifyFpsMaxResolutionLt(video_source_.sink_wants(), kWidth * kHeight);
1503
1504 // Enable kMaintainResolution preference.
1505 test::FrameForwarder new_video_source;
1506 vie_encoder_->SetSource(
1507 &new_video_source,
1508 VideoSendStream::DegradationPreference::kMaintainResolution);
1509 VerifyNoLimitation(new_video_source.sink_wants());
1510
1511 // Trigger adapt down, expect reduced framerate.
1512 vie_encoder_->TriggerQualityLow();
1513 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight));
1514 sink_.WaitForEncodedFrame(3);
1515 VerifyFpsLtResolutionMax(new_video_source.sink_wants(), kInputFps);
1516
1517 // Trigger adapt up, expect no restriction.
1518 vie_encoder_->TriggerQualityHigh();
1519 VerifyNoLimitation(new_video_source.sink_wants());
1520
1521 vie_encoder_->Stop();
1522 }
1523
1416 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetResolutionLimit) { 1524 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetResolutionLimit) {
1417 const int kWidth = 1280; 1525 const int kWidth = 1280;
1418 const int kHeight = 720; 1526 const int kHeight = 720;
1419 const size_t kNumFrames = 10; 1527 const size_t kNumFrames = 10;
1420 1528
1421 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1529 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1422 1530
1423 // Enable adapter, expected input resolutions when downscaling: 1531 // Enable adapter, expected input resolutions when downscaling:
1424 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) 1532 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit)
1425 video_source_.set_adaptation_enabled(true); 1533 video_source_.set_adaptation_enabled(true);
(...skipping 28 matching lines...) Expand all
1454 const int kHeight = 720; 1562 const int kHeight = 720;
1455 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 1563 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1456 1564
1457 // Enable kMaintainFramerate preference, no initial limitation. 1565 // Enable kMaintainFramerate preference, no initial limitation.
1458 AdaptingFrameForwarder source; 1566 AdaptingFrameForwarder source;
1459 source.set_adaptation_enabled(true); 1567 source.set_adaptation_enabled(true);
1460 vie_encoder_->SetSource( 1568 vie_encoder_->SetSource(
1461 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); 1569 &source, VideoSendStream::DegradationPreference::kMaintainFramerate);
1462 1570
1463 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); 1571 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1464 sink_.WaitForEncodedFrame(1); 1572 sink_.WaitForEncodedFrame(kWidth, kHeight);
1465 VerifyNoLimitation(source.sink_wants()); 1573 VerifyNoLimitation(source.sink_wants());
1466 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1574 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1467 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1575 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1468 1576
1469 // Trigger adapt down, expect scaled down resolution. 1577 // Trigger adapt down, expect scaled down resolution.
1470 vie_encoder_->TriggerCpuOveruse(); 1578 vie_encoder_->TriggerCpuOveruse();
1471 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); 1579 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1472 sink_.WaitForEncodedFrame(2); 1580 sink_.WaitForEncodedFrame(2);
1473 VerifyResolutionLimitationLessThan(source.sink_wants(), kWidth * kHeight); 1581 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1474 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1582 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1475 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1583 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1476 1584
1477 // Trigger adapt up, expect no restriction. 1585 // Trigger adapt up, expect no restriction.
1478 vie_encoder_->TriggerCpuNormalUsage(); 1586 vie_encoder_->TriggerCpuNormalUsage();
1479 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); 1587 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight));
1480 sink_.WaitForEncodedFrame(3); 1588 sink_.WaitForEncodedFrame(kWidth, kHeight);
1481 VerifyNoLimitation(source.sink_wants()); 1589 VerifyNoLimitation(source.sink_wants());
1482 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1590 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1483 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1591 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1484 1592
1485 // Trigger adapt down, expect scaled down resolution. 1593 // Trigger adapt down, expect scaled down resolution.
1486 vie_encoder_->TriggerCpuOveruse(); 1594 vie_encoder_->TriggerCpuOveruse();
1487 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); 1595 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight));
1488 sink_.WaitForEncodedFrame(4); 1596 sink_.WaitForEncodedFrame(4);
1489 VerifyResolutionLimitationLessThan(source.sink_wants(), kWidth * kHeight); 1597 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1490 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1598 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1491 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1599 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1492 1600
1493 // Trigger adapt up, expect no restriction. 1601 // Trigger adapt up, expect no restriction.
1494 vie_encoder_->TriggerCpuNormalUsage(); 1602 vie_encoder_->TriggerCpuNormalUsage();
1603 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight));
1604 sink_.WaitForEncodedFrame(kWidth, kHeight);
1495 VerifyNoLimitation(source.sink_wants()); 1605 VerifyNoLimitation(source.sink_wants());
1496 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1606 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1497 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1607 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1498 1608
1499 vie_encoder_->Stop(); 1609 vie_encoder_->Stop();
1500 } 1610 }
1501 1611
1502 TEST_F(ViEEncoderTest, 1612 TEST_F(ViEEncoderTest,
1503 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { 1613 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) {
1504 const int kWidth = 1280; 1614 const int kWidth = 1280;
(...skipping 11 matching lines...) Expand all
1516 VerifyNoLimitation(source.sink_wants()); 1626 VerifyNoLimitation(source.sink_wants());
1517 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1627 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1518 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); 1628 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1519 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1629 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1520 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1630 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1521 1631
1522 // Trigger cpu adapt down, expect scaled down resolution (960x540). 1632 // Trigger cpu adapt down, expect scaled down resolution (960x540).
1523 vie_encoder_->TriggerCpuOveruse(); 1633 vie_encoder_->TriggerCpuOveruse();
1524 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); 1634 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
1525 sink_.WaitForEncodedFrame(2); 1635 sink_.WaitForEncodedFrame(2);
1526 VerifyResolutionLimitationLessThan(source.sink_wants(), kWidth * kHeight); 1636 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight);
1527 rtc::VideoSinkWants last_wants = source.sink_wants();
1528 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1637 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1529 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); 1638 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1530 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1639 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1531 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1640 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1532 1641
1533 // Trigger cpu adapt down, expect scaled down resolution (640x360). 1642 // Trigger cpu adapt down, expect scaled down resolution (640x360).
1534 vie_encoder_->TriggerCpuOveruse(); 1643 vie_encoder_->TriggerCpuOveruse();
1535 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); 1644 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight));
1536 sink_.WaitForEncodedFrame(3); 1645 sink_.WaitForEncodedFrame(3);
1537 EXPECT_LT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count); 1646 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants());
1538 last_wants = source.sink_wants(); 1647 rtc::VideoSinkWants last_wants = source.sink_wants();
1539 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1648 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1540 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); 1649 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1541 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1650 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1542 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1651 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1543 1652
1544 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. 1653 // Trigger cpu adapt down, max cpu downgrades reached, expect no change.
1545 vie_encoder_->TriggerCpuOveruse(); 1654 vie_encoder_->TriggerCpuOveruse();
1546 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); 1655 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight));
1547 sink_.WaitForEncodedFrame(4); 1656 sink_.WaitForEncodedFrame(4);
1548 EXPECT_EQ(last_wants.max_pixel_count, source.sink_wants().max_pixel_count); 1657 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants);
1549 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1658 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1550 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); 1659 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1551 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1660 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1552 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1661 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1553 1662
1554 // Trigger quality adapt down, expect scaled down resolution (480x270). 1663 // Trigger quality adapt down, expect scaled down resolution (480x270).
1555 vie_encoder_->TriggerQualityLow(); 1664 vie_encoder_->TriggerQualityLow();
1556 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); 1665 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight));
1557 sink_.WaitForEncodedFrame(5); 1666 sink_.WaitForEncodedFrame(5);
1558 EXPECT_LT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count); 1667 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants());
1559 last_wants = source.sink_wants();
1560 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1668 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1561 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); 1669 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1562 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1670 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1563 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1671 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1564 1672
1565 // Trigger cpu adapt up, expect upscaled resolution (640x360). 1673 // Trigger cpu adapt up, expect upscaled resolution (640x360).
1566 vie_encoder_->TriggerCpuNormalUsage(); 1674 vie_encoder_->TriggerCpuNormalUsage();
1567 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); 1675 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight));
1568 sink_.WaitForEncodedFrame(6); 1676 sink_.WaitForEncodedFrame(6);
1569 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count); 1677 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
1570 last_wants = source.sink_wants();
1571 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); 1678 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution);
1572 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); 1679 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1573 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1680 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1574 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1681 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1575 1682
1576 // Trigger cpu adapt up, expect upscaled resolution (960x540). 1683 // Trigger cpu adapt up, expect upscaled resolution (960x540).
1577 vie_encoder_->TriggerCpuNormalUsage(); 1684 vie_encoder_->TriggerCpuNormalUsage();
1578 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); 1685 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight));
1579 sink_.WaitForEncodedFrame(7); 1686 sink_.WaitForEncodedFrame(7);
1580 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count); 1687 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
1581 last_wants = source.sink_wants(); 1688 last_wants = source.sink_wants();
1582 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1689 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1583 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); 1690 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1584 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1691 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1585 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1692 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1586 1693
1587 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). 1694 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540).
1588 vie_encoder_->TriggerCpuNormalUsage(); 1695 vie_encoder_->TriggerCpuNormalUsage();
1589 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); 1696 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight));
1590 sink_.WaitForEncodedFrame(8); 1697 sink_.WaitForEncodedFrame(8);
1591 EXPECT_EQ(last_wants.max_pixel_count, source.sink_wants().max_pixel_count); 1698 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants);
1592 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1699 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1593 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); 1700 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution);
1594 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1701 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1595 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1702 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1596 1703
1597 // Trigger quality adapt up, expect no restriction (1280x720). 1704 // Trigger quality adapt up, expect no restriction (1280x720).
1598 vie_encoder_->TriggerQualityHigh(); 1705 vie_encoder_->TriggerQualityHigh();
1599 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); 1706 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight));
1600 sink_.WaitForEncodedFrame(kWidth, kHeight); 1707 sink_.WaitForEncodedFrame(kWidth, kHeight);
1601 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count); 1708 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants());
1602 VerifyNoLimitation(source.sink_wants()); 1709 VerifyNoLimitation(source.sink_wants());
1603 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); 1710 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution);
1604 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); 1711 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution);
1605 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); 1712 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes);
1606 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); 1713 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes);
1607 1714
1608 vie_encoder_->Stop(); 1715 vie_encoder_->Stop();
1609 } 1716 }
1610 1717
1611 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) { 1718 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); 1830 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4));
1724 1831
1725 // Expect to drop this frame, the wait should time out. 1832 // Expect to drop this frame, the wait should time out.
1726 sink_.ExpectDroppedFrame(); 1833 sink_.ExpectDroppedFrame();
1727 1834
1728 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); 1835 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count);
1729 1836
1730 vie_encoder_->Stop(); 1837 vie_encoder_->Stop();
1731 } 1838 }
1732 1839
1733 TEST_F(ViEEncoderTest, NrOfDroppedFramesLimitedWhenBitrateIsTooLow) { 1840 TEST_F(ViEEncoderTest, NumberOfDroppedFramesLimitedWhenBitrateIsTooLow) {
1734 const int kTooLowBitrateForFrameSizeBps = 10000; 1841 const int kTooLowBitrateForFrameSizeBps = 10000;
1735 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); 1842 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0);
1736 const int kWidth = 640; 1843 const int kWidth = 640;
1737 const int kHeight = 360; 1844 const int kHeight = 360;
1738 1845
1739 // We expect the n initial frames to get dropped. 1846 // We expect the n initial frames to get dropped.
1740 int i; 1847 int i;
1741 for (i = 1; i <= kMaxInitialFramedrop; ++i) { 1848 for (i = 1; i <= kMaxInitialFramedrop; ++i) {
1742 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); 1849 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight));
1743 sink_.ExpectDroppedFrame(); 1850 sink_.ExpectDroppedFrame();
(...skipping 23 matching lines...) Expand all
1767 sink_.WaitForEncodedFrame(1); 1874 sink_.WaitForEncodedFrame(1);
1768 1875
1769 vie_encoder_->Stop(); 1876 vie_encoder_->Stop();
1770 } 1877 }
1771 1878
1772 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { 1879 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) {
1773 const int kWidth = 640; 1880 const int kWidth = 640;
1774 const int kHeight = 360; 1881 const int kHeight = 360;
1775 fake_encoder_.SetQualityScaling(false); 1882 fake_encoder_.SetQualityScaling(false);
1776 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); 1883 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0);
1884
1777 // Force quality scaler reconfiguration by resetting the source. 1885 // Force quality scaler reconfiguration by resetting the source.
1778 vie_encoder_->SetSource(&video_source_, 1886 vie_encoder_->SetSource(&video_source_,
1779 VideoSendStream::DegradationPreference::kBalanced); 1887 VideoSendStream::DegradationPreference::kBalanced);
1780 1888
1781 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); 1889 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
1782 // Frame should not be dropped, even if it's too large. 1890 // Frame should not be dropped, even if it's too large.
1783 sink_.WaitForEncodedFrame(1); 1891 sink_.WaitForEncodedFrame(1);
1784 1892
1785 vie_encoder_->Stop(); 1893 vie_encoder_->Stop();
1786 fake_encoder_.SetQualityScaling(true); 1894 fake_encoder_.SetQualityScaling(true);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 for (int i = 0; i < 10; ++i) { 2106 for (int i = 0; i < 10; ++i) {
1999 timestamp_ms += kMinFpsFrameInterval; 2107 timestamp_ms += kMinFpsFrameInterval;
2000 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); 2108 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000);
2001 video_source_.IncomingCapturedFrame( 2109 video_source_.IncomingCapturedFrame(
2002 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); 2110 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight));
2003 sink_.WaitForEncodedFrame(timestamp_ms); 2111 sink_.WaitForEncodedFrame(timestamp_ms);
2004 } 2112 }
2005 vie_encoder_->Stop(); 2113 vie_encoder_->Stop();
2006 } 2114 }
2007 } // namespace webrtc 2115 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698