| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" | 53 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" |
| 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/WebSurfaceLayerBridge.h" |
| 63 #include "third_party/WebKit/public/platform/WebURL.h" | 64 #include "third_party/WebKit/public/platform/WebURL.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 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 preroll_attempt_pending_(false), | 253 preroll_attempt_pending_(false), |
| 253 observer_(params->media_observer()), | 254 observer_(params->media_observer()), |
| 254 max_keyframe_distance_to_disable_background_video_( | 255 max_keyframe_distance_to_disable_background_video_( |
| 255 params->max_keyframe_distance_to_disable_background_video()), | 256 params->max_keyframe_distance_to_disable_background_video()), |
| 256 max_keyframe_distance_to_disable_background_video_mse_( | 257 max_keyframe_distance_to_disable_background_video_mse_( |
| 257 params->max_keyframe_distance_to_disable_background_video_mse()), | 258 params->max_keyframe_distance_to_disable_background_video_mse()), |
| 258 enable_instant_source_buffer_gc_( | 259 enable_instant_source_buffer_gc_( |
| 259 params->enable_instant_source_buffer_gc()), | 260 params->enable_instant_source_buffer_gc()), |
| 260 embedded_media_experience_enabled_( | 261 embedded_media_experience_enabled_( |
| 261 params->embedded_media_experience_enabled()), | 262 params->embedded_media_experience_enabled()), |
| 263 surface_layer_for_video_enabled_( |
| 264 base::FeatureList::IsEnabled(media::kUseSurfaceLayerForVideo)), |
| 262 request_routing_token_cb_(params->request_routing_token_cb()), | 265 request_routing_token_cb_(params->request_routing_token_cb()), |
| 263 overlay_routing_token_(OverlayInfo::RoutingToken()) { | 266 overlay_routing_token_(OverlayInfo::RoutingToken()) { |
| 264 DVLOG(1) << __func__; | 267 DVLOG(1) << __func__; |
| 265 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 268 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 266 DCHECK(renderer_factory_selector_); | 269 DCHECK(renderer_factory_selector_); |
| 267 DCHECK(client_); | 270 DCHECK(client_); |
| 268 DCHECK(delegate_); | 271 DCHECK(delegate_); |
| 269 | 272 |
| 273 if (surface_layer_for_video_enabled_) |
| 274 bridge_ = base::WrapUnique(blink::WebSurfaceLayerBridge::Create()); |
| 275 |
| 270 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 276 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 271 switches::kForceVideoOverlays); | 277 switches::kForceVideoOverlays); |
| 272 | 278 |
| 273 if (base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo)) { | 279 if (base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo)) { |
| 274 bool use_android_overlay = | 280 bool use_android_overlay = |
| 275 base::FeatureList::IsEnabled(media::kUseAndroidOverlay); | 281 base::FeatureList::IsEnabled(media::kUseAndroidOverlay); |
| 276 overlay_mode_ = use_android_overlay ? OverlayMode::kUseAndroidOverlay | 282 overlay_mode_ = use_android_overlay ? OverlayMode::kUseAndroidOverlay |
| 277 : OverlayMode::kUseContentVideoView; | 283 : OverlayMode::kUseContentVideoView; |
| 278 } else { | 284 } else { |
| 279 overlay_mode_ = OverlayMode::kNoOverlays; | 285 overlay_mode_ = OverlayMode::kNoOverlays; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 watch_time_reporter_.reset(); | 322 watch_time_reporter_.reset(); |
| 317 | 323 |
| 318 // The underlying Pipeline must be stopped before it is destroyed. | 324 // The underlying Pipeline must be stopped before it is destroyed. |
| 319 pipeline_controller_.Stop(); | 325 pipeline_controller_.Stop(); |
| 320 | 326 |
| 321 if (last_reported_memory_usage_) | 327 if (last_reported_memory_usage_) |
| 322 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); | 328 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); |
| 323 | 329 |
| 324 // Destruct compositor resources in the proper order. | 330 // Destruct compositor resources in the proper order. |
| 325 client_->SetWebLayer(nullptr); | 331 client_->SetWebLayer(nullptr); |
| 326 if (video_weblayer_) | 332 if (!surface_layer_for_video_enabled_ && video_weblayer_) { |
| 327 static_cast<cc::VideoLayer*>(video_weblayer_->layer())->StopUsingProvider(); | 333 static_cast<cc::VideoLayer*>(video_weblayer_->layer())->StopUsingProvider(); |
| 334 } |
| 335 // TODO(lethalantidote): Handle destruction of compositor for surface layer. |
| 336 // https://crbug/739854. |
| 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 (!surface_layer_for_video_enabled_) { |
| 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 if (bridge_->GetWebLayer()) { |
| 1369 bridge_->GetWebLayer()->CcLayer()->SetContentsOpaque(opaque_); |
| 1370 // TODO(lethalantidote): Figure out how to persist opaque setting |
| 1371 // without calling WebLayerImpl's SetContentsOpaueIsFixed; |
| 1372 // https://crbug/739859. |
| 1373 client_->SetWebLayer(bridge_->GetWebLayer()); |
| 1374 } |
| 1358 } | 1375 } |
| 1359 | 1376 |
| 1360 if (observer_) | 1377 if (observer_) |
| 1361 observer_->OnMetadataChanged(pipeline_metadata_); | 1378 observer_->OnMetadataChanged(pipeline_metadata_); |
| 1362 | 1379 |
| 1363 CreateWatchTimeReporter(); | 1380 CreateWatchTimeReporter(); |
| 1364 UpdatePlayState(); | 1381 UpdatePlayState(); |
| 1365 } | 1382 } |
| 1366 | 1383 |
| 1367 void WebMediaPlayerImpl::OnProgress() { | 1384 void WebMediaPlayerImpl::OnProgress() { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 delegate_->DidPlayerSizeChange(delegate_id_, NaturalSize()); | 1558 delegate_->DidPlayerSizeChange(delegate_id_, NaturalSize()); |
| 1542 } | 1559 } |
| 1543 | 1560 |
| 1544 void WebMediaPlayerImpl::OnVideoOpacityChange(bool opaque) { | 1561 void WebMediaPlayerImpl::OnVideoOpacityChange(bool opaque) { |
| 1545 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1562 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1546 DCHECK_NE(ready_state_, WebMediaPlayer::kReadyStateHaveNothing); | 1563 DCHECK_NE(ready_state_, WebMediaPlayer::kReadyStateHaveNothing); |
| 1547 | 1564 |
| 1548 opaque_ = opaque; | 1565 opaque_ = opaque; |
| 1549 // Modify content opaqueness of cc::Layer directly so that | 1566 // Modify content opaqueness of cc::Layer directly so that |
| 1550 // SetContentsOpaqueIsFixed is ignored. | 1567 // SetContentsOpaqueIsFixed is ignored. |
| 1551 if (video_weblayer_) | 1568 if (!surface_layer_for_video_enabled_) { |
| 1552 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1569 if (video_weblayer_) |
| 1570 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
| 1571 } else if (bridge_->GetWebLayer()) { |
| 1572 bridge_->GetWebLayer()->CcLayer()->SetContentsOpaque(opaque_); |
| 1573 } |
| 1553 } | 1574 } |
| 1554 | 1575 |
| 1555 void WebMediaPlayerImpl::OnVideoAverageKeyframeDistanceUpdate() { | 1576 void WebMediaPlayerImpl::OnVideoAverageKeyframeDistanceUpdate() { |
| 1556 UpdateBackgroundVideoOptimizationState(); | 1577 UpdateBackgroundVideoOptimizationState(); |
| 1557 } | 1578 } |
| 1558 | 1579 |
| 1559 void WebMediaPlayerImpl::OnFrameHidden() { | 1580 void WebMediaPlayerImpl::OnFrameHidden() { |
| 1560 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1581 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1561 | 1582 |
| 1562 // Backgrounding a video requires a user gesture to resume playback. | 1583 // 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()) { | 1737 !IsNewRemotePlaybackPipelineEnabled()) { |
| 1717 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | 1738 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
| 1718 if (frame) | 1739 if (frame) |
| 1719 compositor_->PaintSingleFrame(frame); | 1740 compositor_->PaintSingleFrame(frame); |
| 1720 } | 1741 } |
| 1721 | 1742 |
| 1722 UpdatePlayState(); | 1743 UpdatePlayState(); |
| 1723 } | 1744 } |
| 1724 | 1745 |
| 1725 gfx::Size WebMediaPlayerImpl::GetCanvasSize() const { | 1746 gfx::Size WebMediaPlayerImpl::GetCanvasSize() const { |
| 1726 if (!video_weblayer_) | 1747 if (!surface_layer_for_video_enabled_) { |
| 1748 if (!video_weblayer_) |
| 1749 return pipeline_metadata_.natural_size; |
| 1750 |
| 1751 return video_weblayer_->Bounds(); |
| 1752 } |
| 1753 if (!bridge_->GetWebLayer()) |
| 1727 return pipeline_metadata_.natural_size; | 1754 return pipeline_metadata_.natural_size; |
| 1728 | 1755 |
| 1729 return video_weblayer_->Bounds(); | 1756 return bridge_->GetWebLayer()->Bounds(); |
| 1730 } | 1757 } |
| 1731 | 1758 |
| 1732 void WebMediaPlayerImpl::SetDeviceScaleFactor(float scale_factor) { | 1759 void WebMediaPlayerImpl::SetDeviceScaleFactor(float scale_factor) { |
| 1733 cast_impl_.SetDeviceScaleFactor(scale_factor); | 1760 cast_impl_.SetDeviceScaleFactor(scale_factor); |
| 1734 } | 1761 } |
| 1735 | 1762 |
| 1736 void WebMediaPlayerImpl::SetPoster(const blink::WebURL& poster) { | 1763 void WebMediaPlayerImpl::SetPoster(const blink::WebURL& poster) { |
| 1737 cast_impl_.setPoster(poster); | 1764 cast_impl_.setPoster(poster); |
| 1738 } | 1765 } |
| 1739 #endif // defined(OS_ANDROID) // WMPI_CAST | 1766 #endif // defined(OS_ANDROID) // WMPI_CAST |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2602 } | 2629 } |
| 2603 | 2630 |
| 2604 #undef UMA_HISTOGRAM_VIDEO_HEIGHT | 2631 #undef UMA_HISTOGRAM_VIDEO_HEIGHT |
| 2605 | 2632 |
| 2606 void WebMediaPlayerImpl::SetTickClockForTest(base::TickClock* tick_clock) { | 2633 void WebMediaPlayerImpl::SetTickClockForTest(base::TickClock* tick_clock) { |
| 2607 tick_clock_.reset(tick_clock); | 2634 tick_clock_.reset(tick_clock); |
| 2608 buffered_data_source_host_.SetTickClockForTest(tick_clock); | 2635 buffered_data_source_host_.SetTickClockForTest(tick_clock); |
| 2609 } | 2636 } |
| 2610 | 2637 |
| 2611 } // namespace media | 2638 } // namespace media |
| OLD | NEW |