Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/fake_video_capture_device.h" | 5 #include "media/capture/video/fake_video_capture_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 testing::get<0>(GetParam()) == | 279 testing::get<0>(GetParam()) == |
| 280 FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG) { | 280 FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG) { |
| 281 // Unsupported case | 281 // Unsupported case |
| 282 return; | 282 return; |
| 283 } | 283 } |
| 284 | 284 |
| 285 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 285 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| 286 EnumerateDevices()); | 286 EnumerateDevices()); |
| 287 ASSERT_FALSE(descriptors->empty()); | 287 ASSERT_FALSE(descriptors->empty()); |
| 288 | 288 |
| 289 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 289 std::unique_ptr<VideoCaptureDevice> device = |
|
chfremer
2017/03/02 17:56:10
Thanks for these cleanups!
braveyao
2017/03/03 17:53:12
Acknowledged.
| |
| 290 testing::get<0>(GetParam()), testing::get<1>(GetParam()), | 290 FakeVideoCaptureDeviceMaker::MakeInstance(testing::get<0>(GetParam()), |
| 291 testing::get<2>(GetParam())); | 291 testing::get<1>(GetParam()), |
| 292 testing::get<2>(GetParam())); | |
| 292 ASSERT_TRUE(device); | 293 ASSERT_TRUE(device); |
| 293 | 294 |
| 294 // First: Requested, Second: Expected | 295 // First: Requested, Second: Expected |
| 295 std::vector<std::pair<gfx::Size, gfx::Size>> resolutions_to_test; | 296 std::vector<std::pair<gfx::Size, gfx::Size>> resolutions_to_test; |
| 296 resolutions_to_test.emplace_back(gfx::Size(640, 480), gfx::Size(640, 480)); | 297 resolutions_to_test.emplace_back(gfx::Size(640, 480), gfx::Size(640, 480)); |
| 297 resolutions_to_test.emplace_back(gfx::Size(104, 105), gfx::Size(320, 240)); | 298 resolutions_to_test.emplace_back(gfx::Size(104, 105), gfx::Size(320, 240)); |
| 298 resolutions_to_test.emplace_back(gfx::Size(0, 0), gfx::Size(96, 96)); | 299 resolutions_to_test.emplace_back(gfx::Size(0, 0), gfx::Size(96, 96)); |
| 299 resolutions_to_test.emplace_back(gfx::Size(0, 720), gfx::Size(96, 96)); | 300 resolutions_to_test.emplace_back(gfx::Size(0, 720), gfx::Size(96, 96)); |
| 300 resolutions_to_test.emplace_back(gfx::Size(1920, 1080), | 301 resolutions_to_test.emplace_back(gfx::Size(1920, 1080), |
| 301 gfx::Size(1920, 1080)); | 302 gfx::Size(1920, 1080)); |
| 302 | 303 |
| 303 for (const auto& resolution : resolutions_to_test) { | 304 for (const auto& resolution : resolutions_to_test) { |
| 304 auto client = CreateClient(); | 305 std::unique_ptr<MockClient> client = CreateClient(); |
| 305 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 306 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
| 306 EXPECT_CALL(*client, OnStarted()); | 307 EXPECT_CALL(*client, OnStarted()); |
| 307 | 308 |
| 308 VideoCaptureParams capture_params; | 309 VideoCaptureParams capture_params; |
| 309 capture_params.requested_format.frame_size = resolution.first; | 310 capture_params.requested_format.frame_size = resolution.first; |
| 310 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); | 311 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); |
| 311 device->AllocateAndStart(capture_params, std::move(client)); | 312 device->AllocateAndStart(capture_params, std::move(client)); |
| 312 | 313 |
| 313 WaitForCapturedFrame(); | 314 WaitForCapturedFrame(); |
| 314 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); | 315 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1); | 385 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1); |
| 385 EXPECT_EQ("/dev/video1", depth_device.device_id); | 386 EXPECT_EQ("/dev/video1", depth_device.device_id); |
| 386 ASSERT_TRUE(depth_device.camera_calibration); | 387 ASSERT_TRUE(depth_device.camera_calibration); |
| 387 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); | 388 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); |
| 388 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); | 389 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); |
| 389 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); | 390 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); |
| 390 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); | 391 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); |
| 391 } | 392 } |
| 392 | 393 |
| 393 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { | 394 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { |
| 394 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 395 std::unique_ptr<VideoCaptureDevice> device = |
| 395 FakeVideoCaptureDeviceMaker::PixelFormat::I420, | 396 FakeVideoCaptureDeviceMaker::MakeInstance( |
| 396 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 397 FakeVideoCaptureDeviceMaker::PixelFormat::I420, |
| 397 30.0); | 398 FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 399 USE_DEVICE_INTERNAL_BUFFERS, | |
| 400 30.0); | |
| 398 ASSERT_TRUE(device); | 401 ASSERT_TRUE(device); |
| 399 | 402 |
| 400 VideoCaptureParams capture_params; | 403 VideoCaptureParams capture_params; |
| 401 capture_params.requested_format.frame_size.SetSize(640, 480); | 404 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 402 capture_params.requested_format.frame_rate = 30.0; | 405 capture_params.requested_format.frame_rate = 30.0; |
| 403 EXPECT_CALL(*client_, OnStarted()); | 406 EXPECT_CALL(*client_, OnStarted()); |
| 404 device->AllocateAndStart(capture_params, std::move(client_)); | 407 device->AllocateAndStart(capture_params, std::move(client_)); |
| 405 | 408 |
| 406 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( | 409 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( |
| 407 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities, | 410 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities, |
| 408 image_capture_client_), | 411 image_capture_client_), |
| 409 base::Bind(&ImageCaptureClient::OnGetPhotoCapabilitiesFailure, | 412 base::Bind(&ImageCaptureClient::OnGetPhotoCapabilitiesFailure, |
| 410 image_capture_client_)); | 413 image_capture_client_)); |
| 411 | 414 |
| 412 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) | 415 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) |
| 413 .Times(1); | 416 .Times(1); |
| 414 device->GetPhotoCapabilities(std::move(scoped_get_callback)); | 417 device->GetPhotoCapabilities(std::move(scoped_get_callback)); |
| 415 run_loop_.reset(new base::RunLoop()); | 418 run_loop_.reset(new base::RunLoop()); |
| 416 run_loop_->Run(); | 419 run_loop_->Run(); |
| 417 | 420 |
| 418 auto* capabilities = image_capture_client_->capabilities(); | 421 const mojom::PhotoCapabilities* capabilities = |
| 422 image_capture_client_->capabilities(); | |
| 419 ASSERT_TRUE(capabilities); | 423 ASSERT_TRUE(capabilities); |
| 420 EXPECT_EQ(100, capabilities->iso->min); | 424 EXPECT_EQ(100, capabilities->iso->min); |
| 421 EXPECT_EQ(100, capabilities->iso->max); | 425 EXPECT_EQ(100, capabilities->iso->max); |
| 422 EXPECT_EQ(100, capabilities->iso->current); | 426 EXPECT_EQ(100, capabilities->iso->current); |
| 423 EXPECT_EQ(0, capabilities->iso->step); | 427 EXPECT_EQ(0, capabilities->iso->step); |
| 424 EXPECT_EQ(capture_params.requested_format.frame_size.height(), | 428 EXPECT_EQ(capture_params.requested_format.frame_size.height(), |
| 425 capabilities->height->current); | 429 capabilities->height->current); |
| 426 EXPECT_EQ(96, capabilities->height->min); | 430 EXPECT_EQ(96, capabilities->height->min); |
| 427 EXPECT_EQ(1080, capabilities->height->max); | 431 EXPECT_EQ(1080, capabilities->height->max); |
| 428 EXPECT_EQ(1, capabilities->height->step); | 432 EXPECT_EQ(1, capabilities->height->step); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 device->GetPhotoCapabilities(std::move(scoped_get_callback2)); | 500 device->GetPhotoCapabilities(std::move(scoped_get_callback2)); |
| 497 run_loop_.reset(new base::RunLoop()); | 501 run_loop_.reset(new base::RunLoop()); |
| 498 run_loop_->Run(); | 502 run_loop_->Run(); |
| 499 EXPECT_EQ(max_zoom_value, | 503 EXPECT_EQ(max_zoom_value, |
| 500 image_capture_client_->capabilities()->zoom->current); | 504 image_capture_client_->capabilities()->zoom->current); |
| 501 | 505 |
| 502 device->StopAndDeAllocate(); | 506 device->StopAndDeAllocate(); |
| 503 } | 507 } |
| 504 | 508 |
| 505 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { | 509 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
| 506 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 510 std::unique_ptr<VideoCaptureDevice> device = |
| 507 FakeVideoCaptureDeviceMaker::PixelFormat::I420, | 511 FakeVideoCaptureDeviceMaker::MakeInstance( |
| 508 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 512 FakeVideoCaptureDeviceMaker::PixelFormat::I420, |
| 509 30.0); | 513 FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 514 USE_DEVICE_INTERNAL_BUFFERS, | |
| 515 30.0); | |
| 510 ASSERT_TRUE(device); | 516 ASSERT_TRUE(device); |
| 511 | 517 |
| 512 VideoCaptureParams capture_params; | 518 VideoCaptureParams capture_params; |
| 513 capture_params.requested_format.frame_size.SetSize(640, 480); | 519 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 514 capture_params.requested_format.frame_rate = 30.0; | 520 capture_params.requested_format.frame_rate = 30.0; |
| 515 EXPECT_CALL(*client_, OnStarted()); | 521 EXPECT_CALL(*client_, OnStarted()); |
| 516 device->AllocateAndStart(capture_params, std::move(client_)); | 522 device->AllocateAndStart(capture_params, std::move(client_)); |
| 517 | 523 |
| 518 VideoCaptureDevice::TakePhotoCallback scoped_callback( | 524 VideoCaptureDevice::TakePhotoCallback scoped_callback( |
| 519 base::Bind(&ImageCaptureClient::DoOnPhotoTaken, image_capture_client_), | 525 base::Bind(&ImageCaptureClient::DoOnPhotoTaken, image_capture_client_), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 | 567 |
| 562 std::unique_ptr<VideoCaptureDevice> device = | 568 std::unique_ptr<VideoCaptureDevice> device = |
| 563 video_capture_device_factory_->CreateDevice(descriptors_iterator); | 569 video_capture_device_factory_->CreateDevice(descriptors_iterator); |
| 564 ASSERT_TRUE(device); | 570 ASSERT_TRUE(device); |
| 565 | 571 |
| 566 VideoCaptureParams capture_params; | 572 VideoCaptureParams capture_params; |
| 567 capture_params.requested_format.frame_size.SetSize(1280, 720); | 573 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 568 capture_params.requested_format.frame_rate = GetParam().expected_fps; | 574 capture_params.requested_format.frame_rate = GetParam().expected_fps; |
| 569 capture_params.requested_format.pixel_format = | 575 capture_params.requested_format.pixel_format = |
| 570 GetParam().expected_pixel_formats[device_index]; | 576 GetParam().expected_pixel_formats[device_index]; |
| 571 auto client = CreateClient(); | 577 std::unique_ptr<MockClient> client = CreateClient(); |
| 572 EXPECT_CALL(*client, OnStarted()); | 578 EXPECT_CALL(*client, OnStarted()); |
| 573 device->AllocateAndStart(capture_params, std::move(client)); | 579 device->AllocateAndStart(capture_params, std::move(client)); |
| 574 WaitForCapturedFrame(); | 580 WaitForCapturedFrame(); |
| 575 EXPECT_EQ(1280, last_format().frame_size.width()); | 581 EXPECT_EQ(1280, last_format().frame_size.width()); |
| 576 EXPECT_EQ(720, last_format().frame_size.height()); | 582 EXPECT_EQ(720, last_format().frame_size.height()); |
| 577 EXPECT_EQ(GetParam().expected_fps, last_format().frame_rate); | 583 EXPECT_EQ(GetParam().expected_fps, last_format().frame_rate); |
| 578 EXPECT_EQ(GetParam().expected_pixel_formats[device_index], | 584 EXPECT_EQ(GetParam().expected_pixel_formats[device_index], |
| 579 last_format().pixel_format); | 585 last_format().pixel_format); |
| 580 device->StopAndDeAllocate(); | 586 device->StopAndDeAllocate(); |
| 581 | 587 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 606 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, | 612 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, |
| 607 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, | 613 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, |
| 608 CommandLineTestData{"device-count=4,ownership=client", | 614 CommandLineTestData{"device-count=4,ownership=client", |
| 609 20, | 615 20, |
| 610 4u, | 616 4u, |
| 611 | 617 |
| 612 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, | 618 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, |
| 613 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, | 619 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, |
| 614 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); | 620 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); |
| 615 }; // namespace media | 621 }; // namespace media |
| OLD | NEW |