Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: media/base/factory.h

Issue 18546: Implementation of Pipeline and FilterHost interfaces. This is a large change... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/thread_unittest.cc ('k') | media/base/filter_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 matching lines...) Expand all
40 class FilterFactoryCollection; 40 class FilterFactoryCollection;
41 41
42 class FilterFactory : public base::RefCountedThreadSafe<FilterFactory> { 42 class FilterFactory : public base::RefCountedThreadSafe<FilterFactory> {
43 public: 43 public:
44 // Creates a filter implementing the specified interface. Hides the casting 44 // Creates a filter implementing the specified interface. Hides the casting
45 // and FilterType constants from the callers and produces cleaner code: 45 // and FilterType constants from the callers and produces cleaner code:
46 // AudioDecoder* filter = NULL; 46 // AudioDecoder* filter = NULL;
47 // bool success = Create<AudioDecoder>(media_format, &filter); 47 // bool success = Create<AudioDecoder>(media_format, &filter);
48 template <class T> 48 template <class T>
49 bool Create(const MediaFormat* media_format, T** filter_out) { 49 bool Create(const MediaFormat* media_format, T** filter_out) {
50 return Create(T::kFilterType, media_format, 50 return Create(T::filter_type(), media_format,
51 reinterpret_cast<MediaFilter**>(filter_out)); 51 reinterpret_cast<MediaFilter**>(filter_out));
52 } 52 }
53 53
54 protected: 54 protected:
55 // For accessing the protected version of Create. 55 // For accessing the protected version of Create.
56 friend class FilterFactoryCollection; 56 friend class FilterFactoryCollection;
57 57
58 // Attempt to create a filter of the given type using the information stored 58 // Attempt to create a filter of the given type using the information stored
59 // in |media_format|. If successful, the filter is assigned to |filter_out| 59 // in |media_format|. If successful, the filter is assigned to |filter_out|
60 // and the method returns true. If the filter cannot be created for any 60 // and the method returns true. If the filter cannot be created for any
61 // reason, |filter_out| is assigned NULL and false it returned. 61 // reason, |filter_out| is assigned NULL and false it returned.
62 // 62 //
63 // It is assumed that |filter_out| can be safely casted to the corresponding 63 // It is assumed that |filter_out| can be safely casted to the corresponding
64 // interface type (i.e., FILTER_AUDIO_DECODER -> AudioDecoder). 64 // interface type (i.e., FILTER_AUDIO_DECODER -> AudioDecoder).
65 virtual bool Create(FilterType filter_type, const MediaFormat* media_format, 65 virtual bool Create(FilterType filter_type, const MediaFormat* media_format,
66 MediaFilter** filter_out) = 0; 66 MediaFilter** filter_out) = 0;
67 67
68 friend class base::RefCountedThreadSafe<FilterFactory>; 68 friend class base::RefCountedThreadSafe<FilterFactory>;
69 virtual ~FilterFactory() {} 69 virtual ~FilterFactory() {}
70 }; 70 };
71 71
72 72
73 // Helper template class for implementing trivial filter factories. If your 73 // Helper template class for implementing trivial filter factories. If your
74 // filter does not require any special handling during creation, you can create 74 // filter does not require any special handling during creation, you can create
75 // a factory for it using this class. It requires the following static method: 75 // a factory for it using this class. It requires the following static method:
76 // bool Create(MediaFormat* media_format, YourFilterType** filter_out) 76 // bool Create(MediaFormat* media_format, YourFilterType** filter_out)
77 // 77 //
78 // You can create the filter factory like so: 78 // You can create the filter factory like so:
79 // new TypeFilterFactory<YourFilterType>() 79 // new TypeFilterFactory<YourFilterType>()
80 template <class T> 80 template <class Filter>
81 class TypeFilterFactory : public FilterFactory { 81 class TypeFilterFactory : public FilterFactory {
82 public: 82 public:
83 TypeFilterFactory() {} 83 TypeFilterFactory() {}
84 84
85 protected: 85 protected:
86 // Attempts to create a filter of the template type. Assumes a static method 86 // Attempts to create a filter of the template type. Assumes a static method
87 // Create is declared. 87 // Create is declared.
88 virtual bool Create(FilterType filter_type, const MediaFormat* media_format, 88 virtual bool Create(FilterType filter_type, const MediaFormat* media_format,
89 MediaFilter** filter_out) { 89 MediaFilter** filter_out) {
90 T* typed_out; 90 Filter* filter;
91 if (T::kFilterType == filter_type && T::Create(media_format, &typed_out)) { 91 if (Filter::filter_type() == filter_type &&
92 *filter_out = typed_out; 92 Filter::Create(media_format, &filter)) {
93 *filter_out = filter;
93 return true; 94 return true;
94 } 95 }
95 return false; 96 return false;
96 } 97 }
97 98
98 private: 99 private:
99 DISALLOW_COPY_AND_ASSIGN(TypeFilterFactory); 100 DISALLOW_COPY_AND_ASSIGN(TypeFilterFactory);
100 }; 101 };
101 102
102 103
(...skipping 24 matching lines...) Expand all
127 private: 128 private:
128 typedef std::vector< scoped_refptr<FilterFactory> > FactoryVector; 129 typedef std::vector< scoped_refptr<FilterFactory> > FactoryVector;
129 FactoryVector factories_; 130 FactoryVector factories_;
130 131
131 DISALLOW_COPY_AND_ASSIGN(FilterFactoryCollection); 132 DISALLOW_COPY_AND_ASSIGN(FilterFactoryCollection);
132 }; 133 };
133 134
134 } // namespace media 135 } // namespace media
135 136
136 #endif // MEDIA_BASE_FACTORY_H_ 137 #endif // MEDIA_BASE_FACTORY_H_
OLDNEW
« no previous file with comments | « base/thread_unittest.cc ('k') | media/base/filter_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698