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

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

Issue 1250593002: Remove unused overuse detection metric (capture jitter). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 3 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_engine/overuse_frame_detector.cc ('k') | no next file » | 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
11 #include "webrtc/video_engine/overuse_frame_detector.h" 11 #include "webrtc/video_engine/overuse_frame_detector.h"
12 12
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 #include "webrtc/base/scoped_ptr.h" 16 #include "webrtc/base/scoped_ptr.h"
17 #include "webrtc/system_wrappers/interface/clock.h" 17 #include "webrtc/system_wrappers/interface/clock.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 namespace { 20 namespace {
21 const int kWidth = 640; 21 const int kWidth = 640;
22 const int kHeight = 480; 22 const int kHeight = 480;
23 const int kFrameInterval33ms = 33; 23 const int kFrameInterval33ms = 33;
24 const int kProcessIntervalMs = 5000; 24 const int kProcessIntervalMs = 5000;
25 const int kProcessTime5ms = 5;
25 } // namespace 26 } // namespace
26 27
27 class MockCpuOveruseObserver : public CpuOveruseObserver { 28 class MockCpuOveruseObserver : public CpuOveruseObserver {
28 public: 29 public:
29 MockCpuOveruseObserver() {} 30 MockCpuOveruseObserver() {}
30 virtual ~MockCpuOveruseObserver() {} 31 virtual ~MockCpuOveruseObserver() {}
31 32
32 MOCK_METHOD0(OveruseDetected, void()); 33 MOCK_METHOD0(OveruseDetected, void());
33 MOCK_METHOD0(NormalUsage, void()); 34 MOCK_METHOD0(NormalUsage, void());
34 }; 35 };
(...skipping 11 matching lines...) Expand all
46 int overuse_; 47 int overuse_;
47 int normaluse_; 48 int normaluse_;
48 }; 49 };
49 50
50 class OveruseFrameDetectorTest : public ::testing::Test, 51 class OveruseFrameDetectorTest : public ::testing::Test,
51 public CpuOveruseMetricsObserver { 52 public CpuOveruseMetricsObserver {
52 protected: 53 protected:
53 virtual void SetUp() { 54 virtual void SetUp() {
54 clock_.reset(new SimulatedClock(1234)); 55 clock_.reset(new SimulatedClock(1234));
55 observer_.reset(new MockCpuOveruseObserver()); 56 observer_.reset(new MockCpuOveruseObserver());
56 options_.low_capture_jitter_threshold_ms = 10.0f;
57 options_.high_capture_jitter_threshold_ms = 15.0f;
58 options_.min_process_count = 0; 57 options_.min_process_count = 0;
59 ReinitializeOveruseDetector(); 58 ReinitializeOveruseDetector();
60 } 59 }
61 60
62 void ReinitializeOveruseDetector() { 61 void ReinitializeOveruseDetector() {
63 overuse_detector_.reset(new OveruseFrameDetector(clock_.get(), options_, 62 overuse_detector_.reset(new OveruseFrameDetector(clock_.get(), options_,
64 observer_.get(), this)); 63 observer_.get(), this));
65 } 64 }
66 65
67 void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) override { 66 void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) override {
68 metrics_ = metrics; 67 metrics_ = metrics;
69 } 68 }
70 69
71 int InitialJitter() {
72 return ((options_.low_capture_jitter_threshold_ms +
73 options_.high_capture_jitter_threshold_ms) / 2.0f) + 0.5;
74 }
75
76 int InitialUsage() { 70 int InitialUsage() {
77 return ((options_.low_encode_usage_threshold_percent + 71 return ((options_.low_encode_usage_threshold_percent +
78 options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5; 72 options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5;
79 } 73 }
80 74
81 void InsertFramesWithInterval(
82 size_t num_frames, int interval_ms, int width, int height) {
83 while (num_frames-- > 0) {
84 clock_->AdvanceTimeMilliseconds(interval_ms);
85 overuse_detector_->FrameCaptured(width, height,
86 clock_->TimeInMilliseconds());
87 }
88 }
89
90 void InsertAndSendFramesWithInterval( 75 void InsertAndSendFramesWithInterval(
91 int num_frames, int interval_ms, int width, int height, int delay_ms) { 76 int num_frames, int interval_ms, int width, int height, int delay_ms) {
92 while (num_frames-- > 0) { 77 while (num_frames-- > 0) {
93 int64_t capture_time_ms = clock_->TimeInMilliseconds(); 78 int64_t capture_time_ms = clock_->TimeInMilliseconds();
94 overuse_detector_->FrameCaptured(width, height, capture_time_ms); 79 overuse_detector_->FrameCaptured(width, height, capture_time_ms);
95 clock_->AdvanceTimeMilliseconds(delay_ms); 80 clock_->AdvanceTimeMilliseconds(delay_ms);
96 overuse_detector_->FrameEncoded(delay_ms); 81 overuse_detector_->FrameEncoded(delay_ms);
97 overuse_detector_->FrameSent(capture_time_ms); 82 overuse_detector_->FrameSent(capture_time_ms);
98 clock_->AdvanceTimeMilliseconds(interval_ms - delay_ms); 83 clock_->AdvanceTimeMilliseconds(interval_ms - delay_ms);
99 } 84 }
100 } 85 }
101 86
102 void TriggerOveruse(int num_times) { 87 void TriggerOveruse(int num_times) {
103 for (int i = 0; i < num_times; ++i) {
104 InsertFramesWithInterval(200, kFrameInterval33ms, kWidth, kHeight);
105 InsertFramesWithInterval(50, 110, kWidth, kHeight);
106 overuse_detector_->Process();
107 }
108 }
109
110 void TriggerUnderuse() {
111 InsertFramesWithInterval(900, kFrameInterval33ms, kWidth, kHeight);
112 overuse_detector_->Process();
113 }
114
115 void TriggerOveruseWithProcessingUsage(int num_times) {
116 const int kDelayMs = 32; 88 const int kDelayMs = 32;
117 for (int i = 0; i < num_times; ++i) { 89 for (int i = 0; i < num_times; ++i) {
118 InsertAndSendFramesWithInterval( 90 InsertAndSendFramesWithInterval(
119 1000, kFrameInterval33ms, kWidth, kHeight, kDelayMs); 91 1000, kFrameInterval33ms, kWidth, kHeight, kDelayMs);
120 overuse_detector_->Process(); 92 overuse_detector_->Process();
121 } 93 }
122 } 94 }
123 95
124 void TriggerUnderuseWithProcessingUsage() { 96 void TriggerUnderuse() {
125 const int kDelayMs1 = 5; 97 const int kDelayMs1 = 5;
126 const int kDelayMs2 = 6; 98 const int kDelayMs2 = 6;
127 InsertAndSendFramesWithInterval( 99 InsertAndSendFramesWithInterval(
128 1300, kFrameInterval33ms, kWidth, kHeight, kDelayMs1); 100 1300, kFrameInterval33ms, kWidth, kHeight, kDelayMs1);
129 InsertAndSendFramesWithInterval( 101 InsertAndSendFramesWithInterval(
130 1, kFrameInterval33ms, kWidth, kHeight, kDelayMs2); 102 1, kFrameInterval33ms, kWidth, kHeight, kDelayMs2);
131 overuse_detector_->Process(); 103 overuse_detector_->Process();
132 } 104 }
133 105
134 int CaptureJitterMs() { return metrics_.capture_jitter_ms; }
135
136 int AvgEncodeTimeMs() { return metrics_.avg_encode_time_ms; } 106 int AvgEncodeTimeMs() { return metrics_.avg_encode_time_ms; }
137 107
138 int UsagePercent() { return metrics_.encode_usage_percent; } 108 int UsagePercent() { return metrics_.encode_usage_percent; }
139 109
140 CpuOveruseOptions options_; 110 CpuOveruseOptions options_;
141 rtc::scoped_ptr<SimulatedClock> clock_; 111 rtc::scoped_ptr<SimulatedClock> clock_;
142 rtc::scoped_ptr<MockCpuOveruseObserver> observer_; 112 rtc::scoped_ptr<MockCpuOveruseObserver> observer_;
143 rtc::scoped_ptr<OveruseFrameDetector> overuse_detector_; 113 rtc::scoped_ptr<OveruseFrameDetector> overuse_detector_;
144 CpuOveruseMetrics metrics_; 114 CpuOveruseMetrics metrics_;
145 }; 115 };
146 116
147 // enable_capture_jitter_method = true; 117
148 // CaptureJitterMs() > high_capture_jitter_threshold_ms => overuse. 118 // enable_encode_usage_method = true;
149 // CaptureJitterMs() < low_capture_jitter_threshold_ms => underuse. 119 // enable_extended_processing_usage = false;
120 // UsagePercent() > high_encode_usage_threshold_percent => overuse.
121 // UsagePercent() < low_encode_usage_threshold_percent => underuse.
150 TEST_F(OveruseFrameDetectorTest, TriggerOveruse) { 122 TEST_F(OveruseFrameDetectorTest, TriggerOveruse) {
151 options_.enable_capture_jitter_method = true;
152 options_.enable_encode_usage_method = false;
153 options_.enable_extended_processing_usage = false; 123 options_.enable_extended_processing_usage = false;
154 ReinitializeOveruseDetector(); 124 ReinitializeOveruseDetector();
155 // capture_jitter > high => overuse 125 // usage > high => overuse
156 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); 126 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
157 TriggerOveruse(options_.high_threshold_consecutive_count); 127 TriggerOveruse(options_.high_threshold_consecutive_count);
158 } 128 }
159 129
160 TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) { 130 TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) {
161 options_.enable_capture_jitter_method = true;
162 options_.enable_encode_usage_method = false;
163 options_.enable_extended_processing_usage = false; 131 options_.enable_extended_processing_usage = false;
164 ReinitializeOveruseDetector(); 132 ReinitializeOveruseDetector();
165 // capture_jitter > high => overuse 133 // usage > high => overuse
166 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); 134 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
167 TriggerOveruse(options_.high_threshold_consecutive_count); 135 TriggerOveruse(options_.high_threshold_consecutive_count);
168 // capture_jitter < low => underuse 136 // usage < low => underuse
169 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); 137 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
170 TriggerUnderuse(); 138 TriggerUnderuse();
171 } 139 }
172 140
173 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) { 141 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) {
174 options_.enable_capture_jitter_method = true;
175 options_.enable_encode_usage_method = false;
176 options_.enable_extended_processing_usage = false; 142 options_.enable_extended_processing_usage = false;
177 overuse_detector_.reset( 143 overuse_detector_.reset(
178 new OveruseFrameDetector(clock_.get(), options_, nullptr, this)); 144 new OveruseFrameDetector(clock_.get(), options_, nullptr, this));
179 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); 145 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
180 TriggerOveruse(options_.high_threshold_consecutive_count); 146 TriggerOveruse(options_.high_threshold_consecutive_count);
181 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); 147 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
182 TriggerUnderuse(); 148 TriggerUnderuse();
183 } 149 }
184 150
185 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithMethodDisabled) { 151 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithMethodDisabled) {
186 options_.enable_capture_jitter_method = false;
187 options_.enable_encode_usage_method = false; 152 options_.enable_encode_usage_method = false;
188 options_.enable_extended_processing_usage = false; 153 options_.enable_extended_processing_usage = false;
189 ReinitializeOveruseDetector(); 154 ReinitializeOveruseDetector();
190 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); 155 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
191 TriggerOveruse(options_.high_threshold_consecutive_count); 156 TriggerOveruse(options_.high_threshold_consecutive_count);
192 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); 157 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
193 TriggerUnderuse(); 158 TriggerUnderuse();
194 } 159 }
195 160
196 TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) { 161 TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) {
197 options_.enable_capture_jitter_method = true;
198 options_.enable_encode_usage_method = false;
199 options_.enable_extended_processing_usage = false; 162 options_.enable_extended_processing_usage = false;
200 ReinitializeOveruseDetector(); 163 ReinitializeOveruseDetector();
201 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(2); 164 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(2);
202 TriggerOveruse(options_.high_threshold_consecutive_count); 165 TriggerOveruse(options_.high_threshold_consecutive_count);
203 TriggerOveruse(options_.high_threshold_consecutive_count); 166 TriggerOveruse(options_.high_threshold_consecutive_count);
204 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); 167 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
205 TriggerUnderuse(); 168 TriggerUnderuse();
206 } 169 }
207 170
208 TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) { 171 TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) {
209 options_.enable_capture_jitter_method = true;
210 options_.enable_encode_usage_method = false;
211 options_.enable_extended_processing_usage = false; 172 options_.enable_extended_processing_usage = false;
212 options_.min_process_count = 1; 173 options_.min_process_count = 1;
213 CpuOveruseObserverImpl overuse_observer; 174 CpuOveruseObserverImpl overuse_observer;
214 overuse_detector_.reset(new OveruseFrameDetector(clock_.get(), options_, 175 overuse_detector_.reset(new OveruseFrameDetector(clock_.get(), options_,
215 &overuse_observer, this)); 176 &overuse_observer, this));
216 InsertFramesWithInterval(1200, kFrameInterval33ms, kWidth, kHeight); 177 InsertAndSendFramesWithInterval(
178 1200, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
217 overuse_detector_->Process(); 179 overuse_detector_->Process();
218 EXPECT_EQ(0, overuse_observer.normaluse_); 180 EXPECT_EQ(0, overuse_observer.normaluse_);
219 clock_->AdvanceTimeMilliseconds(kProcessIntervalMs); 181 clock_->AdvanceTimeMilliseconds(kProcessIntervalMs);
220 overuse_detector_->Process(); 182 overuse_detector_->Process();
221 EXPECT_EQ(1, overuse_observer.normaluse_); 183 EXPECT_EQ(1, overuse_observer.normaluse_);
222 } 184 }
223 185
224 TEST_F(OveruseFrameDetectorTest, ConstantOveruseGivesNoNormalUsage) { 186 TEST_F(OveruseFrameDetectorTest, ConstantOveruseGivesNoNormalUsage) {
225 options_.enable_capture_jitter_method = true;
226 options_.enable_encode_usage_method = false;
227 options_.enable_extended_processing_usage = false; 187 options_.enable_extended_processing_usage = false;
228 ReinitializeOveruseDetector(); 188 ReinitializeOveruseDetector();
229 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); 189 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
230 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(64); 190 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(64);
231 for(size_t i = 0; i < 64; ++i) { 191 for(size_t i = 0; i < 64; ++i) {
232 TriggerOveruse(options_.high_threshold_consecutive_count); 192 TriggerOveruse(options_.high_threshold_consecutive_count);
233 } 193 }
234 } 194 }
235 195
236 TEST_F(OveruseFrameDetectorTest, ConsecutiveCountTriggersOveruse) { 196 TEST_F(OveruseFrameDetectorTest, ConsecutiveCountTriggersOveruse) {
237 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); 197 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
238 options_.enable_capture_jitter_method = true;
239 options_.enable_encode_usage_method = false;
240 options_.enable_extended_processing_usage = false; 198 options_.enable_extended_processing_usage = false;
241 options_.high_threshold_consecutive_count = 2; 199 options_.high_threshold_consecutive_count = 2;
242 ReinitializeOveruseDetector(); 200 ReinitializeOveruseDetector();
243 TriggerOveruse(2); 201 TriggerOveruse(2);
244 } 202 }
245 203
246 TEST_F(OveruseFrameDetectorTest, IncorrectConsecutiveCountTriggersNoOveruse) { 204 TEST_F(OveruseFrameDetectorTest, IncorrectConsecutiveCountTriggersNoOveruse) {
247 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); 205 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
248 options_.enable_capture_jitter_method = true;
249 options_.enable_encode_usage_method = false;
250 options_.enable_extended_processing_usage = false; 206 options_.enable_extended_processing_usage = false;
251 options_.high_threshold_consecutive_count = 2; 207 options_.high_threshold_consecutive_count = 2;
252 ReinitializeOveruseDetector(); 208 ReinitializeOveruseDetector();
253 TriggerOveruse(1); 209 TriggerOveruse(1);
254 } 210 }
255 211
256 TEST_F(OveruseFrameDetectorTest, CaptureJitter) { 212 TEST_F(OveruseFrameDetectorTest, ProcessingUsage) {
257 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); 213 InsertAndSendFramesWithInterval(
258 InsertFramesWithInterval(1000, kFrameInterval33ms, kWidth, kHeight); 214 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
259 EXPECT_NE(InitialJitter(), CaptureJitterMs()); 215 EXPECT_EQ(kProcessTime5ms * 100 / kFrameInterval33ms, UsagePercent());
260 } 216 }
261 217
262 TEST_F(OveruseFrameDetectorTest, CaptureJitterResetAfterResolutionChange) { 218 TEST_F(OveruseFrameDetectorTest, ResetAfterResolutionChange) {
263 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); 219 EXPECT_EQ(InitialUsage(), UsagePercent());
264 InsertFramesWithInterval(1000, kFrameInterval33ms, kWidth, kHeight); 220 InsertAndSendFramesWithInterval(
265 EXPECT_NE(InitialJitter(), CaptureJitterMs()); 221 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
222 EXPECT_NE(InitialUsage(), UsagePercent());
266 // Verify reset. 223 // Verify reset.
267 InsertFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight + 1); 224 InsertAndSendFramesWithInterval(
268 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); 225 1, kFrameInterval33ms, kWidth, kHeight + 1, kProcessTime5ms);
226 EXPECT_EQ(InitialUsage(), UsagePercent());
269 } 227 }
270 228
271 TEST_F(OveruseFrameDetectorTest, CaptureJitterResetAfterFrameTimeout) { 229 TEST_F(OveruseFrameDetectorTest, ResetAfterFrameTimeout) {
272 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); 230 EXPECT_EQ(InitialUsage(), UsagePercent());
273 InsertFramesWithInterval(1000, kFrameInterval33ms, kWidth, kHeight); 231 InsertAndSendFramesWithInterval(
274 EXPECT_NE(InitialJitter(), CaptureJitterMs()); 232 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
275 InsertFramesWithInterval( 233 EXPECT_NE(InitialUsage(), UsagePercent());
276 1, options_.frame_timeout_interval_ms, kWidth, kHeight); 234 InsertAndSendFramesWithInterval(
277 EXPECT_NE(InitialJitter(), CaptureJitterMs()); 235 2, options_.frame_timeout_interval_ms, kWidth, kHeight, kProcessTime5ms);
236 EXPECT_NE(InitialUsage(), UsagePercent());
278 // Verify reset. 237 // Verify reset.
279 InsertFramesWithInterval( 238 InsertAndSendFramesWithInterval(
280 1, options_.frame_timeout_interval_ms + 1, kWidth, kHeight); 239 2, options_.frame_timeout_interval_ms + 1, kWidth, kHeight,
281 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); 240 kProcessTime5ms);
241 EXPECT_EQ(InitialUsage(), UsagePercent());
282 } 242 }
283 243
284 TEST_F(OveruseFrameDetectorTest, MinFrameSamplesBeforeUpdatingCaptureJitter) { 244 TEST_F(OveruseFrameDetectorTest, MinFrameSamplesBeforeUpdating) {
285 options_.min_frame_samples = 40; 245 options_.min_frame_samples = 40;
286 ReinitializeOveruseDetector(); 246 ReinitializeOveruseDetector();
287 InsertFramesWithInterval(40, kFrameInterval33ms, kWidth, kHeight); 247 InsertAndSendFramesWithInterval(
288 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); 248 40, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
249 EXPECT_EQ(InitialUsage(), UsagePercent());
250 InsertAndSendFramesWithInterval(
251 1, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms);
252 EXPECT_NE(InitialUsage(), UsagePercent());
253 }
254
255 TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) {
256 EXPECT_EQ(InitialUsage(), UsagePercent());
289 } 257 }
290 258
291 TEST_F(OveruseFrameDetectorTest, FrameDelay_OneFrameDisabled) { 259 TEST_F(OveruseFrameDetectorTest, FrameDelay_OneFrameDisabled) {
292 options_.enable_extended_processing_usage = false; 260 options_.enable_extended_processing_usage = false;
293 ReinitializeOveruseDetector(); 261 ReinitializeOveruseDetector();
294 const int kProcessingTimeMs = 100; 262 const int kProcessingTimeMs = 100;
295 overuse_detector_->FrameCaptured(kWidth, kHeight, 33); 263 overuse_detector_->FrameCaptured(kWidth, kHeight, 33);
296 clock_->AdvanceTimeMilliseconds(kProcessingTimeMs); 264 clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
297 overuse_detector_->FrameSent(33); 265 overuse_detector_->FrameSent(33);
298 EXPECT_EQ(-1, overuse_detector_->LastProcessingTimeMs()); 266 EXPECT_EQ(-1, overuse_detector_->LastProcessingTimeMs());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 TEST_F(OveruseFrameDetectorTest, EncodedFrame) { 359 TEST_F(OveruseFrameDetectorTest, EncodedFrame) {
392 const int kInitialAvgEncodeTimeInMs = 5; 360 const int kInitialAvgEncodeTimeInMs = 5;
393 EXPECT_EQ(kInitialAvgEncodeTimeInMs, AvgEncodeTimeMs()); 361 EXPECT_EQ(kInitialAvgEncodeTimeInMs, AvgEncodeTimeMs());
394 for (int i = 0; i < 30; i++) { 362 for (int i = 0; i < 30; i++) {
395 clock_->AdvanceTimeMilliseconds(33); 363 clock_->AdvanceTimeMilliseconds(33);
396 overuse_detector_->FrameEncoded(2); 364 overuse_detector_->FrameEncoded(2);
397 } 365 }
398 EXPECT_EQ(2, AvgEncodeTimeMs()); 366 EXPECT_EQ(2, AvgEncodeTimeMs());
399 } 367 }
400 368
401 TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) {
402 EXPECT_EQ(InitialUsage(), UsagePercent());
403 }
404
405 TEST_F(OveruseFrameDetectorTest, ProcessingUsage) {
406 const int kProcessingTimeMs = 5;
407 InsertAndSendFramesWithInterval(
408 1000, kFrameInterval33ms, kWidth, kHeight, kProcessingTimeMs);
409 EXPECT_EQ(kProcessingTimeMs * 100 / kFrameInterval33ms, UsagePercent());
410 }
411
412 // enable_encode_usage_method = true; 369 // enable_encode_usage_method = true;
413 // UsagePercent() > high_encode_usage_threshold_percent => overuse.
414 // UsagePercent() < low_encode_usage_threshold_percent => underuse.
415 TEST_F(OveruseFrameDetectorTest, TriggerOveruseWithProcessingUsage) {
416 options_.enable_capture_jitter_method = false;
417 options_.enable_encode_usage_method = true;
418 options_.enable_extended_processing_usage = false;
419 ReinitializeOveruseDetector();
420 // usage > high => overuse
421 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
422 TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count);
423 }
424
425 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithProcessingUsage) {
426 options_.enable_capture_jitter_method = false;
427 options_.enable_encode_usage_method = true;
428 options_.enable_extended_processing_usage = false;
429 ReinitializeOveruseDetector();
430 // usage > high => overuse
431 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
432 TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count);
433 // usage < low => underuse
434 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
435 TriggerUnderuseWithProcessingUsage();
436 }
437
438 TEST_F(OveruseFrameDetectorTest,
439 OveruseAndRecoverWithProcessingUsageMethodDisabled) {
440 options_.enable_capture_jitter_method = false;
441 options_.enable_encode_usage_method = false;
442 options_.enable_extended_processing_usage = false;
443 ReinitializeOveruseDetector();
444 // usage > high => overuse
445 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
446 TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count);
447 // usage < low => underuse
448 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
449 TriggerUnderuseWithProcessingUsage();
450 }
451
452 // enable_extended_processing_usage = true; 370 // enable_extended_processing_usage = true;
453 // enable_encode_usage_method = true;
454 // UsagePercent() > high_encode_usage_threshold_percent => overuse. 371 // UsagePercent() > high_encode_usage_threshold_percent => overuse.
455 // UsagePercent() < low_encode_usage_threshold_percent => underuse. 372 // UsagePercent() < low_encode_usage_threshold_percent => underuse.
456 TEST_F(OveruseFrameDetectorTest, TriggerOveruseWithExtendedProcessingUsage) { 373 TEST_F(OveruseFrameDetectorTest, TriggerOveruseWithExtendedProcessingUsage) {
457 options_.enable_capture_jitter_method = false;
458 options_.enable_encode_usage_method = true;
459 options_.enable_extended_processing_usage = true; 374 options_.enable_extended_processing_usage = true;
460 ReinitializeOveruseDetector(); 375 ReinitializeOveruseDetector();
461 // usage > high => overuse 376 // usage > high => overuse
462 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); 377 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
463 TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count); 378 TriggerOveruse(options_.high_threshold_consecutive_count);
464 } 379 }
465 380
466 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithExtendedProcessingUsage) { 381 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithExtendedProcessingUsage) {
467 options_.enable_capture_jitter_method = false;
468 options_.enable_encode_usage_method = true;
469 options_.enable_extended_processing_usage = true; 382 options_.enable_extended_processing_usage = true;
470 ReinitializeOveruseDetector(); 383 ReinitializeOveruseDetector();
471 // usage > high => overuse 384 // usage > high => overuse
472 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); 385 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
473 TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count); 386 TriggerOveruse(options_.high_threshold_consecutive_count);
474 // usage < low => underuse 387 // usage < low => underuse
475 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); 388 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
476 TriggerUnderuseWithProcessingUsage(); 389 TriggerUnderuse();
477 } 390 }
478 391
479 TEST_F(OveruseFrameDetectorTest, 392 TEST_F(OveruseFrameDetectorTest,
480 OveruseAndRecoverWithExtendedProcessingUsageMethodDisabled) { 393 OveruseAndRecoverWithExtendedProcessingUsageMethodDisabled) {
481 options_.enable_capture_jitter_method = false;
482 options_.enable_encode_usage_method = false; 394 options_.enable_encode_usage_method = false;
483 options_.enable_extended_processing_usage = true; 395 options_.enable_extended_processing_usage = true;
484 ReinitializeOveruseDetector(); 396 ReinitializeOveruseDetector();
485 // usage > high => overuse 397 // usage > high => overuse
486 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); 398 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
487 TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count); 399 TriggerOveruse(options_.high_threshold_consecutive_count);
488 // usage < low => underuse 400 // usage < low => underuse
489 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); 401 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
490 TriggerUnderuseWithProcessingUsage(); 402 TriggerUnderuse();
491 } 403 }
492 404
493 } // namespace webrtc 405 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video_engine/overuse_frame_detector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698