| 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 25 matching lines...) Expand all Loading... |
| 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 FilterHost; | 43 class FilterHost; |
| 44 class MediaFilter; | 44 class MediaFilter; |
| 45 | 45 |
| 46 // Identifies the type of filter implementation. Each filter has to be one of |
| 47 // the following types. This is used to identify filter object during |
| 48 // initialization of pipeline. |
| 49 enum FilterType { |
| 50 FILTER_DATA_SOURCE, |
| 51 FILTER_DEMUXER, |
| 52 FILTER_AUDIO_DECODER, |
| 53 FILTER_VIDEO_DECODER, |
| 54 FILTER_AUDIO_RENDERER, |
| 55 FILTER_VIDEO_RENDERER |
| 56 }; |
| 57 |
| 46 // Used for completing asynchronous methods. | 58 // Used for completing asynchronous methods. |
| 47 typedef Callback0::Type FilterCallback; | 59 typedef Callback0::Type FilterCallback; |
| 48 | 60 |
| 49 class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { | 61 class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { |
| 50 public: | 62 public: |
| 51 MediaFilter(); | 63 MediaFilter(); |
| 52 | 64 |
| 65 // Return the type of this filter. All implementor has to provide this |
| 66 // method. |
| 67 virtual FilterType filter_type() const = 0; |
| 68 |
| 53 // Return the major mime type for this filter. | 69 // Return the major mime type for this filter. |
| 54 virtual const char* major_mime_type() const; | 70 virtual const char* major_mime_type() const; |
| 55 | 71 |
| 56 // Sets the private member |host_|. This is the first method called by | 72 // 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 | 73 // 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 | 74 // 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. | 75 // to be released before the host object is destroyed by the pipeline. |
| 60 virtual void set_host(FilterHost* host); | 76 virtual void set_host(FilterHost* host); |
| 61 | 77 |
| 62 virtual FilterHost* host(); | 78 virtual FilterHost* host(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 DISALLOW_COPY_AND_ASSIGN(MediaFilter); | 139 DISALLOW_COPY_AND_ASSIGN(MediaFilter); |
| 124 }; | 140 }; |
| 125 | 141 |
| 126 class DataSource : public MediaFilter { | 142 class DataSource : public MediaFilter { |
| 127 public: | 143 public: |
| 128 typedef Callback1<size_t>::Type ReadCallback; | 144 typedef Callback1<size_t>::Type ReadCallback; |
| 129 static const size_t kReadError = static_cast<size_t>(-1); | 145 static const size_t kReadError = static_cast<size_t>(-1); |
| 130 | 146 |
| 131 virtual bool IsUrlSupported(const std::string& url); | 147 virtual bool IsUrlSupported(const std::string& url); |
| 132 | 148 |
| 149 static FilterType static_filter_type() { return FILTER_DATA_SOURCE; } |
| 150 virtual FilterType filter_type() const; |
| 151 |
| 133 // Initialize a DataSource for the given URL, executing the callback upon | 152 // Initialize a DataSource for the given URL, executing the callback upon |
| 134 // completion. | 153 // completion. |
| 135 virtual void Initialize(const std::string& url, FilterCallback* callback) = 0; | 154 virtual void Initialize(const std::string& url, FilterCallback* callback) = 0; |
| 136 | 155 |
| 137 // Reads |size| bytes from |position| into |data|. And when the read is done | 156 // 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 | 157 // or failed, |read_callback| is called with the number of bytes read or |
| 139 // kReadError in case of error. | 158 // kReadError in case of error. |
| 140 // TODO(hclam): should change |size| to int! It makes the code so messy | 159 // TODO(hclam): should change |size| to int! It makes the code so messy |
| 141 // with size_t and int all over the place.. | 160 // with size_t and int all over the place.. |
| 142 virtual void Read(int64 position, size_t size, | 161 virtual void Read(int64 position, size_t size, |
| 143 uint8* data, ReadCallback* read_callback) = 0; | 162 uint8* data, ReadCallback* read_callback) = 0; |
| 144 | 163 |
| 145 // Returns true and the file size, false if the file size could not be | 164 // Returns true and the file size, false if the file size could not be |
| 146 // retrieved. | 165 // retrieved. |
| 147 virtual bool GetSize(int64* size_out) = 0; | 166 virtual bool GetSize(int64* size_out) = 0; |
| 148 | 167 |
| 149 // Returns true if we are performing streaming. In this case seeking is | 168 // Returns true if we are performing streaming. In this case seeking is |
| 150 // not possible. | 169 // not possible. |
| 151 virtual bool IsStreaming() = 0; | 170 virtual bool IsStreaming() = 0; |
| 152 }; | 171 }; |
| 153 | 172 |
| 154 | 173 |
| 155 class Demuxer : public MediaFilter { | 174 class Demuxer : public MediaFilter { |
| 156 public: | 175 public: |
| 176 static FilterType static_filter_type() { return FILTER_DEMUXER; } |
| 177 virtual FilterType filter_type() const; |
| 178 |
| 157 virtual bool requires_message_loop() const; | 179 virtual bool requires_message_loop() const; |
| 158 virtual const char* message_loop_name() const; | 180 virtual const char* message_loop_name() const; |
| 159 | 181 |
| 160 // Initialize a Demuxer with the given DataSource, executing the callback upon | 182 // Initialize a Demuxer with the given DataSource, executing the callback upon |
| 161 // completion. | 183 // completion. |
| 162 virtual void Initialize(DataSource* data_source, | 184 virtual void Initialize(DataSource* data_source, |
| 163 FilterCallback* callback) = 0; | 185 FilterCallback* callback) = 0; |
| 164 | 186 |
| 165 // Returns the number of streams available | 187 // Returns the number of streams available |
| 166 virtual size_t GetNumberOfStreams() = 0; | 188 virtual size_t GetNumberOfStreams() = 0; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // public template function will assign the interface to a scoped_refptr<>. | 225 // public template function will assign the interface to a scoped_refptr<>. |
| 204 virtual void* QueryInterface(const char* interface_id) { return NULL; } | 226 virtual void* QueryInterface(const char* interface_id) { return NULL; } |
| 205 | 227 |
| 206 friend class base::RefCountedThreadSafe<DemuxerStream>; | 228 friend class base::RefCountedThreadSafe<DemuxerStream>; |
| 207 virtual ~DemuxerStream(); | 229 virtual ~DemuxerStream(); |
| 208 }; | 230 }; |
| 209 | 231 |
| 210 | 232 |
| 211 class VideoDecoder : public MediaFilter { | 233 class VideoDecoder : public MediaFilter { |
| 212 public: | 234 public: |
| 235 static FilterType static_filter_type() { return FILTER_VIDEO_DECODER; } |
| 236 virtual FilterType filter_type() const; |
| 237 |
| 213 virtual const char* major_mime_type() const; | 238 virtual const char* major_mime_type() const; |
| 214 virtual bool requires_message_loop() const; | 239 virtual bool requires_message_loop() const; |
| 215 virtual const char* message_loop_name() const; | 240 virtual const char* message_loop_name() const; |
| 216 | 241 |
| 217 | 242 |
| 218 // Initialize a VideoDecoder with the given DemuxerStream, executing the | 243 // Initialize a VideoDecoder with the given DemuxerStream, executing the |
| 219 // callback upon completion. | 244 // callback upon completion. |
| 220 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; | 245 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; |
| 221 | 246 |
| 222 // |set_fill_buffer_done_callback| install permanent callback from downstream | 247 // |set_fill_buffer_done_callback| install permanent callback from downstream |
| (...skipping 25 matching lines...) Expand all Loading... |
| 248 VideoDecoder(); | 273 VideoDecoder(); |
| 249 virtual ~VideoDecoder(); | 274 virtual ~VideoDecoder(); |
| 250 | 275 |
| 251 private: | 276 private: |
| 252 scoped_ptr<ConsumeVideoFrameCallback> consume_video_frame_callback_; | 277 scoped_ptr<ConsumeVideoFrameCallback> consume_video_frame_callback_; |
| 253 }; | 278 }; |
| 254 | 279 |
| 255 | 280 |
| 256 class AudioDecoder : public MediaFilter { | 281 class AudioDecoder : public MediaFilter { |
| 257 public: | 282 public: |
| 283 static FilterType static_filter_type() { return FILTER_AUDIO_DECODER; } |
| 284 virtual FilterType filter_type() const; |
| 285 |
| 258 virtual const char* major_mime_type() const; | 286 virtual const char* major_mime_type() const; |
| 259 virtual bool requires_message_loop() const; | 287 virtual bool requires_message_loop() const; |
| 260 virtual const char* message_loop_name() const; | 288 virtual const char* message_loop_name() const; |
| 261 | 289 |
| 262 // Initialize a AudioDecoder with the given DemuxerStream, executing the | 290 // Initialize a AudioDecoder with the given DemuxerStream, executing the |
| 263 // callback upon completion. | 291 // callback upon completion. |
| 264 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; | 292 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; |
| 265 | 293 |
| 266 // |set_fill_buffer_done_callback| install permanent callback from downstream | 294 // |set_fill_buffer_done_callback| install permanent callback from downstream |
| 267 // filter (i.e. Renderer). The callback is used to deliver buffers at | 295 // filter (i.e. Renderer). The callback is used to deliver buffers at |
| (...skipping 19 matching lines...) Expand all Loading... |
| 287 AudioDecoder(); | 315 AudioDecoder(); |
| 288 ~AudioDecoder(); | 316 ~AudioDecoder(); |
| 289 | 317 |
| 290 private: | 318 private: |
| 291 scoped_ptr<ConsumeAudioSamplesCallback> consume_audio_samples_callback_; | 319 scoped_ptr<ConsumeAudioSamplesCallback> consume_audio_samples_callback_; |
| 292 }; | 320 }; |
| 293 | 321 |
| 294 | 322 |
| 295 class VideoRenderer : public MediaFilter { | 323 class VideoRenderer : public MediaFilter { |
| 296 public: | 324 public: |
| 325 static FilterType static_filter_type() { return FILTER_VIDEO_RENDERER; } |
| 326 virtual FilterType filter_type() const; |
| 327 |
| 297 virtual const char* major_mime_type() const; | 328 virtual const char* major_mime_type() const; |
| 298 | 329 |
| 299 // Initialize a VideoRenderer with the given VideoDecoder, executing the | 330 // Initialize a VideoRenderer with the given VideoDecoder, executing the |
| 300 // callback upon completion. | 331 // callback upon completion. |
| 301 virtual void Initialize(VideoDecoder* decoder, FilterCallback* callback) = 0; | 332 virtual void Initialize(VideoDecoder* decoder, FilterCallback* callback) = 0; |
| 302 | 333 |
| 303 // Returns true if this filter has received and processed an end-of-stream | 334 // Returns true if this filter has received and processed an end-of-stream |
| 304 // buffer. | 335 // buffer. |
| 305 virtual bool HasEnded() = 0; | 336 virtual bool HasEnded() = 0; |
| 306 }; | 337 }; |
| 307 | 338 |
| 308 | 339 |
| 309 class AudioRenderer : public MediaFilter { | 340 class AudioRenderer : public MediaFilter { |
| 310 public: | 341 public: |
| 342 static FilterType static_filter_type() { return FILTER_AUDIO_RENDERER; } |
| 343 virtual FilterType filter_type() const; |
| 344 |
| 311 virtual const char* major_mime_type() const; | 345 virtual const char* major_mime_type() const; |
| 312 | 346 |
| 313 // Initialize a AudioRenderer with the given AudioDecoder, executing the | 347 // Initialize a AudioRenderer with the given AudioDecoder, executing the |
| 314 // callback upon completion. | 348 // callback upon completion. |
| 315 virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback) = 0; | 349 virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback) = 0; |
| 316 | 350 |
| 317 // Returns true if this filter has received and processed an end-of-stream | 351 // Returns true if this filter has received and processed an end-of-stream |
| 318 // buffer. | 352 // buffer. |
| 319 virtual bool HasEnded() = 0; | 353 virtual bool HasEnded() = 0; |
| 320 | 354 |
| 321 // Sets the output volume. | 355 // Sets the output volume. |
| 322 virtual void SetVolume(float volume) = 0; | 356 virtual void SetVolume(float volume) = 0; |
| 323 }; | 357 }; |
| 324 | 358 |
| 325 } // namespace media | 359 } // namespace media |
| 326 | 360 |
| 327 #endif // MEDIA_BASE_FILTERS_H_ | 361 #endif // MEDIA_BASE_FILTERS_H_ |
| OLD | NEW |