| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 #include <limits> | 26 #include <limits> |
| 27 #include <string> | 27 #include <string> |
| 28 | 28 |
| 29 #include "base/callback.h" | 29 #include "base/callback.h" |
| 30 #include "base/callback_old.h" | 30 #include "base/callback_old.h" |
| 31 #include "base/memory/ref_counted.h" | 31 #include "base/memory/ref_counted.h" |
| 32 #include "base/memory/scoped_ptr.h" | 32 #include "base/memory/scoped_ptr.h" |
| 33 #include "base/time.h" | 33 #include "base/time.h" |
| 34 #include "media/base/audio_decoder_config.h" | 34 #include "media/base/audio_decoder_config.h" |
| 35 #include "media/base/media_export.h" | |
| 36 #include "media/base/pipeline_status.h" | 35 #include "media/base/pipeline_status.h" |
| 37 #include "media/base/video_frame.h" | 36 #include "media/base/video_frame.h" |
| 38 | 37 |
| 39 struct AVStream; | 38 struct AVStream; |
| 40 | 39 |
| 41 namespace media { | 40 namespace media { |
| 42 | 41 |
| 43 class Buffer; | 42 class Buffer; |
| 44 class Decoder; | 43 class Decoder; |
| 45 class DemuxerStream; | 44 class DemuxerStream; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 61 AUTO, | 60 AUTO, |
| 62 }; | 61 }; |
| 63 | 62 |
| 64 // Used for completing asynchronous methods. | 63 // Used for completing asynchronous methods. |
| 65 typedef Callback0::Type FilterCallback; | 64 typedef Callback0::Type FilterCallback; |
| 66 typedef base::Callback<void(PipelineStatus)> FilterStatusCB; | 65 typedef base::Callback<void(PipelineStatus)> FilterStatusCB; |
| 67 | 66 |
| 68 // This function copies |cb|, calls Reset() on |cb|, and then calls Run() | 67 // This function copies |cb|, calls Reset() on |cb|, and then calls Run() |
| 69 // on the copy. This is used in the common case where you need to clear | 68 // on the copy. This is used in the common case where you need to clear |
| 70 // a callback member variable before running the callback. | 69 // a callback member variable before running the callback. |
| 71 MEDIA_EXPORT void ResetAndRunCB(FilterStatusCB* cb, PipelineStatus status); | 70 void ResetAndRunCB(FilterStatusCB* cb, PipelineStatus status); |
| 72 | 71 |
| 73 // Used for updating pipeline statistics. | 72 // Used for updating pipeline statistics. |
| 74 typedef Callback1<const PipelineStatistics&>::Type StatisticsCallback; | 73 typedef Callback1<const PipelineStatistics&>::Type StatisticsCallback; |
| 75 | 74 |
| 76 class MEDIA_EXPORT Filter : public base::RefCountedThreadSafe<Filter> { | 75 class Filter : public base::RefCountedThreadSafe<Filter> { |
| 77 public: | 76 public: |
| 78 Filter(); | 77 Filter(); |
| 79 | 78 |
| 80 // Sets the private member |host_|. This is the first method called by | 79 // Sets the private member |host_|. This is the first method called by |
| 81 // the FilterHost after a filter is created. The host holds a strong | 80 // the FilterHost after a filter is created. The host holds a strong |
| 82 // reference to the filter. The reference held by the host is guaranteed | 81 // reference to the filter. The reference held by the host is guaranteed |
| 83 // to be released before the host object is destroyed by the pipeline. | 82 // to be released before the host object is destroyed by the pipeline. |
| 84 virtual void set_host(FilterHost* host); | 83 virtual void set_host(FilterHost* host); |
| 85 | 84 |
| 86 virtual FilterHost* host(); | 85 virtual FilterHost* host(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 virtual ~Filter(); | 123 virtual ~Filter(); |
| 125 | 124 |
| 126 FilterHost* host() const { return host_; } | 125 FilterHost* host() const { return host_; } |
| 127 | 126 |
| 128 private: | 127 private: |
| 129 FilterHost* host_; | 128 FilterHost* host_; |
| 130 | 129 |
| 131 DISALLOW_COPY_AND_ASSIGN(Filter); | 130 DISALLOW_COPY_AND_ASSIGN(Filter); |
| 132 }; | 131 }; |
| 133 | 132 |
| 134 class MEDIA_EXPORT DataSource : public Filter { | 133 class DataSource : public Filter { |
| 135 public: | 134 public: |
| 136 typedef Callback1<size_t>::Type ReadCallback; | 135 typedef Callback1<size_t>::Type ReadCallback; |
| 137 static const size_t kReadError = static_cast<size_t>(-1); | 136 static const size_t kReadError = static_cast<size_t>(-1); |
| 138 | 137 |
| 139 // Reads |size| bytes from |position| into |data|. And when the read is done | 138 // Reads |size| bytes from |position| into |data|. And when the read is done |
| 140 // or failed, |read_callback| is called with the number of bytes read or | 139 // or failed, |read_callback| is called with the number of bytes read or |
| 141 // kReadError in case of error. | 140 // kReadError in case of error. |
| 142 // TODO(hclam): should change |size| to int! It makes the code so messy | 141 // TODO(hclam): should change |size| to int! It makes the code so messy |
| 143 // with size_t and int all over the place.. | 142 // with size_t and int all over the place.. |
| 144 virtual void Read(int64 position, size_t size, | 143 virtual void Read(int64 position, size_t size, |
| 145 uint8* data, ReadCallback* read_callback) = 0; | 144 uint8* data, ReadCallback* read_callback) = 0; |
| 146 | 145 |
| 147 // Returns true and the file size, false if the file size could not be | 146 // Returns true and the file size, false if the file size could not be |
| 148 // retrieved. | 147 // retrieved. |
| 149 virtual bool GetSize(int64* size_out) = 0; | 148 virtual bool GetSize(int64* size_out) = 0; |
| 150 | 149 |
| 151 // Returns true if we are performing streaming. In this case seeking is | 150 // Returns true if we are performing streaming. In this case seeking is |
| 152 // not possible. | 151 // not possible. |
| 153 virtual bool IsStreaming() = 0; | 152 virtual bool IsStreaming() = 0; |
| 154 | 153 |
| 155 // Alert the DataSource that the video preload value has been changed. | 154 // Alert the DataSource that the video preload value has been changed. |
| 156 virtual void SetPreload(Preload preload) = 0; | 155 virtual void SetPreload(Preload preload) = 0; |
| 157 }; | 156 }; |
| 158 | 157 |
| 159 class MEDIA_EXPORT DemuxerStream | 158 class DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> { |
| 160 : public base::RefCountedThreadSafe<DemuxerStream> { | |
| 161 public: | 159 public: |
| 162 typedef base::Callback<void(Buffer*)> ReadCallback; | 160 typedef base::Callback<void(Buffer*)> ReadCallback; |
| 163 | 161 |
| 164 enum Type { | 162 enum Type { |
| 165 UNKNOWN, | 163 UNKNOWN, |
| 166 AUDIO, | 164 AUDIO, |
| 167 VIDEO, | 165 VIDEO, |
| 168 NUM_TYPES, // Always keep this entry as the last one! | 166 NUM_TYPES, // Always keep this entry as the last one! |
| 169 }; | 167 }; |
| 170 | 168 |
| 171 // Schedules a read. When the |read_callback| is called, the downstream | 169 // Schedules a read. When the |read_callback| is called, the downstream |
| 172 // filter takes ownership of the buffer by AddRef()'ing the buffer. | 170 // filter takes ownership of the buffer by AddRef()'ing the buffer. |
| 173 virtual void Read(const ReadCallback& read_callback) = 0; | 171 virtual void Read(const ReadCallback& read_callback) = 0; |
| 174 | 172 |
| 175 // Returns an |AVStream*| if supported, or NULL. | 173 // Returns an |AVStream*| if supported, or NULL. |
| 176 virtual AVStream* GetAVStream(); | 174 virtual AVStream* GetAVStream(); |
| 177 | 175 |
| 178 // Returns the type of stream. | 176 // Returns the type of stream. |
| 179 virtual Type type() = 0; | 177 virtual Type type() = 0; |
| 180 | 178 |
| 181 virtual void EnableBitstreamConverter() = 0; | 179 virtual void EnableBitstreamConverter() = 0; |
| 182 | 180 |
| 183 protected: | 181 protected: |
| 184 friend class base::RefCountedThreadSafe<DemuxerStream>; | 182 friend class base::RefCountedThreadSafe<DemuxerStream>; |
| 185 virtual ~DemuxerStream(); | 183 virtual ~DemuxerStream(); |
| 186 }; | 184 }; |
| 187 | 185 |
| 188 class MEDIA_EXPORT Demuxer : public Filter { | 186 class Demuxer : public Filter { |
| 189 public: | 187 public: |
| 190 // Returns the given stream type, or NULL if that type is not present. | 188 // Returns the given stream type, or NULL if that type is not present. |
| 191 virtual scoped_refptr<DemuxerStream> GetStream(DemuxerStream::Type type) = 0; | 189 virtual scoped_refptr<DemuxerStream> GetStream(DemuxerStream::Type type) = 0; |
| 192 | 190 |
| 193 // Alert the Demuxer that the video preload value has been changed. | 191 // Alert the Demuxer that the video preload value has been changed. |
| 194 virtual void SetPreload(Preload preload) = 0; | 192 virtual void SetPreload(Preload preload) = 0; |
| 195 | 193 |
| 196 // Returns the starting time for the media file. | 194 // Returns the starting time for the media file. |
| 197 virtual base::TimeDelta GetStartTime() const = 0; | 195 virtual base::TimeDelta GetStartTime() const = 0; |
| 198 }; | 196 }; |
| 199 | 197 |
| 200 | 198 |
| 201 class MEDIA_EXPORT VideoDecoder : public Filter { | 199 class VideoDecoder : public Filter { |
| 202 public: | 200 public: |
| 203 // Initialize a VideoDecoder with the given DemuxerStream, executing the | 201 // Initialize a VideoDecoder with the given DemuxerStream, executing the |
| 204 // callback upon completion. | 202 // callback upon completion. |
| 205 // stats_callback is used to update global pipeline statistics. | 203 // stats_callback is used to update global pipeline statistics. |
| 206 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback, | 204 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback, |
| 207 StatisticsCallback* stats_callback) = 0; | 205 StatisticsCallback* stats_callback) = 0; |
| 208 | 206 |
| 209 // Renderer provides an output buffer for Decoder to write to. These buffers | 207 // Renderer provides an output buffer for Decoder to write to. These buffers |
| 210 // will be recycled to renderer via the permanent callback. | 208 // will be recycled to renderer via the permanent callback. |
| 211 // | 209 // |
| (...skipping 28 matching lines...) Expand all Loading... |
| 240 } | 238 } |
| 241 | 239 |
| 242 VideoDecoder(); | 240 VideoDecoder(); |
| 243 virtual ~VideoDecoder(); | 241 virtual ~VideoDecoder(); |
| 244 | 242 |
| 245 private: | 243 private: |
| 246 ConsumeVideoFrameCB consume_video_frame_callback_; | 244 ConsumeVideoFrameCB consume_video_frame_callback_; |
| 247 }; | 245 }; |
| 248 | 246 |
| 249 | 247 |
| 250 class MEDIA_EXPORT AudioDecoder : public Filter { | 248 class AudioDecoder : public Filter { |
| 251 public: | 249 public: |
| 252 // Initialize a AudioDecoder with the given DemuxerStream, executing the | 250 // Initialize a AudioDecoder with the given DemuxerStream, executing the |
| 253 // callback upon completion. | 251 // callback upon completion. |
| 254 // stats_callback is used to update global pipeline statistics. | 252 // stats_callback is used to update global pipeline statistics. |
| 255 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback, | 253 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback, |
| 256 StatisticsCallback* stats_callback) = 0; | 254 StatisticsCallback* stats_callback) = 0; |
| 257 | 255 |
| 258 virtual AudioDecoderConfig config() = 0; | 256 virtual AudioDecoderConfig config() = 0; |
| 259 | 257 |
| 260 // Renderer provides an output buffer for Decoder to write to. These buffers | 258 // Renderer provides an output buffer for Decoder to write to. These buffers |
| (...skipping 14 matching lines...) Expand all Loading... |
| 275 virtual ~AudioDecoder(); | 273 virtual ~AudioDecoder(); |
| 276 | 274 |
| 277 // Executes the permanent callback to pass off decoded audio. | 275 // Executes the permanent callback to pass off decoded audio. |
| 278 void ConsumeAudioSamples(scoped_refptr<Buffer> buffer); | 276 void ConsumeAudioSamples(scoped_refptr<Buffer> buffer); |
| 279 | 277 |
| 280 private: | 278 private: |
| 281 ConsumeAudioSamplesCB consume_audio_samples_callback_; | 279 ConsumeAudioSamplesCB consume_audio_samples_callback_; |
| 282 }; | 280 }; |
| 283 | 281 |
| 284 | 282 |
| 285 class MEDIA_EXPORT VideoRenderer : public Filter { | 283 class VideoRenderer : public Filter { |
| 286 public: | 284 public: |
| 287 // Initialize a VideoRenderer with the given VideoDecoder, executing the | 285 // Initialize a VideoRenderer with the given VideoDecoder, executing the |
| 288 // callback upon completion. | 286 // callback upon completion. |
| 289 virtual void Initialize(VideoDecoder* decoder, FilterCallback* callback, | 287 virtual void Initialize(VideoDecoder* decoder, FilterCallback* callback, |
| 290 StatisticsCallback* stats_callback) = 0; | 288 StatisticsCallback* stats_callback) = 0; |
| 291 | 289 |
| 292 // Returns true if this filter has received and processed an end-of-stream | 290 // Returns true if this filter has received and processed an end-of-stream |
| 293 // buffer. | 291 // buffer. |
| 294 virtual bool HasEnded() = 0; | 292 virtual bool HasEnded() = 0; |
| 295 }; | 293 }; |
| 296 | 294 |
| 297 | 295 |
| 298 class MEDIA_EXPORT AudioRenderer : public Filter { | 296 class AudioRenderer : public Filter { |
| 299 public: | 297 public: |
| 300 // Initialize a AudioRenderer with the given AudioDecoder, executing the | 298 // Initialize a AudioRenderer with the given AudioDecoder, executing the |
| 301 // callback upon completion. | 299 // callback upon completion. |
| 302 virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback) = 0; | 300 virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback) = 0; |
| 303 | 301 |
| 304 // Returns true if this filter has received and processed an end-of-stream | 302 // Returns true if this filter has received and processed an end-of-stream |
| 305 // buffer. | 303 // buffer. |
| 306 virtual bool HasEnded() = 0; | 304 virtual bool HasEnded() = 0; |
| 307 | 305 |
| 308 // Sets the output volume. | 306 // Sets the output volume. |
| 309 virtual void SetVolume(float volume) = 0; | 307 virtual void SetVolume(float volume) = 0; |
| 310 }; | 308 }; |
| 311 | 309 |
| 312 } // namespace media | 310 } // namespace media |
| 313 | 311 |
| 314 #endif // MEDIA_BASE_FILTERS_H_ | 312 #endif // MEDIA_BASE_FILTERS_H_ |
| OLD | NEW |