| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 buffer_id, arbitrary_frame_feedback_id, | 95 buffer_id, arbitrary_frame_feedback_id, |
| 96 base::MakeUnique<StubBufferHandleProvider>(mapped_size, buffer), | 96 base::MakeUnique<StubBufferHandleProvider>(mapped_size, buffer), |
| 97 base::MakeUnique<StubReadWritePermission>(buffer)); | 97 base::MakeUnique<StubReadWritePermission>(buffer)); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class MockClient : public VideoCaptureDevice::Client { | 100 class MockClient : public VideoCaptureDevice::Client { |
| 101 public: | 101 public: |
| 102 MOCK_METHOD2(OnError, | 102 MOCK_METHOD2(OnError, |
| 103 void(const tracked_objects::Location& from_here, | 103 void(const tracked_objects::Location& from_here, |
| 104 const std::string& reason)); | 104 const std::string& reason)); |
| 105 MOCK_METHOD0(OnStarted, void(void)); |
| 105 | 106 |
| 106 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 107 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
| 107 : frame_cb_(frame_cb) {} | 108 : frame_cb_(frame_cb) {} |
| 108 | 109 |
| 109 // Client virtual methods for capturing using Device Buffers. | 110 // Client virtual methods for capturing using Device Buffers. |
| 110 void OnIncomingCapturedData(const uint8_t* data, | 111 void OnIncomingCapturedData(const uint8_t* data, |
| 111 int length, | 112 int length, |
| 112 const VideoCaptureFormat& format, | 113 const VideoCaptureFormat& format, |
| 113 int rotation, | 114 int rotation, |
| 114 base::TimeTicks reference_time, | 115 base::TimeTicks reference_time, |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 resolutions_to_test.emplace_back(gfx::Size(640, 480), gfx::Size(640, 480)); | 288 resolutions_to_test.emplace_back(gfx::Size(640, 480), gfx::Size(640, 480)); |
| 288 resolutions_to_test.emplace_back(gfx::Size(104, 105), gfx::Size(320, 240)); | 289 resolutions_to_test.emplace_back(gfx::Size(104, 105), gfx::Size(320, 240)); |
| 289 resolutions_to_test.emplace_back(gfx::Size(0, 0), gfx::Size(96, 96)); | 290 resolutions_to_test.emplace_back(gfx::Size(0, 0), gfx::Size(96, 96)); |
| 290 resolutions_to_test.emplace_back(gfx::Size(0, 720), gfx::Size(96, 96)); | 291 resolutions_to_test.emplace_back(gfx::Size(0, 720), gfx::Size(96, 96)); |
| 291 resolutions_to_test.emplace_back(gfx::Size(1920, 1080), | 292 resolutions_to_test.emplace_back(gfx::Size(1920, 1080), |
| 292 gfx::Size(1920, 1080)); | 293 gfx::Size(1920, 1080)); |
| 293 | 294 |
| 294 for (const auto& resolution : resolutions_to_test) { | 295 for (const auto& resolution : resolutions_to_test) { |
| 295 auto client = CreateClient(); | 296 auto client = CreateClient(); |
| 296 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 297 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
| 298 EXPECT_CALL(*client, OnStarted()); |
| 297 | 299 |
| 298 VideoCaptureParams capture_params; | 300 VideoCaptureParams capture_params; |
| 299 capture_params.requested_format.frame_size = resolution.first; | 301 capture_params.requested_format.frame_size = resolution.first; |
| 300 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); | 302 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); |
| 301 device->AllocateAndStart(capture_params, std::move(client)); | 303 device->AllocateAndStart(capture_params, std::move(client)); |
| 302 | 304 |
| 303 WaitForCapturedFrame(); | 305 WaitForCapturedFrame(); |
| 304 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); | 306 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); |
| 305 EXPECT_EQ(resolution.second.height(), last_format().frame_size.height()); | 307 EXPECT_EQ(resolution.second.height(), last_format().frame_size.height()); |
| 306 EXPECT_EQ(last_format().pixel_format, testing::get<0>(GetParam())); | 308 EXPECT_EQ(last_format().pixel_format, testing::get<0>(GetParam())); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { | 378 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { |
| 377 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 379 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
| 378 PIXEL_FORMAT_I420, | 380 PIXEL_FORMAT_I420, |
| 379 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 381 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, |
| 380 30.0); | 382 30.0); |
| 381 ASSERT_TRUE(device); | 383 ASSERT_TRUE(device); |
| 382 | 384 |
| 383 VideoCaptureParams capture_params; | 385 VideoCaptureParams capture_params; |
| 384 capture_params.requested_format.frame_size.SetSize(640, 480); | 386 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 385 capture_params.requested_format.frame_rate = 30.0; | 387 capture_params.requested_format.frame_rate = 30.0; |
| 388 EXPECT_CALL(*client_, OnStarted()); |
| 386 device->AllocateAndStart(capture_params, std::move(client_)); | 389 device->AllocateAndStart(capture_params, std::move(client_)); |
| 387 | 390 |
| 388 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( | 391 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( |
| 389 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities, | 392 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities, |
| 390 image_capture_client_), | 393 image_capture_client_), |
| 391 base::Bind(&ImageCaptureClient::OnGetPhotoCapabilitiesFailure, | 394 base::Bind(&ImageCaptureClient::OnGetPhotoCapabilitiesFailure, |
| 392 image_capture_client_)); | 395 image_capture_client_)); |
| 393 | 396 |
| 394 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) | 397 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) |
| 395 .Times(1); | 398 .Times(1); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { | 490 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
| 488 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 491 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
| 489 PIXEL_FORMAT_I420, | 492 PIXEL_FORMAT_I420, |
| 490 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 493 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, |
| 491 30.0); | 494 30.0); |
| 492 ASSERT_TRUE(device); | 495 ASSERT_TRUE(device); |
| 493 | 496 |
| 494 VideoCaptureParams capture_params; | 497 VideoCaptureParams capture_params; |
| 495 capture_params.requested_format.frame_size.SetSize(640, 480); | 498 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 496 capture_params.requested_format.frame_rate = 30.0; | 499 capture_params.requested_format.frame_rate = 30.0; |
| 500 EXPECT_CALL(*client_, OnStarted()); |
| 497 device->AllocateAndStart(capture_params, std::move(client_)); | 501 device->AllocateAndStart(capture_params, std::move(client_)); |
| 498 | 502 |
| 499 VideoCaptureDevice::TakePhotoCallback scoped_callback( | 503 VideoCaptureDevice::TakePhotoCallback scoped_callback( |
| 500 base::Bind(&ImageCaptureClient::DoOnPhotoTaken, image_capture_client_), | 504 base::Bind(&ImageCaptureClient::DoOnPhotoTaken, image_capture_client_), |
| 501 base::Bind(&ImageCaptureClient::OnTakePhotoFailure, | 505 base::Bind(&ImageCaptureClient::OnTakePhotoFailure, |
| 502 image_capture_client_)); | 506 image_capture_client_)); |
| 503 | 507 |
| 504 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); | 508 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); |
| 505 device->TakePhoto(std::move(scoped_callback)); | 509 device->TakePhoto(std::move(scoped_callback)); |
| 506 | 510 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 546 |
| 543 std::unique_ptr<VideoCaptureDevice> device = | 547 std::unique_ptr<VideoCaptureDevice> device = |
| 544 video_capture_device_factory_->CreateDevice(descriptors_iterator); | 548 video_capture_device_factory_->CreateDevice(descriptors_iterator); |
| 545 ASSERT_TRUE(device); | 549 ASSERT_TRUE(device); |
| 546 | 550 |
| 547 VideoCaptureParams capture_params; | 551 VideoCaptureParams capture_params; |
| 548 capture_params.requested_format.frame_size.SetSize(1280, 720); | 552 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 549 capture_params.requested_format.frame_rate = GetParam().expected_fps; | 553 capture_params.requested_format.frame_rate = GetParam().expected_fps; |
| 550 capture_params.requested_format.pixel_format = | 554 capture_params.requested_format.pixel_format = |
| 551 GetParam().expected_pixel_formats[device_index]; | 555 GetParam().expected_pixel_formats[device_index]; |
| 552 device->AllocateAndStart(capture_params, CreateClient()); | 556 auto client = CreateClient(); |
| 557 EXPECT_CALL(*client, OnStarted()); |
| 558 device->AllocateAndStart(capture_params, std::move(client)); |
| 553 WaitForCapturedFrame(); | 559 WaitForCapturedFrame(); |
| 554 EXPECT_EQ(1280, last_format().frame_size.width()); | 560 EXPECT_EQ(1280, last_format().frame_size.width()); |
| 555 EXPECT_EQ(720, last_format().frame_size.height()); | 561 EXPECT_EQ(720, last_format().frame_size.height()); |
| 556 EXPECT_EQ(GetParam().expected_fps, last_format().frame_rate); | 562 EXPECT_EQ(GetParam().expected_fps, last_format().frame_rate); |
| 557 EXPECT_EQ(GetParam().expected_pixel_formats[device_index], | 563 EXPECT_EQ(GetParam().expected_pixel_formats[device_index], |
| 558 last_format().pixel_format); | 564 last_format().pixel_format); |
| 559 device->StopAndDeAllocate(); | 565 device->StopAndDeAllocate(); |
| 560 | 566 |
| 561 device_index++; | 567 device_index++; |
| 562 } | 568 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 583 20, | 589 20, |
| 584 3u, | 590 3u, |
| 585 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, | 591 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, |
| 586 CommandLineTestData{ | 592 CommandLineTestData{ |
| 587 "device-count=3,ownership=client", | 593 "device-count=3,ownership=client", |
| 588 20, | 594 20, |
| 589 3u, | 595 3u, |
| 590 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, | 596 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, |
| 591 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); | 597 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); |
| 592 }; // namespace media | 598 }; // namespace media |
| OLD | NEW |