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 "content/browser/renderer_host/media/video_capture_controller.h" | 5 #include "content/browser/renderer_host/media/video_capture_controller.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 bool enable_auto_return_buffer_on_buffer_ready_ = true; | 114 bool enable_auto_return_buffer_on_buffer_ready_ = true; |
115 }; | 115 }; |
116 | 116 |
117 class MockConsumerFeedbackObserver | 117 class MockConsumerFeedbackObserver |
118 : public media::VideoFrameConsumerFeedbackObserver { | 118 : public media::VideoFrameConsumerFeedbackObserver { |
119 public: | 119 public: |
120 MOCK_METHOD2(OnUtilizationReport, | 120 MOCK_METHOD2(OnUtilizationReport, |
121 void(int frame_feedback_id, double utilization)); | 121 void(int frame_feedback_id, double utilization)); |
122 }; | 122 }; |
123 | 123 |
| 124 class MockBuildableVideoCaptureDevice : public BuildableVideoCaptureDevice { |
| 125 public: |
| 126 void CreateAndStartDeviceAsync(VideoCaptureController* controller, |
| 127 const media::VideoCaptureParams& params, |
| 128 BuildableDeviceCallbacks* callbacks, |
| 129 base::OnceClosure done_cb) override {} |
| 130 void ReleaseDeviceAsync(VideoCaptureController* controller, |
| 131 base::OnceClosure done_cb) override {} |
| 132 bool IsDeviceAlive() const override { return false; } |
| 133 void GetPhotoCapabilities( |
| 134 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) |
| 135 const override {} |
| 136 void SetPhotoOptions( |
| 137 media::mojom::PhotoSettingsPtr settings, |
| 138 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) override {} |
| 139 void TakePhoto( |
| 140 media::VideoCaptureDevice::TakePhotoCallback callback) override {} |
| 141 void MaybeSuspendDevice() override {} |
| 142 void ResumeDevice() override {} |
| 143 void RequestRefreshFrame() override {} |
| 144 void SetDesktopCaptureWindowIdAsync(gfx::NativeViewId window_id, |
| 145 base::OnceClosure done_cb) override {} |
| 146 }; |
| 147 |
124 // Test fixture for testing a unit consisting of an instance of | 148 // Test fixture for testing a unit consisting of an instance of |
125 // VideoCaptureController connected to an instance of VideoCaptureDeviceClient, | 149 // VideoCaptureController connected to an instance of VideoCaptureDeviceClient, |
126 // an instance of VideoCaptureBufferPoolImpl, as well as related threading glue | 150 // an instance of VideoCaptureBufferPoolImpl, as well as related threading glue |
127 // that replicates how it is used in production. | 151 // that replicates how it is used in production. |
128 class VideoCaptureControllerTest | 152 class VideoCaptureControllerTest |
129 : public testing::Test, | 153 : public testing::Test, |
130 public testing::WithParamInterface<media::VideoPixelFormat> { | 154 public testing::WithParamInterface<media::VideoPixelFormat> { |
131 public: | 155 public: |
132 VideoCaptureControllerTest() | 156 VideoCaptureControllerTest() |
133 : arbitrary_format_(gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420), | 157 : arbitrary_format_(gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420), |
134 arbitrary_route_id_(0x99), | 158 arbitrary_route_id_(0x99), |
135 arbitrary_session_id_(100) {} | 159 arbitrary_session_id_(100) {} |
136 ~VideoCaptureControllerTest() override {} | 160 ~VideoCaptureControllerTest() override {} |
137 | 161 |
138 protected: | 162 protected: |
139 static const int kPoolSize = 3; | 163 static const int kPoolSize = 3; |
140 | 164 |
141 void SetUp() override { | 165 void SetUp() override { |
142 controller_.reset(new VideoCaptureController()); | 166 const std::string arbitrary_device_id = "arbitrary_device_id"; |
| 167 const MediaStreamType arbitrary_stream_type = |
| 168 content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| 169 const media::VideoCaptureParams arbitrary_params; |
| 170 auto buildable_device = base::MakeUnique<MockBuildableVideoCaptureDevice>(); |
| 171 controller_ = new VideoCaptureController( |
| 172 arbitrary_device_id, arbitrary_stream_type, arbitrary_params, |
| 173 std::move(buildable_device)); |
143 InitializeNewDeviceClientAndBufferPoolInstances(); | 174 InitializeNewDeviceClientAndBufferPoolInstances(); |
144 auto consumer_feedback_observer = | 175 auto consumer_feedback_observer = |
145 base::MakeUnique<MockConsumerFeedbackObserver>(); | 176 base::MakeUnique<MockConsumerFeedbackObserver>(); |
146 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); | 177 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); |
147 controller_->SetConsumerFeedbackObserver( | 178 controller_->SetConsumerFeedbackObserver( |
148 std::move(consumer_feedback_observer)); | 179 std::move(consumer_feedback_observer)); |
149 client_a_.reset( | 180 client_a_.reset( |
150 new MockVideoCaptureControllerEventHandler(controller_.get())); | 181 new MockVideoCaptureControllerEventHandler(controller_.get())); |
151 client_b_.reset( | 182 client_b_.reset( |
152 new MockVideoCaptureControllerEventHandler(controller_.get())); | 183 new MockVideoCaptureControllerEventHandler(controller_.get())); |
(...skipping 26 matching lines...) Expand all Loading... |
179 media::VideoFrame::AllocationSize(stub_frame->format(), | 210 media::VideoFrame::AllocationSize(stub_frame->format(), |
180 stub_frame->coded_size()), | 211 stub_frame->coded_size()), |
181 format, rotation, base::TimeTicks(), base::TimeDelta(), | 212 format, rotation, base::TimeTicks(), base::TimeDelta(), |
182 frame_feedback_id); | 213 frame_feedback_id); |
183 } | 214 } |
184 | 215 |
185 TestBrowserThreadBundle bundle_; | 216 TestBrowserThreadBundle bundle_; |
186 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; | 217 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; |
187 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 218 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
188 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 219 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
189 std::unique_ptr<VideoCaptureController> controller_; | 220 scoped_refptr<VideoCaptureController> controller_; |
190 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; | 221 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; |
191 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; | 222 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; |
192 const float arbitrary_frame_rate_ = 10.0f; | 223 const float arbitrary_frame_rate_ = 10.0f; |
193 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks(); | 224 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks(); |
194 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta(); | 225 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta(); |
195 const media::VideoCaptureFormat arbitrary_format_; | 226 const media::VideoCaptureFormat arbitrary_format_; |
196 const VideoCaptureControllerID arbitrary_route_id_; | 227 const VideoCaptureControllerID arbitrary_route_id_; |
197 const media::VideoCaptureSessionId arbitrary_session_id_; | 228 const media::VideoCaptureSessionId arbitrary_session_id_; |
198 | 229 |
199 private: | 230 private: |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 EXPECT_CALL(*client_b_, OnStarted(_)); | 860 EXPECT_CALL(*client_b_, OnStarted(_)); |
830 device_client_->OnStarted(); | 861 device_client_->OnStarted(); |
831 | 862 |
832 // VideoCaptureController will take care of the OnStarted event for the | 863 // VideoCaptureController will take care of the OnStarted event for the |
833 // clients who join later. | 864 // clients who join later. |
834 EXPECT_CALL(*client_a_, OnStarted(_)); | 865 EXPECT_CALL(*client_a_, OnStarted(_)); |
835 controller_->AddClient(client_a_route_2, client_a_.get(), 200, session_200); | 866 controller_->AddClient(client_a_route_2, client_a_.get(), 200, session_200); |
836 } | 867 } |
837 } | 868 } |
838 } // namespace content | 869 } // namespace content |
OLD | NEW |