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 "content/renderer/media/webmediaplayer_impl.h" | 5 #include "content/renderer/media/webmediaplayer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 preload_(BufferedDataSource::AUTO), | 144 preload_(BufferedDataSource::AUTO), |
145 main_task_runner_(base::MessageLoopProxy::current()), | 145 main_task_runner_(base::MessageLoopProxy::current()), |
146 media_task_runner_(params.media_task_runner()), | 146 media_task_runner_(params.media_task_runner()), |
147 media_log_(params.media_log()), | 147 media_log_(params.media_log()), |
148 pipeline_(media_task_runner_, media_log_.get()), | 148 pipeline_(media_task_runner_, media_log_.get()), |
149 load_type_(LoadTypeURL), | 149 load_type_(LoadTypeURL), |
150 opaque_(false), | 150 opaque_(false), |
151 paused_(true), | 151 paused_(true), |
152 seeking_(false), | 152 seeking_(false), |
153 playback_rate_(0.0f), | 153 playback_rate_(0.0f), |
| 154 ended_(false), |
154 pending_seek_(false), | 155 pending_seek_(false), |
155 pending_seek_seconds_(0.0f), | 156 pending_seek_seconds_(0.0f), |
156 should_notify_time_changed_(false), | 157 should_notify_time_changed_(false), |
157 client_(client), | 158 client_(client), |
158 delegate_(delegate), | 159 delegate_(delegate), |
159 defer_load_cb_(params.defer_load_cb()), | 160 defer_load_cb_(params.defer_load_cb()), |
160 gpu_factories_(params.gpu_factories()), | 161 gpu_factories_(params.gpu_factories()), |
161 supports_save_(true), | 162 supports_save_(true), |
162 chunk_demuxer_(NULL), | 163 chunk_demuxer_(NULL), |
163 compositor_task_runner_(params.compositor_task_runner()), | 164 compositor_task_runner_(params.compositor_task_runner()), |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 304 |
304 bool WebMediaPlayerImpl::supportsSave() const { | 305 bool WebMediaPlayerImpl::supportsSave() const { |
305 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 306 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
306 return supports_save_; | 307 return supports_save_; |
307 } | 308 } |
308 | 309 |
309 void WebMediaPlayerImpl::seek(double seconds) { | 310 void WebMediaPlayerImpl::seek(double seconds) { |
310 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")"; | 311 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")"; |
311 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 312 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
312 | 313 |
| 314 ended_ = false; |
| 315 |
313 if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata) | 316 if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata) |
314 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 317 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
315 | 318 |
316 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); | 319 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); |
317 | 320 |
318 if (seeking_) { | 321 if (seeking_) { |
319 pending_seek_ = true; | 322 pending_seek_ = true; |
320 pending_seek_seconds_ = seconds; | 323 pending_seek_seconds_ = seconds; |
321 if (chunk_demuxer_) | 324 if (chunk_demuxer_) |
322 chunk_demuxer_->CancelPendingSeek(seek_time); | 325 chunk_demuxer_->CancelPendingSeek(seek_time); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 439 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
437 | 440 |
438 if (pipeline_metadata_.timeline_offset.is_null()) | 441 if (pipeline_metadata_.timeline_offset.is_null()) |
439 return std::numeric_limits<double>::quiet_NaN(); | 442 return std::numeric_limits<double>::quiet_NaN(); |
440 | 443 |
441 return pipeline_metadata_.timeline_offset.ToJsTime(); | 444 return pipeline_metadata_.timeline_offset.ToJsTime(); |
442 } | 445 } |
443 | 446 |
444 double WebMediaPlayerImpl::currentTime() const { | 447 double WebMediaPlayerImpl::currentTime() const { |
445 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 448 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 449 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 450 |
| 451 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement, |
| 452 // see http://crbug.com/409280 |
| 453 if (ended_) |
| 454 return duration(); |
| 455 |
446 return (paused_ ? paused_time_ : pipeline_.GetMediaTime()).InSecondsF(); | 456 return (paused_ ? paused_time_ : pipeline_.GetMediaTime()).InSecondsF(); |
447 } | 457 } |
448 | 458 |
449 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { | 459 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { |
450 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 460 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
451 return network_state_; | 461 return network_state_; |
452 } | 462 } |
453 | 463 |
454 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { | 464 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { |
455 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 465 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 // Update our paused time. | 701 // Update our paused time. |
692 if (paused_) | 702 if (paused_) |
693 paused_time_ = pipeline_.GetMediaTime(); | 703 paused_time_ = pipeline_.GetMediaTime(); |
694 | 704 |
695 should_notify_time_changed_ = time_changed; | 705 should_notify_time_changed_ = time_changed; |
696 } | 706 } |
697 | 707 |
698 void WebMediaPlayerImpl::OnPipelineEnded() { | 708 void WebMediaPlayerImpl::OnPipelineEnded() { |
699 DVLOG(1) << __FUNCTION__; | 709 DVLOG(1) << __FUNCTION__; |
700 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 710 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 711 |
| 712 // Ignore state changes until we've completed all outstanding seeks. |
| 713 if (seeking_ || pending_seek_) |
| 714 return; |
| 715 |
| 716 ended_ = true; |
701 client_->timeChanged(); | 717 client_->timeChanged(); |
702 } | 718 } |
703 | 719 |
704 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { | 720 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { |
705 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 721 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
706 DCHECK_NE(error, media::PIPELINE_OK); | 722 DCHECK_NE(error, media::PIPELINE_OK); |
707 | 723 |
708 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) { | 724 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) { |
709 // Any error that occurs before reaching ReadyStateHaveMetadata should | 725 // Any error that occurs before reaching ReadyStateHaveMetadata should |
710 // be considered a format error. | 726 // be considered a format error. |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 compositor_task_runner_->PostTask(FROM_HERE, | 1027 compositor_task_runner_->PostTask(FROM_HERE, |
1012 base::Bind(&GetCurrentFrameAndSignal, | 1028 base::Bind(&GetCurrentFrameAndSignal, |
1013 base::Unretained(compositor_), | 1029 base::Unretained(compositor_), |
1014 &video_frame, | 1030 &video_frame, |
1015 &event)); | 1031 &event)); |
1016 event.Wait(); | 1032 event.Wait(); |
1017 return video_frame; | 1033 return video_frame; |
1018 } | 1034 } |
1019 | 1035 |
1020 } // namespace content | 1036 } // namespace content |
OLD | NEW |