OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 int InitialUsage() { | 94 int InitialUsage() { |
95 return ((options_.low_encode_usage_threshold_percent + | 95 return ((options_.low_encode_usage_threshold_percent + |
96 options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5; | 96 options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5; |
97 } | 97 } |
98 | 98 |
99 void InsertAndSendFramesWithInterval(int num_frames, | 99 void InsertAndSendFramesWithInterval(int num_frames, |
100 int interval_ms, | 100 int interval_ms, |
101 int width, | 101 int width, |
102 int height, | 102 int height, |
103 int delay_ms) { | 103 int delay_ms) { |
104 VideoFrame frame; | 104 VideoFrame frame(I420Buffer::Create(width, height), |
105 frame.CreateEmptyFrame(width, height, width, width / 2, width / 2); | 105 webrtc::kVideoRotation_0, 0); |
106 uint32_t timestamp = 0; | 106 uint32_t timestamp = 0; |
107 while (num_frames-- > 0) { | 107 while (num_frames-- > 0) { |
108 frame.set_timestamp(timestamp); | 108 frame.set_timestamp(timestamp); |
109 overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds()); | 109 overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds()); |
110 clock_->AdvanceTimeMilliseconds(delay_ms); | 110 clock_->AdvanceTimeMilliseconds(delay_ms); |
111 overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds()); | 111 overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds()); |
112 clock_->AdvanceTimeMilliseconds(interval_ms - delay_ms); | 112 clock_->AdvanceTimeMilliseconds(interval_ms - delay_ms); |
113 timestamp += interval_ms * 90; | 113 timestamp += interval_ms * 90; |
114 } | 114 } |
115 } | 115 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 276 |
277 TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) { | 277 TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) { |
278 ForceUpdate(kWidth, kHeight); | 278 ForceUpdate(kWidth, kHeight); |
279 EXPECT_EQ(InitialUsage(), UsagePercent()); | 279 EXPECT_EQ(InitialUsage(), UsagePercent()); |
280 } | 280 } |
281 | 281 |
282 TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) { | 282 TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) { |
283 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(testing::AtLeast(1)); | 283 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(testing::AtLeast(1)); |
284 static const int kIntervalMs = 33; | 284 static const int kIntervalMs = 33; |
285 static const size_t kNumFramesEncodingDelay = 3; | 285 static const size_t kNumFramesEncodingDelay = 3; |
286 VideoFrame frame; | 286 VideoFrame frame(I420Buffer::Create(kWidth, kHeight), |
287 frame.CreateEmptyFrame(kWidth, kHeight, kWidth, kWidth / 2, kWidth / 2); | 287 webrtc::kVideoRotation_0, 0); |
288 for (size_t i = 0; i < 1000; ++i) { | 288 for (size_t i = 0; i < 1000; ++i) { |
289 // Unique timestamps. | 289 // Unique timestamps. |
290 frame.set_timestamp(static_cast<uint32_t>(i)); | 290 frame.set_timestamp(static_cast<uint32_t>(i)); |
291 overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds()); | 291 overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds()); |
292 clock_->AdvanceTimeMilliseconds(kIntervalMs); | 292 clock_->AdvanceTimeMilliseconds(kIntervalMs); |
293 if (i > kNumFramesEncodingDelay) { | 293 if (i > kNumFramesEncodingDelay) { |
294 overuse_detector_->FrameSent( | 294 overuse_detector_->FrameSent( |
295 static_cast<uint32_t>(i - kNumFramesEncodingDelay), | 295 static_cast<uint32_t>(i - kNumFramesEncodingDelay), |
296 clock_->TimeInMilliseconds()); | 296 clock_->TimeInMilliseconds()); |
297 } | 297 } |
298 overuse_detector_->CheckForOveruse(); | 298 overuse_detector_->CheckForOveruse(); |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) { | 302 TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) { |
303 // >85% encoding time should trigger overuse. | 303 // >85% encoding time should trigger overuse. |
304 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(testing::AtLeast(1)); | 304 EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(testing::AtLeast(1)); |
305 static const int kIntervalMs = 33; | 305 static const int kIntervalMs = 33; |
306 static const int kDelayMs = 30; | 306 static const int kDelayMs = 30; |
307 VideoFrame frame; | 307 VideoFrame frame(I420Buffer::Create(kWidth, kHeight), |
308 frame.CreateEmptyFrame(kWidth, kHeight, kWidth, kWidth / 2, kWidth / 2); | 308 webrtc::kVideoRotation_0, 0); |
309 uint32_t timestamp = 0; | 309 uint32_t timestamp = 0; |
310 for (size_t i = 0; i < 1000; ++i) { | 310 for (size_t i = 0; i < 1000; ++i) { |
311 frame.set_timestamp(timestamp); | 311 frame.set_timestamp(timestamp); |
312 overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds()); | 312 overuse_detector_->FrameCaptured(frame, clock_->TimeInMilliseconds()); |
313 // Encode and send first parts almost instantly. | 313 // Encode and send first parts almost instantly. |
314 clock_->AdvanceTimeMilliseconds(1); | 314 clock_->AdvanceTimeMilliseconds(1); |
315 overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds()); | 315 overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds()); |
316 // Encode heavier part, resulting in >85% usage total. | 316 // Encode heavier part, resulting in >85% usage total. |
317 clock_->AdvanceTimeMilliseconds(kDelayMs - 1); | 317 clock_->AdvanceTimeMilliseconds(kDelayMs - 1); |
318 overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds()); | 318 overuse_detector_->FrameSent(timestamp, clock_->TimeInMilliseconds()); |
(...skipping 27 matching lines...) Expand all Loading... |
346 InsertAndSendFramesWithInterval(1300, kFrameInterval33ms, kWidth, kHeight, | 346 InsertAndSendFramesWithInterval(1300, kFrameInterval33ms, kWidth, kHeight, |
347 kDelayMs1); | 347 kDelayMs1); |
348 InsertAndSendFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight, | 348 InsertAndSendFramesWithInterval(1, kFrameInterval33ms, kWidth, kHeight, |
349 kDelayMs2); | 349 kDelayMs2); |
350 }); | 350 }); |
351 | 351 |
352 EXPECT_TRUE(event.Wait(10000)); | 352 EXPECT_TRUE(event.Wait(10000)); |
353 } | 353 } |
354 | 354 |
355 } // namespace webrtc | 355 } // namespace webrtc |
OLD | NEW |