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 // 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 22 matching lines...) Expand all Loading... |
33 #include "media/base/media_format.h" | 33 #include "media/base/media_format.h" |
34 #include "media/base/video_frame.h" | 34 #include "media/base/video_frame.h" |
35 | 35 |
36 class MessageLoop; | 36 class MessageLoop; |
37 | 37 |
38 namespace media { | 38 namespace media { |
39 | 39 |
40 class Buffer; | 40 class Buffer; |
41 class Decoder; | 41 class Decoder; |
42 class DemuxerStream; | 42 class DemuxerStream; |
| 43 class Filter; |
43 class FilterHost; | 44 class FilterHost; |
44 class MediaFilter; | |
45 | 45 |
46 // Used for completing asynchronous methods. | 46 // Used for completing asynchronous methods. |
47 typedef Callback0::Type FilterCallback; | 47 typedef Callback0::Type FilterCallback; |
48 | 48 |
49 class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { | 49 class Filter : public base::RefCountedThreadSafe<Filter> { |
50 public: | 50 public: |
51 MediaFilter(); | 51 Filter(); |
52 | 52 |
53 // Return the major mime type for this filter. | 53 // Return the major mime type for this filter. |
54 virtual const char* major_mime_type() const; | 54 virtual const char* major_mime_type() const; |
55 | 55 |
56 // Sets the private member |host_|. This is the first method called by | 56 // Sets the private member |host_|. This is the first method called by |
57 // the FilterHost after a filter is created. The host holds a strong | 57 // the FilterHost after a filter is created. The host holds a strong |
58 // reference to the filter. The reference held by the host is guaranteed | 58 // reference to the filter. The reference held by the host is guaranteed |
59 // to be released before the host object is destroyed by the pipeline. | 59 // to be released before the host object is destroyed by the pipeline. |
60 virtual void set_host(FilterHost* host); | 60 virtual void set_host(FilterHost* host); |
61 | 61 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // callback upon completion. | 103 // callback upon completion. |
104 virtual void Seek(base::TimeDelta time, FilterCallback* callback); | 104 virtual void Seek(base::TimeDelta time, FilterCallback* callback); |
105 | 105 |
106 // This method is called from the pipeline when the audio renderer | 106 // This method is called from the pipeline when the audio renderer |
107 // is disabled. Filters can ignore the notification if they do not | 107 // is disabled. Filters can ignore the notification if they do not |
108 // need to react to this event. | 108 // need to react to this event. |
109 virtual void OnAudioRendererDisabled(); | 109 virtual void OnAudioRendererDisabled(); |
110 | 110 |
111 protected: | 111 protected: |
112 // Only allow scoped_refptr<> to delete filters. | 112 // Only allow scoped_refptr<> to delete filters. |
113 friend class base::RefCountedThreadSafe<MediaFilter>; | 113 friend class base::RefCountedThreadSafe<Filter>; |
114 virtual ~MediaFilter(); | 114 virtual ~Filter(); |
115 | 115 |
116 FilterHost* host() const { return host_; } | 116 FilterHost* host() const { return host_; } |
117 MessageLoop* message_loop() const { return message_loop_; } | 117 MessageLoop* message_loop() const { return message_loop_; } |
118 | 118 |
119 private: | 119 private: |
120 FilterHost* host_; | 120 FilterHost* host_; |
121 MessageLoop* message_loop_; | 121 MessageLoop* message_loop_; |
122 | 122 |
123 DISALLOW_COPY_AND_ASSIGN(MediaFilter); | 123 DISALLOW_COPY_AND_ASSIGN(Filter); |
124 }; | 124 }; |
125 | 125 |
126 class DataSource : public MediaFilter { | 126 class DataSource : public Filter { |
127 public: | 127 public: |
128 typedef Callback1<size_t>::Type ReadCallback; | 128 typedef Callback1<size_t>::Type ReadCallback; |
129 static const size_t kReadError = static_cast<size_t>(-1); | 129 static const size_t kReadError = static_cast<size_t>(-1); |
130 | 130 |
131 virtual bool IsUrlSupported(const std::string& url); | 131 virtual bool IsUrlSupported(const std::string& url); |
132 | 132 |
133 // Initialize a DataSource for the given URL, executing the callback upon | 133 // Initialize a DataSource for the given URL, executing the callback upon |
134 // completion. | 134 // completion. |
135 virtual void Initialize(const std::string& url, FilterCallback* callback) = 0; | 135 virtual void Initialize(const std::string& url, FilterCallback* callback) = 0; |
136 | 136 |
137 // Reads |size| bytes from |position| into |data|. And when the read is done | 137 // Reads |size| bytes from |position| into |data|. And when the read is done |
138 // or failed, |read_callback| is called with the number of bytes read or | 138 // or failed, |read_callback| is called with the number of bytes read or |
139 // kReadError in case of error. | 139 // kReadError in case of error. |
140 // TODO(hclam): should change |size| to int! It makes the code so messy | 140 // TODO(hclam): should change |size| to int! It makes the code so messy |
141 // with size_t and int all over the place.. | 141 // with size_t and int all over the place.. |
142 virtual void Read(int64 position, size_t size, | 142 virtual void Read(int64 position, size_t size, |
143 uint8* data, ReadCallback* read_callback) = 0; | 143 uint8* data, ReadCallback* read_callback) = 0; |
144 | 144 |
145 // Returns true and the file size, false if the file size could not be | 145 // Returns true and the file size, false if the file size could not be |
146 // retrieved. | 146 // retrieved. |
147 virtual bool GetSize(int64* size_out) = 0; | 147 virtual bool GetSize(int64* size_out) = 0; |
148 | 148 |
149 // Returns true if we are performing streaming. In this case seeking is | 149 // Returns true if we are performing streaming. In this case seeking is |
150 // not possible. | 150 // not possible. |
151 virtual bool IsStreaming() = 0; | 151 virtual bool IsStreaming() = 0; |
152 }; | 152 }; |
153 | 153 |
154 | 154 |
155 class Demuxer : public MediaFilter { | 155 class Demuxer : public Filter { |
156 public: | 156 public: |
157 virtual bool requires_message_loop() const; | 157 virtual bool requires_message_loop() const; |
158 virtual const char* message_loop_name() const; | 158 virtual const char* message_loop_name() const; |
159 | 159 |
160 // Initialize a Demuxer with the given DataSource, executing the callback upon | 160 // Initialize a Demuxer with the given DataSource, executing the callback upon |
161 // completion. | 161 // completion. |
162 virtual void Initialize(DataSource* data_source, | 162 virtual void Initialize(DataSource* data_source, |
163 FilterCallback* callback) = 0; | 163 FilterCallback* callback) = 0; |
164 | 164 |
165 // Returns the number of streams available | 165 // Returns the number of streams available |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // return NULL to indicate the interface is unknown. The derived filter | 201 // return NULL to indicate the interface is unknown. The derived filter |
202 // should NOT AddRef() the interface. The DemuxerStream::QueryInterface() | 202 // should NOT AddRef() the interface. The DemuxerStream::QueryInterface() |
203 // public template function will assign the interface to a scoped_refptr<>. | 203 // public template function will assign the interface to a scoped_refptr<>. |
204 virtual void* QueryInterface(const char* interface_id) { return NULL; } | 204 virtual void* QueryInterface(const char* interface_id) { return NULL; } |
205 | 205 |
206 friend class base::RefCountedThreadSafe<DemuxerStream>; | 206 friend class base::RefCountedThreadSafe<DemuxerStream>; |
207 virtual ~DemuxerStream(); | 207 virtual ~DemuxerStream(); |
208 }; | 208 }; |
209 | 209 |
210 | 210 |
211 class VideoDecoder : public MediaFilter { | 211 class VideoDecoder : public Filter { |
212 public: | 212 public: |
213 virtual const char* major_mime_type() const; | 213 virtual const char* major_mime_type() const; |
214 virtual bool requires_message_loop() const; | 214 virtual bool requires_message_loop() const; |
215 virtual const char* message_loop_name() const; | 215 virtual const char* message_loop_name() const; |
216 | 216 |
217 | 217 |
218 // Initialize a VideoDecoder with the given DemuxerStream, executing the | 218 // Initialize a VideoDecoder with the given DemuxerStream, executing the |
219 // callback upon completion. | 219 // callback upon completion. |
220 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; | 220 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; |
221 | 221 |
(...skipping 24 matching lines...) Expand all Loading... |
246 } | 246 } |
247 | 247 |
248 VideoDecoder(); | 248 VideoDecoder(); |
249 virtual ~VideoDecoder(); | 249 virtual ~VideoDecoder(); |
250 | 250 |
251 private: | 251 private: |
252 scoped_ptr<ConsumeVideoFrameCallback> consume_video_frame_callback_; | 252 scoped_ptr<ConsumeVideoFrameCallback> consume_video_frame_callback_; |
253 }; | 253 }; |
254 | 254 |
255 | 255 |
256 class AudioDecoder : public MediaFilter { | 256 class AudioDecoder : public Filter { |
257 public: | 257 public: |
258 virtual const char* major_mime_type() const; | 258 virtual const char* major_mime_type() const; |
259 virtual bool requires_message_loop() const; | 259 virtual bool requires_message_loop() const; |
260 virtual const char* message_loop_name() const; | 260 virtual const char* message_loop_name() const; |
261 | 261 |
262 // Initialize a AudioDecoder with the given DemuxerStream, executing the | 262 // Initialize a AudioDecoder with the given DemuxerStream, executing the |
263 // callback upon completion. | 263 // callback upon completion. |
264 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; | 264 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; |
265 | 265 |
266 // |set_fill_buffer_done_callback| install permanent callback from downstream | 266 // |set_fill_buffer_done_callback| install permanent callback from downstream |
(...skipping 18 matching lines...) Expand all Loading... |
285 | 285 |
286 protected: | 286 protected: |
287 AudioDecoder(); | 287 AudioDecoder(); |
288 ~AudioDecoder(); | 288 ~AudioDecoder(); |
289 | 289 |
290 private: | 290 private: |
291 scoped_ptr<ConsumeAudioSamplesCallback> consume_audio_samples_callback_; | 291 scoped_ptr<ConsumeAudioSamplesCallback> consume_audio_samples_callback_; |
292 }; | 292 }; |
293 | 293 |
294 | 294 |
295 class VideoRenderer : public MediaFilter { | 295 class VideoRenderer : public Filter { |
296 public: | 296 public: |
297 virtual const char* major_mime_type() const; | 297 virtual const char* major_mime_type() const; |
298 | 298 |
299 // Initialize a VideoRenderer with the given VideoDecoder, executing the | 299 // Initialize a VideoRenderer with the given VideoDecoder, executing the |
300 // callback upon completion. | 300 // callback upon completion. |
301 virtual void Initialize(VideoDecoder* decoder, FilterCallback* callback) = 0; | 301 virtual void Initialize(VideoDecoder* decoder, FilterCallback* callback) = 0; |
302 | 302 |
303 // Returns true if this filter has received and processed an end-of-stream | 303 // Returns true if this filter has received and processed an end-of-stream |
304 // buffer. | 304 // buffer. |
305 virtual bool HasEnded() = 0; | 305 virtual bool HasEnded() = 0; |
306 }; | 306 }; |
307 | 307 |
308 | 308 |
309 class AudioRenderer : public MediaFilter { | 309 class AudioRenderer : public Filter { |
310 public: | 310 public: |
311 virtual const char* major_mime_type() const; | 311 virtual const char* major_mime_type() const; |
312 | 312 |
313 // Initialize a AudioRenderer with the given AudioDecoder, executing the | 313 // Initialize a AudioRenderer with the given AudioDecoder, executing the |
314 // callback upon completion. | 314 // callback upon completion. |
315 virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback) = 0; | 315 virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback) = 0; |
316 | 316 |
317 // Returns true if this filter has received and processed an end-of-stream | 317 // Returns true if this filter has received and processed an end-of-stream |
318 // buffer. | 318 // buffer. |
319 virtual bool HasEnded() = 0; | 319 virtual bool HasEnded() = 0; |
320 | 320 |
321 // Sets the output volume. | 321 // Sets the output volume. |
322 virtual void SetVolume(float volume) = 0; | 322 virtual void SetVolume(float volume) = 0; |
323 }; | 323 }; |
324 | 324 |
325 } // namespace media | 325 } // namespace media |
326 | 326 |
327 #endif // MEDIA_BASE_FILTERS_H_ | 327 #endif // MEDIA_BASE_FILTERS_H_ |
OLD | NEW |