| 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 <sstream> | 14 #include <sstream> |
| 15 | 15 |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
| 18 #include "webrtc/base/scoped_ref_ptr.h" |
| 18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 19 #include "webrtc/modules/utility/interface/process_thread.h" | 20 #include "webrtc/modules/utility/interface/process_thread.h" |
| 20 #include "webrtc/modules/video_capture/ensure_initialized.h" | 21 #include "webrtc/modules/video_capture/ensure_initialized.h" |
| 21 #include "webrtc/modules/video_capture/include/video_capture.h" | 22 #include "webrtc/modules/video_capture/include/video_capture.h" |
| 22 #include "webrtc/modules/video_capture/include/video_capture_factory.h" | 23 #include "webrtc/modules/video_capture/include/video_capture_factory.h" |
| 23 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 24 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 24 #include "webrtc/system_wrappers/interface/scoped_refptr.h" | |
| 25 #include "webrtc/system_wrappers/interface/sleep.h" | 25 #include "webrtc/system_wrappers/interface/sleep.h" |
| 26 #include "webrtc/system_wrappers/interface/tick_util.h" | 26 #include "webrtc/system_wrappers/interface/tick_util.h" |
| 27 #include "webrtc/test/testsupport/gtest_disable.h" | 27 #include "webrtc/test/testsupport/gtest_disable.h" |
| 28 #include "webrtc/video_frame.h" | 28 #include "webrtc/video_frame.h" |
| 29 | 29 |
| 30 using rtc::scoped_ptr; | 30 using rtc::scoped_ptr; |
| 31 using webrtc::CriticalSectionWrapper; | 31 using webrtc::CriticalSectionWrapper; |
| 32 using webrtc::CriticalSectionScoped; | 32 using webrtc::CriticalSectionScoped; |
| 33 using webrtc::SleepMs; | 33 using webrtc::SleepMs; |
| 34 using webrtc::TickTime; | 34 using webrtc::TickTime; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 VideoCaptureTest() : number_of_devices_(0) {} | 235 VideoCaptureTest() : number_of_devices_(0) {} |
| 236 | 236 |
| 237 void SetUp() { | 237 void SetUp() { |
| 238 webrtc::videocapturemodule::EnsureInitialized(); | 238 webrtc::videocapturemodule::EnsureInitialized(); |
| 239 device_info_.reset(VideoCaptureFactory::CreateDeviceInfo(0)); | 239 device_info_.reset(VideoCaptureFactory::CreateDeviceInfo(0)); |
| 240 assert(device_info_.get()); | 240 assert(device_info_.get()); |
| 241 number_of_devices_ = device_info_->NumberOfDevices(); | 241 number_of_devices_ = device_info_->NumberOfDevices(); |
| 242 ASSERT_GT(number_of_devices_, 0u); | 242 ASSERT_GT(number_of_devices_, 0u); |
| 243 } | 243 } |
| 244 | 244 |
| 245 webrtc::scoped_refptr<VideoCaptureModule> OpenVideoCaptureDevice( | 245 rtc::scoped_refptr<VideoCaptureModule> OpenVideoCaptureDevice( |
| 246 unsigned int device, | 246 unsigned int device, |
| 247 VideoCaptureDataCallback* callback) { | 247 VideoCaptureDataCallback* callback) { |
| 248 char device_name[256]; | 248 char device_name[256]; |
| 249 char unique_name[256]; | 249 char unique_name[256]; |
| 250 | 250 |
| 251 EXPECT_EQ(0, device_info_->GetDeviceName( | 251 EXPECT_EQ(0, device_info_->GetDeviceName( |
| 252 device, device_name, 256, unique_name, 256)); | 252 device, device_name, 256, unique_name, 256)); |
| 253 | 253 |
| 254 webrtc::scoped_refptr<VideoCaptureModule> module( | 254 rtc::scoped_refptr<VideoCaptureModule> module( |
| 255 VideoCaptureFactory::Create(device, unique_name)); | 255 VideoCaptureFactory::Create(device, unique_name)); |
| 256 if (module.get() == NULL) | 256 if (module.get() == NULL) |
| 257 return NULL; | 257 return NULL; |
| 258 | 258 |
| 259 EXPECT_FALSE(module->CaptureStarted()); | 259 EXPECT_FALSE(module->CaptureStarted()); |
| 260 | 260 |
| 261 module->RegisterCaptureDataCallback(*callback); | 261 module->RegisterCaptureDataCallback(*callback); |
| 262 return module; | 262 return module; |
| 263 } | 263 } |
| 264 | 264 |
| 265 void StartCapture(VideoCaptureModule* capture_module, | 265 void StartCapture(VideoCaptureModule* capture_module, |
| 266 VideoCaptureCapability capability) { | 266 VideoCaptureCapability capability) { |
| 267 ASSERT_EQ(0, capture_module->StartCapture(capability)); | 267 ASSERT_EQ(0, capture_module->StartCapture(capability)); |
| 268 EXPECT_TRUE(capture_module->CaptureStarted()); | 268 EXPECT_TRUE(capture_module->CaptureStarted()); |
| 269 | 269 |
| 270 VideoCaptureCapability resulting_capability; | 270 VideoCaptureCapability resulting_capability; |
| 271 EXPECT_EQ(0, capture_module->CaptureSettings(resulting_capability)); | 271 EXPECT_EQ(0, capture_module->CaptureSettings(resulting_capability)); |
| 272 EXPECT_EQ(capability.width, resulting_capability.width); | 272 EXPECT_EQ(capability.width, resulting_capability.width); |
| 273 EXPECT_EQ(capability.height, resulting_capability.height); | 273 EXPECT_EQ(capability.height, resulting_capability.height); |
| 274 } | 274 } |
| 275 | 275 |
| 276 scoped_ptr<VideoCaptureModule::DeviceInfo> device_info_; | 276 scoped_ptr<VideoCaptureModule::DeviceInfo> device_info_; |
| 277 unsigned int number_of_devices_; | 277 unsigned int number_of_devices_; |
| 278 }; | 278 }; |
| 279 | 279 |
| 280 TEST_F(VideoCaptureTest, CreateDelete) { | 280 TEST_F(VideoCaptureTest, CreateDelete) { |
| 281 for (int i = 0; i < 5; ++i) { | 281 for (int i = 0; i < 5; ++i) { |
| 282 int64_t start_time = TickTime::MillisecondTimestamp(); | 282 int64_t start_time = TickTime::MillisecondTimestamp(); |
| 283 TestVideoCaptureCallback capture_observer; | 283 TestVideoCaptureCallback capture_observer; |
| 284 webrtc::scoped_refptr<VideoCaptureModule> module(OpenVideoCaptureDevice( | 284 rtc::scoped_refptr<VideoCaptureModule> module( |
| 285 0, &capture_observer)); | 285 OpenVideoCaptureDevice(0, &capture_observer)); |
| 286 ASSERT_TRUE(module.get() != NULL); | 286 ASSERT_TRUE(module.get() != NULL); |
| 287 | 287 |
| 288 VideoCaptureCapability capability; | 288 VideoCaptureCapability capability; |
| 289 #ifndef WEBRTC_MAC | 289 #ifndef WEBRTC_MAC |
| 290 device_info_->GetCapability(module->CurrentDeviceName(), 0, capability); | 290 device_info_->GetCapability(module->CurrentDeviceName(), 0, capability); |
| 291 #else | 291 #else |
| 292 capability.width = kTestWidth; | 292 capability.width = kTestWidth; |
| 293 capability.height = kTestHeight; | 293 capability.height = kTestHeight; |
| 294 capability.maxFPS = kTestFramerate; | 294 capability.maxFPS = kTestFramerate; |
| 295 capability.rawType = webrtc::kVideoUnknown; | 295 capability.rawType = webrtc::kVideoUnknown; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 315 } | 315 } |
| 316 | 316 |
| 317 TEST_F(VideoCaptureTest, Capabilities) { | 317 TEST_F(VideoCaptureTest, Capabilities) { |
| 318 #ifdef WEBRTC_MAC | 318 #ifdef WEBRTC_MAC |
| 319 printf("Video capture capabilities are not supported on Mac.\n"); | 319 printf("Video capture capabilities are not supported on Mac.\n"); |
| 320 return; | 320 return; |
| 321 #endif | 321 #endif |
| 322 | 322 |
| 323 TestVideoCaptureCallback capture_observer; | 323 TestVideoCaptureCallback capture_observer; |
| 324 | 324 |
| 325 webrtc::scoped_refptr<VideoCaptureModule> module(OpenVideoCaptureDevice( | 325 rtc::scoped_refptr<VideoCaptureModule> module( |
| 326 0, &capture_observer)); | 326 OpenVideoCaptureDevice(0, &capture_observer)); |
| 327 ASSERT_TRUE(module.get() != NULL); | 327 ASSERT_TRUE(module.get() != NULL); |
| 328 | 328 |
| 329 int number_of_capabilities = device_info_->NumberOfCapabilities( | 329 int number_of_capabilities = device_info_->NumberOfCapabilities( |
| 330 module->CurrentDeviceName()); | 330 module->CurrentDeviceName()); |
| 331 EXPECT_GT(number_of_capabilities, 0); | 331 EXPECT_GT(number_of_capabilities, 0); |
| 332 // Key is <width>x<height>, value is vector of maxFPS values at that | 332 // Key is <width>x<height>, value is vector of maxFPS values at that |
| 333 // resolution. | 333 // resolution. |
| 334 typedef std::map<std::string, std::vector<int> > FrameRatesByResolution; | 334 typedef std::map<std::string, std::vector<int> > FrameRatesByResolution; |
| 335 FrameRatesByResolution frame_rates_by_resolution; | 335 FrameRatesByResolution frame_rates_by_resolution; |
| 336 for (int i = 0; i < number_of_capabilities; ++i) { | 336 for (int i = 0; i < number_of_capabilities; ++i) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 377 |
| 378 // NOTE: flaky, crashes sometimes. | 378 // NOTE: flaky, crashes sometimes. |
| 379 // http://code.google.com/p/webrtc/issues/detail?id=777 | 379 // http://code.google.com/p/webrtc/issues/detail?id=777 |
| 380 TEST_F(VideoCaptureTest, DISABLED_TestTwoCameras) { | 380 TEST_F(VideoCaptureTest, DISABLED_TestTwoCameras) { |
| 381 if (number_of_devices_ < 2) { | 381 if (number_of_devices_ < 2) { |
| 382 printf("There are not two cameras available. Aborting test. \n"); | 382 printf("There are not two cameras available. Aborting test. \n"); |
| 383 return; | 383 return; |
| 384 } | 384 } |
| 385 | 385 |
| 386 TestVideoCaptureCallback capture_observer1; | 386 TestVideoCaptureCallback capture_observer1; |
| 387 webrtc::scoped_refptr<VideoCaptureModule> module1(OpenVideoCaptureDevice( | 387 rtc::scoped_refptr<VideoCaptureModule> module1( |
| 388 0, &capture_observer1)); | 388 OpenVideoCaptureDevice(0, &capture_observer1)); |
| 389 ASSERT_TRUE(module1.get() != NULL); | 389 ASSERT_TRUE(module1.get() != NULL); |
| 390 VideoCaptureCapability capability1; | 390 VideoCaptureCapability capability1; |
| 391 #ifndef WEBRTC_MAC | 391 #ifndef WEBRTC_MAC |
| 392 device_info_->GetCapability(module1->CurrentDeviceName(), 0, capability1); | 392 device_info_->GetCapability(module1->CurrentDeviceName(), 0, capability1); |
| 393 #else | 393 #else |
| 394 capability1.width = kTestWidth; | 394 capability1.width = kTestWidth; |
| 395 capability1.height = kTestHeight; | 395 capability1.height = kTestHeight; |
| 396 capability1.maxFPS = kTestFramerate; | 396 capability1.maxFPS = kTestFramerate; |
| 397 capability1.rawType = webrtc::kVideoUnknown; | 397 capability1.rawType = webrtc::kVideoUnknown; |
| 398 #endif | 398 #endif |
| 399 capture_observer1.SetExpectedCapability(capability1); | 399 capture_observer1.SetExpectedCapability(capability1); |
| 400 | 400 |
| 401 TestVideoCaptureCallback capture_observer2; | 401 TestVideoCaptureCallback capture_observer2; |
| 402 webrtc::scoped_refptr<VideoCaptureModule> module2(OpenVideoCaptureDevice( | 402 rtc::scoped_refptr<VideoCaptureModule> module2( |
| 403 1, &capture_observer2)); | 403 OpenVideoCaptureDevice(1, &capture_observer2)); |
| 404 ASSERT_TRUE(module1.get() != NULL); | 404 ASSERT_TRUE(module1.get() != NULL); |
| 405 | 405 |
| 406 | 406 |
| 407 VideoCaptureCapability capability2; | 407 VideoCaptureCapability capability2; |
| 408 #ifndef WEBRTC_MAC | 408 #ifndef WEBRTC_MAC |
| 409 device_info_->GetCapability(module2->CurrentDeviceName(), 0, capability2); | 409 device_info_->GetCapability(module2->CurrentDeviceName(), 0, capability2); |
| 410 #else | 410 #else |
| 411 capability2.width = kTestWidth; | 411 capability2.width = kTestWidth; |
| 412 capability2.height = kTestHeight; | 412 capability2.height = kTestHeight; |
| 413 capability2.maxFPS = kTestFramerate; | 413 capability2.maxFPS = kTestFramerate; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 capture_module_->RegisterCaptureCallback(capture_feedback_); | 453 capture_module_->RegisterCaptureCallback(capture_feedback_); |
| 454 capture_module_->EnableFrameRateCallback(true); | 454 capture_module_->EnableFrameRateCallback(true); |
| 455 capture_module_->EnableNoPictureAlarm(true); | 455 capture_module_->EnableNoPictureAlarm(true); |
| 456 } | 456 } |
| 457 | 457 |
| 458 void TearDown() { | 458 void TearDown() { |
| 459 process_module_->Stop(); | 459 process_module_->Stop(); |
| 460 } | 460 } |
| 461 | 461 |
| 462 webrtc::VideoCaptureExternal* capture_input_interface_; | 462 webrtc::VideoCaptureExternal* capture_input_interface_; |
| 463 webrtc::scoped_refptr<VideoCaptureModule> capture_module_; | 463 rtc::scoped_refptr<VideoCaptureModule> capture_module_; |
| 464 rtc::scoped_ptr<webrtc::ProcessThread> process_module_; | 464 rtc::scoped_ptr<webrtc::ProcessThread> process_module_; |
| 465 webrtc::VideoFrame test_frame_; | 465 webrtc::VideoFrame test_frame_; |
| 466 TestVideoCaptureCallback capture_callback_; | 466 TestVideoCaptureCallback capture_callback_; |
| 467 TestVideoCaptureFeedBack capture_feedback_; | 467 TestVideoCaptureFeedBack capture_feedback_; |
| 468 }; | 468 }; |
| 469 | 469 |
| 470 // Test input of external video frames. | 470 // Test input of external video frames. |
| 471 TEST_F(VideoCaptureExternalTest, TestExternalCapture) { | 471 TEST_F(VideoCaptureExternalTest, TestExternalCapture) { |
| 472 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 472 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
| 473 test_frame_.width(), | 473 test_frame_.width(), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 length, capture_callback_.capability(), 0)); | 533 length, capture_callback_.capability(), 0)); |
| 534 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); | 534 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); |
| 535 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); | 535 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); |
| 536 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 536 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 537 length, capture_callback_.capability(), 0)); | 537 length, capture_callback_.capability(), 0)); |
| 538 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); | 538 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); |
| 539 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); | 539 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); |
| 540 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 540 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 541 length, capture_callback_.capability(), 0)); | 541 length, capture_callback_.capability(), 0)); |
| 542 } | 542 } |
| OLD | NEW |