diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-15 18:48:54 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-15 18:48:54 +0000 |
commit | bf5604e21324c32393afa9754d37106d432bc8a7 (patch) | |
tree | fefe898402437a56c091a2261dd99aaa1609e333 /media | |
parent | 675960006c65bd69ae927ac22fcd6a04f5f3dd15 (diff) | |
download | chromium_src-bf5604e21324c32393afa9754d37106d432bc8a7.zip chromium_src-bf5604e21324c32393afa9754d37106d432bc8a7.tar.gz chromium_src-bf5604e21324c32393afa9754d37106d432bc8a7.tar.bz2 |
Revert 66125 -- Broke Windows build - Move FilterType into MediaFilterCollection
MediaFilterCollection is the only code that uses FilterType now so
I'm moving the enum into that class and removing all references from
the MediaFilter & derived classes.
BUG=61823
TEST=No new functionality. Existing tests pass.
Review URL: http://codereview.chromium.org/4653005
TBR=acolwell@chromium.org
Review URL: http://codereview.chromium.org/4991003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66139 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/filters.cc | 24 | ||||
-rw-r--r-- | media/base/filters.h | 34 | ||||
-rw-r--r-- | media/base/media_filter_collection.cc | 71 | ||||
-rw-r--r-- | media/base/media_filter_collection.h | 43 | ||||
-rw-r--r-- | media/base/media_filter_collection_unittest.cc | 36 | ||||
-rw-r--r-- | media/base/mock_filters.h | 12 | ||||
-rw-r--r-- | media/base/pipeline_impl.cc | 12 | ||||
-rw-r--r-- | media/filters/decoder_base_unittest.cc | 4 | ||||
-rw-r--r-- | media/tools/player_x11/player_x11.cc | 18 |
9 files changed, 113 insertions, 141 deletions
diff --git a/media/base/filters.cc b/media/base/filters.cc index 100af78..0773b89 100644 --- a/media/base/filters.cc +++ b/media/base/filters.cc @@ -93,6 +93,14 @@ bool DataSource::IsUrlSupported(const std::string& url) { return true; } +FilterType DataSource::filter_type() const { + return static_filter_type(); +} + +FilterType Demuxer::filter_type() const { + return static_filter_type(); +} + bool Demuxer::requires_message_loop() const { return true; } @@ -101,6 +109,10 @@ const char* Demuxer::message_loop_name() const { return "DemuxerThread"; } +FilterType AudioDecoder::filter_type() const { + return static_filter_type(); +} + const char* AudioDecoder::major_mime_type() const { return mime_type::kMajorTypeAudio; } @@ -113,10 +125,18 @@ const char* AudioDecoder::message_loop_name() const { return "AudioDecoderThread"; } +FilterType AudioRenderer::filter_type() const { + return static_filter_type(); +} + const char* AudioRenderer::major_mime_type() const { return mime_type::kMajorTypeAudio; } +FilterType VideoDecoder::filter_type() const { + return static_filter_type(); +} + const char* VideoDecoder::major_mime_type() const { return mime_type::kMajorTypeVideo; } @@ -129,6 +149,10 @@ const char* VideoDecoder::message_loop_name() const { return "VideoDecoderThread"; } +FilterType VideoRenderer::filter_type() const { + return static_filter_type(); +} + const char* VideoRenderer::major_mime_type() const { return mime_type::kMajorTypeVideo; } diff --git a/media/base/filters.h b/media/base/filters.h index 8c3d757..bec7d39 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -43,6 +43,18 @@ class DemuxerStream; class FilterHost; class MediaFilter; +// Identifies the type of filter implementation. Each filter has to be one of +// the following types. This is used to identify filter object during +// initialization of pipeline. +enum FilterType { + FILTER_DATA_SOURCE, + FILTER_DEMUXER, + FILTER_AUDIO_DECODER, + FILTER_VIDEO_DECODER, + FILTER_AUDIO_RENDERER, + FILTER_VIDEO_RENDERER +}; + // Used for completing asynchronous methods. typedef Callback0::Type FilterCallback; @@ -50,6 +62,10 @@ class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { public: MediaFilter(); + // Return the type of this filter. All implementor has to provide this + // method. + virtual FilterType filter_type() const = 0; + // Return the major mime type for this filter. virtual const char* major_mime_type() const; @@ -130,6 +146,9 @@ class DataSource : public MediaFilter { virtual bool IsUrlSupported(const std::string& url); + static FilterType static_filter_type() { return FILTER_DATA_SOURCE; } + virtual FilterType filter_type() const; + // Initialize a DataSource for the given URL, executing the callback upon // completion. virtual void Initialize(const std::string& url, FilterCallback* callback) = 0; @@ -154,6 +173,9 @@ class DataSource : public MediaFilter { class Demuxer : public MediaFilter { public: + static FilterType static_filter_type() { return FILTER_DEMUXER; } + virtual FilterType filter_type() const; + virtual bool requires_message_loop() const; virtual const char* message_loop_name() const; @@ -210,6 +232,9 @@ class DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> { class VideoDecoder : public MediaFilter { public: + static FilterType static_filter_type() { return FILTER_VIDEO_DECODER; } + virtual FilterType filter_type() const; + virtual const char* major_mime_type() const; virtual bool requires_message_loop() const; virtual const char* message_loop_name() const; @@ -255,6 +280,9 @@ class VideoDecoder : public MediaFilter { class AudioDecoder : public MediaFilter { public: + static FilterType static_filter_type() { return FILTER_AUDIO_DECODER; } + virtual FilterType filter_type() const; + virtual const char* major_mime_type() const; virtual bool requires_message_loop() const; virtual const char* message_loop_name() const; @@ -294,6 +322,9 @@ class AudioDecoder : public MediaFilter { class VideoRenderer : public MediaFilter { public: + static FilterType static_filter_type() { return FILTER_VIDEO_RENDERER; } + virtual FilterType filter_type() const; + virtual const char* major_mime_type() const; // Initialize a VideoRenderer with the given VideoDecoder, executing the @@ -308,6 +339,9 @@ class VideoRenderer : public MediaFilter { class AudioRenderer : public MediaFilter { public: + static FilterType static_filter_type() { return FILTER_AUDIO_RENDERER; } + virtual FilterType filter_type() const; + virtual const char* major_mime_type() const; // Initialize a AudioRenderer with the given AudioDecoder, executing the diff --git a/media/base/media_filter_collection.cc b/media/base/media_filter_collection.cc index a1380c4..2c90412 100644 --- a/media/base/media_filter_collection.cc +++ b/media/base/media_filter_collection.cc @@ -9,28 +9,8 @@ namespace media { MediaFilterCollection::MediaFilterCollection() { } -void MediaFilterCollection::AddDataSource(DataSource* filter) { - AddFilter(DATA_SOURCE, filter); -} - -void MediaFilterCollection::AddDemuxer(Demuxer* filter) { - AddFilter(DEMUXER, filter); -} - -void MediaFilterCollection::AddVideoDecoder(VideoDecoder* filter) { - AddFilter(VIDEO_DECODER, filter); -} - -void MediaFilterCollection::AddAudioDecoder(AudioDecoder* filter) { - AddFilter(AUDIO_DECODER, filter); -} - -void MediaFilterCollection::AddVideoRenderer(VideoRenderer* filter) { - AddFilter(VIDEO_RENDERER, filter); -} - -void MediaFilterCollection::AddAudioRenderer(AudioRenderer* filter) { - AddFilter(AUDIO_RENDERER, filter); +void MediaFilterCollection::AddFilter(MediaFilter* filter) { + filters_.push_back(filter); } bool MediaFilterCollection::IsEmpty() const { @@ -41,60 +21,19 @@ void MediaFilterCollection::Clear() { filters_.clear(); } -void MediaFilterCollection::SelectDataSource( - scoped_refptr<DataSource>* filter_out) { - SelectFilter<DATA_SOURCE>(filter_out); -} - -void MediaFilterCollection::SelectDemuxer(scoped_refptr<Demuxer>* filter_out) { - SelectFilter<DEMUXER>(filter_out); -} - -void MediaFilterCollection::SelectVideoDecoder( - scoped_refptr<VideoDecoder>* filter_out) { - SelectFilter<VIDEO_DECODER>(filter_out); -} - -void MediaFilterCollection::SelectAudioDecoder( - scoped_refptr<AudioDecoder>* filter_out) { - SelectFilter<AUDIO_DECODER>(filter_out); -} - -void MediaFilterCollection::SelectVideoRenderer( - scoped_refptr<VideoRenderer>* filter_out) { - SelectFilter<VIDEO_RENDERER>(filter_out); -} - -void MediaFilterCollection::SelectAudioRenderer( - scoped_refptr<AudioRenderer>* filter_out) { - SelectFilter<AUDIO_RENDERER>(filter_out); -} - -void MediaFilterCollection::AddFilter(FilterType filter_type, - MediaFilter* filter) { - filters_.push_back(FilterListElement(filter_type, filter)); -} - -template<MediaFilterCollection::FilterType filter_type, class Filter> -void MediaFilterCollection::SelectFilter(scoped_refptr<Filter>* filter_out) { - scoped_refptr<MediaFilter> filter; - SelectFilter(filter_type, &filter); - *filter_out = reinterpret_cast<Filter*>(filter.get()); -} - void MediaFilterCollection::SelectFilter( FilterType filter_type, scoped_refptr<MediaFilter>* filter_out) { - FilterList::iterator it = filters_.begin(); + std::list<scoped_refptr<MediaFilter> >::iterator it = filters_.begin(); while (it != filters_.end()) { - if (it->first == filter_type) + if ((*it)->filter_type() == filter_type) break; ++it; } if (it != filters_.end()) { - *filter_out = it->second.get(); + *filter_out = it->get(); filters_.erase(it); } } diff --git a/media/base/media_filter_collection.h b/media/base/media_filter_collection.h index c4a403a..31ea69c 100644 --- a/media/base/media_filter_collection.h +++ b/media/base/media_filter_collection.h @@ -19,12 +19,7 @@ class MediaFilterCollection { MediaFilterCollection(); // Adds a filter to the collection. - void AddDataSource(DataSource* filter); - void AddDemuxer(Demuxer* filter); - void AddVideoDecoder(VideoDecoder* filter); - void AddAudioDecoder(AudioDecoder* filter); - void AddVideoRenderer(VideoRenderer* filter); - void AddAudioRenderer(AudioRenderer* filter); + void AddFilter(MediaFilter* filter); // Is the collection empty? bool IsEmpty() const; @@ -35,38 +30,16 @@ class MediaFilterCollection { // Selects a filter of the specified type from the collection. // If the required filter cannot be found, NULL is returned. // If a filter is returned it is removed from the collection. - void SelectDataSource(scoped_refptr<DataSource>* filter_out); - void SelectDemuxer(scoped_refptr<Demuxer>* filter_out); - void SelectVideoDecoder(scoped_refptr<VideoDecoder>* filter_out); - void SelectAudioDecoder(scoped_refptr<AudioDecoder>* filter_out); - void SelectVideoRenderer(scoped_refptr<VideoRenderer>* filter_out); - void SelectAudioRenderer(scoped_refptr<AudioRenderer>* filter_out); + template <class Filter> + void SelectFilter(scoped_refptr<Filter>* filter_out) { + scoped_refptr<MediaFilter> filter; + SelectFilter(Filter::static_filter_type(), &filter); + *filter_out = reinterpret_cast<Filter*>(filter.get()); + } private: - // Identifies the type of filter implementation. Each filter has to be one of - // the following types. This is used to mark, identify, and support - // downcasting of different filter types stored in the filters_ list. - enum FilterType { - DATA_SOURCE, - DEMUXER, - AUDIO_DECODER, - VIDEO_DECODER, - AUDIO_RENDERER, - VIDEO_RENDERER - }; - // List of filters managed by this collection. - typedef std::pair<FilterType, scoped_refptr<MediaFilter> > FilterListElement; - typedef std::list<FilterListElement> FilterList; - FilterList filters_; - - // Helper function that adds a filter to the filter list. - void AddFilter(FilterType filter_type, MediaFilter* filter); - - // Helper function for SelectXXX() methods. It manages the - // downcasting and mapping between FilterType and Filter class. - template<FilterType filter_type, class Filter> - void SelectFilter(scoped_refptr<Filter>* filter_out); + std::list<scoped_refptr<MediaFilter> > filters_; // Helper function that searches the filters list for a specific // filter type. diff --git a/media/base/media_filter_collection_unittest.cc b/media/base/media_filter_collection_unittest.cc index 523123b..d974b4f 100644 --- a/media/base/media_filter_collection_unittest.cc +++ b/media/base/media_filter_collection_unittest.cc @@ -23,7 +23,7 @@ class MediaFilterCollectionTest : public ::testing::Test { TEST_F(MediaFilterCollectionTest, TestIsEmptyAndClear) { EXPECT_TRUE(collection_.IsEmpty()); - collection_.AddDataSource(mock_filters_.data_source()); + collection_.AddFilter(mock_filters_.data_source()); EXPECT_FALSE(collection_.IsEmpty()); @@ -32,41 +32,41 @@ TEST_F(MediaFilterCollectionTest, TestIsEmptyAndClear) { EXPECT_TRUE(collection_.IsEmpty()); } -TEST_F(MediaFilterCollectionTest, SelectXXXMethods) { +TEST_F(MediaFilterCollectionTest, SelectFilter) { scoped_refptr<AudioDecoder> audio_decoder; scoped_refptr<DataSource> data_source; - collection_.AddDataSource(mock_filters_.data_source()); + collection_.AddFilter(mock_filters_.data_source()); EXPECT_FALSE(collection_.IsEmpty()); // Verify that the data source will not be returned if we // ask for a different type. - collection_.SelectAudioDecoder(&audio_decoder); + collection_.SelectFilter(&audio_decoder); EXPECT_FALSE(audio_decoder); EXPECT_FALSE(collection_.IsEmpty()); // Verify that we can actually retrieve the data source // and that it is removed from the collection. - collection_.SelectDataSource(&data_source); + collection_.SelectFilter(&data_source); EXPECT_TRUE(data_source); EXPECT_TRUE(collection_.IsEmpty()); // Add a data source and audio decoder. - collection_.AddDataSource(mock_filters_.data_source()); - collection_.AddAudioDecoder(mock_filters_.audio_decoder()); + collection_.AddFilter(mock_filters_.data_source()); + collection_.AddFilter(mock_filters_.audio_decoder()); // Verify that we can select the audio decoder. - collection_.SelectAudioDecoder(&audio_decoder); + collection_.SelectFilter(&audio_decoder); EXPECT_TRUE(audio_decoder); EXPECT_FALSE(collection_.IsEmpty()); // Verify that we can't select it again since only one has been added. - collection_.SelectAudioDecoder(&audio_decoder); + collection_.SelectFilter(&audio_decoder); EXPECT_FALSE(audio_decoder); // Verify that we can select the data source and that doing so will // empty the collection again. - collection_.SelectDataSource(&data_source); + collection_.SelectFilter(&data_source); EXPECT_TRUE(collection_.IsEmpty()); } @@ -76,23 +76,23 @@ TEST_F(MediaFilterCollectionTest, MultipleFiltersOfSameType) { scoped_refptr<DataSource> data_source; - collection_.AddDataSource(data_source_a.get()); - collection_.AddDataSource(data_source_b.get()); + collection_.AddFilter(data_source_a.get()); + collection_.AddFilter(data_source_b.get()); - // Verify that first SelectDataSource() returns data_source_a. - collection_.SelectDataSource(&data_source); + // Verify that first SelectFilter() returns data_source_a. + collection_.SelectFilter(&data_source); EXPECT_TRUE(data_source); EXPECT_EQ(data_source, data_source_a); EXPECT_FALSE(collection_.IsEmpty()); - // Verify that second SelectDataSource() returns data_source_b. - collection_.SelectDataSource(&data_source); + // Verify that second SelectFilter() returns data_source_b. + collection_.SelectFilter(&data_source); EXPECT_TRUE(data_source); EXPECT_EQ(data_source, data_source_b); EXPECT_TRUE(collection_.IsEmpty()); - // Verify that third SelectDataSource() returns nothing. - collection_.SelectDataSource(&data_source); + // Verify that third SelectFilter returns nothing. + collection_.SelectFilter(&data_source); EXPECT_FALSE(data_source); } diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index af7c0c5..ba15293 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -293,13 +293,13 @@ class MockFilterCollection { MediaFilterCollection* collection = new MediaFilterCollection(); if (include_data_source) { - collection->AddDataSource(data_source_); + collection->AddFilter(data_source_); } - collection->AddDemuxer(demuxer_); - collection->AddVideoDecoder(video_decoder_); - collection->AddAudioDecoder(audio_decoder_); - collection->AddVideoRenderer(video_renderer_); - collection->AddAudioRenderer(audio_renderer_); + collection->AddFilter(demuxer_); + collection->AddFilter(video_decoder_); + collection->AddFilter(audio_decoder_); + collection->AddFilter(video_renderer_); + collection->AddFilter(audio_renderer_); return collection; } diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 7765cd0..7f17ff8 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -954,7 +954,7 @@ void PipelineImpl::InitializeDataSource() { scoped_refptr<DataSource> data_source; while (true) { - filter_collection_->SelectDataSource(&data_source); + filter_collection_->SelectFilter(&data_source); if (!data_source || data_source->IsUrlSupported(url_)) break; } @@ -979,7 +979,7 @@ void PipelineImpl::InitializeDemuxer( CHECK(data_source); - filter_collection_->SelectDemuxer(&demuxer); + filter_collection_->SelectFilter(&demuxer); if (!demuxer) { SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); return; @@ -1001,7 +1001,7 @@ bool PipelineImpl::InitializeAudioDecoder( if (stream) { scoped_refptr<AudioDecoder> audio_decoder; - filter_collection_->SelectAudioDecoder(&audio_decoder); + filter_collection_->SelectFilter(&audio_decoder); if (audio_decoder) { PrepareFilter(audio_decoder); @@ -1028,7 +1028,7 @@ bool PipelineImpl::InitializeVideoDecoder( if (stream) { scoped_refptr<VideoDecoder> video_decoder; - filter_collection_->SelectVideoDecoder(&video_decoder); + filter_collection_->SelectFilter(&video_decoder); if (video_decoder) { PrepareFilter(video_decoder); @@ -1050,7 +1050,7 @@ bool PipelineImpl::InitializeAudioRenderer( DCHECK(IsPipelineOk()); if (decoder) { - filter_collection_->SelectAudioRenderer(&audio_renderer_); + filter_collection_->SelectFilter(&audio_renderer_); if (audio_renderer_) { PrepareFilter(audio_renderer_); @@ -1070,7 +1070,7 @@ bool PipelineImpl::InitializeVideoRenderer( DCHECK(IsPipelineOk()); if (decoder) { - filter_collection_->SelectVideoRenderer(&video_renderer_); + filter_collection_->SelectFilter(&video_renderer_); if (video_renderer_) { PrepareFilter(video_renderer_); diff --git a/media/filters/decoder_base_unittest.cc b/media/filters/decoder_base_unittest.cc index 410077c..d280895 100644 --- a/media/filters/decoder_base_unittest.cc +++ b/media/filters/decoder_base_unittest.cc @@ -67,6 +67,10 @@ class MockDecoderImpl : public media::DecoderBase< virtual ~MockDecoderImpl() {} + virtual media::FilterType filter_type() const { + return media::FILTER_VIDEO_DECODER; + } + // DecoderBase Implementations. MOCK_METHOD3(DoInitialize, void(media::DemuxerStream* demuxer_stream, diff --git a/media/tools/player_x11/player_x11.cc b/media/tools/player_x11/player_x11.cc index ffff1bd..ad307c4 100644 --- a/media/tools/player_x11/player_x11.cc +++ b/media/tools/player_x11/player_x11.cc @@ -99,23 +99,21 @@ bool InitPipeline(MessageLoop* message_loop, // Create our filter factories. scoped_ptr<media::MediaFilterCollection> collection( new media::MediaFilterCollection()); - collection->AddDataSource(new media::FileDataSource()); - collection->AddDemuxer(new media::FFmpegDemuxer()); - collection->AddAudioDecoder(new media::FFmpegAudioDecoder()); + collection->AddFilter(new media::FileDataSource()); + collection->AddFilter(new media::FFmpegDemuxer()); + collection->AddFilter(new media::FFmpegAudioDecoder()); if (CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableOpenMax)) { - collection->AddVideoDecoder(new media::OmxVideoDecoder(NULL)); + collection->AddFilter(new media::OmxVideoDecoder(NULL)); } else { - collection->AddVideoDecoder(new media::FFmpegVideoDecoder(NULL)); + collection->AddFilter(new media::FFmpegVideoDecoder(NULL)); } - collection->AddVideoRenderer(new Renderer(g_display, - g_window, - paint_message_loop)); + collection->AddFilter(new Renderer(g_display, g_window, paint_message_loop)); if (enable_audio) - collection->AddAudioRenderer(new media::AudioRendererImpl()); + collection->AddFilter(new media::AudioRendererImpl()); else - collection->AddAudioRenderer(new media::NullAudioRenderer()); + collection->AddFilter(new media::NullAudioRenderer()); // Creates the pipeline and start it. *pipeline = new media::PipelineImpl(message_loop); |