| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "content/public/renderer/media_stream_renderer_factory.h" | 9 #include "content/public/renderer/media_stream_renderer_factory.h" |
| 10 #include "content/renderer/media/webmediaplayer_ms.h" | 10 #include "content/renderer/media/webmediaplayer_ms.h" |
| 11 #include "content/renderer/media/webmediaplayer_ms_compositor.h" | 11 #include "content/renderer/media/webmediaplayer_ms_compositor.h" |
| 12 #include "content/renderer/render_frame_impl.h" | 12 #include "content/renderer/render_frame_impl.h" |
| 13 #include "media/base/test_helpers.h" | 13 #include "media/base/test_helpers.h" |
| 14 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
| 15 #include "third_party/WebKit/public/platform/WebLayer.h" |
| 15 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 16 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
| 16 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 17 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 17 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" | 18 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 enum class FrameType { | 22 enum class FrameType { |
| 22 NORMAL_FRAME = 0, | 23 NORMAL_FRAME = 0, |
| 23 BROKEN_FRAME = -1, | 24 BROKEN_FRAME = -1, |
| 24 TEST_BRAKE = -2, // Signal to pause message loop. | 25 TEST_BRAKE = -2, // Signal to pause message loop. |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 void(blink::WebMediaPlayer::NetworkState)); | 448 void(blink::WebMediaPlayer::NetworkState)); |
| 448 MOCK_METHOD1(DoReadyStateChanged, void(blink::WebMediaPlayer::ReadyState)); | 449 MOCK_METHOD1(DoReadyStateChanged, void(blink::WebMediaPlayer::ReadyState)); |
| 449 MOCK_METHOD1(CheckSizeChanged, void(gfx::Size)); | 450 MOCK_METHOD1(CheckSizeChanged, void(gfx::Size)); |
| 450 | 451 |
| 451 base::MessageLoop message_loop_; | 452 base::MessageLoop message_loop_; |
| 452 MockRenderFactory* render_factory_; | 453 MockRenderFactory* render_factory_; |
| 453 FakeWebMediaPlayerDelegate delegate_; | 454 FakeWebMediaPlayerDelegate delegate_; |
| 454 std::unique_ptr<WebMediaPlayerMS> player_; | 455 std::unique_ptr<WebMediaPlayerMS> player_; |
| 455 WebMediaPlayerMSCompositor* compositor_; | 456 WebMediaPlayerMSCompositor* compositor_; |
| 456 ReusableMessageLoopEvent message_loop_controller_; | 457 ReusableMessageLoopEvent message_loop_controller_; |
| 458 blink::WebLayer* web_layer_; |
| 457 | 459 |
| 458 private: | 460 private: |
| 459 // Main function trying to ask WebMediaPlayerMS to submit a frame for | 461 // Main function trying to ask WebMediaPlayerMS to submit a frame for |
| 460 // rendering. | 462 // rendering. |
| 461 void RenderFrame(); | 463 void RenderFrame(); |
| 462 | 464 |
| 463 bool rendering_; | 465 bool rendering_; |
| 464 bool background_rendering_; | 466 bool background_rendering_; |
| 465 }; | 467 }; |
| 466 | 468 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 } | 502 } |
| 501 | 503 |
| 502 void WebMediaPlayerMSTest::readyStateChanged() { | 504 void WebMediaPlayerMSTest::readyStateChanged() { |
| 503 blink::WebMediaPlayer::ReadyState state = player_->getReadyState(); | 505 blink::WebMediaPlayer::ReadyState state = player_->getReadyState(); |
| 504 DoReadyStateChanged(state); | 506 DoReadyStateChanged(state); |
| 505 if (state == blink::WebMediaPlayer::ReadyState::ReadyStateHaveEnoughData) | 507 if (state == blink::WebMediaPlayer::ReadyState::ReadyStateHaveEnoughData) |
| 506 player_->play(); | 508 player_->play(); |
| 507 } | 509 } |
| 508 | 510 |
| 509 void WebMediaPlayerMSTest::setWebLayer(blink::WebLayer* layer) { | 511 void WebMediaPlayerMSTest::setWebLayer(blink::WebLayer* layer) { |
| 512 web_layer_ = layer; |
| 510 if (layer) | 513 if (layer) |
| 511 compositor_->SetVideoFrameProviderClient(this); | 514 compositor_->SetVideoFrameProviderClient(this); |
| 512 DoSetWebLayer(!!layer); | 515 DoSetWebLayer(!!layer); |
| 513 } | 516 } |
| 514 | 517 |
| 515 void WebMediaPlayerMSTest::StopUsingProvider() { | 518 void WebMediaPlayerMSTest::StopUsingProvider() { |
| 516 if (rendering_) | 519 if (rendering_) |
| 517 StopRendering(); | 520 StopRendering(); |
| 518 } | 521 } |
| 519 | 522 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 const blink::WebSize& natural_size = player_->naturalSize(); | 745 const blink::WebSize& natural_size = player_->naturalSize(); |
| 743 // Check that height and width are flipped. | 746 // Check that height and width are flipped. |
| 744 EXPECT_EQ(kStandardHeight, natural_size.width); | 747 EXPECT_EQ(kStandardHeight, natural_size.width); |
| 745 EXPECT_EQ(kStandardWidth, natural_size.height); | 748 EXPECT_EQ(kStandardWidth, natural_size.height); |
| 746 testing::Mock::VerifyAndClearExpectations(this); | 749 testing::Mock::VerifyAndClearExpectations(this); |
| 747 | 750 |
| 748 EXPECT_CALL(*this, DoSetWebLayer(false)); | 751 EXPECT_CALL(*this, DoSetWebLayer(false)); |
| 749 EXPECT_CALL(*this, DoStopRendering()); | 752 EXPECT_CALL(*this, DoStopRendering()); |
| 750 } | 753 } |
| 751 | 754 |
| 755 // During this test, we check that web layer changes opacity according to the |
| 756 // given frames. |
| 757 TEST_F(WebMediaPlayerMSTest, OpacityChange) { |
| 758 MockMediaStreamVideoRenderer* provider = LoadAndGetFrameProvider(true); |
| 759 |
| 760 // Push one opaque frame. |
| 761 const int kTestBrake = static_cast<int>(FrameType::TEST_BRAKE); |
| 762 static int tokens[] = {0, kTestBrake}; |
| 763 std::vector<int> timestamps(tokens, tokens + arraysize(tokens)); |
| 764 provider->QueueFrames(timestamps, true); |
| 765 EXPECT_CALL(*this, DoSetWebLayer(true)); |
| 766 EXPECT_CALL(*this, DoStartRendering()); |
| 767 EXPECT_CALL(*this, DoReadyStateChanged( |
| 768 blink::WebMediaPlayer::ReadyStateHaveMetadata)); |
| 769 EXPECT_CALL(*this, DoReadyStateChanged( |
| 770 blink::WebMediaPlayer::ReadyStateHaveEnoughData)); |
| 771 EXPECT_CALL(*this, |
| 772 CheckSizeChanged(gfx::Size(kStandardWidth, kStandardHeight))); |
| 773 message_loop_controller_.RunAndWaitForStatus( |
| 774 media::PipelineStatus::PIPELINE_OK); |
| 775 ASSERT_TRUE(web_layer_ != nullptr); |
| 776 EXPECT_TRUE(web_layer_->opaque()); |
| 777 |
| 778 // Push one transparent frame. |
| 779 provider->QueueFrames(timestamps, false); |
| 780 message_loop_controller_.RunAndWaitForStatus( |
| 781 media::PipelineStatus::PIPELINE_OK); |
| 782 EXPECT_FALSE(web_layer_->opaque()); |
| 783 |
| 784 // Push another opaque frame. |
| 785 provider->QueueFrames(timestamps, true); |
| 786 message_loop_controller_.RunAndWaitForStatus( |
| 787 media::PipelineStatus::PIPELINE_OK); |
| 788 EXPECT_TRUE(web_layer_->opaque()); |
| 789 |
| 790 testing::Mock::VerifyAndClearExpectations(this); |
| 791 EXPECT_CALL(*this, DoSetWebLayer(false)); |
| 792 EXPECT_CALL(*this, DoStopRendering()); |
| 793 } |
| 794 |
| 752 TEST_F(WebMediaPlayerMSTest, BackgroundRendering) { | 795 TEST_F(WebMediaPlayerMSTest, BackgroundRendering) { |
| 753 // During this test, we will switch to background rendering mode, in which | 796 // During this test, we will switch to background rendering mode, in which |
| 754 // WebMediaPlayerMS::pause does not get called, but | 797 // WebMediaPlayerMS::pause does not get called, but |
| 755 // cc::VideoFrameProviderClient simply stops asking frames from | 798 // cc::VideoFrameProviderClient simply stops asking frames from |
| 756 // WebMediaPlayerMS without an explicit notification. We should expect that | 799 // WebMediaPlayerMS without an explicit notification. We should expect that |
| 757 // WebMediaPlayerMS can digest old frames, rather than piling frames up and | 800 // WebMediaPlayerMS can digest old frames, rather than piling frames up and |
| 758 // explode. | 801 // explode. |
| 759 MockMediaStreamVideoRenderer* provider = LoadAndGetFrameProvider(true); | 802 MockMediaStreamVideoRenderer* provider = LoadAndGetFrameProvider(true); |
| 760 | 803 |
| 761 const int kTestBrake = static_cast<int>(FrameType::TEST_BRAKE); | 804 const int kTestBrake = static_cast<int>(FrameType::TEST_BRAKE); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 // OnShown() should restart after a forced suspension. | 915 // OnShown() should restart after a forced suspension. |
| 873 player_->OnShown(); | 916 player_->OnShown(); |
| 874 EXPECT_FALSE(player_->paused()); | 917 EXPECT_FALSE(player_->paused()); |
| 875 EXPECT_CALL(*this, DoSetWebLayer(false)); | 918 EXPECT_CALL(*this, DoSetWebLayer(false)); |
| 876 | 919 |
| 877 base::RunLoop().RunUntilIdle(); | 920 base::RunLoop().RunUntilIdle(); |
| 878 } | 921 } |
| 879 #endif | 922 #endif |
| 880 | 923 |
| 881 } // namespace content | 924 } // namespace content |
| OLD | NEW |