| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 load_type_(LoadTypeURL), | 174 load_type_(LoadTypeURL), |
| 175 opaque_(false), | 175 opaque_(false), |
| 176 playback_rate_(0.0), | 176 playback_rate_(0.0), |
| 177 paused_(true), | 177 paused_(true), |
| 178 seeking_(false), | 178 seeking_(false), |
| 179 pending_suspend_resume_cycle_(false), | 179 pending_suspend_resume_cycle_(false), |
| 180 ended_(false), | 180 ended_(false), |
| 181 should_notify_time_changed_(false), | 181 should_notify_time_changed_(false), |
| 182 fullscreen_(false), | 182 fullscreen_(false), |
| 183 decoder_requires_restart_for_fullscreen_(false), | 183 decoder_requires_restart_for_fullscreen_(false), |
| 184 supports_overlay_fullscreen_video_(false), | |
| 185 client_(client), | 184 client_(client), |
| 186 encrypted_client_(encrypted_client), | 185 encrypted_client_(encrypted_client), |
| 187 delegate_(delegate), | 186 delegate_(delegate), |
| 188 delegate_id_(0), | 187 delegate_id_(0), |
| 189 defer_load_cb_(params.defer_load_cb()), | 188 defer_load_cb_(params.defer_load_cb()), |
| 190 context_3d_cb_(params.context_3d_cb()), | 189 context_3d_cb_(params.context_3d_cb()), |
| 191 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), | 190 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
| 192 last_reported_memory_usage_(0), | 191 last_reported_memory_usage_(0), |
| 193 supports_save_(true), | 192 supports_save_(true), |
| 194 chunk_demuxer_(NULL), | 193 chunk_demuxer_(NULL), |
| 195 url_index_(url_index), | 194 url_index_(url_index), |
| 196 // Threaded compositing isn't enabled universally yet. | 195 // Threaded compositing isn't enabled universally yet. |
| 197 compositor_task_runner_(params.compositor_task_runner() | 196 compositor_task_runner_(params.compositor_task_runner() |
| 198 ? params.compositor_task_runner() | 197 ? params.compositor_task_runner() |
| 199 : base::ThreadTaskRunnerHandle::Get()), | 198 : base::ThreadTaskRunnerHandle::Get()), |
| 200 compositor_(new VideoFrameCompositor(compositor_task_runner_)), | 199 compositor_(new VideoFrameCompositor(compositor_task_runner_)), |
| 201 is_cdm_attached_(false), | 200 is_cdm_attached_(false), |
| 202 #if defined(OS_ANDROID) // WMPI_CAST | 201 #if defined(OS_ANDROID) // WMPI_CAST |
| 203 cast_impl_(this, client_, params.context_3d_cb()), | 202 cast_impl_(this, client_, params.context_3d_cb()), |
| 204 #endif | 203 #endif |
| 205 volume_(1.0), | 204 volume_(1.0), |
| 206 volume_multiplier_(1.0), | 205 volume_multiplier_(1.0), |
| 207 renderer_factory_(std::move(renderer_factory)), | 206 renderer_factory_(std::move(renderer_factory)), |
| 208 surface_manager_(params.surface_manager()), | 207 surface_manager_(params.surface_manager()), |
| 208 fullscreen_surface_id_(SurfaceManager::kNoSurfaceID), |
| 209 suppress_destruction_errors_(false), | 209 suppress_destruction_errors_(false), |
| 210 can_suspend_state_(CanSuspendState::UNKNOWN) { | 210 can_suspend_state_(CanSuspendState::UNKNOWN) { |
| 211 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 211 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 212 DCHECK(renderer_factory_); | 212 DCHECK(renderer_factory_); |
| 213 DCHECK(client_); | 213 DCHECK(client_); |
| 214 | 214 |
| 215 if (delegate_) | 215 if (delegate_) |
| 216 delegate_id_ = delegate_->AddObserver(this); | 216 delegate_id_ = delegate_->AddObserver(this); |
| 217 | 217 |
| 218 media_log_->AddEvent( | 218 media_log_->AddEvent( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 if (!defer_load_cb_.is_null()) { | 270 if (!defer_load_cb_.is_null()) { |
| 271 defer_load_cb_.Run(base::Bind( | 271 defer_load_cb_.Run(base::Bind( |
| 272 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); | 272 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); |
| 273 return; | 273 return; |
| 274 } | 274 } |
| 275 DoLoad(load_type, url, cors_mode); | 275 DoLoad(load_type, url, cors_mode); |
| 276 } | 276 } |
| 277 | 277 |
| 278 bool WebMediaPlayerImpl::supportsOverlayFullscreenVideo() { | 278 bool WebMediaPlayerImpl::supportsOverlayFullscreenVideo() { |
| 279 #if defined(OS_ANDROID) | 279 #if defined(OS_ANDROID) |
| 280 // OverlayFullscreenVideo is only used when we're H/W decoding to an | 280 return true; |
| 281 // SurfaceView underlay on Android. It's possible that we haven't initialized | |
| 282 // any decoders before entering fullscreen, so we won't know whether to use | |
| 283 // OverlayFullscreenVideo. In that case we'll default to | |
| 284 // non-OverlayFullscreenVideo, which still works correctly, but has janky | |
| 285 // orientation changes. | |
| 286 | |
| 287 // We return a consistent value while in fullscreen to avoid us getting into a | |
| 288 // state where some of the OverlayFullscreenVideo adjustments are applied and | |
| 289 // some aren't. | |
| 290 // TODO(watk): Implement dynamic OverlayFullscreenVideo switching in blink. | |
| 291 if (!fullscreen_) { | |
| 292 supports_overlay_fullscreen_video_ = | |
| 293 decoder_requires_restart_for_fullscreen_; | |
| 294 } | |
| 295 return supports_overlay_fullscreen_video_; | |
| 296 #else | 281 #else |
| 297 return false; | 282 return false; |
| 298 #endif | 283 #endif |
| 299 } | 284 } |
| 300 | 285 |
| 301 void WebMediaPlayerImpl::enteredFullscreen() { | 286 void WebMediaPlayerImpl::enteredFullscreen() { |
| 302 fullscreen_ = true; | 287 fullscreen_ = true; |
| 288 if (surface_manager_) { |
| 289 surface_created_cb_.Reset( |
| 290 base::Bind(&WebMediaPlayerImpl::OnSurfaceCreated, AsWeakPtr())); |
| 291 surface_manager_->CreateFullscreenSurface(pipeline_metadata_.natural_size, |
| 292 surface_created_cb_.callback()); |
| 293 } |
| 303 if (decoder_requires_restart_for_fullscreen_) | 294 if (decoder_requires_restart_for_fullscreen_) |
| 304 ScheduleRestart(); | 295 ScheduleRestart(); |
| 305 } | 296 } |
| 306 | 297 |
| 307 void WebMediaPlayerImpl::exitedFullscreen() { | 298 void WebMediaPlayerImpl::exitedFullscreen() { |
| 308 fullscreen_ = false; | 299 fullscreen_ = false; |
| 300 surface_created_cb_.Cancel(); |
| 301 fullscreen_surface_id_ = SurfaceManager::kNoSurfaceID; |
| 309 if (decoder_requires_restart_for_fullscreen_) | 302 if (decoder_requires_restart_for_fullscreen_) |
| 310 ScheduleRestart(); | 303 ScheduleRestart(); |
| 311 } | 304 } |
| 312 | 305 |
| 313 void WebMediaPlayerImpl::DoLoad(LoadType load_type, | 306 void WebMediaPlayerImpl::DoLoad(LoadType load_type, |
| 314 const blink::WebURL& url, | 307 const blink::WebURL& url, |
| 315 CORSMode cors_mode) { | 308 CORSMode cors_mode) { |
| 316 DVLOG(1) << __FUNCTION__; | 309 DVLOG(1) << __FUNCTION__; |
| 317 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 310 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 318 | 311 |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 DVLOG(1) << __FUNCTION__; | 968 DVLOG(1) << __FUNCTION__; |
| 976 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 969 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 977 | 970 |
| 978 pipeline_metadata_ = metadata; | 971 pipeline_metadata_ = metadata; |
| 979 | 972 |
| 980 UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, | 973 UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, |
| 981 VIDEO_ROTATION_MAX + 1); | 974 VIDEO_ROTATION_MAX + 1); |
| 982 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 975 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 983 | 976 |
| 984 if (hasVideo()) { | 977 if (hasVideo()) { |
| 985 DCHECK(!video_weblayer_); | |
| 986 | |
| 987 if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 || | 978 if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 || |
| 988 pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) { | 979 pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) { |
| 989 gfx::Size size = pipeline_metadata_.natural_size; | 980 gfx::Size size = pipeline_metadata_.natural_size; |
| 990 pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width()); | 981 pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width()); |
| 991 } | 982 } |
| 992 | 983 |
| 984 if (fullscreen_ && surface_manager_) |
| 985 surface_manager_->NaturalSizeChanged(pipeline_metadata_.natural_size); |
| 986 |
| 987 DCHECK(!video_weblayer_); |
| 993 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( | 988 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( |
| 994 compositor_, pipeline_metadata_.video_rotation))); | 989 compositor_, pipeline_metadata_.video_rotation))); |
| 995 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 990 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
| 996 video_weblayer_->SetContentsOpaqueIsFixed(true); | 991 video_weblayer_->SetContentsOpaqueIsFixed(true); |
| 997 client_->setWebLayer(video_weblayer_.get()); | 992 client_->setWebLayer(video_weblayer_.get()); |
| 998 } | 993 } |
| 999 | 994 |
| 1000 UpdatePlayState(); | 995 UpdatePlayState(); |
| 1001 } | 996 } |
| 1002 | 997 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) | 1252 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) |
| 1258 SetNetworkState(WebMediaPlayer::NetworkStateIdle); | 1253 SetNetworkState(WebMediaPlayer::NetworkStateIdle); |
| 1259 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) | 1254 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) |
| 1260 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 1255 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 1261 media_log_->AddEvent( | 1256 media_log_->AddEvent( |
| 1262 media_log_->CreateBooleanEvent( | 1257 media_log_->CreateBooleanEvent( |
| 1263 MediaLogEvent::NETWORK_ACTIVITY_SET, | 1258 MediaLogEvent::NETWORK_ACTIVITY_SET, |
| 1264 "is_downloading_data", is_downloading)); | 1259 "is_downloading_data", is_downloading)); |
| 1265 } | 1260 } |
| 1266 | 1261 |
| 1262 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) { |
| 1263 fullscreen_surface_id_ = surface_id; |
| 1264 if (!pending_surface_request_cb_.is_null()) |
| 1265 base::ResetAndReturn(&pending_surface_request_cb_).Run(surface_id); |
| 1266 } |
| 1267 |
| 1267 // TODO(watk): Move this state management out of WMPI. | 1268 // TODO(watk): Move this state management out of WMPI. |
| 1268 void WebMediaPlayerImpl::OnSurfaceRequested( | 1269 void WebMediaPlayerImpl::OnSurfaceRequested( |
| 1269 const SurfaceCreatedCB& surface_created_cb) { | 1270 const SurfaceCreatedCB& surface_created_cb) { |
| 1270 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1271 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1271 DCHECK(surface_manager_); | 1272 DCHECK(surface_manager_); |
| 1272 | 1273 |
| 1273 // A null callback indicates that the decoder is going away. | 1274 // A null callback indicates that the decoder is going away. |
| 1274 if (surface_created_cb.is_null()) { | 1275 if (surface_created_cb.is_null()) { |
| 1275 decoder_requires_restart_for_fullscreen_ = false; | 1276 decoder_requires_restart_for_fullscreen_ = false; |
| 1277 pending_surface_request_cb_.Reset(); |
| 1276 return; | 1278 return; |
| 1277 } | 1279 } |
| 1278 | 1280 |
| 1279 // If we're getting a surface request it means GVD is initializing, so until | 1281 // If we're getting a surface request it means GVD is initializing, so until |
| 1280 // we get a null surface request, GVD is the active decoder. While that's the | 1282 // we get a null surface request, GVD is the active decoder. While that's the |
| 1281 // case we should restart the pipeline on fullscreen transitions so that when | 1283 // case we should restart the pipeline on fullscreen transitions so that when |
| 1282 // we create a new GVD it will request a surface again and get the right kind | 1284 // we create a new GVD it will request a surface again and get the right kind |
| 1283 // of surface for the fullscreen state. | 1285 // of surface for the fullscreen state. |
| 1284 // TODO(watk): Don't require a pipeline restart to switch surfaces for | 1286 // TODO(watk): Don't require a pipeline restart to switch surfaces for |
| 1285 // cases where it isn't necessary. | 1287 // cases where it isn't necessary. |
| 1286 decoder_requires_restart_for_fullscreen_ = true; | 1288 decoder_requires_restart_for_fullscreen_ = true; |
| 1287 if (fullscreen_) { | 1289 if (fullscreen_) { |
| 1288 surface_manager_->CreateFullscreenSurface(pipeline_metadata_.natural_size, | 1290 if (fullscreen_surface_id_ != SurfaceManager::kNoSurfaceID) |
| 1289 surface_created_cb); | 1291 surface_created_cb.Run(fullscreen_surface_id_); |
| 1292 else |
| 1293 pending_surface_request_cb_ = surface_created_cb; |
| 1290 } else { | 1294 } else { |
| 1291 // Tell the decoder to create its own surface. | 1295 // Tell the decoder to create its own surface. |
| 1292 surface_created_cb.Run(SurfaceManager::kNoSurfaceID); | 1296 surface_created_cb.Run(SurfaceManager::kNoSurfaceID); |
| 1293 } | 1297 } |
| 1294 } | 1298 } |
| 1295 | 1299 |
| 1296 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { | 1300 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { |
| 1297 RequestSurfaceCB request_surface_cb; | 1301 RequestSurfaceCB request_surface_cb; |
| 1298 #if defined(OS_ANDROID) | 1302 #if defined(OS_ANDROID) |
| 1299 request_surface_cb = | 1303 request_surface_cb = |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 if (isRemote()) | 1659 if (isRemote()) |
| 1656 return; | 1660 return; |
| 1657 #endif | 1661 #endif |
| 1658 | 1662 |
| 1659 // Idle timeout chosen arbitrarily. | 1663 // Idle timeout chosen arbitrarily. |
| 1660 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), | 1664 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), |
| 1661 this, &WebMediaPlayerImpl::OnPause); | 1665 this, &WebMediaPlayerImpl::OnPause); |
| 1662 } | 1666 } |
| 1663 | 1667 |
| 1664 } // namespace media | 1668 } // namespace media |
| OLD | NEW |