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 AddFilter(MediaFilter* filter); | 22 void AddDataSource(DataSource* 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); |
23 | 28 |
24 // Is the collection empty? | 29 // Is the collection empty? |
25 bool IsEmpty() const; | 30 bool IsEmpty() const; |
26 | 31 |
27 // Remove remaining filters. | 32 // Remove remaining filters. |
28 void Clear(); | 33 void Clear(); |
29 | 34 |
30 // Selects a filter of the specified type from the collection. | 35 // Selects a filter of the specified type from the collection. |
31 // If the required filter cannot be found, NULL is returned. | 36 // If the required filter cannot be found, NULL is returned. |
32 // If a filter is returned it is removed from the collection. | 37 // If a filter is returned it is removed from the collection. |
33 template <class Filter> | 38 void SelectDataSource(scoped_refptr<DataSource>* filter_out); |
34 void SelectFilter(scoped_refptr<Filter>* filter_out) { | 39 void SelectDemuxer(scoped_refptr<Demuxer>* filter_out); |
35 scoped_refptr<MediaFilter> filter; | 40 void SelectVideoDecoder(scoped_refptr<VideoDecoder>* filter_out); |
36 SelectFilter(Filter::static_filter_type(), &filter); | 41 void SelectAudioDecoder(scoped_refptr<AudioDecoder>* filter_out); |
37 *filter_out = reinterpret_cast<Filter*>(filter.get()); | 42 void SelectVideoRenderer(scoped_refptr<VideoRenderer>* filter_out); |
38 } | 43 void SelectAudioRenderer(scoped_refptr<AudioRenderer>* filter_out); |
39 | 44 |
40 private: | 45 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 |
41 // List of filters managed by this collection. | 58 // List of filters managed by this collection. |
42 std::list<scoped_refptr<MediaFilter> > filters_; | 59 typedef std::pair<FilterType, scoped_refptr<MediaFilter> > FilterListElement; |
| 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); |
43 | 70 |
44 // Helper function that searches the filters list for a specific | 71 // Helper function that searches the filters list for a specific |
45 // filter type. | 72 // filter type. |
46 void SelectFilter(FilterType filter_type, | 73 void SelectFilter(FilterType filter_type, |
47 scoped_refptr<MediaFilter>* filter_out); | 74 scoped_refptr<MediaFilter>* filter_out); |
48 | 75 |
49 DISALLOW_COPY_AND_ASSIGN(MediaFilterCollection); | 76 DISALLOW_COPY_AND_ASSIGN(MediaFilterCollection); |
50 }; | 77 }; |
51 | 78 |
52 } // namespace media | 79 } // namespace media |
53 | 80 |
54 #endif // MEDIA_BASE_MEDIA_FILTER_COLLECTION_H_ | 81 #endif // MEDIA_BASE_MEDIA_FILTER_COLLECTION_H_ |
OLD | NEW |