OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 <stdio.h> | 11 #include <stdio.h> |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 #include <memory> | 14 #include <memory> |
15 #include <sstream> | 15 #include <sstream> |
16 | 16 |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webrtc/base/scoped_ref_ptr.h" | 18 #include "webrtc/base/scoped_ref_ptr.h" |
19 #include "webrtc/base/timeutils.h" | |
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 20 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
20 #include "webrtc/modules/utility/include/process_thread.h" | 21 #include "webrtc/modules/utility/include/process_thread.h" |
21 #include "webrtc/modules/video_capture/video_capture.h" | 22 #include "webrtc/modules/video_capture/video_capture.h" |
22 #include "webrtc/modules/video_capture/video_capture_factory.h" | 23 #include "webrtc/modules/video_capture/video_capture_factory.h" |
23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 24 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
24 #include "webrtc/system_wrappers/include/sleep.h" | 25 #include "webrtc/system_wrappers/include/sleep.h" |
25 #include "webrtc/system_wrappers/include/tick_util.h" | |
26 #include "webrtc/video_frame.h" | 26 #include "webrtc/video_frame.h" |
27 | 27 |
28 using webrtc::CriticalSectionWrapper; | 28 using webrtc::CriticalSectionWrapper; |
29 using webrtc::CriticalSectionScoped; | 29 using webrtc::CriticalSectionScoped; |
30 using webrtc::SleepMs; | 30 using webrtc::SleepMs; |
31 using webrtc::TickTime; | |
32 using webrtc::VideoCaptureAlarm; | 31 using webrtc::VideoCaptureAlarm; |
33 using webrtc::VideoCaptureCapability; | 32 using webrtc::VideoCaptureCapability; |
34 using webrtc::VideoCaptureDataCallback; | 33 using webrtc::VideoCaptureDataCallback; |
35 using webrtc::VideoCaptureFactory; | 34 using webrtc::VideoCaptureFactory; |
36 using webrtc::VideoCaptureFeedBack; | 35 using webrtc::VideoCaptureFeedBack; |
37 using webrtc::VideoCaptureModule; | 36 using webrtc::VideoCaptureModule; |
38 | 37 |
39 | 38 |
40 #define WAIT_(ex, timeout, res) \ | 39 #define WAIT_(ex, timeout, res) \ |
41 do { \ | 40 do { \ |
42 res = (ex); \ | 41 res = (ex); \ |
43 int64_t start = TickTime::MillisecondTimestamp(); \ | 42 int64_t start = rtc::Time64(); \ |
44 while (!res && TickTime::MillisecondTimestamp() < start + timeout) { \ | 43 while (!res && rtc::Time64() < start + timeout) { \ |
45 SleepMs(5); \ | 44 SleepMs(5); \ |
46 res = (ex); \ | 45 res = (ex); \ |
47 } \ | 46 } \ |
48 } while (0) | 47 } while (0) |
49 | 48 |
50 #define EXPECT_TRUE_WAIT(ex, timeout) \ | 49 #define EXPECT_TRUE_WAIT(ex, timeout) \ |
51 do { \ | 50 do { \ |
52 bool res; \ | 51 bool res; \ |
53 WAIT_(ex, timeout, res); \ | 52 WAIT_(ex, timeout, res); \ |
54 if (!res) EXPECT_TRUE(ex); \ | 53 if (!res) EXPECT_TRUE(ex); \ |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 // orientation. | 110 // orientation. |
112 EXPECT_TRUE(height == capability_.height || height == capability_.width); | 111 EXPECT_TRUE(height == capability_.height || height == capability_.width); |
113 EXPECT_TRUE(width == capability_.width || width == capability_.height); | 112 EXPECT_TRUE(width == capability_.width || width == capability_.height); |
114 #else | 113 #else |
115 EXPECT_EQ(height, capability_.height); | 114 EXPECT_EQ(height, capability_.height); |
116 EXPECT_EQ(width, capability_.width); | 115 EXPECT_EQ(width, capability_.width); |
117 EXPECT_EQ(rotate_frame_, videoFrame.rotation()); | 116 EXPECT_EQ(rotate_frame_, videoFrame.rotation()); |
118 #endif | 117 #endif |
119 // RenderTimstamp should be the time now. | 118 // RenderTimstamp should be the time now. |
120 EXPECT_TRUE( | 119 EXPECT_TRUE( |
121 videoFrame.render_time_ms() >= TickTime::MillisecondTimestamp()-30 && | 120 videoFrame.render_time_ms() >= rtc::Time64()-30 && |
122 videoFrame.render_time_ms() <= TickTime::MillisecondTimestamp()); | 121 videoFrame.render_time_ms() <= rtc::Time64()); |
123 | 122 |
124 if ((videoFrame.render_time_ms() > | 123 if ((videoFrame.render_time_ms() > |
125 last_render_time_ms_ + (1000 * 1.1) / capability_.maxFPS && | 124 last_render_time_ms_ + (1000 * 1.1) / capability_.maxFPS && |
126 last_render_time_ms_ > 0) || | 125 last_render_time_ms_ > 0) || |
127 (videoFrame.render_time_ms() < | 126 (videoFrame.render_time_ms() < |
128 last_render_time_ms_ + (1000 * 0.9) / capability_.maxFPS && | 127 last_render_time_ms_ + (1000 * 0.9) / capability_.maxFPS && |
129 last_render_time_ms_ > 0)) { | 128 last_render_time_ms_ > 0)) { |
130 timing_warnings_++; | 129 timing_warnings_++; |
131 } | 130 } |
132 | 131 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 | 269 |
271 #ifdef WEBRTC_MAC | 270 #ifdef WEBRTC_MAC |
272 // Currently fails on Mac 64-bit, see | 271 // Currently fails on Mac 64-bit, see |
273 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406 | 272 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406 |
274 #define MAYBE_CreateDelete DISABLED_CreateDelete | 273 #define MAYBE_CreateDelete DISABLED_CreateDelete |
275 #else | 274 #else |
276 #define MAYBE_CreateDelete CreateDelete | 275 #define MAYBE_CreateDelete CreateDelete |
277 #endif | 276 #endif |
278 TEST_F(VideoCaptureTest, MAYBE_CreateDelete) { | 277 TEST_F(VideoCaptureTest, MAYBE_CreateDelete) { |
279 for (int i = 0; i < 5; ++i) { | 278 for (int i = 0; i < 5; ++i) { |
280 int64_t start_time = TickTime::MillisecondTimestamp(); | 279 int64_t start_time = rtc::Time64(); |
281 TestVideoCaptureCallback capture_observer; | 280 TestVideoCaptureCallback capture_observer; |
282 rtc::scoped_refptr<VideoCaptureModule> module( | 281 rtc::scoped_refptr<VideoCaptureModule> module( |
283 OpenVideoCaptureDevice(0, &capture_observer)); | 282 OpenVideoCaptureDevice(0, &capture_observer)); |
284 ASSERT_TRUE(module.get() != NULL); | 283 ASSERT_TRUE(module.get() != NULL); |
285 | 284 |
286 VideoCaptureCapability capability; | 285 VideoCaptureCapability capability; |
287 #ifndef WEBRTC_MAC | 286 #ifndef WEBRTC_MAC |
288 device_info_->GetCapability(module->CurrentDeviceName(), 0, capability); | 287 device_info_->GetCapability(module->CurrentDeviceName(), 0, capability); |
289 #else | 288 #else |
290 capability.width = kTestWidth; | 289 capability.width = kTestWidth; |
291 capability.height = kTestHeight; | 290 capability.height = kTestHeight; |
292 capability.maxFPS = kTestFramerate; | 291 capability.maxFPS = kTestFramerate; |
293 capability.rawType = webrtc::kVideoUnknown; | 292 capability.rawType = webrtc::kVideoUnknown; |
294 #endif | 293 #endif |
295 capture_observer.SetExpectedCapability(capability); | 294 capture_observer.SetExpectedCapability(capability); |
296 ASSERT_NO_FATAL_FAILURE(StartCapture(module.get(), capability)); | 295 ASSERT_NO_FATAL_FAILURE(StartCapture(module.get(), capability)); |
297 | 296 |
298 // Less than 4s to start the camera. | 297 // Less than 4s to start the camera. |
299 EXPECT_LE(TickTime::MillisecondTimestamp() - start_time, 4000); | 298 EXPECT_LE(rtc::Time64() - start_time, 4000); |
300 | 299 |
301 // Make sure 5 frames are captured. | 300 // Make sure 5 frames are captured. |
302 EXPECT_TRUE_WAIT(capture_observer.incoming_frames() >= 5, kTimeOut); | 301 EXPECT_TRUE_WAIT(capture_observer.incoming_frames() >= 5, kTimeOut); |
303 | 302 |
304 EXPECT_GE(capture_observer.capture_delay(), 0); | 303 EXPECT_GE(capture_observer.capture_delay(), 0); |
305 | 304 |
306 int64_t stop_time = TickTime::MillisecondTimestamp(); | 305 int64_t stop_time = rtc::Time64(); |
307 EXPECT_EQ(0, module->StopCapture()); | 306 EXPECT_EQ(0, module->StopCapture()); |
308 EXPECT_FALSE(module->CaptureStarted()); | 307 EXPECT_FALSE(module->CaptureStarted()); |
309 | 308 |
310 // Less than 3s to stop the camera. | 309 // Less than 3s to stop the camera. |
311 EXPECT_LE(TickTime::MillisecondTimestamp() - stop_time, 3000); | 310 EXPECT_LE(rtc::Time64() - stop_time, 3000); |
312 } | 311 } |
313 } | 312 } |
314 | 313 |
315 #ifdef WEBRTC_MAC | 314 #ifdef WEBRTC_MAC |
316 // Currently fails on Mac 64-bit, see | 315 // Currently fails on Mac 64-bit, see |
317 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406 | 316 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406 |
318 #define MAYBE_Capabilities DISABLED_Capabilities | 317 #define MAYBE_Capabilities DISABLED_Capabilities |
319 #else | 318 #else |
320 #define MAYBE_Capabilities Capabilities | 319 #define MAYBE_Capabilities Capabilities |
321 #endif | 320 #endif |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 | 486 |
488 // Test frame rate and no picture alarm. | 487 // Test frame rate and no picture alarm. |
489 // Flaky on Win32, see webrtc:3270. | 488 // Flaky on Win32, see webrtc:3270. |
490 #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC) | 489 #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC) |
491 #define MAYBE_FrameRate DISABLED_FrameRate | 490 #define MAYBE_FrameRate DISABLED_FrameRate |
492 #else | 491 #else |
493 #define MAYBE_FrameRate FrameRate | 492 #define MAYBE_FrameRate FrameRate |
494 #endif | 493 #endif |
495 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { | 494 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { |
496 int64_t testTime = 3; | 495 int64_t testTime = 3; |
497 TickTime startTime = TickTime::Now(); | 496 int64_t startTime = rtc::TimeNanos(); |
stefan-webrtc
2016/04/19 09:19:12
Seems like startTime should be the same type as re
nisse-webrtc
2016/04/19 12:19:25
Done. Typing seem a bit confused, TimeNanos and Ti
stefan-webrtc
2016/04/19 12:40:47
Do you think there's a reason to return uint64_t f
nisse-webrtc
2016/04/19 13:48:50
I don't have a strong opinion here. Changing retur
| |
498 | 497 |
499 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { | 498 while ((static_cast<int64_t>(rtc::TimeNanos()) - startTime) / |
499 rtc::kNumNanosecsPerMillisec < | |
500 testTime * 1000) { | |
500 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 501 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
501 test_frame_.width(), | 502 test_frame_.width(), |
502 test_frame_.height()); | 503 test_frame_.height()); |
503 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 504 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
504 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); | 505 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); |
505 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 506 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
506 length, capture_callback_.capability(), 0)); | 507 length, capture_callback_.capability(), 0)); |
507 SleepMs(100); | 508 SleepMs(100); |
508 } | 509 } |
509 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && | 510 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && |
510 capture_feedback_.frame_rate() <= 10); | 511 capture_feedback_.frame_rate() <= 10); |
511 SleepMs(500); | 512 SleepMs(500); |
512 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); | 513 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); |
513 | 514 |
514 startTime = TickTime::Now(); | 515 startTime = rtc::TimeNanos(); |
515 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { | 516 while ((static_cast<int64_t>(rtc::TimeNanos()) - startTime) / |
517 rtc::kNumNanosecsPerMillisec < | |
518 testTime * 1000) { | |
516 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 519 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
517 test_frame_.width(), | 520 test_frame_.width(), |
518 test_frame_.height()); | 521 test_frame_.height()); |
519 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 522 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
520 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); | 523 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); |
521 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 524 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
522 length, capture_callback_.capability(), 0)); | 525 length, capture_callback_.capability(), 0)); |
523 SleepMs(1000 / 30); | 526 SleepMs(1000 / 30); |
524 } | 527 } |
525 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); | 528 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); |
(...skipping 18 matching lines...) Expand all Loading... | |
544 length, capture_callback_.capability(), 0)); | 547 length, capture_callback_.capability(), 0)); |
545 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); | 548 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); |
546 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); | 549 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); |
547 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 550 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
548 length, capture_callback_.capability(), 0)); | 551 length, capture_callback_.capability(), 0)); |
549 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); | 552 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); |
550 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); | 553 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); |
551 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 554 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
552 length, capture_callback_.capability(), 0)); | 555 length, capture_callback_.capability(), 0)); |
553 } | 556 } |
OLD | NEW |