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