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