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

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

Issue 2983473002: Android Tango depth camera capture support.
Patch Set: Created 3 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/video_capture_device.h" 5 #include "media/capture/video/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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 last_format_ = format; 284 last_format_ = format;
285 if (run_loop_) 285 if (run_loop_)
286 run_loop_->QuitClosure().Run(); 286 run_loop_->QuitClosure().Run();
287 } 287 }
288 288
289 void WaitForCapturedFrame() { 289 void WaitForCapturedFrame() {
290 run_loop_.reset(new base::RunLoop()); 290 run_loop_.reset(new base::RunLoop());
291 run_loop_->Run(); 291 run_loop_->Run();
292 } 292 }
293 293
294 bool FindUsableDevices() { 294 std::unique_ptr<VideoCaptureDeviceDescriptor> FindUsableDeviceDescriptor() {
295 video_capture_device_factory_->GetDeviceDescriptors( 295 video_capture_device_factory_->GetDeviceDescriptors(
296 device_descriptors_.get()); 296 device_descriptors_.get());
297 297
298 #if defined(OS_ANDROID) 298 #if defined(OS_ANDROID)
299 // Android deprecated/legacy devices capture on a single thread, which is 299 // Android deprecated/legacy devices and Tango cameras capture on a single
300 // occupied by the tests, so nothing gets actually delivered. 300 // thread, which is occupied by the tests, so nothing gets actually
301 // delivered.
301 // TODO(mcasas): use those devices' test mode to deliver frames in a 302 // TODO(mcasas): use those devices' test mode to deliver frames in a
302 // background thread, https://crbug.com/626857 303 // background thread, https://crbug.com/626857
303 for (const auto& descriptor : *device_descriptors_) { 304 for (const auto& descriptor : *device_descriptors_) {
304 if (VideoCaptureDeviceFactoryAndroid::IsLegacyOrDeprecatedDevice( 305 if (!VideoCaptureDeviceFactoryAndroid::IsLegacyOrDeprecatedDevice(
305 descriptor.device_id)) { 306 descriptor.device_id) &&
306 return false; 307 descriptor.capture_api != VideoCaptureApi::ANDROID_TANGO) {
308 LOG(INFO) << "Using camera " << descriptor.display_name << " ("
309 << descriptor.model_id << ")";
310 return std::unique_ptr<VideoCaptureDeviceDescriptor>(
311 new VideoCaptureDeviceDescriptor(descriptor));
307 } 312 }
308 } 313 }
314 LOG(WARNING) << "No usable camera found";
315 return nullptr;
309 #endif 316 #endif
310 317
311 if (device_descriptors_->empty()) 318 if (device_descriptors_->empty()) {
312 LOG(WARNING) << "No camera found"; 319 LOG(WARNING) << "No camera found";
313 else { 320 return nullptr;
314 LOG(INFO) << "Using camera " << device_descriptors_->front().display_name
315 << " (" << device_descriptors_->front().model_id << ")";
316 } 321 }
317 322 LOG(INFO) << "Using camera " << device_descriptors_->front().display_name
318 return !device_descriptors_->empty(); 323 << " (" << device_descriptors_->front().model_id << ")";
324 return std::unique_ptr<VideoCaptureDeviceDescriptor>(
325 new VideoCaptureDeviceDescriptor(device_descriptors_->front()));
319 } 326 }
320 327
321 const VideoCaptureFormat& last_format() const { return last_format_; } 328 const VideoCaptureFormat& last_format() const { return last_format_; }
322 329
323 std::unique_ptr<VideoCaptureDeviceDescriptor> 330 std::unique_ptr<VideoCaptureDeviceDescriptor>
324 GetFirstDeviceDescriptorSupportingPixelFormat( 331 GetFirstDeviceDescriptorSupportingPixelFormat(
325 const VideoPixelFormat& pixel_format) { 332 const VideoPixelFormat& pixel_format) {
326 if (!FindUsableDevices()) 333 if (!FindUsableDeviceDescriptor())
327 return nullptr; 334 return nullptr;
328 335
329 for (const auto& descriptor : *device_descriptors_) { 336 for (const auto& descriptor : *device_descriptors_) {
330 VideoCaptureFormats supported_formats; 337 VideoCaptureFormats supported_formats;
331 video_capture_device_factory_->GetSupportedFormats(descriptor, 338 video_capture_device_factory_->GetSupportedFormats(descriptor,
332 &supported_formats); 339 &supported_formats);
333 for (const auto& formats_iterator : supported_formats) { 340 for (const auto& formats_iterator : supported_formats) {
334 if (formats_iterator.pixel_format == pixel_format) { 341 if (formats_iterator.pixel_format == pixel_format) {
335 return std::unique_ptr<VideoCaptureDeviceDescriptor>( 342 return std::unique_ptr<VideoCaptureDeviceDescriptor>(
336 new VideoCaptureDeviceDescriptor(descriptor)); 343 new VideoCaptureDeviceDescriptor(descriptor));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 capture_params.requested_format.frame_size.SetSize(640, 480); 410 capture_params.requested_format.frame_size.SetSize(640, 480);
404 capture_params.requested_format.frame_rate = 30; 411 capture_params.requested_format.frame_rate = 30;
405 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 412 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
406 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 413 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
407 device->StopAndDeAllocate(); 414 device->StopAndDeAllocate();
408 #endif 415 #endif
409 } 416 }
410 417
411 // Allocates the first enumerated device, and expects a frame. 418 // Allocates the first enumerated device, and expects a frame.
412 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) { 419 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) {
413 if (!FindUsableDevices()) 420 auto descriptor = FindUsableDeviceDescriptor();
421 if (!descriptor)
414 return; 422 return;
415 423
416 const gfx::Size& size = GetParam(); 424 const gfx::Size& size = GetParam();
417 if (!IsCaptureSizeSupported(device_descriptors_->front(), size)) 425 if (!IsCaptureSizeSupported(*descriptor, size))
418 return; 426 return;
419 const int width = size.width(); 427 const int width = size.width();
420 const int height = size.height(); 428 const int height = size.height();
421 429
422 std::unique_ptr<VideoCaptureDevice> device( 430 std::unique_ptr<VideoCaptureDevice> device(
423 video_capture_device_factory_->CreateDevice( 431 video_capture_device_factory_->CreateDevice(
424 device_descriptors_->front())); 432 device_descriptors_->front()));
425 ASSERT_TRUE(device); 433 ASSERT_TRUE(device);
426 434
427 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 435 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
(...skipping 16 matching lines...) Expand all
444 452
445 const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), gfx::Size(1280, 720)}; 453 const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), gfx::Size(1280, 720)};
446 454
447 INSTANTIATE_TEST_CASE_P(VideoCaptureDeviceTests, 455 INSTANTIATE_TEST_CASE_P(VideoCaptureDeviceTests,
448 VideoCaptureDeviceTest, 456 VideoCaptureDeviceTest,
449 testing::ValuesIn(kCaptureSizes)); 457 testing::ValuesIn(kCaptureSizes));
450 458
451 // Allocates a device with an uncommon resolution and verifies frames are 459 // Allocates a device with an uncommon resolution and verifies frames are
452 // captured in a close, much more typical one. 460 // captured in a close, much more typical one.
453 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { 461 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
454 if (!FindUsableDevices()) 462 auto descriptor = FindUsableDeviceDescriptor();
463 if (!descriptor)
455 return; 464 return;
456 465
457 std::unique_ptr<VideoCaptureDevice> device( 466 std::unique_ptr<VideoCaptureDevice> device(
458 video_capture_device_factory_->CreateDevice( 467 video_capture_device_factory_->CreateDevice(*descriptor));
459 device_descriptors_->front()));
460 ASSERT_TRUE(device); 468 ASSERT_TRUE(device);
461 469
462 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 470 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
463 EXPECT_CALL(*video_capture_client_, OnStarted()); 471 EXPECT_CALL(*video_capture_client_, OnStarted());
464 472
465 const gfx::Size input_size(640, 480); 473 const gfx::Size input_size(640, 480);
466 VideoCaptureParams capture_params; 474 VideoCaptureParams capture_params;
467 capture_params.requested_format.frame_size.SetSize(637, 472); 475 capture_params.requested_format.frame_size.SetSize(637, 472);
468 capture_params.requested_format.frame_rate = 35; 476 capture_params.requested_format.frame_rate = 35;
469 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 477 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
470 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 478 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
471 WaitForCapturedFrame(); 479 WaitForCapturedFrame();
472 device->StopAndDeAllocate(); 480 device->StopAndDeAllocate();
473 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); 481 EXPECT_EQ(last_format().frame_size.width(), input_size.width());
474 EXPECT_EQ(last_format().frame_size.height(), input_size.height()); 482 EXPECT_EQ(last_format().frame_size.height(), input_size.height());
475 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) 483 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG)
476 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea()); 484 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea());
477 } 485 }
478 486
479 // Cause hangs on Windows, Linux. Fails Android. https://crbug.com/417824 487 // Cause hangs on Windows, Linux. Fails Android. https://crbug.com/417824
480 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) { 488 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) {
481 if (!FindUsableDevices()) 489 auto descriptor = FindUsableDeviceDescriptor();
490 if (!descriptor)
482 return; 491 return;
483 492
484 // First, do a number of very fast device start/stops. 493 // First, do a number of very fast device start/stops.
485 for (int i = 0; i <= 5; i++) { 494 for (int i = 0; i <= 5; i++) {
486 ResetWithNewClient(); 495 ResetWithNewClient();
487 std::unique_ptr<VideoCaptureDevice> device( 496 std::unique_ptr<VideoCaptureDevice> device(
488 video_capture_device_factory_->CreateDevice( 497 video_capture_device_factory_->CreateDevice(*descriptor));
489 device_descriptors_->front()));
490 gfx::Size resolution; 498 gfx::Size resolution;
491 if (i % 2) 499 if (i % 2)
492 resolution = gfx::Size(640, 480); 500 resolution = gfx::Size(640, 480);
493 else 501 else
494 resolution = gfx::Size(1280, 1024); 502 resolution = gfx::Size(1280, 1024);
495 503
496 VideoCaptureParams capture_params; 504 VideoCaptureParams capture_params;
497 capture_params.requested_format.frame_size = resolution; 505 capture_params.requested_format.frame_size = resolution;
498 capture_params.requested_format.frame_rate = 30; 506 capture_params.requested_format.frame_rate = 30;
499 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 507 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor = 572 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor =
565 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MAX); 573 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MAX);
566 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here 574 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here
567 // since we cannot forecast the hardware capabilities. 575 // since we cannot forecast the hardware capabilities.
568 ASSERT_FALSE(device_descriptor); 576 ASSERT_FALSE(device_descriptor);
569 } 577 }
570 578
571 // Starts the camera and verifies that a photo can be taken. The correctness of 579 // Starts the camera and verifies that a photo can be taken. The correctness of
572 // the photo is enforced by MockImageCaptureClient. 580 // the photo is enforced by MockImageCaptureClient.
573 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { 581 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) {
574 if (!FindUsableDevices()) 582 auto descriptor = FindUsableDeviceDescriptor();
583 if (!descriptor)
575 return; 584 return;
576 585
577 #if defined(OS_CHROMEOS) 586 #if defined(OS_CHROMEOS)
578 // TODO(jcliang): Remove this after we implement TakePhoto. 587 // TODO(jcliang): Remove this after we implement TakePhoto.
579 if (VideoCaptureDeviceFactoryChromeOS::ShouldEnable()) { 588 if (VideoCaptureDeviceFactoryChromeOS::ShouldEnable()) {
580 return; 589 return;
581 } 590 }
582 #endif 591 #endif
583 592
584 #if defined(OS_ANDROID) 593 #if defined(OS_ANDROID)
585 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 594 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840
586 if (base::android::BuildInfo::GetInstance()->sdk_int() < 595 if (base::android::BuildInfo::GetInstance()->sdk_int() <
587 base::android::SDK_VERSION_MARSHMALLOW) { 596 base::android::SDK_VERSION_MARSHMALLOW) {
588 return; 597 return;
589 } 598 }
590 #endif 599 #endif
591 600
592 std::unique_ptr<VideoCaptureDevice> device( 601 std::unique_ptr<VideoCaptureDevice> device(
593 video_capture_device_factory_->CreateDevice( 602 video_capture_device_factory_->CreateDevice(*descriptor));
594 device_descriptors_->front()));
595 ASSERT_TRUE(device); 603 ASSERT_TRUE(device);
596 604
597 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 605 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
598 EXPECT_CALL(*video_capture_client_, OnStarted()); 606 EXPECT_CALL(*video_capture_client_, OnStarted());
599 607
600 VideoCaptureParams capture_params; 608 VideoCaptureParams capture_params;
601 capture_params.requested_format.frame_size.SetSize(320, 240); 609 capture_params.requested_format.frame_size.SetSize(320, 240);
602 capture_params.requested_format.frame_rate = 30; 610 capture_params.requested_format.frame_rate = 30;
603 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 611 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
604 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 612 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
(...skipping 11 matching lines...) Expand all
616 .WillOnce(RunClosure(quit_closure)); 624 .WillOnce(RunClosure(quit_closure));
617 625
618 device->TakePhoto(std::move(scoped_callback)); 626 device->TakePhoto(std::move(scoped_callback));
619 run_loop.Run(); 627 run_loop.Run();
620 628
621 device->StopAndDeAllocate(); 629 device->StopAndDeAllocate();
622 } 630 }
623 631
624 // Starts the camera and verifies that the photo capabilities can be retrieved. 632 // Starts the camera and verifies that the photo capabilities can be retrieved.
625 TEST_F(VideoCaptureDeviceTest, MAYBE_GetPhotoState) { 633 TEST_F(VideoCaptureDeviceTest, MAYBE_GetPhotoState) {
626 if (!FindUsableDevices()) 634 auto descriptor = FindUsableDeviceDescriptor();
635 if (!descriptor)
627 return; 636 return;
628 637
629 #if defined(OS_CHROMEOS) 638 #if defined(OS_CHROMEOS)
630 // TODO(jcliang): Remove this after we implement GetPhotoCapabilities. 639 // TODO(jcliang): Remove this after we implement GetPhotoCapabilities.
631 if (VideoCaptureDeviceFactoryChromeOS::ShouldEnable()) { 640 if (VideoCaptureDeviceFactoryChromeOS::ShouldEnable()) {
632 return; 641 return;
633 } 642 }
634 #endif 643 #endif
635 644
636 #if defined(OS_ANDROID) 645 #if defined(OS_ANDROID)
637 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 646 // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840
638 if (base::android::BuildInfo::GetInstance()->sdk_int() < 647 if (base::android::BuildInfo::GetInstance()->sdk_int() <
639 base::android::SDK_VERSION_MARSHMALLOW) { 648 base::android::SDK_VERSION_MARSHMALLOW) {
640 return; 649 return;
641 } 650 }
642 #endif 651 #endif
643 652
644 std::unique_ptr<VideoCaptureDevice> device( 653 std::unique_ptr<VideoCaptureDevice> device(
645 video_capture_device_factory_->CreateDevice( 654 video_capture_device_factory_->CreateDevice(*descriptor));
646 device_descriptors_->front()));
647 ASSERT_TRUE(device); 655 ASSERT_TRUE(device);
648 656
649 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 657 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
650 EXPECT_CALL(*video_capture_client_, OnStarted()); 658 EXPECT_CALL(*video_capture_client_, OnStarted());
651 659
652 VideoCaptureParams capture_params; 660 VideoCaptureParams capture_params;
653 capture_params.requested_format.frame_size.SetSize(320, 240); 661 capture_params.requested_format.frame_size.SetSize(320, 240);
654 capture_params.requested_format.frame_rate = 30; 662 capture_params.requested_format.frame_rate = 30;
655 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 663 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
656 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 664 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
(...skipping 13 matching lines...) Expand all
670 678
671 device->GetPhotoState(std::move(scoped_get_callback)); 679 device->GetPhotoState(std::move(scoped_get_callback));
672 run_loop.Run(); 680 run_loop.Run();
673 681
674 ASSERT_TRUE(image_capture_client_->capabilities()); 682 ASSERT_TRUE(image_capture_client_->capabilities());
675 683
676 device->StopAndDeAllocate(); 684 device->StopAndDeAllocate();
677 } 685 }
678 686
679 }; // namespace media 687 }; // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698