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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 base::TimeTicks reference_time, | 114 base::TimeTicks reference_time, |
| 115 base::TimeDelta timestamp, | 115 base::TimeDelta timestamp, |
| 116 int frame_feedback_id) override { | 116 int frame_feedback_id) override { |
| 117 frame_cb_.Run(format); | 117 frame_cb_.Run(format); |
| 118 } | 118 } |
| 119 // Virtual methods for capturing using Client's Buffers. | 119 // Virtual methods for capturing using Client's Buffers. |
| 120 Buffer ReserveOutputBuffer(const gfx::Size& dimensions, | 120 Buffer ReserveOutputBuffer(const gfx::Size& dimensions, |
| 121 media::VideoPixelFormat format, | 121 media::VideoPixelFormat format, |
| 122 media::VideoPixelStorage storage, | 122 media::VideoPixelStorage storage, |
| 123 int frame_feedback_id) override { | 123 int frame_feedback_id) override { |
| 124 EXPECT_TRUE((format == media::PIXEL_FORMAT_ARGB && | 124 EXPECT_TRUE(storage == media::PIXEL_STORAGE_CPU); |
|
mcasas
2017/02/15 00:44:19
EXPECT_EQ(media::PIXEL_STORAGE_CPU, storage);
chfremer
2017/02/15 18:11:30
Done.
| |
| 125 storage == media::PIXEL_STORAGE_CPU)); | |
| 126 EXPECT_GT(dimensions.GetArea(), 0); | 125 EXPECT_GT(dimensions.GetArea(), 0); |
| 127 const VideoCaptureFormat frame_format(dimensions, 0.0, format); | 126 const VideoCaptureFormat frame_format(dimensions, 0.0, format); |
| 128 return CreateStubBuffer(0, frame_format.ImageAllocationSize()); | 127 return CreateStubBuffer(0, frame_format.ImageAllocationSize()); |
| 129 } | 128 } |
| 130 void OnIncomingCapturedBuffer(Buffer buffer, | 129 void OnIncomingCapturedBuffer(Buffer buffer, |
| 131 const VideoCaptureFormat& format, | 130 const VideoCaptureFormat& format, |
| 132 base::TimeTicks reference_time, | 131 base::TimeTicks reference_time, |
| 133 base::TimeDelta timestamp) override { | 132 base::TimeDelta timestamp) override { |
| 134 frame_cb_.Run(format); | 133 frame_cb_.Run(format); |
| 135 } | 134 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; | 259 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
| 261 const scoped_refptr<ImageCaptureClient> image_capture_client_; | 260 const scoped_refptr<ImageCaptureClient> image_capture_client_; |
| 262 VideoCaptureFormat last_format_; | 261 VideoCaptureFormat last_format_; |
| 263 const std::unique_ptr<VideoCaptureDeviceFactory> | 262 const std::unique_ptr<VideoCaptureDeviceFactory> |
| 264 video_capture_device_factory_; | 263 video_capture_device_factory_; |
| 265 }; | 264 }; |
| 266 | 265 |
| 267 class FakeVideoCaptureDeviceTest | 266 class FakeVideoCaptureDeviceTest |
| 268 : public FakeVideoCaptureDeviceBase, | 267 : public FakeVideoCaptureDeviceBase, |
| 269 public ::testing::WithParamInterface< | 268 public ::testing::WithParamInterface< |
| 270 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {}; | 269 ::testing::tuple<VideoPixelFormat, |
| 270 FakeVideoCaptureDeviceMaker::DeliveryMode, | |
| 271 float>> {}; | |
| 271 | 272 |
| 272 struct CommandLineTestData { | 273 // Tests that a frame is delivered with the expected settings. |
| 273 // Command line argument | 274 // Sweeps through a fixed set of requested/expected resolutions. |
| 274 std::string argument; | |
| 275 // Expected values | |
| 276 float fps; | |
| 277 size_t device_count; | |
| 278 }; | |
| 279 | |
| 280 class FakeVideoCaptureDeviceCommandLineTest | |
| 281 : public FakeVideoCaptureDeviceBase, | |
| 282 public ::testing::WithParamInterface<CommandLineTestData> {}; | |
| 283 | |
| 284 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { | 275 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { |
| 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 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( | 280 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
| 290 testing::get<0>(GetParam()), testing::get<1>(GetParam()))); | 281 testing::get<0>(GetParam()), testing::get<1>(GetParam()), |
| 282 testing::get<2>(GetParam())); | |
| 291 ASSERT_TRUE(device); | 283 ASSERT_TRUE(device); |
| 292 | 284 |
| 293 VideoCaptureParams capture_params; | 285 // First: Requested, Second: Expected |
| 294 capture_params.requested_format.frame_size.SetSize(640, 480); | 286 std::vector<std::pair<gfx::Size, gfx::Size>> resolutions_to_test; |
| 295 capture_params.requested_format.frame_rate = testing::get<1>(GetParam()); | 287 resolutions_to_test.emplace_back(gfx::Size(640, 480), gfx::Size(640, 480)); |
| 296 device->AllocateAndStart(capture_params, std::move(client_)); | 288 resolutions_to_test.emplace_back(gfx::Size(104, 105), gfx::Size(320, 240)); |
| 289 resolutions_to_test.emplace_back(gfx::Size(0, 0), gfx::Size(96, 96)); | |
| 290 resolutions_to_test.emplace_back(gfx::Size(0, 720), gfx::Size(96, 96)); | |
| 291 resolutions_to_test.emplace_back(gfx::Size(1920, 1080), | |
| 292 gfx::Size(1920, 1080)); | |
| 297 | 293 |
| 298 WaitForCapturedFrame(); | 294 for (const auto& resolution : resolutions_to_test) { |
| 299 EXPECT_EQ(last_format().frame_size.width(), 640); | 295 auto client = CreateClient(); |
| 300 EXPECT_EQ(last_format().frame_size.height(), 480); | 296 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
| 301 EXPECT_EQ(last_format().frame_rate, testing::get<1>(GetParam())); | 297 |
| 302 device->StopAndDeAllocate(); | 298 VideoCaptureParams capture_params; |
| 299 capture_params.requested_format.frame_size = resolution.first; | |
| 300 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); | |
| 301 device->AllocateAndStart(capture_params, std::move(client)); | |
| 302 | |
| 303 WaitForCapturedFrame(); | |
| 304 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); | |
| 305 EXPECT_EQ(resolution.second.height(), last_format().frame_size.height()); | |
| 306 EXPECT_EQ(last_format().pixel_format, testing::get<0>(GetParam())); | |
| 307 EXPECT_EQ(last_format().frame_rate, testing::get<2>(GetParam())); | |
| 308 device->StopAndDeAllocate(); | |
| 309 } | |
| 303 } | 310 } |
| 304 | 311 |
| 305 INSTANTIATE_TEST_CASE_P( | 312 INSTANTIATE_TEST_CASE_P( |
| 306 , | 313 , |
| 307 FakeVideoCaptureDeviceTest, | 314 FakeVideoCaptureDeviceTest, |
| 308 Combine(Values(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, | 315 Combine( |
| 309 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS), | 316 Values(PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_ARGB), |
| 310 Values(20, 29.97, 30, 50, 60))); | 317 Values(FakeVideoCaptureDeviceMaker::DeliveryMode::USE_OWN_BUFFERS, |
| 318 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_CLIENT_BUFFERS), | |
| 319 Values(20, 29.97, 30, 50, 60))); | |
| 311 | 320 |
| 312 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 321 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 313 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 322 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 314 switches::kUseFakeDeviceForMediaStream, "device-count=3"); | 323 switches::kUseFakeDeviceForMediaStream, "device-count=3"); |
| 315 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 324 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| 316 EnumerateDevices()); | 325 EnumerateDevices()); |
| 317 ASSERT_EQ(3u, descriptors->size()); | 326 ASSERT_EQ(3u, descriptors->size()); |
| 318 | 327 |
| 319 for (const auto& descriptors_iterator : *descriptors) { | 328 for (const auto& descriptors_iterator : *descriptors) { |
| 320 VideoCaptureFormats supported_formats; | 329 VideoCaptureFormats supported_formats; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1); | 366 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1); |
| 358 EXPECT_EQ("/dev/video1", depth_device.device_id); | 367 EXPECT_EQ("/dev/video1", depth_device.device_id); |
| 359 ASSERT_TRUE(depth_device.camera_calibration); | 368 ASSERT_TRUE(depth_device.camera_calibration); |
| 360 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); | 369 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); |
| 361 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); | 370 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); |
| 362 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); | 371 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); |
| 363 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); | 372 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); |
| 364 } | 373 } |
| 365 | 374 |
| 366 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { | 375 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { |
| 367 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( | 376 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
| 368 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); | 377 PIXEL_FORMAT_I420, |
| 378 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_OWN_BUFFERS, 30.0); | |
| 369 ASSERT_TRUE(device); | 379 ASSERT_TRUE(device); |
| 370 | 380 |
| 371 VideoCaptureParams capture_params; | 381 VideoCaptureParams capture_params; |
| 372 capture_params.requested_format.frame_size.SetSize(640, 480); | 382 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 373 capture_params.requested_format.frame_rate = 30.0; | 383 capture_params.requested_format.frame_rate = 30.0; |
| 374 device->AllocateAndStart(capture_params, std::move(client_)); | 384 device->AllocateAndStart(capture_params, std::move(client_)); |
| 375 | 385 |
| 376 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( | 386 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( |
| 377 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities, | 387 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities, |
| 378 image_capture_client_), | 388 image_capture_client_), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 device->GetPhotoCapabilities(std::move(scoped_get_callback2)); | 476 device->GetPhotoCapabilities(std::move(scoped_get_callback2)); |
| 467 run_loop_.reset(new base::RunLoop()); | 477 run_loop_.reset(new base::RunLoop()); |
| 468 run_loop_->Run(); | 478 run_loop_->Run(); |
| 469 EXPECT_EQ(max_zoom_value, | 479 EXPECT_EQ(max_zoom_value, |
| 470 image_capture_client_->capabilities()->zoom->current); | 480 image_capture_client_->capabilities()->zoom->current); |
| 471 | 481 |
| 472 device->StopAndDeAllocate(); | 482 device->StopAndDeAllocate(); |
| 473 } | 483 } |
| 474 | 484 |
| 475 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { | 485 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { |
| 476 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( | 486 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( |
| 477 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); | 487 PIXEL_FORMAT_I420, |
| 488 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_OWN_BUFFERS, 30.0); | |
| 478 ASSERT_TRUE(device); | 489 ASSERT_TRUE(device); |
| 479 | 490 |
| 480 VideoCaptureParams capture_params; | 491 VideoCaptureParams capture_params; |
| 481 capture_params.requested_format.frame_size.SetSize(640, 480); | 492 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 482 capture_params.requested_format.frame_rate = 30.0; | 493 capture_params.requested_format.frame_rate = 30.0; |
| 483 device->AllocateAndStart(capture_params, std::move(client_)); | 494 device->AllocateAndStart(capture_params, std::move(client_)); |
| 484 | 495 |
| 485 VideoCaptureDevice::TakePhotoCallback scoped_callback( | 496 VideoCaptureDevice::TakePhotoCallback scoped_callback( |
| 486 base::Bind(&ImageCaptureClient::DoOnPhotoTaken, image_capture_client_), | 497 base::Bind(&ImageCaptureClient::DoOnPhotoTaken, image_capture_client_), |
| 487 base::Bind(&ImageCaptureClient::OnTakePhotoFailure, | 498 base::Bind(&ImageCaptureClient::OnTakePhotoFailure, |
| 488 image_capture_client_)); | 499 image_capture_client_)); |
| 489 | 500 |
| 490 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); | 501 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); |
| 491 device->TakePhoto(std::move(scoped_callback)); | 502 device->TakePhoto(std::move(scoped_callback)); |
| 492 | 503 |
| 493 run_loop_.reset(new base::RunLoop()); | 504 run_loop_.reset(new base::RunLoop()); |
| 494 run_loop_->Run(); | 505 run_loop_->Run(); |
| 495 device->StopAndDeAllocate(); | 506 device->StopAndDeAllocate(); |
| 496 } | 507 } |
| 497 | 508 |
| 498 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRateAndDeviceCount) { | 509 struct CommandLineTestData { |
| 510 std::string switch_value_string; | |
| 511 float expected_fps; | |
| 512 size_t expected_device_count; | |
| 513 std::vector<VideoPixelFormat> expected_pixel_formats; | |
| 514 }; | |
| 515 | |
| 516 class FakeVideoCaptureDeviceFactoryTest | |
|
mcasas
2017/02/15 00:44:19
Maybe we should split this into a file on its own
chfremer
2017/02/15 18:11:30
Agreed that we should split.
Please allow me to de
| |
| 517 : public FakeVideoCaptureDeviceBase, | |
| 518 public ::testing::WithParamInterface<CommandLineTestData> {}; | |
| 519 | |
| 520 // Tests that the FakeVideoCaptureDeviceFactory delivers the expected number | |
| 521 // of devices and formats when being configured using command-line switches. | |
| 522 TEST_P(FakeVideoCaptureDeviceFactoryTest, FrameRateAndDeviceCount) { | |
| 499 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 523 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 500 switches::kUseFakeDeviceForMediaStream, GetParam().argument); | 524 switches::kUseFakeDeviceForMediaStream, GetParam().switch_value_string); |
| 501 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 525 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
| 502 EnumerateDevices()); | 526 EnumerateDevices()); |
| 503 EXPECT_EQ(descriptors->size(), GetParam().device_count); | 527 EXPECT_EQ(GetParam().expected_device_count, descriptors->size()); |
| 504 ASSERT_FALSE(descriptors->empty()); | 528 ASSERT_FALSE(descriptors->empty()); |
| 505 | 529 |
| 530 int device_index = 0; | |
| 506 for (const auto& descriptors_iterator : *descriptors) { | 531 for (const auto& descriptors_iterator : *descriptors) { |
| 532 media::VideoCaptureFormats supported_formats; | |
| 533 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, | |
| 534 &supported_formats); | |
| 535 for (const auto& supported_formats_entry : supported_formats) { | |
| 536 EXPECT_EQ(GetParam().expected_pixel_formats[device_index], | |
| 537 supported_formats_entry.pixel_format); | |
| 538 } | |
| 539 | |
| 507 std::unique_ptr<VideoCaptureDevice> device = | 540 std::unique_ptr<VideoCaptureDevice> device = |
| 508 video_capture_device_factory_->CreateDevice(descriptors_iterator); | 541 video_capture_device_factory_->CreateDevice(descriptors_iterator); |
| 509 ASSERT_TRUE(device); | 542 ASSERT_TRUE(device); |
| 510 | 543 |
| 511 VideoCaptureParams capture_params; | 544 VideoCaptureParams capture_params; |
| 512 capture_params.requested_format.frame_size.SetSize(1280, 720); | 545 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 513 capture_params.requested_format.frame_rate = GetParam().fps; | 546 capture_params.requested_format.frame_rate = GetParam().expected_fps; |
| 547 capture_params.requested_format.pixel_format = | |
| 548 GetParam().expected_pixel_formats[device_index]; | |
| 514 device->AllocateAndStart(capture_params, CreateClient()); | 549 device->AllocateAndStart(capture_params, CreateClient()); |
| 515 WaitForCapturedFrame(); | 550 WaitForCapturedFrame(); |
| 516 EXPECT_EQ(last_format().frame_size.width(), 1280); | 551 EXPECT_EQ(1280, last_format().frame_size.width()); |
| 517 EXPECT_EQ(last_format().frame_size.height(), 720); | 552 EXPECT_EQ(720, last_format().frame_size.height()); |
| 518 EXPECT_EQ(last_format().frame_rate, GetParam().fps); | 553 EXPECT_EQ(GetParam().expected_fps, last_format().frame_rate); |
| 554 EXPECT_EQ(GetParam().expected_pixel_formats[device_index], | |
| 555 last_format().pixel_format); | |
| 519 device->StopAndDeAllocate(); | 556 device->StopAndDeAllocate(); |
| 557 | |
| 558 device_index++; | |
| 520 } | 559 } |
| 521 } | 560 } |
| 522 | 561 |
| 523 INSTANTIATE_TEST_CASE_P( | 562 INSTANTIATE_TEST_CASE_P( |
| 524 , | 563 , |
| 525 FakeVideoCaptureDeviceCommandLineTest, | 564 FakeVideoCaptureDeviceFactoryTest, |
| 526 Values(CommandLineTestData{"fps=-1", 5, 1u}, | 565 Values( |
| 527 CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u}, | 566 CommandLineTestData{"fps=-1", 5, 1u, |
| 528 CommandLineTestData{"fps=60, device-count=2", 60, 2u}, | 567 std::vector<VideoPixelFormat>({PIXEL_FORMAT_I420})}, |
| 529 CommandLineTestData{"fps=1000, device-count=-1", 60, 1u}, | 568 CommandLineTestData{"fps=29.97,device-count=1", 29.97f, 1u, |
| 530 CommandLineTestData{"device-count=2", 20, 2u}, | 569 std::vector<VideoPixelFormat>({PIXEL_FORMAT_I420})}, |
| 531 CommandLineTestData{"device-count=0", 20, 1u})); | 570 CommandLineTestData{"fps=60,device-count=2", 60, 2u, |
| 571 std::vector<VideoPixelFormat>({PIXEL_FORMAT_I420, | |
| 572 PIXEL_FORMAT_Y16})}, | |
| 573 CommandLineTestData{"fps=1000,device-count=-1", 60, 1u, | |
| 574 std::vector<VideoPixelFormat>({PIXEL_FORMAT_I420})}, | |
| 575 CommandLineTestData{ | |
| 576 "device-count=3", 20, 3u, | |
| 577 std::vector<VideoPixelFormat>({PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, | |
| 578 PIXEL_FORMAT_I420})}, | |
| 579 CommandLineTestData{ | |
| 580 "device-count=3,ownership=client", 20, 3u, | |
| 581 std::vector<VideoPixelFormat>({PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, | |
| 582 PIXEL_FORMAT_I420})}, | |
|
mcasas
2017/02/15 00:44:19
Here we could just use
{PIXEL_FORMAT_I420, PIXEL_
chfremer
2017/02/15 18:11:30
Nice! Thanks.
| |
| 583 CommandLineTestData{ | |
| 584 "device-count=0", 20, 1u, | |
| 585 std::vector<VideoPixelFormat>({PIXEL_FORMAT_I420})})); | |
| 532 }; // namespace media | 586 }; // namespace media |
| OLD | NEW |