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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; | 259 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
260 const scoped_refptr<ImageCaptureClient> image_capture_client_; | 260 const scoped_refptr<ImageCaptureClient> image_capture_client_; |
261 VideoCaptureFormat last_format_; | 261 VideoCaptureFormat last_format_; |
262 const std::unique_ptr<VideoCaptureDeviceFactory> | 262 const std::unique_ptr<VideoCaptureDeviceFactory> |
263 video_capture_device_factory_; | 263 video_capture_device_factory_; |
264 }; | 264 }; |
265 | 265 |
266 class FakeVideoCaptureDeviceTest | 266 class FakeVideoCaptureDeviceTest |
267 : public FakeVideoCaptureDeviceBase, | 267 : public FakeVideoCaptureDeviceBase, |
268 public ::testing::WithParamInterface< | 268 public ::testing::WithParamInterface< |
269 ::testing::tuple<VideoPixelFormat, | 269 ::testing::tuple<FakeVideoCaptureDeviceMaker::PixelFormat, |
270 FakeVideoCaptureDeviceMaker::DeliveryMode, | 270 FakeVideoCaptureDeviceMaker::DeliveryMode, |
271 float>> {}; | 271 float>> {}; |
272 | 272 |
273 // Tests that a frame is delivered with the expected settings. | 273 // Tests that a frame is delivered with the expected settings. |
274 // Sweeps through a fixed set of requested/expected resolutions. | 274 // Sweeps through a fixed set of requested/expected resolutions. |
275 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { | 275 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { |
| 276 if (testing::get<1>(GetParam()) == |
| 277 FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 278 USE_CLIENT_PROVIDED_BUFFERS && |
| 279 testing::get<0>(GetParam()) == |
| 280 FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG) { |
| 281 // Unsupported case |
| 282 return; |
| 283 } |
| 284 |
276 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 285 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
277 EnumerateDevices()); | 286 EnumerateDevices()); |
278 ASSERT_FALSE(descriptors->empty()); | 287 ASSERT_FALSE(descriptors->empty()); |
279 | 288 |
280 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 289 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
281 testing::get<0>(GetParam()), testing::get<1>(GetParam()), | 290 testing::get<0>(GetParam()), testing::get<1>(GetParam()), |
282 testing::get<2>(GetParam())); | 291 testing::get<2>(GetParam())); |
283 ASSERT_TRUE(device); | 292 ASSERT_TRUE(device); |
284 | 293 |
285 // First: Requested, Second: Expected | 294 // First: Requested, Second: Expected |
(...skipping 10 matching lines...) Expand all Loading... |
296 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 305 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
297 | 306 |
298 VideoCaptureParams capture_params; | 307 VideoCaptureParams capture_params; |
299 capture_params.requested_format.frame_size = resolution.first; | 308 capture_params.requested_format.frame_size = resolution.first; |
300 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); | 309 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); |
301 device->AllocateAndStart(capture_params, std::move(client)); | 310 device->AllocateAndStart(capture_params, std::move(client)); |
302 | 311 |
303 WaitForCapturedFrame(); | 312 WaitForCapturedFrame(); |
304 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); | 313 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); |
305 EXPECT_EQ(resolution.second.height(), last_format().frame_size.height()); | 314 EXPECT_EQ(resolution.second.height(), last_format().frame_size.height()); |
306 EXPECT_EQ(last_format().pixel_format, testing::get<0>(GetParam())); | 315 EXPECT_EQ(last_format().pixel_format, |
| 316 FakeVideoCaptureDeviceMaker::TranslateToMediaVideoPixelFormat( |
| 317 testing::get<0>(GetParam()))); |
307 EXPECT_EQ(last_format().frame_rate, testing::get<2>(GetParam())); | 318 EXPECT_EQ(last_format().frame_rate, testing::get<2>(GetParam())); |
308 device->StopAndDeAllocate(); | 319 device->StopAndDeAllocate(); |
309 } | 320 } |
310 } | 321 } |
311 | 322 |
312 INSTANTIATE_TEST_CASE_P( | 323 INSTANTIATE_TEST_CASE_P( |
313 , | 324 , |
314 FakeVideoCaptureDeviceTest, | 325 FakeVideoCaptureDeviceTest, |
315 Combine(Values(PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_ARGB), | 326 Combine(Values(FakeVideoCaptureDeviceMaker::PixelFormat::I420, |
| 327 FakeVideoCaptureDeviceMaker::PixelFormat::Y16, |
| 328 FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG), |
316 Values(FakeVideoCaptureDeviceMaker::DeliveryMode:: | 329 Values(FakeVideoCaptureDeviceMaker::DeliveryMode:: |
317 USE_DEVICE_INTERNAL_BUFFERS, | 330 USE_DEVICE_INTERNAL_BUFFERS, |
318 FakeVideoCaptureDeviceMaker::DeliveryMode:: | 331 FakeVideoCaptureDeviceMaker::DeliveryMode:: |
319 USE_CLIENT_PROVIDED_BUFFERS), | 332 USE_CLIENT_PROVIDED_BUFFERS), |
320 Values(20, 29.97, 30, 50, 60))); | 333 Values(20, 29.97, 30, 50, 60))); |
321 | 334 |
322 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 335 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
323 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 336 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
324 switches::kUseFakeDeviceForMediaStream, "device-count=3"); | 337 switches::kUseFakeDeviceForMediaStream, "device-count=4"); |
325 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 338 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
326 EnumerateDevices()); | 339 EnumerateDevices()); |
327 ASSERT_EQ(3u, descriptors->size()); | 340 ASSERT_EQ(4u, descriptors->size()); |
328 | 341 |
329 for (const auto& descriptors_iterator : *descriptors) { | 342 for (const auto& descriptors_iterator : *descriptors) { |
330 VideoCaptureFormats supported_formats; | 343 VideoCaptureFormats supported_formats; |
331 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, | 344 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, |
332 &supported_formats); | 345 &supported_formats); |
333 ASSERT_EQ(5u, supported_formats.size()); | 346 ASSERT_EQ(5u, supported_formats.size()); |
334 const std::string device_id = descriptors_iterator.device_id; | |
335 VideoPixelFormat expected_format = | 347 VideoPixelFormat expected_format = |
336 (device_id == "/dev/video1") ? PIXEL_FORMAT_Y16 : PIXEL_FORMAT_I420; | 348 FakeVideoCaptureDeviceMaker::TranslateToMediaVideoPixelFormat( |
| 349 FakeVideoCaptureDeviceFactory::GetPixelFormatFromDeviceId( |
| 350 descriptors_iterator.device_id)); |
337 EXPECT_EQ(96, supported_formats[0].frame_size.width()); | 351 EXPECT_EQ(96, supported_formats[0].frame_size.width()); |
338 EXPECT_EQ(96, supported_formats[0].frame_size.height()); | 352 EXPECT_EQ(96, supported_formats[0].frame_size.height()); |
339 EXPECT_EQ(expected_format, supported_formats[0].pixel_format); | 353 EXPECT_EQ(expected_format, supported_formats[0].pixel_format); |
340 EXPECT_GE(supported_formats[0].frame_rate, 20.0); | 354 EXPECT_GE(supported_formats[0].frame_rate, 20.0); |
341 EXPECT_EQ(320, supported_formats[1].frame_size.width()); | 355 EXPECT_EQ(320, supported_formats[1].frame_size.width()); |
342 EXPECT_EQ(240, supported_formats[1].frame_size.height()); | 356 EXPECT_EQ(240, supported_formats[1].frame_size.height()); |
343 EXPECT_EQ(expected_format, supported_formats[1].pixel_format); | 357 EXPECT_EQ(expected_format, supported_formats[1].pixel_format); |
344 EXPECT_GE(supported_formats[1].frame_rate, 20.0); | 358 EXPECT_GE(supported_formats[1].frame_rate, 20.0); |
345 EXPECT_EQ(640, supported_formats[2].frame_size.width()); | 359 EXPECT_EQ(640, supported_formats[2].frame_size.width()); |
346 EXPECT_EQ(480, supported_formats[2].frame_size.height()); | 360 EXPECT_EQ(480, supported_formats[2].frame_size.height()); |
(...skipping 21 matching lines...) Expand all Loading... |
368 EXPECT_EQ("/dev/video1", depth_device.device_id); | 382 EXPECT_EQ("/dev/video1", depth_device.device_id); |
369 ASSERT_TRUE(depth_device.camera_calibration); | 383 ASSERT_TRUE(depth_device.camera_calibration); |
370 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); | 384 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); |
371 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); | 385 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); |
372 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); | 386 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); |
373 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); | 387 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); |
374 } | 388 } |
375 | 389 |
376 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { | 390 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { |
377 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 391 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
378 PIXEL_FORMAT_I420, | 392 FakeVideoCaptureDeviceMaker::PixelFormat::I420, |
379 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 393 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, |
380 30.0); | 394 30.0); |
381 ASSERT_TRUE(device); | 395 ASSERT_TRUE(device); |
382 | 396 |
383 VideoCaptureParams capture_params; | 397 VideoCaptureParams capture_params; |
384 capture_params.requested_format.frame_size.SetSize(640, 480); | 398 capture_params.requested_format.frame_size.SetSize(640, 480); |
385 capture_params.requested_format.frame_rate = 30.0; | 399 capture_params.requested_format.frame_rate = 30.0; |
386 device->AllocateAndStart(capture_params, std::move(client_)); | 400 device->AllocateAndStart(capture_params, std::move(client_)); |
387 | 401 |
388 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( | 402 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 run_loop_.reset(new base::RunLoop()); | 493 run_loop_.reset(new base::RunLoop()); |
480 run_loop_->Run(); | 494 run_loop_->Run(); |
481 EXPECT_EQ(max_zoom_value, | 495 EXPECT_EQ(max_zoom_value, |
482 image_capture_client_->capabilities()->zoom->current); | 496 image_capture_client_->capabilities()->zoom->current); |
483 | 497 |
484 device->StopAndDeAllocate(); | 498 device->StopAndDeAllocate(); |
485 } | 499 } |
486 | 500 |
487 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { | 501 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
488 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 502 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
489 PIXEL_FORMAT_I420, | 503 FakeVideoCaptureDeviceMaker::PixelFormat::I420, |
490 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 504 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, |
491 30.0); | 505 30.0); |
492 ASSERT_TRUE(device); | 506 ASSERT_TRUE(device); |
493 | 507 |
494 VideoCaptureParams capture_params; | 508 VideoCaptureParams capture_params; |
495 capture_params.requested_format.frame_size.SetSize(640, 480); | 509 capture_params.requested_format.frame_size.SetSize(640, 480); |
496 capture_params.requested_format.frame_rate = 30.0; | 510 capture_params.requested_format.frame_rate = 30.0; |
497 device->AllocateAndStart(capture_params, std::move(client_)); | 511 device->AllocateAndStart(capture_params, std::move(client_)); |
498 | 512 |
499 VideoCaptureDevice::TakePhotoCallback scoped_callback( | 513 VideoCaptureDevice::TakePhotoCallback scoped_callback( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 1u, | 585 1u, |
572 {PIXEL_FORMAT_I420}}, | 586 {PIXEL_FORMAT_I420}}, |
573 CommandLineTestData{"fps=60,device-count=2", | 587 CommandLineTestData{"fps=60,device-count=2", |
574 60, | 588 60, |
575 2u, | 589 2u, |
576 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16}}, | 590 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16}}, |
577 CommandLineTestData{"fps=1000,device-count=-1", | 591 CommandLineTestData{"fps=1000,device-count=-1", |
578 60, | 592 60, |
579 1u, | 593 1u, |
580 {PIXEL_FORMAT_I420}}, | 594 {PIXEL_FORMAT_I420}}, |
581 CommandLineTestData{ | 595 CommandLineTestData{"device-count=4", |
582 "device-count=3", | 596 20, |
583 20, | 597 4u, |
584 3u, | 598 |
585 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, | 599 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, |
586 CommandLineTestData{ | 600 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, |
587 "device-count=3,ownership=client", | 601 CommandLineTestData{"device-count=4,ownership=client", |
588 20, | 602 20, |
589 3u, | 603 4u, |
590 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, | 604 |
| 605 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, |
| 606 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, |
591 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); | 607 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); |
592 }; // namespace media | 608 }; // namespace media |
OLD | NEW |