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