OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 } | 1041 } |
1042 | 1042 |
1043 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { | 1043 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { |
1044 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1044 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1045 | 1045 |
1046 const int kWidth = 1280; | 1046 const int kWidth = 1280; |
1047 const int kHeight = 720; | 1047 const int kHeight = 720; |
1048 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1048 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1049 sink_.WaitForEncodedFrame(1); | 1049 sink_.WaitForEncodedFrame(1); |
1050 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1050 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1051 EXPECT_FALSE(stats.cpu_limited_resolution); | |
1052 EXPECT_FALSE(stats.bw_limited_resolution); | 1051 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1052 EXPECT_FALSE(stats.bw_limited_framerate); |
1053 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1053 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1054 | 1054 |
1055 // Set new source with adaptation still enabled. | 1055 // Set new source with adaptation still enabled. |
1056 test::FrameForwarder new_video_source; | 1056 test::FrameForwarder new_video_source; |
1057 vie_encoder_->SetSource(&new_video_source, | 1057 vie_encoder_->SetSource(&new_video_source, |
1058 VideoSendStream::DegradationPreference::kBalanced); | 1058 VideoSendStream::DegradationPreference::kBalanced); |
1059 | 1059 |
1060 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1060 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1061 sink_.WaitForEncodedFrame(2); | 1061 sink_.WaitForEncodedFrame(2); |
1062 stats = stats_proxy_->GetStats(); | 1062 stats = stats_proxy_->GetStats(); |
1063 EXPECT_FALSE(stats.cpu_limited_resolution); | |
1064 EXPECT_FALSE(stats.bw_limited_resolution); | 1063 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1064 EXPECT_FALSE(stats.bw_limited_framerate); |
1065 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1065 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1066 | 1066 |
1067 // Trigger adapt down. | 1067 // Trigger adapt down. |
1068 vie_encoder_->TriggerQualityLow(); | 1068 vie_encoder_->TriggerQualityLow(); |
1069 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1069 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1070 sink_.WaitForEncodedFrame(3); | 1070 sink_.WaitForEncodedFrame(3); |
1071 stats = stats_proxy_->GetStats(); | 1071 stats = stats_proxy_->GetStats(); |
1072 EXPECT_FALSE(stats.cpu_limited_resolution); | |
1073 EXPECT_TRUE(stats.bw_limited_resolution); | 1072 EXPECT_TRUE(stats.bw_limited_resolution); |
| 1073 EXPECT_FALSE(stats.bw_limited_framerate); |
1074 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1074 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1075 | 1075 |
1076 // Set new source with adaptation still enabled. | 1076 // Set new source with adaptation still enabled. |
1077 vie_encoder_->SetSource(&new_video_source, | 1077 vie_encoder_->SetSource(&new_video_source, |
1078 VideoSendStream::DegradationPreference::kBalanced); | 1078 VideoSendStream::DegradationPreference::kBalanced); |
1079 | 1079 |
1080 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1080 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1081 sink_.WaitForEncodedFrame(4); | 1081 sink_.WaitForEncodedFrame(4); |
1082 stats = stats_proxy_->GetStats(); | 1082 stats = stats_proxy_->GetStats(); |
1083 EXPECT_FALSE(stats.cpu_limited_resolution); | |
1084 EXPECT_TRUE(stats.bw_limited_resolution); | 1083 EXPECT_TRUE(stats.bw_limited_resolution); |
| 1084 EXPECT_FALSE(stats.bw_limited_framerate); |
1085 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1085 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1086 | 1086 |
1087 // Disable resolution scaling. | 1087 // Disable resolution scaling. |
1088 vie_encoder_->SetSource( | 1088 vie_encoder_->SetSource( |
1089 &new_video_source, | 1089 &new_video_source, |
1090 VideoSendStream::DegradationPreference::kMaintainResolution); | 1090 VideoSendStream::DegradationPreference::kMaintainResolution); |
1091 | 1091 |
1092 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1092 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1093 sink_.WaitForEncodedFrame(5); | 1093 sink_.WaitForEncodedFrame(5); |
1094 stats = stats_proxy_->GetStats(); | 1094 stats = stats_proxy_->GetStats(); |
1095 EXPECT_FALSE(stats.cpu_limited_resolution); | |
1096 EXPECT_FALSE(stats.bw_limited_resolution); | 1095 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1096 EXPECT_FALSE(stats.bw_limited_framerate); |
1097 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1097 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1098 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1098 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1099 | 1099 |
1100 vie_encoder_->Stop(); | 1100 vie_encoder_->Stop(); |
1101 } | 1101 } |
1102 | 1102 |
1103 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { | 1103 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { |
1104 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1104 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1105 | 1105 |
1106 const int kWidth = 1280; | 1106 const int kWidth = 1280; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1147 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1148 | 1148 |
1149 const int kWidth = 1280; | 1149 const int kWidth = 1280; |
1150 const int kHeight = 720; | 1150 const int kHeight = 720; |
1151 int sequence = 1; | 1151 int sequence = 1; |
1152 | 1152 |
1153 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1153 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1154 sink_.WaitForEncodedFrame(sequence++); | 1154 sink_.WaitForEncodedFrame(sequence++); |
1155 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1155 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1156 EXPECT_FALSE(stats.cpu_limited_resolution); | 1156 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1157 EXPECT_FALSE(stats.cpu_limited_framerate); |
1157 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1158 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1158 | 1159 |
1159 // Trigger CPU overuse, should now adapt down. | 1160 // Trigger CPU overuse, should now adapt down. |
1160 vie_encoder_->TriggerCpuOveruse(); | 1161 vie_encoder_->TriggerCpuOveruse(); |
1161 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1162 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1162 sink_.WaitForEncodedFrame(sequence++); | 1163 sink_.WaitForEncodedFrame(sequence++); |
1163 stats = stats_proxy_->GetStats(); | 1164 stats = stats_proxy_->GetStats(); |
1164 EXPECT_TRUE(stats.cpu_limited_resolution); | 1165 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1166 EXPECT_FALSE(stats.cpu_limited_framerate); |
1165 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1167 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1166 | 1168 |
1167 // Set new source with adaptation still enabled. | 1169 // Set new source with adaptation still enabled. |
1168 test::FrameForwarder new_video_source; | 1170 test::FrameForwarder new_video_source; |
1169 vie_encoder_->SetSource( | 1171 vie_encoder_->SetSource( |
1170 &new_video_source, | 1172 &new_video_source, |
1171 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1173 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1172 | 1174 |
1173 new_video_source.IncomingCapturedFrame( | 1175 new_video_source.IncomingCapturedFrame( |
1174 CreateFrame(sequence, kWidth, kHeight)); | 1176 CreateFrame(sequence, kWidth, kHeight)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 // Disable CPU adaptation. | 1214 // Disable CPU adaptation. |
1213 vie_encoder_->SetSource( | 1215 vie_encoder_->SetSource( |
1214 &new_video_source, | 1216 &new_video_source, |
1215 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1217 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1216 new_video_source.IncomingCapturedFrame( | 1218 new_video_source.IncomingCapturedFrame( |
1217 CreateFrame(sequence, kWidth, kHeight)); | 1219 CreateFrame(sequence, kWidth, kHeight)); |
1218 sink_.WaitForEncodedFrame(sequence++); | 1220 sink_.WaitForEncodedFrame(sequence++); |
1219 | 1221 |
1220 stats = stats_proxy_->GetStats(); | 1222 stats = stats_proxy_->GetStats(); |
1221 EXPECT_FALSE(stats.cpu_limited_resolution); | 1223 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1224 EXPECT_FALSE(stats.cpu_limited_framerate); |
1222 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1225 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1223 | 1226 |
1224 // Try to trigger overuse. Should not succeed. | 1227 // Try to trigger overuse. Should not succeed. |
1225 stats_proxy_->SetMockStats(mock_stats); | 1228 stats_proxy_->SetMockStats(mock_stats); |
1226 vie_encoder_->TriggerCpuOveruse(); | 1229 vie_encoder_->TriggerCpuOveruse(); |
1227 stats_proxy_->ResetMockStats(); | 1230 stats_proxy_->ResetMockStats(); |
1228 | 1231 |
1229 stats = stats_proxy_->GetStats(); | 1232 stats = stats_proxy_->GetStats(); |
1230 EXPECT_FALSE(stats.cpu_limited_resolution); | 1233 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1234 EXPECT_FALSE(stats.cpu_limited_framerate); |
1231 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1235 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1232 | 1236 |
1233 // Switch back the source with resolution adaptation enabled. | 1237 // Switch back the source with resolution adaptation enabled. |
1234 vie_encoder_->SetSource( | 1238 vie_encoder_->SetSource( |
1235 &video_source_, | 1239 &video_source_, |
1236 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1240 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1237 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1241 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1238 sink_.WaitForEncodedFrame(sequence++); | 1242 sink_.WaitForEncodedFrame(sequence++); |
1239 stats = stats_proxy_->GetStats(); | 1243 stats = stats_proxy_->GetStats(); |
1240 EXPECT_TRUE(stats.cpu_limited_resolution); | 1244 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1245 EXPECT_FALSE(stats.cpu_limited_framerate); |
1241 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1246 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1242 | 1247 |
1243 // Trigger CPU normal usage. | 1248 // Trigger CPU normal usage. |
1244 vie_encoder_->TriggerCpuNormalUsage(); | 1249 vie_encoder_->TriggerCpuNormalUsage(); |
1245 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1250 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1246 sink_.WaitForEncodedFrame(sequence++); | 1251 sink_.WaitForEncodedFrame(sequence++); |
1247 stats = stats_proxy_->GetStats(); | 1252 stats = stats_proxy_->GetStats(); |
1248 EXPECT_FALSE(stats.cpu_limited_resolution); | 1253 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1254 EXPECT_FALSE(stats.cpu_limited_framerate); |
1249 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1255 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1250 | 1256 |
1251 // Back to the source with adaptation off, set it back to maintain-resolution. | 1257 // Back to the source with adaptation off, set it back to maintain-resolution. |
1252 vie_encoder_->SetSource( | 1258 vie_encoder_->SetSource( |
1253 &new_video_source, | 1259 &new_video_source, |
1254 VideoSendStream::DegradationPreference::kMaintainResolution); | 1260 VideoSendStream::DegradationPreference::kMaintainResolution); |
1255 new_video_source.IncomingCapturedFrame( | 1261 new_video_source.IncomingCapturedFrame( |
1256 CreateFrame(sequence, kWidth, kHeight)); | 1262 CreateFrame(sequence, kWidth, kHeight)); |
1257 sink_.WaitForEncodedFrame(sequence++); | 1263 sink_.WaitForEncodedFrame(sequence++); |
1258 stats = stats_proxy_->GetStats(); | 1264 stats = stats_proxy_->GetStats(); |
1259 // Disabled, since we previously switched the source too disabled. | 1265 // Disabled, since we previously switched the source to disabled. |
1260 EXPECT_FALSE(stats.cpu_limited_resolution); | 1266 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1267 EXPECT_TRUE(stats.cpu_limited_framerate); |
1261 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1268 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1262 | 1269 |
1263 // Trigger CPU normal usage. | 1270 // Trigger CPU normal usage. |
1264 vie_encoder_->TriggerCpuNormalUsage(); | 1271 vie_encoder_->TriggerCpuNormalUsage(); |
1265 new_video_source.IncomingCapturedFrame( | 1272 new_video_source.IncomingCapturedFrame( |
1266 CreateFrame(sequence, kWidth, kHeight)); | 1273 CreateFrame(sequence, kWidth, kHeight)); |
1267 sink_.WaitForEncodedFrame(sequence++); | 1274 sink_.WaitForEncodedFrame(sequence++); |
1268 stats = stats_proxy_->GetStats(); | 1275 stats = stats_proxy_->GetStats(); |
1269 EXPECT_FALSE(stats.cpu_limited_resolution); | 1276 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1277 EXPECT_FALSE(stats.cpu_limited_framerate); |
1270 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); | 1278 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); |
1271 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1279 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1272 | 1280 |
1273 vie_encoder_->Stop(); | 1281 vie_encoder_->Stop(); |
1274 } | 1282 } |
1275 | 1283 |
1276 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { | 1284 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { |
1277 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1285 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1278 | 1286 |
1279 const int kWidth = 1280; | 1287 const int kWidth = 1280; |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2106 for (int i = 0; i < 10; ++i) { | 2114 for (int i = 0; i < 10; ++i) { |
2107 timestamp_ms += kMinFpsFrameInterval; | 2115 timestamp_ms += kMinFpsFrameInterval; |
2108 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); | 2116 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); |
2109 video_source_.IncomingCapturedFrame( | 2117 video_source_.IncomingCapturedFrame( |
2110 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2118 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2111 sink_.WaitForEncodedFrame(timestamp_ms); | 2119 sink_.WaitForEncodedFrame(timestamp_ms); |
2112 } | 2120 } |
2113 vie_encoder_->Stop(); | 2121 vie_encoder_->Stop(); |
2114 } | 2122 } |
2115 } // namespace webrtc | 2123 } // namespace webrtc |
OLD | NEW |