| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 EXPECT_TRUE(device == NULL); | 232 EXPECT_TRUE(device == NULL); |
| 233 } else { | 233 } else { |
| 234 // The presence of the actual device is only checked on AllocateAndStart() | 234 // The presence of the actual device is only checked on AllocateAndStart() |
| 235 // and not on creation for QTKit API in Mac OS X platform. | 235 // and not on creation for QTKit API in Mac OS X platform. |
| 236 EXPECT_CALL(*client_, OnErr()).Times(1); | 236 EXPECT_CALL(*client_, OnErr()).Times(1); |
| 237 | 237 |
| 238 VideoCaptureParams capture_params; | 238 VideoCaptureParams capture_params; |
| 239 capture_params.requested_format.frame_size.SetSize(640, 480); | 239 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 240 capture_params.requested_format.frame_rate = 30; | 240 capture_params.requested_format.frame_rate = 30; |
| 241 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 241 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 242 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 242 device->AllocateAndStart(capture_params, client_.Pass()); |
| 243 device->StopAndDeAllocate(); | 243 device->StopAndDeAllocate(); |
| 244 } | 244 } |
| 245 #endif | 245 #endif |
| 246 } | 246 } |
| 247 | 247 |
| 248 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 248 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
| 249 names_ = EnumerateDevices(); | 249 names_ = EnumerateDevices(); |
| 250 if (!names_->size()) { | 250 if (!names_->size()) { |
| 251 DVLOG(1) << "No camera available. Exiting test."; | 251 DVLOG(1) << "No camera available. Exiting test."; |
| 252 return; | 252 return; |
| 253 } | 253 } |
| 254 | 254 |
| 255 scoped_ptr<VideoCaptureDevice> device( | 255 scoped_ptr<VideoCaptureDevice> device( |
| 256 video_capture_device_factory_->Create(names_->front())); | 256 video_capture_device_factory_->Create(names_->front())); |
| 257 ASSERT_TRUE(device); | 257 ASSERT_TRUE(device); |
| 258 DVLOG(1) << names_->front().id(); | 258 DVLOG(1) << names_->front().id(); |
| 259 | 259 |
| 260 EXPECT_CALL(*client_, OnErr()) | 260 EXPECT_CALL(*client_, OnErr()) |
| 261 .Times(0); | 261 .Times(0); |
| 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_.PassAs<Client>()); | 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 device->StopAndDeAllocate(); | 272 device->StopAndDeAllocate(); |
| 273 } | 273 } |
| 274 | 274 |
| 275 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 275 TEST_F(VideoCaptureDeviceTest, Capture720p) { |
| 276 names_ = EnumerateDevices(); | 276 names_ = EnumerateDevices(); |
| 277 if (!names_->size()) { | 277 if (!names_->size()) { |
| 278 DVLOG(1) << "No camera available. Exiting test."; | 278 DVLOG(1) << "No camera available. Exiting test."; |
| 279 return; | 279 return; |
| 280 } | 280 } |
| 281 | 281 |
| 282 scoped_ptr<VideoCaptureDevice> device( | 282 scoped_ptr<VideoCaptureDevice> device( |
| 283 video_capture_device_factory_->Create(names_->front())); | 283 video_capture_device_factory_->Create(names_->front())); |
| 284 ASSERT_TRUE(device); | 284 ASSERT_TRUE(device); |
| 285 | 285 |
| 286 EXPECT_CALL(*client_, OnErr()) | 286 EXPECT_CALL(*client_, OnErr()) |
| 287 .Times(0); | 287 .Times(0); |
| 288 | 288 |
| 289 VideoCaptureParams capture_params; | 289 VideoCaptureParams capture_params; |
| 290 capture_params.requested_format.frame_size.SetSize(1280, 720); | 290 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 291 capture_params.requested_format.frame_rate = 30; | 291 capture_params.requested_format.frame_rate = 30; |
| 292 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 292 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 293 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 293 device->AllocateAndStart(capture_params, client_.Pass()); |
| 294 // Get captured video frames. | 294 // Get captured video frames. |
| 295 WaitForCapturedFrame(); | 295 WaitForCapturedFrame(); |
| 296 device->StopAndDeAllocate(); | 296 device->StopAndDeAllocate(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 299 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 300 names_ = EnumerateDevices(); | 300 names_ = EnumerateDevices(); |
| 301 if (!names_->size()) { | 301 if (!names_->size()) { |
| 302 DVLOG(1) << "No camera available. Exiting test."; | 302 DVLOG(1) << "No camera available. Exiting test."; |
| 303 return; | 303 return; |
| 304 } | 304 } |
| 305 scoped_ptr<VideoCaptureDevice> device( | 305 scoped_ptr<VideoCaptureDevice> device( |
| 306 video_capture_device_factory_->Create(names_->front())); | 306 video_capture_device_factory_->Create(names_->front())); |
| 307 ASSERT_TRUE(device); | 307 ASSERT_TRUE(device); |
| 308 | 308 |
| 309 EXPECT_CALL(*client_, OnErr()) | 309 EXPECT_CALL(*client_, OnErr()) |
| 310 .Times(0); | 310 .Times(0); |
| 311 | 311 |
| 312 VideoCaptureParams capture_params; | 312 VideoCaptureParams capture_params; |
| 313 capture_params.requested_format.frame_size.SetSize(637, 472); | 313 capture_params.requested_format.frame_size.SetSize(637, 472); |
| 314 capture_params.requested_format.frame_rate = 35; | 314 capture_params.requested_format.frame_rate = 35; |
| 315 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 315 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 316 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 316 device->AllocateAndStart(capture_params, client_.Pass()); |
| 317 WaitForCapturedFrame(); | 317 WaitForCapturedFrame(); |
| 318 device->StopAndDeAllocate(); | 318 device->StopAndDeAllocate(); |
| 319 EXPECT_EQ(last_format().frame_size.width(), 640); | 319 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 320 EXPECT_EQ(last_format().frame_size.height(), 480); | 320 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 321 } | 321 } |
| 322 | 322 |
| 323 // Cause hangs on Windows Debug. http://crbug.com/417824 | 323 // Cause hangs on Windows Debug. http://crbug.com/417824 |
| 324 #if defined(OS_WIN) && !defined(NDEBUG) | 324 #if defined(OS_WIN) && !defined(NDEBUG) |
| 325 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera | 325 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera |
| 326 #else | 326 #else |
| (...skipping 15 matching lines...) Expand all Loading... |
| 342 gfx::Size resolution; | 342 gfx::Size resolution; |
| 343 if (i % 2) { | 343 if (i % 2) { |
| 344 resolution = gfx::Size(640, 480); | 344 resolution = gfx::Size(640, 480); |
| 345 } else { | 345 } else { |
| 346 resolution = gfx::Size(1280, 1024); | 346 resolution = gfx::Size(1280, 1024); |
| 347 } | 347 } |
| 348 VideoCaptureParams capture_params; | 348 VideoCaptureParams capture_params; |
| 349 capture_params.requested_format.frame_size = resolution; | 349 capture_params.requested_format.frame_size = resolution; |
| 350 capture_params.requested_format.frame_rate = 30; | 350 capture_params.requested_format.frame_rate = 30; |
| 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_.PassAs<Client>()); | 352 device->AllocateAndStart(capture_params, client_.Pass()); |
| 353 device->StopAndDeAllocate(); | 353 device->StopAndDeAllocate(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 // Finally, do a device start and wait for it to finish. | 356 // Finally, do a device start and wait for it to finish. |
| 357 VideoCaptureParams capture_params; | 357 VideoCaptureParams capture_params; |
| 358 capture_params.requested_format.frame_size.SetSize(320, 240); | 358 capture_params.requested_format.frame_size.SetSize(320, 240); |
| 359 capture_params.requested_format.frame_rate = 30; | 359 capture_params.requested_format.frame_rate = 30; |
| 360 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 360 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 361 | 361 |
| 362 ResetWithNewClient(); | 362 ResetWithNewClient(); |
| 363 scoped_ptr<VideoCaptureDevice> device( | 363 scoped_ptr<VideoCaptureDevice> device( |
| 364 video_capture_device_factory_->Create(names_->front())); | 364 video_capture_device_factory_->Create(names_->front())); |
| 365 | 365 |
| 366 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 366 device->AllocateAndStart(capture_params, client_.Pass()); |
| 367 WaitForCapturedFrame(); | 367 WaitForCapturedFrame(); |
| 368 device->StopAndDeAllocate(); | 368 device->StopAndDeAllocate(); |
| 369 device.reset(); | 369 device.reset(); |
| 370 EXPECT_EQ(last_format().frame_size.width(), 320); | 370 EXPECT_EQ(last_format().frame_size.width(), 320); |
| 371 EXPECT_EQ(last_format().frame_size.height(), 240); | 371 EXPECT_EQ(last_format().frame_size.height(), 240); |
| 372 } | 372 } |
| 373 | 373 |
| 374 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 374 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
| 375 names_ = EnumerateDevices(); | 375 names_ = EnumerateDevices(); |
| 376 if (!names_->size()) { | 376 if (!names_->size()) { |
| 377 DVLOG(1) << "No camera available. Exiting test."; | 377 DVLOG(1) << "No camera available. Exiting test."; |
| 378 return; | 378 return; |
| 379 } | 379 } |
| 380 scoped_ptr<VideoCaptureDevice> device( | 380 scoped_ptr<VideoCaptureDevice> device( |
| 381 video_capture_device_factory_->Create(names_->front())); | 381 video_capture_device_factory_->Create(names_->front())); |
| 382 ASSERT_TRUE(device); | 382 ASSERT_TRUE(device); |
| 383 | 383 |
| 384 EXPECT_CALL(*client_, OnErr()) | 384 EXPECT_CALL(*client_, OnErr()) |
| 385 .Times(0); | 385 .Times(0); |
| 386 | 386 |
| 387 VideoCaptureParams capture_params; | 387 VideoCaptureParams capture_params; |
| 388 capture_params.requested_format.frame_size.SetSize(640, 480); | 388 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 389 capture_params.requested_format.frame_rate = 30; | 389 capture_params.requested_format.frame_rate = 30; |
| 390 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 390 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 391 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 391 device->AllocateAndStart(capture_params, client_.Pass()); |
| 392 // Get captured video frames. | 392 // Get captured video frames. |
| 393 WaitForCapturedFrame(); | 393 WaitForCapturedFrame(); |
| 394 EXPECT_EQ(last_format().frame_size.width(), 640); | 394 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 395 EXPECT_EQ(last_format().frame_size.height(), 480); | 395 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 396 EXPECT_EQ(last_format().frame_rate, 30); | 396 EXPECT_EQ(last_format().frame_rate, 30); |
| 397 device->StopAndDeAllocate(); | 397 device->StopAndDeAllocate(); |
| 398 } | 398 } |
| 399 | 399 |
| 400 // Start the camera in 720p to capture MJPEG instead of a raw format. | 400 // Start the camera in 720p to capture MJPEG instead of a raw format. |
| 401 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { | 401 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
| 402 scoped_ptr<VideoCaptureDevice::Name> name = | 402 scoped_ptr<VideoCaptureDevice::Name> name = |
| 403 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); | 403 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); |
| 404 if (!name) { | 404 if (!name) { |
| 405 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; | 405 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; |
| 406 return; | 406 return; |
| 407 } | 407 } |
| 408 scoped_ptr<VideoCaptureDevice> device( | 408 scoped_ptr<VideoCaptureDevice> device( |
| 409 video_capture_device_factory_->Create(*name)); | 409 video_capture_device_factory_->Create(*name)); |
| 410 ASSERT_TRUE(device); | 410 ASSERT_TRUE(device); |
| 411 | 411 |
| 412 EXPECT_CALL(*client_, OnErr()) | 412 EXPECT_CALL(*client_, OnErr()) |
| 413 .Times(0); | 413 .Times(0); |
| 414 | 414 |
| 415 VideoCaptureParams capture_params; | 415 VideoCaptureParams capture_params; |
| 416 capture_params.requested_format.frame_size.SetSize(1280, 720); | 416 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 417 capture_params.requested_format.frame_rate = 30; | 417 capture_params.requested_format.frame_rate = 30; |
| 418 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 418 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; |
| 419 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 419 device->AllocateAndStart(capture_params, client_.Pass()); |
| 420 // Get captured video frames. | 420 // Get captured video frames. |
| 421 WaitForCapturedFrame(); | 421 WaitForCapturedFrame(); |
| 422 // 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 |
| 423 // @ 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. |
| 424 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); | 424 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); |
| 425 device->StopAndDeAllocate(); | 425 device->StopAndDeAllocate(); |
| 426 } | 426 } |
| 427 | 427 |
| 428 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 428 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 429 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 429 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
| 430 // GetDeviceSupportedFormats(). | 430 // GetDeviceSupportedFormats(). |
| 431 scoped_ptr<VideoCaptureDevice::Name> name = | 431 scoped_ptr<VideoCaptureDevice::Name> name = |
| 432 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 432 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 433 // 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 |
| 434 // since we cannot forecast the hardware capabilities. | 434 // since we cannot forecast the hardware capabilities. |
| 435 ASSERT_FALSE(name); | 435 ASSERT_FALSE(name); |
| 436 } | 436 } |
| 437 | 437 |
| 438 }; // namespace media | 438 }; // namespace media |
| OLD | NEW |