| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 void ResetMockStats() { | 244 void ResetMockStats() { |
| 245 rtc::CritScope cs(&lock_); | 245 rtc::CritScope cs(&lock_); |
| 246 mock_stats_.reset(); | 246 mock_stats_.reset(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 private: | 249 private: |
| 250 rtc::CriticalSection lock_; | 250 rtc::CriticalSection lock_; |
| 251 rtc::Optional<VideoSendStream::Stats> mock_stats_ GUARDED_BY(lock_); | 251 rtc::Optional<VideoSendStream::Stats> mock_stats_ GUARDED_BY(lock_); |
| 252 }; | 252 }; |
| 253 | 253 |
| 254 class MockBitrateObserver : public VideoBitrateAllocationObserver { |
| 255 public: |
| 256 MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&)); |
| 257 }; |
| 258 |
| 254 } // namespace | 259 } // namespace |
| 255 | 260 |
| 256 class ViEEncoderTest : public ::testing::Test { | 261 class ViEEncoderTest : public ::testing::Test { |
| 257 public: | 262 public: |
| 258 static const int kDefaultTimeoutMs = 30 * 1000; | 263 static const int kDefaultTimeoutMs = 30 * 1000; |
| 259 | 264 |
| 260 ViEEncoderTest() | 265 ViEEncoderTest() |
| 261 : video_send_config_(VideoSendStream::Config(nullptr)), | 266 : video_send_config_(VideoSendStream::Config(nullptr)), |
| 262 codec_width_(320), | 267 codec_width_(320), |
| 263 codec_height_(240), | 268 codec_height_(240), |
| 269 max_framerate_(30), |
| 264 fake_encoder_(), | 270 fake_encoder_(), |
| 265 stats_proxy_(new MockableSendStatisticsProxy( | 271 stats_proxy_(new MockableSendStatisticsProxy( |
| 266 Clock::GetRealTimeClock(), | 272 Clock::GetRealTimeClock(), |
| 267 video_send_config_, | 273 video_send_config_, |
| 268 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), | 274 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), |
| 269 sink_(&fake_encoder_) {} | 275 sink_(&fake_encoder_) {} |
| 270 | 276 |
| 271 void SetUp() override { | 277 void SetUp() override { |
| 272 metrics::Reset(); | 278 metrics::Reset(); |
| 273 video_send_config_ = VideoSendStream::Config(nullptr); | 279 video_send_config_ = VideoSendStream::Config(nullptr); |
| 274 video_send_config_.encoder_settings.encoder = &fake_encoder_; | 280 video_send_config_.encoder_settings.encoder = &fake_encoder_; |
| 275 video_send_config_.encoder_settings.payload_name = "FAKE"; | 281 video_send_config_.encoder_settings.payload_name = "FAKE"; |
| 276 video_send_config_.encoder_settings.payload_type = 125; | 282 video_send_config_.encoder_settings.payload_type = 125; |
| 277 | 283 |
| 278 VideoEncoderConfig video_encoder_config; | 284 VideoEncoderConfig video_encoder_config; |
| 279 test::FillEncoderConfiguration(1, &video_encoder_config); | 285 test::FillEncoderConfiguration(1, &video_encoder_config); |
| 286 video_encoder_config.video_stream_factory = |
| 287 new rtc::RefCountedObject<VideoStreamFactory>(1, max_framerate_); |
| 280 video_encoder_config_ = video_encoder_config.Copy(); | 288 video_encoder_config_ = video_encoder_config.Copy(); |
| 289 |
| 290 // Framerate limit is specified by the VideoStreamFactory. |
| 291 std::vector<VideoStream> streams = |
| 292 video_encoder_config.video_stream_factory->CreateEncoderStreams( |
| 293 codec_width_, codec_height_, video_encoder_config); |
| 294 max_framerate_ = streams[0].max_framerate; |
| 295 fake_clock_.SetTimeMicros(1234); |
| 296 |
| 281 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); | 297 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); |
| 282 } | 298 } |
| 283 | 299 |
| 284 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, | 300 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, |
| 285 bool nack_enabled) { | 301 bool nack_enabled) { |
| 286 if (vie_encoder_) | 302 if (vie_encoder_) |
| 287 vie_encoder_->Stop(); | 303 vie_encoder_->Stop(); |
| 288 vie_encoder_.reset(new ViEEncoderUnderTest( | 304 vie_encoder_.reset(new ViEEncoderUnderTest( |
| 289 stats_proxy_.get(), video_send_config_.encoder_settings)); | 305 stats_proxy_.get(), video_send_config_.encoder_settings)); |
| 290 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); | 306 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); |
| 291 vie_encoder_->SetSource( | 307 vie_encoder_->SetSource( |
| 292 &video_source_, | 308 &video_source_, |
| 293 VideoSendStream::DegradationPreference::kMaintainFramerate); | 309 VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 294 vie_encoder_->SetStartBitrate(kTargetBitrateBps); | 310 vie_encoder_->SetStartBitrate(kTargetBitrateBps); |
| 295 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 311 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 296 kMaxPayloadLength, nack_enabled); | 312 kMaxPayloadLength, nack_enabled); |
| 297 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 313 vie_encoder_->WaitUntilTaskQueueIsIdle(); |
| 298 } | 314 } |
| 299 | 315 |
| 300 void ResetEncoder(const std::string& payload_name, | 316 void ResetEncoder(const std::string& payload_name, |
| 301 size_t num_streams, | 317 size_t num_streams, |
| 302 size_t num_temporal_layers, | 318 size_t num_temporal_layers, |
| 303 bool nack_enabled) { | 319 bool nack_enabled, |
| 320 bool screenshare) { |
| 304 video_send_config_.encoder_settings.payload_name = payload_name; | 321 video_send_config_.encoder_settings.payload_name = payload_name; |
| 305 | 322 |
| 306 VideoEncoderConfig video_encoder_config; | 323 VideoEncoderConfig video_encoder_config; |
| 307 video_encoder_config.number_of_streams = num_streams; | 324 video_encoder_config.number_of_streams = num_streams; |
| 308 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; | 325 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
| 309 video_encoder_config.video_stream_factory = | 326 video_encoder_config.video_stream_factory = |
| 310 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers, | 327 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers, |
| 311 kDefaultFramerate); | 328 kDefaultFramerate); |
| 329 video_encoder_config.content_type = |
| 330 screenshare ? VideoEncoderConfig::ContentType::kScreen |
| 331 : VideoEncoderConfig::ContentType::kRealtimeVideo; |
| 312 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); | 332 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); |
| 313 } | 333 } |
| 314 | 334 |
| 315 VideoFrame CreateFrame(int64_t ntp_time_ms, | 335 VideoFrame CreateFrame(int64_t ntp_time_ms, |
| 316 rtc::Event* destruction_event) const { | 336 rtc::Event* destruction_event) const { |
| 317 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( | 337 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( |
| 318 destruction_event, codec_width_, codec_height_), | 338 destruction_event, codec_width_, codec_height_), |
| 319 99, 99, kVideoRotation_0); | 339 99, 99, kVideoRotation_0); |
| 320 frame.set_ntp_time_ms(ntp_time_ms); | 340 frame.set_ntp_time_ms(ntp_time_ms); |
| 321 return frame; | 341 return frame; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 EXPECT_FALSE(wants.target_pixel_count); | 419 EXPECT_FALSE(wants.target_pixel_count); |
| 400 } | 420 } |
| 401 | 421 |
| 402 void VerifyFpsEqResolutionMax(const rtc::VideoSinkWants& wants, | 422 void VerifyFpsEqResolutionMax(const rtc::VideoSinkWants& wants, |
| 403 int expected_fps) { | 423 int expected_fps) { |
| 404 EXPECT_EQ(expected_fps, wants.max_framerate_fps); | 424 EXPECT_EQ(expected_fps, wants.max_framerate_fps); |
| 405 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); | 425 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); |
| 406 EXPECT_FALSE(wants.target_pixel_count); | 426 EXPECT_FALSE(wants.target_pixel_count); |
| 407 } | 427 } |
| 408 | 428 |
| 429 void WaitForEncodedFrame(int64_t expected_ntp_time) { |
| 430 sink_.WaitForEncodedFrame(expected_ntp_time); |
| 431 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 432 } |
| 433 |
| 434 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, int64_t timeout_ms) { |
| 435 bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, timeout_ms); |
| 436 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 437 return ok; |
| 438 } |
| 439 |
| 440 void WaitForEncodedFrame(uint32_t expected_width, uint32_t expected_height) { |
| 441 sink_.WaitForEncodedFrame(expected_width, expected_height); |
| 442 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 443 } |
| 444 |
| 445 void ExpectDroppedFrame() { |
| 446 sink_.ExpectDroppedFrame(); |
| 447 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 448 } |
| 449 |
| 450 bool WaitForFrame(int64_t timeout_ms) { |
| 451 bool ok = sink_.WaitForFrame(timeout_ms); |
| 452 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 453 return ok; |
| 454 } |
| 455 |
| 409 class TestEncoder : public test::FakeEncoder { | 456 class TestEncoder : public test::FakeEncoder { |
| 410 public: | 457 public: |
| 411 TestEncoder() | 458 TestEncoder() |
| 412 : FakeEncoder(Clock::GetRealTimeClock()), | 459 : FakeEncoder(Clock::GetRealTimeClock()), |
| 413 continue_encode_event_(false, false) {} | 460 continue_encode_event_(false, false) {} |
| 414 | 461 |
| 415 VideoCodec codec_config() const { | 462 VideoCodec codec_config() const { |
| 416 rtc::CritScope lock(&crit_sect_); | 463 rtc::CritScope lock(&crit_sect_); |
| 417 return config_; | 464 return config_; |
| 418 } | 465 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 GUARDED_BY(local_crit_sect_); | 554 GUARDED_BY(local_crit_sect_); |
| 508 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false; | 555 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false; |
| 509 }; | 556 }; |
| 510 | 557 |
| 511 class TestSink : public ViEEncoder::EncoderSink { | 558 class TestSink : public ViEEncoder::EncoderSink { |
| 512 public: | 559 public: |
| 513 explicit TestSink(TestEncoder* test_encoder) | 560 explicit TestSink(TestEncoder* test_encoder) |
| 514 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} | 561 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} |
| 515 | 562 |
| 516 void WaitForEncodedFrame(int64_t expected_ntp_time) { | 563 void WaitForEncodedFrame(int64_t expected_ntp_time) { |
| 564 EXPECT_TRUE( |
| 565 TimedWaitForEncodedFrame(expected_ntp_time, kDefaultTimeoutMs)); |
| 566 } |
| 567 |
| 568 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, |
| 569 int64_t timeout_ms) { |
| 517 uint32_t timestamp = 0; | 570 uint32_t timestamp = 0; |
| 518 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 571 if (!encoded_frame_event_.Wait(timeout_ms)) |
| 572 return false; |
| 519 { | 573 { |
| 520 rtc::CritScope lock(&crit_); | 574 rtc::CritScope lock(&crit_); |
| 521 timestamp = last_timestamp_; | 575 timestamp = last_timestamp_; |
| 522 } | 576 } |
| 523 test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp); | 577 test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp); |
| 578 return true; |
| 524 } | 579 } |
| 525 | 580 |
| 526 void WaitForEncodedFrame(uint32_t expected_width, | 581 void WaitForEncodedFrame(uint32_t expected_width, |
| 527 uint32_t expected_height) { | 582 uint32_t expected_height) { |
| 528 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 583 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
| 529 CheckLastFrameSizeMathces(expected_width, expected_height); | 584 CheckLastFrameSizeMathces(expected_width, expected_height); |
| 530 } | 585 } |
| 531 | 586 |
| 532 void CheckLastFrameSizeMathces(uint32_t expected_width, | 587 void CheckLastFrameSizeMathces(uint32_t expected_width, |
| 533 uint32_t expected_height) { | 588 uint32_t expected_height) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 uint32_t last_width_ = 0; | 647 uint32_t last_width_ = 0; |
| 593 bool expect_frames_ = true; | 648 bool expect_frames_ = true; |
| 594 int number_of_reconfigurations_ = 0; | 649 int number_of_reconfigurations_ = 0; |
| 595 int min_transmit_bitrate_bps_ = 0; | 650 int min_transmit_bitrate_bps_ = 0; |
| 596 }; | 651 }; |
| 597 | 652 |
| 598 VideoSendStream::Config video_send_config_; | 653 VideoSendStream::Config video_send_config_; |
| 599 VideoEncoderConfig video_encoder_config_; | 654 VideoEncoderConfig video_encoder_config_; |
| 600 int codec_width_; | 655 int codec_width_; |
| 601 int codec_height_; | 656 int codec_height_; |
| 657 int max_framerate_; |
| 602 TestEncoder fake_encoder_; | 658 TestEncoder fake_encoder_; |
| 603 std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; | 659 std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; |
| 604 TestSink sink_; | 660 TestSink sink_; |
| 605 AdaptingFrameForwarder video_source_; | 661 AdaptingFrameForwarder video_source_; |
| 606 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; | 662 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; |
| 663 rtc::ScopedFakeClock fake_clock_; |
| 607 }; | 664 }; |
| 608 | 665 |
| 609 TEST_F(ViEEncoderTest, EncodeOneFrame) { | 666 TEST_F(ViEEncoderTest, EncodeOneFrame) { |
| 610 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 667 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 611 rtc::Event frame_destroyed_event(false, false); | 668 rtc::Event frame_destroyed_event(false, false); |
| 612 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 669 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
| 613 sink_.WaitForEncodedFrame(1); | 670 WaitForEncodedFrame(1); |
| 614 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 671 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
| 615 vie_encoder_->Stop(); | 672 vie_encoder_->Stop(); |
| 616 } | 673 } |
| 617 | 674 |
| 618 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { | 675 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { |
| 619 // Dropped since no target bitrate has been set. | 676 // Dropped since no target bitrate has been set. |
| 620 rtc::Event frame_destroyed_event(false, false); | 677 rtc::Event frame_destroyed_event(false, false); |
| 621 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 678 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
| 622 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 679 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
| 623 | 680 |
| 624 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 681 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 625 | 682 |
| 626 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 683 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
| 627 sink_.WaitForEncodedFrame(2); | 684 WaitForEncodedFrame(2); |
| 628 vie_encoder_->Stop(); | 685 vie_encoder_->Stop(); |
| 629 } | 686 } |
| 630 | 687 |
| 631 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { | 688 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { |
| 632 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 689 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 633 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 690 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 634 sink_.WaitForEncodedFrame(1); | 691 WaitForEncodedFrame(1); |
| 635 | 692 |
| 636 vie_encoder_->OnBitrateUpdated(0, 0, 0); | 693 vie_encoder_->OnBitrateUpdated(0, 0, 0); |
| 637 // Dropped since bitrate is zero. | 694 // Dropped since bitrate is zero. |
| 638 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 695 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
| 639 | 696 |
| 640 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 697 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 641 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 698 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
| 642 sink_.WaitForEncodedFrame(3); | 699 WaitForEncodedFrame(3); |
| 643 vie_encoder_->Stop(); | 700 vie_encoder_->Stop(); |
| 644 } | 701 } |
| 645 | 702 |
| 646 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { | 703 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { |
| 647 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 704 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 648 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 705 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 649 sink_.WaitForEncodedFrame(1); | 706 WaitForEncodedFrame(1); |
| 650 | 707 |
| 651 // This frame will be dropped since it has the same ntp timestamp. | 708 // This frame will be dropped since it has the same ntp timestamp. |
| 652 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 709 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 653 | 710 |
| 654 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 711 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
| 655 sink_.WaitForEncodedFrame(2); | 712 WaitForEncodedFrame(2); |
| 656 vie_encoder_->Stop(); | 713 vie_encoder_->Stop(); |
| 657 } | 714 } |
| 658 | 715 |
| 659 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { | 716 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { |
| 660 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 717 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 661 | 718 |
| 662 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 719 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 663 sink_.WaitForEncodedFrame(1); | 720 WaitForEncodedFrame(1); |
| 664 | 721 |
| 665 vie_encoder_->Stop(); | 722 vie_encoder_->Stop(); |
| 666 sink_.SetExpectNoFrames(); | 723 sink_.SetExpectNoFrames(); |
| 667 rtc::Event frame_destroyed_event(false, false); | 724 rtc::Event frame_destroyed_event(false, false); |
| 668 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); | 725 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); |
| 669 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 726 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
| 670 } | 727 } |
| 671 | 728 |
| 672 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { | 729 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { |
| 673 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 730 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 674 | 731 |
| 675 fake_encoder_.BlockNextEncode(); | 732 fake_encoder_.BlockNextEncode(); |
| 676 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 733 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 677 sink_.WaitForEncodedFrame(1); | 734 WaitForEncodedFrame(1); |
| 678 // Here, the encoder thread will be blocked in the TestEncoder waiting for a | 735 // Here, the encoder thread will be blocked in the TestEncoder waiting for a |
| 679 // call to ContinueEncode. | 736 // call to ContinueEncode. |
| 680 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 737 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
| 681 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 738 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
| 682 fake_encoder_.ContinueEncode(); | 739 fake_encoder_.ContinueEncode(); |
| 683 sink_.WaitForEncodedFrame(3); | 740 WaitForEncodedFrame(3); |
| 684 | 741 |
| 685 vie_encoder_->Stop(); | 742 vie_encoder_->Stop(); |
| 686 } | 743 } |
| 687 | 744 |
| 688 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { | 745 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { |
| 689 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 746 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 690 EXPECT_EQ(0, sink_.number_of_reconfigurations()); | 747 EXPECT_EQ(0, sink_.number_of_reconfigurations()); |
| 691 | 748 |
| 692 // Capture a frame and wait for it to synchronize with the encoder thread. | 749 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 693 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 750 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 694 sink_.WaitForEncodedFrame(1); | 751 WaitForEncodedFrame(1); |
| 695 // The encoder will have been configured once when the first frame is | 752 // The encoder will have been configured once when the first frame is |
| 696 // received. | 753 // received. |
| 697 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 754 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 698 | 755 |
| 699 VideoEncoderConfig video_encoder_config; | 756 VideoEncoderConfig video_encoder_config; |
| 700 test::FillEncoderConfiguration(1, &video_encoder_config); | 757 test::FillEncoderConfiguration(1, &video_encoder_config); |
| 701 video_encoder_config.min_transmit_bitrate_bps = 9999; | 758 video_encoder_config.min_transmit_bitrate_bps = 9999; |
| 702 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 759 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 703 kMaxPayloadLength, true /* nack_enabled */); | 760 kMaxPayloadLength, true /* nack_enabled */); |
| 704 | 761 |
| 705 // Capture a frame and wait for it to synchronize with the encoder thread. | 762 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 706 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 763 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
| 707 sink_.WaitForEncodedFrame(2); | 764 WaitForEncodedFrame(2); |
| 708 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 765 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
| 709 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); | 766 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); |
| 710 | 767 |
| 711 vie_encoder_->Stop(); | 768 vie_encoder_->Stop(); |
| 712 } | 769 } |
| 713 | 770 |
| 714 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { | 771 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { |
| 715 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 772 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 716 | 773 |
| 717 // Capture a frame and wait for it to synchronize with the encoder thread. | 774 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 718 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 775 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 719 sink_.WaitForEncodedFrame(1); | 776 WaitForEncodedFrame(1); |
| 720 // The encoder will have been configured once. | 777 // The encoder will have been configured once. |
| 721 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 778 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 722 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 779 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
| 723 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 780 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
| 724 | 781 |
| 725 codec_width_ *= 2; | 782 codec_width_ *= 2; |
| 726 codec_height_ *= 2; | 783 codec_height_ *= 2; |
| 727 // Capture a frame with a higher resolution and wait for it to synchronize | 784 // Capture a frame with a higher resolution and wait for it to synchronize |
| 728 // with the encoder thread. | 785 // with the encoder thread. |
| 729 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 786 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
| 730 sink_.WaitForEncodedFrame(2); | 787 WaitForEncodedFrame(2); |
| 731 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 788 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
| 732 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 789 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
| 733 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 790 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
| 734 | 791 |
| 735 vie_encoder_->Stop(); | 792 vie_encoder_->Stop(); |
| 736 } | 793 } |
| 737 | 794 |
| 738 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor1S1TLWithNackEnabled) { | 795 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor1S1TLWithNackEnabled) { |
| 739 const bool kNackEnabled = true; | 796 const bool kNackEnabled = true; |
| 740 const size_t kNumStreams = 1; | 797 const size_t kNumStreams = 1; |
| 741 const size_t kNumTl = 1; | 798 const size_t kNumTl = 1; |
| 742 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); | 799 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
| 743 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 800 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 744 | 801 |
| 745 // Capture a frame and wait for it to synchronize with the encoder thread. | 802 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 746 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 803 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 747 sink_.WaitForEncodedFrame(1); | 804 WaitForEncodedFrame(1); |
| 748 // The encoder have been configured once when the first frame is received. | 805 // The encoder have been configured once when the first frame is received. |
| 749 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 806 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 750 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 807 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
| 751 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 808 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
| 752 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 809 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
| 753 // Resilience is off for no temporal layers with nack on. | 810 // Resilience is off for no temporal layers with nack on. |
| 754 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); | 811 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); |
| 755 vie_encoder_->Stop(); | 812 vie_encoder_->Stop(); |
| 756 } | 813 } |
| 757 | 814 |
| 758 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor2S1TlWithNackEnabled) { | 815 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor2S1TlWithNackEnabled) { |
| 759 const bool kNackEnabled = true; | 816 const bool kNackEnabled = true; |
| 760 const size_t kNumStreams = 2; | 817 const size_t kNumStreams = 2; |
| 761 const size_t kNumTl = 1; | 818 const size_t kNumTl = 1; |
| 762 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); | 819 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
| 763 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 820 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 764 | 821 |
| 765 // Capture a frame and wait for it to synchronize with the encoder thread. | 822 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 766 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 823 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 767 sink_.WaitForEncodedFrame(1); | 824 WaitForEncodedFrame(1); |
| 768 // The encoder have been configured once when the first frame is received. | 825 // The encoder have been configured once when the first frame is received. |
| 769 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 826 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 770 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 827 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
| 771 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 828 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
| 772 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 829 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
| 773 // Resilience is off for no temporal layers and >1 streams with nack on. | 830 // Resilience is off for no temporal layers and >1 streams with nack on. |
| 774 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); | 831 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); |
| 775 vie_encoder_->Stop(); | 832 vie_encoder_->Stop(); |
| 776 } | 833 } |
| 777 | 834 |
| 778 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S1TLWithNackDisabled) { | 835 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S1TLWithNackDisabled) { |
| 779 const bool kNackEnabled = false; | 836 const bool kNackEnabled = false; |
| 780 const size_t kNumStreams = 1; | 837 const size_t kNumStreams = 1; |
| 781 const size_t kNumTl = 1; | 838 const size_t kNumTl = 1; |
| 782 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); | 839 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
| 783 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 840 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 784 | 841 |
| 785 // Capture a frame and wait for it to synchronize with the encoder thread. | 842 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 786 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 843 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 787 sink_.WaitForEncodedFrame(1); | 844 WaitForEncodedFrame(1); |
| 788 // The encoder have been configured once when the first frame is received. | 845 // The encoder have been configured once when the first frame is received. |
| 789 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 846 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 790 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 847 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
| 791 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 848 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
| 792 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 849 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
| 793 // Resilience is on for no temporal layers with nack off. | 850 // Resilience is on for no temporal layers with nack off. |
| 794 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); | 851 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); |
| 795 vie_encoder_->Stop(); | 852 vie_encoder_->Stop(); |
| 796 } | 853 } |
| 797 | 854 |
| 798 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S2TlWithNackEnabled) { | 855 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S2TlWithNackEnabled) { |
| 799 const bool kNackEnabled = true; | 856 const bool kNackEnabled = true; |
| 800 const size_t kNumStreams = 1; | 857 const size_t kNumStreams = 1; |
| 801 const size_t kNumTl = 2; | 858 const size_t kNumTl = 2; |
| 802 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); | 859 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
| 803 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 860 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 804 | 861 |
| 805 // Capture a frame and wait for it to synchronize with the encoder thread. | 862 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 806 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 863 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 807 sink_.WaitForEncodedFrame(1); | 864 WaitForEncodedFrame(1); |
| 808 // The encoder have been configured once when the first frame is received. | 865 // The encoder have been configured once when the first frame is received. |
| 809 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 866 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 810 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 867 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
| 811 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 868 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
| 812 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 869 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
| 813 // Resilience is on for temporal layers. | 870 // Resilience is on for temporal layers. |
| 814 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); | 871 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); |
| 815 vie_encoder_->Stop(); | 872 vie_encoder_->Stop(); |
| 816 } | 873 } |
| 817 | 874 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 841 VerifyNoLimitation(video_source_.sink_wants()); | 898 VerifyNoLimitation(video_source_.sink_wants()); |
| 842 | 899 |
| 843 int frame_width = 1280; | 900 int frame_width = 1280; |
| 844 int frame_height = 720; | 901 int frame_height = 720; |
| 845 | 902 |
| 846 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should | 903 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should |
| 847 // request lower resolution. | 904 // request lower resolution. |
| 848 for (int i = 1; i <= kMaxDowngrades; ++i) { | 905 for (int i = 1; i <= kMaxDowngrades; ++i) { |
| 849 video_source_.IncomingCapturedFrame( | 906 video_source_.IncomingCapturedFrame( |
| 850 CreateFrame(i, frame_width, frame_height)); | 907 CreateFrame(i, frame_width, frame_height)); |
| 851 sink_.WaitForEncodedFrame(i); | 908 WaitForEncodedFrame(i); |
| 852 | 909 |
| 853 vie_encoder_->TriggerCpuOveruse(); | 910 vie_encoder_->TriggerCpuOveruse(); |
| 854 | 911 |
| 855 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 912 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
| 856 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 913 EXPECT_LT(video_source_.sink_wants().max_pixel_count, |
| 857 frame_width * frame_height); | 914 frame_width * frame_height); |
| 858 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 915 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 859 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 916 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 860 | 917 |
| 861 frame_width /= 2; | 918 frame_width /= 2; |
| 862 frame_height /= 2; | 919 frame_height /= 2; |
| 863 } | 920 } |
| 864 | 921 |
| 865 // Trigger CPU overuse one more time. This should not trigger a request for | 922 // Trigger CPU overuse one more time. This should not trigger a request for |
| 866 // lower resolution. | 923 // lower resolution. |
| 867 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); | 924 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); |
| 868 video_source_.IncomingCapturedFrame( | 925 video_source_.IncomingCapturedFrame( |
| 869 CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); | 926 CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); |
| 870 sink_.WaitForEncodedFrame(kMaxDowngrades + 1); | 927 WaitForEncodedFrame(kMaxDowngrades + 1); |
| 871 vie_encoder_->TriggerCpuOveruse(); | 928 vie_encoder_->TriggerCpuOveruse(); |
| 872 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, | 929 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, |
| 873 current_wants.target_pixel_count); | 930 current_wants.target_pixel_count); |
| 874 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, | 931 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, |
| 875 current_wants.max_pixel_count); | 932 current_wants.max_pixel_count); |
| 876 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 933 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 877 EXPECT_EQ(kMaxDowngrades, | 934 EXPECT_EQ(kMaxDowngrades, |
| 878 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 935 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 879 | 936 |
| 880 // Trigger CPU normal use. | 937 // Trigger CPU normal use. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 VerifyNoLimitation(video_source_.sink_wants()); | 1005 VerifyNoLimitation(video_source_.sink_wants()); |
| 949 | 1006 |
| 950 const int kFrameWidth = 1280; | 1007 const int kFrameWidth = 1280; |
| 951 const int kFrameHeight = 720; | 1008 const int kFrameHeight = 720; |
| 952 const int kFrameIntervalMs = 1000 / 30; | 1009 const int kFrameIntervalMs = 1000 / 30; |
| 953 | 1010 |
| 954 int frame_timestamp = 1; | 1011 int frame_timestamp = 1; |
| 955 | 1012 |
| 956 video_source_.IncomingCapturedFrame( | 1013 video_source_.IncomingCapturedFrame( |
| 957 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 1014 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
| 958 sink_.WaitForEncodedFrame(frame_timestamp); | 1015 WaitForEncodedFrame(frame_timestamp); |
| 959 frame_timestamp += kFrameIntervalMs; | 1016 frame_timestamp += kFrameIntervalMs; |
| 960 | 1017 |
| 961 // Trigger CPU overuse. | 1018 // Trigger CPU overuse. |
| 962 vie_encoder_->TriggerCpuOveruse(); | 1019 vie_encoder_->TriggerCpuOveruse(); |
| 963 video_source_.IncomingCapturedFrame( | 1020 video_source_.IncomingCapturedFrame( |
| 964 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 1021 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
| 965 sink_.WaitForEncodedFrame(frame_timestamp); | 1022 WaitForEncodedFrame(frame_timestamp); |
| 966 frame_timestamp += kFrameIntervalMs; | 1023 frame_timestamp += kFrameIntervalMs; |
| 967 | 1024 |
| 968 // Default degradation preference is maintain-framerate, so will lower max | 1025 // Default degradation preference is maintain-framerate, so will lower max |
| 969 // wanted resolution. | 1026 // wanted resolution. |
| 970 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 1027 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
| 971 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 1028 EXPECT_LT(video_source_.sink_wants().max_pixel_count, |
| 972 kFrameWidth * kFrameHeight); | 1029 kFrameWidth * kFrameHeight); |
| 973 EXPECT_EQ(std::numeric_limits<int>::max(), | 1030 EXPECT_EQ(std::numeric_limits<int>::max(), |
| 974 video_source_.sink_wants().max_framerate_fps); | 1031 video_source_.sink_wants().max_framerate_fps); |
| 975 | 1032 |
| 976 // Set new source, switch to maintain-resolution. | 1033 // Set new source, switch to maintain-resolution. |
| 977 test::FrameForwarder new_video_source; | 1034 test::FrameForwarder new_video_source; |
| 978 vie_encoder_->SetSource( | 1035 vie_encoder_->SetSource( |
| 979 &new_video_source, | 1036 &new_video_source, |
| 980 VideoSendStream::DegradationPreference::kMaintainResolution); | 1037 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 981 | 1038 |
| 982 // Initially no degradation registered. | 1039 // Initially no degradation registered. |
| 983 VerifyNoLimitation(new_video_source.sink_wants()); | 1040 VerifyNoLimitation(new_video_source.sink_wants()); |
| 984 | 1041 |
| 985 // Force an input frame rate to be available, or the adaptation call won't | 1042 // Force an input frame rate to be available, or the adaptation call won't |
| 986 // know what framerate to adapt form. | 1043 // know what framerate to adapt form. |
| 987 const int kInputFps = 30; | 1044 const int kInputFps = 30; |
| 988 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1045 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 989 stats.input_frame_rate = kInputFps; | 1046 stats.input_frame_rate = kInputFps; |
| 990 stats_proxy_->SetMockStats(stats); | 1047 stats_proxy_->SetMockStats(stats); |
| 991 | 1048 |
| 992 vie_encoder_->TriggerCpuOveruse(); | 1049 vie_encoder_->TriggerCpuOveruse(); |
| 993 new_video_source.IncomingCapturedFrame( | 1050 new_video_source.IncomingCapturedFrame( |
| 994 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 1051 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
| 995 sink_.WaitForEncodedFrame(frame_timestamp); | 1052 WaitForEncodedFrame(frame_timestamp); |
| 996 frame_timestamp += kFrameIntervalMs; | 1053 frame_timestamp += kFrameIntervalMs; |
| 997 | 1054 |
| 998 // Some framerate constraint should be set. | 1055 // Some framerate constraint should be set. |
| 999 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 1056 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
| 1000 EXPECT_EQ(std::numeric_limits<int>::max(), | 1057 EXPECT_EQ(std::numeric_limits<int>::max(), |
| 1001 new_video_source.sink_wants().max_pixel_count); | 1058 new_video_source.sink_wants().max_pixel_count); |
| 1002 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); | 1059 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); |
| 1003 | 1060 |
| 1004 // Turn off degradation completely. | 1061 // Turn off degradation completely. |
| 1005 vie_encoder_->SetSource( | 1062 vie_encoder_->SetSource( |
| 1006 &new_video_source, | 1063 &new_video_source, |
| 1007 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1064 VideoSendStream::DegradationPreference::kDegradationDisabled); |
| 1008 VerifyNoLimitation(new_video_source.sink_wants()); | 1065 VerifyNoLimitation(new_video_source.sink_wants()); |
| 1009 | 1066 |
| 1010 vie_encoder_->TriggerCpuOveruse(); | 1067 vie_encoder_->TriggerCpuOveruse(); |
| 1011 new_video_source.IncomingCapturedFrame( | 1068 new_video_source.IncomingCapturedFrame( |
| 1012 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 1069 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
| 1013 sink_.WaitForEncodedFrame(frame_timestamp); | 1070 WaitForEncodedFrame(frame_timestamp); |
| 1014 frame_timestamp += kFrameIntervalMs; | 1071 frame_timestamp += kFrameIntervalMs; |
| 1015 | 1072 |
| 1016 // Still no degradation. | 1073 // Still no degradation. |
| 1017 VerifyNoLimitation(new_video_source.sink_wants()); | 1074 VerifyNoLimitation(new_video_source.sink_wants()); |
| 1018 | 1075 |
| 1019 // Calling SetSource with resolution scaling enabled apply the old SinkWants. | 1076 // Calling SetSource with resolution scaling enabled apply the old SinkWants. |
| 1020 vie_encoder_->SetSource( | 1077 vie_encoder_->SetSource( |
| 1021 &new_video_source, | 1078 &new_video_source, |
| 1022 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1079 VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1023 EXPECT_LT(new_video_source.sink_wants().max_pixel_count, | 1080 EXPECT_LT(new_video_source.sink_wants().max_pixel_count, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1037 | 1094 |
| 1038 vie_encoder_->Stop(); | 1095 vie_encoder_->Stop(); |
| 1039 } | 1096 } |
| 1040 | 1097 |
| 1041 TEST_F(ViEEncoderTest, StatsTracksQualityAdaptationStats) { | 1098 TEST_F(ViEEncoderTest, StatsTracksQualityAdaptationStats) { |
| 1042 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1099 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1043 | 1100 |
| 1044 const int kWidth = 1280; | 1101 const int kWidth = 1280; |
| 1045 const int kHeight = 720; | 1102 const int kHeight = 720; |
| 1046 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1103 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1047 sink_.WaitForEncodedFrame(1); | 1104 WaitForEncodedFrame(1); |
| 1048 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1105 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 1049 EXPECT_FALSE(stats.bw_limited_resolution); | 1106 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1050 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1107 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
| 1051 | 1108 |
| 1052 // Trigger adapt down. | 1109 // Trigger adapt down. |
| 1053 vie_encoder_->TriggerQualityLow(); | 1110 vie_encoder_->TriggerQualityLow(); |
| 1054 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1111 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1055 sink_.WaitForEncodedFrame(2); | 1112 WaitForEncodedFrame(2); |
| 1056 | 1113 |
| 1057 stats = stats_proxy_->GetStats(); | 1114 stats = stats_proxy_->GetStats(); |
| 1058 EXPECT_TRUE(stats.bw_limited_resolution); | 1115 EXPECT_TRUE(stats.bw_limited_resolution); |
| 1059 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1116 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
| 1060 | 1117 |
| 1061 // Trigger adapt up. | 1118 // Trigger adapt up. |
| 1062 vie_encoder_->TriggerQualityHigh(); | 1119 vie_encoder_->TriggerQualityHigh(); |
| 1063 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1120 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 1064 sink_.WaitForEncodedFrame(3); | 1121 WaitForEncodedFrame(3); |
| 1065 | 1122 |
| 1066 stats = stats_proxy_->GetStats(); | 1123 stats = stats_proxy_->GetStats(); |
| 1067 EXPECT_FALSE(stats.bw_limited_resolution); | 1124 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1068 EXPECT_EQ(2, stats.number_of_quality_adapt_changes); | 1125 EXPECT_EQ(2, stats.number_of_quality_adapt_changes); |
| 1069 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1126 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
| 1070 | 1127 |
| 1071 vie_encoder_->Stop(); | 1128 vie_encoder_->Stop(); |
| 1072 } | 1129 } |
| 1073 | 1130 |
| 1074 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStats) { | 1131 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStats) { |
| 1075 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1132 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1076 | 1133 |
| 1077 const int kWidth = 1280; | 1134 const int kWidth = 1280; |
| 1078 const int kHeight = 720; | 1135 const int kHeight = 720; |
| 1079 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1136 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1080 sink_.WaitForEncodedFrame(1); | 1137 WaitForEncodedFrame(1); |
| 1081 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1138 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 1082 EXPECT_FALSE(stats.cpu_limited_resolution); | 1139 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1083 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1140 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
| 1084 | 1141 |
| 1085 // Trigger CPU overuse. | 1142 // Trigger CPU overuse. |
| 1086 vie_encoder_->TriggerCpuOveruse(); | 1143 vie_encoder_->TriggerCpuOveruse(); |
| 1087 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1144 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1088 sink_.WaitForEncodedFrame(2); | 1145 WaitForEncodedFrame(2); |
| 1089 | 1146 |
| 1090 stats = stats_proxy_->GetStats(); | 1147 stats = stats_proxy_->GetStats(); |
| 1091 EXPECT_TRUE(stats.cpu_limited_resolution); | 1148 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1092 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1149 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1093 | 1150 |
| 1094 // Trigger CPU normal use. | 1151 // Trigger CPU normal use. |
| 1095 vie_encoder_->TriggerCpuNormalUsage(); | 1152 vie_encoder_->TriggerCpuNormalUsage(); |
| 1096 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1153 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 1097 sink_.WaitForEncodedFrame(3); | 1154 WaitForEncodedFrame(3); |
| 1098 | 1155 |
| 1099 stats = stats_proxy_->GetStats(); | 1156 stats = stats_proxy_->GetStats(); |
| 1100 EXPECT_FALSE(stats.cpu_limited_resolution); | 1157 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1101 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1158 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 1102 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1159 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
| 1103 | 1160 |
| 1104 vie_encoder_->Stop(); | 1161 vie_encoder_->Stop(); |
| 1105 } | 1162 } |
| 1106 | 1163 |
| 1107 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { | 1164 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { |
| 1108 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1165 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1109 | 1166 |
| 1110 const int kWidth = 1280; | 1167 const int kWidth = 1280; |
| 1111 const int kHeight = 720; | 1168 const int kHeight = 720; |
| 1112 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1169 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1113 sink_.WaitForEncodedFrame(1); | 1170 WaitForEncodedFrame(1); |
| 1114 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1171 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 1115 EXPECT_FALSE(stats.bw_limited_resolution); | 1172 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1116 EXPECT_FALSE(stats.cpu_limited_resolution); | 1173 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1117 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1174 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
| 1118 | 1175 |
| 1119 // Trigger CPU overuse. | 1176 // Trigger CPU overuse. |
| 1120 vie_encoder_->TriggerCpuOveruse(); | 1177 vie_encoder_->TriggerCpuOveruse(); |
| 1121 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1178 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1122 sink_.WaitForEncodedFrame(2); | 1179 WaitForEncodedFrame(2); |
| 1123 stats = stats_proxy_->GetStats(); | 1180 stats = stats_proxy_->GetStats(); |
| 1124 EXPECT_FALSE(stats.bw_limited_resolution); | 1181 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1125 EXPECT_TRUE(stats.cpu_limited_resolution); | 1182 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1126 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1183 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1127 | 1184 |
| 1128 // Set new source with adaptation still enabled. | 1185 // Set new source with adaptation still enabled. |
| 1129 test::FrameForwarder new_video_source; | 1186 test::FrameForwarder new_video_source; |
| 1130 vie_encoder_->SetSource( | 1187 vie_encoder_->SetSource( |
| 1131 &new_video_source, | 1188 &new_video_source, |
| 1132 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1189 VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1133 | 1190 |
| 1134 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1191 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 1135 sink_.WaitForEncodedFrame(3); | 1192 WaitForEncodedFrame(3); |
| 1136 stats = stats_proxy_->GetStats(); | 1193 stats = stats_proxy_->GetStats(); |
| 1137 EXPECT_FALSE(stats.bw_limited_resolution); | 1194 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1138 EXPECT_TRUE(stats.cpu_limited_resolution); | 1195 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1139 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1196 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1140 | 1197 |
| 1141 // Set adaptation disabled. | 1198 // Set adaptation disabled. |
| 1142 vie_encoder_->SetSource( | 1199 vie_encoder_->SetSource( |
| 1143 &new_video_source, | 1200 &new_video_source, |
| 1144 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1201 VideoSendStream::DegradationPreference::kDegradationDisabled); |
| 1145 | 1202 |
| 1146 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1203 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
| 1147 sink_.WaitForEncodedFrame(4); | 1204 WaitForEncodedFrame(4); |
| 1148 stats = stats_proxy_->GetStats(); | 1205 stats = stats_proxy_->GetStats(); |
| 1149 EXPECT_FALSE(stats.bw_limited_resolution); | 1206 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1150 EXPECT_FALSE(stats.cpu_limited_resolution); | 1207 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1151 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1208 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1152 | 1209 |
| 1153 // Set adaptation back to enabled. | 1210 // Set adaptation back to enabled. |
| 1154 vie_encoder_->SetSource( | 1211 vie_encoder_->SetSource( |
| 1155 &new_video_source, | 1212 &new_video_source, |
| 1156 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1213 VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1157 | 1214 |
| 1158 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1215 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
| 1159 sink_.WaitForEncodedFrame(5); | 1216 WaitForEncodedFrame(5); |
| 1160 stats = stats_proxy_->GetStats(); | 1217 stats = stats_proxy_->GetStats(); |
| 1161 EXPECT_FALSE(stats.bw_limited_resolution); | 1218 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1162 EXPECT_TRUE(stats.cpu_limited_resolution); | 1219 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1163 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1220 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1164 | 1221 |
| 1165 // Trigger CPU normal use. | 1222 // Trigger CPU normal use. |
| 1166 vie_encoder_->TriggerCpuNormalUsage(); | 1223 vie_encoder_->TriggerCpuNormalUsage(); |
| 1167 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); | 1224 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
| 1168 sink_.WaitForEncodedFrame(6); | 1225 WaitForEncodedFrame(6); |
| 1169 stats = stats_proxy_->GetStats(); | 1226 stats = stats_proxy_->GetStats(); |
| 1170 EXPECT_FALSE(stats.bw_limited_resolution); | 1227 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1171 EXPECT_FALSE(stats.cpu_limited_resolution); | 1228 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1172 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1229 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 1173 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1230 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
| 1174 | 1231 |
| 1175 vie_encoder_->Stop(); | 1232 vie_encoder_->Stop(); |
| 1176 } | 1233 } |
| 1177 | 1234 |
| 1178 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { | 1235 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { |
| 1179 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1236 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1180 | 1237 |
| 1181 const int kWidth = 1280; | 1238 const int kWidth = 1280; |
| 1182 const int kHeight = 720; | 1239 const int kHeight = 720; |
| 1183 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1240 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1184 sink_.WaitForEncodedFrame(1); | 1241 WaitForEncodedFrame(1); |
| 1185 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1242 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 1186 EXPECT_FALSE(stats.bw_limited_resolution); | 1243 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1187 EXPECT_FALSE(stats.bw_limited_framerate); | 1244 EXPECT_FALSE(stats.bw_limited_framerate); |
| 1188 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1245 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
| 1189 | 1246 |
| 1190 // Set new source with adaptation still enabled. | 1247 // Set new source with adaptation still enabled. |
| 1191 test::FrameForwarder new_video_source; | 1248 test::FrameForwarder new_video_source; |
| 1192 vie_encoder_->SetSource(&new_video_source, | 1249 vie_encoder_->SetSource(&new_video_source, |
| 1193 VideoSendStream::DegradationPreference::kBalanced); | 1250 VideoSendStream::DegradationPreference::kBalanced); |
| 1194 | 1251 |
| 1195 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1252 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1196 sink_.WaitForEncodedFrame(2); | 1253 WaitForEncodedFrame(2); |
| 1197 stats = stats_proxy_->GetStats(); | 1254 stats = stats_proxy_->GetStats(); |
| 1198 EXPECT_FALSE(stats.bw_limited_resolution); | 1255 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1199 EXPECT_FALSE(stats.bw_limited_framerate); | 1256 EXPECT_FALSE(stats.bw_limited_framerate); |
| 1200 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1257 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
| 1201 | 1258 |
| 1202 // Trigger adapt down. | 1259 // Trigger adapt down. |
| 1203 vie_encoder_->TriggerQualityLow(); | 1260 vie_encoder_->TriggerQualityLow(); |
| 1204 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1261 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 1205 sink_.WaitForEncodedFrame(3); | 1262 WaitForEncodedFrame(3); |
| 1206 stats = stats_proxy_->GetStats(); | 1263 stats = stats_proxy_->GetStats(); |
| 1207 EXPECT_TRUE(stats.bw_limited_resolution); | 1264 EXPECT_TRUE(stats.bw_limited_resolution); |
| 1208 EXPECT_FALSE(stats.bw_limited_framerate); | 1265 EXPECT_FALSE(stats.bw_limited_framerate); |
| 1209 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1266 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
| 1210 | 1267 |
| 1211 // Set new source with adaptation still enabled. | 1268 // Set new source with adaptation still enabled. |
| 1212 vie_encoder_->SetSource(&new_video_source, | 1269 vie_encoder_->SetSource(&new_video_source, |
| 1213 VideoSendStream::DegradationPreference::kBalanced); | 1270 VideoSendStream::DegradationPreference::kBalanced); |
| 1214 | 1271 |
| 1215 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1272 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
| 1216 sink_.WaitForEncodedFrame(4); | 1273 WaitForEncodedFrame(4); |
| 1217 stats = stats_proxy_->GetStats(); | 1274 stats = stats_proxy_->GetStats(); |
| 1218 EXPECT_TRUE(stats.bw_limited_resolution); | 1275 EXPECT_TRUE(stats.bw_limited_resolution); |
| 1219 EXPECT_FALSE(stats.bw_limited_framerate); | 1276 EXPECT_FALSE(stats.bw_limited_framerate); |
| 1220 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1277 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
| 1221 | 1278 |
| 1222 // Disable resolution scaling. | 1279 // Disable resolution scaling. |
| 1223 vie_encoder_->SetSource( | 1280 vie_encoder_->SetSource( |
| 1224 &new_video_source, | 1281 &new_video_source, |
| 1225 VideoSendStream::DegradationPreference::kMaintainResolution); | 1282 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1226 | 1283 |
| 1227 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1284 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
| 1228 sink_.WaitForEncodedFrame(5); | 1285 WaitForEncodedFrame(5); |
| 1229 stats = stats_proxy_->GetStats(); | 1286 stats = stats_proxy_->GetStats(); |
| 1230 EXPECT_FALSE(stats.bw_limited_resolution); | 1287 EXPECT_FALSE(stats.bw_limited_resolution); |
| 1231 EXPECT_FALSE(stats.bw_limited_framerate); | 1288 EXPECT_FALSE(stats.bw_limited_framerate); |
| 1232 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1289 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
| 1233 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1290 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
| 1234 | 1291 |
| 1235 vie_encoder_->Stop(); | 1292 vie_encoder_->Stop(); |
| 1236 } | 1293 } |
| 1237 | 1294 |
| 1238 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { | 1295 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { |
| 1239 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1296 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1240 | 1297 |
| 1241 const int kWidth = 1280; | 1298 const int kWidth = 1280; |
| 1242 const int kHeight = 720; | 1299 const int kHeight = 720; |
| 1243 video_source_.set_adaptation_enabled(true); | 1300 video_source_.set_adaptation_enabled(true); |
| 1244 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1301 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1245 sink_.WaitForEncodedFrame(1); | 1302 WaitForEncodedFrame(1); |
| 1246 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1303 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1247 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1304 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1248 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1305 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1249 | 1306 |
| 1250 // Trigger adapt down. | 1307 // Trigger adapt down. |
| 1251 vie_encoder_->TriggerQualityLow(); | 1308 vie_encoder_->TriggerQualityLow(); |
| 1252 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1309 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1253 sink_.WaitForEncodedFrame(2); | 1310 WaitForEncodedFrame(2); |
| 1254 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1311 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1255 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1312 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1256 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1313 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1257 | 1314 |
| 1258 // Trigger overuse. | 1315 // Trigger overuse. |
| 1259 vie_encoder_->TriggerCpuOveruse(); | 1316 vie_encoder_->TriggerCpuOveruse(); |
| 1260 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1317 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 1261 sink_.WaitForEncodedFrame(3); | 1318 WaitForEncodedFrame(3); |
| 1262 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1319 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1263 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1320 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1264 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1321 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1265 | 1322 |
| 1266 // Set source with adaptation still enabled but quality scaler is off. | 1323 // Set source with adaptation still enabled but quality scaler is off. |
| 1267 fake_encoder_.SetQualityScaling(false); | 1324 fake_encoder_.SetQualityScaling(false); |
| 1268 vie_encoder_->SetSource( | 1325 vie_encoder_->SetSource( |
| 1269 &video_source_, | 1326 &video_source_, |
| 1270 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1327 VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1271 | 1328 |
| 1272 video_source_.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1329 video_source_.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
| 1273 sink_.WaitForEncodedFrame(4); | 1330 WaitForEncodedFrame(4); |
| 1274 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1331 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1275 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1332 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1276 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1333 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1277 | 1334 |
| 1278 vie_encoder_->Stop(); | 1335 vie_encoder_->Stop(); |
| 1279 } | 1336 } |
| 1280 | 1337 |
| 1281 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStatsWhenSwitchingSource) { | 1338 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStatsWhenSwitchingSource) { |
| 1282 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1339 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1283 | 1340 |
| 1284 const int kWidth = 1280; | 1341 const int kWidth = 1280; |
| 1285 const int kHeight = 720; | 1342 const int kHeight = 720; |
| 1286 int sequence = 1; | 1343 int sequence = 1; |
| 1287 | 1344 |
| 1288 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1345 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
| 1289 sink_.WaitForEncodedFrame(sequence++); | 1346 WaitForEncodedFrame(sequence++); |
| 1290 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1347 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 1291 EXPECT_FALSE(stats.cpu_limited_resolution); | 1348 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1292 EXPECT_FALSE(stats.cpu_limited_framerate); | 1349 EXPECT_FALSE(stats.cpu_limited_framerate); |
| 1293 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1350 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
| 1294 | 1351 |
| 1295 // Trigger CPU overuse, should now adapt down. | 1352 // Trigger CPU overuse, should now adapt down. |
| 1296 vie_encoder_->TriggerCpuOveruse(); | 1353 vie_encoder_->TriggerCpuOveruse(); |
| 1297 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1354 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
| 1298 sink_.WaitForEncodedFrame(sequence++); | 1355 WaitForEncodedFrame(sequence++); |
| 1299 stats = stats_proxy_->GetStats(); | 1356 stats = stats_proxy_->GetStats(); |
| 1300 EXPECT_TRUE(stats.cpu_limited_resolution); | 1357 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1301 EXPECT_FALSE(stats.cpu_limited_framerate); | 1358 EXPECT_FALSE(stats.cpu_limited_framerate); |
| 1302 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1359 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1303 | 1360 |
| 1304 // Set new source with adaptation still enabled. | 1361 // Set new source with adaptation still enabled. |
| 1305 test::FrameForwarder new_video_source; | 1362 test::FrameForwarder new_video_source; |
| 1306 vie_encoder_->SetSource( | 1363 vie_encoder_->SetSource( |
| 1307 &new_video_source, | 1364 &new_video_source, |
| 1308 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1365 VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1309 | 1366 |
| 1310 new_video_source.IncomingCapturedFrame( | 1367 new_video_source.IncomingCapturedFrame( |
| 1311 CreateFrame(sequence, kWidth, kHeight)); | 1368 CreateFrame(sequence, kWidth, kHeight)); |
| 1312 sink_.WaitForEncodedFrame(sequence++); | 1369 WaitForEncodedFrame(sequence++); |
| 1313 stats = stats_proxy_->GetStats(); | 1370 stats = stats_proxy_->GetStats(); |
| 1314 EXPECT_TRUE(stats.cpu_limited_resolution); | 1371 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1315 EXPECT_FALSE(stats.cpu_limited_framerate); | 1372 EXPECT_FALSE(stats.cpu_limited_framerate); |
| 1316 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1373 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1317 | 1374 |
| 1318 // Set cpu adaptation by frame dropping. | 1375 // Set cpu adaptation by frame dropping. |
| 1319 vie_encoder_->SetSource( | 1376 vie_encoder_->SetSource( |
| 1320 &new_video_source, | 1377 &new_video_source, |
| 1321 VideoSendStream::DegradationPreference::kMaintainResolution); | 1378 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1322 new_video_source.IncomingCapturedFrame( | 1379 new_video_source.IncomingCapturedFrame( |
| 1323 CreateFrame(sequence, kWidth, kHeight)); | 1380 CreateFrame(sequence, kWidth, kHeight)); |
| 1324 sink_.WaitForEncodedFrame(sequence++); | 1381 WaitForEncodedFrame(sequence++); |
| 1325 stats = stats_proxy_->GetStats(); | 1382 stats = stats_proxy_->GetStats(); |
| 1326 // Not adapted at first. | 1383 // Not adapted at first. |
| 1327 EXPECT_FALSE(stats.cpu_limited_resolution); | 1384 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1328 EXPECT_FALSE(stats.cpu_limited_framerate); | 1385 EXPECT_FALSE(stats.cpu_limited_framerate); |
| 1329 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1386 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 1330 | 1387 |
| 1331 // Force an input frame rate to be available, or the adaptation call won't | 1388 // Force an input frame rate to be available, or the adaptation call won't |
| 1332 // know what framerate to adapt from. | 1389 // know what framerate to adapt from. |
| 1333 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); | 1390 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); |
| 1334 mock_stats.input_frame_rate = 30; | 1391 mock_stats.input_frame_rate = 30; |
| 1335 stats_proxy_->SetMockStats(mock_stats); | 1392 stats_proxy_->SetMockStats(mock_stats); |
| 1336 vie_encoder_->TriggerCpuOveruse(); | 1393 vie_encoder_->TriggerCpuOveruse(); |
| 1337 stats_proxy_->ResetMockStats(); | 1394 stats_proxy_->ResetMockStats(); |
| 1338 | 1395 |
| 1339 new_video_source.IncomingCapturedFrame( | 1396 new_video_source.IncomingCapturedFrame( |
| 1340 CreateFrame(sequence, kWidth, kHeight)); | 1397 CreateFrame(sequence, kWidth, kHeight)); |
| 1341 sink_.WaitForEncodedFrame(sequence++); | 1398 WaitForEncodedFrame(sequence++); |
| 1342 | 1399 |
| 1343 // Framerate now adapted. | 1400 // Framerate now adapted. |
| 1344 stats = stats_proxy_->GetStats(); | 1401 stats = stats_proxy_->GetStats(); |
| 1345 EXPECT_FALSE(stats.cpu_limited_resolution); | 1402 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1346 EXPECT_TRUE(stats.cpu_limited_framerate); | 1403 EXPECT_TRUE(stats.cpu_limited_framerate); |
| 1347 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1404 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 1348 | 1405 |
| 1349 // Disable CPU adaptation. | 1406 // Disable CPU adaptation. |
| 1350 vie_encoder_->SetSource( | 1407 vie_encoder_->SetSource( |
| 1351 &new_video_source, | 1408 &new_video_source, |
| 1352 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1409 VideoSendStream::DegradationPreference::kDegradationDisabled); |
| 1353 new_video_source.IncomingCapturedFrame( | 1410 new_video_source.IncomingCapturedFrame( |
| 1354 CreateFrame(sequence, kWidth, kHeight)); | 1411 CreateFrame(sequence, kWidth, kHeight)); |
| 1355 sink_.WaitForEncodedFrame(sequence++); | 1412 WaitForEncodedFrame(sequence++); |
| 1356 | 1413 |
| 1357 stats = stats_proxy_->GetStats(); | 1414 stats = stats_proxy_->GetStats(); |
| 1358 EXPECT_FALSE(stats.cpu_limited_resolution); | 1415 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1359 EXPECT_FALSE(stats.cpu_limited_framerate); | 1416 EXPECT_FALSE(stats.cpu_limited_framerate); |
| 1360 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1417 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 1361 | 1418 |
| 1362 // Try to trigger overuse. Should not succeed. | 1419 // Try to trigger overuse. Should not succeed. |
| 1363 stats_proxy_->SetMockStats(mock_stats); | 1420 stats_proxy_->SetMockStats(mock_stats); |
| 1364 vie_encoder_->TriggerCpuOveruse(); | 1421 vie_encoder_->TriggerCpuOveruse(); |
| 1365 stats_proxy_->ResetMockStats(); | 1422 stats_proxy_->ResetMockStats(); |
| 1366 | 1423 |
| 1367 stats = stats_proxy_->GetStats(); | 1424 stats = stats_proxy_->GetStats(); |
| 1368 EXPECT_FALSE(stats.cpu_limited_resolution); | 1425 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1369 EXPECT_FALSE(stats.cpu_limited_framerate); | 1426 EXPECT_FALSE(stats.cpu_limited_framerate); |
| 1370 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1427 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 1371 | 1428 |
| 1372 // Switch back the source with resolution adaptation enabled. | 1429 // Switch back the source with resolution adaptation enabled. |
| 1373 vie_encoder_->SetSource( | 1430 vie_encoder_->SetSource( |
| 1374 &video_source_, | 1431 &video_source_, |
| 1375 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1432 VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1376 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1433 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
| 1377 sink_.WaitForEncodedFrame(sequence++); | 1434 WaitForEncodedFrame(sequence++); |
| 1378 stats = stats_proxy_->GetStats(); | 1435 stats = stats_proxy_->GetStats(); |
| 1379 EXPECT_TRUE(stats.cpu_limited_resolution); | 1436 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 1380 EXPECT_FALSE(stats.cpu_limited_framerate); | 1437 EXPECT_FALSE(stats.cpu_limited_framerate); |
| 1381 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1438 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 1382 | 1439 |
| 1383 // Trigger CPU normal usage. | 1440 // Trigger CPU normal usage. |
| 1384 vie_encoder_->TriggerCpuNormalUsage(); | 1441 vie_encoder_->TriggerCpuNormalUsage(); |
| 1385 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1442 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
| 1386 sink_.WaitForEncodedFrame(sequence++); | 1443 WaitForEncodedFrame(sequence++); |
| 1387 stats = stats_proxy_->GetStats(); | 1444 stats = stats_proxy_->GetStats(); |
| 1388 EXPECT_FALSE(stats.cpu_limited_resolution); | 1445 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1389 EXPECT_FALSE(stats.cpu_limited_framerate); | 1446 EXPECT_FALSE(stats.cpu_limited_framerate); |
| 1390 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1447 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
| 1391 | 1448 |
| 1392 // Back to the source with adaptation off, set it back to maintain-resolution. | 1449 // Back to the source with adaptation off, set it back to maintain-resolution. |
| 1393 vie_encoder_->SetSource( | 1450 vie_encoder_->SetSource( |
| 1394 &new_video_source, | 1451 &new_video_source, |
| 1395 VideoSendStream::DegradationPreference::kMaintainResolution); | 1452 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1396 new_video_source.IncomingCapturedFrame( | 1453 new_video_source.IncomingCapturedFrame( |
| 1397 CreateFrame(sequence, kWidth, kHeight)); | 1454 CreateFrame(sequence, kWidth, kHeight)); |
| 1398 sink_.WaitForEncodedFrame(sequence++); | 1455 WaitForEncodedFrame(sequence++); |
| 1399 stats = stats_proxy_->GetStats(); | 1456 stats = stats_proxy_->GetStats(); |
| 1400 // Disabled, since we previously switched the source to disabled. | 1457 // Disabled, since we previously switched the source to disabled. |
| 1401 EXPECT_FALSE(stats.cpu_limited_resolution); | 1458 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1402 EXPECT_TRUE(stats.cpu_limited_framerate); | 1459 EXPECT_TRUE(stats.cpu_limited_framerate); |
| 1403 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1460 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
| 1404 | 1461 |
| 1405 // Trigger CPU normal usage. | 1462 // Trigger CPU normal usage. |
| 1406 vie_encoder_->TriggerCpuNormalUsage(); | 1463 vie_encoder_->TriggerCpuNormalUsage(); |
| 1407 new_video_source.IncomingCapturedFrame( | 1464 new_video_source.IncomingCapturedFrame( |
| 1408 CreateFrame(sequence, kWidth, kHeight)); | 1465 CreateFrame(sequence, kWidth, kHeight)); |
| 1409 sink_.WaitForEncodedFrame(sequence++); | 1466 WaitForEncodedFrame(sequence++); |
| 1410 stats = stats_proxy_->GetStats(); | 1467 stats = stats_proxy_->GetStats(); |
| 1411 EXPECT_FALSE(stats.cpu_limited_resolution); | 1468 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 1412 EXPECT_FALSE(stats.cpu_limited_framerate); | 1469 EXPECT_FALSE(stats.cpu_limited_framerate); |
| 1413 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); | 1470 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); |
| 1414 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1471 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
| 1415 | 1472 |
| 1416 vie_encoder_->Stop(); | 1473 vie_encoder_->Stop(); |
| 1417 } | 1474 } |
| 1418 | 1475 |
| 1419 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { | 1476 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { |
| 1420 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1477 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1421 | 1478 |
| 1422 const int kWidth = 1280; | 1479 const int kWidth = 1280; |
| 1423 const int kHeight = 720; | 1480 const int kHeight = 720; |
| 1424 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1481 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1425 sink_.WaitForEncodedFrame(1); | 1482 WaitForEncodedFrame(1); |
| 1426 | 1483 |
| 1427 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1484 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 1428 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, | 1485 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, |
| 1429 stats.preferred_media_bitrate_bps); | 1486 stats.preferred_media_bitrate_bps); |
| 1430 | 1487 |
| 1431 vie_encoder_->Stop(); | 1488 vie_encoder_->Stop(); |
| 1432 } | 1489 } |
| 1433 | 1490 |
| 1434 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 1491 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
| 1435 const int kWidth = 1280; | 1492 const int kWidth = 1280; |
| 1436 const int kHeight = 720; | 1493 const int kHeight = 720; |
| 1437 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1494 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1438 | 1495 |
| 1439 // Expect no scaling to begin with. | 1496 // Expect no scaling to begin with. |
| 1440 VerifyNoLimitation(video_source_.sink_wants()); | 1497 VerifyNoLimitation(video_source_.sink_wants()); |
| 1441 | 1498 |
| 1442 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1499 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1443 sink_.WaitForEncodedFrame(1); | 1500 WaitForEncodedFrame(1); |
| 1444 | 1501 |
| 1445 // Trigger scale down. | 1502 // Trigger scale down. |
| 1446 vie_encoder_->TriggerQualityLow(); | 1503 vie_encoder_->TriggerQualityLow(); |
| 1447 | 1504 |
| 1448 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1505 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1449 sink_.WaitForEncodedFrame(2); | 1506 WaitForEncodedFrame(2); |
| 1450 | 1507 |
| 1451 // Expect a scale down. | 1508 // Expect a scale down. |
| 1452 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 1509 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
| 1453 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 1510 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
| 1454 | 1511 |
| 1455 // Set resolution scaling disabled. | 1512 // Set resolution scaling disabled. |
| 1456 test::FrameForwarder new_video_source; | 1513 test::FrameForwarder new_video_source; |
| 1457 vie_encoder_->SetSource( | 1514 vie_encoder_->SetSource( |
| 1458 &new_video_source, | 1515 &new_video_source, |
| 1459 VideoSendStream::DegradationPreference::kMaintainResolution); | 1516 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1460 | 1517 |
| 1461 // Trigger scale down. | 1518 // Trigger scale down. |
| 1462 vie_encoder_->TriggerQualityLow(); | 1519 vie_encoder_->TriggerQualityLow(); |
| 1463 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1520 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 1464 sink_.WaitForEncodedFrame(3); | 1521 WaitForEncodedFrame(3); |
| 1465 | 1522 |
| 1466 // Expect no scaling. | 1523 // Expect no scaling. |
| 1467 EXPECT_EQ(std::numeric_limits<int>::max(), | 1524 EXPECT_EQ(std::numeric_limits<int>::max(), |
| 1468 new_video_source.sink_wants().max_pixel_count); | 1525 new_video_source.sink_wants().max_pixel_count); |
| 1469 | 1526 |
| 1470 // Trigger scale up. | 1527 // Trigger scale up. |
| 1471 vie_encoder_->TriggerQualityHigh(); | 1528 vie_encoder_->TriggerQualityHigh(); |
| 1472 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1529 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
| 1473 sink_.WaitForEncodedFrame(4); | 1530 WaitForEncodedFrame(4); |
| 1474 | 1531 |
| 1475 // Expect nothing to change, still no scaling. | 1532 // Expect nothing to change, still no scaling. |
| 1476 EXPECT_EQ(std::numeric_limits<int>::max(), | 1533 EXPECT_EQ(std::numeric_limits<int>::max(), |
| 1477 new_video_source.sink_wants().max_pixel_count); | 1534 new_video_source.sink_wants().max_pixel_count); |
| 1478 | 1535 |
| 1479 vie_encoder_->Stop(); | 1536 vie_encoder_->Stop(); |
| 1480 } | 1537 } |
| 1481 | 1538 |
| 1482 TEST_F(ViEEncoderTest, SkipsSameAdaptDownRequest_MaintainFramerateMode) { | 1539 TEST_F(ViEEncoderTest, SkipsSameAdaptDownRequest_MaintainFramerateMode) { |
| 1483 const int kWidth = 1280; | 1540 const int kWidth = 1280; |
| 1484 const int kHeight = 720; | 1541 const int kHeight = 720; |
| 1485 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1542 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1486 | 1543 |
| 1487 // Enable kMaintainFramerate preference, no initial limitation. | 1544 // Enable kMaintainFramerate preference, no initial limitation. |
| 1488 test::FrameForwarder source; | 1545 test::FrameForwarder source; |
| 1489 vie_encoder_->SetSource( | 1546 vie_encoder_->SetSource( |
| 1490 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1547 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1491 | 1548 |
| 1492 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1549 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1493 sink_.WaitForEncodedFrame(1); | 1550 WaitForEncodedFrame(1); |
| 1494 VerifyNoLimitation(source.sink_wants()); | 1551 VerifyNoLimitation(source.sink_wants()); |
| 1495 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1552 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1496 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1553 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1497 | 1554 |
| 1498 // Trigger adapt down, expect scaled down resolution. | 1555 // Trigger adapt down, expect scaled down resolution. |
| 1499 vie_encoder_->TriggerCpuOveruse(); | 1556 vie_encoder_->TriggerCpuOveruse(); |
| 1500 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1557 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 1501 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; | 1558 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; |
| 1502 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1559 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1503 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1560 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 const int kWidth = 1280; | 1611 const int kWidth = 1280; |
| 1555 const int kHeight = 720; | 1612 const int kHeight = 720; |
| 1556 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1613 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1557 | 1614 |
| 1558 // Enable kMaintainFramerate preference, no initial limitation. | 1615 // Enable kMaintainFramerate preference, no initial limitation. |
| 1559 test::FrameForwarder source; | 1616 test::FrameForwarder source; |
| 1560 vie_encoder_->SetSource( | 1617 vie_encoder_->SetSource( |
| 1561 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1618 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1562 | 1619 |
| 1563 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1620 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1564 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1621 WaitForEncodedFrame(kWidth, kHeight); |
| 1565 VerifyNoLimitation(source.sink_wants()); | 1622 VerifyNoLimitation(source.sink_wants()); |
| 1566 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1623 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1567 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1624 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1568 | 1625 |
| 1569 // Trigger adapt up, expect no change. | 1626 // Trigger adapt up, expect no change. |
| 1570 vie_encoder_->TriggerCpuNormalUsage(); | 1627 vie_encoder_->TriggerCpuNormalUsage(); |
| 1571 VerifyNoLimitation(source.sink_wants()); | 1628 VerifyNoLimitation(source.sink_wants()); |
| 1572 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1629 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1573 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1630 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1574 | 1631 |
| 1575 vie_encoder_->Stop(); | 1632 vie_encoder_->Stop(); |
| 1576 } | 1633 } |
| 1577 | 1634 |
| 1578 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainResolutionMode) { | 1635 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainResolutionMode) { |
| 1579 const int kWidth = 1280; | 1636 const int kWidth = 1280; |
| 1580 const int kHeight = 720; | 1637 const int kHeight = 720; |
| 1581 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1638 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1582 | 1639 |
| 1583 // Enable kMaintainResolution preference, no initial limitation. | 1640 // Enable kMaintainResolution preference, no initial limitation. |
| 1584 test::FrameForwarder source; | 1641 test::FrameForwarder source; |
| 1585 vie_encoder_->SetSource( | 1642 vie_encoder_->SetSource( |
| 1586 &source, VideoSendStream::DegradationPreference::kMaintainResolution); | 1643 &source, VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1587 | 1644 |
| 1588 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1645 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1589 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1646 WaitForEncodedFrame(kWidth, kHeight); |
| 1590 VerifyNoLimitation(source.sink_wants()); | 1647 VerifyNoLimitation(source.sink_wants()); |
| 1591 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1648 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 1592 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1649 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1593 | 1650 |
| 1594 // Trigger adapt up, expect no change. | 1651 // Trigger adapt up, expect no change. |
| 1595 vie_encoder_->TriggerCpuNormalUsage(); | 1652 vie_encoder_->TriggerCpuNormalUsage(); |
| 1596 VerifyNoLimitation(source.sink_wants()); | 1653 VerifyNoLimitation(source.sink_wants()); |
| 1597 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1654 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 1598 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1655 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1599 | 1656 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1659 const int kHeight = 720; | 1716 const int kHeight = 720; |
| 1660 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1717 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1661 | 1718 |
| 1662 // Enable kMaintainFramerate preference, no initial limitation. | 1719 // Enable kMaintainFramerate preference, no initial limitation. |
| 1663 AdaptingFrameForwarder source; | 1720 AdaptingFrameForwarder source; |
| 1664 source.set_adaptation_enabled(true); | 1721 source.set_adaptation_enabled(true); |
| 1665 vie_encoder_->SetSource( | 1722 vie_encoder_->SetSource( |
| 1666 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1723 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1667 | 1724 |
| 1668 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1725 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1669 sink_.WaitForEncodedFrame(1); | 1726 WaitForEncodedFrame(1); |
| 1670 VerifyNoLimitation(source.sink_wants()); | 1727 VerifyNoLimitation(source.sink_wants()); |
| 1671 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1728 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1672 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1729 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1673 | 1730 |
| 1674 // Trigger adapt down, expect scaled down resolution. | 1731 // Trigger adapt down, expect scaled down resolution. |
| 1675 vie_encoder_->TriggerQualityLow(); | 1732 vie_encoder_->TriggerQualityLow(); |
| 1676 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1733 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1677 sink_.WaitForEncodedFrame(2); | 1734 WaitForEncodedFrame(2); |
| 1678 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1735 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 1679 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1736 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1680 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1737 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1681 | 1738 |
| 1682 // Trigger adapt up, expect no restriction. | 1739 // Trigger adapt up, expect no restriction. |
| 1683 vie_encoder_->TriggerQualityHigh(); | 1740 vie_encoder_->TriggerQualityHigh(); |
| 1684 VerifyNoLimitation(source.sink_wants()); | 1741 VerifyNoLimitation(source.sink_wants()); |
| 1685 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1742 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1686 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1743 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1687 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1744 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 // Enable adapter, expected input resolutions when downscaling: | 1797 // Enable adapter, expected input resolutions when downscaling: |
| 1741 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) | 1798 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) |
| 1742 video_source_.set_adaptation_enabled(true); | 1799 video_source_.set_adaptation_enabled(true); |
| 1743 | 1800 |
| 1744 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1801 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1745 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1802 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1746 | 1803 |
| 1747 int downscales = 0; | 1804 int downscales = 0; |
| 1748 for (size_t i = 1; i <= kNumFrames; i++) { | 1805 for (size_t i = 1; i <= kNumFrames; i++) { |
| 1749 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1806 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
| 1750 sink_.WaitForEncodedFrame(i); | 1807 WaitForEncodedFrame(i); |
| 1751 | 1808 |
| 1752 // Trigger scale down. | 1809 // Trigger scale down. |
| 1753 rtc::VideoSinkWants last_wants = video_source_.sink_wants(); | 1810 rtc::VideoSinkWants last_wants = video_source_.sink_wants(); |
| 1754 vie_encoder_->TriggerQualityLow(); | 1811 vie_encoder_->TriggerQualityLow(); |
| 1755 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); | 1812 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); |
| 1756 | 1813 |
| 1757 if (video_source_.sink_wants().max_pixel_count < last_wants.max_pixel_count) | 1814 if (video_source_.sink_wants().max_pixel_count < last_wants.max_pixel_count) |
| 1758 ++downscales; | 1815 ++downscales; |
| 1759 | 1816 |
| 1760 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1817 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1771 const int kHeight = 720; | 1828 const int kHeight = 720; |
| 1772 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1829 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1773 | 1830 |
| 1774 // Enable kMaintainFramerate preference, no initial limitation. | 1831 // Enable kMaintainFramerate preference, no initial limitation. |
| 1775 AdaptingFrameForwarder source; | 1832 AdaptingFrameForwarder source; |
| 1776 source.set_adaptation_enabled(true); | 1833 source.set_adaptation_enabled(true); |
| 1777 vie_encoder_->SetSource( | 1834 vie_encoder_->SetSource( |
| 1778 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1835 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1779 | 1836 |
| 1780 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1837 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1781 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1838 WaitForEncodedFrame(kWidth, kHeight); |
| 1782 VerifyNoLimitation(source.sink_wants()); | 1839 VerifyNoLimitation(source.sink_wants()); |
| 1783 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1840 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1784 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1841 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1785 | 1842 |
| 1786 // Trigger adapt down, expect scaled down resolution. | 1843 // Trigger adapt down, expect scaled down resolution. |
| 1787 vie_encoder_->TriggerCpuOveruse(); | 1844 vie_encoder_->TriggerCpuOveruse(); |
| 1788 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1845 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1789 sink_.WaitForEncodedFrame(2); | 1846 WaitForEncodedFrame(2); |
| 1790 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1847 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 1791 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1848 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1792 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1849 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1793 | 1850 |
| 1794 // Trigger adapt up, expect no restriction. | 1851 // Trigger adapt up, expect no restriction. |
| 1795 vie_encoder_->TriggerCpuNormalUsage(); | 1852 vie_encoder_->TriggerCpuNormalUsage(); |
| 1796 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1853 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 1797 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1854 WaitForEncodedFrame(kWidth, kHeight); |
| 1798 VerifyNoLimitation(source.sink_wants()); | 1855 VerifyNoLimitation(source.sink_wants()); |
| 1799 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1856 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1800 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1857 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1801 | 1858 |
| 1802 // Trigger adapt down, expect scaled down resolution. | 1859 // Trigger adapt down, expect scaled down resolution. |
| 1803 vie_encoder_->TriggerCpuOveruse(); | 1860 vie_encoder_->TriggerCpuOveruse(); |
| 1804 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1861 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
| 1805 sink_.WaitForEncodedFrame(4); | 1862 WaitForEncodedFrame(4); |
| 1806 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1863 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 1807 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1864 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1808 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1865 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1809 | 1866 |
| 1810 // Trigger adapt up, expect no restriction. | 1867 // Trigger adapt up, expect no restriction. |
| 1811 vie_encoder_->TriggerCpuNormalUsage(); | 1868 vie_encoder_->TriggerCpuNormalUsage(); |
| 1812 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1869 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
| 1813 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1870 sink_.WaitForEncodedFrame(kWidth, kHeight); |
| 1814 VerifyNoLimitation(source.sink_wants()); | 1871 VerifyNoLimitation(source.sink_wants()); |
| 1815 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1872 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1877 const int kHeight = 720; | 1934 const int kHeight = 720; |
| 1878 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1935 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1879 | 1936 |
| 1880 // Enable kMaintainFramerate preference, no initial limitation. | 1937 // Enable kMaintainFramerate preference, no initial limitation. |
| 1881 AdaptingFrameForwarder source; | 1938 AdaptingFrameForwarder source; |
| 1882 source.set_adaptation_enabled(true); | 1939 source.set_adaptation_enabled(true); |
| 1883 vie_encoder_->SetSource( | 1940 vie_encoder_->SetSource( |
| 1884 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1941 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 1885 | 1942 |
| 1886 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1943 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 1887 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1944 WaitForEncodedFrame(kWidth, kHeight); |
| 1888 VerifyNoLimitation(source.sink_wants()); | 1945 VerifyNoLimitation(source.sink_wants()); |
| 1889 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1946 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1890 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1947 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1891 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1948 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1892 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1949 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1893 | 1950 |
| 1894 // Trigger cpu adapt down, expect scaled down resolution (960x540). | 1951 // Trigger cpu adapt down, expect scaled down resolution (960x540). |
| 1895 vie_encoder_->TriggerCpuOveruse(); | 1952 vie_encoder_->TriggerCpuOveruse(); |
| 1896 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1953 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
| 1897 sink_.WaitForEncodedFrame(2); | 1954 WaitForEncodedFrame(2); |
| 1898 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1955 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 1899 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1956 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1900 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1957 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1901 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1958 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1902 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1959 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1903 | 1960 |
| 1904 // Trigger cpu adapt down, expect scaled down resolution (640x360). | 1961 // Trigger cpu adapt down, expect scaled down resolution (640x360). |
| 1905 vie_encoder_->TriggerCpuOveruse(); | 1962 vie_encoder_->TriggerCpuOveruse(); |
| 1906 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1963 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
| 1907 sink_.WaitForEncodedFrame(3); | 1964 WaitForEncodedFrame(3); |
| 1908 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 1965 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
| 1909 rtc::VideoSinkWants last_wants = source.sink_wants(); | 1966 rtc::VideoSinkWants last_wants = source.sink_wants(); |
| 1910 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1967 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1911 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1968 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1912 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1969 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1913 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1970 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1914 | 1971 |
| 1915 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. | 1972 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. |
| 1916 vie_encoder_->TriggerCpuOveruse(); | 1973 vie_encoder_->TriggerCpuOveruse(); |
| 1917 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1974 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
| 1918 sink_.WaitForEncodedFrame(4); | 1975 WaitForEncodedFrame(4); |
| 1919 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 1976 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
| 1920 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1977 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1921 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1978 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1922 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1979 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1923 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1980 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1924 | 1981 |
| 1925 // Trigger quality adapt down, expect scaled down resolution (480x270). | 1982 // Trigger quality adapt down, expect scaled down resolution (480x270). |
| 1926 vie_encoder_->TriggerQualityLow(); | 1983 vie_encoder_->TriggerQualityLow(); |
| 1927 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1984 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
| 1928 sink_.WaitForEncodedFrame(5); | 1985 WaitForEncodedFrame(5); |
| 1929 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 1986 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
| 1930 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1987 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1931 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1988 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1932 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1989 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1933 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1990 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1934 | 1991 |
| 1935 // Trigger cpu adapt up, expect upscaled resolution (640x360). | 1992 // Trigger cpu adapt up, expect upscaled resolution (640x360). |
| 1936 vie_encoder_->TriggerCpuNormalUsage(); | 1993 vie_encoder_->TriggerCpuNormalUsage(); |
| 1937 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); | 1994 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
| 1938 sink_.WaitForEncodedFrame(6); | 1995 WaitForEncodedFrame(6); |
| 1939 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 1996 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 1940 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1997 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1941 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1998 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1942 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1999 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1943 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2000 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1944 | 2001 |
| 1945 // Trigger cpu adapt up, expect upscaled resolution (960x540). | 2002 // Trigger cpu adapt up, expect upscaled resolution (960x540). |
| 1946 vie_encoder_->TriggerCpuNormalUsage(); | 2003 vie_encoder_->TriggerCpuNormalUsage(); |
| 1947 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); | 2004 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); |
| 1948 sink_.WaitForEncodedFrame(7); | 2005 WaitForEncodedFrame(7); |
| 1949 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2006 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 1950 last_wants = source.sink_wants(); | 2007 last_wants = source.sink_wants(); |
| 1951 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2008 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1952 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2009 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1953 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2010 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1954 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2011 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1955 | 2012 |
| 1956 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). | 2013 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). |
| 1957 vie_encoder_->TriggerCpuNormalUsage(); | 2014 vie_encoder_->TriggerCpuNormalUsage(); |
| 1958 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); | 2015 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); |
| 1959 sink_.WaitForEncodedFrame(8); | 2016 WaitForEncodedFrame(8); |
| 1960 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 2017 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
| 1961 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2018 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1962 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2019 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1963 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2020 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1964 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2021 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1965 | 2022 |
| 1966 // Trigger quality adapt up, expect no restriction (1280x720). | 2023 // Trigger quality adapt up, expect no restriction (1280x720). |
| 1967 vie_encoder_->TriggerQualityHigh(); | 2024 vie_encoder_->TriggerQualityHigh(); |
| 1968 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); | 2025 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); |
| 1969 sink_.WaitForEncodedFrame(kWidth, kHeight); | 2026 WaitForEncodedFrame(kWidth, kHeight); |
| 1970 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2027 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 1971 VerifyNoLimitation(source.sink_wants()); | 2028 VerifyNoLimitation(source.sink_wants()); |
| 1972 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2029 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 1973 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2030 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 1974 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2031 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 1975 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2032 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 1976 | 2033 |
| 1977 vie_encoder_->Stop(); | 2034 vie_encoder_->Stop(); |
| 1978 } | 2035 } |
| 1979 | 2036 |
| 1980 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) { | 2037 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) { |
| 1981 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
| 1982 const int kWidth = 640; | 2038 const int kWidth = 640; |
| 1983 const int kHeight = 360; | 2039 const int kHeight = 360; |
| 1984 | 2040 |
| 2041 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2042 |
| 1985 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 2043 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
| 1986 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 2044 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
| 1987 sink_.WaitForEncodedFrame(i); | 2045 WaitForEncodedFrame(i); |
| 1988 } | 2046 } |
| 1989 | 2047 |
| 1990 vie_encoder_->TriggerCpuOveruse(); | 2048 vie_encoder_->TriggerCpuOveruse(); |
| 1991 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 2049 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
| 1992 video_source_.IncomingCapturedFrame(CreateFrame( | 2050 video_source_.IncomingCapturedFrame(CreateFrame( |
| 1993 SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); | 2051 SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); |
| 1994 sink_.WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + | 2052 WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + i); |
| 1995 i); | |
| 1996 } | 2053 } |
| 1997 | 2054 |
| 1998 vie_encoder_->Stop(); | 2055 vie_encoder_->Stop(); |
| 1999 vie_encoder_.reset(); | 2056 vie_encoder_.reset(); |
| 2000 stats_proxy_.reset(); | 2057 stats_proxy_.reset(); |
| 2001 | 2058 |
| 2002 EXPECT_EQ(1, | 2059 EXPECT_EQ(1, |
| 2003 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 2060 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
| 2004 EXPECT_EQ( | 2061 EXPECT_EQ( |
| 2005 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); | 2062 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
| 2006 } | 2063 } |
| 2007 | 2064 |
| 2008 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsNotReportedForDisabledDegradation) { | 2065 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsNotReportedForDisabledDegradation) { |
| 2009 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2066 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2010 const int kWidth = 640; | 2067 const int kWidth = 640; |
| 2011 const int kHeight = 360; | 2068 const int kHeight = 360; |
| 2012 | 2069 |
| 2013 vie_encoder_->SetSource( | 2070 vie_encoder_->SetSource( |
| 2014 &video_source_, | 2071 &video_source_, |
| 2015 VideoSendStream::DegradationPreference::kDegradationDisabled); | 2072 VideoSendStream::DegradationPreference::kDegradationDisabled); |
| 2016 | 2073 |
| 2017 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 2074 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
| 2018 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 2075 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
| 2019 sink_.WaitForEncodedFrame(i); | 2076 WaitForEncodedFrame(i); |
| 2020 } | 2077 } |
| 2021 | 2078 |
| 2022 vie_encoder_->Stop(); | 2079 vie_encoder_->Stop(); |
| 2023 vie_encoder_.reset(); | 2080 vie_encoder_.reset(); |
| 2024 stats_proxy_.reset(); | 2081 stats_proxy_.reset(); |
| 2025 | 2082 |
| 2026 EXPECT_EQ(0, | 2083 EXPECT_EQ(0, |
| 2027 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 2084 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
| 2028 } | 2085 } |
| 2029 | 2086 |
| 2030 TEST_F(ViEEncoderTest, CallsBitrateObserver) { | 2087 TEST_F(ViEEncoderTest, CallsBitrateObserver) { |
| 2031 class MockBitrateObserver : public VideoBitrateAllocationObserver { | 2088 MockBitrateObserver bitrate_observer; |
| 2032 public: | |
| 2033 MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&)); | |
| 2034 } bitrate_observer; | |
| 2035 vie_encoder_->SetBitrateObserver(&bitrate_observer); | 2089 vie_encoder_->SetBitrateObserver(&bitrate_observer); |
| 2036 | 2090 |
| 2037 const int kDefaultFps = 30; | 2091 const int kDefaultFps = 30; |
| 2038 const BitrateAllocation expected_bitrate = | 2092 const BitrateAllocation expected_bitrate = |
| 2039 DefaultVideoBitrateAllocator(fake_encoder_.codec_config()) | 2093 DefaultVideoBitrateAllocator(fake_encoder_.codec_config()) |
| 2040 .GetAllocation(kLowTargetBitrateBps, kDefaultFps); | 2094 .GetAllocation(kLowTargetBitrateBps, kDefaultFps); |
| 2041 | 2095 |
| 2042 // First called on bitrate updated, then again on first frame. | 2096 // First called on bitrate updated, then again on first frame. |
| 2043 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 2097 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
| 2044 .Times(2); | 2098 .Times(2); |
| 2045 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 2099 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 2046 | 2100 |
| 2047 const int64_t kStartTimeMs = 1; | 2101 const int64_t kStartTimeMs = 1; |
| 2048 video_source_.IncomingCapturedFrame( | 2102 video_source_.IncomingCapturedFrame( |
| 2049 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); | 2103 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); |
| 2050 sink_.WaitForEncodedFrame(kStartTimeMs); | 2104 WaitForEncodedFrame(kStartTimeMs); |
| 2051 | 2105 |
| 2052 // Not called on second frame. | 2106 // Not called on second frame. |
| 2053 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 2107 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
| 2054 .Times(0); | 2108 .Times(0); |
| 2055 video_source_.IncomingCapturedFrame( | 2109 video_source_.IncomingCapturedFrame( |
| 2056 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); | 2110 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); |
| 2057 sink_.WaitForEncodedFrame(kStartTimeMs + 1); | 2111 WaitForEncodedFrame(kStartTimeMs + 1); |
| 2058 | 2112 |
| 2059 // Called after a process interval. | 2113 // Called after a process interval. |
| 2060 const int64_t kProcessIntervalMs = | 2114 const int64_t kProcessIntervalMs = |
| 2061 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; | 2115 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; |
| 2062 // TODO(sprang): ViEEncoder should die and/or get injectable clock. | 2116 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec * |
| 2063 // Sleep for one processing interval plus one frame to avoid flakiness. | 2117 (kProcessIntervalMs + (1000 / kDefaultFps))); |
| 2064 SleepMs(kProcessIntervalMs + 1000 / kDefaultFps); | |
| 2065 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 2118 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
| 2066 .Times(1); | 2119 .Times(1); |
| 2067 video_source_.IncomingCapturedFrame(CreateFrame( | 2120 video_source_.IncomingCapturedFrame(CreateFrame( |
| 2068 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); | 2121 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); |
| 2069 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); | 2122 WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); |
| 2070 | 2123 |
| 2071 vie_encoder_->Stop(); | 2124 vie_encoder_->Stop(); |
| 2072 } | 2125 } |
| 2073 | 2126 |
| 2074 TEST_F(ViEEncoderTest, OveruseDetectorUpdatedOnReconfigureAndAdaption) { | 2127 TEST_F(ViEEncoderTest, OveruseDetectorUpdatedOnReconfigureAndAdaption) { |
| 2075 const int kFrameWidth = 1280; | 2128 const int kFrameWidth = 1280; |
| 2076 const int kFrameHeight = 720; | 2129 const int kFrameHeight = 720; |
| 2077 const int kFramerate = 24; | 2130 const int kFramerate = 24; |
| 2078 | 2131 |
| 2079 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2132 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2231 | 2284 |
| 2232 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { | 2285 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { |
| 2233 const int kTooLowBitrateForFrameSizeBps = 10000; | 2286 const int kTooLowBitrateForFrameSizeBps = 10000; |
| 2234 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); | 2287 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
| 2235 const int kWidth = 640; | 2288 const int kWidth = 640; |
| 2236 const int kHeight = 360; | 2289 const int kHeight = 360; |
| 2237 | 2290 |
| 2238 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 2291 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 2239 | 2292 |
| 2240 // Expect to drop this frame, the wait should time out. | 2293 // Expect to drop this frame, the wait should time out. |
| 2241 sink_.ExpectDroppedFrame(); | 2294 ExpectDroppedFrame(); |
| 2242 | 2295 |
| 2243 // Expect the sink_wants to specify a scaled frame. | 2296 // Expect the sink_wants to specify a scaled frame. |
| 2244 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 2297 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
| 2245 | 2298 |
| 2246 int last_pixel_count = video_source_.sink_wants().max_pixel_count; | 2299 int last_pixel_count = video_source_.sink_wants().max_pixel_count; |
| 2247 | 2300 |
| 2248 // Next frame is scaled. | 2301 // Next frame is scaled. |
| 2249 video_source_.IncomingCapturedFrame( | 2302 video_source_.IncomingCapturedFrame( |
| 2250 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); | 2303 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); |
| 2251 | 2304 |
| 2252 // Expect to drop this frame, the wait should time out. | 2305 // Expect to drop this frame, the wait should time out. |
| 2253 sink_.ExpectDroppedFrame(); | 2306 ExpectDroppedFrame(); |
| 2254 | 2307 |
| 2255 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); | 2308 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); |
| 2256 | 2309 |
| 2257 vie_encoder_->Stop(); | 2310 vie_encoder_->Stop(); |
| 2258 } | 2311 } |
| 2259 | 2312 |
| 2260 TEST_F(ViEEncoderTest, NumberOfDroppedFramesLimitedWhenBitrateIsTooLow) { | 2313 TEST_F(ViEEncoderTest, NumberOfDroppedFramesLimitedWhenBitrateIsTooLow) { |
| 2261 const int kTooLowBitrateForFrameSizeBps = 10000; | 2314 const int kTooLowBitrateForFrameSizeBps = 10000; |
| 2262 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); | 2315 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
| 2263 const int kWidth = 640; | 2316 const int kWidth = 640; |
| 2264 const int kHeight = 360; | 2317 const int kHeight = 360; |
| 2265 | 2318 |
| 2266 // We expect the n initial frames to get dropped. | 2319 // We expect the n initial frames to get dropped. |
| 2267 int i; | 2320 int i; |
| 2268 for (i = 1; i <= kMaxInitialFramedrop; ++i) { | 2321 for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
| 2269 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 2322 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
| 2270 sink_.ExpectDroppedFrame(); | 2323 ExpectDroppedFrame(); |
| 2271 } | 2324 } |
| 2272 // The n+1th frame should not be dropped, even though it's size is too large. | 2325 // The n+1th frame should not be dropped, even though it's size is too large. |
| 2273 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 2326 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
| 2274 sink_.WaitForEncodedFrame(i); | 2327 WaitForEncodedFrame(i); |
| 2275 | 2328 |
| 2276 // Expect the sink_wants to specify a scaled frame. | 2329 // Expect the sink_wants to specify a scaled frame. |
| 2277 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 2330 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
| 2278 | 2331 |
| 2279 vie_encoder_->Stop(); | 2332 vie_encoder_->Stop(); |
| 2280 } | 2333 } |
| 2281 | 2334 |
| 2282 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { | 2335 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { |
| 2283 const int kWidth = 640; | 2336 const int kWidth = 640; |
| 2284 const int kHeight = 360; | 2337 const int kHeight = 360; |
| 2285 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 2338 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 2286 | 2339 |
| 2287 // Set degradation preference. | 2340 // Set degradation preference. |
| 2288 vie_encoder_->SetSource( | 2341 vie_encoder_->SetSource( |
| 2289 &video_source_, | 2342 &video_source_, |
| 2290 VideoSendStream::DegradationPreference::kMaintainResolution); | 2343 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 2291 | 2344 |
| 2292 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 2345 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 2293 // Frame should not be dropped, even if it's too large. | 2346 // Frame should not be dropped, even if it's too large. |
| 2294 sink_.WaitForEncodedFrame(1); | 2347 WaitForEncodedFrame(1); |
| 2295 | 2348 |
| 2296 vie_encoder_->Stop(); | 2349 vie_encoder_->Stop(); |
| 2297 } | 2350 } |
| 2298 | 2351 |
| 2299 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { | 2352 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { |
| 2300 const int kWidth = 640; | 2353 const int kWidth = 640; |
| 2301 const int kHeight = 360; | 2354 const int kHeight = 360; |
| 2302 fake_encoder_.SetQualityScaling(false); | 2355 fake_encoder_.SetQualityScaling(false); |
| 2303 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 2356 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 2304 | 2357 |
| 2305 // Force quality scaler reconfiguration by resetting the source. | 2358 // Force quality scaler reconfiguration by resetting the source. |
| 2306 vie_encoder_->SetSource(&video_source_, | 2359 vie_encoder_->SetSource(&video_source_, |
| 2307 VideoSendStream::DegradationPreference::kBalanced); | 2360 VideoSendStream::DegradationPreference::kBalanced); |
| 2308 | 2361 |
| 2309 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 2362 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
| 2310 // Frame should not be dropped, even if it's too large. | 2363 // Frame should not be dropped, even if it's too large. |
| 2311 sink_.WaitForEncodedFrame(1); | 2364 WaitForEncodedFrame(1); |
| 2312 | 2365 |
| 2313 vie_encoder_->Stop(); | 2366 vie_encoder_->Stop(); |
| 2314 fake_encoder_.SetQualityScaling(true); | 2367 fake_encoder_.SetQualityScaling(true); |
| 2315 } | 2368 } |
| 2316 | 2369 |
| 2317 TEST_F(ViEEncoderTest, | 2370 TEST_F(ViEEncoderTest, |
| 2318 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) { | 2371 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) { |
| 2319 const int kTooSmallWidth = 10; | 2372 const int kTooSmallWidth = 10; |
| 2320 const int kTooSmallHeight = 10; | 2373 const int kTooSmallHeight = 10; |
| 2321 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2374 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2322 | 2375 |
| 2323 // Enable kMaintainFramerate preference, no initial limitation. | 2376 // Enable kMaintainFramerate preference, no initial limitation. |
| 2324 test::FrameForwarder source; | 2377 test::FrameForwarder source; |
| 2325 vie_encoder_->SetSource( | 2378 vie_encoder_->SetSource( |
| 2326 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 2379 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
| 2327 VerifyNoLimitation(source.sink_wants()); | 2380 VerifyNoLimitation(source.sink_wants()); |
| 2328 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2381 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2329 | 2382 |
| 2330 // Trigger adapt down, too small frame, expect no change. | 2383 // Trigger adapt down, too small frame, expect no change. |
| 2331 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); | 2384 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); |
| 2332 sink_.WaitForEncodedFrame(1); | 2385 WaitForEncodedFrame(1); |
| 2333 vie_encoder_->TriggerCpuOveruse(); | 2386 vie_encoder_->TriggerCpuOveruse(); |
| 2334 VerifyNoLimitation(source.sink_wants()); | 2387 VerifyNoLimitation(source.sink_wants()); |
| 2335 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2388 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2336 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2389 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2337 | 2390 |
| 2338 vie_encoder_->Stop(); | 2391 vie_encoder_->Stop(); |
| 2339 } | 2392 } |
| 2340 | 2393 |
| 2341 TEST_F(ViEEncoderTest, ResolutionNotAdaptedForTooSmallFrame_BalancedMode) { | 2394 TEST_F(ViEEncoderTest, ResolutionNotAdaptedForTooSmallFrame_BalancedMode) { |
| 2342 const int kTooSmallWidth = 10; | 2395 const int kTooSmallWidth = 10; |
| 2343 const int kTooSmallHeight = 10; | 2396 const int kTooSmallHeight = 10; |
| 2344 const int kFpsLimit = 7; | 2397 const int kFpsLimit = 7; |
| 2345 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2398 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2346 | 2399 |
| 2347 // Enable kBalanced preference, no initial limitation. | 2400 // Enable kBalanced preference, no initial limitation. |
| 2348 test::FrameForwarder source; | 2401 test::FrameForwarder source; |
| 2349 vie_encoder_->SetSource(&source, | 2402 vie_encoder_->SetSource(&source, |
| 2350 VideoSendStream::DegradationPreference::kBalanced); | 2403 VideoSendStream::DegradationPreference::kBalanced); |
| 2351 VerifyNoLimitation(source.sink_wants()); | 2404 VerifyNoLimitation(source.sink_wants()); |
| 2352 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2405 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2353 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2406 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2354 | 2407 |
| 2355 // Trigger adapt down, expect limited framerate. | 2408 // Trigger adapt down, expect limited framerate. |
| 2356 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); | 2409 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); |
| 2357 sink_.WaitForEncodedFrame(1); | 2410 WaitForEncodedFrame(1); |
| 2358 vie_encoder_->TriggerQualityLow(); | 2411 vie_encoder_->TriggerQualityLow(); |
| 2359 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); | 2412 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); |
| 2360 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2413 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2361 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2414 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2362 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2415 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2363 | 2416 |
| 2364 // Trigger adapt down, too small frame, expect no change. | 2417 // Trigger adapt down, too small frame, expect no change. |
| 2365 source.IncomingCapturedFrame(CreateFrame(2, kTooSmallWidth, kTooSmallHeight)); | 2418 source.IncomingCapturedFrame(CreateFrame(2, kTooSmallWidth, kTooSmallHeight)); |
| 2366 sink_.WaitForEncodedFrame(2); | 2419 WaitForEncodedFrame(2); |
| 2367 vie_encoder_->TriggerQualityLow(); | 2420 vie_encoder_->TriggerQualityLow(); |
| 2368 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); | 2421 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); |
| 2369 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2422 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2370 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2423 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2371 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2424 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2372 | 2425 |
| 2373 vie_encoder_->Stop(); | 2426 vie_encoder_->Stop(); |
| 2374 } | 2427 } |
| 2375 | 2428 |
| 2376 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { | 2429 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { |
| 2377 fake_encoder_.ForceInitEncodeFailure(true); | 2430 fake_encoder_.ForceInitEncodeFailure(true); |
| 2378 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2431 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2379 ResetEncoder("VP8", 2, 1, true); | 2432 ResetEncoder("VP8", 2, 1, true, false); |
| 2380 const int kFrameWidth = 1280; | 2433 const int kFrameWidth = 1280; |
| 2381 const int kFrameHeight = 720; | 2434 const int kFrameHeight = 720; |
| 2382 video_source_.IncomingCapturedFrame( | 2435 video_source_.IncomingCapturedFrame( |
| 2383 CreateFrame(1, kFrameWidth, kFrameHeight)); | 2436 CreateFrame(1, kFrameWidth, kFrameHeight)); |
| 2384 sink_.ExpectDroppedFrame(); | 2437 ExpectDroppedFrame(); |
| 2385 vie_encoder_->Stop(); | 2438 vie_encoder_->Stop(); |
| 2386 } | 2439 } |
| 2387 | 2440 |
| 2388 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. | 2441 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. |
| 2389 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse_MaintainFramerateMode) { | 2442 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse_MaintainFramerateMode) { |
| 2390 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2443 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2391 | 2444 |
| 2392 const int kFrameWidth = 1280; | 2445 const int kFrameWidth = 1280; |
| 2393 const int kFrameHeight = 720; | 2446 const int kFrameHeight = 720; |
| 2394 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as | 2447 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as |
| 2395 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). | 2448 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). |
| 2396 video_source_.set_adaptation_enabled(true); | 2449 video_source_.set_adaptation_enabled(true); |
| 2397 | 2450 |
| 2398 video_source_.IncomingCapturedFrame( | 2451 video_source_.IncomingCapturedFrame( |
| 2399 CreateFrame(1, kFrameWidth, kFrameHeight)); | 2452 CreateFrame(1, kFrameWidth, kFrameHeight)); |
| 2400 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 2453 WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 2401 | 2454 |
| 2402 // Trigger CPU overuse, downscale by 3/4. | 2455 // Trigger CPU overuse, downscale by 3/4. |
| 2403 vie_encoder_->TriggerCpuOveruse(); | 2456 vie_encoder_->TriggerCpuOveruse(); |
| 2404 video_source_.IncomingCapturedFrame( | 2457 video_source_.IncomingCapturedFrame( |
| 2405 CreateFrame(2, kFrameWidth, kFrameHeight)); | 2458 CreateFrame(2, kFrameWidth, kFrameHeight)); |
| 2406 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); | 2459 WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
| 2407 | 2460 |
| 2408 // Trigger CPU normal use, return to original resolution. | 2461 // Trigger CPU normal use, return to original resolution. |
| 2409 vie_encoder_->TriggerCpuNormalUsage(); | 2462 vie_encoder_->TriggerCpuNormalUsage(); |
| 2410 video_source_.IncomingCapturedFrame( | 2463 video_source_.IncomingCapturedFrame( |
| 2411 CreateFrame(3, kFrameWidth, kFrameHeight)); | 2464 CreateFrame(3, kFrameWidth, kFrameHeight)); |
| 2412 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 2465 WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 2413 | 2466 |
| 2414 vie_encoder_->Stop(); | 2467 vie_encoder_->Stop(); |
| 2415 } | 2468 } |
| 2416 | 2469 |
| 2417 TEST_F(ViEEncoderTest, AdaptsFramerateOnOveruse_MaintainResolutionMode) { | 2470 TEST_F(ViEEncoderTest, AdaptsFramerateOnOveruse_MaintainResolutionMode) { |
| 2418 const int kDefaultFramerateFps = 30; | |
| 2419 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kDefaultFramerateFps; | |
| 2420 const int kFrameWidth = 1280; | 2471 const int kFrameWidth = 1280; |
| 2421 const int kFrameHeight = 720; | 2472 const int kFrameHeight = 720; |
| 2422 rtc::ScopedFakeClock fake_clock; | 2473 int kFrameIntervalMs = rtc::kNumMillisecsPerSec / max_framerate_; |
| 2423 | 2474 |
| 2424 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2475 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2425 vie_encoder_->SetSource( | 2476 vie_encoder_->SetSource( |
| 2426 &video_source_, | 2477 &video_source_, |
| 2427 VideoSendStream::DegradationPreference::kMaintainResolution); | 2478 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 2428 video_source_.set_adaptation_enabled(true); | 2479 video_source_.set_adaptation_enabled(true); |
| 2429 | 2480 |
| 2430 fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); | 2481 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
| 2431 int64_t timestamp_ms = kFrameIntervalMs; | |
| 2432 | 2482 |
| 2433 video_source_.IncomingCapturedFrame( | 2483 video_source_.IncomingCapturedFrame( |
| 2434 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2484 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2435 sink_.WaitForEncodedFrame(timestamp_ms); | 2485 WaitForEncodedFrame(timestamp_ms); |
| 2436 | 2486 |
| 2437 // Try to trigger overuse. No fps estimate available => no effect. | 2487 // Try to trigger overuse. No fps estimate available => no effect. |
| 2438 vie_encoder_->TriggerCpuOveruse(); | 2488 vie_encoder_->TriggerCpuOveruse(); |
| 2439 | 2489 |
| 2440 // Insert frames for one second to get a stable estimate. | 2490 // Insert frames for one second to get a stable estimate. |
| 2441 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2491 for (int i = 0; i < max_framerate_; ++i) { |
| 2442 timestamp_ms += kFrameIntervalMs; | 2492 timestamp_ms += kFrameIntervalMs; |
| 2443 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 2444 video_source_.IncomingCapturedFrame( | 2493 video_source_.IncomingCapturedFrame( |
| 2445 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2494 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2446 sink_.WaitForEncodedFrame(timestamp_ms); | 2495 WaitForEncodedFrame(timestamp_ms); |
| 2447 } | 2496 } |
| 2448 | 2497 |
| 2449 // Trigger CPU overuse, reduce framerate by 2/3. | 2498 // Trigger CPU overuse, reduce framerate by 2/3. |
| 2450 vie_encoder_->TriggerCpuOveruse(); | 2499 vie_encoder_->TriggerCpuOveruse(); |
| 2451 int num_frames_dropped = 0; | 2500 int num_frames_dropped = 0; |
| 2452 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2501 for (int i = 0; i < max_framerate_; ++i) { |
| 2453 timestamp_ms += kFrameIntervalMs; | 2502 timestamp_ms += kFrameIntervalMs; |
| 2454 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 2455 video_source_.IncomingCapturedFrame( | 2503 video_source_.IncomingCapturedFrame( |
| 2456 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2504 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2457 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | 2505 if (!WaitForFrame(kFrameTimeoutMs)) { |
| 2458 ++num_frames_dropped; | 2506 ++num_frames_dropped; |
| 2459 } else { | 2507 } else { |
| 2460 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2508 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
| 2461 } | 2509 } |
| 2462 } | 2510 } |
| 2463 | 2511 |
| 2464 // TODO(sprang): Find where there's rounding errors or stuff causing the | 2512 // Add some slack to account for frames dropped by the frame dropper. |
| 2465 // margin here to be a little larger than we'd like (input fps estimate is | 2513 const int kErrorMargin = 1; |
| 2466 // off) and the frame dropping is a little too aggressive. | 2514 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), |
| 2467 const int kErrorMargin = 5; | |
| 2468 EXPECT_NEAR(num_frames_dropped, | |
| 2469 kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), | |
| 2470 kErrorMargin); | 2515 kErrorMargin); |
| 2471 | 2516 |
| 2472 // Trigger CPU overuse, reduce framerate by 2/3 again. | 2517 // Trigger CPU overuse, reduce framerate by 2/3 again. |
| 2473 vie_encoder_->TriggerCpuOveruse(); | 2518 vie_encoder_->TriggerCpuOveruse(); |
| 2474 num_frames_dropped = 0; | 2519 num_frames_dropped = 0; |
| 2475 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2520 for (int i = 0; i < max_framerate_; ++i) { |
| 2476 timestamp_ms += kFrameIntervalMs; | 2521 timestamp_ms += kFrameIntervalMs; |
| 2477 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 2478 video_source_.IncomingCapturedFrame( | 2522 video_source_.IncomingCapturedFrame( |
| 2479 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2523 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2480 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | 2524 if (!WaitForFrame(kFrameTimeoutMs)) { |
| 2481 ++num_frames_dropped; | 2525 ++num_frames_dropped; |
| 2482 } else { | 2526 } else { |
| 2483 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2527 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
| 2484 } | 2528 } |
| 2485 } | 2529 } |
| 2486 EXPECT_NEAR(num_frames_dropped, | 2530 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 4 / 9), |
| 2487 kDefaultFramerateFps - (kDefaultFramerateFps * 4 / 9), | |
| 2488 kErrorMargin); | 2531 kErrorMargin); |
| 2489 | 2532 |
| 2490 // Go back up one step. | 2533 // Go back up one step. |
| 2491 vie_encoder_->TriggerCpuNormalUsage(); | 2534 vie_encoder_->TriggerCpuNormalUsage(); |
| 2492 num_frames_dropped = 0; | 2535 num_frames_dropped = 0; |
| 2493 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2536 for (int i = 0; i < max_framerate_; ++i) { |
| 2494 timestamp_ms += kFrameIntervalMs; | 2537 timestamp_ms += kFrameIntervalMs; |
| 2495 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 2496 video_source_.IncomingCapturedFrame( | 2538 video_source_.IncomingCapturedFrame( |
| 2497 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2539 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2498 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | 2540 if (!WaitForFrame(kFrameTimeoutMs)) { |
| 2499 ++num_frames_dropped; | 2541 ++num_frames_dropped; |
| 2500 } else { | 2542 } else { |
| 2501 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2543 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
| 2502 } | 2544 } |
| 2503 } | 2545 } |
| 2504 EXPECT_NEAR(num_frames_dropped, | 2546 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), |
| 2505 kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), | |
| 2506 kErrorMargin); | 2547 kErrorMargin); |
| 2507 | 2548 |
| 2508 // Go back up to original mode. | 2549 // Go back up to original mode. |
| 2509 vie_encoder_->TriggerCpuNormalUsage(); | 2550 vie_encoder_->TriggerCpuNormalUsage(); |
| 2510 num_frames_dropped = 0; | 2551 num_frames_dropped = 0; |
| 2511 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2552 for (int i = 0; i < max_framerate_; ++i) { |
| 2512 timestamp_ms += kFrameIntervalMs; | 2553 timestamp_ms += kFrameIntervalMs; |
| 2513 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 2514 video_source_.IncomingCapturedFrame( | 2554 video_source_.IncomingCapturedFrame( |
| 2515 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2555 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2516 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | 2556 if (!WaitForFrame(kFrameTimeoutMs)) { |
| 2517 ++num_frames_dropped; | 2557 ++num_frames_dropped; |
| 2518 } else { | 2558 } else { |
| 2519 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2559 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
| 2520 } | 2560 } |
| 2521 } | 2561 } |
| 2522 EXPECT_NEAR(num_frames_dropped, 0, kErrorMargin); | 2562 EXPECT_NEAR(num_frames_dropped, 0, kErrorMargin); |
| 2523 | 2563 |
| 2524 vie_encoder_->Stop(); | 2564 vie_encoder_->Stop(); |
| 2525 } | 2565 } |
| 2526 | 2566 |
| 2527 TEST_F(ViEEncoderTest, DoesntAdaptDownPastMinFramerate) { | 2567 TEST_F(ViEEncoderTest, DoesntAdaptDownPastMinFramerate) { |
| 2528 const int kFramerateFps = 5; | 2568 const int kFramerateFps = 5; |
| 2529 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kFramerateFps; | 2569 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kFramerateFps; |
| 2530 const int kMinFpsFrameInterval = rtc::kNumMillisecsPerSec / kMinFramerateFps; | 2570 const int kMinFpsFrameInterval = rtc::kNumMillisecsPerSec / kMinFramerateFps; |
| 2531 const int kFrameWidth = 1280; | 2571 const int kFrameWidth = 1280; |
| 2532 const int kFrameHeight = 720; | 2572 const int kFrameHeight = 720; |
| 2533 | 2573 |
| 2534 rtc::ScopedFakeClock fake_clock; | 2574 // Reconfigure encoder with two temporal layers and screensharing, which will |
| 2575 // disable frame dropping and make testing easier. |
| 2576 ResetEncoder("VP8", 1, 2, true, true); |
| 2577 |
| 2535 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2578 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2536 vie_encoder_->SetSource( | 2579 vie_encoder_->SetSource( |
| 2537 &video_source_, | 2580 &video_source_, |
| 2538 VideoSendStream::DegradationPreference::kMaintainResolution); | 2581 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 2539 video_source_.set_adaptation_enabled(true); | 2582 video_source_.set_adaptation_enabled(true); |
| 2540 | 2583 |
| 2541 fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); | 2584 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
| 2542 int64_t timestamp_ms = kFrameIntervalMs; | |
| 2543 | 2585 |
| 2544 // Trigger overuse as much as we can. | 2586 // Trigger overuse as much as we can. |
| 2545 for (int i = 0; i < ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { | 2587 for (int i = 0; i < ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { |
| 2546 // Insert frames to get a new fps estimate... | 2588 // Insert frames to get a new fps estimate... |
| 2547 for (int j = 0; j < kFramerateFps; ++j) { | 2589 for (int j = 0; j < kFramerateFps; ++j) { |
| 2548 video_source_.IncomingCapturedFrame( | 2590 video_source_.IncomingCapturedFrame( |
| 2549 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2591 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2550 timestamp_ms += kFrameIntervalMs; | 2592 timestamp_ms += kFrameIntervalMs; |
| 2551 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
| 2552 } | 2593 } |
| 2553 // ...and then try to adapt again. | 2594 // ...and then try to adapt again. |
| 2554 vie_encoder_->TriggerCpuOveruse(); | 2595 vie_encoder_->TriggerCpuOveruse(); |
| 2555 } | 2596 } |
| 2556 | 2597 |
| 2557 // Drain any frame in the pipeline. | 2598 // Drain any frame in the pipeline. |
| 2558 sink_.WaitForFrame(kDefaultTimeoutMs); | 2599 WaitForFrame(kDefaultTimeoutMs); |
| 2559 | 2600 |
| 2560 // Insert frames at min fps, all should go through. | 2601 // Insert frames at min fps, all should go through. |
| 2561 for (int i = 0; i < 10; ++i) { | 2602 for (int i = 0; i < 10; ++i) { |
| 2562 timestamp_ms += kMinFpsFrameInterval; | 2603 timestamp_ms += kMinFpsFrameInterval; |
| 2563 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); | |
| 2564 video_source_.IncomingCapturedFrame( | 2604 video_source_.IncomingCapturedFrame( |
| 2565 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2605 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2566 sink_.WaitForEncodedFrame(timestamp_ms); | 2606 WaitForEncodedFrame(timestamp_ms); |
| 2567 } | 2607 } |
| 2568 | 2608 |
| 2569 vie_encoder_->Stop(); | 2609 vie_encoder_->Stop(); |
| 2570 } | 2610 } |
| 2571 | 2611 |
| 2572 TEST_F(ViEEncoderTest, AdaptsResolutionAndFramerateForLowQuality_BalancedMode) { | 2612 TEST_F(ViEEncoderTest, AdaptsResolutionAndFramerateForLowQuality_BalancedMode) { |
| 2573 const int kWidth = 1280; | 2613 const int kWidth = 1280; |
| 2574 const int kHeight = 720; | 2614 const int kHeight = 720; |
| 2575 const int64_t kFrameIntervalMs = 150; | 2615 const int64_t kFrameIntervalMs = 150; |
| 2576 int64_t timestamp_ms = kFrameIntervalMs; | 2616 int64_t timestamp_ms = kFrameIntervalMs; |
| 2577 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2617 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2578 | 2618 |
| 2579 // Enable kBalanced preference, no initial limitation. | 2619 // Enable kBalanced preference, no initial limitation. |
| 2580 AdaptingFrameForwarder source; | 2620 AdaptingFrameForwarder source; |
| 2581 source.set_adaptation_enabled(true); | 2621 source.set_adaptation_enabled(true); |
| 2582 vie_encoder_->SetSource(&source, | 2622 vie_encoder_->SetSource(&source, |
| 2583 VideoSendStream::DegradationPreference::kBalanced); | 2623 VideoSendStream::DegradationPreference::kBalanced); |
| 2584 timestamp_ms += kFrameIntervalMs; | 2624 timestamp_ms += kFrameIntervalMs; |
| 2585 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2625 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2586 sink_.WaitForEncodedFrame(kWidth, kHeight); | 2626 WaitForEncodedFrame(kWidth, kHeight); |
| 2587 VerifyNoLimitation(source.sink_wants()); | 2627 VerifyNoLimitation(source.sink_wants()); |
| 2588 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2628 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2589 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2629 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2590 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2630 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2591 | 2631 |
| 2592 // Trigger adapt down, expect scaled down resolution (960x540@30fps). | 2632 // Trigger adapt down, expect scaled down resolution (960x540@30fps). |
| 2593 vie_encoder_->TriggerQualityLow(); | 2633 vie_encoder_->TriggerQualityLow(); |
| 2594 timestamp_ms += kFrameIntervalMs; | 2634 timestamp_ms += kFrameIntervalMs; |
| 2595 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2635 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2596 sink_.WaitForEncodedFrame(timestamp_ms); | 2636 WaitForEncodedFrame(timestamp_ms); |
| 2597 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 2637 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 2598 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2638 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2599 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2639 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2600 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2640 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2601 | 2641 |
| 2602 // Trigger adapt down, expect scaled down resolution (640x360@30fps). | 2642 // Trigger adapt down, expect scaled down resolution (640x360@30fps). |
| 2603 vie_encoder_->TriggerQualityLow(); | 2643 vie_encoder_->TriggerQualityLow(); |
| 2604 timestamp_ms += kFrameIntervalMs; | 2644 timestamp_ms += kFrameIntervalMs; |
| 2605 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2645 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2606 sink_.WaitForEncodedFrame(timestamp_ms); | 2646 WaitForEncodedFrame(timestamp_ms); |
| 2607 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 2647 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
| 2608 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2648 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2609 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2649 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2610 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2650 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2611 | 2651 |
| 2612 // Trigger adapt down, expect reduced fps (640x360@15fps). | 2652 // Trigger adapt down, expect reduced fps (640x360@15fps). |
| 2613 vie_encoder_->TriggerQualityLow(); | 2653 vie_encoder_->TriggerQualityLow(); |
| 2614 timestamp_ms += kFrameIntervalMs; | 2654 timestamp_ms += kFrameIntervalMs; |
| 2615 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2655 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2616 sink_.WaitForEncodedFrame(timestamp_ms); | 2656 WaitForEncodedFrame(timestamp_ms); |
| 2617 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); | 2657 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2618 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2658 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2619 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2659 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2620 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2660 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2621 | 2661 |
| 2622 // Trigger adapt down, expect scaled down resolution (480x270@15fps). | 2662 // Trigger adapt down, expect scaled down resolution (480x270@15fps). |
| 2623 vie_encoder_->TriggerQualityLow(); | 2663 vie_encoder_->TriggerQualityLow(); |
| 2624 timestamp_ms += kFrameIntervalMs; | 2664 timestamp_ms += kFrameIntervalMs; |
| 2625 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2665 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2626 sink_.WaitForEncodedFrame(timestamp_ms); | 2666 WaitForEncodedFrame(timestamp_ms); |
| 2627 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); | 2667 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); |
| 2628 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2668 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2629 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2669 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2630 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2670 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2631 | 2671 |
| 2632 // Restrict bitrate, trigger adapt down, expect reduced fps (480x270@10fps). | 2672 // Restrict bitrate, trigger adapt down, expect reduced fps (480x270@10fps). |
| 2633 vie_encoder_->TriggerQualityLow(); | 2673 vie_encoder_->TriggerQualityLow(); |
| 2634 timestamp_ms += kFrameIntervalMs; | 2674 timestamp_ms += kFrameIntervalMs; |
| 2635 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2675 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2636 sink_.WaitForEncodedFrame(timestamp_ms); | 2676 WaitForEncodedFrame(timestamp_ms); |
| 2637 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); | 2677 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2638 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2678 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2639 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2679 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2640 EXPECT_EQ(5, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2680 EXPECT_EQ(5, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2641 | 2681 |
| 2642 // Trigger adapt down, expect scaled down resolution (320x180@10fps). | 2682 // Trigger adapt down, expect scaled down resolution (320x180@10fps). |
| 2643 vie_encoder_->TriggerQualityLow(); | 2683 vie_encoder_->TriggerQualityLow(); |
| 2644 timestamp_ms += kFrameIntervalMs; | 2684 timestamp_ms += kFrameIntervalMs; |
| 2645 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2685 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2646 sink_.WaitForEncodedFrame(timestamp_ms); | 2686 WaitForEncodedFrame(timestamp_ms); |
| 2647 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); | 2687 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); |
| 2648 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2688 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2649 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2689 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2650 EXPECT_EQ(6, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2690 EXPECT_EQ(6, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2651 | 2691 |
| 2652 // Trigger adapt down, expect reduced fps (320x180@7fps). | 2692 // Trigger adapt down, expect reduced fps (320x180@7fps). |
| 2653 vie_encoder_->TriggerQualityLow(); | 2693 vie_encoder_->TriggerQualityLow(); |
| 2654 timestamp_ms += kFrameIntervalMs; | 2694 timestamp_ms += kFrameIntervalMs; |
| 2655 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2695 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2656 sink_.WaitForEncodedFrame(timestamp_ms); | 2696 WaitForEncodedFrame(timestamp_ms); |
| 2657 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); | 2697 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2658 rtc::VideoSinkWants last_wants = source.sink_wants(); | 2698 rtc::VideoSinkWants last_wants = source.sink_wants(); |
| 2659 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2699 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2660 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2700 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2661 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2701 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2662 | 2702 |
| 2663 // Trigger adapt down, min resolution reached, expect no change. | 2703 // Trigger adapt down, min resolution reached, expect no change. |
| 2664 vie_encoder_->TriggerQualityLow(); | 2704 vie_encoder_->TriggerQualityLow(); |
| 2665 timestamp_ms += kFrameIntervalMs; | 2705 timestamp_ms += kFrameIntervalMs; |
| 2666 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2706 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2667 sink_.WaitForEncodedFrame(timestamp_ms); | 2707 WaitForEncodedFrame(timestamp_ms); |
| 2668 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 2708 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
| 2669 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2709 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2670 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2710 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2671 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2711 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2672 | 2712 |
| 2673 // Trigger adapt down, expect expect increased fps (320x180@10fps). | 2713 // Trigger adapt down, expect expect increased fps (320x180@10fps). |
| 2674 vie_encoder_->TriggerQualityHigh(); | 2714 vie_encoder_->TriggerQualityHigh(); |
| 2675 timestamp_ms += kFrameIntervalMs; | 2715 timestamp_ms += kFrameIntervalMs; |
| 2676 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2716 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2677 sink_.WaitForEncodedFrame(timestamp_ms); | 2717 WaitForEncodedFrame(timestamp_ms); |
| 2678 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); | 2718 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2679 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2719 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2680 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2720 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2681 EXPECT_EQ(8, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2721 EXPECT_EQ(8, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2682 | 2722 |
| 2683 // Trigger adapt up, expect upscaled resolution (480x270@10fps). | 2723 // Trigger adapt up, expect upscaled resolution (480x270@10fps). |
| 2684 vie_encoder_->TriggerQualityHigh(); | 2724 vie_encoder_->TriggerQualityHigh(); |
| 2685 timestamp_ms += kFrameIntervalMs; | 2725 timestamp_ms += kFrameIntervalMs; |
| 2686 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2726 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2687 sink_.WaitForEncodedFrame(timestamp_ms); | 2727 WaitForEncodedFrame(timestamp_ms); |
| 2688 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); | 2728 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); |
| 2689 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2729 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2690 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2730 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2691 EXPECT_EQ(9, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2731 EXPECT_EQ(9, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2692 | 2732 |
| 2693 // Increase bitrate, trigger adapt up, expect increased fps (480x270@15fps). | 2733 // Increase bitrate, trigger adapt up, expect increased fps (480x270@15fps). |
| 2694 vie_encoder_->TriggerQualityHigh(); | 2734 vie_encoder_->TriggerQualityHigh(); |
| 2695 timestamp_ms += kFrameIntervalMs; | 2735 timestamp_ms += kFrameIntervalMs; |
| 2696 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2736 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2697 sink_.WaitForEncodedFrame(timestamp_ms); | 2737 WaitForEncodedFrame(timestamp_ms); |
| 2698 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); | 2738 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2699 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2739 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2700 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2740 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2701 EXPECT_EQ(10, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2741 EXPECT_EQ(10, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2702 | 2742 |
| 2703 // Trigger adapt up, expect upscaled resolution (640x360@15fps). | 2743 // Trigger adapt up, expect upscaled resolution (640x360@15fps). |
| 2704 vie_encoder_->TriggerQualityHigh(); | 2744 vie_encoder_->TriggerQualityHigh(); |
| 2705 timestamp_ms += kFrameIntervalMs; | 2745 timestamp_ms += kFrameIntervalMs; |
| 2706 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2746 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2707 sink_.WaitForEncodedFrame(timestamp_ms); | 2747 WaitForEncodedFrame(timestamp_ms); |
| 2708 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); | 2748 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); |
| 2709 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2749 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2710 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2750 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2711 EXPECT_EQ(11, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2751 EXPECT_EQ(11, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2712 | 2752 |
| 2713 // Trigger adapt up, expect increased fps (640x360@30fps). | 2753 // Trigger adapt up, expect increased fps (640x360@30fps). |
| 2714 vie_encoder_->TriggerQualityHigh(); | 2754 vie_encoder_->TriggerQualityHigh(); |
| 2715 timestamp_ms += kFrameIntervalMs; | 2755 timestamp_ms += kFrameIntervalMs; |
| 2716 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2756 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2717 sink_.WaitForEncodedFrame(timestamp_ms); | 2757 WaitForEncodedFrame(timestamp_ms); |
| 2718 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); | 2758 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); |
| 2719 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2759 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2720 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2760 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2721 EXPECT_EQ(12, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2761 EXPECT_EQ(12, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2722 | 2762 |
| 2723 // Trigger adapt up, expect upscaled resolution (960x540@30fps). | 2763 // Trigger adapt up, expect upscaled resolution (960x540@30fps). |
| 2724 vie_encoder_->TriggerQualityHigh(); | 2764 vie_encoder_->TriggerQualityHigh(); |
| 2725 timestamp_ms += kFrameIntervalMs; | 2765 timestamp_ms += kFrameIntervalMs; |
| 2726 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2766 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2727 sink_.WaitForEncodedFrame(timestamp_ms); | 2767 WaitForEncodedFrame(timestamp_ms); |
| 2728 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2768 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 2729 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2769 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2730 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2770 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2731 EXPECT_EQ(13, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2771 EXPECT_EQ(13, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2732 | 2772 |
| 2733 // Trigger adapt up, expect no restriction (1280x720fps@30fps). | 2773 // Trigger adapt up, expect no restriction (1280x720fps@30fps). |
| 2734 vie_encoder_->TriggerQualityHigh(); | 2774 vie_encoder_->TriggerQualityHigh(); |
| 2735 timestamp_ms += kFrameIntervalMs; | 2775 timestamp_ms += kFrameIntervalMs; |
| 2736 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2776 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2737 sink_.WaitForEncodedFrame(kWidth, kHeight); | 2777 WaitForEncodedFrame(kWidth, kHeight); |
| 2738 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2778 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 2739 VerifyNoLimitation(source.sink_wants()); | 2779 VerifyNoLimitation(source.sink_wants()); |
| 2740 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2780 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2741 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2781 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2742 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2782 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2743 | 2783 |
| 2744 // Trigger adapt up, expect no change. | 2784 // Trigger adapt up, expect no change. |
| 2745 vie_encoder_->TriggerQualityHigh(); | 2785 vie_encoder_->TriggerQualityHigh(); |
| 2746 VerifyNoLimitation(source.sink_wants()); | 2786 VerifyNoLimitation(source.sink_wants()); |
| 2747 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2787 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2748 | 2788 |
| 2749 vie_encoder_->Stop(); | 2789 vie_encoder_->Stop(); |
| 2750 } | 2790 } |
| 2751 | 2791 |
| 2752 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Framerate) { | 2792 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Framerate) { |
| 2753 const int kWidth = 1280; | 2793 const int kWidth = 1280; |
| 2754 const int kHeight = 720; | 2794 const int kHeight = 720; |
| 2755 const int64_t kFrameIntervalMs = 150; | 2795 const int64_t kFrameIntervalMs = 150; |
| 2756 int64_t timestamp_ms = kFrameIntervalMs; | 2796 int64_t timestamp_ms = kFrameIntervalMs; |
| 2757 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2797 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2758 | 2798 |
| 2759 // Enable kBalanced preference, no initial limitation. | 2799 // Enable kBalanced preference, no initial limitation. |
| 2760 AdaptingFrameForwarder source; | 2800 AdaptingFrameForwarder source; |
| 2761 source.set_adaptation_enabled(true); | 2801 source.set_adaptation_enabled(true); |
| 2762 vie_encoder_->SetSource(&source, | 2802 vie_encoder_->SetSource(&source, |
| 2763 VideoSendStream::DegradationPreference::kBalanced); | 2803 VideoSendStream::DegradationPreference::kBalanced); |
| 2764 timestamp_ms += kFrameIntervalMs; | 2804 timestamp_ms += kFrameIntervalMs; |
| 2765 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2805 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2766 sink_.WaitForEncodedFrame(kWidth, kHeight); | 2806 WaitForEncodedFrame(kWidth, kHeight); |
| 2767 VerifyNoLimitation(source.sink_wants()); | 2807 VerifyNoLimitation(source.sink_wants()); |
| 2768 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2808 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2769 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2809 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2770 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2810 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2771 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2811 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2772 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2812 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2773 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2813 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2774 | 2814 |
| 2775 // Trigger cpu adapt down, expect scaled down resolution (960x540@30fps). | 2815 // Trigger cpu adapt down, expect scaled down resolution (960x540@30fps). |
| 2776 vie_encoder_->TriggerCpuOveruse(); | 2816 vie_encoder_->TriggerCpuOveruse(); |
| 2777 timestamp_ms += kFrameIntervalMs; | 2817 timestamp_ms += kFrameIntervalMs; |
| 2778 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2818 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2779 sink_.WaitForEncodedFrame(timestamp_ms); | 2819 WaitForEncodedFrame(timestamp_ms); |
| 2780 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 2820 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
| 2781 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2821 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2782 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2822 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2783 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2823 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2784 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2824 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2785 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2825 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2786 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2826 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2787 | 2827 |
| 2788 // Trigger cpu adapt down, expect scaled down resolution (640x360@30fps). | 2828 // Trigger cpu adapt down, expect scaled down resolution (640x360@30fps). |
| 2789 vie_encoder_->TriggerCpuOveruse(); | 2829 vie_encoder_->TriggerCpuOveruse(); |
| 2790 timestamp_ms += kFrameIntervalMs; | 2830 timestamp_ms += kFrameIntervalMs; |
| 2791 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2831 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2792 sink_.WaitForEncodedFrame(timestamp_ms); | 2832 WaitForEncodedFrame(timestamp_ms); |
| 2793 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 2833 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
| 2794 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2834 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2795 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2835 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2796 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2836 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2797 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2837 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2798 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2838 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2799 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2839 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2800 | 2840 |
| 2801 // Trigger quality adapt down, expect reduced fps (640x360@15fps). | 2841 // Trigger quality adapt down, expect reduced fps (640x360@15fps). |
| 2802 vie_encoder_->TriggerQualityLow(); | 2842 vie_encoder_->TriggerQualityLow(); |
| 2803 timestamp_ms += kFrameIntervalMs; | 2843 timestamp_ms += kFrameIntervalMs; |
| 2804 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2844 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2805 sink_.WaitForEncodedFrame(timestamp_ms); | 2845 WaitForEncodedFrame(timestamp_ms); |
| 2806 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); | 2846 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
| 2807 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2847 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2808 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2848 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2809 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2849 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2810 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2850 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2811 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2851 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2812 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2852 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2813 | 2853 |
| 2814 // Trigger cpu adapt up, expect increased fps (640x360@30fps). | 2854 // Trigger cpu adapt up, expect increased fps (640x360@30fps). |
| 2815 vie_encoder_->TriggerCpuNormalUsage(); | 2855 vie_encoder_->TriggerCpuNormalUsage(); |
| 2816 timestamp_ms += kFrameIntervalMs; | 2856 timestamp_ms += kFrameIntervalMs; |
| 2817 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2857 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2818 sink_.WaitForEncodedFrame(timestamp_ms); | 2858 WaitForEncodedFrame(timestamp_ms); |
| 2819 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); | 2859 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); |
| 2820 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2860 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2821 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2861 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2822 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2862 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2823 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2863 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2824 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2864 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2825 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2865 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2826 | 2866 |
| 2827 // Trigger quality adapt up, expect upscaled resolution (960x540@30fps). | 2867 // Trigger quality adapt up, expect upscaled resolution (960x540@30fps). |
| 2828 vie_encoder_->TriggerQualityHigh(); | 2868 vie_encoder_->TriggerQualityHigh(); |
| 2829 timestamp_ms += kFrameIntervalMs; | 2869 timestamp_ms += kFrameIntervalMs; |
| 2830 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2870 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2831 sink_.WaitForEncodedFrame(timestamp_ms); | 2871 WaitForEncodedFrame(timestamp_ms); |
| 2832 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2872 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 2833 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2873 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2834 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2874 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2835 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2875 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2836 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2876 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2837 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2877 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2838 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2878 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2839 | 2879 |
| 2840 // Trigger cpu adapt up, expect no restriction (1280x720fps@30fps). | 2880 // Trigger cpu adapt up, expect no restriction (1280x720fps@30fps). |
| 2841 vie_encoder_->TriggerCpuNormalUsage(); | 2881 vie_encoder_->TriggerCpuNormalUsage(); |
| 2842 timestamp_ms += kFrameIntervalMs; | 2882 timestamp_ms += kFrameIntervalMs; |
| 2843 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2883 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2844 sink_.WaitForEncodedFrame(kWidth, kHeight); | 2884 WaitForEncodedFrame(kWidth, kHeight); |
| 2845 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2885 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
| 2846 VerifyNoLimitation(source.sink_wants()); | 2886 VerifyNoLimitation(source.sink_wants()); |
| 2847 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2887 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2848 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2888 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2849 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2889 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2850 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2890 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2851 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2891 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2852 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2892 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2853 | 2893 |
| 2854 // Trigger adapt up, expect no change. | 2894 // Trigger adapt up, expect no change. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2868 int64_t timestamp_ms = kFrameIntervalMs; | 2908 int64_t timestamp_ms = kFrameIntervalMs; |
| 2869 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2909 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2870 | 2910 |
| 2871 // Enable kBalanced preference, no initial limitation. | 2911 // Enable kBalanced preference, no initial limitation. |
| 2872 AdaptingFrameForwarder source; | 2912 AdaptingFrameForwarder source; |
| 2873 source.set_adaptation_enabled(true); | 2913 source.set_adaptation_enabled(true); |
| 2874 vie_encoder_->SetSource(&source, | 2914 vie_encoder_->SetSource(&source, |
| 2875 VideoSendStream::DegradationPreference::kBalanced); | 2915 VideoSendStream::DegradationPreference::kBalanced); |
| 2876 timestamp_ms += kFrameIntervalMs; | 2916 timestamp_ms += kFrameIntervalMs; |
| 2877 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2917 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2878 sink_.WaitForEncodedFrame(kWidth, kHeight); | 2918 WaitForEncodedFrame(kWidth, kHeight); |
| 2879 VerifyNoLimitation(source.sink_wants()); | 2919 VerifyNoLimitation(source.sink_wants()); |
| 2880 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2920 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2881 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2921 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2882 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2922 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2883 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2923 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2884 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2924 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2885 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2925 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2886 | 2926 |
| 2887 // Trigger cpu adapt down, expect scaled down framerate (640x360@15fps). | 2927 // Trigger cpu adapt down, expect scaled down framerate (640x360@15fps). |
| 2888 vie_encoder_->TriggerCpuOveruse(); | 2928 vie_encoder_->TriggerCpuOveruse(); |
| 2889 timestamp_ms += kFrameIntervalMs; | 2929 timestamp_ms += kFrameIntervalMs; |
| 2890 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2930 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2891 sink_.WaitForEncodedFrame(timestamp_ms); | 2931 WaitForEncodedFrame(timestamp_ms); |
| 2892 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); | 2932 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); |
| 2893 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2933 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2894 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2934 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2895 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2935 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2896 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); | 2936 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2897 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2937 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2898 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2938 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2899 | 2939 |
| 2900 // Trigger quality adapt down, expect scaled down resolution (480x270@15fps). | 2940 // Trigger quality adapt down, expect scaled down resolution (480x270@15fps). |
| 2901 vie_encoder_->TriggerQualityLow(); | 2941 vie_encoder_->TriggerQualityLow(); |
| 2902 timestamp_ms += kFrameIntervalMs; | 2942 timestamp_ms += kFrameIntervalMs; |
| 2903 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2943 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2904 sink_.WaitForEncodedFrame(timestamp_ms); | 2944 WaitForEncodedFrame(timestamp_ms); |
| 2905 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); | 2945 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); |
| 2906 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2946 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2907 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2947 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2908 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2948 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2909 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); | 2949 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2910 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2950 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2911 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2951 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2912 | 2952 |
| 2913 // Trigger cpu adapt up, expect upscaled resolution (640x360@15fps). | 2953 // Trigger cpu adapt up, expect upscaled resolution (640x360@15fps). |
| 2914 vie_encoder_->TriggerCpuNormalUsage(); | 2954 vie_encoder_->TriggerCpuNormalUsage(); |
| 2915 timestamp_ms += kFrameIntervalMs; | 2955 timestamp_ms += kFrameIntervalMs; |
| 2916 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2956 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2917 sink_.WaitForEncodedFrame(timestamp_ms); | 2957 WaitForEncodedFrame(timestamp_ms); |
| 2918 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); | 2958 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); |
| 2919 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2959 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2920 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2960 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2921 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2961 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2922 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2962 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2923 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2963 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2924 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2964 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2925 | 2965 |
| 2926 // Trigger quality adapt up, expect increased fps (640x360@30fps). | 2966 // Trigger quality adapt up, expect increased fps (640x360@30fps). |
| 2927 vie_encoder_->TriggerQualityHigh(); | 2967 vie_encoder_->TriggerQualityHigh(); |
| 2928 timestamp_ms += kFrameIntervalMs; | 2968 timestamp_ms += kFrameIntervalMs; |
| 2929 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2969 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
| 2930 sink_.WaitForEncodedFrame(timestamp_ms); | 2970 WaitForEncodedFrame(timestamp_ms); |
| 2931 VerifyNoLimitation(source.sink_wants()); | 2971 VerifyNoLimitation(source.sink_wants()); |
| 2932 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2972 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
| 2933 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2973 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
| 2934 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2974 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
| 2935 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2975 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
| 2936 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2976 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
| 2937 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2977 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
| 2938 | 2978 |
| 2939 // Trigger adapt up, expect no change. | 2979 // Trigger adapt up, expect no change. |
| 2940 vie_encoder_->TriggerQualityHigh(); | 2980 vie_encoder_->TriggerQualityHigh(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2993 video_encoder_config.video_stream_factory = | 3033 video_encoder_config.video_stream_factory = |
| 2994 new rtc::RefCountedObject<CroppingVideoStreamFactory>(1, kFramerate); | 3034 new rtc::RefCountedObject<CroppingVideoStreamFactory>(1, kFramerate); |
| 2995 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 3035 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 2996 kMaxPayloadLength, false); | 3036 kMaxPayloadLength, false); |
| 2997 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 3037 vie_encoder_->WaitUntilTaskQueueIsIdle(); |
| 2998 | 3038 |
| 2999 video_source_.set_adaptation_enabled(true); | 3039 video_source_.set_adaptation_enabled(true); |
| 3000 | 3040 |
| 3001 video_source_.IncomingCapturedFrame( | 3041 video_source_.IncomingCapturedFrame( |
| 3002 CreateFrame(1, kFrameWidth, kFrameHeight)); | 3042 CreateFrame(1, kFrameWidth, kFrameHeight)); |
| 3003 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 3043 WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 3004 | 3044 |
| 3005 // Trigger CPU overuse, downscale by 3/4. | 3045 // Trigger CPU overuse, downscale by 3/4. |
| 3006 vie_encoder_->TriggerCpuOveruse(); | 3046 vie_encoder_->TriggerCpuOveruse(); |
| 3007 video_source_.IncomingCapturedFrame( | 3047 video_source_.IncomingCapturedFrame( |
| 3008 CreateFrame(2, kFrameWidth, kFrameHeight)); | 3048 CreateFrame(2, kFrameWidth, kFrameHeight)); |
| 3009 sink_.WaitForEncodedFrame(kAdaptedFrameWidth, kAdaptedFrameHeight); | 3049 WaitForEncodedFrame(kAdaptedFrameWidth, kAdaptedFrameHeight); |
| 3010 | 3050 |
| 3011 vie_encoder_->Stop(); | 3051 vie_encoder_->Stop(); |
| 3012 } | 3052 } |
| 3013 | 3053 |
| 3054 TEST_F(ViEEncoderTest, PeriodicallyUpdatesChannelParameters) { |
| 3055 const int kFrameWidth = 1280; |
| 3056 const int kFrameHeight = 720; |
| 3057 const int kLowFps = 2; |
| 3058 const int kHighFps = 30; |
| 3059 |
| 3060 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 3061 |
| 3062 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
| 3063 max_framerate_ = kLowFps; |
| 3064 |
| 3065 // Insert 2 seconds of 2fps video. |
| 3066 for (int i = 0; i < kLowFps * 2; ++i) { |
| 3067 video_source_.IncomingCapturedFrame( |
| 3068 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 3069 WaitForEncodedFrame(timestamp_ms); |
| 3070 timestamp_ms += 1000 / kLowFps; |
| 3071 } |
| 3072 |
| 3073 // Make sure encoder is updated with new target. |
| 3074 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 3075 video_source_.IncomingCapturedFrame( |
| 3076 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 3077 WaitForEncodedFrame(timestamp_ms); |
| 3078 timestamp_ms += 1000 / kLowFps; |
| 3079 |
| 3080 EXPECT_EQ(kLowFps, fake_encoder_.GetConfiguredInputFramerate()); |
| 3081 |
| 3082 // Insert 30fps frames for just a little more than the forced update period. |
| 3083 const int kVcmTimerIntervalFrames = |
| 3084 (vcm::VCMProcessTimer::kDefaultProcessIntervalMs * kHighFps) / 1000; |
| 3085 const int kFrameIntervalMs = 1000 / kHighFps; |
| 3086 max_framerate_ = kHighFps; |
| 3087 for (int i = 0; i < kVcmTimerIntervalFrames + 2; ++i) { |
| 3088 video_source_.IncomingCapturedFrame( |
| 3089 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 3090 // Wait for encoded frame, but skip ahead if it doesn't arrive as it might |
| 3091 // be dropped if the encoder hans't been updated with the new higher target |
| 3092 // framerate yet, causing it to overshoot the target bitrate and then |
| 3093 // suffering the wrath of the media optimizer. |
| 3094 TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameIntervalMs); |
| 3095 timestamp_ms += kFrameIntervalMs; |
| 3096 } |
| 3097 |
| 3098 // Don expect correct measurement just yet, but it should be higher than |
| 3099 // before. |
| 3100 EXPECT_GT(fake_encoder_.GetConfiguredInputFramerate(), kLowFps); |
| 3101 |
| 3102 vie_encoder_->Stop(); |
| 3103 } |
| 3104 |
| 3105 TEST_F(ViEEncoderTest, DoesNotUpdateBitrateAllocationWhenSuspended) { |
| 3106 const int kFrameWidth = 1280; |
| 3107 const int kFrameHeight = 720; |
| 3108 const int kTargetBitrateBps = 1000000; |
| 3109 |
| 3110 MockBitrateObserver bitrate_observer; |
| 3111 vie_encoder_->SetBitrateObserver(&bitrate_observer); |
| 3112 |
| 3113 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(1); |
| 3114 // Initial bitrate update. |
| 3115 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 3116 vie_encoder_->WaitUntilTaskQueueIsIdle(); |
| 3117 |
| 3118 // Insert a first video frame, causes another bitrate update. |
| 3119 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
| 3120 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(1); |
| 3121 video_source_.IncomingCapturedFrame( |
| 3122 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 3123 WaitForEncodedFrame(timestamp_ms); |
| 3124 |
| 3125 // Next, simulate video suspension due to pacer queue overrun. |
| 3126 vie_encoder_->OnBitrateUpdated(0, 0, 1); |
| 3127 |
| 3128 // Skip ahead until a new periodic parameter update should have occured. |
| 3129 timestamp_ms += vcm::VCMProcessTimer::kDefaultProcessIntervalMs; |
| 3130 fake_clock_.AdvanceTimeMicros( |
| 3131 vcm::VCMProcessTimer::kDefaultProcessIntervalMs * |
| 3132 rtc::kNumMicrosecsPerMillisec); |
| 3133 |
| 3134 // Bitrate observer should not be called. |
| 3135 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(0); |
| 3136 video_source_.IncomingCapturedFrame( |
| 3137 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 3138 ExpectDroppedFrame(); |
| 3139 |
| 3140 vie_encoder_->Stop(); |
| 3141 } |
| 3014 | 3142 |
| 3015 } // namespace webrtc | 3143 } // namespace webrtc |
| OLD | NEW |