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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 params.audio_renderer_sink().get() | 206 params.audio_renderer_sink().get() |
207 ? params.audio_renderer_sink() | 207 ? params.audio_renderer_sink() |
208 : new NullAudioSink(media_task_runner_)); | 208 : new NullAudioSink(media_task_runner_)); |
209 } | 209 } |
210 | 210 |
211 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 211 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
212 client_->setWebLayer(NULL); | 212 client_->setWebLayer(NULL); |
213 | 213 |
214 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 214 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
215 | 215 |
216 if (delegate_) { | 216 if (delegate_) |
217 delegate_->RemoveObserver(this); | |
218 delegate_->PlayerGone(this); | 217 delegate_->PlayerGone(this); |
219 } | |
220 | 218 |
221 // Abort any pending IO so stopping the pipeline doesn't get blocked. | 219 // Abort any pending IO so stopping the pipeline doesn't get blocked. |
222 if (data_source_) | 220 if (data_source_) |
223 data_source_->Abort(); | 221 data_source_->Abort(); |
224 if (chunk_demuxer_) { | 222 if (chunk_demuxer_) { |
225 chunk_demuxer_->Shutdown(); | 223 chunk_demuxer_->Shutdown(); |
226 chunk_demuxer_ = NULL; | 224 chunk_demuxer_ = NULL; |
227 } | 225 } |
228 | 226 |
229 renderer_factory_.reset(); | 227 renderer_factory_.reset(); |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 } | 1108 } |
1111 | 1109 |
1112 // We may not be suspended if we were not yet subscribed or the pipeline was | 1110 // We may not be suspended if we were not yet subscribed or the pipeline was |
1113 // not yet started when OnHidden() fired. | 1111 // not yet started when OnHidden() fired. |
1114 if (!suspended_) | 1112 if (!suspended_) |
1115 return; | 1113 return; |
1116 | 1114 |
1117 Resume(); | 1115 Resume(); |
1118 } | 1116 } |
1119 | 1117 |
| 1118 void WebMediaPlayerImpl::OnPlay() { |
| 1119 play(); |
| 1120 client_->playbackStateChanged(); |
| 1121 } |
| 1122 |
| 1123 void WebMediaPlayerImpl::OnPause() { |
| 1124 pause(); |
| 1125 client_->playbackStateChanged(); |
| 1126 } |
| 1127 |
1120 void WebMediaPlayerImpl::Resume() { | 1128 void WebMediaPlayerImpl::Resume() { |
1121 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1129 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1122 CHECK(suspended_); | 1130 CHECK(suspended_); |
1123 CHECK(!resuming_); | 1131 CHECK(!resuming_); |
1124 | 1132 |
1125 // If there was a time change pending when we suspended (which can happen when | 1133 // If there was a time change pending when we suspended (which can happen when |
1126 // we suspend immediately after a seek), surface it after resuming. | 1134 // we suspend immediately after a seek), surface it after resuming. |
1127 bool time_changed = pending_time_change_; | 1135 bool time_changed = pending_time_change_; |
1128 pending_time_change_ = false; | 1136 pending_time_change_ = false; |
1129 | 1137 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 | 1332 |
1325 // pause() may be called after playback has ended and the HTMLMediaElement | 1333 // pause() may be called after playback has ended and the HTMLMediaElement |
1326 // requires that currentTime() == duration() after ending. We want to ensure | 1334 // requires that currentTime() == duration() after ending. We want to ensure |
1327 // |paused_time_| matches currentTime() in this case or a future seek() may | 1335 // |paused_time_| matches currentTime() in this case or a future seek() may |
1328 // incorrectly discard what it thinks is a seek to the existing time. | 1336 // incorrectly discard what it thinks is a seek to the existing time. |
1329 paused_time_ = | 1337 paused_time_ = |
1330 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 1338 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
1331 } | 1339 } |
1332 | 1340 |
1333 void WebMediaPlayerImpl::NotifyPlaybackStarted() { | 1341 void WebMediaPlayerImpl::NotifyPlaybackStarted() { |
1334 if (delegate_) | 1342 if (delegate_) { |
1335 delegate_->DidPlay(this); | 1343 delegate_->DidPlay(this, hasVideo(), hasAudio(), false, |
| 1344 pipeline_.GetMediaDuration()); |
| 1345 } |
1336 if (!memory_usage_reporting_timer_.IsRunning()) { | 1346 if (!memory_usage_reporting_timer_.IsRunning()) { |
1337 memory_usage_reporting_timer_.Start(FROM_HERE, | 1347 memory_usage_reporting_timer_.Start(FROM_HERE, |
1338 base::TimeDelta::FromSeconds(2), this, | 1348 base::TimeDelta::FromSeconds(2), this, |
1339 &WebMediaPlayerImpl::ReportMemoryUsage); | 1349 &WebMediaPlayerImpl::ReportMemoryUsage); |
1340 } | 1350 } |
1341 } | 1351 } |
1342 | 1352 |
1343 void WebMediaPlayerImpl::NotifyPlaybackPaused() { | 1353 void WebMediaPlayerImpl::NotifyPlaybackPaused() { |
1344 if (delegate_) | 1354 if (delegate_) |
1345 delegate_->DidPause(this); | 1355 delegate_->DidPause(this, ended_); |
1346 memory_usage_reporting_timer_.Stop(); | 1356 memory_usage_reporting_timer_.Stop(); |
1347 ReportMemoryUsage(); | 1357 ReportMemoryUsage(); |
1348 } | 1358 } |
1349 | 1359 |
1350 void WebMediaPlayerImpl::ReportMemoryUsage() { | 1360 void WebMediaPlayerImpl::ReportMemoryUsage() { |
1351 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1361 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1352 | 1362 |
1353 // About base::Unretained() usage below: We destroy |demuxer_| on the main | 1363 // About base::Unretained() usage below: We destroy |demuxer_| on the main |
1354 // thread. Before that, however, ~WebMediaPlayerImpl() posts a task to the | 1364 // thread. Before that, however, ~WebMediaPlayerImpl() posts a task to the |
1355 // media thread and waits for it to finish. Hence, the GetMemoryUsage() task | 1365 // media thread and waits for it to finish. Hence, the GetMemoryUsage() task |
(...skipping 22 matching lines...) Expand all Loading... |
1378 << ", Video: " << stats.video_memory_usage << ", DataSource: " | 1388 << ", Video: " << stats.video_memory_usage << ", DataSource: " |
1379 << (data_source_ ? data_source_->GetMemoryUsage() : 0) | 1389 << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
1380 << ", Demuxer: " << demuxer_memory_usage; | 1390 << ", Demuxer: " << demuxer_memory_usage; |
1381 | 1391 |
1382 const int64_t delta = current_memory_usage - last_reported_memory_usage_; | 1392 const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
1383 last_reported_memory_usage_ = current_memory_usage; | 1393 last_reported_memory_usage_ = current_memory_usage; |
1384 adjust_allocated_memory_cb_.Run(delta); | 1394 adjust_allocated_memory_cb_.Run(delta); |
1385 } | 1395 } |
1386 | 1396 |
1387 } // namespace media | 1397 } // namespace media |
OLD | NEW |