| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 void PostTaskAndWait(bool down, AdaptReason reason) { | 75 void PostTaskAndWait(bool down, AdaptReason reason) { |
| 76 rtc::Event event(false, false); | 76 rtc::Event event(false, false); |
| 77 encoder_queue()->PostTask([this, &event, reason, down] { | 77 encoder_queue()->PostTask([this, &event, reason, down] { |
| 78 down ? AdaptDown(reason) : AdaptUp(reason); | 78 down ? AdaptDown(reason) : AdaptUp(reason); |
| 79 event.Set(); | 79 event.Set(); |
| 80 }); | 80 }); |
| 81 ASSERT_TRUE(event.Wait(5000)); | 81 ASSERT_TRUE(event.Wait(5000)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // This is used as a synchronisation mechanism, to make sure that the |
| 85 // encoder queue is not blocked before we start sending it frames. |
| 86 void WaitUntilTaskQueueIsIdle() { |
| 87 rtc::Event event(false, false); |
| 88 encoder_queue()->PostTask([&event] { |
| 89 event.Set(); |
| 90 }); |
| 91 ASSERT_TRUE(event.Wait(5000)); |
| 92 } |
| 93 |
| 84 void TriggerCpuOveruse() { PostTaskAndWait(true, AdaptReason::kCpu); } | 94 void TriggerCpuOveruse() { PostTaskAndWait(true, AdaptReason::kCpu); } |
| 85 | 95 |
| 86 void TriggerCpuNormalUsage() { PostTaskAndWait(false, AdaptReason::kCpu); } | 96 void TriggerCpuNormalUsage() { PostTaskAndWait(false, AdaptReason::kCpu); } |
| 87 | 97 |
| 88 void TriggerQualityLow() { PostTaskAndWait(true, AdaptReason::kQuality); } | 98 void TriggerQualityLow() { PostTaskAndWait(true, AdaptReason::kQuality); } |
| 89 | 99 |
| 90 void TriggerQualityHigh() { PostTaskAndWait(false, AdaptReason::kQuality); } | 100 void TriggerQualityHigh() { PostTaskAndWait(false, AdaptReason::kQuality); } |
| 91 }; | 101 }; |
| 92 | 102 |
| 93 class VideoStreamFactory | 103 class VideoStreamFactory |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 if (vie_encoder_) | 204 if (vie_encoder_) |
| 195 vie_encoder_->Stop(); | 205 vie_encoder_->Stop(); |
| 196 vie_encoder_.reset(new ViEEncoderUnderTest( | 206 vie_encoder_.reset(new ViEEncoderUnderTest( |
| 197 stats_proxy_.get(), video_send_config_.encoder_settings)); | 207 stats_proxy_.get(), video_send_config_.encoder_settings)); |
| 198 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); | 208 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); |
| 199 vie_encoder_->SetSource(&video_source_, | 209 vie_encoder_->SetSource(&video_source_, |
| 200 VideoSendStream::DegradationPreference::kBalanced); | 210 VideoSendStream::DegradationPreference::kBalanced); |
| 201 vie_encoder_->SetStartBitrate(kTargetBitrateBps); | 211 vie_encoder_->SetStartBitrate(kTargetBitrateBps); |
| 202 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 212 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 203 kMaxPayloadLength, nack_enabled); | 213 kMaxPayloadLength, nack_enabled); |
| 214 vie_encoder_->WaitUntilTaskQueueIsIdle(); |
| 204 } | 215 } |
| 205 | 216 |
| 206 void ResetEncoder(const std::string& payload_name, | 217 void ResetEncoder(const std::string& payload_name, |
| 207 size_t num_streams, | 218 size_t num_streams, |
| 208 size_t num_temporal_layers, | 219 size_t num_temporal_layers, |
| 209 bool nack_enabled) { | 220 bool nack_enabled) { |
| 210 video_send_config_.encoder_settings.payload_name = payload_name; | 221 video_send_config_.encoder_settings.payload_name = payload_name; |
| 211 | 222 |
| 212 VideoEncoderConfig video_encoder_config; | 223 VideoEncoderConfig video_encoder_config; |
| 213 video_encoder_config.number_of_streams = num_streams; | 224 video_encoder_config.number_of_streams = num_streams; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 244 rtc::CritScope lock(&crit_sect_); | 255 rtc::CritScope lock(&crit_sect_); |
| 245 return config_; | 256 return config_; |
| 246 } | 257 } |
| 247 | 258 |
| 248 void BlockNextEncode() { | 259 void BlockNextEncode() { |
| 249 rtc::CritScope lock(&local_crit_sect_); | 260 rtc::CritScope lock(&local_crit_sect_); |
| 250 block_next_encode_ = true; | 261 block_next_encode_ = true; |
| 251 } | 262 } |
| 252 | 263 |
| 253 VideoEncoder::ScalingSettings GetScalingSettings() const override { | 264 VideoEncoder::ScalingSettings GetScalingSettings() const override { |
| 265 rtc::CritScope lock(&local_crit_sect_); |
| 254 if (quality_scaling_) | 266 if (quality_scaling_) |
| 255 return VideoEncoder::ScalingSettings(true, 1, 2); | 267 return VideoEncoder::ScalingSettings(true, 1, 2); |
| 256 return VideoEncoder::ScalingSettings(false); | 268 return VideoEncoder::ScalingSettings(false); |
| 257 } | 269 } |
| 258 | 270 |
| 259 void ContinueEncode() { continue_encode_event_.Set(); } | 271 void ContinueEncode() { continue_encode_event_.Set(); } |
| 260 | 272 |
| 261 void CheckLastTimeStampsMatch(int64_t ntp_time_ms, | 273 void CheckLastTimeStampsMatch(int64_t ntp_time_ms, |
| 262 uint32_t timestamp) const { | 274 uint32_t timestamp) const { |
| 263 rtc::CritScope lock(&local_crit_sect_); | 275 rtc::CritScope lock(&local_crit_sect_); |
| 264 EXPECT_EQ(timestamp_, timestamp); | 276 EXPECT_EQ(timestamp_, timestamp); |
| 265 EXPECT_EQ(ntp_time_ms_, ntp_time_ms); | 277 EXPECT_EQ(ntp_time_ms_, ntp_time_ms); |
| 266 } | 278 } |
| 267 | 279 |
| 268 void SetQualityScaling(bool b) { quality_scaling_ = b; } | 280 void SetQualityScaling(bool b) { |
| 281 rtc::CritScope lock(&local_crit_sect_); |
| 282 quality_scaling_ = b; |
| 283 } |
| 269 | 284 |
| 270 private: | 285 private: |
| 271 int32_t Encode(const VideoFrame& input_image, | 286 int32_t Encode(const VideoFrame& input_image, |
| 272 const CodecSpecificInfo* codec_specific_info, | 287 const CodecSpecificInfo* codec_specific_info, |
| 273 const std::vector<FrameType>* frame_types) override { | 288 const std::vector<FrameType>* frame_types) override { |
| 274 bool block_encode; | 289 bool block_encode; |
| 275 { | 290 { |
| 276 rtc::CritScope lock(&local_crit_sect_); | 291 rtc::CritScope lock(&local_crit_sect_); |
| 277 EXPECT_GT(input_image.timestamp(), timestamp_); | 292 EXPECT_GT(input_image.timestamp(), timestamp_); |
| 278 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_); | 293 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 339 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
| 325 { | 340 { |
| 326 rtc::CritScope lock(&crit_); | 341 rtc::CritScope lock(&crit_); |
| 327 width = last_width_; | 342 width = last_width_; |
| 328 height = last_height_; | 343 height = last_height_; |
| 329 } | 344 } |
| 330 EXPECT_EQ(expected_height, height); | 345 EXPECT_EQ(expected_height, height); |
| 331 EXPECT_EQ(expected_width, width); | 346 EXPECT_EQ(expected_width, width); |
| 332 } | 347 } |
| 333 | 348 |
| 334 void ExpectDroppedFrame() { EXPECT_FALSE(encoded_frame_event_.Wait(20)); } | 349 void ExpectDroppedFrame() { EXPECT_FALSE(encoded_frame_event_.Wait(100)); } |
| 335 | 350 |
| 336 void SetExpectNoFrames() { | 351 void SetExpectNoFrames() { |
| 337 rtc::CritScope lock(&crit_); | 352 rtc::CritScope lock(&crit_); |
| 338 expect_frames_ = false; | 353 expect_frames_ = false; |
| 339 } | 354 } |
| 340 | 355 |
| 341 int number_of_reconfigurations() { | 356 int number_of_reconfigurations() { |
| 342 rtc::CritScope lock(&crit_); | 357 rtc::CritScope lock(&crit_); |
| 343 return number_of_reconfigurations_; | 358 return number_of_reconfigurations_; |
| 344 } | 359 } |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 CreateFrame(2, frame_width * 3 / 4, frame_height * 3 / 4)); | 1147 CreateFrame(2, frame_width * 3 / 4, frame_height * 3 / 4)); |
| 1133 | 1148 |
| 1134 // Expect to drop this frame, the wait should time out. | 1149 // Expect to drop this frame, the wait should time out. |
| 1135 sink_.ExpectDroppedFrame(); | 1150 sink_.ExpectDroppedFrame(); |
| 1136 | 1151 |
| 1137 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, last_pixel_count); | 1152 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, last_pixel_count); |
| 1138 | 1153 |
| 1139 vie_encoder_->Stop(); | 1154 vie_encoder_->Stop(); |
| 1140 } | 1155 } |
| 1141 | 1156 |
| 1142 #if defined(MEMORY_SANITIZER) | 1157 TEST_F(ViEEncoderTest, NrOfDroppedFramesLimited) { |
| 1143 // Fails under MemorySanitizer: See http://crbug.com/webrtc/7232 | |
| 1144 #define MAYBE_NrOfDroppedFramesLimited DISABLED_NrOfDroppedFramesLimited | |
| 1145 #else | |
| 1146 #define MAYBE_NrOfDroppedFramesLimited NrOfDroppedFramesLimited | |
| 1147 #endif | |
| 1148 TEST_F(ViEEncoderTest, MAYBE_NrOfDroppedFramesLimited) { | |
| 1149 // 1kbps. This can never be achieved. | 1158 // 1kbps. This can never be achieved. |
| 1150 vie_encoder_->OnBitrateUpdated(1000, 0, 0); | 1159 vie_encoder_->OnBitrateUpdated(1000, 0, 0); |
| 1151 int frame_width = 640; | 1160 int frame_width = 640; |
| 1152 int frame_height = 360; | 1161 int frame_height = 360; |
| 1153 | 1162 |
| 1154 // We expect the n initial frames to get dropped. | 1163 // We expect the n initial frames to get dropped. |
| 1155 int i; | 1164 int i; |
| 1156 for (i = 1; i <= kMaxInitialFramedrop; ++i) { | 1165 for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
| 1157 video_source_.IncomingCapturedFrame( | 1166 video_source_.IncomingCapturedFrame( |
| 1158 CreateFrame(i, frame_width, frame_height)); | 1167 CreateFrame(i, frame_width, frame_height)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1181 VideoSendStream::DegradationPreference::kMaintainResolution); | 1190 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1182 | 1191 |
| 1183 video_source_.IncomingCapturedFrame( | 1192 video_source_.IncomingCapturedFrame( |
| 1184 CreateFrame(1, frame_width, frame_height)); | 1193 CreateFrame(1, frame_width, frame_height)); |
| 1185 // Frame should not be dropped, even if it's too large. | 1194 // Frame should not be dropped, even if it's too large. |
| 1186 sink_.WaitForEncodedFrame(1); | 1195 sink_.WaitForEncodedFrame(1); |
| 1187 | 1196 |
| 1188 vie_encoder_->Stop(); | 1197 vie_encoder_->Stop(); |
| 1189 } | 1198 } |
| 1190 | 1199 |
| 1191 // Disable for TSan v2, see https://crbug.com/webrtc/7260 for details. | 1200 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { |
| 1192 #if defined(THREAD_SANITIZER) | |
| 1193 #define MAYBE_InitialFrameDropOffWhenEncoderDisabledScaling \ | |
| 1194 DISABLED_InitialFrameDropOffWhenEncoderDisabledScaling | |
| 1195 #else | |
| 1196 #define MAYBE_InitialFrameDropOffWhenEncoderDisabledScaling \ | |
| 1197 InitialFrameDropOffWhenEncoderDisabledScaling | |
| 1198 #endif | |
| 1199 TEST_F(ViEEncoderTest, MAYBE_InitialFrameDropOffWhenEncoderDisabledScaling) { | |
| 1200 int frame_width = 640; | 1201 int frame_width = 640; |
| 1201 int frame_height = 360; | 1202 int frame_height = 360; |
| 1202 fake_encoder_.SetQualityScaling(false); | 1203 fake_encoder_.SetQualityScaling(false); |
| 1203 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1204 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 1204 // Force quality scaler reconfiguration by resetting the source. | 1205 // Force quality scaler reconfiguration by resetting the source. |
| 1205 vie_encoder_->SetSource(&video_source_, | 1206 vie_encoder_->SetSource(&video_source_, |
| 1206 VideoSendStream::DegradationPreference::kBalanced); | 1207 VideoSendStream::DegradationPreference::kBalanced); |
| 1207 | 1208 |
| 1208 video_source_.IncomingCapturedFrame( | 1209 video_source_.IncomingCapturedFrame( |
| 1209 CreateFrame(1, frame_width, frame_height)); | 1210 CreateFrame(1, frame_width, frame_height)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1236 | 1237 |
| 1237 // Trigger CPU normal use, return to original resoluton; | 1238 // Trigger CPU normal use, return to original resoluton; |
| 1238 vie_encoder_->TriggerCpuNormalUsage(); | 1239 vie_encoder_->TriggerCpuNormalUsage(); |
| 1239 video_source_.IncomingCapturedFrame( | 1240 video_source_.IncomingCapturedFrame( |
| 1240 CreateFrame(3, kFrameWidth, kFrameHeight)); | 1241 CreateFrame(3, kFrameWidth, kFrameHeight)); |
| 1241 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1242 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 1242 | 1243 |
| 1243 vie_encoder_->Stop(); | 1244 vie_encoder_->Stop(); |
| 1244 } | 1245 } |
| 1245 } // namespace webrtc | 1246 } // namespace webrtc |
| OLD | NEW |