Chromium Code Reviews| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 load_type_(LoadTypeURL), | 170 load_type_(LoadTypeURL), |
| 171 opaque_(false), | 171 opaque_(false), |
| 172 playback_rate_(0.0), | 172 playback_rate_(0.0), |
| 173 paused_(true), | 173 paused_(true), |
| 174 seeking_(false), | 174 seeking_(false), |
| 175 pending_suspend_resume_cycle_(false), | 175 pending_suspend_resume_cycle_(false), |
| 176 ended_(false), | 176 ended_(false), |
| 177 should_notify_time_changed_(false), | 177 should_notify_time_changed_(false), |
| 178 fullscreen_(false), | 178 fullscreen_(false), |
| 179 decoder_requires_restart_for_fullscreen_(false), | 179 decoder_requires_restart_for_fullscreen_(false), |
| 180 supports_overlay_fullscreen_video_(false), | |
| 181 client_(client), | 180 client_(client), |
| 182 encrypted_client_(encrypted_client), | 181 encrypted_client_(encrypted_client), |
| 183 delegate_(delegate), | 182 delegate_(delegate), |
| 184 delegate_id_(0), | 183 delegate_id_(0), |
| 185 defer_load_cb_(params.defer_load_cb()), | 184 defer_load_cb_(params.defer_load_cb()), |
| 186 context_3d_cb_(params.context_3d_cb()), | 185 context_3d_cb_(params.context_3d_cb()), |
| 187 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), | 186 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
| 188 last_reported_memory_usage_(0), | 187 last_reported_memory_usage_(0), |
| 189 supports_save_(true), | 188 supports_save_(true), |
| 190 chunk_demuxer_(NULL), | 189 chunk_demuxer_(NULL), |
| 191 url_index_(url_index), | 190 url_index_(url_index), |
| 192 // Threaded compositing isn't enabled universally yet. | 191 // Threaded compositing isn't enabled universally yet. |
| 193 compositor_task_runner_(params.compositor_task_runner() | 192 compositor_task_runner_(params.compositor_task_runner() |
| 194 ? params.compositor_task_runner() | 193 ? params.compositor_task_runner() |
| 195 : base::ThreadTaskRunnerHandle::Get()), | 194 : base::ThreadTaskRunnerHandle::Get()), |
| 196 compositor_(new VideoFrameCompositor(compositor_task_runner_)), | 195 compositor_(new VideoFrameCompositor(compositor_task_runner_)), |
| 197 is_cdm_attached_(false), | 196 is_cdm_attached_(false), |
| 198 #if defined(OS_ANDROID) // WMPI_CAST | 197 #if defined(OS_ANDROID) // WMPI_CAST |
| 199 cast_impl_(this, client_, params.context_3d_cb()), | 198 cast_impl_(this, client_, params.context_3d_cb()), |
| 200 #endif | 199 #endif |
| 201 volume_(1.0), | 200 volume_(1.0), |
| 202 volume_multiplier_(1.0), | 201 volume_multiplier_(1.0), |
| 203 renderer_factory_(std::move(renderer_factory)), | 202 renderer_factory_(std::move(renderer_factory)), |
| 204 surface_manager_(params.surface_manager()), | 203 surface_manager_(params.surface_manager()), |
| 204 fullscreen_surface_id_(SurfaceManager::kNoSurfaceID), | |
| 205 suppress_destruction_errors_(false), | 205 suppress_destruction_errors_(false), |
| 206 can_suspend_state_(CanSuspendState::UNKNOWN) { | 206 can_suspend_state_(CanSuspendState::UNKNOWN) { |
| 207 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 207 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 208 DCHECK(renderer_factory_); | 208 DCHECK(renderer_factory_); |
| 209 DCHECK(client_); | 209 DCHECK(client_); |
| 210 | 210 |
| 211 if (delegate_) | 211 if (delegate_) |
| 212 delegate_id_ = delegate_->AddObserver(this); | 212 delegate_id_ = delegate_->AddObserver(this); |
| 213 | 213 |
| 214 media_log_->AddEvent( | 214 media_log_->AddEvent( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 if (!defer_load_cb_.is_null()) { | 266 if (!defer_load_cb_.is_null()) { |
| 267 defer_load_cb_.Run(base::Bind( | 267 defer_load_cb_.Run(base::Bind( |
| 268 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); | 268 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); |
| 269 return; | 269 return; |
| 270 } | 270 } |
| 271 DoLoad(load_type, url, cors_mode); | 271 DoLoad(load_type, url, cors_mode); |
| 272 } | 272 } |
| 273 | 273 |
| 274 bool WebMediaPlayerImpl::supportsOverlayFullscreenVideo() { | 274 bool WebMediaPlayerImpl::supportsOverlayFullscreenVideo() { |
| 275 #if defined(OS_ANDROID) | 275 #if defined(OS_ANDROID) |
| 276 // OverlayFullscreenVideo is only used when we're H/W decoding to an | 276 return true; |
| 277 // SurfaceView underlay on Android. It's possible that we haven't initialized | |
| 278 // any decoders before entering fullscreen, so we won't know whether to use | |
| 279 // OverlayFullscreenVideo. In that case we'll default to | |
| 280 // non-OverlayFullscreenVideo, which still works correctly, but has janky | |
| 281 // orientation changes. | |
| 282 | |
| 283 // We return a consistent value while in fullscreen to avoid us getting into a | |
| 284 // state where some of the OverlayFullscreenVideo adjustments are applied and | |
| 285 // some aren't. | |
| 286 // TODO(watk): Implement dynamic OverlayFullscreenVideo switching in blink. | |
| 287 if (!fullscreen_) { | |
| 288 supports_overlay_fullscreen_video_ = | |
| 289 decoder_requires_restart_for_fullscreen_; | |
| 290 } | |
| 291 return supports_overlay_fullscreen_video_; | |
| 292 #else | 277 #else |
| 293 return false; | 278 return false; |
| 294 #endif | 279 #endif |
| 295 } | 280 } |
| 296 | 281 |
| 297 void WebMediaPlayerImpl::enteredFullscreen() { | 282 void WebMediaPlayerImpl::enteredFullscreen() { |
| 298 fullscreen_ = true; | 283 fullscreen_ = true; |
| 284 if (surface_manager_) { | |
| 285 surface_manager_->CreateFullscreenSurface( | |
| 286 pipeline_metadata_.natural_size, | |
| 287 base::Bind(&WebMediaPlayerImpl::OnSurfaceCreated, AsWeakPtr())); | |
| 288 } | |
| 299 if (decoder_requires_restart_for_fullscreen_) | 289 if (decoder_requires_restart_for_fullscreen_) |
| 300 ScheduleRestart(); | 290 ScheduleRestart(); |
| 301 } | 291 } |
| 302 | 292 |
| 303 void WebMediaPlayerImpl::exitedFullscreen() { | 293 void WebMediaPlayerImpl::exitedFullscreen() { |
| 304 fullscreen_ = false; | 294 fullscreen_ = false; |
| 295 fullscreen_surface_id_ = SurfaceManager::kNoSurfaceID; | |
|
sandersd (OOO until July 31)
2016/06/23 22:50:51
If we enter and exit fullscreen fast enough, it lo
watk
2016/06/24 20:26:17
Done.
| |
| 305 if (decoder_requires_restart_for_fullscreen_) | 296 if (decoder_requires_restart_for_fullscreen_) |
| 306 ScheduleRestart(); | 297 ScheduleRestart(); |
| 307 } | 298 } |
| 308 | 299 |
| 309 void WebMediaPlayerImpl::DoLoad(LoadType load_type, | 300 void WebMediaPlayerImpl::DoLoad(LoadType load_type, |
| 310 const blink::WebURL& url, | 301 const blink::WebURL& url, |
| 311 CORSMode cors_mode) { | 302 CORSMode cors_mode) { |
| 312 DVLOG(1) << __FUNCTION__; | 303 DVLOG(1) << __FUNCTION__; |
| 313 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 304 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 314 | 305 |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 971 DVLOG(1) << __FUNCTION__; | 962 DVLOG(1) << __FUNCTION__; |
| 972 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 963 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 973 | 964 |
| 974 pipeline_metadata_ = metadata; | 965 pipeline_metadata_ = metadata; |
| 975 | 966 |
| 976 UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, | 967 UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, |
| 977 VIDEO_ROTATION_MAX + 1); | 968 VIDEO_ROTATION_MAX + 1); |
| 978 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 969 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 979 | 970 |
| 980 if (hasVideo()) { | 971 if (hasVideo()) { |
| 981 DCHECK(!video_weblayer_); | |
| 982 | |
| 983 if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 || | 972 if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 || |
| 984 pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) { | 973 pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) { |
| 985 gfx::Size size = pipeline_metadata_.natural_size; | 974 gfx::Size size = pipeline_metadata_.natural_size; |
| 986 pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width()); | 975 pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width()); |
| 987 } | 976 } |
| 988 | 977 |
| 978 if (fullscreen_ && surface_manager_) | |
| 979 surface_manager_->NaturalSizeChanged(pipeline_metadata_.natural_size); | |
| 980 | |
| 981 DCHECK(!video_weblayer_); | |
| 989 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( | 982 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( |
| 990 compositor_, pipeline_metadata_.video_rotation))); | 983 compositor_, pipeline_metadata_.video_rotation))); |
| 991 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 984 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
| 992 video_weblayer_->SetContentsOpaqueIsFixed(true); | 985 video_weblayer_->SetContentsOpaqueIsFixed(true); |
| 993 client_->setWebLayer(video_weblayer_.get()); | 986 client_->setWebLayer(video_weblayer_.get()); |
| 994 } | 987 } |
| 995 | 988 |
| 996 UpdatePlayState(); | 989 UpdatePlayState(); |
| 997 } | 990 } |
| 998 | 991 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1236 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) | 1229 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) |
| 1237 SetNetworkState(WebMediaPlayer::NetworkStateIdle); | 1230 SetNetworkState(WebMediaPlayer::NetworkStateIdle); |
| 1238 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) | 1231 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) |
| 1239 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 1232 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 1240 media_log_->AddEvent( | 1233 media_log_->AddEvent( |
| 1241 media_log_->CreateBooleanEvent( | 1234 media_log_->CreateBooleanEvent( |
| 1242 MediaLogEvent::NETWORK_ACTIVITY_SET, | 1235 MediaLogEvent::NETWORK_ACTIVITY_SET, |
| 1243 "is_downloading_data", is_downloading)); | 1236 "is_downloading_data", is_downloading)); |
| 1244 } | 1237 } |
| 1245 | 1238 |
| 1239 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) { | |
| 1240 fullscreen_surface_id_ = surface_id; | |
| 1241 if (!pending_surface_request_cb_.is_null()) | |
| 1242 base::ResetAndReturn(&pending_surface_request_cb_).Run(surface_id); | |
| 1243 } | |
| 1244 | |
| 1246 // TODO(watk): Move this state management out of WMPI. | 1245 // TODO(watk): Move this state management out of WMPI. |
| 1247 void WebMediaPlayerImpl::OnSurfaceRequested( | 1246 void WebMediaPlayerImpl::OnSurfaceRequested( |
| 1248 const SurfaceCreatedCB& surface_created_cb) { | 1247 const SurfaceCreatedCB& surface_created_cb) { |
| 1249 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1248 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1250 DCHECK(surface_manager_); | 1249 DCHECK(surface_manager_); |
| 1251 | 1250 |
| 1252 // A null callback indicates that the decoder is going away. | 1251 // A null callback indicates that the decoder is going away. |
| 1253 if (surface_created_cb.is_null()) { | 1252 if (surface_created_cb.is_null()) { |
| 1254 decoder_requires_restart_for_fullscreen_ = false; | 1253 decoder_requires_restart_for_fullscreen_ = false; |
| 1254 pending_surface_request_cb_.Reset(); | |
| 1255 return; | 1255 return; |
| 1256 } | 1256 } |
| 1257 | 1257 |
| 1258 // If we're getting a surface request it means GVD is initializing, so until | 1258 // If we're getting a surface request it means GVD is initializing, so until |
| 1259 // we get a null surface request, GVD is the active decoder. While that's the | 1259 // we get a null surface request, GVD is the active decoder. While that's the |
| 1260 // case we should restart the pipeline on fullscreen transitions so that when | 1260 // case we should restart the pipeline on fullscreen transitions so that when |
| 1261 // we create a new GVD it will request a surface again and get the right kind | 1261 // we create a new GVD it will request a surface again and get the right kind |
| 1262 // of surface for the fullscreen state. | 1262 // of surface for the fullscreen state. |
| 1263 // TODO(watk): Don't require a pipeline restart to switch surfaces for | 1263 // TODO(watk): Don't require a pipeline restart to switch surfaces for |
| 1264 // cases where it isn't necessary. | 1264 // cases where it isn't necessary. |
| 1265 decoder_requires_restart_for_fullscreen_ = true; | 1265 decoder_requires_restart_for_fullscreen_ = true; |
| 1266 if (fullscreen_) { | 1266 if (fullscreen_) { |
| 1267 surface_manager_->CreateFullscreenSurface(pipeline_metadata_.natural_size, | 1267 if (fullscreen_surface_id_ != SurfaceManager::kNoSurfaceID) |
| 1268 surface_created_cb); | 1268 surface_created_cb.Run(fullscreen_surface_id_); |
| 1269 else | |
| 1270 pending_surface_request_cb_ = surface_created_cb; | |
| 1269 } else { | 1271 } else { |
| 1270 // Tell the decoder to create its own surface. | 1272 // Tell the decoder to create its own surface. |
| 1271 surface_created_cb.Run(SurfaceManager::kNoSurfaceID); | 1273 surface_created_cb.Run(SurfaceManager::kNoSurfaceID); |
| 1272 } | 1274 } |
| 1273 } | 1275 } |
| 1274 | 1276 |
| 1275 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { | 1277 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { |
| 1276 RequestSurfaceCB request_surface_cb; | 1278 RequestSurfaceCB request_surface_cb; |
| 1277 #if defined(OS_ANDROID) | 1279 #if defined(OS_ANDROID) |
| 1278 request_surface_cb = | 1280 request_surface_cb = |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1634 if (isRemote()) | 1636 if (isRemote()) |
| 1635 return; | 1637 return; |
| 1636 #endif | 1638 #endif |
| 1637 | 1639 |
| 1638 // Idle timeout chosen arbitrarily. | 1640 // Idle timeout chosen arbitrarily. |
| 1639 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), | 1641 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), |
| 1640 this, &WebMediaPlayerImpl::OnPause); | 1642 this, &WebMediaPlayerImpl::OnPause); |
| 1641 } | 1643 } |
| 1642 | 1644 |
| 1643 } // namespace media | 1645 } // namespace media |
| OLD | NEW |