OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <limits> | 12 #include <limits> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "webrtc/api/video/i420_buffer.h" | 15 #include "webrtc/api/video/i420_buffer.h" |
16 #include "webrtc/media/base/videoadapter.h" | 16 #include "webrtc/media/base/videoadapter.h" |
17 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | 17 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
18 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" | 18 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" |
19 #include "webrtc/rtc_base/fakeclock.h" | 19 #include "webrtc/rtc_base/fakeclock.h" |
20 #include "webrtc/rtc_base/logging.h" | 20 #include "webrtc/rtc_base/logging.h" |
21 #include "webrtc/system_wrappers/include/metrics_default.h" | 21 #include "webrtc/system_wrappers/include/metrics_default.h" |
22 #include "webrtc/system_wrappers/include/sleep.h" | 22 #include "webrtc/system_wrappers/include/sleep.h" |
23 #include "webrtc/test/encoder_settings.h" | 23 #include "webrtc/test/encoder_settings.h" |
24 #include "webrtc/test/fake_encoder.h" | 24 #include "webrtc/test/fake_encoder.h" |
25 #include "webrtc/test/frame_generator.h" | 25 #include "webrtc/test/frame_generator.h" |
26 #include "webrtc/test/gmock.h" | 26 #include "webrtc/test/gmock.h" |
27 #include "webrtc/test/gtest.h" | 27 #include "webrtc/test/gtest.h" |
28 #include "webrtc/video/send_statistics_proxy.h" | 28 #include "webrtc/video/send_statistics_proxy.h" |
29 #include "webrtc/video/vie_encoder.h" | 29 #include "webrtc/video/video_stream_encoder.h" |
30 | 30 |
31 namespace { | 31 namespace { |
32 // TODO(kthelgason): Lower this limit when better testing | 32 // TODO(kthelgason): Lower this limit when better testing |
33 // on MediaCodec and fallback implementations are in place. | 33 // on MediaCodec and fallback implementations are in place. |
34 const int kMinPixelsPerFrame = 320 * 180; | 34 const int kMinPixelsPerFrame = 320 * 180; |
35 const int kMinFramerateFps = 2; | 35 const int kMinFramerateFps = 2; |
36 const int64_t kFrameTimeoutMs = 100; | 36 const int64_t kFrameTimeoutMs = 100; |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 namespace webrtc { | 39 namespace webrtc { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 int GetLastTargetFramerate() { | 86 int GetLastTargetFramerate() { |
87 rtc::CritScope cs(&lock_); | 87 rtc::CritScope cs(&lock_); |
88 return last_target_framerate_fps_; | 88 return last_target_framerate_fps_; |
89 } | 89 } |
90 | 90 |
91 private: | 91 private: |
92 rtc::CriticalSection lock_; | 92 rtc::CriticalSection lock_; |
93 int last_target_framerate_fps_ GUARDED_BY(lock_); | 93 int last_target_framerate_fps_ GUARDED_BY(lock_); |
94 }; | 94 }; |
95 | 95 |
96 class ViEEncoderUnderTest : public ViEEncoder { | 96 class VideoStreamEncoderUnderTest : public VideoStreamEncoder { |
97 public: | 97 public: |
98 ViEEncoderUnderTest(SendStatisticsProxy* stats_proxy, | 98 VideoStreamEncoderUnderTest(SendStatisticsProxy* stats_proxy, |
99 const VideoSendStream::Config::EncoderSettings& settings) | 99 const VideoSendStream::Config::EncoderSettings& settings) |
100 : ViEEncoder(1 /* number_of_cores */, | 100 : VideoStreamEncoder( |
101 stats_proxy, | 101 1 /* number_of_cores */, |
102 settings, | 102 stats_proxy, |
103 nullptr /* pre_encode_callback */, | 103 settings, |
104 nullptr /* encoder_timing */, | 104 nullptr /* pre_encode_callback */, |
105 std::unique_ptr<OveruseFrameDetector>( | 105 nullptr /* encoder_timing */, |
106 overuse_detector_proxy_ = new CpuOveruseDetectorProxy( | 106 std::unique_ptr<OveruseFrameDetector>( |
107 GetCpuOveruseOptions(settings.full_overuse_time), | 107 overuse_detector_proxy_ = new CpuOveruseDetectorProxy( |
108 this, | 108 GetCpuOveruseOptions(settings.full_overuse_time), |
109 nullptr, | 109 this, |
110 stats_proxy))) {} | 110 nullptr, |
| 111 stats_proxy))) {} |
111 | 112 |
112 void PostTaskAndWait(bool down, AdaptReason reason) { | 113 void PostTaskAndWait(bool down, AdaptReason reason) { |
113 rtc::Event event(false, false); | 114 rtc::Event event(false, false); |
114 encoder_queue()->PostTask([this, &event, reason, down] { | 115 encoder_queue()->PostTask([this, &event, reason, down] { |
115 down ? AdaptDown(reason) : AdaptUp(reason); | 116 down ? AdaptDown(reason) : AdaptUp(reason); |
116 event.Set(); | 117 event.Set(); |
117 }); | 118 }); |
118 ASSERT_TRUE(event.Wait(5000)); | 119 ASSERT_TRUE(event.Wait(5000)); |
119 } | 120 } |
120 | 121 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 rtc::Optional<VideoSendStream::Stats> mock_stats_ GUARDED_BY(lock_); | 252 rtc::Optional<VideoSendStream::Stats> mock_stats_ GUARDED_BY(lock_); |
252 }; | 253 }; |
253 | 254 |
254 class MockBitrateObserver : public VideoBitrateAllocationObserver { | 255 class MockBitrateObserver : public VideoBitrateAllocationObserver { |
255 public: | 256 public: |
256 MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&)); | 257 MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&)); |
257 }; | 258 }; |
258 | 259 |
259 } // namespace | 260 } // namespace |
260 | 261 |
261 class ViEEncoderTest : public ::testing::Test { | 262 class VideoStreamEncoderTest : public ::testing::Test { |
262 public: | 263 public: |
263 static const int kDefaultTimeoutMs = 30 * 1000; | 264 static const int kDefaultTimeoutMs = 30 * 1000; |
264 | 265 |
265 ViEEncoderTest() | 266 VideoStreamEncoderTest() |
266 : video_send_config_(VideoSendStream::Config(nullptr)), | 267 : video_send_config_(VideoSendStream::Config(nullptr)), |
267 codec_width_(320), | 268 codec_width_(320), |
268 codec_height_(240), | 269 codec_height_(240), |
269 max_framerate_(30), | 270 max_framerate_(30), |
270 fake_encoder_(), | 271 fake_encoder_(), |
271 stats_proxy_(new MockableSendStatisticsProxy( | 272 stats_proxy_(new MockableSendStatisticsProxy( |
272 Clock::GetRealTimeClock(), | 273 Clock::GetRealTimeClock(), |
273 video_send_config_, | 274 video_send_config_, |
274 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), | 275 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), |
275 sink_(&fake_encoder_) {} | 276 sink_(&fake_encoder_) {} |
(...skipping 16 matching lines...) Expand all Loading... |
292 video_encoder_config.video_stream_factory->CreateEncoderStreams( | 293 video_encoder_config.video_stream_factory->CreateEncoderStreams( |
293 codec_width_, codec_height_, video_encoder_config); | 294 codec_width_, codec_height_, video_encoder_config); |
294 max_framerate_ = streams[0].max_framerate; | 295 max_framerate_ = streams[0].max_framerate; |
295 fake_clock_.SetTimeMicros(1234); | 296 fake_clock_.SetTimeMicros(1234); |
296 | 297 |
297 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); | 298 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); |
298 } | 299 } |
299 | 300 |
300 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, | 301 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, |
301 bool nack_enabled) { | 302 bool nack_enabled) { |
302 if (vie_encoder_) | 303 if (video_stream_encoder_) |
303 vie_encoder_->Stop(); | 304 video_stream_encoder_->Stop(); |
304 vie_encoder_.reset(new ViEEncoderUnderTest( | 305 video_stream_encoder_.reset(new VideoStreamEncoderUnderTest( |
305 stats_proxy_.get(), video_send_config_.encoder_settings)); | 306 stats_proxy_.get(), video_send_config_.encoder_settings)); |
306 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); | 307 video_stream_encoder_->SetSink(&sink_, false /* rotation_applied */); |
307 vie_encoder_->SetSource( | 308 video_stream_encoder_->SetSource( |
308 &video_source_, | 309 &video_source_, |
309 VideoSendStream::DegradationPreference::kMaintainFramerate); | 310 VideoSendStream::DegradationPreference::kMaintainFramerate); |
310 vie_encoder_->SetStartBitrate(kTargetBitrateBps); | 311 video_stream_encoder_->SetStartBitrate(kTargetBitrateBps); |
311 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 312 video_stream_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
312 kMaxPayloadLength, nack_enabled); | 313 kMaxPayloadLength, nack_enabled); |
313 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 314 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
314 } | 315 } |
315 | 316 |
316 void ResetEncoder(const std::string& payload_name, | 317 void ResetEncoder(const std::string& payload_name, |
317 size_t num_streams, | 318 size_t num_streams, |
318 size_t num_temporal_layers, | 319 size_t num_temporal_layers, |
319 bool nack_enabled, | 320 bool nack_enabled, |
320 bool screenshare) { | 321 bool screenshare) { |
321 video_send_config_.encoder_settings.payload_name = payload_name; | 322 video_send_config_.encoder_settings.payload_name = payload_name; |
322 | 323 |
323 VideoEncoderConfig video_encoder_config; | 324 VideoEncoderConfig video_encoder_config; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 uint32_t timestamp_ GUARDED_BY(local_crit_sect_) = 0; | 549 uint32_t timestamp_ GUARDED_BY(local_crit_sect_) = 0; |
549 int64_t ntp_time_ms_ GUARDED_BY(local_crit_sect_) = 0; | 550 int64_t ntp_time_ms_ GUARDED_BY(local_crit_sect_) = 0; |
550 int last_input_width_ GUARDED_BY(local_crit_sect_) = 0; | 551 int last_input_width_ GUARDED_BY(local_crit_sect_) = 0; |
551 int last_input_height_ GUARDED_BY(local_crit_sect_) = 0; | 552 int last_input_height_ GUARDED_BY(local_crit_sect_) = 0; |
552 bool quality_scaling_ GUARDED_BY(local_crit_sect_) = true; | 553 bool quality_scaling_ GUARDED_BY(local_crit_sect_) = true; |
553 std::vector<std::unique_ptr<TemporalLayers>> allocated_temporal_layers_ | 554 std::vector<std::unique_ptr<TemporalLayers>> allocated_temporal_layers_ |
554 GUARDED_BY(local_crit_sect_); | 555 GUARDED_BY(local_crit_sect_); |
555 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false; | 556 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false; |
556 }; | 557 }; |
557 | 558 |
558 class TestSink : public ViEEncoder::EncoderSink { | 559 class TestSink : public VideoStreamEncoder::EncoderSink { |
559 public: | 560 public: |
560 explicit TestSink(TestEncoder* test_encoder) | 561 explicit TestSink(TestEncoder* test_encoder) |
561 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} | 562 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} |
562 | 563 |
563 void WaitForEncodedFrame(int64_t expected_ntp_time) { | 564 void WaitForEncodedFrame(int64_t expected_ntp_time) { |
564 EXPECT_TRUE( | 565 EXPECT_TRUE( |
565 TimedWaitForEncodedFrame(expected_ntp_time, kDefaultTimeoutMs)); | 566 TimedWaitForEncodedFrame(expected_ntp_time, kDefaultTimeoutMs)); |
566 } | 567 } |
567 | 568 |
568 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, | 569 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 653 |
653 VideoSendStream::Config video_send_config_; | 654 VideoSendStream::Config video_send_config_; |
654 VideoEncoderConfig video_encoder_config_; | 655 VideoEncoderConfig video_encoder_config_; |
655 int codec_width_; | 656 int codec_width_; |
656 int codec_height_; | 657 int codec_height_; |
657 int max_framerate_; | 658 int max_framerate_; |
658 TestEncoder fake_encoder_; | 659 TestEncoder fake_encoder_; |
659 std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; | 660 std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; |
660 TestSink sink_; | 661 TestSink sink_; |
661 AdaptingFrameForwarder video_source_; | 662 AdaptingFrameForwarder video_source_; |
662 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; | 663 std::unique_ptr<VideoStreamEncoderUnderTest> video_stream_encoder_; |
663 rtc::ScopedFakeClock fake_clock_; | 664 rtc::ScopedFakeClock fake_clock_; |
664 }; | 665 }; |
665 | 666 |
666 TEST_F(ViEEncoderTest, EncodeOneFrame) { | 667 TEST_F(VideoStreamEncoderTest, EncodeOneFrame) { |
667 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 668 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
668 rtc::Event frame_destroyed_event(false, false); | 669 rtc::Event frame_destroyed_event(false, false); |
669 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 670 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
670 WaitForEncodedFrame(1); | 671 WaitForEncodedFrame(1); |
671 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 672 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
672 vie_encoder_->Stop(); | 673 video_stream_encoder_->Stop(); |
673 } | 674 } |
674 | 675 |
675 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { | 676 TEST_F(VideoStreamEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { |
676 // Dropped since no target bitrate has been set. | 677 // Dropped since no target bitrate has been set. |
677 rtc::Event frame_destroyed_event(false, false); | 678 rtc::Event frame_destroyed_event(false, false); |
678 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 679 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
679 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 680 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
680 | 681 |
681 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 682 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
682 | 683 |
683 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 684 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
684 WaitForEncodedFrame(2); | 685 WaitForEncodedFrame(2); |
685 vie_encoder_->Stop(); | 686 video_stream_encoder_->Stop(); |
686 } | 687 } |
687 | 688 |
688 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { | 689 TEST_F(VideoStreamEncoderTest, DropsFramesWhenRateSetToZero) { |
689 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 690 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
690 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 691 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
691 WaitForEncodedFrame(1); | 692 WaitForEncodedFrame(1); |
692 | 693 |
693 vie_encoder_->OnBitrateUpdated(0, 0, 0); | 694 video_stream_encoder_->OnBitrateUpdated(0, 0, 0); |
694 // Dropped since bitrate is zero. | 695 // Dropped since bitrate is zero. |
695 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 696 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
696 | 697 |
697 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 698 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
698 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 699 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
699 WaitForEncodedFrame(3); | 700 WaitForEncodedFrame(3); |
700 vie_encoder_->Stop(); | 701 video_stream_encoder_->Stop(); |
701 } | 702 } |
702 | 703 |
703 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { | 704 TEST_F(VideoStreamEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { |
704 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 705 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
705 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 706 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
706 WaitForEncodedFrame(1); | 707 WaitForEncodedFrame(1); |
707 | 708 |
708 // This frame will be dropped since it has the same ntp timestamp. | 709 // This frame will be dropped since it has the same ntp timestamp. |
709 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 710 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
710 | 711 |
711 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 712 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
712 WaitForEncodedFrame(2); | 713 WaitForEncodedFrame(2); |
713 vie_encoder_->Stop(); | 714 video_stream_encoder_->Stop(); |
714 } | 715 } |
715 | 716 |
716 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { | 717 TEST_F(VideoStreamEncoderTest, DropsFrameAfterStop) { |
717 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 718 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
718 | 719 |
719 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 720 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
720 WaitForEncodedFrame(1); | 721 WaitForEncodedFrame(1); |
721 | 722 |
722 vie_encoder_->Stop(); | 723 video_stream_encoder_->Stop(); |
723 sink_.SetExpectNoFrames(); | 724 sink_.SetExpectNoFrames(); |
724 rtc::Event frame_destroyed_event(false, false); | 725 rtc::Event frame_destroyed_event(false, false); |
725 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); | 726 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); |
726 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 727 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
727 } | 728 } |
728 | 729 |
729 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { | 730 TEST_F(VideoStreamEncoderTest, DropsPendingFramesOnSlowEncode) { |
730 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 731 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
731 | 732 |
732 fake_encoder_.BlockNextEncode(); | 733 fake_encoder_.BlockNextEncode(); |
733 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 734 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
734 WaitForEncodedFrame(1); | 735 WaitForEncodedFrame(1); |
735 // Here, the encoder thread will be blocked in the TestEncoder waiting for a | 736 // Here, the encoder thread will be blocked in the TestEncoder waiting for a |
736 // call to ContinueEncode. | 737 // call to ContinueEncode. |
737 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 738 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
738 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 739 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
739 fake_encoder_.ContinueEncode(); | 740 fake_encoder_.ContinueEncode(); |
740 WaitForEncodedFrame(3); | 741 WaitForEncodedFrame(3); |
741 | 742 |
742 vie_encoder_->Stop(); | 743 video_stream_encoder_->Stop(); |
743 } | 744 } |
744 | 745 |
745 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { | 746 TEST_F(VideoStreamEncoderTest, |
746 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 747 ConfigureEncoderTriggersOnEncoderConfigurationChanged) { |
| 748 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
747 EXPECT_EQ(0, sink_.number_of_reconfigurations()); | 749 EXPECT_EQ(0, sink_.number_of_reconfigurations()); |
748 | 750 |
749 // Capture a frame and wait for it to synchronize with the encoder thread. | 751 // Capture a frame and wait for it to synchronize with the encoder thread. |
750 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 752 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
751 WaitForEncodedFrame(1); | 753 WaitForEncodedFrame(1); |
752 // The encoder will have been configured once when the first frame is | 754 // The encoder will have been configured once when the first frame is |
753 // received. | 755 // received. |
754 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 756 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
755 | 757 |
756 VideoEncoderConfig video_encoder_config; | 758 VideoEncoderConfig video_encoder_config; |
757 test::FillEncoderConfiguration(1, &video_encoder_config); | 759 test::FillEncoderConfiguration(1, &video_encoder_config); |
758 video_encoder_config.min_transmit_bitrate_bps = 9999; | 760 video_encoder_config.min_transmit_bitrate_bps = 9999; |
759 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 761 video_stream_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
760 kMaxPayloadLength, true /* nack_enabled */); | 762 kMaxPayloadLength, |
| 763 true /* nack_enabled */); |
761 | 764 |
762 // Capture a frame and wait for it to synchronize with the encoder thread. | 765 // Capture a frame and wait for it to synchronize with the encoder thread. |
763 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 766 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
764 WaitForEncodedFrame(2); | 767 WaitForEncodedFrame(2); |
765 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 768 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
766 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); | 769 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); |
767 | 770 |
768 vie_encoder_->Stop(); | 771 video_stream_encoder_->Stop(); |
769 } | 772 } |
770 | 773 |
771 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { | 774 TEST_F(VideoStreamEncoderTest, FrameResolutionChangeReconfigureEncoder) { |
772 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 775 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
773 | 776 |
774 // Capture a frame and wait for it to synchronize with the encoder thread. | 777 // Capture a frame and wait for it to synchronize with the encoder thread. |
775 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 778 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
776 WaitForEncodedFrame(1); | 779 WaitForEncodedFrame(1); |
777 // The encoder will have been configured once. | 780 // The encoder will have been configured once. |
778 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 781 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
779 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 782 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
780 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 783 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
781 | 784 |
782 codec_width_ *= 2; | 785 codec_width_ *= 2; |
783 codec_height_ *= 2; | 786 codec_height_ *= 2; |
784 // Capture a frame with a higher resolution and wait for it to synchronize | 787 // Capture a frame with a higher resolution and wait for it to synchronize |
785 // with the encoder thread. | 788 // with the encoder thread. |
786 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 789 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
787 WaitForEncodedFrame(2); | 790 WaitForEncodedFrame(2); |
788 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 791 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
789 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 792 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
790 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 793 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
791 | 794 |
792 vie_encoder_->Stop(); | 795 video_stream_encoder_->Stop(); |
793 } | 796 } |
794 | 797 |
795 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor1S1TLWithNackEnabled) { | 798 TEST_F(VideoStreamEncoderTest, Vp8ResilienceIsOffFor1S1TLWithNackEnabled) { |
796 const bool kNackEnabled = true; | 799 const bool kNackEnabled = true; |
797 const size_t kNumStreams = 1; | 800 const size_t kNumStreams = 1; |
798 const size_t kNumTl = 1; | 801 const size_t kNumTl = 1; |
799 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); | 802 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
800 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 803 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
801 | 804 |
802 // Capture a frame and wait for it to synchronize with the encoder thread. | 805 // Capture a frame and wait for it to synchronize with the encoder thread. |
803 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 806 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
804 WaitForEncodedFrame(1); | 807 WaitForEncodedFrame(1); |
805 // The encoder have been configured once when the first frame is received. | 808 // The encoder have been configured once when the first frame is received. |
806 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 809 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
807 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 810 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
808 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 811 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
809 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 812 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
810 // Resilience is off for no temporal layers with nack on. | 813 // Resilience is off for no temporal layers with nack on. |
811 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); | 814 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); |
812 vie_encoder_->Stop(); | 815 video_stream_encoder_->Stop(); |
813 } | 816 } |
814 | 817 |
815 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor2S1TlWithNackEnabled) { | 818 TEST_F(VideoStreamEncoderTest, Vp8ResilienceIsOffFor2S1TlWithNackEnabled) { |
816 const bool kNackEnabled = true; | 819 const bool kNackEnabled = true; |
817 const size_t kNumStreams = 2; | 820 const size_t kNumStreams = 2; |
818 const size_t kNumTl = 1; | 821 const size_t kNumTl = 1; |
819 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); | 822 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
820 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 823 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
821 | 824 |
822 // Capture a frame and wait for it to synchronize with the encoder thread. | 825 // Capture a frame and wait for it to synchronize with the encoder thread. |
823 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 826 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
824 WaitForEncodedFrame(1); | 827 WaitForEncodedFrame(1); |
825 // The encoder have been configured once when the first frame is received. | 828 // The encoder have been configured once when the first frame is received. |
826 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 829 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
827 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 830 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
828 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 831 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
829 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 832 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
830 // Resilience is off for no temporal layers and >1 streams with nack on. | 833 // Resilience is off for no temporal layers and >1 streams with nack on. |
831 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); | 834 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); |
832 vie_encoder_->Stop(); | 835 video_stream_encoder_->Stop(); |
833 } | 836 } |
834 | 837 |
835 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S1TLWithNackDisabled) { | 838 TEST_F(VideoStreamEncoderTest, Vp8ResilienceIsOnFor1S1TLWithNackDisabled) { |
836 const bool kNackEnabled = false; | 839 const bool kNackEnabled = false; |
837 const size_t kNumStreams = 1; | 840 const size_t kNumStreams = 1; |
838 const size_t kNumTl = 1; | 841 const size_t kNumTl = 1; |
839 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); | 842 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
840 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 843 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
841 | 844 |
842 // Capture a frame and wait for it to synchronize with the encoder thread. | 845 // Capture a frame and wait for it to synchronize with the encoder thread. |
843 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 846 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
844 WaitForEncodedFrame(1); | 847 WaitForEncodedFrame(1); |
845 // The encoder have been configured once when the first frame is received. | 848 // The encoder have been configured once when the first frame is received. |
846 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 849 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
847 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 850 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
848 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 851 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
849 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 852 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
850 // Resilience is on for no temporal layers with nack off. | 853 // Resilience is on for no temporal layers with nack off. |
851 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); | 854 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); |
852 vie_encoder_->Stop(); | 855 video_stream_encoder_->Stop(); |
853 } | 856 } |
854 | 857 |
855 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S2TlWithNackEnabled) { | 858 TEST_F(VideoStreamEncoderTest, Vp8ResilienceIsOnFor1S2TlWithNackEnabled) { |
856 const bool kNackEnabled = true; | 859 const bool kNackEnabled = true; |
857 const size_t kNumStreams = 1; | 860 const size_t kNumStreams = 1; |
858 const size_t kNumTl = 2; | 861 const size_t kNumTl = 2; |
859 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); | 862 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
860 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 863 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
861 | 864 |
862 // Capture a frame and wait for it to synchronize with the encoder thread. | 865 // Capture a frame and wait for it to synchronize with the encoder thread. |
863 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 866 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
864 WaitForEncodedFrame(1); | 867 WaitForEncodedFrame(1); |
865 // The encoder have been configured once when the first frame is received. | 868 // The encoder have been configured once when the first frame is received. |
866 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 869 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
867 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 870 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
868 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 871 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
869 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 872 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
870 // Resilience is on for temporal layers. | 873 // Resilience is on for temporal layers. |
871 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); | 874 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); |
872 vie_encoder_->Stop(); | 875 video_stream_encoder_->Stop(); |
873 } | 876 } |
874 | 877 |
875 TEST_F(ViEEncoderTest, SwitchSourceDeregisterEncoderAsSink) { | 878 TEST_F(VideoStreamEncoderTest, SwitchSourceDeregisterEncoderAsSink) { |
876 EXPECT_TRUE(video_source_.has_sinks()); | 879 EXPECT_TRUE(video_source_.has_sinks()); |
877 test::FrameForwarder new_video_source; | 880 test::FrameForwarder new_video_source; |
878 vie_encoder_->SetSource( | 881 video_stream_encoder_->SetSource( |
879 &new_video_source, | 882 &new_video_source, |
880 VideoSendStream::DegradationPreference::kMaintainFramerate); | 883 VideoSendStream::DegradationPreference::kMaintainFramerate); |
881 EXPECT_FALSE(video_source_.has_sinks()); | 884 EXPECT_FALSE(video_source_.has_sinks()); |
882 EXPECT_TRUE(new_video_source.has_sinks()); | 885 EXPECT_TRUE(new_video_source.has_sinks()); |
883 | 886 |
884 vie_encoder_->Stop(); | 887 video_stream_encoder_->Stop(); |
885 } | 888 } |
886 | 889 |
887 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { | 890 TEST_F(VideoStreamEncoderTest, SinkWantsRotationApplied) { |
888 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); | 891 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); |
889 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); | 892 video_stream_encoder_->SetSink(&sink_, true /*rotation_applied*/); |
890 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); | 893 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); |
891 vie_encoder_->Stop(); | 894 video_stream_encoder_->Stop(); |
892 } | 895 } |
893 | 896 |
894 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { | 897 TEST_F(VideoStreamEncoderTest, SinkWantsFromOveruseDetector) { |
895 const int kMaxDowngrades = ViEEncoder::kMaxCpuResolutionDowngrades; | 898 const int kMaxDowngrades = VideoStreamEncoder::kMaxCpuResolutionDowngrades; |
896 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 899 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
897 | 900 |
898 VerifyNoLimitation(video_source_.sink_wants()); | 901 VerifyNoLimitation(video_source_.sink_wants()); |
899 | 902 |
900 int frame_width = 1280; | 903 int frame_width = 1280; |
901 int frame_height = 720; | 904 int frame_height = 720; |
902 | 905 |
903 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should | 906 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, VideoStreamEncoder |
904 // request lower resolution. | 907 // should request lower resolution. |
905 for (int i = 1; i <= kMaxDowngrades; ++i) { | 908 for (int i = 1; i <= kMaxDowngrades; ++i) { |
906 video_source_.IncomingCapturedFrame( | 909 video_source_.IncomingCapturedFrame( |
907 CreateFrame(i, frame_width, frame_height)); | 910 CreateFrame(i, frame_width, frame_height)); |
908 WaitForEncodedFrame(i); | 911 WaitForEncodedFrame(i); |
909 | 912 |
910 vie_encoder_->TriggerCpuOveruse(); | 913 video_stream_encoder_->TriggerCpuOveruse(); |
911 | 914 |
912 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 915 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
913 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 916 EXPECT_LT(video_source_.sink_wants().max_pixel_count, |
914 frame_width * frame_height); | 917 frame_width * frame_height); |
915 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 918 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
916 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 919 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
917 | 920 |
918 frame_width /= 2; | 921 frame_width /= 2; |
919 frame_height /= 2; | 922 frame_height /= 2; |
920 } | 923 } |
921 | 924 |
922 // Trigger CPU overuse one more time. This should not trigger a request for | 925 // Trigger CPU overuse one more time. This should not trigger a request for |
923 // lower resolution. | 926 // lower resolution. |
924 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); | 927 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); |
925 video_source_.IncomingCapturedFrame( | 928 video_source_.IncomingCapturedFrame( |
926 CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); | 929 CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); |
927 WaitForEncodedFrame(kMaxDowngrades + 1); | 930 WaitForEncodedFrame(kMaxDowngrades + 1); |
928 vie_encoder_->TriggerCpuOveruse(); | 931 video_stream_encoder_->TriggerCpuOveruse(); |
929 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, | 932 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, |
930 current_wants.target_pixel_count); | 933 current_wants.target_pixel_count); |
931 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, | 934 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, |
932 current_wants.max_pixel_count); | 935 current_wants.max_pixel_count); |
933 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 936 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
934 EXPECT_EQ(kMaxDowngrades, | 937 EXPECT_EQ(kMaxDowngrades, |
935 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 938 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
936 | 939 |
937 // Trigger CPU normal use. | 940 // Trigger CPU normal use. |
938 vie_encoder_->TriggerCpuNormalUsage(); | 941 video_stream_encoder_->TriggerCpuNormalUsage(); |
939 EXPECT_EQ(frame_width * frame_height * 5 / 3, | 942 EXPECT_EQ(frame_width * frame_height * 5 / 3, |
940 video_source_.sink_wants().target_pixel_count.value_or(0)); | 943 video_source_.sink_wants().target_pixel_count.value_or(0)); |
941 EXPECT_EQ(frame_width * frame_height * 4, | 944 EXPECT_EQ(frame_width * frame_height * 4, |
942 video_source_.sink_wants().max_pixel_count); | 945 video_source_.sink_wants().max_pixel_count); |
943 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 946 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
944 EXPECT_EQ(kMaxDowngrades + 1, | 947 EXPECT_EQ(kMaxDowngrades + 1, |
945 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 948 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
946 | 949 |
947 vie_encoder_->Stop(); | 950 video_stream_encoder_->Stop(); |
948 } | 951 } |
949 | 952 |
950 TEST_F(ViEEncoderTest, TestMaxCpuResolutionDowngrades_BalancedMode_NoFpsLimit) { | 953 TEST_F(VideoStreamEncoderTest, |
951 const int kMaxDowngrades = ViEEncoder::kMaxCpuResolutionDowngrades; | 954 TestMaxCpuResolutionDowngrades_BalancedMode_NoFpsLimit) { |
| 955 const int kMaxDowngrades = VideoStreamEncoder::kMaxCpuResolutionDowngrades; |
952 const int kWidth = 1280; | 956 const int kWidth = 1280; |
953 const int kHeight = 720; | 957 const int kHeight = 720; |
954 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 958 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
955 | 959 |
956 // Enable kBalanced preference, no initial limitation. | 960 // Enable kBalanced preference, no initial limitation. |
957 AdaptingFrameForwarder source; | 961 AdaptingFrameForwarder source; |
958 source.set_adaptation_enabled(true); | 962 source.set_adaptation_enabled(true); |
959 vie_encoder_->SetSource(&source, | 963 video_stream_encoder_->SetSource( |
960 VideoSendStream::DegradationPreference::kBalanced); | 964 &source, |
| 965 VideoSendStream::DegradationPreference::kBalanced); |
961 VerifyNoLimitation(source.sink_wants()); | 966 VerifyNoLimitation(source.sink_wants()); |
962 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 967 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
963 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 968 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
964 | 969 |
965 // Trigger adapt down kMaxCpuDowngrades times. | 970 // Trigger adapt down kMaxCpuDowngrades times. |
966 int t = 1; | 971 int t = 1; |
967 for (int i = 1; i <= kMaxDowngrades; ++i) { | 972 for (int i = 1; i <= kMaxDowngrades; ++i) { |
968 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight)); | 973 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight)); |
969 sink_.WaitForEncodedFrame(t++); | 974 sink_.WaitForEncodedFrame(t++); |
970 vie_encoder_->TriggerCpuOveruse(); | 975 video_stream_encoder_->TriggerCpuOveruse(); |
971 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 976 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
972 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 977 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
973 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 978 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
974 } | 979 } |
975 | 980 |
976 // Trigger adapt down, max cpu downgrades reach, expect no change. | 981 // Trigger adapt down, max cpu downgrades reach, expect no change. |
977 rtc::VideoSinkWants last_wants = source.sink_wants(); | 982 rtc::VideoSinkWants last_wants = source.sink_wants(); |
978 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight)); | 983 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight)); |
979 sink_.WaitForEncodedFrame(t++); | 984 sink_.WaitForEncodedFrame(t++); |
980 vie_encoder_->TriggerCpuOveruse(); | 985 video_stream_encoder_->TriggerCpuOveruse(); |
981 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 986 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
982 EXPECT_EQ(last_wants.max_pixel_count, source.sink_wants().max_pixel_count); | 987 EXPECT_EQ(last_wants.max_pixel_count, source.sink_wants().max_pixel_count); |
983 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 988 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
984 EXPECT_EQ(kMaxDowngrades, | 989 EXPECT_EQ(kMaxDowngrades, |
985 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 990 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
986 | 991 |
987 // Trigger adapt up kMaxCpuDowngrades times. | 992 // Trigger adapt up kMaxCpuDowngrades times. |
988 for (int i = 1; i <= kMaxDowngrades; ++i) { | 993 for (int i = 1; i <= kMaxDowngrades; ++i) { |
989 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight)); | 994 source.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight)); |
990 sink_.WaitForEncodedFrame(t++); | 995 sink_.WaitForEncodedFrame(t++); |
991 vie_encoder_->TriggerCpuNormalUsage(); | 996 video_stream_encoder_->TriggerCpuNormalUsage(); |
992 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 997 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
993 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count); | 998 EXPECT_GT(source.sink_wants().max_pixel_count, last_wants.max_pixel_count); |
994 EXPECT_EQ(kMaxDowngrades + i, | 999 EXPECT_EQ(kMaxDowngrades + i, |
995 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1000 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
996 } | 1001 } |
997 | 1002 |
998 VerifyNoLimitation(source.sink_wants()); | 1003 VerifyNoLimitation(source.sink_wants()); |
999 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1004 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1000 | 1005 |
1001 vie_encoder_->Stop(); | 1006 video_stream_encoder_->Stop(); |
1002 } | 1007 } |
1003 TEST_F(ViEEncoderTest, SinkWantsStoredByDegradationPreference) { | 1008 TEST_F(VideoStreamEncoderTest, SinkWantsStoredByDegradationPreference) { |
1004 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1009 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1005 VerifyNoLimitation(video_source_.sink_wants()); | 1010 VerifyNoLimitation(video_source_.sink_wants()); |
1006 | 1011 |
1007 const int kFrameWidth = 1280; | 1012 const int kFrameWidth = 1280; |
1008 const int kFrameHeight = 720; | 1013 const int kFrameHeight = 720; |
1009 const int kFrameIntervalMs = 1000 / 30; | 1014 const int kFrameIntervalMs = 1000 / 30; |
1010 | 1015 |
1011 int frame_timestamp = 1; | 1016 int frame_timestamp = 1; |
1012 | 1017 |
1013 video_source_.IncomingCapturedFrame( | 1018 video_source_.IncomingCapturedFrame( |
1014 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 1019 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
1015 WaitForEncodedFrame(frame_timestamp); | 1020 WaitForEncodedFrame(frame_timestamp); |
1016 frame_timestamp += kFrameIntervalMs; | 1021 frame_timestamp += kFrameIntervalMs; |
1017 | 1022 |
1018 // Trigger CPU overuse. | 1023 // Trigger CPU overuse. |
1019 vie_encoder_->TriggerCpuOveruse(); | 1024 video_stream_encoder_->TriggerCpuOveruse(); |
1020 video_source_.IncomingCapturedFrame( | 1025 video_source_.IncomingCapturedFrame( |
1021 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 1026 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
1022 WaitForEncodedFrame(frame_timestamp); | 1027 WaitForEncodedFrame(frame_timestamp); |
1023 frame_timestamp += kFrameIntervalMs; | 1028 frame_timestamp += kFrameIntervalMs; |
1024 | 1029 |
1025 // Default degradation preference is maintain-framerate, so will lower max | 1030 // Default degradation preference is maintain-framerate, so will lower max |
1026 // wanted resolution. | 1031 // wanted resolution. |
1027 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 1032 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
1028 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 1033 EXPECT_LT(video_source_.sink_wants().max_pixel_count, |
1029 kFrameWidth * kFrameHeight); | 1034 kFrameWidth * kFrameHeight); |
1030 EXPECT_EQ(std::numeric_limits<int>::max(), | 1035 EXPECT_EQ(std::numeric_limits<int>::max(), |
1031 video_source_.sink_wants().max_framerate_fps); | 1036 video_source_.sink_wants().max_framerate_fps); |
1032 | 1037 |
1033 // Set new source, switch to maintain-resolution. | 1038 // Set new source, switch to maintain-resolution. |
1034 test::FrameForwarder new_video_source; | 1039 test::FrameForwarder new_video_source; |
1035 vie_encoder_->SetSource( | 1040 video_stream_encoder_->SetSource( |
1036 &new_video_source, | 1041 &new_video_source, |
1037 VideoSendStream::DegradationPreference::kMaintainResolution); | 1042 VideoSendStream::DegradationPreference::kMaintainResolution); |
1038 | 1043 |
1039 // Initially no degradation registered. | 1044 // Initially no degradation registered. |
1040 VerifyNoLimitation(new_video_source.sink_wants()); | 1045 VerifyNoLimitation(new_video_source.sink_wants()); |
1041 | 1046 |
1042 // Force an input frame rate to be available, or the adaptation call won't | 1047 // Force an input frame rate to be available, or the adaptation call won't |
1043 // know what framerate to adapt form. | 1048 // know what framerate to adapt form. |
1044 const int kInputFps = 30; | 1049 const int kInputFps = 30; |
1045 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1050 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1046 stats.input_frame_rate = kInputFps; | 1051 stats.input_frame_rate = kInputFps; |
1047 stats_proxy_->SetMockStats(stats); | 1052 stats_proxy_->SetMockStats(stats); |
1048 | 1053 |
1049 vie_encoder_->TriggerCpuOveruse(); | 1054 video_stream_encoder_->TriggerCpuOveruse(); |
1050 new_video_source.IncomingCapturedFrame( | 1055 new_video_source.IncomingCapturedFrame( |
1051 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 1056 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
1052 WaitForEncodedFrame(frame_timestamp); | 1057 WaitForEncodedFrame(frame_timestamp); |
1053 frame_timestamp += kFrameIntervalMs; | 1058 frame_timestamp += kFrameIntervalMs; |
1054 | 1059 |
1055 // Some framerate constraint should be set. | 1060 // Some framerate constraint should be set. |
1056 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 1061 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
1057 EXPECT_EQ(std::numeric_limits<int>::max(), | 1062 EXPECT_EQ(std::numeric_limits<int>::max(), |
1058 new_video_source.sink_wants().max_pixel_count); | 1063 new_video_source.sink_wants().max_pixel_count); |
1059 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); | 1064 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); |
1060 | 1065 |
1061 // Turn off degradation completely. | 1066 // Turn off degradation completely. |
1062 vie_encoder_->SetSource( | 1067 video_stream_encoder_->SetSource( |
1063 &new_video_source, | 1068 &new_video_source, |
1064 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1069 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1065 VerifyNoLimitation(new_video_source.sink_wants()); | 1070 VerifyNoLimitation(new_video_source.sink_wants()); |
1066 | 1071 |
1067 vie_encoder_->TriggerCpuOveruse(); | 1072 video_stream_encoder_->TriggerCpuOveruse(); |
1068 new_video_source.IncomingCapturedFrame( | 1073 new_video_source.IncomingCapturedFrame( |
1069 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 1074 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
1070 WaitForEncodedFrame(frame_timestamp); | 1075 WaitForEncodedFrame(frame_timestamp); |
1071 frame_timestamp += kFrameIntervalMs; | 1076 frame_timestamp += kFrameIntervalMs; |
1072 | 1077 |
1073 // Still no degradation. | 1078 // Still no degradation. |
1074 VerifyNoLimitation(new_video_source.sink_wants()); | 1079 VerifyNoLimitation(new_video_source.sink_wants()); |
1075 | 1080 |
1076 // Calling SetSource with resolution scaling enabled apply the old SinkWants. | 1081 // Calling SetSource with resolution scaling enabled apply the old SinkWants. |
1077 vie_encoder_->SetSource( | 1082 video_stream_encoder_->SetSource( |
1078 &new_video_source, | 1083 &new_video_source, |
1079 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1084 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1080 EXPECT_LT(new_video_source.sink_wants().max_pixel_count, | 1085 EXPECT_LT(new_video_source.sink_wants().max_pixel_count, |
1081 kFrameWidth * kFrameHeight); | 1086 kFrameWidth * kFrameHeight); |
1082 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 1087 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
1083 EXPECT_EQ(std::numeric_limits<int>::max(), | 1088 EXPECT_EQ(std::numeric_limits<int>::max(), |
1084 new_video_source.sink_wants().max_framerate_fps); | 1089 new_video_source.sink_wants().max_framerate_fps); |
1085 | 1090 |
1086 // Calling SetSource with framerate scaling enabled apply the old SinkWants. | 1091 // Calling SetSource with framerate scaling enabled apply the old SinkWants. |
1087 vie_encoder_->SetSource( | 1092 video_stream_encoder_->SetSource( |
1088 &new_video_source, | 1093 &new_video_source, |
1089 VideoSendStream::DegradationPreference::kMaintainResolution); | 1094 VideoSendStream::DegradationPreference::kMaintainResolution); |
1090 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 1095 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
1091 EXPECT_EQ(std::numeric_limits<int>::max(), | 1096 EXPECT_EQ(std::numeric_limits<int>::max(), |
1092 new_video_source.sink_wants().max_pixel_count); | 1097 new_video_source.sink_wants().max_pixel_count); |
1093 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); | 1098 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); |
1094 | 1099 |
1095 vie_encoder_->Stop(); | 1100 video_stream_encoder_->Stop(); |
1096 } | 1101 } |
1097 | 1102 |
1098 TEST_F(ViEEncoderTest, StatsTracksQualityAdaptationStats) { | 1103 TEST_F(VideoStreamEncoderTest, StatsTracksQualityAdaptationStats) { |
1099 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1104 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1100 | 1105 |
1101 const int kWidth = 1280; | 1106 const int kWidth = 1280; |
1102 const int kHeight = 720; | 1107 const int kHeight = 720; |
1103 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1108 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1104 WaitForEncodedFrame(1); | 1109 WaitForEncodedFrame(1); |
1105 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1110 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1106 EXPECT_FALSE(stats.bw_limited_resolution); | 1111 EXPECT_FALSE(stats.bw_limited_resolution); |
1107 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1112 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1108 | 1113 |
1109 // Trigger adapt down. | 1114 // Trigger adapt down. |
1110 vie_encoder_->TriggerQualityLow(); | 1115 video_stream_encoder_->TriggerQualityLow(); |
1111 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1116 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1112 WaitForEncodedFrame(2); | 1117 WaitForEncodedFrame(2); |
1113 | 1118 |
1114 stats = stats_proxy_->GetStats(); | 1119 stats = stats_proxy_->GetStats(); |
1115 EXPECT_TRUE(stats.bw_limited_resolution); | 1120 EXPECT_TRUE(stats.bw_limited_resolution); |
1116 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1121 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1117 | 1122 |
1118 // Trigger adapt up. | 1123 // Trigger adapt up. |
1119 vie_encoder_->TriggerQualityHigh(); | 1124 video_stream_encoder_->TriggerQualityHigh(); |
1120 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1125 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1121 WaitForEncodedFrame(3); | 1126 WaitForEncodedFrame(3); |
1122 | 1127 |
1123 stats = stats_proxy_->GetStats(); | 1128 stats = stats_proxy_->GetStats(); |
1124 EXPECT_FALSE(stats.bw_limited_resolution); | 1129 EXPECT_FALSE(stats.bw_limited_resolution); |
1125 EXPECT_EQ(2, stats.number_of_quality_adapt_changes); | 1130 EXPECT_EQ(2, stats.number_of_quality_adapt_changes); |
1126 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1131 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1127 | 1132 |
1128 vie_encoder_->Stop(); | 1133 video_stream_encoder_->Stop(); |
1129 } | 1134 } |
1130 | 1135 |
1131 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStats) { | 1136 TEST_F(VideoStreamEncoderTest, StatsTracksCpuAdaptationStats) { |
1132 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1137 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1133 | 1138 |
1134 const int kWidth = 1280; | 1139 const int kWidth = 1280; |
1135 const int kHeight = 720; | 1140 const int kHeight = 720; |
1136 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1141 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1137 WaitForEncodedFrame(1); | 1142 WaitForEncodedFrame(1); |
1138 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1143 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1139 EXPECT_FALSE(stats.cpu_limited_resolution); | 1144 EXPECT_FALSE(stats.cpu_limited_resolution); |
1140 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1145 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1141 | 1146 |
1142 // Trigger CPU overuse. | 1147 // Trigger CPU overuse. |
1143 vie_encoder_->TriggerCpuOveruse(); | 1148 video_stream_encoder_->TriggerCpuOveruse(); |
1144 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1149 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1145 WaitForEncodedFrame(2); | 1150 WaitForEncodedFrame(2); |
1146 | 1151 |
1147 stats = stats_proxy_->GetStats(); | 1152 stats = stats_proxy_->GetStats(); |
1148 EXPECT_TRUE(stats.cpu_limited_resolution); | 1153 EXPECT_TRUE(stats.cpu_limited_resolution); |
1149 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1154 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1150 | 1155 |
1151 // Trigger CPU normal use. | 1156 // Trigger CPU normal use. |
1152 vie_encoder_->TriggerCpuNormalUsage(); | 1157 video_stream_encoder_->TriggerCpuNormalUsage(); |
1153 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1158 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1154 WaitForEncodedFrame(3); | 1159 WaitForEncodedFrame(3); |
1155 | 1160 |
1156 stats = stats_proxy_->GetStats(); | 1161 stats = stats_proxy_->GetStats(); |
1157 EXPECT_FALSE(stats.cpu_limited_resolution); | 1162 EXPECT_FALSE(stats.cpu_limited_resolution); |
1158 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1163 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1159 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1164 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1160 | 1165 |
1161 vie_encoder_->Stop(); | 1166 video_stream_encoder_->Stop(); |
1162 } | 1167 } |
1163 | 1168 |
1164 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { | 1169 TEST_F(VideoStreamEncoderTest, SwitchingSourceKeepsCpuAdaptation) { |
1165 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1170 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1166 | 1171 |
1167 const int kWidth = 1280; | 1172 const int kWidth = 1280; |
1168 const int kHeight = 720; | 1173 const int kHeight = 720; |
1169 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1174 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1170 WaitForEncodedFrame(1); | 1175 WaitForEncodedFrame(1); |
1171 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1176 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1172 EXPECT_FALSE(stats.bw_limited_resolution); | 1177 EXPECT_FALSE(stats.bw_limited_resolution); |
1173 EXPECT_FALSE(stats.cpu_limited_resolution); | 1178 EXPECT_FALSE(stats.cpu_limited_resolution); |
1174 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1179 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1175 | 1180 |
1176 // Trigger CPU overuse. | 1181 // Trigger CPU overuse. |
1177 vie_encoder_->TriggerCpuOveruse(); | 1182 video_stream_encoder_->TriggerCpuOveruse(); |
1178 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1183 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1179 WaitForEncodedFrame(2); | 1184 WaitForEncodedFrame(2); |
1180 stats = stats_proxy_->GetStats(); | 1185 stats = stats_proxy_->GetStats(); |
1181 EXPECT_FALSE(stats.bw_limited_resolution); | 1186 EXPECT_FALSE(stats.bw_limited_resolution); |
1182 EXPECT_TRUE(stats.cpu_limited_resolution); | 1187 EXPECT_TRUE(stats.cpu_limited_resolution); |
1183 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1188 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1184 | 1189 |
1185 // Set new source with adaptation still enabled. | 1190 // Set new source with adaptation still enabled. |
1186 test::FrameForwarder new_video_source; | 1191 test::FrameForwarder new_video_source; |
1187 vie_encoder_->SetSource( | 1192 video_stream_encoder_->SetSource( |
1188 &new_video_source, | 1193 &new_video_source, |
1189 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1194 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1190 | 1195 |
1191 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1196 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1192 WaitForEncodedFrame(3); | 1197 WaitForEncodedFrame(3); |
1193 stats = stats_proxy_->GetStats(); | 1198 stats = stats_proxy_->GetStats(); |
1194 EXPECT_FALSE(stats.bw_limited_resolution); | 1199 EXPECT_FALSE(stats.bw_limited_resolution); |
1195 EXPECT_TRUE(stats.cpu_limited_resolution); | 1200 EXPECT_TRUE(stats.cpu_limited_resolution); |
1196 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1201 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1197 | 1202 |
1198 // Set adaptation disabled. | 1203 // Set adaptation disabled. |
1199 vie_encoder_->SetSource( | 1204 video_stream_encoder_->SetSource( |
1200 &new_video_source, | 1205 &new_video_source, |
1201 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1206 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1202 | 1207 |
1203 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1208 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1204 WaitForEncodedFrame(4); | 1209 WaitForEncodedFrame(4); |
1205 stats = stats_proxy_->GetStats(); | 1210 stats = stats_proxy_->GetStats(); |
1206 EXPECT_FALSE(stats.bw_limited_resolution); | 1211 EXPECT_FALSE(stats.bw_limited_resolution); |
1207 EXPECT_FALSE(stats.cpu_limited_resolution); | 1212 EXPECT_FALSE(stats.cpu_limited_resolution); |
1208 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1213 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1209 | 1214 |
1210 // Set adaptation back to enabled. | 1215 // Set adaptation back to enabled. |
1211 vie_encoder_->SetSource( | 1216 video_stream_encoder_->SetSource( |
1212 &new_video_source, | 1217 &new_video_source, |
1213 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1218 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1214 | 1219 |
1215 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1220 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1216 WaitForEncodedFrame(5); | 1221 WaitForEncodedFrame(5); |
1217 stats = stats_proxy_->GetStats(); | 1222 stats = stats_proxy_->GetStats(); |
1218 EXPECT_FALSE(stats.bw_limited_resolution); | 1223 EXPECT_FALSE(stats.bw_limited_resolution); |
1219 EXPECT_TRUE(stats.cpu_limited_resolution); | 1224 EXPECT_TRUE(stats.cpu_limited_resolution); |
1220 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1225 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1221 | 1226 |
1222 // Trigger CPU normal use. | 1227 // Trigger CPU normal use. |
1223 vie_encoder_->TriggerCpuNormalUsage(); | 1228 video_stream_encoder_->TriggerCpuNormalUsage(); |
1224 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); | 1229 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
1225 WaitForEncodedFrame(6); | 1230 WaitForEncodedFrame(6); |
1226 stats = stats_proxy_->GetStats(); | 1231 stats = stats_proxy_->GetStats(); |
1227 EXPECT_FALSE(stats.bw_limited_resolution); | 1232 EXPECT_FALSE(stats.bw_limited_resolution); |
1228 EXPECT_FALSE(stats.cpu_limited_resolution); | 1233 EXPECT_FALSE(stats.cpu_limited_resolution); |
1229 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1234 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1230 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1235 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1231 | 1236 |
1232 vie_encoder_->Stop(); | 1237 video_stream_encoder_->Stop(); |
1233 } | 1238 } |
1234 | 1239 |
1235 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { | 1240 TEST_F(VideoStreamEncoderTest, SwitchingSourceKeepsQualityAdaptation) { |
1236 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1241 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1237 | 1242 |
1238 const int kWidth = 1280; | 1243 const int kWidth = 1280; |
1239 const int kHeight = 720; | 1244 const int kHeight = 720; |
1240 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1245 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1241 WaitForEncodedFrame(1); | 1246 WaitForEncodedFrame(1); |
1242 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1247 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1243 EXPECT_FALSE(stats.bw_limited_resolution); | 1248 EXPECT_FALSE(stats.bw_limited_resolution); |
1244 EXPECT_FALSE(stats.bw_limited_framerate); | 1249 EXPECT_FALSE(stats.bw_limited_framerate); |
1245 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1250 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1246 | 1251 |
1247 // Set new source with adaptation still enabled. | 1252 // Set new source with adaptation still enabled. |
1248 test::FrameForwarder new_video_source; | 1253 test::FrameForwarder new_video_source; |
1249 vie_encoder_->SetSource(&new_video_source, | 1254 video_stream_encoder_->SetSource( |
1250 VideoSendStream::DegradationPreference::kBalanced); | 1255 &new_video_source, |
| 1256 VideoSendStream::DegradationPreference::kBalanced); |
1251 | 1257 |
1252 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1258 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1253 WaitForEncodedFrame(2); | 1259 WaitForEncodedFrame(2); |
1254 stats = stats_proxy_->GetStats(); | 1260 stats = stats_proxy_->GetStats(); |
1255 EXPECT_FALSE(stats.bw_limited_resolution); | 1261 EXPECT_FALSE(stats.bw_limited_resolution); |
1256 EXPECT_FALSE(stats.bw_limited_framerate); | 1262 EXPECT_FALSE(stats.bw_limited_framerate); |
1257 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1263 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1258 | 1264 |
1259 // Trigger adapt down. | 1265 // Trigger adapt down. |
1260 vie_encoder_->TriggerQualityLow(); | 1266 video_stream_encoder_->TriggerQualityLow(); |
1261 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1267 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1262 WaitForEncodedFrame(3); | 1268 WaitForEncodedFrame(3); |
1263 stats = stats_proxy_->GetStats(); | 1269 stats = stats_proxy_->GetStats(); |
1264 EXPECT_TRUE(stats.bw_limited_resolution); | 1270 EXPECT_TRUE(stats.bw_limited_resolution); |
1265 EXPECT_FALSE(stats.bw_limited_framerate); | 1271 EXPECT_FALSE(stats.bw_limited_framerate); |
1266 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1272 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1267 | 1273 |
1268 // Set new source with adaptation still enabled. | 1274 // Set new source with adaptation still enabled. |
1269 vie_encoder_->SetSource(&new_video_source, | 1275 video_stream_encoder_->SetSource( |
1270 VideoSendStream::DegradationPreference::kBalanced); | 1276 &new_video_source, |
| 1277 VideoSendStream::DegradationPreference::kBalanced); |
1271 | 1278 |
1272 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1279 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1273 WaitForEncodedFrame(4); | 1280 WaitForEncodedFrame(4); |
1274 stats = stats_proxy_->GetStats(); | 1281 stats = stats_proxy_->GetStats(); |
1275 EXPECT_TRUE(stats.bw_limited_resolution); | 1282 EXPECT_TRUE(stats.bw_limited_resolution); |
1276 EXPECT_FALSE(stats.bw_limited_framerate); | 1283 EXPECT_FALSE(stats.bw_limited_framerate); |
1277 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1284 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1278 | 1285 |
1279 // Disable resolution scaling. | 1286 // Disable resolution scaling. |
1280 vie_encoder_->SetSource( | 1287 video_stream_encoder_->SetSource( |
1281 &new_video_source, | 1288 &new_video_source, |
1282 VideoSendStream::DegradationPreference::kMaintainResolution); | 1289 VideoSendStream::DegradationPreference::kMaintainResolution); |
1283 | 1290 |
1284 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1291 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1285 WaitForEncodedFrame(5); | 1292 WaitForEncodedFrame(5); |
1286 stats = stats_proxy_->GetStats(); | 1293 stats = stats_proxy_->GetStats(); |
1287 EXPECT_FALSE(stats.bw_limited_resolution); | 1294 EXPECT_FALSE(stats.bw_limited_resolution); |
1288 EXPECT_FALSE(stats.bw_limited_framerate); | 1295 EXPECT_FALSE(stats.bw_limited_framerate); |
1289 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1296 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1290 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1297 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1291 | 1298 |
1292 vie_encoder_->Stop(); | 1299 video_stream_encoder_->Stop(); |
1293 } | 1300 } |
1294 | 1301 |
1295 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { | 1302 TEST_F(VideoStreamEncoderTest, |
1296 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1303 QualityAdaptationStatsAreResetWhenScalerIsDisabled) { |
| 1304 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1297 | 1305 |
1298 const int kWidth = 1280; | 1306 const int kWidth = 1280; |
1299 const int kHeight = 720; | 1307 const int kHeight = 720; |
1300 video_source_.set_adaptation_enabled(true); | 1308 video_source_.set_adaptation_enabled(true); |
1301 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1309 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1302 WaitForEncodedFrame(1); | 1310 WaitForEncodedFrame(1); |
1303 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1311 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1304 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1312 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1305 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1313 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1306 | 1314 |
1307 // Trigger adapt down. | 1315 // Trigger adapt down. |
1308 vie_encoder_->TriggerQualityLow(); | 1316 video_stream_encoder_->TriggerQualityLow(); |
1309 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1317 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1310 WaitForEncodedFrame(2); | 1318 WaitForEncodedFrame(2); |
1311 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1319 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1312 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1320 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1313 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1321 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1314 | 1322 |
1315 // Trigger overuse. | 1323 // Trigger overuse. |
1316 vie_encoder_->TriggerCpuOveruse(); | 1324 video_stream_encoder_->TriggerCpuOveruse(); |
1317 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1325 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1318 WaitForEncodedFrame(3); | 1326 WaitForEncodedFrame(3); |
1319 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1327 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1320 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1328 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1321 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1329 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1322 | 1330 |
1323 // Set source with adaptation still enabled but quality scaler is off. | 1331 // Set source with adaptation still enabled but quality scaler is off. |
1324 fake_encoder_.SetQualityScaling(false); | 1332 fake_encoder_.SetQualityScaling(false); |
1325 vie_encoder_->SetSource( | 1333 video_stream_encoder_->SetSource( |
1326 &video_source_, | 1334 &video_source_, |
1327 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1335 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1328 | 1336 |
1329 video_source_.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1337 video_source_.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1330 WaitForEncodedFrame(4); | 1338 WaitForEncodedFrame(4); |
1331 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1339 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1332 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1340 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1333 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1341 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1334 | 1342 |
1335 vie_encoder_->Stop(); | 1343 video_stream_encoder_->Stop(); |
1336 } | 1344 } |
1337 | 1345 |
1338 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStatsWhenSwitchingSource) { | 1346 TEST_F(VideoStreamEncoderTest, |
1339 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1347 StatsTracksCpuAdaptationStatsWhenSwitchingSource) { |
| 1348 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1340 | 1349 |
1341 const int kWidth = 1280; | 1350 const int kWidth = 1280; |
1342 const int kHeight = 720; | 1351 const int kHeight = 720; |
1343 int sequence = 1; | 1352 int sequence = 1; |
1344 | 1353 |
1345 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1354 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1346 WaitForEncodedFrame(sequence++); | 1355 WaitForEncodedFrame(sequence++); |
1347 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1356 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1348 EXPECT_FALSE(stats.cpu_limited_resolution); | 1357 EXPECT_FALSE(stats.cpu_limited_resolution); |
1349 EXPECT_FALSE(stats.cpu_limited_framerate); | 1358 EXPECT_FALSE(stats.cpu_limited_framerate); |
1350 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1359 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1351 | 1360 |
1352 // Trigger CPU overuse, should now adapt down. | 1361 // Trigger CPU overuse, should now adapt down. |
1353 vie_encoder_->TriggerCpuOveruse(); | 1362 video_stream_encoder_->TriggerCpuOveruse(); |
1354 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1363 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1355 WaitForEncodedFrame(sequence++); | 1364 WaitForEncodedFrame(sequence++); |
1356 stats = stats_proxy_->GetStats(); | 1365 stats = stats_proxy_->GetStats(); |
1357 EXPECT_TRUE(stats.cpu_limited_resolution); | 1366 EXPECT_TRUE(stats.cpu_limited_resolution); |
1358 EXPECT_FALSE(stats.cpu_limited_framerate); | 1367 EXPECT_FALSE(stats.cpu_limited_framerate); |
1359 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1368 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1360 | 1369 |
1361 // Set new source with adaptation still enabled. | 1370 // Set new source with adaptation still enabled. |
1362 test::FrameForwarder new_video_source; | 1371 test::FrameForwarder new_video_source; |
1363 vie_encoder_->SetSource( | 1372 video_stream_encoder_->SetSource( |
1364 &new_video_source, | 1373 &new_video_source, |
1365 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1374 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1366 | 1375 |
1367 new_video_source.IncomingCapturedFrame( | 1376 new_video_source.IncomingCapturedFrame( |
1368 CreateFrame(sequence, kWidth, kHeight)); | 1377 CreateFrame(sequence, kWidth, kHeight)); |
1369 WaitForEncodedFrame(sequence++); | 1378 WaitForEncodedFrame(sequence++); |
1370 stats = stats_proxy_->GetStats(); | 1379 stats = stats_proxy_->GetStats(); |
1371 EXPECT_TRUE(stats.cpu_limited_resolution); | 1380 EXPECT_TRUE(stats.cpu_limited_resolution); |
1372 EXPECT_FALSE(stats.cpu_limited_framerate); | 1381 EXPECT_FALSE(stats.cpu_limited_framerate); |
1373 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1382 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1374 | 1383 |
1375 // Set cpu adaptation by frame dropping. | 1384 // Set cpu adaptation by frame dropping. |
1376 vie_encoder_->SetSource( | 1385 video_stream_encoder_->SetSource( |
1377 &new_video_source, | 1386 &new_video_source, |
1378 VideoSendStream::DegradationPreference::kMaintainResolution); | 1387 VideoSendStream::DegradationPreference::kMaintainResolution); |
1379 new_video_source.IncomingCapturedFrame( | 1388 new_video_source.IncomingCapturedFrame( |
1380 CreateFrame(sequence, kWidth, kHeight)); | 1389 CreateFrame(sequence, kWidth, kHeight)); |
1381 WaitForEncodedFrame(sequence++); | 1390 WaitForEncodedFrame(sequence++); |
1382 stats = stats_proxy_->GetStats(); | 1391 stats = stats_proxy_->GetStats(); |
1383 // Not adapted at first. | 1392 // Not adapted at first. |
1384 EXPECT_FALSE(stats.cpu_limited_resolution); | 1393 EXPECT_FALSE(stats.cpu_limited_resolution); |
1385 EXPECT_FALSE(stats.cpu_limited_framerate); | 1394 EXPECT_FALSE(stats.cpu_limited_framerate); |
1386 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1395 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1387 | 1396 |
1388 // Force an input frame rate to be available, or the adaptation call won't | 1397 // Force an input frame rate to be available, or the adaptation call won't |
1389 // know what framerate to adapt from. | 1398 // know what framerate to adapt from. |
1390 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); | 1399 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); |
1391 mock_stats.input_frame_rate = 30; | 1400 mock_stats.input_frame_rate = 30; |
1392 stats_proxy_->SetMockStats(mock_stats); | 1401 stats_proxy_->SetMockStats(mock_stats); |
1393 vie_encoder_->TriggerCpuOveruse(); | 1402 video_stream_encoder_->TriggerCpuOveruse(); |
1394 stats_proxy_->ResetMockStats(); | 1403 stats_proxy_->ResetMockStats(); |
1395 | 1404 |
1396 new_video_source.IncomingCapturedFrame( | 1405 new_video_source.IncomingCapturedFrame( |
1397 CreateFrame(sequence, kWidth, kHeight)); | 1406 CreateFrame(sequence, kWidth, kHeight)); |
1398 WaitForEncodedFrame(sequence++); | 1407 WaitForEncodedFrame(sequence++); |
1399 | 1408 |
1400 // Framerate now adapted. | 1409 // Framerate now adapted. |
1401 stats = stats_proxy_->GetStats(); | 1410 stats = stats_proxy_->GetStats(); |
1402 EXPECT_FALSE(stats.cpu_limited_resolution); | 1411 EXPECT_FALSE(stats.cpu_limited_resolution); |
1403 EXPECT_TRUE(stats.cpu_limited_framerate); | 1412 EXPECT_TRUE(stats.cpu_limited_framerate); |
1404 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1413 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1405 | 1414 |
1406 // Disable CPU adaptation. | 1415 // Disable CPU adaptation. |
1407 vie_encoder_->SetSource( | 1416 video_stream_encoder_->SetSource( |
1408 &new_video_source, | 1417 &new_video_source, |
1409 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1418 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1410 new_video_source.IncomingCapturedFrame( | 1419 new_video_source.IncomingCapturedFrame( |
1411 CreateFrame(sequence, kWidth, kHeight)); | 1420 CreateFrame(sequence, kWidth, kHeight)); |
1412 WaitForEncodedFrame(sequence++); | 1421 WaitForEncodedFrame(sequence++); |
1413 | 1422 |
1414 stats = stats_proxy_->GetStats(); | 1423 stats = stats_proxy_->GetStats(); |
1415 EXPECT_FALSE(stats.cpu_limited_resolution); | 1424 EXPECT_FALSE(stats.cpu_limited_resolution); |
1416 EXPECT_FALSE(stats.cpu_limited_framerate); | 1425 EXPECT_FALSE(stats.cpu_limited_framerate); |
1417 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1426 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1418 | 1427 |
1419 // Try to trigger overuse. Should not succeed. | 1428 // Try to trigger overuse. Should not succeed. |
1420 stats_proxy_->SetMockStats(mock_stats); | 1429 stats_proxy_->SetMockStats(mock_stats); |
1421 vie_encoder_->TriggerCpuOveruse(); | 1430 video_stream_encoder_->TriggerCpuOveruse(); |
1422 stats_proxy_->ResetMockStats(); | 1431 stats_proxy_->ResetMockStats(); |
1423 | 1432 |
1424 stats = stats_proxy_->GetStats(); | 1433 stats = stats_proxy_->GetStats(); |
1425 EXPECT_FALSE(stats.cpu_limited_resolution); | 1434 EXPECT_FALSE(stats.cpu_limited_resolution); |
1426 EXPECT_FALSE(stats.cpu_limited_framerate); | 1435 EXPECT_FALSE(stats.cpu_limited_framerate); |
1427 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1436 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1428 | 1437 |
1429 // Switch back the source with resolution adaptation enabled. | 1438 // Switch back the source with resolution adaptation enabled. |
1430 vie_encoder_->SetSource( | 1439 video_stream_encoder_->SetSource( |
1431 &video_source_, | 1440 &video_source_, |
1432 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1441 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1433 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1442 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1434 WaitForEncodedFrame(sequence++); | 1443 WaitForEncodedFrame(sequence++); |
1435 stats = stats_proxy_->GetStats(); | 1444 stats = stats_proxy_->GetStats(); |
1436 EXPECT_TRUE(stats.cpu_limited_resolution); | 1445 EXPECT_TRUE(stats.cpu_limited_resolution); |
1437 EXPECT_FALSE(stats.cpu_limited_framerate); | 1446 EXPECT_FALSE(stats.cpu_limited_framerate); |
1438 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1447 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1439 | 1448 |
1440 // Trigger CPU normal usage. | 1449 // Trigger CPU normal usage. |
1441 vie_encoder_->TriggerCpuNormalUsage(); | 1450 video_stream_encoder_->TriggerCpuNormalUsage(); |
1442 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1451 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1443 WaitForEncodedFrame(sequence++); | 1452 WaitForEncodedFrame(sequence++); |
1444 stats = stats_proxy_->GetStats(); | 1453 stats = stats_proxy_->GetStats(); |
1445 EXPECT_FALSE(stats.cpu_limited_resolution); | 1454 EXPECT_FALSE(stats.cpu_limited_resolution); |
1446 EXPECT_FALSE(stats.cpu_limited_framerate); | 1455 EXPECT_FALSE(stats.cpu_limited_framerate); |
1447 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1456 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1448 | 1457 |
1449 // Back to the source with adaptation off, set it back to maintain-resolution. | 1458 // Back to the source with adaptation off, set it back to maintain-resolution. |
1450 vie_encoder_->SetSource( | 1459 video_stream_encoder_->SetSource( |
1451 &new_video_source, | 1460 &new_video_source, |
1452 VideoSendStream::DegradationPreference::kMaintainResolution); | 1461 VideoSendStream::DegradationPreference::kMaintainResolution); |
1453 new_video_source.IncomingCapturedFrame( | 1462 new_video_source.IncomingCapturedFrame( |
1454 CreateFrame(sequence, kWidth, kHeight)); | 1463 CreateFrame(sequence, kWidth, kHeight)); |
1455 WaitForEncodedFrame(sequence++); | 1464 WaitForEncodedFrame(sequence++); |
1456 stats = stats_proxy_->GetStats(); | 1465 stats = stats_proxy_->GetStats(); |
1457 // Disabled, since we previously switched the source to disabled. | 1466 // Disabled, since we previously switched the source to disabled. |
1458 EXPECT_FALSE(stats.cpu_limited_resolution); | 1467 EXPECT_FALSE(stats.cpu_limited_resolution); |
1459 EXPECT_TRUE(stats.cpu_limited_framerate); | 1468 EXPECT_TRUE(stats.cpu_limited_framerate); |
1460 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1469 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1461 | 1470 |
1462 // Trigger CPU normal usage. | 1471 // Trigger CPU normal usage. |
1463 vie_encoder_->TriggerCpuNormalUsage(); | 1472 video_stream_encoder_->TriggerCpuNormalUsage(); |
1464 new_video_source.IncomingCapturedFrame( | 1473 new_video_source.IncomingCapturedFrame( |
1465 CreateFrame(sequence, kWidth, kHeight)); | 1474 CreateFrame(sequence, kWidth, kHeight)); |
1466 WaitForEncodedFrame(sequence++); | 1475 WaitForEncodedFrame(sequence++); |
1467 stats = stats_proxy_->GetStats(); | 1476 stats = stats_proxy_->GetStats(); |
1468 EXPECT_FALSE(stats.cpu_limited_resolution); | 1477 EXPECT_FALSE(stats.cpu_limited_resolution); |
1469 EXPECT_FALSE(stats.cpu_limited_framerate); | 1478 EXPECT_FALSE(stats.cpu_limited_framerate); |
1470 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); | 1479 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); |
1471 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1480 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1472 | 1481 |
1473 vie_encoder_->Stop(); | 1482 video_stream_encoder_->Stop(); |
1474 } | 1483 } |
1475 | 1484 |
1476 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { | 1485 TEST_F(VideoStreamEncoderTest, StatsTracksPreferredBitrate) { |
1477 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1486 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1478 | 1487 |
1479 const int kWidth = 1280; | 1488 const int kWidth = 1280; |
1480 const int kHeight = 720; | 1489 const int kHeight = 720; |
1481 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1490 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1482 WaitForEncodedFrame(1); | 1491 WaitForEncodedFrame(1); |
1483 | 1492 |
1484 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1493 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1485 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, | 1494 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, |
1486 stats.preferred_media_bitrate_bps); | 1495 stats.preferred_media_bitrate_bps); |
1487 | 1496 |
1488 vie_encoder_->Stop(); | 1497 video_stream_encoder_->Stop(); |
1489 } | 1498 } |
1490 | 1499 |
1491 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 1500 TEST_F(VideoStreamEncoderTest, |
| 1501 ScalingUpAndDownDoesNothingWithMaintainResolution) { |
1492 const int kWidth = 1280; | 1502 const int kWidth = 1280; |
1493 const int kHeight = 720; | 1503 const int kHeight = 720; |
1494 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1504 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1495 | 1505 |
1496 // Expect no scaling to begin with. | 1506 // Expect no scaling to begin with. |
1497 VerifyNoLimitation(video_source_.sink_wants()); | 1507 VerifyNoLimitation(video_source_.sink_wants()); |
1498 | 1508 |
1499 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1509 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1500 WaitForEncodedFrame(1); | 1510 WaitForEncodedFrame(1); |
1501 | 1511 |
1502 // Trigger scale down. | 1512 // Trigger scale down. |
1503 vie_encoder_->TriggerQualityLow(); | 1513 video_stream_encoder_->TriggerQualityLow(); |
1504 | 1514 |
1505 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1515 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1506 WaitForEncodedFrame(2); | 1516 WaitForEncodedFrame(2); |
1507 | 1517 |
1508 // Expect a scale down. | 1518 // Expect a scale down. |
1509 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 1519 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
1510 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 1520 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
1511 | 1521 |
1512 // Set resolution scaling disabled. | 1522 // Set resolution scaling disabled. |
1513 test::FrameForwarder new_video_source; | 1523 test::FrameForwarder new_video_source; |
1514 vie_encoder_->SetSource( | 1524 video_stream_encoder_->SetSource( |
1515 &new_video_source, | 1525 &new_video_source, |
1516 VideoSendStream::DegradationPreference::kMaintainResolution); | 1526 VideoSendStream::DegradationPreference::kMaintainResolution); |
1517 | 1527 |
1518 // Trigger scale down. | 1528 // Trigger scale down. |
1519 vie_encoder_->TriggerQualityLow(); | 1529 video_stream_encoder_->TriggerQualityLow(); |
1520 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1530 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1521 WaitForEncodedFrame(3); | 1531 WaitForEncodedFrame(3); |
1522 | 1532 |
1523 // Expect no scaling. | 1533 // Expect no scaling. |
1524 EXPECT_EQ(std::numeric_limits<int>::max(), | 1534 EXPECT_EQ(std::numeric_limits<int>::max(), |
1525 new_video_source.sink_wants().max_pixel_count); | 1535 new_video_source.sink_wants().max_pixel_count); |
1526 | 1536 |
1527 // Trigger scale up. | 1537 // Trigger scale up. |
1528 vie_encoder_->TriggerQualityHigh(); | 1538 video_stream_encoder_->TriggerQualityHigh(); |
1529 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1539 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1530 WaitForEncodedFrame(4); | 1540 WaitForEncodedFrame(4); |
1531 | 1541 |
1532 // Expect nothing to change, still no scaling. | 1542 // Expect nothing to change, still no scaling. |
1533 EXPECT_EQ(std::numeric_limits<int>::max(), | 1543 EXPECT_EQ(std::numeric_limits<int>::max(), |
1534 new_video_source.sink_wants().max_pixel_count); | 1544 new_video_source.sink_wants().max_pixel_count); |
1535 | 1545 |
1536 vie_encoder_->Stop(); | 1546 video_stream_encoder_->Stop(); |
1537 } | 1547 } |
1538 | 1548 |
1539 TEST_F(ViEEncoderTest, SkipsSameAdaptDownRequest_MaintainFramerateMode) { | 1549 TEST_F(VideoStreamEncoderTest, |
| 1550 SkipsSameAdaptDownRequest_MaintainFramerateMode) { |
1540 const int kWidth = 1280; | 1551 const int kWidth = 1280; |
1541 const int kHeight = 720; | 1552 const int kHeight = 720; |
1542 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1553 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1543 | 1554 |
1544 // Enable kMaintainFramerate preference, no initial limitation. | 1555 // Enable kMaintainFramerate preference, no initial limitation. |
1545 test::FrameForwarder source; | 1556 test::FrameForwarder source; |
1546 vie_encoder_->SetSource( | 1557 video_stream_encoder_->SetSource( |
1547 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1558 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1548 | 1559 |
1549 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1560 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1550 WaitForEncodedFrame(1); | 1561 WaitForEncodedFrame(1); |
1551 VerifyNoLimitation(source.sink_wants()); | 1562 VerifyNoLimitation(source.sink_wants()); |
1552 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1563 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1553 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1564 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1554 | 1565 |
1555 // Trigger adapt down, expect scaled down resolution. | 1566 // Trigger adapt down, expect scaled down resolution. |
1556 vie_encoder_->TriggerCpuOveruse(); | 1567 video_stream_encoder_->TriggerCpuOveruse(); |
1557 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1568 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1558 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; | 1569 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; |
1559 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1570 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1560 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1571 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1561 | 1572 |
1562 // Trigger adapt down for same input resolution, expect no change. | 1573 // Trigger adapt down for same input resolution, expect no change. |
1563 vie_encoder_->TriggerCpuOveruse(); | 1574 video_stream_encoder_->TriggerCpuOveruse(); |
1564 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); | 1575 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); |
1565 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1576 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1566 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1577 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1567 | 1578 |
1568 vie_encoder_->Stop(); | 1579 video_stream_encoder_->Stop(); |
1569 } | 1580 } |
1570 | 1581 |
1571 TEST_F(ViEEncoderTest, SkipsSameOrLargerAdaptDownRequest_BalancedMode) { | 1582 TEST_F(VideoStreamEncoderTest, SkipsSameOrLargerAdaptDownRequest_BalancedMode) { |
1572 const int kWidth = 1280; | 1583 const int kWidth = 1280; |
1573 const int kHeight = 720; | 1584 const int kHeight = 720; |
1574 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1585 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1575 | 1586 |
1576 // Enable kBalanced preference, no initial limitation. | 1587 // Enable kBalanced preference, no initial limitation. |
1577 test::FrameForwarder source; | 1588 test::FrameForwarder source; |
1578 vie_encoder_->SetSource(&source, | 1589 video_stream_encoder_->SetSource( |
1579 VideoSendStream::DegradationPreference::kBalanced); | 1590 &source, |
| 1591 VideoSendStream::DegradationPreference::kBalanced); |
1580 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1592 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1581 sink_.WaitForEncodedFrame(1); | 1593 sink_.WaitForEncodedFrame(1); |
1582 VerifyNoLimitation(source.sink_wants()); | 1594 VerifyNoLimitation(source.sink_wants()); |
1583 | 1595 |
1584 // Trigger adapt down, expect scaled down resolution. | 1596 // Trigger adapt down, expect scaled down resolution. |
1585 vie_encoder_->TriggerQualityLow(); | 1597 video_stream_encoder_->TriggerQualityLow(); |
1586 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1598 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1587 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1599 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1588 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1600 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1589 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; | 1601 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; |
1590 | 1602 |
1591 // Trigger adapt down for same input resolution, expect no change. | 1603 // Trigger adapt down for same input resolution, expect no change. |
1592 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1604 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1593 sink_.WaitForEncodedFrame(2); | 1605 sink_.WaitForEncodedFrame(2); |
1594 vie_encoder_->TriggerQualityLow(); | 1606 video_stream_encoder_->TriggerQualityLow(); |
1595 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); | 1607 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); |
1596 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1608 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1597 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1609 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1598 | 1610 |
1599 // Trigger adapt down for larger input resolution, expect no change. | 1611 // Trigger adapt down for larger input resolution, expect no change. |
1600 source.IncomingCapturedFrame(CreateFrame(3, kWidth + 1, kHeight + 1)); | 1612 source.IncomingCapturedFrame(CreateFrame(3, kWidth + 1, kHeight + 1)); |
1601 sink_.WaitForEncodedFrame(3); | 1613 sink_.WaitForEncodedFrame(3); |
1602 vie_encoder_->TriggerQualityLow(); | 1614 video_stream_encoder_->TriggerQualityLow(); |
1603 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); | 1615 EXPECT_EQ(kLastMaxPixelCount, source.sink_wants().max_pixel_count); |
1604 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1616 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1605 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1617 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1606 | 1618 |
1607 vie_encoder_->Stop(); | 1619 video_stream_encoder_->Stop(); |
1608 } | 1620 } |
1609 | 1621 |
1610 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainFramerateMode) { | 1622 TEST_F(VideoStreamEncoderTest, |
| 1623 NoChangeForInitialNormalUsage_MaintainFramerateMode) { |
1611 const int kWidth = 1280; | 1624 const int kWidth = 1280; |
1612 const int kHeight = 720; | 1625 const int kHeight = 720; |
1613 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1626 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1614 | 1627 |
1615 // Enable kMaintainFramerate preference, no initial limitation. | 1628 // Enable kMaintainFramerate preference, no initial limitation. |
1616 test::FrameForwarder source; | 1629 test::FrameForwarder source; |
1617 vie_encoder_->SetSource( | 1630 video_stream_encoder_->SetSource( |
1618 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1631 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1619 | 1632 |
1620 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1633 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1621 WaitForEncodedFrame(kWidth, kHeight); | 1634 WaitForEncodedFrame(kWidth, kHeight); |
1622 VerifyNoLimitation(source.sink_wants()); | 1635 VerifyNoLimitation(source.sink_wants()); |
1623 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1636 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1624 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1637 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1625 | 1638 |
1626 // Trigger adapt up, expect no change. | 1639 // Trigger adapt up, expect no change. |
1627 vie_encoder_->TriggerCpuNormalUsage(); | 1640 video_stream_encoder_->TriggerCpuNormalUsage(); |
1628 VerifyNoLimitation(source.sink_wants()); | 1641 VerifyNoLimitation(source.sink_wants()); |
1629 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1642 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1630 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1643 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1631 | 1644 |
1632 vie_encoder_->Stop(); | 1645 video_stream_encoder_->Stop(); |
1633 } | 1646 } |
1634 | 1647 |
1635 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainResolutionMode) { | 1648 TEST_F(VideoStreamEncoderTest, |
| 1649 NoChangeForInitialNormalUsage_MaintainResolutionMode) { |
1636 const int kWidth = 1280; | 1650 const int kWidth = 1280; |
1637 const int kHeight = 720; | 1651 const int kHeight = 720; |
1638 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1652 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1639 | 1653 |
1640 // Enable kMaintainResolution preference, no initial limitation. | 1654 // Enable kMaintainResolution preference, no initial limitation. |
1641 test::FrameForwarder source; | 1655 test::FrameForwarder source; |
1642 vie_encoder_->SetSource( | 1656 video_stream_encoder_->SetSource( |
1643 &source, VideoSendStream::DegradationPreference::kMaintainResolution); | 1657 &source, VideoSendStream::DegradationPreference::kMaintainResolution); |
1644 | 1658 |
1645 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1659 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1646 WaitForEncodedFrame(kWidth, kHeight); | 1660 WaitForEncodedFrame(kWidth, kHeight); |
1647 VerifyNoLimitation(source.sink_wants()); | 1661 VerifyNoLimitation(source.sink_wants()); |
1648 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1662 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1649 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1663 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1650 | 1664 |
1651 // Trigger adapt up, expect no change. | 1665 // Trigger adapt up, expect no change. |
1652 vie_encoder_->TriggerCpuNormalUsage(); | 1666 video_stream_encoder_->TriggerCpuNormalUsage(); |
1653 VerifyNoLimitation(source.sink_wants()); | 1667 VerifyNoLimitation(source.sink_wants()); |
1654 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1668 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1655 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1669 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1656 | 1670 |
1657 vie_encoder_->Stop(); | 1671 video_stream_encoder_->Stop(); |
1658 } | 1672 } |
1659 | 1673 |
1660 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_BalancedMode) { | 1674 TEST_F(VideoStreamEncoderTest, NoChangeForInitialNormalUsage_BalancedMode) { |
1661 const int kWidth = 1280; | 1675 const int kWidth = 1280; |
1662 const int kHeight = 720; | 1676 const int kHeight = 720; |
1663 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1677 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1664 | 1678 |
1665 // Enable kBalanced preference, no initial limitation. | 1679 // Enable kBalanced preference, no initial limitation. |
1666 test::FrameForwarder source; | 1680 test::FrameForwarder source; |
1667 vie_encoder_->SetSource(&source, | 1681 video_stream_encoder_->SetSource( |
1668 VideoSendStream::DegradationPreference::kBalanced); | 1682 &source, |
| 1683 VideoSendStream::DegradationPreference::kBalanced); |
1669 | 1684 |
1670 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1685 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1671 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1686 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1672 VerifyNoLimitation(source.sink_wants()); | 1687 VerifyNoLimitation(source.sink_wants()); |
1673 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1688 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1674 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1689 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1675 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1690 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1676 | 1691 |
1677 // Trigger adapt up, expect no change. | 1692 // Trigger adapt up, expect no change. |
1678 vie_encoder_->TriggerQualityHigh(); | 1693 video_stream_encoder_->TriggerQualityHigh(); |
1679 VerifyNoLimitation(source.sink_wants()); | 1694 VerifyNoLimitation(source.sink_wants()); |
1680 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1695 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1681 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1696 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1682 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1697 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1683 | 1698 |
1684 vie_encoder_->Stop(); | 1699 video_stream_encoder_->Stop(); |
1685 } | 1700 } |
1686 | 1701 |
1687 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_DisabledMode) { | 1702 TEST_F(VideoStreamEncoderTest, NoChangeForInitialNormalUsage_DisabledMode) { |
1688 const int kWidth = 1280; | 1703 const int kWidth = 1280; |
1689 const int kHeight = 720; | 1704 const int kHeight = 720; |
1690 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1705 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1691 | 1706 |
1692 // Enable kDegradationDisabled preference, no initial limitation. | 1707 // Enable kDegradationDisabled preference, no initial limitation. |
1693 test::FrameForwarder source; | 1708 test::FrameForwarder source; |
1694 vie_encoder_->SetSource( | 1709 video_stream_encoder_->SetSource( |
1695 &source, VideoSendStream::DegradationPreference::kDegradationDisabled); | 1710 &source, VideoSendStream::DegradationPreference::kDegradationDisabled); |
1696 | 1711 |
1697 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1712 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1698 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1713 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1699 VerifyNoLimitation(source.sink_wants()); | 1714 VerifyNoLimitation(source.sink_wants()); |
1700 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1715 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1701 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1716 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1702 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1717 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1703 | 1718 |
1704 // Trigger adapt up, expect no change. | 1719 // Trigger adapt up, expect no change. |
1705 vie_encoder_->TriggerQualityHigh(); | 1720 video_stream_encoder_->TriggerQualityHigh(); |
1706 VerifyNoLimitation(source.sink_wants()); | 1721 VerifyNoLimitation(source.sink_wants()); |
1707 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1722 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1708 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1723 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1709 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1724 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1710 | 1725 |
1711 vie_encoder_->Stop(); | 1726 video_stream_encoder_->Stop(); |
1712 } | 1727 } |
1713 | 1728 |
1714 TEST_F(ViEEncoderTest, AdaptsResolutionForLowQuality_MaintainFramerateMode) { | 1729 TEST_F(VideoStreamEncoderTest, |
| 1730 AdaptsResolutionForLowQuality_MaintainFramerateMode) { |
1715 const int kWidth = 1280; | 1731 const int kWidth = 1280; |
1716 const int kHeight = 720; | 1732 const int kHeight = 720; |
1717 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1733 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1718 | 1734 |
1719 // Enable kMaintainFramerate preference, no initial limitation. | 1735 // Enable kMaintainFramerate preference, no initial limitation. |
1720 AdaptingFrameForwarder source; | 1736 AdaptingFrameForwarder source; |
1721 source.set_adaptation_enabled(true); | 1737 source.set_adaptation_enabled(true); |
1722 vie_encoder_->SetSource( | 1738 video_stream_encoder_->SetSource( |
1723 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1739 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1724 | 1740 |
1725 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1741 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1726 WaitForEncodedFrame(1); | 1742 WaitForEncodedFrame(1); |
1727 VerifyNoLimitation(source.sink_wants()); | 1743 VerifyNoLimitation(source.sink_wants()); |
1728 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1744 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1729 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1745 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1730 | 1746 |
1731 // Trigger adapt down, expect scaled down resolution. | 1747 // Trigger adapt down, expect scaled down resolution. |
1732 vie_encoder_->TriggerQualityLow(); | 1748 video_stream_encoder_->TriggerQualityLow(); |
1733 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1749 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1734 WaitForEncodedFrame(2); | 1750 WaitForEncodedFrame(2); |
1735 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1751 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1736 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1752 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1737 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1753 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1738 | 1754 |
1739 // Trigger adapt up, expect no restriction. | 1755 // Trigger adapt up, expect no restriction. |
1740 vie_encoder_->TriggerQualityHigh(); | 1756 video_stream_encoder_->TriggerQualityHigh(); |
1741 VerifyNoLimitation(source.sink_wants()); | 1757 VerifyNoLimitation(source.sink_wants()); |
1742 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1758 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1743 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1759 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1744 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1760 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1745 | 1761 |
1746 vie_encoder_->Stop(); | 1762 video_stream_encoder_->Stop(); |
1747 } | 1763 } |
1748 | 1764 |
1749 TEST_F(ViEEncoderTest, AdaptsFramerateForLowQuality_MaintainResolutionMode) { | 1765 TEST_F(VideoStreamEncoderTest, |
| 1766 AdaptsFramerateForLowQuality_MaintainResolutionMode) { |
1750 const int kWidth = 1280; | 1767 const int kWidth = 1280; |
1751 const int kHeight = 720; | 1768 const int kHeight = 720; |
1752 const int kInputFps = 30; | 1769 const int kInputFps = 30; |
1753 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1770 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1754 | 1771 |
1755 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1772 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1756 stats.input_frame_rate = kInputFps; | 1773 stats.input_frame_rate = kInputFps; |
1757 stats_proxy_->SetMockStats(stats); | 1774 stats_proxy_->SetMockStats(stats); |
1758 | 1775 |
1759 // Expect no scaling to begin with (preference: kMaintainFramerate). | 1776 // Expect no scaling to begin with (preference: kMaintainFramerate). |
1760 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1777 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1761 sink_.WaitForEncodedFrame(1); | 1778 sink_.WaitForEncodedFrame(1); |
1762 VerifyNoLimitation(video_source_.sink_wants()); | 1779 VerifyNoLimitation(video_source_.sink_wants()); |
1763 | 1780 |
1764 // Trigger adapt down, expect scaled down resolution. | 1781 // Trigger adapt down, expect scaled down resolution. |
1765 vie_encoder_->TriggerQualityLow(); | 1782 video_stream_encoder_->TriggerQualityLow(); |
1766 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1783 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1767 sink_.WaitForEncodedFrame(2); | 1784 sink_.WaitForEncodedFrame(2); |
1768 VerifyFpsMaxResolutionLt(video_source_.sink_wants(), kWidth * kHeight); | 1785 VerifyFpsMaxResolutionLt(video_source_.sink_wants(), kWidth * kHeight); |
1769 | 1786 |
1770 // Enable kMaintainResolution preference. | 1787 // Enable kMaintainResolution preference. |
1771 test::FrameForwarder new_video_source; | 1788 test::FrameForwarder new_video_source; |
1772 vie_encoder_->SetSource( | 1789 video_stream_encoder_->SetSource( |
1773 &new_video_source, | 1790 &new_video_source, |
1774 VideoSendStream::DegradationPreference::kMaintainResolution); | 1791 VideoSendStream::DegradationPreference::kMaintainResolution); |
1775 VerifyNoLimitation(new_video_source.sink_wants()); | 1792 VerifyNoLimitation(new_video_source.sink_wants()); |
1776 | 1793 |
1777 // Trigger adapt down, expect reduced framerate. | 1794 // Trigger adapt down, expect reduced framerate. |
1778 vie_encoder_->TriggerQualityLow(); | 1795 video_stream_encoder_->TriggerQualityLow(); |
1779 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1796 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1780 sink_.WaitForEncodedFrame(3); | 1797 sink_.WaitForEncodedFrame(3); |
1781 VerifyFpsLtResolutionMax(new_video_source.sink_wants(), kInputFps); | 1798 VerifyFpsLtResolutionMax(new_video_source.sink_wants(), kInputFps); |
1782 | 1799 |
1783 // Trigger adapt up, expect no restriction. | 1800 // Trigger adapt up, expect no restriction. |
1784 vie_encoder_->TriggerQualityHigh(); | 1801 video_stream_encoder_->TriggerQualityHigh(); |
1785 VerifyNoLimitation(new_video_source.sink_wants()); | 1802 VerifyNoLimitation(new_video_source.sink_wants()); |
1786 | 1803 |
1787 vie_encoder_->Stop(); | 1804 video_stream_encoder_->Stop(); |
1788 } | 1805 } |
1789 | 1806 |
1790 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetResolutionLimit) { | 1807 TEST_F(VideoStreamEncoderTest, DoesNotScaleBelowSetResolutionLimit) { |
1791 const int kWidth = 1280; | 1808 const int kWidth = 1280; |
1792 const int kHeight = 720; | 1809 const int kHeight = 720; |
1793 const size_t kNumFrames = 10; | 1810 const size_t kNumFrames = 10; |
1794 | 1811 |
1795 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1812 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1796 | 1813 |
1797 // Enable adapter, expected input resolutions when downscaling: | 1814 // Enable adapter, expected input resolutions when downscaling: |
1798 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) | 1815 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) |
1799 video_source_.set_adaptation_enabled(true); | 1816 video_source_.set_adaptation_enabled(true); |
1800 | 1817 |
1801 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1818 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1802 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1819 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1803 | 1820 |
1804 int downscales = 0; | 1821 int downscales = 0; |
1805 for (size_t i = 1; i <= kNumFrames; i++) { | 1822 for (size_t i = 1; i <= kNumFrames; i++) { |
1806 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1823 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1807 WaitForEncodedFrame(i); | 1824 WaitForEncodedFrame(i); |
1808 | 1825 |
1809 // Trigger scale down. | 1826 // Trigger scale down. |
1810 rtc::VideoSinkWants last_wants = video_source_.sink_wants(); | 1827 rtc::VideoSinkWants last_wants = video_source_.sink_wants(); |
1811 vie_encoder_->TriggerQualityLow(); | 1828 video_stream_encoder_->TriggerQualityLow(); |
1812 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); | 1829 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); |
1813 | 1830 |
1814 if (video_source_.sink_wants().max_pixel_count < last_wants.max_pixel_count) | 1831 if (video_source_.sink_wants().max_pixel_count < last_wants.max_pixel_count) |
1815 ++downscales; | 1832 ++downscales; |
1816 | 1833 |
1817 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1834 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1818 EXPECT_EQ(downscales, | 1835 EXPECT_EQ(downscales, |
1819 stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1836 stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1820 EXPECT_GT(downscales, 0); | 1837 EXPECT_GT(downscales, 0); |
1821 } | 1838 } |
1822 vie_encoder_->Stop(); | 1839 video_stream_encoder_->Stop(); |
1823 } | 1840 } |
1824 | 1841 |
1825 TEST_F(ViEEncoderTest, | 1842 TEST_F(VideoStreamEncoderTest, |
1826 AdaptsResolutionUpAndDownTwiceOnOveruse_MaintainFramerateMode) { | 1843 AdaptsResolutionUpAndDownTwiceOnOveruse_MaintainFramerateMode) { |
1827 const int kWidth = 1280; | 1844 const int kWidth = 1280; |
1828 const int kHeight = 720; | 1845 const int kHeight = 720; |
1829 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1846 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1830 | 1847 |
1831 // Enable kMaintainFramerate preference, no initial limitation. | 1848 // Enable kMaintainFramerate preference, no initial limitation. |
1832 AdaptingFrameForwarder source; | 1849 AdaptingFrameForwarder source; |
1833 source.set_adaptation_enabled(true); | 1850 source.set_adaptation_enabled(true); |
1834 vie_encoder_->SetSource( | 1851 video_stream_encoder_->SetSource( |
1835 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1852 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1836 | 1853 |
1837 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1854 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1838 WaitForEncodedFrame(kWidth, kHeight); | 1855 WaitForEncodedFrame(kWidth, kHeight); |
1839 VerifyNoLimitation(source.sink_wants()); | 1856 VerifyNoLimitation(source.sink_wants()); |
1840 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1857 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1841 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1858 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1842 | 1859 |
1843 // Trigger adapt down, expect scaled down resolution. | 1860 // Trigger adapt down, expect scaled down resolution. |
1844 vie_encoder_->TriggerCpuOveruse(); | 1861 video_stream_encoder_->TriggerCpuOveruse(); |
1845 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1862 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1846 WaitForEncodedFrame(2); | 1863 WaitForEncodedFrame(2); |
1847 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1864 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1848 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1865 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1849 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1866 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1850 | 1867 |
1851 // Trigger adapt up, expect no restriction. | 1868 // Trigger adapt up, expect no restriction. |
1852 vie_encoder_->TriggerCpuNormalUsage(); | 1869 video_stream_encoder_->TriggerCpuNormalUsage(); |
1853 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1870 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1854 WaitForEncodedFrame(kWidth, kHeight); | 1871 WaitForEncodedFrame(kWidth, kHeight); |
1855 VerifyNoLimitation(source.sink_wants()); | 1872 VerifyNoLimitation(source.sink_wants()); |
1856 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1873 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1857 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1874 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1858 | 1875 |
1859 // Trigger adapt down, expect scaled down resolution. | 1876 // Trigger adapt down, expect scaled down resolution. |
1860 vie_encoder_->TriggerCpuOveruse(); | 1877 video_stream_encoder_->TriggerCpuOveruse(); |
1861 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1878 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1862 WaitForEncodedFrame(4); | 1879 WaitForEncodedFrame(4); |
1863 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1880 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1864 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1881 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1865 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1882 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1866 | 1883 |
1867 // Trigger adapt up, expect no restriction. | 1884 // Trigger adapt up, expect no restriction. |
1868 vie_encoder_->TriggerCpuNormalUsage(); | 1885 video_stream_encoder_->TriggerCpuNormalUsage(); |
1869 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1886 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1870 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1887 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1871 VerifyNoLimitation(source.sink_wants()); | 1888 VerifyNoLimitation(source.sink_wants()); |
1872 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1889 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1873 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1890 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1874 | 1891 |
1875 vie_encoder_->Stop(); | 1892 video_stream_encoder_->Stop(); |
1876 } | 1893 } |
1877 | 1894 |
1878 TEST_F(ViEEncoderTest, | 1895 TEST_F(VideoStreamEncoderTest, |
1879 AdaptsResolutionUpAndDownTwiceForLowQuality_BalancedMode_NoFpsLimit) { | 1896 AdaptsResolutionUpAndDownTwiceForLowQuality_BalancedMode_NoFpsLimit) { |
1880 const int kWidth = 1280; | 1897 const int kWidth = 1280; |
1881 const int kHeight = 720; | 1898 const int kHeight = 720; |
1882 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1899 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1883 | 1900 |
1884 // Enable kBalanced preference, no initial limitation. | 1901 // Enable kBalanced preference, no initial limitation. |
1885 AdaptingFrameForwarder source; | 1902 AdaptingFrameForwarder source; |
1886 source.set_adaptation_enabled(true); | 1903 source.set_adaptation_enabled(true); |
1887 vie_encoder_->SetSource(&source, | 1904 video_stream_encoder_->SetSource( |
1888 VideoSendStream::DegradationPreference::kBalanced); | 1905 &source, |
| 1906 VideoSendStream::DegradationPreference::kBalanced); |
1889 | 1907 |
1890 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1908 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1891 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1909 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1892 VerifyNoLimitation(source.sink_wants()); | 1910 VerifyNoLimitation(source.sink_wants()); |
1893 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1911 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1894 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1912 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1895 | 1913 |
1896 // Trigger adapt down, expect scaled down resolution. | 1914 // Trigger adapt down, expect scaled down resolution. |
1897 vie_encoder_->TriggerQualityLow(); | 1915 video_stream_encoder_->TriggerQualityLow(); |
1898 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1916 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1899 sink_.WaitForEncodedFrame(2); | 1917 sink_.WaitForEncodedFrame(2); |
1900 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1918 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1901 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1919 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1902 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1920 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1903 | 1921 |
1904 // Trigger adapt up, expect no restriction. | 1922 // Trigger adapt up, expect no restriction. |
1905 vie_encoder_->TriggerQualityHigh(); | 1923 video_stream_encoder_->TriggerQualityHigh(); |
1906 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1924 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1907 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1925 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1908 VerifyNoLimitation(source.sink_wants()); | 1926 VerifyNoLimitation(source.sink_wants()); |
1909 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1927 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1910 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1928 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1911 | 1929 |
1912 // Trigger adapt down, expect scaled down resolution. | 1930 // Trigger adapt down, expect scaled down resolution. |
1913 vie_encoder_->TriggerQualityLow(); | 1931 video_stream_encoder_->TriggerQualityLow(); |
1914 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1932 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1915 sink_.WaitForEncodedFrame(4); | 1933 sink_.WaitForEncodedFrame(4); |
1916 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1934 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1917 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1935 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1918 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1936 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1919 | 1937 |
1920 // Trigger adapt up, expect no restriction. | 1938 // Trigger adapt up, expect no restriction. |
1921 vie_encoder_->TriggerQualityHigh(); | 1939 video_stream_encoder_->TriggerQualityHigh(); |
1922 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1940 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1923 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1941 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1924 VerifyNoLimitation(source.sink_wants()); | 1942 VerifyNoLimitation(source.sink_wants()); |
1925 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1943 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1926 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1944 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1927 | 1945 |
1928 vie_encoder_->Stop(); | 1946 video_stream_encoder_->Stop(); |
1929 } | 1947 } |
1930 | 1948 |
1931 TEST_F(ViEEncoderTest, | 1949 TEST_F(VideoStreamEncoderTest, |
1932 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { | 1950 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { |
1933 const int kWidth = 1280; | 1951 const int kWidth = 1280; |
1934 const int kHeight = 720; | 1952 const int kHeight = 720; |
1935 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1953 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1936 | 1954 |
1937 // Enable kMaintainFramerate preference, no initial limitation. | 1955 // Enable kMaintainFramerate preference, no initial limitation. |
1938 AdaptingFrameForwarder source; | 1956 AdaptingFrameForwarder source; |
1939 source.set_adaptation_enabled(true); | 1957 source.set_adaptation_enabled(true); |
1940 vie_encoder_->SetSource( | 1958 video_stream_encoder_->SetSource( |
1941 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1959 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1942 | 1960 |
1943 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1961 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1944 WaitForEncodedFrame(kWidth, kHeight); | 1962 WaitForEncodedFrame(kWidth, kHeight); |
1945 VerifyNoLimitation(source.sink_wants()); | 1963 VerifyNoLimitation(source.sink_wants()); |
1946 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1964 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1947 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1965 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1948 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1966 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1949 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1967 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1950 | 1968 |
1951 // Trigger cpu adapt down, expect scaled down resolution (960x540). | 1969 // Trigger cpu adapt down, expect scaled down resolution (960x540). |
1952 vie_encoder_->TriggerCpuOveruse(); | 1970 video_stream_encoder_->TriggerCpuOveruse(); |
1953 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1971 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1954 WaitForEncodedFrame(2); | 1972 WaitForEncodedFrame(2); |
1955 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1973 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1956 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1974 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1957 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1975 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1958 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1976 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1959 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1977 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1960 | 1978 |
1961 // Trigger cpu adapt down, expect scaled down resolution (640x360). | 1979 // Trigger cpu adapt down, expect scaled down resolution (640x360). |
1962 vie_encoder_->TriggerCpuOveruse(); | 1980 video_stream_encoder_->TriggerCpuOveruse(); |
1963 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1981 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1964 WaitForEncodedFrame(3); | 1982 WaitForEncodedFrame(3); |
1965 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 1983 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
1966 rtc::VideoSinkWants last_wants = source.sink_wants(); | 1984 rtc::VideoSinkWants last_wants = source.sink_wants(); |
1967 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1985 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1968 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1986 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1969 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1987 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1970 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1988 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1971 | 1989 |
1972 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. | 1990 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. |
1973 vie_encoder_->TriggerCpuOveruse(); | 1991 video_stream_encoder_->TriggerCpuOveruse(); |
1974 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1992 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1975 WaitForEncodedFrame(4); | 1993 WaitForEncodedFrame(4); |
1976 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 1994 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
1977 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1995 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1978 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1996 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1979 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1997 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1980 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1998 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1981 | 1999 |
1982 // Trigger quality adapt down, expect scaled down resolution (480x270). | 2000 // Trigger quality adapt down, expect scaled down resolution (480x270). |
1983 vie_encoder_->TriggerQualityLow(); | 2001 video_stream_encoder_->TriggerQualityLow(); |
1984 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 2002 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1985 WaitForEncodedFrame(5); | 2003 WaitForEncodedFrame(5); |
1986 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 2004 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
1987 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2005 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1988 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2006 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1989 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2007 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1990 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2008 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1991 | 2009 |
1992 // Trigger cpu adapt up, expect upscaled resolution (640x360). | 2010 // Trigger cpu adapt up, expect upscaled resolution (640x360). |
1993 vie_encoder_->TriggerCpuNormalUsage(); | 2011 video_stream_encoder_->TriggerCpuNormalUsage(); |
1994 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); | 2012 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
1995 WaitForEncodedFrame(6); | 2013 WaitForEncodedFrame(6); |
1996 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2014 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
1997 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2015 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1998 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2016 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1999 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2017 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2000 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2018 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2001 | 2019 |
2002 // Trigger cpu adapt up, expect upscaled resolution (960x540). | 2020 // Trigger cpu adapt up, expect upscaled resolution (960x540). |
2003 vie_encoder_->TriggerCpuNormalUsage(); | 2021 video_stream_encoder_->TriggerCpuNormalUsage(); |
2004 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); | 2022 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); |
2005 WaitForEncodedFrame(7); | 2023 WaitForEncodedFrame(7); |
2006 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2024 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
2007 last_wants = source.sink_wants(); | 2025 last_wants = source.sink_wants(); |
2008 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2026 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2009 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2027 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2010 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2028 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2011 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2029 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2012 | 2030 |
2013 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). | 2031 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). |
2014 vie_encoder_->TriggerCpuNormalUsage(); | 2032 video_stream_encoder_->TriggerCpuNormalUsage(); |
2015 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); | 2033 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); |
2016 WaitForEncodedFrame(8); | 2034 WaitForEncodedFrame(8); |
2017 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 2035 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
2018 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2036 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2019 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2037 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2020 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2038 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2021 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2039 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2022 | 2040 |
2023 // Trigger quality adapt up, expect no restriction (1280x720). | 2041 // Trigger quality adapt up, expect no restriction (1280x720). |
2024 vie_encoder_->TriggerQualityHigh(); | 2042 video_stream_encoder_->TriggerQualityHigh(); |
2025 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); | 2043 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); |
2026 WaitForEncodedFrame(kWidth, kHeight); | 2044 WaitForEncodedFrame(kWidth, kHeight); |
2027 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2045 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
2028 VerifyNoLimitation(source.sink_wants()); | 2046 VerifyNoLimitation(source.sink_wants()); |
2029 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2047 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2030 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2048 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2031 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2049 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2032 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2050 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2033 | 2051 |
2034 vie_encoder_->Stop(); | 2052 video_stream_encoder_->Stop(); |
2035 } | 2053 } |
2036 | 2054 |
2037 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) { | 2055 TEST_F(VideoStreamEncoderTest, CpuLimitedHistogramIsReported) { |
2038 const int kWidth = 640; | 2056 const int kWidth = 640; |
2039 const int kHeight = 360; | 2057 const int kHeight = 360; |
2040 | 2058 |
2041 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2059 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2042 | 2060 |
2043 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 2061 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
2044 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 2062 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
2045 WaitForEncodedFrame(i); | 2063 WaitForEncodedFrame(i); |
2046 } | 2064 } |
2047 | 2065 |
2048 vie_encoder_->TriggerCpuOveruse(); | 2066 video_stream_encoder_->TriggerCpuOveruse(); |
2049 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 2067 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
2050 video_source_.IncomingCapturedFrame(CreateFrame( | 2068 video_source_.IncomingCapturedFrame(CreateFrame( |
2051 SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); | 2069 SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); |
2052 WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + i); | 2070 WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + i); |
2053 } | 2071 } |
2054 | 2072 |
2055 vie_encoder_->Stop(); | 2073 video_stream_encoder_->Stop(); |
2056 vie_encoder_.reset(); | 2074 video_stream_encoder_.reset(); |
2057 stats_proxy_.reset(); | 2075 stats_proxy_.reset(); |
2058 | 2076 |
2059 EXPECT_EQ(1, | 2077 EXPECT_EQ(1, |
2060 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 2078 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
2061 EXPECT_EQ( | 2079 EXPECT_EQ( |
2062 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); | 2080 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
2063 } | 2081 } |
2064 | 2082 |
2065 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsNotReportedForDisabledDegradation) { | 2083 TEST_F(VideoStreamEncoderTest, |
2066 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2084 CpuLimitedHistogramIsNotReportedForDisabledDegradation) { |
| 2085 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2067 const int kWidth = 640; | 2086 const int kWidth = 640; |
2068 const int kHeight = 360; | 2087 const int kHeight = 360; |
2069 | 2088 |
2070 vie_encoder_->SetSource( | 2089 video_stream_encoder_->SetSource( |
2071 &video_source_, | 2090 &video_source_, |
2072 VideoSendStream::DegradationPreference::kDegradationDisabled); | 2091 VideoSendStream::DegradationPreference::kDegradationDisabled); |
2073 | 2092 |
2074 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 2093 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
2075 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 2094 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
2076 WaitForEncodedFrame(i); | 2095 WaitForEncodedFrame(i); |
2077 } | 2096 } |
2078 | 2097 |
2079 vie_encoder_->Stop(); | 2098 video_stream_encoder_->Stop(); |
2080 vie_encoder_.reset(); | 2099 video_stream_encoder_.reset(); |
2081 stats_proxy_.reset(); | 2100 stats_proxy_.reset(); |
2082 | 2101 |
2083 EXPECT_EQ(0, | 2102 EXPECT_EQ(0, |
2084 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 2103 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
2085 } | 2104 } |
2086 | 2105 |
2087 TEST_F(ViEEncoderTest, CallsBitrateObserver) { | 2106 TEST_F(VideoStreamEncoderTest, CallsBitrateObserver) { |
2088 MockBitrateObserver bitrate_observer; | 2107 MockBitrateObserver bitrate_observer; |
2089 vie_encoder_->SetBitrateObserver(&bitrate_observer); | 2108 video_stream_encoder_->SetBitrateObserver(&bitrate_observer); |
2090 | 2109 |
2091 const int kDefaultFps = 30; | 2110 const int kDefaultFps = 30; |
2092 const BitrateAllocation expected_bitrate = | 2111 const BitrateAllocation expected_bitrate = |
2093 DefaultVideoBitrateAllocator(fake_encoder_.codec_config()) | 2112 DefaultVideoBitrateAllocator(fake_encoder_.codec_config()) |
2094 .GetAllocation(kLowTargetBitrateBps, kDefaultFps); | 2113 .GetAllocation(kLowTargetBitrateBps, kDefaultFps); |
2095 | 2114 |
2096 // First called on bitrate updated, then again on first frame. | 2115 // First called on bitrate updated, then again on first frame. |
2097 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 2116 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
2098 .Times(2); | 2117 .Times(2); |
2099 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 2118 video_stream_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
2100 | 2119 |
2101 const int64_t kStartTimeMs = 1; | 2120 const int64_t kStartTimeMs = 1; |
2102 video_source_.IncomingCapturedFrame( | 2121 video_source_.IncomingCapturedFrame( |
2103 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); | 2122 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); |
2104 WaitForEncodedFrame(kStartTimeMs); | 2123 WaitForEncodedFrame(kStartTimeMs); |
2105 | 2124 |
2106 // Not called on second frame. | 2125 // Not called on second frame. |
2107 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 2126 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
2108 .Times(0); | 2127 .Times(0); |
2109 video_source_.IncomingCapturedFrame( | 2128 video_source_.IncomingCapturedFrame( |
2110 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); | 2129 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); |
2111 WaitForEncodedFrame(kStartTimeMs + 1); | 2130 WaitForEncodedFrame(kStartTimeMs + 1); |
2112 | 2131 |
2113 // Called after a process interval. | 2132 // Called after a process interval. |
2114 const int64_t kProcessIntervalMs = | 2133 const int64_t kProcessIntervalMs = |
2115 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; | 2134 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; |
2116 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec * | 2135 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec * |
2117 (kProcessIntervalMs + (1000 / kDefaultFps))); | 2136 (kProcessIntervalMs + (1000 / kDefaultFps))); |
2118 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 2137 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
2119 .Times(1); | 2138 .Times(1); |
2120 video_source_.IncomingCapturedFrame(CreateFrame( | 2139 video_source_.IncomingCapturedFrame(CreateFrame( |
2121 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); | 2140 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); |
2122 WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); | 2141 WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); |
2123 | 2142 |
2124 vie_encoder_->Stop(); | 2143 video_stream_encoder_->Stop(); |
2125 } | 2144 } |
2126 | 2145 |
2127 TEST_F(ViEEncoderTest, OveruseDetectorUpdatedOnReconfigureAndAdaption) { | 2146 TEST_F(VideoStreamEncoderTest, OveruseDetectorUpdatedOnReconfigureAndAdaption) { |
2128 const int kFrameWidth = 1280; | 2147 const int kFrameWidth = 1280; |
2129 const int kFrameHeight = 720; | 2148 const int kFrameHeight = 720; |
2130 const int kFramerate = 24; | 2149 const int kFramerate = 24; |
2131 | 2150 |
2132 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2151 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2133 test::FrameForwarder source; | 2152 test::FrameForwarder source; |
2134 vie_encoder_->SetSource( | 2153 video_stream_encoder_->SetSource( |
2135 &source, VideoSendStream::DegradationPreference::kMaintainResolution); | 2154 &source, VideoSendStream::DegradationPreference::kMaintainResolution); |
2136 | 2155 |
2137 // Insert a single frame, triggering initial configuration. | 2156 // Insert a single frame, triggering initial configuration. |
2138 source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight)); | 2157 source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight)); |
2139 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2158 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2140 | 2159 |
2141 EXPECT_EQ(vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), | 2160 EXPECT_EQ( |
2142 kDefaultFramerate); | 2161 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), |
| 2162 kDefaultFramerate); |
2143 | 2163 |
2144 // Trigger reconfigure encoder (without resetting the entire instance). | 2164 // Trigger reconfigure encoder (without resetting the entire instance). |
2145 VideoEncoderConfig video_encoder_config; | 2165 VideoEncoderConfig video_encoder_config; |
2146 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; | 2166 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
2147 video_encoder_config.number_of_streams = 1; | 2167 video_encoder_config.number_of_streams = 1; |
2148 video_encoder_config.video_stream_factory = | 2168 video_encoder_config.video_stream_factory = |
2149 new rtc::RefCountedObject<VideoStreamFactory>(1, kFramerate); | 2169 new rtc::RefCountedObject<VideoStreamFactory>(1, kFramerate); |
2150 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 2170 video_stream_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
2151 kMaxPayloadLength, false); | 2171 kMaxPayloadLength, false); |
2152 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2172 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2153 | 2173 |
2154 // Detector should be updated with fps limit from codec config. | 2174 // Detector should be updated with fps limit from codec config. |
2155 EXPECT_EQ(vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), | 2175 EXPECT_EQ( |
2156 kFramerate); | 2176 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), |
| 2177 kFramerate); |
2157 | 2178 |
2158 // Trigger overuse, max framerate should be reduced. | 2179 // Trigger overuse, max framerate should be reduced. |
2159 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 2180 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
2160 stats.input_frame_rate = kFramerate; | 2181 stats.input_frame_rate = kFramerate; |
2161 stats_proxy_->SetMockStats(stats); | 2182 stats_proxy_->SetMockStats(stats); |
2162 vie_encoder_->TriggerCpuOveruse(); | 2183 video_stream_encoder_->TriggerCpuOveruse(); |
2163 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2184 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2164 int adapted_framerate = | 2185 int adapted_framerate = |
2165 vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(); | 2186 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(); |
2166 EXPECT_LT(adapted_framerate, kFramerate); | 2187 EXPECT_LT(adapted_framerate, kFramerate); |
2167 | 2188 |
2168 // Trigger underuse, max framerate should go back to codec configured fps. | 2189 // Trigger underuse, max framerate should go back to codec configured fps. |
2169 // Set extra low fps, to make sure it's actually reset, not just incremented. | 2190 // Set extra low fps, to make sure it's actually reset, not just incremented. |
2170 stats = stats_proxy_->GetStats(); | 2191 stats = stats_proxy_->GetStats(); |
2171 stats.input_frame_rate = adapted_framerate / 2; | 2192 stats.input_frame_rate = adapted_framerate / 2; |
2172 stats_proxy_->SetMockStats(stats); | 2193 stats_proxy_->SetMockStats(stats); |
2173 vie_encoder_->TriggerCpuNormalUsage(); | 2194 video_stream_encoder_->TriggerCpuNormalUsage(); |
2174 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2195 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2175 EXPECT_EQ(vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), | 2196 EXPECT_EQ( |
2176 kFramerate); | 2197 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), |
| 2198 kFramerate); |
2177 | 2199 |
2178 vie_encoder_->Stop(); | 2200 video_stream_encoder_->Stop(); |
2179 } | 2201 } |
2180 | 2202 |
2181 TEST_F(ViEEncoderTest, OveruseDetectorUpdatedRespectsFramerateAfterUnderuse) { | 2203 TEST_F(VideoStreamEncoderTest, |
| 2204 OveruseDetectorUpdatedRespectsFramerateAfterUnderuse) { |
2182 const int kFrameWidth = 1280; | 2205 const int kFrameWidth = 1280; |
2183 const int kFrameHeight = 720; | 2206 const int kFrameHeight = 720; |
2184 const int kLowFramerate = 15; | 2207 const int kLowFramerate = 15; |
2185 const int kHighFramerate = 25; | 2208 const int kHighFramerate = 25; |
2186 | 2209 |
2187 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2210 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2188 test::FrameForwarder source; | 2211 test::FrameForwarder source; |
2189 vie_encoder_->SetSource( | 2212 video_stream_encoder_->SetSource( |
2190 &source, VideoSendStream::DegradationPreference::kMaintainResolution); | 2213 &source, VideoSendStream::DegradationPreference::kMaintainResolution); |
2191 | 2214 |
2192 // Trigger initial configuration. | 2215 // Trigger initial configuration. |
2193 VideoEncoderConfig video_encoder_config; | 2216 VideoEncoderConfig video_encoder_config; |
2194 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; | 2217 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
2195 video_encoder_config.number_of_streams = 1; | 2218 video_encoder_config.number_of_streams = 1; |
2196 video_encoder_config.video_stream_factory = | 2219 video_encoder_config.video_stream_factory = |
2197 new rtc::RefCountedObject<VideoStreamFactory>(1, kLowFramerate); | 2220 new rtc::RefCountedObject<VideoStreamFactory>(1, kLowFramerate); |
2198 source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight)); | 2221 source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight)); |
2199 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 2222 video_stream_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
2200 kMaxPayloadLength, false); | 2223 kMaxPayloadLength, false); |
2201 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2224 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2202 | 2225 |
2203 EXPECT_EQ(vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), | 2226 EXPECT_EQ( |
2204 kLowFramerate); | 2227 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), |
| 2228 kLowFramerate); |
2205 | 2229 |
2206 // Trigger overuse, max framerate should be reduced. | 2230 // Trigger overuse, max framerate should be reduced. |
2207 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 2231 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
2208 stats.input_frame_rate = kLowFramerate; | 2232 stats.input_frame_rate = kLowFramerate; |
2209 stats_proxy_->SetMockStats(stats); | 2233 stats_proxy_->SetMockStats(stats); |
2210 vie_encoder_->TriggerCpuOveruse(); | 2234 video_stream_encoder_->TriggerCpuOveruse(); |
2211 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2235 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2212 int adapted_framerate = | 2236 int adapted_framerate = |
2213 vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(); | 2237 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(); |
2214 EXPECT_LT(adapted_framerate, kLowFramerate); | 2238 EXPECT_LT(adapted_framerate, kLowFramerate); |
2215 | 2239 |
2216 // Reconfigure the encoder with a new (higher max framerate), max fps should | 2240 // Reconfigure the encoder with a new (higher max framerate), max fps should |
2217 // still respect the adaptation. | 2241 // still respect the adaptation. |
2218 video_encoder_config.video_stream_factory = | 2242 video_encoder_config.video_stream_factory = |
2219 new rtc::RefCountedObject<VideoStreamFactory>(1, kHighFramerate); | 2243 new rtc::RefCountedObject<VideoStreamFactory>(1, kHighFramerate); |
2220 source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight)); | 2244 source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight)); |
2221 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 2245 video_stream_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
2222 kMaxPayloadLength, false); | 2246 kMaxPayloadLength, false); |
2223 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2247 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2224 | 2248 |
2225 EXPECT_EQ(vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), | 2249 EXPECT_EQ( |
2226 adapted_framerate); | 2250 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), |
| 2251 adapted_framerate); |
2227 | 2252 |
2228 // Trigger underuse, max framerate should go back to codec configured fps. | 2253 // Trigger underuse, max framerate should go back to codec configured fps. |
2229 stats = stats_proxy_->GetStats(); | 2254 stats = stats_proxy_->GetStats(); |
2230 stats.input_frame_rate = adapted_framerate; | 2255 stats.input_frame_rate = adapted_framerate; |
2231 stats_proxy_->SetMockStats(stats); | 2256 stats_proxy_->SetMockStats(stats); |
2232 vie_encoder_->TriggerCpuNormalUsage(); | 2257 video_stream_encoder_->TriggerCpuNormalUsage(); |
2233 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2258 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2234 EXPECT_EQ(vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), | 2259 EXPECT_EQ( |
2235 kHighFramerate); | 2260 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), |
| 2261 kHighFramerate); |
2236 | 2262 |
2237 vie_encoder_->Stop(); | 2263 video_stream_encoder_->Stop(); |
2238 } | 2264 } |
2239 | 2265 |
2240 TEST_F(ViEEncoderTest, OveruseDetectorUpdatedOnDegradationPreferenceChange) { | 2266 TEST_F(VideoStreamEncoderTest, |
| 2267 OveruseDetectorUpdatedOnDegradationPreferenceChange) { |
2241 const int kFrameWidth = 1280; | 2268 const int kFrameWidth = 1280; |
2242 const int kFrameHeight = 720; | 2269 const int kFrameHeight = 720; |
2243 const int kFramerate = 24; | 2270 const int kFramerate = 24; |
2244 | 2271 |
2245 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2272 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2246 test::FrameForwarder source; | 2273 test::FrameForwarder source; |
2247 vie_encoder_->SetSource( | 2274 video_stream_encoder_->SetSource( |
2248 &source, VideoSendStream::DegradationPreference::kMaintainResolution); | 2275 &source, VideoSendStream::DegradationPreference::kMaintainResolution); |
2249 | 2276 |
2250 // Trigger initial configuration. | 2277 // Trigger initial configuration. |
2251 VideoEncoderConfig video_encoder_config; | 2278 VideoEncoderConfig video_encoder_config; |
2252 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; | 2279 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
2253 video_encoder_config.number_of_streams = 1; | 2280 video_encoder_config.number_of_streams = 1; |
2254 video_encoder_config.video_stream_factory = | 2281 video_encoder_config.video_stream_factory = |
2255 new rtc::RefCountedObject<VideoStreamFactory>(1, kFramerate); | 2282 new rtc::RefCountedObject<VideoStreamFactory>(1, kFramerate); |
2256 source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight)); | 2283 source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight)); |
2257 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 2284 video_stream_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
2258 kMaxPayloadLength, false); | 2285 kMaxPayloadLength, false); |
2259 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2286 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2260 | 2287 |
2261 EXPECT_EQ(vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), | 2288 EXPECT_EQ( |
2262 kFramerate); | 2289 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), |
| 2290 kFramerate); |
2263 | 2291 |
2264 // Trigger overuse, max framerate should be reduced. | 2292 // Trigger overuse, max framerate should be reduced. |
2265 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 2293 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
2266 stats.input_frame_rate = kFramerate; | 2294 stats.input_frame_rate = kFramerate; |
2267 stats_proxy_->SetMockStats(stats); | 2295 stats_proxy_->SetMockStats(stats); |
2268 vie_encoder_->TriggerCpuOveruse(); | 2296 video_stream_encoder_->TriggerCpuOveruse(); |
2269 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2297 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2270 int adapted_framerate = | 2298 int adapted_framerate = |
2271 vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(); | 2299 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(); |
2272 EXPECT_LT(adapted_framerate, kFramerate); | 2300 EXPECT_LT(adapted_framerate, kFramerate); |
2273 | 2301 |
2274 // Change degradation preference to not enable framerate scaling. Target | 2302 // Change degradation preference to not enable framerate scaling. Target |
2275 // framerate should be changed to codec defined limit. | 2303 // framerate should be changed to codec defined limit. |
2276 vie_encoder_->SetSource( | 2304 video_stream_encoder_->SetSource( |
2277 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 2305 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
2278 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 2306 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
2279 EXPECT_EQ(vie_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), | 2307 EXPECT_EQ( |
2280 kFramerate); | 2308 video_stream_encoder_->overuse_detector_proxy_->GetLastTargetFramerate(), |
| 2309 kFramerate); |
2281 | 2310 |
2282 vie_encoder_->Stop(); | 2311 video_stream_encoder_->Stop(); |
2283 } | 2312 } |
2284 | 2313 |
2285 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { | 2314 TEST_F(VideoStreamEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { |
2286 const int kTooLowBitrateForFrameSizeBps = 10000; | 2315 const int kTooLowBitrateForFrameSizeBps = 10000; |
2287 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); | 2316 video_stream_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
2288 const int kWidth = 640; | 2317 const int kWidth = 640; |
2289 const int kHeight = 360; | 2318 const int kHeight = 360; |
2290 | 2319 |
2291 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 2320 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
2292 | 2321 |
2293 // Expect to drop this frame, the wait should time out. | 2322 // Expect to drop this frame, the wait should time out. |
2294 ExpectDroppedFrame(); | 2323 ExpectDroppedFrame(); |
2295 | 2324 |
2296 // Expect the sink_wants to specify a scaled frame. | 2325 // Expect the sink_wants to specify a scaled frame. |
2297 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 2326 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
2298 | 2327 |
2299 int last_pixel_count = video_source_.sink_wants().max_pixel_count; | 2328 int last_pixel_count = video_source_.sink_wants().max_pixel_count; |
2300 | 2329 |
2301 // Next frame is scaled. | 2330 // Next frame is scaled. |
2302 video_source_.IncomingCapturedFrame( | 2331 video_source_.IncomingCapturedFrame( |
2303 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); | 2332 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); |
2304 | 2333 |
2305 // Expect to drop this frame, the wait should time out. | 2334 // Expect to drop this frame, the wait should time out. |
2306 ExpectDroppedFrame(); | 2335 ExpectDroppedFrame(); |
2307 | 2336 |
2308 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); | 2337 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); |
2309 | 2338 |
2310 vie_encoder_->Stop(); | 2339 video_stream_encoder_->Stop(); |
2311 } | 2340 } |
2312 | 2341 |
2313 TEST_F(ViEEncoderTest, NumberOfDroppedFramesLimitedWhenBitrateIsTooLow) { | 2342 TEST_F(VideoStreamEncoderTest, |
| 2343 NumberOfDroppedFramesLimitedWhenBitrateIsTooLow) { |
2314 const int kTooLowBitrateForFrameSizeBps = 10000; | 2344 const int kTooLowBitrateForFrameSizeBps = 10000; |
2315 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); | 2345 video_stream_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
2316 const int kWidth = 640; | 2346 const int kWidth = 640; |
2317 const int kHeight = 360; | 2347 const int kHeight = 360; |
2318 | 2348 |
2319 // We expect the n initial frames to get dropped. | 2349 // We expect the n initial frames to get dropped. |
2320 int i; | 2350 int i; |
2321 for (i = 1; i <= kMaxInitialFramedrop; ++i) { | 2351 for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
2322 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 2352 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
2323 ExpectDroppedFrame(); | 2353 ExpectDroppedFrame(); |
2324 } | 2354 } |
2325 // The n+1th frame should not be dropped, even though it's size is too large. | 2355 // The n+1th frame should not be dropped, even though it's size is too large. |
2326 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 2356 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
2327 WaitForEncodedFrame(i); | 2357 WaitForEncodedFrame(i); |
2328 | 2358 |
2329 // Expect the sink_wants to specify a scaled frame. | 2359 // Expect the sink_wants to specify a scaled frame. |
2330 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 2360 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
2331 | 2361 |
2332 vie_encoder_->Stop(); | 2362 video_stream_encoder_->Stop(); |
2333 } | 2363 } |
2334 | 2364 |
2335 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { | 2365 TEST_F(VideoStreamEncoderTest, |
| 2366 InitialFrameDropOffWithMaintainResolutionPreference) { |
2336 const int kWidth = 640; | 2367 const int kWidth = 640; |
2337 const int kHeight = 360; | 2368 const int kHeight = 360; |
2338 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 2369 video_stream_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
2339 | 2370 |
2340 // Set degradation preference. | 2371 // Set degradation preference. |
2341 vie_encoder_->SetSource( | 2372 video_stream_encoder_->SetSource( |
2342 &video_source_, | 2373 &video_source_, |
2343 VideoSendStream::DegradationPreference::kMaintainResolution); | 2374 VideoSendStream::DegradationPreference::kMaintainResolution); |
2344 | 2375 |
2345 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 2376 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
2346 // Frame should not be dropped, even if it's too large. | 2377 // Frame should not be dropped, even if it's too large. |
2347 WaitForEncodedFrame(1); | 2378 WaitForEncodedFrame(1); |
2348 | 2379 |
2349 vie_encoder_->Stop(); | 2380 video_stream_encoder_->Stop(); |
2350 } | 2381 } |
2351 | 2382 |
2352 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { | 2383 TEST_F(VideoStreamEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { |
2353 const int kWidth = 640; | 2384 const int kWidth = 640; |
2354 const int kHeight = 360; | 2385 const int kHeight = 360; |
2355 fake_encoder_.SetQualityScaling(false); | 2386 fake_encoder_.SetQualityScaling(false); |
2356 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 2387 video_stream_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
2357 | 2388 |
2358 // Force quality scaler reconfiguration by resetting the source. | 2389 // Force quality scaler reconfiguration by resetting the source. |
2359 vie_encoder_->SetSource(&video_source_, | 2390 video_stream_encoder_->SetSource( |
2360 VideoSendStream::DegradationPreference::kBalanced); | 2391 &video_source_, |
| 2392 VideoSendStream::DegradationPreference::kBalanced); |
2361 | 2393 |
2362 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 2394 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
2363 // Frame should not be dropped, even if it's too large. | 2395 // Frame should not be dropped, even if it's too large. |
2364 WaitForEncodedFrame(1); | 2396 WaitForEncodedFrame(1); |
2365 | 2397 |
2366 vie_encoder_->Stop(); | 2398 video_stream_encoder_->Stop(); |
2367 fake_encoder_.SetQualityScaling(true); | 2399 fake_encoder_.SetQualityScaling(true); |
2368 } | 2400 } |
2369 | 2401 |
2370 TEST_F(ViEEncoderTest, | 2402 TEST_F(VideoStreamEncoderTest, |
2371 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) { | 2403 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) { |
2372 const int kTooSmallWidth = 10; | 2404 const int kTooSmallWidth = 10; |
2373 const int kTooSmallHeight = 10; | 2405 const int kTooSmallHeight = 10; |
2374 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2406 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2375 | 2407 |
2376 // Enable kMaintainFramerate preference, no initial limitation. | 2408 // Enable kMaintainFramerate preference, no initial limitation. |
2377 test::FrameForwarder source; | 2409 test::FrameForwarder source; |
2378 vie_encoder_->SetSource( | 2410 video_stream_encoder_->SetSource( |
2379 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 2411 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
2380 VerifyNoLimitation(source.sink_wants()); | 2412 VerifyNoLimitation(source.sink_wants()); |
2381 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2413 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2382 | 2414 |
2383 // Trigger adapt down, too small frame, expect no change. | 2415 // Trigger adapt down, too small frame, expect no change. |
2384 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); | 2416 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); |
2385 WaitForEncodedFrame(1); | 2417 WaitForEncodedFrame(1); |
2386 vie_encoder_->TriggerCpuOveruse(); | 2418 video_stream_encoder_->TriggerCpuOveruse(); |
2387 VerifyNoLimitation(source.sink_wants()); | 2419 VerifyNoLimitation(source.sink_wants()); |
2388 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2420 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2389 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2421 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2390 | 2422 |
2391 vie_encoder_->Stop(); | 2423 video_stream_encoder_->Stop(); |
2392 } | 2424 } |
2393 | 2425 |
2394 TEST_F(ViEEncoderTest, ResolutionNotAdaptedForTooSmallFrame_BalancedMode) { | 2426 TEST_F(VideoStreamEncoderTest, |
| 2427 ResolutionNotAdaptedForTooSmallFrame_BalancedMode) { |
2395 const int kTooSmallWidth = 10; | 2428 const int kTooSmallWidth = 10; |
2396 const int kTooSmallHeight = 10; | 2429 const int kTooSmallHeight = 10; |
2397 const int kFpsLimit = 7; | 2430 const int kFpsLimit = 7; |
2398 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2431 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2399 | 2432 |
2400 // Enable kBalanced preference, no initial limitation. | 2433 // Enable kBalanced preference, no initial limitation. |
2401 test::FrameForwarder source; | 2434 test::FrameForwarder source; |
2402 vie_encoder_->SetSource(&source, | 2435 video_stream_encoder_->SetSource( |
2403 VideoSendStream::DegradationPreference::kBalanced); | 2436 &source, |
| 2437 VideoSendStream::DegradationPreference::kBalanced); |
2404 VerifyNoLimitation(source.sink_wants()); | 2438 VerifyNoLimitation(source.sink_wants()); |
2405 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2439 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2406 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2440 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2407 | 2441 |
2408 // Trigger adapt down, expect limited framerate. | 2442 // Trigger adapt down, expect limited framerate. |
2409 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); | 2443 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); |
2410 WaitForEncodedFrame(1); | 2444 WaitForEncodedFrame(1); |
2411 vie_encoder_->TriggerQualityLow(); | 2445 video_stream_encoder_->TriggerQualityLow(); |
2412 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); | 2446 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); |
2413 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2447 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2414 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2448 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2415 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2449 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2416 | 2450 |
2417 // Trigger adapt down, too small frame, expect no change. | 2451 // Trigger adapt down, too small frame, expect no change. |
2418 source.IncomingCapturedFrame(CreateFrame(2, kTooSmallWidth, kTooSmallHeight)); | 2452 source.IncomingCapturedFrame(CreateFrame(2, kTooSmallWidth, kTooSmallHeight)); |
2419 WaitForEncodedFrame(2); | 2453 WaitForEncodedFrame(2); |
2420 vie_encoder_->TriggerQualityLow(); | 2454 video_stream_encoder_->TriggerQualityLow(); |
2421 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); | 2455 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); |
2422 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2456 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2423 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2457 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2424 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2458 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2425 | 2459 |
2426 vie_encoder_->Stop(); | 2460 video_stream_encoder_->Stop(); |
2427 } | 2461 } |
2428 | 2462 |
2429 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { | 2463 TEST_F(VideoStreamEncoderTest, FailingInitEncodeDoesntCauseCrash) { |
2430 fake_encoder_.ForceInitEncodeFailure(true); | 2464 fake_encoder_.ForceInitEncodeFailure(true); |
2431 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2465 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2432 ResetEncoder("VP8", 2, 1, true, false); | 2466 ResetEncoder("VP8", 2, 1, true, false); |
2433 const int kFrameWidth = 1280; | 2467 const int kFrameWidth = 1280; |
2434 const int kFrameHeight = 720; | 2468 const int kFrameHeight = 720; |
2435 video_source_.IncomingCapturedFrame( | 2469 video_source_.IncomingCapturedFrame( |
2436 CreateFrame(1, kFrameWidth, kFrameHeight)); | 2470 CreateFrame(1, kFrameWidth, kFrameHeight)); |
2437 ExpectDroppedFrame(); | 2471 ExpectDroppedFrame(); |
2438 vie_encoder_->Stop(); | 2472 video_stream_encoder_->Stop(); |
2439 } | 2473 } |
2440 | 2474 |
2441 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. | 2475 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. |
2442 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse_MaintainFramerateMode) { | 2476 TEST_F(VideoStreamEncoderTest, |
2443 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2477 AdaptsResolutionOnOveruse_MaintainFramerateMode) { |
| 2478 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2444 | 2479 |
2445 const int kFrameWidth = 1280; | 2480 const int kFrameWidth = 1280; |
2446 const int kFrameHeight = 720; | 2481 const int kFrameHeight = 720; |
2447 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as | 2482 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as |
2448 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). | 2483 // requested by |
| 2484 // VideoStreamEncoder::VideoSourceProxy::RequestResolutionLowerThan(). |
2449 video_source_.set_adaptation_enabled(true); | 2485 video_source_.set_adaptation_enabled(true); |
2450 | 2486 |
2451 video_source_.IncomingCapturedFrame( | 2487 video_source_.IncomingCapturedFrame( |
2452 CreateFrame(1, kFrameWidth, kFrameHeight)); | 2488 CreateFrame(1, kFrameWidth, kFrameHeight)); |
2453 WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 2489 WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
2454 | 2490 |
2455 // Trigger CPU overuse, downscale by 3/4. | 2491 // Trigger CPU overuse, downscale by 3/4. |
2456 vie_encoder_->TriggerCpuOveruse(); | 2492 video_stream_encoder_->TriggerCpuOveruse(); |
2457 video_source_.IncomingCapturedFrame( | 2493 video_source_.IncomingCapturedFrame( |
2458 CreateFrame(2, kFrameWidth, kFrameHeight)); | 2494 CreateFrame(2, kFrameWidth, kFrameHeight)); |
2459 WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); | 2495 WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
2460 | 2496 |
2461 // Trigger CPU normal use, return to original resolution. | 2497 // Trigger CPU normal use, return to original resolution. |
2462 vie_encoder_->TriggerCpuNormalUsage(); | 2498 video_stream_encoder_->TriggerCpuNormalUsage(); |
2463 video_source_.IncomingCapturedFrame( | 2499 video_source_.IncomingCapturedFrame( |
2464 CreateFrame(3, kFrameWidth, kFrameHeight)); | 2500 CreateFrame(3, kFrameWidth, kFrameHeight)); |
2465 WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 2501 WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
2466 | 2502 |
2467 vie_encoder_->Stop(); | 2503 video_stream_encoder_->Stop(); |
2468 } | 2504 } |
2469 | 2505 |
2470 TEST_F(ViEEncoderTest, AdaptsFramerateOnOveruse_MaintainResolutionMode) { | 2506 TEST_F(VideoStreamEncoderTest, |
| 2507 AdaptsFramerateOnOveruse_MaintainResolutionMode) { |
2471 const int kFrameWidth = 1280; | 2508 const int kFrameWidth = 1280; |
2472 const int kFrameHeight = 720; | 2509 const int kFrameHeight = 720; |
2473 int kFrameIntervalMs = rtc::kNumMillisecsPerSec / max_framerate_; | 2510 int kFrameIntervalMs = rtc::kNumMillisecsPerSec / max_framerate_; |
2474 | 2511 |
2475 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2512 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2476 vie_encoder_->SetSource( | 2513 video_stream_encoder_->SetSource( |
2477 &video_source_, | 2514 &video_source_, |
2478 VideoSendStream::DegradationPreference::kMaintainResolution); | 2515 VideoSendStream::DegradationPreference::kMaintainResolution); |
2479 video_source_.set_adaptation_enabled(true); | 2516 video_source_.set_adaptation_enabled(true); |
2480 | 2517 |
2481 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; | 2518 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
2482 | 2519 |
2483 video_source_.IncomingCapturedFrame( | 2520 video_source_.IncomingCapturedFrame( |
2484 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2521 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2485 WaitForEncodedFrame(timestamp_ms); | 2522 WaitForEncodedFrame(timestamp_ms); |
2486 | 2523 |
2487 // Try to trigger overuse. No fps estimate available => no effect. | 2524 // Try to trigger overuse. No fps estimate available => no effect. |
2488 vie_encoder_->TriggerCpuOveruse(); | 2525 video_stream_encoder_->TriggerCpuOveruse(); |
2489 | 2526 |
2490 // Insert frames for one second to get a stable estimate. | 2527 // Insert frames for one second to get a stable estimate. |
2491 for (int i = 0; i < max_framerate_; ++i) { | 2528 for (int i = 0; i < max_framerate_; ++i) { |
2492 timestamp_ms += kFrameIntervalMs; | 2529 timestamp_ms += kFrameIntervalMs; |
2493 video_source_.IncomingCapturedFrame( | 2530 video_source_.IncomingCapturedFrame( |
2494 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2531 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2495 WaitForEncodedFrame(timestamp_ms); | 2532 WaitForEncodedFrame(timestamp_ms); |
2496 } | 2533 } |
2497 | 2534 |
2498 // Trigger CPU overuse, reduce framerate by 2/3. | 2535 // Trigger CPU overuse, reduce framerate by 2/3. |
2499 vie_encoder_->TriggerCpuOveruse(); | 2536 video_stream_encoder_->TriggerCpuOveruse(); |
2500 int num_frames_dropped = 0; | 2537 int num_frames_dropped = 0; |
2501 for (int i = 0; i < max_framerate_; ++i) { | 2538 for (int i = 0; i < max_framerate_; ++i) { |
2502 timestamp_ms += kFrameIntervalMs; | 2539 timestamp_ms += kFrameIntervalMs; |
2503 video_source_.IncomingCapturedFrame( | 2540 video_source_.IncomingCapturedFrame( |
2504 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2541 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2505 if (!WaitForFrame(kFrameTimeoutMs)) { | 2542 if (!WaitForFrame(kFrameTimeoutMs)) { |
2506 ++num_frames_dropped; | 2543 ++num_frames_dropped; |
2507 } else { | 2544 } else { |
2508 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2545 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2509 } | 2546 } |
2510 } | 2547 } |
2511 | 2548 |
2512 // Add some slack to account for frames dropped by the frame dropper. | 2549 // Add some slack to account for frames dropped by the frame dropper. |
2513 const int kErrorMargin = 1; | 2550 const int kErrorMargin = 1; |
2514 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), | 2551 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), |
2515 kErrorMargin); | 2552 kErrorMargin); |
2516 | 2553 |
2517 // Trigger CPU overuse, reduce framerate by 2/3 again. | 2554 // Trigger CPU overuse, reduce framerate by 2/3 again. |
2518 vie_encoder_->TriggerCpuOveruse(); | 2555 video_stream_encoder_->TriggerCpuOveruse(); |
2519 num_frames_dropped = 0; | 2556 num_frames_dropped = 0; |
2520 for (int i = 0; i < max_framerate_; ++i) { | 2557 for (int i = 0; i < max_framerate_; ++i) { |
2521 timestamp_ms += kFrameIntervalMs; | 2558 timestamp_ms += kFrameIntervalMs; |
2522 video_source_.IncomingCapturedFrame( | 2559 video_source_.IncomingCapturedFrame( |
2523 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2560 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2524 if (!WaitForFrame(kFrameTimeoutMs)) { | 2561 if (!WaitForFrame(kFrameTimeoutMs)) { |
2525 ++num_frames_dropped; | 2562 ++num_frames_dropped; |
2526 } else { | 2563 } else { |
2527 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2564 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2528 } | 2565 } |
2529 } | 2566 } |
2530 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 4 / 9), | 2567 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 4 / 9), |
2531 kErrorMargin); | 2568 kErrorMargin); |
2532 | 2569 |
2533 // Go back up one step. | 2570 // Go back up one step. |
2534 vie_encoder_->TriggerCpuNormalUsage(); | 2571 video_stream_encoder_->TriggerCpuNormalUsage(); |
2535 num_frames_dropped = 0; | 2572 num_frames_dropped = 0; |
2536 for (int i = 0; i < max_framerate_; ++i) { | 2573 for (int i = 0; i < max_framerate_; ++i) { |
2537 timestamp_ms += kFrameIntervalMs; | 2574 timestamp_ms += kFrameIntervalMs; |
2538 video_source_.IncomingCapturedFrame( | 2575 video_source_.IncomingCapturedFrame( |
2539 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2576 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2540 if (!WaitForFrame(kFrameTimeoutMs)) { | 2577 if (!WaitForFrame(kFrameTimeoutMs)) { |
2541 ++num_frames_dropped; | 2578 ++num_frames_dropped; |
2542 } else { | 2579 } else { |
2543 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2580 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2544 } | 2581 } |
2545 } | 2582 } |
2546 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), | 2583 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), |
2547 kErrorMargin); | 2584 kErrorMargin); |
2548 | 2585 |
2549 // Go back up to original mode. | 2586 // Go back up to original mode. |
2550 vie_encoder_->TriggerCpuNormalUsage(); | 2587 video_stream_encoder_->TriggerCpuNormalUsage(); |
2551 num_frames_dropped = 0; | 2588 num_frames_dropped = 0; |
2552 for (int i = 0; i < max_framerate_; ++i) { | 2589 for (int i = 0; i < max_framerate_; ++i) { |
2553 timestamp_ms += kFrameIntervalMs; | 2590 timestamp_ms += kFrameIntervalMs; |
2554 video_source_.IncomingCapturedFrame( | 2591 video_source_.IncomingCapturedFrame( |
2555 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2592 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2556 if (!WaitForFrame(kFrameTimeoutMs)) { | 2593 if (!WaitForFrame(kFrameTimeoutMs)) { |
2557 ++num_frames_dropped; | 2594 ++num_frames_dropped; |
2558 } else { | 2595 } else { |
2559 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2596 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2560 } | 2597 } |
2561 } | 2598 } |
2562 EXPECT_NEAR(num_frames_dropped, 0, kErrorMargin); | 2599 EXPECT_NEAR(num_frames_dropped, 0, kErrorMargin); |
2563 | 2600 |
2564 vie_encoder_->Stop(); | 2601 video_stream_encoder_->Stop(); |
2565 } | 2602 } |
2566 | 2603 |
2567 TEST_F(ViEEncoderTest, DoesntAdaptDownPastMinFramerate) { | 2604 TEST_F(VideoStreamEncoderTest, DoesntAdaptDownPastMinFramerate) { |
2568 const int kFramerateFps = 5; | 2605 const int kFramerateFps = 5; |
2569 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kFramerateFps; | 2606 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kFramerateFps; |
2570 const int kMinFpsFrameInterval = rtc::kNumMillisecsPerSec / kMinFramerateFps; | 2607 const int kMinFpsFrameInterval = rtc::kNumMillisecsPerSec / kMinFramerateFps; |
2571 const int kFrameWidth = 1280; | 2608 const int kFrameWidth = 1280; |
2572 const int kFrameHeight = 720; | 2609 const int kFrameHeight = 720; |
2573 | 2610 |
2574 // Reconfigure encoder with two temporal layers and screensharing, which will | 2611 // Reconfigure encoder with two temporal layers and screensharing, which will |
2575 // disable frame dropping and make testing easier. | 2612 // disable frame dropping and make testing easier. |
2576 ResetEncoder("VP8", 1, 2, true, true); | 2613 ResetEncoder("VP8", 1, 2, true, true); |
2577 | 2614 |
2578 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2615 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2579 vie_encoder_->SetSource( | 2616 video_stream_encoder_->SetSource( |
2580 &video_source_, | 2617 &video_source_, |
2581 VideoSendStream::DegradationPreference::kMaintainResolution); | 2618 VideoSendStream::DegradationPreference::kMaintainResolution); |
2582 video_source_.set_adaptation_enabled(true); | 2619 video_source_.set_adaptation_enabled(true); |
2583 | 2620 |
2584 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; | 2621 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
2585 | 2622 |
2586 // Trigger overuse as much as we can. | 2623 // Trigger overuse as much as we can. |
2587 for (int i = 0; i < ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { | 2624 for (int i = 0; i < VideoStreamEncoder::kMaxCpuResolutionDowngrades; ++i) { |
2588 // Insert frames to get a new fps estimate... | 2625 // Insert frames to get a new fps estimate... |
2589 for (int j = 0; j < kFramerateFps; ++j) { | 2626 for (int j = 0; j < kFramerateFps; ++j) { |
2590 video_source_.IncomingCapturedFrame( | 2627 video_source_.IncomingCapturedFrame( |
2591 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2628 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2592 timestamp_ms += kFrameIntervalMs; | 2629 timestamp_ms += kFrameIntervalMs; |
2593 } | 2630 } |
2594 // ...and then try to adapt again. | 2631 // ...and then try to adapt again. |
2595 vie_encoder_->TriggerCpuOveruse(); | 2632 video_stream_encoder_->TriggerCpuOveruse(); |
2596 } | 2633 } |
2597 | 2634 |
2598 // Drain any frame in the pipeline. | 2635 // Drain any frame in the pipeline. |
2599 WaitForFrame(kDefaultTimeoutMs); | 2636 WaitForFrame(kDefaultTimeoutMs); |
2600 | 2637 |
2601 // Insert frames at min fps, all should go through. | 2638 // Insert frames at min fps, all should go through. |
2602 for (int i = 0; i < 10; ++i) { | 2639 for (int i = 0; i < 10; ++i) { |
2603 timestamp_ms += kMinFpsFrameInterval; | 2640 timestamp_ms += kMinFpsFrameInterval; |
2604 video_source_.IncomingCapturedFrame( | 2641 video_source_.IncomingCapturedFrame( |
2605 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2642 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2606 WaitForEncodedFrame(timestamp_ms); | 2643 WaitForEncodedFrame(timestamp_ms); |
2607 } | 2644 } |
2608 | 2645 |
2609 vie_encoder_->Stop(); | 2646 video_stream_encoder_->Stop(); |
2610 } | 2647 } |
2611 | 2648 |
2612 TEST_F(ViEEncoderTest, AdaptsResolutionAndFramerateForLowQuality_BalancedMode) { | 2649 TEST_F(VideoStreamEncoderTest, |
| 2650 AdaptsResolutionAndFramerateForLowQuality_BalancedMode) { |
2613 const int kWidth = 1280; | 2651 const int kWidth = 1280; |
2614 const int kHeight = 720; | 2652 const int kHeight = 720; |
2615 const int64_t kFrameIntervalMs = 150; | 2653 const int64_t kFrameIntervalMs = 150; |
2616 int64_t timestamp_ms = kFrameIntervalMs; | 2654 int64_t timestamp_ms = kFrameIntervalMs; |
2617 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2655 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2618 | 2656 |
2619 // Enable kBalanced preference, no initial limitation. | 2657 // Enable kBalanced preference, no initial limitation. |
2620 AdaptingFrameForwarder source; | 2658 AdaptingFrameForwarder source; |
2621 source.set_adaptation_enabled(true); | 2659 source.set_adaptation_enabled(true); |
2622 vie_encoder_->SetSource(&source, | 2660 video_stream_encoder_->SetSource( |
2623 VideoSendStream::DegradationPreference::kBalanced); | 2661 &source, |
| 2662 VideoSendStream::DegradationPreference::kBalanced); |
2624 timestamp_ms += kFrameIntervalMs; | 2663 timestamp_ms += kFrameIntervalMs; |
2625 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2664 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2626 WaitForEncodedFrame(kWidth, kHeight); | 2665 WaitForEncodedFrame(kWidth, kHeight); |
2627 VerifyNoLimitation(source.sink_wants()); | 2666 VerifyNoLimitation(source.sink_wants()); |
2628 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2667 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2629 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2668 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2630 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2669 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2631 | 2670 |
2632 // Trigger adapt down, expect scaled down resolution (960x540@30fps). | 2671 // Trigger adapt down, expect scaled down resolution (960x540@30fps). |
2633 vie_encoder_->TriggerQualityLow(); | 2672 video_stream_encoder_->TriggerQualityLow(); |
2634 timestamp_ms += kFrameIntervalMs; | 2673 timestamp_ms += kFrameIntervalMs; |
2635 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2674 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2636 WaitForEncodedFrame(timestamp_ms); | 2675 WaitForEncodedFrame(timestamp_ms); |
2637 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 2676 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
2638 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2677 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2639 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2678 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2640 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2679 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2641 | 2680 |
2642 // Trigger adapt down, expect scaled down resolution (640x360@30fps). | 2681 // Trigger adapt down, expect scaled down resolution (640x360@30fps). |
2643 vie_encoder_->TriggerQualityLow(); | 2682 video_stream_encoder_->TriggerQualityLow(); |
2644 timestamp_ms += kFrameIntervalMs; | 2683 timestamp_ms += kFrameIntervalMs; |
2645 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2684 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2646 WaitForEncodedFrame(timestamp_ms); | 2685 WaitForEncodedFrame(timestamp_ms); |
2647 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 2686 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
2648 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2687 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2649 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2688 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2650 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2689 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2651 | 2690 |
2652 // Trigger adapt down, expect reduced fps (640x360@15fps). | 2691 // Trigger adapt down, expect reduced fps (640x360@15fps). |
2653 vie_encoder_->TriggerQualityLow(); | 2692 video_stream_encoder_->TriggerQualityLow(); |
2654 timestamp_ms += kFrameIntervalMs; | 2693 timestamp_ms += kFrameIntervalMs; |
2655 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2694 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2656 WaitForEncodedFrame(timestamp_ms); | 2695 WaitForEncodedFrame(timestamp_ms); |
2657 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); | 2696 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
2658 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2697 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2659 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2698 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2660 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2699 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2661 | 2700 |
2662 // Trigger adapt down, expect scaled down resolution (480x270@15fps). | 2701 // Trigger adapt down, expect scaled down resolution (480x270@15fps). |
2663 vie_encoder_->TriggerQualityLow(); | 2702 video_stream_encoder_->TriggerQualityLow(); |
2664 timestamp_ms += kFrameIntervalMs; | 2703 timestamp_ms += kFrameIntervalMs; |
2665 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2704 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2666 WaitForEncodedFrame(timestamp_ms); | 2705 WaitForEncodedFrame(timestamp_ms); |
2667 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); | 2706 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); |
2668 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2707 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2669 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2708 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2670 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2709 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2671 | 2710 |
2672 // Restrict bitrate, trigger adapt down, expect reduced fps (480x270@10fps). | 2711 // Restrict bitrate, trigger adapt down, expect reduced fps (480x270@10fps). |
2673 vie_encoder_->TriggerQualityLow(); | 2712 video_stream_encoder_->TriggerQualityLow(); |
2674 timestamp_ms += kFrameIntervalMs; | 2713 timestamp_ms += kFrameIntervalMs; |
2675 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2714 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2676 WaitForEncodedFrame(timestamp_ms); | 2715 WaitForEncodedFrame(timestamp_ms); |
2677 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); | 2716 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
2678 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2717 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2679 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2718 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2680 EXPECT_EQ(5, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2719 EXPECT_EQ(5, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2681 | 2720 |
2682 // Trigger adapt down, expect scaled down resolution (320x180@10fps). | 2721 // Trigger adapt down, expect scaled down resolution (320x180@10fps). |
2683 vie_encoder_->TriggerQualityLow(); | 2722 video_stream_encoder_->TriggerQualityLow(); |
2684 timestamp_ms += kFrameIntervalMs; | 2723 timestamp_ms += kFrameIntervalMs; |
2685 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2724 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2686 WaitForEncodedFrame(timestamp_ms); | 2725 WaitForEncodedFrame(timestamp_ms); |
2687 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); | 2726 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); |
2688 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2727 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2689 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2728 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2690 EXPECT_EQ(6, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2729 EXPECT_EQ(6, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2691 | 2730 |
2692 // Trigger adapt down, expect reduced fps (320x180@7fps). | 2731 // Trigger adapt down, expect reduced fps (320x180@7fps). |
2693 vie_encoder_->TriggerQualityLow(); | 2732 video_stream_encoder_->TriggerQualityLow(); |
2694 timestamp_ms += kFrameIntervalMs; | 2733 timestamp_ms += kFrameIntervalMs; |
2695 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2734 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2696 WaitForEncodedFrame(timestamp_ms); | 2735 WaitForEncodedFrame(timestamp_ms); |
2697 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); | 2736 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
2698 rtc::VideoSinkWants last_wants = source.sink_wants(); | 2737 rtc::VideoSinkWants last_wants = source.sink_wants(); |
2699 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2738 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2700 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2739 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2701 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2740 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2702 | 2741 |
2703 // Trigger adapt down, min resolution reached, expect no change. | 2742 // Trigger adapt down, min resolution reached, expect no change. |
2704 vie_encoder_->TriggerQualityLow(); | 2743 video_stream_encoder_->TriggerQualityLow(); |
2705 timestamp_ms += kFrameIntervalMs; | 2744 timestamp_ms += kFrameIntervalMs; |
2706 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2745 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2707 WaitForEncodedFrame(timestamp_ms); | 2746 WaitForEncodedFrame(timestamp_ms); |
2708 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 2747 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
2709 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2748 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2710 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2749 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2711 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2750 EXPECT_EQ(7, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2712 | 2751 |
2713 // Trigger adapt down, expect expect increased fps (320x180@10fps). | 2752 // Trigger adapt down, expect expect increased fps (320x180@10fps). |
2714 vie_encoder_->TriggerQualityHigh(); | 2753 video_stream_encoder_->TriggerQualityHigh(); |
2715 timestamp_ms += kFrameIntervalMs; | 2754 timestamp_ms += kFrameIntervalMs; |
2716 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2755 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2717 WaitForEncodedFrame(timestamp_ms); | 2756 WaitForEncodedFrame(timestamp_ms); |
2718 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); | 2757 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); |
2719 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2758 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2720 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2759 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2721 EXPECT_EQ(8, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2760 EXPECT_EQ(8, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2722 | 2761 |
2723 // Trigger adapt up, expect upscaled resolution (480x270@10fps). | 2762 // Trigger adapt up, expect upscaled resolution (480x270@10fps). |
2724 vie_encoder_->TriggerQualityHigh(); | 2763 video_stream_encoder_->TriggerQualityHigh(); |
2725 timestamp_ms += kFrameIntervalMs; | 2764 timestamp_ms += kFrameIntervalMs; |
2726 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2765 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2727 WaitForEncodedFrame(timestamp_ms); | 2766 WaitForEncodedFrame(timestamp_ms); |
2728 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); | 2767 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); |
2729 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2768 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2730 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2769 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2731 EXPECT_EQ(9, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2770 EXPECT_EQ(9, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2732 | 2771 |
2733 // Increase bitrate, trigger adapt up, expect increased fps (480x270@15fps). | 2772 // Increase bitrate, trigger adapt up, expect increased fps (480x270@15fps). |
2734 vie_encoder_->TriggerQualityHigh(); | 2773 video_stream_encoder_->TriggerQualityHigh(); |
2735 timestamp_ms += kFrameIntervalMs; | 2774 timestamp_ms += kFrameIntervalMs; |
2736 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2775 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2737 WaitForEncodedFrame(timestamp_ms); | 2776 WaitForEncodedFrame(timestamp_ms); |
2738 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); | 2777 VerifyFpsGtResolutionEq(source.sink_wants(), source.last_wants()); |
2739 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2778 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2740 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2779 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2741 EXPECT_EQ(10, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2780 EXPECT_EQ(10, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2742 | 2781 |
2743 // Trigger adapt up, expect upscaled resolution (640x360@15fps). | 2782 // Trigger adapt up, expect upscaled resolution (640x360@15fps). |
2744 vie_encoder_->TriggerQualityHigh(); | 2783 video_stream_encoder_->TriggerQualityHigh(); |
2745 timestamp_ms += kFrameIntervalMs; | 2784 timestamp_ms += kFrameIntervalMs; |
2746 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2785 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2747 WaitForEncodedFrame(timestamp_ms); | 2786 WaitForEncodedFrame(timestamp_ms); |
2748 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); | 2787 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); |
2749 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2788 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2750 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2789 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2751 EXPECT_EQ(11, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2790 EXPECT_EQ(11, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2752 | 2791 |
2753 // Trigger adapt up, expect increased fps (640x360@30fps). | 2792 // Trigger adapt up, expect increased fps (640x360@30fps). |
2754 vie_encoder_->TriggerQualityHigh(); | 2793 video_stream_encoder_->TriggerQualityHigh(); |
2755 timestamp_ms += kFrameIntervalMs; | 2794 timestamp_ms += kFrameIntervalMs; |
2756 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2795 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2757 WaitForEncodedFrame(timestamp_ms); | 2796 WaitForEncodedFrame(timestamp_ms); |
2758 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); | 2797 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); |
2759 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2798 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2760 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2799 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2761 EXPECT_EQ(12, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2800 EXPECT_EQ(12, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2762 | 2801 |
2763 // Trigger adapt up, expect upscaled resolution (960x540@30fps). | 2802 // Trigger adapt up, expect upscaled resolution (960x540@30fps). |
2764 vie_encoder_->TriggerQualityHigh(); | 2803 video_stream_encoder_->TriggerQualityHigh(); |
2765 timestamp_ms += kFrameIntervalMs; | 2804 timestamp_ms += kFrameIntervalMs; |
2766 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2805 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2767 WaitForEncodedFrame(timestamp_ms); | 2806 WaitForEncodedFrame(timestamp_ms); |
2768 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2807 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
2769 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2808 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2770 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2809 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2771 EXPECT_EQ(13, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2810 EXPECT_EQ(13, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2772 | 2811 |
2773 // Trigger adapt up, expect no restriction (1280x720fps@30fps). | 2812 // Trigger adapt up, expect no restriction (1280x720fps@30fps). |
2774 vie_encoder_->TriggerQualityHigh(); | 2813 video_stream_encoder_->TriggerQualityHigh(); |
2775 timestamp_ms += kFrameIntervalMs; | 2814 timestamp_ms += kFrameIntervalMs; |
2776 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2815 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2777 WaitForEncodedFrame(kWidth, kHeight); | 2816 WaitForEncodedFrame(kWidth, kHeight); |
2778 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2817 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
2779 VerifyNoLimitation(source.sink_wants()); | 2818 VerifyNoLimitation(source.sink_wants()); |
2780 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2819 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2781 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2820 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2782 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2821 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2783 | 2822 |
2784 // Trigger adapt up, expect no change. | 2823 // Trigger adapt up, expect no change. |
2785 vie_encoder_->TriggerQualityHigh(); | 2824 video_stream_encoder_->TriggerQualityHigh(); |
2786 VerifyNoLimitation(source.sink_wants()); | 2825 VerifyNoLimitation(source.sink_wants()); |
2787 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2826 EXPECT_EQ(14, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2788 | 2827 |
2789 vie_encoder_->Stop(); | 2828 video_stream_encoder_->Stop(); |
2790 } | 2829 } |
2791 | 2830 |
2792 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Framerate) { | 2831 TEST_F(VideoStreamEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Framerate) { |
2793 const int kWidth = 1280; | 2832 const int kWidth = 1280; |
2794 const int kHeight = 720; | 2833 const int kHeight = 720; |
2795 const int64_t kFrameIntervalMs = 150; | 2834 const int64_t kFrameIntervalMs = 150; |
2796 int64_t timestamp_ms = kFrameIntervalMs; | 2835 int64_t timestamp_ms = kFrameIntervalMs; |
2797 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2836 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2798 | 2837 |
2799 // Enable kBalanced preference, no initial limitation. | 2838 // Enable kBalanced preference, no initial limitation. |
2800 AdaptingFrameForwarder source; | 2839 AdaptingFrameForwarder source; |
2801 source.set_adaptation_enabled(true); | 2840 source.set_adaptation_enabled(true); |
2802 vie_encoder_->SetSource(&source, | 2841 video_stream_encoder_->SetSource( |
2803 VideoSendStream::DegradationPreference::kBalanced); | 2842 &source, |
| 2843 VideoSendStream::DegradationPreference::kBalanced); |
2804 timestamp_ms += kFrameIntervalMs; | 2844 timestamp_ms += kFrameIntervalMs; |
2805 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2845 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2806 WaitForEncodedFrame(kWidth, kHeight); | 2846 WaitForEncodedFrame(kWidth, kHeight); |
2807 VerifyNoLimitation(source.sink_wants()); | 2847 VerifyNoLimitation(source.sink_wants()); |
2808 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2848 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2809 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2849 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2810 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2850 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2811 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2851 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
2812 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2852 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2813 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2853 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2814 | 2854 |
2815 // Trigger cpu adapt down, expect scaled down resolution (960x540@30fps). | 2855 // Trigger cpu adapt down, expect scaled down resolution (960x540@30fps). |
2816 vie_encoder_->TriggerCpuOveruse(); | 2856 video_stream_encoder_->TriggerCpuOveruse(); |
2817 timestamp_ms += kFrameIntervalMs; | 2857 timestamp_ms += kFrameIntervalMs; |
2818 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2858 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2819 WaitForEncodedFrame(timestamp_ms); | 2859 WaitForEncodedFrame(timestamp_ms); |
2820 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 2860 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
2821 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2861 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2822 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2862 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2823 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2863 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
2824 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2864 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
2825 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2865 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2826 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2866 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2827 | 2867 |
2828 // Trigger cpu adapt down, expect scaled down resolution (640x360@30fps). | 2868 // Trigger cpu adapt down, expect scaled down resolution (640x360@30fps). |
2829 vie_encoder_->TriggerCpuOveruse(); | 2869 video_stream_encoder_->TriggerCpuOveruse(); |
2830 timestamp_ms += kFrameIntervalMs; | 2870 timestamp_ms += kFrameIntervalMs; |
2831 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2871 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2832 WaitForEncodedFrame(timestamp_ms); | 2872 WaitForEncodedFrame(timestamp_ms); |
2833 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 2873 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
2834 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2874 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2835 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2875 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2836 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2876 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
2837 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2877 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
2838 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2878 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2839 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2879 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2840 | 2880 |
2841 // Trigger quality adapt down, expect reduced fps (640x360@15fps). | 2881 // Trigger quality adapt down, expect reduced fps (640x360@15fps). |
2842 vie_encoder_->TriggerQualityLow(); | 2882 video_stream_encoder_->TriggerQualityLow(); |
2843 timestamp_ms += kFrameIntervalMs; | 2883 timestamp_ms += kFrameIntervalMs; |
2844 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2884 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2845 WaitForEncodedFrame(timestamp_ms); | 2885 WaitForEncodedFrame(timestamp_ms); |
2846 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); | 2886 VerifyFpsLtResolutionEq(source.sink_wants(), source.last_wants()); |
2847 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2887 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2848 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 2888 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2849 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2889 EXPECT_TRUE(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(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2891 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2852 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2892 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2853 | 2893 |
2854 // Trigger cpu adapt up, expect increased fps (640x360@30fps). | 2894 // Trigger cpu adapt up, expect increased fps (640x360@30fps). |
2855 vie_encoder_->TriggerCpuNormalUsage(); | 2895 video_stream_encoder_->TriggerCpuNormalUsage(); |
2856 timestamp_ms += kFrameIntervalMs; | 2896 timestamp_ms += kFrameIntervalMs; |
2857 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2897 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2858 WaitForEncodedFrame(timestamp_ms); | 2898 WaitForEncodedFrame(timestamp_ms); |
2859 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); | 2899 VerifyFpsMaxResolutionEq(source.sink_wants(), source.last_wants()); |
2860 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2900 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2861 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2901 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2862 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2902 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
2863 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2903 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
2864 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2904 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2865 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2905 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2866 | 2906 |
2867 // Trigger quality adapt up, expect upscaled resolution (960x540@30fps). | 2907 // Trigger quality adapt up, expect upscaled resolution (960x540@30fps). |
2868 vie_encoder_->TriggerQualityHigh(); | 2908 video_stream_encoder_->TriggerQualityHigh(); |
2869 timestamp_ms += kFrameIntervalMs; | 2909 timestamp_ms += kFrameIntervalMs; |
2870 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2910 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2871 WaitForEncodedFrame(timestamp_ms); | 2911 WaitForEncodedFrame(timestamp_ms); |
2872 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2912 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
2873 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2913 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2874 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2914 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2875 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 2915 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
2876 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2916 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
2877 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2917 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2878 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2918 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2879 | 2919 |
2880 // Trigger cpu adapt up, expect no restriction (1280x720fps@30fps). | 2920 // Trigger cpu adapt up, expect no restriction (1280x720fps@30fps). |
2881 vie_encoder_->TriggerCpuNormalUsage(); | 2921 video_stream_encoder_->TriggerCpuNormalUsage(); |
2882 timestamp_ms += kFrameIntervalMs; | 2922 timestamp_ms += kFrameIntervalMs; |
2883 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2923 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2884 WaitForEncodedFrame(kWidth, kHeight); | 2924 WaitForEncodedFrame(kWidth, kHeight); |
2885 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 2925 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
2886 VerifyNoLimitation(source.sink_wants()); | 2926 VerifyNoLimitation(source.sink_wants()); |
2887 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2927 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2888 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2928 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2889 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2929 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2890 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2930 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
2891 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2931 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2892 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2932 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2893 | 2933 |
2894 // Trigger adapt up, expect no change. | 2934 // Trigger adapt up, expect no change. |
2895 vie_encoder_->TriggerQualityHigh(); | 2935 video_stream_encoder_->TriggerQualityHigh(); |
2896 VerifyNoLimitation(source.sink_wants()); | 2936 VerifyNoLimitation(source.sink_wants()); |
2897 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2937 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2898 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2938 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2899 | 2939 |
2900 vie_encoder_->Stop(); | 2940 video_stream_encoder_->Stop(); |
2901 } | 2941 } |
2902 | 2942 |
2903 TEST_F(ViEEncoderTest, AdaptWithTwoReasonsAndDifferentOrder_Resolution) { | 2943 TEST_F(VideoStreamEncoderTest, |
| 2944 AdaptWithTwoReasonsAndDifferentOrder_Resolution) { |
2904 const int kWidth = 640; | 2945 const int kWidth = 640; |
2905 const int kHeight = 360; | 2946 const int kHeight = 360; |
2906 const int kFpsLimit = 15; | 2947 const int kFpsLimit = 15; |
2907 const int64_t kFrameIntervalMs = 150; | 2948 const int64_t kFrameIntervalMs = 150; |
2908 int64_t timestamp_ms = kFrameIntervalMs; | 2949 int64_t timestamp_ms = kFrameIntervalMs; |
2909 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2950 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2910 | 2951 |
2911 // Enable kBalanced preference, no initial limitation. | 2952 // Enable kBalanced preference, no initial limitation. |
2912 AdaptingFrameForwarder source; | 2953 AdaptingFrameForwarder source; |
2913 source.set_adaptation_enabled(true); | 2954 source.set_adaptation_enabled(true); |
2914 vie_encoder_->SetSource(&source, | 2955 video_stream_encoder_->SetSource( |
2915 VideoSendStream::DegradationPreference::kBalanced); | 2956 &source, |
| 2957 VideoSendStream::DegradationPreference::kBalanced); |
2916 timestamp_ms += kFrameIntervalMs; | 2958 timestamp_ms += kFrameIntervalMs; |
2917 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2959 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2918 WaitForEncodedFrame(kWidth, kHeight); | 2960 WaitForEncodedFrame(kWidth, kHeight); |
2919 VerifyNoLimitation(source.sink_wants()); | 2961 VerifyNoLimitation(source.sink_wants()); |
2920 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2962 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2921 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2963 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2922 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2964 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2923 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 2965 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
2924 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2966 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2925 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2967 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2926 | 2968 |
2927 // Trigger cpu adapt down, expect scaled down framerate (640x360@15fps). | 2969 // Trigger cpu adapt down, expect scaled down framerate (640x360@15fps). |
2928 vie_encoder_->TriggerCpuOveruse(); | 2970 video_stream_encoder_->TriggerCpuOveruse(); |
2929 timestamp_ms += kFrameIntervalMs; | 2971 timestamp_ms += kFrameIntervalMs; |
2930 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2972 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2931 WaitForEncodedFrame(timestamp_ms); | 2973 WaitForEncodedFrame(timestamp_ms); |
2932 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); | 2974 VerifyFpsEqResolutionMax(source.sink_wants(), kFpsLimit); |
2933 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 2975 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2934 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2976 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2935 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2977 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2936 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); | 2978 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); |
2937 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2979 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2938 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2980 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2939 | 2981 |
2940 // Trigger quality adapt down, expect scaled down resolution (480x270@15fps). | 2982 // Trigger quality adapt down, expect scaled down resolution (480x270@15fps). |
2941 vie_encoder_->TriggerQualityLow(); | 2983 video_stream_encoder_->TriggerQualityLow(); |
2942 timestamp_ms += kFrameIntervalMs; | 2984 timestamp_ms += kFrameIntervalMs; |
2943 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2985 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2944 WaitForEncodedFrame(timestamp_ms); | 2986 WaitForEncodedFrame(timestamp_ms); |
2945 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); | 2987 VerifyFpsEqResolutionLt(source.sink_wants(), source.last_wants()); |
2946 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 2988 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
2947 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 2989 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2948 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 2990 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2949 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); | 2991 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_framerate); |
2950 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2992 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2951 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2993 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2952 | 2994 |
2953 // Trigger cpu adapt up, expect upscaled resolution (640x360@15fps). | 2995 // Trigger cpu adapt up, expect upscaled resolution (640x360@15fps). |
2954 vie_encoder_->TriggerCpuNormalUsage(); | 2996 video_stream_encoder_->TriggerCpuNormalUsage(); |
2955 timestamp_ms += kFrameIntervalMs; | 2997 timestamp_ms += kFrameIntervalMs; |
2956 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 2998 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2957 WaitForEncodedFrame(timestamp_ms); | 2999 WaitForEncodedFrame(timestamp_ms); |
2958 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); | 3000 VerifyFpsEqResolutionGt(source.sink_wants(), source.last_wants()); |
2959 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 3001 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2960 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); | 3002 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_framerate); |
2961 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 3003 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2962 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 3004 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
2963 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 3005 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2964 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 3006 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2965 | 3007 |
2966 // Trigger quality adapt up, expect increased fps (640x360@30fps). | 3008 // Trigger quality adapt up, expect increased fps (640x360@30fps). |
2967 vie_encoder_->TriggerQualityHigh(); | 3009 video_stream_encoder_->TriggerQualityHigh(); |
2968 timestamp_ms += kFrameIntervalMs; | 3010 timestamp_ms += kFrameIntervalMs; |
2969 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); | 3011 source.IncomingCapturedFrame(CreateFrame(timestamp_ms, kWidth, kHeight)); |
2970 WaitForEncodedFrame(timestamp_ms); | 3012 WaitForEncodedFrame(timestamp_ms); |
2971 VerifyNoLimitation(source.sink_wants()); | 3013 VerifyNoLimitation(source.sink_wants()); |
2972 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 3014 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
2973 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); | 3015 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_framerate); |
2974 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 3016 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
2975 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 3017 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
2976 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 3018 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2977 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 3019 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2978 | 3020 |
2979 // Trigger adapt up, expect no change. | 3021 // Trigger adapt up, expect no change. |
2980 vie_encoder_->TriggerQualityHigh(); | 3022 video_stream_encoder_->TriggerQualityHigh(); |
2981 VerifyNoLimitation(source.sink_wants()); | 3023 VerifyNoLimitation(source.sink_wants()); |
2982 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 3024 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2983 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 3025 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2984 | 3026 |
2985 vie_encoder_->Stop(); | 3027 video_stream_encoder_->Stop(); |
2986 } | 3028 } |
2987 | 3029 |
2988 TEST_F(ViEEncoderTest, AcceptsFullHdAdaptedDownSimulcastFrames) { | 3030 TEST_F(VideoStreamEncoderTest, AcceptsFullHdAdaptedDownSimulcastFrames) { |
2989 // Simulates simulcast behavior and makes highest stream resolutions divisible | 3031 // Simulates simulcast behavior and makes highest stream resolutions divisible |
2990 // by 4. | 3032 // by 4. |
2991 class CroppingVideoStreamFactory | 3033 class CroppingVideoStreamFactory |
2992 : public VideoEncoderConfig::VideoStreamFactoryInterface { | 3034 : public VideoEncoderConfig::VideoStreamFactoryInterface { |
2993 public: | 3035 public: |
2994 explicit CroppingVideoStreamFactory(size_t num_temporal_layers, | 3036 explicit CroppingVideoStreamFactory(size_t num_temporal_layers, |
2995 int framerate) | 3037 int framerate) |
2996 : num_temporal_layers_(num_temporal_layers), framerate_(framerate) { | 3038 : num_temporal_layers_(num_temporal_layers), framerate_(framerate) { |
2997 EXPECT_GT(num_temporal_layers, 0u); | 3039 EXPECT_GT(num_temporal_layers, 0u); |
2998 EXPECT_GT(framerate, 0); | 3040 EXPECT_GT(framerate, 0); |
(...skipping 19 matching lines...) Expand all Loading... |
3018 }; | 3060 }; |
3019 | 3061 |
3020 const int kFrameWidth = 1920; | 3062 const int kFrameWidth = 1920; |
3021 const int kFrameHeight = 1080; | 3063 const int kFrameHeight = 1080; |
3022 // 3/4 of 1920. | 3064 // 3/4 of 1920. |
3023 const int kAdaptedFrameWidth = 1440; | 3065 const int kAdaptedFrameWidth = 1440; |
3024 // 3/4 of 1080 rounded down to multiple of 4. | 3066 // 3/4 of 1080 rounded down to multiple of 4. |
3025 const int kAdaptedFrameHeight = 808; | 3067 const int kAdaptedFrameHeight = 808; |
3026 const int kFramerate = 24; | 3068 const int kFramerate = 24; |
3027 | 3069 |
3028 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 3070 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
3029 // Trigger reconfigure encoder (without resetting the entire instance). | 3071 // Trigger reconfigure encoder (without resetting the entire instance). |
3030 VideoEncoderConfig video_encoder_config; | 3072 VideoEncoderConfig video_encoder_config; |
3031 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; | 3073 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
3032 video_encoder_config.number_of_streams = 1; | 3074 video_encoder_config.number_of_streams = 1; |
3033 video_encoder_config.video_stream_factory = | 3075 video_encoder_config.video_stream_factory = |
3034 new rtc::RefCountedObject<CroppingVideoStreamFactory>(1, kFramerate); | 3076 new rtc::RefCountedObject<CroppingVideoStreamFactory>(1, kFramerate); |
3035 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 3077 video_stream_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
3036 kMaxPayloadLength, false); | 3078 kMaxPayloadLength, false); |
3037 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 3079 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
3038 | 3080 |
3039 video_source_.set_adaptation_enabled(true); | 3081 video_source_.set_adaptation_enabled(true); |
3040 | 3082 |
3041 video_source_.IncomingCapturedFrame( | 3083 video_source_.IncomingCapturedFrame( |
3042 CreateFrame(1, kFrameWidth, kFrameHeight)); | 3084 CreateFrame(1, kFrameWidth, kFrameHeight)); |
3043 WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 3085 WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
3044 | 3086 |
3045 // Trigger CPU overuse, downscale by 3/4. | 3087 // Trigger CPU overuse, downscale by 3/4. |
3046 vie_encoder_->TriggerCpuOveruse(); | 3088 video_stream_encoder_->TriggerCpuOveruse(); |
3047 video_source_.IncomingCapturedFrame( | 3089 video_source_.IncomingCapturedFrame( |
3048 CreateFrame(2, kFrameWidth, kFrameHeight)); | 3090 CreateFrame(2, kFrameWidth, kFrameHeight)); |
3049 WaitForEncodedFrame(kAdaptedFrameWidth, kAdaptedFrameHeight); | 3091 WaitForEncodedFrame(kAdaptedFrameWidth, kAdaptedFrameHeight); |
3050 | 3092 |
3051 vie_encoder_->Stop(); | 3093 video_stream_encoder_->Stop(); |
3052 } | 3094 } |
3053 | 3095 |
3054 TEST_F(ViEEncoderTest, PeriodicallyUpdatesChannelParameters) { | 3096 TEST_F(VideoStreamEncoderTest, PeriodicallyUpdatesChannelParameters) { |
3055 const int kFrameWidth = 1280; | 3097 const int kFrameWidth = 1280; |
3056 const int kFrameHeight = 720; | 3098 const int kFrameHeight = 720; |
3057 const int kLowFps = 2; | 3099 const int kLowFps = 2; |
3058 const int kHighFps = 30; | 3100 const int kHighFps = 30; |
3059 | 3101 |
3060 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 3102 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
3061 | 3103 |
3062 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; | 3104 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
3063 max_framerate_ = kLowFps; | 3105 max_framerate_ = kLowFps; |
3064 | 3106 |
3065 // Insert 2 seconds of 2fps video. | 3107 // Insert 2 seconds of 2fps video. |
3066 for (int i = 0; i < kLowFps * 2; ++i) { | 3108 for (int i = 0; i < kLowFps * 2; ++i) { |
3067 video_source_.IncomingCapturedFrame( | 3109 video_source_.IncomingCapturedFrame( |
3068 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 3110 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
3069 WaitForEncodedFrame(timestamp_ms); | 3111 WaitForEncodedFrame(timestamp_ms); |
3070 timestamp_ms += 1000 / kLowFps; | 3112 timestamp_ms += 1000 / kLowFps; |
3071 } | 3113 } |
3072 | 3114 |
3073 // Make sure encoder is updated with new target. | 3115 // Make sure encoder is updated with new target. |
3074 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 3116 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
3075 video_source_.IncomingCapturedFrame( | 3117 video_source_.IncomingCapturedFrame( |
3076 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 3118 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
3077 WaitForEncodedFrame(timestamp_ms); | 3119 WaitForEncodedFrame(timestamp_ms); |
3078 timestamp_ms += 1000 / kLowFps; | 3120 timestamp_ms += 1000 / kLowFps; |
3079 | 3121 |
3080 EXPECT_EQ(kLowFps, fake_encoder_.GetConfiguredInputFramerate()); | 3122 EXPECT_EQ(kLowFps, fake_encoder_.GetConfiguredInputFramerate()); |
3081 | 3123 |
3082 // Insert 30fps frames for just a little more than the forced update period. | 3124 // Insert 30fps frames for just a little more than the forced update period. |
3083 const int kVcmTimerIntervalFrames = | 3125 const int kVcmTimerIntervalFrames = |
3084 (vcm::VCMProcessTimer::kDefaultProcessIntervalMs * kHighFps) / 1000; | 3126 (vcm::VCMProcessTimer::kDefaultProcessIntervalMs * kHighFps) / 1000; |
3085 const int kFrameIntervalMs = 1000 / kHighFps; | 3127 const int kFrameIntervalMs = 1000 / kHighFps; |
3086 max_framerate_ = kHighFps; | 3128 max_framerate_ = kHighFps; |
3087 for (int i = 0; i < kVcmTimerIntervalFrames + 2; ++i) { | 3129 for (int i = 0; i < kVcmTimerIntervalFrames + 2; ++i) { |
3088 video_source_.IncomingCapturedFrame( | 3130 video_source_.IncomingCapturedFrame( |
3089 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 3131 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
3090 // Wait for encoded frame, but skip ahead if it doesn't arrive as it might | 3132 // 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 | 3133 // 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 | 3134 // framerate yet, causing it to overshoot the target bitrate and then |
3093 // suffering the wrath of the media optimizer. | 3135 // suffering the wrath of the media optimizer. |
3094 TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameIntervalMs); | 3136 TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameIntervalMs); |
3095 timestamp_ms += kFrameIntervalMs; | 3137 timestamp_ms += kFrameIntervalMs; |
3096 } | 3138 } |
3097 | 3139 |
3098 // Don expect correct measurement just yet, but it should be higher than | 3140 // Don expect correct measurement just yet, but it should be higher than |
3099 // before. | 3141 // before. |
3100 EXPECT_GT(fake_encoder_.GetConfiguredInputFramerate(), kLowFps); | 3142 EXPECT_GT(fake_encoder_.GetConfiguredInputFramerate(), kLowFps); |
3101 | 3143 |
3102 vie_encoder_->Stop(); | 3144 video_stream_encoder_->Stop(); |
3103 } | 3145 } |
3104 | 3146 |
3105 TEST_F(ViEEncoderTest, DoesNotUpdateBitrateAllocationWhenSuspended) { | 3147 TEST_F(VideoStreamEncoderTest, DoesNotUpdateBitrateAllocationWhenSuspended) { |
3106 const int kFrameWidth = 1280; | 3148 const int kFrameWidth = 1280; |
3107 const int kFrameHeight = 720; | 3149 const int kFrameHeight = 720; |
3108 const int kTargetBitrateBps = 1000000; | 3150 const int kTargetBitrateBps = 1000000; |
3109 | 3151 |
3110 MockBitrateObserver bitrate_observer; | 3152 MockBitrateObserver bitrate_observer; |
3111 vie_encoder_->SetBitrateObserver(&bitrate_observer); | 3153 video_stream_encoder_->SetBitrateObserver(&bitrate_observer); |
3112 | 3154 |
3113 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(1); | 3155 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(1); |
3114 // Initial bitrate update. | 3156 // Initial bitrate update. |
3115 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 3157 video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
3116 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 3158 video_stream_encoder_->WaitUntilTaskQueueIsIdle(); |
3117 | 3159 |
3118 // Insert a first video frame, causes another bitrate update. | 3160 // Insert a first video frame, causes another bitrate update. |
3119 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; | 3161 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
3120 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(1); | 3162 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(1); |
3121 video_source_.IncomingCapturedFrame( | 3163 video_source_.IncomingCapturedFrame( |
3122 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 3164 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
3123 WaitForEncodedFrame(timestamp_ms); | 3165 WaitForEncodedFrame(timestamp_ms); |
3124 | 3166 |
3125 // Next, simulate video suspension due to pacer queue overrun. | 3167 // Next, simulate video suspension due to pacer queue overrun. |
3126 vie_encoder_->OnBitrateUpdated(0, 0, 1); | 3168 video_stream_encoder_->OnBitrateUpdated(0, 0, 1); |
3127 | 3169 |
3128 // Skip ahead until a new periodic parameter update should have occured. | 3170 // Skip ahead until a new periodic parameter update should have occured. |
3129 timestamp_ms += vcm::VCMProcessTimer::kDefaultProcessIntervalMs; | 3171 timestamp_ms += vcm::VCMProcessTimer::kDefaultProcessIntervalMs; |
3130 fake_clock_.AdvanceTimeMicros( | 3172 fake_clock_.AdvanceTimeMicros( |
3131 vcm::VCMProcessTimer::kDefaultProcessIntervalMs * | 3173 vcm::VCMProcessTimer::kDefaultProcessIntervalMs * |
3132 rtc::kNumMicrosecsPerMillisec); | 3174 rtc::kNumMicrosecsPerMillisec); |
3133 | 3175 |
3134 // Bitrate observer should not be called. | 3176 // Bitrate observer should not be called. |
3135 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(0); | 3177 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(_)).Times(0); |
3136 video_source_.IncomingCapturedFrame( | 3178 video_source_.IncomingCapturedFrame( |
3137 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 3179 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
3138 ExpectDroppedFrame(); | 3180 ExpectDroppedFrame(); |
3139 | 3181 |
3140 vie_encoder_->Stop(); | 3182 video_stream_encoder_->Stop(); |
3141 } | 3183 } |
3142 | 3184 |
3143 } // namespace webrtc | 3185 } // namespace webrtc |
OLD | NEW |