OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <string> | 10 #include <string> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 54 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
55 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient. h" | 55 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient. h" |
56 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" | 56 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" |
57 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 57 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
58 #include "third_party/WebKit/public/platform/WebRect.h" | 58 #include "third_party/WebKit/public/platform/WebRect.h" |
59 #include "third_party/WebKit/public/platform/WebRuntimeFeatures.h" | 59 #include "third_party/WebKit/public/platform/WebRuntimeFeatures.h" |
60 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 60 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
61 #include "third_party/WebKit/public/platform/WebSize.h" | 61 #include "third_party/WebKit/public/platform/WebSize.h" |
62 #include "third_party/WebKit/public/platform/WebString.h" | 62 #include "third_party/WebKit/public/platform/WebString.h" |
63 #include "third_party/WebKit/public/platform/WebURL.h" | 63 #include "third_party/WebKit/public/platform/WebURL.h" |
64 #include "third_party/WebKit/public/platform/WebVideoSurfaceLayerBridge.h" | |
64 #include "third_party/WebKit/public/web/WebDocument.h" | 65 #include "third_party/WebKit/public/web/WebDocument.h" |
65 #include "third_party/WebKit/public/web/WebFrame.h" | 66 #include "third_party/WebKit/public/web/WebFrame.h" |
66 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 67 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
67 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 68 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
68 #include "third_party/WebKit/public/web/WebView.h" | 69 #include "third_party/WebKit/public/web/WebView.h" |
69 | 70 |
70 #if defined(OS_ANDROID) | 71 #if defined(OS_ANDROID) |
71 #include "media/base/android/media_codec_util.h" | 72 #include "media/base/android/media_codec_util.h" |
72 #endif | 73 #endif |
73 | 74 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 embedded_media_experience_enabled_( | 261 embedded_media_experience_enabled_( |
261 params->embedded_media_experience_enabled()), | 262 params->embedded_media_experience_enabled()), |
262 request_routing_token_cb_(params->request_routing_token_cb()), | 263 request_routing_token_cb_(params->request_routing_token_cb()), |
263 overlay_routing_token_(OverlayInfo::RoutingToken()) { | 264 overlay_routing_token_(OverlayInfo::RoutingToken()) { |
264 DVLOG(1) << __func__; | 265 DVLOG(1) << __func__; |
265 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 266 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
266 DCHECK(renderer_factory_selector_); | 267 DCHECK(renderer_factory_selector_); |
267 DCHECK(client_); | 268 DCHECK(client_); |
268 DCHECK(delegate_); | 269 DCHECK(delegate_); |
269 | 270 |
271 if (base::FeatureList::IsEnabled(media::kUseSurfaceLayerForVideo)) | |
272 bridge_ = base::WrapUnique(blink::WebVideoSurfaceLayerBridge::Create()); | |
273 | |
270 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 274 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
271 switches::kForceVideoOverlays); | 275 switches::kForceVideoOverlays); |
272 | 276 |
273 if (base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo)) { | 277 if (base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo)) { |
274 bool use_android_overlay = | 278 bool use_android_overlay = |
275 base::FeatureList::IsEnabled(media::kUseAndroidOverlay); | 279 base::FeatureList::IsEnabled(media::kUseAndroidOverlay); |
276 overlay_mode_ = use_android_overlay ? OverlayMode::kUseAndroidOverlay | 280 overlay_mode_ = use_android_overlay ? OverlayMode::kUseAndroidOverlay |
277 : OverlayMode::kUseContentVideoView; | 281 : OverlayMode::kUseContentVideoView; |
278 } else { | 282 } else { |
279 overlay_mode_ = OverlayMode::kNoOverlays; | 283 overlay_mode_ = OverlayMode::kNoOverlays; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 watch_time_reporter_.reset(); | 320 watch_time_reporter_.reset(); |
317 | 321 |
318 // The underlying Pipeline must be stopped before it is destroyed. | 322 // The underlying Pipeline must be stopped before it is destroyed. |
319 pipeline_controller_.Stop(); | 323 pipeline_controller_.Stop(); |
320 | 324 |
321 if (last_reported_memory_usage_) | 325 if (last_reported_memory_usage_) |
322 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); | 326 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); |
323 | 327 |
324 // Destruct compositor resources in the proper order. | 328 // Destruct compositor resources in the proper order. |
325 client_->SetWebLayer(nullptr); | 329 client_->SetWebLayer(nullptr); |
326 if (video_weblayer_) | 330 if (!base::FeatureList::IsEnabled(media::kUseSurfaceLayerForVideo) && |
331 video_weblayer_) { | |
327 static_cast<cc::VideoLayer*>(video_weblayer_->layer())->StopUsingProvider(); | 332 static_cast<cc::VideoLayer*>(video_weblayer_->layer())->StopUsingProvider(); |
333 } else { | |
334 if (bridge_->GetWebLayer()) | |
335 static_cast<cc::VideoLayer*>(bridge_->GetCCLayer())->StopUsingProvider(); | |
336 } | |
328 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_); | 337 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_); |
329 | 338 |
330 media_log_->AddEvent( | 339 media_log_->AddEvent( |
331 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); | 340 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
332 } | 341 } |
333 | 342 |
334 void WebMediaPlayerImpl::Load(LoadType load_type, | 343 void WebMediaPlayerImpl::Load(LoadType load_type, |
335 const blink::WebMediaPlayerSource& source, | 344 const blink::WebMediaPlayerSource& source, |
336 CORSMode cors_mode) { | 345 CORSMode cors_mode) { |
337 DVLOG(1) << __func__; | 346 DVLOG(1) << __func__; |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1342 if (overlay_enabled_) { | 1351 if (overlay_enabled_) { |
1343 // SurfaceView doesn't support rotated video, so transition back if | 1352 // SurfaceView doesn't support rotated video, so transition back if |
1344 // the video is now rotated. If |force_video_overlays_|, we keep the | 1353 // the video is now rotated. If |force_video_overlays_|, we keep the |
1345 // overlay anyway so that the state machine keeps working. | 1354 // overlay anyway so that the state machine keeps working. |
1346 if (!force_video_overlays_ && !DoesOverlaySupportMetadata()) | 1355 if (!force_video_overlays_ && !DoesOverlaySupportMetadata()) |
1347 DisableOverlay(); | 1356 DisableOverlay(); |
1348 else if (surface_manager_) | 1357 else if (surface_manager_) |
1349 surface_manager_->NaturalSizeChanged(pipeline_metadata_.natural_size); | 1358 surface_manager_->NaturalSizeChanged(pipeline_metadata_.natural_size); |
1350 } | 1359 } |
1351 | 1360 |
1352 DCHECK(!video_weblayer_); | 1361 if (!base::FeatureList::IsEnabled(media::kUseSurfaceLayerForVideo)) { |
1353 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( | 1362 DCHECK(!video_weblayer_); |
1354 compositor_, pipeline_metadata_.video_rotation))); | 1363 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( |
1355 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1364 compositor_, pipeline_metadata_.video_rotation))); |
1356 video_weblayer_->SetContentsOpaqueIsFixed(true); | 1365 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
1357 client_->SetWebLayer(video_weblayer_.get()); | 1366 video_weblayer_->SetContentsOpaqueIsFixed(true); |
1367 client_->SetWebLayer(video_weblayer_.get()); | |
1368 } else { | |
1369 if (bridge_->GetWebLayer()) { | |
1370 bridge_->GetCCLayer()->SetContentsOpaque(opaque_); | |
enne (OOO)
2017/07/06 01:23:31
To be honest, I'm not sure that this is necessary?
| |
1371 // TODO(lethalantidote): Figure out how to persist opaque setting | |
1372 // without calling WebLayerImpl's SetContentsOpaueIsFixed; | |
1373 client_->SetWebLayer(bridge_->GetWebLayer()); | |
1374 } | |
1375 } | |
1358 } | 1376 } |
1359 | 1377 |
1360 if (observer_) | 1378 if (observer_) |
1361 observer_->OnMetadataChanged(pipeline_metadata_); | 1379 observer_->OnMetadataChanged(pipeline_metadata_); |
1362 | 1380 |
1363 CreateWatchTimeReporter(); | 1381 CreateWatchTimeReporter(); |
1364 UpdatePlayState(); | 1382 UpdatePlayState(); |
1365 } | 1383 } |
1366 | 1384 |
1367 void WebMediaPlayerImpl::OnProgress() { | 1385 void WebMediaPlayerImpl::OnProgress() { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1541 delegate_->DidPlayerSizeChange(delegate_id_, NaturalSize()); | 1559 delegate_->DidPlayerSizeChange(delegate_id_, NaturalSize()); |
1542 } | 1560 } |
1543 | 1561 |
1544 void WebMediaPlayerImpl::OnVideoOpacityChange(bool opaque) { | 1562 void WebMediaPlayerImpl::OnVideoOpacityChange(bool opaque) { |
1545 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1563 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1546 DCHECK_NE(ready_state_, WebMediaPlayer::kReadyStateHaveNothing); | 1564 DCHECK_NE(ready_state_, WebMediaPlayer::kReadyStateHaveNothing); |
1547 | 1565 |
1548 opaque_ = opaque; | 1566 opaque_ = opaque; |
1549 // Modify content opaqueness of cc::Layer directly so that | 1567 // Modify content opaqueness of cc::Layer directly so that |
1550 // SetContentsOpaqueIsFixed is ignored. | 1568 // SetContentsOpaqueIsFixed is ignored. |
1551 if (video_weblayer_) | 1569 if (!base::FeatureList::IsEnabled(media::kUseSurfaceLayerForVideo)) { |
1552 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1570 if (video_weblayer_) |
1571 video_weblayer_->layer()->SetContentsOpaque(opaque_); | |
1572 } else { | |
1573 if (bridge_->GetWebLayer()) { | |
1574 bridge_->GetCCLayer()->SetContentsOpaque(opaque_); | |
1575 } | |
1576 } | |
1553 } | 1577 } |
1554 | 1578 |
1555 void WebMediaPlayerImpl::OnVideoAverageKeyframeDistanceUpdate() { | 1579 void WebMediaPlayerImpl::OnVideoAverageKeyframeDistanceUpdate() { |
1556 UpdateBackgroundVideoOptimizationState(); | 1580 UpdateBackgroundVideoOptimizationState(); |
1557 } | 1581 } |
1558 | 1582 |
1559 void WebMediaPlayerImpl::OnFrameHidden() { | 1583 void WebMediaPlayerImpl::OnFrameHidden() { |
1560 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1584 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1561 | 1585 |
1562 // Backgrounding a video requires a user gesture to resume playback. | 1586 // Backgrounding a video requires a user gesture to resume playback. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1716 !IsNewRemotePlaybackPipelineEnabled()) { | 1740 !IsNewRemotePlaybackPipelineEnabled()) { |
1717 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | 1741 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
1718 if (frame) | 1742 if (frame) |
1719 compositor_->PaintSingleFrame(frame); | 1743 compositor_->PaintSingleFrame(frame); |
1720 } | 1744 } |
1721 | 1745 |
1722 UpdatePlayState(); | 1746 UpdatePlayState(); |
1723 } | 1747 } |
1724 | 1748 |
1725 gfx::Size WebMediaPlayerImpl::GetCanvasSize() const { | 1749 gfx::Size WebMediaPlayerImpl::GetCanvasSize() const { |
1726 if (!video_weblayer_) | 1750 if (!base::FeatureList::IsEnabled(media::kUseSurfaceLayerForVideo) { |
1727 return pipeline_metadata_.natural_size; | 1751 if (!video_weblayer_) |
1752 return pipeline_metadata_.natural_size; | |
1728 | 1753 |
1729 return video_weblayer_->Bounds(); | 1754 return video_weblayer_->Bounds(); |
1755 } else { | |
1756 if (!bridge_->GetWebLayer()) | |
1757 return pipeline_metadate_.natural_size; | |
1758 | |
1759 return bridge_->GetWebLayer()->Bounds(); | |
1760 } | |
1730 } | 1761 } |
1731 | 1762 |
1732 void WebMediaPlayerImpl::SetDeviceScaleFactor(float scale_factor) { | 1763 void WebMediaPlayerImpl::SetDeviceScaleFactor(float scale_factor) { |
1733 cast_impl_.SetDeviceScaleFactor(scale_factor); | 1764 cast_impl_.SetDeviceScaleFactor(scale_factor); |
1734 } | 1765 } |
1735 | 1766 |
1736 void WebMediaPlayerImpl::SetPoster(const blink::WebURL& poster) { | 1767 void WebMediaPlayerImpl::SetPoster(const blink::WebURL& poster) { |
1737 cast_impl_.setPoster(poster); | 1768 cast_impl_.setPoster(poster); |
1738 } | 1769 } |
1739 #endif // defined(OS_ANDROID) // WMPI_CAST | 1770 #endif // defined(OS_ANDROID) // WMPI_CAST |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2602 } | 2633 } |
2603 | 2634 |
2604 #undef UMA_HISTOGRAM_VIDEO_HEIGHT | 2635 #undef UMA_HISTOGRAM_VIDEO_HEIGHT |
2605 | 2636 |
2606 void WebMediaPlayerImpl::SetTickClockForTest(base::TickClock* tick_clock) { | 2637 void WebMediaPlayerImpl::SetTickClockForTest(base::TickClock* tick_clock) { |
2607 tick_clock_.reset(tick_clock); | 2638 tick_clock_.reset(tick_clock); |
2608 buffered_data_source_host_.SetTickClockForTest(tick_clock); | 2639 buffered_data_source_host_.SetTickClockForTest(tick_clock); |
2609 } | 2640 } |
2610 | 2641 |
2611 } // namespace media | 2642 } // namespace media |
OLD | NEW |