Chromium Code Reviews| 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 opaque_tokens[] = {0, kTestBrake}; | |
| 763 std::vector<int> opaque_timestamps( | |
| 764 opaque_tokens, opaque_tokens + sizeof(opaque_tokens) / sizeof(int)); | |
| 765 provider->QueueFrames(opaque_timestamps, true); | |
| 766 EXPECT_CALL(*this, DoSetWebLayer(true)); | |
| 767 EXPECT_CALL(*this, DoStartRendering()); | |
| 768 EXPECT_CALL(*this, DoReadyStateChanged( | |
| 769 blink::WebMediaPlayer::ReadyStateHaveMetadata)); | |
| 770 EXPECT_CALL(*this, DoReadyStateChanged( | |
| 771 blink::WebMediaPlayer::ReadyStateHaveEnoughData)); | |
| 772 EXPECT_CALL(*this, | |
| 773 CheckSizeChanged(gfx::Size(kStandardWidth, kStandardHeight))); | |
| 774 message_loop_controller_.RunAndWaitForStatus( | |
| 775 media::PipelineStatus::PIPELINE_OK); | |
| 776 CHECK(web_layer_); | |
|
mcasas
2016/09/20 00:35:14
Don't use CHECK()s in unittests, since they
crash
emircan
2016/09/20 03:00:06
Done.
| |
| 777 EXPECT_TRUE(web_layer_->opaque()); | |
| 778 | |
| 779 // Push one transparent frame. | |
| 780 static int transparent_tokens[] = {33, kTestBrake}; | |
| 781 std::vector<int> transparent_timestamps( | |
| 782 transparent_tokens, | |
| 783 transparent_tokens + sizeof(transparent_tokens) / sizeof(int)); | |
|
mcasas
2016/09/20 00:35:14
|transparent_tokens| is static, so we can use here
emircan
2016/09/20 03:00:06
Done.
| |
| 784 provider->QueueFrames(transparent_timestamps, false); | |
| 785 message_loop_controller_.RunAndWaitForStatus( | |
| 786 media::PipelineStatus::PIPELINE_OK); | |
| 787 EXPECT_FALSE(web_layer_->opaque()); | |
| 788 | |
| 789 // Push another opaque frame. | |
| 790 provider->QueueFrames(opaque_timestamps, true); | |
|
mcasas
2016/09/20 00:35:14
|opaque_timestamps| has a single frame with a
tim
emircan
2016/09/20 03:00:06
We don't care about timestamps, except the TestBra
| |
| 791 message_loop_controller_.RunAndWaitForStatus( | |
| 792 media::PipelineStatus::PIPELINE_OK); | |
| 793 EXPECT_TRUE(web_layer_->opaque()); | |
| 794 | |
| 795 testing::Mock::VerifyAndClearExpectations(this); | |
| 796 EXPECT_CALL(*this, DoSetWebLayer(false)); | |
| 797 EXPECT_CALL(*this, DoStopRendering()); | |
| 798 } | |
| 799 | |
| 752 TEST_F(WebMediaPlayerMSTest, BackgroundRendering) { | 800 TEST_F(WebMediaPlayerMSTest, BackgroundRendering) { |
| 753 // During this test, we will switch to background rendering mode, in which | 801 // During this test, we will switch to background rendering mode, in which |
| 754 // WebMediaPlayerMS::pause does not get called, but | 802 // WebMediaPlayerMS::pause does not get called, but |
| 755 // cc::VideoFrameProviderClient simply stops asking frames from | 803 // cc::VideoFrameProviderClient simply stops asking frames from |
| 756 // WebMediaPlayerMS without an explicit notification. We should expect that | 804 // WebMediaPlayerMS without an explicit notification. We should expect that |
| 757 // WebMediaPlayerMS can digest old frames, rather than piling frames up and | 805 // WebMediaPlayerMS can digest old frames, rather than piling frames up and |
| 758 // explode. | 806 // explode. |
| 759 MockMediaStreamVideoRenderer* provider = LoadAndGetFrameProvider(true); | 807 MockMediaStreamVideoRenderer* provider = LoadAndGetFrameProvider(true); |
| 760 | 808 |
| 761 const int kTestBrake = static_cast<int>(FrameType::TEST_BRAKE); | 809 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. | 920 // OnShown() should restart after a forced suspension. |
| 873 player_->OnShown(); | 921 player_->OnShown(); |
| 874 EXPECT_FALSE(player_->paused()); | 922 EXPECT_FALSE(player_->paused()); |
| 875 EXPECT_CALL(*this, DoSetWebLayer(false)); | 923 EXPECT_CALL(*this, DoSetWebLayer(false)); |
| 876 | 924 |
| 877 base::RunLoop().RunUntilIdle(); | 925 base::RunLoop().RunUntilIdle(); |
| 878 } | 926 } |
| 879 #endif | 927 #endif |
| 880 | 928 |
| 881 } // namespace content | 929 } // namespace content |
| OLD | NEW |