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