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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), | 185 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
186 last_reported_memory_usage_(0), | 186 last_reported_memory_usage_(0), |
187 supports_save_(true), | 187 supports_save_(true), |
188 chunk_demuxer_(NULL), | 188 chunk_demuxer_(NULL), |
189 url_index_(url_index), | 189 url_index_(url_index), |
190 // Threaded compositing isn't enabled universally yet. | 190 // Threaded compositing isn't enabled universally yet. |
191 compositor_task_runner_( | 191 compositor_task_runner_( |
192 params.compositor_task_runner() | 192 params.compositor_task_runner() |
193 ? params.compositor_task_runner() | 193 ? params.compositor_task_runner() |
194 : base::MessageLoop::current()->task_runner()), | 194 : base::MessageLoop::current()->task_runner()), |
195 compositor_(new VideoFrameCompositor( | 195 compositor_(new VideoFrameCompositor(compositor_task_runner_)), |
196 compositor_task_runner_, | |
197 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | |
198 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | |
199 is_cdm_attached_(false), | 196 is_cdm_attached_(false), |
200 #if defined(OS_ANDROID) // WMPI_CAST | 197 #if defined(OS_ANDROID) // WMPI_CAST |
201 cast_impl_(this, client_, params.context_3d_cb()), | 198 cast_impl_(this, client_, params.context_3d_cb()), |
202 #endif | 199 #endif |
203 volume_(1.0), | 200 volume_(1.0), |
204 volume_multiplier_(1.0), | 201 volume_multiplier_(1.0), |
205 renderer_factory_(std::move(renderer_factory)), | 202 renderer_factory_(std::move(renderer_factory)), |
206 surface_manager_(params.surface_manager()), | 203 surface_manager_(params.surface_manager()), |
207 suppress_destruction_errors_(false), | 204 suppress_destruction_errors_(false), |
208 can_suspend_state_(CanSuspendState::UNKNOWN) { | 205 can_suspend_state_(CanSuspendState::UNKNOWN) { |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { | 1073 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { |
1077 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1074 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1078 | 1075 |
1079 encrypted_client_->didBlockPlaybackWaitingForKey(); | 1076 encrypted_client_->didBlockPlaybackWaitingForKey(); |
1080 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 1077 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
1081 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 1078 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
1082 // |has_additional_usable_key| = true). http://crbug.com/461903 | 1079 // |has_additional_usable_key| = true). http://crbug.com/461903 |
1083 encrypted_client_->didResumePlaybackBlockedForKey(); | 1080 encrypted_client_->didResumePlaybackBlockedForKey(); |
1084 } | 1081 } |
1085 | 1082 |
| 1083 void WebMediaPlayerImpl::OnVideoNaturalSizeChange(const gfx::Size& size) { |
| 1084 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1085 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 1086 |
| 1087 if (size == pipeline_metadata_.natural_size) |
| 1088 return; |
| 1089 |
| 1090 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); |
| 1091 media_log_->AddEvent( |
| 1092 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); |
| 1093 |
| 1094 if (fullscreen_ && surface_manager_) |
| 1095 surface_manager_->NaturalSizeChanged(size); |
| 1096 |
| 1097 pipeline_metadata_.natural_size = size; |
| 1098 client_->sizeChanged(); |
| 1099 } |
| 1100 |
| 1101 void WebMediaPlayerImpl::OnVideoOpacityChange(bool opaque) { |
| 1102 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1103 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 1104 |
| 1105 opaque_ = opaque; |
| 1106 // Modify content opaqueness of cc::Layer directly so that |
| 1107 // SetContentsOpaqueIsFixed is ignored. |
| 1108 if (video_weblayer_) |
| 1109 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
| 1110 } |
| 1111 |
1086 void WebMediaPlayerImpl::OnHidden() { | 1112 void WebMediaPlayerImpl::OnHidden() { |
1087 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1113 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1088 UpdatePlayState(); | 1114 UpdatePlayState(); |
1089 } | 1115 } |
1090 | 1116 |
1091 void WebMediaPlayerImpl::OnShown() { | 1117 void WebMediaPlayerImpl::OnShown() { |
1092 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1118 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1093 must_suspend_ = false; | 1119 must_suspend_ = false; |
1094 UpdatePlayState(); | 1120 UpdatePlayState(); |
1095 } | 1121 } |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 base::TimeDelta duration = pipeline_.GetMediaDuration(); | 1361 base::TimeDelta duration = pipeline_.GetMediaDuration(); |
1336 | 1362 |
1337 // Return positive infinity if the resource is unbounded. | 1363 // Return positive infinity if the resource is unbounded. |
1338 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-
media-duration | 1364 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-
media-duration |
1339 if (duration == kInfiniteDuration()) | 1365 if (duration == kInfiniteDuration()) |
1340 return std::numeric_limits<double>::infinity(); | 1366 return std::numeric_limits<double>::infinity(); |
1341 | 1367 |
1342 return duration.InSecondsF(); | 1368 return duration.InSecondsF(); |
1343 } | 1369 } |
1344 | 1370 |
1345 void WebMediaPlayerImpl::OnNaturalSizeChanged(gfx::Size size) { | |
1346 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
1347 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); | |
1348 | |
1349 if (size == pipeline_metadata_.natural_size) | |
1350 return; | |
1351 | |
1352 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); | |
1353 media_log_->AddEvent( | |
1354 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); | |
1355 | |
1356 if (fullscreen_ && surface_manager_) | |
1357 surface_manager_->NaturalSizeChanged(size); | |
1358 | |
1359 pipeline_metadata_.natural_size = size; | |
1360 client_->sizeChanged(); | |
1361 } | |
1362 | |
1363 void WebMediaPlayerImpl::OnOpacityChanged(bool opaque) { | |
1364 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
1365 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); | |
1366 | |
1367 opaque_ = opaque; | |
1368 // Modify content opaqueness of cc::Layer directly so that | |
1369 // SetContentsOpaqueIsFixed is ignored. | |
1370 if (video_weblayer_) | |
1371 video_weblayer_->layer()->SetContentsOpaque(opaque_); | |
1372 } | |
1373 | |
1374 static void GetCurrentFrameAndSignal( | 1371 static void GetCurrentFrameAndSignal( |
1375 VideoFrameCompositor* compositor, | 1372 VideoFrameCompositor* compositor, |
1376 scoped_refptr<VideoFrame>* video_frame_out, | 1373 scoped_refptr<VideoFrame>* video_frame_out, |
1377 base::WaitableEvent* event) { | 1374 base::WaitableEvent* event) { |
1378 TRACE_EVENT0("media", "GetCurrentFrameAndSignal"); | 1375 TRACE_EVENT0("media", "GetCurrentFrameAndSignal"); |
1379 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); | 1376 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); |
1380 event->Signal(); | 1377 event->Signal(); |
1381 } | 1378 } |
1382 | 1379 |
1383 scoped_refptr<VideoFrame> | 1380 scoped_refptr<VideoFrame> |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 << ", Video: " << stats.video_memory_usage << ", DataSource: " | 1605 << ", Video: " << stats.video_memory_usage << ", DataSource: " |
1609 << (data_source_ ? data_source_->GetMemoryUsage() : 0) | 1606 << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
1610 << ", Demuxer: " << demuxer_memory_usage; | 1607 << ", Demuxer: " << demuxer_memory_usage; |
1611 | 1608 |
1612 const int64_t delta = current_memory_usage - last_reported_memory_usage_; | 1609 const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
1613 last_reported_memory_usage_ = current_memory_usage; | 1610 last_reported_memory_usage_ = current_memory_usage; |
1614 adjust_allocated_memory_cb_.Run(delta); | 1611 adjust_allocated_memory_cb_.Run(delta); |
1615 } | 1612 } |
1616 | 1613 |
1617 } // namespace media | 1614 } // namespace media |
OLD | NEW |