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 // Filters are connected in a strongly typed manner, with downstream filters | 5 // Filters are connected in a strongly typed manner, with downstream filters |
6 // always reading data from upstream filters. Upstream filters have no clue | 6 // always reading data from upstream filters. Upstream filters have no clue |
7 // who is actually reading from them, and return the results via callbacks. | 7 // who is actually reading from them, and return the results via callbacks. |
8 // | 8 // |
9 // DemuxerStream(Video) <- VideoDecoder <- VideoRenderer | 9 // DemuxerStream(Video) <- VideoDecoder <- VideoRenderer |
10 // DataSource <- Demuxer < | 10 // DataSource <- Demuxer < |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // knock off of MSVC's __uuidof() operator. | 46 // knock off of MSVC's __uuidof() operator. |
47 enum FilterType { | 47 enum FilterType { |
48 FILTER_DATA_SOURCE, | 48 FILTER_DATA_SOURCE, |
49 FILTER_DEMUXER, | 49 FILTER_DEMUXER, |
50 FILTER_AUDIO_DECODER, | 50 FILTER_AUDIO_DECODER, |
51 FILTER_VIDEO_DECODER, | 51 FILTER_VIDEO_DECODER, |
52 FILTER_AUDIO_RENDERER, | 52 FILTER_AUDIO_RENDERER, |
53 FILTER_VIDEO_RENDERER | 53 FILTER_VIDEO_RENDERER |
54 }; | 54 }; |
55 | 55 |
| 56 // Used for completing asynchronous methods. |
| 57 typedef Callback0::Type FilterCallback; |
56 | 58 |
57 class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { | 59 class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { |
58 public: | 60 public: |
59 MediaFilter() : host_(NULL), message_loop_(NULL) {} | 61 MediaFilter() : host_(NULL), message_loop_(NULL) {} |
60 | 62 |
61 // Sets the private member |host_|. This is the first method called by | 63 // Sets the private member |host_|. This is the first method called by |
62 // the FilterHost after a filter is created. The host holds a strong | 64 // the FilterHost after a filter is created. The host holds a strong |
63 // reference to the filter. The reference held by the host is guaranteed | 65 // reference to the filter. The reference held by the host is guaranteed |
64 // to be released before the host object is destroyed by the pipeline. | 66 // to be released before the host object is destroyed by the pipeline. |
65 virtual void set_host(FilterHost* host) { | 67 virtual void set_host(FilterHost* host) { |
(...skipping 21 matching lines...) Expand all Loading... |
87 } | 89 } |
88 | 90 |
89 // The pipeline is being stopped either as a result of an error or because | 91 // The pipeline is being stopped either as a result of an error or because |
90 // the client called Stop(). | 92 // the client called Stop(). |
91 virtual void Stop() = 0; | 93 virtual void Stop() = 0; |
92 | 94 |
93 // The pipeline playback rate has been changed. Filters may implement this | 95 // The pipeline playback rate has been changed. Filters may implement this |
94 // method if they need to respond to this call. | 96 // method if they need to respond to this call. |
95 virtual void SetPlaybackRate(float playback_rate) {} | 97 virtual void SetPlaybackRate(float playback_rate) {} |
96 | 98 |
97 // The pipeline is seeking to the specified time. Filters may implement | 99 // Carry out any actions required to seek to the given time, executing the |
98 // this method if they need to respond to this call. | 100 // callback upon completion. |
99 virtual void Seek(base::TimeDelta time) {} | 101 virtual void Seek(base::TimeDelta time, FilterCallback* callback) { |
| 102 scoped_ptr<FilterCallback> seek_callback(callback); |
| 103 if (seek_callback.get()) { |
| 104 seek_callback->Run(); |
| 105 } |
| 106 } |
100 | 107 |
101 protected: | 108 protected: |
102 // Only allow scoped_refptr<> to delete filters. | 109 // Only allow scoped_refptr<> to delete filters. |
103 friend class base::RefCountedThreadSafe<MediaFilter>; | 110 friend class base::RefCountedThreadSafe<MediaFilter>; |
104 virtual ~MediaFilter() {} | 111 virtual ~MediaFilter() {} |
105 | 112 |
106 FilterHost* host() const { return host_; } | 113 FilterHost* host() const { return host_; } |
107 MessageLoop* message_loop() const { return message_loop_; } | 114 MessageLoop* message_loop() const { return message_loop_; } |
108 | 115 |
109 private: | 116 private: |
(...skipping 11 matching lines...) Expand all Loading... |
121 } | 128 } |
122 | 129 |
123 static bool IsMediaFormatSupported(const MediaFormat& media_format) { | 130 static bool IsMediaFormatSupported(const MediaFormat& media_format) { |
124 std::string mime_type; | 131 std::string mime_type; |
125 return (media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && | 132 return (media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && |
126 mime_type == mime_type::kURL); | 133 mime_type == mime_type::kURL); |
127 } | 134 } |
128 | 135 |
129 static const size_t kReadError = static_cast<size_t>(-1); | 136 static const size_t kReadError = static_cast<size_t>(-1); |
130 | 137 |
131 // Initializes this filter, returns true if successful, false otherwise. | 138 // Initialize a DataSource for the given URL, executing the callback upon |
132 virtual bool Initialize(const std::string& url) = 0; | 139 // completion. |
| 140 virtual void Initialize(const std::string& url, FilterCallback* callback) = 0; |
133 | 141 |
134 // Returns the MediaFormat for this filter. | 142 // Returns the MediaFormat for this filter. |
135 virtual const MediaFormat& media_format() = 0; | 143 virtual const MediaFormat& media_format() = 0; |
136 | 144 |
137 // Read the given amount of bytes into data, returns the number of bytes read | 145 // Read the given amount of bytes into data, returns the number of bytes read |
138 // if successful, kReadError otherwise. | 146 // if successful, kReadError otherwise. |
139 virtual size_t Read(uint8* data, size_t size) = 0; | 147 virtual size_t Read(uint8* data, size_t size) = 0; |
140 | 148 |
141 // Returns true and the current file position for this file, false if the | 149 // Returns true and the current file position for this file, false if the |
142 // file position could not be retrieved. | 150 // file position could not be retrieved. |
(...skipping 16 matching lines...) Expand all Loading... |
159 static const FilterType filter_type() { | 167 static const FilterType filter_type() { |
160 return FILTER_DEMUXER; | 168 return FILTER_DEMUXER; |
161 } | 169 } |
162 | 170 |
163 static bool IsMediaFormatSupported(const MediaFormat& media_format) { | 171 static bool IsMediaFormatSupported(const MediaFormat& media_format) { |
164 std::string mime_type; | 172 std::string mime_type; |
165 return (media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && | 173 return (media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && |
166 mime_type == mime_type::kApplicationOctetStream); | 174 mime_type == mime_type::kApplicationOctetStream); |
167 } | 175 } |
168 | 176 |
169 // Initializes this filter, returns true if successful, false otherwise. | 177 // Initialize a Demuxer with the given DataSource, executing the callback upon |
170 virtual bool Initialize(DataSource* data_source) = 0; | 178 // completion. |
| 179 virtual void Initialize(DataSource* data_source, |
| 180 FilterCallback* callback) = 0; |
171 | 181 |
172 // Returns the number of streams available | 182 // Returns the number of streams available |
173 virtual size_t GetNumberOfStreams() = 0; | 183 virtual size_t GetNumberOfStreams() = 0; |
174 | 184 |
175 // Returns the stream for the given index, NULL otherwise | 185 // Returns the stream for the given index, NULL otherwise |
176 virtual scoped_refptr<DemuxerStream> GetStream(int stream_id) = 0; | 186 virtual scoped_refptr<DemuxerStream> GetStream(int stream_id) = 0; |
177 }; | 187 }; |
178 | 188 |
179 | 189 |
180 class DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> { | 190 class DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 class VideoDecoder : public MediaFilter { | 226 class VideoDecoder : public MediaFilter { |
217 public: | 227 public: |
218 static const FilterType filter_type() { | 228 static const FilterType filter_type() { |
219 return FILTER_VIDEO_DECODER; | 229 return FILTER_VIDEO_DECODER; |
220 } | 230 } |
221 | 231 |
222 static const char* major_mime_type() { | 232 static const char* major_mime_type() { |
223 return mime_type::kMajorTypeVideo; | 233 return mime_type::kMajorTypeVideo; |
224 } | 234 } |
225 | 235 |
226 // Initializes this filter, returns true if successful, false otherwise. | 236 // Initialize a VideoDecoder with the given DemuxerStream, executing the |
227 virtual bool Initialize(DemuxerStream* demuxer_stream) = 0; | 237 // callback upon completion. |
| 238 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; |
228 | 239 |
229 // Returns the MediaFormat for this filter. | 240 // Returns the MediaFormat for this filter. |
230 virtual const MediaFormat& media_format() = 0; | 241 virtual const MediaFormat& media_format() = 0; |
231 | 242 |
232 // Schedules a read. Decoder takes ownership of the callback. | 243 // Schedules a read. Decoder takes ownership of the callback. |
233 // | 244 // |
234 // TODO(scherkus): switch Read() callback to scoped_refptr<>. | 245 // TODO(scherkus): switch Read() callback to scoped_refptr<>. |
235 virtual void Read(Callback1<VideoFrame*>::Type* read_callback) = 0; | 246 virtual void Read(Callback1<VideoFrame*>::Type* read_callback) = 0; |
236 }; | 247 }; |
237 | 248 |
238 | 249 |
239 class AudioDecoder : public MediaFilter { | 250 class AudioDecoder : public MediaFilter { |
240 public: | 251 public: |
241 static const FilterType filter_type() { | 252 static const FilterType filter_type() { |
242 return FILTER_AUDIO_DECODER; | 253 return FILTER_AUDIO_DECODER; |
243 } | 254 } |
244 | 255 |
245 static const char* major_mime_type() { | 256 static const char* major_mime_type() { |
246 return mime_type::kMajorTypeAudio; | 257 return mime_type::kMajorTypeAudio; |
247 } | 258 } |
248 | 259 |
249 // Initializes this filter, returns true if successful, false otherwise. | 260 // Initialize a AudioDecoder with the given DemuxerStream, executing the |
250 virtual bool Initialize(DemuxerStream* demuxer_stream) = 0; | 261 // callback upon completion. |
| 262 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; |
251 | 263 |
252 // Returns the MediaFormat for this filter. | 264 // Returns the MediaFormat for this filter. |
253 virtual const MediaFormat& media_format() = 0; | 265 virtual const MediaFormat& media_format() = 0; |
254 | 266 |
255 // Schedules a read. Decoder takes ownership of the callback. | 267 // Schedules a read. Decoder takes ownership of the callback. |
256 // | 268 // |
257 // TODO(scherkus): switch Read() callback to scoped_refptr<>. | 269 // TODO(scherkus): switch Read() callback to scoped_refptr<>. |
258 virtual void Read(Callback1<Buffer*>::Type* read_callback) = 0; | 270 virtual void Read(Callback1<Buffer*>::Type* read_callback) = 0; |
259 }; | 271 }; |
260 | 272 |
261 | 273 |
262 class VideoRenderer : public MediaFilter { | 274 class VideoRenderer : public MediaFilter { |
263 public: | 275 public: |
264 static const FilterType filter_type() { | 276 static const FilterType filter_type() { |
265 return FILTER_VIDEO_RENDERER; | 277 return FILTER_VIDEO_RENDERER; |
266 } | 278 } |
267 | 279 |
268 static const char* major_mime_type() { | 280 static const char* major_mime_type() { |
269 return mime_type::kMajorTypeVideo; | 281 return mime_type::kMajorTypeVideo; |
270 } | 282 } |
271 | 283 |
272 // Initializes this filter, returns true if successful, false otherwise. | 284 // Initialize a VideoRenderer with the given VideoDecoder, executing the |
273 virtual bool Initialize(VideoDecoder* decoder) = 0; | 285 // callback upon completion. |
| 286 virtual void Initialize(VideoDecoder* decoder, FilterCallback* callback) = 0; |
274 }; | 287 }; |
275 | 288 |
276 | 289 |
277 class AudioRenderer : public MediaFilter { | 290 class AudioRenderer : public MediaFilter { |
278 public: | 291 public: |
279 static const FilterType filter_type() { | 292 static const FilterType filter_type() { |
280 return FILTER_AUDIO_RENDERER; | 293 return FILTER_AUDIO_RENDERER; |
281 } | 294 } |
282 | 295 |
283 static const char* major_mime_type() { | 296 static const char* major_mime_type() { |
284 return mime_type::kMajorTypeAudio; | 297 return mime_type::kMajorTypeAudio; |
285 } | 298 } |
286 | 299 |
287 // Initializes this filter, returns true if successful, false otherwise. | 300 // Initialize a AudioRenderer with the given AudioDecoder, executing the |
288 virtual bool Initialize(AudioDecoder* decoder) = 0; | 301 // callback upon completion. |
| 302 virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback) = 0; |
289 | 303 |
290 // Sets the output volume. | 304 // Sets the output volume. |
291 virtual void SetVolume(float volume) = 0; | 305 virtual void SetVolume(float volume) = 0; |
292 }; | 306 }; |
293 | 307 |
294 } // namespace media | 308 } // namespace media |
295 | 309 |
296 #endif // MEDIA_BASE_FILTERS_H_ | 310 #endif // MEDIA_BASE_FILTERS_H_ |
OLD | NEW |