diff options
author | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-18 19:52:08 +0000 |
---|---|---|
committer | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-18 19:52:08 +0000 |
commit | 7b268b7a549561344b59da31d58cbe3c6ca71dd8 (patch) | |
tree | b93d5a298c4e40b896026ed02a28efb999701d35 /media/base/pipeline_impl.cc | |
parent | 49d633905b2467796aa6a4794f64001664358334 (diff) | |
download | chromium_src-7b268b7a549561344b59da31d58cbe3c6ca71dd8.zip chromium_src-7b268b7a549561344b59da31d58cbe3c6ca71dd8.tar.gz chromium_src-7b268b7a549561344b59da31d58cbe3c6ca71dd8.tar.bz2 |
Fire canplaythrough event at the proper time for audio/video
In this CL, the browser fires the canplaythrough event based on an
approximation of the download speed of the media instead of firing the
event right away.
BUG=73609
TEST=NONE
Review URL: http://codereview.chromium.org/8399023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110733 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/pipeline_impl.cc')
-rw-r--r-- | media/base/pipeline_impl.cc | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index e0d8270..386b064 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -143,6 +143,8 @@ void PipelineImpl::Seek(base::TimeDelta time, return; } + download_rate_monitor_.Stop(); + message_loop_->PostTask(FROM_HERE, base::Bind(&PipelineImpl::SeekTask, this, time, seek_callback)); } @@ -186,9 +188,8 @@ float PipelineImpl::GetPlaybackRate() const { } void PipelineImpl::SetPlaybackRate(float playback_rate) { - if (playback_rate < 0.0f) { + if (playback_rate < 0.0f) return; - } base::AutoLock auto_lock(lock_); playback_rate_ = playback_rate; @@ -204,9 +205,8 @@ float PipelineImpl::GetVolume() const { } void PipelineImpl::SetVolume(float volume) { - if (volume < 0.0f || volume > 1.0f) { + if (volume < 0.0f || volume > 1.0f) return; - } base::AutoLock auto_lock(lock_); volume_ = volume; @@ -239,6 +239,7 @@ base::TimeDelta PipelineImpl::GetCurrentTime() const { } base::TimeDelta PipelineImpl::GetCurrentTime_Locked() const { + lock_.AssertAcquired(); base::TimeDelta elapsed = clock_->Elapsed(); if (state_ == kEnded || elapsed > duration_) { return duration_; @@ -258,9 +259,8 @@ base::TimeDelta PipelineImpl::GetBufferedTime() { base::TimeDelta current_time = GetCurrentTime_Locked(); // If buffered time was set, we report that value directly. - if (buffered_time_.ToInternalValue() > 0) { + if (buffered_time_.ToInternalValue() > 0) return std::max(buffered_time_, current_time); - } if (total_bytes_ == 0) return base::TimeDelta(); @@ -371,6 +371,7 @@ void PipelineImpl::ResetState() { waiting_for_clock_update_ = false; audio_disabled_ = false; clock_->SetTime(kZero); + download_rate_monitor_.Reset(); } void PipelineImpl::SetState(State next_state) { @@ -524,16 +525,17 @@ void PipelineImpl::SetTotalBytes(int64 total_bytes) { base::AutoLock auto_lock(lock_); total_bytes_ = total_bytes; + download_rate_monitor_.set_total_bytes(total_bytes_); } void PipelineImpl::SetBufferedBytes(int64 buffered_bytes) { DCHECK(IsRunning()); base::AutoLock auto_lock(lock_); - // See comments in SetCurrentReadPosition() about capping. if (buffered_bytes < current_bytes_) current_bytes_ = buffered_bytes; buffered_bytes_ = buffered_bytes; + download_rate_monitor_.SetBufferedBytes(buffered_bytes, base::Time::Now()); } void PipelineImpl::SetNaturalVideoSize(const gfx::Size& size) { @@ -570,13 +572,24 @@ void PipelineImpl::SetLoaded(bool loaded) { base::AutoLock auto_lock(lock_); loaded_ = loaded; + download_rate_monitor_.set_loaded(loaded_); } void PipelineImpl::SetNetworkActivity(bool is_downloading_data) { DCHECK(IsRunning()); + + NetworkEvent type = DOWNLOAD_PAUSED; + if (is_downloading_data) + type = DOWNLOAD_CONTINUED; + + { + base::AutoLock auto_lock(lock_); + download_rate_monitor_.SetNetworkActivity(is_downloading_data); + } + message_loop_->PostTask(FROM_HERE, base::Bind( - &PipelineImpl::NotifyNetworkEventTask, this, is_downloading_data)); + &PipelineImpl::NotifyNetworkEventTask, this, type)); media_log_->AddEvent( media_log_->CreateBooleanEvent( MediaLogEvent::NETWORK_ACTIVITY_SET, @@ -682,7 +695,6 @@ void PipelineImpl::InitializeTask() { state_ == kInitVideoDecoder || state_ == kInitVideoRenderer); - // Demuxer created, create audio decoder. if (state_ == kInitDemuxer) { SetState(kInitAudioDecoder); @@ -940,10 +952,10 @@ void PipelineImpl::NotifyEndedTask() { } } -void PipelineImpl::NotifyNetworkEventTask(bool is_downloading_data) { +void PipelineImpl::NotifyNetworkEventTask(NetworkEvent type) { DCHECK_EQ(MessageLoop::current(), message_loop_); if (!network_callback_.is_null()) - network_callback_.Run(is_downloading_data); + network_callback_.Run(type); } void PipelineImpl::DisableAudioRendererTask() { @@ -1030,6 +1042,16 @@ void PipelineImpl::FilterStateTransitionTask() { if (!waiting_for_clock_update_) clock_->Play(); + // Start monitoring rate of downloading. + int bitrate = 0; + if (demuxer_.get()) + bitrate = demuxer_->GetBitrate(); + // Needs to be locked because most other calls to |download_rate_monitor_| + // occur on the renderer thread. + download_rate_monitor_.Start( + base::Bind(&PipelineImpl::OnCanPlayThrough, this), bitrate); + download_rate_monitor_.SetBufferedBytes(buffered_bytes_, base::Time::Now()); + if (IsPipelineStopPending()) { // We had a pending stop request need to be honored right now. TearDownPipeline(); @@ -1405,4 +1427,14 @@ void PipelineImpl::OnAudioUnderflow() { audio_renderer_->ResumeAfterUnderflow(true); } +void PipelineImpl::OnCanPlayThrough() { + message_loop_->PostTask(FROM_HERE, + base::Bind(&PipelineImpl::NotifyCanPlayThrough, this)); +} + +void PipelineImpl::NotifyCanPlayThrough() { + DCHECK_EQ(MessageLoop::current(), message_loop_); + NotifyNetworkEventTask(CAN_PLAY_THROUGH); +} + } // namespace media |