| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 opaque_(false), | 147 opaque_(false), |
| 148 playback_rate_(0.0), | 148 playback_rate_(0.0), |
| 149 paused_(true), | 149 paused_(true), |
| 150 seeking_(false), | 150 seeking_(false), |
| 151 pending_suspend_(false), | 151 pending_suspend_(false), |
| 152 pending_time_change_(false), | 152 pending_time_change_(false), |
| 153 pending_resume_(false), | 153 pending_resume_(false), |
| 154 suspending_(false), | 154 suspending_(false), |
| 155 suspended_(false), | 155 suspended_(false), |
| 156 resuming_(false), | 156 resuming_(false), |
| 157 pending_suspend_resume_cycle_(false), |
| 157 ended_(false), | 158 ended_(false), |
| 158 pending_seek_(false), | 159 pending_seek_(false), |
| 159 should_notify_time_changed_(false), | 160 should_notify_time_changed_(false), |
| 161 fullscreen_(false), |
| 162 decoder_requires_restart_for_fullscreen_(false), |
| 160 client_(client), | 163 client_(client), |
| 161 encrypted_client_(encrypted_client), | 164 encrypted_client_(encrypted_client), |
| 162 delegate_(delegate), | 165 delegate_(delegate), |
| 163 delegate_id_(0), | 166 delegate_id_(0), |
| 164 defer_load_cb_(params.defer_load_cb()), | 167 defer_load_cb_(params.defer_load_cb()), |
| 165 context_3d_cb_(params.context_3d_cb()), | 168 context_3d_cb_(params.context_3d_cb()), |
| 166 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), | 169 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
| 167 last_reported_memory_usage_(0), | 170 last_reported_memory_usage_(0), |
| 168 supports_save_(true), | 171 supports_save_(true), |
| 169 chunk_demuxer_(NULL), | 172 chunk_demuxer_(NULL), |
| 170 url_index_(url_index), | 173 url_index_(url_index), |
| 171 // Threaded compositing isn't enabled universally yet. | 174 // Threaded compositing isn't enabled universally yet. |
| 172 compositor_task_runner_( | 175 compositor_task_runner_( |
| 173 params.compositor_task_runner() | 176 params.compositor_task_runner() |
| 174 ? params.compositor_task_runner() | 177 ? params.compositor_task_runner() |
| 175 : base::MessageLoop::current()->task_runner()), | 178 : base::MessageLoop::current()->task_runner()), |
| 176 compositor_(new VideoFrameCompositor( | 179 compositor_(new VideoFrameCompositor( |
| 177 compositor_task_runner_, | 180 compositor_task_runner_, |
| 178 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 181 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
| 179 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 182 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
| 180 encrypted_media_support_(cdm_factory, | 183 encrypted_media_support_(cdm_factory, |
| 181 encrypted_client, | 184 encrypted_client, |
| 182 params.media_permission(), | 185 params.media_permission(), |
| 183 base::Bind(&WebMediaPlayerImpl::SetCdm, | 186 base::Bind(&WebMediaPlayerImpl::SetCdm, |
| 184 AsWeakPtr(), | 187 AsWeakPtr(), |
| 185 base::Bind(&IgnoreCdmAttached))), | 188 base::Bind(&IgnoreCdmAttached))), |
| 186 is_cdm_attached_(false), | 189 is_cdm_attached_(false), |
| 187 #if defined(OS_ANDROID) // WMPI_CAST | 190 #if defined(OS_ANDROID) |
| 191 surface_manager_(nullptr), |
| 192 // WMPI_CAST |
| 188 cast_impl_(this, client_, params.context_3d_cb()), | 193 cast_impl_(this, client_, params.context_3d_cb()), |
| 189 #endif | 194 #endif |
| 190 volume_(1.0), | 195 volume_(1.0), |
| 191 volume_multiplier_(1.0), | 196 volume_multiplier_(1.0), |
| 192 renderer_factory_(std::move(renderer_factory)) { | 197 renderer_factory_(std::move(renderer_factory)) { |
| 193 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 198 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 194 DCHECK(renderer_factory_); | 199 DCHECK(renderer_factory_); |
| 195 | 200 |
| 196 if (delegate_) | 201 if (delegate_) |
| 197 delegate_id_ = delegate_->AddObserver(this); | 202 delegate_id_ = delegate_->AddObserver(this); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", " | 261 DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", " |
| 257 << cors_mode << ")"; | 262 << cors_mode << ")"; |
| 258 if (!defer_load_cb_.is_null()) { | 263 if (!defer_load_cb_.is_null()) { |
| 259 defer_load_cb_.Run(base::Bind( | 264 defer_load_cb_.Run(base::Bind( |
| 260 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); | 265 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); |
| 261 return; | 266 return; |
| 262 } | 267 } |
| 263 DoLoad(load_type, url, cors_mode); | 268 DoLoad(load_type, url, cors_mode); |
| 264 } | 269 } |
| 265 | 270 |
| 271 void WebMediaPlayerImpl::enterFullscreen() { |
| 272 fullscreen_ = true; |
| 273 if (decoder_requires_restart_for_fullscreen_) |
| 274 ScheduleRestart(); |
| 275 } |
| 276 |
| 277 void WebMediaPlayerImpl::exitedFullscreen() { |
| 278 fullscreen_ = false; |
| 279 if (decoder_requires_restart_for_fullscreen_) |
| 280 ScheduleRestart(); |
| 281 } |
| 282 |
| 266 void WebMediaPlayerImpl::DoLoad(LoadType load_type, | 283 void WebMediaPlayerImpl::DoLoad(LoadType load_type, |
| 267 const blink::WebURL& url, | 284 const blink::WebURL& url, |
| 268 CORSMode cors_mode) { | 285 CORSMode cors_mode) { |
| 269 DVLOG(1) << __FUNCTION__; | 286 DVLOG(1) << __FUNCTION__; |
| 270 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 287 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 271 | 288 |
| 272 GURL gurl(url); | 289 GURL gurl(url); |
| 273 ReportMetrics( | 290 ReportMetrics( |
| 274 load_type, gurl, | 291 load_type, gurl, |
| 275 blink::WebStringToGURL(frame_->document().securityOrigin().toString())); | 292 blink::WebStringToGURL(frame_->document().securityOrigin().toString())); |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 | 988 |
| 972 #if defined(OS_ANDROID) | 989 #if defined(OS_ANDROID) |
| 973 if (isRemote()) { | 990 if (isRemote()) { |
| 974 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | 991 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
| 975 if (frame) { | 992 if (frame) { |
| 976 compositor_->PaintFrameUsingOldRenderingPath(frame); | 993 compositor_->PaintFrameUsingOldRenderingPath(frame); |
| 977 } | 994 } |
| 978 } | 995 } |
| 979 #endif | 996 #endif |
| 980 | 997 |
| 981 if (pending_resume_) { | 998 if (pending_resume_ || pending_suspend_resume_cycle_) { |
| 982 pending_resume_ = false; | 999 pending_resume_ = false; |
| 1000 pending_suspend_resume_cycle_ = false; |
| 983 Resume(); | 1001 Resume(); |
| 984 return; | 1002 return; |
| 985 } | 1003 } |
| 986 } | 1004 } |
| 987 | 1005 |
| 988 void WebMediaPlayerImpl::OnPipelineEnded() { | 1006 void WebMediaPlayerImpl::OnPipelineEnded() { |
| 989 DVLOG(1) << __FUNCTION__; | 1007 DVLOG(1) << __FUNCTION__; |
| 990 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1008 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 991 | 1009 |
| 992 // Ignore state changes until we've completed all outstanding seeks. | 1010 // Ignore state changes until we've completed all outstanding seeks. |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 | 1256 |
| 1239 if (chunk_demuxer_) | 1257 if (chunk_demuxer_) |
| 1240 chunk_demuxer_->StartWaitingForSeek(seek_time_); | 1258 chunk_demuxer_->StartWaitingForSeek(seek_time_); |
| 1241 | 1259 |
| 1242 resuming_ = true; | 1260 resuming_ = true; |
| 1243 pipeline_.Resume(CreateRenderer(), seek_time_, | 1261 pipeline_.Resume(CreateRenderer(), seek_time_, |
| 1244 BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, | 1262 BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, |
| 1245 time_changed)); | 1263 time_changed)); |
| 1246 } | 1264 } |
| 1247 | 1265 |
| 1248 #if defined(OS_ANDROID) // WMPI_CAST | 1266 void WebMediaPlayerImpl::ScheduleRestart() { |
| 1267 if (!suspended_ || resuming_) { |
| 1268 pending_suspend_resume_cycle_ = true; |
| 1269 ScheduleSuspend(); |
| 1270 } |
| 1271 } |
| 1249 | 1272 |
| 1273 #if defined(OS_ANDROID) |
| 1274 // TODO(watk): Move the SurfaceManager and associated state out of WMPI. |
| 1275 void WebMediaPlayerImpl::SetSurfaceManager(SurfaceManager* surface_manager) { |
| 1276 surface_manager_ = surface_manager; |
| 1277 } |
| 1278 |
| 1279 void WebMediaPlayerImpl::OnSurfaceRequested( |
| 1280 const SurfaceCreatedCB& surface_created_cb) { |
| 1281 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1282 DCHECK(surface_manager_); |
| 1283 |
| 1284 // A null callback indicates that the decoder is going away. |
| 1285 if (surface_created_cb.is_null()) { |
| 1286 decoder_requires_restart_for_fullscreen_ = false; |
| 1287 return; |
| 1288 } |
| 1289 |
| 1290 // If we're getting a surface request it means GVD is initializing, so until |
| 1291 // we get a null surface request, GVD is the active decoder. While that's the |
| 1292 // case we should restart the pipeline on fullscreen transitions so that when |
| 1293 // we create a new GVD it will request a surface again and use the right kind |
| 1294 // of surface for the new fullscreen state. |
| 1295 // TODO(watk): Don't require a pipeline restart to switch surfaces for |
| 1296 // cases where it isn't necessary. |
| 1297 decoder_requires_restart_for_fullscreen_ = true; |
| 1298 if (fullscreen_) { |
| 1299 surface_manager_->CreateFullscreenSurface(pipeline_metadata_.natural_size, |
| 1300 surface_created_cb); |
| 1301 } else { |
| 1302 // Tell the decoder to create its own surface. |
| 1303 surface_created_cb.Run(SurfaceManager::kNoSurfaceID); |
| 1304 } |
| 1305 } |
| 1306 |
| 1307 // WMPI_CAST |
| 1250 bool WebMediaPlayerImpl::isRemote() const { | 1308 bool WebMediaPlayerImpl::isRemote() const { |
| 1251 return cast_impl_.isRemote(); | 1309 return cast_impl_.isRemote(); |
| 1252 } | 1310 } |
| 1253 | 1311 |
| 1254 void WebMediaPlayerImpl::SetMediaPlayerManager( | 1312 void WebMediaPlayerImpl::SetMediaPlayerManager( |
| 1255 RendererMediaPlayerManagerInterface* media_player_manager) { | 1313 RendererMediaPlayerManagerInterface* media_player_manager) { |
| 1256 cast_impl_.SetMediaPlayerManager(media_player_manager); | 1314 cast_impl_.SetMediaPlayerManager(media_player_manager); |
| 1257 } | 1315 } |
| 1258 | 1316 |
| 1259 void WebMediaPlayerImpl::requestRemotePlayback() { | 1317 void WebMediaPlayerImpl::requestRemotePlayback() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 gfx::Size WebMediaPlayerImpl::GetCanvasSize() const { | 1358 gfx::Size WebMediaPlayerImpl::GetCanvasSize() const { |
| 1301 if (!video_weblayer_) | 1359 if (!video_weblayer_) |
| 1302 return pipeline_metadata_.natural_size; | 1360 return pipeline_metadata_.natural_size; |
| 1303 | 1361 |
| 1304 return video_weblayer_->bounds(); | 1362 return video_weblayer_->bounds(); |
| 1305 } | 1363 } |
| 1306 | 1364 |
| 1307 void WebMediaPlayerImpl::SetDeviceScaleFactor(float scale_factor) { | 1365 void WebMediaPlayerImpl::SetDeviceScaleFactor(float scale_factor) { |
| 1308 cast_impl_.SetDeviceScaleFactor(scale_factor); | 1366 cast_impl_.SetDeviceScaleFactor(scale_factor); |
| 1309 } | 1367 } |
| 1310 #endif // defined(OS_ANDROID) // WMPI_CAST | 1368 #endif // defined(OS_ANDROID) |
| 1311 | 1369 |
| 1312 void WebMediaPlayerImpl::DataSourceInitialized(bool success) { | 1370 void WebMediaPlayerImpl::DataSourceInitialized(bool success) { |
| 1313 DVLOG(1) << __FUNCTION__; | 1371 DVLOG(1) << __FUNCTION__; |
| 1314 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1372 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1315 | 1373 |
| 1316 if (!success) { | 1374 if (!success) { |
| 1317 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); | 1375 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); |
| 1318 return; | 1376 return; |
| 1319 } | 1377 } |
| 1320 | 1378 |
| 1321 StartPipeline(); | 1379 StartPipeline(); |
| 1322 } | 1380 } |
| 1323 | 1381 |
| 1324 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { | 1382 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { |
| 1325 DVLOG(1) << __FUNCTION__; | 1383 DVLOG(1) << __FUNCTION__; |
| 1326 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) | 1384 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) |
| 1327 SetNetworkState(WebMediaPlayer::NetworkStateIdle); | 1385 SetNetworkState(WebMediaPlayer::NetworkStateIdle); |
| 1328 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) | 1386 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) |
| 1329 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 1387 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 1330 media_log_->AddEvent( | 1388 media_log_->AddEvent( |
| 1331 media_log_->CreateBooleanEvent( | 1389 media_log_->CreateBooleanEvent( |
| 1332 MediaLogEvent::NETWORK_ACTIVITY_SET, | 1390 MediaLogEvent::NETWORK_ACTIVITY_SET, |
| 1333 "is_downloading_data", is_downloading)); | 1391 "is_downloading_data", is_downloading)); |
| 1334 } | 1392 } |
| 1335 | 1393 |
| 1336 scoped_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { | 1394 scoped_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { |
| 1395 RequestSurfaceCB request_surface_cb; |
| 1396 #if defined(OS_ANDROID) |
| 1397 request_surface_cb = |
| 1398 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnSurfaceRequested); |
| 1399 #endif |
| 1337 return renderer_factory_->CreateRenderer( | 1400 return renderer_factory_->CreateRenderer( |
| 1338 media_task_runner_, worker_task_runner_, audio_source_provider_.get(), | 1401 media_task_runner_, worker_task_runner_, audio_source_provider_.get(), |
| 1339 compositor_); | 1402 compositor_, request_surface_cb); |
| 1340 } | 1403 } |
| 1341 | 1404 |
| 1342 void WebMediaPlayerImpl::StartPipeline() { | 1405 void WebMediaPlayerImpl::StartPipeline() { |
| 1343 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1406 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1344 | 1407 |
| 1345 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = | 1408 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = |
| 1346 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnEncryptedMediaInitData); | 1409 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnEncryptedMediaInitData); |
| 1347 | 1410 |
| 1348 // Figure out which demuxer to use. | 1411 // Figure out which demuxer to use. |
| 1349 if (load_type_ != LoadTypeMediaSource) { | 1412 if (load_type_ != LoadTypeMediaSource) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 client_->durationChanged(); | 1490 client_->durationChanged(); |
| 1428 } | 1491 } |
| 1429 | 1492 |
| 1430 void WebMediaPlayerImpl::OnNaturalSizeChanged(gfx::Size size) { | 1493 void WebMediaPlayerImpl::OnNaturalSizeChanged(gfx::Size size) { |
| 1431 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1494 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1432 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); | 1495 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 1433 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); | 1496 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); |
| 1434 | 1497 |
| 1435 media_log_->AddEvent( | 1498 media_log_->AddEvent( |
| 1436 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); | 1499 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); |
| 1500 |
| 1501 #if defined(OS_ANDROID) |
| 1502 if (fullscreen_ && surface_manager_ && |
| 1503 pipeline_metadata_.natural_size != size) { |
| 1504 surface_manager_->FullscreenVideoSizeChanged(size); |
| 1505 } |
| 1506 #endif |
| 1507 |
| 1437 pipeline_metadata_.natural_size = size; | 1508 pipeline_metadata_.natural_size = size; |
| 1438 | |
| 1439 client_->sizeChanged(); | 1509 client_->sizeChanged(); |
| 1440 } | 1510 } |
| 1441 | 1511 |
| 1442 void WebMediaPlayerImpl::OnOpacityChanged(bool opaque) { | 1512 void WebMediaPlayerImpl::OnOpacityChanged(bool opaque) { |
| 1443 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1513 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1444 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); | 1514 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 1445 | 1515 |
| 1446 opaque_ = opaque; | 1516 opaque_ = opaque; |
| 1447 // Modify content opaqueness of cc::Layer directly so that | 1517 // Modify content opaqueness of cc::Layer directly so that |
| 1448 // SetContentsOpaqueIsFixed is ignored. | 1518 // SetContentsOpaqueIsFixed is ignored. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 << ", Video: " << stats.video_memory_usage << ", DataSource: " | 1619 << ", Video: " << stats.video_memory_usage << ", DataSource: " |
| 1550 << (data_source_ ? data_source_->GetMemoryUsage() : 0) | 1620 << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
| 1551 << ", Demuxer: " << demuxer_memory_usage; | 1621 << ", Demuxer: " << demuxer_memory_usage; |
| 1552 | 1622 |
| 1553 const int64_t delta = current_memory_usage - last_reported_memory_usage_; | 1623 const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
| 1554 last_reported_memory_usage_ = current_memory_usage; | 1624 last_reported_memory_usage_ = current_memory_usage; |
| 1555 adjust_allocated_memory_cb_.Run(delta); | 1625 adjust_allocated_memory_cb_.Run(delta); |
| 1556 } | 1626 } |
| 1557 | 1627 |
| 1558 } // namespace media | 1628 } // namespace media |
| OLD | NEW |