OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/fake_video_capture_device.h" | 5 #include "media/capture/video/fake_video_capture_device.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 double GetBufferPoolUtilization() const override { return 0.0; } | 114 double GetBufferPoolUtilization() const override { return 0.0; } |
115 | 115 |
116 private: | 116 private: |
117 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 117 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
118 }; | 118 }; |
119 | 119 |
120 class DeviceEnumerationListener | 120 class DeviceEnumerationListener |
121 : public base::RefCounted<DeviceEnumerationListener> { | 121 : public base::RefCounted<DeviceEnumerationListener> { |
122 public: | 122 public: |
123 MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, | 123 MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, |
124 void(VideoCaptureDevice::Names* names)); | 124 void(VideoCaptureDeviceDescriptors* descriptors)); |
125 // GMock doesn't support move-only arguments, so we use this forward method. | 125 // GMock doesn't support move-only arguments, so we use this forward method. |
126 void OnEnumeratedDevicesCallback( | 126 void OnEnumeratedDevicesCallback( |
127 std::unique_ptr<VideoCaptureDevice::Names> names) { | 127 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors) { |
128 OnEnumeratedDevicesCallbackPtr(names.release()); | 128 OnEnumeratedDevicesCallbackPtr(descriptors.release()); |
129 } | 129 } |
130 | 130 |
131 private: | 131 private: |
132 friend class base::RefCounted<DeviceEnumerationListener>; | 132 friend class base::RefCounted<DeviceEnumerationListener>; |
133 virtual ~DeviceEnumerationListener() {} | 133 virtual ~DeviceEnumerationListener() {} |
134 }; | 134 }; |
135 | 135 |
136 class ImageCaptureClient : public base::RefCounted<ImageCaptureClient> { | 136 class ImageCaptureClient : public base::RefCounted<ImageCaptureClient> { |
137 public: | 137 public: |
138 // GMock doesn't support move-only arguments, so we use this forward method. | 138 // GMock doesn't support move-only arguments, so we use this forward method. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 void OnFrameCaptured(const VideoCaptureFormat& format) { | 191 void OnFrameCaptured(const VideoCaptureFormat& format) { |
192 last_format_ = format; | 192 last_format_ = format; |
193 run_loop_->QuitClosure().Run(); | 193 run_loop_->QuitClosure().Run(); |
194 } | 194 } |
195 | 195 |
196 void WaitForCapturedFrame() { | 196 void WaitForCapturedFrame() { |
197 run_loop_.reset(new base::RunLoop()); | 197 run_loop_.reset(new base::RunLoop()); |
198 run_loop_->Run(); | 198 run_loop_->Run(); |
199 } | 199 } |
200 | 200 |
201 std::unique_ptr<VideoCaptureDevice::Names> EnumerateDevices() { | 201 std::unique_ptr<VideoCaptureDeviceDescriptors> EnumerateDevices() { |
202 VideoCaptureDevice::Names* names; | 202 VideoCaptureDeviceDescriptors* descriptors; |
203 EXPECT_CALL(*device_enumeration_listener_.get(), | 203 EXPECT_CALL(*device_enumeration_listener_.get(), |
204 OnEnumeratedDevicesCallbackPtr(_)).WillOnce(SaveArg<0>(&names)); | 204 OnEnumeratedDevicesCallbackPtr(_)) |
| 205 .WillOnce(SaveArg<0>(&descriptors)); |
205 | 206 |
206 video_capture_device_factory_->EnumerateDeviceNames( | 207 video_capture_device_factory_->EnumerateDeviceDescriptors( |
207 base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback, | 208 base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback, |
208 device_enumeration_listener_)); | 209 device_enumeration_listener_)); |
209 base::RunLoop().RunUntilIdle(); | 210 base::RunLoop().RunUntilIdle(); |
210 return std::unique_ptr<VideoCaptureDevice::Names>(names); | 211 return std::unique_ptr<VideoCaptureDeviceDescriptors>(descriptors); |
211 } | 212 } |
212 | 213 |
213 const VideoCaptureFormat& last_format() const { return last_format_; } | 214 const VideoCaptureFormat& last_format() const { return last_format_; } |
214 | 215 |
215 VideoCaptureDevice::Names names_; | 216 VideoCaptureDeviceDescriptors descriptors_; |
216 const std::unique_ptr<base::MessageLoop> loop_; | 217 const std::unique_ptr<base::MessageLoop> loop_; |
217 std::unique_ptr<base::RunLoop> run_loop_; | 218 std::unique_ptr<base::RunLoop> run_loop_; |
218 std::unique_ptr<MockClient> client_; | 219 std::unique_ptr<MockClient> client_; |
219 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; | 220 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
220 const scoped_refptr<ImageCaptureClient> image_capture_client_; | 221 const scoped_refptr<ImageCaptureClient> image_capture_client_; |
221 VideoCaptureFormat last_format_; | 222 VideoCaptureFormat last_format_; |
222 const std::unique_ptr<VideoCaptureDeviceFactory> | 223 const std::unique_ptr<VideoCaptureDeviceFactory> |
223 video_capture_device_factory_; | 224 video_capture_device_factory_; |
224 }; | 225 }; |
225 | 226 |
226 class FakeVideoCaptureDeviceTest | 227 class FakeVideoCaptureDeviceTest |
227 : public FakeVideoCaptureDeviceBase, | 228 : public FakeVideoCaptureDeviceBase, |
228 public ::testing::WithParamInterface< | 229 public ::testing::WithParamInterface< |
229 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {}; | 230 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {}; |
230 | 231 |
231 struct CommandLineTestData { | 232 struct CommandLineTestData { |
232 // Command line argument | 233 // Command line argument |
233 std::string argument; | 234 std::string argument; |
234 // Expected values | 235 // Expected values |
235 float fps; | 236 float fps; |
236 }; | 237 }; |
237 | 238 |
238 class FakeVideoCaptureDeviceCommandLineTest | 239 class FakeVideoCaptureDeviceCommandLineTest |
239 : public FakeVideoCaptureDeviceBase, | 240 : public FakeVideoCaptureDeviceBase, |
240 public ::testing::WithParamInterface<CommandLineTestData> {}; | 241 public ::testing::WithParamInterface<CommandLineTestData> {}; |
241 | 242 |
242 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { | 243 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { |
243 const std::unique_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); | 244 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
244 ASSERT_FALSE(names->empty()); | 245 EnumerateDevices()); |
| 246 ASSERT_FALSE(descriptors->empty()); |
245 | 247 |
246 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( | 248 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( |
247 testing::get<0>(GetParam()), testing::get<1>(GetParam()))); | 249 testing::get<0>(GetParam()), testing::get<1>(GetParam()))); |
248 ASSERT_TRUE(device); | 250 ASSERT_TRUE(device); |
249 | 251 |
250 VideoCaptureParams capture_params; | 252 VideoCaptureParams capture_params; |
251 capture_params.requested_format.frame_size.SetSize(640, 480); | 253 capture_params.requested_format.frame_size.SetSize(640, 480); |
252 capture_params.requested_format.frame_rate = testing::get<1>(GetParam()); | 254 capture_params.requested_format.frame_rate = testing::get<1>(GetParam()); |
253 device->AllocateAndStart(capture_params, std::move(client_)); | 255 device->AllocateAndStart(capture_params, std::move(client_)); |
254 | 256 |
255 WaitForCapturedFrame(); | 257 WaitForCapturedFrame(); |
256 EXPECT_EQ(last_format().frame_size.width(), 640); | 258 EXPECT_EQ(last_format().frame_size.width(), 640); |
257 EXPECT_EQ(last_format().frame_size.height(), 480); | 259 EXPECT_EQ(last_format().frame_size.height(), 480); |
258 EXPECT_EQ(last_format().frame_rate, testing::get<1>(GetParam())); | 260 EXPECT_EQ(last_format().frame_rate, testing::get<1>(GetParam())); |
259 device->StopAndDeAllocate(); | 261 device->StopAndDeAllocate(); |
260 } | 262 } |
261 | 263 |
262 INSTANTIATE_TEST_CASE_P( | 264 INSTANTIATE_TEST_CASE_P( |
263 , | 265 , |
264 FakeVideoCaptureDeviceTest, | 266 FakeVideoCaptureDeviceTest, |
265 Combine(Values(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, | 267 Combine(Values(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, |
266 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS), | 268 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS), |
267 Values(20, 29.97, 30, 50, 60))); | 269 Values(20, 29.97, 30, 50, 60))); |
268 | 270 |
269 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 271 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
270 std::unique_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); | 272 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| 273 EnumerateDevices()); |
271 | 274 |
272 VideoCaptureFormats supported_formats; | 275 for (const auto& descriptors_iterator : *descriptors) { |
273 | 276 VideoCaptureFormats supported_formats; |
274 for (const auto& names_iterator : *names) { | 277 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, |
275 video_capture_device_factory_->GetDeviceSupportedFormats( | 278 &supported_formats); |
276 names_iterator, &supported_formats); | |
277 ASSERT_EQ(supported_formats.size(), 4u); | 279 ASSERT_EQ(supported_formats.size(), 4u); |
278 EXPECT_EQ(supported_formats[0].frame_size.width(), 320); | 280 EXPECT_EQ(supported_formats[0].frame_size.width(), 320); |
279 EXPECT_EQ(supported_formats[0].frame_size.height(), 240); | 281 EXPECT_EQ(supported_formats[0].frame_size.height(), 240); |
280 EXPECT_EQ(supported_formats[0].pixel_format, PIXEL_FORMAT_I420); | 282 EXPECT_EQ(supported_formats[0].pixel_format, PIXEL_FORMAT_I420); |
281 EXPECT_GE(supported_formats[0].frame_rate, 20.0); | 283 EXPECT_GE(supported_formats[0].frame_rate, 20.0); |
282 EXPECT_EQ(supported_formats[1].frame_size.width(), 640); | 284 EXPECT_EQ(supported_formats[1].frame_size.width(), 640); |
283 EXPECT_EQ(supported_formats[1].frame_size.height(), 480); | 285 EXPECT_EQ(supported_formats[1].frame_size.height(), 480); |
284 EXPECT_EQ(supported_formats[1].pixel_format, PIXEL_FORMAT_I420); | 286 EXPECT_EQ(supported_formats[1].pixel_format, PIXEL_FORMAT_I420); |
285 EXPECT_GE(supported_formats[1].frame_rate, 20.0); | 287 EXPECT_GE(supported_formats[1].frame_rate, 20.0); |
286 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); | 288 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 device->TakePhoto(std::move(scoped_callback)); | 392 device->TakePhoto(std::move(scoped_callback)); |
391 | 393 |
392 run_loop_.reset(new base::RunLoop()); | 394 run_loop_.reset(new base::RunLoop()); |
393 run_loop_->Run(); | 395 run_loop_->Run(); |
394 device->StopAndDeAllocate(); | 396 device->StopAndDeAllocate(); |
395 } | 397 } |
396 | 398 |
397 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { | 399 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { |
398 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 400 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
399 switches::kUseFakeDeviceForMediaStream, GetParam().argument); | 401 switches::kUseFakeDeviceForMediaStream, GetParam().argument); |
400 const std::unique_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); | 402 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
401 ASSERT_FALSE(names->empty()); | 403 EnumerateDevices()); |
| 404 ASSERT_FALSE(descriptors->empty()); |
402 | 405 |
403 for (const auto& names_iterator : *names) { | 406 for (const auto& descriptors_iterator : *descriptors) { |
404 std::unique_ptr<VideoCaptureDevice> device = | 407 std::unique_ptr<VideoCaptureDevice> device = |
405 video_capture_device_factory_->Create(names_iterator); | 408 video_capture_device_factory_->CreateDevice(descriptors_iterator); |
406 ASSERT_TRUE(device); | 409 ASSERT_TRUE(device); |
407 | 410 |
408 VideoCaptureParams capture_params; | 411 VideoCaptureParams capture_params; |
409 capture_params.requested_format.frame_size.SetSize(1280, 720); | 412 capture_params.requested_format.frame_size.SetSize(1280, 720); |
410 capture_params.requested_format.frame_rate = GetParam().fps; | 413 capture_params.requested_format.frame_rate = GetParam().fps; |
411 device->AllocateAndStart(capture_params, std::move(client_)); | 414 device->AllocateAndStart(capture_params, std::move(client_)); |
412 | 415 |
413 WaitForCapturedFrame(); | 416 WaitForCapturedFrame(); |
414 EXPECT_EQ(last_format().frame_size.width(), 1280); | 417 EXPECT_EQ(last_format().frame_size.width(), 1280); |
415 EXPECT_EQ(last_format().frame_size.height(), 720); | 418 EXPECT_EQ(last_format().frame_size.height(), 720); |
416 EXPECT_EQ(last_format().frame_rate, GetParam().fps); | 419 EXPECT_EQ(last_format().frame_rate, GetParam().fps); |
417 device->StopAndDeAllocate(); | 420 device->StopAndDeAllocate(); |
418 } | 421 } |
419 } | 422 } |
420 | 423 |
421 INSTANTIATE_TEST_CASE_P(, | 424 INSTANTIATE_TEST_CASE_P(, |
422 FakeVideoCaptureDeviceCommandLineTest, | 425 FakeVideoCaptureDeviceCommandLineTest, |
423 Values(CommandLineTestData{"fps=-1", 5}, | 426 Values(CommandLineTestData{"fps=-1", 5}, |
424 CommandLineTestData{"fps=29.97", 29.97f}, | 427 CommandLineTestData{"fps=29.97", 29.97f}, |
425 CommandLineTestData{"fps=60", 60}, | 428 CommandLineTestData{"fps=60", 60}, |
426 CommandLineTestData{"fps=1000", 60})); | 429 CommandLineTestData{"fps=1000", 60})); |
427 }; // namespace media | 430 }; // namespace media |
OLD | NEW |