| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BASE_MEDIA_FILTER_COLLECTION_H_ | 5 #ifndef MEDIA_BASE_MEDIA_FILTER_COLLECTION_H_ |
| 6 #define MEDIA_BASE_MEDIA_FILTER_COLLECTION_H_ | 6 #define MEDIA_BASE_MEDIA_FILTER_COLLECTION_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 11 #include "media/base/filters.h" | 11 #include "media/base/filters.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 // This is a collection of MediaFilter objects used to form a media playback | 15 // This is a collection of MediaFilter objects used to form a media playback |
| 16 // pipeline. See src/media/base/pipeline.h for more information. | 16 // pipeline. See src/media/base/pipeline.h for more information. |
| 17 class MediaFilterCollection { | 17 class MediaFilterCollection { |
| 18 public: | 18 public: |
| 19 MediaFilterCollection(); | 19 MediaFilterCollection(); |
| 20 | 20 |
| 21 // Adds a filter to the collection. | 21 // Adds a filter to the collection. |
| 22 void AddDataSource(DataSource* filter); | 22 void AddFilter(MediaFilter* filter); |
| 23 void AddDemuxer(Demuxer* filter); | |
| 24 void AddVideoDecoder(VideoDecoder* filter); | |
| 25 void AddAudioDecoder(AudioDecoder* filter); | |
| 26 void AddVideoRenderer(VideoRenderer* filter); | |
| 27 void AddAudioRenderer(AudioRenderer* filter); | |
| 28 | 23 |
| 29 // Is the collection empty? | 24 // Is the collection empty? |
| 30 bool IsEmpty() const; | 25 bool IsEmpty() const; |
| 31 | 26 |
| 32 // Remove remaining filters. | 27 // Remove remaining filters. |
| 33 void Clear(); | 28 void Clear(); |
| 34 | 29 |
| 35 // Selects a filter of the specified type from the collection. | 30 // Selects a filter of the specified type from the collection. |
| 36 // If the required filter cannot be found, NULL is returned. | 31 // If the required filter cannot be found, NULL is returned. |
| 37 // If a filter is returned it is removed from the collection. | 32 // If a filter is returned it is removed from the collection. |
| 38 void SelectDataSource(scoped_refptr<DataSource>* filter_out); | 33 template <class Filter> |
| 39 void SelectDemuxer(scoped_refptr<Demuxer>* filter_out); | 34 void SelectFilter(scoped_refptr<Filter>* filter_out) { |
| 40 void SelectVideoDecoder(scoped_refptr<VideoDecoder>* filter_out); | 35 scoped_refptr<MediaFilter> filter; |
| 41 void SelectAudioDecoder(scoped_refptr<AudioDecoder>* filter_out); | 36 SelectFilter(Filter::static_filter_type(), &filter); |
| 42 void SelectVideoRenderer(scoped_refptr<VideoRenderer>* filter_out); | 37 *filter_out = reinterpret_cast<Filter*>(filter.get()); |
| 43 void SelectAudioRenderer(scoped_refptr<AudioRenderer>* filter_out); | 38 } |
| 44 | 39 |
| 45 private: | 40 private: |
| 46 // Identifies the type of filter implementation. Each filter has to be one of | |
| 47 // the following types. This is used to mark, identify, and support | |
| 48 // downcasting of different filter types stored in the filters_ list. | |
| 49 enum FilterType { | |
| 50 DATA_SOURCE, | |
| 51 DEMUXER, | |
| 52 AUDIO_DECODER, | |
| 53 VIDEO_DECODER, | |
| 54 AUDIO_RENDERER, | |
| 55 VIDEO_RENDERER | |
| 56 }; | |
| 57 | |
| 58 // List of filters managed by this collection. | 41 // List of filters managed by this collection. |
| 59 typedef std::pair<FilterType, scoped_refptr<MediaFilter> > FilterListElement; | 42 std::list<scoped_refptr<MediaFilter> > filters_; |
| 60 typedef std::list<FilterListElement> FilterList; | |
| 61 FilterList filters_; | |
| 62 | |
| 63 // Helper function that adds a filter to the filter list. | |
| 64 void AddFilter(FilterType filter_type, MediaFilter* filter); | |
| 65 | |
| 66 // Helper function for SelectXXX() methods. It manages the | |
| 67 // downcasting and mapping between FilterType and Filter class. | |
| 68 template<FilterType filter_type, class Filter> | |
| 69 void SelectFilter(scoped_refptr<Filter>* filter_out); | |
| 70 | 43 |
| 71 // Helper function that searches the filters list for a specific | 44 // Helper function that searches the filters list for a specific |
| 72 // filter type. | 45 // filter type. |
| 73 void SelectFilter(FilterType filter_type, | 46 void SelectFilter(FilterType filter_type, |
| 74 scoped_refptr<MediaFilter>* filter_out); | 47 scoped_refptr<MediaFilter>* filter_out); |
| 75 | 48 |
| 76 DISALLOW_COPY_AND_ASSIGN(MediaFilterCollection); | 49 DISALLOW_COPY_AND_ASSIGN(MediaFilterCollection); |
| 77 }; | 50 }; |
| 78 | 51 |
| 79 } // namespace media | 52 } // namespace media |
| 80 | 53 |
| 81 #endif // MEDIA_BASE_MEDIA_FILTER_COLLECTION_H_ | 54 #endif // MEDIA_BASE_MEDIA_FILTER_COLLECTION_H_ |
| OLD | NEW |