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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Notify the DataSource of the bitrate of the media. | 157 // Notify the DataSource of the bitrate of the media. |
158 // Values of |bitrate| <= 0 are invalid and should be ignored. | 158 // Values of |bitrate| <= 0 are invalid and should be ignored. |
159 virtual void SetBitrate(int bitrate) = 0; | 159 virtual void SetBitrate(int bitrate) = 0; |
160 }; | 160 }; |
161 | 161 |
162 class MEDIA_EXPORT VideoDecoder : public Filter { | 162 class MEDIA_EXPORT VideoDecoder : public Filter { |
163 public: | 163 public: |
164 // Initialize a VideoDecoder with the given DemuxerStream, executing the | 164 // Initialize a VideoDecoder with the given DemuxerStream, executing the |
165 // callback upon completion. | 165 // callback upon completion. |
166 // stats_callback is used to update global pipeline statistics. | 166 // stats_callback is used to update global pipeline statistics. |
| 167 // |
| 168 // TODO(scherkus): switch to PipelineStatus callback. |
167 virtual void Initialize(DemuxerStream* stream, const base::Closure& callback, | 169 virtual void Initialize(DemuxerStream* stream, const base::Closure& callback, |
168 const StatisticsCallback& stats_callback) = 0; | 170 const StatisticsCallback& stats_callback) = 0; |
169 | 171 |
170 // Renderer provides an output buffer for Decoder to write to. These buffers | 172 // Request a frame to be decoded and returned via the provided callback. |
171 // will be recycled to renderer via the permanent callback. | 173 // Only one read may be in flight at any given time. |
172 // | 174 // |
173 // We could also pass empty pointer here to let decoder provide buffers pool. | 175 // Implementations guarantee that the callback will not be called from within |
174 virtual void ProduceVideoFrame(scoped_refptr<VideoFrame> frame) = 0; | 176 // this method. |
175 | |
176 // Installs a permanent callback for passing decoded video output. | |
177 // | 177 // |
178 // A NULL frame represents a decoding error. | 178 // Frames will be non-NULL yet may be end of stream frames. |
179 typedef base::Callback<void(scoped_refptr<VideoFrame>)> ConsumeVideoFrameCB; | 179 typedef base::Callback<void(scoped_refptr<VideoFrame>)> ReadCB; |
180 void set_consume_video_frame_callback(const ConsumeVideoFrameCB& callback) { | 180 virtual void Read(const ReadCB& callback) = 0; |
181 consume_video_frame_callback_ = callback; | |
182 } | |
183 | 181 |
184 // Returns the natural width and height of decoded video in pixels. | 182 // Returns the natural width and height of decoded video in pixels. |
185 // | 183 // |
186 // Clients should NOT rely on these values to remain constant. Instead, use | 184 // Clients should NOT rely on these values to remain constant. Instead, use |
187 // the width/height from decoded video frames themselves. | 185 // the width/height from decoded video frames themselves. |
188 // | 186 // |
189 // TODO(scherkus): why not rely on prerolling and decoding a single frame to | 187 // TODO(scherkus): why not rely on prerolling and decoding a single frame to |
190 // get dimensions? | 188 // get dimensions? |
191 virtual gfx::Size natural_size() = 0; | 189 virtual const gfx::Size& natural_size() = 0; |
192 | 190 |
193 protected: | 191 protected: |
194 // Executes the permanent callback to pass off decoded video. | |
195 // | |
196 // TODO(scherkus): name this ConsumeVideoFrame() once we fix the TODO in | |
197 // VideoDecodeEngine::EventHandler to remove ConsumeVideoFrame() from there. | |
198 void VideoFrameReady(scoped_refptr<VideoFrame> frame) { | |
199 consume_video_frame_callback_.Run(frame); | |
200 } | |
201 | |
202 VideoDecoder(); | 192 VideoDecoder(); |
203 virtual ~VideoDecoder(); | 193 virtual ~VideoDecoder(); |
204 | |
205 private: | |
206 ConsumeVideoFrameCB consume_video_frame_callback_; | |
207 }; | 194 }; |
208 | 195 |
209 | 196 |
210 class MEDIA_EXPORT AudioDecoder : public Filter { | 197 class MEDIA_EXPORT AudioDecoder : public Filter { |
211 public: | 198 public: |
212 // Initialize a AudioDecoder with the given DemuxerStream, executing the | 199 // Initialize a AudioDecoder with the given DemuxerStream, executing the |
213 // callback upon completion. | 200 // callback upon completion. |
214 // stats_callback is used to update global pipeline statistics. | 201 // stats_callback is used to update global pipeline statistics. |
| 202 // |
| 203 // TODO(scherkus): switch to PipelineStatus callback. |
215 virtual void Initialize(DemuxerStream* stream, const base::Closure& callback, | 204 virtual void Initialize(DemuxerStream* stream, const base::Closure& callback, |
216 const StatisticsCallback& stats_callback) = 0; | 205 const StatisticsCallback& stats_callback) = 0; |
217 | 206 |
218 // 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 |
219 // will be recycled to renderer via the permanent callback. | 208 // will be recycled to renderer via the permanent callback. |
220 // | 209 // |
221 // We could also pass empty pointer here to let decoder provide buffers pool. | 210 // We could also pass empty pointer here to let decoder provide buffers pool. |
222 virtual void ProduceAudioSamples(scoped_refptr<Buffer> buffer) = 0; | 211 virtual void ProduceAudioSamples(scoped_refptr<Buffer> buffer) = 0; |
223 | 212 |
224 // Installs a permanent callback for passing decoded audio output. | 213 // Installs a permanent callback for passing decoded audio output. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 268 |
280 // Resumes playback after underflow occurs. | 269 // Resumes playback after underflow occurs. |
281 // |buffer_more_audio| is set to true if you want to increase the size of the | 270 // |buffer_more_audio| is set to true if you want to increase the size of the |
282 // decoded audio buffer. | 271 // decoded audio buffer. |
283 virtual void ResumeAfterUnderflow(bool buffer_more_audio) = 0; | 272 virtual void ResumeAfterUnderflow(bool buffer_more_audio) = 0; |
284 }; | 273 }; |
285 | 274 |
286 } // namespace media | 275 } // namespace media |
287 | 276 |
288 #endif // MEDIA_BASE_FILTERS_H_ | 277 #endif // MEDIA_BASE_FILTERS_H_ |
OLD | NEW |