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