blob: f00b32df6e147dccabe145f90090964ef18d7e7b [file] [log] [blame]
mflodman@webrtc.orgf8f91d62013-06-26 11:23:011/*
2 * Copyright (c) 2013 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
kwibergda89edd2016-03-01 19:52:3311#include <memory>
12
perkj089bf9f2016-09-07 13:32:1813#include "webrtc/base/event.h"
Henrik Kjellander78f65d02015-10-28 17:17:4014#include "webrtc/system_wrappers/include/clock.h"
kwiberg36a24792016-10-01 05:29:4315#include "webrtc/test/gmock.h"
16#include "webrtc/test/gtest.h"
17#include "webrtc/video/overuse_frame_detector.h"
Peter Boström211f6642016-02-05 10:13:2818#include "webrtc/video_frame.h"
mflodman@webrtc.orgf8f91d62013-06-26 11:23:0119
mflodman@webrtc.orgf8f91d62013-06-26 11:23:0120namespace webrtc {
perkj089bf9f2016-09-07 13:32:1821
22using ::testing::Invoke;
23
asapersson@webrtc.org9da327c2014-03-20 13:15:0124namespace {
25 const int kWidth = 640;
26 const int kHeight = 480;
27 const int kFrameInterval33ms = 33;
28 const int kProcessIntervalMs = 5000;
Åsa Persson2f7bdec2015-09-08 08:52:4229 const int kProcessTime5ms = 5;
asapersson@webrtc.org9da327c2014-03-20 13:15:0130} // namespace
mflodman@webrtc.orgf8f91d62013-06-26 11:23:0131
mflodman@webrtc.orgbf76ae22013-07-23 11:35:0032class MockCpuOveruseObserver : public CpuOveruseObserver {
mflodman@webrtc.orgf8f91d62013-06-26 11:23:0133 public:
mflodman@webrtc.orgbf76ae22013-07-23 11:35:0034 MockCpuOveruseObserver() {}
35 virtual ~MockCpuOveruseObserver() {}
mflodman@webrtc.orgf8f91d62013-06-26 11:23:0136
37 MOCK_METHOD0(OveruseDetected, void());
mflodman@webrtc.orgbf76ae22013-07-23 11:35:0038 MOCK_METHOD0(NormalUsage, void());
mflodman@webrtc.orgf8f91d62013-06-26 11:23:0139};
40
asapersson@webrtc.org9da327c2014-03-20 13:15:0141class CpuOveruseObserverImpl : public CpuOveruseObserver {
42 public:
43 CpuOveruseObserverImpl() :
44 overuse_(0),
45 normaluse_(0) {}
46 virtual ~CpuOveruseObserverImpl() {}
47
48 void OveruseDetected() { ++overuse_; }
49 void NormalUsage() { ++normaluse_; }
50
51 int overuse_;
52 int normaluse_;
53};
54
perkj089bf9f2016-09-07 13:32:1855class OveruseFrameDetectorUnderTest : public OveruseFrameDetector {
56 public:
57 OveruseFrameDetectorUnderTest(Clock* clock,
58 const CpuOveruseOptions& options,
59 CpuOveruseObserver* overuse_observer,
60 EncodedFrameObserver* encoder_timing,
61 CpuOveruseMetricsObserver* metrics_observer)
62 : OveruseFrameDetector(clock,
63 options,
64 overuse_observer,
65 encoder_timing,
66 metrics_observer) {}
67 ~OveruseFrameDetectorUnderTest() {}
68
69 using OveruseFrameDetector::CheckForOveruse;
70};
71
pbos@webrtc.org6ec81f82015-02-26 12:19:3172class OveruseFrameDetectorTest : public ::testing::Test,
73 public CpuOveruseMetricsObserver {
mflodman@webrtc.orgf8f91d62013-06-26 11:23:0174 protected:
nisse44dc40f2016-04-29 13:09:1575 void SetUp() override {
mflodman@webrtc.orgf8f91d62013-06-26 11:23:0176 clock_.reset(new SimulatedClock(1234));
mflodman@webrtc.orgbf76ae22013-07-23 11:35:0077 observer_.reset(new MockCpuOveruseObserver());
asapersson@webrtc.org9da327c2014-03-20 13:15:0178 options_.min_process_count = 0;
Peter Boströmd5d98ba2015-06-26 04:58:1679 ReinitializeOveruseDetector();
80 }
81
82 void ReinitializeOveruseDetector() {
perkj089bf9f2016-09-07 13:32:1883 overuse_detector_.reset(new OveruseFrameDetectorUnderTest(
Peter Boström211f6642016-02-05 10:13:2884 clock_.get(), options_, observer_.get(), nullptr, this));
mflodman@webrtc.orgf8f91d62013-06-26 11:23:0185 }
mflodman@webrtc.orgcb9a72b2013-07-31 16:42:2186
Peter Boström211f6642016-02-05 10:13:2887 void OnEncodedFrameTimeMeasured(int encode_time_ms,
88 const CpuOveruseMetrics& metrics) override {
pbos@webrtc.org6ec81f82015-02-26 12:19:3189 metrics_ = metrics;
90 }
91
asapersson@webrtc.orgd9387772014-10-16 06:57:1292 int InitialUsage() {
asapersson@webrtc.org154951d2014-03-24 21:59:1693 return ((options_.low_encode_usage_threshold_percent +
94 options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5;
95 }
96
Peter Boström211f6642016-02-05 10:13:2897 void InsertAndSendFramesWithInterval(int num_frames,
98 int interval_ms,
99 int width,
100 int height,
101 int delay_ms) {
nisse952cf0f2016-10-05 06:27:30102 VideoFrame frame(I420Buffer::Create(width, height),
103 webrtc::kVideoRotation_0, 0);
Peter Boström211f6642016-02-05 10:13:28104 uint32_t timestamp = 0;
asapersson@webrtc.org154951d2014-03-24 21:59:16105 while (num_frames-- > 0) {
Peter Boström211f6642016-02-05 10:13:28106 frame.set_timestamp(timestamp);
perkj089bf9f2016-09-07 13:32:18107 overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds());
asapersson@webrtc.orgd9387772014-10-16 06:57:12108 clock_->AdvanceTimeMilliseconds(delay_ms);
perkj089bf9f2016-09-07 13:32:18109 overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds());
asapersson@webrtc.orgd9387772014-10-16 06:57:12110 clock_->AdvanceTimeMilliseconds(interval_ms - delay_ms);
Peter Boström211f6642016-02-05 10:13:28111 timestamp += interval_ms * 90;
asapersson@webrtc.org154951d2014-03-24 21:59:16112 }
113 }
114
Peter Boström211f6642016-02-05 10:13:28115 void ForceUpdate(int width, int height) {
116 // Insert one frame, wait a second and then put in another to force update
117 // the usage. From the tests where these are used, adding another sample
118 // doesn't affect the expected outcome (this is mainly to check initial
119 // values and whether the overuse detector has been reset or not).
120 InsertAndSendFramesWithInterval(2, 1000, width, height, kFrameInterval33ms);
121 }
asapersson@webrtc.org9da327c2014-03-20 13:15:01122 void TriggerOveruse(int num_times) {
asapersson@webrtc.orgd9387772014-10-16 06:57:12123 const int kDelayMs = 32;
asapersson@webrtc.org154951d2014-03-24 21:59:16124 for (int i = 0; i < num_times; ++i) {
asapersson@webrtc.orgd9387772014-10-16 06:57:12125 InsertAndSendFramesWithInterval(
126 1000, kFrameInterval33ms, kWidth, kHeight, kDelayMs);
perkj089bf9f2016-09-07 13:32:18127 overuse_detector_->CheckForOveruse();
asapersson@webrtc.org154951d2014-03-24 21:59:16128 }
129 }
130
Åsa Persson2f7bdec2015-09-08 08:52:42131 void TriggerUnderuse() {
asapersson@webrtc.orgd9387772014-10-16 06:57:12132 const int kDelayMs1 = 5;
133 const int kDelayMs2 = 6;
134 InsertAndSendFramesWithInterval(
135 1300, kFrameInterval33ms, kWidth, kHeight, kDelayMs1);
136 InsertAndSendFramesWithInterval(
137 1, kFrameInterval33ms, kWidth, kHeight, kDelayMs2);
perkj089bf9f2016-09-07 13:32:18138 overuse_detector_->CheckForOveruse();
asapersson@webrtc.org154951d2014-03-24 21:59:16139 }
140
pbos@webrtc.org6ec81f82015-02-26 12:19:31141 int UsagePercent() { return metrics_.encode_usage_percent; }
asapersson@webrtc.org4e954362014-05-27 07:43:15142
asapersson@webrtc.org9da327c2014-03-20 13:15:01143 CpuOveruseOptions options_;
kwibergda89edd2016-03-01 19:52:33144 std::unique_ptr<SimulatedClock> clock_;
145 std::unique_ptr<MockCpuOveruseObserver> observer_;
perkj089bf9f2016-09-07 13:32:18146 std::unique_ptr<OveruseFrameDetectorUnderTest> overuse_detector_;
pbos@webrtc.org6ec81f82015-02-26 12:19:31147 CpuOveruseMetrics metrics_;
mflodman@webrtc.orgf8f91d62013-06-26 11:23:01148};
149
Åsa Persson2f7bdec2015-09-08 08:52:42150
Åsa Persson2f7bdec2015-09-08 08:52:42151// UsagePercent() > high_encode_usage_threshold_percent => overuse.
152// UsagePercent() < low_encode_usage_threshold_percent => underuse.
mflodman@webrtc.orgf8f91d62013-06-26 11:23:01153TEST_F(OveruseFrameDetectorTest, TriggerOveruse) {
Åsa Persson2f7bdec2015-09-08 08:52:42154 // usage > high => overuse
asapersson@webrtc.org9da327c2014-03-20 13:15:01155 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
156 TriggerOveruse(options_.high_threshold_consecutive_count);
mflodman@webrtc.orgcb9a72b2013-07-31 16:42:21157}
158
159TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) {
Åsa Persson2f7bdec2015-09-08 08:52:42160 // usage > high => overuse
asapersson@webrtc.org9da327c2014-03-20 13:15:01161 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
162 TriggerOveruse(options_.high_threshold_consecutive_count);
Åsa Persson2f7bdec2015-09-08 08:52:42163 // usage < low => underuse
asapersson@webrtc.org9da327c2014-03-20 13:15:01164 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
asapersson@webrtc.orgd9387772014-10-16 06:57:12165 TriggerUnderuse();
asapersson@webrtc.org9da327c2014-03-20 13:15:01166}
167
asapersson@webrtc.orgf6eaabf2014-06-12 08:46:46168TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) {
perkj089bf9f2016-09-07 13:32:18169 overuse_detector_.reset(new OveruseFrameDetectorUnderTest(
170 clock_.get(), options_, nullptr, nullptr, this));
asapersson@webrtc.org9da327c2014-03-20 13:15:01171 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
172 TriggerOveruse(options_.high_threshold_consecutive_count);
173 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
asapersson@webrtc.orgd9387772014-10-16 06:57:12174 TriggerUnderuse();
asapersson@webrtc.org9da327c2014-03-20 13:15:01175}
176
mflodman@webrtc.orgcb9a72b2013-07-31 16:42:21177TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) {
asapersson@webrtc.org9da327c2014-03-20 13:15:01178 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(2);
179 TriggerOveruse(options_.high_threshold_consecutive_count);
180 TriggerOveruse(options_.high_threshold_consecutive_count);
181 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
asapersson@webrtc.orgd9387772014-10-16 06:57:12182 TriggerUnderuse();
pbos@webrtc.orgce9de712013-08-30 17:16:32183}
mflodman@webrtc.orgcb9a72b2013-07-31 16:42:21184
asapersson@webrtc.orgd9387772014-10-16 06:57:12185TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) {
asapersson@webrtc.org9da327c2014-03-20 13:15:01186 options_.min_process_count = 1;
Peter Boströmd5d98ba2015-06-26 04:58:16187 CpuOveruseObserverImpl overuse_observer;
perkj089bf9f2016-09-07 13:32:18188 overuse_detector_.reset(new OveruseFrameDetectorUnderTest(
Peter Boström211f6642016-02-05 10:13:28189 clock_.get(), options_, &overuse_observer, nullptr, this));
Åsa Persson2f7bdec2015-09-08 08:52:42190 InsertAndSendFramesWithInterval(
191 1200, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
perkj089bf9f2016-09-07 13:32:18192 overuse_detector_->CheckForOveruse();
Peter Boströmd5d98ba2015-06-26 04:58:16193 EXPECT_EQ(0, overuse_observer.normaluse_);
asapersson@webrtc.org9da327c2014-03-20 13:15:01194 clock_->AdvanceTimeMilliseconds(kProcessIntervalMs);
perkj089bf9f2016-09-07 13:32:18195 overuse_detector_->CheckForOveruse();
Peter Boströmd5d98ba2015-06-26 04:58:16196 EXPECT_EQ(1, overuse_observer.normaluse_);
asapersson@webrtc.org99507962014-02-17 19:02:15197}
198
pbos@webrtc.orgce9de712013-08-30 17:16:32199TEST_F(OveruseFrameDetectorTest, ConstantOveruseGivesNoNormalUsage) {
mflodman@webrtc.orgcb9a72b2013-07-31 16:42:21200 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
asapersson@webrtc.org9da327c2014-03-20 13:15:01201 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(64);
kjellander@webrtc.org1069bd82015-11-26 14:24:52202 for (size_t i = 0; i < 64; ++i) {
asapersson@webrtc.org9da327c2014-03-20 13:15:01203 TriggerOveruse(options_.high_threshold_consecutive_count);
204 }
mflodman@webrtc.orgcb9a72b2013-07-31 16:42:21205}
206
asapersson@webrtc.org9da327c2014-03-20 13:15:01207TEST_F(OveruseFrameDetectorTest, ConsecutiveCountTriggersOveruse) {
Peter Boströmd5d98ba2015-06-26 04:58:16208 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
asapersson@webrtc.org9da327c2014-03-20 13:15:01209 options_.high_threshold_consecutive_count = 2;
Peter Boströmd5d98ba2015-06-26 04:58:16210 ReinitializeOveruseDetector();
asapersson@webrtc.org9da327c2014-03-20 13:15:01211 TriggerOveruse(2);
212}
213
214TEST_F(OveruseFrameDetectorTest, IncorrectConsecutiveCountTriggersNoOveruse) {
Peter Boströmd5d98ba2015-06-26 04:58:16215 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
asapersson@webrtc.org9da327c2014-03-20 13:15:01216 options_.high_threshold_consecutive_count = 2;
Peter Boströmd5d98ba2015-06-26 04:58:16217 ReinitializeOveruseDetector();
asapersson@webrtc.org9da327c2014-03-20 13:15:01218 TriggerOveruse(1);
219}
220
Åsa Persson2f7bdec2015-09-08 08:52:42221TEST_F(OveruseFrameDetectorTest, ProcessingUsage) {
222 InsertAndSendFramesWithInterval(
223 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
224 EXPECT_EQ(kProcessTime5ms * 100 / kFrameInterval33ms, UsagePercent());
asapersson@webrtc.org9da327c2014-03-20 13:15:01225}
226
Åsa Persson2f7bdec2015-09-08 08:52:42227TEST_F(OveruseFrameDetectorTest, ResetAfterResolutionChange) {
Peter Boström211f6642016-02-05 10:13:28228 ForceUpdate(kWidth, kHeight);
Åsa Persson2f7bdec2015-09-08 08:52:42229 EXPECT_EQ(InitialUsage(), UsagePercent());
230 InsertAndSendFramesWithInterval(
231 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
232 EXPECT_NE(InitialUsage(), UsagePercent());
Peter Boström211f6642016-02-05 10:13:28233 // Verify reset (with new width/height).
234 ForceUpdate(kWidth, kHeight + 1);
Åsa Persson2f7bdec2015-09-08 08:52:42235 EXPECT_EQ(InitialUsage(), UsagePercent());
asapersson@webrtc.org9da327c2014-03-20 13:15:01236}
237
Åsa Persson2f7bdec2015-09-08 08:52:42238TEST_F(OveruseFrameDetectorTest, ResetAfterFrameTimeout) {
Peter Boström211f6642016-02-05 10:13:28239 ForceUpdate(kWidth, kHeight);
Åsa Persson2f7bdec2015-09-08 08:52:42240 EXPECT_EQ(InitialUsage(), UsagePercent());
241 InsertAndSendFramesWithInterval(
242 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
243 EXPECT_NE(InitialUsage(), UsagePercent());
244 InsertAndSendFramesWithInterval(
245 2, options_.frame_timeout_interval_ms, kWidth, kHeight, kProcessTime5ms);
246 EXPECT_NE(InitialUsage(), UsagePercent());
asapersson@webrtc.org9da327c2014-03-20 13:15:01247 // Verify reset.
Åsa Persson2f7bdec2015-09-08 08:52:42248 InsertAndSendFramesWithInterval(
249 2, options_.frame_timeout_interval_ms + 1, kWidth, kHeight,
250 kProcessTime5ms);
Peter Boström211f6642016-02-05 10:13:28251 ForceUpdate(kWidth, kHeight);
Åsa Persson2f7bdec2015-09-08 08:52:42252 EXPECT_EQ(InitialUsage(), UsagePercent());
asapersson@webrtc.org9da327c2014-03-20 13:15:01253}
254
Åsa Persson2f7bdec2015-09-08 08:52:42255TEST_F(OveruseFrameDetectorTest, MinFrameSamplesBeforeUpdating) {
asapersson@webrtc.org9da327c2014-03-20 13:15:01256 options_.min_frame_samples = 40;
Peter Boströmd5d98ba2015-06-26 04:58:16257 ReinitializeOveruseDetector();
Åsa Persson2f7bdec2015-09-08 08:52:42258 InsertAndSendFramesWithInterval(
259 40, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
260 EXPECT_EQ(InitialUsage(), UsagePercent());
Peter Boström211f6642016-02-05 10:13:28261 // Pass time far enough to digest all previous samples.
262 clock_->AdvanceTimeMilliseconds(1000);
263 InsertAndSendFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight,
264 kProcessTime5ms);
265 // The last sample has not been processed here.
266 EXPECT_EQ(InitialUsage(), UsagePercent());
267
268 // Pass time far enough to digest all previous samples, 41 in total.
269 clock_->AdvanceTimeMilliseconds(1000);
Åsa Persson2f7bdec2015-09-08 08:52:42270 InsertAndSendFramesWithInterval(
271 1, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
272 EXPECT_NE(InitialUsage(), UsagePercent());
273}
274
275TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) {
Peter Boström211f6642016-02-05 10:13:28276 ForceUpdate(kWidth, kHeight);
Åsa Persson2f7bdec2015-09-08 08:52:42277 EXPECT_EQ(InitialUsage(), UsagePercent());
asapersson@webrtc.org47475852013-11-20 13:51:40278}
279
Peter Boström211f6642016-02-05 10:13:28280TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) {
281 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(testing::AtLeast(1));
282 static const int kIntervalMs = 33;
283 static const size_t kNumFramesEncodingDelay = 3;
nisse952cf0f2016-10-05 06:27:30284 VideoFrame frame(I420Buffer::Create(kWidth, kHeight),
285 webrtc::kVideoRotation_0, 0);
Peter Boström211f6642016-02-05 10:13:28286 for (size_t i = 0; i < 1000; ++i) {
287 // Unique timestamps.
288 frame.set_timestamp(static_cast<uint32_t>(i));
perkj089bf9f2016-09-07 13:32:18289 overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds());
Peter Boström211f6642016-02-05 10:13:28290 clock_->AdvanceTimeMilliseconds(kIntervalMs);
291 if (i > kNumFramesEncodingDelay) {
292 overuse_detector_->FrameSent(
perkj089bf9f2016-09-07 13:32:18293 static_cast<uint32_t>(i - kNumFramesEncodingDelay),
294 clock_->TimeInMilliseconds());
Peter Boström211f6642016-02-05 10:13:28295 }
perkj089bf9f2016-09-07 13:32:18296 overuse_detector_->CheckForOveruse();
asapersson@webrtc.orgd9387772014-10-16 06:57:12297 }
asapersson@webrtc.orgd9387772014-10-16 06:57:12298}
299
Peter Boström211f6642016-02-05 10:13:28300TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) {
301 // >85% encoding time should trigger overuse.
302 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(testing::AtLeast(1));
303 static const int kIntervalMs = 33;
304 static const int kDelayMs = 30;
nisse952cf0f2016-10-05 06:27:30305 VideoFrame frame(I420Buffer::Create(kWidth, kHeight),
306 webrtc::kVideoRotation_0, 0);
Peter Boström211f6642016-02-05 10:13:28307 uint32_t timestamp = 0;
308 for (size_t i = 0; i < 1000; ++i) {
309 frame.set_timestamp(timestamp);
perkj089bf9f2016-09-07 13:32:18310 overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds());
Peter Boström211f6642016-02-05 10:13:28311 // Encode and send first parts almost instantly.
312 clock_->AdvanceTimeMilliseconds(1);
perkj089bf9f2016-09-07 13:32:18313 overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds());
Peter Boström211f6642016-02-05 10:13:28314 // Encode heavier part, resulting in >85% usage total.
315 clock_->AdvanceTimeMilliseconds(kDelayMs - 1);
perkj089bf9f2016-09-07 13:32:18316 overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds());
Peter Boström211f6642016-02-05 10:13:28317 clock_->AdvanceTimeMilliseconds(kIntervalMs - kDelayMs);
318 timestamp += kIntervalMs * 90;
perkj089bf9f2016-09-07 13:32:18319 overuse_detector_->CheckForOveruse();
Peter Boström211f6642016-02-05 10:13:28320 }
asapersson@webrtc.orgd9387772014-10-16 06:57:12321}
322
perkj089bf9f2016-09-07 13:32:18323TEST_F(OveruseFrameDetectorTest, RunOnTqNormalUsage) {
324 rtc::TaskQueue queue("OveruseFrameDetectorTestQueue");
325
326 rtc::Event event(false, false);
327 queue.PostTask([this, &event] {
328 overuse_detector_->StartCheckForOveruse();
329 event.Set();
330 });
331 event.Wait(rtc::Event::kForever);
332
333 // Expect NormalUsage(). When called, stop the |overuse_detector_| and then
334 // set |event| to end the test.
335 EXPECT_CALL(*(observer_.get()), NormalUsage())
336 .WillOnce(Invoke([this, &event] {
337 overuse_detector_->StopCheckForOveruse();
338 event.Set();
339 }));
340
341 queue.PostTask([this, &event] {
342 const int kDelayMs1 = 5;
343 const int kDelayMs2 = 6;
344 InsertAndSendFramesWithInterval(1300, kFrameInterval33ms, kWidth, kHeight,
345 kDelayMs1);
346 InsertAndSendFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight,
347 kDelayMs2);
348 });
349
350 EXPECT_TRUE(event.Wait(10000));
351}
352
mflodman@webrtc.orgf8f91d62013-06-26 11:23:01353} // namespace webrtc