| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 VideoCaptureParams capture_params; | 315 VideoCaptureParams capture_params; |
| 316 capture_params.requested_format.frame_size.SetSize(width, height); | 316 capture_params.requested_format.frame_size.SetSize(width, height); |
| 317 capture_params.requested_format.frame_rate = 30.0f; | 317 capture_params.requested_format.frame_rate = 30.0f; |
| 318 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 318 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 319 device->AllocateAndStart(capture_params, client_.Pass()); | 319 device->AllocateAndStart(capture_params, client_.Pass()); |
| 320 // Get captured video frames. | 320 // Get captured video frames. |
| 321 WaitForCapturedFrame(); | 321 WaitForCapturedFrame(); |
| 322 EXPECT_EQ(last_format().frame_size.width(), width); | 322 EXPECT_EQ(last_format().frame_size.width(), width); |
| 323 EXPECT_EQ(last_format().frame_size.height(), height); | 323 EXPECT_EQ(last_format().frame_size.height(), height); |
| 324 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) | 324 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) |
| 325 EXPECT_LE(static_cast<size_t>(width * height * 3 / 2), | 325 EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea()); |
| 326 last_format().ImageAllocationSize()); | |
| 327 device->StopAndDeAllocate(); | 326 device->StopAndDeAllocate(); |
| 328 } | 327 } |
| 329 | 328 |
| 330 #if !defined(OS_ANDROID) | 329 #if !defined(OS_ANDROID) |
| 331 INSTANTIATE_TEST_CASE_P(MAYBE_VideoCaptureDeviceTests, | 330 INSTANTIATE_TEST_CASE_P(MAYBE_VideoCaptureDeviceTests, |
| 332 VideoCaptureDeviceTest, | 331 VideoCaptureDeviceTest, |
| 333 testing::ValuesIn(kCaptureSizes)); | 332 testing::ValuesIn(kCaptureSizes)); |
| 334 #endif | 333 #endif |
| 335 | 334 |
| 336 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 335 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 337 names_ = EnumerateDevices(); | 336 names_ = EnumerateDevices(); |
| 338 if (names_->empty()) { | 337 if (names_->empty()) { |
| 339 DVLOG(1) << "No camera available. Exiting test."; | 338 DVLOG(1) << "No camera available. Exiting test."; |
| 340 return; | 339 return; |
| 341 } | 340 } |
| 342 scoped_ptr<VideoCaptureDevice> device( | 341 scoped_ptr<VideoCaptureDevice> device( |
| 343 video_capture_device_factory_->Create(names_->front())); | 342 video_capture_device_factory_->Create(names_->front())); |
| 344 ASSERT_TRUE(device); | 343 ASSERT_TRUE(device); |
| 345 | 344 |
| 346 EXPECT_CALL(*client_, OnError(_)).Times(0); | 345 EXPECT_CALL(*client_, OnError(_)).Times(0); |
| 347 | 346 |
| 347 const gfx::Size input_size(640, 480); |
| 348 VideoCaptureParams capture_params; | 348 VideoCaptureParams capture_params; |
| 349 capture_params.requested_format.frame_size.SetSize(637, 472); | 349 capture_params.requested_format.frame_size.SetSize(637, 472); |
| 350 capture_params.requested_format.frame_rate = 35; | 350 capture_params.requested_format.frame_rate = 35; |
| 351 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 351 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 352 device->AllocateAndStart(capture_params, client_.Pass()); | 352 device->AllocateAndStart(capture_params, client_.Pass()); |
| 353 WaitForCapturedFrame(); | 353 WaitForCapturedFrame(); |
| 354 device->StopAndDeAllocate(); | 354 device->StopAndDeAllocate(); |
| 355 EXPECT_EQ(last_format().frame_size.width(), 640); | 355 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); |
| 356 EXPECT_EQ(last_format().frame_size.height(), 480); | 356 EXPECT_EQ(last_format().frame_size.height(), input_size.height()); |
| 357 EXPECT_EQ(static_cast<size_t>(640 * 480 * 3 / 2), | 357 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) |
| 358 last_format().ImageAllocationSize()); | 358 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea()); |
| 359 } | 359 } |
| 360 | 360 |
| 361 // Cause hangs on Windows Debug. http://crbug.com/417824 | 361 // Cause hangs on Windows Debug. http://crbug.com/417824 |
| 362 #if defined(OS_WIN) && !defined(NDEBUG) | 362 #if defined(OS_WIN) && !defined(NDEBUG) |
| 363 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera | 363 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera |
| 364 #else | 364 #else |
| 365 #define MAYBE_ReAllocateCamera ReAllocateCamera | 365 #define MAYBE_ReAllocateCamera ReAllocateCamera |
| 366 #endif | 366 #endif |
| 367 | 367 |
| 368 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { | 368 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 467 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
| 468 // GetDeviceSupportedFormats(). | 468 // GetDeviceSupportedFormats(). |
| 469 scoped_ptr<VideoCaptureDevice::Name> name = | 469 scoped_ptr<VideoCaptureDevice::Name> name = |
| 470 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 470 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 471 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 471 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
| 472 // since we cannot forecast the hardware capabilities. | 472 // since we cannot forecast the hardware capabilities. |
| 473 ASSERT_FALSE(name); | 473 ASSERT_FALSE(name); |
| 474 } | 474 } |
| 475 | 475 |
| 476 }; // namespace media | 476 }; // namespace media |
| OLD | NEW |