| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_client.h" | 5 #include "media/capture/video/video_capture_device_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "content/browser/renderer_host/media/video_capture_controller.h" | 18 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 19 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" | |
| 20 #include "content/browser/renderer_host/media/video_frame_receiver_on_io_thread.
h" | |
| 21 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "media/base/limits.h" | 20 #include "media/base/limits.h" |
| 23 #include "media/capture/video/video_capture_buffer_pool_impl.h" | 21 #include "media/capture/video/video_capture_buffer_pool.h" |
| 24 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" | |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 24 |
| 28 using ::testing::_; | 25 using ::testing::_; |
| 29 using ::testing::Mock; | 26 using ::testing::Mock; |
| 30 using ::testing::InSequence; | 27 using ::testing::InSequence; |
| 31 using ::testing::SaveArg; | 28 using ::testing::SaveArg; |
| 32 | 29 |
| 33 namespace content { | 30 namespace content { |
| 34 | 31 |
| 35 namespace { | 32 namespace { |
| 36 | 33 |
| 37 class MockVideoCaptureController : public VideoCaptureController { | 34 class MockVideoCaptureController : public VideoCaptureController { |
| 38 public: | 35 public: |
| 39 explicit MockVideoCaptureController() : VideoCaptureController() {} | 36 explicit MockVideoCaptureController(int max_buffers) |
| 37 : VideoCaptureController(max_buffers) {} |
| 40 ~MockVideoCaptureController() override {} | 38 ~MockVideoCaptureController() override {} |
| 41 | 39 |
| 42 MOCK_METHOD1(MockOnIncomingCapturedVideoFrame, void(const gfx::Size&)); | 40 MOCK_METHOD1(MockOnIncomingCapturedVideoFrame, void(const gfx::Size&)); |
| 43 MOCK_METHOD0(OnError, void()); | 41 MOCK_METHOD0(OnError, void()); |
| 44 MOCK_METHOD1(OnLog, void(const std::string& message)); | 42 MOCK_METHOD1(OnLog, void(const std::string& message)); |
| 45 MOCK_METHOD1(OnBufferDestroyed, void(int buffer_id_to_drop)); | 43 MOCK_METHOD1(OnBufferDestroyed, void(int buffer_id_to_drop)); |
| 46 | 44 |
| 47 void OnIncomingCapturedVideoFrame( | 45 void OnIncomingCapturedVideoFrame( |
| 48 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, | 46 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, |
| 49 scoped_refptr<media::VideoFrame> frame) override { | 47 scoped_refptr<media::VideoFrame> frame) override { |
| 50 MockOnIncomingCapturedVideoFrame(frame->coded_size()); | 48 MockOnIncomingCapturedVideoFrame(frame->coded_size()); |
| 51 } | 49 } |
| 52 }; | 50 }; |
| 53 | 51 |
| 54 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateGpuJpegDecoder( | |
| 55 const media::VideoCaptureJpegDecoder::DecodeDoneCB& decode_done_cb) { | |
| 56 return base::MakeUnique<content::VideoCaptureGpuJpegDecoder>(decode_done_cb); | |
| 57 } | |
| 58 | |
| 59 // Note that this test does not exercise the class VideoCaptureDeviceClient | 52 // Note that this test does not exercise the class VideoCaptureDeviceClient |
| 60 // in isolation. The "unit under test" is an instance of | 53 // in isolation. The "unit under test" is an instance of |
| 61 // VideoCaptureDeviceClient with some context that is specific to | 54 // VideoCaptureDeviceClient with some context that is specific to |
| 62 // renderer_host/media, and therefore this test must live here and not in | 55 // renderer_host/media, and therefore this test must live here and not in |
| 63 // media/capture/video. | 56 // media/capture/video. |
| 64 class VideoCaptureDeviceClientTest : public ::testing::Test { | 57 class VideoCaptureDeviceClientTest : public ::testing::Test { |
| 65 public: | 58 public: |
| 66 VideoCaptureDeviceClientTest() | 59 VideoCaptureDeviceClientTest() |
| 67 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 60 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 68 scoped_refptr<media::VideoCaptureBufferPoolImpl> buffer_pool( | 61 controller_(new MockVideoCaptureController(1)), |
| 69 new media::VideoCaptureBufferPoolImpl( | 62 device_client_(controller_->NewDeviceClient()) {} |
| 70 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), | |
| 71 1)); | |
| 72 controller_ = base::MakeUnique<MockVideoCaptureController>(); | |
| 73 device_client_ = base::MakeUnique<media::VideoCaptureDeviceClient>( | |
| 74 base::MakeUnique<VideoFrameReceiverOnIOThread>( | |
| 75 controller_->GetWeakPtrForIOThread()), | |
| 76 buffer_pool, | |
| 77 base::Bind( | |
| 78 &CreateGpuJpegDecoder, | |
| 79 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame, | |
| 80 controller_->GetWeakPtrForIOThread()))); | |
| 81 } | |
| 82 ~VideoCaptureDeviceClientTest() override {} | 63 ~VideoCaptureDeviceClientTest() override {} |
| 83 | 64 |
| 84 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 65 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
| 85 | 66 |
| 86 protected: | 67 protected: |
| 87 const content::TestBrowserThreadBundle thread_bundle_; | 68 const content::TestBrowserThreadBundle thread_bundle_; |
| 88 std::unique_ptr<MockVideoCaptureController> controller_; | 69 const std::unique_ptr<MockVideoCaptureController> controller_; |
| 89 std::unique_ptr<media::VideoCaptureDeviceClient> device_client_; | 70 const std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; |
| 90 | 71 |
| 91 private: | 72 private: |
| 92 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClientTest); | 73 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClientTest); |
| 93 }; | 74 }; |
| 94 | 75 |
| 95 } // namespace | 76 } // namespace |
| 96 | 77 |
| 97 // A small test for reference and to verify VideoCaptureDeviceClient is | 78 // A small test for reference and to verify VideoCaptureDeviceClient is |
| 98 // minimally functional. | 79 // minimally functional. |
| 99 TEST_F(VideoCaptureDeviceClientTest, Minimal) { | 80 TEST_F(VideoCaptureDeviceClientTest, Minimal) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 230 |
| 250 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width()); | 231 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width()); |
| 251 EXPECT_EQ(coded_size.height(), | 232 EXPECT_EQ(coded_size.height(), |
| 252 size_and_rotation.output_resolution.height()); | 233 size_and_rotation.output_resolution.height()); |
| 253 | 234 |
| 254 Mock::VerifyAndClearExpectations(controller_.get()); | 235 Mock::VerifyAndClearExpectations(controller_.get()); |
| 255 } | 236 } |
| 256 } | 237 } |
| 257 | 238 |
| 258 } // namespace content | 239 } // namespace content |
| OLD | NEW |