OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 // A filter factory handles the creation of filters given a FilterType (i.e., | 5 // A filter factory handles the creation of filters given a FilterType (i.e., |
6 // FILTER_AUDIO_DECODER) and a MediaFormat. Generally a filter factory handles | 6 // FILTER_AUDIO_DECODER) and a MediaFormat. Generally a filter factory handles |
7 // creating a single type of filter, with multiple factories combined into a | 7 // creating a single type of filter, with multiple factories combined into a |
8 // FilterFactoryCollection. We use some template tricks to enforce type-safety | 8 // FilterFactoryCollection. We use some template tricks to enforce type-safety |
9 // and eliminate casting for callers. | 9 // and eliminate casting for callers. |
10 // | 10 // |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // Attempt to create a filter of the given type using the information stored | 60 // Attempt to create a filter of the given type using the information stored |
61 // in |media_format|. If successful, the filter is returned. If the filter | 61 // in |media_format|. If successful, the filter is returned. If the filter |
62 // cannot be created for any reason, NULL is returned. | 62 // cannot be created for any reason, NULL is returned. |
63 // | 63 // |
64 // It is assumed that the MediaFilter interface can be safely cast to the | 64 // It is assumed that the MediaFilter interface can be safely cast to the |
65 // corresponding interface type (i.e., FILTER_AUDIO_DECODER -> AudioDecoder). | 65 // corresponding interface type (i.e., FILTER_AUDIO_DECODER -> AudioDecoder). |
66 virtual MediaFilter* Create(FilterType filter_type, | 66 virtual MediaFilter* Create(FilterType filter_type, |
67 const MediaFormat& media_format) = 0; | 67 const MediaFormat& media_format) = 0; |
68 | 68 |
69 friend class base::RefCountedThreadSafe<FilterFactory>; | 69 friend class base::RefCountedThreadSafe<FilterFactory>; |
70 virtual ~FilterFactory() {} | 70 FilterFactory(); |
| 71 virtual ~FilterFactory(); |
71 }; | 72 }; |
72 | 73 |
73 | 74 |
74 // Maintains a collection of FilterFactories. | 75 // Maintains a collection of FilterFactories. |
75 class FilterFactoryCollection : public FilterFactory { | 76 class FilterFactoryCollection : public FilterFactory { |
76 public: | 77 public: |
77 FilterFactoryCollection() {} | 78 FilterFactoryCollection(); |
78 | 79 |
79 // Adds a factory to the end of the collection. | 80 // Adds a factory to the end of the collection. |
80 void AddFactory(FilterFactory* factory) { | 81 void AddFactory(FilterFactory* factory); |
81 factories_.push_back(factory); | |
82 } | |
83 | 82 |
84 protected: | 83 protected: |
85 // Attempts to create a filter by walking down the list of filter factories. | 84 // Attempts to create a filter by walking down the list of filter factories. |
86 MediaFilter* Create(FilterType filter_type, const MediaFormat& media_format) { | 85 MediaFilter* Create(FilterType filter_type, const MediaFormat& media_format); |
87 MediaFilter* filter = NULL; | |
88 for (FactoryVector::iterator factory = factories_.begin(); | |
89 !filter && factory != factories_.end(); | |
90 ++factory) { | |
91 filter = (*factory)->Create(filter_type, media_format); | |
92 } | |
93 return filter; | |
94 } | |
95 | 86 |
96 private: | 87 private: |
97 ~FilterFactoryCollection() {} | 88 ~FilterFactoryCollection(); |
98 | 89 |
99 typedef std::vector< scoped_refptr<FilterFactory> > FactoryVector; | 90 typedef std::vector< scoped_refptr<FilterFactory> > FactoryVector; |
100 FactoryVector factories_; | 91 FactoryVector factories_; |
101 | 92 |
102 DISALLOW_COPY_AND_ASSIGN(FilterFactoryCollection); | 93 DISALLOW_COPY_AND_ASSIGN(FilterFactoryCollection); |
103 }; | 94 }; |
104 | 95 |
105 //----------------------------------------------------------------------------- | 96 //----------------------------------------------------------------------------- |
106 | 97 |
107 // This template is used by classes to implement a type-safe filter factory. | 98 // This template is used by classes to implement a type-safe filter factory. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 244 |
254 scoped_refptr<Filter> filter_; | 245 scoped_refptr<Filter> filter_; |
255 bool create_called_; | 246 bool create_called_; |
256 | 247 |
257 DISALLOW_COPY_AND_ASSIGN(InstanceFilterFactory); | 248 DISALLOW_COPY_AND_ASSIGN(InstanceFilterFactory); |
258 }; | 249 }; |
259 | 250 |
260 } // namespace media | 251 } // namespace media |
261 | 252 |
262 #endif // MEDIA_BASE_FACTORY_H_ | 253 #endif // MEDIA_BASE_FACTORY_H_ |
OLD | NEW |