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 |
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 Loading... | |
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( | 75 void InsertFramesWithInterval( |
pbos-webrtc
2015/07/21 18:14:09
Is this one dead code now? If so remove. :)
åsapersson
2015/07/22 05:50:24
Done.
| |
82 size_t num_frames, int interval_ms, int width, int height) { | 76 size_t num_frames, int interval_ms, int width, int height) { |
83 while (num_frames-- > 0) { | 77 while (num_frames-- > 0) { |
84 clock_->AdvanceTimeMilliseconds(interval_ms); | 78 clock_->AdvanceTimeMilliseconds(interval_ms); |
85 overuse_detector_->FrameCaptured(width, height, | 79 overuse_detector_->FrameCaptured(width, height, |
86 clock_->TimeInMilliseconds()); | 80 clock_->TimeInMilliseconds()); |
87 } | 81 } |
88 } | 82 } |
89 | 83 |
90 void InsertAndSendFramesWithInterval( | 84 void InsertAndSendFramesWithInterval( |
91 int num_frames, int interval_ms, int width, int height, int delay_ms) { | 85 int num_frames, int interval_ms, int width, int height, int delay_ms) { |
92 while (num_frames-- > 0) { | 86 while (num_frames-- > 0) { |
93 int64_t capture_time_ms = clock_->TimeInMilliseconds(); | 87 int64_t capture_time_ms = clock_->TimeInMilliseconds(); |
94 overuse_detector_->FrameCaptured(width, height, capture_time_ms); | 88 overuse_detector_->FrameCaptured(width, height, capture_time_ms); |
95 clock_->AdvanceTimeMilliseconds(delay_ms); | 89 clock_->AdvanceTimeMilliseconds(delay_ms); |
96 overuse_detector_->FrameEncoded(delay_ms); | 90 overuse_detector_->FrameEncoded(delay_ms); |
97 overuse_detector_->FrameSent(capture_time_ms); | 91 overuse_detector_->FrameSent(capture_time_ms); |
98 clock_->AdvanceTimeMilliseconds(interval_ms - delay_ms); | 92 clock_->AdvanceTimeMilliseconds(interval_ms - delay_ms); |
99 } | 93 } |
100 } | 94 } |
101 | 95 |
102 void TriggerOveruse(int num_times) { | 96 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; | 97 const int kDelayMs = 32; |
117 for (int i = 0; i < num_times; ++i) { | 98 for (int i = 0; i < num_times; ++i) { |
118 InsertAndSendFramesWithInterval( | 99 InsertAndSendFramesWithInterval( |
119 1000, kFrameInterval33ms, kWidth, kHeight, kDelayMs); | 100 1000, kFrameInterval33ms, kWidth, kHeight, kDelayMs); |
120 overuse_detector_->Process(); | 101 overuse_detector_->Process(); |
121 } | 102 } |
122 } | 103 } |
123 | 104 |
124 void TriggerUnderuseWithProcessingUsage() { | 105 void TriggerUnderuse() { |
125 const int kDelayMs1 = 5; | 106 const int kDelayMs1 = 5; |
126 const int kDelayMs2 = 6; | 107 const int kDelayMs2 = 6; |
127 InsertAndSendFramesWithInterval( | 108 InsertAndSendFramesWithInterval( |
128 1300, kFrameInterval33ms, kWidth, kHeight, kDelayMs1); | 109 1300, kFrameInterval33ms, kWidth, kHeight, kDelayMs1); |
129 InsertAndSendFramesWithInterval( | 110 InsertAndSendFramesWithInterval( |
130 1, kFrameInterval33ms, kWidth, kHeight, kDelayMs2); | 111 1, kFrameInterval33ms, kWidth, kHeight, kDelayMs2); |
131 overuse_detector_->Process(); | 112 overuse_detector_->Process(); |
132 } | 113 } |
133 | 114 |
134 int CaptureJitterMs() { return metrics_.capture_jitter_ms; } | |
135 | |
136 int AvgEncodeTimeMs() { return metrics_.avg_encode_time_ms; } | 115 int AvgEncodeTimeMs() { return metrics_.avg_encode_time_ms; } |
137 | 116 |
138 int UsagePercent() { return metrics_.encode_usage_percent; } | 117 int UsagePercent() { return metrics_.encode_usage_percent; } |
139 | 118 |
140 CpuOveruseOptions options_; | 119 CpuOveruseOptions options_; |
141 rtc::scoped_ptr<SimulatedClock> clock_; | 120 rtc::scoped_ptr<SimulatedClock> clock_; |
142 rtc::scoped_ptr<MockCpuOveruseObserver> observer_; | 121 rtc::scoped_ptr<MockCpuOveruseObserver> observer_; |
143 rtc::scoped_ptr<OveruseFrameDetector> overuse_detector_; | 122 rtc::scoped_ptr<OveruseFrameDetector> overuse_detector_; |
144 CpuOveruseMetrics metrics_; | 123 CpuOveruseMetrics metrics_; |
145 }; | 124 }; |
146 | 125 |
147 // enable_capture_jitter_method = true; | 126 |
148 // CaptureJitterMs() > high_capture_jitter_threshold_ms => overuse. | 127 // enable_encode_usage_method = true; |
149 // CaptureJitterMs() < low_capture_jitter_threshold_ms => underuse. | 128 // enable_extended_processing_usage = false; |
129 // UsagePercent() > high_encode_usage_threshold_percent => overuse. | |
130 // UsagePercent() < low_encode_usage_threshold_percent => underuse. | |
150 TEST_F(OveruseFrameDetectorTest, TriggerOveruse) { | 131 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; | 132 options_.enable_extended_processing_usage = false; |
154 ReinitializeOveruseDetector(); | 133 ReinitializeOveruseDetector(); |
155 // capture_jitter > high => overuse | 134 // usage > high => overuse |
156 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); | 135 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); |
157 TriggerOveruse(options_.high_threshold_consecutive_count); | 136 TriggerOveruse(options_.high_threshold_consecutive_count); |
158 } | 137 } |
159 | 138 |
160 TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) { | 139 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; | 140 options_.enable_extended_processing_usage = false; |
164 ReinitializeOveruseDetector(); | 141 ReinitializeOveruseDetector(); |
165 // capture_jitter > high => overuse | 142 // usage > high => overuse |
166 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); | 143 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); |
167 TriggerOveruse(options_.high_threshold_consecutive_count); | 144 TriggerOveruse(options_.high_threshold_consecutive_count); |
168 // capture_jitter < low => underuse | 145 // usage < low => underuse |
169 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); | 146 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); |
170 TriggerUnderuse(); | 147 TriggerUnderuse(); |
171 } | 148 } |
172 | 149 |
173 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) { | 150 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; | 151 options_.enable_extended_processing_usage = false; |
177 overuse_detector_.reset( | 152 overuse_detector_.reset( |
178 new OveruseFrameDetector(clock_.get(), options_, nullptr, this)); | 153 new OveruseFrameDetector(clock_.get(), options_, nullptr, this)); |
179 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); | 154 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); |
180 TriggerOveruse(options_.high_threshold_consecutive_count); | 155 TriggerOveruse(options_.high_threshold_consecutive_count); |
181 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); | 156 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); |
182 TriggerUnderuse(); | 157 TriggerUnderuse(); |
183 } | 158 } |
184 | 159 |
185 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithMethodDisabled) { | 160 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithMethodDisabled) { |
186 options_.enable_capture_jitter_method = false; | |
187 options_.enable_encode_usage_method = false; | 161 options_.enable_encode_usage_method = false; |
188 options_.enable_extended_processing_usage = false; | 162 options_.enable_extended_processing_usage = false; |
189 ReinitializeOveruseDetector(); | 163 ReinitializeOveruseDetector(); |
190 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); | 164 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); |
191 TriggerOveruse(options_.high_threshold_consecutive_count); | 165 TriggerOveruse(options_.high_threshold_consecutive_count); |
192 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); | 166 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); |
193 TriggerUnderuse(); | 167 TriggerUnderuse(); |
194 } | 168 } |
195 | 169 |
196 TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) { | 170 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; | 171 options_.enable_extended_processing_usage = false; |
200 ReinitializeOveruseDetector(); | 172 ReinitializeOveruseDetector(); |
201 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(2); | 173 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(2); |
202 TriggerOveruse(options_.high_threshold_consecutive_count); | 174 TriggerOveruse(options_.high_threshold_consecutive_count); |
203 TriggerOveruse(options_.high_threshold_consecutive_count); | 175 TriggerOveruse(options_.high_threshold_consecutive_count); |
204 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); | 176 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); |
205 TriggerUnderuse(); | 177 TriggerUnderuse(); |
206 } | 178 } |
207 | 179 |
208 TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) { | 180 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; | 181 options_.enable_extended_processing_usage = false; |
212 options_.min_process_count = 1; | 182 options_.min_process_count = 1; |
213 CpuOveruseObserverImpl overuse_observer; | 183 CpuOveruseObserverImpl overuse_observer; |
214 overuse_detector_.reset(new OveruseFrameDetector(clock_.get(), options_, | 184 overuse_detector_.reset(new OveruseFrameDetector(clock_.get(), options_, |
215 &overuse_observer, this)); | 185 &overuse_observer, this)); |
216 InsertFramesWithInterval(1200, kFrameInterval33ms, kWidth, kHeight); | 186 InsertAndSendFramesWithInterval( |
187 1200, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); | |
217 overuse_detector_->Process(); | 188 overuse_detector_->Process(); |
218 EXPECT_EQ(0, overuse_observer.normaluse_); | 189 EXPECT_EQ(0, overuse_observer.normaluse_); |
219 clock_->AdvanceTimeMilliseconds(kProcessIntervalMs); | 190 clock_->AdvanceTimeMilliseconds(kProcessIntervalMs); |
220 overuse_detector_->Process(); | 191 overuse_detector_->Process(); |
221 EXPECT_EQ(1, overuse_observer.normaluse_); | 192 EXPECT_EQ(1, overuse_observer.normaluse_); |
222 } | 193 } |
223 | 194 |
224 TEST_F(OveruseFrameDetectorTest, ConstantOveruseGivesNoNormalUsage) { | 195 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; | 196 options_.enable_extended_processing_usage = false; |
228 ReinitializeOveruseDetector(); | 197 ReinitializeOveruseDetector(); |
229 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); | 198 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); |
230 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(64); | 199 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(64); |
231 for(size_t i = 0; i < 64; ++i) { | 200 for(size_t i = 0; i < 64; ++i) { |
232 TriggerOveruse(options_.high_threshold_consecutive_count); | 201 TriggerOveruse(options_.high_threshold_consecutive_count); |
233 } | 202 } |
234 } | 203 } |
235 | 204 |
236 TEST_F(OveruseFrameDetectorTest, ConsecutiveCountTriggersOveruse) { | 205 TEST_F(OveruseFrameDetectorTest, ConsecutiveCountTriggersOveruse) { |
237 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); | 206 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; | 207 options_.enable_extended_processing_usage = false; |
241 options_.high_threshold_consecutive_count = 2; | 208 options_.high_threshold_consecutive_count = 2; |
242 ReinitializeOveruseDetector(); | 209 ReinitializeOveruseDetector(); |
243 TriggerOveruse(2); | 210 TriggerOveruse(2); |
244 } | 211 } |
245 | 212 |
246 TEST_F(OveruseFrameDetectorTest, IncorrectConsecutiveCountTriggersNoOveruse) { | 213 TEST_F(OveruseFrameDetectorTest, IncorrectConsecutiveCountTriggersNoOveruse) { |
247 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); | 214 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; | 215 options_.enable_extended_processing_usage = false; |
251 options_.high_threshold_consecutive_count = 2; | 216 options_.high_threshold_consecutive_count = 2; |
252 ReinitializeOveruseDetector(); | 217 ReinitializeOveruseDetector(); |
253 TriggerOveruse(1); | 218 TriggerOveruse(1); |
254 } | 219 } |
255 | 220 |
256 TEST_F(OveruseFrameDetectorTest, CaptureJitter) { | 221 TEST_F(OveruseFrameDetectorTest, ProcessingUsage) { |
257 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); | 222 InsertAndSendFramesWithInterval( |
258 InsertFramesWithInterval(1000, kFrameInterval33ms, kWidth, kHeight); | 223 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
259 EXPECT_NE(InitialJitter(), CaptureJitterMs()); | 224 EXPECT_EQ(kProcessTime5ms * 100 / kFrameInterval33ms, UsagePercent()); |
260 } | 225 } |
261 | 226 |
262 TEST_F(OveruseFrameDetectorTest, CaptureJitterResetAfterResolutionChange) { | 227 TEST_F(OveruseFrameDetectorTest, ResetAfterResolutionChange) { |
263 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); | 228 EXPECT_EQ(InitialUsage(), UsagePercent()); |
264 InsertFramesWithInterval(1000, kFrameInterval33ms, kWidth, kHeight); | 229 InsertAndSendFramesWithInterval( |
265 EXPECT_NE(InitialJitter(), CaptureJitterMs()); | 230 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
231 EXPECT_NE(InitialUsage(), UsagePercent()); | |
266 // Verify reset. | 232 // Verify reset. |
267 InsertFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight + 1); | 233 InsertAndSendFramesWithInterval( |
268 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); | 234 1, kFrameInterval33ms, kWidth, kHeight + 1, kProcessTime5ms); |
235 EXPECT_EQ(InitialUsage(), UsagePercent()); | |
269 } | 236 } |
270 | 237 |
271 TEST_F(OveruseFrameDetectorTest, CaptureJitterResetAfterFrameTimeout) { | 238 TEST_F(OveruseFrameDetectorTest, ResetAfterFrameTimeout) { |
272 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); | 239 EXPECT_EQ(InitialUsage(), UsagePercent()); |
273 InsertFramesWithInterval(1000, kFrameInterval33ms, kWidth, kHeight); | 240 InsertAndSendFramesWithInterval( |
274 EXPECT_NE(InitialJitter(), CaptureJitterMs()); | 241 1000, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
275 InsertFramesWithInterval( | 242 EXPECT_NE(InitialUsage(), UsagePercent()); |
276 1, options_.frame_timeout_interval_ms, kWidth, kHeight); | 243 InsertAndSendFramesWithInterval( |
277 EXPECT_NE(InitialJitter(), CaptureJitterMs()); | 244 2, options_.frame_timeout_interval_ms, kWidth, kHeight, kProcessTime5ms); |
245 EXPECT_NE(InitialUsage(), UsagePercent()); | |
278 // Verify reset. | 246 // Verify reset. |
279 InsertFramesWithInterval( | 247 InsertAndSendFramesWithInterval( |
280 1, options_.frame_timeout_interval_ms + 1, kWidth, kHeight); | 248 2, options_.frame_timeout_interval_ms + 1, kWidth, kHeight, |
281 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); | 249 kProcessTime5ms); |
250 EXPECT_EQ(InitialUsage(), UsagePercent()); | |
282 } | 251 } |
283 | 252 |
284 TEST_F(OveruseFrameDetectorTest, MinFrameSamplesBeforeUpdatingCaptureJitter) { | 253 TEST_F(OveruseFrameDetectorTest, MinFrameSamplesBeforeUpdating) { |
285 options_.min_frame_samples = 40; | 254 options_.min_frame_samples = 40; |
286 ReinitializeOveruseDetector(); | 255 ReinitializeOveruseDetector(); |
287 InsertFramesWithInterval(40, kFrameInterval33ms, kWidth, kHeight); | 256 InsertAndSendFramesWithInterval( |
288 EXPECT_EQ(InitialJitter(), CaptureJitterMs()); | 257 40, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); |
258 EXPECT_EQ(InitialUsage(), UsagePercent()); | |
259 InsertAndSendFramesWithInterval( | |
260 1, kFrameInterval33ms, kWidth, kHeight, kProcessTime5ms); | |
261 EXPECT_NE(InitialUsage(), UsagePercent()); | |
262 } | |
263 | |
264 TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) { | |
265 EXPECT_EQ(InitialUsage(), UsagePercent()); | |
289 } | 266 } |
290 | 267 |
291 TEST_F(OveruseFrameDetectorTest, FrameDelay_OneFrameDisabled) { | 268 TEST_F(OveruseFrameDetectorTest, FrameDelay_OneFrameDisabled) { |
292 options_.enable_extended_processing_usage = false; | 269 options_.enable_extended_processing_usage = false; |
293 ReinitializeOveruseDetector(); | 270 ReinitializeOveruseDetector(); |
294 const int kProcessingTimeMs = 100; | 271 const int kProcessingTimeMs = 100; |
295 overuse_detector_->FrameCaptured(kWidth, kHeight, 33); | 272 overuse_detector_->FrameCaptured(kWidth, kHeight, 33); |
296 clock_->AdvanceTimeMilliseconds(kProcessingTimeMs); | 273 clock_->AdvanceTimeMilliseconds(kProcessingTimeMs); |
297 overuse_detector_->FrameSent(33); | 274 overuse_detector_->FrameSent(33); |
298 EXPECT_EQ(-1, overuse_detector_->LastProcessingTimeMs()); | 275 EXPECT_EQ(-1, overuse_detector_->LastProcessingTimeMs()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 TEST_F(OveruseFrameDetectorTest, EncodedFrame) { | 368 TEST_F(OveruseFrameDetectorTest, EncodedFrame) { |
392 const int kInitialAvgEncodeTimeInMs = 5; | 369 const int kInitialAvgEncodeTimeInMs = 5; |
393 EXPECT_EQ(kInitialAvgEncodeTimeInMs, AvgEncodeTimeMs()); | 370 EXPECT_EQ(kInitialAvgEncodeTimeInMs, AvgEncodeTimeMs()); |
394 for (int i = 0; i < 30; i++) { | 371 for (int i = 0; i < 30; i++) { |
395 clock_->AdvanceTimeMilliseconds(33); | 372 clock_->AdvanceTimeMilliseconds(33); |
396 overuse_detector_->FrameEncoded(2); | 373 overuse_detector_->FrameEncoded(2); |
397 } | 374 } |
398 EXPECT_EQ(2, AvgEncodeTimeMs()); | 375 EXPECT_EQ(2, AvgEncodeTimeMs()); |
399 } | 376 } |
400 | 377 |
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; | 378 // 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; | 379 // enable_extended_processing_usage = true; |
453 // enable_encode_usage_method = true; | |
454 // UsagePercent() > high_encode_usage_threshold_percent => overuse. | 380 // UsagePercent() > high_encode_usage_threshold_percent => overuse. |
455 // UsagePercent() < low_encode_usage_threshold_percent => underuse. | 381 // UsagePercent() < low_encode_usage_threshold_percent => underuse. |
456 TEST_F(OveruseFrameDetectorTest, TriggerOveruseWithExtendedProcessingUsage) { | 382 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; | 383 options_.enable_extended_processing_usage = true; |
460 ReinitializeOveruseDetector(); | 384 ReinitializeOveruseDetector(); |
461 // usage > high => overuse | 385 // usage > high => overuse |
462 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); | 386 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); |
463 TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count); | 387 TriggerOveruse(options_.high_threshold_consecutive_count); |
464 } | 388 } |
465 | 389 |
466 TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithExtendedProcessingUsage) { | 390 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; | 391 options_.enable_extended_processing_usage = true; |
470 ReinitializeOveruseDetector(); | 392 ReinitializeOveruseDetector(); |
471 // usage > high => overuse | 393 // usage > high => overuse |
472 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); | 394 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1); |
473 TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count); | 395 TriggerOveruse(options_.high_threshold_consecutive_count); |
474 // usage < low => underuse | 396 // usage < low => underuse |
475 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); | 397 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1)); |
476 TriggerUnderuseWithProcessingUsage(); | 398 TriggerUnderuse(); |
477 } | 399 } |
478 | 400 |
479 TEST_F(OveruseFrameDetectorTest, | 401 TEST_F(OveruseFrameDetectorTest, |
480 OveruseAndRecoverWithExtendedProcessingUsageMethodDisabled) { | 402 OveruseAndRecoverWithExtendedProcessingUsageMethodDisabled) { |
481 options_.enable_capture_jitter_method = false; | |
482 options_.enable_encode_usage_method = false; | 403 options_.enable_encode_usage_method = false; |
483 options_.enable_extended_processing_usage = true; | 404 options_.enable_extended_processing_usage = true; |
484 ReinitializeOveruseDetector(); | 405 ReinitializeOveruseDetector(); |
485 // usage > high => overuse | 406 // usage > high => overuse |
486 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); | 407 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0); |
487 TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count); | 408 TriggerOveruse(options_.high_threshold_consecutive_count); |
488 // usage < low => underuse | 409 // usage < low => underuse |
489 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); | 410 EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0); |
490 TriggerUnderuseWithProcessingUsage(); | 411 TriggerUnderuse(); |
491 } | 412 } |
492 | 413 |
493 } // namespace webrtc | 414 } // namespace webrtc |
OLD | NEW |