| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "media/video/capture/fake_video_capture_device.h" | 12 #include "media/video/capture/fake_video_capture_device.h" |
| 13 #include "media/video/capture/fake_video_capture_device_factory.h" |
| 13 #include "media/video/capture/video_capture_device.h" | 14 #include "media/video/capture/video_capture_device.h" |
| 14 #include "media/video/capture/video_capture_types.h" | 15 #include "media/video/capture/video_capture_types.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 19 #include "base/win/scoped_com_initializer.h" | 20 #include "base/win/scoped_com_initializer.h" |
| 20 #include "media/video/capture/win/video_capture_device_mf_win.h" | 21 #include "media/video/capture/win/video_capture_device_mf_win.h" |
| 21 #endif | 22 #endif |
| 22 | 23 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 class VideoCaptureDeviceTest : public testing::Test { | 98 class VideoCaptureDeviceTest : public testing::Test { |
| 98 protected: | 99 protected: |
| 99 typedef media::VideoCaptureDevice::Client Client; | 100 typedef media::VideoCaptureDevice::Client Client; |
| 100 | 101 |
| 101 VideoCaptureDeviceTest() | 102 VideoCaptureDeviceTest() |
| 102 : loop_(new base::MessageLoop()), | 103 : loop_(new base::MessageLoop()), |
| 103 client_( | 104 client_( |
| 104 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, | 105 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
| 105 base::Unretained(this)))) {} | 106 base::Unretained(this)))), |
| 107 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} |
| 106 | 108 |
| 107 virtual void SetUp() { | 109 virtual void SetUp() { |
| 108 #if defined(OS_ANDROID) | 110 #if defined(OS_ANDROID) |
| 109 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | 111 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
| 110 base::android::AttachCurrentThread()); | 112 base::android::AttachCurrentThread()); |
| 111 #endif | 113 #endif |
| 112 } | 114 } |
| 113 | 115 |
| 114 void ResetWithNewClient() { | 116 void ResetWithNewClient() { |
| 115 client_.reset(new MockClient(base::Bind( | 117 client_.reset(new MockClient(base::Bind( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 157 } |
| 156 | 158 |
| 157 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
| 158 base::win::ScopedCOMInitializer initialize_com_; | 160 base::win::ScopedCOMInitializer initialize_com_; |
| 159 #endif | 161 #endif |
| 160 VideoCaptureDevice::Names names_; | 162 VideoCaptureDevice::Names names_; |
| 161 scoped_ptr<base::MessageLoop> loop_; | 163 scoped_ptr<base::MessageLoop> loop_; |
| 162 scoped_ptr<base::RunLoop> run_loop_; | 164 scoped_ptr<base::RunLoop> run_loop_; |
| 163 scoped_ptr<MockClient> client_; | 165 scoped_ptr<MockClient> client_; |
| 164 VideoCaptureFormat last_format_; | 166 VideoCaptureFormat last_format_; |
| 167 scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; |
| 165 }; | 168 }; |
| 166 | 169 |
| 167 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 170 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
| 168 #if defined(OS_WIN) | 171 #if defined(OS_WIN) |
| 169 VideoCaptureDevice::Name::CaptureApiType api_type = | 172 VideoCaptureDevice::Name::CaptureApiType api_type = |
| 170 VideoCaptureDeviceMFWin::PlatformSupported() | 173 VideoCaptureDeviceMFWin::PlatformSupported() |
| 171 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION | 174 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION |
| 172 : VideoCaptureDevice::Name::DIRECT_SHOW; | 175 : VideoCaptureDevice::Name::DIRECT_SHOW; |
| 173 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); | 176 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); |
| 174 #else | 177 #else |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 WaitForCapturedFrame(); | 328 WaitForCapturedFrame(); |
| 326 EXPECT_EQ(last_format().frame_size.width(), 640); | 329 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 327 EXPECT_EQ(last_format().frame_size.height(), 480); | 330 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 328 EXPECT_EQ(last_format().frame_rate, 30); | 331 EXPECT_EQ(last_format().frame_rate, 30); |
| 329 device->StopAndDeAllocate(); | 332 device->StopAndDeAllocate(); |
| 330 } | 333 } |
| 331 | 334 |
| 332 TEST_F(VideoCaptureDeviceTest, FakeCapture) { | 335 TEST_F(VideoCaptureDeviceTest, FakeCapture) { |
| 333 VideoCaptureDevice::Names names; | 336 VideoCaptureDevice::Names names; |
| 334 | 337 |
| 335 FakeVideoCaptureDevice::GetDeviceNames(&names); | 338 video_capture_device_factory_->GetDeviceNames(&names); |
| 336 | 339 |
| 337 ASSERT_GT(static_cast<int>(names.size()), 0); | 340 ASSERT_GT(static_cast<int>(names.size()), 0); |
| 338 | 341 |
| 339 scoped_ptr<VideoCaptureDevice> device( | 342 scoped_ptr<VideoCaptureDevice> device( |
| 340 FakeVideoCaptureDevice::Create(names.front())); | 343 video_capture_device_factory_->Create(names.front())); |
| 341 ASSERT_TRUE(device); | 344 ASSERT_TRUE(device); |
| 342 | 345 |
| 343 EXPECT_CALL(*client_, OnErr()) | 346 EXPECT_CALL(*client_, OnErr()) |
| 344 .Times(0); | 347 .Times(0); |
| 345 | 348 |
| 346 VideoCaptureParams capture_params; | 349 VideoCaptureParams capture_params; |
| 347 capture_params.requested_format.frame_size.SetSize(640, 480); | 350 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 348 capture_params.requested_format.frame_rate = 30; | 351 capture_params.requested_format.frame_rate = 30; |
| 349 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 352 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 350 capture_params.allow_resolution_change = false; | 353 capture_params.allow_resolution_change = false; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 scoped_ptr<VideoCaptureDevice::Name> name = | 393 scoped_ptr<VideoCaptureDevice::Name> name = |
| 391 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 394 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 392 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 395 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
| 393 // since we cannot forecast the hardware capabilities. | 396 // since we cannot forecast the hardware capabilities. |
| 394 ASSERT_FALSE(name); | 397 ASSERT_FALSE(name); |
| 395 } | 398 } |
| 396 | 399 |
| 397 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { | 400 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { |
| 398 VideoCaptureDevice::Names names; | 401 VideoCaptureDevice::Names names; |
| 399 | 402 |
| 400 FakeVideoCaptureDevice::GetDeviceNames(&names); | 403 video_capture_device_factory_->GetDeviceNames(&names); |
| 401 VideoCaptureParams capture_params; | 404 VideoCaptureParams capture_params; |
| 402 capture_params.requested_format.frame_size.SetSize(640, 480); | 405 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 403 capture_params.requested_format.frame_rate = 30; | 406 capture_params.requested_format.frame_rate = 30; |
| 404 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 407 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 405 capture_params.allow_resolution_change = true; | 408 capture_params.allow_resolution_change = true; |
| 406 | 409 |
| 407 ASSERT_GT(static_cast<int>(names.size()), 0); | 410 ASSERT_GT(static_cast<int>(names.size()), 0); |
| 408 | 411 |
| 409 scoped_ptr<VideoCaptureDevice> device( | 412 scoped_ptr<VideoCaptureDevice> device( |
| 410 FakeVideoCaptureDevice::Create(names.front())); | 413 video_capture_device_factory_->Create(names.front())); |
| 411 ASSERT_TRUE(device); | 414 ASSERT_TRUE(device); |
| 412 | 415 |
| 413 EXPECT_CALL(*client_, OnErr()) | 416 EXPECT_CALL(*client_, OnErr()) |
| 414 .Times(0); | 417 .Times(0); |
| 415 int action_count = 200; | 418 int action_count = 200; |
| 416 | 419 |
| 417 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 420 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
| 418 | 421 |
| 419 // We set TimeWait to 200 action timeouts and this should be enough for at | 422 // We set TimeWait to 200 action timeouts and this should be enough for at |
| 420 // least action_count/kFakeCaptureCapabilityChangePeriod calls. | 423 // least action_count/kFakeCaptureCapabilityChangePeriod calls. |
| 421 for (int i = 0; i < action_count; ++i) { | 424 for (int i = 0; i < action_count; ++i) { |
| 422 WaitForCapturedFrame(); | 425 WaitForCapturedFrame(); |
| 423 } | 426 } |
| 424 device->StopAndDeAllocate(); | 427 device->StopAndDeAllocate(); |
| 425 } | 428 } |
| 426 | 429 |
| 427 TEST_F(VideoCaptureDeviceTest, FakeGetDeviceSupportedFormats) { | 430 TEST_F(VideoCaptureDeviceTest, FakeGetDeviceSupportedFormats) { |
| 428 VideoCaptureDevice::Names names; | 431 VideoCaptureDevice::Names names; |
| 429 FakeVideoCaptureDevice::GetDeviceNames(&names); | 432 video_capture_device_factory_->GetDeviceNames(&names); |
| 430 | 433 |
| 431 VideoCaptureFormats supported_formats; | 434 VideoCaptureFormats supported_formats; |
| 432 VideoCaptureDevice::Names::iterator names_iterator; | 435 VideoCaptureDevice::Names::iterator names_iterator; |
| 433 | 436 |
| 434 for (names_iterator = names.begin(); names_iterator != names.end(); | 437 for (names_iterator = names.begin(); names_iterator != names.end(); |
| 435 ++names_iterator) { | 438 ++names_iterator) { |
| 436 FakeVideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator, | 439 video_capture_device_factory_->GetDeviceSupportedFormats( |
| 437 &supported_formats); | 440 *names_iterator, &supported_formats); |
| 438 EXPECT_EQ(supported_formats.size(), 3u); | 441 EXPECT_EQ(supported_formats.size(), 3u); |
| 439 EXPECT_EQ(supported_formats[0].frame_size.width(), 320); | 442 EXPECT_EQ(supported_formats[0].frame_size.width(), 320); |
| 440 EXPECT_EQ(supported_formats[0].frame_size.height(), 240); | 443 EXPECT_EQ(supported_formats[0].frame_size.height(), 240); |
| 441 EXPECT_EQ(supported_formats[0].pixel_format, media::PIXEL_FORMAT_I420); | 444 EXPECT_EQ(supported_formats[0].pixel_format, media::PIXEL_FORMAT_I420); |
| 442 EXPECT_GE(supported_formats[0].frame_rate, 20); | 445 EXPECT_GE(supported_formats[0].frame_rate, 20); |
| 443 EXPECT_EQ(supported_formats[1].frame_size.width(), 640); | 446 EXPECT_EQ(supported_formats[1].frame_size.width(), 640); |
| 444 EXPECT_EQ(supported_formats[1].frame_size.height(), 480); | 447 EXPECT_EQ(supported_formats[1].frame_size.height(), 480); |
| 445 EXPECT_EQ(supported_formats[1].pixel_format, media::PIXEL_FORMAT_I420); | 448 EXPECT_EQ(supported_formats[1].pixel_format, media::PIXEL_FORMAT_I420); |
| 446 EXPECT_GE(supported_formats[1].frame_rate, 20); | 449 EXPECT_GE(supported_formats[1].frame_rate, 20); |
| 447 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); | 450 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); |
| 448 EXPECT_EQ(supported_formats[2].frame_size.height(), 720); | 451 EXPECT_EQ(supported_formats[2].frame_size.height(), 720); |
| 449 EXPECT_EQ(supported_formats[2].pixel_format, media::PIXEL_FORMAT_I420); | 452 EXPECT_EQ(supported_formats[2].pixel_format, media::PIXEL_FORMAT_I420); |
| 450 EXPECT_GE(supported_formats[2].frame_rate, 20); | 453 EXPECT_GE(supported_formats[2].frame_rate, 20); |
| 451 } | 454 } |
| 452 } | 455 } |
| 453 | 456 |
| 454 }; // namespace media | 457 }; // namespace media |
| OLD | NEW |