| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "media/blink/webmediaplayer_impl.h" | 5 #include "media/blink/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "media/base/media_log.h" | 20 #include "media/base/media_log.h" |
| 21 #include "media/base/test_helpers.h" | 21 #include "media/base/test_helpers.h" |
| 22 #include "media/blink/mock_webframeclient.h" | 22 #include "media/blink/mock_webframeclient.h" |
| 23 #include "media/blink/webmediaplayer_delegate.h" | 23 #include "media/blink/webmediaplayer_delegate.h" |
| 24 #include "media/blink/webmediaplayer_params.h" | 24 #include "media/blink/webmediaplayer_params.h" |
| 25 #include "media/renderers/default_renderer_factory.h" | 25 #include "media/renderers/default_renderer_factory.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 28 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 29 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 29 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 30 #include "third_party/WebKit/public/platform/WebSize.h" |
| 30 #include "third_party/WebKit/public/web/WebFrameClient.h" | 31 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 32 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 32 #include "third_party/WebKit/public/web/WebView.h" | 33 #include "third_party/WebKit/public/web/WebView.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| 35 namespace media { | 36 namespace media { |
| 36 | 37 |
| 37 int64_t OnAdjustAllocatedMemory(int64_t delta) { | 38 int64_t OnAdjustAllocatedMemory(int64_t delta) { |
| 38 return 0; | 39 return 0; |
| 39 } | 40 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 wmpi_->overlay_enabled_ = is_fullscreen; | 138 wmpi_->overlay_enabled_ = is_fullscreen; |
| 138 } | 139 } |
| 139 | 140 |
| 140 void SetMetadata(bool has_audio, bool has_video) { | 141 void SetMetadata(bool has_audio, bool has_video) { |
| 141 wmpi_->SetNetworkState(blink::WebMediaPlayer::NetworkStateLoaded); | 142 wmpi_->SetNetworkState(blink::WebMediaPlayer::NetworkStateLoaded); |
| 142 wmpi_->SetReadyState(blink::WebMediaPlayer::ReadyStateHaveMetadata); | 143 wmpi_->SetReadyState(blink::WebMediaPlayer::ReadyStateHaveMetadata); |
| 143 wmpi_->pipeline_metadata_.has_audio = has_audio; | 144 wmpi_->pipeline_metadata_.has_audio = has_audio; |
| 144 wmpi_->pipeline_metadata_.has_video = has_video; | 145 wmpi_->pipeline_metadata_.has_video = has_video; |
| 145 } | 146 } |
| 146 | 147 |
| 148 void OnMetadata(PipelineMetadata metadata) { wmpi_->OnMetadata(metadata); } |
| 149 |
| 150 void OnVideoNaturalSizeChange(const gfx::Size& size) { |
| 151 wmpi_->OnVideoNaturalSizeChange(size); |
| 152 } |
| 153 |
| 147 WebMediaPlayerImpl::PlayState ComputePlayState() { | 154 WebMediaPlayerImpl::PlayState ComputePlayState() { |
| 148 wmpi_->is_idle_ = false; | 155 wmpi_->is_idle_ = false; |
| 149 wmpi_->must_suspend_ = false; | 156 wmpi_->must_suspend_ = false; |
| 150 return wmpi_->UpdatePlayState_ComputePlayState(false, false, false); | 157 return wmpi_->UpdatePlayState_ComputePlayState(false, false, false); |
| 151 } | 158 } |
| 152 | 159 |
| 153 WebMediaPlayerImpl::PlayState ComputePlayStateSuspended() { | 160 WebMediaPlayerImpl::PlayState ComputePlayStateSuspended() { |
| 154 wmpi_->is_idle_ = false; | 161 wmpi_->is_idle_ = false; |
| 155 wmpi_->must_suspend_ = false; | 162 wmpi_->must_suspend_ = false; |
| 156 return wmpi_->UpdatePlayState_ComputePlayState(false, true, false); | 163 return wmpi_->UpdatePlayState_ComputePlayState(false, true, false); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 EXPECT_FALSE(state.is_memory_reporting_enabled); | 468 EXPECT_FALSE(state.is_memory_reporting_enabled); |
| 462 EXPECT_FALSE(state.is_suspended); | 469 EXPECT_FALSE(state.is_suspended); |
| 463 | 470 |
| 464 SetPaused(false); | 471 SetPaused(false); |
| 465 state = ComputePlayStateSuspended(); | 472 state = ComputePlayStateSuspended(); |
| 466 EXPECT_EQ(WebMediaPlayerImpl::DelegateState::PLAYING, state.delegate_state); | 473 EXPECT_EQ(WebMediaPlayerImpl::DelegateState::PLAYING, state.delegate_state); |
| 467 EXPECT_TRUE(state.is_memory_reporting_enabled); | 474 EXPECT_TRUE(state.is_memory_reporting_enabled); |
| 468 EXPECT_FALSE(state.is_suspended); | 475 EXPECT_FALSE(state.is_suspended); |
| 469 } | 476 } |
| 470 | 477 |
| 478 TEST_F(WebMediaPlayerImplTest, NaturalSizeChange) { |
| 479 PipelineMetadata metadata; |
| 480 metadata.has_video = true; |
| 481 metadata.natural_size = gfx::Size(320, 240); |
| 482 |
| 483 OnMetadata(metadata); |
| 484 ASSERT_EQ(blink::WebSize(320, 240), wmpi_->naturalSize()); |
| 485 |
| 486 // TODO(sandersd): Verify that the client is notified of the size change? |
| 487 OnVideoNaturalSizeChange(gfx::Size(1920, 1080)); |
| 488 ASSERT_EQ(blink::WebSize(1920, 1080), wmpi_->naturalSize()); |
| 489 } |
| 490 |
| 491 TEST_F(WebMediaPlayerImplTest, NaturalSizeChange_Rotated) { |
| 492 PipelineMetadata metadata; |
| 493 metadata.has_video = true; |
| 494 metadata.natural_size = gfx::Size(320, 240); |
| 495 metadata.video_rotation = VIDEO_ROTATION_90; |
| 496 |
| 497 // For 90/270deg rotations, the natural size should be transposed. |
| 498 OnMetadata(metadata); |
| 499 ASSERT_EQ(blink::WebSize(240, 320), wmpi_->naturalSize()); |
| 500 |
| 501 OnVideoNaturalSizeChange(gfx::Size(1920, 1080)); |
| 502 ASSERT_EQ(blink::WebSize(1080, 1920), wmpi_->naturalSize()); |
| 503 } |
| 504 |
| 471 } // namespace media | 505 } // namespace media |
| OLD | NEW |