| 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 "device/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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/test/test_timeouts.h" | 18 #include "base/test/test_timeouts.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "device/capture/video/video_capture_device_factory.h" |
| 22 #include "media/base/bind_to_current_loop.h" | 23 #include "media/base/bind_to_current_loop.h" |
| 23 #include "media/base/video_capture_types.h" | 24 #include "media/base/video_capture_types.h" |
| 24 #include "media/capture/video/video_capture_device_factory.h" | |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 29 #include "base/win/scoped_com_initializer.h" | 29 #include "base/win/scoped_com_initializer.h" |
| 30 #include "base/win/windows_version.h" // For fine-grained suppression. | 30 #include "base/win/windows_version.h" // For fine-grained suppression. |
| 31 #include "media/capture/video/win/video_capture_device_factory_win.h" | 31 #include "device/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 "device/capture/video/mac/video_capture_device_factory_mac.h" |
| 35 #include "media/base/mac/avfoundation_glue.h" | 36 #include "media/base/mac/avfoundation_glue.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 "media/capture/video/android/video_capture_device_android.h" | 41 #include "device/capture/video/android/video_capture_device_android.h" |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
| 45 // Mac will always give you the size you ask for and this case will fail. | 45 // Mac will always give you the size you ask for and this case will fail. |
| 46 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 46 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
| 47 // We will always get YUYV from the Mac AVFoundation implementations. | 47 // We will always get YUYV from the Mac AVFoundation implementations. |
| 48 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | 48 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg |
| 49 #define MAYBE_TakePhoto TakePhoto | 49 #define MAYBE_TakePhoto TakePhoto |
| 50 #elif defined(OS_WIN) | 50 #elif defined(OS_WIN) |
| 51 #define MAYBE_AllocateBadSize AllocateBadSize | 51 #define MAYBE_AllocateBadSize AllocateBadSize |
| (...skipping 19 matching lines...) Expand all Loading... |
| 71 #define MAYBE_TakePhoto DISABLED_TakePhoto | 71 #define MAYBE_TakePhoto DISABLED_TakePhoto |
| 72 #else | 72 #else |
| 73 #define MAYBE_AllocateBadSize AllocateBadSize | 73 #define MAYBE_AllocateBadSize AllocateBadSize |
| 74 #define MAYBE_CaptureMjpeg CaptureMjpeg | 74 #define MAYBE_CaptureMjpeg CaptureMjpeg |
| 75 #define MAYBE_TakePhoto DISABLED_TakePhoto | 75 #define MAYBE_TakePhoto DISABLED_TakePhoto |
| 76 #endif | 76 #endif |
| 77 | 77 |
| 78 using ::testing::_; | 78 using ::testing::_; |
| 79 using ::testing::SaveArg; | 79 using ::testing::SaveArg; |
| 80 | 80 |
| 81 namespace media { | 81 namespace device { |
| 82 namespace { | 82 namespace { |
| 83 | 83 |
| 84 class MockVideoCaptureClient : public VideoCaptureDevice::Client { | 84 class MockVideoCaptureClient : public VideoCaptureDevice::Client { |
| 85 public: | 85 public: |
| 86 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); | 86 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); |
| 87 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); | 87 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
| 88 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); | 88 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); |
| 89 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); | 89 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); |
| 90 MOCK_METHOD2(OnError, | 90 MOCK_METHOD2(OnError, |
| 91 void(const tracked_objects::Location& from_here, | 91 void(const tracked_objects::Location& from_here, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 138 } |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 141 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
| 142 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 142 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { | 145 class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { |
| 146 public: | 146 public: |
| 147 // GMock doesn't support move-only arguments, so we use this forward method. | 147 // GMock doesn't support move-only arguments, so we use this forward method. |
| 148 void DoOnPhotoTaken(mojom::BlobPtr blob) { | 148 void DoOnPhotoTaken(media::mojom::BlobPtr blob) { |
| 149 EXPECT_STREQ("image/jpeg", blob->mime_type.c_str()); | 149 EXPECT_STREQ("image/jpeg", blob->mime_type.c_str()); |
| 150 ASSERT_GT(blob->data.size(), 4u); | 150 ASSERT_GT(blob->data.size(), 4u); |
| 151 // Check some bytes that univocally identify |data| as a JPEG File. | 151 // Check some bytes that univocally identify |data| as a JPEG File. |
| 152 // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_st
ructure | 152 // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_st
ructure |
| 153 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte | 153 EXPECT_EQ(0xFF, blob->data[0]); // First SOI byte |
| 154 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte | 154 EXPECT_EQ(0xD8, blob->data[1]); // Second SOI byte |
| 155 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte | 155 EXPECT_EQ(0xFF, blob->data[2]); // First JFIF-APP0 byte |
| 156 EXPECT_EQ(0xE0, blob->data[3]); // Second JFIF-APP0 byte | 156 EXPECT_EQ(0xE0, blob->data[3]); // Second JFIF-APP0 byte |
| 157 OnCorrectPhotoTaken(); | 157 OnCorrectPhotoTaken(); |
| 158 } | 158 } |
| 159 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); | 159 MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); |
| 160 MOCK_METHOD1(OnTakePhotoFailure, | 160 MOCK_METHOD1(OnTakePhotoFailure, |
| 161 void(const base::Callback<void(mojom::BlobPtr)>&)); | 161 void(const base::Callback<void(media::mojom::BlobPtr)>&)); |
| 162 | 162 |
| 163 private: | 163 private: |
| 164 friend class base::RefCounted<MockImageCaptureClient>; | 164 friend class base::RefCounted<MockImageCaptureClient>; |
| 165 virtual ~MockImageCaptureClient() {} | 165 virtual ~MockImageCaptureClient() {} |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 class DeviceEnumerationListener | 168 class DeviceEnumerationListener |
| 169 : public base::RefCounted<DeviceEnumerationListener> { | 169 : public base::RefCounted<DeviceEnumerationListener> { |
| 170 public: | 170 public: |
| 171 MOCK_METHOD1(OnEnumerateDeviceDescriptorsCallbackPtr, | 171 MOCK_METHOD1(OnEnumerateDeviceDescriptorsCallbackPtr, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 VideoCaptureFormats supported_formats; | 253 VideoCaptureFormats supported_formats; |
| 254 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, | 254 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, |
| 255 &supported_formats); | 255 &supported_formats); |
| 256 for (const auto& formats_iterator : supported_formats) { | 256 for (const auto& formats_iterator : supported_formats) { |
| 257 if (formats_iterator.pixel_format == pixel_format) { | 257 if (formats_iterator.pixel_format == pixel_format) { |
| 258 return std::unique_ptr<VideoCaptureDeviceDescriptor>( | 258 return std::unique_ptr<VideoCaptureDeviceDescriptor>( |
| 259 new VideoCaptureDeviceDescriptor(descriptors_iterator)); | 259 new VideoCaptureDeviceDescriptor(descriptors_iterator)); |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 DVLOG_IF(1, pixel_format != PIXEL_FORMAT_MAX) | 263 DVLOG_IF(1, pixel_format != media::PIXEL_FORMAT_MAX) |
| 264 << "No camera can capture the" | 264 << "No camera can capture the" |
| 265 << " format: " << VideoPixelFormatToString(pixel_format); | 265 << " format: " << VideoPixelFormatToString(pixel_format); |
| 266 return std::unique_ptr<VideoCaptureDeviceDescriptor>(); | 266 return std::unique_ptr<VideoCaptureDeviceDescriptor>(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 bool IsCaptureSizeSupported(const VideoCaptureDeviceDescriptor& device, | 269 bool IsCaptureSizeSupported(const VideoCaptureDeviceDescriptor& device, |
| 270 const gfx::Size& size) { | 270 const gfx::Size& size) { |
| 271 VideoCaptureFormats supported_formats; | 271 VideoCaptureFormats supported_formats; |
| 272 video_capture_device_factory_->GetSupportedFormats(device, | 272 video_capture_device_factory_->GetSupportedFormats(device, |
| 273 &supported_formats); | 273 &supported_formats); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 #if !defined(OS_MACOSX) | 320 #if !defined(OS_MACOSX) |
| 321 EXPECT_TRUE(device == NULL); | 321 EXPECT_TRUE(device == NULL); |
| 322 #else | 322 #else |
| 323 // The presence of the actual device is only checked on AllocateAndStart() | 323 // The presence of the actual device is only checked on AllocateAndStart() |
| 324 // and not on creation. | 324 // and not on creation. |
| 325 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(1); | 325 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(1); |
| 326 | 326 |
| 327 VideoCaptureParams capture_params; | 327 VideoCaptureParams capture_params; |
| 328 capture_params.requested_format.frame_size.SetSize(640, 480); | 328 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 329 capture_params.requested_format.frame_rate = 30; | 329 capture_params.requested_format.frame_rate = 30; |
| 330 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 330 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 331 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 331 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 332 device->StopAndDeAllocate(); | 332 device->StopAndDeAllocate(); |
| 333 #endif | 333 #endif |
| 334 } | 334 } |
| 335 | 335 |
| 336 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) { | 336 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) { |
| 337 device_descriptors_ = EnumerateDeviceDescriptors(); | 337 device_descriptors_ = EnumerateDeviceDescriptors(); |
| 338 if (device_descriptors_->empty()) { | 338 if (device_descriptors_->empty()) { |
| 339 VLOG(1) << "No camera available. Exiting test."; | 339 VLOG(1) << "No camera available. Exiting test."; |
| 340 return; | 340 return; |
| 341 } | 341 } |
| 342 | 342 |
| 343 const gfx::Size& size = GetParam(); | 343 const gfx::Size& size = GetParam(); |
| 344 if (!IsCaptureSizeSupported(device_descriptors_->front(), size)) | 344 if (!IsCaptureSizeSupported(device_descriptors_->front(), size)) |
| 345 return; | 345 return; |
| 346 const int width = size.width(); | 346 const int width = size.width(); |
| 347 const int height = size.height(); | 347 const int height = size.height(); |
| 348 | 348 |
| 349 std::unique_ptr<VideoCaptureDevice> device( | 349 std::unique_ptr<VideoCaptureDevice> device( |
| 350 video_capture_device_factory_->CreateDevice( | 350 video_capture_device_factory_->CreateDevice( |
| 351 device_descriptors_->front())); | 351 device_descriptors_->front())); |
| 352 ASSERT_TRUE(device); | 352 ASSERT_TRUE(device); |
| 353 DVLOG(1) << device_descriptors_->front().device_id; | 353 DVLOG(1) << device_descriptors_->front().device_id; |
| 354 | 354 |
| 355 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 355 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 356 | 356 |
| 357 VideoCaptureParams capture_params; | 357 VideoCaptureParams capture_params; |
| 358 capture_params.requested_format.frame_size.SetSize(width, height); | 358 capture_params.requested_format.frame_size.SetSize(width, height); |
| 359 capture_params.requested_format.frame_rate = 30.0f; | 359 capture_params.requested_format.frame_rate = 30.0f; |
| 360 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 360 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 361 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 361 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 362 // Get captured video frames. | 362 // Get captured video frames. |
| 363 WaitForCapturedFrame(); | 363 WaitForCapturedFrame(); |
| 364 EXPECT_EQ(last_format().frame_size.width(), width); | 364 EXPECT_EQ(last_format().frame_size.width(), width); |
| 365 EXPECT_EQ(last_format().frame_size.height(), height); | 365 EXPECT_EQ(last_format().frame_size.height(), height); |
| 366 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) | 366 if (last_format().pixel_format != media::PIXEL_FORMAT_MJPEG) |
| 367 EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea()); | 367 EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea()); |
| 368 device->StopAndDeAllocate(); | 368 device->StopAndDeAllocate(); |
| 369 } | 369 } |
| 370 | 370 |
| 371 #if !defined(OS_ANDROID) | 371 #if !defined(OS_ANDROID) |
| 372 const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), gfx::Size(1280, 720)}; | 372 const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), gfx::Size(1280, 720)}; |
| 373 | 373 |
| 374 INSTANTIATE_TEST_CASE_P(VideoCaptureDeviceTests, | 374 INSTANTIATE_TEST_CASE_P(VideoCaptureDeviceTests, |
| 375 VideoCaptureDeviceTest, | 375 VideoCaptureDeviceTest, |
| 376 testing::ValuesIn(kCaptureSizes)); | 376 testing::ValuesIn(kCaptureSizes)); |
| 377 #endif | 377 #endif |
| 378 | 378 |
| 379 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 379 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 380 device_descriptors_ = EnumerateDeviceDescriptors(); | 380 device_descriptors_ = EnumerateDeviceDescriptors(); |
| 381 if (device_descriptors_->empty()) { | 381 if (device_descriptors_->empty()) { |
| 382 VLOG(1) << "No camera available. Exiting test."; | 382 VLOG(1) << "No camera available. Exiting test."; |
| 383 return; | 383 return; |
| 384 } | 384 } |
| 385 std::unique_ptr<VideoCaptureDevice> device( | 385 std::unique_ptr<VideoCaptureDevice> device( |
| 386 video_capture_device_factory_->CreateDevice( | 386 video_capture_device_factory_->CreateDevice( |
| 387 device_descriptors_->front())); | 387 device_descriptors_->front())); |
| 388 ASSERT_TRUE(device); | 388 ASSERT_TRUE(device); |
| 389 | 389 |
| 390 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 390 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 391 | 391 |
| 392 const gfx::Size input_size(640, 480); | 392 const gfx::Size input_size(640, 480); |
| 393 VideoCaptureParams capture_params; | 393 VideoCaptureParams capture_params; |
| 394 capture_params.requested_format.frame_size.SetSize(637, 472); | 394 capture_params.requested_format.frame_size.SetSize(637, 472); |
| 395 capture_params.requested_format.frame_rate = 35; | 395 capture_params.requested_format.frame_rate = 35; |
| 396 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 396 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 397 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 397 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 398 WaitForCapturedFrame(); | 398 WaitForCapturedFrame(); |
| 399 device->StopAndDeAllocate(); | 399 device->StopAndDeAllocate(); |
| 400 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); | 400 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); |
| 401 EXPECT_EQ(last_format().frame_size.height(), input_size.height()); | 401 EXPECT_EQ(last_format().frame_size.height(), input_size.height()); |
| 402 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) | 402 if (last_format().pixel_format != media::PIXEL_FORMAT_MJPEG) |
| 403 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea()); | 403 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea()); |
| 404 } | 404 } |
| 405 | 405 |
| 406 // Cause hangs on Windows, Linux. Fails Android. http://crbug.com/417824 | 406 // Cause hangs on Windows, Linux. Fails Android. http://crbug.com/417824 |
| 407 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) { | 407 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) { |
| 408 device_descriptors_ = EnumerateDeviceDescriptors(); | 408 device_descriptors_ = EnumerateDeviceDescriptors(); |
| 409 if (device_descriptors_->empty()) { | 409 if (device_descriptors_->empty()) { |
| 410 VLOG(1) << "No camera available. Exiting test."; | 410 VLOG(1) << "No camera available. Exiting test."; |
| 411 return; | 411 return; |
| 412 } | 412 } |
| 413 | 413 |
| 414 // First, do a number of very fast device start/stops. | 414 // First, do a number of very fast device start/stops. |
| 415 for (int i = 0; i <= 5; i++) { | 415 for (int i = 0; i <= 5; i++) { |
| 416 ResetWithNewClient(); | 416 ResetWithNewClient(); |
| 417 std::unique_ptr<VideoCaptureDevice> device( | 417 std::unique_ptr<VideoCaptureDevice> device( |
| 418 video_capture_device_factory_->CreateDevice( | 418 video_capture_device_factory_->CreateDevice( |
| 419 device_descriptors_->front())); | 419 device_descriptors_->front())); |
| 420 gfx::Size resolution; | 420 gfx::Size resolution; |
| 421 if (i % 2) { | 421 if (i % 2) { |
| 422 resolution = gfx::Size(640, 480); | 422 resolution = gfx::Size(640, 480); |
| 423 } else { | 423 } else { |
| 424 resolution = gfx::Size(1280, 1024); | 424 resolution = gfx::Size(1280, 1024); |
| 425 } | 425 } |
| 426 VideoCaptureParams capture_params; | 426 VideoCaptureParams capture_params; |
| 427 capture_params.requested_format.frame_size = resolution; | 427 capture_params.requested_format.frame_size = resolution; |
| 428 capture_params.requested_format.frame_rate = 30; | 428 capture_params.requested_format.frame_rate = 30; |
| 429 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 429 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 430 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 430 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 431 device->StopAndDeAllocate(); | 431 device->StopAndDeAllocate(); |
| 432 } | 432 } |
| 433 | 433 |
| 434 // Finally, do a device start and wait for it to finish. | 434 // Finally, do a device start and wait for it to finish. |
| 435 VideoCaptureParams capture_params; | 435 VideoCaptureParams capture_params; |
| 436 capture_params.requested_format.frame_size.SetSize(320, 240); | 436 capture_params.requested_format.frame_size.SetSize(320, 240); |
| 437 capture_params.requested_format.frame_rate = 30; | 437 capture_params.requested_format.frame_rate = 30; |
| 438 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 438 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 439 | 439 |
| 440 ResetWithNewClient(); | 440 ResetWithNewClient(); |
| 441 std::unique_ptr<VideoCaptureDevice> device( | 441 std::unique_ptr<VideoCaptureDevice> device( |
| 442 video_capture_device_factory_->CreateDevice( | 442 video_capture_device_factory_->CreateDevice( |
| 443 device_descriptors_->front())); | 443 device_descriptors_->front())); |
| 444 | 444 |
| 445 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 445 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 446 WaitForCapturedFrame(); | 446 WaitForCapturedFrame(); |
| 447 device->StopAndDeAllocate(); | 447 device->StopAndDeAllocate(); |
| 448 device.reset(); | 448 device.reset(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 459 std::unique_ptr<VideoCaptureDevice> device( | 459 std::unique_ptr<VideoCaptureDevice> device( |
| 460 video_capture_device_factory_->CreateDevice( | 460 video_capture_device_factory_->CreateDevice( |
| 461 device_descriptors_->front())); | 461 device_descriptors_->front())); |
| 462 ASSERT_TRUE(device); | 462 ASSERT_TRUE(device); |
| 463 | 463 |
| 464 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 464 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 465 | 465 |
| 466 VideoCaptureParams capture_params; | 466 VideoCaptureParams capture_params; |
| 467 capture_params.requested_format.frame_size.SetSize(640, 480); | 467 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 468 capture_params.requested_format.frame_rate = 30; | 468 capture_params.requested_format.frame_rate = 30; |
| 469 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 469 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 470 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 470 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 471 // Get captured video frames. | 471 // Get captured video frames. |
| 472 WaitForCapturedFrame(); | 472 WaitForCapturedFrame(); |
| 473 EXPECT_EQ(last_format().frame_size.width(), 640); | 473 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 474 EXPECT_EQ(last_format().frame_size.height(), 480); | 474 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 475 EXPECT_EQ(last_format().frame_rate, 30); | 475 EXPECT_EQ(last_format().frame_rate, 30); |
| 476 device->StopAndDeAllocate(); | 476 device->StopAndDeAllocate(); |
| 477 } | 477 } |
| 478 | 478 |
| 479 // Start the camera in 720p to capture MJPEG instead of a raw format. | 479 // Start the camera in 720p to capture MJPEG instead of a raw format. |
| 480 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { | 480 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
| 481 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor = | 481 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor = |
| 482 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MJPEG); | 482 GetFirstDeviceDescriptorSupportingPixelFormat(media::PIXEL_FORMAT_MJPEG); |
| 483 if (!device_descriptor) { | 483 if (!device_descriptor) { |
| 484 VLOG(1) << "No camera supports MJPEG format. Exiting test."; | 484 VLOG(1) << "No camera supports MJPEG format. Exiting test."; |
| 485 return; | 485 return; |
| 486 } | 486 } |
| 487 #if defined(OS_WIN) | 487 #if defined(OS_WIN) |
| 488 base::win::Version version = base::win::GetVersion(); | 488 base::win::Version version = base::win::GetVersion(); |
| 489 VLOG(1) << "Windows version: " << (int)version; | 489 VLOG(1) << "Windows version: " << (int)version; |
| 490 if (version >= base::win::VERSION_WIN10) { | 490 if (version >= base::win::VERSION_WIN10) { |
| 491 VLOG(1) << "Skipped on Win10: http://crbug.com/570604."; | 491 VLOG(1) << "Skipped on Win10: http://crbug.com/570604."; |
| 492 return; | 492 return; |
| 493 } | 493 } |
| 494 #endif | 494 #endif |
| 495 std::unique_ptr<VideoCaptureDevice> device( | 495 std::unique_ptr<VideoCaptureDevice> device( |
| 496 video_capture_device_factory_->CreateDevice(*device_descriptor)); | 496 video_capture_device_factory_->CreateDevice(*device_descriptor)); |
| 497 ASSERT_TRUE(device); | 497 ASSERT_TRUE(device); |
| 498 | 498 |
| 499 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 499 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 500 | 500 |
| 501 VideoCaptureParams capture_params; | 501 VideoCaptureParams capture_params; |
| 502 capture_params.requested_format.frame_size.SetSize(1280, 720); | 502 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 503 capture_params.requested_format.frame_rate = 30; | 503 capture_params.requested_format.frame_rate = 30; |
| 504 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 504 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_MJPEG; |
| 505 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 505 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 506 // Get captured video frames. | 506 // Get captured video frames. |
| 507 WaitForCapturedFrame(); | 507 WaitForCapturedFrame(); |
| 508 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | 508 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 |
| 509 // @ 30 fps, so we don't care about the exact resolution we get. | 509 // @ 30 fps, so we don't care about the exact resolution we get. |
| 510 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); | 510 EXPECT_EQ(last_format().pixel_format, media::PIXEL_FORMAT_MJPEG); |
| 511 EXPECT_GE(static_cast<size_t>(1280 * 720), | 511 EXPECT_GE(static_cast<size_t>(1280 * 720), |
| 512 last_format().ImageAllocationSize()); | 512 last_format().ImageAllocationSize()); |
| 513 device->StopAndDeAllocate(); | 513 device->StopAndDeAllocate(); |
| 514 } | 514 } |
| 515 | 515 |
| 516 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 516 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 517 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 517 // Use media::PIXEL_FORMAT_MAX to iterate all device names for testing |
| 518 // GetDeviceSupportedFormats(). | 518 // GetDeviceSupportedFormats(). |
| 519 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor = | 519 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor = |
| 520 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MAX); | 520 GetFirstDeviceDescriptorSupportingPixelFormat(media::PIXEL_FORMAT_MAX); |
| 521 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 521 // Verify no camera returned for media::PIXEL_FORMAT_MAX. Nothing else to test |
| 522 // since we cannot forecast the hardware capabilities. | 522 // here since we cannot forecast the hardware capabilities. |
| 523 ASSERT_FALSE(device_descriptor); | 523 ASSERT_FALSE(device_descriptor); |
| 524 } | 524 } |
| 525 | 525 |
| 526 // Start the camera and take a photo. | 526 // Start the camera and take a photo. |
| 527 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { | 527 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { |
| 528 device_descriptors_ = EnumerateDeviceDescriptors(); | 528 device_descriptors_ = EnumerateDeviceDescriptors(); |
| 529 if (device_descriptors_->empty()) { | 529 if (device_descriptors_->empty()) { |
| 530 VLOG(1) << "No camera available. Exiting test."; | 530 VLOG(1) << "No camera available. Exiting test."; |
| 531 return; | 531 return; |
| 532 } | 532 } |
| 533 std::unique_ptr<VideoCaptureDevice> device( | 533 std::unique_ptr<VideoCaptureDevice> device( |
| 534 video_capture_device_factory_->CreateDevice( | 534 video_capture_device_factory_->CreateDevice( |
| 535 device_descriptors_->front())); | 535 device_descriptors_->front())); |
| 536 ASSERT_TRUE(device); | 536 ASSERT_TRUE(device); |
| 537 | 537 |
| 538 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 538 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 539 | 539 |
| 540 VideoCaptureParams capture_params; | 540 VideoCaptureParams capture_params; |
| 541 capture_params.requested_format.frame_size.SetSize(640, 480); | 541 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 542 capture_params.requested_format.frame_rate = 30; | 542 capture_params.requested_format.frame_rate = 30; |
| 543 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 543 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 544 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 544 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 545 WaitForCapturedFrame(); | 545 WaitForCapturedFrame(); |
| 546 | 546 |
| 547 VideoCaptureDevice::TakePhotoCallback scoped_callback( | 547 VideoCaptureDevice::TakePhotoCallback scoped_callback( |
| 548 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken, | 548 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken, |
| 549 image_capture_client_), | 549 image_capture_client_), |
| 550 media::BindToCurrentLoop(base::Bind( | 550 media::BindToCurrentLoop(base::Bind( |
| 551 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); | 551 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); |
| 552 | 552 |
| 553 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); | 553 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); |
| 554 device->TakePhoto(std::move(scoped_callback)); | 554 device->TakePhoto(std::move(scoped_callback)); |
| 555 WaitForCapturedFrame(); | 555 WaitForCapturedFrame(); |
| 556 | 556 |
| 557 device->StopAndDeAllocate(); | 557 device->StopAndDeAllocate(); |
| 558 } | 558 } |
| 559 | 559 |
| 560 }; // namespace media | 560 }; // namespace device |
| OLD | NEW |