| 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/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 const uint8* v_data, | 72 const uint8* v_data, |
| 73 size_t y_stride, | 73 size_t y_stride, |
| 74 size_t u_stride, | 74 size_t u_stride, |
| 75 size_t v_stride, | 75 size_t v_stride, |
| 76 const VideoCaptureFormat& frame_format, | 76 const VideoCaptureFormat& frame_format, |
| 77 int clockwise_rotation, | 77 int clockwise_rotation, |
| 78 const base::TimeTicks& timestamp)); | 78 const base::TimeTicks& timestamp)); |
| 79 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); | 79 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); |
| 80 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); | 80 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
| 81 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); | 81 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); |
| 82 MOCK_METHOD1(OnError, void(const std::string& reason)); | 82 MOCK_METHOD2(OnError, |
| 83 void(const tracked_objects::Location& from_here, |
| 84 const std::string& reason)); |
| 83 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); | 85 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); |
| 84 | 86 |
| 85 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 87 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
| 86 : main_thread_(base::ThreadTaskRunnerHandle::Get()), | 88 : main_thread_(base::ThreadTaskRunnerHandle::Get()), |
| 87 frame_cb_(frame_cb) {} | 89 frame_cb_(frame_cb) {} |
| 88 | 90 |
| 89 void OnIncomingCapturedData(const uint8* data, | 91 void OnIncomingCapturedData(const uint8* data, |
| 90 int length, | 92 int length, |
| 91 const VideoCaptureFormat& format, | 93 const VideoCaptureFormat& format, |
| 92 int rotation, | 94 int rotation, |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 scoped_ptr<VideoCaptureDevice> device = | 276 scoped_ptr<VideoCaptureDevice> device = |
| 275 video_capture_device_factory_->Create(device_name); | 277 video_capture_device_factory_->Create(device_name); |
| 276 #if !defined(OS_MACOSX) | 278 #if !defined(OS_MACOSX) |
| 277 EXPECT_TRUE(device == NULL); | 279 EXPECT_TRUE(device == NULL); |
| 278 #else | 280 #else |
| 279 if (VideoCaptureDeviceFactoryMac::PlatformSupportsAVFoundation()) { | 281 if (VideoCaptureDeviceFactoryMac::PlatformSupportsAVFoundation()) { |
| 280 EXPECT_TRUE(device == NULL); | 282 EXPECT_TRUE(device == NULL); |
| 281 } else { | 283 } else { |
| 282 // The presence of the actual device is only checked on AllocateAndStart() | 284 // The presence of the actual device is only checked on AllocateAndStart() |
| 283 // and not on creation for QTKit API in Mac OS X platform. | 285 // and not on creation for QTKit API in Mac OS X platform. |
| 284 EXPECT_CALL(*client_, OnError(_)).Times(1); | 286 EXPECT_CALL(*client_, OnError(_, _)).Times(1); |
| 285 | 287 |
| 286 VideoCaptureParams capture_params; | 288 VideoCaptureParams capture_params; |
| 287 capture_params.requested_format.frame_size.SetSize(640, 480); | 289 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 288 capture_params.requested_format.frame_rate = 30; | 290 capture_params.requested_format.frame_rate = 30; |
| 289 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 291 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 290 device->AllocateAndStart(capture_params, client_.Pass()); | 292 device->AllocateAndStart(capture_params, client_.Pass()); |
| 291 device->StopAndDeAllocate(); | 293 device->StopAndDeAllocate(); |
| 292 } | 294 } |
| 293 #endif | 295 #endif |
| 294 } | 296 } |
| 295 | 297 |
| 296 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) { | 298 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) { |
| 297 names_ = EnumerateDevices(); | 299 names_ = EnumerateDevices(); |
| 298 if (names_->empty()) { | 300 if (names_->empty()) { |
| 299 DVLOG(1) << "No camera available. Exiting test."; | 301 DVLOG(1) << "No camera available. Exiting test."; |
| 300 return; | 302 return; |
| 301 } | 303 } |
| 302 | 304 |
| 303 const gfx::Size& size = GetParam(); | 305 const gfx::Size& size = GetParam(); |
| 304 if (!IsCaptureSizeSupported(names_->front(), size)) | 306 if (!IsCaptureSizeSupported(names_->front(), size)) |
| 305 return; | 307 return; |
| 306 const int width = size.width(); | 308 const int width = size.width(); |
| 307 const int height = size.height(); | 309 const int height = size.height(); |
| 308 | 310 |
| 309 scoped_ptr<VideoCaptureDevice> device( | 311 scoped_ptr<VideoCaptureDevice> device( |
| 310 video_capture_device_factory_->Create(names_->front())); | 312 video_capture_device_factory_->Create(names_->front())); |
| 311 ASSERT_TRUE(device); | 313 ASSERT_TRUE(device); |
| 312 DVLOG(1) << names_->front().id(); | 314 DVLOG(1) << names_->front().id(); |
| 313 | 315 |
| 314 EXPECT_CALL(*client_, OnError(_)).Times(0); | 316 EXPECT_CALL(*client_, OnError(_, _)).Times(0); |
| 315 | 317 |
| 316 VideoCaptureParams capture_params; | 318 VideoCaptureParams capture_params; |
| 317 capture_params.requested_format.frame_size.SetSize(width, height); | 319 capture_params.requested_format.frame_size.SetSize(width, height); |
| 318 capture_params.requested_format.frame_rate = 30.0f; | 320 capture_params.requested_format.frame_rate = 30.0f; |
| 319 capture_params.requested_format.pixel_format = | 321 capture_params.requested_format.pixel_format = |
| 320 PIXEL_FORMAT_I420; | 322 PIXEL_FORMAT_I420; |
| 321 device->AllocateAndStart(capture_params, client_.Pass()); | 323 device->AllocateAndStart(capture_params, client_.Pass()); |
| 322 // Get captured video frames. | 324 // Get captured video frames. |
| 323 WaitForCapturedFrame(); | 325 WaitForCapturedFrame(); |
| 324 EXPECT_EQ(last_format().frame_size.width(), width); | 326 EXPECT_EQ(last_format().frame_size.width(), width); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 337 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 339 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 338 names_ = EnumerateDevices(); | 340 names_ = EnumerateDevices(); |
| 339 if (names_->empty()) { | 341 if (names_->empty()) { |
| 340 DVLOG(1) << "No camera available. Exiting test."; | 342 DVLOG(1) << "No camera available. Exiting test."; |
| 341 return; | 343 return; |
| 342 } | 344 } |
| 343 scoped_ptr<VideoCaptureDevice> device( | 345 scoped_ptr<VideoCaptureDevice> device( |
| 344 video_capture_device_factory_->Create(names_->front())); | 346 video_capture_device_factory_->Create(names_->front())); |
| 345 ASSERT_TRUE(device); | 347 ASSERT_TRUE(device); |
| 346 | 348 |
| 347 EXPECT_CALL(*client_, OnError(_)).Times(0); | 349 EXPECT_CALL(*client_, OnError(_, _)).Times(0); |
| 348 | 350 |
| 349 const gfx::Size input_size(640, 480); | 351 const gfx::Size input_size(640, 480); |
| 350 VideoCaptureParams capture_params; | 352 VideoCaptureParams capture_params; |
| 351 capture_params.requested_format.frame_size.SetSize(637, 472); | 353 capture_params.requested_format.frame_size.SetSize(637, 472); |
| 352 capture_params.requested_format.frame_rate = 35; | 354 capture_params.requested_format.frame_rate = 35; |
| 353 capture_params.requested_format.pixel_format = | 355 capture_params.requested_format.pixel_format = |
| 354 PIXEL_FORMAT_I420; | 356 PIXEL_FORMAT_I420; |
| 355 device->AllocateAndStart(capture_params, client_.Pass()); | 357 device->AllocateAndStart(capture_params, client_.Pass()); |
| 356 WaitForCapturedFrame(); | 358 WaitForCapturedFrame(); |
| 357 device->StopAndDeAllocate(); | 359 device->StopAndDeAllocate(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 417 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
| 416 names_ = EnumerateDevices(); | 418 names_ = EnumerateDevices(); |
| 417 if (names_->empty()) { | 419 if (names_->empty()) { |
| 418 DVLOG(1) << "No camera available. Exiting test."; | 420 DVLOG(1) << "No camera available. Exiting test."; |
| 419 return; | 421 return; |
| 420 } | 422 } |
| 421 scoped_ptr<VideoCaptureDevice> device( | 423 scoped_ptr<VideoCaptureDevice> device( |
| 422 video_capture_device_factory_->Create(names_->front())); | 424 video_capture_device_factory_->Create(names_->front())); |
| 423 ASSERT_TRUE(device); | 425 ASSERT_TRUE(device); |
| 424 | 426 |
| 425 EXPECT_CALL(*client_, OnError(_)).Times(0); | 427 EXPECT_CALL(*client_, OnError(_, _)).Times(0); |
| 426 | 428 |
| 427 VideoCaptureParams capture_params; | 429 VideoCaptureParams capture_params; |
| 428 capture_params.requested_format.frame_size.SetSize(640, 480); | 430 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 429 capture_params.requested_format.frame_rate = 30; | 431 capture_params.requested_format.frame_rate = 30; |
| 430 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 432 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 431 device->AllocateAndStart(capture_params, client_.Pass()); | 433 device->AllocateAndStart(capture_params, client_.Pass()); |
| 432 // Get captured video frames. | 434 // Get captured video frames. |
| 433 WaitForCapturedFrame(); | 435 WaitForCapturedFrame(); |
| 434 EXPECT_EQ(last_format().frame_size.width(), 640); | 436 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 435 EXPECT_EQ(last_format().frame_size.height(), 480); | 437 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 436 EXPECT_EQ(last_format().frame_rate, 30); | 438 EXPECT_EQ(last_format().frame_rate, 30); |
| 437 device->StopAndDeAllocate(); | 439 device->StopAndDeAllocate(); |
| 438 } | 440 } |
| 439 | 441 |
| 440 // Start the camera in 720p to capture MJPEG instead of a raw format. | 442 // Start the camera in 720p to capture MJPEG instead of a raw format. |
| 441 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { | 443 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
| 442 scoped_ptr<VideoCaptureDevice::Name> name = | 444 scoped_ptr<VideoCaptureDevice::Name> name = |
| 443 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); | 445 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); |
| 444 if (!name) { | 446 if (!name) { |
| 445 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; | 447 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; |
| 446 return; | 448 return; |
| 447 } | 449 } |
| 448 scoped_ptr<VideoCaptureDevice> device( | 450 scoped_ptr<VideoCaptureDevice> device( |
| 449 video_capture_device_factory_->Create(*name)); | 451 video_capture_device_factory_->Create(*name)); |
| 450 ASSERT_TRUE(device); | 452 ASSERT_TRUE(device); |
| 451 | 453 |
| 452 EXPECT_CALL(*client_, OnError(_)).Times(0); | 454 EXPECT_CALL(*client_, OnError(_, _)).Times(0); |
| 453 | 455 |
| 454 VideoCaptureParams capture_params; | 456 VideoCaptureParams capture_params; |
| 455 capture_params.requested_format.frame_size.SetSize(1280, 720); | 457 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 456 capture_params.requested_format.frame_rate = 30; | 458 capture_params.requested_format.frame_rate = 30; |
| 457 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 459 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; |
| 458 device->AllocateAndStart(capture_params, client_.Pass()); | 460 device->AllocateAndStart(capture_params, client_.Pass()); |
| 459 // Get captured video frames. | 461 // Get captured video frames. |
| 460 WaitForCapturedFrame(); | 462 WaitForCapturedFrame(); |
| 461 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | 463 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 |
| 462 // @ 30 fps, so we don't care about the exact resolution we get. | 464 // @ 30 fps, so we don't care about the exact resolution we get. |
| 463 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); | 465 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); |
| 464 EXPECT_GE(static_cast<size_t>(1280 * 720), | 466 EXPECT_GE(static_cast<size_t>(1280 * 720), |
| 465 last_format().ImageAllocationSize()); | 467 last_format().ImageAllocationSize()); |
| 466 device->StopAndDeAllocate(); | 468 device->StopAndDeAllocate(); |
| 467 } | 469 } |
| 468 | 470 |
| 469 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 471 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 470 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 472 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
| 471 // GetDeviceSupportedFormats(). | 473 // GetDeviceSupportedFormats(). |
| 472 scoped_ptr<VideoCaptureDevice::Name> name = | 474 scoped_ptr<VideoCaptureDevice::Name> name = |
| 473 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 475 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 474 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else | 476 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else |
| 475 // to test here | 477 // to test here |
| 476 // since we cannot forecast the hardware capabilities. | 478 // since we cannot forecast the hardware capabilities. |
| 477 ASSERT_FALSE(name); | 479 ASSERT_FALSE(name); |
| 478 } | 480 } |
| 479 | 481 |
| 480 }; // namespace media | 482 }; // namespace media |
| OLD | NEW |