diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/base/filter_host.h | 5 | ||||
-rw-r--r-- | media/base/mock_filter_host.h | 1 | ||||
-rw-r--r-- | media/base/pipeline_impl.cc | 28 | ||||
-rw-r--r-- | media/base/pipeline_impl.h | 12 |
4 files changed, 45 insertions, 1 deletions
diff --git a/media/base/filter_host.h b/media/base/filter_host.h index 2b288d2..4ac939b 100644 --- a/media/base/filter_host.h +++ b/media/base/filter_host.h @@ -64,7 +64,10 @@ class FilterHost { // Sets the flag to indicate that our media is now loaded. virtual void SetLoaded(bool loaded) = 0; - // Broadcast a message of type |message| to all other filters from |source|. + // Sets the flag to indicate current network activity. + virtual void SetNetworkActivity(bool network_activity) = 0; + + // Broadcast a message of type |message| to all filters. virtual void BroadcastMessage(FilterMessage message) = 0; protected: diff --git a/media/base/mock_filter_host.h b/media/base/mock_filter_host.h index dfcf403..0ec6912 100644 --- a/media/base/mock_filter_host.h +++ b/media/base/mock_filter_host.h @@ -38,6 +38,7 @@ class MockFilterHost : public FilterHost { MOCK_METHOD2(SetVideoSize, void(size_t width, size_t height)); MOCK_METHOD1(SetStreaming, void(bool streamed)); MOCK_METHOD1(SetLoaded, void(bool loaded)); + MOCK_METHOD1(SetNetworkActivity, void(bool network_activity)); MOCK_METHOD0(NotifyEnded, void()); MOCK_METHOD1(BroadcastMessage, void(FilterMessage message)); diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 49ebe4a..2b38269 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -157,6 +157,11 @@ bool PipelineImpl::IsInitialized() const { } } +bool PipelineImpl::IsNetworkActive() const { + AutoLock auto_lock(lock_); + return network_activity_; +} + bool PipelineImpl::IsRendered(const std::string& major_mime_type) const { AutoLock auto_lock(lock_); bool is_rendered = (rendered_mime_types_.find(major_mime_type) != @@ -284,6 +289,12 @@ void PipelineImpl::SetPipelineErrorCallback(PipelineCallback* error_callback) { error_callback_.reset(error_callback); } +void PipelineImpl::SetNetworkEventCallback(PipelineCallback* network_callback) { + DCHECK(!IsRunning()) + << "Permanent callbacks should be set before the pipeline has started"; + network_callback_.reset(network_callback); +} + void PipelineImpl::ResetState() { AutoLock auto_lock(lock_); const base::TimeDelta kZero; @@ -417,6 +428,16 @@ void PipelineImpl::SetLoaded(bool loaded) { loaded_ = loaded; } +void PipelineImpl::SetNetworkActivity(bool network_activity) { + DCHECK(IsRunning()); + { + AutoLock auto_lock(lock_); + network_activity_ = network_activity; + } + message_loop_->PostTask(FROM_HERE, + NewRunnableMethod(this, &PipelineImpl::NotifyNetworkEventTask)); +} + void PipelineImpl::BroadcastMessage(FilterMessage message) { DCHECK(IsRunning()); @@ -718,6 +739,13 @@ void PipelineImpl::NotifyEndedTask() { } } +void PipelineImpl::NotifyNetworkEventTask() { + DCHECK_EQ(MessageLoop::current(), message_loop_); + if (network_callback_.get()) { + network_callback_->Run(); + } +} + void PipelineImpl::BroadcastMessageTask(FilterMessage message) { DCHECK_EQ(MessageLoop::current(), message_loop_); diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index 891404a..92eceaa 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -72,6 +72,7 @@ class PipelineImpl : public Pipeline, public FilterHost { virtual void Seek(base::TimeDelta time, PipelineCallback* seek_callback); virtual bool IsRunning() const; virtual bool IsInitialized() const; + virtual bool IsNetworkActive() const; virtual bool IsRendered(const std::string& major_mime_type) const; virtual float GetPlaybackRate() const; virtual void SetPlaybackRate(float playback_rate); @@ -96,6 +97,9 @@ class PipelineImpl : public Pipeline, public FilterHost { // of |error_callback|. virtual void SetPipelineErrorCallback(PipelineCallback* error_callback); + // |network_callback_| will be executed when there's a network event. + virtual void SetNetworkEventCallback(PipelineCallback* network_callback); + private: // Pipeline states, as described above. enum State { @@ -145,6 +149,7 @@ class PipelineImpl : public Pipeline, public FilterHost { virtual void SetVideoSize(size_t width, size_t height); virtual void SetStreaming(bool streamed); virtual void SetLoaded(bool loaded); + virtual void SetNetworkActivity(bool network_activity); virtual void NotifyEnded(); virtual void BroadcastMessage(FilterMessage message); @@ -194,6 +199,9 @@ class PipelineImpl : public Pipeline, public FilterHost { // Carries out handling a notification from a filter that it has ended. void NotifyEndedTask(); + // Carries out handling a notification of network event. + void NotifyNetworkEventTask(); + // Carries out message broadcasting on the message loop. void BroadcastMessageTask(FilterMessage message); @@ -299,6 +307,9 @@ class 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. @@ -356,6 +367,7 @@ class PipelineImpl : public Pipeline, public FilterHost { scoped_ptr<PipelineCallback> stop_callback_; scoped_ptr<PipelineCallback> ended_callback_; scoped_ptr<PipelineCallback> error_callback_; + scoped_ptr<PipelineCallback> network_callback_; // Vector of our filters and map maintaining the relationship between the // FilterType and the filter itself. |