Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: media/capture/video/fake_video_capture_device_unittest.cc

Issue 2715513008: Make FakeVideoCaptureDeviceFactory configurable to arbitrary fake device configurations (Closed)
Patch Set: Fix compiler warning. Fix WebRtcDepthCaptureBrowserTest. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 252
253 const VideoCaptureFormat& last_format() const { return last_format_; } 253 const VideoCaptureFormat& last_format() const { return last_format_; }
254 254
255 VideoCaptureDeviceDescriptors descriptors_; 255 VideoCaptureDeviceDescriptors descriptors_;
256 const std::unique_ptr<base::MessageLoop> loop_; 256 const std::unique_ptr<base::MessageLoop> loop_;
257 std::unique_ptr<base::RunLoop> run_loop_; 257 std::unique_ptr<base::RunLoop> run_loop_;
258 std::unique_ptr<MockClient> client_; 258 std::unique_ptr<MockClient> client_;
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<FakeVideoCaptureDeviceFactory>
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 FakeVideoCaptureDevice::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()) == 276 if (testing::get<1>(GetParam()) ==
277 FakeVideoCaptureDeviceMaker::DeliveryMode:: 277 FakeVideoCaptureDevice::DeliveryMode::USE_CLIENT_PROVIDED_BUFFERS &&
278 USE_CLIENT_PROVIDED_BUFFERS && 278 testing::get<0>(GetParam()) == media::PIXEL_FORMAT_MJPEG) {
279 testing::get<0>(GetParam()) ==
280 FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG) {
281 // Unsupported case 279 // Unsupported case
282 return; 280 return;
283 } 281 }
284 282
285 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 283 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
286 EnumerateDevices()); 284 EnumerateDevices());
287 ASSERT_FALSE(descriptors->empty()); 285 ASSERT_FALSE(descriptors->empty());
288 286
289 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( 287 auto device =
290 testing::get<0>(GetParam()), testing::get<1>(GetParam()), 288 FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions(
291 testing::get<2>(GetParam())); 289 testing::get<0>(GetParam()), testing::get<1>(GetParam()),
290 testing::get<2>(GetParam()));
292 ASSERT_TRUE(device); 291 ASSERT_TRUE(device);
293 292
294 // First: Requested, Second: Expected 293 // First: Requested, Second: Expected
295 std::vector<std::pair<gfx::Size, gfx::Size>> resolutions_to_test; 294 std::vector<std::pair<gfx::Size, gfx::Size>> resolutions_to_test;
296 resolutions_to_test.emplace_back(gfx::Size(640, 480), gfx::Size(640, 480)); 295 resolutions_to_test.emplace_back(gfx::Size(640, 480), gfx::Size(640, 480));
297 resolutions_to_test.emplace_back(gfx::Size(104, 105), gfx::Size(320, 240)); 296 resolutions_to_test.emplace_back(gfx::Size(104, 105), gfx::Size(320, 240));
298 resolutions_to_test.emplace_back(gfx::Size(0, 0), gfx::Size(96, 96)); 297 resolutions_to_test.emplace_back(gfx::Size(0, 0), gfx::Size(96, 96));
299 resolutions_to_test.emplace_back(gfx::Size(0, 720), gfx::Size(96, 96)); 298 resolutions_to_test.emplace_back(gfx::Size(0, 720), gfx::Size(96, 96));
300 resolutions_to_test.emplace_back(gfx::Size(1920, 1080), 299 resolutions_to_test.emplace_back(gfx::Size(1920, 1080),
301 gfx::Size(1920, 1080)); 300 gfx::Size(1920, 1080));
302 301
303 for (const auto& resolution : resolutions_to_test) { 302 for (const auto& resolution : resolutions_to_test) {
304 auto client = CreateClient(); 303 auto client = CreateClient();
305 EXPECT_CALL(*client, OnError(_, _)).Times(0); 304 EXPECT_CALL(*client, OnError(_, _)).Times(0);
306 305
307 VideoCaptureParams capture_params; 306 VideoCaptureParams capture_params;
308 capture_params.requested_format.frame_size = resolution.first; 307 capture_params.requested_format.frame_size = resolution.first;
309 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); 308 capture_params.requested_format.frame_rate = testing::get<2>(GetParam());
310 device->AllocateAndStart(capture_params, std::move(client)); 309 device->AllocateAndStart(capture_params, std::move(client));
311 310
312 WaitForCapturedFrame(); 311 WaitForCapturedFrame();
313 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); 312 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width());
314 EXPECT_EQ(resolution.second.height(), last_format().frame_size.height()); 313 EXPECT_EQ(resolution.second.height(), last_format().frame_size.height());
315 EXPECT_EQ(last_format().pixel_format, 314 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())); 315 EXPECT_EQ(last_format().frame_rate, testing::get<2>(GetParam()));
318 device->StopAndDeAllocate(); 316 device->StopAndDeAllocate();
319 } 317 }
320 } 318 }
321 319
322 INSTANTIATE_TEST_CASE_P( 320 INSTANTIATE_TEST_CASE_P(
323 , 321 ,
324 FakeVideoCaptureDeviceTest, 322 FakeVideoCaptureDeviceTest,
325 Combine(Values(FakeVideoCaptureDeviceMaker::PixelFormat::I420, 323 Combine(
326 FakeVideoCaptureDeviceMaker::PixelFormat::Y16, 324 Values(PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_MJPEG),
327 FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG), 325 Values(
328 Values(FakeVideoCaptureDeviceMaker::DeliveryMode:: 326 FakeVideoCaptureDevice::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS,
329 USE_DEVICE_INTERNAL_BUFFERS, 327 FakeVideoCaptureDevice::DeliveryMode::USE_CLIENT_PROVIDED_BUFFERS),
330 FakeVideoCaptureDeviceMaker::DeliveryMode:: 328 Values(20, 29.97, 30, 50, 60)));
331 USE_CLIENT_PROVIDED_BUFFERS),
332 Values(20, 29.97, 30, 50, 60)));
333 329
334 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { 330 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) {
335 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 331 video_capture_device_factory_->SetToDefaultDevicesConfig(4);
336 switches::kUseFakeDeviceForMediaStream, "device-count=4");
337 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 332 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
338 EnumerateDevices()); 333 EnumerateDevices());
339 ASSERT_EQ(4u, descriptors->size()); 334 ASSERT_EQ(4u, descriptors->size());
340 const VideoPixelFormat expected_format_by_device_index[] = { 335 const VideoPixelFormat expected_format_by_device_index[] = {
341 PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_MJPEG, 336 PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_MJPEG,
342 PIXEL_FORMAT_I420}; 337 PIXEL_FORMAT_I420};
343 338
344 int device_index = 0; 339 int device_index = 0;
345 for (const auto& descriptors_iterator : *descriptors) { 340 for (const auto& descriptors_iterator : *descriptors) {
346 VideoCaptureFormats supported_formats; 341 VideoCaptureFormats supported_formats;
(...skipping 20 matching lines...) Expand all
367 EXPECT_GE(supported_formats[3].frame_rate, 20.0); 362 EXPECT_GE(supported_formats[3].frame_rate, 20.0);
368 EXPECT_EQ(1920, supported_formats[4].frame_size.width()); 363 EXPECT_EQ(1920, supported_formats[4].frame_size.width());
369 EXPECT_EQ(1080, supported_formats[4].frame_size.height()); 364 EXPECT_EQ(1080, supported_formats[4].frame_size.height());
370 EXPECT_EQ(expected_format, supported_formats[4].pixel_format); 365 EXPECT_EQ(expected_format, supported_formats[4].pixel_format);
371 EXPECT_GE(supported_formats[4].frame_rate, 20.0); 366 EXPECT_GE(supported_formats[4].frame_rate, 20.0);
372 device_index++; 367 device_index++;
373 } 368 }
374 } 369 }
375 370
376 TEST_F(FakeVideoCaptureDeviceTest, GetCameraCalibration) { 371 TEST_F(FakeVideoCaptureDeviceTest, GetCameraCalibration) {
377 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 372 const size_t device_count = 2;
378 switches::kUseFakeDeviceForMediaStream, "device-count=2"); 373 video_capture_device_factory_->SetToDefaultDevicesConfig(device_count);
379 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 374 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
380 EnumerateDevices()); 375 EnumerateDevices());
381 ASSERT_EQ(2u, descriptors->size()); 376 ASSERT_EQ(device_count, descriptors->size());
382 ASSERT_FALSE(descriptors->at(0).camera_calibration); 377 ASSERT_FALSE(descriptors->at(0).camera_calibration);
383 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1); 378 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1);
384 EXPECT_EQ("/dev/video1", depth_device.device_id); 379 EXPECT_EQ("/dev/video1", depth_device.device_id);
385 ASSERT_TRUE(depth_device.camera_calibration); 380 ASSERT_TRUE(depth_device.camera_calibration);
386 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); 381 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x);
387 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); 382 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y);
388 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); 383 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near);
389 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); 384 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far);
390 } 385 }
391 386
387 TEST_F(FakeVideoCaptureDeviceTest, ErrorDeviceReportsError) {
388 auto device = FakeVideoCaptureDeviceFactory::CreateErrorDevice();
389 ASSERT_TRUE(device);
390 EXPECT_CALL(*client_, OnError(_, _));
391 VideoCaptureParams capture_params;
392 capture_params.requested_format.frame_size.SetSize(640, 480);
393 capture_params.requested_format.frame_rate = 30.0;
394 device->AllocateAndStart(capture_params, std::move(client_));
395 }
396
392 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { 397 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) {
393 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( 398 auto device =
394 FakeVideoCaptureDeviceMaker::PixelFormat::I420, 399 FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions(
395 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, 400 PIXEL_FORMAT_I420,
396 30.0); 401 FakeVideoCaptureDevice::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS,
402 30.0);
397 ASSERT_TRUE(device); 403 ASSERT_TRUE(device);
398 404
399 VideoCaptureParams capture_params; 405 VideoCaptureParams capture_params;
400 capture_params.requested_format.frame_size.SetSize(640, 480); 406 capture_params.requested_format.frame_size.SetSize(640, 480);
401 capture_params.requested_format.frame_rate = 30.0; 407 capture_params.requested_format.frame_rate = 30.0;
402 device->AllocateAndStart(capture_params, std::move(client_)); 408 device->AllocateAndStart(capture_params, std::move(client_));
403 409
404 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( 410 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback(
405 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities, 411 base::Bind(&ImageCaptureClient::DoOnGetPhotoCapabilities,
406 image_capture_client_), 412 image_capture_client_),
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 device->GetPhotoCapabilities(std::move(scoped_get_callback2)); 500 device->GetPhotoCapabilities(std::move(scoped_get_callback2));
495 run_loop_.reset(new base::RunLoop()); 501 run_loop_.reset(new base::RunLoop());
496 run_loop_->Run(); 502 run_loop_->Run();
497 EXPECT_EQ(max_zoom_value, 503 EXPECT_EQ(max_zoom_value,
498 image_capture_client_->capabilities()->zoom->current); 504 image_capture_client_->capabilities()->zoom->current);
499 505
500 device->StopAndDeAllocate(); 506 device->StopAndDeAllocate();
501 } 507 }
502 508
503 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { 509 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) {
504 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( 510 auto device =
505 FakeVideoCaptureDeviceMaker::PixelFormat::I420, 511 FakeVideoCaptureDeviceFactory::CreateDeviceWithDefaultResolutions(
506 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, 512 PIXEL_FORMAT_I420,
507 30.0); 513 FakeVideoCaptureDevice::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS,
514 30.0);
508 ASSERT_TRUE(device); 515 ASSERT_TRUE(device);
509 516
510 VideoCaptureParams capture_params; 517 VideoCaptureParams capture_params;
511 capture_params.requested_format.frame_size.SetSize(640, 480); 518 capture_params.requested_format.frame_size.SetSize(640, 480);
512 capture_params.requested_format.frame_rate = 30.0; 519 capture_params.requested_format.frame_rate = 30.0;
513 device->AllocateAndStart(capture_params, std::move(client_)); 520 device->AllocateAndStart(capture_params, std::move(client_));
514 521
515 VideoCaptureDevice::TakePhotoCallback scoped_callback( 522 VideoCaptureDevice::TakePhotoCallback scoped_callback(
516 base::Bind(&ImageCaptureClient::DoOnPhotoTaken, image_capture_client_), 523 base::Bind(&ImageCaptureClient::DoOnPhotoTaken, image_capture_client_),
517 base::Bind(&ImageCaptureClient::OnTakePhotoFailure, 524 base::Bind(&ImageCaptureClient::OnTakePhotoFailure,
(...skipping 11 matching lines...) Expand all
529 std::string switch_value_string; 536 std::string switch_value_string;
530 float expected_fps; 537 float expected_fps;
531 size_t expected_device_count; 538 size_t expected_device_count;
532 std::vector<VideoPixelFormat> expected_pixel_formats; 539 std::vector<VideoPixelFormat> expected_pixel_formats;
533 }; 540 };
534 541
535 class FakeVideoCaptureDeviceFactoryTest 542 class FakeVideoCaptureDeviceFactoryTest
536 : public FakeVideoCaptureDeviceBase, 543 : public FakeVideoCaptureDeviceBase,
537 public ::testing::WithParamInterface<CommandLineTestData> {}; 544 public ::testing::WithParamInterface<CommandLineTestData> {};
538 545
546 TEST_F(FakeVideoCaptureDeviceFactoryTest, DeviceWithNoSupportedFormats) {
547 std::vector<FakeVideoCaptureDeviceSettings> config;
548 FakeVideoCaptureDeviceSettings device_setting;
549 device_setting.device_id = "Device with no supported formats";
550 config.emplace_back(device_setting);
551 video_capture_device_factory_->SetToCustomDevicesConfig(config);
552
553 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
554 EnumerateDevices());
555 EXPECT_EQ(1u, descriptors->size());
556 media::VideoCaptureFormats supported_formats;
557 video_capture_device_factory_->GetSupportedFormats(descriptors->at(0),
558 &supported_formats);
559 EXPECT_EQ(0u, supported_formats.size());
560 auto device = video_capture_device_factory_->CreateDevice(descriptors->at(0));
561 EXPECT_TRUE(device.get());
562
563 auto client = CreateClient();
564 EXPECT_CALL(*client, OnError(_, _));
565 VideoCaptureParams capture_params;
566 capture_params.requested_format.frame_size.SetSize(1280, 720);
567 device->AllocateAndStart(capture_params, std::move(client));
568 }
569
539 // Tests that the FakeVideoCaptureDeviceFactory delivers the expected number 570 // Tests that the FakeVideoCaptureDeviceFactory delivers the expected number
540 // of devices and formats when being configured using command-line switches. 571 // of devices and formats when being configured using command-line switches.
541 TEST_P(FakeVideoCaptureDeviceFactoryTest, FrameRateAndDeviceCount) { 572 TEST_P(FakeVideoCaptureDeviceFactoryTest, FrameRateAndDeviceCount) {
542 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 573 std::vector<FakeVideoCaptureDeviceSettings> config;
543 switches::kUseFakeDeviceForMediaStream, GetParam().switch_value_string); 574 FakeVideoCaptureDeviceFactory::ParseFakeDevicesConfigFromOptionsString(
575 GetParam().switch_value_string, &config);
576 video_capture_device_factory_->SetToCustomDevicesConfig(config);
577
544 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 578 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
545 EnumerateDevices()); 579 EnumerateDevices());
546 EXPECT_EQ(GetParam().expected_device_count, descriptors->size()); 580 EXPECT_EQ(GetParam().expected_device_count, descriptors->size());
547 ASSERT_FALSE(descriptors->empty());
548 581
549 int device_index = 0; 582 int device_index = 0;
550 for (const auto& descriptors_iterator : *descriptors) { 583 for (const auto& descriptors_iterator : *descriptors) {
551 media::VideoCaptureFormats supported_formats; 584 media::VideoCaptureFormats supported_formats;
552 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, 585 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator,
553 &supported_formats); 586 &supported_formats);
554 for (const auto& supported_formats_entry : supported_formats) { 587 for (const auto& supported_formats_entry : supported_formats) {
555 EXPECT_EQ(GetParam().expected_pixel_formats[device_index], 588 EXPECT_EQ(GetParam().expected_pixel_formats[device_index],
556 supported_formats_entry.pixel_format); 589 supported_formats_entry.pixel_format);
557 } 590 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 4u, 632 4u,
600 633
601 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, 634 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16,
602 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, 635 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}},
603 CommandLineTestData{"device-count=4,ownership=client", 636 CommandLineTestData{"device-count=4,ownership=client",
604 20, 637 20,
605 4u, 638 4u,
606 639
607 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, 640 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16,
608 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}}, 641 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}},
609 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); 642 CommandLineTestData{"device-count=0", 20, 0u, {PIXEL_FORMAT_I420}}));
610 }; // namespace media 643 }; // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698