diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-30 20:33:54 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-30 20:33:54 +0000 |
commit | 86ea7b1013fc49cbdd6a0b7516f9b4faecd6b57a (patch) | |
tree | 310a37ca44d6cab7e1e456c5b00d535c93111c92 | |
parent | 32f497b982637006871eb3e32313a079909c7757 (diff) | |
download | chromium_src-86ea7b1013fc49cbdd6a0b7516f9b4faecd6b57a.zip chromium_src-86ea7b1013fc49cbdd6a0b7516f9b4faecd6b57a.tar.gz chromium_src-86ea7b1013fc49cbdd6a0b7516f9b4faecd6b57a.tar.bz2 |
Fold Pipeline::Init() into Pipeline::Start().
Instead of having clients optionally call Init() (i.e., player_x11, player_wtl) they are forced to pass null callbacks into Start().
Review URL: https://chromiumcodereview.appspot.com/9269022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119723 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | media/base/pipeline.cc | 21 | ||||
-rw-r--r-- | media/base/pipeline.h | 31 | ||||
-rw-r--r-- | media/base/pipeline_unittest.cc | 42 | ||||
-rw-r--r-- | media/filters/pipeline_integration_test.cc | 14 | ||||
-rw-r--r-- | media/tools/player_wtl/movie.cc | 8 | ||||
-rw-r--r-- | media/tools/player_x11/player_x11.cc | 5 | ||||
-rw-r--r-- | webkit/media/webmediaplayer_impl.cc | 10 |
7 files changed, 71 insertions, 60 deletions
diff --git a/media/base/pipeline.cc b/media/base/pipeline.cc index 7995796..fb84f2c 100644 --- a/media/base/pipeline.cc +++ b/media/base/pipeline.cc @@ -86,18 +86,11 @@ Pipeline::~Pipeline() { media_log_->CreateEvent(MediaLogEvent::PIPELINE_DESTROYED)); } -void Pipeline::Init(const PipelineStatusCB& ended_callback, - const PipelineStatusCB& error_callback, - const NetworkEventCB& network_callback) { - DCHECK(!IsRunning()) - << "Init() should be called before the pipeline has started"; - ended_callback_ = ended_callback; - error_callback_ = error_callback; - network_callback_ = network_callback; -} - void Pipeline::Start(scoped_ptr<FilterCollection> collection, const std::string& url, + const PipelineStatusCB& ended_callback, + const PipelineStatusCB& error_callback, + const NetworkEventCB& network_callback, const PipelineStatusCB& start_callback) { base::AutoLock auto_lock(lock_); CHECK(!running_) << "Media pipeline is already running"; @@ -105,7 +98,7 @@ void Pipeline::Start(scoped_ptr<FilterCollection> collection, running_ = true; message_loop_->PostTask(FROM_HERE, base::Bind( &Pipeline::StartTask, this, base::Passed(&collection), - url, start_callback)); + url, ended_callback, error_callback, network_callback, start_callback)); } void Pipeline::Stop(const PipelineStatusCB& stop_callback) { @@ -606,11 +599,17 @@ void Pipeline::OnUpdateStatistics(const PipelineStatistics& stats) { void Pipeline::StartTask(scoped_ptr<FilterCollection> filter_collection, const std::string& url, + const PipelineStatusCB& ended_callback, + const PipelineStatusCB& error_callback, + const NetworkEventCB& network_callback, const PipelineStatusCB& start_callback) { DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK_EQ(kCreated, state_); filter_collection_ = filter_collection.Pass(); url_ = url; + ended_callback_ = ended_callback; + error_callback_ = error_callback; + network_callback_ = network_callback; seek_callback_ = start_callback; // Kick off initialization. diff --git a/media/base/pipeline.h b/media/base/pipeline.h index b4c8d9f..2e6318d 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -56,6 +56,10 @@ enum NetworkEvent { CAN_PLAY_THROUGH }; +// Callback that executes when a network event occurs. +// The parameter specifies the type of event that is being signalled. +typedef base::Callback<void(NetworkEvent)> NetworkEventCB; + // Adapter for using asynchronous Pipeline methods in code that wants to run // synchronously. To use, construct an instance of this class and pass the // |Callback()| to the Pipeline method requiring a callback. Then Wait() for @@ -125,20 +129,9 @@ class MEDIA_EXPORT Pipeline public FilterHost, public DemuxerHost { public: + // Constructs a media pipeline that will execute on |message_loop|. Pipeline(MessageLoop* message_loop, MediaLog* media_log); - // Callback that executes when a network event occurrs. - // The parameter specifies the type of event that is being signaled. - typedef base::Callback<void(NetworkEvent)> NetworkEventCB; - - // Initializes pipeline. - // |ended_callback| will be executed when the media reaches the end. - // |error_callback_| will be executed upon an error in the pipeline. - // |network_callback_| will be executed when there's a network event. - void Init(const PipelineStatusCB& ended_callback, - const PipelineStatusCB& error_callback, - const NetworkEventCB& network_callback); - // Build a pipeline to render the given URL using the given filter collection // to construct a filter chain. // @@ -146,11 +139,22 @@ class MEDIA_EXPORT Pipeline // either poll the IsInitialized() method (discouraged) or optionally pass in // |start_callback|, which will be executed when initialization completes. // + // The following permanent callbacks will be executed as follows: + // |ended_callback| will be executed whenever the media reaches the end. + // |error_callback_| will be executed whenever an error occurs. + // |network_callback_| will be executed whenever there's a network activity. + // + // These callbacks are only executed after Start() has been called and until + // Stop() has completed. + // // It is an error to call this method after the pipeline has already started. // // TODO(scherkus): remove IsInitialized() and force clients to use callbacks. void Start(scoped_ptr<FilterCollection> filter_collection, const std::string& url, + const PipelineStatusCB& ended_callback, + const PipelineStatusCB& error_callback, + const NetworkEventCB& network_callback, const PipelineStatusCB& start_callback); // Asynchronously stops the pipeline and resets it to an uninitialized state. @@ -359,6 +363,9 @@ class MEDIA_EXPORT Pipeline // message loop. void StartTask(scoped_ptr<FilterCollection> filter_collection, const std::string& url, + const PipelineStatusCB& ended_callback, + const PipelineStatusCB& error_callback, + const NetworkEventCB& network_callback, const PipelineStatusCB& start_callback); // InitializeTask() performs initialization in multiple passes. It is executed diff --git a/media/base/pipeline_unittest.cc b/media/base/pipeline_unittest.cc index 9980e2f..325431a 100644 --- a/media/base/pipeline_unittest.cc +++ b/media/base/pipeline_unittest.cc @@ -70,10 +70,6 @@ class PipelineTest : public ::testing::Test { public: PipelineTest() : pipeline_(new Pipeline(&message_loop_, new MediaLog())) { - pipeline_->Init( - base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), - base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), - Pipeline::NetworkEventCB()); mocks_.reset(new MockFilterCollection()); // InitializeDemuxer adds overriding expectations for expected non-NULL @@ -203,13 +199,13 @@ class PipelineTest : public ::testing::Test { // Expect an initialization callback. EXPECT_CALL(callbacks_, OnStart(start_status)); - pipeline_->Start(mocks_->filter_collection(true, - true, - true, - build_status).Pass(), - "", - base::Bind(&CallbackHelper::OnStart, - base::Unretained(&callbacks_))); + pipeline_->Start( + mocks_->filter_collection(true, true, true, build_status).Pass(), + "", + base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), + base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), + NetworkEventCB(), + base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); message_loop_.RunAllPending(); } @@ -318,13 +314,13 @@ TEST_F(PipelineTest, NeverInitializes) { // This test hangs during initialization by never calling // InitializationComplete(). StrictMock<> will ensure that the callback is // never executed. - pipeline_->Start(mocks_->filter_collection(false, - false, - true, - PIPELINE_OK).Pass(), - "", - base::Bind(&CallbackHelper::OnStart, - base::Unretained(&callbacks_))); + pipeline_->Start( + mocks_->filter_collection(false, false, true, PIPELINE_OK).Pass(), + "", + base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), + base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), + NetworkEventCB(), + base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); message_loop_.RunAllPending(); EXPECT_FALSE(pipeline_->IsInitialized()); @@ -347,9 +343,13 @@ TEST_F(PipelineTest, RequiredFilterMissing) { // Create a filter collection with missing filter. scoped_ptr<FilterCollection> collection(mocks_->filter_collection( false, true, true, PIPELINE_ERROR_REQUIRED_FILTER_MISSING)); - pipeline_->Start(collection.Pass(), "", - base::Bind(&CallbackHelper::OnStart, - base::Unretained(&callbacks_))); + pipeline_->Start( + collection.Pass(), + "", + base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), + base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), + NetworkEventCB(), + base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); message_loop_.RunAllPending(); EXPECT_FALSE(pipeline_->IsInitialized()); diff --git a/media/filters/pipeline_integration_test.cc b/media/filters/pipeline_integration_test.cc index b64ed09..37d92c1 100644 --- a/media/filters/pipeline_integration_test.cc +++ b/media/filters/pipeline_integration_test.cc @@ -37,11 +37,6 @@ class PipelineIntegrationTest : public testing::Test { : message_loop_factory_(new MessageLoopFactoryImpl()), pipeline_(new Pipeline(&message_loop_, new MediaLog())), ended_(false) { - pipeline_->Init( - base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), - base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), - Pipeline::NetworkEventCB()); - EXPECT_CALL(*this, OnVideoRendererPaint()).Times(AnyNumber()); EXPECT_CALL(*this, OnSetOpaque(true)); } @@ -82,8 +77,13 @@ class PipelineIntegrationTest : public testing::Test { MOCK_METHOD1(OnError, void(PipelineStatus)); void Start(const std::string& url, PipelineStatus expected_status) { - pipeline_->Start(CreateFilterCollection(url), url, - QuitOnStatusCB(expected_status)); + pipeline_->Start( + CreateFilterCollection(url), + url, + base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), + base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), + NetworkEventCB(), + QuitOnStatusCB(expected_status)); message_loop_.Run(); } diff --git a/media/tools/player_wtl/movie.cc b/media/tools/player_wtl/movie.cc index fcecd5f..4e44cfc 100644 --- a/media/tools/player_wtl/movie.cc +++ b/media/tools/player_wtl/movie.cc @@ -96,7 +96,13 @@ bool Movie::Open(const wchar_t* url, VideoRendererBase* video_renderer) { // Create and start our pipeline. media::PipelineStatusNotification note; - pipeline_->Start(collection.Pass(), url_utf8, note.Callback()); + pipeline_->Start( + collection.Pass(), + url_utf8, + media::PipelineStatusCB(), + media::PipelineStatusCB(), + media::NetworkEventCB(), + note.Callback()); // Wait until the pipeline is fully initialized. note.Wait(); diff --git a/media/tools/player_x11/player_x11.cc b/media/tools/player_x11/player_x11.cc index ef4f126..a90ede5 100644 --- a/media/tools/player_x11/player_x11.cc +++ b/media/tools/player_x11/player_x11.cc @@ -142,7 +142,10 @@ bool InitPipeline(MessageLoop* message_loop, // Create the pipeline and start it. *pipeline = new media::Pipeline(message_loop, new media::MediaLog()); media::PipelineStatusNotification note; - (*pipeline)->Start(collection.Pass(), filename, note.Callback()); + (*pipeline)->Start( + collection.Pass(), filename, media::PipelineStatusCB(), + media::PipelineStatusCB(), media::NetworkEventCB(), + note.Callback()); // Wait until the pipeline is fully initialized. note.Wait(); diff --git a/webkit/media/webmediaplayer_impl.cc b/webkit/media/webmediaplayer_impl.cc index 011e630..da28423 100644 --- a/webkit/media/webmediaplayer_impl.cc +++ b/webkit/media/webmediaplayer_impl.cc @@ -128,13 +128,6 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( message_loop_factory_->GetMessageLoop("PipelineThread"); CHECK(pipeline_message_loop) << "Failed to create a new thread"; pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_); - pipeline_->Init( - base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, - proxy_.get()), - base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, - proxy_.get()), - base::Bind(&WebMediaPlayerProxy::NetworkEventCallback, - proxy_.get())); // Let V8 know we started new thread if we did not did it yet. // Made separate task to avoid deletion of player currently being created. @@ -837,6 +830,9 @@ void WebMediaPlayerImpl::StartPipeline(const GURL& gurl) { pipeline_->Start( filter_collection_.Pass(), gurl.spec(), + base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), + base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), + base::Bind(&WebMediaPlayerProxy::NetworkEventCallback, proxy_.get()), base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, proxy_.get())); } |