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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 opaque_(false), | 148 opaque_(false), |
149 playback_rate_(0.0), | 149 playback_rate_(0.0), |
150 paused_(true), | 150 paused_(true), |
151 seeking_(false), | 151 seeking_(false), |
152 pending_suspend_(false), | 152 pending_suspend_(false), |
153 pending_time_change_(false), | 153 pending_time_change_(false), |
154 pending_resume_(false), | 154 pending_resume_(false), |
155 suspending_(false), | 155 suspending_(false), |
156 suspended_(false), | 156 suspended_(false), |
157 resuming_(false), | 157 resuming_(false), |
| 158 pending_suspend_resume_cycle_(false), |
158 ended_(false), | 159 ended_(false), |
159 pending_seek_(false), | 160 pending_seek_(false), |
160 should_notify_time_changed_(false), | 161 should_notify_time_changed_(false), |
| 162 fullscreen_(false), |
| 163 decoder_requires_restart_for_fullscreen_(false), |
161 client_(client), | 164 client_(client), |
162 encrypted_client_(encrypted_client), | 165 encrypted_client_(encrypted_client), |
163 delegate_(delegate), | 166 delegate_(delegate), |
164 delegate_id_(0), | 167 delegate_id_(0), |
165 defer_load_cb_(params.defer_load_cb()), | 168 defer_load_cb_(params.defer_load_cb()), |
166 context_3d_cb_(params.context_3d_cb()), | 169 context_3d_cb_(params.context_3d_cb()), |
167 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), | 170 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
168 last_reported_memory_usage_(0), | 171 last_reported_memory_usage_(0), |
169 supports_save_(true), | 172 supports_save_(true), |
170 chunk_demuxer_(NULL), | 173 chunk_demuxer_(NULL), |
(...skipping 12 matching lines...) Expand all Loading... |
183 params.media_permission(), | 186 params.media_permission(), |
184 base::Bind(&WebMediaPlayerImpl::SetCdm, | 187 base::Bind(&WebMediaPlayerImpl::SetCdm, |
185 AsWeakPtr(), | 188 AsWeakPtr(), |
186 base::Bind(&IgnoreCdmAttached))), | 189 base::Bind(&IgnoreCdmAttached))), |
187 is_cdm_attached_(false), | 190 is_cdm_attached_(false), |
188 #if defined(OS_ANDROID) // WMPI_CAST | 191 #if defined(OS_ANDROID) // WMPI_CAST |
189 cast_impl_(this, client_, params.context_3d_cb()), | 192 cast_impl_(this, client_, params.context_3d_cb()), |
190 #endif | 193 #endif |
191 volume_(1.0), | 194 volume_(1.0), |
192 volume_multiplier_(1.0), | 195 volume_multiplier_(1.0), |
193 renderer_factory_(std::move(renderer_factory)) { | 196 renderer_factory_(std::move(renderer_factory)), |
| 197 surface_manager_(params.surface_manager()) { |
194 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 198 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
195 DCHECK(renderer_factory_); | 199 DCHECK(renderer_factory_); |
196 | 200 |
197 if (delegate_) | 201 if (delegate_) |
198 delegate_id_ = delegate_->AddObserver(this); | 202 delegate_id_ = delegate_->AddObserver(this); |
199 | 203 |
200 media_log_->AddEvent( | 204 media_log_->AddEvent( |
201 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 205 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
202 | 206 |
203 if (params.initial_cdm()) { | 207 if (params.initial_cdm()) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", " | 261 DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", " |
258 << cors_mode << ")"; | 262 << cors_mode << ")"; |
259 if (!defer_load_cb_.is_null()) { | 263 if (!defer_load_cb_.is_null()) { |
260 defer_load_cb_.Run(base::Bind( | 264 defer_load_cb_.Run(base::Bind( |
261 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); | 265 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); |
262 return; | 266 return; |
263 } | 267 } |
264 DoLoad(load_type, url, cors_mode); | 268 DoLoad(load_type, url, cors_mode); |
265 } | 269 } |
266 | 270 |
| 271 void WebMediaPlayerImpl::enteredFullscreen() { |
| 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 |
267 void WebMediaPlayerImpl::DoLoad(LoadType load_type, | 283 void WebMediaPlayerImpl::DoLoad(LoadType load_type, |
268 const blink::WebURL& url, | 284 const blink::WebURL& url, |
269 CORSMode cors_mode) { | 285 CORSMode cors_mode) { |
270 DVLOG(1) << __FUNCTION__; | 286 DVLOG(1) << __FUNCTION__; |
271 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 287 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
272 | 288 |
273 GURL gurl(url); | 289 GURL gurl(url); |
274 ReportMetrics( | 290 ReportMetrics( |
275 load_type, gurl, | 291 load_type, gurl, |
276 blink::WebStringToGURL(frame_->document().securityOrigin().toString())); | 292 blink::WebStringToGURL(frame_->document().securityOrigin().toString())); |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 | 981 |
966 #if defined(OS_ANDROID) | 982 #if defined(OS_ANDROID) |
967 if (isRemote()) { | 983 if (isRemote()) { |
968 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | 984 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
969 if (frame) { | 985 if (frame) { |
970 compositor_->PaintFrameUsingOldRenderingPath(frame); | 986 compositor_->PaintFrameUsingOldRenderingPath(frame); |
971 } | 987 } |
972 } | 988 } |
973 #endif | 989 #endif |
974 | 990 |
975 if (pending_resume_) { | 991 if (pending_resume_ || pending_suspend_resume_cycle_) { |
976 pending_resume_ = false; | 992 pending_resume_ = false; |
| 993 pending_suspend_resume_cycle_ = false; |
977 Resume(); | 994 Resume(); |
978 return; | 995 return; |
979 } | 996 } |
980 } | 997 } |
981 | 998 |
982 void WebMediaPlayerImpl::OnPipelineEnded() { | 999 void WebMediaPlayerImpl::OnPipelineEnded() { |
983 DVLOG(1) << __FUNCTION__; | 1000 DVLOG(1) << __FUNCTION__; |
984 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1001 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
985 | 1002 |
986 // Ignore state changes until we've completed all outstanding seeks. | 1003 // Ignore state changes until we've completed all outstanding seeks. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 | 1249 |
1233 if (chunk_demuxer_) | 1250 if (chunk_demuxer_) |
1234 chunk_demuxer_->StartWaitingForSeek(seek_time_); | 1251 chunk_demuxer_->StartWaitingForSeek(seek_time_); |
1235 | 1252 |
1236 resuming_ = true; | 1253 resuming_ = true; |
1237 pipeline_.Resume(CreateRenderer(), seek_time_, | 1254 pipeline_.Resume(CreateRenderer(), seek_time_, |
1238 BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, | 1255 BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, |
1239 time_changed)); | 1256 time_changed)); |
1240 } | 1257 } |
1241 | 1258 |
| 1259 void WebMediaPlayerImpl::ScheduleRestart() { |
| 1260 // If we're suspended but not resuming there is no need to restart because |
| 1261 // there is no renderer to kill. |
| 1262 if (!suspended_ || resuming_) { |
| 1263 pending_suspend_resume_cycle_ = true; |
| 1264 ScheduleSuspend(); |
| 1265 } |
| 1266 } |
| 1267 |
1242 #if defined(OS_ANDROID) // WMPI_CAST | 1268 #if defined(OS_ANDROID) // WMPI_CAST |
1243 | 1269 |
1244 bool WebMediaPlayerImpl::isRemote() const { | 1270 bool WebMediaPlayerImpl::isRemote() const { |
1245 return cast_impl_.isRemote(); | 1271 return cast_impl_.isRemote(); |
1246 } | 1272 } |
1247 | 1273 |
1248 void WebMediaPlayerImpl::SetMediaPlayerManager( | 1274 void WebMediaPlayerImpl::SetMediaPlayerManager( |
1249 RendererMediaPlayerManagerInterface* media_player_manager) { | 1275 RendererMediaPlayerManagerInterface* media_player_manager) { |
1250 cast_impl_.SetMediaPlayerManager(media_player_manager); | 1276 cast_impl_.SetMediaPlayerManager(media_player_manager); |
1251 } | 1277 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) | 1346 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) |
1321 SetNetworkState(WebMediaPlayer::NetworkStateIdle); | 1347 SetNetworkState(WebMediaPlayer::NetworkStateIdle); |
1322 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) | 1348 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) |
1323 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 1349 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
1324 media_log_->AddEvent( | 1350 media_log_->AddEvent( |
1325 media_log_->CreateBooleanEvent( | 1351 media_log_->CreateBooleanEvent( |
1326 MediaLogEvent::NETWORK_ACTIVITY_SET, | 1352 MediaLogEvent::NETWORK_ACTIVITY_SET, |
1327 "is_downloading_data", is_downloading)); | 1353 "is_downloading_data", is_downloading)); |
1328 } | 1354 } |
1329 | 1355 |
| 1356 // TODO(watk): Move this state management out of WMPI. |
| 1357 void WebMediaPlayerImpl::OnSurfaceRequested( |
| 1358 const SurfaceCreatedCB& surface_created_cb) { |
| 1359 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1360 DCHECK(surface_manager_); |
| 1361 |
| 1362 // A null callback indicates that the decoder is going away. |
| 1363 if (surface_created_cb.is_null()) { |
| 1364 decoder_requires_restart_for_fullscreen_ = false; |
| 1365 return; |
| 1366 } |
| 1367 |
| 1368 // If we're getting a surface request it means GVD is initializing, so until |
| 1369 // we get a null surface request, GVD is the active decoder. While that's the |
| 1370 // case we should restart the pipeline on fullscreen transitions so that when |
| 1371 // we create a new GVD it will request a surface again and get the right kind |
| 1372 // of surface for the fullscreen state. |
| 1373 // TODO(watk): Don't require a pipeline restart to switch surfaces for |
| 1374 // cases where it isn't necessary. |
| 1375 decoder_requires_restart_for_fullscreen_ = true; |
| 1376 if (fullscreen_) { |
| 1377 surface_manager_->CreateFullscreenSurface(pipeline_metadata_.natural_size, |
| 1378 surface_created_cb); |
| 1379 } else { |
| 1380 // Tell the decoder to create its own surface. |
| 1381 surface_created_cb.Run(SurfaceManager::kNoSurfaceID); |
| 1382 } |
| 1383 } |
| 1384 |
1330 scoped_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { | 1385 scoped_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { |
| 1386 RequestSurfaceCB request_surface_cb; |
| 1387 #if defined(OS_ANDROID) |
| 1388 request_surface_cb = |
| 1389 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnSurfaceRequested); |
| 1390 #endif |
1331 return renderer_factory_->CreateRenderer( | 1391 return renderer_factory_->CreateRenderer( |
1332 media_task_runner_, worker_task_runner_, audio_source_provider_.get(), | 1392 media_task_runner_, worker_task_runner_, audio_source_provider_.get(), |
1333 compositor_); | 1393 compositor_, request_surface_cb); |
1334 } | 1394 } |
1335 | 1395 |
1336 void WebMediaPlayerImpl::StartPipeline() { | 1396 void WebMediaPlayerImpl::StartPipeline() { |
1337 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1397 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1338 | 1398 |
1339 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = | 1399 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = |
1340 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnEncryptedMediaInitData); | 1400 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnEncryptedMediaInitData); |
1341 | 1401 |
1342 // Figure out which demuxer to use. | 1402 // Figure out which demuxer to use. |
1343 if (load_type_ != LoadTypeMediaSource) { | 1403 if (load_type_ != LoadTypeMediaSource) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 client_->durationChanged(); | 1481 client_->durationChanged(); |
1422 } | 1482 } |
1423 | 1483 |
1424 void WebMediaPlayerImpl::OnNaturalSizeChanged(gfx::Size size) { | 1484 void WebMediaPlayerImpl::OnNaturalSizeChanged(gfx::Size size) { |
1425 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1485 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1426 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); | 1486 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
1427 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); | 1487 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); |
1428 | 1488 |
1429 media_log_->AddEvent( | 1489 media_log_->AddEvent( |
1430 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); | 1490 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); |
| 1491 |
| 1492 if (fullscreen_ && surface_manager_ && |
| 1493 pipeline_metadata_.natural_size != size) { |
| 1494 surface_manager_->NaturalSizeChanged(size); |
| 1495 } |
| 1496 |
1431 pipeline_metadata_.natural_size = size; | 1497 pipeline_metadata_.natural_size = size; |
1432 | |
1433 client_->sizeChanged(); | 1498 client_->sizeChanged(); |
1434 } | 1499 } |
1435 | 1500 |
1436 void WebMediaPlayerImpl::OnOpacityChanged(bool opaque) { | 1501 void WebMediaPlayerImpl::OnOpacityChanged(bool opaque) { |
1437 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1502 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1438 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); | 1503 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
1439 | 1504 |
1440 opaque_ = opaque; | 1505 opaque_ = opaque; |
1441 // Modify content opaqueness of cc::Layer directly so that | 1506 // Modify content opaqueness of cc::Layer directly so that |
1442 // SetContentsOpaqueIsFixed is ignored. | 1507 // SetContentsOpaqueIsFixed is ignored. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 << ", Video: " << stats.video_memory_usage << ", DataSource: " | 1608 << ", Video: " << stats.video_memory_usage << ", DataSource: " |
1544 << (data_source_ ? data_source_->GetMemoryUsage() : 0) | 1609 << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
1545 << ", Demuxer: " << demuxer_memory_usage; | 1610 << ", Demuxer: " << demuxer_memory_usage; |
1546 | 1611 |
1547 const int64_t delta = current_memory_usage - last_reported_memory_usage_; | 1612 const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
1548 last_reported_memory_usage_ = current_memory_usage; | 1613 last_reported_memory_usage_ = current_memory_usage; |
1549 adjust_allocated_memory_cb_.Run(delta); | 1614 adjust_allocated_memory_cb_.Run(delta); |
1550 } | 1615 } |
1551 | 1616 |
1552 } // namespace media | 1617 } // namespace media |
OLD | NEW |