diff options
-rw-r--r-- | media/base/filter_host.h | 2 | ||||
-rw-r--r-- | media/base/pipeline.h | 11 | ||||
-rw-r--r-- | media/base/pipeline_impl.cc | 26 | ||||
-rw-r--r-- | media/base/pipeline_impl.h | 12 | ||||
-rw-r--r-- | media/base/pipeline_impl_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source.cc | 10 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source.h | 4 | ||||
-rw-r--r-- | webkit/glue/media/buffered_resource_loader.cc | 35 | ||||
-rw-r--r-- | webkit/glue/media/buffered_resource_loader.h | 12 | ||||
-rw-r--r-- | webkit/glue/webmediaplayer_impl.cc | 12 | ||||
-rw-r--r-- | webkit/glue/webmediaplayer_impl.h | 2 | ||||
-rw-r--r-- | webkit/glue/webmediaplayer_proxy.cc | 23 | ||||
-rw-r--r-- | webkit/glue/webmediaplayer_proxy.h | 4 |
13 files changed, 65 insertions, 90 deletions
diff --git a/media/base/filter_host.h b/media/base/filter_host.h index d6977b6..412fdd7 100644 --- a/media/base/filter_host.h +++ b/media/base/filter_host.h @@ -67,7 +67,7 @@ class MEDIA_EXPORT FilterHost { virtual void SetLoaded(bool loaded) = 0; // Sets the flag to indicate current network activity. - virtual void SetNetworkActivity(bool network_activity) = 0; + virtual void SetNetworkActivity(bool is_downloading_data) = 0; // Disable audio renderer by calling OnAudioRendererDisabled() on all // filters. diff --git a/media/base/pipeline.h b/media/base/pipeline.h index 1945010..7cf5e73 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -38,6 +38,12 @@ class FilterCollection; class MEDIA_EXPORT Pipeline : public base::RefCountedThreadSafe<Pipeline> { public: + // Callback that executes when a network event occurrs. + // The parameter represents the state of network activity: true if the network + // is downloading data, false if it is not. If the callback never runs, it is + // assumed the network is not downloading data. + typedef base::Callback<void(bool)> NetworkEventCB; + // Initializes pipeline. Pipeline takes ownership of all callbacks passed // into this method. // |ended_callback| will be executed when the media reaches the end. @@ -45,7 +51,7 @@ class MEDIA_EXPORT Pipeline : public base::RefCountedThreadSafe<Pipeline> { // |network_callback_| will be executed when there's a network event. virtual void Init(const PipelineStatusCB& ended_callback, const PipelineStatusCB& error_callback, - const PipelineStatusCB& network_callback) = 0; + const NetworkEventCB& network_callback) = 0; // Build a pipeline to render the given URL using the given filter collection // to construct a filter chain. Returns true if successful, false otherwise @@ -92,9 +98,6 @@ class MEDIA_EXPORT Pipeline : public base::RefCountedThreadSafe<Pipeline> { // for a pipeline to be started but not initialized (i.e., an error occurred). virtual bool IsInitialized() const = 0; - // Returns true if there has been network activity. - virtual bool IsNetworkActive() const = 0; - // Returns true if the media has audio. virtual bool HasAudio() const = 0; diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 1eb4416..cebab46 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -64,7 +64,6 @@ class PipelineImpl::PipelineInitState { PipelineImpl::PipelineImpl(MessageLoop* message_loop, MediaLog* media_log) : message_loop_(message_loop), media_log_(media_log), - network_activity_(false), clock_(new Clock(&base::Time::Now)), waiting_for_clock_update_(false), state_(kCreated), @@ -87,7 +86,7 @@ PipelineImpl::~PipelineImpl() { void PipelineImpl::Init(const PipelineStatusCB& ended_callback, const PipelineStatusCB& error_callback, - const PipelineStatusCB& network_callback) { + const NetworkEventCB& network_callback) { DCHECK(!IsRunning()) << "Init() should be called before the pipeline has started"; ended_callback_ = ended_callback; @@ -169,11 +168,6 @@ bool PipelineImpl::IsInitialized() const { } } -bool PipelineImpl::IsNetworkActive() const { - base::AutoLock auto_lock(lock_); - return network_activity_; -} - bool PipelineImpl::HasAudio() const { base::AutoLock auto_lock(lock_); return has_audio_; @@ -564,18 +558,15 @@ void PipelineImpl::SetLoaded(bool loaded) { loaded_ = loaded; } -void PipelineImpl::SetNetworkActivity(bool network_activity) { +void PipelineImpl::SetNetworkActivity(bool is_downloading_data) { DCHECK(IsRunning()); - { - base::AutoLock auto_lock(lock_); - network_activity_ = network_activity; - } message_loop_->PostTask(FROM_HERE, - base::Bind(&PipelineImpl::NotifyNetworkEventTask, this)); + base::Bind( + &PipelineImpl::NotifyNetworkEventTask, this, is_downloading_data)); media_log_->AddEvent( media_log_->CreateBooleanEvent( MediaLogEvent::NETWORK_ACTIVITY_SET, - "network_activity", network_activity)); + "is_downloading_data", is_downloading_data)); } void PipelineImpl::DisableAudioRenderer() { @@ -935,11 +926,10 @@ void PipelineImpl::NotifyEndedTask() { } } -void PipelineImpl::NotifyNetworkEventTask() { +void PipelineImpl::NotifyNetworkEventTask(bool is_downloading_data) { DCHECK_EQ(MessageLoop::current(), message_loop_); - if (!network_callback_.is_null()) { - network_callback_.Run(status_); - } + if (!network_callback_.is_null()) + network_callback_.Run(is_downloading_data); } void PipelineImpl::DisableAudioRendererTask() { diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index c4c9898..ef52ac2 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -102,7 +102,7 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { // Pipeline implementation. virtual void Init(const PipelineStatusCB& ended_callback, const PipelineStatusCB& error_callback, - const PipelineStatusCB& network_callback) OVERRIDE; + const NetworkEventCB& network_callback) OVERRIDE; virtual bool Start(FilterCollection* filter_collection, const std::string& uri, const PipelineStatusCB& start_callback) OVERRIDE; @@ -111,7 +111,6 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { const PipelineStatusCB& seek_callback) OVERRIDE; virtual bool IsRunning() const OVERRIDE; virtual bool IsInitialized() const OVERRIDE; - virtual bool IsNetworkActive() const OVERRIDE; virtual bool HasAudio() const OVERRIDE; virtual bool HasVideo() const OVERRIDE; virtual float GetPlaybackRate() const OVERRIDE; @@ -202,7 +201,7 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; virtual void SetStreaming(bool streamed) OVERRIDE; virtual void SetLoaded(bool loaded) OVERRIDE; - virtual void SetNetworkActivity(bool network_activity) OVERRIDE; + virtual void SetNetworkActivity(bool is_downloading_data) OVERRIDE; virtual void NotifyEnded() OVERRIDE; virtual void DisableAudioRenderer() OVERRIDE; virtual void SetCurrentReadPosition(int64 offset) OVERRIDE; @@ -262,7 +261,7 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { void NotifyEndedTask(); // Carries out handling a notification of network event. - void NotifyNetworkEventTask(); + void NotifyNetworkEventTask(bool is_downloading_data); // Carries out disabling the audio renderer. void DisableAudioRendererTask(); @@ -383,9 +382,6 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { // loaded source. bool loaded_; - // Sets by the filters to indicate whether network is active. - bool network_activity_; - // Current volume level (from 0.0f to 1.0f). This value is set immediately // via SetVolume() and a task is dispatched on the message loop to notify the // filters. @@ -457,7 +453,7 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { PipelineStatusCB stop_callback_; PipelineStatusCB ended_callback_; PipelineStatusCB error_callback_; - PipelineStatusCB network_callback_; + NetworkEventCB network_callback_; // Reference to the filter(s) that constitute the pipeline. scoped_refptr<Filter> pipeline_filter_; diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index 4f7fb51..d6b5068 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -65,7 +65,7 @@ class PipelineImplTest : public ::testing::Test { pipeline_->Init( base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), - PipelineStatusCB()); + Pipeline::NetworkEventCB()); mocks_.reset(new MockFilterCollection()); // InitializeDemuxer adds overriding expectations for expected non-NULL diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc index 407a73a..a3f43cf5 100644 --- a/webkit/glue/media/buffered_data_source.cc +++ b/webkit/glue/media/buffered_data_source.cc @@ -50,7 +50,7 @@ BufferedDataSource::BufferedDataSource( streaming_(false), frame_(frame), loader_(NULL), - network_activity_(false), + is_downloading_data_(false), read_position_(0), read_size_(0), read_buffer_(NULL), @@ -621,7 +621,7 @@ void BufferedDataSource::NetworkEventCallback() { if (loaded_) return; - bool network_activity = loader_->network_activity(); + bool is_downloading_data = loader_->is_downloading_data(); int64 buffered_position = loader_->GetBufferedPosition(); // If we get an unspecified value, return immediately. @@ -640,10 +640,10 @@ void BufferedDataSource::NetworkEventCallback() { if (stop_signal_received_) return; - if (network_activity != network_activity_) { - network_activity_ = network_activity; + if (is_downloading_data != is_downloading_data_) { + is_downloading_data_ = is_downloading_data; if (host()) - host()->SetNetworkActivity(network_activity); + host()->SetNetworkActivity(is_downloading_data); } buffered_bytes_ = buffered_position + 1; diff --git a/webkit/glue/media/buffered_data_source.h b/webkit/glue/media/buffered_data_source.h index b157d5e..7667e4c 100644 --- a/webkit/glue/media/buffered_data_source.h +++ b/webkit/glue/media/buffered_data_source.h @@ -158,8 +158,8 @@ class BufferedDataSource : public WebDataSource { // A resource loader for the media resource. scoped_refptr<BufferedResourceLoader> loader_; - // True if network is active. - bool network_activity_; + // True if |loader| is downloading data. + bool is_downloading_data_; // Callback method from the pipeline for initialization. media::PipelineStatusCB initialize_cb_; diff --git a/webkit/glue/media/buffered_resource_loader.cc b/webkit/glue/media/buffered_resource_loader.cc index d39d54b..457aee2 100644 --- a/webkit/glue/media/buffered_resource_loader.cc +++ b/webkit/glue/media/buffered_resource_loader.cc @@ -295,12 +295,8 @@ void BufferedResourceLoader::Read(int64 position, // Make sure we stop deferring now that there's additional capacity. // // XXX: can we DCHECK(url_loader_.get()) at this point in time? - if (deferred_ && url_loader_.get()) { - deferred_ = false; - - url_loader_->setDefersLoading(deferred_); - NotifyNetworkEvent(); - } + if (deferred_) + SetDeferred(false); DCHECK(!ShouldEnableDefer()) << "Capacity was not adjusted properly to prevent deferring."; @@ -330,7 +326,7 @@ bool BufferedResourceLoader::range_supported() { return range_supported_; } -bool BufferedResourceLoader::network_activity() { +bool BufferedResourceLoader::is_downloading_data() { return !completed_ && !deferred_; } @@ -609,11 +605,17 @@ void BufferedResourceLoader::UpdateDeferBehavior() { if (!url_loader_.get() || !buffer_.get()) return; - if ((deferred_ && ShouldDisableDefer()) || - (!deferred_ && ShouldEnableDefer())) { - bool eventOccurred = ToggleDeferring(); - if (eventOccurred) - NotifyNetworkEvent(); + // If necessary, toggle defer state and continue/pause downloading data + // accordingly. + if (ShouldEnableDefer() || ShouldDisableDefer()) + SetDeferred(!deferred_); +} + +void BufferedResourceLoader::SetDeferred(bool deferred) { + deferred_ = deferred; + if (url_loader_.get()) { + url_loader_->setDefersLoading(deferred); + NotifyNetworkEvent(); } } @@ -668,15 +670,6 @@ bool BufferedResourceLoader::ShouldDisableDefer() { return false; } -bool BufferedResourceLoader::ToggleDeferring() { - deferred_ = !deferred_; - if (url_loader_.get()) { - url_loader_->setDefersLoading(deferred_); - return true; - } - return false; -} - bool BufferedResourceLoader::CanFulfillRead() { // If we are reading too far in the backward direction. if (first_offset_ < 0 && diff --git a/webkit/glue/media/buffered_resource_loader.h b/webkit/glue/media/buffered_resource_loader.h index 1b6d55f..50e2ae8 100644 --- a/webkit/glue/media/buffered_resource_loader.h +++ b/webkit/glue/media/buffered_resource_loader.h @@ -116,8 +116,8 @@ class BufferedResourceLoader // Returns true if the server supports byte range requests. virtual bool range_supported(); - // Returns true if network is currently active. - virtual bool network_activity(); + // Returns true if the resource loader is currently downloading data. + virtual bool is_downloading_data(); // Returns resulting URL. virtual const GURL& url(); @@ -179,10 +179,6 @@ class BufferedResourceLoader // Updates the |buffer_|'s forward and backward capacities. void UpdateBufferWindow(); - // Toggles whether the resource loading is deferred or not. - // Returns true if a network event was fired. - bool ToggleDeferring(); - // Returns true if we should defer resource loading, based // on current buffering scheme. bool ShouldEnableDefer(); @@ -194,6 +190,10 @@ class BufferedResourceLoader // Updates deferring behavior based on current buffering scheme. void UpdateDeferBehavior(); + // Set defer state to |deferred| and cease/continue downloading data + // accordingly. + void SetDeferred(bool deferred); + // Returns true if the current read request can be fulfilled by what is in // the buffer. bool CanFulfillRead(); diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc index fd8d497..a7d6878 100644 --- a/webkit/glue/webmediaplayer_impl.cc +++ b/webkit/glue/webmediaplayer_impl.cc @@ -786,14 +786,12 @@ void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { Repaint(); } -void WebMediaPlayerImpl::OnNetworkEvent(PipelineStatus status) { +void WebMediaPlayerImpl::OnNetworkEvent(bool is_downloading_data) { DCHECK_EQ(main_loop_, MessageLoop::current()); - if (status == media::PIPELINE_OK) { - if (pipeline_->IsNetworkActive()) - SetNetworkState(WebKit::WebMediaPlayer::Loading); - else - SetNetworkState(WebKit::WebMediaPlayer::Idle); - } + if (is_downloading_data) + SetNetworkState(WebKit::WebMediaPlayer::Loading); + else + SetNetworkState(WebKit::WebMediaPlayer::Idle); } void WebMediaPlayerImpl::OnDemuxerOpened() { diff --git a/webkit/glue/webmediaplayer_impl.h b/webkit/glue/webmediaplayer_impl.h index 7f1eb13..ea19d58 100644 --- a/webkit/glue/webmediaplayer_impl.h +++ b/webkit/glue/webmediaplayer_impl.h @@ -196,7 +196,7 @@ class WebMediaPlayerImpl void OnPipelineSeek(media::PipelineStatus status); void OnPipelineEnded(media::PipelineStatus status); void OnPipelineError(media::PipelineStatus error); - void OnNetworkEvent(media::PipelineStatus status); + void OnNetworkEvent(bool is_downloading_data); void OnDemuxerOpened(); private: diff --git a/webkit/glue/webmediaplayer_proxy.cc b/webkit/glue/webmediaplayer_proxy.cc index 99071aa..3110f37 100644 --- a/webkit/glue/webmediaplayer_proxy.cc +++ b/webkit/glue/webmediaplayer_proxy.cc @@ -127,9 +127,9 @@ void WebMediaPlayerProxy::PipelineErrorCallback(PipelineStatus error) { this, &WebMediaPlayerProxy::PipelineErrorTask, error)); } -void WebMediaPlayerProxy::NetworkEventCallback(PipelineStatus status) { +void WebMediaPlayerProxy::NetworkEventCallback(bool is_downloading_data) { render_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &WebMediaPlayerProxy::NetworkEventTask, status)); + this, &WebMediaPlayerProxy::NetworkEventTask, is_downloading_data)); } void WebMediaPlayerProxy::AddDataSource(WebDataSource* data_source) { @@ -151,37 +151,32 @@ void WebMediaPlayerProxy::RepaintTask() { void WebMediaPlayerProxy::PipelineInitializationTask(PipelineStatus status) { DCHECK(MessageLoop::current() == render_loop_); - if (webmediaplayer_) { + if (webmediaplayer_) webmediaplayer_->OnPipelineInitialize(status); - } } void WebMediaPlayerProxy::PipelineSeekTask(PipelineStatus status) { DCHECK(MessageLoop::current() == render_loop_); - if (webmediaplayer_) { + if (webmediaplayer_) webmediaplayer_->OnPipelineSeek(status); - } } void WebMediaPlayerProxy::PipelineEndedTask(PipelineStatus status) { DCHECK(MessageLoop::current() == render_loop_); - if (webmediaplayer_) { + if (webmediaplayer_) webmediaplayer_->OnPipelineEnded(status); - } } void WebMediaPlayerProxy::PipelineErrorTask(PipelineStatus error) { DCHECK(MessageLoop::current() == render_loop_); - if (webmediaplayer_) { + if (webmediaplayer_) webmediaplayer_->OnPipelineError(error); - } } -void WebMediaPlayerProxy::NetworkEventTask(PipelineStatus status) { +void WebMediaPlayerProxy::NetworkEventTask(bool is_downloading_data) { DCHECK(MessageLoop::current() == render_loop_); - if (webmediaplayer_) { - webmediaplayer_->OnNetworkEvent(status); - } + if (webmediaplayer_) + webmediaplayer_->OnNetworkEvent(is_downloading_data); } void WebMediaPlayerProxy::GetCurrentFrame( diff --git a/webkit/glue/webmediaplayer_proxy.h b/webkit/glue/webmediaplayer_proxy.h index 5dbc1bd..9fd3d25 100644 --- a/webkit/glue/webmediaplayer_proxy.h +++ b/webkit/glue/webmediaplayer_proxy.h @@ -52,7 +52,7 @@ class WebMediaPlayerProxy void PipelineSeekCallback(media::PipelineStatus status); void PipelineEndedCallback(media::PipelineStatus status); void PipelineErrorCallback(media::PipelineStatus error); - void NetworkEventCallback(media::PipelineStatus status); + void NetworkEventCallback(bool network_activity); // ChunkDemuxerClient implementation. virtual void DemuxerOpened(media::ChunkDemuxer* demuxer) OVERRIDE; @@ -94,7 +94,7 @@ class WebMediaPlayerProxy void PipelineErrorTask(media::PipelineStatus error); // Notify |webmediaplayer_| that there's a network event. - void NetworkEventTask(media::PipelineStatus status); + void NetworkEventTask(bool network_activity); // The render message loop where WebKit lives. MessageLoop* render_loop_; |