| 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( |
| 127 VideoCaptureController* entry, |
| 128 VideoCaptureController* controller, |
| 129 const media::VideoCaptureParams& params, |
| 130 BuildableDeviceCallbacks* callbacks, |
| 131 std::unique_ptr<Ownership> context_reference) override {} |
| 132 void ReleaseDeviceAsync( |
| 133 VideoCaptureController* controller, |
| 134 std::unique_ptr<Ownership> context_reference) override {} |
| 135 bool IsDeviceAlive() const override { return false; } |
| 136 void GetPhotoCapabilities( |
| 137 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) |
| 138 const override {} |
| 139 void SetPhotoOptions( |
| 140 media::mojom::PhotoSettingsPtr settings, |
| 141 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) override {} |
| 142 void TakePhoto( |
| 143 media::VideoCaptureDevice::TakePhotoCallback callback) override {} |
| 144 void MaybeSuspendDevice() override {} |
| 145 void ResumeDevice() override {} |
| 146 void RequestRefreshFrame() override {} |
| 147 void SetDesktopCaptureWindowIdAsync( |
| 148 gfx::NativeViewId window_id, |
| 149 std::unique_ptr<Ownership> context_reference) override {} |
| 150 }; |
| 151 |
| 124 // Test fixture for testing a unit consisting of an instance of | 152 // Test fixture for testing a unit consisting of an instance of |
| 125 // VideoCaptureController connected to an instance of VideoCaptureDeviceClient, | 153 // VideoCaptureController connected to an instance of VideoCaptureDeviceClient, |
| 126 // an instance of VideoCaptureBufferPoolImpl, as well as related threading glue | 154 // an instance of VideoCaptureBufferPoolImpl, as well as related threading glue |
| 127 // that replicates how it is used in production. | 155 // that replicates how it is used in production. |
| 128 class VideoCaptureControllerTest | 156 class VideoCaptureControllerTest |
| 129 : public testing::Test, | 157 : public testing::Test, |
| 130 public testing::WithParamInterface<media::VideoPixelFormat> { | 158 public testing::WithParamInterface<media::VideoPixelFormat> { |
| 131 public: | 159 public: |
| 132 VideoCaptureControllerTest() | 160 VideoCaptureControllerTest() |
| 133 : arbitrary_format_(gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420), | 161 : arbitrary_format_(gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420), |
| 134 arbitrary_route_id_(0x99), | 162 arbitrary_route_id_(0x99), |
| 135 arbitrary_session_id_(100) {} | 163 arbitrary_session_id_(100) {} |
| 136 ~VideoCaptureControllerTest() override {} | 164 ~VideoCaptureControllerTest() override {} |
| 137 | 165 |
| 138 protected: | 166 protected: |
| 139 static const int kPoolSize = 3; | 167 static const int kPoolSize = 3; |
| 140 | 168 |
| 141 void SetUp() override { | 169 void SetUp() override { |
| 142 controller_.reset(new VideoCaptureController()); | 170 const std::string arbitrary_device_id = "arbitrary_device_id"; |
| 171 const MediaStreamType arbitrary_stream_type = |
| 172 content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| 173 const media::VideoCaptureParams arbitrary_params; |
| 174 auto buildable_device = base::MakeUnique<MockBuildableVideoCaptureDevice>(); |
| 175 controller_ = new VideoCaptureController( |
| 176 arbitrary_device_id, arbitrary_stream_type, arbitrary_params, |
| 177 std::move(buildable_device)); |
| 143 InitializeNewDeviceClientAndBufferPoolInstances(); | 178 InitializeNewDeviceClientAndBufferPoolInstances(); |
| 144 auto consumer_feedback_observer = | 179 auto consumer_feedback_observer = |
| 145 base::MakeUnique<MockConsumerFeedbackObserver>(); | 180 base::MakeUnique<MockConsumerFeedbackObserver>(); |
| 146 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); | 181 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); |
| 147 controller_->SetConsumerFeedbackObserver( | 182 controller_->SetConsumerFeedbackObserver( |
| 148 std::move(consumer_feedback_observer)); | 183 std::move(consumer_feedback_observer)); |
| 149 client_a_.reset( | 184 client_a_.reset( |
| 150 new MockVideoCaptureControllerEventHandler(controller_.get())); | 185 new MockVideoCaptureControllerEventHandler(controller_.get())); |
| 151 client_b_.reset( | 186 client_b_.reset( |
| 152 new MockVideoCaptureControllerEventHandler(controller_.get())); | 187 new MockVideoCaptureControllerEventHandler(controller_.get())); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 179 media::VideoFrame::AllocationSize(stub_frame->format(), | 214 media::VideoFrame::AllocationSize(stub_frame->format(), |
| 180 stub_frame->coded_size()), | 215 stub_frame->coded_size()), |
| 181 format, rotation, base::TimeTicks(), base::TimeDelta(), | 216 format, rotation, base::TimeTicks(), base::TimeDelta(), |
| 182 frame_feedback_id); | 217 frame_feedback_id); |
| 183 } | 218 } |
| 184 | 219 |
| 185 TestBrowserThreadBundle bundle_; | 220 TestBrowserThreadBundle bundle_; |
| 186 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; | 221 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; |
| 187 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 222 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
| 188 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 223 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
| 189 std::unique_ptr<VideoCaptureController> controller_; | 224 scoped_refptr<VideoCaptureController> controller_; |
| 190 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; | 225 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; |
| 191 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; | 226 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; |
| 192 const float arbitrary_frame_rate_ = 10.0f; | 227 const float arbitrary_frame_rate_ = 10.0f; |
| 193 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks(); | 228 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks(); |
| 194 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta(); | 229 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta(); |
| 195 const media::VideoCaptureFormat arbitrary_format_; | 230 const media::VideoCaptureFormat arbitrary_format_; |
| 196 const VideoCaptureControllerID arbitrary_route_id_; | 231 const VideoCaptureControllerID arbitrary_route_id_; |
| 197 const media::VideoCaptureSessionId arbitrary_session_id_; | 232 const media::VideoCaptureSessionId arbitrary_session_id_; |
| 198 | 233 |
| 199 private: | 234 private: |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 // buffer is expected to stay alive. | 833 // buffer is expected to stay alive. |
| 799 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, first_buffer_id)).Times(0); | 834 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, first_buffer_id)).Times(0); |
| 800 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, second_buffer_id)).Times(0); | 835 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, second_buffer_id)).Times(0); |
| 801 controller_->ReturnBuffer(arbitrary_route_id_, client_a_.get(), | 836 controller_->ReturnBuffer(arbitrary_route_id_, client_a_.get(), |
| 802 second_buffer_id, arbitrary_utilization); | 837 second_buffer_id, arbitrary_utilization); |
| 803 base::RunLoop().RunUntilIdle(); | 838 base::RunLoop().RunUntilIdle(); |
| 804 Mock::VerifyAndClearExpectations(client_a_.get()); | 839 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 805 } | 840 } |
| 806 | 841 |
| 807 } // namespace content | 842 } // namespace content |
| OLD | NEW |