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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 int overuse_; | 51 int overuse_; |
52 int normaluse_; | 52 int normaluse_; |
53 }; | 53 }; |
54 | 54 |
55 class OveruseFrameDetectorUnderTest : public OveruseFrameDetector { | 55 class OveruseFrameDetectorUnderTest : public OveruseFrameDetector { |
56 public: | 56 public: |
57 OveruseFrameDetectorUnderTest(Clock* clock, | 57 OveruseFrameDetectorUnderTest(Clock* clock, |
58 const CpuOveruseOptions& options, | 58 const CpuOveruseOptions& options, |
59 CpuOveruseObserver* overuse_observer, | 59 CpuOveruseObserver* overuse_observer, |
60 EncodedFrameObserver* encoder_timing, | |
61 CpuOveruseMetricsObserver* metrics_observer) | 60 CpuOveruseMetricsObserver* metrics_observer) |
62 : OveruseFrameDetector(clock, | 61 : OveruseFrameDetector(clock, |
63 options, | 62 options, |
64 overuse_observer, | 63 overuse_observer, |
65 encoder_timing, | |
66 metrics_observer) {} | 64 metrics_observer) {} |
67 ~OveruseFrameDetectorUnderTest() {} | 65 ~OveruseFrameDetectorUnderTest() {} |
68 | 66 |
69 using OveruseFrameDetector::CheckForOveruse; | 67 using OveruseFrameDetector::CheckForOveruse; |
70 }; | 68 }; |
71 | 69 |
72 class OveruseFrameDetectorTest : public ::testing::Test, | 70 class OveruseFrameDetectorTest : public ::testing::Test, |
73 public CpuOveruseMetricsObserver { | 71 public CpuOveruseMetricsObserver { |
74 protected: | 72 protected: |
75 void SetUp() override { | 73 void SetUp() override { |
76 clock_.reset(new SimulatedClock(1234)); | 74 clock_.reset(new SimulatedClock(1234)); |
77 observer_.reset(new MockCpuOveruseObserver()); | 75 observer_.reset(new MockCpuOveruseObserver()); |
78 options_.min_process_count = 0; | 76 options_.min_process_count = 0; |
79 ReinitializeOveruseDetector(); | 77 ReinitializeOveruseDetector(); |
80 } | 78 } |
81 | 79 |
82 void ReinitializeOveruseDetector() { | 80 void ReinitializeOveruseDetector() { |
83 overuse_detector_.reset(new OveruseFrameDetectorUnderTest( | 81 overuse_detector_.reset(new OveruseFrameDetectorUnderTest( |
84 clock_.get(), options_, observer_.get(), nullptr, this)); | 82 clock_.get(), options_, observer_.get(), this)); |
85 } | 83 } |
86 | 84 |
87 void OnEncodedFrameTimeMeasured(int encode_time_ms, | 85 void OnEncodedFrameTimeMeasured(int encode_time_ms, |
88 const CpuOveruseMetrics& metrics) override { | 86 const CpuOveruseMetrics& metrics) override { |
89 metrics_ = metrics; | 87 metrics_ = metrics; |
90 } | 88 } |
91 | 89 |
92 int InitialUsage() { | 90 int InitialUsage() { |
93 return ((options_.low_encode_usage_threshold_percent + | 91 return ((options_.low_encode_usage_threshold_percent + |
94 options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5; | 92 options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) { | 157 TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) { |
160 // usage > high => overuse | 158 // usage > high => overuse |
161 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); | 159 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); |
162 TriggerOveruse(options_.high_threshold_consecutive_count); | 160 TriggerOveruse(options_.high_threshold_consecutive_count); |
163 // usage < low => underuse | 161 // usage < low => underuse |
164 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); | 162 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); |
165 TriggerUnderuse(); | 163 TriggerUnderuse(); |
166 } | 164 } |
167 | 165 |
168 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) { | 166 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) { |
169 overuse_detector_.reset(new OveruseFrameDetectorUnderTest( | 167 overuse_detector_.reset( |
170 clock_.get(), options_, nullptr, nullptr, this)); | 168 new OveruseFrameDetectorUnderTest(clock_.get(), options_, nullptr, this)); |
171 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); | 169 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); |
172 TriggerOveruse(options_.high_threshold_consecutive_count); | 170 TriggerOveruse(options_.high_threshold_consecutive_count); |
173 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); | 171 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); |
174 TriggerUnderuse(); | 172 TriggerUnderuse(); |
175 } | 173 } |
176 | 174 |
177 TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) { | 175 TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) { |
178 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(2); | 176 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(2); |
179 TriggerOveruse(options_.high_threshold_consecutive_count); | 177 TriggerOveruse(options_.high_threshold_consecutive_count); |
180 TriggerOveruse(options_.high_threshold_consecutive_count); | 178 TriggerOveruse(options_.high_threshold_consecutive_count); |
181 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); | 179 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); |
182 TriggerUnderuse(); | 180 TriggerUnderuse(); |
183 } | 181 } |
184 | 182 |
185 TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) { | 183 TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) { |
186 options_.min_process_count = 1; | 184 options_.min_process_count = 1; |
187 CpuOveruseObserverImpl overuse_observer; | 185 CpuOveruseObserverImpl overuse_observer; |
188 overuse_detector_.reset(new OveruseFrameDetectorUnderTest( | 186 overuse_detector_.reset(new OveruseFrameDetectorUnderTest( |
189 clock_.get(), options_, &overuse_observer, nullptr, this)); | 187 clock_.get(), options_, &overuse_observer, this)); |
190 InsertAndSendFramesWithInterval( | 188 InsertAndSendFramesWithInterval( |
191 1200, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); | 189 1200, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
192 overuse_detector_->CheckForOveruse(); | 190 overuse_detector_->CheckForOveruse(); |
193 EXPECT_EQ(0, overuse_observer.normaluse_); | 191 EXPECT_EQ(0, overuse_observer.normaluse_); |
194 clock_->AdvanceTimeMilliseconds(kProcessIntervalMs); | 192 clock_->AdvanceTimeMilliseconds(kProcessIntervalMs); |
195 overuse_detector_->CheckForOveruse(); | 193 overuse_detector_->CheckForOveruse(); |
196 EXPECT_EQ(1, overuse_observer.normaluse_); | 194 EXPECT_EQ(1, overuse_observer.normaluse_); |
197 } | 195 } |
198 | 196 |
199 TEST_F(OveruseFrameDetectorTest, ConstantOveruseGivesNoNormalUsage) { | 197 TEST_F(OveruseFrameDetectorTest, ConstantOveruseGivesNoNormalUsage) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 TEST_F(OveruseFrameDetectorTest, RunOnTqNormalUsage) { | 321 TEST_F(OveruseFrameDetectorTest, RunOnTqNormalUsage) { |
324 rtc::TaskQueue queue("OveruseFrameDetectorTestQueue"); | 322 rtc::TaskQueue queue("OveruseFrameDetectorTestQueue"); |
325 | 323 |
326 rtc::Event event(false, false); | 324 rtc::Event event(false, false); |
327 queue.PostTask([this, &event] { | 325 queue.PostTask([this, &event] { |
328 overuse_detector_->StartCheckForOveruse(); | 326 overuse_detector_->StartCheckForOveruse(); |
329 event.Set(); | 327 event.Set(); |
330 }); | 328 }); |
331 event.Wait(rtc::Event::kForever); | 329 event.Wait(rtc::Event::kForever); |
332 | 330 |
333 // Expect NormalUsage(). When called, stop the |overuse_detector_| and then | 331 // Expect NormalUsage(). |
334 // set |event| to end the test. | |
335 EXPECT_CALL(*(observer_.get()), NormalUsage()) | 332 EXPECT_CALL(*(observer_.get()), NormalUsage()) |
336 .WillOnce(Invoke([this, &event] { | 333 .WillOnce(Invoke([this, &event] { |
337 overuse_detector_->StopCheckForOveruse(); | |
338 event.Set(); | 334 event.Set(); |
339 })); | 335 })); |
340 | 336 |
341 queue.PostTask([this, &event] { | 337 queue.PostTask([this, &event] { |
342 const int kDelayMs1 = 5; | 338 const int kDelayMs1 = 5; |
343 const int kDelayMs2 = 6; | 339 const int kDelayMs2 = 6; |
344 InsertAndSendFramesWithInterval(1300, kFrameInterval33ms, kWidth, kHeight, | 340 InsertAndSendFramesWithInterval(1300, kFrameInterval33ms, kWidth, kHeight, |
345 kDelayMs1); | 341 kDelayMs1); |
346 InsertAndSendFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight, | 342 InsertAndSendFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight, |
347 kDelayMs2); | 343 kDelayMs2); |
348 }); | 344 }); |
349 | 345 |
| 346 // Wait for NormalUsage(). |
| 347 EXPECT_TRUE(event.Wait(10000)); |
| 348 |
| 349 // Delete the detector on TQ. |
| 350 queue.PostTask([this, &event] { |
| 351 overuse_detector_.reset(); |
| 352 event.Set(); |
| 353 }); |
350 EXPECT_TRUE(event.Wait(10000)); | 354 EXPECT_TRUE(event.Wait(10000)); |
351 } | 355 } |
352 | 356 |
353 } // namespace webrtc | 357 } // namespace webrtc |
OLD | NEW |