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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return ((options_.low_encode_usage_threshold_percent + | 91 return ((options_.low_encode_usage_threshold_percent + |
92 options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5; | 92 options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5; |
93 } | 93 } |
94 | 94 |
95 void InsertAndSendFramesWithInterval(int num_frames, | 95 void InsertAndSendFramesWithInterval(int num_frames, |
96 int interval_us, | 96 int interval_us, |
97 int width, | 97 int width, |
98 int height, | 98 int height, |
99 int delay_us) { | 99 int delay_us) { |
100 VideoFrame frame(I420Buffer::Create(width, height), | 100 VideoFrame frame(I420Buffer::Create(width, height), |
101 webrtc::kVideoRotation_0, 0); | 101 webrtc::kVideoRotation_0, |
| 102 webrtc::VideoContentType::kDefault, 0); |
102 uint32_t timestamp = 0; | 103 uint32_t timestamp = 0; |
103 while (num_frames-- > 0) { | 104 while (num_frames-- > 0) { |
104 frame.set_timestamp(timestamp); | 105 frame.set_timestamp(timestamp); |
105 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); | 106 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); |
106 clock_.AdvanceTimeMicros(delay_us); | 107 clock_.AdvanceTimeMicros(delay_us); |
107 overuse_detector_->FrameSent(timestamp, rtc::TimeMicros()); | 108 overuse_detector_->FrameSent(timestamp, rtc::TimeMicros()); |
108 clock_.AdvanceTimeMicros(interval_us - delay_us); | 109 clock_.AdvanceTimeMicros(interval_us - delay_us); |
109 timestamp += interval_us * 90 / 1000; | 110 timestamp += interval_us * 90 / 1000; |
110 } | 111 } |
111 } | 112 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 ForceUpdate(kWidth, kHeight); | 280 ForceUpdate(kWidth, kHeight); |
280 EXPECT_EQ(InitialUsage(), UsagePercent()); | 281 EXPECT_EQ(InitialUsage(), UsagePercent()); |
281 } | 282 } |
282 | 283 |
283 TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) { | 284 TEST_F(OveruseFrameDetectorTest, MeasuresMultipleConcurrentSamples) { |
284 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)) | 285 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)) |
285 .Times(testing::AtLeast(1)); | 286 .Times(testing::AtLeast(1)); |
286 static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; | 287 static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; |
287 static const size_t kNumFramesEncodingDelay = 3; | 288 static const size_t kNumFramesEncodingDelay = 3; |
288 VideoFrame frame(I420Buffer::Create(kWidth, kHeight), | 289 VideoFrame frame(I420Buffer::Create(kWidth, kHeight), |
289 webrtc::kVideoRotation_0, 0); | 290 webrtc::kVideoRotation_0, webrtc::VideoContentType::kDefault, |
| 291 0); |
290 for (size_t i = 0; i < 1000; ++i) { | 292 for (size_t i = 0; i < 1000; ++i) { |
291 // Unique timestamps. | 293 // Unique timestamps. |
292 frame.set_timestamp(static_cast<uint32_t>(i)); | 294 frame.set_timestamp(static_cast<uint32_t>(i)); |
293 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); | 295 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); |
294 clock_.AdvanceTimeMicros(kIntervalUs); | 296 clock_.AdvanceTimeMicros(kIntervalUs); |
295 if (i > kNumFramesEncodingDelay) { | 297 if (i > kNumFramesEncodingDelay) { |
296 overuse_detector_->FrameSent( | 298 overuse_detector_->FrameSent( |
297 static_cast<uint32_t>(i - kNumFramesEncodingDelay), | 299 static_cast<uint32_t>(i - kNumFramesEncodingDelay), |
298 rtc::TimeMicros()); | 300 rtc::TimeMicros()); |
299 } | 301 } |
300 overuse_detector_->CheckForOveruse(); | 302 overuse_detector_->CheckForOveruse(); |
301 } | 303 } |
302 } | 304 } |
303 | 305 |
304 TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) { | 306 TEST_F(OveruseFrameDetectorTest, UpdatesExistingSamples) { |
305 // >85% encoding time should trigger overuse. | 307 // >85% encoding time should trigger overuse. |
306 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)) | 308 EXPECT_CALL(*(observer_.get()), AdaptDown(reason_)) |
307 .Times(testing::AtLeast(1)); | 309 .Times(testing::AtLeast(1)); |
308 static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; | 310 static const int kIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; |
309 static const int kDelayUs = 30 * rtc::kNumMicrosecsPerMillisec; | 311 static const int kDelayUs = 30 * rtc::kNumMicrosecsPerMillisec; |
310 VideoFrame frame(I420Buffer::Create(kWidth, kHeight), | 312 VideoFrame frame(I420Buffer::Create(kWidth, kHeight), |
311 webrtc::kVideoRotation_0, 0); | 313 webrtc::kVideoRotation_0, webrtc::VideoContentType::kDefault, |
| 314 0); |
312 uint32_t timestamp = 0; | 315 uint32_t timestamp = 0; |
313 for (size_t i = 0; i < 1000; ++i) { | 316 for (size_t i = 0; i < 1000; ++i) { |
314 frame.set_timestamp(timestamp); | 317 frame.set_timestamp(timestamp); |
315 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); | 318 overuse_detector_->FrameCaptured(frame, rtc::TimeMicros()); |
316 // Encode and send first parts almost instantly. | 319 // Encode and send first parts almost instantly. |
317 clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec); | 320 clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec); |
318 overuse_detector_->FrameSent(timestamp, rtc::TimeMicros()); | 321 overuse_detector_->FrameSent(timestamp, rtc::TimeMicros()); |
319 // Encode heavier part, resulting in >85% usage total. | 322 // Encode heavier part, resulting in >85% usage total. |
320 clock_.AdvanceTimeMicros(kDelayUs - rtc::kNumMicrosecsPerMillisec); | 323 clock_.AdvanceTimeMicros(kDelayUs - rtc::kNumMicrosecsPerMillisec); |
321 overuse_detector_->FrameSent(timestamp, rtc::TimeMicros()); | 324 overuse_detector_->FrameSent(timestamp, rtc::TimeMicros()); |
(...skipping 27 matching lines...) Expand all Loading... |
349 InsertAndSendFramesWithInterval(1300, kFrameIntervalUs, kWidth, kHeight, | 352 InsertAndSendFramesWithInterval(1300, kFrameIntervalUs, kWidth, kHeight, |
350 kDelayUs1); | 353 kDelayUs1); |
351 InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight, | 354 InsertAndSendFramesWithInterval(1, kFrameIntervalUs, kWidth, kHeight, |
352 kDelayUs2); | 355 kDelayUs2); |
353 }); | 356 }); |
354 | 357 |
355 EXPECT_TRUE(event.Wait(10000)); | 358 EXPECT_TRUE(event.Wait(10000)); |
356 } | 359 } |
357 | 360 |
358 } // namespace webrtc | 361 } // namespace webrtc |
OLD | NEW |