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 20 matching lines...) Expand all Loading... |
31 #include "media/capture/video/win/video_capture_device_factory_win.h" | 31 #include "media/capture/video/win/video_capture_device_factory_win.h" |
32 #endif | 32 #endif |
33 | 33 |
34 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
35 #include "media/base/mac/avfoundation_glue.h" | 35 #include "media/base/mac/avfoundation_glue.h" |
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/jni_android.h" | 40 #include "base/android/jni_android.h" |
| 41 #include "base/android/build_info.h" |
41 #include "media/capture/video/android/video_capture_device_android.h" | 42 #include "media/capture/video/android/video_capture_device_android.h" |
42 #include "media/capture/video/android/video_capture_device_factory_android.h" | 43 #include "media/capture/video/android/video_capture_device_factory_android.h" |
43 #endif | 44 #endif |
44 | 45 |
45 #if defined(OS_MACOSX) | 46 #if defined(OS_MACOSX) |
46 // 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. |
47 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 48 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
48 // We will always get YUYV from the Mac AVFoundation implementations. | 49 // We will always get YUYV from the Mac AVFoundation implementations. |
49 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | 50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg |
50 #define MAYBE_TakePhoto TakePhoto | 51 #define MAYBE_TakePhoto TakePhoto |
51 #elif defined(OS_WIN) | 52 #elif defined(OS_WIN) |
52 #define MAYBE_AllocateBadSize AllocateBadSize | 53 #define MAYBE_AllocateBadSize AllocateBadSize |
53 #define MAYBE_CaptureMjpeg CaptureMjpeg | 54 #define MAYBE_CaptureMjpeg CaptureMjpeg |
54 #define MAYBE_TakePhoto DISABLED_TakePhoto | 55 #define MAYBE_TakePhoto DISABLED_TakePhoto |
55 #elif defined(OS_ANDROID) | 56 #elif defined(OS_ANDROID) |
56 #define MAYBE_AllocateBadSize AllocateBadSize | 57 #define MAYBE_AllocateBadSize AllocateBadSize |
57 #define MAYBE_CaptureMjpeg CaptureMjpeg | 58 #define MAYBE_CaptureMjpeg CaptureMjpeg |
58 #define MAYBE_TakePhoto DISABLED_TakePhoto | 59 #define MAYBE_TakePhoto TakePhoto |
59 #elif defined(OS_LINUX) | 60 #elif defined(OS_LINUX) |
60 // 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 |
61 // 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 |
62 // this test without fixing the many bugs associated with it: | 63 // this test without fixing the many bugs associated with it: |
63 // 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 |
64 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 65 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
65 #define MAYBE_CaptureMjpeg CaptureMjpeg | 66 #define MAYBE_CaptureMjpeg CaptureMjpeg |
66 #define MAYBE_TakePhoto DISABLED_TakePhoto | 67 #define MAYBE_TakePhoto DISABLED_TakePhoto |
67 #else | 68 #else |
68 #define MAYBE_AllocateBadSize AllocateBadSize | 69 #define MAYBE_AllocateBadSize AllocateBadSize |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 public: | 142 public: |
142 // GMock doesn't support move-only arguments, so we use this forward method. | 143 // GMock doesn't support move-only arguments, so we use this forward method. |
143 void DoOnPhotoTaken(mojom::BlobPtr blob) { | 144 void DoOnPhotoTaken(mojom::BlobPtr blob) { |
144 EXPECT_STREQ("image/jpeg", blob->mime_type.c_str()); | 145 EXPECT_STREQ("image/jpeg", blob->mime_type.c_str()); |
145 ASSERT_GT(blob->data.size(), 4u); | 146 ASSERT_GT(blob->data.size(), 4u); |
146 // Check some bytes that univocally identify |data| as a JPEG File. | 147 // Check some bytes that univocally identify |data| as a JPEG File. |
147 // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_st
ructure | 148 // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_st
ructure |
148 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte | 149 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte |
149 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte | 150 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte |
150 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte | 151 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte |
151 EXPECT_EQ(0xE0, blob->data[3]); // Second JFIF-APP0 byte | 152 EXPECT_EQ(0xE0, blob->data[3] & 0xF0); // Second JFIF-APP0/APP1 byte |
152 OnCorrectPhotoTaken(); | 153 OnCorrectPhotoTaken(); |
153 } | 154 } |
154 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); | 155 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); |
155 MOCK_METHOD1(OnTakePhotoFailure, | 156 MOCK_METHOD1(OnTakePhotoFailure, |
156 void(const base::Callback<void(mojom::BlobPtr)>&)); | 157 void(const base::Callback<void(mojom::BlobPtr)>&)); |
157 | 158 |
158 private: | 159 private: |
159 friend class base::RefCounted<MockImageCaptureClient>; | 160 friend class base::RefCounted<MockImageCaptureClient>; |
160 virtual ~MockImageCaptureClient() {} | 161 virtual ~MockImageCaptureClient() {} |
161 }; | 162 }; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 503 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
503 // since we cannot forecast the hardware capabilities. | 504 // since we cannot forecast the hardware capabilities. |
504 ASSERT_FALSE(device_descriptor); | 505 ASSERT_FALSE(device_descriptor); |
505 } | 506 } |
506 | 507 |
507 // Starts the camera and take a photo. | 508 // Starts the camera and take a photo. |
508 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { | 509 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { |
509 if (!EnumerateAndFindUsableDevices()) | 510 if (!EnumerateAndFindUsableDevices()) |
510 return; | 511 return; |
511 | 512 |
| 513 #if defined(OS_ANDROID) |
| 514 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 |
| 515 if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| 516 base::android::SDK_VERSION_MARSHMALLOW) { |
| 517 return; |
| 518 } |
| 519 #endif |
| 520 |
512 std::unique_ptr<VideoCaptureDevice> device( | 521 std::unique_ptr<VideoCaptureDevice> device( |
513 video_capture_device_factory_->CreateDevice( | 522 video_capture_device_factory_->CreateDevice( |
514 device_descriptors_->front())); | 523 device_descriptors_->front())); |
515 ASSERT_TRUE(device); | 524 ASSERT_TRUE(device); |
516 | 525 |
517 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 526 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
518 | 527 |
519 VideoCaptureParams capture_params; | 528 VideoCaptureParams capture_params; |
520 capture_params.requested_format.frame_size.SetSize(640, 480); | 529 capture_params.requested_format.frame_size.SetSize(640, 480); |
521 capture_params.requested_format.frame_rate = 30; | 530 capture_params.requested_format.frame_rate = 30; |
522 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 531 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
523 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 532 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
524 WaitForCapturedFrame(); | 533 WaitForCapturedFrame(); |
525 | 534 |
526 VideoCaptureDevice::TakePhotoCallback scoped_callback( | 535 VideoCaptureDevice::TakePhotoCallback scoped_callback( |
527 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken, | 536 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken, |
528 image_capture_client_), | 537 image_capture_client_), |
529 media::BindToCurrentLoop(base::Bind( | 538 media::BindToCurrentLoop(base::Bind( |
530 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); | 539 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); |
531 | 540 |
532 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); | 541 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); |
533 device->TakePhoto(std::move(scoped_callback)); | 542 device->TakePhoto(std::move(scoped_callback)); |
534 WaitForCapturedFrame(); | 543 WaitForCapturedFrame(); |
535 | 544 |
536 device->StopAndDeAllocate(); | 545 device->StopAndDeAllocate(); |
537 } | 546 } |
538 | 547 |
539 }; // namespace media | 548 }; // namespace media |
OLD | NEW |