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/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 | 262 |
| 263 VideoCaptureParams capture_params; | 263 VideoCaptureParams capture_params; |
| 264 capture_params.requested_format.frame_size.SetSize(640, 480); | 264 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 265 capture_params.requested_format.frame_rate = 30; | 265 capture_params.requested_format.frame_rate = 30; |
| 266 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 266 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 267 device->AllocateAndStart(capture_params, client_.Pass()); | 267 device->AllocateAndStart(capture_params, client_.Pass()); |
| 268 // Get captured video frames. | 268 // Get captured video frames. |
| 269 WaitForCapturedFrame(); | 269 WaitForCapturedFrame(); |
| 270 EXPECT_EQ(last_format().frame_size.width(), 640); | 270 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 271 EXPECT_EQ(last_format().frame_size.height(), 480); | 271 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 272 EXPECT_EQ((size_t)640*480*3/2, last_format().ImageAllocationSize()); | |
|
mcasas
2015/02/03 20:48:46
static_cast
| |
| 272 device->StopAndDeAllocate(); | 273 device->StopAndDeAllocate(); |
| 273 } | 274 } |
| 274 | 275 |
| 275 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 276 TEST_F(VideoCaptureDeviceTest, Capture720p) { |
| 276 names_ = EnumerateDevices(); | 277 names_ = EnumerateDevices(); |
| 277 if (!names_->size()) { | 278 if (!names_->size()) { |
| 278 DVLOG(1) << "No camera available. Exiting test."; | 279 DVLOG(1) << "No camera available. Exiting test."; |
| 279 return; | 280 return; |
| 280 } | 281 } |
| 281 | 282 |
| 282 scoped_ptr<VideoCaptureDevice> device( | 283 scoped_ptr<VideoCaptureDevice> device( |
| 283 video_capture_device_factory_->Create(names_->front())); | 284 video_capture_device_factory_->Create(names_->front())); |
| 284 ASSERT_TRUE(device); | 285 ASSERT_TRUE(device); |
| 285 | 286 |
| 286 EXPECT_CALL(*client_, OnErr()) | 287 EXPECT_CALL(*client_, OnErr()) |
| 287 .Times(0); | 288 .Times(0); |
| 288 | 289 |
| 289 VideoCaptureParams capture_params; | 290 VideoCaptureParams capture_params; |
| 290 capture_params.requested_format.frame_size.SetSize(1280, 720); | 291 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 291 capture_params.requested_format.frame_rate = 30; | 292 capture_params.requested_format.frame_rate = 30; |
| 292 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 293 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 293 device->AllocateAndStart(capture_params, client_.Pass()); | 294 device->AllocateAndStart(capture_params, client_.Pass()); |
| 294 // Get captured video frames. | 295 // Get captured video frames. |
| 295 WaitForCapturedFrame(); | 296 WaitForCapturedFrame(); |
| 297 EXPECT_EQ(last_format().frame_size.width(), 1280); | |
| 298 EXPECT_EQ(last_format().frame_size.height(), 720); | |
| 299 EXPECT_EQ((size_t)1280*720*3/2, last_format().ImageAllocationSize()); | |
|
mcasas
2015/02/03 20:48:46
idem
| |
| 296 device->StopAndDeAllocate(); | 300 device->StopAndDeAllocate(); |
| 297 } | 301 } |
| 298 | 302 |
| 299 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 303 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 300 names_ = EnumerateDevices(); | 304 names_ = EnumerateDevices(); |
| 301 if (!names_->size()) { | 305 if (!names_->size()) { |
| 302 DVLOG(1) << "No camera available. Exiting test."; | 306 DVLOG(1) << "No camera available. Exiting test."; |
| 303 return; | 307 return; |
| 304 } | 308 } |
| 305 scoped_ptr<VideoCaptureDevice> device( | 309 scoped_ptr<VideoCaptureDevice> device( |
| 306 video_capture_device_factory_->Create(names_->front())); | 310 video_capture_device_factory_->Create(names_->front())); |
| 307 ASSERT_TRUE(device); | 311 ASSERT_TRUE(device); |
| 308 | 312 |
| 309 EXPECT_CALL(*client_, OnErr()) | 313 EXPECT_CALL(*client_, OnErr()) |
| 310 .Times(0); | 314 .Times(0); |
| 311 | 315 |
| 312 VideoCaptureParams capture_params; | 316 VideoCaptureParams capture_params; |
| 313 capture_params.requested_format.frame_size.SetSize(637, 472); | 317 capture_params.requested_format.frame_size.SetSize(637, 472); |
| 314 capture_params.requested_format.frame_rate = 35; | 318 capture_params.requested_format.frame_rate = 35; |
| 315 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 319 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 316 device->AllocateAndStart(capture_params, client_.Pass()); | 320 device->AllocateAndStart(capture_params, client_.Pass()); |
| 317 WaitForCapturedFrame(); | 321 WaitForCapturedFrame(); |
| 318 device->StopAndDeAllocate(); | 322 device->StopAndDeAllocate(); |
| 319 EXPECT_EQ(last_format().frame_size.width(), 640); | 323 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 320 EXPECT_EQ(last_format().frame_size.height(), 480); | 324 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 325 EXPECT_EQ((size_t)640*480*3/2, last_format().ImageAllocationSize()); | |
|
mcasas
2015/02/03 20:48:46
idem, and all those remaining if any
| |
| 321 } | 326 } |
| 322 | 327 |
| 323 // Cause hangs on Windows Debug. http://crbug.com/417824 | 328 // Cause hangs on Windows Debug. http://crbug.com/417824 |
| 324 #if defined(OS_WIN) && !defined(NDEBUG) | 329 #if defined(OS_WIN) && !defined(NDEBUG) |
| 325 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera | 330 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera |
| 326 #else | 331 #else |
| 327 #define MAYBE_ReAllocateCamera ReAllocateCamera | 332 #define MAYBE_ReAllocateCamera ReAllocateCamera |
| 328 #endif | 333 #endif |
| 329 | 334 |
| 330 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { | 335 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 VideoCaptureParams capture_params; | 420 VideoCaptureParams capture_params; |
| 416 capture_params.requested_format.frame_size.SetSize(1280, 720); | 421 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 417 capture_params.requested_format.frame_rate = 30; | 422 capture_params.requested_format.frame_rate = 30; |
| 418 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 423 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; |
| 419 device->AllocateAndStart(capture_params, client_.Pass()); | 424 device->AllocateAndStart(capture_params, client_.Pass()); |
| 420 // Get captured video frames. | 425 // Get captured video frames. |
| 421 WaitForCapturedFrame(); | 426 WaitForCapturedFrame(); |
| 422 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | 427 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 |
| 423 // @ 30 fps, so we don't care about the exact resolution we get. | 428 // @ 30 fps, so we don't care about the exact resolution we get. |
| 424 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); | 429 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); |
| 430 EXPECT_GE((size_t)1280*720, last_format().ImageAllocationSize()); | |
| 425 device->StopAndDeAllocate(); | 431 device->StopAndDeAllocate(); |
| 426 } | 432 } |
| 427 | 433 |
| 428 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 434 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 429 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 435 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
| 430 // GetDeviceSupportedFormats(). | 436 // GetDeviceSupportedFormats(). |
| 431 scoped_ptr<VideoCaptureDevice::Name> name = | 437 scoped_ptr<VideoCaptureDevice::Name> name = |
| 432 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 438 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 433 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 439 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
| 434 // since we cannot forecast the hardware capabilities. | 440 // since we cannot forecast the hardware capabilities. |
| 435 ASSERT_FALSE(name); | 441 ASSERT_FALSE(name); |
| 436 } | 442 } |
| 437 | 443 |
| 438 }; // namespace media | 444 }; // namespace media |
| OLD | NEW |