| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 gfx::Rect visible_rect, | 287 gfx::Rect visible_rect, |
| 288 const media::VideoFrameMetadata& additional_metadata) override { | 288 const media::VideoFrameMetadata& additional_metadata) override { |
| 289 EXPECT_FALSE(visible_rect.IsEmpty()); | 289 EXPECT_FALSE(visible_rect.IsEmpty()); |
| 290 EXPECT_EQ(media::PIXEL_FORMAT_I420, format.pixel_format); | 290 EXPECT_EQ(media::PIXEL_FORMAT_I420, format.pixel_format); |
| 291 EXPECT_EQ(kTestFramesPerSecond, format.frame_rate); | 291 EXPECT_EQ(kTestFramesPerSecond, format.frame_rate); |
| 292 | 292 |
| 293 // TODO(miu): We just look at the center pixel presently, because if the | 293 // TODO(miu): We just look at the center pixel presently, because if the |
| 294 // analysis is too slow, the backlog of frames will grow without bound and | 294 // analysis is too slow, the backlog of frames will grow without bound and |
| 295 // trouble erupts. http://crbug.com/174519 | 295 // trouble erupts. http://crbug.com/174519 |
| 296 using media::VideoFrame; | 296 using media::VideoFrame; |
| 297 auto buffer_access = buffer.handle_provider->GetHandleForInProcessAccess(); | 297 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_access = |
| 298 auto frame = VideoFrame::WrapExternalSharedMemory( | 298 buffer.handle_provider->GetHandleForInProcessAccess(); |
| 299 media::PIXEL_FORMAT_I420, format.frame_size, visible_rect, | 299 scoped_refptr<media::VideoFrame> frame = |
| 300 format.frame_size, buffer_access->data(), buffer_access->mapped_size(), | 300 VideoFrame::WrapExternalSharedMemory( |
| 301 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta()); | 301 media::PIXEL_FORMAT_I420, format.frame_size, visible_rect, |
| 302 format.frame_size, buffer_access->data(), |
| 303 buffer_access->mapped_size(), base::SharedMemory::NULLHandle(), 0u, |
| 304 base::TimeDelta()); |
| 302 const gfx::Point center = visible_rect.CenterPoint(); | 305 const gfx::Point center = visible_rect.CenterPoint(); |
| 303 const int center_offset_y = | 306 const int center_offset_y = |
| 304 (frame->stride(VideoFrame::kYPlane) * center.y()) + center.x(); | 307 (frame->stride(VideoFrame::kYPlane) * center.y()) + center.x(); |
| 305 const int center_offset_uv = | 308 const int center_offset_uv = |
| 306 (frame->stride(VideoFrame::kUPlane) * (center.y() / 2)) + | 309 (frame->stride(VideoFrame::kUPlane) * (center.y() / 2)) + |
| 307 (center.x() / 2); | 310 (center.x() / 2); |
| 308 report_callback_.Run( | 311 report_callback_.Run( |
| 309 SkColorSetRGB(frame->data(VideoFrame::kYPlane)[center_offset_y], | 312 SkColorSetRGB(frame->data(VideoFrame::kYPlane)[center_offset_y], |
| 310 frame->data(VideoFrame::kUPlane)[center_offset_uv], | 313 frame->data(VideoFrame::kUPlane)[center_offset_uv], |
| 311 frame->data(VideoFrame::kVPlane)[center_offset_uv]), | 314 frame->data(VideoFrame::kVPlane)[center_offset_uv]), |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 550 |
| 548 // Schedule the update to occur when the test runs the event loop (and not | 551 // Schedule the update to occur when the test runs the event loop (and not |
| 549 // before expectations have been set). | 552 // before expectations have been set). |
| 550 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 553 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 551 base::Bind(&CaptureTestView::SimulateUpdate, | 554 base::Bind(&CaptureTestView::SimulateUpdate, |
| 552 base::Unretained(test_view()))); | 555 base::Unretained(test_view()))); |
| 553 } | 556 } |
| 554 | 557 |
| 555 void SimulateSourceSizeChange(const gfx::Size& size) { | 558 void SimulateSourceSizeChange(const gfx::Size& size) { |
| 556 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 559 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 557 auto* const view = test_view(); | 560 CaptureTestView* const view = test_view(); |
| 558 view->SetSize(size); | 561 view->SetSize(size); |
| 559 // Normally, RenderWidgetHostImpl would notify WebContentsImpl that the size | 562 // Normally, RenderWidgetHostImpl would notify WebContentsImpl that the size |
| 560 // has changed. However, in this test setup, where there is no render | 563 // has changed. However, in this test setup, where there is no render |
| 561 // process, we must notify WebContentsImpl directly. | 564 // process, we must notify WebContentsImpl directly. |
| 562 WebContentsImpl* const as_web_contents_impl = | 565 WebContentsImpl* const as_web_contents_impl = |
| 563 static_cast<WebContentsImpl*>(web_contents_.get()); | 566 static_cast<WebContentsImpl*>(web_contents_.get()); |
| 564 RenderWidgetHostDelegate* const as_rwh_delegate = | 567 RenderWidgetHostDelegate* const as_rwh_delegate = |
| 565 static_cast<RenderWidgetHostDelegate*>(as_web_contents_impl); | 568 static_cast<RenderWidgetHostDelegate*>(as_web_contents_impl); |
| 566 as_rwh_delegate->RenderWidgetWasResized( | 569 as_rwh_delegate->RenderWidgetWasResized( |
| 567 as_web_contents_impl->GetMainFrame()->GetRenderWidgetHost(), true); | 570 as_web_contents_impl->GetMainFrame()->GetRenderWidgetHost(), true); |
| 568 } | 571 } |
| 569 | 572 |
| 570 // Repeatedly schedules draw events and scans for frames until the output from | 573 // Repeatedly schedules draw events and scans for frames until the output from |
| 571 // the capture device matches the given RGB |color| and frame |size|. | 574 // the capture device matches the given RGB |color| and frame |size|. |
| 572 void SimulateDrawsUntilNewFrameSizeArrives(SkColor color, | 575 void SimulateDrawsUntilNewFrameSizeArrives(SkColor color, |
| 573 const gfx::Size& size) { | 576 const gfx::Size& size) { |
| 574 const base::TimeTicks start_time = base::TimeTicks::Now(); | 577 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 575 while ((base::TimeTicks::Now() - start_time) < | 578 while ((base::TimeTicks::Now() - start_time) < |
| 576 TestTimeouts::action_max_timeout()) { | 579 TestTimeouts::action_max_timeout()) { |
| 577 SimulateDrawEvent(); | 580 SimulateDrawEvent(); |
| 578 const auto color_and_size = client_observer()->WaitForNextFrame(); | 581 const std::pair<SkColor, gfx::Size>& color_and_size = |
| 582 client_observer()->WaitForNextFrame(); |
| 579 if (color_and_size.first == ConvertRgbToYuv(color) && | 583 if (color_and_size.first == ConvertRgbToYuv(color) && |
| 580 color_and_size.second == size) { | 584 color_and_size.second == size) { |
| 581 return; | 585 return; |
| 582 } | 586 } |
| 583 } | 587 } |
| 584 DeadlineExceeded(base::Closure()); | 588 DeadlineExceeded(base::Closure()); |
| 585 } | 589 } |
| 586 | 590 |
| 587 void SimulateRefreshFrameRequest() { | 591 void SimulateRefreshFrameRequest() { |
| 588 // Force at least three frame period's worth of time to pass. The wait is | 592 // Force at least three frame period's worth of time to pass. The wait is |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 std::unique_ptr<media::VideoCaptureDevice> device_; | 640 std::unique_ptr<media::VideoCaptureDevice> device_; |
| 637 }; | 641 }; |
| 638 | 642 |
| 639 // In real-world use cases, there can exist a race condition between starting | 643 // In real-world use cases, there can exist a race condition between starting |
| 640 // capture on a WebContents and having the WebContents be destroyed in the | 644 // capture on a WebContents and having the WebContents be destroyed in the |
| 641 // meantime. This tests that WebContentsVideoCaptureDevice errors-out | 645 // meantime. This tests that WebContentsVideoCaptureDevice errors-out |
| 642 // gracefully. | 646 // gracefully. |
| 643 TEST_F(WebContentsVideoCaptureDeviceTest, | 647 TEST_F(WebContentsVideoCaptureDeviceTest, |
| 644 SafelyStartsUpAfterWebContentsHasGone) { | 648 SafelyStartsUpAfterWebContentsHasGone) { |
| 645 ResetWebContents(); | 649 ResetWebContents(); |
| 646 auto client = client_observer()->PassClient(); | 650 std::unique_ptr<StubClient> client = client_observer()->PassClient(); |
| 647 EXPECT_CALL(*client, OnStarted()); | 651 EXPECT_CALL(*client, OnStarted()); |
| 648 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); | 652 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
| 649 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); | 653 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); |
| 650 device()->StopAndDeAllocate(); | 654 device()->StopAndDeAllocate(); |
| 651 } | 655 } |
| 652 | 656 |
| 653 // Tests that WebContentsVideoCaptureDevice starts, captures a frame, and then | 657 // Tests that WebContentsVideoCaptureDevice starts, captures a frame, and then |
| 654 // gracefully errors-out if the WebContents is destroyed before the device is | 658 // gracefully errors-out if the WebContents is destroyed before the device is |
| 655 // stopped. | 659 // stopped. |
| 656 TEST_F(WebContentsVideoCaptureDeviceTest, | 660 TEST_F(WebContentsVideoCaptureDeviceTest, |
| 657 RunsThenErrorsOutWhenWebContentsIsDestroyed) { | 661 RunsThenErrorsOutWhenWebContentsIsDestroyed) { |
| 658 // We'll simulate the tab being closed after the capture pipeline is up and | 662 // We'll simulate the tab being closed after the capture pipeline is up and |
| 659 // running. | 663 // running. |
| 660 auto client = client_observer()->PassClient(); | 664 std::unique_ptr<StubClient> client = client_observer()->PassClient(); |
| 661 EXPECT_CALL(*client, OnStarted()); | 665 EXPECT_CALL(*client, OnStarted()); |
| 662 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); | 666 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
| 663 | 667 |
| 664 // Do one capture to prove the tab is initially open and being captured | 668 // Do one capture to prove the tab is initially open and being captured |
| 665 // normally. | 669 // normally. |
| 666 test_view()->SetSolidColor(SK_ColorRED); | 670 test_view()->SetSolidColor(SK_ColorRED); |
| 667 SimulateDrawEvent(); | 671 SimulateDrawEvent(); |
| 668 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 672 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
| 669 | 673 |
| 670 base::RunLoop().RunUntilIdle(); | 674 base::RunLoop().RunUntilIdle(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 696 // wind up in the idle state. | 700 // wind up in the idle state. |
| 697 base::RunLoop().RunUntilIdle(); | 701 base::RunLoop().RunUntilIdle(); |
| 698 } | 702 } |
| 699 | 703 |
| 700 // Tests that frames are delivered to different clients across restarts of the | 704 // Tests that frames are delivered to different clients across restarts of the |
| 701 // same instance. | 705 // same instance. |
| 702 TEST_F(WebContentsVideoCaptureDeviceTest, | 706 TEST_F(WebContentsVideoCaptureDeviceTest, |
| 703 DeliversToCorrectClientAcrossRestarts) { | 707 DeliversToCorrectClientAcrossRestarts) { |
| 704 // While the device is up-and-running, expect frame captures. | 708 // While the device is up-and-running, expect frame captures. |
| 705 client_observer()->SetIsExpectingFrames(true); | 709 client_observer()->SetIsExpectingFrames(true); |
| 706 auto client = client_observer()->PassClient(); | 710 std::unique_ptr<StubClient> client = client_observer()->PassClient(); |
| 707 EXPECT_CALL(*client, OnStarted()); | 711 EXPECT_CALL(*client, OnStarted()); |
| 708 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); | 712 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
| 709 base::RunLoop().RunUntilIdle(); | 713 base::RunLoop().RunUntilIdle(); |
| 710 test_view()->SetSolidColor(SK_ColorRED); | 714 test_view()->SetSolidColor(SK_ColorRED); |
| 711 SimulateDrawEvent(); | 715 SimulateDrawEvent(); |
| 712 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 716 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
| 713 SimulateDrawEvent(); | 717 SimulateDrawEvent(); |
| 714 test_view()->SetSolidColor(SK_ColorGREEN); | 718 test_view()->SetSolidColor(SK_ColorGREEN); |
| 715 SimulateDrawEvent(); | 719 SimulateDrawEvent(); |
| 716 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 720 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
| 717 SimulateDrawEvent(); | 721 SimulateDrawEvent(); |
| 718 device()->StopAndDeAllocate(); | 722 device()->StopAndDeAllocate(); |
| 719 | 723 |
| 720 base::RunLoop().RunUntilIdle(); | 724 base::RunLoop().RunUntilIdle(); |
| 721 | 725 |
| 722 // Now that the device is stopped, expect frames are no longer captured. | 726 // Now that the device is stopped, expect frames are no longer captured. |
| 723 client_observer()->SetIsExpectingFrames(false); | 727 client_observer()->SetIsExpectingFrames(false); |
| 724 SimulateDrawEvent(); | 728 SimulateDrawEvent(); |
| 725 SimulateDrawEvent(); | 729 SimulateDrawEvent(); |
| 726 base::RunLoop().RunUntilIdle(); | 730 base::RunLoop().RunUntilIdle(); |
| 727 | 731 |
| 728 // Re-start the device with a different client. Only the second client should | 732 // Re-start the device with a different client. Only the second client should |
| 729 // expect to see any frame captures. | 733 // expect to see any frame captures. |
| 730 StubClientObserver observer2; | 734 StubClientObserver observer2; |
| 731 observer2.SetIsExpectingFrames(true); | 735 observer2.SetIsExpectingFrames(true); |
| 732 auto client2 = observer2.PassClient(); | 736 std::unique_ptr<StubClient> client2 = observer2.PassClient(); |
| 733 EXPECT_CALL(*client2, OnStarted()); | 737 EXPECT_CALL(*client2, OnStarted()); |
| 734 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client2)); | 738 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client2)); |
| 735 test_view()->SetSolidColor(SK_ColorBLUE); | 739 test_view()->SetSolidColor(SK_ColorBLUE); |
| 736 SimulateDrawEvent(); | 740 SimulateDrawEvent(); |
| 737 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorBLUE)); | 741 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorBLUE)); |
| 738 test_view()->SetSolidColor(SK_ColorYELLOW); | 742 test_view()->SetSolidColor(SK_ColorYELLOW); |
| 739 SimulateDrawEvent(); | 743 SimulateDrawEvent(); |
| 740 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorYELLOW)); | 744 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorYELLOW)); |
| 741 device()->StopAndDeAllocate(); | 745 device()->StopAndDeAllocate(); |
| 742 } | 746 } |
| 743 | 747 |
| 744 // The "happy case" test. No scaling is needed, so we should be able to change | 748 // The "happy case" test. No scaling is needed, so we should be able to change |
| 745 // the picture emitted from the source and expect to see each delivered to the | 749 // the picture emitted from the source and expect to see each delivered to the |
| 746 // consumer. The test will alternate between the RGB/SkBitmap and YUV/VideoFrame | 750 // consumer. The test will alternate between the RGB/SkBitmap and YUV/VideoFrame |
| 747 // capture paths. | 751 // capture paths. |
| 748 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { | 752 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { |
| 749 auto client = client_observer()->PassClient(); | 753 std::unique_ptr<StubClient> client = client_observer()->PassClient(); |
| 750 EXPECT_CALL(*client, OnStarted()); | 754 EXPECT_CALL(*client, OnStarted()); |
| 751 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); | 755 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
| 752 | 756 |
| 753 for (int i = 0; i < 3; i++) { | 757 for (int i = 0; i < 3; i++) { |
| 754 SCOPED_TRACE(base::StringPrintf("Iteration #%d", i)); | 758 SCOPED_TRACE(base::StringPrintf("Iteration #%d", i)); |
| 755 | 759 |
| 756 test_view()->SetSolidColor(SK_ColorRED); | 760 test_view()->SetSolidColor(SK_ColorRED); |
| 757 for (int j = 0; j <= i; j++) | 761 for (int j = 0; j <= i; j++) |
| 758 SimulateDrawEvent(); | 762 SimulateDrawEvent(); |
| 759 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 763 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 774 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLACK)); | 778 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLACK)); |
| 775 } | 779 } |
| 776 | 780 |
| 777 device()->StopAndDeAllocate(); | 781 device()->StopAndDeAllocate(); |
| 778 } | 782 } |
| 779 | 783 |
| 780 // Tests that, when configured with the FIXED_ASPECT_RATIO resolution change | 784 // Tests that, when configured with the FIXED_ASPECT_RATIO resolution change |
| 781 // policy, the source size changes result in video frames of possibly varying | 785 // policy, the source size changes result in video frames of possibly varying |
| 782 // resolutions, but all with the same aspect ratio. | 786 // resolutions, but all with the same aspect ratio. |
| 783 TEST_F(WebContentsVideoCaptureDeviceTest, VariableResolution_FixedAspectRatio) { | 787 TEST_F(WebContentsVideoCaptureDeviceTest, VariableResolution_FixedAspectRatio) { |
| 784 auto capture_params = DefaultCaptureParams(); | 788 media::VideoCaptureParams capture_params = DefaultCaptureParams(); |
| 785 capture_params.resolution_change_policy = | 789 capture_params.resolution_change_policy = |
| 786 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; | 790 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; |
| 787 auto client = client_observer()->PassClient(); | 791 std::unique_ptr<StubClient> client = client_observer()->PassClient(); |
| 788 EXPECT_CALL(*client, OnStarted()); | 792 EXPECT_CALL(*client, OnStarted()); |
| 789 device()->AllocateAndStart(capture_params, std::move(client)); | 793 device()->AllocateAndStart(capture_params, std::move(client)); |
| 790 | 794 |
| 791 // Source size equals maximum size. Expect delivered frames to be | 795 // Source size equals maximum size. Expect delivered frames to be |
| 792 // kTestWidth by kTestHeight. | 796 // kTestWidth by kTestHeight. |
| 793 test_view()->SetSolidColor(SK_ColorRED); | 797 test_view()->SetSolidColor(SK_ColorRED); |
| 794 const float device_scale_factor = GetDeviceScaleFactor(); | 798 const float device_scale_factor = GetDeviceScaleFactor(); |
| 795 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( | 799 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( |
| 796 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); | 800 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); |
| 797 SimulateDrawsUntilNewFrameSizeArrives( | 801 SimulateDrawsUntilNewFrameSizeArrives( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 822 SimulateDrawsUntilNewFrameSizeArrives( | 826 SimulateDrawsUntilNewFrameSizeArrives( |
| 823 SK_ColorBLACK, gfx::Size(kTestWidth, kTestHeight)); | 827 SK_ColorBLACK, gfx::Size(kTestWidth, kTestHeight)); |
| 824 | 828 |
| 825 device()->StopAndDeAllocate(); | 829 device()->StopAndDeAllocate(); |
| 826 } | 830 } |
| 827 | 831 |
| 828 // Tests that, when configured with the ANY_WITHIN_LIMIT resolution change | 832 // Tests that, when configured with the ANY_WITHIN_LIMIT resolution change |
| 829 // policy, the source size changes result in video frames of possibly varying | 833 // policy, the source size changes result in video frames of possibly varying |
| 830 // resolutions. | 834 // resolutions. |
| 831 TEST_F(WebContentsVideoCaptureDeviceTest, VariableResolution_AnyWithinLimits) { | 835 TEST_F(WebContentsVideoCaptureDeviceTest, VariableResolution_AnyWithinLimits) { |
| 832 auto capture_params = DefaultCaptureParams(); | 836 media::VideoCaptureParams capture_params = DefaultCaptureParams(); |
| 833 capture_params.resolution_change_policy = | 837 capture_params.resolution_change_policy = |
| 834 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; | 838 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; |
| 835 auto client = client_observer()->PassClient(); | 839 std::unique_ptr<StubClient> client = client_observer()->PassClient(); |
| 836 EXPECT_CALL(*client, OnStarted()); | 840 EXPECT_CALL(*client, OnStarted()); |
| 837 device()->AllocateAndStart(capture_params, std::move(client)); | 841 device()->AllocateAndStart(capture_params, std::move(client)); |
| 838 | 842 |
| 839 // Source size equals maximum size. Expect delivered frames to be | 843 // Source size equals maximum size. Expect delivered frames to be |
| 840 // kTestWidth by kTestHeight. | 844 // kTestWidth by kTestHeight. |
| 841 test_view()->SetSolidColor(SK_ColorRED); | 845 test_view()->SetSolidColor(SK_ColorRED); |
| 842 const float device_scale_factor = GetDeviceScaleFactor(); | 846 const float device_scale_factor = GetDeviceScaleFactor(); |
| 843 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( | 847 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( |
| 844 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); | 848 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); |
| 845 SimulateDrawsUntilNewFrameSizeArrives( | 849 SimulateDrawsUntilNewFrameSizeArrives( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 // the |oddball_size| is always the expected size; whereas for the | 898 // the |oddball_size| is always the expected size; whereas for the |
| 895 // variable-resolution cases, the |standard_size| is the expected size. | 899 // variable-resolution cases, the |standard_size| is the expected size. |
| 896 // Also, adjust to account for the device scale factor. | 900 // Also, adjust to account for the device scale factor. |
| 897 gfx::Size capture_preferred_size = gfx::ScaleToFlooredSize( | 901 gfx::Size capture_preferred_size = gfx::ScaleToFlooredSize( |
| 898 policy == media::RESOLUTION_POLICY_FIXED_RESOLUTION ? oddball_size | 902 policy == media::RESOLUTION_POLICY_FIXED_RESOLUTION ? oddball_size |
| 899 : standard_size, | 903 : standard_size, |
| 900 1.0f / GetDeviceScaleFactor()); | 904 1.0f / GetDeviceScaleFactor()); |
| 901 ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize()); | 905 ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize()); |
| 902 | 906 |
| 903 // Start the WebContentsVideoCaptureDevice. | 907 // Start the WebContentsVideoCaptureDevice. |
| 904 auto capture_params = DefaultCaptureParams(); | 908 media::VideoCaptureParams capture_params = DefaultCaptureParams(); |
| 905 capture_params.requested_format.frame_size = oddball_size; | 909 capture_params.requested_format.frame_size = oddball_size; |
| 906 capture_params.resolution_change_policy = policy; | 910 capture_params.resolution_change_policy = policy; |
| 907 StubClientObserver unused_observer; | 911 StubClientObserver unused_observer; |
| 908 auto client = unused_observer.PassClient(); | 912 std::unique_ptr<StubClient> client = unused_observer.PassClient(); |
| 909 EXPECT_CALL(*client, OnStarted()); | 913 EXPECT_CALL(*client, OnStarted()); |
| 910 device()->AllocateAndStart(capture_params, std::move(client)); | 914 device()->AllocateAndStart(capture_params, std::move(client)); |
| 911 base::RunLoop().RunUntilIdle(); | 915 base::RunLoop().RunUntilIdle(); |
| 912 | 916 |
| 913 // Check that the preferred size of the WebContents matches the one provided | 917 // Check that the preferred size of the WebContents matches the one provided |
| 914 // by WebContentsVideoCaptureDevice. | 918 // by WebContentsVideoCaptureDevice. |
| 915 EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize()); | 919 EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize()); |
| 916 | 920 |
| 917 // Stop the WebContentsVideoCaptureDevice. | 921 // Stop the WebContentsVideoCaptureDevice. |
| 918 device()->StopAndDeAllocate(); | 922 device()->StopAndDeAllocate(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000)); | 970 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000)); |
| 967 RunTestForPreferredSize( | 971 RunTestForPreferredSize( |
| 968 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000)); | 972 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000)); |
| 969 RunTestForPreferredSize( | 973 RunTestForPreferredSize( |
| 970 policies[i], gfx::Size(837, 999), gfx::Size(837, 999)); | 974 policies[i], gfx::Size(837, 999), gfx::Size(837, 999)); |
| 971 } | 975 } |
| 972 } | 976 } |
| 973 | 977 |
| 974 // Tests the Suspend/Resume() functionality. | 978 // Tests the Suspend/Resume() functionality. |
| 975 TEST_F(WebContentsVideoCaptureDeviceTest, SuspendsAndResumes) { | 979 TEST_F(WebContentsVideoCaptureDeviceTest, SuspendsAndResumes) { |
| 976 auto client = client_observer()->PassClient(); | 980 std::unique_ptr<StubClient> client = client_observer()->PassClient(); |
| 977 EXPECT_CALL(*client, OnStarted()); | 981 EXPECT_CALL(*client, OnStarted()); |
| 978 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); | 982 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
| 979 | 983 |
| 980 for (int i = 0; i < 3; ++i) { | 984 for (int i = 0; i < 3; ++i) { |
| 981 // Draw a RED frame and wait for a normal frame capture to occur. | 985 // Draw a RED frame and wait for a normal frame capture to occur. |
| 982 test_view()->SetSolidColor(SK_ColorRED); | 986 test_view()->SetSolidColor(SK_ColorRED); |
| 983 SimulateDrawEvent(); | 987 SimulateDrawEvent(); |
| 984 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 988 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
| 985 | 989 |
| 986 // Suspend capture and then draw a GREEN frame. No frame capture should | 990 // Suspend capture and then draw a GREEN frame. No frame capture should |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1001 test_view()->SetSolidColor(SK_ColorBLUE); | 1005 test_view()->SetSolidColor(SK_ColorBLUE); |
| 1002 SimulateDrawEvent(); | 1006 SimulateDrawEvent(); |
| 1003 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLUE)); | 1007 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLUE)); |
| 1004 } | 1008 } |
| 1005 | 1009 |
| 1006 device()->StopAndDeAllocate(); | 1010 device()->StopAndDeAllocate(); |
| 1007 } | 1011 } |
| 1008 | 1012 |
| 1009 // Tests the RequestRefreshFrame() functionality. | 1013 // Tests the RequestRefreshFrame() functionality. |
| 1010 TEST_F(WebContentsVideoCaptureDeviceTest, ProvidesRefreshFrames) { | 1014 TEST_F(WebContentsVideoCaptureDeviceTest, ProvidesRefreshFrames) { |
| 1011 auto client = client_observer()->PassClient(); | 1015 std::unique_ptr<StubClient> client = client_observer()->PassClient(); |
| 1012 EXPECT_CALL(*client, OnStarted()); | 1016 EXPECT_CALL(*client, OnStarted()); |
| 1013 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); | 1017 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
| 1014 | 1018 |
| 1015 // Request a refresh frame before the first frame has been drawn. This forces | 1019 // Request a refresh frame before the first frame has been drawn. This forces |
| 1016 // a capture. | 1020 // a capture. |
| 1017 test_view()->SetSolidColor(SK_ColorRED); | 1021 test_view()->SetSolidColor(SK_ColorRED); |
| 1018 SimulateRefreshFrameRequest(); | 1022 SimulateRefreshFrameRequest(); |
| 1019 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 1023 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
| 1020 | 1024 |
| 1021 // Now, draw a frame and wait for a normal frame capture to occur. | 1025 // Now, draw a frame and wait for a normal frame capture to occur. |
| 1022 test_view()->SetSolidColor(SK_ColorGREEN); | 1026 test_view()->SetSolidColor(SK_ColorGREEN); |
| 1023 SimulateDrawEvent(); | 1027 SimulateDrawEvent(); |
| 1024 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 1028 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
| 1025 | 1029 |
| 1026 // Now, make three more refresh frame requests. Although the source has | 1030 // Now, make three more refresh frame requests. Although the source has |
| 1027 // changed to BLUE, no draw event has occurred. Therefore, expect the refresh | 1031 // changed to BLUE, no draw event has occurred. Therefore, expect the refresh |
| 1028 // frames to contain the content from the last drawn frame, which is GREEN. | 1032 // frames to contain the content from the last drawn frame, which is GREEN. |
| 1029 test_view()->SetSolidColor(SK_ColorBLUE); | 1033 test_view()->SetSolidColor(SK_ColorBLUE); |
| 1030 for (int i = 0; i < 3; ++i) { | 1034 for (int i = 0; i < 3; ++i) { |
| 1031 SimulateRefreshFrameRequest(); | 1035 SimulateRefreshFrameRequest(); |
| 1032 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 1036 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
| 1033 } | 1037 } |
| 1034 | 1038 |
| 1035 device()->StopAndDeAllocate(); | 1039 device()->StopAndDeAllocate(); |
| 1036 } | 1040 } |
| 1037 | 1041 |
| 1038 } // namespace | 1042 } // namespace |
| 1039 } // namespace content | 1043 } // namespace content |
| OLD | NEW |