| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/webmediaplayer_impl.h" | 5 #include "webkit/glue/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 WebMediaPlayerImpl::WebMediaPlayerImpl( | 226 WebMediaPlayerImpl::WebMediaPlayerImpl( |
| 227 WebKit::WebMediaPlayerClient* client, | 227 WebKit::WebMediaPlayerClient* client, |
| 228 media::FilterCollection* collection) | 228 media::FilterCollection* collection) |
| 229 : network_state_(WebKit::WebMediaPlayer::Empty), | 229 : network_state_(WebKit::WebMediaPlayer::Empty), |
| 230 ready_state_(WebKit::WebMediaPlayer::HaveNothing), | 230 ready_state_(WebKit::WebMediaPlayer::HaveNothing), |
| 231 main_loop_(NULL), | 231 main_loop_(NULL), |
| 232 filter_collection_(collection), | 232 filter_collection_(collection), |
| 233 pipeline_(NULL), | 233 pipeline_(NULL), |
| 234 pipeline_thread_("PipelineThread"), | 234 pipeline_thread_("PipelineThread"), |
| 235 paused_(true), | 235 paused_(true), |
| 236 seeking_(false), |
| 236 playback_rate_(0.0f), | 237 playback_rate_(0.0f), |
| 237 client_(client), | 238 client_(client), |
| 238 proxy_(NULL), | 239 proxy_(NULL), |
| 239 pipeline_stopped_(false, false) { | 240 pipeline_stopped_(false, false) { |
| 240 // Saves the current message loop. | 241 // Saves the current message loop. |
| 241 DCHECK(!main_loop_); | 242 DCHECK(!main_loop_); |
| 242 main_loop_ = MessageLoop::current(); | 243 main_loop_ = MessageLoop::current(); |
| 243 } | 244 } |
| 244 | 245 |
| 245 bool WebMediaPlayerImpl::Initialize( | 246 bool WebMediaPlayerImpl::Initialize( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // cause extra pre-rolling and will break servers without range request | 362 // cause extra pre-rolling and will break servers without range request |
| 362 // support. | 363 // support. |
| 363 // | 364 // |
| 364 // We still have to notify WebKit that time has changed otherwise | 365 // We still have to notify WebKit that time has changed otherwise |
| 365 // HTMLMediaElement gets into an inconsistent state. | 366 // HTMLMediaElement gets into an inconsistent state. |
| 366 if (pipeline_->GetCurrentTime().ToInternalValue() == 0 && seconds == 0) { | 367 if (pipeline_->GetCurrentTime().ToInternalValue() == 0 && seconds == 0) { |
| 367 GetClient()->timeChanged(); | 368 GetClient()->timeChanged(); |
| 368 return; | 369 return; |
| 369 } | 370 } |
| 370 | 371 |
| 371 // Drop our ready state if the media file isn't fully loaded. | |
| 372 if (!pipeline_->IsLoaded()) { | |
| 373 SetReadyState(WebKit::WebMediaPlayer::HaveMetadata); | |
| 374 } | |
| 375 | |
| 376 // Try to preserve as much accuracy as possible. | 372 // Try to preserve as much accuracy as possible. |
| 377 float microseconds = seconds * base::Time::kMicrosecondsPerSecond; | 373 float microseconds = seconds * base::Time::kMicrosecondsPerSecond; |
| 378 base::TimeDelta seek_time = | 374 base::TimeDelta seek_time = |
| 379 base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); | 375 base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); |
| 380 | 376 |
| 381 // Update our paused time. | 377 // Update our paused time. |
| 382 if (paused_) { | 378 if (paused_) { |
| 383 paused_time_ = seek_time; | 379 paused_time_ = seek_time; |
| 384 } | 380 } |
| 385 | 381 |
| 382 seeking_ = true; |
| 383 |
| 386 // Kick off the asynchronous seek! | 384 // Kick off the asynchronous seek! |
| 387 pipeline_->Seek( | 385 pipeline_->Seek( |
| 388 seek_time, | 386 seek_time, |
| 389 NewCallback(proxy_.get(), | 387 NewCallback(proxy_.get(), |
| 390 &WebMediaPlayerImpl::Proxy::PipelineSeekCallback)); | 388 &WebMediaPlayerImpl::Proxy::PipelineSeekCallback)); |
| 391 } | 389 } |
| 392 | 390 |
| 393 void WebMediaPlayerImpl::setEndTime(float seconds) { | 391 void WebMediaPlayerImpl::setEndTime(float seconds) { |
| 394 DCHECK(MessageLoop::current() == main_loop_); | 392 DCHECK(MessageLoop::current() == main_loop_); |
| 395 | 393 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 467 |
| 470 return pipeline_->GetPlaybackRate() == 0.0f; | 468 return pipeline_->GetPlaybackRate() == 0.0f; |
| 471 } | 469 } |
| 472 | 470 |
| 473 bool WebMediaPlayerImpl::seeking() const { | 471 bool WebMediaPlayerImpl::seeking() const { |
| 474 DCHECK(MessageLoop::current() == main_loop_); | 472 DCHECK(MessageLoop::current() == main_loop_); |
| 475 | 473 |
| 476 if (ready_state_ == WebKit::WebMediaPlayer::HaveNothing) | 474 if (ready_state_ == WebKit::WebMediaPlayer::HaveNothing) |
| 477 return false; | 475 return false; |
| 478 | 476 |
| 479 return ready_state_ == WebKit::WebMediaPlayer::HaveMetadata; | 477 return seeking_; |
| 480 } | 478 } |
| 481 | 479 |
| 482 float WebMediaPlayerImpl::duration() const { | 480 float WebMediaPlayerImpl::duration() const { |
| 483 DCHECK(MessageLoop::current() == main_loop_); | 481 DCHECK(MessageLoop::current() == main_loop_); |
| 484 | 482 |
| 485 base::TimeDelta duration = pipeline_->GetMediaDuration(); | 483 base::TimeDelta duration = pipeline_->GetMediaDuration(); |
| 486 if (duration.InMicroseconds() == media::Limits::kMaxTimeInMicroseconds) | 484 if (duration.InMicroseconds() == media::Limits::kMaxTimeInMicroseconds) |
| 487 return std::numeric_limits<float>::infinity(); | 485 return std::numeric_limits<float>::infinity(); |
| 488 return static_cast<float>(duration.InSecondsF()); | 486 return static_cast<float>(duration.InSecondsF()); |
| 489 } | 487 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 | 696 |
| 699 void WebMediaPlayerImpl::OnPipelineSeek() { | 697 void WebMediaPlayerImpl::OnPipelineSeek() { |
| 700 DCHECK(MessageLoop::current() == main_loop_); | 698 DCHECK(MessageLoop::current() == main_loop_); |
| 701 if (pipeline_->GetError() == media::PIPELINE_OK) { | 699 if (pipeline_->GetError() == media::PIPELINE_OK) { |
| 702 // Update our paused time. | 700 // Update our paused time. |
| 703 if (paused_) { | 701 if (paused_) { |
| 704 paused_time_ = pipeline_->GetCurrentTime(); | 702 paused_time_ = pipeline_->GetCurrentTime(); |
| 705 } | 703 } |
| 706 | 704 |
| 707 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData); | 705 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData); |
| 706 seeking_ = false; |
| 708 GetClient()->timeChanged(); | 707 GetClient()->timeChanged(); |
| 709 } | 708 } |
| 710 } | 709 } |
| 711 | 710 |
| 712 void WebMediaPlayerImpl::OnPipelineEnded() { | 711 void WebMediaPlayerImpl::OnPipelineEnded() { |
| 713 DCHECK(MessageLoop::current() == main_loop_); | 712 DCHECK(MessageLoop::current() == main_loop_); |
| 714 if (pipeline_->GetError() == media::PIPELINE_OK) { | 713 if (pipeline_->GetError() == media::PIPELINE_OK) { |
| 715 GetClient()->timeChanged(); | 714 GetClient()->timeChanged(); |
| 716 } | 715 } |
| 717 } | 716 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 pipeline_stopped_.Signal(); | 807 pipeline_stopped_.Signal(); |
| 809 } | 808 } |
| 810 | 809 |
| 811 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { | 810 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { |
| 812 DCHECK(MessageLoop::current() == main_loop_); | 811 DCHECK(MessageLoop::current() == main_loop_); |
| 813 DCHECK(client_); | 812 DCHECK(client_); |
| 814 return client_; | 813 return client_; |
| 815 } | 814 } |
| 816 | 815 |
| 817 } // namespace webkit_glue | 816 } // namespace webkit_glue |
| OLD | NEW |