| 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::TimeMillis(); \ |
| 44 while (!res && TickTime::MillisecondTimestamp() < start + timeout) { \ | 43 while (!res && rtc::TimeMillis() < 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::TimeMillis()-30 && |
| 122 videoFrame.render_time_ms() <= TickTime::MillisecondTimestamp()); | 121 videoFrame.render_time_ms() <= rtc::TimeMillis()); |
| 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::TimeMillis(); |
| 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::TimeMillis() - 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::TimeMillis(); |
| 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::TimeMillis() - 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 } | 484 } |
| 486 | 485 |
| 487 // Test frame rate and no picture alarm. | 486 // Test frame rate and no picture alarm. |
| 488 // Flaky on Win32, see webrtc:3270. | 487 // Flaky on Win32, see webrtc:3270. |
| 489 #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC) | 488 #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC) |
| 490 #define MAYBE_FrameRate DISABLED_FrameRate | 489 #define MAYBE_FrameRate DISABLED_FrameRate |
| 491 #else | 490 #else |
| 492 #define MAYBE_FrameRate FrameRate | 491 #define MAYBE_FrameRate FrameRate |
| 493 #endif | 492 #endif |
| 494 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { | 493 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { |
| 495 int64_t testTime = 3; | 494 uint64_t testTime = 3 * rtc::kNumNanosecsPerSec; |
| 496 TickTime startTime = TickTime::Now(); | 495 uint64_t startTime = rtc::TimeNanos(); |
| 497 | 496 |
| 498 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { | 497 while ((rtc::TimeNanos() - startTime) < testTime) { |
| 499 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 498 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
| 500 test_frame_.width(), | 499 test_frame_.width(), |
| 501 test_frame_.height()); | 500 test_frame_.height()); |
| 502 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 501 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
| 503 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); | 502 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); |
| 504 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 503 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 505 length, capture_callback_.capability(), 0)); | 504 length, capture_callback_.capability(), 0)); |
| 506 SleepMs(100); | 505 SleepMs(100); |
| 507 } | 506 } |
| 508 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && | 507 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && |
| 509 capture_feedback_.frame_rate() <= 10); | 508 capture_feedback_.frame_rate() <= 10); |
| 510 SleepMs(500); | 509 SleepMs(500); |
| 511 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); | 510 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); |
| 512 | 511 |
| 513 startTime = TickTime::Now(); | 512 startTime = rtc::TimeNanos(); |
| 514 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { | 513 while ((rtc::TimeNanos() - startTime) < testTime) { |
| 515 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 514 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
| 516 test_frame_.width(), | 515 test_frame_.width(), |
| 517 test_frame_.height()); | 516 test_frame_.height()); |
| 518 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 517 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
| 519 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); | 518 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); |
| 520 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 519 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 521 length, capture_callback_.capability(), 0)); | 520 length, capture_callback_.capability(), 0)); |
| 522 SleepMs(1000 / 30); | 521 SleepMs(1000 / 30); |
| 523 } | 522 } |
| 524 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); | 523 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 543 length, capture_callback_.capability(), 0)); | 542 length, capture_callback_.capability(), 0)); |
| 544 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); | 543 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); |
| 545 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); | 544 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); |
| 546 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 545 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 547 length, capture_callback_.capability(), 0)); | 546 length, capture_callback_.capability(), 0)); |
| 548 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); | 547 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); |
| 549 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); | 548 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); |
| 550 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 549 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 551 length, capture_callback_.capability(), 0)); | 550 length, capture_callback_.capability(), 0)); |
| 552 } | 551 } |
| OLD | NEW |