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