diff options
author | kylep@chromium.org <kylep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-28 20:00:44 +0000 |
---|---|---|
committer | kylep@chromium.org <kylep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-28 20:00:44 +0000 |
commit | 4940216a4f034e8de5740d30b413eec3ed495b6d (patch) | |
tree | b8aa9c088d767f309b0a1a880c587ce23040272f /media | |
parent | 024086b48429fe6aab498df59b1f463b81d3073f (diff) | |
download | chromium_src-4940216a4f034e8de5740d30b413eec3ed495b6d.zip chromium_src-4940216a4f034e8de5740d30b413eec3ed495b6d.tar.gz chromium_src-4940216a4f034e8de5740d30b413eec3ed495b6d.tar.bz2 |
Pipeline will execute a callback whenever an run-time error has happened.
BUG=16738
TEST=pipeline_impl_unittest.cc
Review URL: http://codereview.chromium.org/159373
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21877 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/pipeline_impl.cc | 10 | ||||
-rw-r--r-- | media/base/pipeline_impl.h | 9 | ||||
-rw-r--r-- | media/base/pipeline_impl_unittest.cc | 7 |
3 files changed, 25 insertions, 1 deletions
diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 9b482f8..20bd4cb 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -237,6 +237,10 @@ PipelineError PipelineImpl::GetError() const { return error_; } +void PipelineImpl::SetPipelineErrorCallback(PipelineCallback* error_callback) { + error_callback_.reset(error_callback); +} + void PipelineImpl::ResetState() { AutoLock auto_lock(lock_); running_ = false; @@ -533,6 +537,12 @@ void PipelineImpl::ErrorChangedTask(PipelineError error) { // Destroy every filter and reset the pipeline as well. DestroyFilters(); + + // If our owner has requested to be notified of an error, execute + // |error_callback_| unless we have a "good" error. + if (error_callback_.get() && error != PIPELINE_STOPPING) { + error_callback_->Run(); + } } void PipelineImpl::PlaybackRateChangedTask(float playback_rate) { diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index 4eed436..be3ad28 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -7,9 +7,10 @@ #ifndef MEDIA_BASE_PIPELINE_IMPL_H_ #define MEDIA_BASE_PIPELINE_IMPL_H_ +#include <map> +#include <set> #include <string> #include <vector> -#include <set> #include "base/message_loop.h" #include "base/ref_counted.h" @@ -82,6 +83,11 @@ class PipelineImpl : public Pipeline, public FilterHost { virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; virtual PipelineError GetError() const; + // |error_callback_| will be executed upon an error in the pipeline. If + // |error_callback_| is NULL, it is ignored. The pipeline takes ownernship + // of |error_callback|. + virtual void SetPipelineErrorCallback(PipelineCallback* error_callback); + private: // Pipeline states, as described above. enum State { @@ -314,6 +320,7 @@ class PipelineImpl : public Pipeline, public FilterHost { // Callbacks for various pipeline operations. scoped_ptr<PipelineCallback> seek_callback_; scoped_ptr<PipelineCallback> stop_callback_; + scoped_ptr<PipelineCallback> error_callback_; // Vector of our filters and map maintaining the relationship between the // FilterType and the filter itself. diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index e745761..6913cdc 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -32,6 +32,7 @@ class CallbackHelper { MOCK_METHOD0(OnStart, void()); MOCK_METHOD0(OnSeek, void()); MOCK_METHOD0(OnStop, void()); + MOCK_METHOD0(OnError, void()); private: DISALLOW_COPY_AND_ASSIGN(CallbackHelper); @@ -48,6 +49,9 @@ class PipelineImplTest : public ::testing::Test { PipelineImplTest() : pipeline_(new PipelineImpl(&message_loop_)), mocks_(new MockFilterFactory()) { + pipeline_->SetPipelineErrorCallback(NewCallback( + reinterpret_cast<CallbackHelper*>(&callbacks_), + &CallbackHelper::OnError)); } virtual ~PipelineImplTest() { @@ -232,6 +236,7 @@ TEST_F(PipelineImplTest, NeverInitializes) { } TEST_F(PipelineImplTest, RequiredFilterMissing) { + EXPECT_CALL(callbacks_, OnError()); mocks_->set_creation_successful(false); InitializePipeline(); @@ -245,6 +250,7 @@ TEST_F(PipelineImplTest, URLNotFound) { .WillOnce(DoAll(SetError(mocks_->data_source(), PIPELINE_ERROR_URL_NOT_FOUND), Invoke(&RunFilterCallback))); + EXPECT_CALL(callbacks_, OnError()); EXPECT_CALL(*mocks_->data_source(), Stop()); InitializePipeline(); @@ -264,6 +270,7 @@ TEST_F(PipelineImplTest, NoStreams) { EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) .WillRepeatedly(Return(0)); EXPECT_CALL(*mocks_->demuxer(), Stop()); + EXPECT_CALL(callbacks_, OnError()); InitializePipeline(); EXPECT_FALSE(pipeline_->IsInitialized()); |