| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 FakeVideoCaptureDevice::DeliveryMode::USE_CLIENT_PROVIDED_BUFFERS && | 278 FakeVideoCaptureDevice::DeliveryMode::USE_CLIENT_PROVIDED_BUFFERS && |
| 279 testing::get<0>(GetParam()) == media::PIXEL_FORMAT_MJPEG) { | 279 testing::get<0>(GetParam()) == media::PIXEL_FORMAT_MJPEG) { |
| 280 // Unsupported case | 280 // Unsupported case |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 | 283 |
| 284 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 284 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| 285 EnumerateDevices()); | 285 EnumerateDevices()); |
| 286 ASSERT_FALSE(descriptors->empty()); | 286 ASSERT_FALSE(descriptors->empty()); |
| 287 | 287 |
| 288 auto device = | 288 std::unique_ptr<VideoCaptureDevice> device = |
| 289 FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions( | 289 FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions( |
| 290 testing::get<0>(GetParam()), testing::get<1>(GetParam()), | 290 testing::get<0>(GetParam()), testing::get<1>(GetParam()), |
| 291 testing::get<2>(GetParam())); | 291 testing::get<2>(GetParam())); |
| 292 ASSERT_TRUE(device); | 292 ASSERT_TRUE(device); |
| 293 | 293 |
| 294 // First: Requested, Second: Expected | 294 // First: Requested, Second: Expected |
| 295 std::vector<std::pair<gfx::Size, gfx::Size>> resolutions_to_test; | 295 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)); | 296 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)); | 297 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)); | 298 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)); | 299 resolutions_to_test.emplace_back(gfx::Size(0, 720), gfx::Size(96, 96)); |
| 300 resolutions_to_test.emplace_back(gfx::Size(1920, 1080), | 300 resolutions_to_test.emplace_back(gfx::Size(1920, 1080), |
| 301 gfx::Size(1920, 1080)); | 301 gfx::Size(1920, 1080)); |
| 302 | 302 |
| 303 for (const auto& resolution : resolutions_to_test) { | 303 for (const auto& resolution : resolutions_to_test) { |
| 304 auto client = CreateClient(); | 304 std::unique_ptr<MockClient> client = CreateClient(); |
| 305 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 305 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
| 306 EXPECT_CALL(*client, OnStarted()); | 306 EXPECT_CALL(*client, OnStarted()); |
| 307 | 307 |
| 308 VideoCaptureParams capture_params; | 308 VideoCaptureParams capture_params; |
| 309 capture_params.requested_format.frame_size = resolution.first; | 309 capture_params.requested_format.frame_size = resolution.first; |
| 310 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); | 310 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); |
| 311 device->AllocateAndStart(capture_params, std::move(client)); | 311 device->AllocateAndStart(capture_params, std::move(client)); |
| 312 | 312 |
| 313 WaitForCapturedFrame(); | 313 WaitForCapturedFrame(); |
| 314 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); | 314 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 auto device = FakeVideoCaptureDeviceFactory::CreateErrorDevice(); | 390 auto device = FakeVideoCaptureDeviceFactory::CreateErrorDevice(); |
| 391 ASSERT_TRUE(device); | 391 ASSERT_TRUE(device); |
| 392 EXPECT_CALL(*client_, OnError(_, _)); | 392 EXPECT_CALL(*client_, OnError(_, _)); |
| 393 VideoCaptureParams capture_params; | 393 VideoCaptureParams capture_params; |
| 394 capture_params.requested_format.frame_size.SetSize(640, 480); | 394 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 395 capture_params.requested_format.frame_rate = 30.0; | 395 capture_params.requested_format.frame_rate = 30.0; |
| 396 device->AllocateAndStart(capture_params, std::move(client_)); | 396 device->AllocateAndStart(capture_params, std::move(client_)); |
| 397 } | 397 } |
| 398 | 398 |
| 399 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { | 399 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { |
| 400 auto device = | 400 std::unique_ptr<VideoCaptureDevice> device = |
| 401 FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions( | 401 FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions( |
| 402 PIXEL_FORMAT_I420, | 402 PIXEL_FORMAT_I420, |
| 403 FakeVideoCaptureDevice::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 403 FakeVideoCaptureDevice::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, |
| 404 30.0); | 404 30.0); |
| 405 ASSERT_TRUE(device); | 405 ASSERT_TRUE(device); |
| 406 | 406 |
| 407 VideoCaptureParams capture_params; | 407 VideoCaptureParams capture_params; |
| 408 capture_params.requested_format.frame_size.SetSize(640, 480); | 408 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 409 capture_params.requested_format.frame_rate = 30.0; | 409 capture_params.requested_format.frame_rate = 30.0; |
| 410 EXPECT_CALL(*client_, OnStarted()); | 410 EXPECT_CALL(*client_, OnStarted()); |
| 411 device->AllocateAndStart(capture_params, std::move(client_)); | 411 device->AllocateAndStart(capture_params, std::move(client_)); |
| 412 | 412 |
| 413 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( | 413 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( |
| 414 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities, | 414 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities, |
| 415 image_capture_client_), | 415 image_capture_client_), |
| 416 base::Bind(&ImageCaptureClient::OnGetPhotoCapabilitiesFailure, | 416 base::Bind(&ImageCaptureClient::OnGetPhotoCapabilitiesFailure, |
| 417 image_capture_client_)); | 417 image_capture_client_)); |
| 418 | 418 |
| 419 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) | 419 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) |
| 420 .Times(1); | 420 .Times(1); |
| 421 device->GetPhotoCapabilities(std::move(scoped_get_callback)); | 421 device->GetPhotoCapabilities(std::move(scoped_get_callback)); |
| 422 run_loop_.reset(new base::RunLoop()); | 422 run_loop_.reset(new base::RunLoop()); |
| 423 run_loop_->Run(); | 423 run_loop_->Run(); |
| 424 | 424 |
| 425 auto* capabilities = image_capture_client_->capabilities(); | 425 const mojom::PhotoCapabilities* capabilities = |
| 426 image_capture_client_->capabilities(); |
| 426 ASSERT_TRUE(capabilities); | 427 ASSERT_TRUE(capabilities); |
| 427 EXPECT_EQ(100, capabilities->iso->min); | 428 EXPECT_EQ(100, capabilities->iso->min); |
| 428 EXPECT_EQ(100, capabilities->iso->max); | 429 EXPECT_EQ(100, capabilities->iso->max); |
| 429 EXPECT_EQ(100, capabilities->iso->current); | 430 EXPECT_EQ(100, capabilities->iso->current); |
| 430 EXPECT_EQ(0, capabilities->iso->step); | 431 EXPECT_EQ(0, capabilities->iso->step); |
| 431 EXPECT_EQ(capture_params.requested_format.frame_size.height(), | 432 EXPECT_EQ(capture_params.requested_format.frame_size.height(), |
| 432 capabilities->height->current); | 433 capabilities->height->current); |
| 433 EXPECT_EQ(96, capabilities->height->min); | 434 EXPECT_EQ(96, capabilities->height->min); |
| 434 EXPECT_EQ(1080, capabilities->height->max); | 435 EXPECT_EQ(1080, capabilities->height->max); |
| 435 EXPECT_EQ(1, capabilities->height->step); | 436 EXPECT_EQ(1, capabilities->height->step); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 device->GetPhotoCapabilities(std::move(scoped_get_callback2)); | 504 device->GetPhotoCapabilities(std::move(scoped_get_callback2)); |
| 504 run_loop_.reset(new base::RunLoop()); | 505 run_loop_.reset(new base::RunLoop()); |
| 505 run_loop_->Run(); | 506 run_loop_->Run(); |
| 506 EXPECT_EQ(max_zoom_value, | 507 EXPECT_EQ(max_zoom_value, |
| 507 image_capture_client_->capabilities()->zoom->current); | 508 image_capture_client_->capabilities()->zoom->current); |
| 508 | 509 |
| 509 device->StopAndDeAllocate(); | 510 device->StopAndDeAllocate(); |
| 510 } | 511 } |
| 511 | 512 |
| 512 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { | 513 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
| 513 auto device = | 514 std::unique_ptr<VideoCaptureDevice> device = |
| 514 FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions( | 515 FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions( |
| 515 PIXEL_FORMAT_I420, | 516 PIXEL_FORMAT_I420, |
| 516 FakeVideoCaptureDevice::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 517 FakeVideoCaptureDevice::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, |
| 517 30.0); | 518 30.0); |
| 518 ASSERT_TRUE(device); | 519 ASSERT_TRUE(device); |
| 519 | 520 |
| 520 VideoCaptureParams capture_params; | 521 VideoCaptureParams capture_params; |
| 521 capture_params.requested_format.frame_size.SetSize(640, 480); | 522 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 522 capture_params.requested_format.frame_rate = 30.0; | 523 capture_params.requested_format.frame_rate = 30.0; |
| 523 EXPECT_CALL(*client_, OnStarted()); | 524 EXPECT_CALL(*client_, OnStarted()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 | 596 |
| 596 std::unique_ptr<VideoCaptureDevice> device = | 597 std::unique_ptr<VideoCaptureDevice> device = |
| 597 video_capture_device_factory_->CreateDevice(descriptors_iterator); | 598 video_capture_device_factory_->CreateDevice(descriptors_iterator); |
| 598 ASSERT_TRUE(device); | 599 ASSERT_TRUE(device); |
| 599 | 600 |
| 600 VideoCaptureParams capture_params; | 601 VideoCaptureParams capture_params; |
| 601 capture_params.requested_format.frame_size.SetSize(1280, 720); | 602 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 602 capture_params.requested_format.frame_rate = GetParam().expected_fps; | 603 capture_params.requested_format.frame_rate = GetParam().expected_fps; |
| 603 capture_params.requested_format.pixel_format = | 604 capture_params.requested_format.pixel_format = |
| 604 GetParam().expected_pixel_formats[device_index]; | 605 GetParam().expected_pixel_formats[device_index]; |
| 605 auto client = CreateClient(); | 606 std::unique_ptr<MockClient> client = CreateClient(); |
| 606 EXPECT_CALL(*client, OnStarted()); | 607 EXPECT_CALL(*client, OnStarted()); |
| 607 device->AllocateAndStart(capture_params, std::move(client)); | 608 device->AllocateAndStart(capture_params, std::move(client)); |
| 608 WaitForCapturedFrame(); | 609 WaitForCapturedFrame(); |
| 609 EXPECT_EQ(1280, last_format().frame_size.width()); | 610 EXPECT_EQ(1280, last_format().frame_size.width()); |
| 610 EXPECT_EQ(720, last_format().frame_size.height()); | 611 EXPECT_EQ(720, last_format().frame_size.height()); |
| 611 EXPECT_EQ(GetParam().expected_fps, last_format().frame_rate); | 612 EXPECT_EQ(GetParam().expected_fps, last_format().frame_rate); |
| 612 EXPECT_EQ(GetParam().expected_pixel_formats[device_index], | 613 EXPECT_EQ(GetParam().expected_pixel_formats[device_index], |
| 613 last_format().pixel_format); | 614 last_format().pixel_format); |
| 614 device->StopAndDeAllocate(); | 615 device->StopAndDeAllocate(); |
| 615 | 616 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 638 4u, | 639 4u, |
| 639 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, | 640 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, |
| 640 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, | 641 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, |
| 641 CommandLineTestData{"device-count=4,ownership=client", | 642 CommandLineTestData{"device-count=4,ownership=client", |
| 642 20, | 643 20, |
| 643 4u, | 644 4u, |
| 644 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, | 645 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, |
| 645 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, | 646 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, |
| 646 CommandLineTestData{"device-count=0", 20, 0u, {PIXEL_FORMAT_I420}})); | 647 CommandLineTestData{"device-count=0", 20, 0u, {PIXEL_FORMAT_I420}})); |
| 647 }; // namespace media | 648 }; // namespace media |
| OLD | NEW |