OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 net_config.delay_standard_deviation_ms = 10; | 466 net_config.delay_standard_deviation_ms = 10; |
467 // TODO(wu): lower the threshold as the calculation/estimatation becomes more | 467 // TODO(wu): lower the threshold as the calculation/estimatation becomes more |
468 // accurate. | 468 // accurate. |
469 const int kThresholdMs = 100; | 469 const int kThresholdMs = 100; |
470 const int kStartTimeMs = 10000; | 470 const int kStartTimeMs = 10000; |
471 const int kRunTimeMs = 20000; | 471 const int kRunTimeMs = 20000; |
472 TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs); | 472 TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs); |
473 } | 473 } |
474 | 474 |
475 TEST_F(CallPerfTest, ReceivesCpuOveruseAndUnderuse) { | 475 TEST_F(CallPerfTest, ReceivesCpuOveruseAndUnderuse) { |
| 476 // Set fake encoder delay to 150% (3/2) of time limit when simulating overuse. |
| 477 const int kOveruseFrameIntervalMs = (3 * 1000) / (2 * kDefaultFramerate); |
| 478 |
476 class LoadObserver : public test::SendTest, | 479 class LoadObserver : public test::SendTest, |
477 public test::FrameGeneratorCapturer::SinkWantsObserver { | 480 public test::FrameGeneratorCapturer::SinkWantsObserver { |
478 public: | 481 public: |
479 LoadObserver() | 482 LoadObserver() |
480 : SendTest(kLongTimeoutMs), | 483 : SendTest(kLongTimeoutMs), |
481 expect_lower_resolution_wants_(true), | 484 test_phase_(TestPhase::kStart), |
482 encoder_(Clock::GetRealTimeClock(), 60 /* delay_ms */) {} | 485 encoder_(Clock::GetRealTimeClock(), kOveruseFrameIntervalMs) {} |
483 | 486 |
484 void OnFrameGeneratorCapturerCreated( | 487 void OnFrameGeneratorCapturerCreated( |
485 test::FrameGeneratorCapturer* frame_generator_capturer) override { | 488 test::FrameGeneratorCapturer* frame_generator_capturer) override { |
486 frame_generator_capturer->SetSinkWantsObserver(this); | 489 frame_generator_capturer->SetSinkWantsObserver(this); |
487 // Set a high initial resolution to be sure that we can scale down. | 490 // Set a high initial resolution to be sure that we can scale down. |
488 frame_generator_capturer->ChangeResolution(1920, 1080); | 491 frame_generator_capturer->ChangeResolution(1920, 1080); |
489 } | 492 } |
490 | 493 |
491 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink | 494 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink |
492 // is called. | 495 // is called. |
| 496 // TODO(sprang): Add integration test for maintain-framerate mode? |
493 void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink, | 497 void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink, |
494 const rtc::VideoSinkWants& wants) override { | 498 const rtc::VideoSinkWants& wants) override { |
495 // First expect CPU overuse. Then expect CPU underuse when the encoder | 499 // First expect CPU overuse. Then expect CPU underuse when the encoder |
496 // delay has been decreased. | 500 // delay has been decreased. |
497 if (wants.target_pixel_count && | 501 switch (test_phase_) { |
498 *wants.target_pixel_count < | 502 case TestPhase::kStart: |
499 wants.max_pixel_count.value_or(std::numeric_limits<int>::max())) { | 503 if (wants.max_pixel_count < std::numeric_limits<int>::max()) { |
500 // On adapting up, ViEEncoder::VideoSourceProxy will set the target | 504 // On adapting down, ViEEncoder::VideoSourceProxy will set only the |
501 // pixel count to a step up from the current and the max value to | 505 // max pixel count, leaving the target unset. |
502 // something higher than the target. | 506 test_phase_ = TestPhase::kAdaptedDown; |
503 EXPECT_FALSE(expect_lower_resolution_wants_); | 507 encoder_.SetDelay(2); |
504 observation_complete_.Set(); | 508 } else { |
505 } else if (wants.max_pixel_count) { | 509 ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
506 // On adapting down, ViEEncoder::VideoSourceProxy will set only the max | 510 << wants.max_pixel_count << ", target res = " |
507 // pixel count, leaving the target unset. | 511 << wants.target_pixel_count.value_or(-1) |
508 EXPECT_TRUE(expect_lower_resolution_wants_); | 512 << ", max fps = " << wants.max_framerate_fps; |
509 expect_lower_resolution_wants_ = false; | 513 } |
510 encoder_.SetDelay(2); | 514 break; |
| 515 case TestPhase::kAdaptedDown: |
| 516 // On adapting up, the adaptation counter will again be at zero, and |
| 517 // so all constraints will be reset. |
| 518 if (wants.max_pixel_count == std::numeric_limits<int>::max() && |
| 519 !wants.target_pixel_count) { |
| 520 test_phase_ = TestPhase::kAdaptedUp; |
| 521 observation_complete_.Set(); |
| 522 } else { |
| 523 ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
| 524 << wants.max_pixel_count << ", target res = " |
| 525 << wants.target_pixel_count.value_or(-1) |
| 526 << ", max fps = " << wants.max_framerate_fps; |
| 527 } |
| 528 break; |
| 529 case TestPhase::kAdaptedUp: |
| 530 ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
| 531 << wants.max_pixel_count << ", target res = " |
| 532 << wants.target_pixel_count.value_or(-1) |
| 533 << ", max fps = " << wants.max_framerate_fps; |
511 } | 534 } |
512 } | 535 } |
513 | 536 |
514 void ModifyVideoConfigs( | 537 void ModifyVideoConfigs( |
515 VideoSendStream::Config* send_config, | 538 VideoSendStream::Config* send_config, |
516 std::vector<VideoReceiveStream::Config>* receive_configs, | 539 std::vector<VideoReceiveStream::Config>* receive_configs, |
517 VideoEncoderConfig* encoder_config) override { | 540 VideoEncoderConfig* encoder_config) override { |
518 send_config->encoder_settings.encoder = &encoder_; | 541 send_config->encoder_settings.encoder = &encoder_; |
519 } | 542 } |
520 | 543 |
521 void PerformTest() override { | 544 void PerformTest() override { |
522 EXPECT_TRUE(Wait()) << "Timed out before receiving an overuse callback."; | 545 EXPECT_TRUE(Wait()) << "Timed out before receiving an overuse callback."; |
523 } | 546 } |
524 | 547 |
525 bool expect_lower_resolution_wants_; | 548 enum class TestPhase { kStart, kAdaptedDown, kAdaptedUp } test_phase_; |
526 test::DelayedEncoder encoder_; | 549 test::DelayedEncoder encoder_; |
527 } test; | 550 } test; |
528 | 551 |
529 RunBaseTest(&test); | 552 RunBaseTest(&test); |
530 } | 553 } |
531 | 554 |
532 void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) { | 555 void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) { |
533 static const int kMaxEncodeBitrateKbps = 30; | 556 static const int kMaxEncodeBitrateKbps = 30; |
534 static const int kMinTransmitBitrateBps = 150000; | 557 static const int kMinTransmitBitrateBps = 150000; |
535 static const int kMinAcceptableTransmitBitrate = 130; | 558 static const int kMinAcceptableTransmitBitrate = 130; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 uint32_t last_set_bitrate_kbps_; | 762 uint32_t last_set_bitrate_kbps_; |
740 VideoSendStream* send_stream_; | 763 VideoSendStream* send_stream_; |
741 test::FrameGeneratorCapturer* frame_generator_; | 764 test::FrameGeneratorCapturer* frame_generator_; |
742 VideoEncoderConfig encoder_config_; | 765 VideoEncoderConfig encoder_config_; |
743 } test; | 766 } test; |
744 | 767 |
745 RunBaseTest(&test); | 768 RunBaseTest(&test); |
746 } | 769 } |
747 | 770 |
748 } // namespace webrtc | 771 } // namespace webrtc |
OLD | NEW |