Chromium Code Reviews| 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 | 314 |
| 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_I420) { |
| 325 EXPECT_EQ(static_cast<size_t>(width * height * 3 / 2), | |
|
mcasas
2015/06/10 00:48:04
What about counting pixels instead of bytes?
if (
emircan
2015/06/10 01:19:59
Done.
| |
| 326 last_format().ImageAllocationSize()); | |
| 327 } else if ((last_format().pixel_format != PIXEL_FORMAT_MJPEG)) { | |
| 325 EXPECT_LE(static_cast<size_t>(width * height * 3 / 2), | 328 EXPECT_LE(static_cast<size_t>(width * height * 3 / 2), |
| 326 last_format().ImageAllocationSize()); | 329 last_format().ImageAllocationSize()); |
| 330 } | |
| 327 device->StopAndDeAllocate(); | 331 device->StopAndDeAllocate(); |
| 328 } | 332 } |
| 329 | 333 |
| 330 #if !defined(OS_ANDROID) | 334 #if !defined(OS_ANDROID) |
| 331 INSTANTIATE_TEST_CASE_P(MAYBE_VideoCaptureDeviceTests, | 335 INSTANTIATE_TEST_CASE_P(MAYBE_VideoCaptureDeviceTests, |
| 332 VideoCaptureDeviceTest, | 336 VideoCaptureDeviceTest, |
| 333 testing::ValuesIn(kCaptureSizes)); | 337 testing::ValuesIn(kCaptureSizes)); |
| 334 #endif | 338 #endif |
| 335 | 339 |
| 336 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 340 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 337 names_ = EnumerateDevices(); | 341 names_ = EnumerateDevices(); |
| 338 if (names_->empty()) { | 342 if (names_->empty()) { |
| 339 DVLOG(1) << "No camera available. Exiting test."; | 343 DVLOG(1) << "No camera available. Exiting test."; |
| 340 return; | 344 return; |
| 341 } | 345 } |
| 342 scoped_ptr<VideoCaptureDevice> device( | 346 scoped_ptr<VideoCaptureDevice> device( |
| 343 video_capture_device_factory_->Create(names_->front())); | 347 video_capture_device_factory_->Create(names_->front())); |
| 344 ASSERT_TRUE(device); | 348 ASSERT_TRUE(device); |
| 345 | 349 |
| 346 EXPECT_CALL(*client_, OnError(_)).Times(0); | 350 EXPECT_CALL(*client_, OnError(_)).Times(0); |
| 347 | 351 |
| 352 const int width = 640; | |
| 353 const int height = 480; | |
| 354 | |
| 348 VideoCaptureParams capture_params; | 355 VideoCaptureParams capture_params; |
| 349 capture_params.requested_format.frame_size.SetSize(637, 472); | 356 capture_params.requested_format.frame_size.SetSize(637, 472); |
| 350 capture_params.requested_format.frame_rate = 35; | 357 capture_params.requested_format.frame_rate = 35; |
| 351 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 358 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 352 device->AllocateAndStart(capture_params, client_.Pass()); | 359 device->AllocateAndStart(capture_params, client_.Pass()); |
| 353 WaitForCapturedFrame(); | 360 WaitForCapturedFrame(); |
| 354 device->StopAndDeAllocate(); | 361 device->StopAndDeAllocate(); |
| 355 EXPECT_EQ(last_format().frame_size.width(), 640); | 362 EXPECT_EQ(last_format().frame_size.width(), width); |
| 356 EXPECT_EQ(last_format().frame_size.height(), 480); | 363 EXPECT_EQ(last_format().frame_size.height(), height); |
| 357 EXPECT_EQ(static_cast<size_t>(640 * 480 * 3 / 2), | 364 if (last_format().pixel_format == PIXEL_FORMAT_I420) { |
|
mcasas
2015/06/10 00:48:04
Idem.
| |
| 358 last_format().ImageAllocationSize()); | 365 EXPECT_EQ(static_cast<size_t>(width * height * 3 / 2), |
| 366 last_format().ImageAllocationSize()); | |
| 367 } else if ((last_format().pixel_format != PIXEL_FORMAT_MJPEG)) { | |
| 368 EXPECT_LE(static_cast<size_t>(width * height * 3 / 2), | |
| 369 last_format().ImageAllocationSize()); | |
| 370 } | |
| 359 } | 371 } |
| 360 | 372 |
| 361 // Cause hangs on Windows Debug. http://crbug.com/417824 | 373 // Cause hangs on Windows Debug. http://crbug.com/417824 |
| 362 #if defined(OS_WIN) && !defined(NDEBUG) | 374 #if defined(OS_WIN) && !defined(NDEBUG) |
| 363 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera | 375 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera |
| 364 #else | 376 #else |
| 365 #define MAYBE_ReAllocateCamera ReAllocateCamera | 377 #define MAYBE_ReAllocateCamera ReAllocateCamera |
| 366 #endif | 378 #endif |
| 367 | 379 |
| 368 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { | 380 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 | 479 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
| 468 // GetDeviceSupportedFormats(). | 480 // GetDeviceSupportedFormats(). |
| 469 scoped_ptr<VideoCaptureDevice::Name> name = | 481 scoped_ptr<VideoCaptureDevice::Name> name = |
| 470 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 482 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 471 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 483 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
| 472 // since we cannot forecast the hardware capabilities. | 484 // since we cannot forecast the hardware capabilities. |
| 473 ASSERT_FALSE(name); | 485 ASSERT_FALSE(name); |
| 474 } | 486 } |
| 475 | 487 |
| 476 }; // namespace media | 488 }; // namespace media |
| OLD | NEW |