Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: webrtc/video/overuse_frame_detector_unittest.cc

Issue 2652893015: Rename adaptation api methods, extended vie_encoder unit test. (Closed)
Patch Set: Rebase, again Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/overuse_frame_detector.cc ('k') | webrtc/video/vie_encoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 23
24 using ::testing::InvokeWithoutArgs; 24 using ::testing::InvokeWithoutArgs;
25 25
26 namespace { 26 namespace {
27 const int kWidth = 640; 27 const int kWidth = 640;
28 const int kHeight = 480; 28 const int kHeight = 480;
29 const int kFrameIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; 29 const int kFrameIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec;
30 const int kProcessTimeUs = 5 * rtc::kNumMicrosecsPerMillisec; 30 const int kProcessTimeUs = 5 * rtc::kNumMicrosecsPerMillisec;
31 } // namespace 31 } // namespace
32 32
33 class MockCpuOveruseObserver : public ScalingObserverInterface { 33 class MockCpuOveruseObserver : public AdaptationObserverInterface {
34 public: 34 public:
35 MockCpuOveruseObserver() {} 35 MockCpuOveruseObserver() {}
36 virtual ~MockCpuOveruseObserver() {} 36 virtual ~MockCpuOveruseObserver() {}
37 37
38 MOCK_METHOD1(ScaleUp, void(ScaleReason)); 38 MOCK_METHOD1(AdaptUp, void(AdaptReason));
39 MOCK_METHOD1(ScaleDown, void(ScaleReason)); 39 MOCK_METHOD1(AdaptDown, void(AdaptReason));
40 }; 40 };
41 41
42 class CpuOveruseObserverImpl : public ScalingObserverInterface { 42 class CpuOveruseObserverImpl : public AdaptationObserverInterface {
43 public: 43 public:
44 CpuOveruseObserverImpl() : 44 CpuOveruseObserverImpl() :
45 overuse_(0), 45 overuse_(0),
46 normaluse_(0) {} 46 normaluse_(0) {}
47 virtual ~CpuOveruseObserverImpl() {} 47 virtual ~CpuOveruseObserverImpl() {}
48 48
49 void ScaleDown(ScaleReason) { ++overuse_; } 49 void AdaptDown(AdaptReason) { ++overuse_; }
50 void ScaleUp(ScaleReason) { ++normaluse_; } 50 void AdaptUp(AdaptReason) { ++normaluse_; }
51 51
52 int overuse_; 52 int overuse_;
53 int normaluse_; 53 int normaluse_;
54 }; 54 };
55 55
56 class OveruseFrameDetectorUnderTest : public OveruseFrameDetector { 56 class OveruseFrameDetectorUnderTest : public OveruseFrameDetector {
57 public: 57 public:
58 OveruseFrameDetectorUnderTest(const CpuOveruseOptions& options, 58 OveruseFrameDetectorUnderTest(const CpuOveruseOptions& options,
59 ScalingObserverInterface* overuse_observer, 59 AdaptationObserverInterface* overuse_observer,
60 EncodedFrameObserver* encoder_timing, 60 EncodedFrameObserver* encoder_timing,
61 CpuOveruseMetricsObserver* metrics_observer) 61 CpuOveruseMetricsObserver* metrics_observer)
62 : OveruseFrameDetector(options, 62 : OveruseFrameDetector(options,
63 overuse_observer, 63 overuse_observer,
64 encoder_timing, 64 encoder_timing,
65 metrics_observer) {} 65 metrics_observer) {}
66 ~OveruseFrameDetectorUnderTest() {} 66 ~OveruseFrameDetectorUnderTest() {}
67 67
68 using OveruseFrameDetector::CheckForOveruse; 68 using OveruseFrameDetector::CheckForOveruse;
69 }; 69 };
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 139
140 int UsagePercent() { return metrics_.encode_usage_percent; } 140 int UsagePercent() { return metrics_.encode_usage_percent; }
141 141
142 CpuOveruseOptions options_; 142 CpuOveruseOptions options_;
143 rtc::ScopedFakeClock clock_; 143 rtc::ScopedFakeClock clock_;
144 std::unique_ptr<MockCpuOveruseObserver> observer_; 144 std::unique_ptr<MockCpuOveruseObserver> observer_;
145 std::unique_ptr<OveruseFrameDetectorUnderTest> overuse_detector_; 145 std::unique_ptr<OveruseFrameDetectorUnderTest> overuse_detector_;
146 CpuOveruseMetrics metrics_; 146 CpuOveruseMetrics metrics_;
147 147
148 static const auto reason_ = ScalingObserverInterface::ScaleReason::kCpu; 148 static const auto reason_ = AdaptationObserverInterface::AdaptReason::kCpu;
149 }; 149 };
150 150
151 151
152 // UsagePercent() > high_encode_usage_threshold_percent => overuse. 152 // UsagePercent() > high_encode_usage_threshold_percent => overuse.
153 // UsagePercent() < low_encode_usage_threshold_percent => underuse. 153 // UsagePercent() < low_encode_usage_threshold_percent => underuse.
154 TEST_F(OveruseFrameDetectorTest, TriggerOveruse) { 154 TEST_F(OveruseFrameDetectorTest, TriggerOveruse) {
155 // usage > high => overuse 155 // usage > high => overuse
156 EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)).Times(1); 156 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)).Times(1);
157 TriggerOveruse(options_.high_threshold_consecutive_count); 157 TriggerOveruse(options_.high_threshold_consecutive_count);
158 } 158 }
159 159
160 TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) { 160 TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) {
161 // usage > high => overuse 161 // usage > high => overuse
162 EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)).Times(1); 162 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)).Times(1);
163 TriggerOveruse(options_.high_threshold_consecutive_count); 163 TriggerOveruse(options_.high_threshold_consecutive_count);
164 // usage < low => underuse 164 // usage < low => underuse
165 EXPECT_CALL(*(observer_.get()), ScaleUp(reason_)).Times(testing::AtLeast(1)); 165 EXPECT_CALL(*(observer_.get()), AdaptUp(reason_)).Times(testing::AtLeast(1));
166 TriggerUnderuse(); 166 TriggerUnderuse();
167 } 167 }
168 168
169 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) { 169 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) {
170 overuse_detector_.reset(new OveruseFrameDetectorUnderTest( 170 overuse_detector_.reset(new OveruseFrameDetectorUnderTest(
171 options_, nullptr, nullptr, this)); 171 options_, nullptr, nullptr, this));
172 EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)).Times(0); 172 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)).Times(0);
173 TriggerOveruse(options_.high_threshold_consecutive_count); 173 TriggerOveruse(options_.high_threshold_consecutive_count);
174 EXPECT_CALL(*(observer_.get()), ScaleUp(reason_)).Times(0); 174 EXPECT_CALL(*(observer_.get()), AdaptUp(reason_)).Times(0);
175 TriggerUnderuse(); 175 TriggerUnderuse();
176 } 176 }
177 177
178 TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) { 178 TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) {
179 EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)).Times(2); 179 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)).Times(2);
180 TriggerOveruse(options_.high_threshold_consecutive_count); 180 TriggerOveruse(options_.high_threshold_consecutive_count);
181 TriggerOveruse(options_.high_threshold_consecutive_count); 181 TriggerOveruse(options_.high_threshold_consecutive_count);
182 EXPECT_CALL(*(observer_.get()), ScaleUp(reason_)).Times(testing::AtLeast(1)); 182 EXPECT_CALL(*(observer_.get()), AdaptUp(reason_)).Times(testing::AtLeast(1));
183 TriggerUnderuse(); 183 TriggerUnderuse();
184 } 184 }
185 185
186 TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) { 186 TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) {
187 const int kProcessIntervalUs = 5 * rtc::kNumMicrosecsPerSec; 187 const int kProcessIntervalUs = 5 * rtc::kNumMicrosecsPerSec;
188 options_.min_process_count = 1; 188 options_.min_process_count = 1;
189 CpuOveruseObserverImpl overuse_observer; 189 CpuOveruseObserverImpl overuse_observer;
190 overuse_detector_.reset(new OveruseFrameDetectorUnderTest( 190 overuse_detector_.reset(new OveruseFrameDetectorUnderTest(
191 options_, &overuse_observer, nullptr, this)); 191 options_, &overuse_observer, nullptr, this));
192 InsertAndSendFramesWithInterval( 192 InsertAndSendFramesWithInterval(
193 1200, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); 193 1200, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs);
194 overuse_detector_->CheckForOveruse(); 194 overuse_detector_->CheckForOveruse();
195 EXPECT_EQ(0, overuse_observer.normaluse_); 195 EXPECT_EQ(0, overuse_observer.normaluse_);
196 clock_.AdvanceTimeMicros(kProcessIntervalUs); 196 clock_.AdvanceTimeMicros(kProcessIntervalUs);
197 overuse_detector_->CheckForOveruse(); 197 overuse_detector_->CheckForOveruse();
198 EXPECT_EQ(1, overuse_observer.normaluse_); 198 EXPECT_EQ(1, overuse_observer.normaluse_);
199 } 199 }
200 200
201 TEST_F(OveruseFrameDetectorTest, ConstantOveruseGivesNoNormalUsage) { 201 TEST_F(OveruseFrameDetectorTest, ConstantOveruseGivesNoNormalUsage) {
202 EXPECT_CALL(*(observer_.get()), ScaleUp(reason_)).Times(0); 202 EXPECT_CALL(*(observer_.get()), AdaptUp(reason_)).Times(0);
203 EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)).Times(64); 203 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)).Times(64);
204 for (size_t i = 0; i < 64; ++i) { 204 for (size_t i = 0; i < 64; ++i) {
205 TriggerOveruse(options_.high_threshold_consecutive_count); 205 TriggerOveruse(options_.high_threshold_consecutive_count);
206 } 206 }
207 } 207 }
208 208
209 TEST_F(OveruseFrameDetectorTest, ConsecutiveCountTriggersOveruse) { 209 TEST_F(OveruseFrameDetectorTest, ConsecutiveCountTriggersOveruse) {
210 EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)).Times(1); 210 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)).Times(1);
211 options_.high_threshold_consecutive_count = 2; 211 options_.high_threshold_consecutive_count = 2;
212 ReinitializeOveruseDetector(); 212 ReinitializeOveruseDetector();
213 TriggerOveruse(2); 213 TriggerOveruse(2);
214 } 214 }
215 215
216 TEST_F(OveruseFrameDetectorTest, IncorrectConsecutiveCountTriggersNoOveruse) { 216 TEST_F(OveruseFrameDetectorTest, IncorrectConsecutiveCountTriggersNoOveruse) {
217 EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)).Times(0); 217 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)).Times(0);
218 options_.high_threshold_consecutive_count = 2; 218 options_.high_threshold_consecutive_count = 2;
219 ReinitializeOveruseDetector(); 219 ReinitializeOveruseDetector();
220 TriggerOveruse(1); 220 TriggerOveruse(1);
221 } 221 }
222 222
223 TEST_F(OveruseFrameDetectorTest, ProcessingUsage) { 223 TEST_F(OveruseFrameDetectorTest, ProcessingUsage) {
224 InsertAndSendFramesWithInterval( 224 InsertAndSendFramesWithInterval(
225 1000, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); 225 1000, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs);
226 EXPECT_EQ(kProcessTimeUs * 100 / kFrameIntervalUs, UsagePercent()); 226 EXPECT_EQ(kProcessTimeUs * 100 / kFrameIntervalUs, UsagePercent());
227 } 227 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 1, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs); 274 1, kFrameIntervalUs, kWidth, kHeight, kProcessTimeUs);
275 EXPECT_NE(InitialUsage(), UsagePercent()); 275 EXPECT_NE(InitialUsage(), UsagePercent());
276 } 276 }
277 277
278 TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) { 278 TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) {
279 ForceUpdate(kWidth, kHeight); 279 ForceUpdate(kWidth, kHeight);
280 EXPECT_EQ(InitialUsage(), UsagePercent()); 280 EXPECT_EQ(InitialUsage(), UsagePercent());
281 } 281 }
282 282
283 TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) { 283 TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) {
284 EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)) 284 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_))
285 .Times(testing::AtLeast(1)); 285 .Times(testing::AtLeast(1));
286 static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; 286 static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec;
287 static const size_t kNumFramesEncodingDelay = 3; 287 static const size_t kNumFramesEncodingDelay = 3;
288 VideoFrame frame(I420Buffer::Create(kWidth, kHeight), 288 VideoFrame frame(I420Buffer::Create(kWidth, kHeight),
289 webrtc::kVideoRotation_0, 0); 289 webrtc::kVideoRotation_0, 0);
290 for (size_t i = 0; i < 1000; ++i) { 290 for (size_t i = 0; i < 1000; ++i) {
291 // Unique timestamps. 291 // Unique timestamps.
292 frame.set_timestamp(static_cast<uint32_t>(i)); 292 frame.set_timestamp(static_cast<uint32_t>(i));
293 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); 293 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros());
294 clock_.AdvanceTimeMicros(kIntervalUs); 294 clock_.AdvanceTimeMicros(kIntervalUs);
295 if (i > kNumFramesEncodingDelay) { 295 if (i > kNumFramesEncodingDelay) {
296 overuse_detector_->FrameSent( 296 overuse_detector_->FrameSent(
297 static_cast<uint32_t>(i - kNumFramesEncodingDelay), 297 static_cast<uint32_t>(i - kNumFramesEncodingDelay),
298 rtc::TimeMicros()); 298 rtc::TimeMicros());
299 } 299 }
300 overuse_detector_->CheckForOveruse(); 300 overuse_detector_->CheckForOveruse();
301 } 301 }
302 } 302 }
303 303
304 TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) { 304 TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) {
305 // >85% encoding time should trigger overuse. 305 // >85% encoding time should trigger overuse.
306 EXPECT_CALL(*(observer_.get()), ScaleDown(reason_)) 306 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_))
307 .Times(testing::AtLeast(1)); 307 .Times(testing::AtLeast(1));
308 static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; 308 static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec;
309 static const int kDelayUs = 30 * rtc::kNumMicrosecsPerMillisec; 309 static const int kDelayUs = 30 * rtc::kNumMicrosecsPerMillisec;
310 VideoFrame frame(I420Buffer::Create(kWidth, kHeight), 310 VideoFrame frame(I420Buffer::Create(kWidth, kHeight),
311 webrtc::kVideoRotation_0, 0); 311 webrtc::kVideoRotation_0, 0);
312 uint32_t timestamp = 0; 312 uint32_t timestamp = 0;
313 for (size_t i = 0; i < 1000; ++i) { 313 for (size_t i = 0; i < 1000; ++i) {
314 frame.set_timestamp(timestamp); 314 frame.set_timestamp(timestamp);
315 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); 315 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros());
316 // Encode and send first parts almost instantly. 316 // Encode and send first parts almost instantly.
(...skipping 13 matching lines...) Expand all
330 330
331 rtc::Event event(false, false); 331 rtc::Event event(false, false);
332 queue.PostTask([this, &event] { 332 queue.PostTask([this, &event] {
333 overuse_detector_->StartCheckForOveruse(); 333 overuse_detector_->StartCheckForOveruse();
334 event.Set(); 334 event.Set();
335 }); 335 });
336 event.Wait(rtc::Event::kForever); 336 event.Wait(rtc::Event::kForever);
337 337
338 // Expect NormalUsage(). When called, stop the |overuse_detector_| and then 338 // Expect NormalUsage(). When called, stop the |overuse_detector_| and then
339 // set |event| to end the test. 339 // set |event| to end the test.
340 EXPECT_CALL(*(observer_.get()), ScaleUp(reason_)) 340 EXPECT_CALL(*(observer_.get()), AdaptUp(reason_))
341 .WillOnce(InvokeWithoutArgs([this, &event] { 341 .WillOnce(InvokeWithoutArgs([this, &event] {
342 overuse_detector_->StopCheckForOveruse(); 342 overuse_detector_->StopCheckForOveruse();
343 event.Set(); 343 event.Set();
344 })); 344 }));
345 345
346 queue.PostTask([this, &event] { 346 queue.PostTask([this, &event] {
347 const int kDelayUs1 = 5 * rtc::kNumMicrosecsPerMillisec; 347 const int kDelayUs1 = 5 * rtc::kNumMicrosecsPerMillisec;
348 const int kDelayUs2 = 6 * rtc::kNumMicrosecsPerMillisec; 348 const int kDelayUs2 = 6 * rtc::kNumMicrosecsPerMillisec;
349 InsertAndSendFramesWithInterval(1300, kFrameIntervalUs, kWidth, kHeight, 349 InsertAndSendFramesWithInterval(1300, kFrameIntervalUs, kWidth, kHeight,
350 kDelayUs1); 350 kDelayUs1);
351 InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight, 351 InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight,
352 kDelayUs2); 352 kDelayUs2);
353 }); 353 });
354 354
355 EXPECT_TRUE(event.Wait(10000)); 355 EXPECT_TRUE(event.Wait(10000));
356 } 356 }
357 357
358 } // namespace webrtc 358 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/overuse_frame_detector.cc ('k') | webrtc/video/vie_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698