| 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 |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "webrtc/api/video/i420_buffer.h" | 14 #include "webrtc/api/video/i420_buffer.h" |
| 15 #include "webrtc/base/fakeclock.h" | |
| 16 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/media/base/videoadapter.h" | 16 #include "webrtc/media/base/videoadapter.h" |
| 18 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" | 17 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" |
| 19 #include "webrtc/system_wrappers/include/metrics_default.h" | 18 #include "webrtc/system_wrappers/include/metrics_default.h" |
| 20 #include "webrtc/system_wrappers/include/sleep.h" | 19 #include "webrtc/system_wrappers/include/sleep.h" |
| 21 #include "webrtc/test/encoder_settings.h" | 20 #include "webrtc/test/encoder_settings.h" |
| 22 #include "webrtc/test/fake_encoder.h" | 21 #include "webrtc/test/fake_encoder.h" |
| 23 #include "webrtc/test/frame_generator.h" | 22 #include "webrtc/test/frame_generator.h" |
| 24 #include "webrtc/test/gmock.h" | 23 #include "webrtc/test/gmock.h" |
| 25 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
| 26 #include "webrtc/video/send_statistics_proxy.h" | 25 #include "webrtc/video/send_statistics_proxy.h" |
| 27 #include "webrtc/video/vie_encoder.h" | 26 #include "webrtc/video/vie_encoder.h" |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 #if defined(WEBRTC_ANDROID) | 29 #if defined(WEBRTC_ANDROID) |
| 31 // TODO(kthelgason): Lower this limit when better testing | 30 // TODO(kthelgason): Lower this limit when better testing |
| 32 // on MediaCodec and fallback implementations are in place. | 31 // on MediaCodec and fallback implementations are in place. |
| 33 const int kMinPixelsPerFrame = 320 * 180; | 32 const int kMinPixelsPerFrame = 320 * 180; |
| 34 #else | 33 #else |
| 35 const int kMinPixelsPerFrame = 120 * 90; | 34 const int kMinPixelsPerFrame = 120 * 90; |
| 36 #endif | 35 #endif |
| 37 const int kMinFramerateFps = 2; | 36 } |
| 38 const int64_t kFrameTimeoutMs = 100; | |
| 39 } // namespace | |
| 40 | 37 |
| 41 namespace webrtc { | 38 namespace webrtc { |
| 42 | 39 |
| 43 using DegredationPreference = VideoSendStream::DegradationPreference; | 40 using DegredationPreference = VideoSendStream::DegradationPreference; |
| 44 using ScaleReason = AdaptationObserverInterface::AdaptReason; | 41 using ScaleReason = AdaptationObserverInterface::AdaptReason; |
| 45 using ::testing::_; | 42 using ::testing::_; |
| 46 using ::testing::Return; | 43 using ::testing::Return; |
| 47 | 44 |
| 48 namespace { | 45 namespace { |
| 49 const size_t kMaxPayloadLength = 1440; | 46 const size_t kMaxPayloadLength = 1440; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 bool adaption_enabled() { | 136 bool adaption_enabled() { |
| 140 rtc::CritScope cs(&crit_); | 137 rtc::CritScope cs(&crit_); |
| 141 return adaptation_enabled_; | 138 return adaptation_enabled_; |
| 142 } | 139 } |
| 143 | 140 |
| 144 void IncomingCapturedFrame(const VideoFrame& video_frame) override { | 141 void IncomingCapturedFrame(const VideoFrame& video_frame) override { |
| 145 int cropped_width = 0; | 142 int cropped_width = 0; |
| 146 int cropped_height = 0; | 143 int cropped_height = 0; |
| 147 int out_width = 0; | 144 int out_width = 0; |
| 148 int out_height = 0; | 145 int out_height = 0; |
| 149 if (adaption_enabled()) { | 146 if (adaption_enabled() && |
| 150 if (adapter_.AdaptFrameResolution( | 147 adapter_.AdaptFrameResolution(video_frame.width(), video_frame.height(), |
| 151 video_frame.width(), video_frame.height(), | 148 video_frame.timestamp_us() * 1000, |
| 152 video_frame.timestamp_us() * 1000, &cropped_width, | 149 &cropped_width, &cropped_height, |
| 153 &cropped_height, &out_width, &out_height)) { | 150 &out_width, &out_height)) { |
| 154 VideoFrame adapted_frame(new rtc::RefCountedObject<TestBuffer>( | 151 VideoFrame adapted_frame( |
| 155 nullptr, out_width, out_height), | 152 new rtc::RefCountedObject<TestBuffer>(nullptr, out_width, out_height), |
| 156 99, 99, kVideoRotation_0); | 153 99, 99, kVideoRotation_0); |
| 157 adapted_frame.set_ntp_time_ms(video_frame.ntp_time_ms()); | 154 adapted_frame.set_ntp_time_ms(video_frame.ntp_time_ms()); |
| 158 test::FrameForwarder::IncomingCapturedFrame(adapted_frame); | 155 test::FrameForwarder::IncomingCapturedFrame(adapted_frame); |
| 159 } | |
| 160 } else { | 156 } else { |
| 161 test::FrameForwarder::IncomingCapturedFrame(video_frame); | 157 test::FrameForwarder::IncomingCapturedFrame(video_frame); |
| 162 } | 158 } |
| 163 } | 159 } |
| 164 | 160 |
| 165 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, | 161 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 166 const rtc::VideoSinkWants& wants) override { | 162 const rtc::VideoSinkWants& wants) override { |
| 167 rtc::CritScope cs(&crit_); | 163 rtc::CritScope cs(&crit_); |
| 168 adapter_.OnResolutionFramerateRequest(wants.target_pixel_count, | 164 adapter_.OnResolutionRequest(wants.target_pixel_count, |
| 169 wants.max_pixel_count, | 165 wants.max_pixel_count); |
| 170 wants.max_framerate_fps); | |
| 171 test::FrameForwarder::AddOrUpdateSink(sink, wants); | 166 test::FrameForwarder::AddOrUpdateSink(sink, wants); |
| 172 } | 167 } |
| 173 | 168 |
| 174 cricket::VideoAdapter adapter_; | 169 cricket::VideoAdapter adapter_; |
| 175 bool adaptation_enabled_ GUARDED_BY(crit_); | 170 bool adaptation_enabled_ GUARDED_BY(crit_); |
| 176 }; | 171 }; |
| 177 | |
| 178 class MockableSendStatisticsProxy : public SendStatisticsProxy { | |
| 179 public: | |
| 180 MockableSendStatisticsProxy(Clock* clock, | |
| 181 const VideoSendStream::Config& config, | |
| 182 VideoEncoderConfig::ContentType content_type) | |
| 183 : SendStatisticsProxy(clock, config, content_type) {} | |
| 184 | |
| 185 VideoSendStream::Stats GetStats() override { | |
| 186 rtc::CritScope cs(&lock_); | |
| 187 if (mock_stats_) | |
| 188 return *mock_stats_; | |
| 189 return SendStatisticsProxy::GetStats(); | |
| 190 } | |
| 191 | |
| 192 void SetMockStats(const VideoSendStream::Stats& stats) { | |
| 193 rtc::CritScope cs(&lock_); | |
| 194 mock_stats_.emplace(stats); | |
| 195 } | |
| 196 | |
| 197 void ResetMockStats() { | |
| 198 rtc::CritScope cs(&lock_); | |
| 199 mock_stats_.reset(); | |
| 200 } | |
| 201 | |
| 202 private: | |
| 203 rtc::CriticalSection lock_; | |
| 204 rtc::Optional<VideoSendStream::Stats> mock_stats_ GUARDED_BY(lock_); | |
| 205 }; | |
| 206 | |
| 207 } // namespace | 172 } // namespace |
| 208 | 173 |
| 209 class ViEEncoderTest : public ::testing::Test { | 174 class ViEEncoderTest : public ::testing::Test { |
| 210 public: | 175 public: |
| 211 static const int kDefaultTimeoutMs = 30 * 1000; | 176 static const int kDefaultTimeoutMs = 30 * 1000; |
| 212 | 177 |
| 213 ViEEncoderTest() | 178 ViEEncoderTest() |
| 214 : video_send_config_(VideoSendStream::Config(nullptr)), | 179 : video_send_config_(VideoSendStream::Config(nullptr)), |
| 215 codec_width_(320), | 180 codec_width_(320), |
| 216 codec_height_(240), | 181 codec_height_(240), |
| 217 fake_encoder_(), | 182 fake_encoder_(), |
| 218 stats_proxy_(new MockableSendStatisticsProxy( | 183 stats_proxy_(new SendStatisticsProxy( |
| 219 Clock::GetRealTimeClock(), | 184 Clock::GetRealTimeClock(), |
| 220 video_send_config_, | 185 video_send_config_, |
| 221 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), | 186 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), |
| 222 sink_(&fake_encoder_) {} | 187 sink_(&fake_encoder_) {} |
| 223 | 188 |
| 224 void SetUp() override { | 189 void SetUp() override { |
| 225 metrics::Reset(); | 190 metrics::Reset(); |
| 226 video_send_config_ = VideoSendStream::Config(nullptr); | 191 video_send_config_ = VideoSendStream::Config(nullptr); |
| 227 video_send_config_.encoder_settings.encoder = &fake_encoder_; | 192 video_send_config_.encoder_settings.encoder = &fake_encoder_; |
| 228 video_send_config_.encoder_settings.payload_name = "FAKE"; | 193 video_send_config_.encoder_settings.payload_name = "FAKE"; |
| 229 video_send_config_.encoder_settings.payload_type = 125; | 194 video_send_config_.encoder_settings.payload_type = 125; |
| 230 | 195 |
| 231 VideoEncoderConfig video_encoder_config; | 196 VideoEncoderConfig video_encoder_config; |
| 232 test::FillEncoderConfiguration(1, &video_encoder_config); | 197 test::FillEncoderConfiguration(1, &video_encoder_config); |
| 233 video_encoder_config_ = video_encoder_config.Copy(); | 198 video_encoder_config_ = video_encoder_config.Copy(); |
| 234 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); | 199 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); |
| 235 } | 200 } |
| 236 | 201 |
| 237 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, | 202 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, |
| 238 bool nack_enabled) { | 203 bool nack_enabled) { |
| 239 if (vie_encoder_) | 204 if (vie_encoder_) |
| 240 vie_encoder_->Stop(); | 205 vie_encoder_->Stop(); |
| 241 vie_encoder_.reset(new ViEEncoderUnderTest( | 206 vie_encoder_.reset(new ViEEncoderUnderTest( |
| 242 stats_proxy_.get(), video_send_config_.encoder_settings)); | 207 stats_proxy_.get(), video_send_config_.encoder_settings)); |
| 243 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); | 208 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); |
| 244 vie_encoder_->SetSource( | 209 vie_encoder_->SetSource(&video_source_, |
| 245 &video_source_, | 210 VideoSendStream::DegradationPreference::kBalanced); |
| 246 VideoSendStream::DegradationPreference::kMaintainFramerate); | |
| 247 vie_encoder_->SetStartBitrate(kTargetBitrateBps); | 211 vie_encoder_->SetStartBitrate(kTargetBitrateBps); |
| 248 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 212 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 249 kMaxPayloadLength, nack_enabled); | 213 kMaxPayloadLength, nack_enabled); |
| 250 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 214 vie_encoder_->WaitUntilTaskQueueIsIdle(); |
| 251 } | 215 } |
| 252 | 216 |
| 253 void ResetEncoder(const std::string& payload_name, | 217 void ResetEncoder(const std::string& payload_name, |
| 254 size_t num_streams, | 218 size_t num_streams, |
| 255 size_t num_temporal_layers, | 219 size_t num_temporal_layers, |
| 256 bool nack_enabled) { | 220 bool nack_enabled) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 271 99, 99, kVideoRotation_0); | 235 99, 99, kVideoRotation_0); |
| 272 frame.set_ntp_time_ms(ntp_time_ms); | 236 frame.set_ntp_time_ms(ntp_time_ms); |
| 273 return frame; | 237 return frame; |
| 274 } | 238 } |
| 275 | 239 |
| 276 VideoFrame CreateFrame(int64_t ntp_time_ms, int width, int height) const { | 240 VideoFrame CreateFrame(int64_t ntp_time_ms, int width, int height) const { |
| 277 VideoFrame frame( | 241 VideoFrame frame( |
| 278 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99, | 242 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99, |
| 279 kVideoRotation_0); | 243 kVideoRotation_0); |
| 280 frame.set_ntp_time_ms(ntp_time_ms); | 244 frame.set_ntp_time_ms(ntp_time_ms); |
| 281 frame.set_timestamp_us(ntp_time_ms * 1000); | |
| 282 return frame; | 245 return frame; |
| 283 } | 246 } |
| 284 | 247 |
| 285 class TestEncoder : public test::FakeEncoder { | 248 class TestEncoder : public test::FakeEncoder { |
| 286 public: | 249 public: |
| 287 TestEncoder() | 250 TestEncoder() |
| 288 : FakeEncoder(Clock::GetRealTimeClock()), | 251 : FakeEncoder(Clock::GetRealTimeClock()), |
| 289 continue_encode_event_(false, false) {} | 252 continue_encode_event_(false, false) {} |
| 290 | 253 |
| 291 VideoCodec codec_config() { | 254 VideoCodec codec_config() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 327 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
| 365 { | 328 { |
| 366 rtc::CritScope lock(&crit_); | 329 rtc::CritScope lock(&crit_); |
| 367 timestamp = last_timestamp_; | 330 timestamp = last_timestamp_; |
| 368 } | 331 } |
| 369 test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp); | 332 test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp); |
| 370 } | 333 } |
| 371 | 334 |
| 372 void WaitForEncodedFrame(uint32_t expected_width, | 335 void WaitForEncodedFrame(uint32_t expected_width, |
| 373 uint32_t expected_height) { | 336 uint32_t expected_height) { |
| 374 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | |
| 375 CheckLastFrameSizeMathces(expected_width, expected_height); | |
| 376 } | |
| 377 | |
| 378 void CheckLastFrameSizeMathces(uint32_t expected_width, | |
| 379 uint32_t expected_height) { | |
| 380 uint32_t width = 0; | 337 uint32_t width = 0; |
| 381 uint32_t height = 0; | 338 uint32_t height = 0; |
| 339 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
| 382 { | 340 { |
| 383 rtc::CritScope lock(&crit_); | 341 rtc::CritScope lock(&crit_); |
| 384 width = last_width_; | 342 width = last_width_; |
| 385 height = last_height_; | 343 height = last_height_; |
| 386 } | 344 } |
| 387 EXPECT_EQ(expected_height, height); | 345 EXPECT_EQ(expected_height, height); |
| 388 EXPECT_EQ(expected_width, width); | 346 EXPECT_EQ(expected_width, width); |
| 389 } | 347 } |
| 390 | 348 |
| 391 void ExpectDroppedFrame() { EXPECT_FALSE(encoded_frame_event_.Wait(100)); } | 349 void ExpectDroppedFrame() { EXPECT_FALSE(encoded_frame_event_.Wait(100)); } |
| 392 | 350 |
| 393 bool WaitForFrame(int64_t timeout_ms) { | |
| 394 return encoded_frame_event_.Wait(timeout_ms); | |
| 395 } | |
| 396 | |
| 397 void SetExpectNoFrames() { | 351 void SetExpectNoFrames() { |
| 398 rtc::CritScope lock(&crit_); | 352 rtc::CritScope lock(&crit_); |
| 399 expect_frames_ = false; | 353 expect_frames_ = false; |
| 400 } | 354 } |
| 401 | 355 |
| 402 int number_of_reconfigurations() { | 356 int number_of_reconfigurations() { |
| 403 rtc::CritScope lock(&crit_); | 357 rtc::CritScope lock(&crit_); |
| 404 return number_of_reconfigurations_; | 358 return number_of_reconfigurations_; |
| 405 } | 359 } |
| 406 | 360 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 bool expect_frames_ = true; | 393 bool expect_frames_ = true; |
| 440 int number_of_reconfigurations_ = 0; | 394 int number_of_reconfigurations_ = 0; |
| 441 int min_transmit_bitrate_bps_ = 0; | 395 int min_transmit_bitrate_bps_ = 0; |
| 442 }; | 396 }; |
| 443 | 397 |
| 444 VideoSendStream::Config video_send_config_; | 398 VideoSendStream::Config video_send_config_; |
| 445 VideoEncoderConfig video_encoder_config_; | 399 VideoEncoderConfig video_encoder_config_; |
| 446 int codec_width_; | 400 int codec_width_; |
| 447 int codec_height_; | 401 int codec_height_; |
| 448 TestEncoder fake_encoder_; | 402 TestEncoder fake_encoder_; |
| 449 std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; | 403 std::unique_ptr<SendStatisticsProxy> stats_proxy_; |
| 450 TestSink sink_; | 404 TestSink sink_; |
| 451 AdaptingFrameForwarder video_source_; | 405 AdaptingFrameForwarder video_source_; |
| 452 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; | 406 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; |
| 453 }; | 407 }; |
| 454 | 408 |
| 455 TEST_F(ViEEncoderTest, EncodeOneFrame) { | 409 TEST_F(ViEEncoderTest, EncodeOneFrame) { |
| 456 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 410 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 457 rtc::Event frame_destroyed_event(false, false); | 411 rtc::Event frame_destroyed_event(false, false); |
| 458 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 412 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
| 459 sink_.WaitForEncodedFrame(1); | 413 sink_.WaitForEncodedFrame(1); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 611 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
| 658 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 612 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
| 659 // Resilience is on for temporal layers. | 613 // Resilience is on for temporal layers. |
| 660 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); | 614 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); |
| 661 vie_encoder_->Stop(); | 615 vie_encoder_->Stop(); |
| 662 } | 616 } |
| 663 | 617 |
| 664 TEST_F(ViEEncoderTest, SwitchSourceDeregisterEncoderAsSink) { | 618 TEST_F(ViEEncoderTest, SwitchSourceDeregisterEncoderAsSink) { |
| 665 EXPECT_TRUE(video_source_.has_sinks()); | 619 EXPECT_TRUE(video_source_.has_sinks()); |
| 666 test::FrameForwarder new_video_source; | 620 test::FrameForwarder new_video_source; |
| 667 vie_encoder_->SetSource( | 621 vie_encoder_->SetSource(&new_video_source, |
| 668 &new_video_source, | 622 VideoSendStream::DegradationPreference::kBalanced); |
| 669 VideoSendStream::DegradationPreference::kMaintainFramerate); | |
| 670 EXPECT_FALSE(video_source_.has_sinks()); | 623 EXPECT_FALSE(video_source_.has_sinks()); |
| 671 EXPECT_TRUE(new_video_source.has_sinks()); | 624 EXPECT_TRUE(new_video_source.has_sinks()); |
| 672 | 625 |
| 673 vie_encoder_->Stop(); | 626 vie_encoder_->Stop(); |
| 674 } | 627 } |
| 675 | 628 |
| 676 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { | 629 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { |
| 677 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); | 630 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); |
| 678 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); | 631 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); |
| 679 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); | 632 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); |
| 680 vie_encoder_->Stop(); | 633 vie_encoder_->Stop(); |
| 681 } | 634 } |
| 682 | 635 |
| 683 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { | 636 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { |
| 684 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 637 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 685 | 638 |
| 686 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 639 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
| 687 EXPECT_EQ(std::numeric_limits<int>::max(), | 640 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
| 688 video_source_.sink_wants().max_pixel_count); | |
| 689 | 641 |
| 690 int frame_width = 1280; | 642 int frame_width = 1280; |
| 691 int frame_height = 720; | 643 int frame_height = 720; |
| 692 | 644 |
| 693 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should | 645 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should |
| 694 // request lower resolution. | 646 // request lower resolution. |
| 695 for (int i = 1; i <= ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { | 647 for (int i = 1; i <= ViEEncoder::kMaxCpuDowngrades; ++i) { |
| 696 video_source_.IncomingCapturedFrame( | 648 video_source_.IncomingCapturedFrame( |
| 697 CreateFrame(i, frame_width, frame_height)); | 649 CreateFrame(i, frame_width, frame_height)); |
| 698 sink_.WaitForEncodedFrame(i); | 650 sink_.WaitForEncodedFrame(i); |
| 699 | 651 |
| 700 vie_encoder_->TriggerCpuOveruse(); | 652 vie_encoder_->TriggerCpuOveruse(); |
| 701 | 653 |
| 702 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 654 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
| 703 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 655 EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( |
| 656 std::numeric_limits<int>::max()), |
| 704 frame_width * frame_height); | 657 frame_width * frame_height); |
| 705 | 658 |
| 706 frame_width /= 2; | 659 frame_width /= 2; |
| 707 frame_height /= 2; | 660 frame_height /= 2; |
| 708 } | 661 } |
| 709 | 662 |
| 710 // Trigger CPU overuse one more time. This should not trigger a request for | 663 // Trigger CPU overuse one more time. This should not trigger a request for |
| 711 // lower resolution. | 664 // lower resolution. |
| 712 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); | 665 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); |
| 713 video_source_.IncomingCapturedFrame(CreateFrame( | 666 video_source_.IncomingCapturedFrame(CreateFrame( |
| 714 ViEEncoder::kMaxCpuResolutionDowngrades + 1, frame_width, frame_height)); | 667 ViEEncoder::kMaxCpuDowngrades + 1, frame_width, frame_height)); |
| 715 sink_.WaitForEncodedFrame(ViEEncoder::kMaxCpuResolutionDowngrades + 1); | 668 sink_.WaitForEncodedFrame(ViEEncoder::kMaxCpuDowngrades + 1); |
| 716 vie_encoder_->TriggerCpuOveruse(); | 669 vie_encoder_->TriggerCpuOveruse(); |
| 717 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, | 670 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, |
| 718 current_wants.target_pixel_count); | 671 current_wants.target_pixel_count); |
| 719 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, | 672 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, |
| 720 current_wants.max_pixel_count); | 673 current_wants.max_pixel_count); |
| 721 | 674 |
| 722 // Trigger CPU normal use. | 675 // Trigger CPU normal use. |
| 723 vie_encoder_->TriggerCpuNormalUsage(); | 676 vie_encoder_->TriggerCpuNormalUsage(); |
| 724 EXPECT_EQ(frame_width * frame_height * 5 / 3, | 677 EXPECT_EQ(frame_width * frame_height * 5 / 3, |
| 725 video_source_.sink_wants().target_pixel_count.value_or(0)); | 678 video_source_.sink_wants().target_pixel_count.value_or(0)); |
| 726 EXPECT_EQ(frame_width * frame_height * 4, | 679 EXPECT_EQ(frame_width * frame_height * 4, |
| 727 video_source_.sink_wants().max_pixel_count); | 680 video_source_.sink_wants().max_pixel_count.value_or(0)); |
| 728 | 681 |
| 729 vie_encoder_->Stop(); | 682 vie_encoder_->Stop(); |
| 730 } | 683 } |
| 731 | 684 |
| 732 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) { | 685 TEST_F(ViEEncoderTest, |
| 686 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { |
| 733 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 687 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 734 | 688 |
| 735 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 689 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
| 736 EXPECT_EQ(std::numeric_limits<int>::max(), | 690 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
| 737 video_source_.sink_wants().max_pixel_count); | |
| 738 EXPECT_EQ(std::numeric_limits<int>::max(), | |
| 739 video_source_.sink_wants().max_framerate_fps); | |
| 740 | 691 |
| 741 const int kFrameWidth = 1280; | 692 int frame_width = 1280; |
| 742 const int kFrameHeight = 720; | 693 int frame_height = 720; |
| 743 const int kFrameIntervalMs = 1000 / 30; | |
| 744 | |
| 745 int frame_timestamp = 1; | |
| 746 | 694 |
| 747 video_source_.IncomingCapturedFrame( | 695 video_source_.IncomingCapturedFrame( |
| 748 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 696 CreateFrame(1, frame_width, frame_height)); |
| 749 sink_.WaitForEncodedFrame(frame_timestamp); | 697 sink_.WaitForEncodedFrame(1); |
| 750 frame_timestamp += kFrameIntervalMs; | |
| 751 | |
| 752 // Trigger CPU overuse. | 698 // Trigger CPU overuse. |
| 753 vie_encoder_->TriggerCpuOveruse(); | 699 vie_encoder_->TriggerCpuOveruse(); |
| 700 |
| 754 video_source_.IncomingCapturedFrame( | 701 video_source_.IncomingCapturedFrame( |
| 755 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 702 CreateFrame(2, frame_width, frame_height)); |
| 756 sink_.WaitForEncodedFrame(frame_timestamp); | 703 sink_.WaitForEncodedFrame(2); |
| 757 frame_timestamp += kFrameIntervalMs; | 704 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
| 705 EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( |
| 706 std::numeric_limits<int>::max()), |
| 707 frame_width * frame_height); |
| 758 | 708 |
| 759 // Default degradation preference in maintain-framerate, so will lower max | 709 // Set new source. |
| 760 // wanted resolution. | |
| 761 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | |
| 762 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | |
| 763 kFrameWidth * kFrameHeight); | |
| 764 EXPECT_EQ(std::numeric_limits<int>::max(), | |
| 765 video_source_.sink_wants().max_framerate_fps); | |
| 766 | |
| 767 // Set new source, switch to maintain-resolution. | |
| 768 test::FrameForwarder new_video_source; | 710 test::FrameForwarder new_video_source; |
| 769 vie_encoder_->SetSource( | 711 vie_encoder_->SetSource( |
| 770 &new_video_source, | 712 &new_video_source, |
| 771 VideoSendStream::DegradationPreference::kMaintainResolution); | 713 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 772 | 714 |
| 773 // Initially no degradation registered. | |
| 774 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 715 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
| 775 EXPECT_EQ(std::numeric_limits<int>::max(), | 716 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
| 776 new_video_source.sink_wants().max_pixel_count); | |
| 777 EXPECT_EQ(std::numeric_limits<int>::max(), | |
| 778 new_video_source.sink_wants().max_framerate_fps); | |
| 779 | 717 |
| 780 // Force an input frame rate to be available, or the adaptation call won't | |
| 781 // know what framerate to adapt form. | |
| 782 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | |
| 783 stats.input_frame_rate = 30; | |
| 784 stats_proxy_->SetMockStats(stats); | |
| 785 | |
| 786 vie_encoder_->TriggerCpuOveruse(); | |
| 787 new_video_source.IncomingCapturedFrame( | 718 new_video_source.IncomingCapturedFrame( |
| 788 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 719 CreateFrame(3, frame_width, frame_height)); |
| 789 sink_.WaitForEncodedFrame(frame_timestamp); | 720 sink_.WaitForEncodedFrame(3); |
| 790 frame_timestamp += kFrameIntervalMs; | |
| 791 | |
| 792 // Some framerate constraint should be set. | |
| 793 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 721 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
| 794 EXPECT_EQ(std::numeric_limits<int>::max(), | 722 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
| 795 new_video_source.sink_wants().max_pixel_count); | |
| 796 EXPECT_TRUE(new_video_source.sink_wants().max_framerate_fps); | |
| 797 | |
| 798 // Turn of degradation completely. | |
| 799 vie_encoder_->SetSource( | |
| 800 &new_video_source, | |
| 801 VideoSendStream::DegradationPreference::kDegradationDisabled); | |
| 802 | |
| 803 // Initially no degradation registered. | |
| 804 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | |
| 805 EXPECT_EQ(std::numeric_limits<int>::max(), | |
| 806 new_video_source.sink_wants().max_pixel_count); | |
| 807 EXPECT_EQ(std::numeric_limits<int>::max(), | |
| 808 new_video_source.sink_wants().max_framerate_fps); | |
| 809 | |
| 810 vie_encoder_->TriggerCpuOveruse(); | |
| 811 new_video_source.IncomingCapturedFrame( | |
| 812 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | |
| 813 sink_.WaitForEncodedFrame(frame_timestamp); | |
| 814 frame_timestamp += kFrameIntervalMs; | |
| 815 | |
| 816 // Still no degradation. | |
| 817 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | |
| 818 EXPECT_EQ(std::numeric_limits<int>::max(), | |
| 819 new_video_source.sink_wants().max_pixel_count); | |
| 820 EXPECT_EQ(std::numeric_limits<int>::max(), | |
| 821 new_video_source.sink_wants().max_framerate_fps); | |
| 822 | 723 |
| 823 // Calling SetSource with resolution scaling enabled apply the old SinkWants. | 724 // Calling SetSource with resolution scaling enabled apply the old SinkWants. |
| 824 vie_encoder_->SetSource( | 725 vie_encoder_->SetSource(&new_video_source, |
| 825 &new_video_source, | 726 VideoSendStream::DegradationPreference::kBalanced); |
| 826 VideoSendStream::DegradationPreference::kMaintainFramerate); | 727 EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or( |
| 827 EXPECT_LT(new_video_source.sink_wants().max_pixel_count, | 728 std::numeric_limits<int>::max()), |
| 828 kFrameWidth * kFrameHeight); | 729 frame_width * frame_height); |
| 829 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 730 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
| 830 EXPECT_EQ(std::numeric_limits<int>::max(), | |
| 831 new_video_source.sink_wants().max_framerate_fps); | |
| 832 | |
| 833 // Calling SetSource with framerate scaling enabled apply the old SinkWants. | |
| 834 vie_encoder_->SetSource( | |
| 835 &new_video_source, | |
| 836 VideoSendStream::DegradationPreference::kMaintainResolution); | |
| 837 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | |
| 838 EXPECT_EQ(std::numeric_limits<int>::max(), | |
| 839 new_video_source.sink_wants().max_pixel_count); | |
| 840 EXPECT_TRUE(new_video_source.sink_wants().max_framerate_fps); | |
| 841 | 731 |
| 842 vie_encoder_->Stop(); | 732 vie_encoder_->Stop(); |
| 843 } | 733 } |
| 844 | 734 |
| 845 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) { | 735 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) { |
| 846 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 736 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 847 | 737 |
| 848 int frame_width = 1280; | 738 int frame_width = 1280; |
| 849 int frame_height = 720; | 739 int frame_height = 720; |
| 850 | 740 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 | 785 |
| 896 video_source_.IncomingCapturedFrame( | 786 video_source_.IncomingCapturedFrame( |
| 897 CreateFrame(2, frame_width, frame_height)); | 787 CreateFrame(2, frame_width, frame_height)); |
| 898 sink_.WaitForEncodedFrame(2); | 788 sink_.WaitForEncodedFrame(2); |
| 899 stats = stats_proxy_->GetStats(); | 789 stats = stats_proxy_->GetStats(); |
| 900 EXPECT_TRUE(stats.cpu_limited_resolution); | 790 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 901 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 791 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 902 | 792 |
| 903 // Set new source with adaptation still enabled. | 793 // Set new source with adaptation still enabled. |
| 904 test::FrameForwarder new_video_source; | 794 test::FrameForwarder new_video_source; |
| 905 vie_encoder_->SetSource( | 795 vie_encoder_->SetSource(&new_video_source, |
| 906 &new_video_source, | 796 VideoSendStream::DegradationPreference::kBalanced); |
| 907 VideoSendStream::DegradationPreference::kMaintainFramerate); | |
| 908 | 797 |
| 909 new_video_source.IncomingCapturedFrame( | 798 new_video_source.IncomingCapturedFrame( |
| 910 CreateFrame(3, frame_width, frame_height)); | 799 CreateFrame(3, frame_width, frame_height)); |
| 911 sink_.WaitForEncodedFrame(3); | 800 sink_.WaitForEncodedFrame(3); |
| 912 stats = stats_proxy_->GetStats(); | 801 stats = stats_proxy_->GetStats(); |
| 913 EXPECT_TRUE(stats.cpu_limited_resolution); | 802 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 914 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 803 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 915 | 804 |
| 916 // Set adaptation disabled. | 805 // Set adaptation disabled. |
| 917 vie_encoder_->SetSource( | 806 vie_encoder_->SetSource( |
| 918 &new_video_source, | 807 &new_video_source, |
| 919 VideoSendStream::DegradationPreference::kDegradationDisabled); | 808 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 920 | 809 |
| 921 new_video_source.IncomingCapturedFrame( | 810 new_video_source.IncomingCapturedFrame( |
| 922 CreateFrame(4, frame_width, frame_height)); | 811 CreateFrame(4, frame_width, frame_height)); |
| 923 sink_.WaitForEncodedFrame(4); | 812 sink_.WaitForEncodedFrame(4); |
| 924 stats = stats_proxy_->GetStats(); | 813 stats = stats_proxy_->GetStats(); |
| 925 EXPECT_FALSE(stats.cpu_limited_resolution); | 814 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 926 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 815 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 927 | 816 |
| 928 // Set adaptation back to enabled. | 817 // Set adaptation back to enabled. |
| 929 vie_encoder_->SetSource( | 818 vie_encoder_->SetSource(&new_video_source, |
| 930 &new_video_source, | 819 VideoSendStream::DegradationPreference::kBalanced); |
| 931 VideoSendStream::DegradationPreference::kMaintainFramerate); | |
| 932 | 820 |
| 933 new_video_source.IncomingCapturedFrame( | 821 new_video_source.IncomingCapturedFrame( |
| 934 CreateFrame(5, frame_width, frame_height)); | 822 CreateFrame(5, frame_width, frame_height)); |
| 935 sink_.WaitForEncodedFrame(5); | 823 sink_.WaitForEncodedFrame(5); |
| 936 stats = stats_proxy_->GetStats(); | 824 stats = stats_proxy_->GetStats(); |
| 937 EXPECT_TRUE(stats.cpu_limited_resolution); | 825 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 938 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 826 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 939 | 827 |
| 940 vie_encoder_->TriggerCpuNormalUsage(); | 828 vie_encoder_->TriggerCpuNormalUsage(); |
| 941 | 829 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 video_source_.IncomingCapturedFrame( | 918 video_source_.IncomingCapturedFrame( |
| 1031 CreateFrame(sequence, frame_width, frame_height)); | 919 CreateFrame(sequence, frame_width, frame_height)); |
| 1032 sink_.WaitForEncodedFrame(sequence++); | 920 sink_.WaitForEncodedFrame(sequence++); |
| 1033 | 921 |
| 1034 stats = stats_proxy_->GetStats(); | 922 stats = stats_proxy_->GetStats(); |
| 1035 EXPECT_TRUE(stats.cpu_limited_resolution); | 923 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1036 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 924 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1037 | 925 |
| 1038 // Set new source with adaptation still enabled. | 926 // Set new source with adaptation still enabled. |
| 1039 test::FrameForwarder new_video_source; | 927 test::FrameForwarder new_video_source; |
| 1040 vie_encoder_->SetSource( | 928 vie_encoder_->SetSource(&new_video_source, |
| 1041 &new_video_source, | 929 VideoSendStream::DegradationPreference::kBalanced); |
| 1042 VideoSendStream::DegradationPreference::kMaintainFramerate); | |
| 1043 | 930 |
| 1044 new_video_source.IncomingCapturedFrame( | 931 new_video_source.IncomingCapturedFrame( |
| 1045 CreateFrame(sequence, frame_width, frame_height)); | 932 CreateFrame(sequence, frame_width, frame_height)); |
| 1046 sink_.WaitForEncodedFrame(sequence++); | 933 sink_.WaitForEncodedFrame(sequence++); |
| 1047 stats = stats_proxy_->GetStats(); | 934 stats = stats_proxy_->GetStats(); |
| 1048 EXPECT_TRUE(stats.cpu_limited_resolution); | 935 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1049 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 936 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1050 | 937 |
| 1051 // Set cpu adaptation by frame dropping. | 938 // Set adaptation disabled. |
| 1052 vie_encoder_->SetSource( | 939 vie_encoder_->SetSource( |
| 1053 &new_video_source, | 940 &new_video_source, |
| 1054 VideoSendStream::DegradationPreference::kMaintainResolution); | 941 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1055 new_video_source.IncomingCapturedFrame( | 942 new_video_source.IncomingCapturedFrame( |
| 1056 CreateFrame(sequence, frame_width, frame_height)); | 943 CreateFrame(sequence, frame_width, frame_height)); |
| 1057 sink_.WaitForEncodedFrame(sequence++); | 944 sink_.WaitForEncodedFrame(sequence++); |
| 1058 stats = stats_proxy_->GetStats(); | 945 stats = stats_proxy_->GetStats(); |
| 1059 // Not adapted at first. | |
| 1060 EXPECT_FALSE(stats.cpu_limited_resolution); | 946 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1061 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 947 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1062 | 948 |
| 1063 // Force an input frame rate to be available, or the adaptation call won't | 949 // Switch back the source with adaptation enabled. |
| 1064 // know what framerate to adapt form. | 950 vie_encoder_->SetSource(&video_source_, |
| 1065 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); | 951 VideoSendStream::DegradationPreference::kBalanced); |
| 1066 mock_stats.input_frame_rate = 30; | |
| 1067 stats_proxy_->SetMockStats(mock_stats); | |
| 1068 vie_encoder_->TriggerCpuOveruse(); | |
| 1069 stats_proxy_->ResetMockStats(); | |
| 1070 | |
| 1071 new_video_source.IncomingCapturedFrame( | |
| 1072 CreateFrame(sequence, frame_width, frame_height)); | |
| 1073 sink_.WaitForEncodedFrame(sequence++); | |
| 1074 | |
| 1075 // Framerate now adapted. | |
| 1076 stats = stats_proxy_->GetStats(); | |
| 1077 EXPECT_TRUE(stats.cpu_limited_resolution); | |
| 1078 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | |
| 1079 | |
| 1080 // Disable CPU adaptation. | |
| 1081 vie_encoder_->SetSource( | |
| 1082 &new_video_source, | |
| 1083 VideoSendStream::DegradationPreference::kDegradationDisabled); | |
| 1084 new_video_source.IncomingCapturedFrame( | |
| 1085 CreateFrame(sequence, frame_width, frame_height)); | |
| 1086 sink_.WaitForEncodedFrame(sequence++); | |
| 1087 | |
| 1088 stats = stats_proxy_->GetStats(); | |
| 1089 EXPECT_FALSE(stats.cpu_limited_resolution); | |
| 1090 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | |
| 1091 | |
| 1092 // Try to trigger overuse. Should not succeed. | |
| 1093 stats_proxy_->SetMockStats(mock_stats); | |
| 1094 vie_encoder_->TriggerCpuOveruse(); | |
| 1095 stats_proxy_->ResetMockStats(); | |
| 1096 | |
| 1097 stats = stats_proxy_->GetStats(); | |
| 1098 EXPECT_FALSE(stats.cpu_limited_resolution); | |
| 1099 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | |
| 1100 | |
| 1101 // Switch back the source with resolution adaptation enabled. | |
| 1102 vie_encoder_->SetSource( | |
| 1103 &video_source_, | |
| 1104 VideoSendStream::DegradationPreference::kMaintainFramerate); | |
| 1105 video_source_.IncomingCapturedFrame( | 952 video_source_.IncomingCapturedFrame( |
| 1106 CreateFrame(sequence, frame_width, frame_height)); | 953 CreateFrame(sequence, frame_width, frame_height)); |
| 1107 sink_.WaitForEncodedFrame(sequence++); | 954 sink_.WaitForEncodedFrame(sequence++); |
| 1108 stats = stats_proxy_->GetStats(); | 955 stats = stats_proxy_->GetStats(); |
| 1109 EXPECT_TRUE(stats.cpu_limited_resolution); | 956 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1110 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 957 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1111 | 958 |
| 1112 // Trigger CPU normal usage. | 959 // Trigger CPU normal usage. |
| 1113 vie_encoder_->TriggerCpuNormalUsage(); | 960 vie_encoder_->TriggerCpuNormalUsage(); |
| 1114 video_source_.IncomingCapturedFrame( | 961 video_source_.IncomingCapturedFrame( |
| 1115 CreateFrame(sequence, frame_width, frame_height)); | 962 CreateFrame(sequence, frame_width, frame_height)); |
| 1116 sink_.WaitForEncodedFrame(sequence++); | 963 sink_.WaitForEncodedFrame(sequence++); |
| 1117 stats = stats_proxy_->GetStats(); | 964 stats = stats_proxy_->GetStats(); |
| 1118 EXPECT_FALSE(stats.cpu_limited_resolution); | 965 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1119 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 966 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 1120 | |
| 1121 // Back to the source with adaptation off, set it back to maintain-resolution. | |
| 1122 vie_encoder_->SetSource( | |
| 1123 &new_video_source, | |
| 1124 VideoSendStream::DegradationPreference::kMaintainResolution); | |
| 1125 new_video_source.IncomingCapturedFrame( | |
| 1126 CreateFrame(sequence, frame_width, frame_height)); | |
| 1127 sink_.WaitForEncodedFrame(sequence++); | |
| 1128 stats = stats_proxy_->GetStats(); | |
| 1129 // Disabled, since we previously switched the source too disabled. | |
| 1130 EXPECT_FALSE(stats.cpu_limited_resolution); | |
| 1131 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | |
| 1132 | |
| 1133 // Trigger CPU normal usage. | |
| 1134 vie_encoder_->TriggerCpuNormalUsage(); | |
| 1135 new_video_source.IncomingCapturedFrame( | |
| 1136 CreateFrame(sequence, frame_width, frame_height)); | |
| 1137 sink_.WaitForEncodedFrame(sequence++); | |
| 1138 stats = stats_proxy_->GetStats(); | |
| 1139 EXPECT_FALSE(stats.cpu_limited_resolution); | |
| 1140 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); | |
| 1141 | 967 |
| 1142 vie_encoder_->Stop(); | 968 vie_encoder_->Stop(); |
| 1143 } | 969 } |
| 1144 | 970 |
| 1145 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { | 971 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { |
| 1146 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 972 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1147 | 973 |
| 1148 video_source_.IncomingCapturedFrame(CreateFrame(1, 1280, 720)); | 974 video_source_.IncomingCapturedFrame(CreateFrame(1, 1280, 720)); |
| 1149 sink_.WaitForEncodedFrame(1); | 975 sink_.WaitForEncodedFrame(1); |
| 1150 | 976 |
| 1151 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 977 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 1152 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, | 978 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, |
| 1153 stats.preferred_media_bitrate_bps); | 979 stats.preferred_media_bitrate_bps); |
| 1154 | 980 |
| 1155 vie_encoder_->Stop(); | 981 vie_encoder_->Stop(); |
| 1156 } | 982 } |
| 1157 | 983 |
| 1158 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 984 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
| 1159 int frame_width = 1280; | 985 int frame_width = 1280; |
| 1160 int frame_height = 720; | 986 int frame_height = 720; |
| 1161 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 987 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1162 | 988 |
| 1163 // Expect no scaling to begin with | 989 // Expect no scaling to begin with |
| 1164 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 990 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
| 1165 EXPECT_EQ(std::numeric_limits<int>::max(), | 991 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
| 1166 video_source_.sink_wants().max_pixel_count); | |
| 1167 | 992 |
| 1168 video_source_.IncomingCapturedFrame( | 993 video_source_.IncomingCapturedFrame( |
| 1169 CreateFrame(1, frame_width, frame_height)); | 994 CreateFrame(1, frame_width, frame_height)); |
| 1170 sink_.WaitForEncodedFrame(1); | 995 sink_.WaitForEncodedFrame(1); |
| 1171 | 996 |
| 1172 // Trigger scale down | 997 // Trigger scale down |
| 1173 vie_encoder_->TriggerQualityLow(); | 998 vie_encoder_->TriggerQualityLow(); |
| 1174 | 999 |
| 1175 video_source_.IncomingCapturedFrame( | 1000 video_source_.IncomingCapturedFrame( |
| 1176 CreateFrame(2, frame_width, frame_height)); | 1001 CreateFrame(2, frame_width, frame_height)); |
| 1177 sink_.WaitForEncodedFrame(2); | 1002 sink_.WaitForEncodedFrame(2); |
| 1178 | 1003 |
| 1179 // Expect a scale down. | 1004 // Expect a scale down. |
| 1180 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 1005 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
| 1181 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 1006 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, |
| 1182 frame_width * frame_height); | 1007 frame_width * frame_height); |
| 1183 | 1008 |
| 1184 // Set adaptation disabled. | 1009 // Set adaptation disabled. |
| 1185 test::FrameForwarder new_video_source; | 1010 test::FrameForwarder new_video_source; |
| 1186 vie_encoder_->SetSource( | 1011 vie_encoder_->SetSource( |
| 1187 &new_video_source, | 1012 &new_video_source, |
| 1188 VideoSendStream::DegradationPreference::kMaintainResolution); | 1013 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1189 | 1014 |
| 1190 // Trigger scale down | 1015 // Trigger scale down |
| 1191 vie_encoder_->TriggerQualityLow(); | 1016 vie_encoder_->TriggerQualityLow(); |
| 1192 new_video_source.IncomingCapturedFrame( | 1017 new_video_source.IncomingCapturedFrame( |
| 1193 CreateFrame(3, frame_width, frame_height)); | 1018 CreateFrame(3, frame_width, frame_height)); |
| 1194 sink_.WaitForEncodedFrame(3); | 1019 sink_.WaitForEncodedFrame(3); |
| 1195 | 1020 |
| 1196 // Expect no scaling | 1021 // Expect no scaling |
| 1197 EXPECT_EQ(std::numeric_limits<int>::max(), | 1022 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
| 1198 new_video_source.sink_wants().max_pixel_count); | |
| 1199 | 1023 |
| 1200 // Trigger scale up | 1024 // Trigger scale up |
| 1201 vie_encoder_->TriggerQualityHigh(); | 1025 vie_encoder_->TriggerQualityHigh(); |
| 1202 new_video_source.IncomingCapturedFrame( | 1026 new_video_source.IncomingCapturedFrame( |
| 1203 CreateFrame(4, frame_width, frame_height)); | 1027 CreateFrame(4, frame_width, frame_height)); |
| 1204 sink_.WaitForEncodedFrame(4); | 1028 sink_.WaitForEncodedFrame(4); |
| 1205 | 1029 |
| 1206 // Expect nothing to change, still no scaling | 1030 // Expect nothing to change, still no scaling |
| 1207 EXPECT_EQ(std::numeric_limits<int>::max(), | 1031 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
| 1208 new_video_source.sink_wants().max_pixel_count); | |
| 1209 | 1032 |
| 1210 vie_encoder_->Stop(); | 1033 vie_encoder_->Stop(); |
| 1211 } | 1034 } |
| 1212 | 1035 |
| 1213 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { | 1036 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { |
| 1214 int frame_width = 1280; | 1037 int frame_width = 1280; |
| 1215 int frame_height = 720; | 1038 int frame_height = 720; |
| 1216 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1039 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1217 | 1040 |
| 1218 for (size_t i = 1; i <= 10; i++) { | 1041 for (size_t i = 1; i <= 10; i++) { |
| 1219 video_source_.IncomingCapturedFrame( | 1042 video_source_.IncomingCapturedFrame( |
| 1220 CreateFrame(i, frame_width, frame_height)); | 1043 CreateFrame(i, frame_width, frame_height)); |
| 1221 sink_.WaitForEncodedFrame(i); | 1044 sink_.WaitForEncodedFrame(i); |
| 1222 // Trigger scale down | 1045 // Trigger scale down |
| 1223 vie_encoder_->TriggerQualityLow(); | 1046 vie_encoder_->TriggerQualityLow(); |
| 1224 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); | 1047 EXPECT_GE(*video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); |
| 1225 } | 1048 } |
| 1226 | 1049 |
| 1227 vie_encoder_->Stop(); | 1050 vie_encoder_->Stop(); |
| 1228 } | 1051 } |
| 1229 | 1052 |
| 1230 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { | 1053 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { |
| 1231 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1054 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1232 | 1055 |
| 1233 int frame_width = 640; | 1056 int frame_width = 640; |
| 1234 int frame_height = 360; | 1057 int frame_height = 360; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 int frame_width = 640; | 1130 int frame_width = 640; |
| 1308 int frame_height = 360; | 1131 int frame_height = 360; |
| 1309 | 1132 |
| 1310 video_source_.IncomingCapturedFrame( | 1133 video_source_.IncomingCapturedFrame( |
| 1311 CreateFrame(1, frame_width, frame_height)); | 1134 CreateFrame(1, frame_width, frame_height)); |
| 1312 | 1135 |
| 1313 // Expect to drop this frame, the wait should time out. | 1136 // Expect to drop this frame, the wait should time out. |
| 1314 sink_.ExpectDroppedFrame(); | 1137 sink_.ExpectDroppedFrame(); |
| 1315 | 1138 |
| 1316 // Expect the sink_wants to specify a scaled frame. | 1139 // Expect the sink_wants to specify a scaled frame. |
| 1317 EXPECT_LT(video_source_.sink_wants().max_pixel_count, 1000 * 1000); | 1140 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
| 1141 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, 1000 * 1000); |
| 1318 | 1142 |
| 1319 int last_pixel_count = video_source_.sink_wants().max_pixel_count; | 1143 int last_pixel_count = *video_source_.sink_wants().max_pixel_count; |
| 1320 | 1144 |
| 1321 // Next frame is scaled | 1145 // Next frame is scaled |
| 1322 video_source_.IncomingCapturedFrame( | 1146 video_source_.IncomingCapturedFrame( |
| 1323 CreateFrame(2, frame_width * 3 / 4, frame_height * 3 / 4)); | 1147 CreateFrame(2, frame_width * 3 / 4, frame_height * 3 / 4)); |
| 1324 | 1148 |
| 1325 // Expect to drop this frame, the wait should time out. | 1149 // Expect to drop this frame, the wait should time out. |
| 1326 sink_.ExpectDroppedFrame(); | 1150 sink_.ExpectDroppedFrame(); |
| 1327 | 1151 |
| 1328 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); |
| 1329 | 1153 |
| 1330 vie_encoder_->Stop(); | 1154 vie_encoder_->Stop(); |
| 1331 } | 1155 } |
| 1332 | 1156 |
| 1333 TEST_F(ViEEncoderTest, NrOfDroppedFramesLimited) { | 1157 TEST_F(ViEEncoderTest, NrOfDroppedFramesLimited) { |
| 1334 // 1kbps. This can never be achieved. | 1158 // 1kbps. This can never be achieved. |
| 1335 vie_encoder_->OnBitrateUpdated(1000, 0, 0); | 1159 vie_encoder_->OnBitrateUpdated(1000, 0, 0); |
| 1336 int frame_width = 640; | 1160 int frame_width = 640; |
| 1337 int frame_height = 360; | 1161 int frame_height = 360; |
| 1338 | 1162 |
| 1339 // We expect the n initial frames to get dropped. | 1163 // We expect the n initial frames to get dropped. |
| 1340 int i; | 1164 int i; |
| 1341 for (i = 1; i <= kMaxInitialFramedrop; ++i) { | 1165 for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
| 1342 video_source_.IncomingCapturedFrame( | 1166 video_source_.IncomingCapturedFrame( |
| 1343 CreateFrame(i, frame_width, frame_height)); | 1167 CreateFrame(i, frame_width, frame_height)); |
| 1344 sink_.ExpectDroppedFrame(); | 1168 sink_.ExpectDroppedFrame(); |
| 1345 } | 1169 } |
| 1346 // The n+1th frame should not be dropped, even though it's size is too large. | 1170 // The n+1th frame should not be dropped, even though it's size is too large. |
| 1347 video_source_.IncomingCapturedFrame( | 1171 video_source_.IncomingCapturedFrame( |
| 1348 CreateFrame(i, frame_width, frame_height)); | 1172 CreateFrame(i, frame_width, frame_height)); |
| 1349 sink_.WaitForEncodedFrame(i); | 1173 sink_.WaitForEncodedFrame(i); |
| 1350 | 1174 |
| 1351 // Expect the sink_wants to specify a scaled frame. | 1175 // Expect the sink_wants to specify a scaled frame. |
| 1352 EXPECT_LT(video_source_.sink_wants().max_pixel_count, 1000 * 1000); | 1176 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
| 1177 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, 1000 * 1000); |
| 1353 | 1178 |
| 1354 vie_encoder_->Stop(); | 1179 vie_encoder_->Stop(); |
| 1355 } | 1180 } |
| 1356 | 1181 |
| 1357 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { | 1182 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { |
| 1358 int frame_width = 640; | 1183 int frame_width = 640; |
| 1359 int frame_height = 360; | 1184 int frame_height = 360; |
| 1360 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1185 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 1361 | 1186 |
| 1362 // Set degradation preference. | 1187 // Set degradation preference. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 video_source_.IncomingCapturedFrame( | 1228 video_source_.IncomingCapturedFrame( |
| 1404 CreateFrame(1, kFrameWidth, kFrameHeight)); | 1229 CreateFrame(1, kFrameWidth, kFrameHeight)); |
| 1405 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1230 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 1406 | 1231 |
| 1407 // Trigger CPU overuse, downscale by 3/4. | 1232 // Trigger CPU overuse, downscale by 3/4. |
| 1408 vie_encoder_->TriggerCpuOveruse(); | 1233 vie_encoder_->TriggerCpuOveruse(); |
| 1409 video_source_.IncomingCapturedFrame( | 1234 video_source_.IncomingCapturedFrame( |
| 1410 CreateFrame(2, kFrameWidth, kFrameHeight)); | 1235 CreateFrame(2, kFrameWidth, kFrameHeight)); |
| 1411 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); | 1236 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
| 1412 | 1237 |
| 1413 // Trigger CPU normal use, return to original resolution; | 1238 // Trigger CPU normal use, return to original resoluton; |
| 1414 vie_encoder_->TriggerCpuNormalUsage(); | 1239 vie_encoder_->TriggerCpuNormalUsage(); |
| 1415 video_source_.IncomingCapturedFrame( | 1240 video_source_.IncomingCapturedFrame( |
| 1416 CreateFrame(3, kFrameWidth, kFrameHeight)); | 1241 CreateFrame(3, kFrameWidth, kFrameHeight)); |
| 1417 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1242 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 1418 | 1243 |
| 1419 vie_encoder_->Stop(); | 1244 vie_encoder_->Stop(); |
| 1420 } | 1245 } |
| 1421 | |
| 1422 TEST_F(ViEEncoderTest, AdaptsFrameOnOveruseWithMaintainResolution) { | |
| 1423 const int kDefaultFramerateFps = 30; | |
| 1424 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kDefaultFramerateFps; | |
| 1425 const int kFrameWidth = 1280; | |
| 1426 const int kFrameHeight = 720; | |
| 1427 rtc::ScopedFakeClock fake_clock; | |
| 1428 | |
| 1429 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
| 1430 vie_encoder_->SetSource( | |
| 1431 &video_source_, | |
| 1432 VideoSendStream::DegradationPreference::kMaintainResolution); | |
| 1433 video_source_.set_adaptation_enabled(true); | |
| 1434 | |
| 1435 fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); | |
| 1436 int64_t timestamp_ms = kFrameIntervalMs; | |
| 1437 | |
| 1438 video_source_.IncomingCapturedFrame( | |
| 1439 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
| 1440 sink_.WaitForEncodedFrame(timestamp_ms); | |
| 1441 | |
| 1442 // Try to trigger overuse. No fps estimate available => no effect. | |
| 1443 vie_encoder_->TriggerCpuOveruse(); | |
| 1444 | |
| 1445 // Insert frames for one second to get a stable estimate. | |
| 1446 for (int i = 0; i < kDefaultFramerateFps; ++i) { | |
| 1447 timestamp_ms += kFrameIntervalMs; | |
| 1448 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 1449 video_source_.IncomingCapturedFrame( | |
| 1450 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
| 1451 sink_.WaitForEncodedFrame(timestamp_ms); | |
| 1452 } | |
| 1453 | |
| 1454 // Trigger CPU overuse, reduce framerate by 2/3. | |
| 1455 vie_encoder_->TriggerCpuOveruse(); | |
| 1456 int num_frames_dropped = 0; | |
| 1457 for (int i = 0; i < kDefaultFramerateFps; ++i) { | |
| 1458 timestamp_ms += kFrameIntervalMs; | |
| 1459 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 1460 video_source_.IncomingCapturedFrame( | |
| 1461 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
| 1462 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | |
| 1463 ++num_frames_dropped; | |
| 1464 } else { | |
| 1465 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | |
| 1466 } | |
| 1467 } | |
| 1468 | |
| 1469 // TODO(sprang): Find where there's rounding errors or stuff causing the | |
| 1470 // margin here to be a little larger than we'd like (input fps estimate is | |
| 1471 // off) and the frame dropping is a little too aggressive. | |
| 1472 const int kErrorMargin = 5; | |
| 1473 EXPECT_NEAR(num_frames_dropped, | |
| 1474 kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), | |
| 1475 kErrorMargin); | |
| 1476 | |
| 1477 // Trigger CPU overuse, reduce framerate by 2/3 again. | |
| 1478 vie_encoder_->TriggerCpuOveruse(); | |
| 1479 num_frames_dropped = 0; | |
| 1480 for (int i = 0; i < kDefaultFramerateFps; ++i) { | |
| 1481 timestamp_ms += kFrameIntervalMs; | |
| 1482 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 1483 video_source_.IncomingCapturedFrame( | |
| 1484 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
| 1485 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | |
| 1486 ++num_frames_dropped; | |
| 1487 } else { | |
| 1488 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | |
| 1489 } | |
| 1490 } | |
| 1491 EXPECT_NEAR(num_frames_dropped, | |
| 1492 kDefaultFramerateFps - (kDefaultFramerateFps * 4 / 9), | |
| 1493 kErrorMargin); | |
| 1494 | |
| 1495 // Go back up one step. | |
| 1496 vie_encoder_->TriggerCpuNormalUsage(); | |
| 1497 num_frames_dropped = 0; | |
| 1498 for (int i = 0; i < kDefaultFramerateFps; ++i) { | |
| 1499 timestamp_ms += kFrameIntervalMs; | |
| 1500 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 1501 video_source_.IncomingCapturedFrame( | |
| 1502 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
| 1503 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | |
| 1504 ++num_frames_dropped; | |
| 1505 } else { | |
| 1506 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | |
| 1507 } | |
| 1508 } | |
| 1509 EXPECT_NEAR(num_frames_dropped, | |
| 1510 kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), | |
| 1511 kErrorMargin); | |
| 1512 | |
| 1513 // Go back up to original mode. | |
| 1514 vie_encoder_->TriggerCpuNormalUsage(); | |
| 1515 num_frames_dropped = 0; | |
| 1516 for (int i = 0; i < kDefaultFramerateFps; ++i) { | |
| 1517 timestamp_ms += kFrameIntervalMs; | |
| 1518 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 1519 video_source_.IncomingCapturedFrame( | |
| 1520 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
| 1521 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | |
| 1522 ++num_frames_dropped; | |
| 1523 } else { | |
| 1524 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | |
| 1525 } | |
| 1526 } | |
| 1527 EXPECT_NEAR(num_frames_dropped, 0, kErrorMargin); | |
| 1528 | |
| 1529 vie_encoder_->Stop(); | |
| 1530 } | |
| 1531 | |
| 1532 TEST_F(ViEEncoderTest, DoesntAdaptDownPastMinFramerate) { | |
| 1533 const int kFramerateFps = 5; | |
| 1534 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kFramerateFps; | |
| 1535 const int kMinFpsFrameInterval = rtc::kNumMillisecsPerSec / kMinFramerateFps; | |
| 1536 const int kFrameWidth = 1280; | |
| 1537 const int kFrameHeight = 720; | |
| 1538 | |
| 1539 rtc::ScopedFakeClock fake_clock; | |
| 1540 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
| 1541 vie_encoder_->SetSource( | |
| 1542 &video_source_, | |
| 1543 VideoSendStream::DegradationPreference::kMaintainResolution); | |
| 1544 video_source_.set_adaptation_enabled(true); | |
| 1545 | |
| 1546 fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); | |
| 1547 int64_t timestamp_ms = kFrameIntervalMs; | |
| 1548 | |
| 1549 // Trigger overuse as much as we can. | |
| 1550 for (int i = 0; i < ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { | |
| 1551 // Insert frames to get a new fps estimate... | |
| 1552 for (int j = 0; j < kFramerateFps; ++j) { | |
| 1553 video_source_.IncomingCapturedFrame( | |
| 1554 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
| 1555 timestamp_ms += kFrameIntervalMs; | |
| 1556 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 1557 } | |
| 1558 // ...and then try to adapt again. | |
| 1559 vie_encoder_->TriggerCpuOveruse(); | |
| 1560 } | |
| 1561 | |
| 1562 // Drain any frame in the pipeline. | |
| 1563 sink_.WaitForFrame(kDefaultTimeoutMs); | |
| 1564 | |
| 1565 // Insert frames at min fps, all should go through. | |
| 1566 for (int i = 0; i < 10; ++i) { | |
| 1567 timestamp_ms += kMinFpsFrameInterval; | |
| 1568 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); | |
| 1569 video_source_.IncomingCapturedFrame( | |
| 1570 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
| 1571 sink_.WaitForEncodedFrame(timestamp_ms); | |
| 1572 } | |
| 1573 | |
| 1574 vie_encoder_->Stop(); | |
| 1575 } | |
| 1576 } // namespace webrtc | 1246 } // namespace webrtc |
| OLD | NEW |