OLD | NEW |
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 "content/browser/media/capture/web_contents_video_capture_device.h" | 5 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/debug/debugger.h" | 8 #include "base/debug/debugger.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) { | 637 TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) { |
638 // Before the installs itself on the UI thread up to start capturing, we'll | 638 // Before the installs itself on the UI thread up to start capturing, we'll |
639 // delete the web contents. This should trigger an error which can happen in | 639 // delete the web contents. This should trigger an error which can happen in |
640 // practice; we should be able to recover gracefully. | 640 // practice; we should be able to recover gracefully. |
641 ResetWebContents(); | 641 ResetWebContents(); |
642 | 642 |
643 media::VideoCaptureParams capture_params; | 643 media::VideoCaptureParams capture_params; |
644 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); | 644 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); |
645 capture_params.requested_format.frame_rate = kTestFramesPerSecond; | 645 capture_params.requested_format.frame_rate = kTestFramesPerSecond; |
646 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 646 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
647 capture_params.allow_resolution_change = false; | |
648 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); | 647 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); |
649 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); | 648 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); |
650 device()->StopAndDeAllocate(); | 649 device()->StopAndDeAllocate(); |
651 } | 650 } |
652 | 651 |
653 TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) { | 652 TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) { |
654 const gfx::Size capture_preferred_size( | 653 const gfx::Size capture_preferred_size( |
655 static_cast<int>(kTestWidth / kTestDeviceScaleFactor), | 654 static_cast<int>(kTestWidth / kTestDeviceScaleFactor), |
656 static_cast<int>(kTestHeight / kTestDeviceScaleFactor)); | 655 static_cast<int>(kTestHeight / kTestDeviceScaleFactor)); |
657 ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize()); | 656 ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize()); |
658 | 657 |
659 // We'll simulate the tab being closed after the capture pipeline is up and | 658 // We'll simulate the tab being closed after the capture pipeline is up and |
660 // running. | 659 // running. |
661 media::VideoCaptureParams capture_params; | 660 media::VideoCaptureParams capture_params; |
662 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); | 661 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); |
663 capture_params.requested_format.frame_rate = kTestFramesPerSecond; | 662 capture_params.requested_format.frame_rate = kTestFramesPerSecond; |
664 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 663 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
665 capture_params.allow_resolution_change = false; | |
666 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); | 664 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); |
667 // Do one capture to prove | 665 // Do one capture to prove |
668 source()->SetSolidColor(SK_ColorRED); | 666 source()->SetSolidColor(SK_ColorRED); |
669 SimulateDrawEvent(); | 667 SimulateDrawEvent(); |
670 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 668 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
671 | 669 |
672 base::RunLoop().RunUntilIdle(); | 670 base::RunLoop().RunUntilIdle(); |
673 | 671 |
674 // Check that the preferred size of the WebContents matches the one provided | 672 // Check that the preferred size of the WebContents matches the one provided |
675 // by WebContentsVideoCaptureDevice. | 673 // by WebContentsVideoCaptureDevice. |
676 EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize()); | 674 EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize()); |
677 | 675 |
678 // Post a task to close the tab. We should see an error reported to the | 676 // Post a task to close the tab. We should see an error reported to the |
679 // consumer. | 677 // consumer. |
680 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 678 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
681 base::Bind(&WebContentsVideoCaptureDeviceTest::ResetWebContents, | 679 base::Bind(&WebContentsVideoCaptureDeviceTest::ResetWebContents, |
682 base::Unretained(this))); | 680 base::Unretained(this))); |
683 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); | 681 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); |
684 device()->StopAndDeAllocate(); | 682 device()->StopAndDeAllocate(); |
685 } | 683 } |
686 | 684 |
687 TEST_F(WebContentsVideoCaptureDeviceTest, | 685 TEST_F(WebContentsVideoCaptureDeviceTest, |
688 StopDeviceBeforeCaptureMachineCreation) { | 686 StopDeviceBeforeCaptureMachineCreation) { |
689 media::VideoCaptureParams capture_params; | 687 media::VideoCaptureParams capture_params; |
690 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); | 688 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); |
691 capture_params.requested_format.frame_rate = kTestFramesPerSecond; | 689 capture_params.requested_format.frame_rate = kTestFramesPerSecond; |
692 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 690 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
693 capture_params.allow_resolution_change = false; | |
694 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); | 691 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); |
695 | 692 |
696 // Make a point of not running the UI messageloop here. | 693 // Make a point of not running the UI messageloop here. |
697 device()->StopAndDeAllocate(); | 694 device()->StopAndDeAllocate(); |
698 DestroyVideoCaptureDevice(); | 695 DestroyVideoCaptureDevice(); |
699 | 696 |
700 // Currently, there should be CreateCaptureMachineOnUIThread() and | 697 // Currently, there should be CreateCaptureMachineOnUIThread() and |
701 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message | 698 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message |
702 // loop. These should both succeed without crashing, and the machine should | 699 // loop. These should both succeed without crashing, and the machine should |
703 // wind up in the idle state. | 700 // wind up in the idle state. |
704 base::RunLoop().RunUntilIdle(); | 701 base::RunLoop().RunUntilIdle(); |
705 } | 702 } |
706 | 703 |
707 TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { | 704 TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { |
708 // Set up the test to use RGB copies and an normal | 705 // Set up the test to use RGB copies and an normal |
709 source()->SetCanCopyToVideoFrame(false); | 706 source()->SetCanCopyToVideoFrame(false); |
710 source()->SetUseFrameSubscriber(false); | 707 source()->SetUseFrameSubscriber(false); |
711 media::VideoCaptureParams capture_params; | 708 media::VideoCaptureParams capture_params; |
712 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); | 709 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); |
713 capture_params.requested_format.frame_rate = kTestFramesPerSecond; | 710 capture_params.requested_format.frame_rate = kTestFramesPerSecond; |
714 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 711 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
715 capture_params.allow_resolution_change = false; | |
716 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); | 712 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); |
717 | 713 |
718 base::RunLoop().RunUntilIdle(); | 714 base::RunLoop().RunUntilIdle(); |
719 | 715 |
720 for (int i = 0; i < 10; ++i) | 716 for (int i = 0; i < 10; ++i) |
721 SimulateDrawEvent(); | 717 SimulateDrawEvent(); |
722 | 718 |
723 ASSERT_FALSE(client_observer()->HasError()); | 719 ASSERT_FALSE(client_observer()->HasError()); |
724 device()->StopAndDeAllocate(); | 720 device()->StopAndDeAllocate(); |
725 ASSERT_FALSE(client_observer()->HasError()); | 721 ASSERT_FALSE(client_observer()->HasError()); |
726 base::RunLoop().RunUntilIdle(); | 722 base::RunLoop().RunUntilIdle(); |
727 ASSERT_FALSE(client_observer()->HasError()); | 723 ASSERT_FALSE(client_observer()->HasError()); |
728 } | 724 } |
729 | 725 |
730 TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) { | 726 TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) { |
731 media::VideoCaptureParams capture_params; | 727 media::VideoCaptureParams capture_params; |
732 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); | 728 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); |
733 capture_params.requested_format.frame_rate = kTestFramesPerSecond; | 729 capture_params.requested_format.frame_rate = kTestFramesPerSecond; |
734 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 730 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
735 capture_params.allow_resolution_change = false; | |
736 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); | 731 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); |
737 base::RunLoop().RunUntilIdle(); | 732 base::RunLoop().RunUntilIdle(); |
738 source()->SetSolidColor(SK_ColorRED); | 733 source()->SetSolidColor(SK_ColorRED); |
739 SimulateDrawEvent(); | 734 SimulateDrawEvent(); |
740 SimulateDrawEvent(); | 735 SimulateDrawEvent(); |
741 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 736 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
742 SimulateDrawEvent(); | 737 SimulateDrawEvent(); |
743 SimulateDrawEvent(); | 738 SimulateDrawEvent(); |
744 source()->SetSolidColor(SK_ColorGREEN); | 739 source()->SetSolidColor(SK_ColorGREEN); |
745 SimulateDrawEvent(); | 740 SimulateDrawEvent(); |
(...skipping 18 matching lines...) Expand all Loading... |
764 | 759 |
765 // The "happy case" test. No scaling is needed, so we should be able to change | 760 // The "happy case" test. No scaling is needed, so we should be able to change |
766 // the picture emitted from the source and expect to see each delivered to the | 761 // the picture emitted from the source and expect to see each delivered to the |
767 // consumer. The test will alternate between the three capture paths, simulating | 762 // consumer. The test will alternate between the three capture paths, simulating |
768 // falling in and out of accelerated compositing. | 763 // falling in and out of accelerated compositing. |
769 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { | 764 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { |
770 media::VideoCaptureParams capture_params; | 765 media::VideoCaptureParams capture_params; |
771 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); | 766 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); |
772 capture_params.requested_format.frame_rate = kTestFramesPerSecond; | 767 capture_params.requested_format.frame_rate = kTestFramesPerSecond; |
773 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 768 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
774 capture_params.allow_resolution_change = false; | |
775 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); | 769 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); |
776 | 770 |
777 for (int i = 0; i < 6; i++) { | 771 for (int i = 0; i < 6; i++) { |
778 const char* name = NULL; | 772 const char* name = NULL; |
779 switch (i % 3) { | 773 switch (i % 3) { |
780 case 0: | 774 case 0: |
781 source()->SetCanCopyToVideoFrame(true); | 775 source()->SetCanCopyToVideoFrame(true); |
782 source()->SetUseFrameSubscriber(false); | 776 source()->SetUseFrameSubscriber(false); |
783 name = "VideoFrame"; | 777 name = "VideoFrame"; |
784 break; | 778 break; |
(...skipping 30 matching lines...) Expand all Loading... |
815 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLACK)); | 809 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLACK)); |
816 } | 810 } |
817 device()->StopAndDeAllocate(); | 811 device()->StopAndDeAllocate(); |
818 } | 812 } |
819 | 813 |
820 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) { | 814 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) { |
821 media::VideoCaptureParams capture_params; | 815 media::VideoCaptureParams capture_params; |
822 capture_params.requested_format.frame_size.SetSize(1280, 720); | 816 capture_params.requested_format.frame_size.SetSize(1280, 720); |
823 capture_params.requested_format.frame_rate = -2; | 817 capture_params.requested_format.frame_rate = -2; |
824 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 818 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
825 capture_params.allow_resolution_change = false; | |
826 BrowserThread::PostTask( | 819 BrowserThread::PostTask( |
827 BrowserThread::UI, | 820 BrowserThread::UI, |
828 FROM_HERE, | 821 FROM_HERE, |
829 base::Bind(&media::VideoCaptureDevice::AllocateAndStart, | 822 base::Bind(&media::VideoCaptureDevice::AllocateAndStart, |
830 base::Unretained(device()), | 823 base::Unretained(device()), |
831 capture_params, | 824 capture_params, |
832 base::Passed(client_observer()->PassClient()))); | 825 base::Passed(client_observer()->PassClient()))); |
833 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); | 826 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); |
834 BrowserThread::PostTask( | 827 BrowserThread::PostTask( |
835 BrowserThread::UI, | 828 BrowserThread::UI, |
836 FROM_HERE, | 829 FROM_HERE, |
837 base::Bind(&media::VideoCaptureDevice::StopAndDeAllocate, | 830 base::Bind(&media::VideoCaptureDevice::StopAndDeAllocate, |
838 base::Unretained(device()))); | 831 base::Unretained(device()))); |
839 base::RunLoop().RunUntilIdle(); | 832 base::RunLoop().RunUntilIdle(); |
840 } | 833 } |
841 | 834 |
842 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) { | 835 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) { |
843 media::VideoCaptureParams capture_params; | 836 media::VideoCaptureParams capture_params; |
844 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); | 837 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); |
845 capture_params.requested_format.frame_rate = kTestFramesPerSecond; | 838 capture_params.requested_format.frame_rate = kTestFramesPerSecond; |
846 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 839 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
847 capture_params.allow_resolution_change = false; | |
848 // 1x1 is too small to process; we intend for this to result in an error. | 840 // 1x1 is too small to process; we intend for this to result in an error. |
849 source()->SetCopyResultSize(1, 1); | 841 source()->SetCopyResultSize(1, 1); |
850 source()->SetSolidColor(SK_ColorRED); | 842 source()->SetSolidColor(SK_ColorRED); |
851 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); | 843 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); |
852 | 844 |
853 // These frames ought to be dropped during the Render stage. Let | 845 // These frames ought to be dropped during the Render stage. Let |
854 // several captures to happen. | 846 // several captures to happen. |
855 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); | 847 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); |
856 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); | 848 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); |
857 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); | 849 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); |
858 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); | 850 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); |
859 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); | 851 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); |
860 | 852 |
861 // Now push some good frames through; they should be processed normally. | 853 // Now push some good frames through; they should be processed normally. |
862 source()->SetCopyResultSize(kTestWidth, kTestHeight); | 854 source()->SetCopyResultSize(kTestWidth, kTestHeight); |
863 source()->SetSolidColor(SK_ColorGREEN); | 855 source()->SetSolidColor(SK_ColorGREEN); |
864 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 856 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
865 source()->SetSolidColor(SK_ColorRED); | 857 source()->SetSolidColor(SK_ColorRED); |
866 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 858 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
867 | 859 |
868 device()->StopAndDeAllocate(); | 860 device()->StopAndDeAllocate(); |
869 } | 861 } |
870 | 862 |
871 } // namespace | 863 } // namespace |
872 } // namespace content | 864 } // namespace content |
OLD | NEW |