diff options
-rw-r--r-- | media/base/pipeline.h | 4 | ||||
-rw-r--r-- | media/base/pipeline_impl.h | 2 | ||||
-rw-r--r-- | media/base/pipeline_impl_unittest.cc | 130 | ||||
-rw-r--r-- | media/player/movie.cc | 20 | ||||
-rw-r--r-- | media/player/movie.h | 2 | ||||
-rw-r--r-- | webkit/glue/webmediaplayer_impl.cc | 2 | ||||
-rw-r--r-- | webkit/glue/webmediaplayer_impl.h | 2 |
7 files changed, 82 insertions, 80 deletions
diff --git a/media/base/pipeline.h b/media/base/pipeline.h index 83e30ef..58de36b 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -48,7 +48,7 @@ enum PipelineError { // inspect the Pipeline for errors. typedef Callback0::Type PipelineCallback; -class Pipeline { +class Pipeline : public base::RefCountedThreadSafe<Pipeline> { public: // Build a pipeline to render the given URL using the given filter factory to // construct a filter chain. Returns true if successful, false otherwise @@ -153,6 +153,8 @@ class Pipeline { virtual PipelineError GetError() const = 0; protected: + // Only allow ourselves to be deleted by reference counting. + friend class base::RefCountedThreadSafe<Pipeline>; virtual ~Pipeline() {} }; diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index 6b97c94..3efcbe4 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -30,7 +30,6 @@ class PipelineInternal; class PipelineImpl : public Pipeline { public: PipelineImpl(MessageLoop* message_loop); - virtual ~PipelineImpl(); // Pipeline implementation. virtual bool Start(FilterFactory* filter_factory, @@ -56,6 +55,7 @@ class PipelineImpl : public Pipeline { private: friend class FilterHostImpl; friend class PipelineInternal; + virtual ~PipelineImpl(); // Reset the state of the pipeline object to the initial state. This method // is used by the constructor, and the Stop method. diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index c3e63e5..9fe3654 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -46,19 +46,19 @@ class CallbackHelper { class PipelineImplTest : public ::testing::Test { public: PipelineImplTest() - : pipeline_(&message_loop_), + : pipeline_(new PipelineImpl(&message_loop_)), mocks_(new MockFilterFactory()) { } virtual ~PipelineImplTest() { - if (!pipeline_.IsRunning()) { + if (!pipeline_->IsRunning()) { return; } // Expect a stop callback if we were started. EXPECT_CALL(callbacks_, OnStop()); - pipeline_.Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), - &CallbackHelper::OnStop)); + pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), + &CallbackHelper::OnStop)); message_loop_.RunAllPending(); } @@ -130,16 +130,16 @@ class PipelineImplTest : public ::testing::Test { void InitializePipeline() { // Expect an initialization callback. EXPECT_CALL(callbacks_, OnStart()); - pipeline_.Start(mocks_, "", - NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), - &CallbackHelper::OnStart)); + pipeline_->Start(mocks_, "", + NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), + &CallbackHelper::OnStart)); message_loop_.RunAllPending(); } // Fixture members. StrictMock<CallbackHelper> callbacks_; MessageLoop message_loop_; - PipelineImpl pipeline_; + scoped_refptr<PipelineImpl> pipeline_; scoped_refptr<media::MockFilterFactory> mocks_; private: @@ -153,50 +153,50 @@ TEST_F(PipelineImplTest, NotStarted) { // StrictMock<> will ensure these never get called, and valgrind/purify will // make sure the callbacks are instantly deleted. - pipeline_.Start(NULL, "", + pipeline_->Start(NULL, "", + NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), + &CallbackHelper::OnStart)); + pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), + &CallbackHelper::OnStop)); + pipeline_->Seek(kZero, NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), - &CallbackHelper::OnStart)); - pipeline_.Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), - &CallbackHelper::OnStop)); - pipeline_.Seek(kZero, - NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), - &CallbackHelper::OnSeek)); - - EXPECT_FALSE(pipeline_.IsRunning()); - EXPECT_FALSE(pipeline_.IsInitialized()); - EXPECT_FALSE(pipeline_.IsRendered("")); - EXPECT_FALSE(pipeline_.IsRendered(AudioDecoder::major_mime_type())); - EXPECT_FALSE(pipeline_.IsRendered(VideoDecoder::major_mime_type())); + &CallbackHelper::OnSeek)); + + EXPECT_FALSE(pipeline_->IsRunning()); + EXPECT_FALSE(pipeline_->IsInitialized()); + EXPECT_FALSE(pipeline_->IsRendered("")); + EXPECT_FALSE(pipeline_->IsRendered(AudioDecoder::major_mime_type())); + EXPECT_FALSE(pipeline_->IsRendered(VideoDecoder::major_mime_type())); // Setting should still work. - EXPECT_EQ(0.0f, pipeline_.GetPlaybackRate()); - pipeline_.SetPlaybackRate(-1.0f); - EXPECT_EQ(0.0f, pipeline_.GetPlaybackRate()); - pipeline_.SetPlaybackRate(1.0f); - EXPECT_EQ(1.0f, pipeline_.GetPlaybackRate()); + EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); + pipeline_->SetPlaybackRate(-1.0f); + EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); + pipeline_->SetPlaybackRate(1.0f); + EXPECT_EQ(1.0f, pipeline_->GetPlaybackRate()); // Setting should still work. - EXPECT_EQ(1.0f, pipeline_.GetVolume()); - pipeline_.SetVolume(-1.0f); - EXPECT_EQ(1.0f, pipeline_.GetVolume()); - pipeline_.SetVolume(0.0f); - EXPECT_EQ(0.0f, pipeline_.GetVolume()); + EXPECT_EQ(1.0f, pipeline_->GetVolume()); + pipeline_->SetVolume(-1.0f); + EXPECT_EQ(1.0f, pipeline_->GetVolume()); + pipeline_->SetVolume(0.0f); + EXPECT_EQ(0.0f, pipeline_->GetVolume()); - EXPECT_TRUE(kZero == pipeline_.GetCurrentTime()); - EXPECT_TRUE(kZero == pipeline_.GetBufferedTime()); - EXPECT_TRUE(kZero == pipeline_.GetDuration()); + EXPECT_TRUE(kZero == pipeline_->GetCurrentTime()); + EXPECT_TRUE(kZero == pipeline_->GetBufferedTime()); + EXPECT_TRUE(kZero == pipeline_->GetDuration()); - EXPECT_EQ(0, pipeline_.GetBufferedBytes()); - EXPECT_EQ(0, pipeline_.GetTotalBytes()); + EXPECT_EQ(0, pipeline_->GetBufferedBytes()); + EXPECT_EQ(0, pipeline_->GetTotalBytes()); // Should always get set to zero. size_t width = 1u; size_t height = 1u; - pipeline_.GetVideoSize(&width, &height); + pipeline_->GetVideoSize(&width, &height); EXPECT_EQ(0u, width); EXPECT_EQ(0u, height); - EXPECT_EQ(PIPELINE_OK, pipeline_.GetError()); + EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); } TEST_F(PipelineImplTest, NeverInitializes) { @@ -207,13 +207,13 @@ TEST_F(PipelineImplTest, NeverInitializes) { // This test hangs during initialization by never calling // InitializationComplete(). StrictMock<> will ensure that the callback is // never executed. - pipeline_.Start(mocks_, "", - NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), - &CallbackHelper::OnStart)); + pipeline_->Start(mocks_, "", + NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), + &CallbackHelper::OnStart)); message_loop_.RunAllPending(); - EXPECT_FALSE(pipeline_.IsInitialized()); - EXPECT_EQ(PIPELINE_OK, pipeline_.GetError()); + EXPECT_FALSE(pipeline_->IsInitialized()); + EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); // Because our callback will get executed when the test tears down, we'll // verify that nothing has been called, then set our expectation for the call @@ -226,9 +226,9 @@ TEST_F(PipelineImplTest, RequiredFilterMissing) { mocks_->set_creation_successful(false); InitializePipeline(); - EXPECT_FALSE(pipeline_.IsInitialized()); + EXPECT_FALSE(pipeline_->IsInitialized()); EXPECT_EQ(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, - pipeline_.GetError()); + pipeline_->GetError()); } TEST_F(PipelineImplTest, URLNotFound) { @@ -239,8 +239,8 @@ TEST_F(PipelineImplTest, URLNotFound) { EXPECT_CALL(*mocks_->data_source(), Stop()); InitializePipeline(); - EXPECT_FALSE(pipeline_.IsInitialized()); - EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_.GetError()); + EXPECT_FALSE(pipeline_->IsInitialized()); + EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); } TEST_F(PipelineImplTest, NoStreams) { @@ -257,8 +257,8 @@ TEST_F(PipelineImplTest, NoStreams) { EXPECT_CALL(*mocks_->demuxer(), Stop()); InitializePipeline(); - EXPECT_FALSE(pipeline_.IsInitialized()); - EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_.GetError()); + EXPECT_FALSE(pipeline_->IsInitialized()); + EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); } TEST_F(PipelineImplTest, AudioStream) { @@ -273,10 +273,10 @@ TEST_F(PipelineImplTest, AudioStream) { InitializeAudioRenderer(); InitializePipeline(); - EXPECT_TRUE(pipeline_.IsInitialized()); - EXPECT_EQ(PIPELINE_OK, pipeline_.GetError()); - EXPECT_TRUE(pipeline_.IsRendered(media::mime_type::kMajorTypeAudio)); - EXPECT_FALSE(pipeline_.IsRendered(media::mime_type::kMajorTypeVideo)); + EXPECT_TRUE(pipeline_->IsInitialized()); + EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); + EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); + EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); } TEST_F(PipelineImplTest, VideoStream) { @@ -291,10 +291,10 @@ TEST_F(PipelineImplTest, VideoStream) { InitializeVideoRenderer(); InitializePipeline(); - EXPECT_TRUE(pipeline_.IsInitialized()); - EXPECT_EQ(PIPELINE_OK, pipeline_.GetError()); - EXPECT_FALSE(pipeline_.IsRendered(media::mime_type::kMajorTypeAudio)); - EXPECT_TRUE(pipeline_.IsRendered(media::mime_type::kMajorTypeVideo)); + EXPECT_TRUE(pipeline_->IsInitialized()); + EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); + EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); + EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); } TEST_F(PipelineImplTest, AudioVideoStream) { @@ -314,10 +314,10 @@ TEST_F(PipelineImplTest, AudioVideoStream) { InitializeVideoRenderer(); InitializePipeline(); - EXPECT_TRUE(pipeline_.IsInitialized()); - EXPECT_EQ(PIPELINE_OK, pipeline_.GetError()); - EXPECT_TRUE(pipeline_.IsRendered(media::mime_type::kMajorTypeAudio)); - EXPECT_TRUE(pipeline_.IsRendered(media::mime_type::kMajorTypeVideo)); + EXPECT_TRUE(pipeline_->IsInitialized()); + EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); + EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); + EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); } TEST_F(PipelineImplTest, Seek) { @@ -356,9 +356,9 @@ TEST_F(PipelineImplTest, Seek) { // Initialize then seek! InitializePipeline(); - pipeline_.Seek(expected, - NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), - &CallbackHelper::OnSeek)); + pipeline_->Seek(expected, + NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), + &CallbackHelper::OnSeek)); message_loop_.RunAllPending(); } @@ -379,7 +379,7 @@ TEST_F(PipelineImplTest, SetVolume) { // Initialize then set volume! InitializePipeline(); - pipeline_.SetVolume(expected); + pipeline_->SetVolume(expected); } } // namespace media diff --git a/media/player/movie.cc b/media/player/movie.cc index 3554730..7f13f24 100644 --- a/media/player/movie.cc +++ b/media/player/movie.cc @@ -49,7 +49,7 @@ Movie::~Movie() { } bool Movie::IsOpen() { - return pipeline_.get() != NULL; + return pipeline_ != NULL; } void Movie::SetFrameBuffer(HBITMAP hbmp, HWND hwnd) { @@ -59,7 +59,7 @@ void Movie::SetFrameBuffer(HBITMAP hbmp, HWND hwnd) { bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { // Close previous movie. - if (pipeline_.get()) { + if (pipeline_) { Close(); } @@ -81,10 +81,10 @@ bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { thread_.reset(new base::Thread("PipelineThread")); thread_->Start(); - pipeline_.reset(new PipelineImpl(thread_->message_loop())); + pipeline_ = new PipelineImpl(thread_->message_loop()); // Create and start our pipeline. - pipeline_->Start(factories.get(), WideToUTF8(std::wstring(url)), NULL); + pipeline_->Start(factories, WideToUTF8(std::wstring(url)), NULL); while (true) { PlatformThread::Sleep(100); if (pipeline_->IsInitialized()) @@ -98,7 +98,7 @@ bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { void Movie::Play(float rate) { // Begin playback. - if (pipeline_.get()) + if (pipeline_) pipeline_->SetPlaybackRate(enable_pause_ ? 0.0f : rate); if (rate > 0.0f) play_rate_ = rate; @@ -112,7 +112,7 @@ float Movie::GetPlayRate() { // Get movie duration in seconds. float Movie::GetDuration() { float duration = 0.f; - if (pipeline_.get()) + if (pipeline_) duration = (pipeline_->GetDuration()).InMicroseconds() / 1000000.0f; return duration; } @@ -120,7 +120,7 @@ float Movie::GetDuration() { // Get current movie position in seconds. float Movie::GetPosition() { float position = 0.f; - if (pipeline_.get()) + if (pipeline_) position = (pipeline_->GetCurrentTime()).InMicroseconds() / 1000000.0f; return position; } @@ -129,7 +129,7 @@ float Movie::GetPosition() { void Movie::SetPosition(float position) { int64 us = static_cast<int64>(position * 1000000); base::TimeDelta time = base::TimeDelta::FromMicroseconds(us); - if (pipeline_.get()) + if (pipeline_) pipeline_->Seek(time, NULL); } @@ -195,10 +195,10 @@ bool Movie::GetOpenMpEnable() { // Teardown. void Movie::Close() { - if (pipeline_.get()) { + if (pipeline_) { pipeline_->Stop(NULL); thread_->Stop(); - pipeline_.reset(); + pipeline_ = NULL; thread_.reset(); } } diff --git a/media/player/movie.h b/media/player/movie.h index eb23822..ac8fba1 100644 --- a/media/player/movie.h +++ b/media/player/movie.h @@ -90,7 +90,7 @@ class Movie : public Singleton<Movie> { Movie(); virtual ~Movie(); - scoped_ptr<PipelineImpl> pipeline_; + scoped_refptr<PipelineImpl> pipeline_; scoped_ptr<base::Thread> thread_; bool enable_audio_; diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc index fad8825..d8bad19 100644 --- a/webkit/glue/webmediaplayer_impl.cc +++ b/webkit/glue/webmediaplayer_impl.cc @@ -139,7 +139,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(WebKit::WebMediaPlayerClient* client, if (!pipeline_thread_.Start()) { NOTREACHED() << "Could not start PipelineThread"; } else { - pipeline_.reset(new media::PipelineImpl(pipeline_thread_.message_loop())); + pipeline_ = new media::PipelineImpl(pipeline_thread_.message_loop()); } // Also we want to be notified of |main_loop_| destruction. diff --git a/webkit/glue/webmediaplayer_impl.h b/webkit/glue/webmediaplayer_impl.h index 5904023..3972653 100644 --- a/webkit/glue/webmediaplayer_impl.h +++ b/webkit/glue/webmediaplayer_impl.h @@ -237,7 +237,7 @@ class WebMediaPlayerImpl : public WebKit::WebMediaPlayer, scoped_refptr<media::FilterFactoryCollection> filter_factory_; // The actual pipeline and the thread it runs on. - scoped_ptr<media::PipelineImpl> pipeline_; + scoped_refptr<media::PipelineImpl> pipeline_; base::Thread pipeline_thread_; // Playback state. |