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 // A base class that provides the plumbing for a decoder filters. | 5 // A base class that provides the plumbing for a decoder filters. |
6 | 6 |
7 #ifndef MEDIA_FILTERS_DECODER_BASE_H_ | 7 #ifndef MEDIA_FILTERS_DECODER_BASE_H_ |
8 #define MEDIA_FILTERS_DECODER_BASE_H_ | 8 #define MEDIA_FILTERS_DECODER_BASE_H_ |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
14 #include "base/task.h" | 14 #include "base/task.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "media/base/buffers.h" | 16 #include "media/base/buffers.h" |
17 #include "media/base/callback.h" | 17 #include "media/base/callback.h" |
18 #include "media/base/filters.h" | 18 #include "media/base/filters.h" |
19 #include "media/base/filter_host.h" | 19 #include "media/base/filter_host.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 // In this class, we over-specify method lookup via this-> to avoid unexpected | 23 // In this class, we over-specify method lookup via this-> to avoid unexpected |
24 // name resolution issues due to the two-phase lookup needed for dependent | 24 // name resolution issues due to the two-phase lookup needed for dependent |
25 // name resolution in templates. | 25 // name resolution in templates. |
26 template <class Decoder, class Output> | 26 template <class Decoder, class Output> |
27 class DecoderBase : public Decoder { | 27 class DecoderBase : public Decoder { |
28 public: | 28 public: |
29 | |
30 // Filter implementation. | 29 // Filter implementation. |
31 virtual void Stop(FilterCallback* callback) { | 30 virtual void Stop(FilterCallback* callback) { |
32 this->message_loop()->PostTask( | 31 this->message_loop()->PostTask( |
33 FROM_HERE, | 32 FROM_HERE, |
34 NewRunnableMethod(this, &DecoderBase::StopTask, callback)); | 33 NewRunnableMethod(this, &DecoderBase::StopTask, callback)); |
35 } | 34 } |
36 | 35 |
37 virtual void Seek(base::TimeDelta time, | 36 virtual void Seek(base::TimeDelta time, |
38 FilterCallback* callback) { | 37 FilterCallback* callback) { |
39 this->message_loop()->PostTask( | 38 this->message_loop()->PostTask( |
(...skipping 15 matching lines...) Expand all Loading... |
55 virtual const MediaFormat& media_format() { return media_format_; } | 54 virtual const MediaFormat& media_format() { return media_format_; } |
56 | 55 |
57 // Audio decoder. | 56 // Audio decoder. |
58 // Note that this class is only used by the audio decoder, this will | 57 // Note that this class is only used by the audio decoder, this will |
59 // eventually be merged into FFmpegAudioDecoder. | 58 // eventually be merged into FFmpegAudioDecoder. |
60 virtual void ProduceAudioSamples(scoped_refptr<Output> output) { | 59 virtual void ProduceAudioSamples(scoped_refptr<Output> output) { |
61 this->message_loop()->PostTask(FROM_HERE, | 60 this->message_loop()->PostTask(FROM_HERE, |
62 NewRunnableMethod(this, &DecoderBase::ReadTask, output)); | 61 NewRunnableMethod(this, &DecoderBase::ReadTask, output)); |
63 } | 62 } |
64 | 63 |
| 64 MessageLoop* message_loop() { return message_loop_; } |
| 65 |
65 protected: | 66 protected: |
66 DecoderBase() | 67 DecoderBase(MessageLoop* message_loop) |
67 : pending_reads_(0), | 68 : message_loop_(message_loop), |
| 69 pending_reads_(0), |
68 pending_requests_(0), | 70 pending_requests_(0), |
69 state_(kUninitialized) { | 71 state_(kUninitialized) { |
70 } | 72 } |
71 | 73 |
72 virtual ~DecoderBase() { | 74 virtual ~DecoderBase() { |
73 DCHECK(state_ == kUninitialized || state_ == kStopped); | 75 DCHECK(state_ == kUninitialized || state_ == kStopped); |
74 DCHECK(result_queue_.empty()); | 76 DCHECK(result_queue_.empty()); |
75 } | 77 } |
76 | 78 |
77 // This method is called by the derived class from within the OnDecode method. | 79 // This method is called by the derived class from within the OnDecode method. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // Execute the callback! | 269 // Execute the callback! |
268 --pending_requests_; | 270 --pending_requests_; |
269 | 271 |
270 // TODO(hclam): We only inherit this class from FFmpegAudioDecoder so we | 272 // TODO(hclam): We only inherit this class from FFmpegAudioDecoder so we |
271 // are making this call. We should correct this by merging this class into | 273 // are making this call. We should correct this by merging this class into |
272 // FFmpegAudioDecoder. | 274 // FFmpegAudioDecoder. |
273 Decoder::consume_audio_samples_callback()->Run(output); | 275 Decoder::consume_audio_samples_callback()->Run(output); |
274 return true; | 276 return true; |
275 } | 277 } |
276 | 278 |
| 279 MessageLoop* message_loop_; |
| 280 |
277 // Tracks the number of asynchronous reads issued to |demuxer_stream_|. | 281 // Tracks the number of asynchronous reads issued to |demuxer_stream_|. |
278 // Using size_t since it is always compared against deque::size(). | 282 // Using size_t since it is always compared against deque::size(). |
279 size_t pending_reads_; | 283 size_t pending_reads_; |
280 // Tracks the number of asynchronous reads issued from renderer. | 284 // Tracks the number of asynchronous reads issued from renderer. |
281 size_t pending_requests_; | 285 size_t pending_requests_; |
282 | 286 |
283 // Pointer to the demuxer stream that will feed us compressed buffers. | 287 // Pointer to the demuxer stream that will feed us compressed buffers. |
284 scoped_refptr<DemuxerStream> demuxer_stream_; | 288 scoped_refptr<DemuxerStream> demuxer_stream_; |
285 | 289 |
286 // Queue of decoded samples produced in the OnDecode() method of the decoder. | 290 // Queue of decoded samples produced in the OnDecode() method of the decoder. |
(...skipping 14 matching lines...) Expand all Loading... |
301 kStopped, | 305 kStopped, |
302 }; | 306 }; |
303 State state_; | 307 State state_; |
304 | 308 |
305 DISALLOW_COPY_AND_ASSIGN(DecoderBase); | 309 DISALLOW_COPY_AND_ASSIGN(DecoderBase); |
306 }; | 310 }; |
307 | 311 |
308 } // namespace media | 312 } // namespace media |
309 | 313 |
310 #endif // MEDIA_FILTERS_DECODER_BASE_H_ | 314 #endif // MEDIA_FILTERS_DECODER_BASE_H_ |
OLD | NEW |