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