OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } // namespace | 211 } // namespace |
212 | 212 |
213 class ViEEncoderTest : public ::testing::Test { | 213 class ViEEncoderTest : public ::testing::Test { |
214 public: | 214 public: |
215 static const int kDefaultTimeoutMs = 30 * 1000; | 215 static const int kDefaultTimeoutMs = 30 * 1000; |
216 | 216 |
217 ViEEncoderTest() | 217 ViEEncoderTest() |
218 : video_send_config_(VideoSendStream::Config(nullptr)), | 218 : video_send_config_(VideoSendStream::Config(nullptr)), |
219 codec_width_(320), | 219 codec_width_(320), |
220 codec_height_(240), | 220 codec_height_(240), |
| 221 max_framerate_(30), |
221 fake_encoder_(), | 222 fake_encoder_(), |
222 stats_proxy_(new MockableSendStatisticsProxy( | 223 stats_proxy_(new MockableSendStatisticsProxy( |
223 Clock::GetRealTimeClock(), | 224 Clock::GetRealTimeClock(), |
224 video_send_config_, | 225 video_send_config_, |
225 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), | 226 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), |
226 sink_(&fake_encoder_) {} | 227 sink_(&fake_encoder_) {} |
227 | 228 |
228 void SetUp() override { | 229 void SetUp() override { |
229 metrics::Reset(); | 230 metrics::Reset(); |
230 video_send_config_ = VideoSendStream::Config(nullptr); | 231 video_send_config_ = VideoSendStream::Config(nullptr); |
231 video_send_config_.encoder_settings.encoder = &fake_encoder_; | 232 video_send_config_.encoder_settings.encoder = &fake_encoder_; |
232 video_send_config_.encoder_settings.payload_name = "FAKE"; | 233 video_send_config_.encoder_settings.payload_name = "FAKE"; |
233 video_send_config_.encoder_settings.payload_type = 125; | 234 video_send_config_.encoder_settings.payload_type = 125; |
234 | 235 |
235 VideoEncoderConfig video_encoder_config; | 236 VideoEncoderConfig video_encoder_config; |
236 test::FillEncoderConfiguration(1, &video_encoder_config); | 237 test::FillEncoderConfiguration(1, &video_encoder_config); |
| 238 video_encoder_config.video_stream_factory = |
| 239 new rtc::RefCountedObject<VideoStreamFactory>(1); |
237 video_encoder_config_ = video_encoder_config.Copy(); | 240 video_encoder_config_ = video_encoder_config.Copy(); |
| 241 |
| 242 // Framerate limit is specified by the VideoStreamFactory. |
| 243 std::vector<VideoStream> streams = |
| 244 video_encoder_config.video_stream_factory->CreateEncoderStreams( |
| 245 codec_width_, codec_height_, video_encoder_config); |
| 246 max_framerate_ = streams[0].max_framerate; |
| 247 fake_clock_.SetTimeMicros(1234); |
| 248 |
238 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); | 249 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); |
239 } | 250 } |
240 | 251 |
241 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, | 252 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, |
242 bool nack_enabled) { | 253 bool nack_enabled) { |
243 if (vie_encoder_) | 254 if (vie_encoder_) |
244 vie_encoder_->Stop(); | 255 vie_encoder_->Stop(); |
245 vie_encoder_.reset(new ViEEncoderUnderTest( | 256 vie_encoder_.reset(new ViEEncoderUnderTest( |
246 stats_proxy_.get(), video_send_config_.encoder_settings)); | 257 stats_proxy_.get(), video_send_config_.encoder_settings)); |
247 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); | 258 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); |
248 vie_encoder_->SetSource( | 259 vie_encoder_->SetSource( |
249 &video_source_, | 260 &video_source_, |
250 VideoSendStream::DegradationPreference::kMaintainFramerate); | 261 VideoSendStream::DegradationPreference::kMaintainFramerate); |
251 vie_encoder_->SetStartBitrate(kTargetBitrateBps); | 262 vie_encoder_->SetStartBitrate(kTargetBitrateBps); |
252 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 263 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
253 kMaxPayloadLength, nack_enabled); | 264 kMaxPayloadLength, nack_enabled); |
254 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 265 vie_encoder_->WaitUntilTaskQueueIsIdle(); |
255 } | 266 } |
256 | 267 |
257 void ResetEncoder(const std::string& payload_name, | 268 void ResetEncoder(const std::string& payload_name, |
258 size_t num_streams, | 269 size_t num_streams, |
259 size_t num_temporal_layers, | 270 size_t num_temporal_layers, |
260 bool nack_enabled) { | 271 bool nack_enabled, |
| 272 bool screenshare) { |
261 video_send_config_.encoder_settings.payload_name = payload_name; | 273 video_send_config_.encoder_settings.payload_name = payload_name; |
262 | 274 |
263 VideoEncoderConfig video_encoder_config; | 275 VideoEncoderConfig video_encoder_config; |
264 video_encoder_config.number_of_streams = num_streams; | 276 video_encoder_config.number_of_streams = num_streams; |
265 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; | 277 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
266 video_encoder_config.video_stream_factory = | 278 video_encoder_config.video_stream_factory = |
267 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); | 279 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); |
| 280 video_encoder_config.content_type = |
| 281 screenshare ? VideoEncoderConfig::ContentType::kScreen |
| 282 : VideoEncoderConfig::ContentType::kRealtimeVideo; |
268 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); | 283 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); |
269 } | 284 } |
270 | 285 |
271 VideoFrame CreateFrame(int64_t ntp_time_ms, | 286 VideoFrame CreateFrame(int64_t ntp_time_ms, |
272 rtc::Event* destruction_event) const { | 287 rtc::Event* destruction_event) const { |
273 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( | 288 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( |
274 destruction_event, codec_width_, codec_height_), | 289 destruction_event, codec_width_, codec_height_), |
275 99, 99, kVideoRotation_0); | 290 99, 99, kVideoRotation_0); |
276 frame.set_ntp_time_ms(ntp_time_ms); | 291 frame.set_ntp_time_ms(ntp_time_ms); |
277 return frame; | 292 return frame; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 EXPECT_LT(wants.max_pixel_count, pixel_count); | 332 EXPECT_LT(wants.max_pixel_count, pixel_count); |
318 EXPECT_GT(wants.max_pixel_count, 0); | 333 EXPECT_GT(wants.max_pixel_count, 0); |
319 } | 334 } |
320 | 335 |
321 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) { | 336 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) { |
322 EXPECT_LT(wants.max_framerate_fps, fps); | 337 EXPECT_LT(wants.max_framerate_fps, fps); |
323 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); | 338 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); |
324 EXPECT_FALSE(wants.target_pixel_count); | 339 EXPECT_FALSE(wants.target_pixel_count); |
325 } | 340 } |
326 | 341 |
| 342 void WaitForEncodedFrame(int64_t expected_ntp_time) { |
| 343 sink_.WaitForEncodedFrame(expected_ntp_time); |
| 344 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 345 } |
| 346 |
| 347 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, int64_t timeout_ms) { |
| 348 bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, timeout_ms); |
| 349 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 350 return ok; |
| 351 } |
| 352 |
| 353 void WaitForEncodedFrame(uint32_t expected_width, uint32_t expected_height) { |
| 354 sink_.WaitForEncodedFrame(expected_width, expected_height); |
| 355 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 356 } |
| 357 |
| 358 void ExpectDroppedFrame() { |
| 359 sink_.ExpectDroppedFrame(); |
| 360 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 361 } |
| 362 |
| 363 bool WaitForFrame(int64_t timeout_ms) { |
| 364 bool ok = sink_.WaitForFrame(timeout_ms); |
| 365 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
| 366 return ok; |
| 367 } |
| 368 |
327 class TestEncoder : public test::FakeEncoder { | 369 class TestEncoder : public test::FakeEncoder { |
328 public: | 370 public: |
329 TestEncoder() | 371 TestEncoder() |
330 : FakeEncoder(Clock::GetRealTimeClock()), | 372 : FakeEncoder(Clock::GetRealTimeClock()), |
331 continue_encode_event_(false, false) {} | 373 continue_encode_event_(false, false) {} |
332 | 374 |
333 VideoCodec codec_config() const { | 375 VideoCodec codec_config() const { |
334 rtc::CritScope lock(&crit_sect_); | 376 rtc::CritScope lock(&crit_sect_); |
335 return config_; | 377 return config_; |
336 } | 378 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 GUARDED_BY(local_crit_sect_); | 467 GUARDED_BY(local_crit_sect_); |
426 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false; | 468 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false; |
427 }; | 469 }; |
428 | 470 |
429 class TestSink : public ViEEncoder::EncoderSink { | 471 class TestSink : public ViEEncoder::EncoderSink { |
430 public: | 472 public: |
431 explicit TestSink(TestEncoder* test_encoder) | 473 explicit TestSink(TestEncoder* test_encoder) |
432 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} | 474 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} |
433 | 475 |
434 void WaitForEncodedFrame(int64_t expected_ntp_time) { | 476 void WaitForEncodedFrame(int64_t expected_ntp_time) { |
| 477 EXPECT_TRUE( |
| 478 TimedWaitForEncodedFrame(expected_ntp_time, kDefaultTimeoutMs)); |
| 479 } |
| 480 |
| 481 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, |
| 482 int64_t timeout_ms) { |
435 uint32_t timestamp = 0; | 483 uint32_t timestamp = 0; |
436 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 484 if (!encoded_frame_event_.Wait(timeout_ms)) |
| 485 return false; |
437 { | 486 { |
438 rtc::CritScope lock(&crit_); | 487 rtc::CritScope lock(&crit_); |
439 timestamp = last_timestamp_; | 488 timestamp = last_timestamp_; |
440 } | 489 } |
441 test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp); | 490 test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp); |
| 491 return true; |
442 } | 492 } |
443 | 493 |
444 void WaitForEncodedFrame(uint32_t expected_width, | 494 void WaitForEncodedFrame(uint32_t expected_width, |
445 uint32_t expected_height) { | 495 uint32_t expected_height) { |
446 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 496 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
447 CheckLastFrameSizeMathces(expected_width, expected_height); | 497 CheckLastFrameSizeMathces(expected_width, expected_height); |
448 } | 498 } |
449 | 499 |
450 void CheckLastFrameSizeMathces(uint32_t expected_width, | 500 void CheckLastFrameSizeMathces(uint32_t expected_width, |
451 uint32_t expected_height) { | 501 uint32_t expected_height) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 uint32_t last_width_ = 0; | 560 uint32_t last_width_ = 0; |
511 bool expect_frames_ = true; | 561 bool expect_frames_ = true; |
512 int number_of_reconfigurations_ = 0; | 562 int number_of_reconfigurations_ = 0; |
513 int min_transmit_bitrate_bps_ = 0; | 563 int min_transmit_bitrate_bps_ = 0; |
514 }; | 564 }; |
515 | 565 |
516 VideoSendStream::Config video_send_config_; | 566 VideoSendStream::Config video_send_config_; |
517 VideoEncoderConfig video_encoder_config_; | 567 VideoEncoderConfig video_encoder_config_; |
518 int codec_width_; | 568 int codec_width_; |
519 int codec_height_; | 569 int codec_height_; |
| 570 int max_framerate_; |
520 TestEncoder fake_encoder_; | 571 TestEncoder fake_encoder_; |
521 std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; | 572 std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; |
522 TestSink sink_; | 573 TestSink sink_; |
523 AdaptingFrameForwarder video_source_; | 574 AdaptingFrameForwarder video_source_; |
524 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; | 575 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; |
| 576 rtc::ScopedFakeClock fake_clock_; |
525 }; | 577 }; |
526 | 578 |
527 TEST_F(ViEEncoderTest, EncodeOneFrame) { | 579 TEST_F(ViEEncoderTest, EncodeOneFrame) { |
528 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 580 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
529 rtc::Event frame_destroyed_event(false, false); | 581 rtc::Event frame_destroyed_event(false, false); |
530 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 582 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
531 sink_.WaitForEncodedFrame(1); | 583 WaitForEncodedFrame(1); |
532 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 584 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
533 vie_encoder_->Stop(); | 585 vie_encoder_->Stop(); |
534 } | 586 } |
535 | 587 |
536 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { | 588 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { |
537 // Dropped since no target bitrate has been set. | 589 // Dropped since no target bitrate has been set. |
538 rtc::Event frame_destroyed_event(false, false); | 590 rtc::Event frame_destroyed_event(false, false); |
539 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 591 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
540 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 592 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
541 | 593 |
542 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 594 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
543 | 595 |
544 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 596 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
545 sink_.WaitForEncodedFrame(2); | 597 WaitForEncodedFrame(2); |
546 vie_encoder_->Stop(); | 598 vie_encoder_->Stop(); |
547 } | 599 } |
548 | 600 |
549 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { | 601 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { |
550 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 602 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
551 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 603 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
552 sink_.WaitForEncodedFrame(1); | 604 WaitForEncodedFrame(1); |
553 | 605 |
554 vie_encoder_->OnBitrateUpdated(0, 0, 0); | 606 vie_encoder_->OnBitrateUpdated(0, 0, 0); |
555 // Dropped since bitrate is zero. | 607 // Dropped since bitrate is zero. |
556 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 608 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
557 | 609 |
558 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 610 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
559 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 611 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
560 sink_.WaitForEncodedFrame(3); | 612 WaitForEncodedFrame(3); |
561 vie_encoder_->Stop(); | 613 vie_encoder_->Stop(); |
562 } | 614 } |
563 | 615 |
564 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { | 616 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { |
565 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 617 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
566 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 618 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
567 sink_.WaitForEncodedFrame(1); | 619 WaitForEncodedFrame(1); |
568 | 620 |
569 // This frame will be dropped since it has the same ntp timestamp. | 621 // This frame will be dropped since it has the same ntp timestamp. |
570 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 622 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
571 | 623 |
572 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 624 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
573 sink_.WaitForEncodedFrame(2); | 625 WaitForEncodedFrame(2); |
574 vie_encoder_->Stop(); | 626 vie_encoder_->Stop(); |
575 } | 627 } |
576 | 628 |
577 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { | 629 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { |
578 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 630 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
579 | 631 |
580 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 632 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
581 sink_.WaitForEncodedFrame(1); | 633 WaitForEncodedFrame(1); |
582 | 634 |
583 vie_encoder_->Stop(); | 635 vie_encoder_->Stop(); |
584 sink_.SetExpectNoFrames(); | 636 sink_.SetExpectNoFrames(); |
585 rtc::Event frame_destroyed_event(false, false); | 637 rtc::Event frame_destroyed_event(false, false); |
586 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); | 638 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); |
587 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 639 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
588 } | 640 } |
589 | 641 |
590 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { | 642 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { |
591 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 643 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
592 | 644 |
593 fake_encoder_.BlockNextEncode(); | 645 fake_encoder_.BlockNextEncode(); |
594 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 646 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
595 sink_.WaitForEncodedFrame(1); | 647 WaitForEncodedFrame(1); |
596 // Here, the encoder thread will be blocked in the TestEncoder waiting for a | 648 // Here, the encoder thread will be blocked in the TestEncoder waiting for a |
597 // call to ContinueEncode. | 649 // call to ContinueEncode. |
598 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 650 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
599 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 651 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
600 fake_encoder_.ContinueEncode(); | 652 fake_encoder_.ContinueEncode(); |
601 sink_.WaitForEncodedFrame(3); | 653 WaitForEncodedFrame(3); |
602 | 654 |
603 vie_encoder_->Stop(); | 655 vie_encoder_->Stop(); |
604 } | 656 } |
605 | 657 |
606 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { | 658 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { |
607 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 659 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
608 EXPECT_EQ(0, sink_.number_of_reconfigurations()); | 660 EXPECT_EQ(0, sink_.number_of_reconfigurations()); |
609 | 661 |
610 // Capture a frame and wait for it to synchronize with the encoder thread. | 662 // Capture a frame and wait for it to synchronize with the encoder thread. |
611 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 663 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
612 sink_.WaitForEncodedFrame(1); | 664 WaitForEncodedFrame(1); |
613 // The encoder will have been configured once when the first frame is | 665 // The encoder will have been configured once when the first frame is |
614 // received. | 666 // received. |
615 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 667 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
616 | 668 |
617 VideoEncoderConfig video_encoder_config; | 669 VideoEncoderConfig video_encoder_config; |
618 test::FillEncoderConfiguration(1, &video_encoder_config); | 670 test::FillEncoderConfiguration(1, &video_encoder_config); |
619 video_encoder_config.min_transmit_bitrate_bps = 9999; | 671 video_encoder_config.min_transmit_bitrate_bps = 9999; |
620 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 672 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
621 kMaxPayloadLength, true /* nack_enabled */); | 673 kMaxPayloadLength, true /* nack_enabled */); |
622 | 674 |
623 // Capture a frame and wait for it to synchronize with the encoder thread. | 675 // Capture a frame and wait for it to synchronize with the encoder thread. |
624 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 676 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
625 sink_.WaitForEncodedFrame(2); | 677 WaitForEncodedFrame(2); |
626 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 678 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
627 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); | 679 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); |
628 | 680 |
629 vie_encoder_->Stop(); | 681 vie_encoder_->Stop(); |
630 } | 682 } |
631 | 683 |
632 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { | 684 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { |
633 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 685 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
634 | 686 |
635 // Capture a frame and wait for it to synchronize with the encoder thread. | 687 // Capture a frame and wait for it to synchronize with the encoder thread. |
636 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 688 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
637 sink_.WaitForEncodedFrame(1); | 689 WaitForEncodedFrame(1); |
638 // The encoder will have been configured once. | 690 // The encoder will have been configured once. |
639 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 691 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
640 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 692 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
641 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 693 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
642 | 694 |
643 codec_width_ *= 2; | 695 codec_width_ *= 2; |
644 codec_height_ *= 2; | 696 codec_height_ *= 2; |
645 // Capture a frame with a higher resolution and wait for it to synchronize | 697 // Capture a frame with a higher resolution and wait for it to synchronize |
646 // with the encoder thread. | 698 // with the encoder thread. |
647 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 699 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
648 sink_.WaitForEncodedFrame(2); | 700 WaitForEncodedFrame(2); |
649 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 701 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
650 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 702 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
651 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 703 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
652 | 704 |
653 vie_encoder_->Stop(); | 705 vie_encoder_->Stop(); |
654 } | 706 } |
655 | 707 |
656 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor1S1TLWithNackEnabled) { | 708 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor1S1TLWithNackEnabled) { |
657 const bool kNackEnabled = true; | 709 const bool kNackEnabled = true; |
658 const size_t kNumStreams = 1; | 710 const size_t kNumStreams = 1; |
659 const size_t kNumTl = 1; | 711 const size_t kNumTl = 1; |
660 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); | 712 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
661 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 713 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
662 | 714 |
663 // Capture a frame and wait for it to synchronize with the encoder thread. | 715 // Capture a frame and wait for it to synchronize with the encoder thread. |
664 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 716 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
665 sink_.WaitForEncodedFrame(1); | 717 WaitForEncodedFrame(1); |
666 // The encoder have been configured once when the first frame is received. | 718 // The encoder have been configured once when the first frame is received. |
667 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 719 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
668 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 720 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
669 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 721 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
670 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 722 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
671 // Resilience is off for no temporal layers with nack on. | 723 // Resilience is off for no temporal layers with nack on. |
672 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); | 724 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); |
673 vie_encoder_->Stop(); | 725 vie_encoder_->Stop(); |
674 } | 726 } |
675 | 727 |
676 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor2S1TlWithNackEnabled) { | 728 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor2S1TlWithNackEnabled) { |
677 const bool kNackEnabled = true; | 729 const bool kNackEnabled = true; |
678 const size_t kNumStreams = 2; | 730 const size_t kNumStreams = 2; |
679 const size_t kNumTl = 1; | 731 const size_t kNumTl = 1; |
680 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); | 732 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
681 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 733 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
682 | 734 |
683 // Capture a frame and wait for it to synchronize with the encoder thread. | 735 // Capture a frame and wait for it to synchronize with the encoder thread. |
684 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 736 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
685 sink_.WaitForEncodedFrame(1); | 737 WaitForEncodedFrame(1); |
686 // The encoder have been configured once when the first frame is received. | 738 // The encoder have been configured once when the first frame is received. |
687 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 739 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
688 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 740 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
689 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 741 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
690 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 742 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
691 // Resilience is off for no temporal layers and >1 streams with nack on. | 743 // Resilience is off for no temporal layers and >1 streams with nack on. |
692 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); | 744 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); |
693 vie_encoder_->Stop(); | 745 vie_encoder_->Stop(); |
694 } | 746 } |
695 | 747 |
696 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S1TLWithNackDisabled) { | 748 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S1TLWithNackDisabled) { |
697 const bool kNackEnabled = false; | 749 const bool kNackEnabled = false; |
698 const size_t kNumStreams = 1; | 750 const size_t kNumStreams = 1; |
699 const size_t kNumTl = 1; | 751 const size_t kNumTl = 1; |
700 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); | 752 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
701 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 753 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
702 | 754 |
703 // Capture a frame and wait for it to synchronize with the encoder thread. | 755 // Capture a frame and wait for it to synchronize with the encoder thread. |
704 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 756 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
705 sink_.WaitForEncodedFrame(1); | 757 WaitForEncodedFrame(1); |
706 // The encoder have been configured once when the first frame is received. | 758 // The encoder have been configured once when the first frame is received. |
707 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 759 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
708 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 760 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
709 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 761 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
710 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 762 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
711 // Resilience is on for no temporal layers with nack off. | 763 // Resilience is on for no temporal layers with nack off. |
712 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); | 764 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); |
713 vie_encoder_->Stop(); | 765 vie_encoder_->Stop(); |
714 } | 766 } |
715 | 767 |
716 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S2TlWithNackEnabled) { | 768 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S2TlWithNackEnabled) { |
717 const bool kNackEnabled = true; | 769 const bool kNackEnabled = true; |
718 const size_t kNumStreams = 1; | 770 const size_t kNumStreams = 1; |
719 const size_t kNumTl = 2; | 771 const size_t kNumTl = 2; |
720 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); | 772 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
721 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 773 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
722 | 774 |
723 // Capture a frame and wait for it to synchronize with the encoder thread. | 775 // Capture a frame and wait for it to synchronize with the encoder thread. |
724 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 776 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
725 sink_.WaitForEncodedFrame(1); | 777 WaitForEncodedFrame(1); |
726 // The encoder have been configured once when the first frame is received. | 778 // The encoder have been configured once when the first frame is received. |
727 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 779 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
728 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 780 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
729 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 781 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
730 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 782 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
731 // Resilience is on for temporal layers. | 783 // Resilience is on for temporal layers. |
732 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); | 784 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); |
733 vie_encoder_->Stop(); | 785 vie_encoder_->Stop(); |
734 } | 786 } |
735 | 787 |
(...skipping 23 matching lines...) Expand all Loading... |
759 VerifyNoLimitation(video_source_.sink_wants()); | 811 VerifyNoLimitation(video_source_.sink_wants()); |
760 | 812 |
761 int frame_width = 1280; | 813 int frame_width = 1280; |
762 int frame_height = 720; | 814 int frame_height = 720; |
763 | 815 |
764 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should | 816 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should |
765 // request lower resolution. | 817 // request lower resolution. |
766 for (int i = 1; i <= kMaxDowngrades; ++i) { | 818 for (int i = 1; i <= kMaxDowngrades; ++i) { |
767 video_source_.IncomingCapturedFrame( | 819 video_source_.IncomingCapturedFrame( |
768 CreateFrame(i, frame_width, frame_height)); | 820 CreateFrame(i, frame_width, frame_height)); |
769 sink_.WaitForEncodedFrame(i); | 821 WaitForEncodedFrame(i); |
770 | 822 |
771 vie_encoder_->TriggerCpuOveruse(); | 823 vie_encoder_->TriggerCpuOveruse(); |
772 | 824 |
773 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 825 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
774 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 826 EXPECT_LT(video_source_.sink_wants().max_pixel_count, |
775 frame_width * frame_height); | 827 frame_width * frame_height); |
776 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 828 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
777 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 829 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
778 | 830 |
779 frame_width /= 2; | 831 frame_width /= 2; |
780 frame_height /= 2; | 832 frame_height /= 2; |
781 } | 833 } |
782 | 834 |
783 // Trigger CPU overuse one more time. This should not trigger a request for | 835 // Trigger CPU overuse one more time. This should not trigger a request for |
784 // lower resolution. | 836 // lower resolution. |
785 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); | 837 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); |
786 video_source_.IncomingCapturedFrame( | 838 video_source_.IncomingCapturedFrame( |
787 CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); | 839 CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); |
788 sink_.WaitForEncodedFrame(kMaxDowngrades + 1); | 840 WaitForEncodedFrame(kMaxDowngrades + 1); |
789 vie_encoder_->TriggerCpuOveruse(); | 841 vie_encoder_->TriggerCpuOveruse(); |
790 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, | 842 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, |
791 current_wants.target_pixel_count); | 843 current_wants.target_pixel_count); |
792 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, | 844 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, |
793 current_wants.max_pixel_count); | 845 current_wants.max_pixel_count); |
794 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 846 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
795 EXPECT_EQ(kMaxDowngrades, | 847 EXPECT_EQ(kMaxDowngrades, |
796 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 848 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
797 | 849 |
798 // Trigger CPU normal use. | 850 // Trigger CPU normal use. |
(...skipping 14 matching lines...) Expand all Loading... |
813 VerifyNoLimitation(video_source_.sink_wants()); | 865 VerifyNoLimitation(video_source_.sink_wants()); |
814 | 866 |
815 const int kFrameWidth = 1280; | 867 const int kFrameWidth = 1280; |
816 const int kFrameHeight = 720; | 868 const int kFrameHeight = 720; |
817 const int kFrameIntervalMs = 1000 / 30; | 869 const int kFrameIntervalMs = 1000 / 30; |
818 | 870 |
819 int frame_timestamp = 1; | 871 int frame_timestamp = 1; |
820 | 872 |
821 video_source_.IncomingCapturedFrame( | 873 video_source_.IncomingCapturedFrame( |
822 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 874 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
823 sink_.WaitForEncodedFrame(frame_timestamp); | 875 WaitForEncodedFrame(frame_timestamp); |
824 frame_timestamp += kFrameIntervalMs; | 876 frame_timestamp += kFrameIntervalMs; |
825 | 877 |
826 // Trigger CPU overuse. | 878 // Trigger CPU overuse. |
827 vie_encoder_->TriggerCpuOveruse(); | 879 vie_encoder_->TriggerCpuOveruse(); |
828 video_source_.IncomingCapturedFrame( | 880 video_source_.IncomingCapturedFrame( |
829 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 881 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
830 sink_.WaitForEncodedFrame(frame_timestamp); | 882 WaitForEncodedFrame(frame_timestamp); |
831 frame_timestamp += kFrameIntervalMs; | 883 frame_timestamp += kFrameIntervalMs; |
832 | 884 |
833 // Default degradation preference is maintain-framerate, so will lower max | 885 // Default degradation preference is maintain-framerate, so will lower max |
834 // wanted resolution. | 886 // wanted resolution. |
835 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 887 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
836 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 888 EXPECT_LT(video_source_.sink_wants().max_pixel_count, |
837 kFrameWidth * kFrameHeight); | 889 kFrameWidth * kFrameHeight); |
838 EXPECT_EQ(std::numeric_limits<int>::max(), | 890 EXPECT_EQ(std::numeric_limits<int>::max(), |
839 video_source_.sink_wants().max_framerate_fps); | 891 video_source_.sink_wants().max_framerate_fps); |
840 | 892 |
841 // Set new source, switch to maintain-resolution. | 893 // Set new source, switch to maintain-resolution. |
842 test::FrameForwarder new_video_source; | 894 test::FrameForwarder new_video_source; |
843 vie_encoder_->SetSource( | 895 vie_encoder_->SetSource( |
844 &new_video_source, | 896 &new_video_source, |
845 VideoSendStream::DegradationPreference::kMaintainResolution); | 897 VideoSendStream::DegradationPreference::kMaintainResolution); |
846 | 898 |
847 // Initially no degradation registered. | 899 // Initially no degradation registered. |
848 VerifyNoLimitation(new_video_source.sink_wants()); | 900 VerifyNoLimitation(new_video_source.sink_wants()); |
849 | 901 |
850 // Force an input frame rate to be available, or the adaptation call won't | 902 // Force an input frame rate to be available, or the adaptation call won't |
851 // know what framerate to adapt form. | 903 // know what framerate to adapt form. |
852 const int kInputFps = 30; | 904 const int kInputFps = 30; |
853 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 905 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
854 stats.input_frame_rate = kInputFps; | 906 stats.input_frame_rate = kInputFps; |
855 stats_proxy_->SetMockStats(stats); | 907 stats_proxy_->SetMockStats(stats); |
856 | 908 |
857 vie_encoder_->TriggerCpuOveruse(); | 909 vie_encoder_->TriggerCpuOveruse(); |
858 new_video_source.IncomingCapturedFrame( | 910 new_video_source.IncomingCapturedFrame( |
859 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 911 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
860 sink_.WaitForEncodedFrame(frame_timestamp); | 912 WaitForEncodedFrame(frame_timestamp); |
861 frame_timestamp += kFrameIntervalMs; | 913 frame_timestamp += kFrameIntervalMs; |
862 | 914 |
863 // Some framerate constraint should be set. | 915 // Some framerate constraint should be set. |
864 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 916 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
865 EXPECT_EQ(std::numeric_limits<int>::max(), | 917 EXPECT_EQ(std::numeric_limits<int>::max(), |
866 new_video_source.sink_wants().max_pixel_count); | 918 new_video_source.sink_wants().max_pixel_count); |
867 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); | 919 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); |
868 | 920 |
869 // Turn off degradation completely. | 921 // Turn off degradation completely. |
870 vie_encoder_->SetSource( | 922 vie_encoder_->SetSource( |
871 &new_video_source, | 923 &new_video_source, |
872 VideoSendStream::DegradationPreference::kDegradationDisabled); | 924 VideoSendStream::DegradationPreference::kDegradationDisabled); |
873 VerifyNoLimitation(new_video_source.sink_wants()); | 925 VerifyNoLimitation(new_video_source.sink_wants()); |
874 | 926 |
875 vie_encoder_->TriggerCpuOveruse(); | 927 vie_encoder_->TriggerCpuOveruse(); |
876 new_video_source.IncomingCapturedFrame( | 928 new_video_source.IncomingCapturedFrame( |
877 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 929 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
878 sink_.WaitForEncodedFrame(frame_timestamp); | 930 WaitForEncodedFrame(frame_timestamp); |
879 frame_timestamp += kFrameIntervalMs; | 931 frame_timestamp += kFrameIntervalMs; |
880 | 932 |
881 // Still no degradation. | 933 // Still no degradation. |
882 VerifyNoLimitation(new_video_source.sink_wants()); | 934 VerifyNoLimitation(new_video_source.sink_wants()); |
883 | 935 |
884 // Calling SetSource with resolution scaling enabled apply the old SinkWants. | 936 // Calling SetSource with resolution scaling enabled apply the old SinkWants. |
885 vie_encoder_->SetSource( | 937 vie_encoder_->SetSource( |
886 &new_video_source, | 938 &new_video_source, |
887 VideoSendStream::DegradationPreference::kMaintainFramerate); | 939 VideoSendStream::DegradationPreference::kMaintainFramerate); |
888 EXPECT_LT(new_video_source.sink_wants().max_pixel_count, | 940 EXPECT_LT(new_video_source.sink_wants().max_pixel_count, |
(...skipping 13 matching lines...) Expand all Loading... |
902 | 954 |
903 vie_encoder_->Stop(); | 955 vie_encoder_->Stop(); |
904 } | 956 } |
905 | 957 |
906 TEST_F(ViEEncoderTest, StatsTracksQualityAdaptationStats) { | 958 TEST_F(ViEEncoderTest, StatsTracksQualityAdaptationStats) { |
907 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 959 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
908 | 960 |
909 const int kWidth = 1280; | 961 const int kWidth = 1280; |
910 const int kHeight = 720; | 962 const int kHeight = 720; |
911 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 963 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
912 sink_.WaitForEncodedFrame(1); | 964 WaitForEncodedFrame(1); |
913 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 965 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
914 EXPECT_FALSE(stats.bw_limited_resolution); | 966 EXPECT_FALSE(stats.bw_limited_resolution); |
915 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 967 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
916 | 968 |
917 // Trigger adapt down. | 969 // Trigger adapt down. |
918 vie_encoder_->TriggerQualityLow(); | 970 vie_encoder_->TriggerQualityLow(); |
919 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 971 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
920 sink_.WaitForEncodedFrame(2); | 972 WaitForEncodedFrame(2); |
921 | 973 |
922 stats = stats_proxy_->GetStats(); | 974 stats = stats_proxy_->GetStats(); |
923 EXPECT_TRUE(stats.bw_limited_resolution); | 975 EXPECT_TRUE(stats.bw_limited_resolution); |
924 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 976 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
925 | 977 |
926 // Trigger adapt up. | 978 // Trigger adapt up. |
927 vie_encoder_->TriggerQualityHigh(); | 979 vie_encoder_->TriggerQualityHigh(); |
928 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 980 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
929 sink_.WaitForEncodedFrame(3); | 981 WaitForEncodedFrame(3); |
930 | 982 |
931 stats = stats_proxy_->GetStats(); | 983 stats = stats_proxy_->GetStats(); |
932 EXPECT_FALSE(stats.bw_limited_resolution); | 984 EXPECT_FALSE(stats.bw_limited_resolution); |
933 EXPECT_EQ(2, stats.number_of_quality_adapt_changes); | 985 EXPECT_EQ(2, stats.number_of_quality_adapt_changes); |
934 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 986 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
935 | 987 |
936 vie_encoder_->Stop(); | 988 vie_encoder_->Stop(); |
937 } | 989 } |
938 | 990 |
939 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStats) { | 991 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStats) { |
940 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 992 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
941 | 993 |
942 const int kWidth = 1280; | 994 const int kWidth = 1280; |
943 const int kHeight = 720; | 995 const int kHeight = 720; |
944 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 996 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
945 sink_.WaitForEncodedFrame(1); | 997 WaitForEncodedFrame(1); |
946 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 998 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
947 EXPECT_FALSE(stats.cpu_limited_resolution); | 999 EXPECT_FALSE(stats.cpu_limited_resolution); |
948 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1000 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
949 | 1001 |
950 // Trigger CPU overuse. | 1002 // Trigger CPU overuse. |
951 vie_encoder_->TriggerCpuOveruse(); | 1003 vie_encoder_->TriggerCpuOveruse(); |
952 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1004 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
953 sink_.WaitForEncodedFrame(2); | 1005 WaitForEncodedFrame(2); |
954 | 1006 |
955 stats = stats_proxy_->GetStats(); | 1007 stats = stats_proxy_->GetStats(); |
956 EXPECT_TRUE(stats.cpu_limited_resolution); | 1008 EXPECT_TRUE(stats.cpu_limited_resolution); |
957 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1009 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
958 | 1010 |
959 // Trigger CPU normal use. | 1011 // Trigger CPU normal use. |
960 vie_encoder_->TriggerCpuNormalUsage(); | 1012 vie_encoder_->TriggerCpuNormalUsage(); |
961 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1013 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
962 sink_.WaitForEncodedFrame(3); | 1014 WaitForEncodedFrame(3); |
963 | 1015 |
964 stats = stats_proxy_->GetStats(); | 1016 stats = stats_proxy_->GetStats(); |
965 EXPECT_FALSE(stats.cpu_limited_resolution); | 1017 EXPECT_FALSE(stats.cpu_limited_resolution); |
966 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1018 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
967 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1019 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
968 | 1020 |
969 vie_encoder_->Stop(); | 1021 vie_encoder_->Stop(); |
970 } | 1022 } |
971 | 1023 |
972 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { | 1024 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { |
973 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1025 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
974 | 1026 |
975 const int kWidth = 1280; | 1027 const int kWidth = 1280; |
976 const int kHeight = 720; | 1028 const int kHeight = 720; |
977 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1029 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
978 sink_.WaitForEncodedFrame(1); | 1030 WaitForEncodedFrame(1); |
979 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1031 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
980 EXPECT_FALSE(stats.bw_limited_resolution); | 1032 EXPECT_FALSE(stats.bw_limited_resolution); |
981 EXPECT_FALSE(stats.cpu_limited_resolution); | 1033 EXPECT_FALSE(stats.cpu_limited_resolution); |
982 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1034 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
983 | 1035 |
984 // Trigger CPU overuse. | 1036 // Trigger CPU overuse. |
985 vie_encoder_->TriggerCpuOveruse(); | 1037 vie_encoder_->TriggerCpuOveruse(); |
986 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1038 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
987 sink_.WaitForEncodedFrame(2); | 1039 WaitForEncodedFrame(2); |
988 stats = stats_proxy_->GetStats(); | 1040 stats = stats_proxy_->GetStats(); |
989 EXPECT_FALSE(stats.bw_limited_resolution); | 1041 EXPECT_FALSE(stats.bw_limited_resolution); |
990 EXPECT_TRUE(stats.cpu_limited_resolution); | 1042 EXPECT_TRUE(stats.cpu_limited_resolution); |
991 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1043 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
992 | 1044 |
993 // Set new source with adaptation still enabled. | 1045 // Set new source with adaptation still enabled. |
994 test::FrameForwarder new_video_source; | 1046 test::FrameForwarder new_video_source; |
995 vie_encoder_->SetSource( | 1047 vie_encoder_->SetSource( |
996 &new_video_source, | 1048 &new_video_source, |
997 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1049 VideoSendStream::DegradationPreference::kMaintainFramerate); |
998 | 1050 |
999 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1051 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1000 sink_.WaitForEncodedFrame(3); | 1052 WaitForEncodedFrame(3); |
1001 stats = stats_proxy_->GetStats(); | 1053 stats = stats_proxy_->GetStats(); |
1002 EXPECT_FALSE(stats.bw_limited_resolution); | 1054 EXPECT_FALSE(stats.bw_limited_resolution); |
1003 EXPECT_TRUE(stats.cpu_limited_resolution); | 1055 EXPECT_TRUE(stats.cpu_limited_resolution); |
1004 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1056 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1005 | 1057 |
1006 // Set adaptation disabled. | 1058 // Set adaptation disabled. |
1007 vie_encoder_->SetSource( | 1059 vie_encoder_->SetSource( |
1008 &new_video_source, | 1060 &new_video_source, |
1009 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1061 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1010 | 1062 |
1011 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1063 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1012 sink_.WaitForEncodedFrame(4); | 1064 WaitForEncodedFrame(4); |
1013 stats = stats_proxy_->GetStats(); | 1065 stats = stats_proxy_->GetStats(); |
1014 EXPECT_FALSE(stats.bw_limited_resolution); | 1066 EXPECT_FALSE(stats.bw_limited_resolution); |
1015 EXPECT_FALSE(stats.cpu_limited_resolution); | 1067 EXPECT_FALSE(stats.cpu_limited_resolution); |
1016 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1068 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1017 | 1069 |
1018 // Set adaptation back to enabled. | 1070 // Set adaptation back to enabled. |
1019 vie_encoder_->SetSource( | 1071 vie_encoder_->SetSource( |
1020 &new_video_source, | 1072 &new_video_source, |
1021 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1073 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1022 | 1074 |
1023 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1075 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1024 sink_.WaitForEncodedFrame(5); | 1076 WaitForEncodedFrame(5); |
1025 stats = stats_proxy_->GetStats(); | 1077 stats = stats_proxy_->GetStats(); |
1026 EXPECT_FALSE(stats.bw_limited_resolution); | 1078 EXPECT_FALSE(stats.bw_limited_resolution); |
1027 EXPECT_TRUE(stats.cpu_limited_resolution); | 1079 EXPECT_TRUE(stats.cpu_limited_resolution); |
1028 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1080 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1029 | 1081 |
1030 // Trigger CPU normal use. | 1082 // Trigger CPU normal use. |
1031 vie_encoder_->TriggerCpuNormalUsage(); | 1083 vie_encoder_->TriggerCpuNormalUsage(); |
1032 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); | 1084 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
1033 sink_.WaitForEncodedFrame(6); | 1085 WaitForEncodedFrame(6); |
1034 stats = stats_proxy_->GetStats(); | 1086 stats = stats_proxy_->GetStats(); |
1035 EXPECT_FALSE(stats.bw_limited_resolution); | 1087 EXPECT_FALSE(stats.bw_limited_resolution); |
1036 EXPECT_FALSE(stats.cpu_limited_resolution); | 1088 EXPECT_FALSE(stats.cpu_limited_resolution); |
1037 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1089 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1038 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1090 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1039 | 1091 |
1040 vie_encoder_->Stop(); | 1092 vie_encoder_->Stop(); |
1041 } | 1093 } |
1042 | 1094 |
1043 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { | 1095 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { |
1044 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1096 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1045 | 1097 |
1046 const int kWidth = 1280; | 1098 const int kWidth = 1280; |
1047 const int kHeight = 720; | 1099 const int kHeight = 720; |
1048 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1100 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1049 sink_.WaitForEncodedFrame(1); | 1101 WaitForEncodedFrame(1); |
1050 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1102 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1051 EXPECT_FALSE(stats.bw_limited_resolution); | 1103 EXPECT_FALSE(stats.bw_limited_resolution); |
1052 EXPECT_FALSE(stats.bw_limited_framerate); | 1104 EXPECT_FALSE(stats.bw_limited_framerate); |
1053 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1105 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1054 | 1106 |
1055 // Set new source with adaptation still enabled. | 1107 // Set new source with adaptation still enabled. |
1056 test::FrameForwarder new_video_source; | 1108 test::FrameForwarder new_video_source; |
1057 vie_encoder_->SetSource(&new_video_source, | 1109 vie_encoder_->SetSource(&new_video_source, |
1058 VideoSendStream::DegradationPreference::kBalanced); | 1110 VideoSendStream::DegradationPreference::kBalanced); |
1059 | 1111 |
1060 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1112 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1061 sink_.WaitForEncodedFrame(2); | 1113 WaitForEncodedFrame(2); |
1062 stats = stats_proxy_->GetStats(); | 1114 stats = stats_proxy_->GetStats(); |
1063 EXPECT_FALSE(stats.bw_limited_resolution); | 1115 EXPECT_FALSE(stats.bw_limited_resolution); |
1064 EXPECT_FALSE(stats.bw_limited_framerate); | 1116 EXPECT_FALSE(stats.bw_limited_framerate); |
1065 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1117 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1066 | 1118 |
1067 // Trigger adapt down. | 1119 // Trigger adapt down. |
1068 vie_encoder_->TriggerQualityLow(); | 1120 vie_encoder_->TriggerQualityLow(); |
1069 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1121 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1070 sink_.WaitForEncodedFrame(3); | 1122 WaitForEncodedFrame(3); |
1071 stats = stats_proxy_->GetStats(); | 1123 stats = stats_proxy_->GetStats(); |
1072 EXPECT_TRUE(stats.bw_limited_resolution); | 1124 EXPECT_TRUE(stats.bw_limited_resolution); |
1073 EXPECT_FALSE(stats.bw_limited_framerate); | 1125 EXPECT_FALSE(stats.bw_limited_framerate); |
1074 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1126 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1075 | 1127 |
1076 // Set new source with adaptation still enabled. | 1128 // Set new source with adaptation still enabled. |
1077 vie_encoder_->SetSource(&new_video_source, | 1129 vie_encoder_->SetSource(&new_video_source, |
1078 VideoSendStream::DegradationPreference::kBalanced); | 1130 VideoSendStream::DegradationPreference::kBalanced); |
1079 | 1131 |
1080 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1132 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1081 sink_.WaitForEncodedFrame(4); | 1133 WaitForEncodedFrame(4); |
1082 stats = stats_proxy_->GetStats(); | 1134 stats = stats_proxy_->GetStats(); |
1083 EXPECT_TRUE(stats.bw_limited_resolution); | 1135 EXPECT_TRUE(stats.bw_limited_resolution); |
1084 EXPECT_FALSE(stats.bw_limited_framerate); | 1136 EXPECT_FALSE(stats.bw_limited_framerate); |
1085 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1137 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1086 | 1138 |
1087 // Disable resolution scaling. | 1139 // Disable resolution scaling. |
1088 vie_encoder_->SetSource( | 1140 vie_encoder_->SetSource( |
1089 &new_video_source, | 1141 &new_video_source, |
1090 VideoSendStream::DegradationPreference::kMaintainResolution); | 1142 VideoSendStream::DegradationPreference::kMaintainResolution); |
1091 | 1143 |
1092 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1144 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1093 sink_.WaitForEncodedFrame(5); | 1145 WaitForEncodedFrame(5); |
1094 stats = stats_proxy_->GetStats(); | 1146 stats = stats_proxy_->GetStats(); |
1095 EXPECT_FALSE(stats.bw_limited_resolution); | 1147 EXPECT_FALSE(stats.bw_limited_resolution); |
1096 EXPECT_FALSE(stats.bw_limited_framerate); | 1148 EXPECT_FALSE(stats.bw_limited_framerate); |
1097 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1149 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1098 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1150 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1099 | 1151 |
1100 vie_encoder_->Stop(); | 1152 vie_encoder_->Stop(); |
1101 } | 1153 } |
1102 | 1154 |
1103 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { | 1155 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { |
1104 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1156 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1105 | 1157 |
1106 const int kWidth = 1280; | 1158 const int kWidth = 1280; |
1107 const int kHeight = 720; | 1159 const int kHeight = 720; |
1108 video_source_.set_adaptation_enabled(true); | 1160 video_source_.set_adaptation_enabled(true); |
1109 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1161 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1110 sink_.WaitForEncodedFrame(1); | 1162 WaitForEncodedFrame(1); |
1111 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1163 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1112 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1164 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1113 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1165 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1114 | 1166 |
1115 // Trigger adapt down. | 1167 // Trigger adapt down. |
1116 vie_encoder_->TriggerQualityLow(); | 1168 vie_encoder_->TriggerQualityLow(); |
1117 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1169 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1118 sink_.WaitForEncodedFrame(2); | 1170 WaitForEncodedFrame(2); |
1119 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1171 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1120 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1172 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1121 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1173 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1122 | 1174 |
1123 // Trigger overuse. | 1175 // Trigger overuse. |
1124 vie_encoder_->TriggerCpuOveruse(); | 1176 vie_encoder_->TriggerCpuOveruse(); |
1125 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1177 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1126 sink_.WaitForEncodedFrame(3); | 1178 WaitForEncodedFrame(3); |
1127 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1179 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1128 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1180 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1129 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1181 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1130 | 1182 |
1131 // Set source with adaptation still enabled but quality scaler is off. | 1183 // Set source with adaptation still enabled but quality scaler is off. |
1132 fake_encoder_.SetQualityScaling(false); | 1184 fake_encoder_.SetQualityScaling(false); |
1133 vie_encoder_->SetSource( | 1185 vie_encoder_->SetSource( |
1134 &video_source_, | 1186 &video_source_, |
1135 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1187 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1136 | 1188 |
1137 video_source_.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1189 video_source_.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1138 sink_.WaitForEncodedFrame(4); | 1190 WaitForEncodedFrame(4); |
1139 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1191 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1140 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1192 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1141 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1193 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1142 | 1194 |
1143 vie_encoder_->Stop(); | 1195 vie_encoder_->Stop(); |
1144 } | 1196 } |
1145 | 1197 |
1146 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStatsWhenSwitchingSource) { | 1198 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStatsWhenSwitchingSource) { |
1147 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1199 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1148 | 1200 |
1149 const int kWidth = 1280; | 1201 const int kWidth = 1280; |
1150 const int kHeight = 720; | 1202 const int kHeight = 720; |
1151 int sequence = 1; | 1203 int sequence = 1; |
1152 | 1204 |
1153 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1205 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1154 sink_.WaitForEncodedFrame(sequence++); | 1206 WaitForEncodedFrame(sequence++); |
1155 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1207 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1156 EXPECT_FALSE(stats.cpu_limited_resolution); | 1208 EXPECT_FALSE(stats.cpu_limited_resolution); |
1157 EXPECT_FALSE(stats.cpu_limited_framerate); | 1209 EXPECT_FALSE(stats.cpu_limited_framerate); |
1158 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1210 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1159 | 1211 |
1160 // Trigger CPU overuse, should now adapt down. | 1212 // Trigger CPU overuse, should now adapt down. |
1161 vie_encoder_->TriggerCpuOveruse(); | 1213 vie_encoder_->TriggerCpuOveruse(); |
1162 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1214 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1163 sink_.WaitForEncodedFrame(sequence++); | 1215 WaitForEncodedFrame(sequence++); |
1164 stats = stats_proxy_->GetStats(); | 1216 stats = stats_proxy_->GetStats(); |
1165 EXPECT_TRUE(stats.cpu_limited_resolution); | 1217 EXPECT_TRUE(stats.cpu_limited_resolution); |
1166 EXPECT_FALSE(stats.cpu_limited_framerate); | 1218 EXPECT_FALSE(stats.cpu_limited_framerate); |
1167 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1219 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1168 | 1220 |
1169 // Set new source with adaptation still enabled. | 1221 // Set new source with adaptation still enabled. |
1170 test::FrameForwarder new_video_source; | 1222 test::FrameForwarder new_video_source; |
1171 vie_encoder_->SetSource( | 1223 vie_encoder_->SetSource( |
1172 &new_video_source, | 1224 &new_video_source, |
1173 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1225 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1174 | 1226 |
1175 new_video_source.IncomingCapturedFrame( | 1227 new_video_source.IncomingCapturedFrame( |
1176 CreateFrame(sequence, kWidth, kHeight)); | 1228 CreateFrame(sequence, kWidth, kHeight)); |
1177 sink_.WaitForEncodedFrame(sequence++); | 1229 WaitForEncodedFrame(sequence++); |
1178 stats = stats_proxy_->GetStats(); | 1230 stats = stats_proxy_->GetStats(); |
1179 EXPECT_TRUE(stats.cpu_limited_resolution); | 1231 EXPECT_TRUE(stats.cpu_limited_resolution); |
1180 EXPECT_FALSE(stats.cpu_limited_framerate); | 1232 EXPECT_FALSE(stats.cpu_limited_framerate); |
1181 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1233 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1182 | 1234 |
1183 // Set cpu adaptation by frame dropping. | 1235 // Set cpu adaptation by frame dropping. |
1184 vie_encoder_->SetSource( | 1236 vie_encoder_->SetSource( |
1185 &new_video_source, | 1237 &new_video_source, |
1186 VideoSendStream::DegradationPreference::kMaintainResolution); | 1238 VideoSendStream::DegradationPreference::kMaintainResolution); |
1187 new_video_source.IncomingCapturedFrame( | 1239 new_video_source.IncomingCapturedFrame( |
1188 CreateFrame(sequence, kWidth, kHeight)); | 1240 CreateFrame(sequence, kWidth, kHeight)); |
1189 sink_.WaitForEncodedFrame(sequence++); | 1241 WaitForEncodedFrame(sequence++); |
1190 stats = stats_proxy_->GetStats(); | 1242 stats = stats_proxy_->GetStats(); |
1191 // Not adapted at first. | 1243 // Not adapted at first. |
1192 EXPECT_FALSE(stats.cpu_limited_resolution); | 1244 EXPECT_FALSE(stats.cpu_limited_resolution); |
1193 EXPECT_FALSE(stats.cpu_limited_framerate); | 1245 EXPECT_FALSE(stats.cpu_limited_framerate); |
1194 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1246 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1195 | 1247 |
1196 // Force an input frame rate to be available, or the adaptation call won't | 1248 // Force an input frame rate to be available, or the adaptation call won't |
1197 // know what framerate to adapt from. | 1249 // know what framerate to adapt from. |
1198 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); | 1250 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); |
1199 mock_stats.input_frame_rate = 30; | 1251 mock_stats.input_frame_rate = 30; |
1200 stats_proxy_->SetMockStats(mock_stats); | 1252 stats_proxy_->SetMockStats(mock_stats); |
1201 vie_encoder_->TriggerCpuOveruse(); | 1253 vie_encoder_->TriggerCpuOveruse(); |
1202 stats_proxy_->ResetMockStats(); | 1254 stats_proxy_->ResetMockStats(); |
1203 | 1255 |
1204 new_video_source.IncomingCapturedFrame( | 1256 new_video_source.IncomingCapturedFrame( |
1205 CreateFrame(sequence, kWidth, kHeight)); | 1257 CreateFrame(sequence, kWidth, kHeight)); |
1206 sink_.WaitForEncodedFrame(sequence++); | 1258 WaitForEncodedFrame(sequence++); |
1207 | 1259 |
1208 // Framerate now adapted. | 1260 // Framerate now adapted. |
1209 stats = stats_proxy_->GetStats(); | 1261 stats = stats_proxy_->GetStats(); |
1210 EXPECT_FALSE(stats.cpu_limited_resolution); | 1262 EXPECT_FALSE(stats.cpu_limited_resolution); |
1211 EXPECT_TRUE(stats.cpu_limited_framerate); | 1263 EXPECT_TRUE(stats.cpu_limited_framerate); |
1212 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1264 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1213 | 1265 |
1214 // Disable CPU adaptation. | 1266 // Disable CPU adaptation. |
1215 vie_encoder_->SetSource( | 1267 vie_encoder_->SetSource( |
1216 &new_video_source, | 1268 &new_video_source, |
1217 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1269 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1218 new_video_source.IncomingCapturedFrame( | 1270 new_video_source.IncomingCapturedFrame( |
1219 CreateFrame(sequence, kWidth, kHeight)); | 1271 CreateFrame(sequence, kWidth, kHeight)); |
1220 sink_.WaitForEncodedFrame(sequence++); | 1272 WaitForEncodedFrame(sequence++); |
1221 | 1273 |
1222 stats = stats_proxy_->GetStats(); | 1274 stats = stats_proxy_->GetStats(); |
1223 EXPECT_FALSE(stats.cpu_limited_resolution); | 1275 EXPECT_FALSE(stats.cpu_limited_resolution); |
1224 EXPECT_FALSE(stats.cpu_limited_framerate); | 1276 EXPECT_FALSE(stats.cpu_limited_framerate); |
1225 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1277 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1226 | 1278 |
1227 // Try to trigger overuse. Should not succeed. | 1279 // Try to trigger overuse. Should not succeed. |
1228 stats_proxy_->SetMockStats(mock_stats); | 1280 stats_proxy_->SetMockStats(mock_stats); |
1229 vie_encoder_->TriggerCpuOveruse(); | 1281 vie_encoder_->TriggerCpuOveruse(); |
1230 stats_proxy_->ResetMockStats(); | 1282 stats_proxy_->ResetMockStats(); |
1231 | 1283 |
1232 stats = stats_proxy_->GetStats(); | 1284 stats = stats_proxy_->GetStats(); |
1233 EXPECT_FALSE(stats.cpu_limited_resolution); | 1285 EXPECT_FALSE(stats.cpu_limited_resolution); |
1234 EXPECT_FALSE(stats.cpu_limited_framerate); | 1286 EXPECT_FALSE(stats.cpu_limited_framerate); |
1235 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1287 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1236 | 1288 |
1237 // Switch back the source with resolution adaptation enabled. | 1289 // Switch back the source with resolution adaptation enabled. |
1238 vie_encoder_->SetSource( | 1290 vie_encoder_->SetSource( |
1239 &video_source_, | 1291 &video_source_, |
1240 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1292 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1241 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1293 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1242 sink_.WaitForEncodedFrame(sequence++); | 1294 WaitForEncodedFrame(sequence++); |
1243 stats = stats_proxy_->GetStats(); | 1295 stats = stats_proxy_->GetStats(); |
1244 EXPECT_TRUE(stats.cpu_limited_resolution); | 1296 EXPECT_TRUE(stats.cpu_limited_resolution); |
1245 EXPECT_FALSE(stats.cpu_limited_framerate); | 1297 EXPECT_FALSE(stats.cpu_limited_framerate); |
1246 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1298 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1247 | 1299 |
1248 // Trigger CPU normal usage. | 1300 // Trigger CPU normal usage. |
1249 vie_encoder_->TriggerCpuNormalUsage(); | 1301 vie_encoder_->TriggerCpuNormalUsage(); |
1250 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1302 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1251 sink_.WaitForEncodedFrame(sequence++); | 1303 WaitForEncodedFrame(sequence++); |
1252 stats = stats_proxy_->GetStats(); | 1304 stats = stats_proxy_->GetStats(); |
1253 EXPECT_FALSE(stats.cpu_limited_resolution); | 1305 EXPECT_FALSE(stats.cpu_limited_resolution); |
1254 EXPECT_FALSE(stats.cpu_limited_framerate); | 1306 EXPECT_FALSE(stats.cpu_limited_framerate); |
1255 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1307 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1256 | 1308 |
1257 // Back to the source with adaptation off, set it back to maintain-resolution. | 1309 // Back to the source with adaptation off, set it back to maintain-resolution. |
1258 vie_encoder_->SetSource( | 1310 vie_encoder_->SetSource( |
1259 &new_video_source, | 1311 &new_video_source, |
1260 VideoSendStream::DegradationPreference::kMaintainResolution); | 1312 VideoSendStream::DegradationPreference::kMaintainResolution); |
1261 new_video_source.IncomingCapturedFrame( | 1313 new_video_source.IncomingCapturedFrame( |
1262 CreateFrame(sequence, kWidth, kHeight)); | 1314 CreateFrame(sequence, kWidth, kHeight)); |
1263 sink_.WaitForEncodedFrame(sequence++); | 1315 WaitForEncodedFrame(sequence++); |
1264 stats = stats_proxy_->GetStats(); | 1316 stats = stats_proxy_->GetStats(); |
1265 // Disabled, since we previously switched the source to disabled. | 1317 // Disabled, since we previously switched the source to disabled. |
1266 EXPECT_FALSE(stats.cpu_limited_resolution); | 1318 EXPECT_FALSE(stats.cpu_limited_resolution); |
1267 EXPECT_TRUE(stats.cpu_limited_framerate); | 1319 EXPECT_TRUE(stats.cpu_limited_framerate); |
1268 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1320 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1269 | 1321 |
1270 // Trigger CPU normal usage. | 1322 // Trigger CPU normal usage. |
1271 vie_encoder_->TriggerCpuNormalUsage(); | 1323 vie_encoder_->TriggerCpuNormalUsage(); |
1272 new_video_source.IncomingCapturedFrame( | 1324 new_video_source.IncomingCapturedFrame( |
1273 CreateFrame(sequence, kWidth, kHeight)); | 1325 CreateFrame(sequence, kWidth, kHeight)); |
1274 sink_.WaitForEncodedFrame(sequence++); | 1326 WaitForEncodedFrame(sequence++); |
1275 stats = stats_proxy_->GetStats(); | 1327 stats = stats_proxy_->GetStats(); |
1276 EXPECT_FALSE(stats.cpu_limited_resolution); | 1328 EXPECT_FALSE(stats.cpu_limited_resolution); |
1277 EXPECT_FALSE(stats.cpu_limited_framerate); | 1329 EXPECT_FALSE(stats.cpu_limited_framerate); |
1278 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); | 1330 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); |
1279 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1331 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1280 | 1332 |
1281 vie_encoder_->Stop(); | 1333 vie_encoder_->Stop(); |
1282 } | 1334 } |
1283 | 1335 |
1284 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { | 1336 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { |
1285 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1337 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1286 | 1338 |
1287 const int kWidth = 1280; | 1339 const int kWidth = 1280; |
1288 const int kHeight = 720; | 1340 const int kHeight = 720; |
1289 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1341 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1290 sink_.WaitForEncodedFrame(1); | 1342 WaitForEncodedFrame(1); |
1291 | 1343 |
1292 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1344 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1293 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, | 1345 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, |
1294 stats.preferred_media_bitrate_bps); | 1346 stats.preferred_media_bitrate_bps); |
1295 | 1347 |
1296 vie_encoder_->Stop(); | 1348 vie_encoder_->Stop(); |
1297 } | 1349 } |
1298 | 1350 |
1299 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 1351 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
1300 const int kWidth = 1280; | 1352 const int kWidth = 1280; |
1301 const int kHeight = 720; | 1353 const int kHeight = 720; |
1302 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1354 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1303 | 1355 |
1304 // Expect no scaling to begin with. | 1356 // Expect no scaling to begin with. |
1305 VerifyNoLimitation(video_source_.sink_wants()); | 1357 VerifyNoLimitation(video_source_.sink_wants()); |
1306 | 1358 |
1307 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1359 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1308 sink_.WaitForEncodedFrame(1); | 1360 WaitForEncodedFrame(1); |
1309 | 1361 |
1310 // Trigger scale down. | 1362 // Trigger scale down. |
1311 vie_encoder_->TriggerQualityLow(); | 1363 vie_encoder_->TriggerQualityLow(); |
1312 | 1364 |
1313 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1365 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1314 sink_.WaitForEncodedFrame(2); | 1366 WaitForEncodedFrame(2); |
1315 | 1367 |
1316 // Expect a scale down. | 1368 // Expect a scale down. |
1317 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 1369 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
1318 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 1370 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
1319 | 1371 |
1320 // Set resolution scaling disabled. | 1372 // Set resolution scaling disabled. |
1321 test::FrameForwarder new_video_source; | 1373 test::FrameForwarder new_video_source; |
1322 vie_encoder_->SetSource( | 1374 vie_encoder_->SetSource( |
1323 &new_video_source, | 1375 &new_video_source, |
1324 VideoSendStream::DegradationPreference::kMaintainResolution); | 1376 VideoSendStream::DegradationPreference::kMaintainResolution); |
1325 | 1377 |
1326 // Trigger scale down. | 1378 // Trigger scale down. |
1327 vie_encoder_->TriggerQualityLow(); | 1379 vie_encoder_->TriggerQualityLow(); |
1328 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1380 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1329 sink_.WaitForEncodedFrame(3); | 1381 WaitForEncodedFrame(3); |
1330 | 1382 |
1331 // Expect no scaling. | 1383 // Expect no scaling. |
1332 EXPECT_EQ(std::numeric_limits<int>::max(), | 1384 EXPECT_EQ(std::numeric_limits<int>::max(), |
1333 new_video_source.sink_wants().max_pixel_count); | 1385 new_video_source.sink_wants().max_pixel_count); |
1334 | 1386 |
1335 // Trigger scale up. | 1387 // Trigger scale up. |
1336 vie_encoder_->TriggerQualityHigh(); | 1388 vie_encoder_->TriggerQualityHigh(); |
1337 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1389 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1338 sink_.WaitForEncodedFrame(4); | 1390 WaitForEncodedFrame(4); |
1339 | 1391 |
1340 // Expect nothing to change, still no scaling. | 1392 // Expect nothing to change, still no scaling. |
1341 EXPECT_EQ(std::numeric_limits<int>::max(), | 1393 EXPECT_EQ(std::numeric_limits<int>::max(), |
1342 new_video_source.sink_wants().max_pixel_count); | 1394 new_video_source.sink_wants().max_pixel_count); |
1343 | 1395 |
1344 vie_encoder_->Stop(); | 1396 vie_encoder_->Stop(); |
1345 } | 1397 } |
1346 | 1398 |
1347 TEST_F(ViEEncoderTest, SkipsSameAdaptDownRequest_MaintainFramerateMode) { | 1399 TEST_F(ViEEncoderTest, SkipsSameAdaptDownRequest_MaintainFramerateMode) { |
1348 const int kWidth = 1280; | 1400 const int kWidth = 1280; |
1349 const int kHeight = 720; | 1401 const int kHeight = 720; |
1350 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1402 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1351 | 1403 |
1352 // Enable kMaintainFramerate preference, no initial limitation. | 1404 // Enable kMaintainFramerate preference, no initial limitation. |
1353 test::FrameForwarder source; | 1405 test::FrameForwarder source; |
1354 vie_encoder_->SetSource( | 1406 vie_encoder_->SetSource( |
1355 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1407 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1356 | 1408 |
1357 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1409 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1358 sink_.WaitForEncodedFrame(1); | 1410 WaitForEncodedFrame(1); |
1359 VerifyNoLimitation(source.sink_wants()); | 1411 VerifyNoLimitation(source.sink_wants()); |
1360 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1412 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1361 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1413 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1362 | 1414 |
1363 // Trigger adapt down, expect scaled down resolution. | 1415 // Trigger adapt down, expect scaled down resolution. |
1364 vie_encoder_->TriggerCpuOveruse(); | 1416 vie_encoder_->TriggerCpuOveruse(); |
1365 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1417 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1366 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; | 1418 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; |
1367 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1419 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1368 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1420 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
(...skipping 11 matching lines...) Expand all Loading... |
1380 const int kWidth = 1280; | 1432 const int kWidth = 1280; |
1381 const int kHeight = 720; | 1433 const int kHeight = 720; |
1382 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1434 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1383 | 1435 |
1384 // Enable kMaintainFramerate preference, no initial limitation. | 1436 // Enable kMaintainFramerate preference, no initial limitation. |
1385 test::FrameForwarder source; | 1437 test::FrameForwarder source; |
1386 vie_encoder_->SetSource( | 1438 vie_encoder_->SetSource( |
1387 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1439 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1388 | 1440 |
1389 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1441 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1390 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1442 WaitForEncodedFrame(kWidth, kHeight); |
1391 VerifyNoLimitation(source.sink_wants()); | 1443 VerifyNoLimitation(source.sink_wants()); |
1392 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1444 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1393 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1445 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1394 | 1446 |
1395 // Trigger adapt up, expect no change. | 1447 // Trigger adapt up, expect no change. |
1396 vie_encoder_->TriggerCpuNormalUsage(); | 1448 vie_encoder_->TriggerCpuNormalUsage(); |
1397 VerifyNoLimitation(source.sink_wants()); | 1449 VerifyNoLimitation(source.sink_wants()); |
1398 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1450 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1399 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1451 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1400 | 1452 |
1401 vie_encoder_->Stop(); | 1453 vie_encoder_->Stop(); |
1402 } | 1454 } |
1403 | 1455 |
1404 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainResolutionMode) { | 1456 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainResolutionMode) { |
1405 const int kWidth = 1280; | 1457 const int kWidth = 1280; |
1406 const int kHeight = 720; | 1458 const int kHeight = 720; |
1407 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1459 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1408 | 1460 |
1409 // Enable kMaintainResolution preference, no initial limitation. | 1461 // Enable kMaintainResolution preference, no initial limitation. |
1410 test::FrameForwarder source; | 1462 test::FrameForwarder source; |
1411 vie_encoder_->SetSource( | 1463 vie_encoder_->SetSource( |
1412 &source, VideoSendStream::DegradationPreference::kMaintainResolution); | 1464 &source, VideoSendStream::DegradationPreference::kMaintainResolution); |
1413 | 1465 |
1414 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1466 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1415 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1467 WaitForEncodedFrame(kWidth, kHeight); |
1416 VerifyNoLimitation(source.sink_wants()); | 1468 VerifyNoLimitation(source.sink_wants()); |
1417 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1469 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1418 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1470 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1419 | 1471 |
1420 // Trigger adapt up, expect no change. | 1472 // Trigger adapt up, expect no change. |
1421 vie_encoder_->TriggerCpuNormalUsage(); | 1473 vie_encoder_->TriggerCpuNormalUsage(); |
1422 VerifyNoLimitation(source.sink_wants()); | 1474 VerifyNoLimitation(source.sink_wants()); |
1423 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1475 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1424 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1476 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1425 | 1477 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 const int kHeight = 720; | 1510 const int kHeight = 720; |
1459 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1511 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1460 | 1512 |
1461 // Enable kMaintainFramerate preference, no initial limitation. | 1513 // Enable kMaintainFramerate preference, no initial limitation. |
1462 AdaptingFrameForwarder source; | 1514 AdaptingFrameForwarder source; |
1463 source.set_adaptation_enabled(true); | 1515 source.set_adaptation_enabled(true); |
1464 vie_encoder_->SetSource( | 1516 vie_encoder_->SetSource( |
1465 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1517 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1466 | 1518 |
1467 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1519 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1468 sink_.WaitForEncodedFrame(1); | 1520 WaitForEncodedFrame(1); |
1469 VerifyNoLimitation(source.sink_wants()); | 1521 VerifyNoLimitation(source.sink_wants()); |
1470 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1522 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1471 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1523 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1472 | 1524 |
1473 // Trigger adapt down, expect scaled down resolution. | 1525 // Trigger adapt down, expect scaled down resolution. |
1474 vie_encoder_->TriggerQualityLow(); | 1526 vie_encoder_->TriggerQualityLow(); |
1475 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1527 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1476 sink_.WaitForEncodedFrame(2); | 1528 WaitForEncodedFrame(2); |
1477 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1529 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1478 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1530 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1479 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1531 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1480 | 1532 |
1481 // Trigger adapt up, expect no restriction. | 1533 // Trigger adapt up, expect no restriction. |
1482 vie_encoder_->TriggerQualityHigh(); | 1534 vie_encoder_->TriggerQualityHigh(); |
1483 VerifyNoLimitation(source.sink_wants()); | 1535 VerifyNoLimitation(source.sink_wants()); |
1484 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1536 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1485 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1537 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1486 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1538 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 // Enable adapter, expected input resolutions when downscaling: | 1591 // Enable adapter, expected input resolutions when downscaling: |
1540 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) | 1592 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) |
1541 video_source_.set_adaptation_enabled(true); | 1593 video_source_.set_adaptation_enabled(true); |
1542 | 1594 |
1543 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1595 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1544 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1596 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1545 | 1597 |
1546 int downscales = 0; | 1598 int downscales = 0; |
1547 for (size_t i = 1; i <= kNumFrames; i++) { | 1599 for (size_t i = 1; i <= kNumFrames; i++) { |
1548 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1600 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1549 sink_.WaitForEncodedFrame(i); | 1601 WaitForEncodedFrame(i); |
1550 | 1602 |
1551 // Trigger scale down. | 1603 // Trigger scale down. |
1552 rtc::VideoSinkWants last_wants = video_source_.sink_wants(); | 1604 rtc::VideoSinkWants last_wants = video_source_.sink_wants(); |
1553 vie_encoder_->TriggerQualityLow(); | 1605 vie_encoder_->TriggerQualityLow(); |
1554 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); | 1606 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); |
1555 | 1607 |
1556 if (video_source_.sink_wants().max_pixel_count < last_wants.max_pixel_count) | 1608 if (video_source_.sink_wants().max_pixel_count < last_wants.max_pixel_count) |
1557 ++downscales; | 1609 ++downscales; |
1558 | 1610 |
1559 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1611 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
(...skipping 10 matching lines...) Expand all Loading... |
1570 const int kHeight = 720; | 1622 const int kHeight = 720; |
1571 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1623 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1572 | 1624 |
1573 // Enable kMaintainFramerate preference, no initial limitation. | 1625 // Enable kMaintainFramerate preference, no initial limitation. |
1574 AdaptingFrameForwarder source; | 1626 AdaptingFrameForwarder source; |
1575 source.set_adaptation_enabled(true); | 1627 source.set_adaptation_enabled(true); |
1576 vie_encoder_->SetSource( | 1628 vie_encoder_->SetSource( |
1577 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1629 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1578 | 1630 |
1579 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1631 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1580 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1632 WaitForEncodedFrame(kWidth, kHeight); |
1581 VerifyNoLimitation(source.sink_wants()); | 1633 VerifyNoLimitation(source.sink_wants()); |
1582 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1634 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1583 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1635 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1584 | 1636 |
1585 // Trigger adapt down, expect scaled down resolution. | 1637 // Trigger adapt down, expect scaled down resolution. |
1586 vie_encoder_->TriggerCpuOveruse(); | 1638 vie_encoder_->TriggerCpuOveruse(); |
1587 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1639 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1588 sink_.WaitForEncodedFrame(2); | 1640 WaitForEncodedFrame(2); |
1589 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1641 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1590 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1642 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1591 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1643 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1592 | 1644 |
1593 // Trigger adapt up, expect no restriction. | 1645 // Trigger adapt up, expect no restriction. |
1594 vie_encoder_->TriggerCpuNormalUsage(); | 1646 vie_encoder_->TriggerCpuNormalUsage(); |
1595 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1647 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1596 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1648 WaitForEncodedFrame(kWidth, kHeight); |
1597 VerifyNoLimitation(source.sink_wants()); | 1649 VerifyNoLimitation(source.sink_wants()); |
1598 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1650 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1599 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1651 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1600 | 1652 |
1601 // Trigger adapt down, expect scaled down resolution. | 1653 // Trigger adapt down, expect scaled down resolution. |
1602 vie_encoder_->TriggerCpuOveruse(); | 1654 vie_encoder_->TriggerCpuOveruse(); |
1603 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1655 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1604 sink_.WaitForEncodedFrame(4); | 1656 WaitForEncodedFrame(4); |
1605 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1657 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1606 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1658 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1607 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1659 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1608 | 1660 |
1609 // Trigger adapt up, expect no restriction. | 1661 // Trigger adapt up, expect no restriction. |
1610 vie_encoder_->TriggerCpuNormalUsage(); | 1662 vie_encoder_->TriggerCpuNormalUsage(); |
1611 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1663 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1612 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1664 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1613 VerifyNoLimitation(source.sink_wants()); | 1665 VerifyNoLimitation(source.sink_wants()); |
1614 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1666 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1615 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1667 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1616 | 1668 |
1617 vie_encoder_->Stop(); | 1669 vie_encoder_->Stop(); |
1618 } | 1670 } |
1619 | 1671 |
1620 TEST_F(ViEEncoderTest, | 1672 TEST_F(ViEEncoderTest, |
1621 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { | 1673 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { |
1622 const int kWidth = 1280; | 1674 const int kWidth = 1280; |
1623 const int kHeight = 720; | 1675 const int kHeight = 720; |
1624 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1676 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1625 | 1677 |
1626 // Enable kMaintainFramerate preference, no initial limitation. | 1678 // Enable kMaintainFramerate preference, no initial limitation. |
1627 AdaptingFrameForwarder source; | 1679 AdaptingFrameForwarder source; |
1628 source.set_adaptation_enabled(true); | 1680 source.set_adaptation_enabled(true); |
1629 vie_encoder_->SetSource( | 1681 vie_encoder_->SetSource( |
1630 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1682 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1631 | 1683 |
1632 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1684 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1633 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1685 WaitForEncodedFrame(kWidth, kHeight); |
1634 VerifyNoLimitation(source.sink_wants()); | 1686 VerifyNoLimitation(source.sink_wants()); |
1635 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1687 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1636 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1688 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1637 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1689 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1638 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1690 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1639 | 1691 |
1640 // Trigger cpu adapt down, expect scaled down resolution (960x540). | 1692 // Trigger cpu adapt down, expect scaled down resolution (960x540). |
1641 vie_encoder_->TriggerCpuOveruse(); | 1693 vie_encoder_->TriggerCpuOveruse(); |
1642 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1694 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1643 sink_.WaitForEncodedFrame(2); | 1695 WaitForEncodedFrame(2); |
1644 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1696 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1645 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1697 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1646 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1698 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1647 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1699 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1648 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1700 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1649 | 1701 |
1650 // Trigger cpu adapt down, expect scaled down resolution (640x360). | 1702 // Trigger cpu adapt down, expect scaled down resolution (640x360). |
1651 vie_encoder_->TriggerCpuOveruse(); | 1703 vie_encoder_->TriggerCpuOveruse(); |
1652 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1704 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1653 sink_.WaitForEncodedFrame(3); | 1705 WaitForEncodedFrame(3); |
1654 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 1706 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
1655 rtc::VideoSinkWants last_wants = source.sink_wants(); | 1707 rtc::VideoSinkWants last_wants = source.sink_wants(); |
1656 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1708 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1657 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1709 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1658 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1710 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1659 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1711 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1660 | 1712 |
1661 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. | 1713 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. |
1662 vie_encoder_->TriggerCpuOveruse(); | 1714 vie_encoder_->TriggerCpuOveruse(); |
1663 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1715 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1664 sink_.WaitForEncodedFrame(4); | 1716 WaitForEncodedFrame(4); |
1665 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 1717 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
1666 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1718 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1667 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1719 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1668 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1720 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1669 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1721 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1670 | 1722 |
1671 // Trigger quality adapt down, expect scaled down resolution (480x270). | 1723 // Trigger quality adapt down, expect scaled down resolution (480x270). |
1672 vie_encoder_->TriggerQualityLow(); | 1724 vie_encoder_->TriggerQualityLow(); |
1673 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1725 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1674 sink_.WaitForEncodedFrame(5); | 1726 WaitForEncodedFrame(5); |
1675 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 1727 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
1676 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1728 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1677 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1729 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1678 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1730 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1679 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1731 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1680 | 1732 |
1681 // Trigger cpu adapt up, expect upscaled resolution (640x360). | 1733 // Trigger cpu adapt up, expect upscaled resolution (640x360). |
1682 vie_encoder_->TriggerCpuNormalUsage(); | 1734 vie_encoder_->TriggerCpuNormalUsage(); |
1683 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); | 1735 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
1684 sink_.WaitForEncodedFrame(6); | 1736 WaitForEncodedFrame(6); |
1685 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 1737 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
1686 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1738 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1687 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1739 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1688 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1740 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1689 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1741 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1690 | 1742 |
1691 // Trigger cpu adapt up, expect upscaled resolution (960x540). | 1743 // Trigger cpu adapt up, expect upscaled resolution (960x540). |
1692 vie_encoder_->TriggerCpuNormalUsage(); | 1744 vie_encoder_->TriggerCpuNormalUsage(); |
1693 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); | 1745 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); |
1694 sink_.WaitForEncodedFrame(7); | 1746 WaitForEncodedFrame(7); |
1695 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 1747 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
1696 last_wants = source.sink_wants(); | 1748 last_wants = source.sink_wants(); |
1697 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1749 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1698 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1750 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1699 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1751 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1700 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1752 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1701 | 1753 |
1702 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). | 1754 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). |
1703 vie_encoder_->TriggerCpuNormalUsage(); | 1755 vie_encoder_->TriggerCpuNormalUsage(); |
1704 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); | 1756 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); |
1705 sink_.WaitForEncodedFrame(8); | 1757 WaitForEncodedFrame(8); |
1706 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 1758 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
1707 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1759 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1708 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1760 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1709 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1761 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1710 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1762 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1711 | 1763 |
1712 // Trigger quality adapt up, expect no restriction (1280x720). | 1764 // Trigger quality adapt up, expect no restriction (1280x720). |
1713 vie_encoder_->TriggerQualityHigh(); | 1765 vie_encoder_->TriggerQualityHigh(); |
1714 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); | 1766 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); |
1715 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1767 WaitForEncodedFrame(kWidth, kHeight); |
1716 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 1768 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
1717 VerifyNoLimitation(source.sink_wants()); | 1769 VerifyNoLimitation(source.sink_wants()); |
1718 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1770 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1719 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1771 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1720 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1772 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1721 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1773 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1722 | 1774 |
1723 vie_encoder_->Stop(); | 1775 vie_encoder_->Stop(); |
1724 } | 1776 } |
1725 | 1777 |
1726 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) { | 1778 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) { |
1727 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
1728 const int kWidth = 640; | 1779 const int kWidth = 640; |
1729 const int kHeight = 360; | 1780 const int kHeight = 360; |
1730 | 1781 |
| 1782 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1783 |
1731 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 1784 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
1732 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1785 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1733 sink_.WaitForEncodedFrame(i); | 1786 WaitForEncodedFrame(i); |
1734 } | 1787 } |
1735 | 1788 |
1736 vie_encoder_->TriggerCpuOveruse(); | 1789 vie_encoder_->TriggerCpuOveruse(); |
1737 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 1790 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
1738 video_source_.IncomingCapturedFrame(CreateFrame( | 1791 video_source_.IncomingCapturedFrame(CreateFrame( |
1739 SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); | 1792 SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); |
1740 sink_.WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + | 1793 WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + i); |
1741 i); | |
1742 } | 1794 } |
1743 | 1795 |
1744 vie_encoder_->Stop(); | 1796 vie_encoder_->Stop(); |
1745 vie_encoder_.reset(); | 1797 vie_encoder_.reset(); |
1746 stats_proxy_.reset(); | 1798 stats_proxy_.reset(); |
1747 | 1799 |
1748 EXPECT_EQ(1, | 1800 EXPECT_EQ(1, |
1749 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 1801 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
1750 EXPECT_EQ( | 1802 EXPECT_EQ( |
1751 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); | 1803 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
1752 } | 1804 } |
1753 | 1805 |
1754 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsNotReportedForDisabledDegradation) { | 1806 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsNotReportedForDisabledDegradation) { |
1755 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1807 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1756 const int kWidth = 640; | 1808 const int kWidth = 640; |
1757 const int kHeight = 360; | 1809 const int kHeight = 360; |
1758 | 1810 |
1759 vie_encoder_->SetSource( | 1811 vie_encoder_->SetSource( |
1760 &video_source_, | 1812 &video_source_, |
1761 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1813 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1762 | 1814 |
1763 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 1815 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
1764 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1816 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1765 sink_.WaitForEncodedFrame(i); | 1817 WaitForEncodedFrame(i); |
1766 } | 1818 } |
1767 | 1819 |
1768 vie_encoder_->Stop(); | 1820 vie_encoder_->Stop(); |
1769 vie_encoder_.reset(); | 1821 vie_encoder_.reset(); |
1770 stats_proxy_.reset(); | 1822 stats_proxy_.reset(); |
1771 | 1823 |
1772 EXPECT_EQ(0, | 1824 EXPECT_EQ(0, |
1773 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 1825 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
1774 } | 1826 } |
1775 | 1827 |
(...skipping 10 matching lines...) Expand all Loading... |
1786 .GetAllocation(kLowTargetBitrateBps, kDefaultFps); | 1838 .GetAllocation(kLowTargetBitrateBps, kDefaultFps); |
1787 | 1839 |
1788 // First called on bitrate updated, then again on first frame. | 1840 // First called on bitrate updated, then again on first frame. |
1789 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1841 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
1790 .Times(2); | 1842 .Times(2); |
1791 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1843 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
1792 | 1844 |
1793 const int64_t kStartTimeMs = 1; | 1845 const int64_t kStartTimeMs = 1; |
1794 video_source_.IncomingCapturedFrame( | 1846 video_source_.IncomingCapturedFrame( |
1795 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); | 1847 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); |
1796 sink_.WaitForEncodedFrame(kStartTimeMs); | 1848 WaitForEncodedFrame(kStartTimeMs); |
1797 | 1849 |
1798 // Not called on second frame. | 1850 // Not called on second frame. |
1799 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1851 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
1800 .Times(0); | 1852 .Times(0); |
1801 video_source_.IncomingCapturedFrame( | 1853 video_source_.IncomingCapturedFrame( |
1802 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); | 1854 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); |
1803 sink_.WaitForEncodedFrame(kStartTimeMs + 1); | 1855 WaitForEncodedFrame(kStartTimeMs + 1); |
1804 | 1856 |
1805 // Called after a process interval. | 1857 // Called after a process interval. |
1806 const int64_t kProcessIntervalMs = | 1858 const int64_t kProcessIntervalMs = |
1807 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; | 1859 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; |
1808 // TODO(sprang): ViEEncoder should die and/or get injectable clock. | 1860 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec * |
1809 // Sleep for one processing interval plus one frame to avoid flakiness. | 1861 (kProcessIntervalMs + (1000 / kDefaultFps))); |
1810 SleepMs(kProcessIntervalMs + 1000 / kDefaultFps); | |
1811 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1862 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
1812 .Times(1); | 1863 .Times(1); |
1813 video_source_.IncomingCapturedFrame(CreateFrame( | 1864 video_source_.IncomingCapturedFrame(CreateFrame( |
1814 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); | 1865 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); |
1815 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); | 1866 WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); |
1816 | 1867 |
1817 vie_encoder_->Stop(); | 1868 vie_encoder_->Stop(); |
1818 } | 1869 } |
1819 | 1870 |
1820 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { | 1871 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { |
1821 const int kTooLowBitrateForFrameSizeBps = 10000; | 1872 const int kTooLowBitrateForFrameSizeBps = 10000; |
1822 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); | 1873 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
1823 const int kWidth = 640; | 1874 const int kWidth = 640; |
1824 const int kHeight = 360; | 1875 const int kHeight = 360; |
1825 | 1876 |
1826 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1877 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1827 | 1878 |
1828 // Expect to drop this frame, the wait should time out. | 1879 // Expect to drop this frame, the wait should time out. |
1829 sink_.ExpectDroppedFrame(); | 1880 ExpectDroppedFrame(); |
1830 | 1881 |
1831 // Expect the sink_wants to specify a scaled frame. | 1882 // Expect the sink_wants to specify a scaled frame. |
1832 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 1883 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
1833 | 1884 |
1834 int last_pixel_count = video_source_.sink_wants().max_pixel_count; | 1885 int last_pixel_count = video_source_.sink_wants().max_pixel_count; |
1835 | 1886 |
1836 // Next frame is scaled. | 1887 // Next frame is scaled. |
1837 video_source_.IncomingCapturedFrame( | 1888 video_source_.IncomingCapturedFrame( |
1838 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); | 1889 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); |
1839 | 1890 |
1840 // Expect to drop this frame, the wait should time out. | 1891 // Expect to drop this frame, the wait should time out. |
1841 sink_.ExpectDroppedFrame(); | 1892 ExpectDroppedFrame(); |
1842 | 1893 |
1843 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); | 1894 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); |
1844 | 1895 |
1845 vie_encoder_->Stop(); | 1896 vie_encoder_->Stop(); |
1846 } | 1897 } |
1847 | 1898 |
1848 TEST_F(ViEEncoderTest, NumberOfDroppedFramesLimitedWhenBitrateIsTooLow) { | 1899 TEST_F(ViEEncoderTest, NumberOfDroppedFramesLimitedWhenBitrateIsTooLow) { |
1849 const int kTooLowBitrateForFrameSizeBps = 10000; | 1900 const int kTooLowBitrateForFrameSizeBps = 10000; |
1850 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); | 1901 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
1851 const int kWidth = 640; | 1902 const int kWidth = 640; |
1852 const int kHeight = 360; | 1903 const int kHeight = 360; |
1853 | 1904 |
1854 // We expect the n initial frames to get dropped. | 1905 // We expect the n initial frames to get dropped. |
1855 int i; | 1906 int i; |
1856 for (i = 1; i <= kMaxInitialFramedrop; ++i) { | 1907 for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
1857 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1908 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1858 sink_.ExpectDroppedFrame(); | 1909 ExpectDroppedFrame(); |
1859 } | 1910 } |
1860 // The n+1th frame should not be dropped, even though it's size is too large. | 1911 // The n+1th frame should not be dropped, even though it's size is too large. |
1861 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1912 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1862 sink_.WaitForEncodedFrame(i); | 1913 WaitForEncodedFrame(i); |
1863 | 1914 |
1864 // Expect the sink_wants to specify a scaled frame. | 1915 // Expect the sink_wants to specify a scaled frame. |
1865 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 1916 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
1866 | 1917 |
1867 vie_encoder_->Stop(); | 1918 vie_encoder_->Stop(); |
1868 } | 1919 } |
1869 | 1920 |
1870 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { | 1921 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { |
1871 const int kWidth = 640; | 1922 const int kWidth = 640; |
1872 const int kHeight = 360; | 1923 const int kHeight = 360; |
1873 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1924 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
1874 | 1925 |
1875 // Set degradation preference. | 1926 // Set degradation preference. |
1876 vie_encoder_->SetSource( | 1927 vie_encoder_->SetSource( |
1877 &video_source_, | 1928 &video_source_, |
1878 VideoSendStream::DegradationPreference::kMaintainResolution); | 1929 VideoSendStream::DegradationPreference::kMaintainResolution); |
1879 | 1930 |
1880 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1931 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1881 // Frame should not be dropped, even if it's too large. | 1932 // Frame should not be dropped, even if it's too large. |
1882 sink_.WaitForEncodedFrame(1); | 1933 WaitForEncodedFrame(1); |
1883 | 1934 |
1884 vie_encoder_->Stop(); | 1935 vie_encoder_->Stop(); |
1885 } | 1936 } |
1886 | 1937 |
1887 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { | 1938 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { |
1888 const int kWidth = 640; | 1939 const int kWidth = 640; |
1889 const int kHeight = 360; | 1940 const int kHeight = 360; |
1890 fake_encoder_.SetQualityScaling(false); | 1941 fake_encoder_.SetQualityScaling(false); |
1891 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1942 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
1892 | 1943 |
1893 // Force quality scaler reconfiguration by resetting the source. | 1944 // Force quality scaler reconfiguration by resetting the source. |
1894 vie_encoder_->SetSource(&video_source_, | 1945 vie_encoder_->SetSource(&video_source_, |
1895 VideoSendStream::DegradationPreference::kBalanced); | 1946 VideoSendStream::DegradationPreference::kBalanced); |
1896 | 1947 |
1897 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1948 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1898 // Frame should not be dropped, even if it's too large. | 1949 // Frame should not be dropped, even if it's too large. |
1899 sink_.WaitForEncodedFrame(1); | 1950 WaitForEncodedFrame(1); |
1900 | 1951 |
1901 vie_encoder_->Stop(); | 1952 vie_encoder_->Stop(); |
1902 fake_encoder_.SetQualityScaling(true); | 1953 fake_encoder_.SetQualityScaling(true); |
1903 } | 1954 } |
1904 | 1955 |
1905 TEST_F(ViEEncoderTest, | 1956 TEST_F(ViEEncoderTest, |
1906 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) { | 1957 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) { |
1907 const int kTooSmallWidth = 10; | 1958 const int kTooSmallWidth = 10; |
1908 const int kTooSmallHeight = 10; | 1959 const int kTooSmallHeight = 10; |
1909 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1960 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1910 | 1961 |
1911 // Enable kMaintainFramerate preference, no initial limitation. | 1962 // Enable kMaintainFramerate preference, no initial limitation. |
1912 test::FrameForwarder source; | 1963 test::FrameForwarder source; |
1913 vie_encoder_->SetSource( | 1964 vie_encoder_->SetSource( |
1914 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1965 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1915 VerifyNoLimitation(source.sink_wants()); | 1966 VerifyNoLimitation(source.sink_wants()); |
1916 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1967 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1917 | 1968 |
1918 // Trigger adapt down, too small frame, expect no change. | 1969 // Trigger adapt down, too small frame, expect no change. |
1919 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); | 1970 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); |
1920 sink_.WaitForEncodedFrame(1); | 1971 WaitForEncodedFrame(1); |
1921 vie_encoder_->TriggerCpuOveruse(); | 1972 vie_encoder_->TriggerCpuOveruse(); |
1922 VerifyNoLimitation(source.sink_wants()); | 1973 VerifyNoLimitation(source.sink_wants()); |
1923 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1974 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1924 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1975 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1925 | 1976 |
1926 vie_encoder_->Stop(); | 1977 vie_encoder_->Stop(); |
1927 } | 1978 } |
1928 | 1979 |
1929 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { | 1980 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { |
1930 fake_encoder_.ForceInitEncodeFailure(true); | 1981 fake_encoder_.ForceInitEncodeFailure(true); |
1931 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1982 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1932 ResetEncoder("VP8", 2, 1, true); | 1983 ResetEncoder("VP8", 2, 1, true, false); |
1933 const int kFrameWidth = 1280; | 1984 const int kFrameWidth = 1280; |
1934 const int kFrameHeight = 720; | 1985 const int kFrameHeight = 720; |
1935 video_source_.IncomingCapturedFrame( | 1986 video_source_.IncomingCapturedFrame( |
1936 CreateFrame(1, kFrameWidth, kFrameHeight)); | 1987 CreateFrame(1, kFrameWidth, kFrameHeight)); |
1937 sink_.ExpectDroppedFrame(); | 1988 ExpectDroppedFrame(); |
1938 vie_encoder_->Stop(); | 1989 vie_encoder_->Stop(); |
1939 } | 1990 } |
1940 | 1991 |
1941 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. | 1992 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. |
1942 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse_MaintainFramerateMode) { | 1993 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse_MaintainFramerateMode) { |
1943 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1994 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1944 | 1995 |
1945 const int kFrameWidth = 1280; | 1996 const int kFrameWidth = 1280; |
1946 const int kFrameHeight = 720; | 1997 const int kFrameHeight = 720; |
1947 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as | 1998 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as |
1948 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). | 1999 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). |
1949 video_source_.set_adaptation_enabled(true); | 2000 video_source_.set_adaptation_enabled(true); |
1950 | 2001 |
1951 video_source_.IncomingCapturedFrame( | 2002 video_source_.IncomingCapturedFrame( |
1952 CreateFrame(1, kFrameWidth, kFrameHeight)); | 2003 CreateFrame(1, kFrameWidth, kFrameHeight)); |
1953 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 2004 WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
1954 | 2005 |
1955 // Trigger CPU overuse, downscale by 3/4. | 2006 // Trigger CPU overuse, downscale by 3/4. |
1956 vie_encoder_->TriggerCpuOveruse(); | 2007 vie_encoder_->TriggerCpuOveruse(); |
1957 video_source_.IncomingCapturedFrame( | 2008 video_source_.IncomingCapturedFrame( |
1958 CreateFrame(2, kFrameWidth, kFrameHeight)); | 2009 CreateFrame(2, kFrameWidth, kFrameHeight)); |
1959 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); | 2010 WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
1960 | 2011 |
1961 // Trigger CPU normal use, return to original resolution. | 2012 // Trigger CPU normal use, return to original resolution. |
1962 vie_encoder_->TriggerCpuNormalUsage(); | 2013 vie_encoder_->TriggerCpuNormalUsage(); |
1963 video_source_.IncomingCapturedFrame( | 2014 video_source_.IncomingCapturedFrame( |
1964 CreateFrame(3, kFrameWidth, kFrameHeight)); | 2015 CreateFrame(3, kFrameWidth, kFrameHeight)); |
1965 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 2016 WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
1966 | 2017 |
1967 vie_encoder_->Stop(); | 2018 vie_encoder_->Stop(); |
1968 } | 2019 } |
1969 | 2020 |
1970 TEST_F(ViEEncoderTest, AdaptsFramerateOnOveruse_MaintainResolutionMode) { | 2021 TEST_F(ViEEncoderTest, AdaptsFramerateOnOveruse_MaintainResolutionMode) { |
1971 const int kDefaultFramerateFps = 30; | 2022 // const int kDefaultFramerateFps = 30; |
1972 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kDefaultFramerateFps; | |
1973 const int kFrameWidth = 1280; | 2023 const int kFrameWidth = 1280; |
1974 const int kFrameHeight = 720; | 2024 const int kFrameHeight = 720; |
1975 rtc::ScopedFakeClock fake_clock; | 2025 int kFrameIntervalMs = rtc::kNumMillisecsPerSec / max_framerate_; |
1976 | 2026 |
1977 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2027 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1978 vie_encoder_->SetSource( | 2028 vie_encoder_->SetSource( |
1979 &video_source_, | 2029 &video_source_, |
1980 VideoSendStream::DegradationPreference::kMaintainResolution); | 2030 VideoSendStream::DegradationPreference::kMaintainResolution); |
1981 video_source_.set_adaptation_enabled(true); | 2031 video_source_.set_adaptation_enabled(true); |
1982 | 2032 |
1983 fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); | 2033 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
1984 int64_t timestamp_ms = kFrameIntervalMs; | |
1985 | 2034 |
1986 video_source_.IncomingCapturedFrame( | 2035 video_source_.IncomingCapturedFrame( |
1987 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2036 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
1988 sink_.WaitForEncodedFrame(timestamp_ms); | 2037 WaitForEncodedFrame(timestamp_ms); |
1989 | 2038 |
1990 // Try to trigger overuse. No fps estimate available => no effect. | 2039 // Try to trigger overuse. No fps estimate available => no effect. |
1991 vie_encoder_->TriggerCpuOveruse(); | 2040 vie_encoder_->TriggerCpuOveruse(); |
1992 | 2041 |
1993 // Insert frames for one second to get a stable estimate. | 2042 // Insert frames for one second to get a stable estimate. |
1994 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2043 for (int i = 0; i < max_framerate_; ++i) { |
1995 timestamp_ms += kFrameIntervalMs; | 2044 timestamp_ms += kFrameIntervalMs; |
1996 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
1997 video_source_.IncomingCapturedFrame( | 2045 video_source_.IncomingCapturedFrame( |
1998 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2046 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
1999 sink_.WaitForEncodedFrame(timestamp_ms); | 2047 WaitForEncodedFrame(timestamp_ms); |
2000 } | 2048 } |
2001 | 2049 |
2002 // Trigger CPU overuse, reduce framerate by 2/3. | 2050 // Trigger CPU overuse, reduce framerate by 2/3. |
2003 vie_encoder_->TriggerCpuOveruse(); | 2051 vie_encoder_->TriggerCpuOveruse(); |
2004 int num_frames_dropped = 0; | 2052 int num_frames_dropped = 0; |
2005 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2053 for (int i = 0; i < max_framerate_; ++i) { |
2006 timestamp_ms += kFrameIntervalMs; | 2054 timestamp_ms += kFrameIntervalMs; |
2007 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
2008 video_source_.IncomingCapturedFrame( | 2055 video_source_.IncomingCapturedFrame( |
2009 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2056 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2010 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | 2057 if (!WaitForFrame(kFrameTimeoutMs)) { |
2011 ++num_frames_dropped; | 2058 ++num_frames_dropped; |
2012 } else { | 2059 } else { |
2013 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2060 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2014 } | 2061 } |
2015 } | 2062 } |
2016 | 2063 |
2017 // TODO(sprang): Find where there's rounding errors or stuff causing the | 2064 // Add some slack to account for frames dropped by the frame dropper. |
2018 // margin here to be a little larger than we'd like (input fps estimate is | 2065 const int kErrorMargin = 1; |
2019 // off) and the frame dropping is a little too aggressive. | 2066 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), |
2020 const int kErrorMargin = 5; | |
2021 EXPECT_NEAR(num_frames_dropped, | |
2022 kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), | |
2023 kErrorMargin); | 2067 kErrorMargin); |
2024 | 2068 |
2025 // Trigger CPU overuse, reduce framerate by 2/3 again. | 2069 // Trigger CPU overuse, reduce framerate by 2/3 again. |
2026 vie_encoder_->TriggerCpuOveruse(); | 2070 vie_encoder_->TriggerCpuOveruse(); |
2027 num_frames_dropped = 0; | 2071 num_frames_dropped = 0; |
2028 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2072 for (int i = 0; i < max_framerate_; ++i) { |
2029 timestamp_ms += kFrameIntervalMs; | 2073 timestamp_ms += kFrameIntervalMs; |
2030 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
2031 video_source_.IncomingCapturedFrame( | 2074 video_source_.IncomingCapturedFrame( |
2032 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2075 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2033 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | 2076 if (!WaitForFrame(kFrameTimeoutMs)) { |
2034 ++num_frames_dropped; | 2077 ++num_frames_dropped; |
2035 } else { | 2078 } else { |
2036 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2079 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2037 } | 2080 } |
2038 } | 2081 } |
2039 EXPECT_NEAR(num_frames_dropped, | 2082 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 4 / 9), |
2040 kDefaultFramerateFps - (kDefaultFramerateFps * 4 / 9), | |
2041 kErrorMargin); | 2083 kErrorMargin); |
2042 | 2084 |
2043 // Go back up one step. | 2085 // Go back up one step. |
2044 vie_encoder_->TriggerCpuNormalUsage(); | 2086 vie_encoder_->TriggerCpuNormalUsage(); |
2045 num_frames_dropped = 0; | 2087 num_frames_dropped = 0; |
2046 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2088 for (int i = 0; i < max_framerate_; ++i) { |
2047 timestamp_ms += kFrameIntervalMs; | 2089 timestamp_ms += kFrameIntervalMs; |
2048 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
2049 video_source_.IncomingCapturedFrame( | 2090 video_source_.IncomingCapturedFrame( |
2050 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2091 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2051 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | 2092 if (!WaitForFrame(kFrameTimeoutMs)) { |
2052 ++num_frames_dropped; | 2093 ++num_frames_dropped; |
2053 } else { | 2094 } else { |
2054 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2095 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2055 } | 2096 } |
2056 } | 2097 } |
2057 EXPECT_NEAR(num_frames_dropped, | 2098 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), |
2058 kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), | |
2059 kErrorMargin); | 2099 kErrorMargin); |
2060 | 2100 |
2061 // Go back up to original mode. | 2101 // Go back up to original mode. |
2062 vie_encoder_->TriggerCpuNormalUsage(); | 2102 vie_encoder_->TriggerCpuNormalUsage(); |
2063 num_frames_dropped = 0; | 2103 num_frames_dropped = 0; |
2064 for (int i = 0; i < kDefaultFramerateFps; ++i) { | 2104 for (int i = 0; i < max_framerate_; ++i) { |
2065 timestamp_ms += kFrameIntervalMs; | 2105 timestamp_ms += kFrameIntervalMs; |
2066 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
2067 video_source_.IncomingCapturedFrame( | 2106 video_source_.IncomingCapturedFrame( |
2068 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2107 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2069 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { | 2108 if (!WaitForFrame(kFrameTimeoutMs)) { |
2070 ++num_frames_dropped; | 2109 ++num_frames_dropped; |
2071 } else { | 2110 } else { |
2072 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2111 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2073 } | 2112 } |
2074 } | 2113 } |
2075 EXPECT_NEAR(num_frames_dropped, 0, kErrorMargin); | 2114 EXPECT_NEAR(num_frames_dropped, 0, kErrorMargin); |
2076 | 2115 |
2077 vie_encoder_->Stop(); | 2116 vie_encoder_->Stop(); |
2078 } | 2117 } |
2079 | 2118 |
2080 TEST_F(ViEEncoderTest, DoesntAdaptDownPastMinFramerate) { | 2119 TEST_F(ViEEncoderTest, DoesntAdaptDownPastMinFramerate) { |
2081 const int kFramerateFps = 5; | 2120 const int kFramerateFps = 5; |
2082 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kFramerateFps; | 2121 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kFramerateFps; |
2083 const int kMinFpsFrameInterval = rtc::kNumMillisecsPerSec / kMinFramerateFps; | 2122 const int kMinFpsFrameInterval = rtc::kNumMillisecsPerSec / kMinFramerateFps; |
2084 const int kFrameWidth = 1280; | 2123 const int kFrameWidth = 1280; |
2085 const int kFrameHeight = 720; | 2124 const int kFrameHeight = 720; |
2086 | 2125 |
2087 rtc::ScopedFakeClock fake_clock; | 2126 // Reconfigure encoder with two temporal layers and screensharing, which will |
| 2127 // disable frame dropping and make testing easier. |
| 2128 ResetEncoder("VP8", 1, 2, true, true); |
| 2129 |
2088 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2130 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2089 vie_encoder_->SetSource( | 2131 vie_encoder_->SetSource( |
2090 &video_source_, | 2132 &video_source_, |
2091 VideoSendStream::DegradationPreference::kMaintainResolution); | 2133 VideoSendStream::DegradationPreference::kMaintainResolution); |
2092 video_source_.set_adaptation_enabled(true); | 2134 video_source_.set_adaptation_enabled(true); |
2093 | 2135 |
2094 fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); | 2136 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
2095 int64_t timestamp_ms = kFrameIntervalMs; | |
2096 | 2137 |
2097 // Trigger overuse as much as we can. | 2138 // Trigger overuse as much as we can. |
2098 for (int i = 0; i < ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { | 2139 for (int i = 0; i < ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { |
2099 // Insert frames to get a new fps estimate... | 2140 // Insert frames to get a new fps estimate... |
2100 for (int j = 0; j < kFramerateFps; ++j) { | 2141 for (int j = 0; j < kFramerateFps; ++j) { |
2101 video_source_.IncomingCapturedFrame( | 2142 video_source_.IncomingCapturedFrame( |
2102 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2143 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2103 timestamp_ms += kFrameIntervalMs; | 2144 timestamp_ms += kFrameIntervalMs; |
2104 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); | |
2105 } | 2145 } |
2106 // ...and then try to adapt again. | 2146 // ...and then try to adapt again. |
2107 vie_encoder_->TriggerCpuOveruse(); | 2147 vie_encoder_->TriggerCpuOveruse(); |
2108 } | 2148 } |
2109 | 2149 |
2110 // Drain any frame in the pipeline. | 2150 // Drain any frame in the pipeline. |
2111 sink_.WaitForFrame(kDefaultTimeoutMs); | 2151 WaitForFrame(kDefaultTimeoutMs); |
2112 | 2152 |
2113 // Insert frames at min fps, all should go through. | 2153 // Insert frames at min fps, all should go through. |
2114 for (int i = 0; i < 10; ++i) { | 2154 for (int i = 0; i < 10; ++i) { |
2115 timestamp_ms += kMinFpsFrameInterval; | 2155 timestamp_ms += kMinFpsFrameInterval; |
2116 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); | |
2117 video_source_.IncomingCapturedFrame( | 2156 video_source_.IncomingCapturedFrame( |
2118 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2157 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2119 sink_.WaitForEncodedFrame(timestamp_ms); | 2158 WaitForEncodedFrame(timestamp_ms); |
2120 } | 2159 } |
2121 vie_encoder_->Stop(); | 2160 vie_encoder_->Stop(); |
2122 } | 2161 } |
| 2162 |
| 2163 TEST_F(ViEEncoderTest, PriodicallyUpdatesChannelParameters) { |
| 2164 const int kFrameWidth = 1280; |
| 2165 const int kFrameHeight = 720; |
| 2166 const int kLowFps = 2; |
| 2167 const int kHighFps = 30; |
| 2168 |
| 2169 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2170 |
| 2171 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
| 2172 max_framerate_ = kLowFps; |
| 2173 |
| 2174 // Insert 2 seconds of 2fps video. |
| 2175 for (int i = 0; i < kLowFps * 2; ++i) { |
| 2176 video_source_.IncomingCapturedFrame( |
| 2177 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2178 WaitForEncodedFrame(timestamp_ms); |
| 2179 timestamp_ms += 1000 / kLowFps; |
| 2180 } |
| 2181 |
| 2182 // Make sure encoder is updated with new target. |
| 2183 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2184 video_source_.IncomingCapturedFrame( |
| 2185 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2186 WaitForEncodedFrame(timestamp_ms); |
| 2187 timestamp_ms += 1000 / kLowFps; |
| 2188 |
| 2189 EXPECT_EQ(kLowFps, fake_encoder_.GetConfiguredInputFramerate()); |
| 2190 |
| 2191 // Insert 30fps frames for just a little more than the forced update period. |
| 2192 const int kVcmTimerIntervalFrames = |
| 2193 (vcm::VCMProcessTimer::kDefaultProcessIntervalMs * kHighFps) / 1000; |
| 2194 const int kFrameIntervalMs = 1000 / kHighFps; |
| 2195 max_framerate_ = kHighFps; |
| 2196 for (int i = 0; i < kVcmTimerIntervalFrames + 2; ++i) { |
| 2197 video_source_.IncomingCapturedFrame( |
| 2198 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
| 2199 // Wait for encoded frame, but skip ahead if it doesn't arrive as it might |
| 2200 // be dropped if the encoder hans't been updated with the new higher target |
| 2201 // framerate yet, causing it to overshoot the target bitrate and then |
| 2202 // suffering the wrath of the media optimizer. |
| 2203 TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameIntervalMs); |
| 2204 timestamp_ms += kFrameIntervalMs; |
| 2205 } |
| 2206 |
| 2207 // Don expect correct measurement just yet, but it should be higher than |
| 2208 // before. |
| 2209 EXPECT_GT(fake_encoder_.GetConfiguredInputFramerate(), kLowFps); |
| 2210 |
| 2211 vie_encoder_->Stop(); |
| 2212 } |
2123 } // namespace webrtc | 2213 } // namespace webrtc |
OLD | NEW |