Chromium Code Reviews| 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 static_cast<VideoPixelFormat>(testing::get<0>(GetParam()))); | |
| 307 EXPECT_EQ(last_format().frame_rate, testing::get<2>(GetParam())); | 317 EXPECT_EQ(last_format().frame_rate, testing::get<2>(GetParam())); |
| 308 device->StopAndDeAllocate(); | 318 device->StopAndDeAllocate(); |
| 309 } | 319 } |
| 310 } | 320 } |
| 311 | 321 |
| 312 INSTANTIATE_TEST_CASE_P( | 322 INSTANTIATE_TEST_CASE_P( |
| 313 , | 323 , |
| 314 FakeVideoCaptureDeviceTest, | 324 FakeVideoCaptureDeviceTest, |
| 315 Combine(Values(PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_ARGB), | 325 Combine(Values(FakeVideoCaptureDeviceMaker::PixelFormat::I420, |
| 326 FakeVideoCaptureDeviceMaker::PixelFormat::Y16, | |
| 327 FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG), | |
| 316 Values(FakeVideoCaptureDeviceMaker::DeliveryMode:: | 328 Values(FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 317 USE_DEVICE_INTERNAL_BUFFERS, | 329 USE_DEVICE_INTERNAL_BUFFERS, |
| 318 FakeVideoCaptureDeviceMaker::DeliveryMode:: | 330 FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 319 USE_CLIENT_PROVIDED_BUFFERS), | 331 USE_CLIENT_PROVIDED_BUFFERS), |
| 320 Values(20, 29.97, 30, 50, 60))); | 332 Values(20, 29.97, 30, 50, 60))); |
| 321 | 333 |
| 322 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 334 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 323 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 335 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 324 switches::kUseFakeDeviceForMediaStream, "device-count=3"); | 336 switches::kUseFakeDeviceForMediaStream, "device-count=4"); |
| 325 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 337 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| 326 EnumerateDevices()); | 338 EnumerateDevices()); |
| 327 ASSERT_EQ(3u, descriptors->size()); | 339 ASSERT_EQ(4u, descriptors->size()); |
| 340 VideoPixelFormat expected_format_by_device_index[] = { | |
|
mcasas
2017/02/23 21:46:18
nit: const
| |
| 341 PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_MJPEG, | |
| 342 PIXEL_FORMAT_I420}; | |
| 328 | 343 |
| 344 int device_index = 0; | |
| 329 for (const auto& descriptors_iterator : *descriptors) { | 345 for (const auto& descriptors_iterator : *descriptors) { |
| 330 VideoCaptureFormats supported_formats; | 346 VideoCaptureFormats supported_formats; |
| 331 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, | 347 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, |
| 332 &supported_formats); | 348 &supported_formats); |
| 333 ASSERT_EQ(5u, supported_formats.size()); | 349 ASSERT_EQ(5u, supported_formats.size()); |
| 334 const std::string device_id = descriptors_iterator.device_id; | |
| 335 VideoPixelFormat expected_format = | 350 VideoPixelFormat expected_format = |
| 336 (device_id == "/dev/video1") ? PIXEL_FORMAT_Y16 : PIXEL_FORMAT_I420; | 351 expected_format_by_device_index[device_index]; |
| 337 EXPECT_EQ(96, supported_formats[0].frame_size.width()); | 352 EXPECT_EQ(96, supported_formats[0].frame_size.width()); |
| 338 EXPECT_EQ(96, supported_formats[0].frame_size.height()); | 353 EXPECT_EQ(96, supported_formats[0].frame_size.height()); |
| 339 EXPECT_EQ(expected_format, supported_formats[0].pixel_format); | 354 EXPECT_EQ(expected_format, supported_formats[0].pixel_format); |
| 340 EXPECT_GE(supported_formats[0].frame_rate, 20.0); | 355 EXPECT_GE(supported_formats[0].frame_rate, 20.0); |
| 341 EXPECT_EQ(320, supported_formats[1].frame_size.width()); | 356 EXPECT_EQ(320, supported_formats[1].frame_size.width()); |
| 342 EXPECT_EQ(240, supported_formats[1].frame_size.height()); | 357 EXPECT_EQ(240, supported_formats[1].frame_size.height()); |
| 343 EXPECT_EQ(expected_format, supported_formats[1].pixel_format); | 358 EXPECT_EQ(expected_format, supported_formats[1].pixel_format); |
| 344 EXPECT_GE(supported_formats[1].frame_rate, 20.0); | 359 EXPECT_GE(supported_formats[1].frame_rate, 20.0); |
| 345 EXPECT_EQ(640, supported_formats[2].frame_size.width()); | 360 EXPECT_EQ(640, supported_formats[2].frame_size.width()); |
| 346 EXPECT_EQ(480, supported_formats[2].frame_size.height()); | 361 EXPECT_EQ(480, supported_formats[2].frame_size.height()); |
| 347 EXPECT_EQ(expected_format, supported_formats[2].pixel_format); | 362 EXPECT_EQ(expected_format, supported_formats[2].pixel_format); |
| 348 EXPECT_GE(supported_formats[2].frame_rate, 20.0); | 363 EXPECT_GE(supported_formats[2].frame_rate, 20.0); |
| 349 EXPECT_EQ(1280, supported_formats[3].frame_size.width()); | 364 EXPECT_EQ(1280, supported_formats[3].frame_size.width()); |
| 350 EXPECT_EQ(720, supported_formats[3].frame_size.height()); | 365 EXPECT_EQ(720, supported_formats[3].frame_size.height()); |
| 351 EXPECT_EQ(expected_format, supported_formats[3].pixel_format); | 366 EXPECT_EQ(expected_format, supported_formats[3].pixel_format); |
| 352 EXPECT_GE(supported_formats[3].frame_rate, 20.0); | 367 EXPECT_GE(supported_formats[3].frame_rate, 20.0); |
| 353 EXPECT_EQ(1920, supported_formats[4].frame_size.width()); | 368 EXPECT_EQ(1920, supported_formats[4].frame_size.width()); |
| 354 EXPECT_EQ(1080, supported_formats[4].frame_size.height()); | 369 EXPECT_EQ(1080, supported_formats[4].frame_size.height()); |
| 355 EXPECT_EQ(expected_format, supported_formats[4].pixel_format); | 370 EXPECT_EQ(expected_format, supported_formats[4].pixel_format); |
| 356 EXPECT_GE(supported_formats[4].frame_rate, 20.0); | 371 EXPECT_GE(supported_formats[4].frame_rate, 20.0); |
| 372 device_index++; | |
| 357 } | 373 } |
| 358 } | 374 } |
| 359 | 375 |
| 360 TEST_F(FakeVideoCaptureDeviceTest, GetCameraCalibration) { | 376 TEST_F(FakeVideoCaptureDeviceTest, GetCameraCalibration) { |
| 361 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 377 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 362 switches::kUseFakeDeviceForMediaStream, "device-count=2"); | 378 switches::kUseFakeDeviceForMediaStream, "device-count=2"); |
| 363 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 379 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| 364 EnumerateDevices()); | 380 EnumerateDevices()); |
| 365 ASSERT_EQ(2u, descriptors->size()); | 381 ASSERT_EQ(2u, descriptors->size()); |
| 366 ASSERT_FALSE(descriptors->at(0).camera_calibration); | 382 ASSERT_FALSE(descriptors->at(0).camera_calibration); |
| 367 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1); | 383 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1); |
| 368 EXPECT_EQ("/dev/video1", depth_device.device_id); | 384 EXPECT_EQ("/dev/video1", depth_device.device_id); |
| 369 ASSERT_TRUE(depth_device.camera_calibration); | 385 ASSERT_TRUE(depth_device.camera_calibration); |
| 370 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); | 386 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); |
| 371 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); | 387 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); |
| 372 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); | 388 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); |
| 373 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); | 389 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); |
| 374 } | 390 } |
| 375 | 391 |
| 376 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { | 392 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { |
| 377 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 393 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
| 378 PIXEL_FORMAT_I420, | 394 FakeVideoCaptureDeviceMaker::PixelFormat::I420, |
| 379 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 395 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, |
| 380 30.0); | 396 30.0); |
| 381 ASSERT_TRUE(device); | 397 ASSERT_TRUE(device); |
| 382 | 398 |
| 383 VideoCaptureParams capture_params; | 399 VideoCaptureParams capture_params; |
| 384 capture_params.requested_format.frame_size.SetSize(640, 480); | 400 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 385 capture_params.requested_format.frame_rate = 30.0; | 401 capture_params.requested_format.frame_rate = 30.0; |
| 386 device->AllocateAndStart(capture_params, std::move(client_)); | 402 device->AllocateAndStart(capture_params, std::move(client_)); |
| 387 | 403 |
| 388 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( | 404 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()); | 495 run_loop_.reset(new base::RunLoop()); |
| 480 run_loop_->Run(); | 496 run_loop_->Run(); |
| 481 EXPECT_EQ(max_zoom_value, | 497 EXPECT_EQ(max_zoom_value, |
| 482 image_capture_client_->capabilities()->zoom->current); | 498 image_capture_client_->capabilities()->zoom->current); |
| 483 | 499 |
| 484 device->StopAndDeAllocate(); | 500 device->StopAndDeAllocate(); |
| 485 } | 501 } |
| 486 | 502 |
| 487 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { | 503 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
| 488 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( | 504 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
| 489 PIXEL_FORMAT_I420, | 505 FakeVideoCaptureDeviceMaker::PixelFormat::I420, |
| 490 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, | 506 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, |
| 491 30.0); | 507 30.0); |
| 492 ASSERT_TRUE(device); | 508 ASSERT_TRUE(device); |
| 493 | 509 |
| 494 VideoCaptureParams capture_params; | 510 VideoCaptureParams capture_params; |
| 495 capture_params.requested_format.frame_size.SetSize(640, 480); | 511 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 496 capture_params.requested_format.frame_rate = 30.0; | 512 capture_params.requested_format.frame_rate = 30.0; |
| 497 device->AllocateAndStart(capture_params, std::move(client_)); | 513 device->AllocateAndStart(capture_params, std::move(client_)); |
| 498 | 514 |
| 499 VideoCaptureDevice::TakePhotoCallback scoped_callback( | 515 VideoCaptureDevice::TakePhotoCallback scoped_callback( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 1u, | 587 1u, |
| 572 {PIXEL_FORMAT_I420}}, | 588 {PIXEL_FORMAT_I420}}, |
| 573 CommandLineTestData{"fps=60,device-count=2", | 589 CommandLineTestData{"fps=60,device-count=2", |
| 574 60, | 590 60, |
| 575 2u, | 591 2u, |
| 576 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16}}, | 592 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16}}, |
| 577 CommandLineTestData{"fps=1000,device-count=-1", | 593 CommandLineTestData{"fps=1000,device-count=-1", |
| 578 60, | 594 60, |
| 579 1u, | 595 1u, |
| 580 {PIXEL_FORMAT_I420}}, | 596 {PIXEL_FORMAT_I420}}, |
| 581 CommandLineTestData{ | 597 CommandLineTestData{"device-count=4", |
| 582 "device-count=3", | 598 20, |
| 583 20, | 599 4u, |
| 584 3u, | 600 |
| 585 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, | 601 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, |
| 586 CommandLineTestData{ | 602 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, |
| 587 "device-count=3,ownership=client", | 603 CommandLineTestData{"device-count=4,ownership=client", |
| 588 20, | 604 20, |
| 589 3u, | 605 4u, |
| 590 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, | 606 |
| 607 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, | |
| 608 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, | |
| 591 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); | 609 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); |
| 592 }; // namespace media | 610 }; // namespace media |
| OLD | NEW |