Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1263)

Side by Side Diff: media/capture/video/video_capture_device_unittest.cc

Issue 1544313002: Convert Pass()→std::move() in //media (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/capture/video/video_capture_device_factory.cc ('k') | media/cast/cast_environment.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "media/capture/video/video_capture_device.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility>
7 10
8 #include "base/bind.h" 11 #include "base/bind.h"
9 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
10 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
12 #include "base/run_loop.h" 15 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
14 #include "base/test/test_timeouts.h" 17 #include "base/test/test_timeouts.h"
15 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
16 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
17 #include "build/build_config.h" 20 #include "build/build_config.h"
18 #include "media/base/video_capture_types.h" 21 #include "media/base/video_capture_types.h"
19 #include "media/capture/video/video_capture_device.h"
20 #include "media/capture/video/video_capture_device_factory.h" 22 #include "media/capture/video/video_capture_device_factory.h"
21 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 25
24 #if defined(OS_WIN) 26 #if defined(OS_WIN)
25 #include "base/win/scoped_com_initializer.h" 27 #include "base/win/scoped_com_initializer.h"
26 #include "base/win/windows_version.h" // For fine-grained suppression. 28 #include "base/win/windows_version.h" // For fine-grained suppression.
27 #include "media/capture/video/win/video_capture_device_factory_win.h" 29 #include "media/capture/video/win/video_capture_device_factory_win.h"
28 #endif 30 #endif
29 31
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 ASSERT_TRUE(device); 318 ASSERT_TRUE(device);
317 DVLOG(1) << names_->front().id(); 319 DVLOG(1) << names_->front().id();
318 320
319 EXPECT_CALL(*client_, OnError(_, _)).Times(0); 321 EXPECT_CALL(*client_, OnError(_, _)).Times(0);
320 322
321 VideoCaptureParams capture_params; 323 VideoCaptureParams capture_params;
322 capture_params.requested_format.frame_size.SetSize(width, height); 324 capture_params.requested_format.frame_size.SetSize(width, height);
323 capture_params.requested_format.frame_rate = 30.0f; 325 capture_params.requested_format.frame_rate = 30.0f;
324 capture_params.requested_format.pixel_format = 326 capture_params.requested_format.pixel_format =
325 PIXEL_FORMAT_I420; 327 PIXEL_FORMAT_I420;
326 device->AllocateAndStart(capture_params, client_.Pass()); 328 device->AllocateAndStart(capture_params, std::move(client_));
327 // Get captured video frames. 329 // Get captured video frames.
328 WaitForCapturedFrame(); 330 WaitForCapturedFrame();
329 EXPECT_EQ(last_format().frame_size.width(), width); 331 EXPECT_EQ(last_format().frame_size.width(), width);
330 EXPECT_EQ(last_format().frame_size.height(), height); 332 EXPECT_EQ(last_format().frame_size.height(), height);
331 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) 333 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG)
332 EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea()); 334 EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea());
333 device->StopAndDeAllocate(); 335 device->StopAndDeAllocate();
334 } 336 }
335 337
336 #if !defined(OS_ANDROID) 338 #if !defined(OS_ANDROID)
(...skipping 13 matching lines...) Expand all
350 ASSERT_TRUE(device); 352 ASSERT_TRUE(device);
351 353
352 EXPECT_CALL(*client_, OnError(_, _)).Times(0); 354 EXPECT_CALL(*client_, OnError(_, _)).Times(0);
353 355
354 const gfx::Size input_size(640, 480); 356 const gfx::Size input_size(640, 480);
355 VideoCaptureParams capture_params; 357 VideoCaptureParams capture_params;
356 capture_params.requested_format.frame_size.SetSize(637, 472); 358 capture_params.requested_format.frame_size.SetSize(637, 472);
357 capture_params.requested_format.frame_rate = 35; 359 capture_params.requested_format.frame_rate = 35;
358 capture_params.requested_format.pixel_format = 360 capture_params.requested_format.pixel_format =
359 PIXEL_FORMAT_I420; 361 PIXEL_FORMAT_I420;
360 device->AllocateAndStart(capture_params, client_.Pass()); 362 device->AllocateAndStart(capture_params, std::move(client_));
361 WaitForCapturedFrame(); 363 WaitForCapturedFrame();
362 device->StopAndDeAllocate(); 364 device->StopAndDeAllocate();
363 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); 365 EXPECT_EQ(last_format().frame_size.width(), input_size.width());
364 EXPECT_EQ(last_format().frame_size.height(), input_size.height()); 366 EXPECT_EQ(last_format().frame_size.height(), input_size.height());
365 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) 367 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG)
366 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea()); 368 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea());
367 } 369 }
368 370
369 // Cause hangs on Windows, Linux. Fails Android. http://crbug.com/417824 371 // Cause hangs on Windows, Linux. Fails Android. http://crbug.com/417824
370 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) { 372 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) {
(...skipping 11 matching lines...) Expand all
382 gfx::Size resolution; 384 gfx::Size resolution;
383 if (i % 2) { 385 if (i % 2) {
384 resolution = gfx::Size(640, 480); 386 resolution = gfx::Size(640, 480);
385 } else { 387 } else {
386 resolution = gfx::Size(1280, 1024); 388 resolution = gfx::Size(1280, 1024);
387 } 389 }
388 VideoCaptureParams capture_params; 390 VideoCaptureParams capture_params;
389 capture_params.requested_format.frame_size = resolution; 391 capture_params.requested_format.frame_size = resolution;
390 capture_params.requested_format.frame_rate = 30; 392 capture_params.requested_format.frame_rate = 30;
391 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 393 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
392 device->AllocateAndStart(capture_params, client_.Pass()); 394 device->AllocateAndStart(capture_params, std::move(client_));
393 device->StopAndDeAllocate(); 395 device->StopAndDeAllocate();
394 } 396 }
395 397
396 // Finally, do a device start and wait for it to finish. 398 // Finally, do a device start and wait for it to finish.
397 VideoCaptureParams capture_params; 399 VideoCaptureParams capture_params;
398 capture_params.requested_format.frame_size.SetSize(320, 240); 400 capture_params.requested_format.frame_size.SetSize(320, 240);
399 capture_params.requested_format.frame_rate = 30; 401 capture_params.requested_format.frame_rate = 30;
400 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 402 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
401 403
402 ResetWithNewClient(); 404 ResetWithNewClient();
403 scoped_ptr<VideoCaptureDevice> device( 405 scoped_ptr<VideoCaptureDevice> device(
404 video_capture_device_factory_->Create(names_->front())); 406 video_capture_device_factory_->Create(names_->front()));
405 407
406 device->AllocateAndStart(capture_params, client_.Pass()); 408 device->AllocateAndStart(capture_params, std::move(client_));
407 WaitForCapturedFrame(); 409 WaitForCapturedFrame();
408 device->StopAndDeAllocate(); 410 device->StopAndDeAllocate();
409 device.reset(); 411 device.reset();
410 EXPECT_EQ(last_format().frame_size.width(), 320); 412 EXPECT_EQ(last_format().frame_size.width(), 320);
411 EXPECT_EQ(last_format().frame_size.height(), 240); 413 EXPECT_EQ(last_format().frame_size.height(), 240);
412 } 414 }
413 415
414 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { 416 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
415 names_ = EnumerateDevices(); 417 names_ = EnumerateDevices();
416 if (names_->empty()) { 418 if (names_->empty()) {
417 VLOG(1) << "No camera available. Exiting test."; 419 VLOG(1) << "No camera available. Exiting test.";
418 return; 420 return;
419 } 421 }
420 scoped_ptr<VideoCaptureDevice> device( 422 scoped_ptr<VideoCaptureDevice> device(
421 video_capture_device_factory_->Create(names_->front())); 423 video_capture_device_factory_->Create(names_->front()));
422 ASSERT_TRUE(device); 424 ASSERT_TRUE(device);
423 425
424 EXPECT_CALL(*client_, OnError(_, _)).Times(0); 426 EXPECT_CALL(*client_, OnError(_, _)).Times(0);
425 427
426 VideoCaptureParams capture_params; 428 VideoCaptureParams capture_params;
427 capture_params.requested_format.frame_size.SetSize(640, 480); 429 capture_params.requested_format.frame_size.SetSize(640, 480);
428 capture_params.requested_format.frame_rate = 30; 430 capture_params.requested_format.frame_rate = 30;
429 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 431 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
430 device->AllocateAndStart(capture_params, client_.Pass()); 432 device->AllocateAndStart(capture_params, std::move(client_));
431 // Get captured video frames. 433 // Get captured video frames.
432 WaitForCapturedFrame(); 434 WaitForCapturedFrame();
433 EXPECT_EQ(last_format().frame_size.width(), 640); 435 EXPECT_EQ(last_format().frame_size.width(), 640);
434 EXPECT_EQ(last_format().frame_size.height(), 480); 436 EXPECT_EQ(last_format().frame_size.height(), 480);
435 EXPECT_EQ(last_format().frame_rate, 30); 437 EXPECT_EQ(last_format().frame_rate, 30);
436 device->StopAndDeAllocate(); 438 device->StopAndDeAllocate();
437 } 439 }
438 440
439 // Start the camera in 720p to capture MJPEG instead of a raw format. 441 // Start the camera in 720p to capture MJPEG instead of a raw format.
440 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { 442 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
(...skipping 12 matching lines...) Expand all
453 scoped_ptr<VideoCaptureDevice> device( 455 scoped_ptr<VideoCaptureDevice> device(
454 video_capture_device_factory_->Create(*name)); 456 video_capture_device_factory_->Create(*name));
455 ASSERT_TRUE(device); 457 ASSERT_TRUE(device);
456 458
457 EXPECT_CALL(*client_, OnError(_, _)).Times(0); 459 EXPECT_CALL(*client_, OnError(_, _)).Times(0);
458 460
459 VideoCaptureParams capture_params; 461 VideoCaptureParams capture_params;
460 capture_params.requested_format.frame_size.SetSize(1280, 720); 462 capture_params.requested_format.frame_size.SetSize(1280, 720);
461 capture_params.requested_format.frame_rate = 30; 463 capture_params.requested_format.frame_rate = 30;
462 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; 464 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
463 device->AllocateAndStart(capture_params, client_.Pass()); 465 device->AllocateAndStart(capture_params, std::move(client_));
464 // Get captured video frames. 466 // Get captured video frames.
465 WaitForCapturedFrame(); 467 WaitForCapturedFrame();
466 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 468 // Verify we get MJPEG from the device. Not all devices can capture 1280x720
467 // @ 30 fps, so we don't care about the exact resolution we get. 469 // @ 30 fps, so we don't care about the exact resolution we get.
468 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); 470 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG);
469 EXPECT_GE(static_cast<size_t>(1280 * 720), 471 EXPECT_GE(static_cast<size_t>(1280 * 720),
470 last_format().ImageAllocationSize()); 472 last_format().ImageAllocationSize());
471 device->StopAndDeAllocate(); 473 device->StopAndDeAllocate();
472 } 474 }
473 475
474 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { 476 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
475 // Use PIXEL_FORMAT_MAX to iterate all device names for testing 477 // Use PIXEL_FORMAT_MAX to iterate all device names for testing
476 // GetDeviceSupportedFormats(). 478 // GetDeviceSupportedFormats().
477 scoped_ptr<VideoCaptureDevice::Name> name = 479 scoped_ptr<VideoCaptureDevice::Name> name =
478 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); 480 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX);
479 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else 481 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else
480 // to test here 482 // to test here
481 // since we cannot forecast the hardware capabilities. 483 // since we cannot forecast the hardware capabilities.
482 ASSERT_FALSE(name); 484 ASSERT_FALSE(name);
483 } 485 }
484 486
485 }; // namespace media 487 }; // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/video_capture_device_factory.cc ('k') | media/cast/cast_environment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698