| 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 "media/capture/video/video_capture_device.h" | 5 #include "media/capture/video/video_capture_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "media/capture/video/mac/video_capture_device_factory_mac.h" | 36 #include "media/capture/video/mac/video_capture_device_factory_mac.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 #if defined(OS_ANDROID) | 39 #if defined(OS_ANDROID) |
| 40 #include "base/android/build_info.h" | 40 #include "base/android/build_info.h" |
| 41 #include "base/android/jni_android.h" | 41 #include "base/android/jni_android.h" |
| 42 #include "media/capture/video/android/video_capture_device_android.h" | 42 #include "media/capture/video/android/video_capture_device_android.h" |
| 43 #include "media/capture/video/android/video_capture_device_factory_android.h" | 43 #include "media/capture/video/android/video_capture_device_factory_android.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 #if defined(OS_CHROMEOS) |
| 47 #include "media/capture/video/chromeos/video_capture_device_arc_chromeos.h" |
| 48 #include "media/capture/video/chromeos/video_capture_device_factory_chromeos.h" |
| 49 #include "mojo/edk/embedder/embedder.h" |
| 50 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 51 #endif |
| 52 |
| 46 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
| 47 // Mac will always give you the size you ask for and this case will fail. | 54 // Mac will always give you the size you ask for and this case will fail. |
| 48 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 55 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
| 49 // We will always get YUYV from the Mac AVFoundation implementations. | 56 // We will always get YUYV from the Mac AVFoundation implementations. |
| 50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | 57 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg |
| 51 #define MAYBE_TakePhoto TakePhoto | 58 #define MAYBE_TakePhoto TakePhoto |
| 52 #define MAYBE_GetPhotoState GetPhotoState | 59 #define MAYBE_GetPhotoState GetPhotoState |
| 53 #elif defined(OS_WIN) | 60 #elif defined(OS_WIN) |
| 54 #define MAYBE_AllocateBadSize AllocateBadSize | 61 #define MAYBE_AllocateBadSize AllocateBadSize |
| 55 #define MAYBE_CaptureMjpeg CaptureMjpeg | 62 #define MAYBE_CaptureMjpeg CaptureMjpeg |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 205 |
| 199 const mojom::PhotoState* capabilities() { return state_.get(); } | 206 const mojom::PhotoState* capabilities() { return state_.get(); } |
| 200 | 207 |
| 201 private: | 208 private: |
| 202 friend class base::RefCountedThreadSafe<MockImageCaptureClient>; | 209 friend class base::RefCountedThreadSafe<MockImageCaptureClient>; |
| 203 virtual ~MockImageCaptureClient() {} | 210 virtual ~MockImageCaptureClient() {} |
| 204 | 211 |
| 205 mojom::PhotoStatePtr state_; | 212 mojom::PhotoStatePtr state_; |
| 206 }; | 213 }; |
| 207 | 214 |
| 215 #if defined(OS_CHROMEOS) |
| 216 |
| 217 class MojoEnabledTestEnvironment final : public testing::Environment { |
| 218 public: |
| 219 MojoEnabledTestEnvironment() : mojo_ipc_thread_("MojoIpcThread") {} |
| 220 |
| 221 ~MojoEnabledTestEnvironment() final {} |
| 222 |
| 223 void SetUp() final { |
| 224 mojo::edk::Init(); |
| 225 mojo_ipc_thread_.StartWithOptions( |
| 226 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 227 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport( |
| 228 mojo_ipc_thread_.task_runner(), |
| 229 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST)); |
| 230 VLOG(1) << "Mojo initialized"; |
| 231 } |
| 232 |
| 233 void TearDown() final { |
| 234 mojo_ipc_support_.reset(); |
| 235 VLOG(1) << "Mojo IPC tear down"; |
| 236 } |
| 237 |
| 238 private: |
| 239 base::Thread mojo_ipc_thread_; |
| 240 std::unique_ptr<mojo::edk::ScopedIPCSupport> mojo_ipc_support_; |
| 241 }; |
| 242 |
| 243 testing::Environment* const mojo_test_env = |
| 244 testing::AddGlobalTestEnvironment(new MojoEnabledTestEnvironment()); |
| 245 |
| 246 #endif |
| 247 |
| 208 } // namespace | 248 } // namespace |
| 209 | 249 |
| 210 class VideoCaptureDeviceTest : public testing::TestWithParam<gfx::Size> { | 250 class VideoCaptureDeviceTest : public testing::TestWithParam<gfx::Size> { |
| 211 protected: | 251 protected: |
| 212 typedef VideoCaptureDevice::Client Client; | 252 typedef VideoCaptureDevice::Client Client; |
| 213 | 253 |
| 214 VideoCaptureDeviceTest() | 254 VideoCaptureDeviceTest() |
| 215 : device_descriptors_(new VideoCaptureDeviceDescriptors()), | 255 : device_descriptors_(new VideoCaptureDeviceDescriptors()), |
| 216 video_capture_client_(new MockVideoCaptureClient( | 256 video_capture_client_(new MockVideoCaptureClient( |
| 217 base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, | 257 base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 // since we cannot forecast the hardware capabilities. | 560 // since we cannot forecast the hardware capabilities. |
| 521 ASSERT_FALSE(device_descriptor); | 561 ASSERT_FALSE(device_descriptor); |
| 522 } | 562 } |
| 523 | 563 |
| 524 // Starts the camera and verifies that a photo can be taken. The correctness of | 564 // Starts the camera and verifies that a photo can be taken. The correctness of |
| 525 // the photo is enforced by MockImageCaptureClient. | 565 // the photo is enforced by MockImageCaptureClient. |
| 526 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { | 566 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { |
| 527 if (!FindUsableDevices()) | 567 if (!FindUsableDevices()) |
| 528 return; | 568 return; |
| 529 | 569 |
| 570 #if defined(OS_CHROMEOS) |
| 571 // TODO(jcliang): Remove this after we implement TakePhoto. |
| 572 if (VideoCaptureDeviceFactoryChromeOS::ShouldEnable()) { |
| 573 return; |
| 574 } |
| 575 #endif |
| 576 |
| 530 #if defined(OS_ANDROID) | 577 #if defined(OS_ANDROID) |
| 531 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 | 578 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 |
| 532 if (base::android::BuildInfo::GetInstance()->sdk_int() < | 579 if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| 533 base::android::SDK_VERSION_MARSHMALLOW) { | 580 base::android::SDK_VERSION_MARSHMALLOW) { |
| 534 return; | 581 return; |
| 535 } | 582 } |
| 536 #endif | 583 #endif |
| 537 | 584 |
| 538 std::unique_ptr<VideoCaptureDevice> device( | 585 std::unique_ptr<VideoCaptureDevice> device( |
| 539 video_capture_device_factory_->CreateDevice( | 586 video_capture_device_factory_->CreateDevice( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 565 run_loop.Run(); | 612 run_loop.Run(); |
| 566 | 613 |
| 567 device->StopAndDeAllocate(); | 614 device->StopAndDeAllocate(); |
| 568 } | 615 } |
| 569 | 616 |
| 570 // Starts the camera and verifies that the photo capabilities can be retrieved. | 617 // Starts the camera and verifies that the photo capabilities can be retrieved. |
| 571 TEST_F(VideoCaptureDeviceTest, MAYBE_GetPhotoState) { | 618 TEST_F(VideoCaptureDeviceTest, MAYBE_GetPhotoState) { |
| 572 if (!FindUsableDevices()) | 619 if (!FindUsableDevices()) |
| 573 return; | 620 return; |
| 574 | 621 |
| 622 #if defined(OS_CHROMEOS) |
| 623 // TODO(jcliang): Remove this after we implement GetPhotoCapabilities. |
| 624 if (VideoCaptureDeviceFactoryChromeOS::ShouldEnable()) { |
| 625 return; |
| 626 } |
| 627 #endif |
| 628 |
| 575 #if defined(OS_ANDROID) | 629 #if defined(OS_ANDROID) |
| 576 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 | 630 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 |
| 577 if (base::android::BuildInfo::GetInstance()->sdk_int() < | 631 if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| 578 base::android::SDK_VERSION_MARSHMALLOW) { | 632 base::android::SDK_VERSION_MARSHMALLOW) { |
| 579 return; | 633 return; |
| 580 } | 634 } |
| 581 #endif | 635 #endif |
| 582 | 636 |
| 583 std::unique_ptr<VideoCaptureDevice> device( | 637 std::unique_ptr<VideoCaptureDevice> device( |
| 584 video_capture_device_factory_->CreateDevice( | 638 video_capture_device_factory_->CreateDevice( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 609 | 663 |
| 610 device->GetPhotoState(std::move(scoped_get_callback)); | 664 device->GetPhotoState(std::move(scoped_get_callback)); |
| 611 run_loop.Run(); | 665 run_loop.Run(); |
| 612 | 666 |
| 613 ASSERT_TRUE(image_capture_client_->capabilities()); | 667 ASSERT_TRUE(image_capture_client_->capabilities()); |
| 614 | 668 |
| 615 device->StopAndDeAllocate(); | 669 device->StopAndDeAllocate(); |
| 616 } | 670 } |
| 617 | 671 |
| 618 }; // namespace media | 672 }; // namespace media |
| OLD | NEW |