Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller_unittest.cc

Issue 2738763002: [Mojo Video Capture] Introduce abstraction BuildableVideoCaptureDevice (Closed)
Patch Set: Use base::OnceClosure for ownership, use DeviceBuildContext Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 DeviceBuildContext context) override {}
129 void ReleaseDeviceAsync(VideoCaptureController* controller,
130 base::OnceClosure done_cb) override {}
131 bool IsDeviceAlive() const override { return false; }
132 void GetPhotoCapabilities(
133 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback)
134 const override {}
135 void SetPhotoOptions(
136 media::mojom::PhotoSettingsPtr settings,
137 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) override {}
138 void TakePhoto(
139 media::VideoCaptureDevice::TakePhotoCallback callback) override {}
140 void MaybeSuspendDevice() override {}
141 void ResumeDevice() override {}
142 void RequestRefreshFrame() override {}
143 void SetDesktopCaptureWindowIdAsync(gfx::NativeViewId window_id,
144 base::OnceClosure done_cb) override {}
145 };
146
124 // Test fixture for testing a unit consisting of an instance of 147 // Test fixture for testing a unit consisting of an instance of
125 // VideoCaptureController connected to an instance of VideoCaptureDeviceClient, 148 // VideoCaptureController connected to an instance of VideoCaptureDeviceClient,
126 // an instance of VideoCaptureBufferPoolImpl, as well as related threading glue 149 // an instance of VideoCaptureBufferPoolImpl, as well as related threading glue
127 // that replicates how it is used in production. 150 // that replicates how it is used in production.
128 class VideoCaptureControllerTest 151 class VideoCaptureControllerTest
129 : public testing::Test, 152 : public testing::Test,
130 public testing::WithParamInterface<media::VideoPixelFormat> { 153 public testing::WithParamInterface<media::VideoPixelFormat> {
131 public: 154 public:
132 VideoCaptureControllerTest() 155 VideoCaptureControllerTest()
133 : arbitrary_format_(gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420), 156 : arbitrary_format_(gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420),
134 arbitrary_route_id_(0x99), 157 arbitrary_route_id_(0x99),
135 arbitrary_session_id_(100) {} 158 arbitrary_session_id_(100) {}
136 ~VideoCaptureControllerTest() override {} 159 ~VideoCaptureControllerTest() override {}
137 160
138 protected: 161 protected:
139 static const int kPoolSize = 3; 162 static const int kPoolSize = 3;
140 163
141 void SetUp() override { 164 void SetUp() override {
142 controller_.reset(new VideoCaptureController()); 165 const std::string arbitrary_device_id = "arbitrary_device_id";
166 const MediaStreamType arbitrary_stream_type =
167 content::MEDIA_DEVICE_VIDEO_CAPTURE;
168 const media::VideoCaptureParams arbitrary_params;
169 auto buildable_device = base::MakeUnique<MockBuildableVideoCaptureDevice>();
170 controller_ = new VideoCaptureController(
171 arbitrary_device_id, arbitrary_stream_type, arbitrary_params,
172 std::move(buildable_device));
143 InitializeNewDeviceClientAndBufferPoolInstances(); 173 InitializeNewDeviceClientAndBufferPoolInstances();
144 auto consumer_feedback_observer = 174 auto consumer_feedback_observer =
145 base::MakeUnique<MockConsumerFeedbackObserver>(); 175 base::MakeUnique<MockConsumerFeedbackObserver>();
146 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); 176 mock_consumer_feedback_observer_ = consumer_feedback_observer.get();
147 controller_->SetConsumerFeedbackObserver( 177 controller_->SetConsumerFeedbackObserver(
148 std::move(consumer_feedback_observer)); 178 std::move(consumer_feedback_observer));
149 client_a_.reset( 179 client_a_.reset(
150 new MockVideoCaptureControllerEventHandler(controller_.get())); 180 new MockVideoCaptureControllerEventHandler(controller_.get()));
151 client_b_.reset( 181 client_b_.reset(
152 new MockVideoCaptureControllerEventHandler(controller_.get())); 182 new MockVideoCaptureControllerEventHandler(controller_.get()));
(...skipping 26 matching lines...) Expand all
179 media::VideoFrame::AllocationSize(stub_frame->format(), 209 media::VideoFrame::AllocationSize(stub_frame->format(),
180 stub_frame->coded_size()), 210 stub_frame->coded_size()),
181 format, rotation, base::TimeTicks(), base::TimeDelta(), 211 format, rotation, base::TimeTicks(), base::TimeDelta(),
182 frame_feedback_id); 212 frame_feedback_id);
183 } 213 }
184 214
185 TestBrowserThreadBundle bundle_; 215 TestBrowserThreadBundle bundle_;
186 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; 216 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_;
187 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; 217 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_;
188 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; 218 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_;
189 std::unique_ptr<VideoCaptureController> controller_; 219 scoped_refptr<VideoCaptureController> controller_;
190 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; 220 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_;
191 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; 221 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_;
192 const float arbitrary_frame_rate_ = 10.0f; 222 const float arbitrary_frame_rate_ = 10.0f;
193 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks(); 223 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks();
194 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta(); 224 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta();
195 const media::VideoCaptureFormat arbitrary_format_; 225 const media::VideoCaptureFormat arbitrary_format_;
196 const VideoCaptureControllerID arbitrary_route_id_; 226 const VideoCaptureControllerID arbitrary_route_id_;
197 const media::VideoCaptureSessionId arbitrary_session_id_; 227 const media::VideoCaptureSessionId arbitrary_session_id_;
198 228
199 private: 229 private:
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 EXPECT_CALL(*client_b_, OnStarted(_)); 859 EXPECT_CALL(*client_b_, OnStarted(_));
830 device_client_->OnStarted(); 860 device_client_->OnStarted();
831 861
832 // VideoCaptureController will take care of the OnStarted event for the 862 // VideoCaptureController will take care of the OnStarted event for the
833 // clients who join later. 863 // clients who join later.
834 EXPECT_CALL(*client_a_, OnStarted(_)); 864 EXPECT_CALL(*client_a_, OnStarted(_));
835 controller_->AddClient(client_a_route_2, client_a_.get(), 200, session_200); 865 controller_->AddClient(client_a_route_2, client_a_.get(), 200, session_200);
836 } 866 }
837 } 867 }
838 } // namespace content 868 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698