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

Side by Side Diff: content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc

Issue 83633008: Reland: Reorganize media::VideoCapture* types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
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 "content/browser/renderer_host/media/web_contents_video_capture_device. h" 5 #include "content/browser/renderer_host/media/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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 new PoolBuffer(buffer_pool_, buffer_id, data, size)); 332 new PoolBuffer(buffer_pool_, buffer_id, data, size));
333 } 333 }
334 334
335 virtual void OnIncomingCapturedFrame( 335 virtual void OnIncomingCapturedFrame(
336 const uint8* data, 336 const uint8* data,
337 int length, 337 int length,
338 base::Time timestamp, 338 base::Time timestamp,
339 int rotation, 339 int rotation,
340 bool flip_vert, 340 bool flip_vert,
341 bool flip_horiz, 341 bool flip_horiz,
342 const media::VideoCaptureCapability& frame_info) OVERRIDE { 342 const media::VideoCaptureFormat& frame_format) OVERRIDE {
343 FAIL(); 343 FAIL();
344 } 344 }
345 345
346 virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, 346 virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer,
347 media::VideoFrame::Format format, 347 media::VideoFrame::Format format,
348 const gfx::Size& dimensions, 348 const gfx::Size& dimensions,
349 base::Time timestamp, 349 base::Time timestamp,
350 int frame_rate) OVERRIDE { 350 int frame_rate) OVERRIDE {
351 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), dimensions); 351 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), dimensions);
352 EXPECT_EQ(media::VideoFrame::I420, format); 352 EXPECT_EQ(media::VideoFrame::I420, format);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 587
588 TestBrowserThreadBundle thread_bundle_; 588 TestBrowserThreadBundle thread_bundle_;
589 }; 589 };
590 590
591 TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) { 591 TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) {
592 // Before the installs itself on the UI thread up to start capturing, we'll 592 // Before the installs itself on the UI thread up to start capturing, we'll
593 // delete the web contents. This should trigger an error which can happen in 593 // delete the web contents. This should trigger an error which can happen in
594 // practice; we should be able to recover gracefully. 594 // practice; we should be able to recover gracefully.
595 ResetWebContents(); 595 ResetWebContents();
596 596
597 media::VideoCaptureCapability capture_format( 597 media::VideoCaptureParams capture_params;
598 kTestWidth, 598 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
599 kTestHeight, 599 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
600 kTestFramesPerSecond, 600 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
601 media::PIXEL_FORMAT_I420, 601 capture_params.allow_resolution_change = false;
602 media::ConstantResolutionVideoCaptureDevice); 602 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
603 device()->AllocateAndStart(
604 capture_format, client_observer()->PassClient());
605 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); 603 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError());
606 device()->StopAndDeAllocate(); 604 device()->StopAndDeAllocate();
607 } 605 }
608 606
609 TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) { 607 TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) {
610 // We'll simulate the tab being closed after the capture pipeline is up and 608 // We'll simulate the tab being closed after the capture pipeline is up and
611 // running. 609 // running.
612 media::VideoCaptureCapability capture_format( 610 media::VideoCaptureParams capture_params;
613 kTestWidth, 611 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
614 kTestHeight, 612 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
615 kTestFramesPerSecond, 613 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
616 media::PIXEL_FORMAT_I420, 614 capture_params.allow_resolution_change = false;
617 media::ConstantResolutionVideoCaptureDevice); 615 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
618 device()->AllocateAndStart(
619 capture_format, client_observer()->PassClient());
620 // Do one capture to prove 616 // Do one capture to prove
621 source()->SetSolidColor(SK_ColorRED); 617 source()->SetSolidColor(SK_ColorRED);
622 SimulateDrawEvent(); 618 SimulateDrawEvent();
623 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); 619 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED));
624 620
625 base::RunLoop().RunUntilIdle(); 621 base::RunLoop().RunUntilIdle();
626 622
627 // Post a task to close the tab. We should see an error reported to the 623 // Post a task to close the tab. We should see an error reported to the
628 // consumer. 624 // consumer.
629 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 625 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
630 base::Bind(&WebContentsVideoCaptureDeviceTest::ResetWebContents, 626 base::Bind(&WebContentsVideoCaptureDeviceTest::ResetWebContents,
631 base::Unretained(this))); 627 base::Unretained(this)));
632 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); 628 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError());
633 device()->StopAndDeAllocate(); 629 device()->StopAndDeAllocate();
634 } 630 }
635 631
636 TEST_F(WebContentsVideoCaptureDeviceTest, 632 TEST_F(WebContentsVideoCaptureDeviceTest,
637 StopDeviceBeforeCaptureMachineCreation) { 633 StopDeviceBeforeCaptureMachineCreation) {
638 media::VideoCaptureCapability capture_format( 634 media::VideoCaptureParams capture_params;
639 kTestWidth, 635 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
640 kTestHeight, 636 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
641 kTestFramesPerSecond, 637 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
642 media::PIXEL_FORMAT_I420, 638 capture_params.allow_resolution_change = false;
643 media::ConstantResolutionVideoCaptureDevice); 639 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
644 device()->AllocateAndStart(
645 capture_format, client_observer()->PassClient());
646 640
647 // Make a point of not running the UI messageloop here. 641 // Make a point of not running the UI messageloop here.
648 device()->StopAndDeAllocate(); 642 device()->StopAndDeAllocate();
649 DestroyVideoCaptureDevice(); 643 DestroyVideoCaptureDevice();
650 644
651 // Currently, there should be CreateCaptureMachineOnUIThread() and 645 // Currently, there should be CreateCaptureMachineOnUIThread() and
652 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message 646 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message
653 // loop. These should both succeed without crashing, and the machine should 647 // loop. These should both succeed without crashing, and the machine should
654 // wind up in the idle state. 648 // wind up in the idle state.
655 base::RunLoop().RunUntilIdle(); 649 base::RunLoop().RunUntilIdle();
656 } 650 }
657 651
658 TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { 652 TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) {
659 // Set up the test to use RGB copies and an normal 653 // Set up the test to use RGB copies and an normal
660 source()->SetCanCopyToVideoFrame(false); 654 source()->SetCanCopyToVideoFrame(false);
661 source()->SetUseFrameSubscriber(false); 655 source()->SetUseFrameSubscriber(false);
662 media::VideoCaptureCapability capture_format( 656 media::VideoCaptureParams capture_params;
663 kTestWidth, 657 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
664 kTestHeight, 658 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
665 kTestFramesPerSecond, 659 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
666 media::PIXEL_FORMAT_I420, 660 capture_params.allow_resolution_change = false;
667 media::ConstantResolutionVideoCaptureDevice); 661 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
668 device()->AllocateAndStart(
669 capture_format, client_observer()->PassClient());
670 662
671 base::RunLoop().RunUntilIdle(); 663 base::RunLoop().RunUntilIdle();
672 664
673 for (int i = 0; i < 10; ++i) 665 for (int i = 0; i < 10; ++i)
674 SimulateDrawEvent(); 666 SimulateDrawEvent();
675 667
676 ASSERT_FALSE(client_observer()->HasError()); 668 ASSERT_FALSE(client_observer()->HasError());
677 device()->StopAndDeAllocate(); 669 device()->StopAndDeAllocate();
678 ASSERT_FALSE(client_observer()->HasError()); 670 ASSERT_FALSE(client_observer()->HasError());
679 base::RunLoop().RunUntilIdle(); 671 base::RunLoop().RunUntilIdle();
680 ASSERT_FALSE(client_observer()->HasError()); 672 ASSERT_FALSE(client_observer()->HasError());
681 } 673 }
682 674
683 TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) { 675 TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) {
684 media::VideoCaptureCapability capture_format( 676 media::VideoCaptureParams capture_params;
685 kTestWidth, 677 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
686 kTestHeight, 678 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
687 kTestFramesPerSecond, 679 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
688 media::PIXEL_FORMAT_I420, 680 capture_params.allow_resolution_change = false;
689 media::ConstantResolutionVideoCaptureDevice); 681 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
690 device()->AllocateAndStart(
691 capture_format, client_observer()->PassClient());
692 base::RunLoop().RunUntilIdle(); 682 base::RunLoop().RunUntilIdle();
693 source()->SetSolidColor(SK_ColorRED); 683 source()->SetSolidColor(SK_ColorRED);
694 SimulateDrawEvent(); 684 SimulateDrawEvent();
695 SimulateDrawEvent(); 685 SimulateDrawEvent();
696 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); 686 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED));
697 SimulateDrawEvent(); 687 SimulateDrawEvent();
698 SimulateDrawEvent(); 688 SimulateDrawEvent();
699 source()->SetSolidColor(SK_ColorGREEN); 689 source()->SetSolidColor(SK_ColorGREEN);
700 SimulateDrawEvent(); 690 SimulateDrawEvent();
701 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); 691 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN));
702 device()->StopAndDeAllocate(); 692 device()->StopAndDeAllocate();
703 693
704 // Device is stopped, but content can still be animating. 694 // Device is stopped, but content can still be animating.
705 SimulateDrawEvent(); 695 SimulateDrawEvent();
706 SimulateDrawEvent(); 696 SimulateDrawEvent();
707 base::RunLoop().RunUntilIdle(); 697 base::RunLoop().RunUntilIdle();
708 698
709 StubClientObserver observer2; 699 StubClientObserver observer2;
710 device()->AllocateAndStart(capture_format, observer2.PassClient()); 700 device()->AllocateAndStart(capture_params, observer2.PassClient());
711 source()->SetSolidColor(SK_ColorBLUE); 701 source()->SetSolidColor(SK_ColorBLUE);
712 SimulateDrawEvent(); 702 SimulateDrawEvent();
713 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorBLUE)); 703 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorBLUE));
714 source()->SetSolidColor(SK_ColorYELLOW); 704 source()->SetSolidColor(SK_ColorYELLOW);
715 SimulateDrawEvent(); 705 SimulateDrawEvent();
716 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorYELLOW)); 706 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorYELLOW));
717 device()->StopAndDeAllocate(); 707 device()->StopAndDeAllocate();
718 } 708 }
719 709
720 // The "happy case" test. No scaling is needed, so we should be able to change 710 // The "happy case" test. No scaling is needed, so we should be able to change
721 // the picture emitted from the source and expect to see each delivered to the 711 // the picture emitted from the source and expect to see each delivered to the
722 // consumer. The test will alternate between the three capture paths, simulating 712 // consumer. The test will alternate between the three capture paths, simulating
723 // falling in and out of accelerated compositing. 713 // falling in and out of accelerated compositing.
724 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { 714 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) {
725 media::VideoCaptureCapability capture_format( 715 media::VideoCaptureParams capture_params;
726 kTestWidth, 716 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
727 kTestHeight, 717 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
728 kTestFramesPerSecond, 718 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
729 media::PIXEL_FORMAT_I420, 719 capture_params.allow_resolution_change = false;
730 media::ConstantResolutionVideoCaptureDevice); 720 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
731 device()->AllocateAndStart(
732 capture_format, client_observer()->PassClient());
733 721
734 for (int i = 0; i < 6; i++) { 722 for (int i = 0; i < 6; i++) {
735 const char* name = NULL; 723 const char* name = NULL;
736 switch (i % 3) { 724 switch (i % 3) {
737 case 0: 725 case 0:
738 source()->SetCanCopyToVideoFrame(true); 726 source()->SetCanCopyToVideoFrame(true);
739 source()->SetUseFrameSubscriber(false); 727 source()->SetUseFrameSubscriber(false);
740 name = "VideoFrame"; 728 name = "VideoFrame";
741 break; 729 break;
742 case 1: 730 case 1:
(...skipping 25 matching lines...) Expand all
768 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLUE)); 756 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLUE));
769 757
770 source()->SetSolidColor(SK_ColorBLACK); 758 source()->SetSolidColor(SK_ColorBLACK);
771 SimulateDrawEvent(); 759 SimulateDrawEvent();
772 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLACK)); 760 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLACK));
773 } 761 }
774 device()->StopAndDeAllocate(); 762 device()->StopAndDeAllocate();
775 } 763 }
776 764
777 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) { 765 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) {
778 media::VideoCaptureCapability capture_format( 766 media::VideoCaptureParams capture_params;
779 1280, 767 capture_params.requested_format.frame_size.SetSize(1280, 720);
780 720, 768 capture_params.requested_format.frame_rate = -2;
781 -2, 769 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
782 media::PIXEL_FORMAT_I420, 770 capture_params.allow_resolution_change = false;
783 media::ConstantResolutionVideoCaptureDevice);
784 BrowserThread::PostTask( 771 BrowserThread::PostTask(
785 BrowserThread::UI, 772 BrowserThread::UI,
786 FROM_HERE, 773 FROM_HERE,
787 base::Bind(&media::VideoCaptureDevice::AllocateAndStart, 774 base::Bind(&media::VideoCaptureDevice::AllocateAndStart,
788 base::Unretained(device()), 775 base::Unretained(device()),
789 capture_format, 776 capture_params,
790 base::Passed(client_observer()->PassClient()))); 777 base::Passed(client_observer()->PassClient())));
791 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); 778 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError());
792 BrowserThread::PostTask( 779 BrowserThread::PostTask(
793 BrowserThread::UI, 780 BrowserThread::UI,
794 FROM_HERE, 781 FROM_HERE,
795 base::Bind(&media::VideoCaptureDevice::StopAndDeAllocate, 782 base::Bind(&media::VideoCaptureDevice::StopAndDeAllocate,
796 base::Unretained(device()))); 783 base::Unretained(device())));
797 base::RunLoop().RunUntilIdle(); 784 base::RunLoop().RunUntilIdle();
798 } 785 }
799 786
800 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) { 787 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) {
801 media::VideoCaptureCapability capture_format( 788 media::VideoCaptureParams capture_params;
802 kTestWidth, 789 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
803 kTestHeight, 790 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
804 kTestFramesPerSecond, 791 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
805 media::PIXEL_FORMAT_I420, 792 capture_params.allow_resolution_change = false;
806 media::ConstantResolutionVideoCaptureDevice);
807 // 1x1 is too small to process; we intend for this to result in an error. 793 // 1x1 is too small to process; we intend for this to result in an error.
808 source()->SetCopyResultSize(1, 1); 794 source()->SetCopyResultSize(1, 1);
809 source()->SetSolidColor(SK_ColorRED); 795 source()->SetSolidColor(SK_ColorRED);
810 device()->AllocateAndStart( 796 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
811 capture_format, client_observer()->PassClient());
812 797
813 // These frames ought to be dropped during the Render stage. Let 798 // These frames ought to be dropped during the Render stage. Let
814 // several captures to happen. 799 // several captures to happen.
815 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); 800 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
816 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); 801 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
817 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); 802 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
818 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); 803 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
819 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); 804 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
820 805
821 // Now push some good frames through; they should be processed normally. 806 // Now push some good frames through; they should be processed normally.
822 source()->SetCopyResultSize(kTestWidth, kTestHeight); 807 source()->SetCopyResultSize(kTestWidth, kTestHeight);
823 source()->SetSolidColor(SK_ColorGREEN); 808 source()->SetSolidColor(SK_ColorGREEN);
824 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); 809 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN));
825 source()->SetSolidColor(SK_ColorRED); 810 source()->SetSolidColor(SK_ColorRED);
826 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); 811 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED));
827 812
828 device()->StopAndDeAllocate(); 813 device()->StopAndDeAllocate();
829 } 814 }
830 815
831 } // namespace 816 } // namespace
832 } // namespace content 817 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/web_contents_video_capture_device.cc ('k') | content/common/media/media_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698