You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
5.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <limits>
  11. #include <vector>
  12. #include "api/rtp_parameters.h"
  13. #include "api/video/video_frame.h"
  14. #include "api/video/video_sink_interface.h"
  15. #include "api/video/video_source_interface.h"
  16. #include "api/video_codecs/video_encoder_config.h"
  17. #include "call/video_receive_stream.h"
  18. #include "call/video_send_stream.h"
  19. #include "rtc_base/checks.h"
  20. #include "rtc_base/event.h"
  21. #include "test/call_test.h"
  22. #include "test/field_trial.h"
  23. #include "test/frame_generator_capturer.h"
  24. #include "test/gtest.h"
  25. namespace webrtc {
  26. namespace {
  27. constexpr int kWidth = 1280;
  28. constexpr int kHeight = 720;
  29. constexpr int kFps = 28;
  30. } // namespace
  31. // Minimal normal usage at start, then 60s overuse.
  32. class CpuOveruseTest : public test::CallTest {
  33. protected:
  34. CpuOveruseTest()
  35. : field_trials_("WebRTC-ForceSimulatedOveruseIntervalMs/1-60000-60000/") {
  36. }
  37. void RunTestAndCheckForAdaptation(
  38. const DegradationPreference& degradation_preference,
  39. bool expect_adaptation);
  40. test::ScopedFieldTrials field_trials_;
  41. };
  42. void CpuOveruseTest::RunTestAndCheckForAdaptation(
  43. const DegradationPreference& degradation_preference,
  44. bool expect_adaptation) {
  45. class OveruseObserver
  46. : public test::SendTest,
  47. public test::FrameGeneratorCapturer::SinkWantsObserver {
  48. public:
  49. OveruseObserver(const DegradationPreference& degradation_preference,
  50. bool expect_adaptation)
  51. : SendTest(expect_adaptation ? kLongTimeoutMs : kDefaultTimeoutMs),
  52. degradation_preference_(degradation_preference),
  53. expect_adaptation_(expect_adaptation) {}
  54. private:
  55. void OnFrameGeneratorCapturerCreated(
  56. test::FrameGeneratorCapturer* frame_generator_capturer) override {
  57. frame_generator_capturer->SetSinkWantsObserver(this);
  58. // Set initial resolution.
  59. frame_generator_capturer->ChangeResolution(kWidth, kHeight);
  60. }
  61. // Called when FrameGeneratorCapturer::AddOrUpdateSink is called.
  62. void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
  63. const rtc::VideoSinkWants& wants) override {
  64. if (wants.max_pixel_count == std::numeric_limits<int>::max() &&
  65. wants.max_framerate_fps == kFps) {
  66. // Max configured framerate is initially set.
  67. return;
  68. }
  69. switch (degradation_preference_) {
  70. case DegradationPreference::MAINTAIN_FRAMERATE:
  71. EXPECT_LT(wants.max_pixel_count, kWidth * kHeight);
  72. observation_complete_.Set();
  73. break;
  74. case DegradationPreference::MAINTAIN_RESOLUTION:
  75. EXPECT_LT(wants.max_framerate_fps, kFps);
  76. observation_complete_.Set();
  77. break;
  78. case DegradationPreference::BALANCED:
  79. if (wants.max_pixel_count == std::numeric_limits<int>::max() &&
  80. wants.max_framerate_fps == std::numeric_limits<int>::max()) {
  81. // |adapt_counters_| map in VideoStreamEncoder is reset when
  82. // balanced mode is set.
  83. break;
  84. }
  85. EXPECT_TRUE(wants.max_pixel_count < kWidth * kHeight ||
  86. wants.max_framerate_fps < kFps);
  87. observation_complete_.Set();
  88. break;
  89. default:
  90. RTC_NOTREACHED();
  91. }
  92. }
  93. void ModifyVideoConfigs(
  94. VideoSendStream::Config* send_config,
  95. std::vector<VideoReceiveStream::Config>* receive_configs,
  96. VideoEncoderConfig* encoder_config) override {
  97. EXPECT_FALSE(encoder_config->simulcast_layers.empty());
  98. encoder_config->simulcast_layers[0].max_framerate = kFps;
  99. }
  100. void ModifyVideoDegradationPreference(
  101. DegradationPreference* degradation_preference) override {
  102. *degradation_preference = degradation_preference_;
  103. }
  104. void PerformTest() override {
  105. EXPECT_EQ(expect_adaptation_, Wait())
  106. << "Timed out while waiting for a scale down.";
  107. }
  108. const DegradationPreference degradation_preference_;
  109. const bool expect_adaptation_;
  110. } test(degradation_preference, expect_adaptation);
  111. RunBaseTest(&test);
  112. }
  113. TEST_F(CpuOveruseTest, AdaptsDownInResolutionOnOveruse) {
  114. RunTestAndCheckForAdaptation(DegradationPreference::MAINTAIN_FRAMERATE, true);
  115. }
  116. TEST_F(CpuOveruseTest, AdaptsDownInFpsOnOveruse) {
  117. RunTestAndCheckForAdaptation(DegradationPreference::MAINTAIN_RESOLUTION,
  118. true);
  119. }
  120. TEST_F(CpuOveruseTest, AdaptsDownInResolutionOrFpsOnOveruse) {
  121. RunTestAndCheckForAdaptation(DegradationPreference::BALANCED, true);
  122. }
  123. TEST_F(CpuOveruseTest, NoAdaptDownOnOveruse) {
  124. RunTestAndCheckForAdaptation(DegradationPreference::DISABLED, false);
  125. }
  126. } // namespace webrtc