| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_MACOSX) | 46 #if defined(OS_MACOSX) |
| 47 // Mac will always give you the size you ask for and this case will fail. | 47 // Mac will always give you the size you ask for and this case will fail. |
| 48 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 48 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
| 49 // We will always get YUYV from the Mac AVFoundation implementations. | 49 // We will always get YUYV from the Mac AVFoundation implementations. |
| 50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | 50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg |
| 51 #define MAYBE_TakePhoto TakePhoto | 51 #define MAYBE_TakePhoto TakePhoto |
| 52 #define MAYBE_GetPhotoCapabilities DISABLED_GetPhotoCapabilities | |
| 53 #elif defined(OS_WIN) | 52 #elif defined(OS_WIN) |
| 54 #define MAYBE_AllocateBadSize AllocateBadSize | 53 #define MAYBE_AllocateBadSize AllocateBadSize |
| 55 #define MAYBE_CaptureMjpeg CaptureMjpeg | 54 #define MAYBE_CaptureMjpeg CaptureMjpeg |
| 56 #define MAYBE_TakePhoto TakePhoto | 55 #define MAYBE_TakePhoto TakePhoto |
| 57 #define MAYBE_GetPhotoCapabilities DISABLED_GetPhotoCapabilities | |
| 58 #elif defined(OS_ANDROID) | 56 #elif defined(OS_ANDROID) |
| 59 #define MAYBE_AllocateBadSize AllocateBadSize | 57 #define MAYBE_AllocateBadSize AllocateBadSize |
| 60 #define MAYBE_CaptureMjpeg CaptureMjpeg | 58 #define MAYBE_CaptureMjpeg CaptureMjpeg |
| 61 #define MAYBE_TakePhoto TakePhoto | 59 #define MAYBE_TakePhoto TakePhoto |
| 62 #define MAYBE_GetPhotoCapabilities GetPhotoCapabilities | |
| 63 #elif defined(OS_LINUX) | 60 #elif defined(OS_LINUX) |
| 64 // AllocateBadSize will hang when a real camera is attached and if more than one | 61 // AllocateBadSize will hang when a real camera is attached and if more than one |
| 65 // test is trying to use the camera (even across processes). Do NOT renable | 62 // test is trying to use the camera (even across processes). Do NOT renable |
| 66 // this test without fixing the many bugs associated with it: | 63 // this test without fixing the many bugs associated with it: |
| 67 // http://crbug.com/94134 http://crbug.com/137260 http://crbug.com/417824 | 64 // http://crbug.com/94134 http://crbug.com/137260 http://crbug.com/417824 |
| 68 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 65 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
| 69 #define MAYBE_CaptureMjpeg CaptureMjpeg | 66 #define MAYBE_CaptureMjpeg CaptureMjpeg |
| 70 #define MAYBE_TakePhoto TakePhoto | 67 #define MAYBE_TakePhoto TakePhoto |
| 71 #define MAYBE_GetPhotoCapabilities GetPhotoCapabilities | |
| 72 #else | 68 #else |
| 73 #define MAYBE_AllocateBadSize AllocateBadSize | 69 #define MAYBE_AllocateBadSize AllocateBadSize |
| 74 #define MAYBE_CaptureMjpeg CaptureMjpeg | 70 #define MAYBE_CaptureMjpeg CaptureMjpeg |
| 75 #define MAYBE_TakePhoto DISABLED_TakePhoto | 71 #define MAYBE_TakePhoto DISABLED_TakePhoto |
| 76 #define MAYBE_GetPhotoCapabilities DISABLED_GetPhotoCapabilities | |
| 77 #endif | 72 #endif |
| 78 | 73 |
| 79 using ::testing::_; | 74 using ::testing::_; |
| 80 using ::testing::SaveArg; | 75 using ::testing::SaveArg; |
| 81 | 76 |
| 82 namespace media { | 77 namespace media { |
| 83 namespace { | 78 namespace { |
| 84 | 79 |
| 85 class MockVideoCaptureClient : public VideoCaptureDevice::Client { | 80 class MockVideoCaptureClient : public VideoCaptureDevice::Client { |
| 86 public: | 81 public: |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 EXPECT_EQ('G', blob->data[3]); | 158 EXPECT_EQ('G', blob->data[3]); |
| 164 OnCorrectPhotoTaken(); | 159 OnCorrectPhotoTaken(); |
| 165 } else { | 160 } else { |
| 166 ADD_FAILURE() << "Photo format should be jpeg or png"; | 161 ADD_FAILURE() << "Photo format should be jpeg or png"; |
| 167 } | 162 } |
| 168 } | 163 } |
| 169 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); | 164 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); |
| 170 MOCK_METHOD1(OnTakePhotoFailure, | 165 MOCK_METHOD1(OnTakePhotoFailure, |
| 171 void(const base::Callback<void(mojom::BlobPtr)>&)); | 166 void(const base::Callback<void(mojom::BlobPtr)>&)); |
| 172 | 167 |
| 173 // GMock doesn't support move-only arguments, so we use this forward method. | |
| 174 void DoOnGetPhotoCapabilities(mojom::PhotoCapabilitiesPtr capabilities) { | |
| 175 capabilities_ = std::move(capabilities); | |
| 176 OnCorrectGetPhotoCapabilities(); | |
| 177 } | |
| 178 MOCK_METHOD0(OnCorrectGetPhotoCapabilities, void(void)); | |
| 179 MOCK_METHOD1(OnGetPhotoCapabilitiesFailure, | |
| 180 void(const base::Callback<void(mojom::PhotoCapabilitiesPtr)>&)); | |
| 181 | |
| 182 const mojom::PhotoCapabilities* capabilities() { return capabilities_.get(); } | |
| 183 | |
| 184 private: | 168 private: |
| 185 friend class base::RefCounted<MockImageCaptureClient>; | 169 friend class base::RefCounted<MockImageCaptureClient>; |
| 186 virtual ~MockImageCaptureClient() {} | 170 virtual ~MockImageCaptureClient() {} |
| 187 | |
| 188 mojom::PhotoCapabilitiesPtr capabilities_; | |
| 189 }; | 171 }; |
| 190 | 172 |
| 191 class DeviceEnumerationListener | 173 class DeviceEnumerationListener |
| 192 : public base::RefCounted<DeviceEnumerationListener> { | 174 : public base::RefCounted<DeviceEnumerationListener> { |
| 193 public: | 175 public: |
| 194 MOCK_METHOD1(DoOnEnumerateDeviceDescriptors, | 176 MOCK_METHOD1(DoOnEnumerateDeviceDescriptors, |
| 195 void(VideoCaptureDeviceDescriptors* device_descriptors)); | 177 void(VideoCaptureDeviceDescriptors* device_descriptors)); |
| 196 // GMock doesn't support move-only arguments, so we use this forward method. | 178 // GMock doesn't support move-only arguments, so we use this forward method. |
| 197 void OnEnumerateDeviceDescriptors( | 179 void OnEnumerateDeviceDescriptors( |
| 198 std::unique_ptr<VideoCaptureDeviceDescriptors> device_descriptors) { | 180 std::unique_ptr<VideoCaptureDeviceDescriptors> device_descriptors) { |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 TEST_F(VideoCaptureDeviceTest, NoCameraSupportsPixelFormatMax) { | 507 TEST_F(VideoCaptureDeviceTest, NoCameraSupportsPixelFormatMax) { |
| 526 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 508 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
| 527 // GetDeviceSupportedFormats(). | 509 // GetDeviceSupportedFormats(). |
| 528 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor = | 510 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor = |
| 529 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MAX); | 511 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 530 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 512 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
| 531 // since we cannot forecast the hardware capabilities. | 513 // since we cannot forecast the hardware capabilities. |
| 532 ASSERT_FALSE(device_descriptor); | 514 ASSERT_FALSE(device_descriptor); |
| 533 } | 515 } |
| 534 | 516 |
| 535 // Starts the camera and takes a photo. | 517 // Starts the camera and take a photo. |
| 536 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { | 518 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { |
| 537 if (!EnumerateAndFindUsableDevices()) | 519 if (!EnumerateAndFindUsableDevices()) |
| 538 return; | 520 return; |
| 539 | 521 |
| 540 #if defined(OS_ANDROID) | 522 #if defined(OS_ANDROID) |
| 541 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 | 523 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 |
| 542 if (base::android::BuildInfo::GetInstance()->sdk_int() < | 524 if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| 543 base::android::SDK_VERSION_MARSHMALLOW) { | 525 base::android::SDK_VERSION_MARSHMALLOW) { |
| 544 return; | 526 return; |
| 545 } | 527 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 565 media::BindToCurrentLoop(base::Bind( | 547 media::BindToCurrentLoop(base::Bind( |
| 566 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); | 548 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); |
| 567 | 549 |
| 568 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); | 550 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); |
| 569 device->TakePhoto(std::move(scoped_callback)); | 551 device->TakePhoto(std::move(scoped_callback)); |
| 570 WaitForCapturedFrame(); | 552 WaitForCapturedFrame(); |
| 571 | 553 |
| 572 device->StopAndDeAllocate(); | 554 device->StopAndDeAllocate(); |
| 573 } | 555 } |
| 574 | 556 |
| 575 // Starts the camera and tries to get the Photo capabilities. | |
| 576 TEST_F(VideoCaptureDeviceTest, MAYBE_GetPhotoCapabilities) { | |
| 577 if (!EnumerateAndFindUsableDevices()) | |
| 578 return; | |
| 579 | |
| 580 #if defined(OS_ANDROID) | |
| 581 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 | |
| 582 if (base::android::BuildInfo::GetInstance()->sdk_int() < | |
| 583 base::android::SDK_VERSION_MARSHMALLOW) { | |
| 584 return; | |
| 585 } | |
| 586 #endif | |
| 587 | |
| 588 std::unique_ptr<VideoCaptureDevice> device( | |
| 589 video_capture_device_factory_->CreateDevice( | |
| 590 device_descriptors_->front())); | |
| 591 ASSERT_TRUE(device); | |
| 592 | |
| 593 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | |
| 594 | |
| 595 VideoCaptureParams capture_params; | |
| 596 capture_params.requested_format.frame_size.SetSize(320, 240); | |
| 597 capture_params.requested_format.frame_rate = 30; | |
| 598 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
| 599 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | |
| 600 WaitForCapturedFrame(); | |
| 601 | |
| 602 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( | |
| 603 base::Bind(&MockImageCaptureClient::DoOnGetPhotoCapabilities, | |
| 604 image_capture_client_), | |
| 605 media::BindToCurrentLoop( | |
| 606 base::Bind(&MockImageCaptureClient::OnGetPhotoCapabilitiesFailure, | |
| 607 image_capture_client_))); | |
| 608 | |
| 609 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) | |
| 610 .Times(1); | |
| 611 | |
| 612 device->GetPhotoCapabilities(std::move(scoped_get_callback)); | |
| 613 WaitForCapturedFrame(); | |
| 614 | |
| 615 auto* capabilities = image_capture_client_->capabilities(); | |
| 616 ASSERT_TRUE(capabilities); | |
| 617 | |
| 618 device->StopAndDeAllocate(); | |
| 619 } | |
| 620 | |
| 621 }; // namespace media | 557 }; // namespace media |
| OLD | NEW |