| 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 "media/capture/video/video_capture_device.h" | 5 #include "media/capture/video/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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 class MockVideoCaptureClient : public VideoCaptureDevice::Client { | 94 class MockVideoCaptureClient : public VideoCaptureDevice::Client { |
| 95 public: | 95 public: |
| 96 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); | 96 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); |
| 97 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); | 97 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
| 98 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); | 98 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); |
| 99 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); | 99 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); |
| 100 MOCK_METHOD2(OnError, | 100 MOCK_METHOD2(OnError, |
| 101 void(const tracked_objects::Location& from_here, | 101 void(const tracked_objects::Location& from_here, |
| 102 const std::string& reason)); | 102 const std::string& reason)); |
| 103 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); | 103 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); |
| 104 MOCK_METHOD0(OnStarted, void(void)); |
| 104 | 105 |
| 105 explicit MockVideoCaptureClient( | 106 explicit MockVideoCaptureClient( |
| 106 base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 107 base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
| 107 : main_thread_(base::ThreadTaskRunnerHandle::Get()), frame_cb_(frame_cb) { | 108 : main_thread_(base::ThreadTaskRunnerHandle::Get()), frame_cb_(frame_cb) { |
| 108 ON_CALL(*this, OnError(_, _)).WillByDefault(Invoke(DumpError)); | 109 ON_CALL(*this, OnError(_, _)).WillByDefault(Invoke(DumpError)); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void OnIncomingCapturedData(const uint8_t* data, | 112 void OnIncomingCapturedData(const uint8_t* data, |
| 112 int length, | 113 int length, |
| 113 const VideoCaptureFormat& format, | 114 const VideoCaptureFormat& format, |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 return; | 399 return; |
| 399 const int width = size.width(); | 400 const int width = size.width(); |
| 400 const int height = size.height(); | 401 const int height = size.height(); |
| 401 | 402 |
| 402 std::unique_ptr<VideoCaptureDevice> device( | 403 std::unique_ptr<VideoCaptureDevice> device( |
| 403 video_capture_device_factory_->CreateDevice( | 404 video_capture_device_factory_->CreateDevice( |
| 404 device_descriptors_->front())); | 405 device_descriptors_->front())); |
| 405 ASSERT_TRUE(device); | 406 ASSERT_TRUE(device); |
| 406 | 407 |
| 407 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 408 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 409 EXPECT_CALL(*video_capture_client_, OnStarted()); |
| 408 | 410 |
| 409 VideoCaptureParams capture_params; | 411 VideoCaptureParams capture_params; |
| 410 capture_params.requested_format.frame_size.SetSize(width, height); | 412 capture_params.requested_format.frame_size.SetSize(width, height); |
| 411 capture_params.requested_format.frame_rate = 30.0f; | 413 capture_params.requested_format.frame_rate = 30.0f; |
| 412 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 414 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 413 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 415 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 414 | 416 |
| 415 WaitForCapturedFrame(); | 417 WaitForCapturedFrame(); |
| 416 EXPECT_EQ(last_format().frame_size.width(), width); | 418 EXPECT_EQ(last_format().frame_size.width(), width); |
| 417 EXPECT_EQ(last_format().frame_size.height(), height); | 419 EXPECT_EQ(last_format().frame_size.height(), height); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 432 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 434 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 433 if (!EnumerateAndFindUsableDevices()) | 435 if (!EnumerateAndFindUsableDevices()) |
| 434 return; | 436 return; |
| 435 | 437 |
| 436 std::unique_ptr<VideoCaptureDevice> device( | 438 std::unique_ptr<VideoCaptureDevice> device( |
| 437 video_capture_device_factory_->CreateDevice( | 439 video_capture_device_factory_->CreateDevice( |
| 438 device_descriptors_->front())); | 440 device_descriptors_->front())); |
| 439 ASSERT_TRUE(device); | 441 ASSERT_TRUE(device); |
| 440 | 442 |
| 441 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 443 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 444 EXPECT_CALL(*video_capture_client_, OnStarted()); |
| 442 | 445 |
| 443 const gfx::Size input_size(640, 480); | 446 const gfx::Size input_size(640, 480); |
| 444 VideoCaptureParams capture_params; | 447 VideoCaptureParams capture_params; |
| 445 capture_params.requested_format.frame_size.SetSize(637, 472); | 448 capture_params.requested_format.frame_size.SetSize(637, 472); |
| 446 capture_params.requested_format.frame_rate = 35; | 449 capture_params.requested_format.frame_rate = 35; |
| 447 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 450 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 448 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 451 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 449 WaitForCapturedFrame(); | 452 WaitForCapturedFrame(); |
| 450 device->StopAndDeAllocate(); | 453 device->StopAndDeAllocate(); |
| 451 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); | 454 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 VLOG(1) << "Skipped on Win10: http://crbug.com/570604, current: " | 515 VLOG(1) << "Skipped on Win10: http://crbug.com/570604, current: " |
| 513 << static_cast<int>(version); | 516 << static_cast<int>(version); |
| 514 return; | 517 return; |
| 515 } | 518 } |
| 516 #endif | 519 #endif |
| 517 std::unique_ptr<VideoCaptureDevice> device( | 520 std::unique_ptr<VideoCaptureDevice> device( |
| 518 video_capture_device_factory_->CreateDevice(*device_descriptor)); | 521 video_capture_device_factory_->CreateDevice(*device_descriptor)); |
| 519 ASSERT_TRUE(device); | 522 ASSERT_TRUE(device); |
| 520 | 523 |
| 521 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 524 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 525 EXPECT_CALL(*video_capture_client_, OnStarted()); |
| 522 | 526 |
| 523 VideoCaptureParams capture_params; | 527 VideoCaptureParams capture_params; |
| 524 capture_params.requested_format.frame_size.SetSize(1280, 720); | 528 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 525 capture_params.requested_format.frame_rate = 30; | 529 capture_params.requested_format.frame_rate = 30; |
| 526 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 530 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; |
| 527 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 531 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 528 | 532 |
| 529 WaitForCapturedFrame(); | 533 WaitForCapturedFrame(); |
| 530 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | 534 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 |
| 531 // @ 30 fps, so we don't care about the exact resolution we get. | 535 // @ 30 fps, so we don't care about the exact resolution we get. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 558 return; | 562 return; |
| 559 } | 563 } |
| 560 #endif | 564 #endif |
| 561 | 565 |
| 562 std::unique_ptr<VideoCaptureDevice> device( | 566 std::unique_ptr<VideoCaptureDevice> device( |
| 563 video_capture_device_factory_->CreateDevice( | 567 video_capture_device_factory_->CreateDevice( |
| 564 device_descriptors_->front())); | 568 device_descriptors_->front())); |
| 565 ASSERT_TRUE(device); | 569 ASSERT_TRUE(device); |
| 566 | 570 |
| 567 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 571 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 572 EXPECT_CALL(*video_capture_client_, OnStarted()); |
| 568 | 573 |
| 569 VideoCaptureParams capture_params; | 574 VideoCaptureParams capture_params; |
| 570 capture_params.requested_format.frame_size.SetSize(320, 240); | 575 capture_params.requested_format.frame_size.SetSize(320, 240); |
| 571 capture_params.requested_format.frame_rate = 30; | 576 capture_params.requested_format.frame_rate = 30; |
| 572 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 577 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 573 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 578 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 574 | 579 |
| 575 VideoCaptureDevice::TakePhotoCallback scoped_callback( | 580 VideoCaptureDevice::TakePhotoCallback scoped_callback( |
| 576 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken, | 581 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken, |
| 577 image_capture_client_), | 582 image_capture_client_), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 602 return; | 607 return; |
| 603 } | 608 } |
| 604 #endif | 609 #endif |
| 605 | 610 |
| 606 std::unique_ptr<VideoCaptureDevice> device( | 611 std::unique_ptr<VideoCaptureDevice> device( |
| 607 video_capture_device_factory_->CreateDevice( | 612 video_capture_device_factory_->CreateDevice( |
| 608 device_descriptors_->front())); | 613 device_descriptors_->front())); |
| 609 ASSERT_TRUE(device); | 614 ASSERT_TRUE(device); |
| 610 | 615 |
| 611 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); | 616 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); |
| 617 EXPECT_CALL(*video_capture_client_, OnStarted()); |
| 612 | 618 |
| 613 VideoCaptureParams capture_params; | 619 VideoCaptureParams capture_params; |
| 614 capture_params.requested_format.frame_size.SetSize(320, 240); | 620 capture_params.requested_format.frame_size.SetSize(320, 240); |
| 615 capture_params.requested_format.frame_rate = 30; | 621 capture_params.requested_format.frame_rate = 30; |
| 616 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 622 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 617 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); | 623 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); |
| 618 | 624 |
| 619 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( | 625 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( |
| 620 base::Bind(&MockImageCaptureClient::DoOnGetPhotoCapabilities, | 626 base::Bind(&MockImageCaptureClient::DoOnGetPhotoCapabilities, |
| 621 image_capture_client_), | 627 image_capture_client_), |
| 622 media::BindToCurrentLoop( | 628 media::BindToCurrentLoop( |
| 623 base::Bind(&MockImageCaptureClient::OnGetPhotoCapabilitiesFailure, | 629 base::Bind(&MockImageCaptureClient::OnGetPhotoCapabilitiesFailure, |
| 624 image_capture_client_))); | 630 image_capture_client_))); |
| 625 | 631 |
| 626 base::RunLoop run_loop; | 632 base::RunLoop run_loop; |
| 627 base::Closure quit_closure = media::BindToCurrentLoop(run_loop.QuitClosure()); | 633 base::Closure quit_closure = media::BindToCurrentLoop(run_loop.QuitClosure()); |
| 628 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) | 634 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) |
| 629 .Times(1) | 635 .Times(1) |
| 630 .WillOnce(RunClosure(quit_closure)); | 636 .WillOnce(RunClosure(quit_closure)); |
| 631 | 637 |
| 632 device->GetPhotoCapabilities(std::move(scoped_get_callback)); | 638 device->GetPhotoCapabilities(std::move(scoped_get_callback)); |
| 633 run_loop.Run(); | 639 run_loop.Run(); |
| 634 | 640 |
| 635 ASSERT_TRUE(image_capture_client_->capabilities()); | 641 ASSERT_TRUE(image_capture_client_->capabilities()); |
| 636 | 642 |
| 637 device->StopAndDeAllocate(); | 643 device->StopAndDeAllocate(); |
| 638 } | 644 } |
| 639 | 645 |
| 640 }; // namespace media | 646 }; // namespace media |
| OLD | NEW |