diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 23:57:23 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 23:57:23 +0000 |
commit | cea25d5216c226cfc55c56ccff3e9626878b7c80 (patch) | |
tree | 1414b9588743b478c867b96c4f0a1dde34bc9412 /media | |
parent | db99c1b50a8b39899e425a4860cfa03348a68795 (diff) | |
download | chromium_src-cea25d5216c226cfc55c56ccff3e9626878b7c80.zip chromium_src-cea25d5216c226cfc55c56ccff3e9626878b7c80.tar.gz chromium_src-cea25d5216c226cfc55c56ccff3e9626878b7c80.tar.bz2 |
Made MediaFilter::host_ and MediaFilter::message_loop_ private.
More cleanup relating to pipeline cleanup.
BUG=16008
TEST=no real code chage, nothing should change
Review URL: http://codereview.chromium.org/155230
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20338 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/filters.h | 19 | ||||
-rw-r--r-- | media/base/mock_media_filters.h | 20 | ||||
-rw-r--r-- | media/base/pipeline_impl.cc | 4 | ||||
-rw-r--r-- | media/filters/audio_renderer_base.cc | 6 | ||||
-rw-r--r-- | media/filters/decoder_base.h | 20 | ||||
-rw-r--r-- | media/filters/ffmpeg_audio_decoder.cc | 4 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer.cc | 20 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer_unittest.cc | 4 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder.cc | 2 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder_unittest.cc | 4 | ||||
-rw-r--r-- | media/filters/file_data_source.cc | 8 | ||||
-rw-r--r-- | media/filters/file_data_source_unittest.cc | 4 | ||||
-rw-r--r-- | media/filters/video_renderer_base.cc | 8 |
13 files changed, 62 insertions, 61 deletions
diff --git a/media/base/filters.h b/media/base/filters.h index bc94d39..9fd1b2e 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -58,26 +58,34 @@ class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { public: MediaFilter() : host_(NULL), message_loop_(NULL) {} - // Sets the protected member |host_|. This is the first method called by + // Sets the private member |host_|. This is the first method called by // the FilterHost after a filter is created. The host holds a strong // reference to the filter. The reference held by the host is guaranteed // to be released before the host object is destroyed by the pipeline. - virtual void SetFilterHost(FilterHost* host) { + virtual void set_host(FilterHost* host) { DCHECK(host); DCHECK(!host_); host_ = host; } - // Sets the protected member |message_loop_|, which is used by filters for + virtual FilterHost* host() { + return host_; + } + + // Sets the private member |message_loop_|, which is used by filters for // processing asynchronous tasks and maintaining synchronized access to // internal data members. The message loop should be running and exceed the // lifetime of the filter. - virtual void SetMessageLoop(MessageLoop* message_loop) { + virtual void set_message_loop(MessageLoop* message_loop) { DCHECK(message_loop); DCHECK(!message_loop_); message_loop_ = message_loop; } + virtual MessageLoop* message_loop() { + return message_loop_; + } + // The pipeline is being stopped either as a result of an error or because // the client called Stop(). virtual void Stop() = 0; @@ -95,11 +103,10 @@ class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { friend class base::RefCountedThreadSafe<MediaFilter>; virtual ~MediaFilter() {} - // TODO(scherkus): make these private with public/protected accessors. + private: FilterHost* host_; MessageLoop* message_loop_; - private: DISALLOW_COPY_AND_ASSIGN(MediaFilter); }; diff --git a/media/base/mock_media_filters.h b/media/base/mock_media_filters.h index b8749d9..698815f 100644 --- a/media/base/mock_media_filters.h +++ b/media/base/mock_media_filters.h @@ -105,15 +105,15 @@ class MockDataSource : public DataSource { media_format_.SetAsString(MediaFormat::kMimeType, mime_type::kApplicationOctetStream); media_format_.SetAsString(MediaFormat::kURL, url); - host_->SetTotalBytes(config_->media_total_bytes); + host()->SetTotalBytes(config_->media_total_bytes); switch (config_->data_source_behavior) { case MOCK_DATA_SOURCE_NORMAL_INIT: - host_->InitializationComplete(); + host()->InitializationComplete(); return true; case MOCK_DATA_SOURCE_NEVER_INIT: return true; case MOCK_DATA_SOURCE_URL_ERROR_IN_INIT: - host_->Error(PIPELINE_ERROR_URL_NOT_FOUND); + host()->Error(PIPELINE_ERROR_URL_NOT_FOUND); return false; case MOCK_DATA_SOURCE_INIT_RETURN_FALSE: return false; @@ -234,7 +234,7 @@ class MockDemuxer : public Demuxer { // Implementation of Demuxer. virtual bool Initialize(DataSource* data_source) { - host_->InitializationComplete(); + host()->InitializationComplete(); return true; } @@ -299,7 +299,7 @@ class MockAudioDecoder : public AudioDecoder { // Implementation of AudioDecoder. virtual bool Initialize(DemuxerStream* stream) { - host_->InitializationComplete(); + host()->InitializationComplete(); return true; } @@ -338,7 +338,7 @@ class MockAudioRenderer : public AudioRenderer { // Implementation of AudioRenderer. virtual bool Initialize(AudioDecoder* decoder) { - host_->InitializationComplete(); + host()->InitializationComplete(); return true; } @@ -404,7 +404,7 @@ class MockVideoDecoder : public VideoDecoder { // Implementation of VideoDecoder. virtual bool Initialize(DemuxerStream* stream) { - host_->InitializationComplete(); + host()->InitializationComplete(); return true; } @@ -436,7 +436,7 @@ class MockVideoDecoder : public VideoDecoder { config_->frame_duration, &frame); if (!frame) { - host_->Error(PIPELINE_ERROR_OUT_OF_MEMORY); + host()->Error(PIPELINE_ERROR_OUT_OF_MEMORY); ADD_FAILURE(); } else { mock_frame_time_ += config_->frame_duration; @@ -475,8 +475,8 @@ class MockVideoRenderer : public VideoRenderer { // Implementation of VideoRenderer. virtual bool Initialize(VideoDecoder* decoder) { - host_->SetVideoSize(config_->video_width, config_->video_height); - host_->InitializationComplete(); + host()->SetVideoSize(config_->video_width, config_->video_height); + host()->InitializationComplete(); return true; } diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index e9edc4f..56a71a6 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -604,7 +604,7 @@ void PipelineThread::CreateFilter(FilterFactory* filter_factory, NOTREACHED() << "Could not start filter thread"; Error(PIPELINE_ERROR_INITIALIZATION_FAILED); } else { - filter->SetMessageLoop(thread->message_loop()); + filter->set_message_loop(thread->message_loop()); filter_threads_.push_back(thread.release()); } } @@ -612,7 +612,7 @@ void PipelineThread::CreateFilter(FilterFactory* filter_factory, // Creating a thread could have failed, verify we're still OK. if (IsPipelineOk()) { filter_hosts_.push_back(host.get()); - filter->SetFilterHost(host.release()); + filter->set_host(host.release()); if (!filter->Initialize(source)) { Error(PIPELINE_ERROR_INITIALIZATION_FAILED); } diff --git a/media/filters/audio_renderer_base.cc b/media/filters/audio_renderer_base.cc index 43f79ca..ba52fe0 100644 --- a/media/filters/audio_renderer_base.cc +++ b/media/filters/audio_renderer_base.cc @@ -89,10 +89,10 @@ void AudioRendererBase::OnReadComplete(Buffer* buffer_in) { if (queue_.empty()) { // If we say we have initialized but buffer queue is empty, raise an // error. - host_->Error(PIPELINE_ERROR_NO_DATA); + host()->Error(PIPELINE_ERROR_NO_DATA); } else { initialized_ = true; - host_->InitializationComplete(); + host()->InitializationComplete(); } } } @@ -210,7 +210,7 @@ size_t AudioRendererBase::FillBuffer(uint8* dest, // finer time update events. if (playback_delay < last_fill_buffer_time) last_fill_buffer_time -= playback_delay; - host_->SetTime(last_fill_buffer_time); + host()->SetTime(last_fill_buffer_time); } return dest_written; diff --git a/media/filters/decoder_base.h b/media/filters/decoder_base.h index b36a9b8..a4ed764 100644 --- a/media/filters/decoder_base.h +++ b/media/filters/decoder_base.h @@ -26,18 +26,18 @@ class DecoderBase : public Decoder { // MediaFilter implementation. virtual void Stop() { - message_loop()->PostTask(FROM_HERE, + this->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &DecoderBase::StopTask)); } virtual void Seek(base::TimeDelta time) { - message_loop()->PostTask(FROM_HERE, + this->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &DecoderBase::SeekTask, time)); } // Decoder implementation. virtual bool Initialize(DemuxerStream* demuxer_stream) { - message_loop()->PostTask(FROM_HERE, + this->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &DecoderBase::InitializeTask, demuxer_stream)); return true; } @@ -46,7 +46,7 @@ class DecoderBase : public Decoder { // Audio or video decoder. virtual void Read(ReadCallback* read_callback) { - message_loop()->PostTask(FROM_HERE, + this->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &DecoderBase::ReadTask, read_callback)); } @@ -57,7 +57,7 @@ class DecoderBase : public Decoder { // TODO(scherkus): change the callback format to pass a scoped_refptr<> or // better yet see if we can get away with not using reference counting. scoped_refptr<Buffer> buffer_ref = buffer; - message_loop()->PostTask(FROM_HERE, + this->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &DecoderBase::ReadCompleteTask, buffer_ref)); } @@ -116,12 +116,6 @@ class DecoderBase : public Decoder { MediaFormat media_format_; private: - // GCC doesn't let us access superclass member variables directly, so use - // a helper to get around the situation. - // - // TODO(scherkus): another reason to add protected accessors to MediaFilter. - FilterHost* host() const { return Decoder::host_; } - MessageLoop* message_loop() const { return Decoder::message_loop_; } bool IsStopped() { return state_ == STOPPED; } void StopTask() { @@ -159,14 +153,14 @@ class DecoderBase : public Decoder { // Delegate to subclass first. if (!OnInitialize(demuxer_stream_)) { - host()->Error(PIPELINE_ERROR_DECODE); + this->host()->Error(PIPELINE_ERROR_DECODE); return; } // TODO(scherkus): subclass shouldn't mutate superclass media format. DCHECK(!media_format_.empty()) << "Subclass did not set media_format_"; state_ = INITIALIZED; - host()->InitializationComplete(); + this->host()->InitializationComplete(); } void ReadTask(ReadCallback* read_callback) { diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index 12e7be8..5d9e3c1 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -67,7 +67,7 @@ bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) { // Prepare the output buffer. output_buffer_.reset(static_cast<uint8*>(av_malloc(kOutputBufferSize))); if (!output_buffer_.get()) { - host_->Error(PIPELINE_ERROR_OUT_OF_MEMORY); + host()->Error(PIPELINE_ERROR_OUT_OF_MEMORY); return false; } return true; @@ -101,7 +101,7 @@ void FFmpegAudioDecoder::OnDecode(Buffer* input) { if (result < 0 || output_buffer_size < 0 || static_cast<size_t>(output_buffer_size) > kOutputBufferSize) { - host_->Error(PIPELINE_ERROR_DECODE); + host()->Error(PIPELINE_ERROR_DECODE); return; } diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc index 00a2fbd..c12e0ad 100644 --- a/media/filters/ffmpeg_demuxer.cc +++ b/media/filters/ffmpeg_demuxer.cc @@ -156,7 +156,7 @@ const MediaFormat& FFmpegDemuxerStream::media_format() { void FFmpegDemuxerStream::Read(Callback1<Buffer*>::Type* read_callback) { DCHECK(read_callback); - demuxer_->message_loop_->PostTask(FROM_HERE, + demuxer_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &FFmpegDemuxerStream::ReadTask, read_callback)); } @@ -252,13 +252,13 @@ FFmpegDemuxer::~FFmpegDemuxer() { } void FFmpegDemuxer::PostDemuxTask() { - message_loop_->PostTask(FROM_HERE, + message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &FFmpegDemuxer::DemuxTask)); } void FFmpegDemuxer::Stop() { // Post a task to notify the streams to stop as well. - message_loop_->PostTask(FROM_HERE, + message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &FFmpegDemuxer::StopTask)); } @@ -267,12 +267,12 @@ void FFmpegDemuxer::Seek(base::TimeDelta time) { // operation is completed and filters behind the demuxer is good to issue // more reads, but we are posting a task here, which makes the seek operation // asynchronous, should change how seek works to make it fully asynchronous. - message_loop_->PostTask(FROM_HERE, + message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &FFmpegDemuxer::SeekTask, time)); } bool FFmpegDemuxer::Initialize(DataSource* data_source) { - message_loop_->PostTask(FROM_HERE, + message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &FFmpegDemuxer::InititalizeTask, data_source)); return true; } @@ -313,7 +313,7 @@ void FFmpegDemuxer::InititalizeTask(DataSource* data_source) { FFmpegGlue::get()->RemoveDataSource(data_source); if (result < 0) { - host_->Error(DEMUXER_ERROR_COULD_NOT_OPEN); + host()->Error(DEMUXER_ERROR_COULD_NOT_OPEN); return; } @@ -327,7 +327,7 @@ void FFmpegDemuxer::InititalizeTask(DataSource* data_source) { // Fully initialize AVFormatContext by parsing the stream a little. result = av_find_stream_info(format_context_); if (result < 0) { - host_->Error(DEMUXER_ERROR_COULD_NOT_PARSE); + host()->Error(DEMUXER_ERROR_COULD_NOT_PARSE); return; } } @@ -349,13 +349,13 @@ void FFmpegDemuxer::InititalizeTask(DataSource* data_source) { } } if (streams_.empty()) { - host_->Error(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); + host()->Error(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); return; } // Good to go: set the duration and notify we're done initializing. - host_->SetDuration(max_duration); - host_->InitializationComplete(); + host()->SetDuration(max_duration); + host()->InitializationComplete(); } void FFmpegDemuxer::SeekTask(base::TimeDelta time) { diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc index dc21c49..43b14c7 100644 --- a/media/filters/ffmpeg_demuxer_unittest.cc +++ b/media/filters/ffmpeg_demuxer_unittest.cc @@ -67,8 +67,8 @@ class FFmpegDemuxerTest : public testing::Test { DCHECK(demuxer_); // Inject a filter host and message loop and prepare a data source. - demuxer_->SetFilterHost(&host_); - demuxer_->SetMessageLoop(&message_loop_); + demuxer_->set_host(&host_); + demuxer_->set_message_loop(&message_loop_); data_source_ = new StrictMock<MockDataSource>(); // Initialize FFmpeg fixtures. diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc index 6423db4..c396c00 100644 --- a/media/filters/ffmpeg_video_decoder.cc +++ b/media/filters/ffmpeg_video_decoder.cc @@ -337,7 +337,7 @@ VideoSurface::Format FFmpegVideoDecoder::GetSurfaceFormat( } void FFmpegVideoDecoder::SignalPipelineError() { - host_->Error(PIPELINE_ERROR_DECODE); + host()->Error(PIPELINE_ERROR_DECODE); state_ = kDecodeFinished; } diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index fca238e..6603b58 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -79,8 +79,8 @@ class FFmpegVideoDecoderTest : public testing::Test { DCHECK(decoder_); // Inject a filter host and message loop and prepare a demuxer stream. - decoder_->SetFilterHost(&host_); - decoder_->SetMessageLoop(&message_loop_); + decoder_->set_host(&host_); + decoder_->set_message_loop(&message_loop_); demuxer_ = new StrictMock<MockFFmpegDemuxerStream>(); // Manually set the thread id for tests that don't initialize the decoder. diff --git a/media/filters/file_data_source.cc b/media/filters/file_data_source.cc index bdab8fb..2e13a59 100644 --- a/media/filters/file_data_source.cc +++ b/media/filters/file_data_source.cc @@ -32,15 +32,15 @@ bool FileDataSource::Initialize(const std::string& url) { } if (!file_) { file_size_ = 0; - host_->Error(PIPELINE_ERROR_URL_NOT_FOUND); + host()->Error(PIPELINE_ERROR_URL_NOT_FOUND); return false; } media_format_.SetAsString(MediaFormat::kMimeType, mime_type::kApplicationOctetStream); media_format_.SetAsString(MediaFormat::kURL, url); - host_->SetTotalBytes(file_size_); - host_->SetBufferedBytes(file_size_); - host_->InitializationComplete(); + host()->SetTotalBytes(file_size_); + host()->SetBufferedBytes(file_size_); + host()->InitializationComplete(); return true; } diff --git a/media/filters/file_data_source_unittest.cc b/media/filters/file_data_source_unittest.cc index 5b9157a..dd41e88 100644 --- a/media/filters/file_data_source_unittest.cc +++ b/media/filters/file_data_source_unittest.cc @@ -43,7 +43,7 @@ TEST(FileDataSourceTest, OpenFile) { EXPECT_CALL(host, InitializationComplete()); scoped_refptr<FileDataSource> filter = new FileDataSource(); - filter->SetFilterHost(&host); + filter->set_host(&host); EXPECT_TRUE(filter->Initialize(TestFileURL())); } @@ -56,7 +56,7 @@ TEST(FileDataSourceTest, ReadData) { // Create our mock filter host and initialize the data source. NiceMock<MockFilterHost> host; scoped_refptr<FileDataSource> filter = new FileDataSource(); - filter->SetFilterHost(&host); + filter->set_host(&host); EXPECT_TRUE(filter->Initialize(TestFileURL())); EXPECT_TRUE(filter->GetSize(&size)); diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc index 094c92a..7eace6f 100644 --- a/media/filters/video_renderer_base.cc +++ b/media/filters/video_renderer_base.cc @@ -104,7 +104,7 @@ bool VideoRendererBase::Initialize(VideoDecoder* decoder) { int height = 0; if (!ParseMediaFormat(decoder->media_format(), &width, &height)) return false; - host_->SetVideoSize(width, height); + host()->SetVideoSize(width, height); // Initialize the subclass. // TODO(scherkus): do we trust subclasses not to do something silly while @@ -188,7 +188,7 @@ void VideoRendererBase::ThreadMain() { OnFrameAvailable(); // Determine the current and next presentation timestamps. - base::TimeDelta now = host_->GetTime(); + base::TimeDelta now = host()->GetTime(); base::TimeDelta this_pts = current_frame_->GetTimestamp(); base::TimeDelta next_pts; if (next_frame) { @@ -248,11 +248,11 @@ void VideoRendererBase::OnReadComplete(VideoFrame* frame) { if (frames_.empty()) { // We should have initialized but there's no decoded frames in the queue. // Raise an error. - host_->Error(PIPELINE_ERROR_NO_DATA); + host()->Error(PIPELINE_ERROR_NO_DATA); } else { state_ = INITIALIZED; current_frame_ = frames_.front(); - host_->InitializationComplete(); + host()->InitializationComplete(); } } } |