| 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/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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 base::AutoLock guard(lock_); | 398 base::AutoLock guard(lock_); |
| 399 error_encountered_ = true; | 399 error_encountered_ = true; |
| 400 } | 400 } |
| 401 PostColorOrError(kNothingYet); | 401 PostColorOrError(kNothingYet); |
| 402 } | 402 } |
| 403 | 403 |
| 404 virtual void OnFrameInfo(const media::VideoCaptureCapability& info) OVERRIDE { | 404 virtual void OnFrameInfo(const media::VideoCaptureCapability& info) OVERRIDE { |
| 405 EXPECT_EQ(kTestWidth, info.width); | 405 EXPECT_EQ(kTestWidth, info.width); |
| 406 EXPECT_EQ(kTestHeight, info.height); | 406 EXPECT_EQ(kTestHeight, info.height); |
| 407 EXPECT_EQ(kTestFramesPerSecond, info.frame_rate); | 407 EXPECT_EQ(kTestFramesPerSecond, info.frame_rate); |
| 408 EXPECT_EQ(media::VideoCaptureCapability::kI420, info.color); | 408 EXPECT_EQ(media::kI420, info.color); |
| 409 } | 409 } |
| 410 | 410 |
| 411 private: | 411 private: |
| 412 base::Lock lock_; | 412 base::Lock lock_; |
| 413 bool error_encountered_; | 413 bool error_encountered_; |
| 414 SkColor wait_color_yuv_; | 414 SkColor wait_color_yuv_; |
| 415 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 415 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 416 | 416 |
| 417 DISALLOW_COPY_AND_ASSIGN(StubConsumer); | 417 DISALLOW_COPY_AND_ASSIGN(StubConsumer); |
| 418 }; | 418 }; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) { | 538 TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) { |
| 539 // Before the installs itself on the UI thread up to start capturing, we'll | 539 // Before the installs itself on the UI thread up to start capturing, we'll |
| 540 // delete the web contents. This should trigger an error which can happen in | 540 // delete the web contents. This should trigger an error which can happen in |
| 541 // practice; we should be able to recover gracefully. | 541 // practice; we should be able to recover gracefully. |
| 542 ResetWebContents(); | 542 ResetWebContents(); |
| 543 | 543 |
| 544 media::VideoCaptureCapability capture_format( | 544 media::VideoCaptureCapability capture_format( |
| 545 kTestWidth, | 545 kTestWidth, |
| 546 kTestHeight, | 546 kTestHeight, |
| 547 kTestFramesPerSecond, | 547 kTestFramesPerSecond, |
| 548 media::VideoCaptureCapability::kI420, | 548 media::kI420, |
| 549 0, | 549 0, |
| 550 false, | 550 false, |
| 551 media::ConstantResolutionVideoCaptureDevice); | 551 media::ConstantResolutionVideoCaptureDevice); |
| 552 device()->Allocate(capture_format, consumer()); | 552 device()->Allocate(capture_format, consumer()); |
| 553 device()->Start(); | 553 device()->Start(); |
| 554 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError()); | 554 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError()); |
| 555 device()->DeAllocate(); | 555 device()->DeAllocate(); |
| 556 } | 556 } |
| 557 | 557 |
| 558 TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) { | 558 TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) { |
| 559 // We'll simulate the tab being closed after the capture pipeline is up and | 559 // We'll simulate the tab being closed after the capture pipeline is up and |
| 560 // running. | 560 // running. |
| 561 media::VideoCaptureCapability capture_format( | 561 media::VideoCaptureCapability capture_format( |
| 562 kTestWidth, | 562 kTestWidth, |
| 563 kTestHeight, | 563 kTestHeight, |
| 564 kTestFramesPerSecond, | 564 kTestFramesPerSecond, |
| 565 media::VideoCaptureCapability::kI420, | 565 media::kI420, |
| 566 0, | 566 0, |
| 567 false, | 567 false, |
| 568 media::ConstantResolutionVideoCaptureDevice); | 568 media::ConstantResolutionVideoCaptureDevice); |
| 569 device()->Allocate(capture_format, consumer()); | 569 device()->Allocate(capture_format, consumer()); |
| 570 device()->Start(); | 570 device()->Start(); |
| 571 | 571 |
| 572 // Do one capture to prove | 572 // Do one capture to prove |
| 573 source()->SetSolidColor(SK_ColorRED); | 573 source()->SetSolidColor(SK_ColorRED); |
| 574 SimulateDrawEvent(); | 574 SimulateDrawEvent(); |
| 575 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); | 575 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); |
| 576 | 576 |
| 577 base::RunLoop().RunUntilIdle(); | 577 base::RunLoop().RunUntilIdle(); |
| 578 | 578 |
| 579 // Post a task to close the tab. We should see an error reported to the | 579 // Post a task to close the tab. We should see an error reported to the |
| 580 // consumer. | 580 // consumer. |
| 581 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 581 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 582 base::Bind(&WebContentsVideoCaptureDeviceTest::ResetWebContents, | 582 base::Bind(&WebContentsVideoCaptureDeviceTest::ResetWebContents, |
| 583 base::Unretained(this))); | 583 base::Unretained(this))); |
| 584 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError()); | 584 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError()); |
| 585 device()->DeAllocate(); | 585 device()->DeAllocate(); |
| 586 } | 586 } |
| 587 | 587 |
| 588 TEST_F(WebContentsVideoCaptureDeviceTest, | 588 TEST_F(WebContentsVideoCaptureDeviceTest, |
| 589 StopDeviceBeforeCaptureMachineCreation) { | 589 StopDeviceBeforeCaptureMachineCreation) { |
| 590 media::VideoCaptureCapability capture_format( | 590 media::VideoCaptureCapability capture_format( |
| 591 kTestWidth, | 591 kTestWidth, |
| 592 kTestHeight, | 592 kTestHeight, |
| 593 kTestFramesPerSecond, | 593 kTestFramesPerSecond, |
| 594 media::VideoCaptureCapability::kI420, | 594 media::kI420, |
| 595 0, | 595 0, |
| 596 false, | 596 false, |
| 597 media::ConstantResolutionVideoCaptureDevice); | 597 media::ConstantResolutionVideoCaptureDevice); |
| 598 device()->Allocate(capture_format, consumer()); | 598 device()->Allocate(capture_format, consumer()); |
| 599 device()->Start(); | 599 device()->Start(); |
| 600 // Make a point of not running the UI messageloop here. | 600 // Make a point of not running the UI messageloop here. |
| 601 device()->Stop(); | 601 device()->Stop(); |
| 602 device()->DeAllocate(); | 602 device()->DeAllocate(); |
| 603 DestroyVideoCaptureDevice(); | 603 DestroyVideoCaptureDevice(); |
| 604 | 604 |
| 605 // Currently, there should be CreateCaptureMachineOnUIThread() and | 605 // Currently, there should be CreateCaptureMachineOnUIThread() and |
| 606 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message | 606 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message |
| 607 // loop. These should both succeed without crashing, and the machine should | 607 // loop. These should both succeed without crashing, and the machine should |
| 608 // wind up in the idle state. | 608 // wind up in the idle state. |
| 609 base::RunLoop().RunUntilIdle(); | 609 base::RunLoop().RunUntilIdle(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { | 612 TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { |
| 613 // Set up the test to use RGB copies and an normal | 613 // Set up the test to use RGB copies and an normal |
| 614 source()->SetCanCopyToVideoFrame(false); | 614 source()->SetCanCopyToVideoFrame(false); |
| 615 source()->SetUseFrameSubscriber(false); | 615 source()->SetUseFrameSubscriber(false); |
| 616 media::VideoCaptureCapability capture_format( | 616 media::VideoCaptureCapability capture_format( |
| 617 kTestWidth, | 617 kTestWidth, |
| 618 kTestHeight, | 618 kTestHeight, |
| 619 kTestFramesPerSecond, | 619 kTestFramesPerSecond, |
| 620 media::VideoCaptureCapability::kI420, | 620 media::kI420, |
| 621 0, | 621 0, |
| 622 false, | 622 false, |
| 623 media::ConstantResolutionVideoCaptureDevice); | 623 media::ConstantResolutionVideoCaptureDevice); |
| 624 device()->Allocate(capture_format, consumer()); | 624 device()->Allocate(capture_format, consumer()); |
| 625 | 625 |
| 626 device()->Start(); | 626 device()->Start(); |
| 627 // Make a point of not running the UI messageloop here. | 627 // Make a point of not running the UI messageloop here. |
| 628 // TODO(ajwong): Why do we care? | 628 // TODO(ajwong): Why do we care? |
| 629 base::RunLoop().RunUntilIdle(); | 629 base::RunLoop().RunUntilIdle(); |
| 630 | 630 |
| 631 for (int i = 0; i < 10; ++i) | 631 for (int i = 0; i < 10; ++i) |
| 632 SimulateDrawEvent(); | 632 SimulateDrawEvent(); |
| 633 | 633 |
| 634 device()->Stop(); | 634 device()->Stop(); |
| 635 device()->DeAllocate(); | 635 device()->DeAllocate(); |
| 636 // Currently, there should be CreateCaptureMachineOnUIThread() and | 636 // Currently, there should be CreateCaptureMachineOnUIThread() and |
| 637 // DestroyCaptureMachineOnUIThread() tasks pending on the current message | 637 // DestroyCaptureMachineOnUIThread() tasks pending on the current message |
| 638 // loop. These should both succeed without crashing, and the machine should | 638 // loop. These should both succeed without crashing, and the machine should |
| 639 // wind up in the idle state. | 639 // wind up in the idle state. |
| 640 ASSERT_FALSE(consumer()->HasError()); | 640 ASSERT_FALSE(consumer()->HasError()); |
| 641 base::RunLoop().RunUntilIdle(); | 641 base::RunLoop().RunUntilIdle(); |
| 642 ASSERT_FALSE(consumer()->HasError()); | 642 ASSERT_FALSE(consumer()->HasError()); |
| 643 } | 643 } |
| 644 | 644 |
| 645 TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) { | 645 TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) { |
| 646 media::VideoCaptureCapability capture_format( | 646 media::VideoCaptureCapability capture_format( |
| 647 kTestWidth, | 647 kTestWidth, |
| 648 kTestHeight, | 648 kTestHeight, |
| 649 kTestFramesPerSecond, | 649 kTestFramesPerSecond, |
| 650 media::VideoCaptureCapability::kI420, | 650 media::kI420, |
| 651 0, | 651 0, |
| 652 false, | 652 false, |
| 653 media::ConstantResolutionVideoCaptureDevice); | 653 media::ConstantResolutionVideoCaptureDevice); |
| 654 device()->Allocate(capture_format, consumer()); | 654 device()->Allocate(capture_format, consumer()); |
| 655 device()->Start(); | 655 device()->Start(); |
| 656 base::RunLoop().RunUntilIdle(); | 656 base::RunLoop().RunUntilIdle(); |
| 657 source()->SetSolidColor(SK_ColorRED); | 657 source()->SetSolidColor(SK_ColorRED); |
| 658 SimulateDrawEvent(); | 658 SimulateDrawEvent(); |
| 659 SimulateDrawEvent(); | 659 SimulateDrawEvent(); |
| 660 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); | 660 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 682 | 682 |
| 683 // The "happy case" test. No scaling is needed, so we should be able to change | 683 // The "happy case" test. No scaling is needed, so we should be able to change |
| 684 // the picture emitted from the source and expect to see each delivered to the | 684 // the picture emitted from the source and expect to see each delivered to the |
| 685 // consumer. The test will alternate between the three capture paths, simulating | 685 // consumer. The test will alternate between the three capture paths, simulating |
| 686 // falling in and out of accelerated compositing. | 686 // falling in and out of accelerated compositing. |
| 687 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { | 687 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { |
| 688 media::VideoCaptureCapability capture_format( | 688 media::VideoCaptureCapability capture_format( |
| 689 kTestWidth, | 689 kTestWidth, |
| 690 kTestHeight, | 690 kTestHeight, |
| 691 kTestFramesPerSecond, | 691 kTestFramesPerSecond, |
| 692 media::VideoCaptureCapability::kI420, | 692 media::kI420, |
| 693 0, | 693 0, |
| 694 false, | 694 false, |
| 695 media::ConstantResolutionVideoCaptureDevice); | 695 media::ConstantResolutionVideoCaptureDevice); |
| 696 device()->Allocate(capture_format, consumer()); | 696 device()->Allocate(capture_format, consumer()); |
| 697 | 697 |
| 698 device()->Start(); | 698 device()->Start(); |
| 699 | 699 |
| 700 for (int i = 0; i < 6; i++) { | 700 for (int i = 0; i < 6; i++) { |
| 701 const char* name = NULL; | 701 const char* name = NULL; |
| 702 switch (i % 3) { | 702 switch (i % 3) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorBLACK)); | 738 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorBLACK)); |
| 739 } | 739 } |
| 740 device()->DeAllocate(); | 740 device()->DeAllocate(); |
| 741 } | 741 } |
| 742 | 742 |
| 743 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) { | 743 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) { |
| 744 media::VideoCaptureCapability capture_format( | 744 media::VideoCaptureCapability capture_format( |
| 745 1280, | 745 1280, |
| 746 720, | 746 720, |
| 747 -2, | 747 -2, |
| 748 media::VideoCaptureCapability::kI420, | 748 media::kI420, |
| 749 0, | 749 0, |
| 750 false, | 750 false, |
| 751 media::ConstantResolutionVideoCaptureDevice); | 751 media::ConstantResolutionVideoCaptureDevice); |
| 752 BrowserThread::PostTask(BrowserThread::UI, | 752 BrowserThread::PostTask(BrowserThread::UI, |
| 753 FROM_HERE, | 753 FROM_HERE, |
| 754 base::Bind(&media::VideoCaptureDevice::Allocate, | 754 base::Bind(&media::VideoCaptureDevice::Allocate, |
| 755 base::Unretained(device()), | 755 base::Unretained(device()), |
| 756 capture_format, | 756 capture_format, |
| 757 consumer())); | 757 consumer())); |
| 758 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError()); | 758 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError()); |
| 759 } | 759 } |
| 760 | 760 |
| 761 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) { | 761 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) { |
| 762 media::VideoCaptureCapability capture_format( | 762 media::VideoCaptureCapability capture_format( |
| 763 kTestWidth, | 763 kTestWidth, |
| 764 kTestHeight, | 764 kTestHeight, |
| 765 kTestFramesPerSecond, | 765 kTestFramesPerSecond, |
| 766 media::VideoCaptureCapability::kI420, | 766 media::kI420, |
| 767 0, | 767 0, |
| 768 false, | 768 false, |
| 769 media::ConstantResolutionVideoCaptureDevice); | 769 media::ConstantResolutionVideoCaptureDevice); |
| 770 device()->Allocate(capture_format, consumer()); | 770 device()->Allocate(capture_format, consumer()); |
| 771 | 771 |
| 772 // 1x1 is too small to process; we intend for this to result in an error. | 772 // 1x1 is too small to process; we intend for this to result in an error. |
| 773 source()->SetCopyResultSize(1, 1); | 773 source()->SetCopyResultSize(1, 1); |
| 774 source()->SetSolidColor(SK_ColorRED); | 774 source()->SetSolidColor(SK_ColorRED); |
| 775 device()->Start(); | 775 device()->Start(); |
| 776 | 776 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 788 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorGREEN)); | 788 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorGREEN)); |
| 789 source()->SetSolidColor(SK_ColorRED); | 789 source()->SetSolidColor(SK_ColorRED); |
| 790 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); | 790 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); |
| 791 | 791 |
| 792 device()->Stop(); | 792 device()->Stop(); |
| 793 device()->DeAllocate(); | 793 device()->DeAllocate(); |
| 794 } | 794 } |
| 795 | 795 |
| 796 } // namespace | 796 } // namespace |
| 797 } // namespace content | 797 } // namespace content |
| OLD | NEW |